From de60c5f78e3166dd1405e18ce546a2db704fc7c4 Mon Sep 17 00:00:00 2001 From: despiegk Date: Sat, 16 Aug 2025 11:23:58 +0200 Subject: [PATCH] ... --- examples/clients/gitea.vsh | 4 +- examples/core/generate.vsh | 2 +- lib/biz/bizmodel/play.v | 3 +- .../giteaclient/giteaclient_factory_.v | 54 ++++---- lib/clients/giteaclient/giteaclient_model.v | 7 +- lib/clients/ipapi/ipapi_factory_.v | 116 ++++++++++------- lib/clients/jina/jina_factory_.v | 116 ++++++++++------- lib/clients/livekit/livekit_factory_.v | 116 ++++++++++------- lib/clients/mailclient/mailclient_factory_.v | 116 ++++++++++------- .../meilisearch/meilisearch_factory_.v | 116 ++++++++++------- lib/clients/mycelium/mycelium_factory_.v | 116 ++++++++++------- .../mycelium_rpc/mycelium_rpc_factory_.v | 116 ++++++++++------- lib/clients/openai/openai_factory_.v | 117 +++++++++++------- .../postgresql_client_factory_.v | 116 ++++++++++------- lib/clients/qdrant/qdrant_factory_.v | 116 ++++++++++------- lib/clients/rclone/rclone_factory_.v | 116 ++++++++++------- lib/clients/runpod/runpod_factory_.v | 116 ++++++++++------- lib/clients/sendgrid/sendgrid_factory_.v | 116 ++++++++++------- lib/clients/vastai/vastai_factory_.v | 116 ++++++++++------- lib/clients/wireguard/wireguard_factory_.v | 116 ++++++++++------- .../zerodb_client/zerodb_client_factory_.v | 116 ++++++++++------- lib/clients/zinit_rpc/zinit_rpc_factory_.v | 116 ++++++++++------- lib/core/base/context.v | 7 +- lib/core/base/session.v | 1 - .../templates/objname_factory_.vtemplate | 46 +++---- .../generic/templates/objname_model.vtemplate | 7 ++ lib/core/playcmds/play_core.v | 5 +- lib/core/playcmds/play_git.v | 3 +- lib/core/playcmds/play_luadns.v | 4 +- lib/core/playcmds/play_ssh.v | 4 +- lib/data/doctree/play.v | 2 - lib/data/radixtree/correctness_test.v | 14 +-- lib/data/radixtree/debug_deletion_test.v | 2 +- lib/data/radixtree/debug_test.v | 12 +- lib/data/radixtree/radixtree.v | 56 +++++---- lib/data/radixtree/serialize.v | 6 +- lib/osal/core/done.v | 10 +- lib/osal/core/exec.v | 21 ++-- 38 files changed, 1374 insertions(+), 869 deletions(-) diff --git a/examples/clients/gitea.vsh b/examples/clients/gitea.vsh index b9c11098..3b9f6b89 100755 --- a/examples/clients/gitea.vsh +++ b/examples/clients/gitea.vsh @@ -20,9 +20,9 @@ heroscript := " // Process the heroscript configuration // playcmds.play(heroscript: heroscript, emptycheck: false)! -println(giteaclient.list(fromdb:true)!) +println(giteaclient.list(fromdb: true)!) -$dbg; +//$dbg; // Get the configured client mut client := giteaclient.get()! diff --git a/examples/core/generate.vsh b/examples/core/generate.vsh index 77d4a124..ef3bf223 100755 --- a/examples/core/generate.vsh +++ b/examples/core/generate.vsh @@ -4,7 +4,7 @@ import freeflowuniverse.herolib.core.generator.generic as generator import freeflowuniverse.herolib.core.pathlib mut args := generator.GeneratorArgs{ - path: '~/code/github/freeflowuniverse/herolib/lib/clients/postgresql_client' + path: '~/code/github/freeflowuniverse/herolib/lib/clients' force: true } diff --git a/lib/biz/bizmodel/play.v b/lib/biz/bizmodel/play.v index c44d6eca..63bb4d2f 100644 --- a/lib/biz/bizmodel/play.v +++ b/lib/biz/bizmodel/play.v @@ -12,8 +12,7 @@ const action_priorities = { } pub fn play(mut plbook PlayBook) ! { - - if plbook.exists(filter: 'bizmodel.')==false{ + if plbook.exists(filter: 'bizmodel.') == false { return } // group actions by which bizmodel they belong to diff --git a/lib/clients/giteaclient/giteaclient_factory_.v b/lib/clients/giteaclient/giteaclient_factory_.v index 0c2311bb..7d5015a9 100644 --- a/lib/clients/giteaclient/giteaclient_factory_.v +++ b/lib/clients/giteaclient/giteaclient_factory_.v @@ -15,15 +15,15 @@ __global ( @[params] pub struct ArgsGet { pub mut: - name string = "default" - fromdb bool //will load from filesystem - create bool //default will not create if not exist + name string = 'default' + fromdb bool // will load from filesystem + create bool // default will not create if not exist } pub fn new(args ArgsGet) !&GiteaClient { mut obj := GiteaClient{ - name: args.name - } + name: args.name + } set(obj)! return &obj } @@ -36,21 +36,21 @@ pub fn get(args ArgsGet) !&GiteaClient { if r.hexists('context:giteaclient', args.name)! { data := r.hget('context:giteaclient', args.name)! if data.len == 0 { - return error('giteaclient with name:${args.name} does not exist, prob bug.') + return error('giteaclient with name: giteaclient does not exist, prob bug.') } - mut obj := json.decode(GiteaClient,data)! + mut obj := json.decode(GiteaClient, data)! set_in_mem(obj)! - }else{ + } else { if args.create { - new(args)! - }else{ - return error("GiteaClient with name '${args.name}' does not exist") + new(args)! + } else { + return error("GiteaClient with name 'giteaclient' does not exist") } } - return get(name: args.name)! //no longer from db nor create + return get(name: args.name)! // no longer from db nor create } return giteaclient_global[args.name] or { - return error('could not get config for giteaclient with name:${args.name}') + return error('could not get config for giteaclient with name:giteaclient') } } @@ -68,7 +68,6 @@ pub fn exists(args ArgsGet) !bool { mut context := base.context()! mut r := context.redis()! return r.hexists('context:giteaclient', args.name)! - } pub fn delete(args ArgsGet) ! { @@ -80,11 +79,11 @@ pub fn delete(args ArgsGet) ! { @[params] pub struct ArgsList { pub mut: - fromdb bool //will load from filesystem + fromdb bool // will load from filesystem } // if fromdb set: load from filesystem, and not from mem, will also reset what is in mem -pub fn list(args ArgsList) ![]&GiteaClient { +pub fn list(args ArgsList) ![]&GiteaClient { mut res := []&GiteaClient{} mut context := base.context()! if args.fromdb { @@ -92,12 +91,12 @@ pub fn list(args ArgsList) ![]&GiteaClient { giteaclient_global = map[string]&GiteaClient{} giteaclient_default = '' } - if args.fromdb { + if args.fromdb { mut r := context.redis()! mut l := r.hkeys('context:giteaclient')! - for name in l{ - res << get(name:name,fromdb:true)! + for name in l { + res << get(name: name, fromdb: true)! } return res } else { @@ -116,6 +115,11 @@ fn set_in_mem(o GiteaClient) ! { giteaclient_default = o.name } +// switch instance to be used for giteaclient +pub fn switch(name string) { + giteaclient_default = name +} + pub fn play(mut plbook PlayBook) ! { mut install_actions := plbook.find(filter: 'giteaclient.configure')! if install_actions.len > 0 { @@ -126,15 +130,3 @@ pub fn play(mut plbook PlayBook) ! { } } } - -// switch instance to be used for giteaclient -pub fn switch(name string) { - giteaclient_default = name -} - -// helpers - -@[params] -pub struct DefaultConfigArgs { - instance string = 'default' -} diff --git a/lib/clients/giteaclient/giteaclient_model.v b/lib/clients/giteaclient/giteaclient_model.v index ff56b2ed..45f940a2 100644 --- a/lib/clients/giteaclient/giteaclient_model.v +++ b/lib/clients/giteaclient/giteaclient_model.v @@ -57,4 +57,9 @@ fn obj_init(mycfg_ GiteaClient) !GiteaClient { return mycfg } -pub \ No newline at end of file +/////////////NORMALLY NO NEED TO TOUCH + +pub fn heroscript_loads(heroscript string) !GiteaClient { + mut obj := encoderhero.decode[GiteaClient](heroscript)! + return obj +} diff --git a/lib/clients/ipapi/ipapi_factory_.v b/lib/clients/ipapi/ipapi_factory_.v index 29946e74..9307baf0 100644 --- a/lib/clients/ipapi/ipapi_factory_.v +++ b/lib/clients/ipapi/ipapi_factory_.v @@ -3,6 +3,7 @@ module ipapi import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook { PlayBook } import freeflowuniverse.herolib.ui.console +import json __global ( ipapi_global map[string]&IPApi @@ -14,61 +15,97 @@ __global ( @[params] pub struct ArgsGet { pub mut: - name string + name string = 'default' + fromdb bool // will load from filesystem + create bool // default will not create if not exist } -fn args_get(args_ ArgsGet) ArgsGet { - mut args := args_ - if args.name == '' { - args.name = 'default' - } - return args -} - -pub fn get(args_ ArgsGet) !&IPApi { - mut context := base.context()! - mut args := args_get(args_) +pub fn new(args ArgsGet) !&IPApi { mut obj := IPApi{ name: args.name } - if args.name !in ipapi_global { - if !exists(args)! { - set(obj)! + set(obj)! + return &obj +} + +pub fn get(args ArgsGet) !&IPApi { + mut context := base.context()! + ipapi_default = args.name + if args.fromdb || args.name !in ipapi_global { + mut r := context.redis()! + if r.hexists('context:ipapi', args.name)! { + data := r.hget('context:ipapi', args.name)! + if data.len == 0 { + return error('ipapi with name: ipapi does not exist, prob bug.') + } + mut obj := json.decode(IPApi, data)! + set_in_mem(obj)! } else { - heroscript := context.hero_config_get('ipapi', args.name)! - mut obj_ := heroscript_loads(heroscript)! - set_in_mem(obj_)! + if args.create { + new(args)! + } else { + return error("IPApi with name 'ipapi' does not exist") + } } + return get(name: args.name)! // no longer from db nor create } return ipapi_global[args.name] or { - println(ipapi_global) - // bug if we get here because should be in globals - panic('could not get config for ipapi with name, is bug:${args.name}') + return error('could not get config for ipapi with name:ipapi') } } // register the config for the future pub fn set(o IPApi) ! { set_in_mem(o)! + ipapi_default = o.name mut context := base.context()! - heroscript := heroscript_dumps(o)! - context.hero_config_set('ipapi', o.name, heroscript)! + mut r := context.redis()! + r.hset('context:ipapi', o.name, json.encode(o))! } // does the config exists? -pub fn exists(args_ ArgsGet) !bool { +pub fn exists(args ArgsGet) !bool { mut context := base.context()! - mut args := args_get(args_) - return context.hero_config_exists('ipapi', args.name) + mut r := context.redis()! + return r.hexists('context:ipapi', args.name)! } -pub fn delete(args_ ArgsGet) ! { - mut args := args_get(args_) +pub fn delete(args ArgsGet) ! { mut context := base.context()! - context.hero_config_delete('ipapi', args.name)! - if args.name in ipapi_global { - // del ipapi_global[args.name] + mut r := context.redis()! + r.hdel('context:ipapi', args.name)! +} + +@[params] +pub struct ArgsList { +pub mut: + fromdb bool // will load from filesystem +} + +// if fromdb set: load from filesystem, and not from mem, will also reset what is in mem +pub fn list(args ArgsList) ![]&IPApi { + mut res := []&IPApi{} + mut context := base.context()! + if args.fromdb { + // reset what is in mem + ipapi_global = map[string]&IPApi{} + ipapi_default = '' } + if args.fromdb { + mut r := context.redis()! + mut l := r.hkeys('context:ipapi')! + + for name in l { + res << get(name: name, fromdb: true)! + } + return res + } else { + // load from memory + for _, client in ipapi_global { + res << client + } + } + return res } // only sets in mem, does not set as config @@ -78,6 +115,11 @@ fn set_in_mem(o IPApi) ! { ipapi_default = o.name } +// switch instance to be used for ipapi +pub fn switch(name string) { + ipapi_default = name +} + pub fn play(mut plbook PlayBook) ! { mut install_actions := plbook.find(filter: 'ipapi.configure')! if install_actions.len > 0 { @@ -88,15 +130,3 @@ pub fn play(mut plbook PlayBook) ! { } } } - -// switch instance to be used for ipapi -pub fn switch(name string) { - ipapi_default = name -} - -// helpers - -@[params] -pub struct DefaultConfigArgs { - instance string = 'default' -} diff --git a/lib/clients/jina/jina_factory_.v b/lib/clients/jina/jina_factory_.v index 61d9d82a..571140cc 100644 --- a/lib/clients/jina/jina_factory_.v +++ b/lib/clients/jina/jina_factory_.v @@ -3,6 +3,7 @@ module jina import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook { PlayBook } import freeflowuniverse.herolib.ui.console +import json __global ( jina_global map[string]&Jina @@ -14,61 +15,97 @@ __global ( @[params] pub struct ArgsGet { pub mut: - name string + name string = 'default' + fromdb bool // will load from filesystem + create bool // default will not create if not exist } -fn args_get(args_ ArgsGet) ArgsGet { - mut args := args_ - if args.name == '' { - args.name = 'default' - } - return args -} - -pub fn get(args_ ArgsGet) !&Jina { - mut context := base.context()! - mut args := args_get(args_) +pub fn new(args ArgsGet) !&Jina { mut obj := Jina{ name: args.name } - if args.name !in jina_global { - if !exists(args)! { - set(obj)! + set(obj)! + return &obj +} + +pub fn get(args ArgsGet) !&Jina { + mut context := base.context()! + jina_default = args.name + if args.fromdb || args.name !in jina_global { + mut r := context.redis()! + if r.hexists('context:jina', args.name)! { + data := r.hget('context:jina', args.name)! + if data.len == 0 { + return error('jina with name: jina does not exist, prob bug.') + } + mut obj := json.decode(Jina, data)! + set_in_mem(obj)! } else { - heroscript := context.hero_config_get('jina', args.name)! - mut obj_ := heroscript_loads(heroscript)! - set_in_mem(obj_)! + if args.create { + new(args)! + } else { + return error("Jina with name 'jina' does not exist") + } } + return get(name: args.name)! // no longer from db nor create } return jina_global[args.name] or { - println(jina_global) - // bug if we get here because should be in globals - panic('could not get config for jina with name, is bug:${args.name}') + return error('could not get config for jina with name:jina') } } // register the config for the future pub fn set(o Jina) ! { set_in_mem(o)! + jina_default = o.name mut context := base.context()! - heroscript := heroscript_dumps(o)! - context.hero_config_set('jina', o.name, heroscript)! + mut r := context.redis()! + r.hset('context:jina', o.name, json.encode(o))! } // does the config exists? -pub fn exists(args_ ArgsGet) !bool { +pub fn exists(args ArgsGet) !bool { mut context := base.context()! - mut args := args_get(args_) - return context.hero_config_exists('jina', args.name) + mut r := context.redis()! + return r.hexists('context:jina', args.name)! } -pub fn delete(args_ ArgsGet) ! { - mut args := args_get(args_) +pub fn delete(args ArgsGet) ! { mut context := base.context()! - context.hero_config_delete('jina', args.name)! - if args.name in jina_global { - // del jina_global[args.name] + mut r := context.redis()! + r.hdel('context:jina', args.name)! +} + +@[params] +pub struct ArgsList { +pub mut: + fromdb bool // will load from filesystem +} + +// if fromdb set: load from filesystem, and not from mem, will also reset what is in mem +pub fn list(args ArgsList) ![]&Jina { + mut res := []&Jina{} + mut context := base.context()! + if args.fromdb { + // reset what is in mem + jina_global = map[string]&Jina{} + jina_default = '' } + if args.fromdb { + mut r := context.redis()! + mut l := r.hkeys('context:jina')! + + for name in l { + res << get(name: name, fromdb: true)! + } + return res + } else { + // load from memory + for _, client in jina_global { + res << client + } + } + return res } // only sets in mem, does not set as config @@ -78,6 +115,11 @@ fn set_in_mem(o Jina) ! { jina_default = o.name } +// switch instance to be used for jina +pub fn switch(name string) { + jina_default = name +} + pub fn play(mut plbook PlayBook) ! { mut install_actions := plbook.find(filter: 'jina.configure')! if install_actions.len > 0 { @@ -88,15 +130,3 @@ pub fn play(mut plbook PlayBook) ! { } } } - -// switch instance to be used for jina -pub fn switch(name string) { - jina_default = name -} - -// helpers - -@[params] -pub struct DefaultConfigArgs { - instance string = 'default' -} diff --git a/lib/clients/livekit/livekit_factory_.v b/lib/clients/livekit/livekit_factory_.v index 5a2eec80..d7b28d98 100644 --- a/lib/clients/livekit/livekit_factory_.v +++ b/lib/clients/livekit/livekit_factory_.v @@ -3,6 +3,7 @@ module livekit import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook { PlayBook } import freeflowuniverse.herolib.ui.console +import json __global ( livekit_global map[string]&LivekitClient @@ -14,61 +15,97 @@ __global ( @[params] pub struct ArgsGet { pub mut: - name string + name string = 'default' + fromdb bool // will load from filesystem + create bool // default will not create if not exist } -fn args_get(args_ ArgsGet) ArgsGet { - mut args := args_ - if args.name == '' { - args.name = 'default' - } - return args -} - -pub fn get(args_ ArgsGet) !&LivekitClient { - mut context := base.context()! - mut args := args_get(args_) +pub fn new(args ArgsGet) !&LivekitClient { mut obj := LivekitClient{ name: args.name } - if args.name !in livekit_global { - if !exists(args)! { - set(obj)! + set(obj)! + return &obj +} + +pub fn get(args ArgsGet) !&LivekitClient { + mut context := base.context()! + livekit_default = args.name + if args.fromdb || args.name !in livekit_global { + mut r := context.redis()! + if r.hexists('context:livekit', args.name)! { + data := r.hget('context:livekit', args.name)! + if data.len == 0 { + return error('livekit with name: livekit does not exist, prob bug.') + } + mut obj := json.decode(LivekitClient, data)! + set_in_mem(obj)! } else { - heroscript := context.hero_config_get('livekit', args.name)! - mut obj_ := heroscript_loads(heroscript)! - set_in_mem(obj_)! + if args.create { + new(args)! + } else { + return error("LivekitClient with name 'livekit' does not exist") + } } + return get(name: args.name)! // no longer from db nor create } return livekit_global[args.name] or { - println(livekit_global) - // bug if we get here because should be in globals - panic('could not get config for livekit with name, is bug:${args.name}') + return error('could not get config for livekit with name:livekit') } } // register the config for the future pub fn set(o LivekitClient) ! { set_in_mem(o)! + livekit_default = o.name mut context := base.context()! - heroscript := heroscript_dumps(o)! - context.hero_config_set('livekit', o.name, heroscript)! + mut r := context.redis()! + r.hset('context:livekit', o.name, json.encode(o))! } // does the config exists? -pub fn exists(args_ ArgsGet) !bool { +pub fn exists(args ArgsGet) !bool { mut context := base.context()! - mut args := args_get(args_) - return context.hero_config_exists('livekit', args.name) + mut r := context.redis()! + return r.hexists('context:livekit', args.name)! } -pub fn delete(args_ ArgsGet) ! { - mut args := args_get(args_) +pub fn delete(args ArgsGet) ! { mut context := base.context()! - context.hero_config_delete('livekit', args.name)! - if args.name in livekit_global { - // del livekit_global[args.name] + mut r := context.redis()! + r.hdel('context:livekit', args.name)! +} + +@[params] +pub struct ArgsList { +pub mut: + fromdb bool // will load from filesystem +} + +// if fromdb set: load from filesystem, and not from mem, will also reset what is in mem +pub fn list(args ArgsList) ![]&LivekitClient { + mut res := []&LivekitClient{} + mut context := base.context()! + if args.fromdb { + // reset what is in mem + livekit_global = map[string]&LivekitClient{} + livekit_default = '' } + if args.fromdb { + mut r := context.redis()! + mut l := r.hkeys('context:livekit')! + + for name in l { + res << get(name: name, fromdb: true)! + } + return res + } else { + // load from memory + for _, client in livekit_global { + res << client + } + } + return res } // only sets in mem, does not set as config @@ -78,6 +115,11 @@ fn set_in_mem(o LivekitClient) ! { livekit_default = o.name } +// switch instance to be used for livekit +pub fn switch(name string) { + livekit_default = name +} + pub fn play(mut plbook PlayBook) ! { mut install_actions := plbook.find(filter: 'livekit.configure')! if install_actions.len > 0 { @@ -88,15 +130,3 @@ pub fn play(mut plbook PlayBook) ! { } } } - -// switch instance to be used for livekit -pub fn switch(name string) { - livekit_default = name -} - -// helpers - -@[params] -pub struct DefaultConfigArgs { - instance string = 'default' -} diff --git a/lib/clients/mailclient/mailclient_factory_.v b/lib/clients/mailclient/mailclient_factory_.v index 82a90703..f8a7c650 100644 --- a/lib/clients/mailclient/mailclient_factory_.v +++ b/lib/clients/mailclient/mailclient_factory_.v @@ -3,6 +3,7 @@ module mailclient import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook { PlayBook } import freeflowuniverse.herolib.ui.console +import json __global ( mailclient_global map[string]&MailClient @@ -14,61 +15,97 @@ __global ( @[params] pub struct ArgsGet { pub mut: - name string + name string = 'default' + fromdb bool // will load from filesystem + create bool // default will not create if not exist } -fn args_get(args_ ArgsGet) ArgsGet { - mut args := args_ - if args.name == '' { - args.name = 'default' - } - return args -} - -pub fn get(args_ ArgsGet) !&MailClient { - mut context := base.context()! - mut args := args_get(args_) +pub fn new(args ArgsGet) !&MailClient { mut obj := MailClient{ name: args.name } - if args.name !in mailclient_global { - if !exists(args)! { - set(obj)! + set(obj)! + return &obj +} + +pub fn get(args ArgsGet) !&MailClient { + mut context := base.context()! + mailclient_default = args.name + if args.fromdb || args.name !in mailclient_global { + mut r := context.redis()! + if r.hexists('context:mailclient', args.name)! { + data := r.hget('context:mailclient', args.name)! + if data.len == 0 { + return error('mailclient with name: mailclient does not exist, prob bug.') + } + mut obj := json.decode(MailClient, data)! + set_in_mem(obj)! } else { - heroscript := context.hero_config_get('mailclient', args.name)! - mut obj_ := heroscript_loads(heroscript)! - set_in_mem(obj_)! + if args.create { + new(args)! + } else { + return error("MailClient with name 'mailclient' does not exist") + } } + return get(name: args.name)! // no longer from db nor create } return mailclient_global[args.name] or { - println(mailclient_global) - // bug if we get here because should be in globals - panic('could not get config for mailclient with name, is bug:${args.name}') + return error('could not get config for mailclient with name:mailclient') } } // register the config for the future pub fn set(o MailClient) ! { set_in_mem(o)! + mailclient_default = o.name mut context := base.context()! - heroscript := heroscript_dumps(o)! - context.hero_config_set('mailclient', o.name, heroscript)! + mut r := context.redis()! + r.hset('context:mailclient', o.name, json.encode(o))! } // does the config exists? -pub fn exists(args_ ArgsGet) !bool { +pub fn exists(args ArgsGet) !bool { mut context := base.context()! - mut args := args_get(args_) - return context.hero_config_exists('mailclient', args.name) + mut r := context.redis()! + return r.hexists('context:mailclient', args.name)! } -pub fn delete(args_ ArgsGet) ! { - mut args := args_get(args_) +pub fn delete(args ArgsGet) ! { mut context := base.context()! - context.hero_config_delete('mailclient', args.name)! - if args.name in mailclient_global { - // del mailclient_global[args.name] + mut r := context.redis()! + r.hdel('context:mailclient', args.name)! +} + +@[params] +pub struct ArgsList { +pub mut: + fromdb bool // will load from filesystem +} + +// if fromdb set: load from filesystem, and not from mem, will also reset what is in mem +pub fn list(args ArgsList) ![]&MailClient { + mut res := []&MailClient{} + mut context := base.context()! + if args.fromdb { + // reset what is in mem + mailclient_global = map[string]&MailClient{} + mailclient_default = '' } + if args.fromdb { + mut r := context.redis()! + mut l := r.hkeys('context:mailclient')! + + for name in l { + res << get(name: name, fromdb: true)! + } + return res + } else { + // load from memory + for _, client in mailclient_global { + res << client + } + } + return res } // only sets in mem, does not set as config @@ -78,6 +115,11 @@ fn set_in_mem(o MailClient) ! { mailclient_default = o.name } +// switch instance to be used for mailclient +pub fn switch(name string) { + mailclient_default = name +} + pub fn play(mut plbook PlayBook) ! { mut install_actions := plbook.find(filter: 'mailclient.configure')! if install_actions.len > 0 { @@ -88,15 +130,3 @@ pub fn play(mut plbook PlayBook) ! { } } } - -// switch instance to be used for mailclient -pub fn switch(name string) { - mailclient_default = name -} - -// helpers - -@[params] -pub struct DefaultConfigArgs { - instance string = 'default' -} diff --git a/lib/clients/meilisearch/meilisearch_factory_.v b/lib/clients/meilisearch/meilisearch_factory_.v index d1453c38..573a8831 100644 --- a/lib/clients/meilisearch/meilisearch_factory_.v +++ b/lib/clients/meilisearch/meilisearch_factory_.v @@ -3,6 +3,7 @@ module meilisearch import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook { PlayBook } import freeflowuniverse.herolib.ui.console +import json __global ( meilisearch_global map[string]&MeilisearchClient @@ -14,61 +15,97 @@ __global ( @[params] pub struct ArgsGet { pub mut: - name string + name string = 'default' + fromdb bool // will load from filesystem + create bool // default will not create if not exist } -fn args_get(args_ ArgsGet) ArgsGet { - mut args := args_ - if args.name == '' { - args.name = 'default' - } - return args -} - -pub fn get(args_ ArgsGet) !&MeilisearchClient { - mut context := base.context()! - mut args := args_get(args_) +pub fn new(args ArgsGet) !&MeilisearchClient { mut obj := MeilisearchClient{ name: args.name } - if args.name !in meilisearch_global { - if !exists(args)! { - set(obj)! + set(obj)! + return &obj +} + +pub fn get(args ArgsGet) !&MeilisearchClient { + mut context := base.context()! + meilisearch_default = args.name + if args.fromdb || args.name !in meilisearch_global { + mut r := context.redis()! + if r.hexists('context:meilisearch', args.name)! { + data := r.hget('context:meilisearch', args.name)! + if data.len == 0 { + return error('meilisearch with name: meilisearch does not exist, prob bug.') + } + mut obj := json.decode(MeilisearchClient, data)! + set_in_mem(obj)! } else { - heroscript := context.hero_config_get('meilisearch', args.name)! - mut obj_ := heroscript_loads(heroscript)! - set_in_mem(obj_)! + if args.create { + new(args)! + } else { + return error("MeilisearchClient with name 'meilisearch' does not exist") + } } + return get(name: args.name)! // no longer from db nor create } return meilisearch_global[args.name] or { - println(meilisearch_global) - // bug if we get here because should be in globals - panic('could not get config for meilisearch with name, is bug:${args.name}') + return error('could not get config for meilisearch with name:meilisearch') } } // register the config for the future pub fn set(o MeilisearchClient) ! { set_in_mem(o)! + meilisearch_default = o.name mut context := base.context()! - heroscript := heroscript_dumps(o)! - context.hero_config_set('meilisearch', o.name, heroscript)! + mut r := context.redis()! + r.hset('context:meilisearch', o.name, json.encode(o))! } // does the config exists? -pub fn exists(args_ ArgsGet) !bool { +pub fn exists(args ArgsGet) !bool { mut context := base.context()! - mut args := args_get(args_) - return context.hero_config_exists('meilisearch', args.name) + mut r := context.redis()! + return r.hexists('context:meilisearch', args.name)! } -pub fn delete(args_ ArgsGet) ! { - mut args := args_get(args_) +pub fn delete(args ArgsGet) ! { mut context := base.context()! - context.hero_config_delete('meilisearch', args.name)! - if args.name in meilisearch_global { - // del meilisearch_global[args.name] + mut r := context.redis()! + r.hdel('context:meilisearch', args.name)! +} + +@[params] +pub struct ArgsList { +pub mut: + fromdb bool // will load from filesystem +} + +// if fromdb set: load from filesystem, and not from mem, will also reset what is in mem +pub fn list(args ArgsList) ![]&MeilisearchClient { + mut res := []&MeilisearchClient{} + mut context := base.context()! + if args.fromdb { + // reset what is in mem + meilisearch_global = map[string]&MeilisearchClient{} + meilisearch_default = '' } + if args.fromdb { + mut r := context.redis()! + mut l := r.hkeys('context:meilisearch')! + + for name in l { + res << get(name: name, fromdb: true)! + } + return res + } else { + // load from memory + for _, client in meilisearch_global { + res << client + } + } + return res } // only sets in mem, does not set as config @@ -78,6 +115,11 @@ fn set_in_mem(o MeilisearchClient) ! { meilisearch_default = o.name } +// switch instance to be used for meilisearch +pub fn switch(name string) { + meilisearch_default = name +} + pub fn play(mut plbook PlayBook) ! { mut install_actions := plbook.find(filter: 'meilisearch.configure')! if install_actions.len > 0 { @@ -88,15 +130,3 @@ pub fn play(mut plbook PlayBook) ! { } } } - -// switch instance to be used for meilisearch -pub fn switch(name string) { - meilisearch_default = name -} - -// helpers - -@[params] -pub struct DefaultConfigArgs { - instance string = 'default' -} diff --git a/lib/clients/mycelium/mycelium_factory_.v b/lib/clients/mycelium/mycelium_factory_.v index d0d3c1b5..1de2107a 100644 --- a/lib/clients/mycelium/mycelium_factory_.v +++ b/lib/clients/mycelium/mycelium_factory_.v @@ -3,6 +3,7 @@ module mycelium import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook { PlayBook } import freeflowuniverse.herolib.ui.console +import json __global ( mycelium_global map[string]&Mycelium @@ -14,61 +15,97 @@ __global ( @[params] pub struct ArgsGet { pub mut: - name string + name string = 'default' + fromdb bool // will load from filesystem + create bool // default will not create if not exist } -fn args_get(args_ ArgsGet) ArgsGet { - mut args := args_ - if args.name == '' { - args.name = 'default' - } - return args -} - -pub fn get(args_ ArgsGet) !&Mycelium { - mut context := base.context()! - mut args := args_get(args_) +pub fn new(args ArgsGet) !&Mycelium { mut obj := Mycelium{ name: args.name } - if args.name !in mycelium_global { - if !exists(args)! { - set(obj)! + set(obj)! + return &obj +} + +pub fn get(args ArgsGet) !&Mycelium { + mut context := base.context()! + mycelium_default = args.name + if args.fromdb || args.name !in mycelium_global { + mut r := context.redis()! + if r.hexists('context:mycelium', args.name)! { + data := r.hget('context:mycelium', args.name)! + if data.len == 0 { + return error('mycelium with name: mycelium does not exist, prob bug.') + } + mut obj := json.decode(Mycelium, data)! + set_in_mem(obj)! } else { - heroscript := context.hero_config_get('mycelium', args.name)! - mut obj_ := heroscript_loads(heroscript)! - set_in_mem(obj_)! + if args.create { + new(args)! + } else { + return error("Mycelium with name 'mycelium' does not exist") + } } + return get(name: args.name)! // no longer from db nor create } return mycelium_global[args.name] or { - println(mycelium_global) - // bug if we get here because should be in globals - panic('could not get config for mycelium with name, is bug:${args.name}') + return error('could not get config for mycelium with name:mycelium') } } // register the config for the future pub fn set(o Mycelium) ! { set_in_mem(o)! + mycelium_default = o.name mut context := base.context()! - heroscript := heroscript_dumps(o)! - context.hero_config_set('mycelium', o.name, heroscript)! + mut r := context.redis()! + r.hset('context:mycelium', o.name, json.encode(o))! } // does the config exists? -pub fn exists(args_ ArgsGet) !bool { +pub fn exists(args ArgsGet) !bool { mut context := base.context()! - mut args := args_get(args_) - return context.hero_config_exists('mycelium', args.name) + mut r := context.redis()! + return r.hexists('context:mycelium', args.name)! } -pub fn delete(args_ ArgsGet) ! { - mut args := args_get(args_) +pub fn delete(args ArgsGet) ! { mut context := base.context()! - context.hero_config_delete('mycelium', args.name)! - if args.name in mycelium_global { - // del mycelium_global[args.name] + mut r := context.redis()! + r.hdel('context:mycelium', args.name)! +} + +@[params] +pub struct ArgsList { +pub mut: + fromdb bool // will load from filesystem +} + +// if fromdb set: load from filesystem, and not from mem, will also reset what is in mem +pub fn list(args ArgsList) ![]&Mycelium { + mut res := []&Mycelium{} + mut context := base.context()! + if args.fromdb { + // reset what is in mem + mycelium_global = map[string]&Mycelium{} + mycelium_default = '' } + if args.fromdb { + mut r := context.redis()! + mut l := r.hkeys('context:mycelium')! + + for name in l { + res << get(name: name, fromdb: true)! + } + return res + } else { + // load from memory + for _, client in mycelium_global { + res << client + } + } + return res } // only sets in mem, does not set as config @@ -78,6 +115,11 @@ fn set_in_mem(o Mycelium) ! { mycelium_default = o.name } +// switch instance to be used for mycelium +pub fn switch(name string) { + mycelium_default = name +} + pub fn play(mut plbook PlayBook) ! { mut install_actions := plbook.find(filter: 'mycelium.configure')! if install_actions.len > 0 { @@ -88,15 +130,3 @@ pub fn play(mut plbook PlayBook) ! { } } } - -// switch instance to be used for mycelium -pub fn switch(name string) { - mycelium_default = name -} - -// helpers - -@[params] -pub struct DefaultConfigArgs { - instance string = 'default' -} diff --git a/lib/clients/mycelium_rpc/mycelium_rpc_factory_.v b/lib/clients/mycelium_rpc/mycelium_rpc_factory_.v index f8b3fd97..23a038a4 100644 --- a/lib/clients/mycelium_rpc/mycelium_rpc_factory_.v +++ b/lib/clients/mycelium_rpc/mycelium_rpc_factory_.v @@ -3,6 +3,7 @@ module mycelium_rpc import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook { PlayBook } import freeflowuniverse.herolib.ui.console +import json __global ( mycelium_rpc_global map[string]&MyceliumRPC @@ -14,61 +15,97 @@ __global ( @[params] pub struct ArgsGet { pub mut: - name string + name string = 'default' + fromdb bool // will load from filesystem + create bool // default will not create if not exist } -fn args_get(args_ ArgsGet) ArgsGet { - mut args := args_ - if args.name == '' { - args.name = 'default' - } - return args -} - -pub fn get(args_ ArgsGet) !&MyceliumRPC { - mut context := base.context()! - mut args := args_get(args_) +pub fn new(args ArgsGet) !&MyceliumRPC { mut obj := MyceliumRPC{ name: args.name } - if args.name !in mycelium_rpc_global { - if !exists(args)! { - set(obj)! + set(obj)! + return &obj +} + +pub fn get(args ArgsGet) !&MyceliumRPC { + mut context := base.context()! + mycelium_rpc_default = args.name + if args.fromdb || args.name !in mycelium_rpc_global { + mut r := context.redis()! + if r.hexists('context:mycelium_rpc', args.name)! { + data := r.hget('context:mycelium_rpc', args.name)! + if data.len == 0 { + return error('mycelium_rpc with name: mycelium_rpc does not exist, prob bug.') + } + mut obj := json.decode(MyceliumRPC, data)! + set_in_mem(obj)! } else { - heroscript := context.hero_config_get('mycelium_rpc', args.name)! - mut obj_ := heroscript_loads(heroscript)! - set_in_mem(obj_)! + if args.create { + new(args)! + } else { + return error("MyceliumRPC with name 'mycelium_rpc' does not exist") + } } + return get(name: args.name)! // no longer from db nor create } return mycelium_rpc_global[args.name] or { - println(mycelium_rpc_global) - // bug if we get here because should be in globals - panic('could not get config for mycelium_rpc with name, is bug:${args.name}') + return error('could not get config for mycelium_rpc with name:mycelium_rpc') } } // register the config for the future pub fn set(o MyceliumRPC) ! { set_in_mem(o)! + mycelium_rpc_default = o.name mut context := base.context()! - heroscript := heroscript_dumps(o)! - context.hero_config_set('mycelium_rpc', o.name, heroscript)! + mut r := context.redis()! + r.hset('context:mycelium_rpc', o.name, json.encode(o))! } // does the config exists? -pub fn exists(args_ ArgsGet) !bool { +pub fn exists(args ArgsGet) !bool { mut context := base.context()! - mut args := args_get(args_) - return context.hero_config_exists('mycelium_rpc', args.name) + mut r := context.redis()! + return r.hexists('context:mycelium_rpc', args.name)! } -pub fn delete(args_ ArgsGet) ! { - mut args := args_get(args_) +pub fn delete(args ArgsGet) ! { mut context := base.context()! - context.hero_config_delete('mycelium_rpc', args.name)! - if args.name in mycelium_rpc_global { - // del mycelium_rpc_global[args.name] + mut r := context.redis()! + r.hdel('context:mycelium_rpc', args.name)! +} + +@[params] +pub struct ArgsList { +pub mut: + fromdb bool // will load from filesystem +} + +// if fromdb set: load from filesystem, and not from mem, will also reset what is in mem +pub fn list(args ArgsList) ![]&MyceliumRPC { + mut res := []&MyceliumRPC{} + mut context := base.context()! + if args.fromdb { + // reset what is in mem + mycelium_rpc_global = map[string]&MyceliumRPC{} + mycelium_rpc_default = '' } + if args.fromdb { + mut r := context.redis()! + mut l := r.hkeys('context:mycelium_rpc')! + + for name in l { + res << get(name: name, fromdb: true)! + } + return res + } else { + // load from memory + for _, client in mycelium_rpc_global { + res << client + } + } + return res } // only sets in mem, does not set as config @@ -78,6 +115,11 @@ fn set_in_mem(o MyceliumRPC) ! { mycelium_rpc_default = o.name } +// switch instance to be used for mycelium_rpc +pub fn switch(name string) { + mycelium_rpc_default = name +} + pub fn play(mut plbook PlayBook) ! { mut install_actions := plbook.find(filter: 'mycelium_rpc.configure')! if install_actions.len > 0 { @@ -88,15 +130,3 @@ pub fn play(mut plbook PlayBook) ! { } } } - -// switch instance to be used for mycelium_rpc -pub fn switch(name string) { - mycelium_rpc_default = name -} - -// helpers - -@[params] -pub struct DefaultConfigArgs { - instance string = 'default' -} diff --git a/lib/clients/openai/openai_factory_.v b/lib/clients/openai/openai_factory_.v index 8aeb1af6..71b29fe9 100644 --- a/lib/clients/openai/openai_factory_.v +++ b/lib/clients/openai/openai_factory_.v @@ -3,6 +3,7 @@ module openai import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook { PlayBook } import freeflowuniverse.herolib.ui.console +import json __global ( openai_global map[string]&OpenAI @@ -14,61 +15,97 @@ __global ( @[params] pub struct ArgsGet { pub mut: - name string + name string = 'default' + fromdb bool // will load from filesystem + create bool // default will not create if not exist } -fn args_get(args_ ArgsGet) ArgsGet { - mut args := args_ - if args.name == '' { - args.name = 'default' - } - return args -} - -pub fn get(args_ ArgsGet) !&OpenAI { - mut context := base.context()! - mut args := args_get(args_) +pub fn new(args ArgsGet) !&OpenAI { mut obj := OpenAI{ name: args.name } - if args.name !in openai_global { - if !exists(args)! { - set(obj)! + set(obj)! + return &obj +} + +pub fn get(args ArgsGet) !&OpenAI { + mut context := base.context()! + openai_default = args.name + if args.fromdb || args.name !in openai_global { + mut r := context.redis()! + if r.hexists('context:openai', args.name)! { + data := r.hget('context:openai', args.name)! + if data.len == 0 { + return error('openai with name: openai does not exist, prob bug.') + } + mut obj := json.decode(OpenAI, data)! + set_in_mem(obj)! } else { - heroscript := context.hero_config_get('openai', args.name)! - mut obj_ := heroscript_loads(heroscript)! - set_in_mem(obj_)! + if args.create { + new(args)! + } else { + return error("OpenAI with name 'openai' does not exist") + } } + return get(name: args.name)! // no longer from db nor create } return openai_global[args.name] or { - println(openai_global) - // bug if we get here because should be in globals - panic('could not get config for openai with name, is bug:${args.name}') + return error('could not get config for openai with name:openai') } } // register the config for the future pub fn set(o OpenAI) ! { set_in_mem(o)! + openai_default = o.name mut context := base.context()! - heroscript := heroscript_dumps(o)! - context.hero_config_set('openai', o.name, heroscript)! + mut r := context.redis()! + r.hset('context:openai', o.name, json.encode(o))! } // does the config exists? -pub fn exists(args_ ArgsGet) !bool { +pub fn exists(args ArgsGet) !bool { mut context := base.context()! - mut args := args_get(args_) - return context.hero_config_exists('openai', args.name) + mut r := context.redis()! + return r.hexists('context:openai', args.name)! } -pub fn delete(args_ ArgsGet) ! { - mut args := args_get(args_) +pub fn delete(args ArgsGet) ! { mut context := base.context()! - context.hero_config_delete('openai', args.name)! - if args.name in openai_global { - // del openai_global[args.name] + mut r := context.redis()! + r.hdel('context:openai', args.name)! +} + +@[params] +pub struct ArgsList { +pub mut: + fromdb bool // will load from filesystem +} + +// if fromdb set: load from filesystem, and not from mem, will also reset what is in mem +pub fn list(args ArgsList) ![]&OpenAI { + mut res := []&OpenAI{} + mut context := base.context()! + if args.fromdb { + // reset what is in mem + openai_global = map[string]&OpenAI{} + openai_default = '' } + if args.fromdb { + mut r := context.redis()! + mut l := r.hkeys('context:openai')! + + for name in l { + res << get(name: name, fromdb: true)! + } + return res + } else { + // load from memory + for _, client in openai_global { + res << client + } + } + return res } // only sets in mem, does not set as config @@ -78,26 +115,18 @@ fn set_in_mem(o OpenAI) ! { openai_default = o.name } +// switch instance to be used for openai +pub fn switch(name string) { + openai_default = name +} + pub fn play(mut plbook PlayBook) ! { mut install_actions := plbook.find(filter: 'openai.configure')! if install_actions.len > 0 { for install_action in install_actions { - // println('install_action: ${install_action}') heroscript := install_action.heroscript() mut obj2 := heroscript_loads(heroscript)! set(obj2)! } } } - -// switch instance to be used for openai -pub fn switch(name string) { - openai_default = name -} - -// helpers - -@[params] -pub struct DefaultConfigArgs { - instance string = 'default' -} diff --git a/lib/clients/postgresql_client/postgresql_client_factory_.v b/lib/clients/postgresql_client/postgresql_client_factory_.v index a4271490..7be2367b 100644 --- a/lib/clients/postgresql_client/postgresql_client_factory_.v +++ b/lib/clients/postgresql_client/postgresql_client_factory_.v @@ -3,6 +3,7 @@ module postgresql_client import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook { PlayBook } import freeflowuniverse.herolib.ui.console +import json __global ( postgresql_client_global map[string]&PostgresqlClient @@ -14,61 +15,97 @@ __global ( @[params] pub struct ArgsGet { pub mut: - name string + name string = 'default' + fromdb bool // will load from filesystem + create bool // default will not create if not exist } -fn args_get(args_ ArgsGet) ArgsGet { - mut args := args_ - if args.name == '' { - args.name = 'default' - } - return args -} - -pub fn get(args_ ArgsGet) !&PostgresqlClient { - mut context := base.context()! - mut args := args_get(args_) +pub fn new(args ArgsGet) !&PostgresqlClient { mut obj := PostgresqlClient{ name: args.name } - if args.name !in postgresql_client_global { - if !exists(args)! { - set(obj)! + set(obj)! + return &obj +} + +pub fn get(args ArgsGet) !&PostgresqlClient { + mut context := base.context()! + postgresql_client_default = args.name + if args.fromdb || args.name !in postgresql_client_global { + mut r := context.redis()! + if r.hexists('context:postgresql_client', args.name)! { + data := r.hget('context:postgresql_client', args.name)! + if data.len == 0 { + return error('postgresql_client with name: postgresql_client does not exist, prob bug.') + } + mut obj := json.decode(PostgresqlClient, data)! + set_in_mem(obj)! } else { - heroscript := context.hero_config_get('postgresql_client', args.name)! - mut obj_ := heroscript_loads(heroscript)! - set_in_mem(obj_)! + if args.create { + new(args)! + } else { + return error("PostgresqlClient with name 'postgresql_client' does not exist") + } } + return get(name: args.name)! // no longer from db nor create } return postgresql_client_global[args.name] or { - println(postgresql_client_global) - // bug if we get here because should be in globals - panic('could not get config for postgresql_client with name, is bug:${args.name}') + return error('could not get config for postgresql_client with name:postgresql_client') } } // register the config for the future pub fn set(o PostgresqlClient) ! { set_in_mem(o)! + postgresql_client_default = o.name mut context := base.context()! - heroscript := heroscript_dumps(o)! - context.hero_config_set('postgresql_client', o.name, heroscript)! + mut r := context.redis()! + r.hset('context:postgresql_client', o.name, json.encode(o))! } // does the config exists? -pub fn exists(args_ ArgsGet) !bool { +pub fn exists(args ArgsGet) !bool { mut context := base.context()! - mut args := args_get(args_) - return context.hero_config_exists('postgresql_client', args.name) + mut r := context.redis()! + return r.hexists('context:postgresql_client', args.name)! } -pub fn delete(args_ ArgsGet) ! { - mut args := args_get(args_) +pub fn delete(args ArgsGet) ! { mut context := base.context()! - context.hero_config_delete('postgresql_client', args.name)! - if args.name in postgresql_client_global { - // del postgresql_client_global[args.name] + mut r := context.redis()! + r.hdel('context:postgresql_client', args.name)! +} + +@[params] +pub struct ArgsList { +pub mut: + fromdb bool // will load from filesystem +} + +// if fromdb set: load from filesystem, and not from mem, will also reset what is in mem +pub fn list(args ArgsList) ![]&PostgresqlClient { + mut res := []&PostgresqlClient{} + mut context := base.context()! + if args.fromdb { + // reset what is in mem + postgresql_client_global = map[string]&PostgresqlClient{} + postgresql_client_default = '' } + if args.fromdb { + mut r := context.redis()! + mut l := r.hkeys('context:postgresql_client')! + + for name in l { + res << get(name: name, fromdb: true)! + } + return res + } else { + // load from memory + for _, client in postgresql_client_global { + res << client + } + } + return res } // only sets in mem, does not set as config @@ -78,6 +115,11 @@ fn set_in_mem(o PostgresqlClient) ! { postgresql_client_default = o.name } +// switch instance to be used for postgresql_client +pub fn switch(name string) { + postgresql_client_default = name +} + pub fn play(mut plbook PlayBook) ! { mut install_actions := plbook.find(filter: 'postgresql_client.configure')! if install_actions.len > 0 { @@ -88,15 +130,3 @@ pub fn play(mut plbook PlayBook) ! { } } } - -// switch instance to be used for postgresql_client -pub fn switch(name string) { - postgresql_client_default = name -} - -// helpers - -@[params] -pub struct DefaultConfigArgs { - instance string = 'default' -} diff --git a/lib/clients/qdrant/qdrant_factory_.v b/lib/clients/qdrant/qdrant_factory_.v index 9e143549..b9f65ed2 100644 --- a/lib/clients/qdrant/qdrant_factory_.v +++ b/lib/clients/qdrant/qdrant_factory_.v @@ -3,6 +3,7 @@ module qdrant import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook { PlayBook } import freeflowuniverse.herolib.ui.console +import json __global ( qdrant_global map[string]&QDrantClient @@ -14,61 +15,97 @@ __global ( @[params] pub struct ArgsGet { pub mut: - name string + name string = 'default' + fromdb bool // will load from filesystem + create bool // default will not create if not exist } -fn args_get(args_ ArgsGet) ArgsGet { - mut args := args_ - if args.name == '' { - args.name = 'default' - } - return args -} - -pub fn get(args_ ArgsGet) !&QDrantClient { - mut context := base.context()! - mut args := args_get(args_) +pub fn new(args ArgsGet) !&QDrantClient { mut obj := QDrantClient{ name: args.name } - if args.name !in qdrant_global { - if !exists(args)! { - set(obj)! + set(obj)! + return &obj +} + +pub fn get(args ArgsGet) !&QDrantClient { + mut context := base.context()! + qdrant_default = args.name + if args.fromdb || args.name !in qdrant_global { + mut r := context.redis()! + if r.hexists('context:qdrant', args.name)! { + data := r.hget('context:qdrant', args.name)! + if data.len == 0 { + return error('qdrant with name: qdrant does not exist, prob bug.') + } + mut obj := json.decode(QDrantClient, data)! + set_in_mem(obj)! } else { - heroscript := context.hero_config_get('qdrant', args.name)! - mut obj_ := heroscript_loads(heroscript)! - set_in_mem(obj_)! + if args.create { + new(args)! + } else { + return error("QDrantClient with name 'qdrant' does not exist") + } } + return get(name: args.name)! // no longer from db nor create } return qdrant_global[args.name] or { - println(qdrant_global) - // bug if we get here because should be in globals - panic('could not get config for qdrant with name, is bug:${args.name}') + return error('could not get config for qdrant with name:qdrant') } } // register the config for the future pub fn set(o QDrantClient) ! { set_in_mem(o)! + qdrant_default = o.name mut context := base.context()! - heroscript := heroscript_dumps(o)! - context.hero_config_set('qdrant', o.name, heroscript)! + mut r := context.redis()! + r.hset('context:qdrant', o.name, json.encode(o))! } // does the config exists? -pub fn exists(args_ ArgsGet) !bool { +pub fn exists(args ArgsGet) !bool { mut context := base.context()! - mut args := args_get(args_) - return context.hero_config_exists('qdrant', args.name) + mut r := context.redis()! + return r.hexists('context:qdrant', args.name)! } -pub fn delete(args_ ArgsGet) ! { - mut args := args_get(args_) +pub fn delete(args ArgsGet) ! { mut context := base.context()! - context.hero_config_delete('qdrant', args.name)! - if args.name in qdrant_global { - // del qdrant_global[args.name] + mut r := context.redis()! + r.hdel('context:qdrant', args.name)! +} + +@[params] +pub struct ArgsList { +pub mut: + fromdb bool // will load from filesystem +} + +// if fromdb set: load from filesystem, and not from mem, will also reset what is in mem +pub fn list(args ArgsList) ![]&QDrantClient { + mut res := []&QDrantClient{} + mut context := base.context()! + if args.fromdb { + // reset what is in mem + qdrant_global = map[string]&QDrantClient{} + qdrant_default = '' } + if args.fromdb { + mut r := context.redis()! + mut l := r.hkeys('context:qdrant')! + + for name in l { + res << get(name: name, fromdb: true)! + } + return res + } else { + // load from memory + for _, client in qdrant_global { + res << client + } + } + return res } // only sets in mem, does not set as config @@ -78,6 +115,11 @@ fn set_in_mem(o QDrantClient) ! { qdrant_default = o.name } +// switch instance to be used for qdrant +pub fn switch(name string) { + qdrant_default = name +} + pub fn play(mut plbook PlayBook) ! { mut install_actions := plbook.find(filter: 'qdrant.configure')! if install_actions.len > 0 { @@ -88,15 +130,3 @@ pub fn play(mut plbook PlayBook) ! { } } } - -// switch instance to be used for qdrant -pub fn switch(name string) { - qdrant_default = name -} - -// helpers - -@[params] -pub struct DefaultConfigArgs { - instance string = 'default' -} diff --git a/lib/clients/rclone/rclone_factory_.v b/lib/clients/rclone/rclone_factory_.v index 10a661f2..5635de04 100644 --- a/lib/clients/rclone/rclone_factory_.v +++ b/lib/clients/rclone/rclone_factory_.v @@ -3,6 +3,7 @@ module rclone import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook { PlayBook } import freeflowuniverse.herolib.ui.console +import json __global ( rclone_global map[string]&RCloneClient @@ -14,61 +15,97 @@ __global ( @[params] pub struct ArgsGet { pub mut: - name string + name string = 'default' + fromdb bool // will load from filesystem + create bool // default will not create if not exist } -fn args_get(args_ ArgsGet) ArgsGet { - mut args := args_ - if args.name == '' { - args.name = 'default' - } - return args -} - -pub fn get(args_ ArgsGet) !&RCloneClient { - mut context := base.context()! - mut args := args_get(args_) +pub fn new(args ArgsGet) !&RCloneClient { mut obj := RCloneClient{ name: args.name } - if args.name !in rclone_global { - if !exists(args)! { - set(obj)! + set(obj)! + return &obj +} + +pub fn get(args ArgsGet) !&RCloneClient { + mut context := base.context()! + rclone_default = args.name + if args.fromdb || args.name !in rclone_global { + mut r := context.redis()! + if r.hexists('context:rclone', args.name)! { + data := r.hget('context:rclone', args.name)! + if data.len == 0 { + return error('rclone with name: rclone does not exist, prob bug.') + } + mut obj := json.decode(RCloneClient, data)! + set_in_mem(obj)! } else { - heroscript := context.hero_config_get('rclone', args.name)! - mut obj_ := heroscript_loads(heroscript)! - set_in_mem(obj_)! + if args.create { + new(args)! + } else { + return error("RCloneClient with name 'rclone' does not exist") + } } + return get(name: args.name)! // no longer from db nor create } return rclone_global[args.name] or { - println(rclone_global) - // bug if we get here because should be in globals - panic('could not get config for rclone with name, is bug:${args.name}') + return error('could not get config for rclone with name:rclone') } } // register the config for the future pub fn set(o RCloneClient) ! { set_in_mem(o)! + rclone_default = o.name mut context := base.context()! - heroscript := heroscript_dumps(o)! - context.hero_config_set('rclone', o.name, heroscript)! + mut r := context.redis()! + r.hset('context:rclone', o.name, json.encode(o))! } // does the config exists? -pub fn exists(args_ ArgsGet) !bool { +pub fn exists(args ArgsGet) !bool { mut context := base.context()! - mut args := args_get(args_) - return context.hero_config_exists('rclone', args.name) + mut r := context.redis()! + return r.hexists('context:rclone', args.name)! } -pub fn delete(args_ ArgsGet) ! { - mut args := args_get(args_) +pub fn delete(args ArgsGet) ! { mut context := base.context()! - context.hero_config_delete('rclone', args.name)! - if args.name in rclone_global { - // del rclone_global[args.name] + mut r := context.redis()! + r.hdel('context:rclone', args.name)! +} + +@[params] +pub struct ArgsList { +pub mut: + fromdb bool // will load from filesystem +} + +// if fromdb set: load from filesystem, and not from mem, will also reset what is in mem +pub fn list(args ArgsList) ![]&RCloneClient { + mut res := []&RCloneClient{} + mut context := base.context()! + if args.fromdb { + // reset what is in mem + rclone_global = map[string]&RCloneClient{} + rclone_default = '' } + if args.fromdb { + mut r := context.redis()! + mut l := r.hkeys('context:rclone')! + + for name in l { + res << get(name: name, fromdb: true)! + } + return res + } else { + // load from memory + for _, client in rclone_global { + res << client + } + } + return res } // only sets in mem, does not set as config @@ -78,6 +115,11 @@ fn set_in_mem(o RCloneClient) ! { rclone_default = o.name } +// switch instance to be used for rclone +pub fn switch(name string) { + rclone_default = name +} + pub fn play(mut plbook PlayBook) ! { mut install_actions := plbook.find(filter: 'rclone.configure')! if install_actions.len > 0 { @@ -88,15 +130,3 @@ pub fn play(mut plbook PlayBook) ! { } } } - -// switch instance to be used for rclone -pub fn switch(name string) { - rclone_default = name -} - -// helpers - -@[params] -pub struct DefaultConfigArgs { - instance string = 'default' -} diff --git a/lib/clients/runpod/runpod_factory_.v b/lib/clients/runpod/runpod_factory_.v index 3ff2a255..d30d98e9 100644 --- a/lib/clients/runpod/runpod_factory_.v +++ b/lib/clients/runpod/runpod_factory_.v @@ -3,6 +3,7 @@ module runpod import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook { PlayBook } import freeflowuniverse.herolib.ui.console +import json __global ( runpod_global map[string]&RunPod @@ -14,61 +15,97 @@ __global ( @[params] pub struct ArgsGet { pub mut: - name string + name string = 'default' + fromdb bool // will load from filesystem + create bool // default will not create if not exist } -fn args_get(args_ ArgsGet) ArgsGet { - mut args := args_ - if args.name == '' { - args.name = 'default' - } - return args -} - -pub fn get(args_ ArgsGet) !&RunPod { - mut context := base.context()! - mut args := args_get(args_) +pub fn new(args ArgsGet) !&RunPod { mut obj := RunPod{ name: args.name } - if args.name !in runpod_global { - if !exists(args)! { - set(obj)! + set(obj)! + return &obj +} + +pub fn get(args ArgsGet) !&RunPod { + mut context := base.context()! + runpod_default = args.name + if args.fromdb || args.name !in runpod_global { + mut r := context.redis()! + if r.hexists('context:runpod', args.name)! { + data := r.hget('context:runpod', args.name)! + if data.len == 0 { + return error('runpod with name: runpod does not exist, prob bug.') + } + mut obj := json.decode(RunPod, data)! + set_in_mem(obj)! } else { - heroscript := context.hero_config_get('runpod', args.name)! - mut obj_ := heroscript_loads(heroscript)! - set_in_mem(obj_)! + if args.create { + new(args)! + } else { + return error("RunPod with name 'runpod' does not exist") + } } + return get(name: args.name)! // no longer from db nor create } return runpod_global[args.name] or { - println(runpod_global) - // bug if we get here because should be in globals - panic('could not get config for runpod with name, is bug:${args.name}') + return error('could not get config for runpod with name:runpod') } } // register the config for the future pub fn set(o RunPod) ! { set_in_mem(o)! + runpod_default = o.name mut context := base.context()! - heroscript := heroscript_dumps(o)! - context.hero_config_set('runpod', o.name, heroscript)! + mut r := context.redis()! + r.hset('context:runpod', o.name, json.encode(o))! } // does the config exists? -pub fn exists(args_ ArgsGet) !bool { +pub fn exists(args ArgsGet) !bool { mut context := base.context()! - mut args := args_get(args_) - return context.hero_config_exists('runpod', args.name) + mut r := context.redis()! + return r.hexists('context:runpod', args.name)! } -pub fn delete(args_ ArgsGet) ! { - mut args := args_get(args_) +pub fn delete(args ArgsGet) ! { mut context := base.context()! - context.hero_config_delete('runpod', args.name)! - if args.name in runpod_global { - // del runpod_global[args.name] + mut r := context.redis()! + r.hdel('context:runpod', args.name)! +} + +@[params] +pub struct ArgsList { +pub mut: + fromdb bool // will load from filesystem +} + +// if fromdb set: load from filesystem, and not from mem, will also reset what is in mem +pub fn list(args ArgsList) ![]&RunPod { + mut res := []&RunPod{} + mut context := base.context()! + if args.fromdb { + // reset what is in mem + runpod_global = map[string]&RunPod{} + runpod_default = '' } + if args.fromdb { + mut r := context.redis()! + mut l := r.hkeys('context:runpod')! + + for name in l { + res << get(name: name, fromdb: true)! + } + return res + } else { + // load from memory + for _, client in runpod_global { + res << client + } + } + return res } // only sets in mem, does not set as config @@ -78,6 +115,11 @@ fn set_in_mem(o RunPod) ! { runpod_default = o.name } +// switch instance to be used for runpod +pub fn switch(name string) { + runpod_default = name +} + pub fn play(mut plbook PlayBook) ! { mut install_actions := plbook.find(filter: 'runpod.configure')! if install_actions.len > 0 { @@ -88,15 +130,3 @@ pub fn play(mut plbook PlayBook) ! { } } } - -// switch instance to be used for runpod -pub fn switch(name string) { - runpod_default = name -} - -// helpers - -@[params] -pub struct DefaultConfigArgs { - instance string = 'default' -} diff --git a/lib/clients/sendgrid/sendgrid_factory_.v b/lib/clients/sendgrid/sendgrid_factory_.v index e2804849..53e21e29 100644 --- a/lib/clients/sendgrid/sendgrid_factory_.v +++ b/lib/clients/sendgrid/sendgrid_factory_.v @@ -3,6 +3,7 @@ module sendgrid import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook { PlayBook } import freeflowuniverse.herolib.ui.console +import json __global ( sendgrid_global map[string]&SendGrid @@ -14,61 +15,97 @@ __global ( @[params] pub struct ArgsGet { pub mut: - name string + name string = 'default' + fromdb bool // will load from filesystem + create bool // default will not create if not exist } -fn args_get(args_ ArgsGet) ArgsGet { - mut args := args_ - if args.name == '' { - args.name = 'default' - } - return args -} - -pub fn get(args_ ArgsGet) !&SendGrid { - mut context := base.context()! - mut args := args_get(args_) +pub fn new(args ArgsGet) !&SendGrid { mut obj := SendGrid{ name: args.name } - if args.name !in sendgrid_global { - if !exists(args)! { - set(obj)! + set(obj)! + return &obj +} + +pub fn get(args ArgsGet) !&SendGrid { + mut context := base.context()! + sendgrid_default = args.name + if args.fromdb || args.name !in sendgrid_global { + mut r := context.redis()! + if r.hexists('context:sendgrid', args.name)! { + data := r.hget('context:sendgrid', args.name)! + if data.len == 0 { + return error('sendgrid with name: sendgrid does not exist, prob bug.') + } + mut obj := json.decode(SendGrid, data)! + set_in_mem(obj)! } else { - heroscript := context.hero_config_get('sendgrid', args.name)! - mut obj_ := heroscript_loads(heroscript)! - set_in_mem(obj_)! + if args.create { + new(args)! + } else { + return error("SendGrid with name 'sendgrid' does not exist") + } } + return get(name: args.name)! // no longer from db nor create } return sendgrid_global[args.name] or { - println(sendgrid_global) - // bug if we get here because should be in globals - panic('could not get config for sendgrid with name, is bug:${args.name}') + return error('could not get config for sendgrid with name:sendgrid') } } // register the config for the future pub fn set(o SendGrid) ! { set_in_mem(o)! + sendgrid_default = o.name mut context := base.context()! - heroscript := heroscript_dumps(o)! - context.hero_config_set('sendgrid', o.name, heroscript)! + mut r := context.redis()! + r.hset('context:sendgrid', o.name, json.encode(o))! } // does the config exists? -pub fn exists(args_ ArgsGet) !bool { +pub fn exists(args ArgsGet) !bool { mut context := base.context()! - mut args := args_get(args_) - return context.hero_config_exists('sendgrid', args.name) + mut r := context.redis()! + return r.hexists('context:sendgrid', args.name)! } -pub fn delete(args_ ArgsGet) ! { - mut args := args_get(args_) +pub fn delete(args ArgsGet) ! { mut context := base.context()! - context.hero_config_delete('sendgrid', args.name)! - if args.name in sendgrid_global { - // del sendgrid_global[args.name] + mut r := context.redis()! + r.hdel('context:sendgrid', args.name)! +} + +@[params] +pub struct ArgsList { +pub mut: + fromdb bool // will load from filesystem +} + +// if fromdb set: load from filesystem, and not from mem, will also reset what is in mem +pub fn list(args ArgsList) ![]&SendGrid { + mut res := []&SendGrid{} + mut context := base.context()! + if args.fromdb { + // reset what is in mem + sendgrid_global = map[string]&SendGrid{} + sendgrid_default = '' } + if args.fromdb { + mut r := context.redis()! + mut l := r.hkeys('context:sendgrid')! + + for name in l { + res << get(name: name, fromdb: true)! + } + return res + } else { + // load from memory + for _, client in sendgrid_global { + res << client + } + } + return res } // only sets in mem, does not set as config @@ -78,6 +115,11 @@ fn set_in_mem(o SendGrid) ! { sendgrid_default = o.name } +// switch instance to be used for sendgrid +pub fn switch(name string) { + sendgrid_default = name +} + pub fn play(mut plbook PlayBook) ! { mut install_actions := plbook.find(filter: 'sendgrid.configure')! if install_actions.len > 0 { @@ -88,15 +130,3 @@ pub fn play(mut plbook PlayBook) ! { } } } - -// switch instance to be used for sendgrid -pub fn switch(name string) { - sendgrid_default = name -} - -// helpers - -@[params] -pub struct DefaultConfigArgs { - instance string = 'default' -} diff --git a/lib/clients/vastai/vastai_factory_.v b/lib/clients/vastai/vastai_factory_.v index 849fc68e..9a3b9bb9 100644 --- a/lib/clients/vastai/vastai_factory_.v +++ b/lib/clients/vastai/vastai_factory_.v @@ -3,6 +3,7 @@ module vastai import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook { PlayBook } import freeflowuniverse.herolib.ui.console +import json __global ( vastai_global map[string]&VastAI @@ -14,61 +15,97 @@ __global ( @[params] pub struct ArgsGet { pub mut: - name string + name string = 'default' + fromdb bool // will load from filesystem + create bool // default will not create if not exist } -fn args_get(args_ ArgsGet) ArgsGet { - mut args := args_ - if args.name == '' { - args.name = 'default' - } - return args -} - -pub fn get(args_ ArgsGet) !&VastAI { - mut context := base.context()! - mut args := args_get(args_) +pub fn new(args ArgsGet) !&VastAI { mut obj := VastAI{ name: args.name } - if args.name !in vastai_global { - if !exists(args)! { - set(obj)! + set(obj)! + return &obj +} + +pub fn get(args ArgsGet) !&VastAI { + mut context := base.context()! + vastai_default = args.name + if args.fromdb || args.name !in vastai_global { + mut r := context.redis()! + if r.hexists('context:vastai', args.name)! { + data := r.hget('context:vastai', args.name)! + if data.len == 0 { + return error('vastai with name: vastai does not exist, prob bug.') + } + mut obj := json.decode(VastAI, data)! + set_in_mem(obj)! } else { - heroscript := context.hero_config_get('vastai', args.name)! - mut obj_ := heroscript_loads(heroscript)! - set_in_mem(obj_)! + if args.create { + new(args)! + } else { + return error("VastAI with name 'vastai' does not exist") + } } + return get(name: args.name)! // no longer from db nor create } return vastai_global[args.name] or { - println(vastai_global) - // bug if we get here because should be in globals - panic('could not get config for vastai with name, is bug:${args.name}') + return error('could not get config for vastai with name:vastai') } } // register the config for the future pub fn set(o VastAI) ! { set_in_mem(o)! + vastai_default = o.name mut context := base.context()! - heroscript := heroscript_dumps(o)! - context.hero_config_set('vastai', o.name, heroscript)! + mut r := context.redis()! + r.hset('context:vastai', o.name, json.encode(o))! } // does the config exists? -pub fn exists(args_ ArgsGet) !bool { +pub fn exists(args ArgsGet) !bool { mut context := base.context()! - mut args := args_get(args_) - return context.hero_config_exists('vastai', args.name) + mut r := context.redis()! + return r.hexists('context:vastai', args.name)! } -pub fn delete(args_ ArgsGet) ! { - mut args := args_get(args_) +pub fn delete(args ArgsGet) ! { mut context := base.context()! - context.hero_config_delete('vastai', args.name)! - if args.name in vastai_global { - // del vastai_global[args.name] + mut r := context.redis()! + r.hdel('context:vastai', args.name)! +} + +@[params] +pub struct ArgsList { +pub mut: + fromdb bool // will load from filesystem +} + +// if fromdb set: load from filesystem, and not from mem, will also reset what is in mem +pub fn list(args ArgsList) ![]&VastAI { + mut res := []&VastAI{} + mut context := base.context()! + if args.fromdb { + // reset what is in mem + vastai_global = map[string]&VastAI{} + vastai_default = '' } + if args.fromdb { + mut r := context.redis()! + mut l := r.hkeys('context:vastai')! + + for name in l { + res << get(name: name, fromdb: true)! + } + return res + } else { + // load from memory + for _, client in vastai_global { + res << client + } + } + return res } // only sets in mem, does not set as config @@ -78,6 +115,11 @@ fn set_in_mem(o VastAI) ! { vastai_default = o.name } +// switch instance to be used for vastai +pub fn switch(name string) { + vastai_default = name +} + pub fn play(mut plbook PlayBook) ! { mut install_actions := plbook.find(filter: 'vastai.configure')! if install_actions.len > 0 { @@ -88,15 +130,3 @@ pub fn play(mut plbook PlayBook) ! { } } } - -// switch instance to be used for vastai -pub fn switch(name string) { - vastai_default = name -} - -// helpers - -@[params] -pub struct DefaultConfigArgs { - instance string = 'default' -} diff --git a/lib/clients/wireguard/wireguard_factory_.v b/lib/clients/wireguard/wireguard_factory_.v index 21a4e0c4..17547e41 100644 --- a/lib/clients/wireguard/wireguard_factory_.v +++ b/lib/clients/wireguard/wireguard_factory_.v @@ -3,6 +3,7 @@ module wireguard import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook { PlayBook } import freeflowuniverse.herolib.ui.console +import json __global ( wireguard_global map[string]&WireGuard @@ -14,61 +15,97 @@ __global ( @[params] pub struct ArgsGet { pub mut: - name string + name string = 'default' + fromdb bool // will load from filesystem + create bool // default will not create if not exist } -fn args_get(args_ ArgsGet) ArgsGet { - mut args := args_ - if args.name == '' { - args.name = 'default' - } - return args -} - -pub fn get(args_ ArgsGet) !&WireGuard { - mut context := base.context()! - mut args := args_get(args_) +pub fn new(args ArgsGet) !&WireGuard { mut obj := WireGuard{ name: args.name } - if args.name !in wireguard_global { - if !exists(args)! { - set(obj)! + set(obj)! + return &obj +} + +pub fn get(args ArgsGet) !&WireGuard { + mut context := base.context()! + wireguard_default = args.name + if args.fromdb || args.name !in wireguard_global { + mut r := context.redis()! + if r.hexists('context:wireguard', args.name)! { + data := r.hget('context:wireguard', args.name)! + if data.len == 0 { + return error('wireguard with name: wireguard does not exist, prob bug.') + } + mut obj := json.decode(WireGuard, data)! + set_in_mem(obj)! } else { - heroscript := context.hero_config_get('wireguard', args.name)! - mut obj_ := heroscript_loads(heroscript)! - set_in_mem(obj_)! + if args.create { + new(args)! + } else { + return error("WireGuard with name 'wireguard' does not exist") + } } + return get(name: args.name)! // no longer from db nor create } return wireguard_global[args.name] or { - println(wireguard_global) - // bug if we get here because should be in globals - panic('could not get config for wireguard with name, is bug:${args.name}') + return error('could not get config for wireguard with name:wireguard') } } // register the config for the future pub fn set(o WireGuard) ! { set_in_mem(o)! + wireguard_default = o.name mut context := base.context()! - heroscript := heroscript_dumps(o)! - context.hero_config_set('wireguard', o.name, heroscript)! + mut r := context.redis()! + r.hset('context:wireguard', o.name, json.encode(o))! } // does the config exists? -pub fn exists(args_ ArgsGet) !bool { +pub fn exists(args ArgsGet) !bool { mut context := base.context()! - mut args := args_get(args_) - return context.hero_config_exists('wireguard', args.name) + mut r := context.redis()! + return r.hexists('context:wireguard', args.name)! } -pub fn delete(args_ ArgsGet) ! { - mut args := args_get(args_) +pub fn delete(args ArgsGet) ! { mut context := base.context()! - context.hero_config_delete('wireguard', args.name)! - if args.name in wireguard_global { - // del wireguard_global[args.name] + mut r := context.redis()! + r.hdel('context:wireguard', args.name)! +} + +@[params] +pub struct ArgsList { +pub mut: + fromdb bool // will load from filesystem +} + +// if fromdb set: load from filesystem, and not from mem, will also reset what is in mem +pub fn list(args ArgsList) ![]&WireGuard { + mut res := []&WireGuard{} + mut context := base.context()! + if args.fromdb { + // reset what is in mem + wireguard_global = map[string]&WireGuard{} + wireguard_default = '' } + if args.fromdb { + mut r := context.redis()! + mut l := r.hkeys('context:wireguard')! + + for name in l { + res << get(name: name, fromdb: true)! + } + return res + } else { + // load from memory + for _, client in wireguard_global { + res << client + } + } + return res } // only sets in mem, does not set as config @@ -78,6 +115,11 @@ fn set_in_mem(o WireGuard) ! { wireguard_default = o.name } +// switch instance to be used for wireguard +pub fn switch(name string) { + wireguard_default = name +} + pub fn play(mut plbook PlayBook) ! { mut install_actions := plbook.find(filter: 'wireguard.configure')! if install_actions.len > 0 { @@ -88,15 +130,3 @@ pub fn play(mut plbook PlayBook) ! { } } } - -// switch instance to be used for wireguard -pub fn switch(name string) { - wireguard_default = name -} - -// helpers - -@[params] -pub struct DefaultConfigArgs { - instance string = 'default' -} diff --git a/lib/clients/zerodb_client/zerodb_client_factory_.v b/lib/clients/zerodb_client/zerodb_client_factory_.v index f565ff10..16d7932f 100644 --- a/lib/clients/zerodb_client/zerodb_client_factory_.v +++ b/lib/clients/zerodb_client/zerodb_client_factory_.v @@ -3,6 +3,7 @@ module zerodb_client import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook { PlayBook } import freeflowuniverse.herolib.ui.console +import json __global ( zerodb_client_global map[string]&ZeroDBClient @@ -14,61 +15,97 @@ __global ( @[params] pub struct ArgsGet { pub mut: - name string + name string = 'default' + fromdb bool // will load from filesystem + create bool // default will not create if not exist } -fn args_get(args_ ArgsGet) ArgsGet { - mut args := args_ - if args.name == '' { - args.name = 'default' - } - return args -} - -pub fn get(args_ ArgsGet) !&ZeroDBClient { - mut context := base.context()! - mut args := args_get(args_) +pub fn new(args ArgsGet) !&ZeroDBClient { mut obj := ZeroDBClient{ name: args.name } - if args.name !in zerodb_client_global { - if !exists(args)! { - set(obj)! + set(obj)! + return &obj +} + +pub fn get(args ArgsGet) !&ZeroDBClient { + mut context := base.context()! + zerodb_client_default = args.name + if args.fromdb || args.name !in zerodb_client_global { + mut r := context.redis()! + if r.hexists('context:zerodb_client', args.name)! { + data := r.hget('context:zerodb_client', args.name)! + if data.len == 0 { + return error('zerodb_client with name: zerodb_client does not exist, prob bug.') + } + mut obj := json.decode(ZeroDBClient, data)! + set_in_mem(obj)! } else { - heroscript := context.hero_config_get('zerodb_client', args.name)! - mut obj_ := heroscript_loads(heroscript)! - set_in_mem(obj_)! + if args.create { + new(args)! + } else { + return error("ZeroDBClient with name 'zerodb_client' does not exist") + } } + return get(name: args.name)! // no longer from db nor create } return zerodb_client_global[args.name] or { - println(zerodb_client_global) - // bug if we get here because should be in globals - panic('could not get config for zerodb_client with name, is bug:${args.name}') + return error('could not get config for zerodb_client with name:zerodb_client') } } // register the config for the future pub fn set(o ZeroDBClient) ! { set_in_mem(o)! + zerodb_client_default = o.name mut context := base.context()! - heroscript := heroscript_dumps(o)! - context.hero_config_set('zerodb_client', o.name, heroscript)! + mut r := context.redis()! + r.hset('context:zerodb_client', o.name, json.encode(o))! } // does the config exists? -pub fn exists(args_ ArgsGet) !bool { +pub fn exists(args ArgsGet) !bool { mut context := base.context()! - mut args := args_get(args_) - return context.hero_config_exists('zerodb_client', args.name) + mut r := context.redis()! + return r.hexists('context:zerodb_client', args.name)! } -pub fn delete(args_ ArgsGet) ! { - mut args := args_get(args_) +pub fn delete(args ArgsGet) ! { mut context := base.context()! - context.hero_config_delete('zerodb_client', args.name)! - if args.name in zerodb_client_global { - // del zerodb_client_global[args.name] + mut r := context.redis()! + r.hdel('context:zerodb_client', args.name)! +} + +@[params] +pub struct ArgsList { +pub mut: + fromdb bool // will load from filesystem +} + +// if fromdb set: load from filesystem, and not from mem, will also reset what is in mem +pub fn list(args ArgsList) ![]&ZeroDBClient { + mut res := []&ZeroDBClient{} + mut context := base.context()! + if args.fromdb { + // reset what is in mem + zerodb_client_global = map[string]&ZeroDBClient{} + zerodb_client_default = '' } + if args.fromdb { + mut r := context.redis()! + mut l := r.hkeys('context:zerodb_client')! + + for name in l { + res << get(name: name, fromdb: true)! + } + return res + } else { + // load from memory + for _, client in zerodb_client_global { + res << client + } + } + return res } // only sets in mem, does not set as config @@ -78,6 +115,11 @@ fn set_in_mem(o ZeroDBClient) ! { zerodb_client_default = o.name } +// switch instance to be used for zerodb_client +pub fn switch(name string) { + zerodb_client_default = name +} + pub fn play(mut plbook PlayBook) ! { mut install_actions := plbook.find(filter: 'zerodb_client.configure')! if install_actions.len > 0 { @@ -88,15 +130,3 @@ pub fn play(mut plbook PlayBook) ! { } } } - -// switch instance to be used for zerodb_client -pub fn switch(name string) { - zerodb_client_default = name -} - -// helpers - -@[params] -pub struct DefaultConfigArgs { - instance string = 'default' -} diff --git a/lib/clients/zinit_rpc/zinit_rpc_factory_.v b/lib/clients/zinit_rpc/zinit_rpc_factory_.v index 743fb50a..348cb25e 100644 --- a/lib/clients/zinit_rpc/zinit_rpc_factory_.v +++ b/lib/clients/zinit_rpc/zinit_rpc_factory_.v @@ -3,6 +3,7 @@ module zinit_rpc import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook { PlayBook } import freeflowuniverse.herolib.ui.console +import json __global ( zinit_rpc_global map[string]&ZinitRPC @@ -14,61 +15,97 @@ __global ( @[params] pub struct ArgsGet { pub mut: - name string + name string = 'default' + fromdb bool // will load from filesystem + create bool // default will not create if not exist } -fn args_get(args_ ArgsGet) ArgsGet { - mut args := args_ - if args.name == '' { - args.name = 'default' - } - return args -} - -pub fn get(args_ ArgsGet) !&ZinitRPC { - mut context := base.context()! - mut args := args_get(args_) +pub fn new(args ArgsGet) !&ZinitRPC { mut obj := ZinitRPC{ name: args.name } - if args.name !in zinit_rpc_global { - if !exists(args)! { - set(obj)! + set(obj)! + return &obj +} + +pub fn get(args ArgsGet) !&ZinitRPC { + mut context := base.context()! + zinit_rpc_default = args.name + if args.fromdb || args.name !in zinit_rpc_global { + mut r := context.redis()! + if r.hexists('context:zinit_rpc', args.name)! { + data := r.hget('context:zinit_rpc', args.name)! + if data.len == 0 { + return error('zinit_rpc with name: zinit_rpc does not exist, prob bug.') + } + mut obj := json.decode(ZinitRPC, data)! + set_in_mem(obj)! } else { - heroscript := context.hero_config_get('zinit_rpc', args.name)! - mut obj_ := heroscript_loads(heroscript)! - set_in_mem(obj_)! + if args.create { + new(args)! + } else { + return error("ZinitRPC with name 'zinit_rpc' does not exist") + } } + return get(name: args.name)! // no longer from db nor create } return zinit_rpc_global[args.name] or { - println(zinit_rpc_global) - // bug if we get here because should be in globals - panic('could not get config for zinit_rpc with name, is bug:${args.name}') + return error('could not get config for zinit_rpc with name:zinit_rpc') } } // register the config for the future pub fn set(o ZinitRPC) ! { set_in_mem(o)! + zinit_rpc_default = o.name mut context := base.context()! - heroscript := heroscript_dumps(o)! - context.hero_config_set('zinit_rpc', o.name, heroscript)! + mut r := context.redis()! + r.hset('context:zinit_rpc', o.name, json.encode(o))! } // does the config exists? -pub fn exists(args_ ArgsGet) !bool { +pub fn exists(args ArgsGet) !bool { mut context := base.context()! - mut args := args_get(args_) - return context.hero_config_exists('zinit_rpc', args.name) + mut r := context.redis()! + return r.hexists('context:zinit_rpc', args.name)! } -pub fn delete(args_ ArgsGet) ! { - mut args := args_get(args_) +pub fn delete(args ArgsGet) ! { mut context := base.context()! - context.hero_config_delete('zinit_rpc', args.name)! - if args.name in zinit_rpc_global { - // del zinit_rpc_global[args.name] + mut r := context.redis()! + r.hdel('context:zinit_rpc', args.name)! +} + +@[params] +pub struct ArgsList { +pub mut: + fromdb bool // will load from filesystem +} + +// if fromdb set: load from filesystem, and not from mem, will also reset what is in mem +pub fn list(args ArgsList) ![]&ZinitRPC { + mut res := []&ZinitRPC{} + mut context := base.context()! + if args.fromdb { + // reset what is in mem + zinit_rpc_global = map[string]&ZinitRPC{} + zinit_rpc_default = '' } + if args.fromdb { + mut r := context.redis()! + mut l := r.hkeys('context:zinit_rpc')! + + for name in l { + res << get(name: name, fromdb: true)! + } + return res + } else { + // load from memory + for _, client in zinit_rpc_global { + res << client + } + } + return res } // only sets in mem, does not set as config @@ -78,6 +115,11 @@ fn set_in_mem(o ZinitRPC) ! { zinit_rpc_default = o.name } +// switch instance to be used for zinit_rpc +pub fn switch(name string) { + zinit_rpc_default = name +} + pub fn play(mut plbook PlayBook) ! { mut install_actions := plbook.find(filter: 'zinit_rpc.configure')! if install_actions.len > 0 { @@ -88,15 +130,3 @@ pub fn play(mut plbook PlayBook) ! { } } } - -// switch instance to be used for zinit_rpc -pub fn switch(name string) { - zinit_rpc_default = name -} - -// helpers - -@[params] -pub struct DefaultConfigArgs { - instance string = 'default' -} diff --git a/lib/core/base/context.v b/lib/core/base/context.v index cc634ea9..0ed72b81 100644 --- a/lib/core/base/context.v +++ b/lib/core/base/context.v @@ -9,9 +9,9 @@ import os @[heap] pub struct Context { mut: - params_ ?¶msparser.Params - redis_ ?&redisclient.Redis @[skip; str: skip] - path_ ?pathlib.Path + params_ ?¶msparser.Params + redis_ ?&redisclient.Redis @[skip; str: skip] + path_ ?pathlib.Path pub mut: // snippets map[string]string config ContextConfig @@ -88,7 +88,6 @@ fn (mut self Context) cfg_redis_exists() !bool { return r.exists('context:config')! } - // pub fn (mut self Context) secret_encrypt(txt string) !string { // return aes_symmetric.encrypt_str(txt, self.secret_get()!) // } diff --git a/lib/core/base/session.v b/lib/core/base/session.v index 87da5934..1e5c1e94 100644 --- a/lib/core/base/session.v +++ b/lib/core/base/session.v @@ -31,7 +31,6 @@ pub mut: // return 'hero:sessions:${self.guid()}' // } - // load the params from redis pub fn (mut self Session) load() ! { mut r := self.context.redis()! diff --git a/lib/core/generator/generic/templates/objname_factory_.vtemplate b/lib/core/generator/generic/templates/objname_factory_.vtemplate index ac9bf152..4fbc9090 100644 --- a/lib/core/generator/generic/templates/objname_factory_.vtemplate +++ b/lib/core/generator/generic/templates/objname_factory_.vtemplate @@ -5,6 +5,7 @@ import freeflowuniverse.herolib.core.base @end import freeflowuniverse.herolib.core.playbook { PlayBook } import freeflowuniverse.herolib.ui.console +import json @if args.cat == .installer import freeflowuniverse.herolib.osal.startupmanager @@ -21,7 +22,7 @@ __global ( /////////FACTORY -@[params] +@@[params] pub struct ArgsGet { pub mut: name string = "default" @@ -42,21 +43,25 @@ pub fn get(args ArgsGet) !&${args.classname} { mut context := base.context()! ${args.name}_default = args.name if args.fromdb || args.name !in ${args.name}_global { - if context.hero_config_exists('${args.name}', args.name) { - heroscript := context.hero_config_get('${args.name}', args.name)! - mut obj_ := heroscript_loads(heroscript)! - set_in_mem(obj_)! + mut r := context.redis()! + if r.hexists('context:${args.name}', args.name)! { + data := r.hget('context:${args.name}', args.name)! + if data.len == 0 { + return error('${args.name} with name: ${args.name} does not exist, prob bug.') + } + mut obj := json.decode(${args.classname},data)! + set_in_mem(obj)! }else{ if args.create { new(args)! }else{ - return error("${args.classname} with name '\${args.name}' does not exist") + return error("${args.classname} with name '${args.name}' does not exist") } } return get(name: args.name)! //no longer from db nor create } return ${args.name}_global[args.name] or { - return error('could not get config for ${args.name} with name:\${args.name}') + return error('could not get config for ${args.name} with name:${args.name}') } } @@ -65,23 +70,24 @@ pub fn set(o ${args.classname}) ! { set_in_mem(o)! ${args.name}_default = o.name mut context := base.context()! - heroscript := heroscript_dumps(o)! - context.hero_config_set('${args.name}', o.name, heroscript)! + mut r := context.redis()! + r.hset('context:${args.name}', o.name, json.encode(o))! } // does the config exists? pub fn exists(args ArgsGet) !bool { mut context := base.context()! - return context.hero_config_exists('${args.name}', args.name) + mut r := context.redis()! + return r.hexists('context:${args.name}', args.name)! } pub fn delete(args ArgsGet) ! { mut context := base.context()! - ${args.name}_global.delete(args.name) - context.hero_config_delete('${args.name}', args.name)! + mut r := context.redis()! + r.hdel('context:${args.name}', args.name)! } -@[params] +@@[params] pub struct ArgsList { pub mut: fromdb bool //will load from filesystem @@ -97,11 +103,11 @@ pub fn list(args ArgsList) ![]&${args.classname} { ${args.name}_default = '' } if args.fromdb { - for name in context.hero_config_list('${args.name}')!{ - mut hscript := context.hero_config_get('${args.name}', name)! - mut obj := heroscript_loads(hscript)! - set_in_mem(obj)! - res << &obj + mut r := context.redis()! + mut l := r.hkeys('context:${args.name}')! + + for name in l{ + res << get(name:name,fromdb:true)! } return res } else { @@ -331,7 +337,3 @@ pub fn (mut self ${args.classname}) destroy() ! { @end -//switch instance to be used for ${args.name} -pub fn switch(name string) { - ${args.name}_default = name -} diff --git a/lib/core/generator/generic/templates/objname_model.vtemplate b/lib/core/generator/generic/templates/objname_model.vtemplate index 92eb6b13..9933e197 100644 --- a/lib/core/generator/generic/templates/objname_model.vtemplate +++ b/lib/core/generator/generic/templates/objname_model.vtemplate @@ -66,3 +66,10 @@ fn configure() ! { } @end + +/////////////NORMALLY NO NEED TO TOUCH + +pub fn heroscript_loads(heroscript string) !${args.classname} { + mut obj := encoderhero.decode[${args.classname}](heroscript)! + return obj +} diff --git a/lib/core/playcmds/play_core.v b/lib/core/playcmds/play_core.v index 1ad28f88..ea38bcb6 100644 --- a/lib/core/playcmds/play_core.v +++ b/lib/core/playcmds/play_core.v @@ -11,8 +11,9 @@ import os // ------------------------------------------------------------------- fn play_core(mut plbook PlayBook) ! { - - if plbook.exists(filter: 'play.')==false && plbook.exists(filter: 'play.')==false && plbook.exists(filter: 'core.')==false{ + if plbook.exists(filter: 'play.') == false && plbook.exists(filter: 'play.') == false && plbook.exists( + filter: 'core.' + ) == false { return } diff --git a/lib/core/playcmds/play_git.v b/lib/core/playcmds/play_git.v index e06df621..c2d20431 100644 --- a/lib/core/playcmds/play_git.v +++ b/lib/core/playcmds/play_git.v @@ -11,8 +11,7 @@ import freeflowuniverse.herolib.ui.console // For verbose error reporting // --------------------------------------------------------------- fn play_git(mut plbook PlayBook) ! { - - if plbook.exists(filter: 'git.')==false{ + if plbook.exists(filter: 'git.') == false { return } diff --git a/lib/core/playcmds/play_luadns.v b/lib/core/playcmds/play_luadns.v index 443746dd..b46b3c26 100644 --- a/lib/core/playcmds/play_luadns.v +++ b/lib/core/playcmds/play_luadns.v @@ -5,12 +5,10 @@ import freeflowuniverse.herolib.core.playbook { PlayBook } // import os fn play_luadns(mut plbook PlayBook) ! { - - if plbook.exists(filter: 'luadns.')==false{ + if plbook.exists(filter: 'luadns.') == false { return } - // Variables below are not used, commenting them out // mut buildroot := '${os.home_dir()}/hero/var/mdbuild' // mut publishroot := '${os.home_dir()}/hero/www/info' diff --git a/lib/core/playcmds/play_ssh.v b/lib/core/playcmds/play_ssh.v index 480b526e..2e654541 100644 --- a/lib/core/playcmds/play_ssh.v +++ b/lib/core/playcmds/play_ssh.v @@ -4,9 +4,7 @@ import freeflowuniverse.herolib.osal.sshagent import freeflowuniverse.herolib.core.playbook { PlayBook } fn play_ssh(mut plbook PlayBook) ! { - - - if plbook.exists(filter: 'sshagent.')==false{ + if plbook.exists(filter: 'sshagent.') == false { return } diff --git a/lib/data/doctree/play.v b/lib/data/doctree/play.v index 0579d582..a391bebe 100644 --- a/lib/data/doctree/play.v +++ b/lib/data/doctree/play.v @@ -4,12 +4,10 @@ import freeflowuniverse.herolib.core.playbook { PlayBook } // import freeflowuniverse.herolib.ui.console pub fn play(mut plbook PlayBook) ! { - if !plbook.exists(filter: 'doctree.') { return } - mut doctrees := map[string]&Tree{} mut collection_actions := plbook.find(filter: 'doctree.scan')! diff --git a/lib/data/radixtree/correctness_test.v b/lib/data/radixtree/correctness_test.v index bcf7177b..4b48edd6 100644 --- a/lib/data/radixtree/correctness_test.v +++ b/lib/data/radixtree/correctness_test.v @@ -10,7 +10,7 @@ fn test_prefix_overlap_bug() ! { // Insert longer key first rt.set('test', 'value1'.bytes())! rt.set('testing', 'value2'.bytes())! - + // Now insert shorter key that is a prefix - this was the bug rt.set('te', 'value3'.bytes())! @@ -42,7 +42,7 @@ fn test_partial_overlap_split() ! { rt.set('foobar', 'value1'.bytes())! console.print_debug('After inserting foobar') rt.print_tree()! - + rt.set('foobaz', 'value2'.bytes())! console.print_debug('After inserting foobaz') rt.print_tree()! @@ -155,7 +155,7 @@ fn test_empty_key() ! { // Set empty key rt.set('', 'empty_value'.bytes())! - + // Set regular key rt.set('regular', 'regular_value'.bytes())! @@ -223,7 +223,7 @@ fn test_complex_overlaps() ! { 'ac', 'b', 'ba', - 'bb' + 'bb', ] // Insert in random order to test robustness @@ -257,7 +257,7 @@ fn test_complex_overlaps() ! { // Run all correctness tests fn test_all_correctness() ! { console.print_debug('Running all correctness tests...') - + test_prefix_overlap_bug()! test_partial_overlap_split()! test_deletion_compression()! @@ -266,6 +266,6 @@ fn test_all_correctness() ! { test_empty_key()! test_long_keys()! test_complex_overlaps()! - + console.print_debug('All correctness tests passed!') -} \ No newline at end of file +} diff --git a/lib/data/radixtree/debug_deletion_test.v b/lib/data/radixtree/debug_deletion_test.v index 6238de45..f60b9f92 100644 --- a/lib/data/radixtree/debug_deletion_test.v +++ b/lib/data/radixtree/debug_deletion_test.v @@ -28,4 +28,4 @@ fn test_debug_deletion() ! { } else { console.print_debug('ERROR: cargo not found after deletion') } -} \ No newline at end of file +} diff --git a/lib/data/radixtree/debug_test.v b/lib/data/radixtree/debug_test.v index 4de2ef4f..bceeda47 100644 --- a/lib/data/radixtree/debug_test.v +++ b/lib/data/radixtree/debug_test.v @@ -9,24 +9,24 @@ fn test_simple_debug() ! { console.print_debug('Inserting "foobar"') rt.set('foobar', 'value1'.bytes())! rt.print_tree()! - + console.print_debug('Getting "foobar"') value1 := rt.get('foobar')! console.print_debug('Got value: ${value1.bytestr()}') - + console.print_debug('Inserting "foobaz"') rt.set('foobaz', 'value2'.bytes())! rt.print_tree()! - + console.print_debug('Getting "foobar" again') value1_again := rt.get('foobar')! console.print_debug('Got value: ${value1_again.bytestr()}') - + console.print_debug('Getting "foobaz"') value2 := rt.get('foobaz')! console.print_debug('Got value: ${value2.bytestr()}') - + console.print_debug('Listing all keys') all_keys := rt.list('')! console.print_debug('All keys: ${all_keys}') -} \ No newline at end of file +} diff --git a/lib/data/radixtree/radixtree.v b/lib/data/radixtree/radixtree.v index 00ca87a0..6cdb3b1c 100644 --- a/lib/data/radixtree/radixtree.v +++ b/lib/data/radixtree/radixtree.v @@ -156,10 +156,12 @@ pub fn (mut rt RadixTree) set(key string, value []u8) ! { mut intermediate := Node{ key_segment: '' // not used at traversal time value: []u8{} - children: [NodeRef{ - key_part: child_suffix - node_id: split_child_id - }] + children: [ + NodeRef{ + key_part: child_suffix + node_id: split_child_id + }, + ] is_leaf: false } @@ -222,7 +224,7 @@ pub fn (mut rt RadixTree) get(key string) ![]u8 { child := node.children[child_idx] common_prefix := get_common_prefix(rem, child.key_part) - + if common_prefix.len != child.key_part.len { // partial match - key doesn't exist return error('Key not found') @@ -231,7 +233,7 @@ pub fn (mut rt RadixTree) get(key string) ![]u8 { current_id = child.node_id offset += child.key_part.len } - + return error('Key not found') } @@ -322,9 +324,9 @@ pub fn (mut rt RadixTree) delete(key string) ! { if common_prefix.len == child.key_part.len { // Full match with child edge path << PathInfo{ - node_id: current_id + node_id: current_id edge_to_child: child.key_part - child_id: child.node_id + child_id: child.node_id } current_id = child.node_id offset += child.key_part.len @@ -362,7 +364,7 @@ pub fn (mut rt RadixTree) delete(key string) ! { parent_info := path.last() parent_id := parent_info.node_id mut parent_node := deserialize_node(rt.db.get(parent_id)!)! - + // Remove the child reference for i, child in parent_node.children { if child.node_id == current_id { @@ -370,12 +372,12 @@ pub fn (mut rt RadixTree) delete(key string) ! { break } } - + rt.db.set(id: parent_id, data: serialize_node(parent_node))! rt.db.delete(current_id)! - + // Compress the parent if needed - rt.maybe_compress_with_path(parent_id, path[..path.len-1])! + rt.maybe_compress_with_path(parent_id, path[..path.len - 1])! } else { // This is the root node, just mark as non-leaf target_node.is_leaf = false @@ -398,7 +400,7 @@ fn (mut rt RadixTree) maybe_compress_with_path(node_id u32, path []PathInfo) ! { if node.children.len != 1 { return } - + ch := node.children[0] mut child_node := deserialize_node(rt.db.get(ch.node_id)!)! @@ -409,7 +411,7 @@ fn (mut rt RadixTree) maybe_compress_with_path(node_id u32, path []PathInfo) ! { rt.db.set(id: node_id, data: serialize_node(node))! rt.db.delete(ch.node_id)! - + // Update the parent's edge to include the compressed path if path.len > 0 { // Find the parent that points to this node @@ -417,7 +419,7 @@ fn (mut rt RadixTree) maybe_compress_with_path(node_id u32, path []PathInfo) ! { if path[i].child_id == node_id { parent_id := path[i].node_id mut parent_node := deserialize_node(rt.db.get(parent_id)!)! - + // Update the edge label to include the compressed segment for j, child in parent_node.children { if child.node_id == node_id { @@ -435,18 +437,18 @@ fn (mut rt RadixTree) maybe_compress_with_path(node_id u32, path []PathInfo) ! { // Lists all keys with a given prefix pub fn (mut rt RadixTree) list(prefix string) ![]string { mut result := []string{} - + if prefix.len == 0 { rt.collect_all_keys(rt.root_id, '', mut result)! return result } - + node_info := rt.find_node_for_prefix_with_path(prefix) or { // prefix not found, return empty result return result } rt.collect_all_keys(node_info.node_id, node_info.path, mut result)! - + // Filter results to only include keys that actually start with the prefix mut filtered_result := []string{} for key in result { @@ -454,7 +456,7 @@ pub fn (mut rt RadixTree) list(prefix string) ![]string { filtered_result << key } } - + return filtered_result } @@ -468,20 +470,20 @@ fn (mut rt RadixTree) find_node_for_prefix_with_path(prefix string) !NodePathInf mut current_id := rt.root_id mut offset := 0 mut current_path := '' - + for offset < prefix.len { node := deserialize_node(rt.db.get(current_id)!)! rem := prefix[offset..] - + mut found := false for child in node.children { common_prefix := get_common_prefix(rem, child.key_part) cp_len := common_prefix.len - + if cp_len == 0 { continue } - + if cp_len == child.key_part.len { // child edge is fully consumed by prefix current_id = child.node_id @@ -494,22 +496,22 @@ fn (mut rt RadixTree) find_node_for_prefix_with_path(prefix string) !NodePathInf // but only those that actually start with the full prefix return NodePathInfo{ node_id: current_id - path: current_path + path: current_path } } else { // diverged -> no matches return error('Prefix not found') } } - + if !found { return error('Prefix not found') } } - + return NodePathInfo{ node_id: current_id - path: current_path + path: current_path } } diff --git a/lib/data/radixtree/serialize.v b/lib/data/radixtree/serialize.v index 64134414..9e04421c 100644 --- a/lib/data/radixtree/serialize.v +++ b/lib/data/radixtree/serialize.v @@ -18,19 +18,19 @@ fn serialize_node(node Node) []u8 { if node.is_leaf { flags |= 0x01 } - + // Check if value should be stored out-of-line has_large_value := node.value.len > max_inline_value_size if has_large_value { flags |= 0x02 } - + // Check if children should be paged has_many_children := node.children.len > max_inline_children if has_many_children { flags |= 0x04 } - + e.add_u8(flags) // Note: key_segment is redundant and not stored (saves space) diff --git a/lib/osal/core/done.v b/lib/osal/core/done.v index 592807fc..cb646938 100644 --- a/lib/osal/core/done.v +++ b/lib/osal/core/done.v @@ -11,17 +11,17 @@ fn donedb() !&redisclient.Redis { pub fn done_set(key string, val string) ! { mut db := donedb()! - db.hset("context:done",key, val)! + db.hset('context:done', key, val)! } pub fn done_get(key string) ?string { mut db := donedb() or { panic(err) } - return db.hget("context:done", key) or { return none } + return db.hget('context:done', key) or { return none } } pub fn done_delete(key string) ! { mut db := donedb()! - db.hdel("context:done", key)! + db.hdel('context:done', key)! } pub fn done_get_str(key string) string { @@ -36,7 +36,7 @@ pub fn done_get_int(key string) int { pub fn done_exists(key string) bool { mut db := donedb() or { panic(err) } - return db.hexists("context:done", key) or { false } + return db.hexists('context:done', key) or { false } } pub fn done_print() ! { @@ -52,5 +52,5 @@ pub fn done_print() ! { pub fn done_reset() ! { mut db := donedb()! - db.del("context:done")! + db.del('context:done')! } diff --git a/lib/osal/core/exec.v b/lib/osal/core/exec.v index 9f2a6f89..9c009334 100644 --- a/lib/osal/core/exec.v +++ b/lib/osal/core/exec.v @@ -482,7 +482,6 @@ pub fn exec_string(cmd Command) !string { return job.cmd.scriptpath } - @[params] pub struct CommandFast { pub mut: @@ -491,18 +490,17 @@ pub mut: work_folder string // location where cmd will be executed environment map[string]string // env variables ignore_error_codes []int - debug bool // if debug will put +ex in the script which is being executed and will make sure script stays + debug bool // if debug will put +ex in the script which is being executed and will make sure script stays includeprofile bool notempty bool } - -//execute something fast, make sure it returns an error if the result is empty -//source the +// execute something fast, make sure it returns an error if the result is empty +// source the pub fn exec_fast(cmd_ CommandFast) !string { mut cmd_str := texttools.dedent(cmd_.cmd) - mut toexecute:=[]string{} + mut toexecute := []string{} if cmd_.debug { // Add +ex for debug mode if it's a bash script @@ -515,13 +513,12 @@ pub fn exec_fast(cmd_ CommandFast) !string { toexecute << profile_path_source_and()! } - for key,val in cmd_.environment { - toexecute << 'export ${key}=${val}' + for key, val in cmd_.environment { + toexecute << 'export ${key}=${val}' } - if cmd_.work_folder.len > 0 { - toexecute << "cd ${cmd_.work_folder}" + toexecute << 'cd ${cmd_.work_folder}' } toexecute << cmd_str @@ -533,7 +530,7 @@ pub fn exec_fast(cmd_ CommandFast) !string { if result.exit_code != 0 { if !(cmd_.ignore_error || result.exit_code in cmd_.ignore_error_codes) { return error("couldn't execute '${cmd_.cmd}', result code: ${result.exit_code}\n${result.output}") - } + } } if cmd_.notempty && result.output.len == 0 { @@ -541,4 +538,4 @@ pub fn exec_fast(cmd_ CommandFast) !string { } return result.output -} \ No newline at end of file +}