From 5a9f9369130235b8df380380cf2835ce206bf032 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Thu, 22 Sep 2022 13:39:19 -0400 Subject: [PATCH] feat(striker-ui-api): add getAnvilData to accessModule --- striker-ui-api/src/lib/accessModule.ts | 17 ++++++++++++++++- striker-ui-api/src/types/AnvilDataStruct.d.ts | 3 +++ .../src/types/GetAnvilDataOptions.d.ts | 3 +++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 striker-ui-api/src/types/AnvilDataStruct.d.ts create mode 100644 striker-ui-api/src/types/GetAnvilDataOptions.d.ts diff --git a/striker-ui-api/src/lib/accessModule.ts b/striker-ui-api/src/lib/accessModule.ts index bae56b51..8216d31f 100644 --- a/striker-ui-api/src/lib/accessModule.ts +++ b/striker-ui-api/src/lib/accessModule.ts @@ -19,7 +19,7 @@ const execAnvilAccessModule = ( throw error; } - if (stderr) { + if (stderr.length > 0) { throw new Error(stderr.toString()); } @@ -122,6 +122,20 @@ const dbSubRefreshTimestamp = () => const dbWrite = (query: string, options?: SpawnSyncOptions) => execAnvilAccessModule(['--query', query, '--mode', 'write'], options); +const getAnvilData = ( + dataStruct: AnvilDataStruct, + { predata, ...spawnSyncOptions }: GetAnvilDataOptions = {}, +) => + execAnvilAccessModule( + [ + '--predata', + JSON.stringify(predata), + '--data', + JSON.stringify(dataStruct), + ], + spawnSyncOptions, + ).stdout; + const getLocalHostUUID = () => execModuleSubroutine('host_uuid', { subModuleName: 'Get', @@ -132,6 +146,7 @@ export { dbQuery, dbSubRefreshTimestamp, dbWrite, + getAnvilData, getLocalHostUUID, execModuleSubroutine as sub, }; diff --git a/striker-ui-api/src/types/AnvilDataStruct.d.ts b/striker-ui-api/src/types/AnvilDataStruct.d.ts new file mode 100644 index 00000000..984875f9 --- /dev/null +++ b/striker-ui-api/src/types/AnvilDataStruct.d.ts @@ -0,0 +1,3 @@ +interface AnvilDataStruct { + [key: string]: AnvilDataStruct | boolean; +} diff --git a/striker-ui-api/src/types/GetAnvilDataOptions.d.ts b/striker-ui-api/src/types/GetAnvilDataOptions.d.ts new file mode 100644 index 00000000..baf39d7a --- /dev/null +++ b/striker-ui-api/src/types/GetAnvilDataOptions.d.ts @@ -0,0 +1,3 @@ +type GetAnvilDataOptions = import('child_process').SpawnSyncOptions & { + predata?: Array<[string, ...unknown[]]>; +};