refactor(striker-ui-api): organize types after complete migrate to access interact

main
Tsu-ba-me 2 years ago
parent d8cc7d9979
commit 82f4bdff04
  1. 12
      striker-ui-api/src/lib/accessModule.ts
  2. 10
      striker-ui-api/src/lib/request_handlers/command/buildHostPowerHandler.ts
  3. 2
      striker-ui-api/src/lib/request_handlers/command/runManifest.ts
  4. 34
      striker-ui-api/src/types/AccessModule.d.ts
  5. 3
      striker-ui-api/src/types/AnvilSyncSharedFunction.d.ts
  6. 0
      striker-ui-api/src/types/BuildGetRequestHandlerFunction.d.ts
  7. 0
      striker-ui-api/src/types/CallFunction.d.ts
  8. 4
      striker-ui-api/src/types/DBInsertOrUpdateFunctionCommon.d.ts
  9. 3
      striker-ui-api/src/types/DBJobAnvilSyncSharedOptions.d.ts
  10. 5
      striker-ui-api/src/types/ExecModuleSubroutineFunction.d.ts
  11. 2
      striker-ui-api/src/types/GetPeerDataFunction.d.ts
  12. 2
      striker-ui-api/src/types/InsertOrUpdateJobFunction.d.ts
  13. 6
      striker-ui-api/src/types/InsertOrUpdateVariableFunction.d.ts
  14. 3
      striker-ui-api/src/types/ModuleSubroutineCommonParams.d.ts

@ -13,10 +13,6 @@ import {
uuid, uuid,
} from './shell'; } from './shell';
type AccessStartOptions = {
args?: readonly string[];
} & SpawnOptions;
class Access extends EventEmitter { class Access extends EventEmitter {
private ps: ChildProcess; private ps: ChildProcess;
private queue: string[] = []; private queue: string[] = [];
@ -184,7 +180,7 @@ const insertOrUpdateJob = async ({
job_progress = 0, job_progress = 0,
line = 0, line = 0,
...rest ...rest
}: DBJobParams) => { }: JobParams) => {
const [uuid]: [string] = await subroutine('insert_or_update_jobs', { const [uuid]: [string] = await subroutine('insert_or_update_jobs', {
params: [{ job_progress, line, ...rest }], params: [{ job_progress, line, ...rest }],
}); });
@ -192,7 +188,7 @@ const insertOrUpdateJob = async ({
return uuid; return uuid;
}; };
const insertOrUpdateVariable: DBInsertOrUpdateVariableFunction = async ( const insertOrUpdateVariable: InsertOrUpdateVariableFunction = async (
params, params,
) => { ) => {
const [uuid]: [string] = await subroutine('insert_or_update_variables', { const [uuid]: [string] = await subroutine('insert_or_update_variables', {
@ -207,9 +203,9 @@ const anvilSyncShared = (
jobData: string, jobData: string,
jobTitle: string, jobTitle: string,
jobDescription: string, jobDescription: string,
{ jobHostUUID }: DBJobAnvilSyncSharedOptions = { jobHostUUID: undefined }, { jobHostUUID }: JobAnvilSyncSharedOptions = { jobHostUUID: undefined },
) => { ) => {
const subParams: DBJobParams = { const subParams: JobParams = {
file: __filename, file: __filename,
job_command: SERVER_PATHS.usr.sbin['anvil-sync-shared'].self, job_command: SERVER_PATHS.usr.sbin['anvil-sync-shared'].self,
job_data: jobData, job_data: jobData,

@ -5,14 +5,14 @@ import SERVER_PATHS from '../../consts/SERVER_PATHS';
import { job } from '../../accessModule'; import { job } from '../../accessModule';
import { stderr } from '../../shell'; import { stderr } from '../../shell';
type DistinctDBJobParams = Omit< type DistinctJobParams = Omit<
DBJobParams, JobParams,
'file' | 'line' | 'job_data' | 'job_progress' 'file' | 'line' | 'job_data' | 'job_progress'
>; >;
const MANAGE_HOST_POWER_JOB_PARAMS: { const MANAGE_HOST_POWER_JOB_PARAMS: {
poweroff: DistinctDBJobParams; poweroff: DistinctJobParams;
reboot: DistinctDBJobParams; reboot: DistinctJobParams;
} = { } = {
poweroff: { poweroff: {
job_command: `${SERVER_PATHS.usr.sbin['anvil-manage-power'].self} --poweroff -y`, job_command: `${SERVER_PATHS.usr.sbin['anvil-manage-power'].self} --poweroff -y`,
@ -33,7 +33,7 @@ export const buildHostPowerHandler: (
) => RequestHandler = ) => RequestHandler =
(task = 'reboot') => (task = 'reboot') =>
async (request, response) => { async (request, response) => {
const subParams: DBJobParams = { const subParams: JobParams = {
file: __filename, file: __filename,
...MANAGE_HOST_POWER_JOB_PARAMS[task], ...MANAGE_HOST_POWER_JOB_PARAMS[task],

@ -114,7 +114,7 @@ export const runManifest: RequestHandler<
} = rawManifestListData; } = rawManifestListData;
const { hosts: { by_uuid: mapToHostNameData = {} } = {} } = rawSysData; const { hosts: { by_uuid: mapToHostNameData = {} } = {} } = rawSysData;
const joinAnJobs: DBJobParams[] = []; const joinAnJobs: JobParams[] = [];
let anParams: Record<string, string>; let anParams: Record<string, string>;

@ -1,30 +1,12 @@
type AsyncAnvilAccessModuleCloseArgs = { type AccessStartOptions = {
ecode: number | null; args?: readonly string[];
signal: NodeJS.Signals | null; } & import('child_process').SpawnOptions;
stderr: string;
stdout: unknown;
};
type AsyncDatabaseWriteCloseArgs = AsyncAnvilAccessModuleCloseArgs & {
wcode: number | null;
};
type AsyncAnvilAccessModuleCloseHandler = (
args: AsyncAnvilAccessModuleCloseArgs,
) => void;
type AsyncDatabaseWriteCloseHandler = (
args: AsyncDatabaseWriteCloseArgs,
) => void;
type AsyncAnvilAccessModuleOptions = import('child_process').SpawnOptions & { type SubroutineCommonParams = {
onClose?: AsyncAnvilAccessModuleCloseHandler; debug?: number;
onError?: (err: Error) => void;
}; };
type AsyncDatabaseWriteOptions = Omit< type InsertOrUpdateFunctionCommonParams = SubroutineCommonParams & {
AsyncAnvilAccessModuleOptions, file: string;
'onClose' line?: number;
> & {
onClose?: AsyncDatabaseWriteCloseHandler;
}; };

@ -0,0 +1,3 @@
type JobAnvilSyncSharedOptions = {
jobHostUUID?: string;
};

@ -1,4 +0,0 @@
type DBInsertOrUpdateFunctionCommonParams = ModuleSubroutineCommonParams & {
file: string;
line?: number;
};

@ -1,3 +0,0 @@
type DBJobAnvilSyncSharedOptions = {
jobHostUUID?: string;
};

@ -1,5 +0,0 @@
type ExecModuleSubroutineOptions = {
spawnSyncOptions?: import('child_process').SpawnSyncOptions;
subModuleName?: string;
subParams?: Record<string, unknown>;
};

@ -6,7 +6,7 @@ type PeerDataHash = {
os_registered: string; os_registered: string;
}; };
type GetPeerDataOptions = ModuleSubroutineCommonParams & { type GetPeerDataOptions = SubroutineCommonParams & {
password?: string; password?: string;
port?: number; port?: number;
}; };

@ -1,4 +1,4 @@
type DBJobParams = DBInsertOrUpdateFunctionCommonParams & { type JobParams = InsertOrUpdateFunctionCommonParams & {
job_command: string; job_command: string;
job_data?: string; job_data?: string;
job_name: string; job_name: string;

@ -1,4 +1,4 @@
type DBVariableParams = DBInsertOrUpdateFunctionCommonParams & { type VariableParams = InsertOrUpdateFunctionCommonParams & {
update_value_only?: 0 | 1; update_value_only?: 0 | 1;
variable_default?: string; variable_default?: string;
varaible_description?: string; varaible_description?: string;
@ -10,6 +10,6 @@ type DBVariableParams = DBInsertOrUpdateFunctionCommonParams & {
variable_value?: number | string; variable_value?: number | string;
}; };
type DBInsertOrUpdateVariableFunction = ( type InsertOrUpdateVariableFunction = (
params: DBVariableParams, params: VariableParams,
) => Promise<string>; ) => Promise<string>;

@ -1,3 +0,0 @@
type ModuleSubroutineCommonParams = {
debug?: number;
};
Loading…
Cancel
Save