@toolproof-npm/shared 0.1.83 → 0.1.86

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.
@@ -1,5 +1,5 @@
1
1
  import type { ResourceIdentityJson, ResourceTypeIdentityJson, ResourceJson, ResourceMissingJson, JobJson, ResourcePotentialOutputJson, StrategyStateJson, CreationContextJson } from '@toolproof-npm/schema';
2
- import type { ResourceMap } from '../types.js';
2
+ import type { ResourceMap } from '../../types.js';
3
3
  export declare function extractResourcesByType(resourceMap: ResourceMap, resourceTypeRef: ResourceTypeIdentityJson): Record<ResourceIdentityJson, ResourceJson>;
4
4
  export declare function extractJobMap(resourceMap: ResourceMap): Map<`JOB-${string}`, JobJson>;
5
5
  export type ResolveResult = {
@@ -1,5 +1,5 @@
1
1
  import type { ResourceTypeIdentityJson } from '@toolproof-npm/schema';
2
- import type { StepConst, ResourceMap, TerminalConst } from './_lib/types.js';
2
+ import type { StepConst, ResourceMap, TerminalConst } from './types.js';
3
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>;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * as CONSTANTS from './constants.js';
2
- export * as TYPES from './_lib/types.js';
2
+ export * as TYPES from './types.js';
3
3
  export * as UTILS from './_lib/utils/utils.js';
4
4
  export * as RESOURCE_CREATION from './_lib/utils/resourceCreation.js';
5
5
  export * from './firebaseAdminHelpers.js';
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export * as CONSTANTS from './constants.js';
2
- export * as TYPES from './_lib/types.js';
2
+ export * as TYPES from './types.js';
3
3
  export * as UTILS from './_lib/utils/utils.js';
4
4
  export * as RESOURCE_CREATION from './_lib/utils/resourceCreation.js';
5
5
  export * from './firebaseAdminHelpers.js';
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ExecutionIdentityJson, ResourceIdentityJson, ResourceJson, ResourceRoleIdentityJson, ResourceRoleValueJson, ResourceTypeIdentityJson } from '@toolproof-npm/schema';
1
+ import type { ResourceJson, ResourceRoleIdentityJson, ResourceRoleValueJson, ResourceTypeIdentityJson } from '@toolproof-npm/schema';
2
2
  import { CONSTANTS } from './constants.js';
3
3
  export type BucketConst = typeof CONSTANTS.STORAGE.BUCKETS.tp_resources;
4
4
  export type CollectionConst = keyof typeof CONSTANTS.STORAGE.COLLECTIONS;
@@ -8,12 +8,3 @@ export type Role = {
8
8
  identity: ResourceRoleIdentityJson;
9
9
  } & ResourceRoleValueJson;
10
10
  export type ResourceMap = Record<ResourceTypeIdentityJson, ResourceJson[]>;
11
- export type PartialResourceMeta = {
12
- identity: ResourceIdentityJson;
13
- resourceTypeRef: ResourceTypeIdentityJson;
14
- creationContext: {
15
- resourceRoleRef: ResourceRoleIdentityJson;
16
- executionRef: ExecutionIdentityJson;
17
- };
18
- timestamp?: string;
19
- };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toolproof-npm/shared",
3
- "version": "0.1.83",
3
+ "version": "0.1.86",
4
4
  "description": "Core library utilities for ToolProof",
5
5
  "keywords": [
6
6
  "toolproof",
package/dist/utils.d.ts DELETED
@@ -1,24 +0,0 @@
1
- import type { ResourceIdentityJson, ResourceTypeIdentityJson, ResourceJson, ResourceMissingJson, JobJson, ResourcePotentialOutputJson, StrategyStateJson, CreationContextJson } from '@toolproof-npm/schema';
2
- import type { ResourceMap } from './types.js';
3
- export declare function extractResourcesByType(resourceMap: ResourceMap, resourceTypeRef: ResourceTypeIdentityJson): Record<ResourceIdentityJson, ResourceJson>;
4
- export declare function extractJobMap(resourceMap: ResourceMap): Map<`JOB-${string}`, JobJson>;
5
- export type ResolveResult = {
6
- status: 'materialized';
7
- entry: ResourceJson;
8
- path: CreationContextJson[];
9
- } | {
10
- status: 'missing';
11
- entry: ResourceMissingJson;
12
- path: CreationContextJson[];
13
- } | {
14
- status: 'blocked-output';
15
- entry: ResourcePotentialOutputJson;
16
- path: CreationContextJson[];
17
- } | {
18
- status: 'unresolved';
19
- reason: 'missing-entry' | 'cycle' | 'depth-exceeded';
20
- path: CreationContextJson[];
21
- };
22
- export declare function resolveResourceChain(strategyState: StrategyStateJson, start: CreationContextJson, opts?: {
23
- maxDepth?: number;
24
- }): ResolveResult;
package/dist/utils.js DELETED
@@ -1,58 +0,0 @@
1
- export function extractResourcesByType(resourceMap, resourceTypeRef) {
2
- const resources = resourceMap[resourceTypeRef] ?? [];
3
- const result = {};
4
- for (const resource of resources) {
5
- result[resource.identity] = resource;
6
- }
7
- return result;
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); // ATTENTION: why do we need type assertion here?
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.executionRef}::${current.resourceRoleRef}`;
27
- if (visited.has(visitKey)) {
28
- return { status: 'unresolved', reason: 'cycle', path };
29
- }
30
- visited.add(visitKey);
31
- const bucket = strategyState[current.executionRef];
32
- if (!bucket)
33
- return { status: 'unresolved', reason: 'missing-entry', path };
34
- const entry = bucket[current.resourceRoleRef];
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 === 'missing') {
41
- return { status: 'missing', entry: entry, path };
42
- }
43
- if (entry.kind === 'potential-output') {
44
- return { status: 'blocked-output', entry: entry, path };
45
- }
46
- // potential-input: follow ref backwards
47
- if (entry.kind === 'potential-input') {
48
- const rpi = entry.creationContext;
49
- if (!rpi)
50
- return { status: 'unresolved', reason: 'missing-entry', path };
51
- current = rpi;
52
- continue;
53
- }
54
- // Unknown case
55
- return { status: 'unresolved', reason: 'missing-entry', path };
56
- }
57
- return { status: 'unresolved', reason: 'depth-exceeded', path };
58
- }