@toolproof-npm/shared 0.1.79 → 0.1.81
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/_lib/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
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,7 @@ export type Role = {
|
|
|
8
8
|
identity: ResourceRoleIdentityJson;
|
|
9
9
|
} & ResourceRoleValueJson;
|
|
10
10
|
export type ResourceMap = Record<ResourceTypeIdentityJson, ResourceJson[]>;
|
|
11
|
-
export type PartialResourceMeta = {
|
|
12
|
-
|
|
13
|
-
resourceTypeRef: ResourceTypeIdentityJson;
|
|
14
|
-
creationContext: {
|
|
15
|
-
resourceRoleRef: ResourceRoleIdentityJson;
|
|
16
|
-
executionRef: ExecutionIdentityJson;
|
|
17
|
-
};
|
|
11
|
+
export type PartialResourceMeta = Omit<ResourceJson, 'kind' | 'timestamp' | 'path' | 'extractedData'> & {
|
|
12
|
+
/** Optional timestamp (for replacing existing resources with same timestamp) */
|
|
18
13
|
timestamp?: string;
|
|
19
14
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ResourceTypeIdentityJson, ResourceJson, ResourcePotentialOutputJson, JsonDataJson } from '@toolproof-npm/schema';
|
|
2
|
+
import type { PartialResourceMeta } from '../types.js';
|
|
2
3
|
/**
|
|
3
4
|
* Generates SHA-256 hash of content
|
|
4
5
|
* @param content The content to hash
|
|
@@ -12,14 +13,6 @@ export declare function generateContentHash(content: string): string;
|
|
|
12
13
|
* @returns The path in format: {resourceTypeRef}/{contentHash}
|
|
13
14
|
*/
|
|
14
15
|
export declare function generateContentAddressedPath(resourceTypeRef: ResourceTypeIdentityJson, content: string): string;
|
|
15
|
-
/**
|
|
16
|
-
* Options for creating a materialized resource from scratch
|
|
17
|
-
* Omits 'kind' (always set to 'materialized'), 'path' (auto-generated), and makes 'timestamp' optional
|
|
18
|
-
*/
|
|
19
|
-
export type CreateMaterializedResourceFromScratchOptions = Omit<ResourceJson, 'kind' | 'timestamp' | 'path'> & {
|
|
20
|
-
/** Optional timestamp (for replacing existing resources with same timestamp) */
|
|
21
|
-
timestamp?: string;
|
|
22
|
-
};
|
|
23
16
|
/**
|
|
24
17
|
* Creates a materialized resource from a potential-output resource.
|
|
25
18
|
* Converts the potential output to a materialized resource by generating a content-addressed path,
|
|
@@ -40,24 +33,27 @@ export type CreateMaterializedResourceFromScratchOptions = Omit<ResourceJson, 'k
|
|
|
40
33
|
export declare function createMaterializedResourceFromPotentialOutput(potentialOutput: ResourcePotentialOutputJson, content: JsonDataJson): ResourceJson;
|
|
41
34
|
/**
|
|
42
35
|
* Creates a materialized resource from scratch (for manual resource creation).
|
|
43
|
-
* Generates a content-addressed path from the
|
|
36
|
+
* Generates a content-addressed path from the content and creates a timestamp.
|
|
44
37
|
* Use this when creating resources manually without a potential-output template.
|
|
45
38
|
*
|
|
46
|
-
* @param
|
|
39
|
+
* @param partialResourceMeta Partial metadata (identity, type, context, optional timestamp)
|
|
40
|
+
* @param content The actual content/data (assigned directly to extractedData)
|
|
47
41
|
* @returns A fully materialized ResourceJson
|
|
48
42
|
*
|
|
49
43
|
* @example
|
|
50
44
|
* ```typescript
|
|
51
|
-
* const materialized = createMaterializedResourceFromScratch(
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
45
|
+
* const materialized = createMaterializedResourceFromScratch(
|
|
46
|
+
* {
|
|
47
|
+
* identity: 'RESOURCE-abc123',
|
|
48
|
+
* resourceTypeRef: 'TYPE-Natural',
|
|
49
|
+
* creationContext: {
|
|
50
|
+
* resourceRoleRef: 'ROLE-Manual',
|
|
51
|
+
* executionRef: 'EXECUTION-Genesis'
|
|
52
|
+
* },
|
|
53
|
+
* timestamp: '2025-01-03T12:00:00.000Z' // optional
|
|
57
54
|
* },
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* });
|
|
55
|
+
* { identity: 42 }
|
|
56
|
+
* );
|
|
61
57
|
* ```
|
|
62
58
|
*/
|
|
63
|
-
export declare function createMaterializedResourceFromScratch(
|
|
59
|
+
export declare function createMaterializedResourceFromScratch(partialResourceMeta: PartialResourceMeta, content: JsonDataJson): ResourceJson;
|
|
@@ -50,30 +50,33 @@ export function createMaterializedResourceFromPotentialOutput(potentialOutput, c
|
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
52
|
* Creates a materialized resource from scratch (for manual resource creation).
|
|
53
|
-
* Generates a content-addressed path from the
|
|
53
|
+
* Generates a content-addressed path from the content and creates a timestamp.
|
|
54
54
|
* Use this when creating resources manually without a potential-output template.
|
|
55
55
|
*
|
|
56
|
-
* @param
|
|
56
|
+
* @param partialResourceMeta Partial metadata (identity, type, context, optional timestamp)
|
|
57
|
+
* @param content The actual content/data (assigned directly to extractedData)
|
|
57
58
|
* @returns A fully materialized ResourceJson
|
|
58
59
|
*
|
|
59
60
|
* @example
|
|
60
61
|
* ```typescript
|
|
61
|
-
* const materialized = createMaterializedResourceFromScratch(
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
62
|
+
* const materialized = createMaterializedResourceFromScratch(
|
|
63
|
+
* {
|
|
64
|
+
* identity: 'RESOURCE-abc123',
|
|
65
|
+
* resourceTypeRef: 'TYPE-Natural',
|
|
66
|
+
* creationContext: {
|
|
67
|
+
* resourceRoleRef: 'ROLE-Manual',
|
|
68
|
+
* executionRef: 'EXECUTION-Genesis'
|
|
69
|
+
* },
|
|
70
|
+
* timestamp: '2025-01-03T12:00:00.000Z' // optional
|
|
67
71
|
* },
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
* });
|
|
72
|
+
* { identity: 42 }
|
|
73
|
+
* );
|
|
71
74
|
* ```
|
|
72
75
|
*/
|
|
73
|
-
export function createMaterializedResourceFromScratch(
|
|
74
|
-
const { identity, resourceTypeRef, creationContext,
|
|
75
|
-
// Generate content-addressed path from the
|
|
76
|
-
const contentString = JSON.stringify(
|
|
76
|
+
export function createMaterializedResourceFromScratch(partialResourceMeta, content) {
|
|
77
|
+
const { identity, resourceTypeRef, creationContext, timestamp } = partialResourceMeta;
|
|
78
|
+
// Generate content-addressed path from the content
|
|
79
|
+
const contentString = JSON.stringify(content);
|
|
77
80
|
const path = generateContentAddressedPath(resourceTypeRef, contentString);
|
|
78
81
|
return {
|
|
79
82
|
identity,
|
|
@@ -82,6 +85,6 @@ export function createMaterializedResourceFromScratch(options) {
|
|
|
82
85
|
kind: 'materialized',
|
|
83
86
|
path,
|
|
84
87
|
timestamp: timestamp ?? new Date().toISOString(),
|
|
85
|
-
extractedData,
|
|
88
|
+
extractedData: content,
|
|
86
89
|
};
|
|
87
90
|
}
|
package/dist/constants.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export declare const CONSTANTS: {
|
|
|
19
19
|
readonly type: "type";
|
|
20
20
|
readonly role: "role";
|
|
21
21
|
readonly job: "job";
|
|
22
|
-
readonly execution: "
|
|
22
|
+
readonly execution: "execution";
|
|
23
23
|
readonly resource: "resource";
|
|
24
24
|
readonly stateless_strategy: "stateless_strategy";
|
|
25
25
|
readonly stateful_strategy: "stateful_strategy";
|
package/dist/constants.js
CHANGED