@openplanr/protocol 0.8.0 → 0.10.0
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/README.md +9 -0
- package/package.json +17 -1
- package/registries/commands.json +22 -22
- package/registries/skills.json +136 -58
- package/registry/v1.17.0/commands.json +88 -0
- package/schemas/v1.16.0/artifact-envelope.schema.json +408 -0
- package/schemas/v1.16.0/design-review-bundle.schema.json +590 -0
- package/schemas/v1.17.0/artifact-paste-v2.schema.json +52 -0
- package/schemas/v1.17.0/artifact-room-append-v3.schema.json +159 -0
- package/schemas/v1.17.0/artifact-room-create-v3.schema.json +111 -0
- package/schemas/v1.17.0/artifact-room-descriptor-v3.schema.json +92 -0
- package/schemas/v1.17.0/artifact-room-event-v3.schema.json +130 -0
- package/schemas/v1.17.0/artifact-room-management-v3.schema.json +47 -0
- package/schemas/v1.17.0/artifact-room-read-page-v3.schema.json +308 -0
- package/schemas/v1.17.0/company-resource-manifest.schema.json +128 -0
- package/schemas/v1.17.0/company-resource-upload-prepare.schema.json +164 -0
- package/schemas/v1.17.0/company-resource-upload-receipt.schema.json +63 -0
- package/schemas/v1.17.0/company-resource-upload-status.schema.json +123 -0
- package/schemas/v1.17.0/diagram-authoring-bundle.schema.json +1117 -0
- package/schemas/v1.17.0/diagram-edit-transaction.schema.json +3295 -0
- package/schemas/v1.17.0/diagram-presentation.schema.json +37 -0
- package/schemas/v1.17.0/diagram-review-bundle.schema.json +2439 -0
- package/schemas/v1.17.0/encrypted-resource-manifest.schema.json +131 -0
- package/schemas/v1.17.0/encrypted-upload-commit.schema.json +38 -0
- package/schemas/v1.17.0/encrypted-upload-prepare.schema.json +234 -0
- package/schemas/v1.17.0/encrypted-upload-receipt.schema.json +54 -0
- package/schemas/v1.17.0/encrypted-upload-status.schema.json +129 -0
- package/schemas/v1.17.0/encrypted-workspace-event-v2.schema.json +79 -0
- package/schemas/v1.17.0/encrypted-workspace-v2.schema.json +91 -0
- package/schemas/v1.17.0/enterprise-agent-handoff.schema.json +985 -0
- package/schemas/v1.17.0/enterprise-artifact-revision.schema.json +115 -0
- package/schemas/v1.17.0/enterprise-change-proposal.schema.json +379 -0
- package/schemas/v1.17.0/enterprise-evidence-reference.schema.json +159 -0
- package/schemas/v1.17.0/enterprise-review-thread.schema.json +298 -0
- package/schemas/v1.17.0/enterprise-sync-state.schema.json +189 -0
- package/schemas/v1.17.0/preview-bridge-message.schema.json +197 -0
- package/schemas/v1.17.0/resource-catalog.schema.json +145 -0
- package/schemas/v1.17.0/sharing-crypto-aad.schema.json +36 -0
- package/schemas/v1.17.0/workspace-management-v2.schema.json +45 -0
- package/schemas/v1.17.0/workspace-rotation-v2.schema.json +61 -0
- package/schemas/v1.18.0/runtime-lock.schema.json +122 -0
- package/src/bounded-json-data.d.mts +2 -0
- package/src/bounded-json-data.mjs +56 -0
- package/src/browser-contracts.d.mts +14 -1
- package/src/browser-contracts.mjs +16 -0
- package/src/canonical-json.mjs +17 -16
- package/src/contracts.d.mts +1 -1
- package/src/contracts.mjs +97 -3
- package/src/diagram-authoring-contracts.d.mts +12 -0
- package/src/diagram-authoring-contracts.mjs +174 -1
- package/src/enterprise-contract-validation.d.mts +44 -0
- package/src/enterprise-contract-validation.mjs +279 -0
- package/src/enterprise-contracts.mjs +25 -231
- package/src/enterprise-resource-contracts.d.mts +72 -0
- package/src/enterprise-resource-contracts.mjs +202 -0
- package/src/generated/artifact-envelope-metadata.mjs +769 -0
- package/src/generated/canonical-registries.mjs +158 -80
- package/src/index.d.mts +21 -0
- package/src/index.mjs +23 -0
- package/src/large-object-contracts.d.mts +107 -0
- package/src/large-object-contracts.mjs +473 -0
- package/src/large-object-limits.d.mts +16 -0
- package/src/large-object-limits.mjs +17 -0
- package/src/registries.mjs +1 -0
- package/src/review-experience-contracts.d.mts +1 -0
- package/src/review-experience-contracts.mjs +25 -4
- package/src/sharing-security-contracts.d.mts +63 -0
- package/src/sharing-security-contracts.mjs +403 -0
- package/src/studio-presentation-contracts.d.mts +92 -0
- package/src/studio-presentation-contracts.mjs +287 -0
package/src/contracts.mjs
CHANGED
|
@@ -15,6 +15,7 @@ import { PROTOCOL_V115_CONTRACTS, validateDiagramReviewArtifact } from './browse
|
|
|
15
15
|
import { deepFreeze } from './canonical-json.mjs';
|
|
16
16
|
import { DESIGN_HANDOFF_CONTRACT_FILES } from './design-handoff-contracts.mjs';
|
|
17
17
|
import {
|
|
18
|
+
assertDiagramData,
|
|
18
19
|
DIAGRAM_AUTHORING_CONTRACT_FILES,
|
|
19
20
|
validateDiagramAuthoringArtifact,
|
|
20
21
|
} from './diagram-authoring-contracts.mjs';
|
|
@@ -22,11 +23,26 @@ import { ENTERPRISE_SCHEMAS } from './enterprise-contracts.mjs';
|
|
|
22
23
|
import { PipelineError } from './errors.mjs';
|
|
23
24
|
import { OPERATE_CONTRACT_CATALOG_V2 } from './generated/contract-catalog-v2.mjs';
|
|
24
25
|
import { validateJson } from './json-schema.mjs';
|
|
26
|
+
import {
|
|
27
|
+
assertLargeObjectContract,
|
|
28
|
+
assertLargeObjectData,
|
|
29
|
+
LARGE_OBJECT_SCHEMAS,
|
|
30
|
+
} from './large-object-contracts.mjs';
|
|
31
|
+
import {
|
|
32
|
+
assertSharingSecurityContract,
|
|
33
|
+
SHARING_SECURITY_SCHEMAS,
|
|
34
|
+
} from './sharing-security-contracts.mjs';
|
|
25
35
|
import {
|
|
26
36
|
PROTOCOL_V16_CONTRACT_FILES,
|
|
27
37
|
PROTOCOL_V17_CONTRACT_FILES,
|
|
28
38
|
PROTOCOL_V18_CONTRACT_FILES,
|
|
29
39
|
} from './skill-source-contracts.mjs';
|
|
40
|
+
import {
|
|
41
|
+
assertDiagramPresentation,
|
|
42
|
+
assertDiagramReviewBundleV11,
|
|
43
|
+
assertVersionedDiagramAuthoringBundle,
|
|
44
|
+
assertVersionedDiagramEditTransaction,
|
|
45
|
+
} from './studio-presentation-contracts.mjs';
|
|
30
46
|
|
|
31
47
|
const packageRoot = join(dirname(fileURLToPath(import.meta.url)), '..');
|
|
32
48
|
|
|
@@ -37,10 +53,21 @@ const v17Schema = (kind) => `schemas/v1.7.0/${PROTOCOL_V17_CONTRACT_FILES[kind]}
|
|
|
37
53
|
const v18Schema = (kind) => `schemas/v1.8.0/${PROTOCOL_V18_CONTRACT_FILES[kind]}`;
|
|
38
54
|
|
|
39
55
|
const foundationPaths = {
|
|
56
|
+
...Object.fromEntries(
|
|
57
|
+
Object.keys(LARGE_OBJECT_SCHEMAS).map((name) => [
|
|
58
|
+
name,
|
|
59
|
+
{ '1.17.0': `schemas/v1.17.0/${name}.schema.json` },
|
|
60
|
+
]),
|
|
61
|
+
),
|
|
40
62
|
...Object.fromEntries(
|
|
41
63
|
Object.keys(ENTERPRISE_SCHEMAS).map((name) => [
|
|
42
64
|
name,
|
|
43
|
-
{
|
|
65
|
+
{
|
|
66
|
+
...(Object.hasOwn(LARGE_OBJECT_SCHEMAS, name)
|
|
67
|
+
? { '1.17.0': `schemas/v1.17.0/${name}.schema.json` }
|
|
68
|
+
: {}),
|
|
69
|
+
'1.12.0': `schemas/v1.12.0/${name}.schema.json`,
|
|
70
|
+
},
|
|
44
71
|
]),
|
|
45
72
|
),
|
|
46
73
|
'design-document': { '1.9.0': 'schemas/v1.9.0/design-document.schema.json' },
|
|
@@ -51,6 +78,7 @@ const foundationPaths = {
|
|
|
51
78
|
'design-review-bundle': {
|
|
52
79
|
'1.9.0': 'schemas/v1.9.0/design-review-bundle.schema.json',
|
|
53
80
|
'1.10.0': 'schemas/v1.10.0/design-review-bundle.schema.json',
|
|
81
|
+
'1.16.0': 'schemas/v1.16.0/design-review-bundle.schema.json',
|
|
54
82
|
},
|
|
55
83
|
'design-review-context': { '1.10.0': 'schemas/v1.10.0/design-review-context.schema.json' },
|
|
56
84
|
'design-review-handoff': { '1.10.0': 'schemas/v1.10.0/design-review-handoff.schema.json' },
|
|
@@ -70,7 +98,11 @@ const foundationPaths = {
|
|
|
70
98
|
task: { '1.0.0': 'schemas/v1.0.0/task.schema.json', '1.7.0': v17Schema('task') },
|
|
71
99
|
'pipeline-shipped': { '1.0.0': 'schemas/v1.0.0/pipeline-shipped.schema.json' },
|
|
72
100
|
'run-manifest': { '1.0.0': 'schemas/v1.0.0/run-manifest.schema.json' },
|
|
73
|
-
|
|
101
|
+
// The lock body's protocolVersion names adapter compatibility, not this contract version.
|
|
102
|
+
'runtime-lock': {
|
|
103
|
+
'1.1.0': 'schemas/v1.1.0/runtime-lock.schema.json',
|
|
104
|
+
'1.18.0': 'schemas/v1.18.0/runtime-lock.schema.json',
|
|
105
|
+
},
|
|
74
106
|
'provenance-event': { '1.1.0': 'schemas/v1.1.0/provenance-event.schema.json' },
|
|
75
107
|
'ship-closure': { '1.1.0': 'schemas/v1.1.0/ship-closure.schema.json' },
|
|
76
108
|
'professional-specification': {
|
|
@@ -111,7 +143,10 @@ const foundationPaths = {
|
|
|
111
143
|
'1.3.0': 'schemas/v1.3.0/release-compatibility-claim.schema.json',
|
|
112
144
|
},
|
|
113
145
|
'release-ledger-receipt': { '1.3.0': 'schemas/v1.3.0/release-ledger-receipt.schema.json' },
|
|
114
|
-
'artifact-envelope': {
|
|
146
|
+
'artifact-envelope': {
|
|
147
|
+
'1.1.0': 'schemas/v1.1.0/artifact-envelope.schema.json',
|
|
148
|
+
'1.16.0': 'schemas/v1.16.0/artifact-envelope.schema.json',
|
|
149
|
+
},
|
|
115
150
|
'artifact-review': { '1.1.0': 'schemas/v1.1.0/artifact-review.schema.json' },
|
|
116
151
|
'artifact-paste': { '1.1.0': 'schemas/v1.1.0/artifact-paste.schema.json' },
|
|
117
152
|
'artifact-room-event': { '1.1.0': 'schemas/v1.1.0/artifact-room-event.schema.json' },
|
|
@@ -1083,6 +1118,8 @@ function compareProtocolVersions(left, right) {
|
|
|
1083
1118
|
|
|
1084
1119
|
function inferredVersion(kind, value, explicitVersion) {
|
|
1085
1120
|
if (explicitVersion) return explicitVersion;
|
|
1121
|
+
// A lock records adapter compatibility; its protocolVersion is not a schema envelope version.
|
|
1122
|
+
if (kind === 'runtime-lock') return '1.18.0';
|
|
1086
1123
|
if (typeof value?.protocolVersion === 'string') return value.protocolVersion;
|
|
1087
1124
|
if (explicitProtocolVersionKinds.has(kind)) {
|
|
1088
1125
|
throw new PipelineError(
|
|
@@ -1198,6 +1235,10 @@ function guidedQuestionnaireCompatibilityErrors(value) {
|
|
|
1198
1235
|
|
|
1199
1236
|
/** @type {typeof import('./contracts.d.mts').validateProtocolArtifact} */
|
|
1200
1237
|
export function validateProtocolArtifact(kind, value, { protocolVersion } = {}) {
|
|
1238
|
+
const studioKind = Object.hasOwn(LARGE_OBJECT_SCHEMAS, kind);
|
|
1239
|
+
if (studioKind && protocolVersion === '1.17.0') {
|
|
1240
|
+
return validateStudioArtifact(kind, value, sharedProtocolSchema(kind, protocolVersion));
|
|
1241
|
+
}
|
|
1201
1242
|
if (Object.hasOwn(PROTOCOL_V115_CONTRACTS, kind)) {
|
|
1202
1243
|
// Review transport envelopes do not carry a Protocol version. Do not read
|
|
1203
1244
|
// arbitrary input properties while selecting the dedicated safety preflight.
|
|
@@ -1222,13 +1263,66 @@ export function validateProtocolArtifact(kind, value, { protocolVersion } = {})
|
|
|
1222
1263
|
if (descriptor && !Object.hasOwn(descriptor, 'value'))
|
|
1223
1264
|
return validateDiagramAuthoringArtifact(kind, value);
|
|
1224
1265
|
versionInput = { protocolVersion: descriptor?.value };
|
|
1266
|
+
} else if (studioKind && !protocolVersion) {
|
|
1267
|
+
// New resource envelopes may be hostile objects. Version inference must use
|
|
1268
|
+
// descriptors too; the bounded additive reader owns the safety diagnostic.
|
|
1269
|
+
let descriptor;
|
|
1270
|
+
try {
|
|
1271
|
+
descriptor =
|
|
1272
|
+
value !== null && typeof value === 'object'
|
|
1273
|
+
? Object.getOwnPropertyDescriptor(value, 'protocolVersion')
|
|
1274
|
+
: undefined;
|
|
1275
|
+
} catch {
|
|
1276
|
+
return invalidStudioData();
|
|
1277
|
+
}
|
|
1278
|
+
if (descriptor && !Object.hasOwn(descriptor, 'value')) return invalidStudioData();
|
|
1279
|
+
versionInput = { protocolVersion: descriptor?.value };
|
|
1225
1280
|
}
|
|
1226
1281
|
const version = inferredVersion(kind, versionInput, protocolVersion);
|
|
1282
|
+
if (studioKind && version === '1.17.0') {
|
|
1283
|
+
return validateStudioArtifact(kind, value, sharedProtocolSchema(kind, version));
|
|
1284
|
+
}
|
|
1227
1285
|
if (version === '1.13.0' && authoringKind) {
|
|
1228
1286
|
return validateDiagramAuthoringArtifact(kind, value);
|
|
1229
1287
|
}
|
|
1230
1288
|
return validateGenericArtifact(kind, value, sharedProtocolSchema(kind, version));
|
|
1231
1289
|
}
|
|
1290
|
+
function invalidStudioData() {
|
|
1291
|
+
return [
|
|
1292
|
+
{ path: '$', rule: 'studio-protocol-contract', detail: 'Expected bounded inert JSON data.' },
|
|
1293
|
+
];
|
|
1294
|
+
}
|
|
1295
|
+
function validateStudioArtifact(kind, value, resolved) {
|
|
1296
|
+
try {
|
|
1297
|
+
if (
|
|
1298
|
+
[
|
|
1299
|
+
'diagram-authoring-bundle',
|
|
1300
|
+
'diagram-edit-transaction',
|
|
1301
|
+
'diagram-review-bundle',
|
|
1302
|
+
'diagram-presentation',
|
|
1303
|
+
].includes(kind)
|
|
1304
|
+
)
|
|
1305
|
+
assertDiagramData(value);
|
|
1306
|
+
else assertLargeObjectData(value);
|
|
1307
|
+
const errors = validateResolvedArtifact(value, resolved);
|
|
1308
|
+
if (errors.length) return errors;
|
|
1309
|
+
if (Object.hasOwn(SHARING_SECURITY_SCHEMAS, kind)) assertSharingSecurityContract(value, kind);
|
|
1310
|
+
else if (kind === 'diagram-authoring-bundle') assertVersionedDiagramAuthoringBundle(value);
|
|
1311
|
+
else if (kind === 'diagram-edit-transaction') assertVersionedDiagramEditTransaction(value);
|
|
1312
|
+
else if (kind === 'diagram-review-bundle') assertDiagramReviewBundleV11(value);
|
|
1313
|
+
else if (kind === 'diagram-presentation') assertDiagramPresentation(value);
|
|
1314
|
+
else assertLargeObjectContract(value, kind);
|
|
1315
|
+
return [];
|
|
1316
|
+
} catch (error) {
|
|
1317
|
+
return [
|
|
1318
|
+
{
|
|
1319
|
+
path: '$',
|
|
1320
|
+
rule: 'studio-protocol-contract',
|
|
1321
|
+
detail: error instanceof Error ? error.message : 'Invalid Studio contract data.',
|
|
1322
|
+
},
|
|
1323
|
+
];
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1232
1326
|
function validateGenericArtifact(kind, value, resolved) {
|
|
1233
1327
|
const errors = validateResolvedArtifact(value, resolved);
|
|
1234
1328
|
if (kind === 'guided-questionnaire' && resolved.protocolVersion === '1.2.0')
|
|
@@ -454,3 +454,15 @@ export declare function summarizeDiagramAuthoringContent(bundle: DiagramAuthorin
|
|
|
454
454
|
hasVisibleContent: boolean;
|
|
455
455
|
};
|
|
456
456
|
export declare function inspectLegacyDiagramDocument(value: unknown): DiagramLegacyInspection;
|
|
457
|
+
|
|
458
|
+
/** Internal: detached and recursively frozen inert data, without a semantic validity claim. */
|
|
459
|
+
export declare function copyImmutableDiagramData<T>(value: T, previous?: T | null): T;
|
|
460
|
+
/** Inspect inert authoring data with the existing aggregate limits, without copying it. */
|
|
461
|
+
export declare function assertDiagramData<T>(value: T): T;
|
|
462
|
+
|
|
463
|
+
/** Internal: seals an inert draft into an immutable copy without claiming semantic validity. */
|
|
464
|
+
export declare function sealImmutableDiagramData<T>(value: T, previous?: T | null): T;
|
|
465
|
+
|
|
466
|
+
export function immutableDiagramDataUsage(
|
|
467
|
+
value: unknown,
|
|
468
|
+
): { values: number; text: number; height: number } | null;
|
|
@@ -639,6 +639,11 @@ export function getDiagramAuthoringCapability(grammarId) {
|
|
|
639
639
|
}
|
|
640
640
|
|
|
641
641
|
const error = (path, rule, detail) => ({ path, rule, detail });
|
|
642
|
+
// Only this module's detached, recursively frozen copies carry inert-data provenance.
|
|
643
|
+
// A caller's Object.freeze() or claimed digest never enters either cache.
|
|
644
|
+
const immutableDataProofs = new WeakMap();
|
|
645
|
+
const immutableDigests = new WeakMap();
|
|
646
|
+
const immutableCanonical = new WeakMap();
|
|
642
647
|
// Descriptors are inspected before values; neither validation nor hashing invokes accessors.
|
|
643
648
|
function inspectData(value) {
|
|
644
649
|
const issues = [];
|
|
@@ -673,6 +678,17 @@ function inspectData(value) {
|
|
|
673
678
|
issues.push(error(path, 'plain-data', 'Only JSON data is accepted.'));
|
|
674
679
|
return;
|
|
675
680
|
}
|
|
681
|
+
const proof = immutableDataProofs.get(current);
|
|
682
|
+
if (
|
|
683
|
+
proof &&
|
|
684
|
+
count + proof.values - 1 <= DIAGRAM_AUTHORING_LIMITS.values &&
|
|
685
|
+
textSize + proof.text <= DIAGRAM_AUTHORING_LIMITS.textCodeUnits &&
|
|
686
|
+
depth + proof.height <= DIAGRAM_AUTHORING_LIMITS.depth
|
|
687
|
+
) {
|
|
688
|
+
count += proof.values - 1;
|
|
689
|
+
textSize += proof.text;
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
676
692
|
const proto = Object.getPrototypeOf(current);
|
|
677
693
|
if (
|
|
678
694
|
Array.isArray(current)
|
|
@@ -734,17 +750,174 @@ function inspectData(value) {
|
|
|
734
750
|
}
|
|
735
751
|
return issues;
|
|
736
752
|
}
|
|
753
|
+
/**
|
|
754
|
+
* Internal snapshot boundary. The copy is inspected completely before any proof is recorded.
|
|
755
|
+
* @param {unknown} value
|
|
756
|
+
* @param {import('./diagram-authoring-contracts.d.mts').DiagramAuthoringBundle | null} previous
|
|
757
|
+
*/
|
|
758
|
+
export function copyImmutableDiagramData(value, previous = null) {
|
|
759
|
+
assertData(value);
|
|
760
|
+
const ancestors = new Set();
|
|
761
|
+
let copiedValues = 0;
|
|
762
|
+
function copyData(current, depth) {
|
|
763
|
+
if (++copiedValues > DIAGRAM_AUTHORING_LIMITS.values || depth > DIAGRAM_AUTHORING_LIMITS.depth)
|
|
764
|
+
throw new TypeError('Copy exceeds portable resource limits.');
|
|
765
|
+
if (!current || typeof current !== 'object') return current;
|
|
766
|
+
if (immutableDataProofs.has(current)) return current;
|
|
767
|
+
if (ancestors.has(current)) throw new TypeError('Cyclic copy is not accepted.');
|
|
768
|
+
ancestors.add(current);
|
|
769
|
+
const result = Array.isArray(current) ? [] : {};
|
|
770
|
+
const descriptors = Object.getOwnPropertyDescriptors(current);
|
|
771
|
+
for (const key of Reflect.ownKeys(descriptors)) {
|
|
772
|
+
const descriptor = descriptors[/** @type {string} */ (key)];
|
|
773
|
+
if (!Object.hasOwn(descriptor, 'value'))
|
|
774
|
+
throw new TypeError('Accessor copy is not accepted.');
|
|
775
|
+
if (Array.isArray(current) && key === 'length') {
|
|
776
|
+
result.length = descriptor.value;
|
|
777
|
+
continue;
|
|
778
|
+
}
|
|
779
|
+
Object.defineProperty(result, key, {
|
|
780
|
+
value: copyData(descriptor.value, depth + 1),
|
|
781
|
+
enumerable: descriptor.enumerable,
|
|
782
|
+
configurable: true,
|
|
783
|
+
writable: true,
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
ancestors.delete(current);
|
|
787
|
+
return result;
|
|
788
|
+
}
|
|
789
|
+
let copy = copyData(value, 0);
|
|
790
|
+
assertData(copy);
|
|
791
|
+
if (previous && immutableDataProofs.has(previous)) {
|
|
792
|
+
// Inspected descendants can stay shared; reuse must never mutate an owned frozen root.
|
|
793
|
+
if (immutableDataProofs.has(copy)) copy = Array.isArray(copy) ? [...copy] : { ...copy };
|
|
794
|
+
for (const field of ['document', 'originalSource', 'sourceMap'])
|
|
795
|
+
if (
|
|
796
|
+
copy[field] !== previous[field] &&
|
|
797
|
+
JSON.stringify(copy[field]) === JSON.stringify(previous[field])
|
|
798
|
+
)
|
|
799
|
+
copy[field] = previous[field];
|
|
800
|
+
if (copy.presentation?.elements && previous.presentation?.elements) {
|
|
801
|
+
const placements = new Map(
|
|
802
|
+
previous.presentation.elements.map((item) => [item.elementId, item]),
|
|
803
|
+
);
|
|
804
|
+
copy.presentation = {
|
|
805
|
+
...copy.presentation,
|
|
806
|
+
elements: copy.presentation.elements.map((item) => {
|
|
807
|
+
const old = placements.get(item.elementId);
|
|
808
|
+
return old && (old === item || JSON.stringify(old) === JSON.stringify(item)) ? old : item;
|
|
809
|
+
}),
|
|
810
|
+
};
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
freezeImmutableOwnedData(copy);
|
|
814
|
+
return copy;
|
|
815
|
+
}
|
|
816
|
+
// Call only for values constructed here from inspected copies and immutable descendants.
|
|
817
|
+
function freezeImmutableOwnedData(current) {
|
|
818
|
+
if (!current || typeof current !== 'object')
|
|
819
|
+
return { values: 1, text: typeof current === 'string' ? current.length : 0, height: 0 };
|
|
820
|
+
const retained = immutableDataProofs.get(current);
|
|
821
|
+
if (retained) return retained;
|
|
822
|
+
const proof = { values: 1, text: 0, height: 0 };
|
|
823
|
+
for (const child of Object.values(current)) {
|
|
824
|
+
const part = freezeImmutableOwnedData(child);
|
|
825
|
+
proof.values += part.values;
|
|
826
|
+
proof.text += part.text;
|
|
827
|
+
proof.height = Math.max(proof.height, part.height + 1);
|
|
828
|
+
}
|
|
829
|
+
Object.freeze(current);
|
|
830
|
+
immutableDataProofs.set(current, proof);
|
|
831
|
+
return proof;
|
|
832
|
+
}
|
|
833
|
+
export function immutableDiagramDataUsage(value) {
|
|
834
|
+
const proof = value && typeof value === 'object' ? immutableDataProofs.get(value) : null;
|
|
835
|
+
return proof ? { ...proof } : null;
|
|
836
|
+
}
|
|
837
|
+
function rememberImmutableDigest(value, field, digest) {
|
|
838
|
+
immutableDigests.set(value, new Map([[field, digest]]));
|
|
839
|
+
return value;
|
|
840
|
+
}
|
|
841
|
+
/** Seal an inspected private draft. Every memoized hash was computed from these exact immutable bytes. */
|
|
842
|
+
export function sealImmutableDiagramData(value, previous = null) {
|
|
843
|
+
const draft = copyImmutableDiagramData(value, previous);
|
|
844
|
+
const semanticDigest = diagramDocumentDigest(draft.document);
|
|
845
|
+
const document =
|
|
846
|
+
draft.document.documentDigest === semanticDigest
|
|
847
|
+
? draft.document
|
|
848
|
+
: rememberImmutableDigest(
|
|
849
|
+
{ ...draft.document, documentDigest: semanticDigest },
|
|
850
|
+
'documentDigest',
|
|
851
|
+
semanticDigest,
|
|
852
|
+
);
|
|
853
|
+
freezeImmutableOwnedData(document);
|
|
854
|
+
const sourceMap = draft.sourceMap ? { ...draft.sourceMap, semanticDigest } : null;
|
|
855
|
+
freezeImmutableOwnedData(sourceMap);
|
|
856
|
+
const presentationDraft = { ...draft.presentation, semanticDigest };
|
|
857
|
+
freezeImmutableOwnedData(presentationDraft);
|
|
858
|
+
const presentationDigest = diagramPresentationDigest(presentationDraft);
|
|
859
|
+
const presentation = rememberImmutableDigest(
|
|
860
|
+
{ ...presentationDraft, presentationDigest },
|
|
861
|
+
'presentationDigest',
|
|
862
|
+
presentationDigest,
|
|
863
|
+
);
|
|
864
|
+
freezeImmutableOwnedData(presentation);
|
|
865
|
+
const bundleDraft = { ...draft, document, presentation, sourceMap };
|
|
866
|
+
freezeImmutableOwnedData(bundleDraft);
|
|
867
|
+
const bundleDigest = diagramAuthoringBundleDigest(bundleDraft);
|
|
868
|
+
const bundle = rememberImmutableDigest(
|
|
869
|
+
{ ...bundleDraft, bundleDigest },
|
|
870
|
+
'bundleDigest',
|
|
871
|
+
bundleDigest,
|
|
872
|
+
);
|
|
873
|
+
freezeImmutableOwnedData(bundle);
|
|
874
|
+
return bundle;
|
|
875
|
+
}
|
|
737
876
|
function assertData(value) {
|
|
738
877
|
const issues = inspectData(value);
|
|
739
878
|
if (issues.length) throw new TypeError(`${issues[0].path}: ${issues[0].rule}`);
|
|
740
879
|
}
|
|
880
|
+
/** Inspect inert authoring data with the existing aggregate limits, without copying it.
|
|
881
|
+
* @type {typeof import('./diagram-authoring-contracts.d.mts').assertDiagramData}
|
|
882
|
+
*/
|
|
883
|
+
export function assertDiagramData(value) {
|
|
884
|
+
assertData(value);
|
|
885
|
+
return value;
|
|
886
|
+
}
|
|
887
|
+
// Called only on private inspected immutable descendants plus the owned digest-exclusion root.
|
|
888
|
+
function canonicalImmutableData(value) {
|
|
889
|
+
if (!value || typeof value !== 'object') return canonicalizeJson(value);
|
|
890
|
+
const known = immutableDataProofs.has(value);
|
|
891
|
+
const cached = known ? immutableCanonical.get(value) : undefined;
|
|
892
|
+
if (cached !== undefined) return cached;
|
|
893
|
+
const text = Array.isArray(value)
|
|
894
|
+
? '[' + value.map(canonicalImmutableData).join(',') + ']'
|
|
895
|
+
: '{' +
|
|
896
|
+
Object.keys(value)
|
|
897
|
+
.sort()
|
|
898
|
+
.map((key) => canonicalizeJson(key) + ':' + canonicalImmutableData(value[key]))
|
|
899
|
+
.join(',') +
|
|
900
|
+
'}';
|
|
901
|
+
// Bound per-record caching; do not retain another whole document/bundle string for each revision.
|
|
902
|
+
if (known && text.length <= 16384) immutableCanonical.set(value, text);
|
|
903
|
+
return text;
|
|
904
|
+
}
|
|
741
905
|
function digestExcluding(value, field) {
|
|
906
|
+
const proof = value && typeof value === 'object' && immutableDataProofs.has(value);
|
|
907
|
+
const retained = proof ? immutableDigests.get(value)?.get(field) : undefined;
|
|
908
|
+
if (retained) return retained;
|
|
742
909
|
assertData(value);
|
|
743
910
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
744
911
|
throw new TypeError('Digest input must be an object.');
|
|
745
912
|
const input = { ...value };
|
|
746
913
|
delete input[field];
|
|
747
|
-
|
|
914
|
+
const digest = proof ? `sha256:${sha256Hex(canonicalImmutableData(input))}` : sha256Jcs(input);
|
|
915
|
+
if (proof) {
|
|
916
|
+
const cache = immutableDigests.get(value) ?? new Map();
|
|
917
|
+
cache.set(field, digest);
|
|
918
|
+
immutableDigests.set(value, cache);
|
|
919
|
+
}
|
|
920
|
+
return digest;
|
|
748
921
|
}
|
|
749
922
|
/** @type {typeof import('./diagram-authoring-contracts.d.mts').diagramDocumentDigest} */
|
|
750
923
|
export const diagramDocumentDigest = (value) => digestExcluding(value, 'documentDigest');
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
EnterpriseAgentHandoff,
|
|
3
|
+
EnterpriseChangeProposal,
|
|
4
|
+
EnterpriseEvidenceReference,
|
|
5
|
+
EnterpriseReviewThread,
|
|
6
|
+
EnterpriseSchema,
|
|
7
|
+
EnterpriseSyncState,
|
|
8
|
+
} from './enterprise-contracts.mjs';
|
|
9
|
+
|
|
10
|
+
type VersionedData<T> = Omit<T, 'schemaVersion'> & { schemaVersion: '1.0.0' | '1.1.0' };
|
|
11
|
+
type ThreadData = VersionedData<EnterpriseReviewThread>;
|
|
12
|
+
type EvidenceData = VersionedData<EnterpriseEvidenceReference>;
|
|
13
|
+
type HandoffData = Omit<VersionedData<EnterpriseAgentHandoff>, 'threads' | 'evidence'> & {
|
|
14
|
+
threads: ThreadData[];
|
|
15
|
+
evidence: EvidenceData[];
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export declare function assertPlainData(value: unknown, depth?: number, seen?: Set<unknown>): void;
|
|
19
|
+
export declare function assertEnterpriseContractWithSchema<T>(
|
|
20
|
+
value: T,
|
|
21
|
+
schema: EnterpriseSchema,
|
|
22
|
+
): T;
|
|
23
|
+
export declare function assertEnterpriseReviewThreadWithSchema<T extends ThreadData>(
|
|
24
|
+
value: T,
|
|
25
|
+
schema: EnterpriseSchema,
|
|
26
|
+
): T;
|
|
27
|
+
export declare function assertEnterpriseProposalWithSchema<
|
|
28
|
+
T extends VersionedData<EnterpriseChangeProposal>,
|
|
29
|
+
>(value: T, schema: EnterpriseSchema): T;
|
|
30
|
+
export declare function assertEnterpriseEvidenceWithSchema<T extends EvidenceData>(
|
|
31
|
+
value: T,
|
|
32
|
+
schema: EnterpriseSchema,
|
|
33
|
+
): T;
|
|
34
|
+
export declare function assertEnterpriseSyncWithSchema<
|
|
35
|
+
T extends VersionedData<EnterpriseSyncState>,
|
|
36
|
+
>(value: T, schema: EnterpriseSchema): T;
|
|
37
|
+
export declare function assertEnterpriseHandoffWithSchema<T extends HandoffData>(
|
|
38
|
+
value: T,
|
|
39
|
+
schema: EnterpriseSchema,
|
|
40
|
+
assertThread: (thread: ThreadData) => unknown,
|
|
41
|
+
assertEvidence: (evidence: EvidenceData) => unknown,
|
|
42
|
+
): T;
|
|
43
|
+
export declare function isEnterpriseRepositoryPathData(value: unknown): boolean;
|
|
44
|
+
export declare function renderEnterpriseHandoffMarkdownData(value: HandoffData): string;
|