@azx-pbc/axiom-builder 0.0.0-stage → 0.0.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.
Files changed (231) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +648 -2
  3. package/dist/cards/selectors.d.ts +70 -0
  4. package/dist/cards/selectors.d.ts.map +1 -0
  5. package/dist/cards/selectors.js +194 -0
  6. package/dist/cards/selectors.js.map +1 -0
  7. package/dist/definition.d.ts +36 -0
  8. package/dist/definition.d.ts.map +1 -0
  9. package/dist/definition.js +48 -0
  10. package/dist/definition.js.map +1 -0
  11. package/dist/evidence/cases.d.ts +44 -0
  12. package/dist/evidence/cases.d.ts.map +1 -0
  13. package/dist/evidence/cases.js +578 -0
  14. package/dist/evidence/cases.js.map +1 -0
  15. package/dist/evidence/repairs.d.ts +99 -0
  16. package/dist/evidence/repairs.d.ts.map +1 -0
  17. package/dist/evidence/repairs.js +181 -0
  18. package/dist/evidence/repairs.js.map +1 -0
  19. package/dist/evidence/summary.d.ts +35 -0
  20. package/dist/evidence/summary.d.ts.map +1 -0
  21. package/dist/evidence/summary.js +38 -0
  22. package/dist/evidence/summary.js.map +1 -0
  23. package/dist/i18n/gaps.d.ts +3 -0
  24. package/dist/i18n/gaps.d.ts.map +1 -0
  25. package/dist/i18n/gaps.js +2 -0
  26. package/dist/i18n/gaps.js.map +1 -0
  27. package/dist/i18n/message-slots.d.ts +19 -0
  28. package/dist/i18n/message-slots.d.ts.map +1 -0
  29. package/dist/i18n/message-slots.js +101 -0
  30. package/dist/i18n/message-slots.js.map +1 -0
  31. package/dist/i18n/text-locale.d.ts +13 -0
  32. package/dist/i18n/text-locale.d.ts.map +1 -0
  33. package/dist/i18n/text-locale.js +14 -0
  34. package/dist/i18n/text-locale.js.map +1 -0
  35. package/dist/i18n/translations.d.ts +56 -0
  36. package/dist/i18n/translations.d.ts.map +1 -0
  37. package/dist/i18n/translations.js +103 -0
  38. package/dist/i18n/translations.js.map +1 -0
  39. package/dist/impact/references.d.ts +143 -0
  40. package/dist/impact/references.d.ts.map +1 -0
  41. package/dist/impact/references.js +429 -0
  42. package/dist/impact/references.js.map +1 -0
  43. package/dist/index.d.ts +86 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +58 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/preview/compile-preview.d.ts +67 -0
  48. package/dist/preview/compile-preview.d.ts.map +1 -0
  49. package/dist/preview/compile-preview.js +286 -0
  50. package/dist/preview/compile-preview.js.map +1 -0
  51. package/dist/preview/handle.d.ts +119 -0
  52. package/dist/preview/handle.d.ts.map +1 -0
  53. package/dist/preview/handle.js +2 -0
  54. package/dist/preview/handle.js.map +1 -0
  55. package/dist/preview/held.d.ts +39 -0
  56. package/dist/preview/held.d.ts.map +1 -0
  57. package/dist/preview/held.js +15 -0
  58. package/dist/preview/held.js.map +1 -0
  59. package/dist/preview/measurement.d.ts +5 -0
  60. package/dist/preview/measurement.d.ts.map +1 -0
  61. package/dist/preview/measurement.js +18 -0
  62. package/dist/preview/measurement.js.map +1 -0
  63. package/dist/publish/build.d.ts +33 -0
  64. package/dist/publish/build.d.ts.map +1 -0
  65. package/dist/publish/build.js +15 -0
  66. package/dist/publish/build.js.map +1 -0
  67. package/dist/publish/diff.d.ts +208 -0
  68. package/dist/publish/diff.d.ts.map +1 -0
  69. package/dist/publish/diff.js +227 -0
  70. package/dist/publish/diff.js.map +1 -0
  71. package/dist/publish/review.d.ts +41 -0
  72. package/dist/publish/review.d.ts.map +1 -0
  73. package/dist/publish/review.js +22 -0
  74. package/dist/publish/review.js.map +1 -0
  75. package/dist/schema/dataset-input.d.ts +30 -0
  76. package/dist/schema/dataset-input.d.ts.map +1 -0
  77. package/dist/schema/dataset-input.js +58 -0
  78. package/dist/schema/dataset-input.js.map +1 -0
  79. package/dist/schema/dataset.d.ts +166 -0
  80. package/dist/schema/dataset.d.ts.map +1 -0
  81. package/dist/schema/dataset.js +281 -0
  82. package/dist/schema/dataset.js.map +1 -0
  83. package/dist/schema/declarations.d.ts +15 -0
  84. package/dist/schema/declarations.d.ts.map +1 -0
  85. package/dist/schema/declarations.js +47 -0
  86. package/dist/schema/declarations.js.map +1 -0
  87. package/dist/schema/document.d.ts +504 -0
  88. package/dist/schema/document.d.ts.map +1 -0
  89. package/dist/schema/document.js +337 -0
  90. package/dist/schema/document.js.map +1 -0
  91. package/dist/schema/error.d.ts +15 -0
  92. package/dist/schema/error.d.ts.map +1 -0
  93. package/dist/schema/error.js +18 -0
  94. package/dist/schema/error.js.map +1 -0
  95. package/dist/schema/field-id.d.ts +8 -0
  96. package/dist/schema/field-id.d.ts.map +1 -0
  97. package/dist/schema/field-id.js +47 -0
  98. package/dist/schema/field-id.js.map +1 -0
  99. package/dist/schema/layout.d.ts +118 -0
  100. package/dist/schema/layout.d.ts.map +1 -0
  101. package/dist/schema/layout.js +101 -0
  102. package/dist/schema/layout.js.map +1 -0
  103. package/dist/schema/palette.d.ts +103 -0
  104. package/dist/schema/palette.d.ts.map +1 -0
  105. package/dist/schema/palette.js +140 -0
  106. package/dist/schema/palette.js.map +1 -0
  107. package/dist/schema/read.d.ts +49 -0
  108. package/dist/schema/read.d.ts.map +1 -0
  109. package/dist/schema/read.js +942 -0
  110. package/dist/schema/read.js.map +1 -0
  111. package/dist/store/apply-dataset.d.ts +14 -0
  112. package/dist/store/apply-dataset.d.ts.map +1 -0
  113. package/dist/store/apply-dataset.js +513 -0
  114. package/dist/store/apply-dataset.js.map +1 -0
  115. package/dist/store/apply.d.ts +37 -0
  116. package/dist/store/apply.d.ts.map +1 -0
  117. package/dist/store/apply.js +2269 -0
  118. package/dist/store/apply.js.map +1 -0
  119. package/dist/store/candidate.d.ts +37 -0
  120. package/dist/store/candidate.d.ts.map +1 -0
  121. package/dist/store/candidate.js +178 -0
  122. package/dist/store/candidate.js.map +1 -0
  123. package/dist/store/commands/coverage.d.ts +58 -0
  124. package/dist/store/commands/coverage.d.ts.map +1 -0
  125. package/dist/store/commands/coverage.js +354 -0
  126. package/dist/store/commands/coverage.js.map +1 -0
  127. package/dist/store/commands/dataset.d.ts +26 -0
  128. package/dist/store/commands/dataset.d.ts.map +1 -0
  129. package/dist/store/commands/dataset.js +368 -0
  130. package/dist/store/commands/dataset.js.map +1 -0
  131. package/dist/store/commands/document.d.ts +21 -0
  132. package/dist/store/commands/document.d.ts.map +1 -0
  133. package/dist/store/commands/document.js +160 -0
  134. package/dist/store/commands/document.js.map +1 -0
  135. package/dist/store/commands/field.d.ts +32 -0
  136. package/dist/store/commands/field.d.ts.map +1 -0
  137. package/dist/store/commands/field.js +572 -0
  138. package/dist/store/commands/field.js.map +1 -0
  139. package/dist/store/commands/layout.d.ts +16 -0
  140. package/dist/store/commands/layout.d.ts.map +1 -0
  141. package/dist/store/commands/layout.js +70 -0
  142. package/dist/store/commands/layout.js.map +1 -0
  143. package/dist/store/commands/parse.d.ts +19 -0
  144. package/dist/store/commands/parse.d.ts.map +1 -0
  145. package/dist/store/commands/parse.js +328 -0
  146. package/dist/store/commands/parse.js.map +1 -0
  147. package/dist/store/commands/readers.d.ts +198 -0
  148. package/dist/store/commands/readers.d.ts.map +1 -0
  149. package/dist/store/commands/readers.js +711 -0
  150. package/dist/store/commands/readers.js.map +1 -0
  151. package/dist/store/commands/rule.d.ts +24 -0
  152. package/dist/store/commands/rule.d.ts.map +1 -0
  153. package/dist/store/commands/rule.js +379 -0
  154. package/dist/store/commands/rule.js.map +1 -0
  155. package/dist/store/commands/shapes.d.ts +900 -0
  156. package/dist/store/commands/shapes.d.ts.map +1 -0
  157. package/dist/store/commands/shapes.js +166 -0
  158. package/dist/store/commands/shapes.js.map +1 -0
  159. package/dist/store/commands/suggestions.d.ts +37 -0
  160. package/dist/store/commands/suggestions.d.ts.map +1 -0
  161. package/dist/store/commands/suggestions.js +177 -0
  162. package/dist/store/commands/suggestions.js.map +1 -0
  163. package/dist/store/commands.d.ts +16 -0
  164. package/dist/store/commands.d.ts.map +1 -0
  165. package/dist/store/commands.js +13 -0
  166. package/dist/store/commands.js.map +1 -0
  167. package/dist/store/dataset-candidate.d.ts +33 -0
  168. package/dist/store/dataset-candidate.d.ts.map +1 -0
  169. package/dist/store/dataset-candidate.js +31 -0
  170. package/dist/store/dataset-candidate.js.map +1 -0
  171. package/dist/store/dataset-pin.d.ts +93 -0
  172. package/dist/store/dataset-pin.d.ts.map +1 -0
  173. package/dist/store/dataset-pin.js +86 -0
  174. package/dist/store/dataset-pin.js.map +1 -0
  175. package/dist/store/dataset-store.d.ts +96 -0
  176. package/dist/store/dataset-store.d.ts.map +1 -0
  177. package/dist/store/dataset-store.js +112 -0
  178. package/dist/store/dataset-store.js.map +1 -0
  179. package/dist/store/history.d.ts +149 -0
  180. package/dist/store/history.d.ts.map +1 -0
  181. package/dist/store/history.js +173 -0
  182. package/dist/store/history.js.map +1 -0
  183. package/dist/store/measurement.d.ts +5 -0
  184. package/dist/store/measurement.d.ts.map +1 -0
  185. package/dist/store/measurement.js +20 -0
  186. package/dist/store/measurement.js.map +1 -0
  187. package/dist/store/notify.d.ts +11 -0
  188. package/dist/store/notify.d.ts.map +1 -0
  189. package/dist/store/notify.js +26 -0
  190. package/dist/store/notify.js.map +1 -0
  191. package/dist/store/published.d.ts +50 -0
  192. package/dist/store/published.d.ts.map +1 -0
  193. package/dist/store/published.js +27 -0
  194. package/dist/store/published.js.map +1 -0
  195. package/dist/store/refusals.d.ts +175 -0
  196. package/dist/store/refusals.d.ts.map +1 -0
  197. package/dist/store/refusals.js +160 -0
  198. package/dist/store/refusals.js.map +1 -0
  199. package/dist/store/steps.d.ts +14 -0
  200. package/dist/store/steps.d.ts.map +1 -0
  201. package/dist/store/steps.js +124 -0
  202. package/dist/store/steps.js.map +1 -0
  203. package/dist/store/store.d.ts +142 -0
  204. package/dist/store/store.d.ts.map +1 -0
  205. package/dist/store/store.js +136 -0
  206. package/dist/store/store.js.map +1 -0
  207. package/dist/store/unchanged.d.ts +12 -0
  208. package/dist/store/unchanged.d.ts.map +1 -0
  209. package/dist/store/unchanged.js +35 -0
  210. package/dist/store/unchanged.js.map +1 -0
  211. package/dist/visual/emit.d.ts +21 -0
  212. package/dist/visual/emit.d.ts.map +1 -0
  213. package/dist/visual/emit.js +133 -0
  214. package/dist/visual/emit.js.map +1 -0
  215. package/dist/visual/parse.d.ts +32 -0
  216. package/dist/visual/parse.d.ts.map +1 -0
  217. package/dist/visual/parse.js +330 -0
  218. package/dist/visual/parse.js.map +1 -0
  219. package/dist/visual/project.d.ts +40 -0
  220. package/dist/visual/project.d.ts.map +1 -0
  221. package/dist/visual/project.js +349 -0
  222. package/dist/visual/project.js.map +1 -0
  223. package/dist/visual/represent.d.ts +50 -0
  224. package/dist/visual/represent.d.ts.map +1 -0
  225. package/dist/visual/represent.js +66 -0
  226. package/dist/visual/represent.js.map +1 -0
  227. package/dist/visual/vocabulary.d.ts +121 -0
  228. package/dist/visual/vocabulary.d.ts.map +1 -0
  229. package/dist/visual/vocabulary.js +32 -0
  230. package/dist/visual/vocabulary.js.map +1 -0
  231. package/package.json +52 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handle.js","sourceRoot":"","sources":["../../src/preview/handle.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n CandidateDelta,\n Engine,\n EngineCandidate,\n EngineFieldExplanation,\n EngineOperation,\n EngineOutcome,\n EnginePorts,\n EvaluationEnv,\n EvaluationInput,\n FormBlocker,\n FormState,\n ReportFacts,\n SessionRefusal,\n} from '@azx-pbc/axiom-runtime';\nimport type { SchemaDiagnostic, TranslationGap } from '@azx-pbc/axiom-compiler';\n\n/**\n * The preview handle a builder renders from.\n *\n * A preview is a live, ephemeral form: it evaluates the document an author is editing so the UI\n * can show it, and it is *not* a deployable artifact. The distinction is the type, not a naming\n * convention. The handle carries a derived `FormState` whose report states no digest, and an\n * engine whose every report-bearing member is narrowed the same way. No member returns the\n * compiled schema, the artifact, or anything from which one could be serialised into a\n * deployment.\n *\n * **Both** digests a build states are withheld, not only the report's. `ReportFacts` is the\n * report body without `reportHash`, and it still carries `behaviorHash` — the artifact's own\n * behaviour commitment, which the compiler's publish gate compares evidence against\n * (`readinessGaps`). Because behaviour hashes strip presentation, the preview's value is\n * *identical* to the strict build's, so a preview that stated it would hand a host a correct\n * answer to \"what will this ship\" for a document that has not even been translated. A preview\n * therefore narrows the body to `PreviewReportFacts` and states neither digest.\n */\n\n/** A report body without either digest a deployment is read from. */\nexport type PreviewReportFacts = Omit<ReportFacts, 'behaviorHash'>;\n\n/** The derived form state a preview states: the runtime's own, with its report narrowed. */\nexport type PreviewFormState = Omit<FormState, 'report'> & {\n readonly report: PreviewReportFacts;\n};\n\n/** What a caller may supply to a preview engine; the artifact is already fixed. */\nexport interface PreviewEngineConfig {\n /** The record the session starts from; an empty record when the caller states none. */\n readonly input?: EvaluationInput;\n readonly env?: EvaluationEnv;\n readonly ports?: EnginePorts;\n}\n\n/**\n * A proposal a preview session can commit, with its report and form state narrowed.\n *\n * `Engine.preview` seals the report of the state the operations would produce, and a sealed\n * report carries a digest. That digest is one of the two values a preview must not hand a\n * caller, so the proposal states the report's body and nothing a build could be mistaken for.\n * Commit maps this narrowed view back to the session's original owned candidate.\n */\nexport type PreviewCandidate = Omit<EngineCandidate, 'report' | 'form' | 'session'> & {\n readonly report: PreviewReportFacts;\n readonly form: PreviewFormState;\n};\n\n/** The audit trail behind one binding, without either digest a deployment is read from. */\nexport type PreviewFieldExplanation = Omit<EngineFieldExplanation, 'reportHash' | 'behaviorHash'>;\n\n/**\n * A delta stated by a preview, with the two report digests withheld.\n *\n * The candidate delta names the reports before and after a change set, and both are digests a\n * build is read from. A preview states the same facts with those two members removed, exactly as\n * it states a proposal without a sealed report's digest.\n */\nexport type PreviewCandidateDelta = Omit<CandidateDelta, 'baseReportHash' | 'candidateReportHash'>;\n\n/** A proposal a preview session can commit, with its report, form state and delta narrowed. */\nexport type PreviewProposal = {\n readonly outcome: 'proposed';\n readonly candidate: PreviewCandidate;\n /**\n * The blockers the change set adds, computed without sealing either report.\n *\n * A host that only decides whether a write is worth confirming reads this and nothing else, so\n * a staged write that is never inspected pays no canonicalisation or hash.\n */\n readonly addedBlockers: readonly FormBlocker[];\n /**\n * The whole delta, built lazily on first read with the two report digests withheld.\n */\n readonly delta: PreviewCandidateDelta;\n};\n\n/**\n * A live session over the preview artifact, with every hash a deployment could be read from\n * removed.\n *\n * Every operation, subscription and derived state of `Engine` is available. Five members answer\n * with a sealed report or a state that carries one — `report`, `getFormState`, `preview`,\n * `propose` and `explainField` — and each is narrowed here to the report's digest-free body.\n * `commit` maps the narrowed proposal to the original candidate, whose owning session checks its\n * basis and operations.\n */\nexport type PreviewEngine = Omit<\n Engine,\n 'report' | 'getFormState' | 'preview' | 'propose' | 'explainField' | 'commit'\n> & {\n readonly report: () => PreviewReportFacts;\n readonly getFormState: () => PreviewFormState;\n readonly preview: (operations: readonly EngineOperation[]) => PreviewCandidate | SessionRefusal;\n readonly propose: (operations: readonly EngineOperation[]) => PreviewProposal | SessionRefusal;\n readonly commit: (candidate: PreviewCandidate) => EngineOutcome;\n readonly explainField: (fieldId: string, rowKey?: string | number) => PreviewFieldExplanation;\n};\n\n/** The preview could not be built: the document does not compile, or the locale is not carried. */\nexport interface PreviewFailure {\n readonly ok: false;\n readonly previewOnly: true;\n /** Why no preview exists, in the compiler's own vocabulary, so an editor underlines them. */\n readonly diagnostics: readonly SchemaDiagnostic[];\n}\n\n/** A live preview of the document, with every member opaque about the artifact beneath it. */\nexport interface PreviewSuccess {\n readonly ok: true;\n readonly previewOnly: true;\n /**\n * SHA-256 of the authored source document the preview was built from.\n *\n * It identifies *the draft*, not a build: two edits to one field produce two hashes, and the\n * same draft always produces the same one. It is deliberately not a report hash.\n */\n readonly sourceHash: string;\n /** The form the preview's record evaluates to, with no digest in its report. */\n readonly state: PreviewFormState;\n /** Every declared locale a catalogue entry is missing, from the compiler's own walk. */\n readonly translationGaps: readonly TranslationGap[];\n /** Evaluates another record against the same preview artifact, purely. */\n readonly evaluatePreview: (input: EvaluationInput, env?: EvaluationEnv) => PreviewFormState;\n /** Opens a live session over the same preview artifact. */\n readonly createPreviewEngine: (config?: PreviewEngineConfig) => PreviewEngine;\n}\n\n/** A preview or the reasons there is none. */\nexport type PreviewCompileResult = PreviewSuccess | PreviewFailure;\n"]}
@@ -0,0 +1,39 @@
1
+ import type { CompiledSchema } from '@azx-pbc/axiom-runtime';
2
+ import type { AuthoringDocument } from '../schema/document.js';
3
+ /**
4
+ * The artifact one committed dispatch already compiled, held for the preview of that state.
5
+ *
6
+ * A dispatch compiles its candidate to learn what a build would say about it. The preview of the
7
+ * state that dispatch committed compiles the same draft again unless the artifact is kept, so a
8
+ * keystroke plus a preview cost two compiles of one document. This is where the gate's artifact
9
+ * is filed: keyed by the document object it read, which is the object the store hands back.
10
+ *
11
+ * The entry carries the exact source the compile read, not only the artifact. The preview accepts
12
+ * it only when that source is still the document's own text and is also the single-locale source
13
+ * the preview would compile, so a mutated draft or another locale falls back to a compile rather
14
+ * than showing a form the draft no longer has.
15
+ *
16
+ * **One slot, not a map.** The hold used to be a `WeakMap` keyed by every document it saw, and
17
+ * the undo chain retains one document per step: two hundred steps then retained two hundred
18
+ * compiled artifacts — 0.69 MiB per step, 138 MiB at the limit, against 0.02 MiB for a control
19
+ * that kept the same documents and no artifact. Only the most recent dispatch's state can be the
20
+ * one previewed next, so one slot answers every reuse the chain can offer, and a second append
21
+ * replaces it rather than filing a second entry. Re-previewing an older state compiles again,
22
+ * which is the price of a bound that does not grow with the history.
23
+ */
24
+ /** One artifact, with the source text the compile consumed to produce it. */
25
+ export interface HeldPreviewArtifact {
26
+ readonly source: string;
27
+ readonly schema: CompiledSchema;
28
+ }
29
+ /** One held artifact and the document object identity it answers for. */
30
+ export interface HeldPreviewSlot extends HeldPreviewArtifact {
31
+ readonly document: AuthoringDocument;
32
+ }
33
+ /** Files the artifact a candidate check compiled for the document it checked. */
34
+ export declare function holdPreviewArtifact(document: AuthoringDocument, artifact: HeldPreviewArtifact): void;
35
+ /** The artifact held for this exact document object, if a dispatch compiled one. */
36
+ export declare function heldPreviewArtifact(document: AuthoringDocument): HeldPreviewArtifact | undefined;
37
+ /** The slots the hold keeps: none before the first dispatch, then exactly the latest one. */
38
+ export declare function heldPreviewSlots(): readonly HeldPreviewSlot[];
39
+ //# sourceMappingURL=held.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"held.d.ts","sourceRoot":"","sources":["../../src/preview/held.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,6EAA6E;AAC7E,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;CACjC;AAED,yEAAyE;AACzE,MAAM,WAAW,eAAgB,SAAQ,mBAAmB;IAC1D,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAC;CACtC;AAKD,iFAAiF;AACjF,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,iBAAiB,EAC3B,QAAQ,EAAE,mBAAmB,GAC5B,IAAI,CAEN;AAED,oFAAoF;AACpF,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,mBAAmB,GAAG,SAAS,CAEhG;AAED,6FAA6F;AAC7F,wBAAgB,gBAAgB,IAAI,SAAS,eAAe,EAAE,CAE7D"}
@@ -0,0 +1,15 @@
1
+ /** The one artifact the process holds. A later dispatch replaces it, never appends to it. */
2
+ let slot;
3
+ /** Files the artifact a candidate check compiled for the document it checked. */
4
+ export function holdPreviewArtifact(document, artifact) {
5
+ slot = { document, source: artifact.source, schema: artifact.schema };
6
+ }
7
+ /** The artifact held for this exact document object, if a dispatch compiled one. */
8
+ export function heldPreviewArtifact(document) {
9
+ return slot !== undefined && slot.document === document ? slot : undefined;
10
+ }
11
+ /** The slots the hold keeps: none before the first dispatch, then exactly the latest one. */
12
+ export function heldPreviewSlots() {
13
+ return slot === undefined ? [] : [slot];
14
+ }
15
+ //# sourceMappingURL=held.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"held.js","sourceRoot":"","sources":["../../src/preview/held.ts"],"names":[],"mappings":"AAoCA,6FAA6F;AAC7F,IAAI,IAAiC,CAAC;AAEtC,iFAAiF;AACjF,MAAM,UAAU,mBAAmB,CACjC,QAA2B,EAC3B,QAA6B;IAE7B,IAAI,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;AACxE,CAAC;AAED,oFAAoF;AACpF,MAAM,UAAU,mBAAmB,CAAC,QAA2B;IAC7D,OAAO,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;AAC7E,CAAC;AAED,6FAA6F;AAC7F,MAAM,UAAU,gBAAgB;IAC9B,OAAO,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["import type { CompiledSchema } from '@azx-pbc/axiom-runtime';\nimport type { AuthoringDocument } from '../schema/document.js';\n\n/**\n * The artifact one committed dispatch already compiled, held for the preview of that state.\n *\n * A dispatch compiles its candidate to learn what a build would say about it. The preview of the\n * state that dispatch committed compiles the same draft again unless the artifact is kept, so a\n * keystroke plus a preview cost two compiles of one document. This is where the gate's artifact\n * is filed: keyed by the document object it read, which is the object the store hands back.\n *\n * The entry carries the exact source the compile read, not only the artifact. The preview accepts\n * it only when that source is still the document's own text and is also the single-locale source\n * the preview would compile, so a mutated draft or another locale falls back to a compile rather\n * than showing a form the draft no longer has.\n *\n * **One slot, not a map.** The hold used to be a `WeakMap` keyed by every document it saw, and\n * the undo chain retains one document per step: two hundred steps then retained two hundred\n * compiled artifacts — 0.69 MiB per step, 138 MiB at the limit, against 0.02 MiB for a control\n * that kept the same documents and no artifact. Only the most recent dispatch's state can be the\n * one previewed next, so one slot answers every reuse the chain can offer, and a second append\n * replaces it rather than filing a second entry. Re-previewing an older state compiles again,\n * which is the price of a bound that does not grow with the history.\n */\n\n/** One artifact, with the source text the compile consumed to produce it. */\nexport interface HeldPreviewArtifact {\n readonly source: string;\n readonly schema: CompiledSchema;\n}\n\n/** One held artifact and the document object identity it answers for. */\nexport interface HeldPreviewSlot extends HeldPreviewArtifact {\n readonly document: AuthoringDocument;\n}\n\n/** The one artifact the process holds. A later dispatch replaces it, never appends to it. */\nlet slot: HeldPreviewSlot | undefined;\n\n/** Files the artifact a candidate check compiled for the document it checked. */\nexport function holdPreviewArtifact(\n document: AuthoringDocument,\n artifact: HeldPreviewArtifact,\n): void {\n slot = { document, source: artifact.source, schema: artifact.schema };\n}\n\n/** The artifact held for this exact document object, if a dispatch compiled one. */\nexport function heldPreviewArtifact(document: AuthoringDocument): HeldPreviewArtifact | undefined {\n return slot !== undefined && slot.document === document ? slot : undefined;\n}\n\n/** The slots the hold keeps: none before the first dispatch, then exactly the latest one. */\nexport function heldPreviewSlots(): readonly HeldPreviewSlot[] {\n return slot === undefined ? [] : [slot];\n}\n"]}
@@ -0,0 +1,5 @@
1
+ /** Records one compile the preview performed. */
2
+ export declare function notePreviewCompile(): void;
3
+ /** The compiles the preview performed since the process started. */
4
+ export declare function previewCompiles(): number;
5
+ //# sourceMappingURL=measurement.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"measurement.d.ts","sourceRoot":"","sources":["../../src/preview/measurement.ts"],"names":[],"mappings":"AAUA,iDAAiD;AACjD,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC;AAED,oEAAoE;AACpE,wBAAgB,eAAe,IAAI,MAAM,CAExC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Measurement hooks for the preview's compile.
3
+ *
4
+ * A preview compiles the draft's single-locale source once, unless the store's candidate gate
5
+ * already compiled that exact document and filed its artifact. The count is how a test states
6
+ * that, as a count rather than a stopwatch. The spelling follows the runtime's `wireValidations`
7
+ * and `restrictedCanonicalizations`.
8
+ */
9
+ let compiles = 0;
10
+ /** Records one compile the preview performed. */
11
+ export function notePreviewCompile() {
12
+ compiles += 1;
13
+ }
14
+ /** The compiles the preview performed since the process started. */
15
+ export function previewCompiles() {
16
+ return compiles;
17
+ }
18
+ //# sourceMappingURL=measurement.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"measurement.js","sourceRoot":"","sources":["../../src/preview/measurement.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,IAAI,QAAQ,GAAG,CAAC,CAAC;AAEjB,iDAAiD;AACjD,MAAM,UAAU,kBAAkB;IAChC,QAAQ,IAAI,CAAC,CAAC;AAChB,CAAC;AAED,oEAAoE;AACpE,MAAM,UAAU,eAAe;IAC7B,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["/**\n * Measurement hooks for the preview's compile.\n *\n * A preview compiles the draft's single-locale source once, unless the store's candidate gate\n * already compiled that exact document and filed its artifact. The count is how a test states\n * that, as a count rather than a stopwatch. The spelling follows the runtime's `wireValidations`\n * and `restrictedCanonicalizations`.\n */\nlet compiles = 0;\n\n/** Records one compile the preview performed. */\nexport function notePreviewCompile(): void {\n compiles += 1;\n}\n\n/** The compiles the preview performed since the process started. */\nexport function previewCompiles(): number {\n return compiles;\n}\n"]}
@@ -0,0 +1,33 @@
1
+ import type { CompileResult, CompiledDatasetDeclaration } from '@azx-pbc/axiom-compiler';
2
+ import type { Tier } from '@azx-pbc/axiom-runtime';
3
+ import type { AuthoringDocument } from '../schema/document.js';
4
+ import type { DatasetInput } from '../schema/dataset-input.js';
5
+ /**
6
+ * The strict build of one draft, with the tables its rules read.
7
+ *
8
+ * This is the one entry a host calls when it means "what would I publish": it serialises the
9
+ * document, compiles it once, and hands the compiler the declarations of the document's own pinned
10
+ * tables, compiled from the documents or stores the host supplied. A build that needs a table the
11
+ * host did not supply is the compiler's own `DATASET_DECLARATION_MISSING`, naming the table, so
12
+ * the author is told which one to hand over rather than reading a compile that could not check
13
+ * their rule.
14
+ */
15
+ export interface BuildDocumentOptions {
16
+ /** The tier the artifact is for; a server artifact is the default, as `compile` states it. */
17
+ readonly target?: Tier;
18
+ /** The release to stamp as `producerVersion`; see `CompileOptions`. */
19
+ readonly producerVersion?: string | null;
20
+ /**
21
+ * The authored tables the host holds, or the dataset stores editing them.
22
+ *
23
+ * Only the tables this document pins are compiled, so a host can pass the table library it
24
+ * already has. Omitting this leaves a document that reads a table unbuildable; the compiler says
25
+ * which table.
26
+ */
27
+ readonly tables?: readonly DatasetInput[];
28
+ /** Declarations a host already compiled, for a caller that compiled its tables elsewhere. */
29
+ readonly datasets?: readonly CompiledDatasetDeclaration[];
30
+ }
31
+ /** Compiles one draft strictly, with the declarations of its own pinned tables. */
32
+ export declare function buildDocument(document: AuthoringDocument, options?: BuildDocumentOptions): CompileResult;
33
+ //# sourceMappingURL=build.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/publish/build.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AACzF,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAEnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAG/D;;;;;;;;;GASG;AACH,MAAM,WAAW,oBAAoB;IACnC,8FAA8F;IAC9F,QAAQ,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC;IACvB,uEAAuE;IACvE,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzC;;;;;;OAMG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,YAAY,EAAE,CAAC;IAC1C,6FAA6F;IAC7F,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,0BAA0B,EAAE,CAAC;CAC3D;AAED,mFAAmF;AACnF,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,iBAAiB,EAC3B,OAAO,GAAE,oBAAyB,GACjC,aAAa,CAQf"}
@@ -0,0 +1,15 @@
1
+ import { compile } from '@azx-pbc/axiom-compiler';
2
+ import { serializeDocument } from '../schema/document.js';
3
+ import { withDatasetDeclarations } from '../schema/dataset-input.js';
4
+ /** Compiles one draft strictly, with the declarations of its own pinned tables. */
5
+ export function buildDocument(document, options = {}) {
6
+ const resolved = withDatasetDeclarations(document, options.datasets, options.tables);
7
+ if (!resolved.ok)
8
+ return { ok: false, diagnostics: [resolved.diagnostic], warnings: [] };
9
+ return compile(serializeDocument(document), {
10
+ ...(options.target === undefined ? {} : { target: options.target }),
11
+ ...(options.producerVersion === undefined ? {} : { producerVersion: options.producerVersion }),
12
+ ...(resolved.declarations.length === 0 ? {} : { datasets: resolved.declarations }),
13
+ });
14
+ }
15
+ //# sourceMappingURL=build.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/publish/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAGlD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAG1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AA6BrE,mFAAmF;AACnF,MAAM,UAAU,aAAa,CAC3B,QAA2B,EAC3B,OAAO,GAAyB,EAAE;IAElC,MAAM,QAAQ,GAAG,uBAAuB,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IACrF,IAAI,CAAC,QAAQ,CAAC,EAAE;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;IACzF,OAAO,OAAO,CAAC,iBAAiB,CAAC,QAAQ,CAAC,EAAE;QAC1C,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;QACnE,GAAG,CAAC,OAAO,CAAC,eAAe,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,OAAO,CAAC,eAAe,EAAE,CAAC;QAC9F,GAAG,CAAC,QAAQ,CAAC,YAAY,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,YAAY,EAAE,CAAC;KACnF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { compile } from '@azx-pbc/axiom-compiler';\nimport type { CompileResult, CompiledDatasetDeclaration } from '@azx-pbc/axiom-compiler';\nimport type { Tier } from '@azx-pbc/axiom-runtime';\nimport { serializeDocument } from '../schema/document.js';\nimport type { AuthoringDocument } from '../schema/document.js';\nimport type { DatasetInput } from '../schema/dataset-input.js';\nimport { withDatasetDeclarations } from '../schema/dataset-input.js';\n\n/**\n * The strict build of one draft, with the tables its rules read.\n *\n * This is the one entry a host calls when it means \"what would I publish\": it serialises the\n * document, compiles it once, and hands the compiler the declarations of the document's own pinned\n * tables, compiled from the documents or stores the host supplied. A build that needs a table the\n * host did not supply is the compiler's own `DATASET_DECLARATION_MISSING`, naming the table, so\n * the author is told which one to hand over rather than reading a compile that could not check\n * their rule.\n */\nexport interface BuildDocumentOptions {\n /** The tier the artifact is for; a server artifact is the default, as `compile` states it. */\n readonly target?: Tier;\n /** The release to stamp as `producerVersion`; see `CompileOptions`. */\n readonly producerVersion?: string | null;\n /**\n * The authored tables the host holds, or the dataset stores editing them.\n *\n * Only the tables this document pins are compiled, so a host can pass the table library it\n * already has. Omitting this leaves a document that reads a table unbuildable; the compiler says\n * which table.\n */\n readonly tables?: readonly DatasetInput[];\n /** Declarations a host already compiled, for a caller that compiled its tables elsewhere. */\n readonly datasets?: readonly CompiledDatasetDeclaration[];\n}\n\n/** Compiles one draft strictly, with the declarations of its own pinned tables. */\nexport function buildDocument(\n document: AuthoringDocument,\n options: BuildDocumentOptions = {},\n): CompileResult {\n const resolved = withDatasetDeclarations(document, options.datasets, options.tables);\n if (!resolved.ok) return { ok: false, diagnostics: [resolved.diagnostic], warnings: [] };\n return compile(serializeDocument(document), {\n ...(options.target === undefined ? {} : { target: options.target }),\n ...(options.producerVersion === undefined ? {} : { producerVersion: options.producerVersion }),\n ...(resolved.declarations.length === 0 ? {} : { datasets: resolved.declarations }),\n });\n}\n"]}
@@ -0,0 +1,208 @@
1
+ import type { RevisionMigration, SchemaDiagnostic } from '@azx-pbc/axiom-compiler';
2
+ import type { ArtifactDiff, CompiledDatasetDeclaration } from '@azx-pbc/axiom-compiler';
3
+ import type { ArtifactBehaviour, CompiledSchema, SchemaCatalogue, Upcasters } from '@azx-pbc/axiom-runtime';
4
+ import type { AuthoringDocument } from '../schema/document.js';
5
+ import type { DatasetInput } from '../schema/dataset-input.js';
6
+ /**
7
+ * What publishing a draft would mean against the revision a host already published.
8
+ *
9
+ * The authoring store can say what a document declares; only a diff against the published
10
+ * revision can say whether publishing it is a presentation-only edit, a behaviour change a version
11
+ * bump carries, or a revision that recorded values cannot move to without something the revision
12
+ * does not itself contain (`spec/semantics/evolution-v1.md` `EVOL-1.1.1`–`EVOL-3.1.3`).
13
+ *
14
+ * The classification is not a second opinion about behaviour. A compiled draft and the published
15
+ * artifact are compared by `classifyArtifactDiff`, and the hashes the answer rests on are
16
+ * `artifactBehaviour`'s — the identity an evaluation report pins and the publish gate binds its
17
+ * evidence to — so this answer and `verifyPublishReadiness()` cannot disagree about whether a
18
+ * revision moved.
19
+ */
20
+ /**
21
+ * What a revision requires before it may publish.
22
+ *
23
+ * - `none`: the behaviour identity is unchanged, so layout and copy alone moved
24
+ * (`EVOL-1.1.1` permits publishing those without a version bump).
25
+ * - `additive`: behaviour moved, the edition advanced, every published declaration is kept, and
26
+ * the revision asks nothing of the values recorded under the published one, so a new edition is
27
+ * all it is.
28
+ * - `requires-migration`: the revision is lawful but not yet migratable — `migrations` names what
29
+ * recorded values need before it publishes.
30
+ *
31
+ * A revision that drops a published declaration, or gives a deprecated one a new rule, is refused
32
+ * instead: neither is something a migration can repair.
33
+ */
34
+ export type RevisionVerdict = 'none' | 'additive' | 'requires-migration';
35
+ /** The revision difference a host reads before it publishes a draft. */
36
+ export interface PublishedDiff extends ArtifactDiff {
37
+ /** What the revision requires. A host publishes on `none` and `additive` only. */
38
+ readonly verdict: RevisionVerdict;
39
+ /**
40
+ * What the revision asks of the values recorded under the published one, one entry per kind,
41
+ * unioned over every edition the transition passes through. Empty unless `verdict` is
42
+ * `requires-migration`.
43
+ */
44
+ readonly migrations: readonly RevisionMigration[];
45
+ readonly publishedVersion: number;
46
+ readonly draftVersion: number;
47
+ /** The published artifact's behaviour identity, `artifactBehaviour()`. */
48
+ readonly publishedBehaviorHash: string;
49
+ /** The identity the draft would publish with. */
50
+ readonly draftBehaviorHash: string;
51
+ }
52
+ /** Why a draft is not a revision the host may publish. */
53
+ export type RevisionRefusal =
54
+ /** The draft does not compile, so it has no behaviour identity to compare. */
55
+ {
56
+ readonly kind: 'draft_not_compiling';
57
+ readonly diagnostics: readonly SchemaDiagnostic[];
58
+ }
59
+ /** The two artifacts are revisions of different documents. */
60
+ | {
61
+ readonly kind: 'different_schema';
62
+ readonly publishedSchemaId: string;
63
+ readonly draftSchemaId: string;
64
+ }
65
+ /**
66
+ * The draft drops a declaration the published revision states. `EVOL-3.1.2` forbids deleting a
67
+ * `fieldId`: a retired field is marked `deprecated` and kept, because signatures, digests and
68
+ * historical reports bind to the identifier. No catalogue entry makes the removal lawful — the
69
+ * upcast refuses the recorded value of a declaration one of the two versions does not name
70
+ * (`EVOL-2.1.7`) — so this is not a migration the host can supply.
71
+ */
72
+ | {
73
+ readonly kind: 'removal_forbidden';
74
+ /** Every published declaration the draft no longer states, in code-point order. */
75
+ readonly removedFields: readonly string[];
76
+ }
77
+ /** A rule a deprecated field newly acquires, forbidden by `EVOL-3.1.3`. */
78
+ | {
79
+ readonly kind: 'deprecated_field_rule';
80
+ /** Every newly acquired rule/deprecated target pair, in rule then field code-point order. */
81
+ readonly violations: readonly {
82
+ readonly ruleId: string;
83
+ readonly fieldId: string;
84
+ }[];
85
+ }
86
+ /**
87
+ * A declaration the draft keeps changes which array scope holds its value — out of an array into
88
+ * the record root, or between arrays. `EVOL-2.1.6` carries a value row for row and a row is never
89
+ * an upcaster key, so the recorded values have no pairing and no transform repairs the structure:
90
+ * the host re-establishes where the value belongs, or retires the declaration by deprecating it
91
+ * and adding one that fits.
92
+ */
93
+ | {
94
+ readonly kind: 'row_scope_unpairable';
95
+ /** Every declaration whose row scope the draft changes, in code-point order. */
96
+ readonly fieldIds: readonly string[];
97
+ }
98
+ /** A transform names no value-bearing declaration on both sides of its hop (`EVOL-2.1.7`). */
99
+ | {
100
+ readonly kind: 'upcaster_unresolved';
101
+ /** Every unresolved transform id, in code-point order. */
102
+ readonly fieldIds: readonly string[];
103
+ }
104
+ /**
105
+ * Behaviour moved without the edition advancing — it stayed at the published version or went
106
+ * backwards — which `EVOL-1.1.1` forbids: a device that resolves the published version would
107
+ * evaluate a different form under the same pin, and no retained version resolves backwards.
108
+ */
109
+ | {
110
+ readonly kind: 'version_not_advanced';
111
+ readonly publishedVersion: number;
112
+ readonly draftVersion: number;
113
+ }
114
+ /**
115
+ * The draft skips an edition whose artifact the caller did not supply, so no hop between the two
116
+ * can be read. `EVOL-2.1.2` transforms one edition at a time and `EVOL-2.1.7` refuses a version
117
+ * the catalogue does not hold, so a transition through an unretained edition is one recorded
118
+ * values have no path across.
119
+ */
120
+ | {
121
+ readonly kind: 'version_not_retained';
122
+ readonly from: number;
123
+ readonly to: number;
124
+ /** The first edition the walk needed and the caller did not supply. */
125
+ readonly missingVersion: number;
126
+ };
127
+ /** A revision diff, or the reason the draft cannot publish against the published revision. */
128
+ export type PublishedDiffResult = {
129
+ readonly kind: 'diff';
130
+ readonly diff: PublishedDiff;
131
+ } | {
132
+ readonly kind: 'refused';
133
+ readonly refusal: RevisionRefusal;
134
+ };
135
+ /** What the caller supplies that is not in the draft. */
136
+ export interface DiffAgainstPublishedOptions {
137
+ /**
138
+ * The compiled declarations of tables the draft's expressions read. A `datasetRef` pins a
139
+ * table's id and version but does not carry its columns or kind, so strict compilation needs
140
+ * the same declarations the host supplied when it compiled the published artifact.
141
+ */
142
+ readonly datasets?: readonly CompiledDatasetDeclaration[];
143
+ /**
144
+ * The authored tables the host holds, or the dataset stores editing them. The job the `datasets`
145
+ * option does for a caller that already compiled its tables; only the draft's pinned tables are
146
+ * compiled. Either way an expression that reads an undeclared table is the compiler's refusal,
147
+ * naming it.
148
+ */
149
+ readonly tables?: readonly DatasetInput[];
150
+ /**
151
+ * The artifacts the host retains for the editions the draft skips.
152
+ *
153
+ * A consecutive edition needs none: the two artifacts the call already holds are its one hop. A
154
+ * draft that skips editions is judged hop by hop, because each hop states its own requirements
155
+ * and `EVOL-2.1.7` refuses a transition through a version nobody retains — which is why a
156
+ * skipped edition the catalogue does not hold is refused rather than assumed to be an identity.
157
+ */
158
+ readonly catalogue?: SchemaCatalogue;
159
+ /**
160
+ * The transforms the host publishes, keyed by the version each hop starts at and then by
161
+ * `fieldId` (`EVOL-2.1.5`).
162
+ *
163
+ * A transform states what a recorded value becomes, so the hop it belongs to stops requiring an
164
+ * upcaster or a code mapping for that field and the revision can publish. Omitting the map states
165
+ * that the host has written no transform, which is why every requirement the declarations state
166
+ * is then outstanding. It discharges nothing else: row identity, archived context and the
167
+ * measurement basis are not values an upcast sees.
168
+ */
169
+ readonly upcasters?: Upcasters;
170
+ /**
171
+ * The artifact classifier, so a caller that already knows what moved can supply it and a test
172
+ * can prove the invariant below. Defaults to `classifyArtifactDiff`. A supplied classifier is
173
+ * trusted for the declaration sets it reports; the behaviour answer it states is checked
174
+ * against `artifactBehaviour`, because that is the one fact with a second derivation. The
175
+ * identities this call derived are handed to the classifier rather than derived again.
176
+ */
177
+ readonly classify?: (published: CompiledSchema, draft: CompiledSchema, behaviours: {
178
+ readonly published: ArtifactBehaviour;
179
+ readonly draft: ArtifactBehaviour;
180
+ }) => ArtifactDiff;
181
+ }
182
+ /**
183
+ * Diff a draft against the revision a host published.
184
+ *
185
+ * The draft is compiled strictly, because the publication it is compared against carries no
186
+ * diagnostics and a draft that does not compile has no behaviour to compare. The comparison then
187
+ * applies the revision contract: presentation-only edits need nothing, a behaviour change needs
188
+ * the edition to advance, and the transition is read one edition at a time so a skipped edition's
189
+ * own requirements and refusals are not lost. A declaration the draft drops, and a rule newly
190
+ * acquired by a deprecated declaration, are refused because no migration repairs either.
191
+ *
192
+ * A classifier that calls a revision presentation-only while `artifactBehaviour` moved — or
193
+ * reports a move the hashes do not show — is a violated invariant, not a diff, so it throws
194
+ * rather than returning a flag a caller could choose to print.
195
+ */
196
+ export declare function diffAgainstPublished(published: CompiledSchema, draft: AuthoringDocument, options?: DiffAgainstPublishedOptions): PublishedDiffResult;
197
+ /** The options a diff of an already-compiled draft reads; the dataset inputs have done their work. */
198
+ export type DiffAgainstCompiledOptions = Omit<DiffAgainstPublishedOptions, 'datasets' | 'tables'>;
199
+ /**
200
+ * Diff an already-compiled draft against the published revision.
201
+ *
202
+ * The compile is the expensive half and the caller often already holds its artifact — a build, a
203
+ * publish panel, a review — so this is the entry that lets one compile serve the build and the
204
+ * diff. `draft` must be the artifact compiled from the document being compared; the diff reads
205
+ * only the artifact and the published revision, so it cannot detect a mismatch.
206
+ */
207
+ export declare function diffAgainstCompiled(published: CompiledSchema, draft: CompiledSchema, options?: DiffAgainstCompiledOptions):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+ import { AxiomError, artifactBehaviour, compareCodePoints, ruleTargets, unresolvedUpcasters, } from '@azx-pbc/axiom-runtime';
3
+ import { serializeDocument } from '../schema/document.js';
4
+ import { withDatasetDeclarations } from '../schema/dataset-input.js';
5
+ /** Every declaration marked deprecated, including members nested in records and arrays. */
6
+ function deprecatedFieldIds(fields) {
7
+ const ids = new Set();
8
+ const visit = (members) => {
9
+ for (const member of members) {
10
+ if (member.annotations?.['deprecated'] === true)
11
+ ids.add(member.fieldId);
12
+ visit(member.fields ?? []);
13
+ }
14
+ };
15
+ visit(fields);
16
+ return ids;
17
+ }
18
+ /** Every declaration a rule decides, including the member an item rule addresses. */
19
+ function ruledFieldIds(rule) {
20
+ // An item rule's `fieldId` is its array; `targetFieldId` is the member it constrains or writes.
21
+ const targets = new Set(ruleTargets(rule));
22
+ if (rule.targetFieldId !== undefined)
23
+ targets.add(rule.targetFieldId);
24
+ return targets;
25
+ }
26
+ /** Every rule/target pair that gives a deprecated declaration a rule it did not previously have. */
27
+ function newRulesOnDeprecatedFields(published, draft) {
28
+ const publishedRules = new Map((published.rules ?? []).map((rule) => [rule.ruleId, rule]));
29
+ const deprecated = deprecatedFieldIds(draft.fields);
30
+ const violations = [];
31
+ for (const rule of draft.rules ?? []) {
32
+ const prior = publishedRules.get(rule.ruleId);
33
+ const priorTargets = prior === undefined ? undefined : ruledFieldIds(prior);
34
+ for (const fieldId of ruledFieldIds(rule)) {
35
+ if (deprecated.has(fieldId) && priorTargets?.has(fieldId) !== true) {
36
+ violations.push({ ruleId: rule.ruleId, fieldId });
37
+ }
38
+ }
39
+ }
40
+ return violations.sort((left, right) => compareCodePoints(left.ruleId, right.ruleId) ||
41
+ compareCodePoints(left.fieldId, right.fieldId));
42
+ }
43
+ /**
44
+ * Every hop from the published edition to the draft's, one edition at a time.
45
+ *
46
+ * The endpoints are the artifacts the call holds; a skipped edition's artifact is the host's, so
47
+ * the catalogue supplies it. A hop the walk cannot read is reported rather than skipped: treating
48
+ * an unretained edition as an identity would answer for a path the upcast refuses to take.
49
+ */
50
+ function editionHops(published, draft, catalogue) {
51
+ const first = published.schemaVersion;
52
+ const last = draft.schemaVersion;
53
+ const hops = [];
54
+ for (let version = first; version < last; version += 1) {
55
+ const from = version === first ? published : catalogue?.get(version);
56
+ const to = version + 1 === last ? draft : catalogue?.get(version + 1);
57
+ if (from === undefined)
58
+ return { kind: 'missing', missingVersion: version };
59
+ if (to === undefined)
60
+ return { kind: 'missing', missingVersion: version + 1 };
61
+ hops.push({ from, to });
62
+ }
63
+ return { kind: 'walked', hops };
64
+ }
65
+ /**
66
+ * Diff a draft against the revision a host published.
67
+ *
68
+ * The draft is compiled strictly, because the publication it is compared against carries no
69
+ * diagnostics and a draft that does not compile has no behaviour to compare. The comparison then
70
+ * applies the revision contract: presentation-only edits need nothing, a behaviour change needs
71
+ * the edition to advance, and the transition is read one edition at a time so a skipped edition's
72
+ * own requirements and refusals are not lost. A declaration the draft drops, and a rule newly
73
+ * acquired by a deprecated declaration, are refused because no migration repairs either.
74
+ *
75
+ * A classifier that calls a revision presentation-only while `artifactBehaviour` moved — or
76
+ * reports a move the hashes do not show — is a violated invariant, not a diff, so it throws
77
+ * rather than returning a flag a caller could choose to print.
78
+ */
79
+ export function diffAgainstPublished(published, draft, options = {}) {
80
+ const resolved = withDatasetDeclarations(draft, options.datasets, options.tables);
81
+ if (!resolved.ok) {
82
+ return {
83
+ kind: 'refused',
84
+ refusal: { kind: 'draft_not_compiling', diagnostics: [resolved.diagnostic] },
85
+ };
86
+ }
87
+ const compiled = compile(serializeDocument(draft), resolved.declarations.length === 0 ? {} : { datasets: resolved.declarations });
88
+ if (!compiled.ok) {
89
+ return {
90
+ kind: 'refused',
91
+ refusal: { kind: 'draft_not_compiling', diagnostics: compiled.diagnostics },
92
+ };
93
+ }
94
+ return diffAgainstCompiled(published, compiled.schema, options);
95
+ }
96
+ /**
97
+ * Diff an already-compiled draft against the published revision.
98
+ *
99
+ * The compile is the expensive half and the caller often already holds its artifact — a build, a
100
+ * publish panel, a review — so this is the entry that lets one compile serve the build and the
101
+ * diff. `draft` must be the artifact compiled from the document being compared; the diff reads
102
+ * only the artifact and the published revision, so it cannot detect a mismatch.
103
+ */
104
+ export function diffAgainstCompiled(published, draft, options = {}) {
105
+ const next = draft;
106
+ if (next.schemaId !== published.schemaId) {
107
+ return {
108
+ kind: 'refused',
109
+ refusal: {
110
+ kind: 'different_schema',
111
+ publishedSchemaId: published.schemaId,
112
+ draftSchemaId: next.schemaId,
113
+ },
114
+ };
115
+ }
116
+ const classify = options.classify ?? classifyArtifactDiff;
117
+ // One derivation per side: the classifier's answer and the hashes this result states are the
118
+ // same two identities, so neither side is hashed a second time.
119
+ const publishedBehaviour = artifactBehaviour(published);
120
+ const draftBehaviour = artifactBehaviour(next);
121
+ const change = classify(published, next, {
122
+ published: publishedBehaviour,
123
+ draft: draftBehaviour,
124
+ });
125
+ const publishedBehaviorHash = publishedBehaviour.behaviorHash;
126
+ const draftBehaviorHash = draftBehaviour.behaviorHash;
127
+ const behaviorChanged = publishedBehaviorHash !== draftBehaviorHash;
128
+ if (change.behaviorChanged !== behaviorChanged) {
129
+ throw new AxiomError('ENGINE_ERROR', `\`${published.schemaId}\` behaviour ${behaviorChanged ? 'moved' : 'did not move'} from ${publishedBehaviorHash} to ${draftBehaviorHash}, but the classifier reported behaviorChanged: ${String(change.behaviorChanged)}`);
130
+ }
131
+ const publishedVersion = published.schemaVersion;
132
+ const draftVersion = next.schemaVersion;
133
+ if (!behaviorChanged) {
134
+ return {
135
+ kind: 'diff',
136
+ diff: {
137
+ ...change,
138
+ verdict: 'none',
139
+ // Empty by construction, not by omission: every member a requirement or a refusal is read
140
+ // from — a value domain, an option domain, a `rowKey`, the array containers that locate a
141
+ // value, a context root, a dataset pin — is part of the behaviour identity, so an unchanged
142
+ // identity cannot hide one.
143
+ migrations: [],
144
+ publishedVersion,
145
+ draftVersion,
146
+ publishedBehaviorHash,
147
+ draftBehaviorHash,
148
+ },
149
+ };
150
+ }
151
+ if (draftVersion <= publishedVersion) {
152
+ return {
153
+ kind: 'refused',
154
+ refusal: { kind: 'version_not_advanced', publishedVersion, draftVersion },
155
+ };
156
+ }
157
+ const walk = editionHops(published, next, options.catalogue);
158
+ if (walk.kind === 'missing') {
159
+ return {
160
+ kind: 'refused',
161
+ refusal: {
162
+ kind: 'version_not_retained',
163
+ from: publishedVersion,
164
+ to: draftVersion,
165
+ missingVersion: walk.missingVersion,
166
+ },
167
+ };
168
+ }
169
+ const requirements = walk.hops.map((hop) => revisionRequirements(hop.from, hop.to, options.upcasters?.get(hop.from.schemaVersion)));
170
+ // The refusal covers every hop, so a declaration dropped at an edition the draft passes through
171
+ // is refused even when the endpoints both declare it; for a consecutive edition this is the
172
+ // same set the classifier reports as `removedFields`.
173
+ const removedFields = [
174
+ ...new Set(requirements.flatMap((requirement) => requirement.removedFields)),
175
+ ].sort(compareCodePoints);
176
+ // `EVOL-3.1.2`: a published declaration may be deprecated, never deleted. The target refuses the
177
+ // recorded value of a declaration it does not name (`relocateRecord` → `field_unresolved`), so
178
+ // no catalogue entry can carry a value across a removal. Refusing here keeps this answer and the
179
+ // runtime from disagreeing about whether the transition is survivable.
180
+ if (removedFields.length > 0) {
181
+ return { kind: 'refused', refusal: { kind: 'removal_forbidden', removedFields } };
182
+ }
183
+ const rowsUnpaired = [
184
+ ...new Set(requirements.flatMap((requirement) => requirement.rowsUnpaired)),
185
+ ].sort(compareCodePoints);
186
+ if (rowsUnpaired.length > 0) {
187
+ return { kind: 'refused', refusal: { kind: 'row_scope_unpairable', fieldIds: rowsUnpaired } };
188
+ }
189
+ const unresolved = [
190
+ ...new Set(walk.hops.flatMap((hop) => unresolvedUpcasters(hop.from, hop.to, options.upcasters?.get(hop.from.schemaVersion)))),
191
+ ].sort(compareCodePoints);
192
+ if (unresolved.length > 0) {
193
+ return { kind: 'refused', refusal: { kind: 'upcaster_unresolved', fieldIds: unresolved } };
194
+ }
195
+ // Acquisition belongs to a hop, not just the endpoints: a deprecated field that loses a rule in
196
+ // a retained edition cannot re-acquire it in a later one merely because the endpoints match.
197
+ const deprecatedViolations = walk.hops
198
+ .flatMap((hop) => newRulesOnDeprecatedFields(hop.from, hop.to))
199
+ .sort((left, right) => compareCodePoints(left.ruleId, right.ruleId) ||
200
+ compareCodePoints(left.fieldId, right.fieldId))
201
+ .filter((violation, index, all) => {
202
+ const previous = all[index - 1];
203
+ return (previous === undefined ||
204
+ previous.ruleId !== violation.ruleId ||
205
+ previous.fieldId !== violation.fieldId);
206
+ });
207
+ if (deprecatedViolations.length > 0) {
208
+ return {
209
+ kind: 'refused',
210
+ refusal: { kind: 'deprecated_field_rule', violations: deprecatedViolations },
211
+ };
212
+ }
213
+ const migrations = mergeRevisionMigrations(requirements.flatMap((requirement) => requirement.migrations));
214
+ return {
215
+ kind: 'diff',
216
+ diff: {
217
+ ...change,
218
+ verdict: migrations.length === 0 ? 'additive' : 'requires-migration',
219
+ migrations,
220
+ publishedVersion,
221
+ draftVersion,
222
+ publishedBehaviorHash,
223
+ draftBehaviorHash,
224
+ },
225
+ };
226
+ }
227
+ //# sourceMappingURL=diff.js.map