@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.
Files changed (43) hide show
  1. package/dist/artifacts/artifacts.d.ts +3 -3
  2. package/dist/integrations/firebase/createRunnableStrategy.d.ts +3 -0
  3. package/dist/integrations/firebase/createRunnableStrategy.d.ts.map +1 -0
  4. package/dist/integrations/firebase/createRunnableStrategy.js +10 -0
  5. package/dist/integrations/firebase/createRunnableStrategy.js.map +1 -0
  6. package/dist/integrations/firebase/createStep.d.ts +11 -0
  7. package/dist/integrations/firebase/createStep.d.ts.map +1 -0
  8. package/dist/integrations/firebase/createStep.js +43 -0
  9. package/dist/integrations/firebase/createStep.js.map +1 -0
  10. package/dist/integrations/firebase/firebaseAdminHelpers.d.ts +6 -0
  11. package/dist/integrations/firebase/firebaseAdminHelpers.d.ts.map +1 -0
  12. package/dist/integrations/firebase/firebaseAdminHelpers.js +154 -0
  13. package/dist/integrations/firebase/firebaseAdminHelpers.js.map +1 -0
  14. package/dist/integrations/firebase/firebaseAdminInit.d.ts +4 -0
  15. package/dist/integrations/firebase/firebaseAdminInit.d.ts.map +1 -0
  16. package/{src/_lib/setup/firebaseAdminInit.ts → dist/integrations/firebase/firebaseAdminInit.js} +33 -38
  17. package/dist/integrations/firebase/firebaseAdminInit.js.map +1 -0
  18. package/dist/utils/creation/resourceCreation.d.ts +9 -0
  19. package/dist/utils/creation/resourceCreation.d.ts.map +1 -0
  20. package/dist/utils/creation/resourceCreation.js +62 -0
  21. package/dist/utils/creation/resourceCreation.js.map +1 -0
  22. package/dist/utils/creation/runnableStrategyCreation.d.ts +4 -0
  23. package/dist/utils/creation/runnableStrategyCreation.d.ts.map +1 -0
  24. package/dist/utils/creation/runnableStrategyCreation.js +27 -0
  25. package/dist/utils/creation/runnableStrategyCreation.js.map +1 -0
  26. package/dist/utils/creation/stepCreation.d.ts +34 -0
  27. package/dist/utils/creation/stepCreation.d.ts.map +1 -0
  28. package/dist/utils/creation/stepCreation.js +89 -0
  29. package/dist/utils/creation/stepCreation.js.map +1 -0
  30. package/dist/utils/extractData.js +3 -3
  31. package/dist/utils/extractData.js.map +1 -1
  32. package/package.json +12 -12
  33. package/src/integrations/firebase/createRunnableStrategy.ts +20 -0
  34. package/src/integrations/firebase/createStep.ts +71 -0
  35. package/src/{firebase → integrations/firebase}/firebaseAdminHelpers.ts +87 -49
  36. package/src/integrations/firebase/firebaseAdminInit.ts +39 -0
  37. package/src/utils/{createResource.ts → creation/resourceCreation.ts} +9 -11
  38. package/src/utils/creation/runnableStrategyCreation.ts +46 -0
  39. package/src/utils/creation/stepCreation.ts +159 -0
  40. package/src/utils/extractData.ts +3 -3
  41. package/tsconfig.tsbuildinfo +1 -1
  42. package/src/utils/createRunnableStrategy.ts +0 -31
  43. package/src/utils/createStep.ts +0 -111
@@ -0,0 +1,46 @@
1
+ import type {
2
+ RawStrategyJson,
3
+ RunnableStrategyIdentityJson,
4
+ RunnableStrategyJson,
5
+ StepJson,
6
+ StepsByStrategyThreadJson,
7
+ StrategyThreadIdentityJson,
8
+ } from '@toolproof-core/schema';
9
+ import { CONSTANTS } from '../../artifacts/artifacts.js';
10
+ import { getIndependentThreads } from '../parallelizeSteps.js';
11
+
12
+ export function getRunnableStrategyThreadGroups(rawStrategy: RawStrategyJson): StepJson[][] {
13
+ return getIndependentThreads(rawStrategy.steps, rawStrategy.strategyState);
14
+ }
15
+
16
+ export function buildRunnableStrategy(
17
+ rawStrategy: RawStrategyJson,
18
+ runnableStrategyIdentity: RunnableStrategyIdentityJson,
19
+ threadStepGroups: StepJson[][],
20
+ threadIdentities: StrategyThreadIdentityJson[],
21
+ ): RunnableStrategyJson {
22
+ if (threadStepGroups.length !== threadIdentities.length) {
23
+ throw new Error('buildRunnableStrategy requires one thread identity per thread group');
24
+ }
25
+
26
+ const stepsByStrategyThread: StepsByStrategyThreadJson = {};
27
+
28
+ for (const [index, group] of threadStepGroups.entries()) {
29
+ const threadIdentity = threadIdentities[index];
30
+
31
+ if (!threadIdentity) {
32
+ throw new Error(`Missing thread identity for thread group index ${index}`);
33
+ }
34
+
35
+ stepsByStrategyThread[threadIdentity] = group;
36
+ }
37
+
38
+ return {
39
+ identity: runnableStrategyIdentity,
40
+ runnableStrategyContext: {
41
+ status: CONSTANTS.Enums.RunnableStrategyStatus.pending,
42
+ },
43
+ stepsByStrategyThread,
44
+ strategyState: rawStrategy.strategyState,
45
+ };
46
+ }
@@ -0,0 +1,159 @@
1
+ import type {
2
+ BranchStepIdentityJson,
3
+ BranchStepJson,
4
+ CaseJson,
5
+ ForStepIdentityJson,
6
+ ForStepJson,
7
+ JobJson,
8
+ JobStepIdentityJson,
9
+ JobStepJson,
10
+ ResourceRoleIdentityJson,
11
+ WhileStepIdentityJson,
12
+ WhileStepJson,
13
+ } from '@toolproof-core/schema';
14
+ import { CONSTANTS } from '../../artifacts/artifacts.js';
15
+
16
+ export type LoopStepBuildIdentities =
17
+ | {
18
+ stepKind: typeof CONSTANTS.Enums.StepKind.for;
19
+ stepIdentity: ForStepIdentityJson;
20
+ whatIdentity: JobStepIdentityJson;
21
+ whenIdentity: JobStepIdentityJson;
22
+ }
23
+ | {
24
+ stepKind: typeof CONSTANTS.Enums.StepKind.while;
25
+ stepIdentity: WhileStepIdentityJson;
26
+ whatIdentity: JobStepIdentityJson;
27
+ whenIdentity: JobStepIdentityJson;
28
+ };
29
+
30
+ export type BranchCaseBuildIdentities = {
31
+ whatIdentity: JobStepIdentityJson;
32
+ whenIdentity: JobStepIdentityJson;
33
+ };
34
+
35
+ function assertNonEmpty<T>(arr: T[], msg: string): asserts arr is [T, ...T[]] {
36
+ if (arr.length === 0) {
37
+ throw new Error(msg);
38
+ }
39
+ }
40
+
41
+ function getRoleBindings(job: JobJson): JobStepJson['roleBindings'] {
42
+ return {
43
+ inputBindings: Object.keys(job.roles.inputRoleValuesByIdentity) as ResourceRoleIdentityJson[],
44
+ outputBindings: Object.keys(job.roles.outputRoleValuesByIdentity) as ResourceRoleIdentityJson[],
45
+ };
46
+ }
47
+
48
+ export function buildJobStepFromJob(
49
+ job: JobJson,
50
+ identity: JobStepIdentityJson,
51
+ ): JobStepJson {
52
+ return {
53
+ identity,
54
+ stepKind: CONSTANTS.Enums.StepKind.job,
55
+ jobHandle: job.identity,
56
+ roleBindings: getRoleBindings(job),
57
+ };
58
+ }
59
+
60
+ export function buildLoopStepFromJobPair(
61
+ whatJob: JobJson,
62
+ whenJob: JobJson,
63
+ identities: LoopStepBuildIdentities,
64
+ ): ForStepJson | WhileStepJson {
65
+ const what = buildJobStepFromJob(whatJob, identities.whatIdentity);
66
+ const when = buildJobStepFromJob(whenJob, identities.whenIdentity);
67
+
68
+ if (identities.stepKind === CONSTANTS.Enums.StepKind.for) {
69
+ return {
70
+ identity: identities.stepIdentity,
71
+ stepKind: CONSTANTS.Enums.StepKind.for,
72
+ case: { what, when },
73
+ };
74
+ }
75
+
76
+ return {
77
+ identity: identities.stepIdentity,
78
+ stepKind: CONSTANTS.Enums.StepKind.while,
79
+ case: { what, when },
80
+ };
81
+ }
82
+
83
+ export function buildBranchStepFromJobPairs(
84
+ cases: Array<{ whatJob: JobJson; whenJob: JobJson }>,
85
+ branchIdentity: BranchStepIdentityJson,
86
+ caseIdentities: BranchCaseBuildIdentities[],
87
+ ): BranchStepJson {
88
+ if (cases.length !== caseIdentities.length) {
89
+ throw new Error('buildBranchStepFromJobPairs requires one identity pair per case');
90
+ }
91
+
92
+ const resolved = cases.map(({ whatJob, whenJob }, index) => {
93
+ const identities = caseIdentities[index];
94
+
95
+ if (!identities) {
96
+ throw new Error(`Missing case identities for case index ${index}`);
97
+ }
98
+
99
+ const what = buildJobStepFromJob(whatJob, identities.whatIdentity);
100
+ const when = buildJobStepFromJob(whenJob, identities.whenIdentity);
101
+ return { what, when } satisfies CaseJson;
102
+ });
103
+
104
+ assertNonEmpty(resolved, 'buildBranchStepFromJobPairs requires at least one case');
105
+
106
+ return {
107
+ identity: branchIdentity,
108
+ stepKind: CONSTANTS.Enums.StepKind.branch,
109
+ cases: resolved,
110
+ };
111
+ }
112
+
113
+ export function cloneForStepWithIdentities(
114
+ forStep: ForStepJson,
115
+ identities: {
116
+ stepIdentity: ForStepIdentityJson;
117
+ whatIdentity: JobStepIdentityJson;
118
+ whenIdentity: JobStepIdentityJson;
119
+ },
120
+ ): ForStepJson {
121
+ return {
122
+ identity: identities.stepIdentity,
123
+ stepKind: CONSTANTS.Enums.StepKind.for,
124
+ case: {
125
+ what: {
126
+ ...forStep.case.what,
127
+ identity: identities.whatIdentity,
128
+ },
129
+ when: {
130
+ ...forStep.case.when,
131
+ identity: identities.whenIdentity,
132
+ },
133
+ },
134
+ };
135
+ }
136
+
137
+ export function cloneWhileStepWithIdentities(
138
+ whileStep: WhileStepJson,
139
+ identities: {
140
+ stepIdentity: WhileStepIdentityJson;
141
+ whatIdentity: JobStepIdentityJson;
142
+ whenIdentity: JobStepIdentityJson;
143
+ },
144
+ ): WhileStepJson {
145
+ return {
146
+ identity: identities.stepIdentity,
147
+ stepKind: CONSTANTS.Enums.StepKind.while,
148
+ case: {
149
+ what: {
150
+ ...whileStep.case.what,
151
+ identity: identities.whatIdentity,
152
+ },
153
+ when: {
154
+ ...whileStep.case.when,
155
+ identity: identities.whenIdentity,
156
+ },
157
+ },
158
+ };
159
+ }
@@ -77,13 +77,13 @@ export function extractRoleMapFromRawStrategy(rawStrategy: RawStrategyJson, jobM
77
77
  const job = jobMap.get(jobHandle);
78
78
  if (!job) continue;
79
79
 
80
- for (const [rid, role] of Object.entries(job.roles.inputDict)) {
80
+ for (const [rid, role] of Object.entries(job.roles.inputRoleValuesByIdentity)) {
81
81
  roleMap.set(rid as ResourceRoleIdentityJson, {
82
82
  identity: rid as ResourceRoleIdentityJson,
83
83
  ...role,
84
84
  });
85
85
  }
86
- for (const [rid, role] of Object.entries(job.roles.outputDict)) {
86
+ for (const [rid, role] of Object.entries(job.roles.outputRoleValuesByIdentity)) {
87
87
  roleMap.set(rid as ResourceRoleIdentityJson, {
88
88
  identity: rid as ResourceRoleIdentityJson,
89
89
  ...role,
@@ -96,7 +96,7 @@ export function extractRoleMapFromRawStrategy(rawStrategy: RawStrategyJson, jobM
96
96
 
97
97
  export function extractSingleNonErrorOutputTypeHandle(job: JobJson): ResourceTypeIdentityJson | null {
98
98
  const errorRoleId = CONSTANTS.Cosmos.ROLE_ErrorOutput;
99
- const outputEntries = Object.entries(job.roles.outputDict).filter(([roleId]) => roleId !== errorRoleId);
99
+ const outputEntries = Object.entries(job.roles.outputRoleValuesByIdentity).filter(([roleId]) => roleId !== errorRoleId);
100
100
  if (!outputEntries || !outputEntries[0] || outputEntries.length !== 1) {
101
101
  throw new Error(`Job ${job.identity} must have exactly one non-error output role to be branchable/loopable`);
102
102
  } // ATTENTION_PUREIFY