@agent-teams/engineering-foundation 0.13.1 → 0.15.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.
Files changed (131) hide show
  1. package/dist/canonical-json.d.ts +12 -0
  2. package/dist/canonical-json.d.ts.map +1 -0
  3. package/dist/canonical-json.js +151 -0
  4. package/dist/canonical-json.js.map +1 -0
  5. package/dist/document-authoring/adapters/canonical-markdown.d.ts +14 -0
  6. package/dist/document-authoring/adapters/canonical-markdown.d.ts.map +1 -0
  7. package/dist/document-authoring/adapters/canonical-markdown.js +354 -0
  8. package/dist/document-authoring/adapters/canonical-markdown.js.map +1 -0
  9. package/dist/document-authoring/adapters/node/load-validated-document-authoring-profile.d.ts +31 -0
  10. package/dist/document-authoring/adapters/node/load-validated-document-authoring-profile.d.ts.map +1 -0
  11. package/dist/document-authoring/adapters/node/load-validated-document-authoring-profile.js +47 -0
  12. package/dist/document-authoring/adapters/node/load-validated-document-authoring-profile.js.map +1 -0
  13. package/dist/document-authoring/adapters/node/node-authoring-profile-reader.d.ts.map +1 -1
  14. package/dist/document-authoring/adapters/node/node-authoring-profile-reader.js +14 -36
  15. package/dist/document-authoring/adapters/node/node-authoring-profile-reader.js.map +1 -1
  16. package/dist/document-authoring/adapters/node/node-document-contract-validator.d.ts +7 -0
  17. package/dist/document-authoring/adapters/node/node-document-contract-validator.d.ts.map +1 -0
  18. package/dist/document-authoring/adapters/node/node-document-contract-validator.js +179 -0
  19. package/dist/document-authoring/adapters/node/node-document-contract-validator.js.map +1 -0
  20. package/dist/document-authoring/adapters/node/node-document-planning-profile-reader.d.ts +10 -0
  21. package/dist/document-authoring/adapters/node/node-document-planning-profile-reader.d.ts.map +1 -0
  22. package/dist/document-authoring/adapters/node/node-document-planning-profile-reader.js +72 -0
  23. package/dist/document-authoring/adapters/node/node-document-planning-profile-reader.js.map +1 -0
  24. package/dist/document-authoring/adapters/node/node-document-planning-state-reader.d.ts +10 -0
  25. package/dist/document-authoring/adapters/node/node-document-planning-state-reader.d.ts.map +1 -0
  26. package/dist/document-authoring/adapters/node/node-document-planning-state-reader.js +164 -0
  27. package/dist/document-authoring/adapters/node/node-document-planning-state-reader.js.map +1 -0
  28. package/dist/document-authoring/adapters/node/node-document-template-reader.d.ts +10 -0
  29. package/dist/document-authoring/adapters/node/node-document-template-reader.d.ts.map +1 -0
  30. package/dist/document-authoring/adapters/node/node-document-template-reader.js +32 -0
  31. package/dist/document-authoring/adapters/node/node-document-template-reader.js.map +1 -0
  32. package/dist/document-authoring/adapters/node/read-document-authority-file.d.ts.map +1 -1
  33. package/dist/document-authoring/adapters/node/read-document-authority-file.js +3 -13
  34. package/dist/document-authoring/adapters/node/read-document-authority-file.js.map +1 -1
  35. package/dist/document-authoring/application/model/document-planning.d.ts +171 -0
  36. package/dist/document-authoring/application/model/document-planning.d.ts.map +1 -0
  37. package/dist/document-authoring/application/model/document-planning.js +2 -0
  38. package/dist/document-authoring/application/model/document-planning.js.map +1 -0
  39. package/dist/document-authoring/application/policies/authoring-profile-semantics.d.ts +38 -0
  40. package/dist/document-authoring/application/policies/authoring-profile-semantics.d.ts.map +1 -0
  41. package/dist/document-authoring/application/policies/authoring-profile-semantics.js +122 -0
  42. package/dist/document-authoring/application/policies/authoring-profile-semantics.js.map +1 -0
  43. package/dist/document-authoring/application/policies/document-contract-digests.d.ts +20 -0
  44. package/dist/document-authoring/application/policies/document-contract-digests.d.ts.map +1 -0
  45. package/dist/document-authoring/application/policies/document-contract-digests.js +275 -0
  46. package/dist/document-authoring/application/policies/document-contract-digests.js.map +1 -0
  47. package/dist/document-authoring/application/policies/document-logical-preimage.d.ts +14 -0
  48. package/dist/document-authoring/application/policies/document-logical-preimage.d.ts.map +1 -0
  49. package/dist/document-authoring/application/policies/document-logical-preimage.js +61 -0
  50. package/dist/document-authoring/application/policies/document-logical-preimage.js.map +1 -0
  51. package/dist/document-authoring/application/policies/document-planning-policy-error.d.ts +6 -0
  52. package/dist/document-authoring/application/policies/document-planning-policy-error.d.ts.map +1 -0
  53. package/dist/document-authoring/application/policies/document-planning-policy-error.js +9 -0
  54. package/dist/document-authoring/application/policies/document-planning-policy-error.js.map +1 -0
  55. package/dist/document-authoring/application/policies/document-repository-path.d.ts +1 -0
  56. package/dist/document-authoring/application/policies/document-repository-path.d.ts.map +1 -1
  57. package/dist/document-authoring/application/policies/document-repository-path.js +21 -2
  58. package/dist/document-authoring/application/policies/document-repository-path.js.map +1 -1
  59. package/dist/document-authoring/application/policies/document-temporary-path.d.ts +7 -0
  60. package/dist/document-authoring/application/policies/document-temporary-path.d.ts.map +1 -0
  61. package/dist/document-authoring/application/policies/document-temporary-path.js +34 -0
  62. package/dist/document-authoring/application/policies/document-temporary-path.js.map +1 -0
  63. package/dist/document-authoring/application/policies/normalize-document-intent.d.ts +3 -0
  64. package/dist/document-authoring/application/policies/normalize-document-intent.d.ts.map +1 -0
  65. package/dist/document-authoring/application/policies/normalize-document-intent.js +104 -0
  66. package/dist/document-authoring/application/policies/normalize-document-intent.js.map +1 -0
  67. package/dist/document-authoring/application/policies/resolve-document-authoring.d.ts +13 -0
  68. package/dist/document-authoring/application/policies/resolve-document-authoring.d.ts.map +1 -0
  69. package/dist/document-authoring/application/policies/resolve-document-authoring.js +154 -0
  70. package/dist/document-authoring/application/policies/resolve-document-authoring.js.map +1 -0
  71. package/dist/document-authoring/application/ports/canonical-document-renderer.d.ts +29 -0
  72. package/dist/document-authoring/application/ports/canonical-document-renderer.d.ts.map +1 -0
  73. package/dist/document-authoring/application/ports/canonical-document-renderer.js +2 -0
  74. package/dist/document-authoring/application/ports/canonical-document-renderer.js.map +1 -0
  75. package/dist/document-authoring/application/ports/document-contract-validator.d.ts +6 -0
  76. package/dist/document-authoring/application/ports/document-contract-validator.d.ts.map +1 -0
  77. package/dist/document-authoring/application/ports/document-contract-validator.js +2 -0
  78. package/dist/document-authoring/application/ports/document-contract-validator.js.map +1 -0
  79. package/dist/document-authoring/application/ports/document-planning-profile-reader.d.ts +9 -0
  80. package/dist/document-authoring/application/ports/document-planning-profile-reader.d.ts.map +1 -0
  81. package/dist/document-authoring/application/ports/document-planning-profile-reader.js +2 -0
  82. package/dist/document-authoring/application/ports/document-planning-profile-reader.js.map +1 -0
  83. package/dist/document-authoring/application/ports/document-planning-state-reader.d.ts +9 -0
  84. package/dist/document-authoring/application/ports/document-planning-state-reader.d.ts.map +1 -0
  85. package/dist/document-authoring/application/ports/document-planning-state-reader.js +2 -0
  86. package/dist/document-authoring/application/ports/document-planning-state-reader.js.map +1 -0
  87. package/dist/document-authoring/application/ports/document-template-reader.d.ts +9 -0
  88. package/dist/document-authoring/application/ports/document-template-reader.d.ts.map +1 -0
  89. package/dist/document-authoring/application/ports/document-template-reader.js +2 -0
  90. package/dist/document-authoring/application/ports/document-template-reader.js.map +1 -0
  91. package/dist/document-authoring/application/ports/documentation-catalog-reader.d.ts +11 -0
  92. package/dist/document-authoring/application/ports/documentation-catalog-reader.d.ts.map +1 -0
  93. package/dist/document-authoring/application/ports/documentation-catalog-reader.js +2 -0
  94. package/dist/document-authoring/application/ports/documentation-catalog-reader.js.map +1 -0
  95. package/dist/document-authoring/application/use-cases/build-documentation-catalog.d.ts +2 -1
  96. package/dist/document-authoring/application/use-cases/build-documentation-catalog.d.ts.map +1 -1
  97. package/dist/document-authoring/application/use-cases/build-documentation-catalog.js.map +1 -1
  98. package/dist/document-authoring/application/use-cases/compile-document-plan.d.ts +6 -0
  99. package/dist/document-authoring/application/use-cases/compile-document-plan.d.ts.map +1 -0
  100. package/dist/document-authoring/application/use-cases/compile-document-plan.js +156 -0
  101. package/dist/document-authoring/application/use-cases/compile-document-plan.js.map +1 -0
  102. package/dist/document-authoring/application/use-cases/plan-documentation-document.d.ts +66 -0
  103. package/dist/document-authoring/application/use-cases/plan-documentation-document.d.ts.map +1 -0
  104. package/dist/document-authoring/application/use-cases/plan-documentation-document.js +276 -0
  105. package/dist/document-authoring/application/use-cases/plan-documentation-document.js.map +1 -0
  106. package/dist/document-authoring/document-planning-error.d.ts +6 -0
  107. package/dist/document-authoring/document-planning-error.d.ts.map +1 -0
  108. package/dist/document-authoring/document-planning-error.js +9 -0
  109. package/dist/document-authoring/document-planning-error.js.map +1 -0
  110. package/dist/document-authoring/index.d.ts +10 -0
  111. package/dist/document-authoring/index.d.ts.map +1 -1
  112. package/dist/document-authoring/index.js +72 -0
  113. package/dist/document-authoring/index.js.map +1 -1
  114. package/dist/transaction-coordination/adapters/node/document-temporary-identity.d.ts +4 -0
  115. package/dist/transaction-coordination/adapters/node/document-temporary-identity.d.ts.map +1 -0
  116. package/dist/transaction-coordination/adapters/node/document-temporary-identity.js +30 -0
  117. package/dist/transaction-coordination/adapters/node/document-temporary-identity.js.map +1 -0
  118. package/dist/transaction-coordination/adapters/node/legacy-document-envelope-v2.d.ts +5 -0
  119. package/dist/transaction-coordination/adapters/node/legacy-document-envelope-v2.d.ts.map +1 -0
  120. package/dist/transaction-coordination/adapters/node/legacy-document-envelope-v2.js +212 -0
  121. package/dist/transaction-coordination/adapters/node/legacy-document-envelope-v2.js.map +1 -0
  122. package/dist/transaction-coordination/adapters/node/node-foundation-transaction-slot.d.ts.map +1 -1
  123. package/dist/transaction-coordination/adapters/node/node-foundation-transaction-slot.js +47 -25
  124. package/dist/transaction-coordination/adapters/node/node-foundation-transaction-slot.js.map +1 -1
  125. package/package.json +1 -1
  126. package/schemas/document-authoring-profile/v1.schema.json +64 -15
  127. package/schemas/document-command-envelope/v1.schema.json +1 -1
  128. package/schemas/document-intent/v1.schema.json +48 -6
  129. package/schemas/document-plan/v1.schema.json +20 -4
  130. package/schemas/document-receipt/v1.schema.json +1 -1
  131. package/schemas/foundation-transaction-envelope/v2.schema.json +21 -3
@@ -0,0 +1,275 @@
1
+ import { compareBinaryStrings } from "../../../binary-string-comparator.js";
2
+ import { canonicalJson, sha256Bytes, sha256Json } from "../../../canonical-json.js";
3
+ import { documentTemporaryPath } from "./document-temporary-path.js";
4
+ import { documentRepositoryParentPath } from "./document-repository-path.js";
5
+ const DOMAIN_PREFIX = "agent-teams.foundation.document-authoring";
6
+ class DocumentContractDigestError extends Error {
7
+ constructor(message, options) {
8
+ super(message, options);
9
+ this.name = "DocumentContractDigestError";
10
+ }
11
+ }
12
+ function domainDigest(domain, payload) {
13
+ return sha256Json({ domain, payload });
14
+ }
15
+ function withoutOwnDigest(value, field) {
16
+ const snapshot = JSON.parse(canonicalJson(value));
17
+ const result = Object.create(null);
18
+ for (const key of Reflect.ownKeys(snapshot)) {
19
+ if (key === field) {
20
+ continue;
21
+ }
22
+ if (typeof key !== "string") {
23
+ throw new DocumentContractDigestError("Document digest input must not contain symbolic properties.");
24
+ }
25
+ const descriptor = Object.getOwnPropertyDescriptor(snapshot, key);
26
+ if (descriptor === undefined || !("value" in descriptor)) {
27
+ throw new DocumentContractDigestError("Document digest input must contain only own data properties.");
28
+ }
29
+ result[key] = descriptor.value;
30
+ }
31
+ return result;
32
+ }
33
+ export function documentIntentDigest(intent) {
34
+ return domainDigest(`${DOMAIN_PREFIX}/intent/v1`, intent);
35
+ }
36
+ export function documentOwnerMembershipDigest(ownerCatalogDigest, ownerId) {
37
+ return domainDigest(`${DOMAIN_PREFIX}/owner-membership/v1`, {
38
+ ownerCatalogDigest,
39
+ ownerId
40
+ });
41
+ }
42
+ export function documentIdentityProjectionDigest(entries) {
43
+ const snapshot = JSON.parse(canonicalJson(entries));
44
+ const normalized = snapshot
45
+ .map(({ id, repositoryPath }) => ({ id, repositoryPath }))
46
+ .toSorted((left, right) => compareBinaryStrings(left.id, right.id) ||
47
+ compareBinaryStrings(left.repositoryPath, right.repositoryPath));
48
+ return domainDigest(`${DOMAIN_PREFIX}/identity-projection/v1`, {
49
+ entries: normalized
50
+ });
51
+ }
52
+ export function documentReferencedDocumentDigest(document) {
53
+ const snapshot = JSON.parse(canonicalJson(document));
54
+ return domainDigest(`${DOMAIN_PREFIX}/referenced-document/v1`, {
55
+ id: snapshot.id,
56
+ path: snapshot.path
57
+ });
58
+ }
59
+ export function documentPlanDigest(plan) {
60
+ return domainDigest(`${DOMAIN_PREFIX}/plan/v1`, withoutOwnDigest(plan, "planDigest"));
61
+ }
62
+ export function documentReceiptDigest(receipt) {
63
+ return domainDigest(`${DOMAIN_PREFIX}/receipt/v1`, withoutOwnDigest(receipt, "receiptDigest"));
64
+ }
65
+ function record(value, subject) {
66
+ if (value === null || Array.isArray(value) || typeof value !== "object") {
67
+ throw new DocumentContractDigestError(`${subject} must be a JSON object.`);
68
+ }
69
+ return value;
70
+ }
71
+ function validatedRecord(value, subject) {
72
+ const candidate = record(value, subject);
73
+ try {
74
+ return JSON.parse(canonicalJson(candidate));
75
+ }
76
+ catch (error) {
77
+ throw new DocumentContractDigestError(`${subject} must use the closed canonical JSON data model.`, { cause: error });
78
+ }
79
+ }
80
+ function assertPublicationBindings(plan) {
81
+ const destination = plan["destination"];
82
+ const expectedParent = record(plan["expectedParent"], "Document Plan expected parent");
83
+ const precondition = record(plan["destinationPrecondition"], "Document Plan destination precondition");
84
+ const capabilities = plan["requiredAdapterCapabilities"];
85
+ let hasTemporaryCapacity = false;
86
+ if (typeof destination === "string" && typeof plan["planDigest"] === "string") {
87
+ try {
88
+ documentTemporaryPath(destination, plan["planDigest"]);
89
+ hasTemporaryCapacity = true;
90
+ }
91
+ catch {
92
+ // The single publication error below is the stable public failure surface.
93
+ }
94
+ }
95
+ if (typeof destination !== "string" ||
96
+ !hasTemporaryCapacity ||
97
+ expectedParent["path"] !== documentRepositoryParentPath(destination) ||
98
+ expectedParent["state"] !== "directory" ||
99
+ expectedParent["ancestry"] !== "real-directories" ||
100
+ precondition["state"] !== "absent" ||
101
+ !Array.isArray(capabilities) ||
102
+ !capabilities.some((capability) => capability === "create-file-no-replace/v1")) {
103
+ throw new DocumentContractDigestError("Document Plan publication bindings are invalid.");
104
+ }
105
+ }
106
+ function assertIntentDigest(plan) {
107
+ const intent = record(plan["intent"], "Document Plan Intent");
108
+ if (plan["intentDigest"] !== documentIntentDigest(intent)) {
109
+ throw new DocumentContractDigestError("Document Plan Intent digest is invalid.");
110
+ }
111
+ }
112
+ function assertOwnerMembershipDigest(plan) {
113
+ const intent = record(plan["intent"], "Document Plan Intent");
114
+ const authority = record(plan["authority"], "Document Plan authority");
115
+ const ownerCatalog = record(authority["ownerCatalog"], "Document Plan owner catalog authority");
116
+ const selectedOwner = record(plan["selectedOwner"], "Document Plan selected owner");
117
+ if (typeof ownerCatalog["digest"] !== "string" ||
118
+ typeof intent["owner"] !== "string" ||
119
+ typeof selectedOwner["id"] !== "string" ||
120
+ selectedOwner["id"] !== intent["owner"] ||
121
+ selectedOwner["membershipDigest"] !==
122
+ documentOwnerMembershipDigest(ownerCatalog["digest"], selectedOwner["id"])) {
123
+ throw new DocumentContractDigestError("Document Plan owner membership digest is invalid.");
124
+ }
125
+ }
126
+ function hasExactCommit(commit, expected) {
127
+ return Object.entries(expected).every(([field, value]) => commit[field] === value);
128
+ }
129
+ function isRecoveryCommit(outcome, commit) {
130
+ const publication = commit["publication"];
131
+ const atomicity = commit["atomicity"];
132
+ return (commit["state"] === outcome &&
133
+ ["none", "published", "unknown"].includes(publication) &&
134
+ ["not-applicable", "single-file-atomic-create"].includes(atomicity) &&
135
+ (publication !== "published" || atomicity === "single-file-atomic-create") &&
136
+ (publication !== "none" || atomicity === "not-applicable") &&
137
+ commit["recoverability"] === "preserved-for-recovery");
138
+ }
139
+ function assertReceiptOutcomeCommit(receipt) {
140
+ const outcome = receipt["outcome"];
141
+ const commit = record(receipt["commit"], "Document Receipt commit observation");
142
+ const noResultOutcomes = [
143
+ "authority-stale",
144
+ "rejected",
145
+ "failed-before-publication",
146
+ "cancelled"
147
+ ];
148
+ const recoveryOutcomes = ["recovery-required", "manual-recovery-required"];
149
+ const applied = outcome === "applied" &&
150
+ typeof receipt["resultDigest"] === "string" &&
151
+ hasExactCommit(commit, {
152
+ state: "committed",
153
+ publication: "published",
154
+ atomicity: "single-file-atomic-create",
155
+ recoverability: "not-required"
156
+ });
157
+ const alreadyApplied = outcome === "already-applied" &&
158
+ typeof receipt["resultDigest"] === "string" &&
159
+ hasExactCommit(commit, {
160
+ state: "committed",
161
+ publication: "preexisting-exact",
162
+ atomicity: "not-applicable",
163
+ recoverability: "not-required"
164
+ });
165
+ const noResult = typeof outcome === "string" &&
166
+ noResultOutcomes.includes(outcome) &&
167
+ receipt["resultDigest"] === undefined &&
168
+ hasExactCommit(commit, {
169
+ state: "not-published",
170
+ publication: "none",
171
+ atomicity: "not-applicable",
172
+ recoverability: "not-required"
173
+ });
174
+ const recovery = typeof outcome === "string" &&
175
+ recoveryOutcomes.includes(outcome) &&
176
+ receipt["resultDigest"] === undefined &&
177
+ isRecoveryCommit(outcome, commit);
178
+ if (!applied && !alreadyApplied && !noResult && !recovery) {
179
+ throw new DocumentContractDigestError("Document Receipt outcome and commit observation are incompatible.");
180
+ }
181
+ }
182
+ function assertReferencedDocumentDigests(plan) {
183
+ const references = plan["referencedDocuments"];
184
+ if (!Array.isArray(references)) {
185
+ throw new DocumentContractDigestError("Document Plan referenced documents must be an array.");
186
+ }
187
+ for (const referenceValue of references) {
188
+ const reference = record(referenceValue, "Document Plan referenced document");
189
+ if (typeof reference["id"] !== "string" ||
190
+ typeof reference["path"] !== "string" ||
191
+ reference["projectionDigest"] !==
192
+ documentReferencedDocumentDigest({
193
+ id: reference["id"],
194
+ path: reference["path"]
195
+ })) {
196
+ throw new DocumentContractDigestError("Document Plan referenced-document digest is invalid.");
197
+ }
198
+ }
199
+ }
200
+ function assertOutputDigest(plan) {
201
+ const output = record(plan["output"], "Document Plan output");
202
+ if (typeof output["contentBase64"] !== "string") {
203
+ throw new DocumentContractDigestError("Document Plan output content must be canonical Base64.");
204
+ }
205
+ const bytes = Buffer.from(output["contentBase64"], "base64");
206
+ if (bytes.toString("base64") !== output["contentBase64"] ||
207
+ output["size"] !== bytes.byteLength ||
208
+ output["digest"] !== sha256Bytes(bytes)) {
209
+ throw new DocumentContractDigestError("Document Plan output digest is invalid.");
210
+ }
211
+ if (bytes[0] === 0xef && bytes[1] === 0xbb && bytes[2] === 0xbf) {
212
+ throw new DocumentContractDigestError("Document Plan output must not start with a UTF-8 BOM.");
213
+ }
214
+ let source;
215
+ try {
216
+ source = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
217
+ }
218
+ catch (error) {
219
+ throw new DocumentContractDigestError("Document Plan output is not well-formed UTF-8.", { cause: error });
220
+ }
221
+ if (source.startsWith("\uFEFF") ||
222
+ source.includes("\u0000") ||
223
+ source.includes("\r") ||
224
+ !source.endsWith("\n") ||
225
+ source.endsWith("\n\n") ||
226
+ output["mode"] !== "0644" ||
227
+ output["mediaType"] !== "text/markdown; charset=utf-8") {
228
+ throw new DocumentContractDigestError("Document Plan output violates the canonical Markdown byte contract.");
229
+ }
230
+ }
231
+ export function assertDocumentPlanDigests(value) {
232
+ const plan = validatedRecord(value, "Document Plan");
233
+ assertIntentDigest(plan);
234
+ assertOwnerMembershipDigest(plan);
235
+ assertReferencedDocumentDigests(plan);
236
+ assertOutputDigest(plan);
237
+ assertPublicationBindings(plan);
238
+ if (plan["planDigest"] !== documentPlanDigest(plan)) {
239
+ throw new DocumentContractDigestError("Document Plan digest is invalid.");
240
+ }
241
+ }
242
+ export function assertDocumentReceiptDigest(value, planValue) {
243
+ const receipt = validatedRecord(value, "Document Receipt");
244
+ if (receipt["receiptDigest"] !== documentReceiptDigest(receipt)) {
245
+ throw new DocumentContractDigestError("Document Receipt digest is invalid.");
246
+ }
247
+ assertReceiptOutcomeCommit(receipt);
248
+ if (planValue === undefined) {
249
+ return;
250
+ }
251
+ assertDocumentPlanDigests(planValue);
252
+ const plan = validatedRecord(planValue, "Document Plan");
253
+ const output = record(plan["output"], "Document Plan output");
254
+ const outcome = receipt["outcome"];
255
+ const hasProvenOutput = outcome === "applied" || outcome === "already-applied";
256
+ const supportedOutcomes = new Set([
257
+ "applied",
258
+ "already-applied",
259
+ "authority-stale",
260
+ "rejected",
261
+ "recovery-required",
262
+ "manual-recovery-required",
263
+ "failed-before-publication",
264
+ "cancelled"
265
+ ]);
266
+ if (typeof outcome !== "string" ||
267
+ !supportedOutcomes.has(outcome) ||
268
+ receipt["planDigest"] !== plan["planDigest"] ||
269
+ receipt["destination"] !== plan["destination"] ||
270
+ (hasProvenOutput && receipt["resultDigest"] !== output["digest"]) ||
271
+ (!hasProvenOutput && receipt["resultDigest"] !== undefined)) {
272
+ throw new DocumentContractDigestError("Document Receipt result evidence does not bind the referenced Plan.");
273
+ }
274
+ }
275
+ //# sourceMappingURL=document-contract-digests.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document-contract-digests.js","sourceRoot":"","sources":["../../../../src/document-authoring/application/policies/document-contract-digests.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAC5E,OAAO,EACL,aAAa,EAEb,WAAW,EACX,UAAU,EACX,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,4BAA4B,EAAE,MAAM,+BAA+B,CAAC;AAK7E,MAAM,aAAa,GAAG,2CAA2C,CAAC;AAElE,MAAM,2BAA4B,SAAQ,KAAK;IAC7C,YAAmB,OAAe,EAAE,OAAsB;QACxD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;IAC5C,CAAC;CACF;AAED,SAAS,YAAY,CAAC,MAAc,EAAE,OAA2B;IAC/D,OAAO,UAAU,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;AACzC,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAiB,EAAE,KAAa;IACxD,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAe,CAAC;IAChE,MAAM,MAAM,GAAuC,MAAM,CAAC,MAAM,CAAC,IAAI,CAGpE,CAAC;IACF,KAAK,MAAM,GAAG,IAAI,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AC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { DocumentCatalogCollection } from "../model/document-planning.js";
2
+ import type { DocumentIdentityProjectionEntry, DocumentationCatalogSnapshot } from "../model/document-catalog.js";
3
+ export declare function isDestinationCoveredByCatalog(destination: string, collections: readonly DocumentCatalogCollection[], excludedPrefixes: readonly string[]): boolean;
4
+ export declare function classifyDocumentLogicalPreimage(input: {
5
+ readonly catalog: DocumentationCatalogSnapshot;
6
+ readonly destination: string;
7
+ readonly expectedBytes: Uint8Array;
8
+ readonly id: string;
9
+ readonly observedBytes?: Uint8Array;
10
+ }): {
11
+ readonly identityProjection: readonly DocumentIdentityProjectionEntry[];
12
+ readonly isExactSelf: boolean;
13
+ };
14
+ //# sourceMappingURL=document-logical-preimage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document-logical-preimage.d.ts","sourceRoot":"","sources":["../../../../src/document-authoring/application/policies/document-logical-preimage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,yBAAyB,EAC1B,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EACV,+BAA+B,EAC/B,4BAA4B,EAC7B,MAAM,8BAA8B,CAAC;AAOtC,wBAAgB,6BAA6B,CAC3C,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,SAAS,yBAAyB,EAAE,EACjD,gBAAgB,EAAE,SAAS,MAAM,EAAE,GAClC,OAAO,CAUT;AAqBD,wBAAgB,+BAA+B,CAAC,KAAK,EAAE;IACrD,QAAQ,CAAC,OAAO,EAAE,4BAA4B,CAAC;IAC/C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,aAAa,EAAE,UAAU,CAAC;IACnC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,aAAa,CAAC,EAAE,UAAU,CAAC;CACrC,GAAG;IACF,QAAQ,CAAC,kBAAkB,EAAE,SAAS,+BAA+B,EAAE,CAAC;IACxE,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;CAC/B,CA8CA"}
@@ -0,0 +1,61 @@
1
+ import { compareBinaryStrings } from "../../../binary-string-comparator.js";
2
+ import { DocumentPlanningPolicyError } from "./document-planning-policy-error.js";
3
+ function isPrefix(prefix, path) {
4
+ return path === prefix || path.startsWith(`${prefix}/`);
5
+ }
6
+ export function isDestinationCoveredByCatalog(destination, collections, excludedPrefixes) {
7
+ if (excludedPrefixes.some((prefix) => isPrefix(prefix, destination))) {
8
+ return false;
9
+ }
10
+ return collections.some((collection) => collection.kind === "markdown-tree"
11
+ ? isPrefix(collection.root, destination)
12
+ : destination.endsWith("/README.md") &&
13
+ collection.roots.some((root) => isPrefix(root, destination)));
14
+ }
15
+ function sameBytes(left, right) {
16
+ return left.length === right.length && left.every((value, index) => value === right[index]);
17
+ }
18
+ function portablePath(path) {
19
+ return path.normalize("NFC").toLowerCase();
20
+ }
21
+ function sortedProjection(entries) {
22
+ return Object.freeze(entries
23
+ .map((entry) => Object.freeze({ id: entry.id, repositoryPath: entry.repositoryPath }))
24
+ .toSorted((left, right) => compareBinaryStrings(left.id, right.id) ||
25
+ compareBinaryStrings(left.repositoryPath, right.repositoryPath)));
26
+ }
27
+ export function classifyDocumentLogicalPreimage(input) {
28
+ if (input.catalog.status !== "complete") {
29
+ throw new DocumentPlanningPolicyError("catalog-incomplete", "Document planning requires a complete catalog.");
30
+ }
31
+ const entries = input.catalog.identityProjection;
32
+ const ids = new Set();
33
+ const paths = new Set();
34
+ for (const entry of entries) {
35
+ const path = portablePath(entry.repositoryPath);
36
+ if (ids.has(entry.id) || paths.has(path)) {
37
+ throw new DocumentPlanningPolicyError("catalog-collision", "Document catalog contains an identity or portable path collision.");
38
+ }
39
+ ids.add(entry.id);
40
+ paths.add(path);
41
+ }
42
+ const exactDescriptor = input.catalog.documents.filter((document) => document.id === input.id && document.repositoryPath === input.destination);
43
+ const exactEntry = entries.filter((entry) => entry.id === input.id && entry.repositoryPath === input.destination);
44
+ const isExactSelf = input.observedBytes !== undefined &&
45
+ sameBytes(input.observedBytes, input.expectedBytes) &&
46
+ exactDescriptor.length === 1 &&
47
+ exactEntry.length === 1;
48
+ const idCollision = entries.some((entry) => entry.id === input.id && !(isExactSelf && entry.repositoryPath === input.destination));
49
+ const pathCollision = entries.some((entry) => portablePath(entry.repositoryPath) === portablePath(input.destination) &&
50
+ !(isExactSelf && entry.repositoryPath === input.destination && entry.id === input.id));
51
+ if (idCollision || pathCollision || (input.observedBytes !== undefined && !isExactSelf)) {
52
+ throw new DocumentPlanningPolicyError("destination-conflict", "Document identity or destination conflicts with the logical preimage.");
53
+ }
54
+ return Object.freeze({
55
+ identityProjection: sortedProjection(isExactSelf
56
+ ? entries.filter((entry) => !(entry.id === input.id && entry.repositoryPath === input.destination))
57
+ : entries),
58
+ isExactSelf
59
+ });
60
+ }
61
+ //# sourceMappingURL=document-logical-preimage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document-logical-preimage.js","sourceRoot":"","sources":["../../../../src/document-authoring/application/policies/document-logical-preimage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAQ5E,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAElF,SAAS,QAAQ,CAAC,MAAc,EAAE,IAAY;IAC5C,OAAO,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC;AAC1D,CAAC;AAED,MAAM,UAAU,6BAA6B,CAC3C,WAAmB,EACnB,WAAiD,EACjD,gBAAmC;IAEnC,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC;QACrE,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CACrC,UA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M,WAAW,GAAG,OAAO,CAAC,IAAI,CAC9B,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC,WAAW,IAAI,KAAK,CAAC,cAAc,KAAK,KAAK,CAAC,WAAW,CAAC,CACjG,CAAC;IACF,MAAM,aAAa,GAAG,OAAO,CAAC,IAAI,CAChC,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,cAAc,CAAC,KAAK,YAAY,CAAC,KAAK,CAAC,WAAW,CAAC;QAC/E,CAAC,CAAC,WAAW,IAAI,KAAK,CAAC,cAAc,KAAK,KAAK,CAAC,WAAW,IAAI,KAAK,CAAC,EAAE,KAAK,KAAK,CAAC,EAAE,CAAC,CACxF,CAAC;IACF,IAAI,WAAW,IAAI,aAAa,IAAI,CAAC,KAAK,CAAC,aAAa,KAAK,SAAS,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;QACxF,MAAM,IAAI,2BAA2B,CAAC,sBAAsB,EAAE,uEAAuE,CAAC,CAAC;IACzI,CAAC;IAED,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,kBAAkB,EAAE,gBAAgB,CAClC,WAAW;YACT,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,KAAK,KAAK,CAAC,EAAE,IAAI,KAAK,CAAC,cAAc,KAAK,KAAK,CAAC,WAAW,CAAC,CAAC;YACnG,CAAC,CAAC,OAAO,CACZ;QACD,WAAW;KACZ,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,6 @@
1
+ export type DocumentPlanningPolicyProblem = "catalog-collision" | "catalog-incomplete" | "destination-conflict" | "destination-not-covered" | "duplicate-related" | "invalid-artifact-type" | "invalid-destination" | "invalid-identity" | "invalid-intent-json" | "invalid-slug" | "missing-destination" | "missing-slug";
2
+ export declare class DocumentPlanningPolicyError extends Error {
3
+ readonly problem: DocumentPlanningPolicyProblem;
4
+ constructor(problem: DocumentPlanningPolicyProblem, message: string);
5
+ }
6
+ //# sourceMappingURL=document-planning-policy-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document-planning-policy-error.d.ts","sourceRoot":"","sources":["../../../../src/document-authoring/application/policies/document-planning-policy-error.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,6BAA6B,GACrC,mBAAmB,GACnB,oBAAoB,GACpB,sBAAsB,GACtB,yBAAyB,GACzB,mBAAmB,GACnB,uBAAuB,GACvB,qBAAqB,GACrB,kBAAkB,GAClB,qBAAqB,GACrB,cAAc,GACd,qBAAqB,GACrB,cAAc,CAAC;AAEnB,qBAAa,2BAA4B,SAAQ,KAAK;IACpD,QAAQ,CAAC,OAAO,EAAE,6BAA6B,CAAC;IAEhD,YAAY,OAAO,EAAE,6BAA6B,EAAE,OAAO,EAAE,MAAM,EAIlE;CACF"}
@@ -0,0 +1,9 @@
1
+ export class DocumentPlanningPolicyError extends Error {
2
+ problem;
3
+ constructor(problem, message) {
4
+ super(message);
5
+ this.name = "DocumentPlanningPolicyError";
6
+ this.problem = problem;
7
+ }
8
+ }
9
+ //# sourceMappingURL=document-planning-policy-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document-planning-policy-error.js","sourceRoot":"","sources":["../../../../src/document-authoring/application/policies/document-planning-policy-error.ts"],"names":[],"mappings":"AAcA,MAAM,OAAO,2BAA4B,SAAQ,KAAK;IAC3C,OAAO,CAAgC;IAEhD,YAAY,OAAsC,EAAE,OAAe;QACjE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;QAC1C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF"}
@@ -1,2 +1,3 @@
1
1
  export declare function isDocumentRepositoryPath(path: string): boolean;
2
+ export declare function documentRepositoryParentPath(path: string): string;
2
3
  //# sourceMappingURL=document-repository-path.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"document-repository-path.d.ts","sourceRoot":"","sources":["../../../../src/document-authoring/application/policies/document-repository-path.ts"],"names":[],"mappings":"AAGA,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE9D"}
1
+ {"version":3,"file":"document-repository-path.d.ts","sourceRoot":"","sources":["../../../../src/document-authoring/application/policies/document-repository-path.ts"],"names":[],"mappings":"AAIA,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAmB9D;AAED,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGjE"}
@@ -1,5 +1,24 @@
1
- const DOCUMENT_REPOSITORY_PATH = /^(?!.*(?:^|\/)\.{1,2}(?:\/|$))(?!.*\.(?:\/|$))(?!.*(?:^|\/)(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.[A-Za-z0-9._@-]*)?(?:\/|$))[A-Za-z0-9._@-]+(?:\/[A-Za-z0-9._@-]+)*$/iu;
1
+ const DOCUMENT_REPOSITORY_SEGMENT = /^[A-Za-z0-9._@-]+$/u;
2
+ const WINDOWS_RESERVED_NAMES = /^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/iu;
3
+ const utf8 = new TextEncoder();
2
4
  export function isDocumentRepositoryPath(path) {
3
- return path.length <= 512 && DOCUMENT_REPOSITORY_PATH.test(path);
5
+ if (utf8.encode(path).byteLength > 512 ||
6
+ path.startsWith("/") ||
7
+ path.includes("\\")) {
8
+ return false;
9
+ }
10
+ const segments = path.split("/");
11
+ return segments.every((segment) => segment.length > 0 &&
12
+ segment !== "." &&
13
+ segment !== ".." &&
14
+ utf8.encode(segment).byteLength <= 255 &&
15
+ !segment.endsWith(".") &&
16
+ !segment.endsWith(" ") &&
17
+ !WINDOWS_RESERVED_NAMES.test(segment) &&
18
+ DOCUMENT_REPOSITORY_SEGMENT.test(segment));
19
+ }
20
+ export function documentRepositoryParentPath(path) {
21
+ const separator = path.lastIndexOf("/");
22
+ return separator === -1 ? "." : path.slice(0, separator);
4
23
  }
5
24
  //# sourceMappingURL=document-repository-path.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"document-repository-path.js","sourceRoot":"","sources":["../../../../src/document-authoring/application/policies/document-repository-path.ts"],"names":[],"mappings":"AAAA,MAAM,wBAAwB,GAC5B,4KAA4K,CAAC;AAE/K,MAAM,UAAU,wBAAwB,CAAC,IAAY;IACnD,OAAO,IAAI,CAAC,MAAM,IAAI,GAAG,IAAI,wBAAwB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACnE,CAAC"}
1
+ {"version":3,"file":"document-repository-path.js","sourceRoot":"","sources":["../../../../src/document-authoring/application/policies/document-repository-path.ts"],"names":[],"mappings":"AAAA,MAAM,2BAA2B,GAAG,qBAAqB,CAAC;AAC1D,MAAM,sBAAsB,GAAG,kDAAkD,CAAC;AAClF,MAAM,IAAI,GAAG,IAAI,WAAW,EAAE,CAAC;AAE/B,MAAM,UAAU,wBAAwB,CAAC,IAAY;IACnD,IACE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,UAAU,GAAG,GAAG;QAClC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;QACpB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EACnB,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACjC,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,EAAE,CAChC,OAAO,CAAC,MAAM,GAAG,CAAC;QAClB,OAAO,KAAK,GAAG;QACf,OAAO,KAAK,IAAI;QAChB,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,UAAU,IAAI,GAAG;QACtC,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC;QACtB,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC;QACtB,CAAC,sBAAsB,CAAC,IAAI,CAAC,OAAO,CAAC;QACrC,2BAA2B,CAAC,IAAI,CAAC,OAAO,CAAC,CAC1C,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,4BAA4B,CAAC,IAAY;IACvD,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACxC,OAAO,SAAS,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;AAC3D,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Derives the only transaction-owned temporary path for a Document Plan.
3
+ * The name is bounded independently of the destination basename and remains
4
+ * in the destination's already-authorized parent directory.
5
+ */
6
+ export declare function documentTemporaryPath(destination: string, planDigest: string): string;
7
+ //# sourceMappingURL=document-temporary-path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document-temporary-path.d.ts","sourceRoot":"","sources":["../../../../src/document-authoring/application/policies/document-temporary-path.ts"],"names":[],"mappings":"AAaA;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,GACjB,MAAM,CAyBR"}
@@ -0,0 +1,34 @@
1
+ import { isDocumentRepositoryPath } from "./document-repository-path.js";
2
+ const CANONICAL_SHA256_DIGEST = /^sha256:[0-9a-f]{64}$/u;
3
+ const TEMPORARY_PREFIX = ".foundation-document-";
4
+ const TEMPORARY_SUFFIX = ".tmp";
5
+ class DocumentTemporaryPathError extends Error {
6
+ constructor(message) {
7
+ super(message);
8
+ this.name = "DocumentTemporaryPathError";
9
+ }
10
+ }
11
+ /**
12
+ * Derives the only transaction-owned temporary path for a Document Plan.
13
+ * The name is bounded independently of the destination basename and remains
14
+ * in the destination's already-authorized parent directory.
15
+ */
16
+ export function documentTemporaryPath(destination, planDigest) {
17
+ if (!isDocumentRepositoryPath(destination)) {
18
+ throw new DocumentTemporaryPathError("Document destination is not a portable repository path.");
19
+ }
20
+ if (!CANONICAL_SHA256_DIGEST.test(planDigest)) {
21
+ throw new DocumentTemporaryPathError("Document Plan digest is not canonical SHA-256.");
22
+ }
23
+ const separator = destination.lastIndexOf("/");
24
+ const parent = separator === -1 ? "" : destination.slice(0, separator);
25
+ const temporaryName = `${TEMPORARY_PREFIX}${planDigest.slice("sha256:".length)}${TEMPORARY_SUFFIX}`;
26
+ const temporaryPath = parent.length === 0
27
+ ? temporaryName
28
+ : `${parent}/${temporaryName}`;
29
+ if (!isDocumentRepositoryPath(temporaryPath)) {
30
+ throw new DocumentTemporaryPathError("Document destination parent cannot contain the bounded transaction temporary.");
31
+ }
32
+ return temporaryPath;
33
+ }
34
+ //# sourceMappingURL=document-temporary-path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document-temporary-path.js","sourceRoot":"","sources":["../../../../src/document-authoring/application/policies/document-temporary-path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE,MAAM,uBAAuB,GAAG,wBAAwB,CAAC;AACzD,MAAM,gBAAgB,GAAG,uBAAuB,CAAC;AACjD,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEhC,MAAM,0BAA2B,SAAQ,KAAK;IAC5C,YAAmB,OAAe;QAChC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAC3C,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CACnC,WAAmB,EACnB,UAAkB;IAElB,IAAI,CAAC,wBAAwB,CAAC,WAAW,CAAC,EAAE,CAAC;QAC3C,MAAM,IAAI,0BAA0B,CAClC,yDAAyD,CAC1D,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;QAC9C,MAAM,IAAI,0BAA0B,CAClC,gDAAgD,CACjD,CAAC;IACJ,CAAC;IAED,MAAM,SAAS,GAAG,WAAW,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAC/C,MAAM,MAAM,GAAG,SAAS,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;IACvE,MAAM,aAAa,GAAG,GAAG,gBAAgB,GAAG,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,gBAAgB,EAAE,CAAC;IACpG,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,KAAK,CAAC;QACvC,CAAC,CAAC,aAAa;QACf,CAAC,CAAC,GAAG,MAAM,IAAI,aAAa,EAAE,CAAC;IAEjC,IAAI,CAAC,wBAAwB,CAAC,aAAa,CAAC,EAAE,CAAC;QAC7C,MAAM,IAAI,0BAA0B,CAClC,+EAA+E,CAChF,CAAC;IACJ,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { DocumentIntent } from "../model/document-planning.js";
2
+ export declare function normalizeDocumentIntent(input: DocumentIntent): DocumentIntent;
3
+ //# sourceMappingURL=normalize-document-intent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize-document-intent.d.ts","sourceRoot":"","sources":["../../../../src/document-authoring/application/policies/normalize-document-intent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EAGf,MAAM,+BAA+B,CAAC;AA4FvC,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,cAAc,GAAG,cAAc,CAyB7E"}
@@ -0,0 +1,104 @@
1
+ import { compareBinaryStrings } from "../../../binary-string-comparator.js";
2
+ import { DocumentPlanningPolicyError } from "./document-planning-policy-error.js";
3
+ const FORBIDDEN_KEYS = new Set(["__proto__", "constructor", "prototype"]);
4
+ const GOVERNED_KEYS = new Set([
5
+ "destination",
6
+ "id",
7
+ "owner",
8
+ "related",
9
+ "slug",
10
+ "status",
11
+ "summary",
12
+ "title",
13
+ "type"
14
+ ]);
15
+ function invalidJson(message) {
16
+ throw new DocumentPlanningPolicyError("invalid-intent-json", message);
17
+ }
18
+ function normalizeString(value) {
19
+ for (let index = 0; index < value.length; index += 1) {
20
+ const unit = value.charCodeAt(index);
21
+ if (unit >= 0xd800 && unit <= 0xdbff) {
22
+ const next = value.charCodeAt(index + 1);
23
+ if (!Number.isInteger(next) || next < 0xdc00 || next > 0xdfff) {
24
+ return invalidJson("Document Intent contains a lone UTF-16 surrogate.");
25
+ }
26
+ index += 1;
27
+ }
28
+ else if (unit >= 0xdc00 && unit <= 0xdfff) {
29
+ return invalidJson("Document Intent contains a lone UTF-16 surrogate.");
30
+ }
31
+ }
32
+ return value.normalize("NFC");
33
+ }
34
+ function normalizeJsonObject(value) {
35
+ const normalized = new Map();
36
+ for (const [rawKey, rawValue] of Object.entries(value)) {
37
+ const key = normalizeString(rawKey);
38
+ if (FORBIDDEN_KEYS.has(key)) {
39
+ return invalidJson(`Document Intent contains forbidden metadata key: ${key}.`);
40
+ }
41
+ if (normalized.has(key)) {
42
+ return invalidJson("Document Intent metadata keys collide after NFC normalization.");
43
+ }
44
+ normalized.set(key, normalizeJson(rawValue));
45
+ }
46
+ return Object.freeze(Object.fromEntries([...normalized].toSorted(([left], [right]) => compareBinaryStrings(left, right))));
47
+ }
48
+ function isJsonArray(value) {
49
+ return Array.isArray(value);
50
+ }
51
+ function normalizeJson(value) {
52
+ if (typeof value === "string") {
53
+ return normalizeString(value);
54
+ }
55
+ if (typeof value === "number") {
56
+ if (!Number.isSafeInteger(value) || Object.is(value, -0)) {
57
+ return invalidJson("Document Intent numbers must be safe integers other than negative zero.");
58
+ }
59
+ return value;
60
+ }
61
+ if (value === null || typeof value === "boolean") {
62
+ return value;
63
+ }
64
+ if (isJsonArray(value)) {
65
+ return Object.freeze(value.map(normalizeJson));
66
+ }
67
+ return normalizeJsonObject(value);
68
+ }
69
+ function normalizeAdditionalMetadata(metadata) {
70
+ if (metadata === undefined) {
71
+ return undefined;
72
+ }
73
+ const normalized = normalizeJsonObject(metadata);
74
+ for (const key of Object.keys(normalized)) {
75
+ if (GOVERNED_KEYS.has(key)) {
76
+ return invalidJson(`Document Intent additional metadata replaces governed key: ${key}.`);
77
+ }
78
+ }
79
+ return normalized;
80
+ }
81
+ export function normalizeDocumentIntent(input) {
82
+ const related = input.related?.map(normalizeString);
83
+ if (related !== undefined && new Set(related).size !== related.length) {
84
+ throw new DocumentPlanningPolicyError("duplicate-related", "Document Intent related identifiers must remain unique after NFC normalization.");
85
+ }
86
+ const additionalMetadata = normalizeAdditionalMetadata(input.additionalMetadata);
87
+ return Object.freeze({
88
+ schemaVersion: 1,
89
+ type: normalizeString(input.type),
90
+ id: normalizeString(input.id),
91
+ title: normalizeString(input.title),
92
+ owner: normalizeString(input.owner),
93
+ summary: normalizeString(input.summary),
94
+ ...(input.slug === undefined ? {} : { slug: normalizeString(input.slug) }),
95
+ ...(input.destination === undefined
96
+ ? {}
97
+ : { destination: normalizeString(input.destination) }),
98
+ ...(related === undefined
99
+ ? {}
100
+ : { related: Object.freeze(related.toSorted(compareBinaryStrings)) }),
101
+ ...(additionalMetadata === undefined ? {} : { additionalMetadata })
102
+ });
103
+ }
104
+ //# sourceMappingURL=normalize-document-intent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize-document-intent.js","sourceRoot":"","sources":["../../../../src/document-authoring/application/policies/normalize-document-intent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAM5E,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAElF,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC,CAAC;AAC1E,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC;IAC5B,aAAa;IACb,IA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