@toolproof-core/lib 1.0.33 → 1.0.34

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 (47) hide show
  1. package/dist/artifacts/artifacts.d.ts +2 -2
  2. package/dist/artifacts/artifacts.js +2 -2
  3. package/dist/artifacts/artifacts.js.map +1 -1
  4. package/dist/integrations/firebase/createThreadedStrategy.d.ts +3 -0
  5. package/dist/integrations/firebase/createThreadedStrategy.d.ts.map +1 -0
  6. package/dist/integrations/firebase/createThreadedStrategy.js +9 -0
  7. package/dist/integrations/firebase/createThreadedStrategy.js.map +1 -0
  8. package/dist/integrations/firebase/firebaseAdminHelpers.d.ts.map +1 -1
  9. package/dist/integrations/firebase/firebaseAdminHelpers.js +15 -12
  10. package/dist/integrations/firebase/firebaseAdminHelpers.js.map +1 -1
  11. package/dist/utils/bindInputRoleToResource.d.ts +4 -4
  12. package/dist/utils/bindInputRoleToResource.d.ts.map +1 -1
  13. package/dist/utils/bindInputRoleToResource.js.map +1 -1
  14. package/dist/utils/creation/threadedStrategyCreation.d.ts +19 -0
  15. package/dist/utils/creation/threadedStrategyCreation.d.ts.map +1 -0
  16. package/dist/utils/creation/threadedStrategyCreation.js +17 -0
  17. package/dist/utils/creation/threadedStrategyCreation.js.map +1 -0
  18. package/dist/utils/extractData.d.ts +5 -5
  19. package/dist/utils/extractData.d.ts.map +1 -1
  20. package/dist/utils/extractData.js +6 -6
  21. package/dist/utils/extractData.js.map +1 -1
  22. package/dist/utils/roleSpec.d.ts +7 -2
  23. package/dist/utils/roleSpec.d.ts.map +1 -1
  24. package/dist/utils/roleSpec.js.map +1 -1
  25. package/dist/utils/strategyState.d.ts +5 -4
  26. package/dist/utils/strategyState.d.ts.map +1 -1
  27. package/dist/utils/strategyState.js.map +1 -1
  28. package/package.json +4 -4
  29. package/src/artifacts/artifacts.ts +2 -2
  30. package/src/integrations/firebase/createThreadedStrategy.ts +19 -0
  31. package/src/integrations/firebase/firebaseAdminHelpers.ts +21 -12
  32. package/src/utils/bindInputRoleToResource.ts +10 -9
  33. package/src/utils/creation/threadedStrategyCreation.ts +42 -0
  34. package/src/utils/extractData.ts +7 -7
  35. package/src/utils/roleSpec.ts +6 -2
  36. package/src/utils/strategyState.ts +12 -11
  37. package/tsconfig.tsbuildinfo +1 -1
  38. package/dist/integrations/firebase/createRunnableStrategy.d.ts +0 -3
  39. package/dist/integrations/firebase/createRunnableStrategy.d.ts.map +0 -1
  40. package/dist/integrations/firebase/createRunnableStrategy.js +0 -9
  41. package/dist/integrations/firebase/createRunnableStrategy.js.map +0 -1
  42. package/dist/utils/creation/runnableStrategyCreation.d.ts +0 -4
  43. package/dist/utils/creation/runnableStrategyCreation.d.ts.map +0 -1
  44. package/dist/utils/creation/runnableStrategyCreation.js +0 -17
  45. package/dist/utils/creation/runnableStrategyCreation.js.map +0 -1
  46. package/src/integrations/firebase/createRunnableStrategy.ts +0 -18
  47. package/src/utils/creation/runnableStrategyCreation.ts +0 -28
@@ -1,7 +1,6 @@
1
1
  import type {
2
2
  RoleName,
3
3
  RoleValue,
4
- Strategy,
5
4
  ToolId,
6
5
  Tool,
7
6
  ToolStep,
@@ -15,12 +14,13 @@ import {
15
14
  getInputRoleEntries,
16
15
  getOutputRoleEntries,
17
16
  toToolRoleDescriptor,
17
+ type StrategyStepGraph,
18
18
  type ToolRoleDescriptor,
19
19
  } from './roleSpec.js';
20
20
 
21
21
 
22
- export function extractToolIdsFromRawStrategy(rawStrategy: Strategy): ToolId[] {
23
- const toolSteps = extractToolStepsFromRawStrategy(rawStrategy);
22
+ export function extractToolIdsFromUnthreadedStrategy(unthreadedStrategy: StrategyStepGraph): ToolId[] {
23
+ const toolSteps = extractToolStepsFromUnthreadedStrategy(unthreadedStrategy);
24
24
  const ids = new Set<ToolId>();
25
25
  for (const jStep of toolSteps) {
26
26
  ids.add(jStep.toolId);
@@ -28,14 +28,14 @@ export function extractToolIdsFromRawStrategy(rawStrategy: Strategy): ToolId[] {
28
28
  return Array.from(ids);
29
29
  }
30
30
 
31
- export function extractToolStepsFromRawStrategy(rawStrategy: Strategy): ToolStep[] {
32
- return extractToolStepsFromStrategy(rawStrategy);
31
+ export function extractToolStepsFromUnthreadedStrategy(unthreadedStrategy: StrategyStepGraph): ToolStep[] {
32
+ return extractToolStepsFromStrategy(unthreadedStrategy);
33
33
  }
34
34
 
35
35
 
36
- export function extractRoleMapFromRawStrategy(rawStrategy: Strategy, toolMap: Map<ToolId, Tool>): Map<RoleName, ToolRoleDescriptor> {
36
+ export function extractRoleMapFromUnthreadedStrategy(unthreadedStrategy: StrategyStepGraph, toolMap: Map<ToolId, Tool>): Map<RoleName, ToolRoleDescriptor> {
37
37
  const roleMap = new Map<RoleName, ToolRoleDescriptor>();
38
- const toolIds = extractToolIdsFromRawStrategy(rawStrategy);
38
+ const toolIds = extractToolIdsFromUnthreadedStrategy(unthreadedStrategy);
39
39
 
40
40
  for (const toolId of toolIds) {
41
41
  const tool = toolMap.get(toolId);
@@ -1,12 +1,16 @@
1
1
  import type {
2
2
  RoleName,
3
3
  RoleValue,
4
- Strategy,
5
4
  Step,
5
+ StepArrayArray,
6
6
  Tool,
7
7
  ToolStep,
8
8
  } from '@toolproof-core/schema';
9
9
 
10
+ export type StrategyStepGraph =
11
+ | { steps: Step[] }
12
+ | { stepsByThreadIndex: StepArrayArray };
13
+
10
14
  export interface ToolRoleDescriptor extends RoleValue {
11
15
  id: RoleName;
12
16
  name: string;
@@ -36,7 +40,7 @@ export function toToolRoleDescriptor([roleName, roleValue]: [RoleName, RoleValue
36
40
  };
37
41
  }
38
42
 
39
- export function extractToolStepsFromStrategy(strategy: Strategy): ToolStep[] {
43
+ export function extractToolStepsFromStrategy(strategy: StrategyStepGraph): ToolStep[] {
40
44
  const toolSteps: ToolStep[] = [];
41
45
 
42
46
  const visitStep = (step: Step) => {
@@ -6,26 +6,27 @@ import type {
6
6
  } from '@toolproof-core/schema';
7
7
 
8
8
  export type StrategyState = Strategy['strategyState'];
9
+ export type StrategyStateLike = Record<string, Record<string, unknown>>;
9
10
 
10
11
  export function getStrategyStateBucket(
11
- strategyState: StrategyState,
12
+ strategyState: StrategyStateLike,
12
13
  toolStepPath: CreationContext['toolStepPath'],
13
14
  ): StrategyStateInputEntryByRoleName | undefined {
14
- return strategyState[toolStepPath];
15
+ return strategyState[toolStepPath] as StrategyStateInputEntryByRoleName | undefined;
15
16
  }
16
17
 
17
18
  export function getStrategyStateEntry(
18
- strategyState: StrategyState,
19
+ strategyState: StrategyStateLike,
19
20
  context: CreationContext,
20
21
  ): StrategyStateInputEntry | undefined {
21
22
  return getStrategyStateBucket(strategyState, context.toolStepPath)?.[context.roleName];
22
23
  }
23
24
 
24
- export function setStrategyStateEntry(
25
- strategyState: StrategyState,
25
+ export function setStrategyStateEntry<TStrategyState extends StrategyStateLike>(
26
+ strategyState: TStrategyState,
26
27
  context: CreationContext,
27
28
  entry: StrategyStateInputEntry,
28
- ): StrategyState {
29
+ ): TStrategyState {
29
30
  const bucket = getStrategyStateBucket(strategyState, context.toolStepPath) ?? {};
30
31
 
31
32
  return {
@@ -34,13 +35,13 @@ export function setStrategyStateEntry(
34
35
  ...bucket,
35
36
  [context.roleName]: entry,
36
37
  },
37
- };
38
+ } as TStrategyState;
38
39
  }
39
40
 
40
- export function clearStrategyStateEntry(
41
- strategyState: StrategyState,
41
+ export function clearStrategyStateEntry<TStrategyState extends StrategyStateLike>(
42
+ strategyState: TStrategyState,
42
43
  context: CreationContext,
43
- ): StrategyState {
44
+ ): TStrategyState {
44
45
  const bucket = getStrategyStateBucket(strategyState, context.toolStepPath);
45
46
  if (!bucket || !(context.roleName in bucket)) {
46
47
  return strategyState;
@@ -52,5 +53,5 @@ export function clearStrategyStateEntry(
52
53
  return {
53
54
  ...strategyState,
54
55
  [context.toolStepPath]: nextBucket,
55
- };
56
+ } as TStrategyState;
56
57
  }