@toolproof-npm/shared 0.1.93 → 0.1.95
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { WorkStepJson, WhileStepJson, ForStepJson, JobJson } from '@toolproof-npm/schema';
|
|
2
|
+
export declare const makeWorkStepFromJob: (job: JobJson) => Promise<WorkStepJson>;
|
|
3
|
+
export declare const makeLoopStepFromJob: (job: JobJson, lessThanJob: JobJson, kind: "for" | "while") => Promise<ForStepJson | WhileStepJson>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { CONSTANTS } from '@toolproof-npm/shared/constants';
|
|
2
|
+
import { getNewIdentity } from '@toolproof-npm/shared/server';
|
|
3
|
+
// DOC: Helper function to construct an Execution object from a job
|
|
4
|
+
const makeExecutionFromJob = async (job, executionRef) => {
|
|
5
|
+
const execIdentity = executionRef ?? await getNewIdentity(CONSTANTS.TERMINALS.execution);
|
|
6
|
+
const inputBindingMap = {};
|
|
7
|
+
const inputs = job.roles.inputMap;
|
|
8
|
+
await Promise.all(Object.keys(inputs).map(async (resourceRoleRef) => {
|
|
9
|
+
const resourceId = await getNewIdentity(CONSTANTS.TERMINALS.resource);
|
|
10
|
+
inputBindingMap[resourceRoleRef] = resourceId;
|
|
11
|
+
}));
|
|
12
|
+
const outputBindingMap = {};
|
|
13
|
+
const outputs = job.roles.outputMap;
|
|
14
|
+
await Promise.all(Object.keys(outputs).map(async (resourceRoleRef) => {
|
|
15
|
+
const resourceId = await getNewIdentity(CONSTANTS.TERMINALS.resource);
|
|
16
|
+
outputBindingMap[resourceRoleRef] = resourceId;
|
|
17
|
+
}));
|
|
18
|
+
return {
|
|
19
|
+
identity: execIdentity,
|
|
20
|
+
jobRef: job.identity,
|
|
21
|
+
roleBindings: {
|
|
22
|
+
inputBindingMap,
|
|
23
|
+
outputBindingMap
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
// DOC: Helper function to construct a WorkStep object from an jobMetaJson (does not append to statelessStrategy.steps)
|
|
28
|
+
export const makeWorkStepFromJob = async (job) => {
|
|
29
|
+
const workStepIdentity = await getNewIdentity(CONSTANTS.STEPS.work);
|
|
30
|
+
const executionRef = workStepIdentity.replace(CONSTANTS.STEPS.work.toUpperCase(), 'execution'.toUpperCase()); // ATTENTION: use function
|
|
31
|
+
const execution = await makeExecutionFromJob(job, executionRef);
|
|
32
|
+
const newWorkStep = {
|
|
33
|
+
identity: workStepIdentity,
|
|
34
|
+
kind: CONSTANTS.STEPS.work,
|
|
35
|
+
execution
|
|
36
|
+
};
|
|
37
|
+
return newWorkStep;
|
|
38
|
+
};
|
|
39
|
+
// DOC: Helper function to construct a ForStep or WhileStep from a job
|
|
40
|
+
export const makeLoopStepFromJob = async (job, lessThanJob, kind) => {
|
|
41
|
+
// Create the "what" WorkStep from the provided job
|
|
42
|
+
const whatWorkStep = await makeWorkStepFromJob(job);
|
|
43
|
+
// Create the "when" WorkStep from the LessThan job
|
|
44
|
+
const whenWorkStep = await makeWorkStepFromJob(lessThanJob);
|
|
45
|
+
// Generate loop step identity based on kind
|
|
46
|
+
const stepIdentity = (kind === 'for'
|
|
47
|
+
? await getNewIdentity(CONSTANTS.STEPS.for)
|
|
48
|
+
: await getNewIdentity(CONSTANTS.STEPS.while));
|
|
49
|
+
// Assemble the loop step
|
|
50
|
+
return {
|
|
51
|
+
identity: stepIdentity,
|
|
52
|
+
kind,
|
|
53
|
+
case: {
|
|
54
|
+
what: whatWorkStep,
|
|
55
|
+
when: whenWorkStep
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -2,5 +2,6 @@ export * as CONSTANTS from './constants.js';
|
|
|
2
2
|
export * as TYPES from './_lib/types.js';
|
|
3
3
|
export * as UTILS from './_lib/utils/utils.js';
|
|
4
4
|
export * as RESOURCE_CREATION from './_lib/utils/resourceCreation.js';
|
|
5
|
+
export * as MAKE_HELPERS from './_lib/utils/makeHelpers.js';
|
|
5
6
|
export * from './firebaseAdminHelpers.js';
|
|
6
7
|
export * from './firebaseAdminInit.js';
|
package/dist/index.js
CHANGED
|
@@ -2,5 +2,6 @@ export * as CONSTANTS from './constants.js';
|
|
|
2
2
|
export * as TYPES from './_lib/types.js';
|
|
3
3
|
export * as UTILS from './_lib/utils/utils.js';
|
|
4
4
|
export * as RESOURCE_CREATION from './_lib/utils/resourceCreation.js';
|
|
5
|
+
export * as MAKE_HELPERS from './_lib/utils/makeHelpers.js';
|
|
5
6
|
export * from './firebaseAdminHelpers.js';
|
|
6
7
|
export * from './firebaseAdminInit.js';
|