@toolproof-core/lib 1.0.30 → 1.0.32

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 (46) hide show
  1. package/dist/integrations/firebase/createRunnableStrategy.d.ts +2 -2
  2. package/dist/integrations/firebase/createRunnableStrategy.d.ts.map +1 -1
  3. package/dist/integrations/firebase/createRunnableStrategy.js.map +1 -1
  4. package/dist/integrations/firebase/createStep.d.ts +8 -8
  5. package/dist/integrations/firebase/createStep.d.ts.map +1 -1
  6. package/dist/integrations/firebase/createStep.js.map +1 -1
  7. package/dist/integrations/firebase/firebaseAdminHelpers.d.ts +3 -3
  8. package/dist/integrations/firebase/firebaseAdminHelpers.d.ts.map +1 -1
  9. package/dist/integrations/firebase/firebaseAdminHelpers.js.map +1 -1
  10. package/dist/types/types.d.ts +3 -3
  11. package/dist/types/types.d.ts.map +1 -1
  12. package/dist/utils/bindInputRoleToResource.d.ts +4 -4
  13. package/dist/utils/bindInputRoleToResource.d.ts.map +1 -1
  14. package/dist/utils/bindInputRoleToResource.js.map +1 -1
  15. package/dist/utils/creation/resourceCreation.d.ts +8 -8
  16. package/dist/utils/creation/resourceCreation.d.ts.map +1 -1
  17. package/dist/utils/creation/resourceCreation.js.map +1 -1
  18. package/dist/utils/creation/runnableStrategyCreation.d.ts +3 -3
  19. package/dist/utils/creation/runnableStrategyCreation.d.ts.map +1 -1
  20. package/dist/utils/creation/runnableStrategyCreation.js.map +1 -1
  21. package/dist/utils/creation/stepCreation.d.ts +24 -24
  22. package/dist/utils/creation/stepCreation.d.ts.map +1 -1
  23. package/dist/utils/creation/stepCreation.js.map +1 -1
  24. package/dist/utils/extractData.d.ts +7 -7
  25. package/dist/utils/extractData.d.ts.map +1 -1
  26. package/dist/utils/extractData.js.map +1 -1
  27. package/dist/utils/parallelizeSteps.d.ts +2 -2
  28. package/dist/utils/parallelizeSteps.d.ts.map +1 -1
  29. package/dist/utils/parallelizeSteps.js +3 -3
  30. package/dist/utils/parallelizeSteps.js.map +1 -1
  31. package/dist/utils/resolveResourceChain.d.ts +9 -9
  32. package/dist/utils/resolveResourceChain.d.ts.map +1 -1
  33. package/dist/utils/resolveResourceChain.js.map +1 -1
  34. package/package.json +2 -2
  35. package/src/integrations/firebase/createRunnableStrategy.ts +2 -2
  36. package/src/integrations/firebase/createStep.ts +13 -13
  37. package/src/integrations/firebase/firebaseAdminHelpers.ts +8 -8
  38. package/src/types/types.ts +5 -5
  39. package/src/utils/bindInputRoleToResource.ts +22 -22
  40. package/src/utils/creation/resourceCreation.ts +25 -25
  41. package/src/utils/creation/runnableStrategyCreation.ts +13 -13
  42. package/src/utils/creation/stepCreation.ts +42 -42
  43. package/src/utils/extractData.ts +33 -33
  44. package/src/utils/parallelizeSteps.ts +21 -21
  45. package/src/utils/resolveResourceChain.ts +21 -21
  46. package/tsconfig.tsbuildinfo +1 -1
@@ -1,9 +1,9 @@
1
1
  import type {
2
- BranchStepJson,
3
- ForStepJson,
4
- ToolJson,
5
- ToolStepJson,
6
- WhileStepJson,
2
+ BranchStep,
3
+ ForStep,
4
+ Tool,
5
+ ToolStep,
6
+ WhileStep,
7
7
  } from '@toolproof-core/schema';
8
8
  import { CONSTANTS } from '../../artifacts/artifacts.js';
9
9
  import {
@@ -15,15 +15,15 @@ import {
15
15
  } from '../../utils/creation/stepCreation.js';
16
16
  import { getNewStepId } from './firebaseAdminHelpers.js';
17
17
 
18
- export function createToolStepFromTool(tool: ToolJson): ToolStepJson {
18
+ export function createToolStepFromTool(tool: Tool): ToolStep {
19
19
  return buildToolStepFromTool(tool, getNewStepId(CONSTANTS.Enums.StepKind.tool));
20
20
  }
21
21
 
22
22
  export function createLoopStepFromToolPair(
23
- whatTool: ToolJson,
24
- whenTool: ToolJson,
23
+ whatTool: Tool,
24
+ whenTool: Tool,
25
25
  stepKind: typeof CONSTANTS.Enums.StepKind.for | typeof CONSTANTS.Enums.StepKind.while,
26
- ): ForStepJson | WhileStepJson {
26
+ ): ForStep | WhileStep {
27
27
  if (stepKind === CONSTANTS.Enums.StepKind.for) {
28
28
  return buildLoopStepFromToolPair(whatTool, whenTool, {
29
29
  stepKind,
@@ -42,8 +42,8 @@ export function createLoopStepFromToolPair(
42
42
  }
43
43
 
44
44
  export function createBranchStepFromToolPairs(
45
- cases: Array<{ whatTool: ToolJson; whenTool: ToolJson }>,
46
- ): BranchStepJson {
45
+ cases: Array<{ whatTool: Tool; whenTool: Tool }>,
46
+ ): BranchStep {
47
47
  return buildBranchStepFromToolPairs(
48
48
  cases,
49
49
  getNewStepId(CONSTANTS.Enums.StepKind.branch),
@@ -54,7 +54,7 @@ export function createBranchStepFromToolPairs(
54
54
  );
55
55
  }
56
56
 
57
- export function cloneForStep(forStep: ForStepJson): ForStepJson {
57
+ export function cloneForStep(forStep: ForStep): ForStep {
58
58
  return cloneForStepWithIdentities(forStep, {
59
59
  stepId: getNewStepId(CONSTANTS.Enums.StepKind.for),
60
60
  whatId: getNewStepId(CONSTANTS.Enums.StepKind.tool),
@@ -62,7 +62,7 @@ export function cloneForStep(forStep: ForStepJson): ForStepJson {
62
62
  });
63
63
  }
64
64
 
65
- export function cloneWhileStep(whileStep: WhileStepJson): WhileStepJson {
65
+ export function cloneWhileStep(whileStep: WhileStep): WhileStep {
66
66
  return cloneWhileStepWithIdentities(whileStep, {
67
67
  stepId: getNewStepId(CONSTANTS.Enums.StepKind.while),
68
68
  whatId: getNewStepId(CONSTANTS.Enums.StepKind.tool),
@@ -1,7 +1,7 @@
1
1
  import type {
2
- ResourceJson,
3
- ResourceTypeIdJson,
4
- StepKindJson,
2
+ Resource,
3
+ ResourceTypeId,
4
+ StepKind,
5
5
  } from '@toolproof-core/schema';
6
6
  import type {
7
7
  IdName,
@@ -31,7 +31,7 @@ export function getNewId<K extends IdName>(idName: K): IdStringByIdName<K> {
31
31
  return (prefix + docRef.id) as IdStringByIdName<K>;
32
32
  }
33
33
 
34
- export function getNewStepId<K extends StepKindJson>(stepKind: K): StepIdStringByStepKind<K> {
34
+ export function getNewStepId<K extends StepKind>(stepKind: K): StepIdStringByStepKind<K> {
35
35
  const idName = `${capitalizeFirst(stepKind)}StepId` as IdName;
36
36
 
37
37
  if (!(idName in MAPPINGS.IdNameToIdPrefix)) {
@@ -42,13 +42,13 @@ export function getNewStepId<K extends StepKindJson>(stepKind: K): StepIdStringB
42
42
  }
43
43
 
44
44
  export async function listResources(
45
- resourceTypeIds: ResourceTypeIdJson[],
45
+ resourceTypeIds: ResourceTypeId[],
46
46
  ): Promise<ResourcesByType> {
47
47
  const bucketResources = storageAdmin.bucket(CONSTANTS.Persistence.Buckets.tp_resources);
48
48
  const bucketStrategies = storageAdmin.bucket(CONSTANTS.Persistence.Buckets.tp_strategies);
49
49
 
50
50
  async function fetchFilesUnder(
51
- resourceTypeId: ResourceTypeIdJson,
51
+ resourceTypeId: ResourceTypeId,
52
52
  ): Promise<Array<{ data: unknown; meta: any; name: string }>> {
53
53
  const bucket = resourceTypeId === CONSTANTS.Cosmos.TYPE_RunnableStrategy
54
54
  ? bucketStrategies
@@ -81,7 +81,7 @@ export async function listResources(
81
81
  const entries = await Promise.all(
82
82
  resourceTypeIds.map(async (resourceTypeId) => {
83
83
  const rows = await fetchFilesUnder(resourceTypeId);
84
- const items: ResourceJson[] = rows.map(({ data, meta, name }) => {
84
+ const items: Resource[] = rows.map(({ data, meta, name }) => {
85
85
  const flat = meta?.metadata ?? {};
86
86
  const root: any = {};
87
87
 
@@ -184,7 +184,7 @@ export async function listResources(
184
184
  timestamp: timestamp as string,
185
185
  path: resourcePath as string,
186
186
  nucleus: data as any,
187
- } as unknown as ResourceJson;
187
+ } as unknown as Resource;
188
188
  });
189
189
 
190
190
  return [resourceTypeId, items] as const;
@@ -1,7 +1,7 @@
1
1
  import type {
2
- StepKindJson,
3
- ResourceJson,
4
- ResourceTypeIdJson,
2
+ StepKind,
3
+ Resource,
4
+ ResourceTypeId,
5
5
  } from '@toolproof-core/schema';
6
6
  import { CONSTANTS } from '../artifacts/artifacts.js';
7
7
  import { MAPPINGS } from '../artifacts/artifacts.js';
@@ -12,13 +12,13 @@ export type Collection = keyof typeof CONSTANTS.Persistence.Collections;
12
12
 
13
13
  export type SchemaLike = Record<string, unknown>;
14
14
 
15
- export type ResourcesByType = Record<ResourceTypeIdJson, ResourceJson[]>;
15
+ export type ResourcesByType = Record<ResourceTypeId, Resource[]>;
16
16
 
17
17
  export type IdName = keyof typeof MAPPINGS.IdNameToIdPrefix;
18
18
 
19
19
  export type IdStringByIdName<K extends IdName> = `${(typeof MAPPINGS.IdNameToIdPrefix)[K]}${string}`;
20
20
 
21
- export type StepIdStringByStepKind<K extends StepKindJson> = `${(typeof MAPPINGS.StepKindToStepIdPrefix)[K]}${string}`;
21
+ export type StepIdStringByStepKind<K extends StepKind> = `${(typeof MAPPINGS.StepKindToStepIdPrefix)[K]}${string}`;
22
22
 
23
23
  export interface NucleusBaseSmall<T extends string = string> {
24
24
  id: T;
@@ -1,21 +1,21 @@
1
1
  import type {
2
- CreationContextJson,
3
- ExternalInputPotentialShellJson,
4
- InternalInputPotentialShellJson,
5
- OutputPotentialShellJson,
6
- ResourceJson,
7
- ResourcePotentialJson,
8
- StrategyStateJson,
2
+ CreationContext,
3
+ ExternalInputPotentialShell,
4
+ InternalInputPotentialShell,
5
+ OutputPotentialShell,
6
+ Resource,
7
+ ResourcePotential,
8
+ StrategyState,
9
9
  } from '@toolproof-core/schema';
10
10
  import { CONSTANTS } from '../artifacts/artifacts.js';
11
11
  import { resolveResourceChain } from './resolveResourceChain.js';
12
12
 
13
13
 
14
14
  export function bindInputResInStrategyState(
15
- strategyState: StrategyStateJson,
16
- target: CreationContextJson,
17
- resource: ResourceJson
18
- ): StrategyStateJson {
15
+ strategyState: StrategyState,
16
+ target: CreationContext,
17
+ resource: Resource
18
+ ): StrategyState {
19
19
  const bucket = strategyState[target.toolStepId] ?? {};
20
20
  return {
21
21
  ...strategyState,
@@ -27,13 +27,13 @@ export function bindInputResInStrategyState(
27
27
  }
28
28
 
29
29
  export function bindInputRefInStrategyState(
30
- strategyState: StrategyStateJson,
31
- target: CreationContextJson,
32
- source: CreationContextJson
33
- ): StrategyStateJson {
30
+ strategyState: StrategyState,
31
+ target: CreationContext,
32
+ source: CreationContext
33
+ ): StrategyState {
34
34
  const sourceEntry = strategyState?.[source.toolStepId]?.[source.resourceRoleId] as (
35
- | ResourceJson
36
- | ResourcePotentialJson
35
+ | Resource
36
+ | ResourcePotential
37
37
  | undefined
38
38
  );
39
39
  if (!sourceEntry) {
@@ -55,7 +55,7 @@ export function bindInputRefInStrategyState(
55
55
 
56
56
  if (result.status === CONSTANTS.Enums.ResourceShellKind.externalInputPotential) {
57
57
  const externalInput = result.entry;
58
- const reusedExternalInput: ExternalInputPotentialShellJson = {
58
+ const reusedExternalInput: ExternalInputPotentialShell = {
59
59
  id: externalInput.id,
60
60
  resourceTypeId: externalInput.resourceTypeId,
61
61
  resourceShellKind: CONSTANTS.Enums.ResourceShellKind.externalInputPotential,
@@ -71,7 +71,7 @@ export function bindInputRefInStrategyState(
71
71
  }
72
72
 
73
73
  if (result.status === CONSTANTS.Enums.ResourceShellKind.outputPotential) {
74
- const potentialInput: InternalInputPotentialShellJson = {
74
+ const potentialInput: InternalInputPotentialShell = {
75
75
  id: sourceEntry.id,
76
76
  resourceTypeId: sourceEntry.resourceTypeId,
77
77
  creationContext: {
@@ -94,9 +94,9 @@ export function bindInputRefInStrategyState(
94
94
  }
95
95
 
96
96
  export function clearInputBindingInStrategyState(
97
- strategyState: StrategyStateJson,
98
- target: CreationContextJson
99
- ): StrategyStateJson {
97
+ strategyState: StrategyState,
98
+ target: CreationContext
99
+ ): StrategyState {
100
100
  const bucket = strategyState?.[target.toolStepId];
101
101
  if (!bucket?.[target.resourceRoleId]) return strategyState;
102
102
 
@@ -1,23 +1,23 @@
1
1
  import type {
2
- CreationContextJson,
3
- ExternalInputPotentialShellJson,
4
- InternalInputPotentialShellJson,
5
- OutputPotentialShellJson,
6
- ResourceIdJson,
7
- ResourceJson,
8
- ResourceTypeIdJson,
2
+ CreationContext,
3
+ ExternalInputPotentialShell,
4
+ InternalInputPotentialShell,
5
+ OutputPotentialShell,
6
+ ResourceId,
7
+ Resource,
8
+ ResourceTypeId,
9
9
  } from '@toolproof-core/schema';
10
10
  import { CONSTANTS } from '../../artifacts/artifacts.js';
11
11
 
12
- export function generatePath(resourceTypeId: ResourceTypeIdJson, id: ResourceIdJson): string {
12
+ export function generatePath(resourceTypeId: ResourceTypeId, id: ResourceId): string {
13
13
  return `${resourceTypeId}/${id}.json`;
14
14
  }
15
15
 
16
16
  export function createMaterializedFromOutputPotential(
17
- outputPotential: OutputPotentialShellJson,
17
+ outputPotential: OutputPotentialShell,
18
18
  nucleus: unknown,
19
19
  timestamp?: string,
20
- ): ResourceJson {
20
+ ): Resource {
21
21
  const { id, resourceTypeId, creationContext } = outputPotential;
22
22
  const path = generatePath(resourceTypeId, id);
23
23
 
@@ -34,10 +34,10 @@ export function createMaterializedFromOutputPotential(
34
34
  }
35
35
 
36
36
  export function createMaterializedFromInputPotential(
37
- inputPotential: InternalInputPotentialShellJson,
37
+ inputPotential: InternalInputPotentialShell,
38
38
  nucleus: unknown,
39
39
  timestamp?: string,
40
- ): ResourceJson {
40
+ ): Resource {
41
41
  const { id, resourceTypeId, creationContext } = inputPotential;
42
42
  const path = generatePath(resourceTypeId, id);
43
43
 
@@ -54,10 +54,10 @@ export function createMaterializedFromInputPotential(
54
54
  }
55
55
 
56
56
  export function createMaterializedFromPotential(
57
- potential: InternalInputPotentialShellJson | OutputPotentialShellJson,
57
+ potential: InternalInputPotentialShell | OutputPotentialShell,
58
58
  nucleus: unknown,
59
59
  timestamp?: string,
60
- ): ResourceJson {
60
+ ): Resource {
61
61
  if (potential.resourceShellKind === CONSTANTS.Enums.ResourceShellKind.internalInputPotential) {
62
62
  return createMaterializedFromInputPotential(potential, nucleus, timestamp);
63
63
  }
@@ -66,9 +66,9 @@ export function createMaterializedFromPotential(
66
66
  }
67
67
 
68
68
  export function createExternalInputPotential(
69
- id: ResourceIdJson,
70
- resourceTypeId: ResourceTypeIdJson,
71
- ): ExternalInputPotentialShellJson {
69
+ id: ResourceId,
70
+ resourceTypeId: ResourceTypeId,
71
+ ): ExternalInputPotentialShell {
72
72
  return {
73
73
  id,
74
74
  resourceTypeId,
@@ -77,10 +77,10 @@ export function createExternalInputPotential(
77
77
  }
78
78
 
79
79
  export function createInputPotential(
80
- id: ResourceIdJson,
81
- resourceTypeId: ResourceTypeIdJson,
82
- creationContext: CreationContextJson,
83
- ): InternalInputPotentialShellJson {
80
+ id: ResourceId,
81
+ resourceTypeId: ResourceTypeId,
82
+ creationContext: CreationContext,
83
+ ): InternalInputPotentialShell {
84
84
  return {
85
85
  id,
86
86
  resourceTypeId,
@@ -90,10 +90,10 @@ export function createInputPotential(
90
90
  }
91
91
 
92
92
  export function createOutputPotential(
93
- id: ResourceIdJson,
94
- resourceTypeId: ResourceTypeIdJson,
95
- creationContext: CreationContextJson,
96
- ): OutputPotentialShellJson {
93
+ id: ResourceId,
94
+ resourceTypeId: ResourceTypeId,
95
+ creationContext: CreationContext,
96
+ ): OutputPotentialShell {
97
97
  return {
98
98
  id,
99
99
  resourceTypeId,
@@ -1,28 +1,28 @@
1
1
  import type {
2
- RawStrategyJson,
3
- RunnableStrategyIdJson,
4
- RunnableStrategyJson,
5
- StepJson,
6
- StepArrayByStrategyThreadJson,
7
- StrategyThreadIdJson,
2
+ RawStrategy,
3
+ RunnableStrategyId,
4
+ RunnableStrategy,
5
+ Step,
6
+ StepArrayByStrategyThread,
7
+ StrategyThreadId,
8
8
  } from '@toolproof-core/schema';
9
9
  import { getIndependentThreads } from '../parallelizeSteps.js';
10
10
 
11
- export function getRunnableStrategyThreadGroups(rawStrategy: RawStrategyJson): StepJson[][] {
11
+ export function getRunnableStrategyThreadGroups(rawStrategy: RawStrategy): Step[][] {
12
12
  return getIndependentThreads(rawStrategy.steps, rawStrategy.strategyState);
13
13
  }
14
14
 
15
15
  export function buildRunnableStrategy(
16
- rawStrategy: RawStrategyJson,
17
- runnableStrategyId: RunnableStrategyIdJson,
18
- threadStepGroups: StepJson[][],
19
- threadIdentities: StrategyThreadIdJson[],
20
- ): RunnableStrategyJson {
16
+ rawStrategy: RawStrategy,
17
+ runnableStrategyId: RunnableStrategyId,
18
+ threadStepGroups: Step[][],
19
+ threadIdentities: StrategyThreadId[],
20
+ ): RunnableStrategy {
21
21
  if (threadStepGroups.length !== threadIdentities.length) {
22
22
  throw new Error('buildRunnableStrategy requires one thread id per thread group');
23
23
  }
24
24
 
25
- const stepsByStrategyThread: StepArrayByStrategyThreadJson = {};
25
+ const stepsByStrategyThread: StepArrayByStrategyThread = {};
26
26
 
27
27
  for (const [index, group] of threadStepGroups.entries()) {
28
28
  const threadId = threadIdentities[index];
@@ -1,35 +1,35 @@
1
1
  import type {
2
- BranchStepIdJson,
3
- BranchStepJson,
4
- CaseJson,
5
- ForStepIdJson,
6
- ForStepJson,
7
- ToolJson,
8
- ToolStepIdJson,
9
- ToolStepJson,
10
- ResourceRoleIdJson,
11
- WhileStepIdJson,
12
- WhileStepJson,
2
+ BranchStepId,
3
+ BranchStep,
4
+ Case,
5
+ ForStepId,
6
+ ForStep,
7
+ Tool,
8
+ ToolStepId,
9
+ ToolStep,
10
+ ResourceRoleId,
11
+ WhileStepId,
12
+ WhileStep,
13
13
  } from '@toolproof-core/schema';
14
14
  import { CONSTANTS } from '../../artifacts/artifacts.js';
15
15
 
16
16
  export type LoopStepBuildIdentities =
17
17
  | {
18
18
  stepKind: typeof CONSTANTS.Enums.StepKind.for;
19
- stepId: ForStepIdJson;
20
- whatId: ToolStepIdJson;
21
- whenId: ToolStepIdJson;
19
+ stepId: ForStepId;
20
+ whatId: ToolStepId;
21
+ whenId: ToolStepId;
22
22
  }
23
23
  | {
24
24
  stepKind: typeof CONSTANTS.Enums.StepKind.while;
25
- stepId: WhileStepIdJson;
26
- whatId: ToolStepIdJson;
27
- whenId: ToolStepIdJson;
25
+ stepId: WhileStepId;
26
+ whatId: ToolStepId;
27
+ whenId: ToolStepId;
28
28
  };
29
29
 
30
30
  export type BranchCaseBuildIdentities = {
31
- whatId: ToolStepIdJson;
32
- whenId: ToolStepIdJson;
31
+ whatId: ToolStepId;
32
+ whenId: ToolStepId;
33
33
  };
34
34
 
35
35
  function assertNonEmpty<T>(arr: T[], msg: string): asserts arr is [T, ...T[]] {
@@ -38,17 +38,17 @@ function assertNonEmpty<T>(arr: T[], msg: string): asserts arr is [T, ...T[]] {
38
38
  }
39
39
  }
40
40
 
41
- function getRoleBindingSpec(tool: ToolJson): ToolStepJson['roleBindingSpec'] {
41
+ function getRoleBindingSpec(tool: Tool): ToolStep['roleBindingSpec'] {
42
42
  return {
43
- inputBindings: Object.keys(tool.roleSpec.inputRoleValueById) as ResourceRoleIdJson[],
44
- outputBindings: Object.keys(tool.roleSpec.outputRoleValueById) as ResourceRoleIdJson[],
43
+ inputBindings: Object.keys(tool.roleSpec.inputRoleValueById) as ResourceRoleId[],
44
+ outputBindings: Object.keys(tool.roleSpec.outputRoleValueById) as ResourceRoleId[],
45
45
  };
46
46
  }
47
47
 
48
48
  export function buildToolStepFromTool(
49
- tool: ToolJson,
50
- id: ToolStepIdJson,
51
- ): ToolStepJson {
49
+ tool: Tool,
50
+ id: ToolStepId,
51
+ ): ToolStep {
52
52
  return {
53
53
  id,
54
54
  stepKind: CONSTANTS.Enums.StepKind.tool,
@@ -58,10 +58,10 @@ export function buildToolStepFromTool(
58
58
  }
59
59
 
60
60
  export function buildLoopStepFromToolPair(
61
- whatTool: ToolJson,
62
- whenTool: ToolJson,
61
+ whatTool: Tool,
62
+ whenTool: Tool,
63
63
  identities: LoopStepBuildIdentities,
64
- ): ForStepJson | WhileStepJson {
64
+ ): ForStep | WhileStep {
65
65
  const what = buildToolStepFromTool(whatTool, identities.whatId);
66
66
  const when = buildToolStepFromTool(whenTool, identities.whenId);
67
67
 
@@ -81,10 +81,10 @@ export function buildLoopStepFromToolPair(
81
81
  }
82
82
 
83
83
  export function buildBranchStepFromToolPairs(
84
- cases: Array<{ whatTool: ToolJson; whenTool: ToolJson }>,
85
- branchId: BranchStepIdJson,
84
+ cases: Array<{ whatTool: Tool; whenTool: Tool }>,
85
+ branchId: BranchStepId,
86
86
  caseIdentities: BranchCaseBuildIdentities[],
87
- ): BranchStepJson {
87
+ ): BranchStep {
88
88
  if (cases.length !== caseIdentities.length) {
89
89
  throw new Error('buildBranchStepFromToolPairs requires one id pair per case');
90
90
  }
@@ -98,7 +98,7 @@ export function buildBranchStepFromToolPairs(
98
98
 
99
99
  const what = buildToolStepFromTool(whatTool, identities.whatId);
100
100
  const when = buildToolStepFromTool(whenTool, identities.whenId);
101
- return { what, when } satisfies CaseJson;
101
+ return { what, when } satisfies Case;
102
102
  });
103
103
 
104
104
  assertNonEmpty(resolved, 'buildBranchStepFromToolPairs requires at least one case');
@@ -111,13 +111,13 @@ export function buildBranchStepFromToolPairs(
111
111
  }
112
112
 
113
113
  export function cloneForStepWithIdentities(
114
- forStep: ForStepJson,
114
+ forStep: ForStep,
115
115
  identities: {
116
- stepId: ForStepIdJson;
117
- whatId: ToolStepIdJson;
118
- whenId: ToolStepIdJson;
116
+ stepId: ForStepId;
117
+ whatId: ToolStepId;
118
+ whenId: ToolStepId;
119
119
  },
120
- ): ForStepJson {
120
+ ): ForStep {
121
121
  return {
122
122
  id: identities.stepId,
123
123
  stepKind: CONSTANTS.Enums.StepKind.for,
@@ -135,13 +135,13 @@ export function cloneForStepWithIdentities(
135
135
  }
136
136
 
137
137
  export function cloneWhileStepWithIdentities(
138
- whileStep: WhileStepJson,
138
+ whileStep: WhileStep,
139
139
  identities: {
140
- stepId: WhileStepIdJson;
141
- whatId: ToolStepIdJson;
142
- whenId: ToolStepIdJson;
140
+ stepId: WhileStepId;
141
+ whatId: ToolStepId;
142
+ whenId: ToolStepId;
143
143
  },
144
- ): WhileStepJson {
144
+ ): WhileStep {
145
145
  return {
146
146
  id: identities.stepId,
147
147
  stepKind: CONSTANTS.Enums.StepKind.while,
@@ -1,33 +1,33 @@
1
1
  import type {
2
- RawStrategyJson,
3
- ToolIdJson,
4
- ToolJson,
5
- ToolStepIdJson,
6
- ToolStepJson,
7
- StepJson,
8
- ResourceRoleIdJson,
9
- ResourceRoleJson,
10
- ResourceIdJson,
11
- ResourceTypeIdJson,
12
- ResourceJson,
2
+ RawStrategy,
3
+ ToolId,
4
+ Tool,
5
+ ToolStepId,
6
+ ToolStep,
7
+ Step,
8
+ ResourceRoleId,
9
+ ResourceRole,
10
+ ResourceId,
11
+ ResourceTypeId,
12
+ Resource,
13
13
  } from '@toolproof-core/schema';
14
14
  import { CONSTANTS } from '../artifacts/artifacts.js';
15
15
 
16
16
 
17
- export function extractToolIdsFromRawStrategy(rawStrategy: RawStrategyJson): ToolIdJson[] {
17
+ export function extractToolIdsFromRawStrategy(rawStrategy: RawStrategy): ToolId[] {
18
18
  const toolSteps = extractToolStepsFromRawStrategy(rawStrategy);
19
- const ids = new Set<ToolIdJson>();
19
+ const ids = new Set<ToolId>();
20
20
  for (const jStep of toolSteps) {
21
21
  ids.add(jStep.toolId);
22
22
  }
23
23
  return Array.from(ids);
24
24
  }
25
25
 
26
- export function extractToolStepsFromRawStrategy(rawStrategy: RawStrategyJson): ToolStepJson[] {
27
- const toolSteps: ToolStepJson[] = [];
28
- const seen = new Set<ToolStepIdJson>();
26
+ export function extractToolStepsFromRawStrategy(rawStrategy: RawStrategy): ToolStep[] {
27
+ const toolSteps: ToolStep[] = [];
28
+ const seen = new Set<ToolStepId>();
29
29
 
30
- const addToolStep = (toolStep: ToolStepJson) => {
30
+ const addToolStep = (toolStep: ToolStep) => {
31
31
  if (seen.has(toolStep.id)) {
32
32
  throw new Error(`Duplicate tool step id encountered: ${toolStep.id}`);
33
33
  }
@@ -35,7 +35,7 @@ export function extractToolStepsFromRawStrategy(rawStrategy: RawStrategyJson): T
35
35
  toolSteps.push(toolStep);
36
36
  };
37
37
 
38
- const visitStep = (step: StepJson) => {
38
+ const visitStep = (step: Step) => {
39
39
  switch (step.stepKind) {
40
40
  case CONSTANTS.Enums.StepKind.tool: {
41
41
  addToolStep(step);
@@ -69,8 +69,8 @@ export function extractToolStepsFromRawStrategy(rawStrategy: RawStrategyJson): T
69
69
  }
70
70
 
71
71
 
72
- export function extractRoleMapFromRawStrategy(rawStrategy: RawStrategyJson, toolMap: Map<ToolIdJson, ToolJson>): Map<ResourceRoleIdJson, ResourceRoleJson> {
73
- const roleMap = new Map<ResourceRoleIdJson, ResourceRoleJson>();
72
+ export function extractRoleMapFromRawStrategy(rawStrategy: RawStrategy, toolMap: Map<ToolId, Tool>): Map<ResourceRoleId, ResourceRole> {
73
+ const roleMap = new Map<ResourceRoleId, ResourceRole>();
74
74
  const toolIds = extractToolIdsFromRawStrategy(rawStrategy);
75
75
 
76
76
  for (const toolId of toolIds) {
@@ -78,14 +78,14 @@ export function extractRoleMapFromRawStrategy(rawStrategy: RawStrategyJson, tool
78
78
  if (!tool) continue;
79
79
 
80
80
  for (const [rid, role] of Object.entries(tool.roleSpec.inputRoleValueById)) {
81
- roleMap.set(rid as ResourceRoleIdJson, {
82
- id: rid as ResourceRoleIdJson,
81
+ roleMap.set(rid as ResourceRoleId, {
82
+ id: rid as ResourceRoleId,
83
83
  ...role,
84
84
  });
85
85
  }
86
86
  for (const [rid, role] of Object.entries(tool.roleSpec.outputRoleValueById)) {
87
- roleMap.set(rid as ResourceRoleIdJson, {
88
- id: rid as ResourceRoleIdJson,
87
+ roleMap.set(rid as ResourceRoleId, {
88
+ id: rid as ResourceRoleId,
89
89
  ...role,
90
90
  });
91
91
  }
@@ -94,7 +94,7 @@ export function extractRoleMapFromRawStrategy(rawStrategy: RawStrategyJson, tool
94
94
  return roleMap;
95
95
  }
96
96
 
97
- export function extractSingleNonErrorOutputTypeId(tool: ToolJson): ResourceTypeIdJson | null {
97
+ export function extractSingleNonErrorOutputTypeId(tool: Tool): ResourceTypeId | null {
98
98
  const errorRoleId = CONSTANTS.Cosmos.ROLE_ErrorOutput;
99
99
  const outputEntries = Object.entries(tool.roleSpec.outputRoleValueById).filter(([roleId]) => roleId !== errorRoleId);
100
100
  if (!outputEntries || !outputEntries[0] || outputEntries.length !== 1) {
@@ -106,12 +106,12 @@ export function extractSingleNonErrorOutputTypeId(tool: ToolJson): ResourceTypeI
106
106
 
107
107
 
108
108
 
109
- export function extractResourceMapForType<TResource extends ResourceJson = ResourceJson>(
110
- resourcesByType: Partial<Record<ResourceTypeIdJson, TResource[]>>,
111
- resourceTypeId: ResourceTypeIdJson
112
- ): Map<ResourceIdJson, TResource> {
109
+ export function extractResourceMapForType<TResource extends Resource = Resource>(
110
+ resourcesByType: Partial<Record<ResourceTypeId, TResource[]>>,
111
+ resourceTypeId: ResourceTypeId
112
+ ): Map<ResourceId, TResource> {
113
113
  const resources = resourcesByType[resourceTypeId] ?? [];
114
- const map = new Map<ResourceIdJson, TResource>();
114
+ const map = new Map<ResourceId, TResource>();
115
115
 
116
116
  for (const resource of resources) {
117
117
  map.set(resource.id, resource);
@@ -124,10 +124,10 @@ export function extractResourceMapForType<TResource extends ResourceJson = Resou
124
124
  export function extractIdKeyedNucleusMapForType<
125
125
  TKey extends string = string,
126
126
  TNucleus extends { id: string | number | boolean } = { id: string | number | boolean },
127
- TResource extends ResourceJson = ResourceJson
127
+ TResource extends Resource = Resource
128
128
  >(
129
- resourcesByType: Partial<Record<ResourceTypeIdJson, TResource[]>>,
130
- resourceTypeId: ResourceTypeIdJson,
129
+ resourcesByType: Partial<Record<ResourceTypeId, TResource[]>>,
130
+ resourceTypeId: ResourceTypeId,
131
131
  ): Map<TKey, TNucleus> {
132
132
  const resourceMap = extractResourceMapForType<TResource>(resourcesByType, resourceTypeId);
133
133
  const out = new Map<TKey, TNucleus>();