@toolproof-npm/shared 0.1.98 → 0.1.100

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,8 @@
1
+ import type { WorkStepJson, BranchStepJson, WhileStepJson, ForStepJson, JobJson } from '@toolproof-npm/schema';
2
+ export declare const createWorkStepFromJob: (job: JobJson) => Promise<WorkStepJson>;
3
+ export declare const createLoopStepFromJob: (whatJob: JobJson, whenJob: JobJson, kind: "for" | "while") => Promise<ForStepJson | WhileStepJson>;
4
+ export declare const createBranchStepFromJobPairs: (cases: {
5
+ whatJob: JobJson;
6
+ whenJob: JobJson;
7
+ }[]) => Promise<BranchStepJson>;
8
+ export declare const cloneForStep: (forStep: ForStepJson) => Promise<ForStepJson>;
@@ -0,0 +1,126 @@
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 createExecutionFromJob = 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 createWorkStepFromJob = 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 createExecutionFromJob(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 createLoopStepFromJob = async (whatJob, whenJob, kind) => {
41
+ // Create the "what" WorkStep from the provided job
42
+ const whatWorkStep = await createWorkStepFromJob(whatJob);
43
+ // Create the "when" WorkStep from the LessThan job
44
+ const whenWorkStep = await createWorkStepFromJob(whenJob);
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
+ };
59
+ // DOC: Helper function to construct a BranchStep from an array of job pairs
60
+ export const createBranchStepFromJobPairs = async (cases) => {
61
+ // Generate branch step identity
62
+ const branchStepIdentity = await getNewIdentity(CONSTANTS.STEPS.branch);
63
+ // Create WorkSteps for each case (what and when pair)
64
+ const casesWithWorkSteps = await Promise.all(cases.map(async ({ whatJob, whenJob }) => {
65
+ const whatWorkStep = await createWorkStepFromJob(whatJob);
66
+ const whenWorkStep = await createWorkStepFromJob(whenJob);
67
+ return {
68
+ what: whatWorkStep,
69
+ when: whenWorkStep
70
+ };
71
+ }));
72
+ // Assemble the branch step
73
+ return {
74
+ identity: branchStepIdentity,
75
+ kind: CONSTANTS.STEPS.branch,
76
+ cases: casesWithWorkSteps
77
+ };
78
+ };
79
+ // DOC: Helper function to clone a ForStep with new identities for steps and executions, preserving job references and bindings
80
+ export const cloneForStep = async (forStep) => {
81
+ // Generate new ForStep identity
82
+ const newForStepIdentity = await getNewIdentity(CONSTANTS.STEPS.for);
83
+ // Clone the "what" WorkStep
84
+ const originalWhatWorkStep = forStep.case.what;
85
+ const newWhatWorkStepIdentity = await getNewIdentity(CONSTANTS.STEPS.work);
86
+ const newWhatExecutionIdentity = newWhatWorkStepIdentity.replace(CONSTANTS.STEPS.work.toUpperCase(), 'execution'.toUpperCase());
87
+ const newWhatExecution = {
88
+ identity: newWhatExecutionIdentity,
89
+ jobRef: originalWhatWorkStep.execution.jobRef,
90
+ roleBindings: {
91
+ inputBindingMap: { ...originalWhatWorkStep.execution.roleBindings.inputBindingMap },
92
+ outputBindingMap: { ...originalWhatWorkStep.execution.roleBindings.outputBindingMap }
93
+ }
94
+ };
95
+ const newWhatWorkStep = {
96
+ identity: newWhatWorkStepIdentity,
97
+ kind: CONSTANTS.STEPS.work,
98
+ execution: newWhatExecution
99
+ };
100
+ // Clone the "when" WorkStep
101
+ const originalWhenWorkStep = forStep.case.when;
102
+ const newWhenWorkStepIdentity = await getNewIdentity(CONSTANTS.STEPS.work);
103
+ const newWhenExecutionIdentity = newWhenWorkStepIdentity.replace(CONSTANTS.STEPS.work.toUpperCase(), 'execution'.toUpperCase());
104
+ const newWhenExecution = {
105
+ identity: newWhenExecutionIdentity,
106
+ jobRef: originalWhenWorkStep.execution.jobRef,
107
+ roleBindings: {
108
+ inputBindingMap: { ...originalWhenWorkStep.execution.roleBindings.inputBindingMap },
109
+ outputBindingMap: { ...originalWhenWorkStep.execution.roleBindings.outputBindingMap }
110
+ }
111
+ };
112
+ const newWhenWorkStep = {
113
+ identity: newWhenWorkStepIdentity,
114
+ kind: CONSTANTS.STEPS.work,
115
+ execution: newWhenExecution
116
+ };
117
+ // Assemble the cloned ForStep
118
+ return {
119
+ identity: newForStepIdentity,
120
+ kind: CONSTANTS.STEPS.for,
121
+ case: {
122
+ what: newWhatWorkStep,
123
+ when: newWhenWorkStep
124
+ }
125
+ };
126
+ };
package/dist/index.d.ts CHANGED
@@ -2,6 +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
+ export * as STEP_CREATION from './_lib/utils/stepCreation.js';
6
6
  export * from './firebaseAdminHelpers.js';
7
7
  export * from './firebaseAdminInit.js';
package/dist/index.js CHANGED
@@ -2,6 +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
+ export * as STEP_CREATION from './_lib/utils/stepCreation.js';
6
6
  export * from './firebaseAdminHelpers.js';
7
7
  export * from './firebaseAdminInit.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toolproof-npm/shared",
3
- "version": "0.1.98",
3
+ "version": "0.1.100",
4
4
  "description": "Core library utilities for ToolProof",
5
5
  "keywords": [
6
6
  "toolproof",
@@ -1,7 +0,0 @@
1
- import type { WorkStepJson, BranchStepJson, WhileStepJson, ForStepJson, JobJson } from '@toolproof-npm/schema';
2
- export declare const makeWorkStepFromJob: (job: JobJson) => Promise<WorkStepJson>;
3
- export declare const makeLoopStepFromJob: (whatJob: JobJson, whenJob: JobJson, kind: "for" | "while") => Promise<ForStepJson | WhileStepJson>;
4
- export declare const makeBranchStepFromJobPairs: (cases: {
5
- whatJob: JobJson;
6
- whenJob: JobJson;
7
- }[]) => Promise<BranchStepJson>;
@@ -1,78 +0,0 @@
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 (whatJob, whenJob, kind) => {
41
- // Create the "what" WorkStep from the provided job
42
- const whatWorkStep = await makeWorkStepFromJob(whatJob);
43
- // Create the "when" WorkStep from the LessThan job
44
- const whenWorkStep = await makeWorkStepFromJob(whenJob);
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
- };
59
- // DOC: Helper function to construct a BranchStep from an array of job pairs
60
- export const makeBranchStepFromJobPairs = async (cases) => {
61
- // Generate branch step identity
62
- const branchStepIdentity = await getNewIdentity(CONSTANTS.STEPS.branch);
63
- // Create WorkSteps for each case (what and when pair)
64
- const casesWithWorkSteps = await Promise.all(cases.map(async ({ whatJob, whenJob }) => {
65
- const whatWorkStep = await makeWorkStepFromJob(whatJob);
66
- const whenWorkStep = await makeWorkStepFromJob(whenJob);
67
- return {
68
- what: whatWorkStep,
69
- when: whenWorkStep
70
- };
71
- }));
72
- // Assemble the branch step
73
- return {
74
- identity: branchStepIdentity,
75
- kind: CONSTANTS.STEPS.branch,
76
- cases: casesWithWorkSteps
77
- };
78
- };