fix(striker-ui-api): connect data, subroutine wrappers to access interact

main
Tsu-ba-me 2 years ago
parent ea78090ac0
commit cb6a699fc7
  1. 34
      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); this.queue.push(scriptId);
stdin?.write(script); stdin?.write(script);
@ -139,6 +139,36 @@ class Access extends EventEmitter {
const access = new Access(); const access = new Access();
const data = async <T>(...keys: string[]) =>
access.interact<T>('x', `data->${keys.join('->')}`);
const subroutine = <T extends Record<string, unknown>>(
subroutine: string,
{
params = [],
pre = ['Database'],
}: {
params?: unknown[];
pre?: string[];
},
) => {
const chain = `${pre.join('->')}->${subroutine}`;
const subParams: string[] = params.map<string>((p) => {
let result: string;
try {
result = JSON.stringify(p);
} catch (error) {
result = String(p);
}
return result;
});
return access.interact<T>('x', chain, ...subParams);
};
const query = <T extends (number | null | string)[][]>(script: string) => const query = <T extends (number | null | string)[][]>(script: string) =>
access.interact<T>('r', formatSql(script)); access.interact<T>('r', formatSql(script));
@ -366,6 +396,8 @@ export {
getLocalHostName, getLocalHostName,
getLocalHostUUID, getLocalHostUUID,
getPeerData, getPeerData,
data,
query, query,
subroutine,
write, write,
}; };

Loading…
Cancel
Save