@toolproof-npm/shared 0.1.52 → 0.1.53
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/constants.d.ts +14 -25
- package/dist/constants.js +15 -26
- package/dist/firebaseAdminHelpers.d.ts +4 -4
- package/dist/firebaseAdminHelpers.js +16 -18
- package/dist/types.d.ts +11 -15
- package/dist/utils.d.ts +8 -8
- package/dist/utils.js +6 -6
- package/package.json +2 -2
package/dist/constants.d.ts
CHANGED
|
@@ -1,46 +1,35 @@
|
|
|
1
1
|
export declare const CONSTANTS: {
|
|
2
2
|
readonly SCHEMA: {
|
|
3
|
-
readonly
|
|
4
|
-
readonly
|
|
3
|
+
readonly ResourceFormat: "ResourceFormat";
|
|
4
|
+
readonly ResourceType: "ResourceType";
|
|
5
5
|
readonly Execution: "Execution";
|
|
6
|
-
readonly
|
|
6
|
+
readonly StrategyState: "StrategyState";
|
|
7
7
|
};
|
|
8
8
|
readonly STORAGE: {
|
|
9
9
|
readonly BUCKETS: {
|
|
10
|
-
readonly tp_shapes: "tp-shapes";
|
|
11
10
|
readonly tp_resources: "tp-resources";
|
|
12
11
|
};
|
|
13
12
|
readonly COLLECTIONS: {
|
|
14
|
-
readonly shapes: "shapes";
|
|
15
13
|
readonly resources: "resources";
|
|
16
|
-
};
|
|
17
|
-
readonly FILTER: {
|
|
18
14
|
readonly members: "members";
|
|
19
|
-
readonly specials: "specials";
|
|
20
15
|
};
|
|
21
16
|
};
|
|
22
|
-
readonly
|
|
23
|
-
readonly
|
|
24
|
-
readonly
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
readonly
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
readonly
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
readonly STEP: {
|
|
17
|
+
readonly TERMINALS: {
|
|
18
|
+
readonly format: "format";
|
|
19
|
+
readonly type: "type";
|
|
20
|
+
readonly role: "role";
|
|
21
|
+
readonly job: "job";
|
|
22
|
+
readonly execution: "executions";
|
|
23
|
+
readonly resource: "resource";
|
|
24
|
+
readonly stateless_strategy: "stateless_strategy";
|
|
25
|
+
readonly stateful_strategy: "stateful_strategy";
|
|
26
|
+
};
|
|
27
|
+
readonly STEPS: {
|
|
34
28
|
readonly work: "work";
|
|
35
29
|
readonly branch: "branch";
|
|
36
30
|
readonly while: "while";
|
|
37
31
|
readonly for: "for";
|
|
38
32
|
};
|
|
39
|
-
readonly WORKFLOW: {
|
|
40
|
-
readonly execution: "execution";
|
|
41
|
-
readonly workflow: "workflow";
|
|
42
|
-
readonly workflowSpec: "workflowSpec";
|
|
43
|
-
};
|
|
44
33
|
readonly ENGINE: {
|
|
45
34
|
readonly GraphRunStrategy: "GraphRunStrategy";
|
|
46
35
|
};
|
package/dist/constants.js
CHANGED
|
@@ -1,46 +1,35 @@
|
|
|
1
1
|
export const CONSTANTS = {
|
|
2
2
|
SCHEMA: {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
ResourceFormat: 'ResourceFormat',
|
|
4
|
+
ResourceType: 'ResourceType',
|
|
5
5
|
Execution: 'Execution',
|
|
6
|
-
|
|
6
|
+
StrategyState: 'StrategyState',
|
|
7
7
|
},
|
|
8
8
|
STORAGE: {
|
|
9
9
|
BUCKETS: {
|
|
10
|
-
tp_shapes: 'tp-shapes',
|
|
11
10
|
tp_resources: 'tp-resources',
|
|
12
11
|
},
|
|
13
12
|
COLLECTIONS: {
|
|
14
|
-
shapes: 'shapes',
|
|
15
13
|
resources: 'resources',
|
|
16
|
-
},
|
|
17
|
-
FILTER: {
|
|
18
14
|
members: 'members',
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
SHAPES: {
|
|
23
|
-
formats: 'formats',
|
|
24
|
-
types: 'types',
|
|
25
|
-
},
|
|
26
|
-
ROLES: {
|
|
27
|
-
roles: 'roles',
|
|
28
|
-
},
|
|
29
|
-
RESOURCES: {
|
|
30
|
-
resources: 'resources',
|
|
31
|
-
jobs: 'jobs',
|
|
15
|
+
},
|
|
32
16
|
},
|
|
33
|
-
|
|
17
|
+
TERMINALS: {
|
|
18
|
+
format: 'format',
|
|
19
|
+
type: 'type',
|
|
20
|
+
role: 'role',
|
|
21
|
+
job: 'job',
|
|
22
|
+
execution: 'executions',
|
|
23
|
+
resource: 'resource',
|
|
24
|
+
stateless_strategy: 'stateless_strategy',
|
|
25
|
+
stateful_strategy: 'stateful_strategy',
|
|
26
|
+
},
|
|
27
|
+
STEPS: {
|
|
34
28
|
work: 'work',
|
|
35
29
|
branch: 'branch',
|
|
36
30
|
while: 'while',
|
|
37
31
|
for: 'for',
|
|
38
32
|
},
|
|
39
|
-
WORKFLOW: {
|
|
40
|
-
execution: 'execution',
|
|
41
|
-
workflow: 'workflow',
|
|
42
|
-
workflowSpec: 'workflowSpec',
|
|
43
|
-
},
|
|
44
33
|
ENGINE: {
|
|
45
34
|
GraphRunStrategy: 'GraphRunStrategy',
|
|
46
35
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
export declare function
|
|
1
|
+
import type { ResourceTypeIdentityJson } from '@toolproof-npm/schema';
|
|
2
|
+
import type { StepConst, ResourceMap, TerminalConst } from './types.d.ts';
|
|
3
|
+
export declare function getNewIdentity(identifiable: TerminalConst | StepConst): string;
|
|
4
4
|
export declare function listResources(// ATTENTION: must clean up
|
|
5
|
-
|
|
5
|
+
resourceTypeRefs: ResourceTypeIdentityJson[]): Promise<ResourceMap>;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { CONSTANTS } from './constants.js';
|
|
2
2
|
import { dbAdmin, storageAdmin } from "./firebaseAdminInit.js";
|
|
3
|
-
export function
|
|
3
|
+
export function getNewIdentity(identifiable) {
|
|
4
4
|
const base = identifiable.toUpperCase();
|
|
5
5
|
const normalized = base.endsWith('S') ? base.slice(0, -1) : base;
|
|
6
6
|
const prefix = normalized + '-';
|
|
7
|
-
const docRef = dbAdmin.collection(CONSTANTS.STORAGE.COLLECTIONS.
|
|
7
|
+
const docRef = dbAdmin.collection(CONSTANTS.STORAGE.COLLECTIONS.resources).doc(identifiable).collection(CONSTANTS.STORAGE.COLLECTIONS.members).doc();
|
|
8
8
|
return prefix + docRef.id;
|
|
9
9
|
}
|
|
10
10
|
export async function listResources(// ATTENTION: must clean up
|
|
11
|
-
|
|
11
|
+
resourceTypeRefs) {
|
|
12
12
|
const bucket = storageAdmin.bucket(CONSTANTS.STORAGE.BUCKETS.tp_resources);
|
|
13
|
-
async function fetchFilesUnder(
|
|
14
|
-
const prefix = `${
|
|
13
|
+
async function fetchFilesUnder(resourceTypeRef) {
|
|
14
|
+
const prefix = `${resourceTypeRef}/`;
|
|
15
15
|
const [found] = await bucket.getFiles({ prefix });
|
|
16
16
|
const files = found.filter(f => {
|
|
17
17
|
const name = f.name || '';
|
|
@@ -34,8 +34,8 @@ resourceTypeIds) {
|
|
|
34
34
|
}));
|
|
35
35
|
return items.filter(Boolean);
|
|
36
36
|
}
|
|
37
|
-
const entries = await Promise.all(
|
|
38
|
-
const rows = await fetchFilesUnder(
|
|
37
|
+
const entries = await Promise.all(resourceTypeRefs.map(async (resourceTypeRef) => {
|
|
38
|
+
const rows = await fetchFilesUnder(resourceTypeRef);
|
|
39
39
|
const items = rows.map(({ data, meta, name }) => {
|
|
40
40
|
const flat = meta?.metadata ?? {};
|
|
41
41
|
// Reconstruct nested object from flattened keys (dot and array index notation)
|
|
@@ -91,18 +91,16 @@ resourceTypeIds) {
|
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
const identity = root.identity;
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
const
|
|
97
|
-
const executionId = (root.creationContext?.executionId ?? root.executionId);
|
|
94
|
+
// const resourceTypeRef = root.resourceTypeRef; // we already have this
|
|
95
|
+
const resourceRoleRef = root.creationContext.resourceRoleRef;
|
|
96
|
+
const executionRef = root.creationContext.executionRef;
|
|
98
97
|
const kind = root.kind;
|
|
99
98
|
const path = root.path;
|
|
100
99
|
const timestamp = root.timestamp;
|
|
101
100
|
const missing = [
|
|
102
101
|
['identity', identity],
|
|
103
|
-
['
|
|
104
|
-
['
|
|
105
|
-
['executionId', executionId],
|
|
102
|
+
['resourceRoleRef', resourceRoleRef],
|
|
103
|
+
['executionRef', executionRef],
|
|
106
104
|
['kind', kind],
|
|
107
105
|
['timestamp', timestamp],
|
|
108
106
|
['path', path],
|
|
@@ -113,10 +111,10 @@ resourceTypeIds) {
|
|
|
113
111
|
}
|
|
114
112
|
return {
|
|
115
113
|
identity,
|
|
116
|
-
|
|
114
|
+
resourceTypeRef,
|
|
117
115
|
creationContext: {
|
|
118
|
-
|
|
119
|
-
|
|
116
|
+
resourceRoleRef,
|
|
117
|
+
executionRef,
|
|
120
118
|
},
|
|
121
119
|
kind: kind,
|
|
122
120
|
path: path,
|
|
@@ -124,7 +122,7 @@ resourceTypeIds) {
|
|
|
124
122
|
extractedData: data,
|
|
125
123
|
};
|
|
126
124
|
});
|
|
127
|
-
return [
|
|
125
|
+
return [resourceTypeRef, items];
|
|
128
126
|
}));
|
|
129
127
|
return Object.fromEntries(entries);
|
|
130
128
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ExecutionIdentityJson, ResourceIdentityJson, ResourceJson, ResourceRoleIdentityJson, ResourceRoleValueJson, ResourceTypeIdentityJson } from '@toolproof-npm/schema';
|
|
2
2
|
import { CONSTANTS } from './constants.js';
|
|
3
|
-
export type BucketConst = typeof CONSTANTS.STORAGE.BUCKETS.
|
|
4
|
-
export type CollectionConst = typeof CONSTANTS.STORAGE.COLLECTIONS.
|
|
5
|
-
export type
|
|
6
|
-
export type
|
|
7
|
-
export type ResourceRoleConst = typeof CONSTANTS.ROLES.roles;
|
|
8
|
-
export type ResourceConst = typeof CONSTANTS.RESOURCES.resources;
|
|
9
|
-
export type StepConst = typeof CONSTANTS.STEP.work | typeof CONSTANTS.STEP.branch | typeof CONSTANTS.STEP.while | typeof CONSTANTS.STEP.for;
|
|
10
|
-
export type WorkflowConst = typeof CONSTANTS.WORKFLOW.workflow | typeof CONSTANTS.WORKFLOW.workflowSpec | typeof CONSTANTS.WORKFLOW.execution;
|
|
3
|
+
export type BucketConst = typeof CONSTANTS.STORAGE.BUCKETS.tp_resources;
|
|
4
|
+
export type CollectionConst = typeof CONSTANTS.STORAGE.COLLECTIONS.resources | typeof CONSTANTS.STORAGE.COLLECTIONS.members;
|
|
5
|
+
export type TerminalConst = typeof CONSTANTS.TERMINALS.format | typeof CONSTANTS.TERMINALS.type | typeof CONSTANTS.TERMINALS.role | typeof CONSTANTS.TERMINALS.job | typeof CONSTANTS.TERMINALS.execution | typeof CONSTANTS.TERMINALS.resource | typeof CONSTANTS.TERMINALS.stateless_strategy | typeof CONSTANTS.TERMINALS.stateful_strategy;
|
|
6
|
+
export type StepConst = typeof CONSTANTS.STEPS.work | typeof CONSTANTS.STEPS.branch | typeof CONSTANTS.STEPS.while | typeof CONSTANTS.STEPS.for;
|
|
11
7
|
export type Role = {
|
|
12
|
-
|
|
8
|
+
identity: ResourceRoleIdentityJson;
|
|
13
9
|
} & ResourceRoleValueJson;
|
|
14
|
-
export type ResourceMap = Record<
|
|
10
|
+
export type ResourceMap = Record<ResourceTypeIdentityJson, ResourceJson[]>;
|
|
15
11
|
export type PartialResourceMeta = {
|
|
16
|
-
identity:
|
|
17
|
-
|
|
12
|
+
identity: ResourceIdentityJson;
|
|
13
|
+
resourceTypeRef: ResourceTypeIdentityJson;
|
|
18
14
|
creationContext: {
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
resourceRoleRef: ResourceRoleIdentityJson;
|
|
16
|
+
executionRef: ExecutionIdentityJson;
|
|
21
17
|
};
|
|
22
18
|
};
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ResourceIdentityJson, ResourceTypeIdentityJson, ResourceJson, ResourceMissingJson, JobJson, ResourcePotentialOutputJson, StrategyStateJson, CreationContextJson } from '@toolproof-npm/schema';
|
|
2
2
|
import type { ResourceMap } from './types.js';
|
|
3
|
-
export declare function extractResourcesByType(resourceMap: ResourceMap,
|
|
4
|
-
export declare function extractJobMap(resourceMap: ResourceMap): Map
|
|
3
|
+
export declare function extractResourcesByType(resourceMap: ResourceMap, resourceTypeRef: ResourceTypeIdentityJson): Record<ResourceIdentityJson, ResourceJson>;
|
|
4
|
+
export declare function extractJobMap(resourceMap: ResourceMap): Map<`JOB-${string}`, JobJson>;
|
|
5
5
|
export type ResolveResult = {
|
|
6
6
|
status: 'materialized';
|
|
7
7
|
entry: ResourceJson;
|
|
8
|
-
path:
|
|
8
|
+
path: CreationContextJson[];
|
|
9
9
|
} | {
|
|
10
10
|
status: 'missing';
|
|
11
11
|
entry: ResourceMissingJson;
|
|
12
|
-
path:
|
|
12
|
+
path: CreationContextJson[];
|
|
13
13
|
} | {
|
|
14
14
|
status: 'blocked-output';
|
|
15
15
|
entry: ResourcePotentialOutputJson;
|
|
16
|
-
path:
|
|
16
|
+
path: CreationContextJson[];
|
|
17
17
|
} | {
|
|
18
18
|
status: 'unresolved';
|
|
19
19
|
reason: 'missing-entry' | 'cycle' | 'depth-exceeded';
|
|
20
|
-
path:
|
|
20
|
+
path: CreationContextJson[];
|
|
21
21
|
};
|
|
22
|
-
export declare function resolveResourceChain(strategyState:
|
|
22
|
+
export declare function resolveResourceChain(strategyState: StrategyStateJson, start: CreationContextJson, opts?: {
|
|
23
23
|
maxDepth?: number;
|
|
24
24
|
}): ResolveResult;
|
package/dist/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export function extractResourcesByType(resourceMap,
|
|
2
|
-
const resources = resourceMap[
|
|
1
|
+
export function extractResourcesByType(resourceMap, resourceTypeRef) {
|
|
2
|
+
const resources = resourceMap[resourceTypeRef] ?? [];
|
|
3
3
|
const result = {};
|
|
4
4
|
for (const resource of resources) {
|
|
5
5
|
result[resource.identity] = resource;
|
|
@@ -11,7 +11,7 @@ export function extractJobMap(resourceMap) {
|
|
|
11
11
|
const jobMap = new Map();
|
|
12
12
|
Object.values(resourceJobMap).forEach((resource) => {
|
|
13
13
|
if (resource.extractedData?.identity) {
|
|
14
|
-
jobMap.set(resource.extractedData.identity, resource.extractedData);
|
|
14
|
+
jobMap.set(resource.extractedData.identity, resource.extractedData); // ATTENTION: why do we need type assertion here?
|
|
15
15
|
}
|
|
16
16
|
});
|
|
17
17
|
return jobMap;
|
|
@@ -23,15 +23,15 @@ export function resolveResourceChain(strategyState, start, opts) {
|
|
|
23
23
|
let current = start;
|
|
24
24
|
for (let depth = 0; depth <= maxDepth; depth++) {
|
|
25
25
|
path.push(current);
|
|
26
|
-
const visitKey = `${current.
|
|
26
|
+
const visitKey = `${current.executionRef}::${current.resourceRoleRef}`;
|
|
27
27
|
if (visited.has(visitKey)) {
|
|
28
28
|
return { status: 'unresolved', reason: 'cycle', path };
|
|
29
29
|
}
|
|
30
30
|
visited.add(visitKey);
|
|
31
|
-
const bucket = strategyState[current.
|
|
31
|
+
const bucket = strategyState[current.executionRef];
|
|
32
32
|
if (!bucket)
|
|
33
33
|
return { status: 'unresolved', reason: 'missing-entry', path };
|
|
34
|
-
const entry = bucket[current.
|
|
34
|
+
const entry = bucket[current.resourceRoleRef];
|
|
35
35
|
if (!entry)
|
|
36
36
|
return { status: 'unresolved', reason: 'missing-entry', path };
|
|
37
37
|
if (entry.kind === 'materialized') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toolproof-npm/shared",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.53",
|
|
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.
|
|
59
|
+
"@toolproof-npm/schema": "^0.1.45",
|
|
60
60
|
"firebase-admin": "^13.6.0"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|