@toolproof-core/lib 1.0.14 → 1.0.16
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.
- package/dist/artifacts/artifacts.d.ts +3 -3
- package/dist/integrations/firebase/createRunnableStrategy.d.ts +3 -0
- package/dist/integrations/firebase/createRunnableStrategy.d.ts.map +1 -0
- package/dist/integrations/firebase/createRunnableStrategy.js +10 -0
- package/dist/integrations/firebase/createRunnableStrategy.js.map +1 -0
- package/dist/integrations/firebase/createStep.d.ts +11 -0
- package/dist/integrations/firebase/createStep.d.ts.map +1 -0
- package/dist/integrations/firebase/createStep.js +43 -0
- package/dist/integrations/firebase/createStep.js.map +1 -0
- package/dist/integrations/firebase/firebaseAdminHelpers.d.ts +6 -0
- package/dist/integrations/firebase/firebaseAdminHelpers.d.ts.map +1 -0
- package/dist/integrations/firebase/firebaseAdminHelpers.js +154 -0
- package/dist/integrations/firebase/firebaseAdminHelpers.js.map +1 -0
- package/dist/integrations/firebase/firebaseAdminInit.d.ts +4 -0
- package/dist/integrations/firebase/firebaseAdminInit.d.ts.map +1 -0
- package/{src/_lib/setup/firebaseAdminInit.ts → dist/integrations/firebase/firebaseAdminInit.js} +33 -38
- package/dist/integrations/firebase/firebaseAdminInit.js.map +1 -0
- package/dist/utils/creation/resourceCreation.d.ts +9 -0
- package/dist/utils/creation/resourceCreation.d.ts.map +1 -0
- package/dist/utils/creation/resourceCreation.js +62 -0
- package/dist/utils/creation/resourceCreation.js.map +1 -0
- package/dist/utils/creation/runnableStrategyCreation.d.ts +4 -0
- package/dist/utils/creation/runnableStrategyCreation.d.ts.map +1 -0
- package/dist/utils/creation/runnableStrategyCreation.js +27 -0
- package/dist/utils/creation/runnableStrategyCreation.js.map +1 -0
- package/dist/utils/creation/stepCreation.d.ts +34 -0
- package/dist/utils/creation/stepCreation.d.ts.map +1 -0
- package/dist/utils/creation/stepCreation.js +89 -0
- package/dist/utils/creation/stepCreation.js.map +1 -0
- package/dist/utils/extractData.js +3 -3
- package/dist/utils/extractData.js.map +1 -1
- package/package.json +12 -12
- package/src/integrations/firebase/createRunnableStrategy.ts +20 -0
- package/src/integrations/firebase/createStep.ts +71 -0
- package/src/{firebase → integrations/firebase}/firebaseAdminHelpers.ts +87 -49
- package/src/integrations/firebase/firebaseAdminInit.ts +39 -0
- package/src/utils/{createResource.ts → creation/resourceCreation.ts} +9 -11
- package/src/utils/creation/runnableStrategyCreation.ts +46 -0
- package/src/utils/creation/stepCreation.ts +159 -0
- package/src/utils/extractData.ts +3 -3
- package/tsconfig.tsbuildinfo +1 -1
- package/src/utils/createRunnableStrategy.ts +0 -31
- package/src/utils/createStep.ts +0 -111
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { CONSTANTS } from '../../artifacts/artifacts.js';
|
|
2
|
+
function assertNonEmpty(arr, msg) {
|
|
3
|
+
if (arr.length === 0) {
|
|
4
|
+
throw new Error(msg);
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
function getRoleBindings(job) {
|
|
8
|
+
return {
|
|
9
|
+
inputBindings: Object.keys(job.roles.inputRoleValuesByIdentity),
|
|
10
|
+
outputBindings: Object.keys(job.roles.outputRoleValuesByIdentity),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export function buildJobStepFromJob(job, identity) {
|
|
14
|
+
return {
|
|
15
|
+
identity,
|
|
16
|
+
stepKind: CONSTANTS.Enums.StepKind.job,
|
|
17
|
+
jobHandle: job.identity,
|
|
18
|
+
roleBindings: getRoleBindings(job),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export function buildLoopStepFromJobPair(whatJob, whenJob, identities) {
|
|
22
|
+
const what = buildJobStepFromJob(whatJob, identities.whatIdentity);
|
|
23
|
+
const when = buildJobStepFromJob(whenJob, identities.whenIdentity);
|
|
24
|
+
if (identities.stepKind === CONSTANTS.Enums.StepKind.for) {
|
|
25
|
+
return {
|
|
26
|
+
identity: identities.stepIdentity,
|
|
27
|
+
stepKind: CONSTANTS.Enums.StepKind.for,
|
|
28
|
+
case: { what, when },
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
identity: identities.stepIdentity,
|
|
33
|
+
stepKind: CONSTANTS.Enums.StepKind.while,
|
|
34
|
+
case: { what, when },
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export function buildBranchStepFromJobPairs(cases, branchIdentity, caseIdentities) {
|
|
38
|
+
if (cases.length !== caseIdentities.length) {
|
|
39
|
+
throw new Error('buildBranchStepFromJobPairs requires one identity pair per case');
|
|
40
|
+
}
|
|
41
|
+
const resolved = cases.map(({ whatJob, whenJob }, index) => {
|
|
42
|
+
const identities = caseIdentities[index];
|
|
43
|
+
if (!identities) {
|
|
44
|
+
throw new Error(`Missing case identities for case index ${index}`);
|
|
45
|
+
}
|
|
46
|
+
const what = buildJobStepFromJob(whatJob, identities.whatIdentity);
|
|
47
|
+
const when = buildJobStepFromJob(whenJob, identities.whenIdentity);
|
|
48
|
+
return { what, when };
|
|
49
|
+
});
|
|
50
|
+
assertNonEmpty(resolved, 'buildBranchStepFromJobPairs requires at least one case');
|
|
51
|
+
return {
|
|
52
|
+
identity: branchIdentity,
|
|
53
|
+
stepKind: CONSTANTS.Enums.StepKind.branch,
|
|
54
|
+
cases: resolved,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export function cloneForStepWithIdentities(forStep, identities) {
|
|
58
|
+
return {
|
|
59
|
+
identity: identities.stepIdentity,
|
|
60
|
+
stepKind: CONSTANTS.Enums.StepKind.for,
|
|
61
|
+
case: {
|
|
62
|
+
what: {
|
|
63
|
+
...forStep.case.what,
|
|
64
|
+
identity: identities.whatIdentity,
|
|
65
|
+
},
|
|
66
|
+
when: {
|
|
67
|
+
...forStep.case.when,
|
|
68
|
+
identity: identities.whenIdentity,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export function cloneWhileStepWithIdentities(whileStep, identities) {
|
|
74
|
+
return {
|
|
75
|
+
identity: identities.stepIdentity,
|
|
76
|
+
stepKind: CONSTANTS.Enums.StepKind.while,
|
|
77
|
+
case: {
|
|
78
|
+
what: {
|
|
79
|
+
...whileStep.case.what,
|
|
80
|
+
identity: identities.whatIdentity,
|
|
81
|
+
},
|
|
82
|
+
when: {
|
|
83
|
+
...whileStep.case.when,
|
|
84
|
+
identity: identities.whenIdentity,
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=stepCreation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stepCreation.js","sourceRoot":"","sources":["../../../src/utils/creation/stepCreation.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAqBzD,SAAS,cAAc,CAAI,GAAQ,EAAE,GAAW;IAC5C,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;AACL,CAAC;AAED,SAAS,eAAe,CAAC,GAAY;IACjC,OAAO;QACH,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,yBAAyB,CAA+B;QAC7F,cAAc,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,0BAA0B,CAA+B;KAClG,CAAC;AACN,CAAC;AAED,MAAM,UAAU,mBAAmB,CAC/B,GAAY,EACZ,QAA6B;IAE7B,OAAO;QACH,QAAQ;QACR,QAAQ,EAAE,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG;QACtC,SAAS,EAAE,GAAG,CAAC,QAAQ;QACvB,YAAY,EAAE,eAAe,CAAC,GAAG,CAAC;KACrC,CAAC;AACN,CAAC;AAED,MAAM,UAAU,wBAAwB,CACpC,OAAgB,EAChB,OAAgB,EAChB,UAAmC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!job)
|
|
56
56
|
continue;
|
|
57
|
-
for (const [rid, role] of Object.entries(job.roles.
|
|
57
|
+
for (const [rid, role] of Object.entries(job.roles.inputRoleValuesByIdentity)) {
|
|
58
58
|
roleMap.set(rid, {
|
|
59
59
|
identity: rid,
|
|
60
60
|
...role,
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
|
-
for (const [rid, role] of Object.entries(job.roles.
|
|
63
|
+
for (const [rid, role] of Object.entries(job.roles.outputRoleValuesByIdentity)) {
|
|
64
64
|
roleMap.set(rid, {
|
|
65
65
|
identity: rid,
|
|
66
66
|
...role,
|
|
@@ -71,7 +71,7 @@ export function extractRoleMapFromRawStrategy(rawStrategy, jobMap) {
|
|
|
71
71
|
}
|
|
72
72
|
export function extractSingleNonErrorOutputTypeHandle(job) {
|
|
73
73
|
const errorRoleId = CONSTANTS.Cosmos.ROLE_ErrorOutput;
|
|
74
|
-
const outputEntries = Object.entries(job.roles.
|
|
74
|
+
const outputEntries = Object.entries(job.roles.outputRoleValuesByIdentity).filter(([roleId]) => roleId !== errorRoleId);
|
|
75
75
|
if (!outputEntries || !outputEntries[0] || outputEntries.length !== 1) {
|
|
76
76
|
throw new Error(`Job ${job.identity} must have exactly one non-error output role to be branchable/loopable`);
|
|
77
77
|
} // ATTENTION_PUREIFY
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractData.js","sourceRoot":"","sources":["../../src/utils/extractData.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAGtD,MAAM,UAAU,gCAAgC,CAAC,WAA4B;IACzE,MAAM,QAAQ,GAAG,8BAA8B,CAAC,WAAW,CAAC,CAAC;IAC7D,MAAM,GAAG,GAAG,IAAI,GAAG,EAAmB,CAAC;IACvC,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;QAC3B,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAC7B,CAAC;IACD,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AAI,KAAK,SAAS,EAAE,CAAC;YACtC,SAAS;QACb,CAAC;QACD,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC3B,SAAS;QACb,CAAC;QAED,MAAM,aAAa,GAAI,IAAY,CAAC,QAAmB,CAAC;QACxD,IAAI,aAAa,KAAK,IAAI,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC;YACxD,SAAS;QACb,CAAC;QAED,MAAM,KAAK,GAAG,IAAgB,CAAC;QAC/B,MAAM,GAAG,GAAG,MAAM,CAAC,aAAa,CAAS,CAAC;QAE1C,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACxB,CAAC;IAED,OAAO,GAAG,CAAC;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toolproof-core/lib",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.16",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [],
|
|
@@ -20,16 +20,16 @@
|
|
|
20
20
|
"import": "./dist/utils/extractData.js"
|
|
21
21
|
},
|
|
22
22
|
"./create-resource": {
|
|
23
|
-
"types": "./dist/utils/
|
|
24
|
-
"import": "./dist/utils/
|
|
23
|
+
"types": "./dist/utils/creation/resourceCreation.d.ts",
|
|
24
|
+
"import": "./dist/utils/creation/resourceCreation.js"
|
|
25
25
|
},
|
|
26
26
|
"./create-step": {
|
|
27
|
-
"types": "./dist/
|
|
28
|
-
"import": "./dist/
|
|
27
|
+
"types": "./dist/integrations/firebase/createStep.d.ts",
|
|
28
|
+
"import": "./dist/integrations/firebase/createStep.js"
|
|
29
29
|
},
|
|
30
30
|
"./create-runnable-strategy": {
|
|
31
|
-
"types": "./dist/
|
|
32
|
-
"import": "./dist/
|
|
31
|
+
"types": "./dist/integrations/firebase/createRunnableStrategy.d.ts",
|
|
32
|
+
"import": "./dist/integrations/firebase/createRunnableStrategy.js"
|
|
33
33
|
},
|
|
34
34
|
"./resolve-resource-chain": {
|
|
35
35
|
"types": "./dist/utils/resolveResourceChain.d.ts",
|
|
@@ -40,19 +40,19 @@
|
|
|
40
40
|
"import": "./dist/utils/bindInputRoleToResource.js"
|
|
41
41
|
},
|
|
42
42
|
"./firebase-admin-init": {
|
|
43
|
-
"types": "./dist/
|
|
44
|
-
"import": "./dist/
|
|
43
|
+
"types": "./dist/integrations/firebase/firebaseAdminInit.d.ts",
|
|
44
|
+
"import": "./dist/integrations/firebase/firebaseAdminInit.js"
|
|
45
45
|
},
|
|
46
46
|
"./firebase-admin-helpers": {
|
|
47
|
-
"types": "./dist/firebase/firebaseAdminHelpers.d.ts",
|
|
48
|
-
"import": "./dist/firebase/firebaseAdminHelpers.js"
|
|
47
|
+
"types": "./dist/integrations/firebase/firebaseAdminHelpers.d.ts",
|
|
48
|
+
"import": "./dist/integrations/firebase/firebaseAdminHelpers.js"
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/node": "^22.0.0"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@toolproof-core/schema": "^1.0.
|
|
55
|
+
"@toolproof-core/schema": "^1.0.24",
|
|
56
56
|
"firebase-admin": "^13.7.0"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { RawStrategyJson, RunnableStrategyJson } from '@toolproof-core/schema';
|
|
2
|
+
import { CONSTANTS } from '../../artifacts/artifacts.js';
|
|
3
|
+
import {
|
|
4
|
+
buildRunnableStrategy,
|
|
5
|
+
getRunnableStrategyThreadGroups,
|
|
6
|
+
} from '../../utils/creation/runnableStrategyCreation.js';
|
|
7
|
+
import { getNewIdentity } from './firebaseAdminHelpers.js';
|
|
8
|
+
|
|
9
|
+
export function createRunnableStrategy(rawStrategy: RawStrategyJson): RunnableStrategyJson {
|
|
10
|
+
const threadStepGroups = getRunnableStrategyThreadGroups(rawStrategy);
|
|
11
|
+
const runnableStrategyIdentity = getNewIdentity(CONSTANTS.Names.RunnableStrategyIdentity);
|
|
12
|
+
const threadIdentities = threadStepGroups.map(() => getNewIdentity(CONSTANTS.Names.StrategyThreadIdentity));
|
|
13
|
+
|
|
14
|
+
return buildRunnableStrategy(
|
|
15
|
+
rawStrategy,
|
|
16
|
+
runnableStrategyIdentity,
|
|
17
|
+
threadStepGroups,
|
|
18
|
+
threadIdentities,
|
|
19
|
+
);
|
|
20
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BranchStepJson,
|
|
3
|
+
ForStepJson,
|
|
4
|
+
JobJson,
|
|
5
|
+
JobStepJson,
|
|
6
|
+
WhileStepJson,
|
|
7
|
+
} from '@toolproof-core/schema';
|
|
8
|
+
import { CONSTANTS } from '../../artifacts/artifacts.js';
|
|
9
|
+
import {
|
|
10
|
+
buildBranchStepFromJobPairs,
|
|
11
|
+
buildJobStepFromJob,
|
|
12
|
+
buildLoopStepFromJobPair,
|
|
13
|
+
cloneForStepWithIdentities,
|
|
14
|
+
cloneWhileStepWithIdentities,
|
|
15
|
+
} from '../../utils/creation/stepCreation.js';
|
|
16
|
+
import { getNewStepIdentity } from './firebaseAdminHelpers.js';
|
|
17
|
+
|
|
18
|
+
export function createJobStepFromJob(job: JobJson): JobStepJson {
|
|
19
|
+
return buildJobStepFromJob(job, getNewStepIdentity(CONSTANTS.Enums.StepKind.job));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function createLoopStepFromJobPair(
|
|
23
|
+
whatJob: JobJson,
|
|
24
|
+
whenJob: JobJson,
|
|
25
|
+
stepKind: typeof CONSTANTS.Enums.StepKind.for | typeof CONSTANTS.Enums.StepKind.while,
|
|
26
|
+
): ForStepJson | WhileStepJson {
|
|
27
|
+
if (stepKind === CONSTANTS.Enums.StepKind.for) {
|
|
28
|
+
return buildLoopStepFromJobPair(whatJob, whenJob, {
|
|
29
|
+
stepKind,
|
|
30
|
+
stepIdentity: getNewStepIdentity(CONSTANTS.Enums.StepKind.for),
|
|
31
|
+
whatIdentity: getNewStepIdentity(CONSTANTS.Enums.StepKind.job),
|
|
32
|
+
whenIdentity: getNewStepIdentity(CONSTANTS.Enums.StepKind.job),
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return buildLoopStepFromJobPair(whatJob, whenJob, {
|
|
37
|
+
stepKind,
|
|
38
|
+
stepIdentity: getNewStepIdentity(CONSTANTS.Enums.StepKind.while),
|
|
39
|
+
whatIdentity: getNewStepIdentity(CONSTANTS.Enums.StepKind.job),
|
|
40
|
+
whenIdentity: getNewStepIdentity(CONSTANTS.Enums.StepKind.job),
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function createBranchStepFromJobPairs(
|
|
45
|
+
cases: Array<{ whatJob: JobJson; whenJob: JobJson }>,
|
|
46
|
+
): BranchStepJson {
|
|
47
|
+
return buildBranchStepFromJobPairs(
|
|
48
|
+
cases,
|
|
49
|
+
getNewStepIdentity(CONSTANTS.Enums.StepKind.branch),
|
|
50
|
+
cases.map(() => ({
|
|
51
|
+
whatIdentity: getNewStepIdentity(CONSTANTS.Enums.StepKind.job),
|
|
52
|
+
whenIdentity: getNewStepIdentity(CONSTANTS.Enums.StepKind.job),
|
|
53
|
+
})),
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function cloneForStep(forStep: ForStepJson): ForStepJson {
|
|
58
|
+
return cloneForStepWithIdentities(forStep, {
|
|
59
|
+
stepIdentity: getNewStepIdentity(CONSTANTS.Enums.StepKind.for),
|
|
60
|
+
whatIdentity: getNewStepIdentity(CONSTANTS.Enums.StepKind.job),
|
|
61
|
+
whenIdentity: getNewStepIdentity(CONSTANTS.Enums.StepKind.job),
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function cloneWhileStep(whileStep: WhileStepJson): WhileStepJson {
|
|
66
|
+
return cloneWhileStepWithIdentities(whileStep, {
|
|
67
|
+
stepIdentity: getNewStepIdentity(CONSTANTS.Enums.StepKind.while),
|
|
68
|
+
whatIdentity: getNewStepIdentity(CONSTANTS.Enums.StepKind.job),
|
|
69
|
+
whenIdentity: getNewStepIdentity(CONSTANTS.Enums.StepKind.job),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
@@ -3,14 +3,20 @@ import type {
|
|
|
3
3
|
ResourceTypeIdentityJson,
|
|
4
4
|
StepKindJson,
|
|
5
5
|
} from '@toolproof-core/schema';
|
|
6
|
-
import type {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
import type {
|
|
7
|
+
IdentityName,
|
|
8
|
+
IdentityStringByIdentityName,
|
|
9
|
+
ResourcesByTypeDict,
|
|
10
|
+
StepIdentityStringByStepKind,
|
|
11
|
+
} from '../../types/types.js';
|
|
12
|
+
import { CONSTANTS, MAPPINGS } from '../../artifacts/artifacts.js';
|
|
13
|
+
import { dbAdmin, storageAdmin } from './firebaseAdminInit.js';
|
|
11
14
|
|
|
12
15
|
function capitalizeFirst(value: string): string {
|
|
13
|
-
if (!value)
|
|
16
|
+
if (!value) {
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
|
|
14
20
|
return value.charAt(0).toUpperCase() + value.slice(1);
|
|
15
21
|
}
|
|
16
22
|
|
|
@@ -21,35 +27,43 @@ export function getNewIdentity<K extends IdentityName>(identityName: K): Identit
|
|
|
21
27
|
.doc(identityName)
|
|
22
28
|
.collection(CONSTANTS.Persistence.Collections.members)
|
|
23
29
|
.doc();
|
|
30
|
+
|
|
24
31
|
return (prefix + docRef.id) as IdentityStringByIdentityName<K>;
|
|
25
32
|
}
|
|
26
33
|
|
|
27
34
|
export function getNewStepIdentity<K extends StepKindJson>(stepKind: K): StepIdentityStringByStepKind<K> {
|
|
28
35
|
const identityName = `${capitalizeFirst(stepKind)}StepIdentity` as IdentityName;
|
|
36
|
+
|
|
29
37
|
if (!(identityName in MAPPINGS.IdentityNameToIdentityPrefix)) {
|
|
30
38
|
throw new Error(`No IdentityNameToIdentityPrefix entry for derived step identity name: ${identityName}`);
|
|
31
39
|
}
|
|
40
|
+
|
|
32
41
|
return getNewIdentity(identityName) as StepIdentityStringByStepKind<K>;
|
|
33
42
|
}
|
|
34
43
|
|
|
35
44
|
export async function listResources(
|
|
36
|
-
resourceTypeHandles: ResourceTypeIdentityJson[]
|
|
45
|
+
resourceTypeHandles: ResourceTypeIdentityJson[],
|
|
37
46
|
): Promise<ResourcesByTypeDict> {
|
|
38
|
-
const
|
|
39
|
-
const
|
|
47
|
+
const bucketResources = storageAdmin.bucket(CONSTANTS.Persistence.Buckets.tp_resources);
|
|
48
|
+
const bucketStrategies = storageAdmin.bucket(CONSTANTS.Persistence.Buckets.tp_strategies);
|
|
40
49
|
|
|
41
|
-
async function fetchFilesUnder(
|
|
50
|
+
async function fetchFilesUnder(
|
|
51
|
+
resourceTypeHandle: ResourceTypeIdentityJson,
|
|
52
|
+
): Promise<Array<{ data: unknown; meta: any; name: string }>> {
|
|
42
53
|
const bucket = resourceTypeHandle === CONSTANTS.Cosmos.TYPE_RunnableStrategy
|
|
43
|
-
?
|
|
44
|
-
:
|
|
54
|
+
? bucketStrategies
|
|
55
|
+
: bucketResources;
|
|
45
56
|
const prefix = `${resourceTypeHandle}/`;
|
|
46
57
|
const [found] = await bucket.getFiles({ prefix });
|
|
47
|
-
const files = found.filter(
|
|
48
|
-
const name =
|
|
49
|
-
|
|
50
|
-
return true;
|
|
58
|
+
const files = found.filter((file) => {
|
|
59
|
+
const name = file.name || '';
|
|
60
|
+
return !!name && !name.endsWith('/');
|
|
51
61
|
});
|
|
52
|
-
|
|
62
|
+
|
|
63
|
+
if (!files.length) {
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
|
|
53
67
|
const items = await Promise.all(files.map(async (file) => {
|
|
54
68
|
try {
|
|
55
69
|
const [buf] = await file.download();
|
|
@@ -60,6 +74,7 @@ export async function listResources(
|
|
|
60
74
|
return null as unknown as { data: unknown; meta: any; name: string };
|
|
61
75
|
}
|
|
62
76
|
}));
|
|
77
|
+
|
|
63
78
|
return items.filter(Boolean) as Array<{ data: unknown; meta: any; name: string }>;
|
|
64
79
|
}
|
|
65
80
|
|
|
@@ -68,47 +83,70 @@ export async function listResources(
|
|
|
68
83
|
const rows = await fetchFilesUnder(resourceTypeHandle);
|
|
69
84
|
const items: ResourceJson[] = rows.map(({ data, meta, name }) => {
|
|
70
85
|
const flat = meta?.metadata ?? {};
|
|
71
|
-
// Reconstruct nested object from flattened keys (dot and array index notation)
|
|
72
86
|
const root: any = {};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
87
|
+
|
|
88
|
+
for (const [key, valueRaw] of Object.entries(flat)) {
|
|
89
|
+
if (typeof valueRaw !== 'string') {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const valueString = valueRaw.trim();
|
|
94
|
+
let value: any = valueString;
|
|
95
|
+
|
|
96
|
+
if ((valueString.startsWith('{') && valueString.endsWith('}')) || (valueString.startsWith('[') && valueString.endsWith(']'))) {
|
|
97
|
+
try {
|
|
98
|
+
value = JSON.parse(valueString);
|
|
99
|
+
} catch {
|
|
100
|
+
value = valueString;
|
|
101
|
+
}
|
|
80
102
|
}
|
|
81
|
-
|
|
82
|
-
const segments =
|
|
103
|
+
|
|
104
|
+
const segments = key.split('.');
|
|
83
105
|
let cursor = root;
|
|
84
|
-
|
|
85
|
-
|
|
106
|
+
|
|
107
|
+
for (const [index, segment] of segments.entries()) {
|
|
108
|
+
const arrIdxMatch = segment.match(/^(.*)\[(\d+)\]$/);
|
|
109
|
+
|
|
86
110
|
if (arrIdxMatch) {
|
|
87
111
|
const base = arrIdxMatch[1];
|
|
88
112
|
const idxStr = arrIdxMatch[2];
|
|
89
|
-
|
|
113
|
+
|
|
114
|
+
if (base === undefined || idxStr === undefined) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
|
|
90
118
|
const idx = parseInt(idxStr, 10);
|
|
91
|
-
|
|
92
|
-
if (!Array.isArray(cursor[base]))
|
|
93
|
-
|
|
94
|
-
|
|
119
|
+
|
|
120
|
+
if (!cursor[base] || !Array.isArray(cursor[base])) {
|
|
121
|
+
cursor[base] = [];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
while (cursor[base].length <= idx) {
|
|
125
|
+
cursor[base].push(undefined);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (index === segments.length - 1) {
|
|
95
129
|
cursor[base][idx] = value;
|
|
96
130
|
} else {
|
|
97
|
-
if (!cursor[base][idx])
|
|
131
|
+
if (!cursor[base][idx]) {
|
|
132
|
+
cursor[base][idx] = {};
|
|
133
|
+
}
|
|
98
134
|
cursor = cursor[base][idx];
|
|
99
135
|
}
|
|
100
136
|
} else {
|
|
101
|
-
if (
|
|
102
|
-
cursor[
|
|
137
|
+
if (index === segments.length - 1) {
|
|
138
|
+
cursor[segment] = value;
|
|
103
139
|
} else {
|
|
104
|
-
if (!cursor[
|
|
105
|
-
|
|
140
|
+
if (!cursor[segment] || typeof cursor[segment] !== 'object') {
|
|
141
|
+
cursor[segment] = {};
|
|
142
|
+
}
|
|
143
|
+
cursor = cursor[segment];
|
|
106
144
|
}
|
|
107
145
|
}
|
|
108
146
|
}
|
|
109
147
|
}
|
|
148
|
+
|
|
110
149
|
const identity = root.identity;
|
|
111
|
-
// const resourceTypeHandle = root.resourceTypeHandle; // we already have this
|
|
112
150
|
const resourceRoleHandle = root.creationContext.resourceRoleHandle;
|
|
113
151
|
const jobStepHandle = root.creationContext.jobStepHandle;
|
|
114
152
|
const resourceShellKind = root.resourceShellKind;
|
|
@@ -116,7 +154,7 @@ export async function listResources(
|
|
|
116
154
|
const version = typeof versionRaw === 'number'
|
|
117
155
|
? versionRaw
|
|
118
156
|
: parseInt(String(versionRaw ?? ''), 10);
|
|
119
|
-
const
|
|
157
|
+
const resourcePath = root.path;
|
|
120
158
|
const timestamp = root.timestamp;
|
|
121
159
|
|
|
122
160
|
const missing = [
|
|
@@ -126,11 +164,11 @@ export async function listResources(
|
|
|
126
164
|
['resourceShellKind', resourceShellKind],
|
|
127
165
|
['version', Number.isFinite(version) ? String(version) : ''],
|
|
128
166
|
['timestamp', timestamp],
|
|
129
|
-
['path',
|
|
130
|
-
].filter(([_,
|
|
167
|
+
['path', resourcePath],
|
|
168
|
+
].filter(([_, value]) => typeof value !== 'string' || (value as string).length === 0) as Array<[string, string | undefined]>;
|
|
131
169
|
|
|
132
170
|
if (missing.length) {
|
|
133
|
-
const keys = missing.map(([
|
|
171
|
+
const keys = missing.map(([key]) => key).join(', ');
|
|
134
172
|
throw new Error(`Missing required metadata keys [${keys}] for resource file: ${name}`);
|
|
135
173
|
}
|
|
136
174
|
|
|
@@ -144,14 +182,14 @@ export async function listResources(
|
|
|
144
182
|
resourceShellKind,
|
|
145
183
|
version,
|
|
146
184
|
timestamp: timestamp as string,
|
|
147
|
-
path:
|
|
185
|
+
path: resourcePath as string,
|
|
148
186
|
nucleus: data as any,
|
|
149
187
|
} as unknown as ResourceJson;
|
|
150
188
|
});
|
|
189
|
+
|
|
151
190
|
return [resourceTypeHandle, items] as const;
|
|
152
|
-
})
|
|
191
|
+
}),
|
|
153
192
|
);
|
|
154
|
-
return Object.fromEntries(entries) as ResourcesByTypeDict;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
193
|
|
|
194
|
+
return Object.fromEntries(entries) as ResourcesByTypeDict;
|
|
195
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { getApp, getApps, initializeApp, applicationDefault, cert } from 'firebase-admin/app';
|
|
2
|
+
import { getFirestore } from 'firebase-admin/firestore';
|
|
3
|
+
import { getStorage } from 'firebase-admin/storage';
|
|
4
|
+
import { existsSync, readFileSync } from 'fs';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
|
|
7
|
+
function resolveCredential() {
|
|
8
|
+
const jsonString = process.env.GOOGLE_APPLICATION_CREDENTIALS_JSON;
|
|
9
|
+
const envPath = process.env.GOOGLE_APPLICATION_CREDENTIALS;
|
|
10
|
+
const localKeyPath = path.join(process.cwd(), 'gcp-key.json');
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
if (jsonString) {
|
|
14
|
+
return cert(JSON.parse(jsonString));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (envPath && existsSync(envPath)) {
|
|
18
|
+
return cert(JSON.parse(readFileSync(envPath, 'utf8')));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (existsSync(localKeyPath)) {
|
|
22
|
+
return cert(JSON.parse(readFileSync(localKeyPath, 'utf8')));
|
|
23
|
+
}
|
|
24
|
+
} catch {
|
|
25
|
+
return applicationDefault();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return applicationDefault();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const app = getApps().length ? getApp() : initializeApp({
|
|
32
|
+
credential: resolveCredential(),
|
|
33
|
+
projectId: 'toolproof-563fe',
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const dbAdmin = getFirestore(app);
|
|
37
|
+
const storageAdmin = getStorage(app);
|
|
38
|
+
|
|
39
|
+
export { dbAdmin, storageAdmin };
|
|
@@ -7,8 +7,7 @@ import type {
|
|
|
7
7
|
ResourceOutputPotentialJson,
|
|
8
8
|
ResourceTypeIdentityJson,
|
|
9
9
|
} from '@toolproof-core/schema';
|
|
10
|
-
import { CONSTANTS } from '
|
|
11
|
-
|
|
10
|
+
import { CONSTANTS } from '../../artifacts/artifacts.js';
|
|
12
11
|
|
|
13
12
|
export function generatePath(resourceTypeHandle: ResourceTypeIdentityJson, identity: ResourceIdentityJson): string {
|
|
14
13
|
return `${resourceTypeHandle}/${identity}.json`;
|
|
@@ -17,10 +16,9 @@ export function generatePath(resourceTypeHandle: ResourceTypeIdentityJson, ident
|
|
|
17
16
|
export function createMaterializedFromOutputPotential(
|
|
18
17
|
outputPotential: ResourceOutputPotentialJson,
|
|
19
18
|
nucleus: unknown,
|
|
20
|
-
timestamp?: string
|
|
19
|
+
timestamp?: string,
|
|
21
20
|
): ResourceJson {
|
|
22
21
|
const { identity, resourceTypeHandle, creationContext } = outputPotential;
|
|
23
|
-
|
|
24
22
|
const path = generatePath(resourceTypeHandle, identity);
|
|
25
23
|
|
|
26
24
|
return {
|
|
@@ -29,7 +27,7 @@ export function createMaterializedFromOutputPotential(
|
|
|
29
27
|
creationContext,
|
|
30
28
|
resourceShellKind: CONSTANTS.Enums.ResourceShellKind.materialized,
|
|
31
29
|
version: 1,
|
|
32
|
-
timestamp: timestamp ?? new Date().toISOString(),
|
|
30
|
+
timestamp: timestamp ?? new Date().toISOString(),
|
|
33
31
|
path,
|
|
34
32
|
nucleus,
|
|
35
33
|
};
|
|
@@ -38,10 +36,9 @@ export function createMaterializedFromOutputPotential(
|
|
|
38
36
|
export function createMaterializedFromInputPotential(
|
|
39
37
|
inputPotential: ResourceInputPotentialJson,
|
|
40
38
|
nucleus: unknown,
|
|
41
|
-
timestamp?: string
|
|
39
|
+
timestamp?: string,
|
|
42
40
|
): ResourceJson {
|
|
43
41
|
const { identity, resourceTypeHandle, creationContext } = inputPotential;
|
|
44
|
-
|
|
45
42
|
const path = generatePath(resourceTypeHandle, identity);
|
|
46
43
|
|
|
47
44
|
return {
|
|
@@ -59,17 +56,18 @@ export function createMaterializedFromInputPotential(
|
|
|
59
56
|
export function createMaterializedFromPotential(
|
|
60
57
|
potential: ResourceInputPotentialJson | ResourceOutputPotentialJson,
|
|
61
58
|
nucleus: unknown,
|
|
62
|
-
timestamp?: string
|
|
59
|
+
timestamp?: string,
|
|
63
60
|
): ResourceJson {
|
|
64
61
|
if (potential.resourceShellKind === CONSTANTS.Enums.ResourceShellKind.inputPotential) {
|
|
65
62
|
return createMaterializedFromInputPotential(potential, nucleus, timestamp);
|
|
66
63
|
}
|
|
64
|
+
|
|
67
65
|
return createMaterializedFromOutputPotential(potential, nucleus, timestamp);
|
|
68
66
|
}
|
|
69
67
|
|
|
70
68
|
export function createMissing(
|
|
71
69
|
identity: ResourceIdentityJson,
|
|
72
|
-
resourceTypeHandle: ResourceTypeIdentityJson
|
|
70
|
+
resourceTypeHandle: ResourceTypeIdentityJson,
|
|
73
71
|
): ResourceMissingJson {
|
|
74
72
|
return {
|
|
75
73
|
identity,
|
|
@@ -81,7 +79,7 @@ export function createMissing(
|
|
|
81
79
|
export function createInputPotential(
|
|
82
80
|
identity: ResourceIdentityJson,
|
|
83
81
|
resourceTypeHandle: ResourceTypeIdentityJson,
|
|
84
|
-
creationContext: CreationContextJson
|
|
82
|
+
creationContext: CreationContextJson,
|
|
85
83
|
): ResourceInputPotentialJson {
|
|
86
84
|
return {
|
|
87
85
|
identity,
|
|
@@ -94,7 +92,7 @@ export function createInputPotential(
|
|
|
94
92
|
export function createOutputPotential(
|
|
95
93
|
identity: ResourceIdentityJson,
|
|
96
94
|
resourceTypeHandle: ResourceTypeIdentityJson,
|
|
97
|
-
creationContext: CreationContextJson
|
|
95
|
+
creationContext: CreationContextJson,
|
|
98
96
|
): ResourceOutputPotentialJson {
|
|
99
97
|
return {
|
|
100
98
|
identity,
|