@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.
- package/dist/artifacts/artifacts.d.ts +2 -2
- package/dist/artifacts/artifacts.js +2 -2
- package/dist/artifacts/artifacts.js.map +1 -1
- package/dist/integrations/firebase/createThreadedStrategy.d.ts +3 -0
- package/dist/integrations/firebase/createThreadedStrategy.d.ts.map +1 -0
- package/dist/integrations/firebase/createThreadedStrategy.js +9 -0
- package/dist/integrations/firebase/createThreadedStrategy.js.map +1 -0
- package/dist/integrations/firebase/firebaseAdminHelpers.d.ts.map +1 -1
- package/dist/integrations/firebase/firebaseAdminHelpers.js +15 -12
- package/dist/integrations/firebase/firebaseAdminHelpers.js.map +1 -1
- package/dist/utils/bindInputRoleToResource.d.ts +4 -4
- package/dist/utils/bindInputRoleToResource.d.ts.map +1 -1
- package/dist/utils/bindInputRoleToResource.js.map +1 -1
- package/dist/utils/creation/threadedStrategyCreation.d.ts +19 -0
- package/dist/utils/creation/threadedStrategyCreation.d.ts.map +1 -0
- package/dist/utils/creation/threadedStrategyCreation.js +17 -0
- package/dist/utils/creation/threadedStrategyCreation.js.map +1 -0
- package/dist/utils/extractData.d.ts +5 -5
- package/dist/utils/extractData.d.ts.map +1 -1
- package/dist/utils/extractData.js +6 -6
- package/dist/utils/extractData.js.map +1 -1
- package/dist/utils/roleSpec.d.ts +7 -2
- package/dist/utils/roleSpec.d.ts.map +1 -1
- package/dist/utils/roleSpec.js.map +1 -1
- package/dist/utils/strategyState.d.ts +5 -4
- package/dist/utils/strategyState.d.ts.map +1 -1
- package/dist/utils/strategyState.js.map +1 -1
- package/package.json +4 -4
- package/src/artifacts/artifacts.ts +2 -2
- package/src/integrations/firebase/createThreadedStrategy.ts +19 -0
- package/src/integrations/firebase/firebaseAdminHelpers.ts +21 -12
- package/src/utils/bindInputRoleToResource.ts +10 -9
- package/src/utils/creation/threadedStrategyCreation.ts +42 -0
- package/src/utils/extractData.ts +7 -7
- package/src/utils/roleSpec.ts +6 -2
- package/src/utils/strategyState.ts +12 -11
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/integrations/firebase/createRunnableStrategy.d.ts +0 -3
- package/dist/integrations/firebase/createRunnableStrategy.d.ts.map +0 -1
- package/dist/integrations/firebase/createRunnableStrategy.js +0 -9
- package/dist/integrations/firebase/createRunnableStrategy.js.map +0 -1
- package/dist/utils/creation/runnableStrategyCreation.d.ts +0 -4
- package/dist/utils/creation/runnableStrategyCreation.d.ts.map +0 -1
- package/dist/utils/creation/runnableStrategyCreation.js +0 -17
- package/dist/utils/creation/runnableStrategyCreation.js.map +0 -1
- package/src/integrations/firebase/createRunnableStrategy.ts +0 -18
- package/src/utils/creation/runnableStrategyCreation.ts +0 -28
package/src/utils/extractData.ts
CHANGED
|
@@ -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
|
|
23
|
-
const toolSteps =
|
|
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
|
|
32
|
-
return extractToolStepsFromStrategy(
|
|
31
|
+
export function extractToolStepsFromUnthreadedStrategy(unthreadedStrategy: StrategyStepGraph): ToolStep[] {
|
|
32
|
+
return extractToolStepsFromStrategy(unthreadedStrategy);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
|
|
36
|
-
export function
|
|
36
|
+
export function extractRoleMapFromUnthreadedStrategy(unthreadedStrategy: StrategyStepGraph, toolMap: Map<ToolId, Tool>): Map<RoleName, ToolRoleDescriptor> {
|
|
37
37
|
const roleMap = new Map<RoleName, ToolRoleDescriptor>();
|
|
38
|
-
const toolIds =
|
|
38
|
+
const toolIds = extractToolIdsFromUnthreadedStrategy(unthreadedStrategy);
|
|
39
39
|
|
|
40
40
|
for (const toolId of toolIds) {
|
|
41
41
|
const tool = toolMap.get(toolId);
|
package/src/utils/roleSpec.ts
CHANGED
|
@@ -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:
|
|
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:
|
|
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:
|
|
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:
|
|
25
|
+
export function setStrategyStateEntry<TStrategyState extends StrategyStateLike>(
|
|
26
|
+
strategyState: TStrategyState,
|
|
26
27
|
context: CreationContext,
|
|
27
28
|
entry: StrategyStateInputEntry,
|
|
28
|
-
):
|
|
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:
|
|
41
|
+
export function clearStrategyStateEntry<TStrategyState extends StrategyStateLike>(
|
|
42
|
+
strategyState: TStrategyState,
|
|
42
43
|
context: CreationContext,
|
|
43
|
-
):
|
|
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
|
}
|