From cb6a699fc779631f14788420dc78127bb61f45d3 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Wed, 26 Apr 2023 15:35:51 -0400 Subject: [PATCH] fix(striker-ui-api): connect data, subroutine wrappers to access interact --- striker-ui-api/src/lib/accessModule.ts | 34 +++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) 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, };