diff --git a/striker-ui-api/src/lib/accessModule.ts b/striker-ui-api/src/lib/accessModule.ts index 17af7d9c..389ab5f2 100644 --- a/striker-ui-api/src/lib/accessModule.ts +++ b/striker-ui-api/src/lib/accessModule.ts @@ -128,7 +128,7 @@ class Access extends EventEmitter { }); }); - shvar({ scriptId, script }); + shvar({ scriptId, script }, 'Access interact: '); this.queue.push(scriptId); stdin?.write(script); @@ -139,6 +139,36 @@ class Access extends EventEmitter { const access = new Access(); +const data = async (...keys: string[]) => + access.interact('x', `data->${keys.join('->')}`); + +const subroutine = >( + subroutine: string, + { + params = [], + pre = ['Database'], + }: { + params?: unknown[]; + pre?: string[]; + }, +) => { + const chain = `${pre.join('->')}->${subroutine}`; + + const subParams: string[] = params.map((p) => { + let result: string; + + try { + result = JSON.stringify(p); + } catch (error) { + result = String(p); + } + + return result; + }); + + return access.interact('x', chain, ...subParams); +}; + const query = (script: string) => access.interact('r', formatSql(script)); @@ -366,6 +396,8 @@ export { getLocalHostName, getLocalHostUUID, getPeerData, + data, query, + subroutine, write, };