@toolproof-npm/shared 0.1.81 → 0.1.83

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.
@@ -8,7 +8,3 @@ export type Role = {
8
8
  identity: ResourceRoleIdentityJson;
9
9
  } & ResourceRoleValueJson;
10
10
  export type ResourceMap = Record<ResourceTypeIdentityJson, ResourceJson[]>;
11
- export type PartialResourceMeta = Omit<ResourceJson, 'kind' | 'timestamp' | 'path' | 'extractedData'> & {
12
- /** Optional timestamp (for replacing existing resources with same timestamp) */
13
- timestamp?: string;
14
- };
@@ -1,5 +1,4 @@
1
1
  import type { ResourceTypeIdentityJson, ResourceJson, ResourcePotentialOutputJson, JsonDataJson } from '@toolproof-npm/schema';
2
- import type { PartialResourceMeta } from '../types.js';
3
2
  /**
4
3
  * Generates SHA-256 hash of content
5
4
  * @param content The content to hash
@@ -14,46 +13,21 @@ export declare function generateContentHash(content: string): string;
14
13
  */
15
14
  export declare function generateContentAddressedPath(resourceTypeRef: ResourceTypeIdentityJson, content: string): string;
16
15
  /**
17
- * Creates a materialized resource from a potential-output resource.
18
- * Converts the potential output to a materialized resource by generating a content-addressed path,
19
- * assigning the content as extractedData, and creating a timestamp.
16
+ * Creates a materialized resource from a potential-output resource and content.
17
+ * Generates a content-addressed path from the content.
20
18
  *
21
19
  * @param potentialOutput The potential-output resource to materialize
22
- * @param content The actual content produced by the job (assigned directly to extractedData)
23
- * @returns A fully materialized ResourceJson
24
- *
25
- * @example
26
- * ```typescript
27
- * const materialized = createMaterializedResourceFromPotentialOutput(
28
- * potentialOutput,
29
- * { identity: 42, someData: "result" }
30
- * );
31
- * ```
32
- */
33
- export declare function createMaterializedResourceFromPotentialOutput(potentialOutput: ResourcePotentialOutputJson, content: JsonDataJson): ResourceJson;
34
- /**
35
- * Creates a materialized resource from scratch (for manual resource creation).
36
- * Generates a content-addressed path from the content and creates a timestamp.
37
- * Use this when creating resources manually without a potential-output template.
38
- *
39
- * @param partialResourceMeta Partial metadata (identity, type, context, optional timestamp)
40
20
  * @param content The actual content/data (assigned directly to extractedData)
21
+ * @param timestamp Optional timestamp to preserve (e.g., when copying resources). If not provided, generates a new timestamp.
41
22
  * @returns A fully materialized ResourceJson
42
23
  *
43
24
  * @example
44
25
  * ```typescript
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
54
- * },
55
- * { identity: 42 }
56
- * );
26
+ * // Materialize from potential output
27
+ * const materialized = createMaterializedResource(potentialOutput, { identity: 42 });
28
+ *
29
+ * // Preserve original timestamp when copying
30
+ * const copy = createMaterializedResource(potentialOutput, { identity: 42 }, originalTimestamp);
57
31
  * ```
58
32
  */
59
- export declare function createMaterializedResourceFromScratch(partialResourceMeta: PartialResourceMeta, content: JsonDataJson): ResourceJson;
33
+ export declare function createMaterializedResource(potentialOutput: ResourcePotentialOutputJson, content: JsonDataJson, timestamp?: string): ResourceJson;
@@ -18,65 +18,27 @@ export function generateContentAddressedPath(resourceTypeRef, content) {
18
18
  return `${resourceTypeRef}/${contentHash}`;
19
19
  }
20
20
  /**
21
- * Creates a materialized resource from a potential-output resource.
22
- * Converts the potential output to a materialized resource by generating a content-addressed path,
23
- * assigning the content as extractedData, and creating a timestamp.
21
+ * Creates a materialized resource from a potential-output resource and content.
22
+ * Generates a content-addressed path from the content.
24
23
  *
25
24
  * @param potentialOutput The potential-output resource to materialize
26
- * @param content The actual content produced by the job (assigned directly to extractedData)
27
- * @returns A fully materialized ResourceJson
28
- *
29
- * @example
30
- * ```typescript
31
- * const materialized = createMaterializedResourceFromPotentialOutput(
32
- * potentialOutput,
33
- * { identity: 42, someData: "result" }
34
- * );
35
- * ```
36
- */
37
- export function createMaterializedResourceFromPotentialOutput(potentialOutput, content) {
38
- // Generate content-addressed path from the content
39
- const contentString = JSON.stringify(content);
40
- const path = generateContentAddressedPath(potentialOutput.resourceTypeRef, contentString);
41
- return {
42
- identity: potentialOutput.identity,
43
- resourceTypeRef: potentialOutput.resourceTypeRef,
44
- creationContext: potentialOutput.creationContext,
45
- kind: 'materialized',
46
- path,
47
- timestamp: new Date().toISOString(),
48
- extractedData: content,
49
- };
50
- }
51
- /**
52
- * Creates a materialized resource from scratch (for manual resource creation).
53
- * Generates a content-addressed path from the content and creates a timestamp.
54
- * Use this when creating resources manually without a potential-output template.
55
- *
56
- * @param partialResourceMeta Partial metadata (identity, type, context, optional timestamp)
57
25
  * @param content The actual content/data (assigned directly to extractedData)
26
+ * @param timestamp Optional timestamp to preserve (e.g., when copying resources). If not provided, generates a new timestamp.
58
27
  * @returns A fully materialized ResourceJson
59
28
  *
60
29
  * @example
61
30
  * ```typescript
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
71
- * },
72
- * { identity: 42 }
73
- * );
31
+ * // Materialize from potential output
32
+ * const materialized = createMaterializedResource(potentialOutput, { identity: 42 });
33
+ *
34
+ * // Preserve original timestamp when copying
35
+ * const copy = createMaterializedResource(potentialOutput, { identity: 42 }, originalTimestamp);
74
36
  * ```
75
37
  */
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);
38
+ export function createMaterializedResource(potentialOutput, content, timestamp) {
39
+ const { identity, resourceTypeRef, creationContext } = potentialOutput;
40
+ // Generate content-addressed path from the content (use pretty-printed format)
41
+ const contentString = JSON.stringify(content, null, 2);
80
42
  const path = generateContentAddressedPath(resourceTypeRef, contentString);
81
43
  return {
82
44
  identity,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toolproof-npm/shared",
3
- "version": "0.1.81",
3
+ "version": "0.1.83",
4
4
  "description": "Core library utilities for ToolProof",
5
5
  "keywords": [
6
6
  "toolproof",