sysprom 1.7.0 → 1.7.1
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/src/endpoint-types.d.ts +7 -3
- package/dist/src/endpoint-types.js +8 -8
- package/dist/src/md-to-json.js +9 -1
- package/dist/src/sync.d.ts +12 -9
- package/dist/src/sync.js +19 -12
- package/package.json +1 -1
|
@@ -12,9 +12,13 @@ export declare const RELATIONSHIP_ENDPOINT_TYPES: Record<RelationshipType, {
|
|
|
12
12
|
}>;
|
|
13
13
|
/**
|
|
14
14
|
* Check if a relationship type is valid for the given endpoint node types.
|
|
15
|
-
* @param relType The relationship type
|
|
16
|
-
* @param fromType The source node type
|
|
17
|
-
* @param toType The target node type
|
|
15
|
+
* @param relType - The relationship type
|
|
16
|
+
* @param fromType - The source node type
|
|
17
|
+
* @param toType - The target node type
|
|
18
18
|
* @returns true if the endpoint types are valid for this relationship
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* isValidEndpointPair("refines", "intent", "concept") // true
|
|
22
|
+
* ```
|
|
19
23
|
*/
|
|
20
24
|
export declare function isValidEndpointPair(relType: RelationshipType, fromType: NodeType, toType: NodeType): boolean;
|
|
@@ -288,16 +288,16 @@ export const RELATIONSHIP_ENDPOINT_TYPES = {
|
|
|
288
288
|
};
|
|
289
289
|
/**
|
|
290
290
|
* Check if a relationship type is valid for the given endpoint node types.
|
|
291
|
-
* @param relType The relationship type
|
|
292
|
-
* @param fromType The source node type
|
|
293
|
-
* @param toType The target node type
|
|
291
|
+
* @param relType - The relationship type
|
|
292
|
+
* @param fromType - The source node type
|
|
293
|
+
* @param toType - The target node type
|
|
294
294
|
* @returns true if the endpoint types are valid for this relationship
|
|
295
|
+
* @example
|
|
296
|
+
* ```ts
|
|
297
|
+
* isValidEndpointPair("refines", "intent", "concept") // true
|
|
298
|
+
* ```
|
|
295
299
|
*/
|
|
296
300
|
export function isValidEndpointPair(relType, fromType, toType) {
|
|
297
301
|
const endpoints = RELATIONSHIP_ENDPOINT_TYPES[relType];
|
|
298
|
-
|
|
299
|
-
// Unknown relationship type — should be caught by schema validation
|
|
300
|
-
return false;
|
|
301
|
-
}
|
|
302
|
-
return (endpoints.from.includes(fromType) && endpoints.to.includes(toType));
|
|
302
|
+
return endpoints.from.includes(fromType) && endpoints.to.includes(toType);
|
|
303
303
|
}
|
package/dist/src/md-to-json.js
CHANGED
|
@@ -35,7 +35,15 @@ function parseText(raw) {
|
|
|
35
35
|
const lines = raw.split("\n");
|
|
36
36
|
return lines.length === 1 ? lines[0] : lines;
|
|
37
37
|
}
|
|
38
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* Separate $schema from front matter so it becomes a top-level document key.
|
|
40
|
+
* @param front - The front matter object
|
|
41
|
+
* @returns An object with extracted schema and remaining metadata
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* const { schema, metadata } = extractSchema({ $schema: "...", foo: "bar" });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
39
47
|
function extractSchema(front) {
|
|
40
48
|
const schema = typeof front.$schema === "string" ? front.$schema : undefined;
|
|
41
49
|
const metadata = { ...front };
|
package/dist/src/sync.d.ts
CHANGED
|
@@ -12,15 +12,18 @@ export interface DetectionResult {
|
|
|
12
12
|
/**
|
|
13
13
|
* Detect whether JSON and/or Markdown have changed.
|
|
14
14
|
* Strategy:
|
|
15
|
-
* 1. Parse both JSON and Markdown to document objects
|
|
16
|
-
* 2. If documents are identical
|
|
17
|
-
* 3. If documents differ
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* @param jsonPath Path to JSON file
|
|
23
|
-
* @param mdPath Path to Markdown file (single or multi-doc)
|
|
15
|
+
* 1. Parse both JSON and Markdown to document objects.
|
|
16
|
+
* 2. If documents are identical, no change.
|
|
17
|
+
* 3. If documents differ, use file modification times to determine which was
|
|
18
|
+
* edited more recently. The newer file is considered the "changed" one.
|
|
19
|
+
* If modification times are very close (< 100ms), treat as conflict.
|
|
20
|
+
* @param jsonPath - Path to JSON file
|
|
21
|
+
* @param mdPath - Path to Markdown file (single or multi-doc)
|
|
24
22
|
* @returns Detection result with jsonChanged, mdChanged, and conflict flags
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* const result = detectChanges("doc.spm.json", "doc.spm.md");
|
|
26
|
+
* if (result.conflict) throw new Error("Both files changed");
|
|
27
|
+
* ```
|
|
25
28
|
*/
|
|
26
29
|
export declare function detectChanges(jsonPath: string, mdPath: string): DetectionResult;
|
package/dist/src/sync.js
CHANGED
|
@@ -5,31 +5,38 @@ import { SysProMDocument } from "./schema.js";
|
|
|
5
5
|
/**
|
|
6
6
|
* Compute a normalised hash of a document for comparison.
|
|
7
7
|
* Uses canonical JSON representation.
|
|
8
|
-
* @param doc The SysProM document
|
|
8
|
+
* @param doc - The SysProM document
|
|
9
9
|
* @returns SHA256 hash of the canonicalised document
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const hash = normaliseHash({ nodes: [], relationships: [] });
|
|
13
|
+
* ```
|
|
10
14
|
*/
|
|
11
15
|
function normaliseHash(doc) {
|
|
12
|
-
const
|
|
16
|
+
const keys = doc && typeof doc === "object" ? Object.keys(doc).sort() : [];
|
|
17
|
+
const sorted = JSON.stringify(doc, keys);
|
|
13
18
|
return createHash("sha256").update(sorted).digest("hex");
|
|
14
19
|
}
|
|
15
20
|
/**
|
|
16
21
|
* Detect whether JSON and/or Markdown have changed.
|
|
17
22
|
* Strategy:
|
|
18
|
-
* 1. Parse both JSON and Markdown to document objects
|
|
19
|
-
* 2. If documents are identical
|
|
20
|
-
* 3. If documents differ
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* @param jsonPath Path to JSON file
|
|
26
|
-
* @param mdPath Path to Markdown file (single or multi-doc)
|
|
23
|
+
* 1. Parse both JSON and Markdown to document objects.
|
|
24
|
+
* 2. If documents are identical, no change.
|
|
25
|
+
* 3. If documents differ, use file modification times to determine which was
|
|
26
|
+
* edited more recently. The newer file is considered the "changed" one.
|
|
27
|
+
* If modification times are very close (< 100ms), treat as conflict.
|
|
28
|
+
* @param jsonPath - Path to JSON file
|
|
29
|
+
* @param mdPath - Path to Markdown file (single or multi-doc)
|
|
27
30
|
* @returns Detection result with jsonChanged, mdChanged, and conflict flags
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* const result = detectChanges("doc.spm.json", "doc.spm.md");
|
|
34
|
+
* if (result.conflict) throw new Error("Both files changed");
|
|
35
|
+
* ```
|
|
28
36
|
*/
|
|
29
37
|
export function detectChanges(jsonPath, mdPath) {
|
|
30
38
|
// Read files
|
|
31
39
|
const jsonContent = readFileSync(jsonPath, "utf8");
|
|
32
|
-
const mdContent = readFileSync(mdPath, "utf8");
|
|
33
40
|
// Parse JSON
|
|
34
41
|
const jsonDoc = JSON.parse(jsonContent);
|
|
35
42
|
if (!SysProMDocument.is(jsonDoc)) {
|