@toolproof-npm/shared 0.1.49 → 0.1.51

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.
@@ -42,7 +42,7 @@ export declare const CONSTANTS: {
42
42
  readonly workflowSpec: "workflowSpec";
43
43
  };
44
44
  readonly ENGINE: {
45
- readonly GraphRunWorkflow: "GraphRunWorkflow";
45
+ readonly GraphRunStrategy: "GraphRunStrategy";
46
46
  };
47
47
  readonly SPECIALS: {
48
48
  readonly FORMAT_ApplicationJson: "FORMAT-ApplicationJson";
package/dist/constants.js CHANGED
@@ -42,7 +42,7 @@ export const CONSTANTS = {
42
42
  workflowSpec: 'workflowSpec',
43
43
  },
44
44
  ENGINE: {
45
- GraphRunWorkflow: 'GraphRunWorkflow',
45
+ GraphRunStrategy: 'GraphRunStrategy',
46
46
  },
47
47
  SPECIALS: {
48
48
  FORMAT_ApplicationJson: 'FORMAT-ApplicationJson',
package/dist/utils.d.ts CHANGED
@@ -1,3 +1,20 @@
1
- import type { ResourceIdJson, ResourceTypeIdJson, ResourceJson } from '@toolproof-npm/schema';
1
+ import type { ResourceIdJson, ResourceTypeIdJson, ResourceJson, JobJson, ResourcePotentialOutputJson, StrategyStateValueJson, CreationContextValueJson } from '@toolproof-npm/schema';
2
2
  import type { ResourceMap } from './types.js';
3
3
  export declare function extractResourcesByType(resourceMap: ResourceMap, resourceTypeId: ResourceTypeIdJson): Record<ResourceIdJson, ResourceJson>;
4
+ export declare function extractJobMap(resourceMap: ResourceMap): Map<string, JobJson>;
5
+ export type ResolveResult = {
6
+ status: 'materialized';
7
+ entry: ResourceJson;
8
+ path: CreationContextValueJson[];
9
+ } | {
10
+ status: 'blocked-output';
11
+ entry: ResourcePotentialOutputJson;
12
+ path: CreationContextValueJson[];
13
+ } | {
14
+ status: 'unresolved';
15
+ reason: 'missing-entry' | 'cycle' | 'depth-exceeded';
16
+ path: CreationContextValueJson[];
17
+ };
18
+ export declare function resolveResourceChain(strategyState: StrategyStateValueJson, start: CreationContextValueJson, opts?: {
19
+ maxDepth?: number;
20
+ }): ResolveResult;
package/dist/utils.js CHANGED
@@ -6,3 +6,50 @@ export function extractResourcesByType(resourceMap, resourceTypeId) {
6
6
  }
7
7
  return result;
8
8
  }
9
+ export function extractJobMap(resourceMap) {
10
+ const resourceJobMap = extractResourcesByType(resourceMap, 'TYPE-Job');
11
+ const jobMap = new Map();
12
+ Object.values(resourceJobMap).forEach((resource) => {
13
+ if (resource.extractedData?.identity) {
14
+ jobMap.set(resource.extractedData.identity, resource.extractedData);
15
+ }
16
+ });
17
+ return jobMap;
18
+ }
19
+ export function resolveResourceChain(strategyState, start, opts) {
20
+ const maxDepth = opts?.maxDepth ?? 50;
21
+ const visited = new Set();
22
+ const path = [];
23
+ let current = start;
24
+ for (let depth = 0; depth <= maxDepth; depth++) {
25
+ path.push(current);
26
+ const visitKey = `${current.executionId}::${current.resourceRoleId}`;
27
+ if (visited.has(visitKey)) {
28
+ return { status: 'unresolved', reason: 'cycle', path };
29
+ }
30
+ visited.add(visitKey);
31
+ const bucket = strategyState[current.executionId];
32
+ if (!bucket)
33
+ return { status: 'unresolved', reason: 'missing-entry', path };
34
+ const entry = bucket[current.resourceRoleId];
35
+ if (!entry)
36
+ return { status: 'unresolved', reason: 'missing-entry', path };
37
+ if (entry.kind === 'materialized') {
38
+ return { status: 'materialized', entry: entry, path };
39
+ }
40
+ if (entry.kind === 'potential-output') {
41
+ return { status: 'blocked-output', entry: entry, path };
42
+ }
43
+ // potential-input: follow ref backwards
44
+ if (entry.kind === 'potential-input') {
45
+ const rpi = entry.creationContext;
46
+ if (!rpi)
47
+ return { status: 'unresolved', reason: 'missing-entry', path };
48
+ current = rpi;
49
+ continue;
50
+ }
51
+ // Unknown case
52
+ return { status: 'unresolved', reason: 'missing-entry', path };
53
+ }
54
+ return { status: 'unresolved', reason: 'depth-exceeded', path };
55
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toolproof-npm/shared",
3
- "version": "0.1.49",
3
+ "version": "0.1.51",
4
4
  "description": "Core library utilities for ToolProof",
5
5
  "keywords": [
6
6
  "toolproof",
@@ -56,7 +56,7 @@
56
56
  "typescript": "^5.9.3"
57
57
  },
58
58
  "dependencies": {
59
- "@toolproof-npm/schema": "^0.1.40",
59
+ "@toolproof-npm/schema": "^0.1.43",
60
60
  "firebase-admin": "^13.6.0"
61
61
  },
62
62
  "scripts": {