@azx-pbc/axiom-builder 0.0.0-stage → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +648 -2
- package/dist/cards/selectors.d.ts +70 -0
- package/dist/cards/selectors.d.ts.map +1 -0
- package/dist/cards/selectors.js +194 -0
- package/dist/cards/selectors.js.map +1 -0
- package/dist/definition.d.ts +36 -0
- package/dist/definition.d.ts.map +1 -0
- package/dist/definition.js +48 -0
- package/dist/definition.js.map +1 -0
- package/dist/evidence/cases.d.ts +44 -0
- package/dist/evidence/cases.d.ts.map +1 -0
- package/dist/evidence/cases.js +578 -0
- package/dist/evidence/cases.js.map +1 -0
- package/dist/evidence/repairs.d.ts +99 -0
- package/dist/evidence/repairs.d.ts.map +1 -0
- package/dist/evidence/repairs.js +181 -0
- package/dist/evidence/repairs.js.map +1 -0
- package/dist/evidence/summary.d.ts +35 -0
- package/dist/evidence/summary.d.ts.map +1 -0
- package/dist/evidence/summary.js +38 -0
- package/dist/evidence/summary.js.map +1 -0
- package/dist/i18n/gaps.d.ts +3 -0
- package/dist/i18n/gaps.d.ts.map +1 -0
- package/dist/i18n/gaps.js +2 -0
- package/dist/i18n/gaps.js.map +1 -0
- package/dist/i18n/message-slots.d.ts +19 -0
- package/dist/i18n/message-slots.d.ts.map +1 -0
- package/dist/i18n/message-slots.js +101 -0
- package/dist/i18n/message-slots.js.map +1 -0
- package/dist/i18n/text-locale.d.ts +13 -0
- package/dist/i18n/text-locale.d.ts.map +1 -0
- package/dist/i18n/text-locale.js +14 -0
- package/dist/i18n/text-locale.js.map +1 -0
- package/dist/i18n/translations.d.ts +56 -0
- package/dist/i18n/translations.d.ts.map +1 -0
- package/dist/i18n/translations.js +103 -0
- package/dist/i18n/translations.js.map +1 -0
- package/dist/impact/references.d.ts +143 -0
- package/dist/impact/references.d.ts.map +1 -0
- package/dist/impact/references.js +429 -0
- package/dist/impact/references.js.map +1 -0
- package/dist/index.d.ts +86 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +58 -0
- package/dist/index.js.map +1 -0
- package/dist/preview/compile-preview.d.ts +67 -0
- package/dist/preview/compile-preview.d.ts.map +1 -0
- package/dist/preview/compile-preview.js +286 -0
- package/dist/preview/compile-preview.js.map +1 -0
- package/dist/preview/handle.d.ts +119 -0
- package/dist/preview/handle.d.ts.map +1 -0
- package/dist/preview/handle.js +2 -0
- package/dist/preview/handle.js.map +1 -0
- package/dist/preview/held.d.ts +39 -0
- package/dist/preview/held.d.ts.map +1 -0
- package/dist/preview/held.js +15 -0
- package/dist/preview/held.js.map +1 -0
- package/dist/preview/measurement.d.ts +5 -0
- package/dist/preview/measurement.d.ts.map +1 -0
- package/dist/preview/measurement.js +18 -0
- package/dist/preview/measurement.js.map +1 -0
- package/dist/publish/build.d.ts +33 -0
- package/dist/publish/build.d.ts.map +1 -0
- package/dist/publish/build.js +15 -0
- package/dist/publish/build.js.map +1 -0
- package/dist/publish/diff.d.ts +208 -0
- package/dist/publish/diff.d.ts.map +1 -0
- package/dist/publish/diff.js +227 -0
- package/dist/publish/diff.js.map +1 -0
- package/dist/publish/review.d.ts +41 -0
- package/dist/publish/review.d.ts.map +1 -0
- package/dist/publish/review.js +22 -0
- package/dist/publish/review.js.map +1 -0
- package/dist/schema/dataset-input.d.ts +30 -0
- package/dist/schema/dataset-input.d.ts.map +1 -0
- package/dist/schema/dataset-input.js +58 -0
- package/dist/schema/dataset-input.js.map +1 -0
- package/dist/schema/dataset.d.ts +166 -0
- package/dist/schema/dataset.d.ts.map +1 -0
- package/dist/schema/dataset.js +281 -0
- package/dist/schema/dataset.js.map +1 -0
- package/dist/schema/declarations.d.ts +15 -0
- package/dist/schema/declarations.d.ts.map +1 -0
- package/dist/schema/declarations.js +47 -0
- package/dist/schema/declarations.js.map +1 -0
- package/dist/schema/document.d.ts +504 -0
- package/dist/schema/document.d.ts.map +1 -0
- package/dist/schema/document.js +337 -0
- package/dist/schema/document.js.map +1 -0
- package/dist/schema/error.d.ts +15 -0
- package/dist/schema/error.d.ts.map +1 -0
- package/dist/schema/error.js +18 -0
- package/dist/schema/error.js.map +1 -0
- package/dist/schema/field-id.d.ts +8 -0
- package/dist/schema/field-id.d.ts.map +1 -0
- package/dist/schema/field-id.js +47 -0
- package/dist/schema/field-id.js.map +1 -0
- package/dist/schema/layout.d.ts +118 -0
- package/dist/schema/layout.d.ts.map +1 -0
- package/dist/schema/layout.js +101 -0
- package/dist/schema/layout.js.map +1 -0
- package/dist/schema/palette.d.ts +103 -0
- package/dist/schema/palette.d.ts.map +1 -0
- package/dist/schema/palette.js +140 -0
- package/dist/schema/palette.js.map +1 -0
- package/dist/schema/read.d.ts +49 -0
- package/dist/schema/read.d.ts.map +1 -0
- package/dist/schema/read.js +942 -0
- package/dist/schema/read.js.map +1 -0
- package/dist/store/apply-dataset.d.ts +14 -0
- package/dist/store/apply-dataset.d.ts.map +1 -0
- package/dist/store/apply-dataset.js +513 -0
- package/dist/store/apply-dataset.js.map +1 -0
- package/dist/store/apply.d.ts +37 -0
- package/dist/store/apply.d.ts.map +1 -0
- package/dist/store/apply.js +2269 -0
- package/dist/store/apply.js.map +1 -0
- package/dist/store/candidate.d.ts +37 -0
- package/dist/store/candidate.d.ts.map +1 -0
- package/dist/store/candidate.js +178 -0
- package/dist/store/candidate.js.map +1 -0
- package/dist/store/commands/coverage.d.ts +58 -0
- package/dist/store/commands/coverage.d.ts.map +1 -0
- package/dist/store/commands/coverage.js +354 -0
- package/dist/store/commands/coverage.js.map +1 -0
- package/dist/store/commands/dataset.d.ts +26 -0
- package/dist/store/commands/dataset.d.ts.map +1 -0
- package/dist/store/commands/dataset.js +368 -0
- package/dist/store/commands/dataset.js.map +1 -0
- package/dist/store/commands/document.d.ts +21 -0
- package/dist/store/commands/document.d.ts.map +1 -0
- package/dist/store/commands/document.js +160 -0
- package/dist/store/commands/document.js.map +1 -0
- package/dist/store/commands/field.d.ts +32 -0
- package/dist/store/commands/field.d.ts.map +1 -0
- package/dist/store/commands/field.js +572 -0
- package/dist/store/commands/field.js.map +1 -0
- package/dist/store/commands/layout.d.ts +16 -0
- package/dist/store/commands/layout.d.ts.map +1 -0
- package/dist/store/commands/layout.js +70 -0
- package/dist/store/commands/layout.js.map +1 -0
- package/dist/store/commands/parse.d.ts +19 -0
- package/dist/store/commands/parse.d.ts.map +1 -0
- package/dist/store/commands/parse.js +328 -0
- package/dist/store/commands/parse.js.map +1 -0
- package/dist/store/commands/readers.d.ts +198 -0
- package/dist/store/commands/readers.d.ts.map +1 -0
- package/dist/store/commands/readers.js +711 -0
- package/dist/store/commands/readers.js.map +1 -0
- package/dist/store/commands/rule.d.ts +24 -0
- package/dist/store/commands/rule.d.ts.map +1 -0
- package/dist/store/commands/rule.js +379 -0
- package/dist/store/commands/rule.js.map +1 -0
- package/dist/store/commands/shapes.d.ts +900 -0
- package/dist/store/commands/shapes.d.ts.map +1 -0
- package/dist/store/commands/shapes.js +166 -0
- package/dist/store/commands/shapes.js.map +1 -0
- package/dist/store/commands/suggestions.d.ts +37 -0
- package/dist/store/commands/suggestions.d.ts.map +1 -0
- package/dist/store/commands/suggestions.js +177 -0
- package/dist/store/commands/suggestions.js.map +1 -0
- package/dist/store/commands.d.ts +16 -0
- package/dist/store/commands.d.ts.map +1 -0
- package/dist/store/commands.js +13 -0
- package/dist/store/commands.js.map +1 -0
- package/dist/store/dataset-candidate.d.ts +33 -0
- package/dist/store/dataset-candidate.d.ts.map +1 -0
- package/dist/store/dataset-candidate.js +31 -0
- package/dist/store/dataset-candidate.js.map +1 -0
- package/dist/store/dataset-pin.d.ts +93 -0
- package/dist/store/dataset-pin.d.ts.map +1 -0
- package/dist/store/dataset-pin.js +86 -0
- package/dist/store/dataset-pin.js.map +1 -0
- package/dist/store/dataset-store.d.ts +96 -0
- package/dist/store/dataset-store.d.ts.map +1 -0
- package/dist/store/dataset-store.js +112 -0
- package/dist/store/dataset-store.js.map +1 -0
- package/dist/store/history.d.ts +149 -0
- package/dist/store/history.d.ts.map +1 -0
- package/dist/store/history.js +173 -0
- package/dist/store/history.js.map +1 -0
- package/dist/store/measurement.d.ts +5 -0
- package/dist/store/measurement.d.ts.map +1 -0
- package/dist/store/measurement.js +20 -0
- package/dist/store/measurement.js.map +1 -0
- package/dist/store/notify.d.ts +11 -0
- package/dist/store/notify.d.ts.map +1 -0
- package/dist/store/notify.js +26 -0
- package/dist/store/notify.js.map +1 -0
- package/dist/store/published.d.ts +50 -0
- package/dist/store/published.d.ts.map +1 -0
- package/dist/store/published.js +27 -0
- package/dist/store/published.js.map +1 -0
- package/dist/store/refusals.d.ts +175 -0
- package/dist/store/refusals.d.ts.map +1 -0
- package/dist/store/refusals.js +160 -0
- package/dist/store/refusals.js.map +1 -0
- package/dist/store/steps.d.ts +14 -0
- package/dist/store/steps.d.ts.map +1 -0
- package/dist/store/steps.js +124 -0
- package/dist/store/steps.js.map +1 -0
- package/dist/store/store.d.ts +142 -0
- package/dist/store/store.d.ts.map +1 -0
- package/dist/store/store.js +136 -0
- package/dist/store/store.js.map +1 -0
- package/dist/store/unchanged.d.ts +12 -0
- package/dist/store/unchanged.d.ts.map +1 -0
- package/dist/store/unchanged.js +35 -0
- package/dist/store/unchanged.js.map +1 -0
- package/dist/visual/emit.d.ts +21 -0
- package/dist/visual/emit.d.ts.map +1 -0
- package/dist/visual/emit.js +133 -0
- package/dist/visual/emit.js.map +1 -0
- package/dist/visual/parse.d.ts +32 -0
- package/dist/visual/parse.d.ts.map +1 -0
- package/dist/visual/parse.js +330 -0
- package/dist/visual/parse.js.map +1 -0
- package/dist/visual/project.d.ts +40 -0
- package/dist/visual/project.d.ts.map +1 -0
- package/dist/visual/project.js +349 -0
- package/dist/visual/project.js.map +1 -0
- package/dist/visual/represent.d.ts +50 -0
- package/dist/visual/represent.d.ts.map +1 -0
- package/dist/visual/represent.js +66 -0
- package/dist/visual/represent.js.map +1 -0
- package/dist/visual/vocabulary.d.ts +121 -0
- package/dist/visual/vocabulary.d.ts.map +1 -0
- package/dist/visual/vocabulary.js +32 -0
- package/dist/visual/vocabulary.js.map +1 -0
- package/package.json +52 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@azx-pbc/axiom-builder` — the headless authoring store.
|
|
3
|
+
*
|
|
4
|
+
* A host that authors a closed schema document needs the document contract outside its own UI
|
|
5
|
+
* code. This package supplies it: every edit is a command over an immutable snapshot, so undo,
|
|
6
|
+
* redo, preview and diff read the same history. It carries no React, no DOM, no clock, no
|
|
7
|
+
* randomness and no business domain: a starter template here would be one client's vocabulary
|
|
8
|
+
* shipped to every client.
|
|
9
|
+
*
|
|
10
|
+
* The store refuses what the compiler refuses. Its hard refusals are the compiler's own
|
|
11
|
+
* predicates: the closed metaschema, the layout grammar and C11, and the structural codes of the
|
|
12
|
+
* compile's verdict. Everything the compile still reports (an unfinished expression, an unresolved
|
|
13
|
+
* reference, a cycle, a missing translation) is accepted as a draft with diagnostics attached.
|
|
14
|
+
* Keeping those drafts instead of refusing them is what lets an author type mid-expression.
|
|
15
|
+
*
|
|
16
|
+
* `compilePreview` states the other half: a live preview is opaque by construction, compiled from
|
|
17
|
+
* a closure-scoped multi-locale fallback copy (or a single-locale fast path when every entry
|
|
18
|
+
* already declares the requested locale) where borrowed text stays filed under its authored source
|
|
19
|
+
* locale for CLDR plural checking, so nothing a UI can read is a deployable artifact or a report
|
|
20
|
+
* hash. A build compiles the document the author holds, strictly, through
|
|
21
|
+
* `@azx-pbc/axiom-compiler`.
|
|
22
|
+
*/
|
|
23
|
+
export { AuthoringError, createEmptySchema, duplicateDocument, serializeDocument, } from './schema/document.js';
|
|
24
|
+
export { DefinitionError, defineDocument } from './definition.js';
|
|
25
|
+
export { readDocument } from './schema/read.js';
|
|
26
|
+
export { createDatasetTable, datasetDigest, readDatasetDocument } from './schema/dataset.js';
|
|
27
|
+
export { documentIndex } from './schema/declarations.js';
|
|
28
|
+
export { layoutIndex } from './schema/layout.js';
|
|
29
|
+
export { suggestFieldId } from './schema/field-id.js';
|
|
30
|
+
export { FIELD_PALETTE } from './schema/palette.js';
|
|
31
|
+
export { COMMAND_KINDS, DATASET_COMMAND_KINDS, DATASET_COMMAND_KIND_SET, parseCommand, parseDatasetCommand, MAX_MEMBER_NESTING, } from './store/commands.js';
|
|
32
|
+
export { createAuthoringStore } from './store/store.js';
|
|
33
|
+
export { createDatasetStore } from './store/dataset-store.js';
|
|
34
|
+
export { checkDatasetPin, datasetPinChecks, publishDataset, } from './store/dataset-pin.js';
|
|
35
|
+
export { HISTORY_LIMIT } from './store/history.js';
|
|
36
|
+
export { AUTHORING_REFUSAL_CODES, AUTHORING_REFUSAL_REPAIRS, authoringRefusal, } from './store/refusals.js';
|
|
37
|
+
export { declaredEvidenceRepairs, notCausalRepairs } from './evidence/repairs.js';
|
|
38
|
+
export { evidenceSummary } from './evidence/summary.js';
|
|
39
|
+
export { translationGaps } from './i18n/gaps.js';
|
|
40
|
+
export { exportMissingTranslations, importTranslations, } from './i18n/translations.js';
|
|
41
|
+
export { compilePreview } from './preview/compile-preview.js';
|
|
42
|
+
export { diagnosticCardField, fieldCards, unattachedDiagnostics } from './cards/selectors.js';
|
|
43
|
+
export { projectRule, toVisual } from './visual/project.js';
|
|
44
|
+
export { emitVisual, visualSource } from './visual/emit.js';
|
|
45
|
+
export { representVisual } from './visual/represent.js';
|
|
46
|
+
export { MAX_VISUAL_NESTING, parseVisual } from './visual/parse.js';
|
|
47
|
+
export { DATE_SPANS, FORMAT_CHECKS, ORDERED_COMPARISONS, PRESENCE_CHECKS, TEXT_MATCH_OPERATORS, } from './visual/vocabulary.js';
|
|
48
|
+
export { referencesOf, ruleExpressionSlots } from './impact/references.js';
|
|
49
|
+
/**
|
|
50
|
+
* What publishing a draft would mean against the revision a host published: a presentation-only
|
|
51
|
+
* edit, a behaviour change a version bump carries, what the revision still needs of recorded
|
|
52
|
+
* values, or a refusal the revision contract states. The classification is the compiler's, so
|
|
53
|
+
* `axiom-cli diff` and an authoring host agree about whether behaviour moved.
|
|
54
|
+
*/
|
|
55
|
+
export { buildDocument } from './publish/build.js';
|
|
56
|
+
export { diffAgainstCompiled, diffAgainstPublished } from './publish/diff.js';
|
|
57
|
+
export { reviewDocument } from './publish/review.js';
|
|
58
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAoC7F,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAQjD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EACL,aAAa,EACb,qBAAqB,EACrB,wBAAwB,EACxB,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AA+D7B,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAUxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAS9D,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,cAAc,GACf,MAAM,wBAAwB,CAAC;AAOhC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EACL,uBAAuB,EACvB,yBAAyB,EACzB,gBAAgB,GACjB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAQlF,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD,OAAO,EACL,yBAAyB,EACzB,kBAAkB,GACnB,MAAM,wBAAwB,CAAC;AAMhC,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAe9D,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAE9F,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAMxD,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEpE,OAAO,EACL,UAAU,EACV,aAAa,EACb,mBAAmB,EACnB,eAAe,EACf,oBAAoB,GACrB,MAAM,wBAAwB,CAAC;AAahC,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAS3E;;;;;GAKG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAS9E,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC","sourcesContent":["/**\n * `@azx-pbc/axiom-builder` — the headless authoring store.\n *\n * A host that authors a closed schema document needs the document contract outside its own UI\n * code. This package supplies it: every edit is a command over an immutable snapshot, so undo,\n * redo, preview and diff read the same history. It carries no React, no DOM, no clock, no\n * randomness and no business domain: a starter template here would be one client's vocabulary\n * shipped to every client.\n *\n * The store refuses what the compiler refuses. Its hard refusals are the compiler's own\n * predicates: the closed metaschema, the layout grammar and C11, and the structural codes of the\n * compile's verdict. Everything the compile still reports (an unfinished expression, an unresolved\n * reference, a cycle, a missing translation) is accepted as a draft with diagnostics attached.\n * Keeping those drafts instead of refusing them is what lets an author type mid-expression.\n *\n * `compilePreview` states the other half: a live preview is opaque by construction, compiled from\n * a closure-scoped multi-locale fallback copy (or a single-locale fast path when every entry\n * already declares the requested locale) where borrowed text stays filed under its authored source\n * locale for CLDR plural checking, so nothing a UI can read is a deployable artifact or a report\n * hash. A build compiles the document the author holds, strictly, through\n * `@azx-pbc/axiom-compiler`.\n */\nexport {\n AuthoringError,\n createEmptySchema,\n duplicateDocument,\n serializeDocument,\n} from './schema/document.js';\nexport { DefinitionError, defineDocument } from './definition.js';\nexport { readDocument } from './schema/read.js';\nexport type { DocumentRead } from './schema/read.js';\nexport { createDatasetTable, datasetDigest, readDatasetDocument } from './schema/dataset.js';\nexport type {\n AuthoredDatasetBinding,\n AuthoredDatasetDocument,\n AuthoredDatasetIdentity,\n AuthoredDecisionRow,\n AuthoredDecisionTable,\n AuthoredHitPolicy,\n AuthoredLookupRow,\n AuthoredLookupTable,\n AuthoredSetTable,\n CreateDatasetOptions,\n DatasetDocumentRead,\n} from './schema/dataset.js';\nexport type {\n AuthoringAnnotations,\n AuthoringCatalogue,\n AuthoringContext,\n AuthoringDatasetReference,\n AuthoringDocument,\n AuthoringField,\n AuthoringGate,\n AuthoringGateItem,\n AuthoringItem,\n AuthoringLayoutNode,\n AuthoringOption,\n AuthoringRowKey,\n AuthoringRule,\n AuthoringScreenReason,\n AuthoringSuggestedRef,\n AuthoringSuggestion,\n AuthoringSuggestionOperation,\n AuthoringTestCase,\n CreateSchemaOptions,\n ScalarPrimitive,\n} from './schema/document.js';\nexport { documentIndex } from './schema/declarations.js';\nexport { layoutIndex } from './schema/layout.js';\nexport type {\n IndexedLayoutNode,\n IndexedReadout,\n LayoutIndex,\n LayoutKind,\n LayoutPlacement,\n} from './schema/layout.js';\nexport { suggestFieldId } from './schema/field-id.js';\nexport { FIELD_PALETTE } from './schema/palette.js';\nexport type { FieldPaletteEntry, PaletteDeclaration, PaletteNeeds } from './schema/palette.js';\nexport {\n COMMAND_KINDS,\n DATASET_COMMAND_KINDS,\n DATASET_COMMAND_KIND_SET,\n parseCommand,\n parseDatasetCommand,\n MAX_MEMBER_NESTING,\n} from './store/commands.js';\nexport type {\n AddDatasetRowCommand,\n AddFieldSpec,\n AddOptionSpec,\n AddRecordArraySpec,\n AddRuleSpec,\n AddRuleTestCaseCommand,\n AuthoringCommand,\n AuthoringRuleKind,\n CommandParse,\n ContextRootSpec,\n DatasetCellInput,\n DatasetCommand,\n DatasetCommandParse,\n DatasetPinSpec,\n DatasetRowSpec,\n DeprecateOptionCommand,\n EditFieldCommand,\n EditFieldSpec,\n EditLayoutNodeCommand,\n EditRuleCommand,\n EditRuleSpec,\n FieldDeclarationSpec,\n FieldPrimitiveSpec,\n GateEditSpec,\n GateItemSpec,\n GateSpec,\n LayoutPath,\n MemberFieldSpec,\n MemberSpec,\n MoveLayoutNodeCommand,\n OptionAvailabilitySpec,\n PinDatasetCommand,\n PlaceFieldCommand,\n RemoveContextRootCommand,\n RemoveDatasetRowCommand,\n RemoveFieldCommand,\n RemoveLayoutNodeCommand,\n RemoveRuleCommand,\n ReplaceDatasetRowCommand,\n ScreenReasonSpec,\n SetContextRootCommand,\n SetDatasetCellCommand,\n SetDatasetColumnsCommand,\n SetDatasetEffectiveRangeCommand,\n SetDatasetHitPolicyCommand,\n SetDatasetValuesCommand,\n SetDocumentTitleCommand,\n SetFieldDeclarationCommand,\n SetFieldPrimitiveCommand,\n SetLocalesCommand,\n SetOnHideCommand,\n SetOptionAvailabilityCommand,\n SetPrimaryCommand,\n SetRuleExprCommand,\n SetRuleSuggestsCommand,\n SetSignatureCoversCommand,\n SuggestionOperationSpec,\n SuggestionSpec,\n TestCaseSpec,\n UnpinDatasetCommand,\n} from './store/commands.js';\nexport { createAuthoringStore } from './store/store.js';\nexport type {\n AuthoringStore,\n AuthoringStoreOptions,\n DispatchContext,\n DispatchEffects,\n DispatchOutcome,\n HistoryOutcome,\n HistoryRefusal,\n} from './store/store.js';\nexport { createDatasetStore } from './store/dataset-store.js';\nexport type {\n DatasetDispatchEffects,\n DatasetDispatchOutcome,\n DatasetHistoryOutcome,\n DatasetState,\n DatasetStore,\n DatasetStoreOptions,\n} from './store/dataset-store.js';\nexport {\n checkDatasetPin,\n datasetPinChecks,\n publishDataset,\n} from './store/dataset-pin.js';\nexport type {\n DatasetPin,\n DatasetPinCheck,\n DatasetPublication,\n} from './store/dataset-pin.js';\nexport type { AuthoringState, HistoryStep } from './store/history.js';\nexport { HISTORY_LIMIT } from './store/history.js';\nexport type { ClampedField } from './store/apply.js';\nexport {\n AUTHORING_REFUSAL_CODES,\n AUTHORING_REFUSAL_REPAIRS,\n authoringRefusal,\n} from './store/refusals.js';\nexport type { AuthoringRefusal, AuthoringRefusalCode } from './store/refusals.js';\nexport type { PublishedBaseline } from './store/published.js';\nexport { declaredEvidenceRepairs, notCausalRepairs } from './evidence/repairs.js';\nexport type {\n EvidenceAssertion,\n EvidenceRepair,\n NotCausalRepair,\n SuggestedCase,\n VerifiedEvidence,\n} from './evidence/repairs.js';\nexport { evidenceSummary } from './evidence/summary.js';\nexport type { EvidenceSummary } from './evidence/summary.js';\nexport { translationGaps } from './i18n/gaps.js';\nexport type { TranslationGap } from './i18n/gaps.js';\nexport {\n exportMissingTranslations,\n importTranslations,\n} from './i18n/translations.js';\nexport type {\n MissingTranslation,\n TranslationEntry,\n TranslationImport,\n} from './i18n/translations.js';\nexport { compilePreview } from './preview/compile-preview.js';\nexport type { PreviewOptions } from './preview/compile-preview.js';\nexport type {\n PreviewCandidate,\n PreviewCandidateDelta,\n PreviewCompileResult,\n PreviewEngine,\n PreviewEngineConfig,\n PreviewFailure,\n PreviewFieldExplanation,\n PreviewFormState,\n PreviewProposal,\n PreviewReportFacts,\n PreviewSuccess,\n} from './preview/handle.js';\nexport { diagnosticCardField, fieldCards, unattachedDiagnostics } from './cards/selectors.js';\nexport type { CardContext, FieldCard } from './cards/selectors.js';\nexport { projectRule, toVisual } from './visual/project.js';\nexport { emitVisual, visualSource } from './visual/emit.js';\nexport { representVisual } from './visual/represent.js';\nexport type {\n VisualRefusal,\n VisualRefusalReason,\n VisualRepresentation,\n} from './visual/represent.js';\nexport { MAX_VISUAL_NESTING, parseVisual } from './visual/parse.js';\nexport type { VisualParse } from './visual/parse.js';\nexport {\n DATE_SPANS,\n FORMAT_CHECKS,\n ORDERED_COMPARISONS,\n PRESENCE_CHECKS,\n TEXT_MATCH_OPERATORS,\n} from './visual/vocabulary.js';\nexport type {\n DateSpan,\n FormatCheck,\n OrderedComparison,\n PresenceCheck,\n RuleExpression,\n ScalarVisualValue,\n TextMatchOperator,\n VisualExpr,\n VisualList,\n VisualValue,\n} from './visual/vocabulary.js';\nexport { referencesOf, ruleExpressionSlots } from './impact/references.js';\nexport type {\n DependencyRead,\n ExpressionSlot,\n FieldReference,\n FieldReferenceKind,\n FieldReferences,\n UnparseableExpression,\n} from './impact/references.js';\n/**\n * What publishing a draft would mean against the revision a host published: a presentation-only\n * edit, a behaviour change a version bump carries, what the revision still needs of recorded\n * values, or a refusal the revision contract states. The classification is the compiler's, so\n * `axiom-cli diff` and an authoring host agree about whether behaviour moved.\n */\nexport { buildDocument } from './publish/build.js';\nexport type { BuildDocumentOptions } from './publish/build.js';\nexport { diffAgainstCompiled, diffAgainstPublished } from './publish/diff.js';\nexport type {\n DiffAgainstCompiledOptions,\n DiffAgainstPublishedOptions,\n PublishedDiff,\n PublishedDiffResult,\n RevisionRefusal,\n RevisionVerdict,\n} from './publish/diff.js';\nexport { reviewDocument } from './publish/review.js';\nexport type { DocumentReview, ReviewDocumentOptions } from './publish/review.js';\nexport type { DatasetInput, DatasetSource } from './schema/dataset-input.js';\n"]}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { CompiledDatasetDeclaration } from '@azx-pbc/axiom-compiler';
|
|
2
|
+
import type { EvaluationEnv, EvaluationInput } from '@azx-pbc/axiom-runtime';
|
|
3
|
+
import type { AuthoringDocument } from '../schema/document.js';
|
|
4
|
+
import type { DatasetInput } from '../schema/dataset-input.js';
|
|
5
|
+
import type { PreviewCompileResult } from './handle.js';
|
|
6
|
+
/**
|
|
7
|
+
* A live preview of a draft, compiled in a locale fallback that never leaves this module.
|
|
8
|
+
*
|
|
9
|
+
* The compile a build runs is strict: every declared locale is required for every message, and a
|
|
10
|
+
* gap fails it. An author editing a four-locale form has gaps almost all the time, so a preview
|
|
11
|
+
* that ran the strict compile would be blank exactly when it is useful. This module builds a
|
|
12
|
+
* fallback copy of the document in closure scope: every entry keeps the requested locale's own
|
|
13
|
+
* text when present, or borrows from the document's default locale (then the entry's first stated
|
|
14
|
+
* locale) while keeping borrowed text filed under its authored source locale so ICU plural rules
|
|
15
|
+
* are checked against the language the author wrote, with unwritten slots held by an internal
|
|
16
|
+
* placeholder that never leaves closure scope. When every entry already declares the requested
|
|
17
|
+
* locale, the copy takes the single-locale fast path with `locales: [locale]`. The document the
|
|
18
|
+
* author holds is untouched; the gaps it still has travel beside the preview as `translationGaps`,
|
|
19
|
+
* and the fallback document and its artifact are reachable from no member of the handle.
|
|
20
|
+
*
|
|
21
|
+
* Locale selection is the runtime's one selector, `resolveSchemaLocale`: the same exact-then-prefix
|
|
22
|
+
* -then-default order a shipped artifact uses, so a preview of `pt-PT` against a catalogue carrying
|
|
23
|
+
* `pt` renders the `pt` text under `pt` plural rules.
|
|
24
|
+
*/
|
|
25
|
+
/** What a caller may state about the preview itself. */
|
|
26
|
+
export interface PreviewOptions {
|
|
27
|
+
/** The record to evaluate for `state`; an empty record when the caller states none. */
|
|
28
|
+
readonly input?: EvaluationInput;
|
|
29
|
+
readonly env?: EvaluationEnv;
|
|
30
|
+
/** The locale to show, as the host spells it; omitted means the document's default. */
|
|
31
|
+
readonly locale?: string;
|
|
32
|
+
/** Refuse a request the catalogue does not carry rather than showing the default language. */
|
|
33
|
+
readonly strict?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* The compiled declarations of the tables the draft's rules read, from `compileDataset`.
|
|
36
|
+
*
|
|
37
|
+
* A `datasetRef` pins a table's id and version but carries neither its columns nor its kind, so
|
|
38
|
+
* a rule that calls `lookup`, `decide` or `in_set` is only checkable with the compiled
|
|
39
|
+
* declaration in hand. The preview compiles the draft's fallback copy (or its single-locale fast
|
|
40
|
+
* path when every entry declares the requested locale) exactly as a build compiles the document,
|
|
41
|
+
* so it forwards these to that compile and reports the same `DATASET_DECLARATION_MISSING`
|
|
42
|
+
* refusal when a table the draft pins has no declaration at the pinned version. The array
|
|
43
|
+
* travels nowhere: the handle still exposes no artifact.
|
|
44
|
+
*/
|
|
45
|
+
readonly datasets?: readonly CompiledDatasetDeclaration[];
|
|
46
|
+
/**
|
|
47
|
+
* The authored tables the host holds, or the dataset stores editing them: the same input
|
|
48
|
+
* `buildDocument` takes. Only the draft's pinned tables are compiled, and a table that does not
|
|
49
|
+
* compile is reported as the build diagnostic naming it.
|
|
50
|
+
*/
|
|
51
|
+
readonly tables?: readonly DatasetInput[];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Compiles a preview of the document and returns an opaque handle over it.
|
|
55
|
+
*
|
|
56
|
+
* The artifact is the one a committed dispatch already compiled for this exact document, and only
|
|
57
|
+
* when that draft serialises identically to the preview copy (which holds on the single-locale
|
|
58
|
+
* fast path when every entry already declares the requested locale). Everything else compiles the
|
|
59
|
+
* multi-locale fallback copy in closure scope.
|
|
60
|
+
*
|
|
61
|
+
* The ok arm's seven members are the whole surface: the preview marker, the source hash, the
|
|
62
|
+
* derived state, the outstanding translation gaps and the two ways to evaluate more records. The
|
|
63
|
+
* failure arm states the compiler's diagnostics, including an unsupported locale under a strict
|
|
64
|
+
* request, and nothing else. No member states a report hash or a behaviour hash.
|
|
65
|
+
*/
|
|
66
|
+
export declare function compilePreview(document: AuthoringDocument, options?: PreviewOptions): PreviewCompileResult;
|
|
67
|
+
//# sourceMappingURL=compile-preview.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile-preview.d.ts","sourceRoot":"","sources":["../../src/preview/compile-preview.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,0BAA0B,EAAoB,MAAM,yBAAyB,CAAC;AAS5F,OAAO,KAAK,EAIV,aAAa,EACb,eAAe,EAMhB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAO/D,OAAO,KAAK,EAGV,oBAAoB,EAMrB,MAAM,aAAa,CAAC;AAErB;;;;;;;;;;;;;;;;;;GAkBG;AAEH,wDAAwD;AACxD,MAAM,WAAW,cAAc;IAC7B,uFAAuF;IACvF,QAAQ,CAAC,KAAK,CAAC,EAAE,eAAe,CAAC;IACjC,QAAQ,CAAC,GAAG,CAAC,EAAE,aAAa,CAAC;IAC7B,uFAAuF;IACvF,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,8FAA8F;IAC9F,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,0BAA0B,EAAE,CAAC;IAC1D;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,YAAY,EAAE,CAAC;CAC3C;AAgQD;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,iBAAiB,EAC3B,OAAO,GAAE,cAAmB,GAC3B,oBAAoB,CA6DtB"}
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import { compile } from '@azx-pbc/axiom-compiler';
|
|
2
|
+
import { assertNever, canonicalHash, compareCodePoints, createEngine, describeFormState, resolveSchemaLocale, } from '@azx-pbc/axiom-runtime';
|
|
3
|
+
import { withDatasetDeclarations } from '../schema/dataset-input.js';
|
|
4
|
+
import { serializeDocument } from '../schema/document.js';
|
|
5
|
+
import { translationGaps } from '../i18n/gaps.js';
|
|
6
|
+
import { documentTextLocale } from '../i18n/text-locale.js';
|
|
7
|
+
import { notePreviewCompile } from './measurement.js';
|
|
8
|
+
import { heldPreviewArtifact } from './held.js';
|
|
9
|
+
/** The catalogue locale selection reads: the declared set, the default and the keys. */
|
|
10
|
+
function catalogueOf(document) {
|
|
11
|
+
return {
|
|
12
|
+
...(document.locales === undefined ? {} : { locales: document.locales }),
|
|
13
|
+
...(document.defaultLocale === undefined ? {} : { defaultLocale: document.defaultLocale }),
|
|
14
|
+
messages: document.messages,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/** The one refusal shape a preview's locale decision states, at the document's locale list. */
|
|
18
|
+
function localeDiagnostic(requested, detail) {
|
|
19
|
+
return {
|
|
20
|
+
code: 'MESSAGE_LOCALE',
|
|
21
|
+
path: '$.locales',
|
|
22
|
+
detail,
|
|
23
|
+
...(requested === undefined ? {} : { locale: requested }),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function previewLocale(document, options) {
|
|
27
|
+
const resolution = resolveSchemaLocale(catalogueOf(document), options.locale, options.strict === true && options.locale !== undefined ? { strict: true } : {});
|
|
28
|
+
if (resolution.ok)
|
|
29
|
+
return { ok: true, locale: resolution.locale };
|
|
30
|
+
switch (resolution.reason) {
|
|
31
|
+
case 'invalid_tag':
|
|
32
|
+
return {
|
|
33
|
+
ok: false,
|
|
34
|
+
diagnostic: localeDiagnostic(options.locale, `\`${options.locale ?? ''}\` is not a locale tag; write a language, an optional script and an optional region, as \`pt-BR\``),
|
|
35
|
+
};
|
|
36
|
+
case 'unsupported_tag':
|
|
37
|
+
return {
|
|
38
|
+
ok: false,
|
|
39
|
+
diagnostic: localeDiagnostic(options.locale, `the document declares no catalogue entry for \`${options.locale ?? ''}\`, and a strict preview refuses to show another language's text`),
|
|
40
|
+
};
|
|
41
|
+
case 'no_catalogue':
|
|
42
|
+
return {
|
|
43
|
+
ok: false,
|
|
44
|
+
diagnostic: localeDiagnostic(options.locale, 'the document has no catalogue locale to preview; add a message in the locale you mean to show'),
|
|
45
|
+
};
|
|
46
|
+
default:
|
|
47
|
+
return assertNever(resolution.reason);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* A non-empty, parameter-free, plural-free placeholder for a catalogue slot the author has not
|
|
52
|
+
* written yet. It satisfies the compiler's completeness check on the closed-scope fallback
|
|
53
|
+
* document without inventing words or triggering CLDR plural rules on an unwritten locale, and it
|
|
54
|
+
* never leaves this closure.
|
|
55
|
+
*/
|
|
56
|
+
const UNWRITTEN_PREVIEW_SLOT = '-';
|
|
57
|
+
/** The own text an entry holds under `locale`, ignoring inherited object members. */
|
|
58
|
+
function ownText(entry, locale) {
|
|
59
|
+
return Object.hasOwn(entry, locale) ? entry[locale] : undefined;
|
|
60
|
+
}
|
|
61
|
+
/** The first stated locale and text of an entry, in code-point order, as the last fallback. */
|
|
62
|
+
function firstEntryOf(entry) {
|
|
63
|
+
for (const key of Object.keys(entry).sort(compareCodePoints)) {
|
|
64
|
+
const text = ownText(entry, key);
|
|
65
|
+
if (text !== undefined)
|
|
66
|
+
return [key, text];
|
|
67
|
+
}
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The document narrowed for preview: every entry carries the requested locale's own text when
|
|
72
|
+
* present, or borrows from the document's default locale (then the entry's first stated locale)
|
|
73
|
+
* while keeping borrowed text filed under the locale it was written in.
|
|
74
|
+
*
|
|
75
|
+
* Filing borrowed text under its source locale lets the compiler judge any ICU plural branches
|
|
76
|
+
* against the CLDR rules of the language the author wrote rather than an unwritten target locale,
|
|
77
|
+
* while unwritten slots in the fallback copy hold a plain placeholder so completeness passes and
|
|
78
|
+
* honest `translationGaps` travel beside the preview handle. When every entry already states
|
|
79
|
+
* `locale`, the result is a single-locale document with `locales: [locale]`.
|
|
80
|
+
*
|
|
81
|
+
* The copy is built here, used once, and stays in this closure: nothing returns it.
|
|
82
|
+
*/
|
|
83
|
+
function previewDocument(document, locale) {
|
|
84
|
+
const resolved = [];
|
|
85
|
+
const localeSet = new Set([locale]);
|
|
86
|
+
const textLocale = documentTextLocale(document);
|
|
87
|
+
for (const [key, entry] of Object.entries(document.messages)) {
|
|
88
|
+
const direct = ownText(entry, locale);
|
|
89
|
+
if (direct !== undefined) {
|
|
90
|
+
resolved.push({ key, sourceLocale: locale, text: direct });
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const fromDefault = textLocale === undefined ? undefined : ownText(entry, textLocale);
|
|
94
|
+
if (textLocale !== undefined && fromDefault !== undefined) {
|
|
95
|
+
localeSet.add(textLocale);
|
|
96
|
+
resolved.push({ key, sourceLocale: textLocale, text: fromDefault });
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const fallback = firstEntryOf(entry);
|
|
100
|
+
// A message with no text in any locale is left out; the compile then names the message key a
|
|
101
|
+
// slot resolves to and nothing invented here fills it.
|
|
102
|
+
if (fallback !== undefined) {
|
|
103
|
+
localeSet.add(fallback[0]);
|
|
104
|
+
resolved.push({ key, sourceLocale: fallback[0], text: fallback[1] });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const previewLocales = [...localeSet];
|
|
108
|
+
const messages = previewLocales.length === 1
|
|
109
|
+
? resolved.map(({ key, text }) => [key, { [locale]: text }])
|
|
110
|
+
: resolved.map(({ key, sourceLocale, text }) => [
|
|
111
|
+
key,
|
|
112
|
+
Object.fromEntries(previewLocales.map((tag) => [
|
|
113
|
+
tag,
|
|
114
|
+
tag === sourceLocale ? text : UNWRITTEN_PREVIEW_SLOT,
|
|
115
|
+
])),
|
|
116
|
+
]);
|
|
117
|
+
return {
|
|
118
|
+
...document,
|
|
119
|
+
locales: previewLocales,
|
|
120
|
+
defaultLocale: locale,
|
|
121
|
+
// Preserve every own key for validation; assignment would treat `__proto__` as a setter.
|
|
122
|
+
messages: Object.fromEntries(messages),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* The report body without either digest: the one shape the preview states.
|
|
127
|
+
*
|
|
128
|
+
* `ReportFacts` is `Omit<EvaluationReport, 'reportHash'>`, and it still carries `behaviorHash` —
|
|
129
|
+
* the artifact's behaviour commitment, which the publish gate compares evidence against. Dropping
|
|
130
|
+
* both members is the whole conversion: a preview states no digest of a report it would never let
|
|
131
|
+
* anyone deploy, and no identity of the artifact it compiled in a locale fallback.
|
|
132
|
+
*/
|
|
133
|
+
function previewFacts(report) {
|
|
134
|
+
const { behaviorHash: _behaviorHash, ...facts } = report;
|
|
135
|
+
return facts;
|
|
136
|
+
}
|
|
137
|
+
/** A sealed report narrowed to the same body, for the members that answer from one. */
|
|
138
|
+
function factsOf(report) {
|
|
139
|
+
const { reportHash: _reportHash, ...facts } = report;
|
|
140
|
+
return previewFacts(facts);
|
|
141
|
+
}
|
|
142
|
+
/** The runtime's derived state with its report narrowed, for every member that answers with one. */
|
|
143
|
+
function formStateOf(state) {
|
|
144
|
+
return { ...state, report: previewFacts(state.report) };
|
|
145
|
+
}
|
|
146
|
+
/** A session over the preview artifact, narrowed so no member states a digest. */
|
|
147
|
+
function previewEngine(engine) {
|
|
148
|
+
// A narrowed proposal is a view of the engine's own candidate, not a new candidate: session
|
|
149
|
+
// ownership and the basis stay with the original, which commit reads without restoring a digest
|
|
150
|
+
// into the value the caller holds.
|
|
151
|
+
const candidates = new WeakMap();
|
|
152
|
+
const narrowCandidate = (candidate) => {
|
|
153
|
+
// Reading `candidate.report` seals the candidate report. `candidate.form.report` carries the
|
|
154
|
+
// same unsealed report facts, so narrowing from `form` keeps preview staging zero-seal.
|
|
155
|
+
const form = formStateOf(candidate.form);
|
|
156
|
+
const narrowed = {
|
|
157
|
+
outcome: candidate.outcome,
|
|
158
|
+
basis: candidate.basis,
|
|
159
|
+
report: form.report,
|
|
160
|
+
form,
|
|
161
|
+
operations: candidate.operations,
|
|
162
|
+
};
|
|
163
|
+
candidates.set(narrowed, candidate);
|
|
164
|
+
return Object.freeze(narrowed);
|
|
165
|
+
};
|
|
166
|
+
return {
|
|
167
|
+
...engine,
|
|
168
|
+
getFormState: () => formStateOf(engine.getFormState()),
|
|
169
|
+
report: () => factsOf(engine.report()),
|
|
170
|
+
explainField: (fieldId, rowKey) => {
|
|
171
|
+
const { reportHash: _reportHash, behaviorHash: _behaviorHash, ...explanation } = engine.explainField(fieldId, rowKey);
|
|
172
|
+
return explanation;
|
|
173
|
+
},
|
|
174
|
+
preview: (operations) => {
|
|
175
|
+
const candidate = engine.preview(operations);
|
|
176
|
+
if (candidate.outcome !== 'candidate')
|
|
177
|
+
return candidate;
|
|
178
|
+
return narrowCandidate(candidate);
|
|
179
|
+
},
|
|
180
|
+
propose: (operations) => {
|
|
181
|
+
const proposal = engine.propose(operations);
|
|
182
|
+
if (proposal.outcome !== 'proposed')
|
|
183
|
+
return proposal;
|
|
184
|
+
const candidate = narrowCandidate(proposal.candidate);
|
|
185
|
+
let pending = proposal;
|
|
186
|
+
let delta;
|
|
187
|
+
const deltaOf = () => {
|
|
188
|
+
if (delta !== undefined)
|
|
189
|
+
return delta;
|
|
190
|
+
if (pending === undefined) {
|
|
191
|
+
throw new Error('preview proposal delta source was released before delta was built');
|
|
192
|
+
}
|
|
193
|
+
// The delta names the reports before and after the change set. Both are digests a build
|
|
194
|
+
// is read from, so the preview states the same delta without them.
|
|
195
|
+
const { baseReportHash: _base, candidateReportHash: _candidate, ...narrowed } = pending.delta;
|
|
196
|
+
pending = undefined;
|
|
197
|
+
delta = Object.freeze(narrowed);
|
|
198
|
+
return delta;
|
|
199
|
+
};
|
|
200
|
+
const narrowed = {
|
|
201
|
+
outcome: 'proposed',
|
|
202
|
+
candidate,
|
|
203
|
+
addedBlockers: proposal.addedBlockers,
|
|
204
|
+
get delta() {
|
|
205
|
+
return deltaOf();
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
return Object.freeze(narrowed);
|
|
209
|
+
},
|
|
210
|
+
commit: (candidate) => {
|
|
211
|
+
const original = candidates.get(candidate);
|
|
212
|
+
if (original === undefined) {
|
|
213
|
+
return { outcome: 'refused', code: 'STALE_BASIS', basis: candidate.basis };
|
|
214
|
+
}
|
|
215
|
+
return engine.commit(original);
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Compiles a preview of the document and returns an opaque handle over it.
|
|
221
|
+
*
|
|
222
|
+
* The artifact is the one a committed dispatch already compiled for this exact document, and only
|
|
223
|
+
* when that draft serialises identically to the preview copy (which holds on the single-locale
|
|
224
|
+
* fast path when every entry already declares the requested locale). Everything else compiles the
|
|
225
|
+
* multi-locale fallback copy in closure scope.
|
|
226
|
+
*
|
|
227
|
+
* The ok arm's seven members are the whole surface: the preview marker, the source hash, the
|
|
228
|
+
* derived state, the outstanding translation gaps and the two ways to evaluate more records. The
|
|
229
|
+
* failure arm states the compiler's diagnostics, including an unsupported locale under a strict
|
|
230
|
+
* request, and nothing else. No member states a report hash or a behaviour hash.
|
|
231
|
+
*/
|
|
232
|
+
export function compilePreview(document, options = {}) {
|
|
233
|
+
const selected = previewLocale(document, options);
|
|
234
|
+
if (!selected.ok) {
|
|
235
|
+
return { ok: false, previewOnly: true, diagnostics: [selected.diagnostic] };
|
|
236
|
+
}
|
|
237
|
+
const resolved = withDatasetDeclarations(document, options.datasets, options.tables);
|
|
238
|
+
if (!resolved.ok) {
|
|
239
|
+
return { ok: false, previewOnly: true, diagnostics: [resolved.diagnostic] };
|
|
240
|
+
}
|
|
241
|
+
const input = options.input ?? { values: {} };
|
|
242
|
+
const env = options.env ?? {};
|
|
243
|
+
const sourceHash = canonicalHash(document);
|
|
244
|
+
const source = serializeDocument(document);
|
|
245
|
+
// The preview copy (multi-locale fallback, or single-locale fast path when complete) is built
|
|
246
|
+
// at most once: the held-artifact check needs its text, and a miss needs its text to compile.
|
|
247
|
+
let narrowedSource;
|
|
248
|
+
const previewSource = () => (narrowedSource ??= serializeDocument(previewDocument(document, selected.locale)));
|
|
249
|
+
// The only reusable artifact is the one a committed dispatch compiled from this exact document
|
|
250
|
+
// object, and only while the draft still serialises to the exact source the preview would
|
|
251
|
+
// compile (for example, on the single-locale fast path). A caller cannot supply one: a hash and
|
|
252
|
+
// a locale are assertions beside a schema, not facts derived from it, so nothing cheaper than
|
|
253
|
+
// the compile itself can prove a supplied artifact is this draft's.
|
|
254
|
+
const held = heldPreviewArtifact(document);
|
|
255
|
+
const reusable = held !== undefined && held.source === source && previewSource() === source
|
|
256
|
+
? held.schema
|
|
257
|
+
: undefined;
|
|
258
|
+
let artifact;
|
|
259
|
+
if (reusable !== undefined) {
|
|
260
|
+
artifact = reusable;
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
notePreviewCompile();
|
|
264
|
+
const compiled = compile(previewSource(), resolved.declarations.length === 0 ? {} : { datasets: resolved.declarations });
|
|
265
|
+
if (!compiled.ok) {
|
|
266
|
+
return { ok: false, previewOnly: true, diagnostics: compiled.diagnostics };
|
|
267
|
+
}
|
|
268
|
+
artifact = compiled.schema;
|
|
269
|
+
}
|
|
270
|
+
const evaluatePreview = (record, environment = {}) => describeFormState(artifact, record, environment);
|
|
271
|
+
const handle = {
|
|
272
|
+
ok: true,
|
|
273
|
+
previewOnly: true,
|
|
274
|
+
sourceHash,
|
|
275
|
+
state: formStateOf(evaluatePreview(input, env)),
|
|
276
|
+
translationGaps: translationGaps(document),
|
|
277
|
+
evaluatePreview: (record, environment) => formStateOf(evaluatePreview(record, environment)),
|
|
278
|
+
createPreviewEngine: (config = {}) => previewEngine(createEngine(artifact, {
|
|
279
|
+
input: config.input ?? { values: {} },
|
|
280
|
+
...(config.env === undefined ? {} : { env: config.env }),
|
|
281
|
+
ports: config.ports ?? {},
|
|
282
|
+
})),
|
|
283
|
+
};
|
|
284
|
+
return handle;
|
|
285
|
+
}
|
|
286
|
+
//# sourceMappingURL=compile-preview.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile-preview.js","sourceRoot":"","sources":["../../src/preview/compile-preview.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAElD,OAAO,EACL,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,YAAY,EACZ,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,wBAAwB,CAAC;AAehC,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AA6DhD,wFAAwF;AACxF,SAAS,WAAW,CAAC,QAA2B;IAC9C,OAAO;QACL,GAAG,CAAC,QAAQ,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC;QACxE,GAAG,CAAC,QAAQ,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,QAAQ,CAAC,aAAa,EAAE,CAAC;QAC1F,QAAQ,EAAE,QAAQ,CAAC,QAAQ;KAC5B,CAAC;AACJ,CAAC;AAED,+FAA+F;AAC/F,SAAS,gBAAgB,CAAC,SAA6B,EAAE,MAAc;IACrE,OAAO;QACL,IAAI,EAAE,gBAAgB;QACtB,IAAI,EAAE,WAAW;QACjB,MAAM;QACN,GAAG,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,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esContent":["import { compile } from '@azx-pbc/axiom-compiler';\nimport type { CompiledDatasetDeclaration, SchemaDiagnostic } from '@azx-pbc/axiom-compiler';\nimport {\n assertNever,\n canonicalHash,\n compareCodePoints,\n createEngine,\n describeFormState,\n resolveSchemaLocale,\n} from '@azx-pbc/axiom-runtime';\nimport type {\n CompiledSchema,\n Engine,\n EngineCandidate,\n EvaluationEnv,\n EvaluationInput,\n EvaluationReport,\n FormState,\n LocaleCatalogue,\n ProposedCandidate,\n ReportFacts,\n} from '@azx-pbc/axiom-runtime';\nimport type { AuthoringDocument } from '../schema/document.js';\nimport type { DatasetInput } from '../schema/dataset-input.js';\nimport { withDatasetDeclarations } from '../schema/dataset-input.js';\nimport { serializeDocument } from '../schema/document.js';\nimport { translationGaps } from '../i18n/gaps.js';\nimport { documentTextLocale } from '../i18n/text-locale.js';\nimport { notePreviewCompile } from './measurement.js';\nimport { heldPreviewArtifact } from './held.js';\nimport type {\n PreviewCandidate,\n PreviewCandidateDelta,\n PreviewCompileResult,\n PreviewEngine,\n PreviewFormState,\n PreviewProposal,\n PreviewReportFacts,\n PreviewSuccess,\n} from './handle.js';\n\n/**\n * A live preview of a draft, compiled in a locale fallback that never leaves this module.\n *\n * The compile a build runs is strict: every declared locale is required for every message, and a\n * gap fails it. An author editing a four-locale form has gaps almost all the time, so a preview\n * that ran the strict compile would be blank exactly when it is useful. This module builds a\n * fallback copy of the document in closure scope: every entry keeps the requested locale's own\n * text when present, or borrows from the document's default locale (then the entry's first stated\n * locale) while keeping borrowed text filed under its authored source locale so ICU plural rules\n * are checked against the language the author wrote, with unwritten slots held by an internal\n * placeholder that never leaves closure scope. When every entry already declares the requested\n * locale, the copy takes the single-locale fast path with `locales: [locale]`. The document the\n * author holds is untouched; the gaps it still has travel beside the preview as `translationGaps`,\n * and the fallback document and its artifact are reachable from no member of the handle.\n *\n * Locale selection is the runtime's one selector, `resolveSchemaLocale`: the same exact-then-prefix\n * -then-default order a shipped artifact uses, so a preview of `pt-PT` against a catalogue carrying\n * `pt` renders the `pt` text under `pt` plural rules.\n */\n\n/** What a caller may state about the preview itself. */\nexport interface PreviewOptions {\n /** The record to evaluate for `state`; an empty record when the caller states none. */\n readonly input?: EvaluationInput;\n readonly env?: EvaluationEnv;\n /** The locale to show, as the host spells it; omitted means the document's default. */\n readonly locale?: string;\n /** Refuse a request the catalogue does not carry rather than showing the default language. */\n readonly strict?: boolean;\n /**\n * The compiled declarations of the tables the draft's rules read, from `compileDataset`.\n *\n * A `datasetRef` pins a table's id and version but carries neither its columns nor its kind, so\n * a rule that calls `lookup`, `decide` or `in_set` is only checkable with the compiled\n * declaration in hand. The preview compiles the draft's fallback copy (or its single-locale fast\n * path when every entry declares the requested locale) exactly as a build compiles the document,\n * so it forwards these to that compile and reports the same `DATASET_DECLARATION_MISSING`\n * refusal when a table the draft pins has no declaration at the pinned version. The array\n * travels nowhere: the handle still exposes no artifact.\n */\n readonly datasets?: readonly CompiledDatasetDeclaration[];\n /**\n * The authored tables the host holds, or the dataset stores editing them: the same input\n * `buildDocument` takes. Only the draft's pinned tables are compiled, and a table that does not\n * compile is reported as the build diagnostic naming it.\n */\n readonly tables?: readonly DatasetInput[];\n}\n\n/** The catalogue locale selection reads: the declared set, the default and the keys. */\nfunction catalogueOf(document: AuthoringDocument): LocaleCatalogue {\n return {\n ...(document.locales === undefined ? {} : { locales: document.locales }),\n ...(document.defaultLocale === undefined ? {} : { defaultLocale: document.defaultLocale }),\n messages: document.messages,\n };\n}\n\n/** The one refusal shape a preview's locale decision states, at the document's locale list. */\nfunction localeDiagnostic(requested: string | undefined, detail: string): SchemaDiagnostic {\n return {\n code: 'MESSAGE_LOCALE',\n path: '$.locales',\n detail,\n ...(requested === undefined ? {} : { locale: requested }),\n };\n}\n\n/** The locale the preview shows, or the refusal that names why none does. */\ntype PreviewLocale =\n | { readonly ok: true; readonly locale: string }\n | { readonly ok: false; readonly diagnostic: SchemaDiagnostic };\n\nfunction previewLocale(document: AuthoringDocument, options: PreviewOptions): PreviewLocale {\n const resolution = resolveSchemaLocale(\n catalogueOf(document),\n options.locale,\n options.strict === true && options.locale !== undefined ? { strict: true } : {},\n );\n if (resolution.ok) return { ok: true, locale: resolution.locale };\n switch (resolution.reason) {\n case 'invalid_tag':\n return {\n ok: false,\n diagnostic: localeDiagnostic(\n options.locale,\n `\\`${options.locale ?? ''}\\` is not a locale tag; write a language, an optional script and an optional region, as \\`pt-BR\\``,\n ),\n };\n case 'unsupported_tag':\n return {\n ok: false,\n diagnostic: localeDiagnostic(\n options.locale,\n `the document declares no catalogue entry for \\`${options.locale ?? ''}\\`, and a strict preview refuses to show another language's text`,\n ),\n };\n case 'no_catalogue':\n return {\n ok: false,\n diagnostic: localeDiagnostic(\n options.locale,\n 'the document has no catalogue locale to preview; add a message in the locale you mean to show',\n ),\n };\n default:\n return assertNever(resolution.reason);\n }\n}\n\n/**\n * A non-empty, parameter-free, plural-free placeholder for a catalogue slot the author has not\n * written yet. It satisfies the compiler's completeness check on the closed-scope fallback\n * document without inventing words or triggering CLDR plural rules on an unwritten locale, and it\n * never leaves this closure.\n */\nconst UNWRITTEN_PREVIEW_SLOT = '-';\n\n/** The own text an entry holds under `locale`, ignoring inherited object members. */\nfunction ownText(entry: Readonly<Record<string, string>>, locale: string): string | undefined {\n return Object.hasOwn(entry, locale) ? entry[locale] : undefined;\n}\n\n/** The first stated locale and text of an entry, in code-point order, as the last fallback. */\nfunction firstEntryOf(\n entry: Readonly<Record<string, string>>,\n): readonly [string, string] | undefined {\n for (const key of Object.keys(entry).sort(compareCodePoints)) {\n const text = ownText(entry, key);\n if (text !== undefined) return [key, text];\n }\n return undefined;\n}\n\n/** One entry's chosen text and the locale it was authored in. */\ninterface ResolvedPreviewEntry {\n readonly key: string;\n readonly sourceLocale: string;\n readonly text: string;\n}\n\n/**\n * The document narrowed for preview: every entry carries the requested locale's own text when\n * present, or borrows from the document's default locale (then the entry's first stated locale)\n * while keeping borrowed text filed under the locale it was written in.\n *\n * Filing borrowed text under its source locale lets the compiler judge any ICU plural branches\n * against the CLDR rules of the language the author wrote rather than an unwritten target locale,\n * while unwritten slots in the fallback copy hold a plain placeholder so completeness passes and\n * honest `translationGaps` travel beside the preview handle. When every entry already states\n * `locale`, the result is a single-locale document with `locales: [locale]`.\n *\n * The copy is built here, used once, and stays in this closure: nothing returns it.\n */\nfunction previewDocument(document: AuthoringDocument, locale: string): AuthoringDocument {\n const resolved: ResolvedPreviewEntry[] = [];\n const localeSet = new Set<string>([locale]);\n const textLocale = documentTextLocale(document);\n for (const [key, entry] of Object.entries(document.messages)) {\n const direct = ownText(entry, locale);\n if (direct !== undefined) {\n resolved.push({ key, sourceLocale: locale, text: direct });\n continue;\n }\n const fromDefault = textLocale === undefined ? undefined : ownText(entry, textLocale);\n if (textLocale !== undefined && fromDefault !== undefined) {\n localeSet.add(textLocale);\n resolved.push({ key, sourceLocale: textLocale, text: fromDefault });\n continue;\n }\n const fallback = firstEntryOf(entry);\n // A message with no text in any locale is left out; the compile then names the message key a\n // slot resolves to and nothing invented here fills it.\n if (fallback !== undefined) {\n localeSet.add(fallback[0]);\n resolved.push({ key, sourceLocale: fallback[0], text: fallback[1] });\n }\n }\n const previewLocales = [...localeSet];\n const messages: [string, Readonly<Record<string, string>>][] =\n previewLocales.length === 1\n ? resolved.map(({ key, text }) => [key, { [locale]: text }])\n : resolved.map(({ key, sourceLocale, text }) => [\n key,\n Object.fromEntries(\n previewLocales.map((tag) => [\n tag,\n tag === sourceLocale ? text : UNWRITTEN_PREVIEW_SLOT,\n ]),\n ),\n ]);\n return {\n ...document,\n locales: previewLocales,\n defaultLocale: locale,\n // Preserve every own key for validation; assignment would treat `__proto__` as a setter.\n messages: Object.fromEntries(messages),\n };\n}\n\n/**\n * The report body without either digest: the one shape the preview states.\n *\n * `ReportFacts` is `Omit<EvaluationReport, 'reportHash'>`, and it still carries `behaviorHash` —\n * the artifact's behaviour commitment, which the publish gate compares evidence against. Dropping\n * both members is the whole conversion: a preview states no digest of a report it would never let\n * anyone deploy, and no identity of the artifact it compiled in a locale fallback.\n */\nfunction previewFacts(report: ReportFacts): PreviewReportFacts {\n const { behaviorHash: _behaviorHash, ...facts } = report;\n return facts;\n}\n\n/** A sealed report narrowed to the same body, for the members that answer from one. */\nfunction factsOf(report: EvaluationReport): PreviewReportFacts {\n const { reportHash: _reportHash, ...facts } = report;\n return previewFacts(facts);\n}\n\n/** The runtime's derived state with its report narrowed, for every member that answers with one. */\nfunction formStateOf(state: FormState): PreviewFormState {\n return { ...state, report: previewFacts(state.report) };\n}\n\n/** A session over the preview artifact, narrowed so no member states a digest. */\nfunction previewEngine(engine: Engine): PreviewEngine {\n // A narrowed proposal is a view of the engine's own candidate, not a new candidate: session\n // ownership and the basis stay with the original, which commit reads without restoring a digest\n // into the value the caller holds.\n const candidates = new WeakMap<PreviewCandidate, EngineCandidate>();\n const narrowCandidate = (candidate: EngineCandidate): PreviewCandidate => {\n // Reading `candidate.report` seals the candidate report. `candidate.form.report` carries the\n // same unsealed report facts, so narrowing from `form` keeps preview staging zero-seal.\n const form = formStateOf(candidate.form);\n const narrowed: PreviewCandidate = {\n outcome: candidate.outcome,\n basis: candidate.basis,\n report: form.report,\n form,\n operations: candidate.operations,\n };\n candidates.set(narrowed, candidate);\n return Object.freeze(narrowed);\n };\n return {\n ...engine,\n getFormState: () => formStateOf(engine.getFormState()),\n report: () => factsOf(engine.report()),\n explainField: (fieldId, rowKey) => {\n const {\n reportHash: _reportHash,\n behaviorHash: _behaviorHash,\n ...explanation\n } = engine.explainField(fieldId, rowKey);\n return explanation;\n },\n preview: (operations) => {\n const candidate = engine.preview(operations);\n if (candidate.outcome !== 'candidate') return candidate;\n return narrowCandidate(candidate);\n },\n propose: (operations) => {\n const proposal = engine.propose(operations);\n if (proposal.outcome !== 'proposed') return proposal;\n const candidate = narrowCandidate(proposal.candidate);\n let pending: ProposedCandidate | undefined = proposal;\n let delta: PreviewCandidateDelta | undefined;\n const deltaOf = (): PreviewCandidateDelta => {\n if (delta !== undefined) return delta;\n if (pending === undefined) {\n throw new Error('preview proposal delta source was released before delta was built');\n }\n // The delta names the reports before and after the change set. Both are digests a build\n // is read from, so the preview states the same delta without them.\n const {\n baseReportHash: _base,\n candidateReportHash: _candidate,\n ...narrowed\n } = pending.delta;\n pending = undefined;\n delta = Object.freeze(narrowed);\n return delta;\n };\n const narrowed: PreviewProposal = {\n outcome: 'proposed',\n candidate,\n addedBlockers: proposal.addedBlockers,\n get delta(): PreviewCandidateDelta {\n return deltaOf();\n },\n };\n return Object.freeze(narrowed);\n },\n commit: (candidate) => {\n const original = candidates.get(candidate);\n if (original === undefined) {\n return { outcome: 'refused', code: 'STALE_BASIS', basis: candidate.basis };\n }\n return engine.commit(original);\n },\n };\n}\n\n/**\n * Compiles a preview of the document and returns an opaque handle over it.\n *\n * The artifact is the one a committed dispatch already compiled for this exact document, and only\n * when that draft serialises identically to the preview copy (which holds on the single-locale\n * fast path when every entry already declares the requested locale). Everything else compiles the\n * multi-locale fallback copy in closure scope.\n *\n * The ok arm's seven members are the whole surface: the preview marker, the source hash, the\n * derived state, the outstanding translation gaps and the two ways to evaluate more records. The\n * failure arm states the compiler's diagnostics, including an unsupported locale under a strict\n * request, and nothing else. No member states a report hash or a behaviour hash.\n */\nexport function compilePreview(\n document: AuthoringDocument,\n options: PreviewOptions = {},\n): PreviewCompileResult {\n const selected = previewLocale(document, options);\n if (!selected.ok) {\n return { ok: false, previewOnly: true, diagnostics: [selected.diagnostic] };\n }\n const resolved = withDatasetDeclarations(document, options.datasets, options.tables);\n if (!resolved.ok) {\n return { ok: false, previewOnly: true, diagnostics: [resolved.diagnostic] };\n }\n const input = options.input ?? { values: {} };\n const env = options.env ?? {};\n const sourceHash = canonicalHash(document);\n const source = serializeDocument(document);\n // The preview copy (multi-locale fallback, or single-locale fast path when complete) is built\n // at most once: the held-artifact check needs its text, and a miss needs its text to compile.\n let narrowedSource: string | undefined;\n const previewSource = (): string =>\n (narrowedSource ??= serializeDocument(previewDocument(document, selected.locale)));\n // The only reusable artifact is the one a committed dispatch compiled from this exact document\n // object, and only while the draft still serialises to the exact source the preview would\n // compile (for example, on the single-locale fast path). A caller cannot supply one: a hash and\n // a locale are assertions beside a schema, not facts derived from it, so nothing cheaper than\n // the compile itself can prove a supplied artifact is this draft's.\n const held = heldPreviewArtifact(document);\n const reusable =\n held !== undefined && held.source === source && previewSource() === source\n ? held.schema\n : undefined;\n let artifact: CompiledSchema;\n if (reusable !== undefined) {\n artifact = reusable;\n } else {\n notePreviewCompile();\n const compiled = compile(\n previewSource(),\n resolved.declarations.length === 0 ? {} : { datasets: resolved.declarations },\n );\n if (!compiled.ok) {\n return { ok: false, previewOnly: true, diagnostics: compiled.diagnostics };\n }\n artifact = compiled.schema;\n }\n const evaluatePreview = (record: EvaluationInput, environment: EvaluationEnv = {}): FormState =>\n describeFormState(artifact, record, environment);\n const handle: PreviewSuccess = {\n ok: true,\n previewOnly: true,\n sourceHash,\n state: formStateOf(evaluatePreview(input, env)),\n translationGaps: translationGaps(document),\n evaluatePreview: (record, environment) => formStateOf(evaluatePreview(record, environment)),\n createPreviewEngine: (config = {}) =>\n previewEngine(\n createEngine(artifact, {\n input: config.input ?? { values: {} },\n ...(config.env === undefined ? {} : { env: config.env }),\n ports: config.ports ?? {},\n }),\n ),\n };\n return handle;\n}\n"]}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { CandidateDelta, Engine, EngineCandidate, EngineFieldExplanation, EngineOperation, EngineOutcome, EnginePorts, EvaluationEnv, EvaluationInput, FormBlocker, FormState, ReportFacts, SessionRefusal } from '@azx-pbc/axiom-runtime';
|
|
2
|
+
import type { SchemaDiagnostic, TranslationGap } from '@azx-pbc/axiom-compiler';
|
|
3
|
+
/**
|
|
4
|
+
* The preview handle a builder renders from.
|
|
5
|
+
*
|
|
6
|
+
* A preview is a live, ephemeral form: it evaluates the document an author is editing so the UI
|
|
7
|
+
* can show it, and it is *not* a deployable artifact. The distinction is the type, not a naming
|
|
8
|
+
* convention. The handle carries a derived `FormState` whose report states no digest, and an
|
|
9
|
+
* engine whose every report-bearing member is narrowed the same way. No member returns the
|
|
10
|
+
* compiled schema, the artifact, or anything from which one could be serialised into a
|
|
11
|
+
* deployment.
|
|
12
|
+
*
|
|
13
|
+
* **Both** digests a build states are withheld, not only the report's. `ReportFacts` is the
|
|
14
|
+
* report body without `reportHash`, and it still carries `behaviorHash` — the artifact's own
|
|
15
|
+
* behaviour commitment, which the compiler's publish gate compares evidence against
|
|
16
|
+
* (`readinessGaps`). Because behaviour hashes strip presentation, the preview's value is
|
|
17
|
+
* *identical* to the strict build's, so a preview that stated it would hand a host a correct
|
|
18
|
+
* answer to "what will this ship" for a document that has not even been translated. A preview
|
|
19
|
+
* therefore narrows the body to `PreviewReportFacts` and states neither digest.
|
|
20
|
+
*/
|
|
21
|
+
/** A report body without either digest a deployment is read from. */
|
|
22
|
+
export type PreviewReportFacts = Omit<ReportFacts, 'behaviorHash'>;
|
|
23
|
+
/** The derived form state a preview states: the runtime's own, with its report narrowed. */
|
|
24
|
+
export type PreviewFormState = Omit<FormState, 'report'> & {
|
|
25
|
+
readonly report: PreviewReportFacts;
|
|
26
|
+
};
|
|
27
|
+
/** What a caller may supply to a preview engine; the artifact is already fixed. */
|
|
28
|
+
export interface PreviewEngineConfig {
|
|
29
|
+
/** The record the session starts from; an empty record when the caller states none. */
|
|
30
|
+
readonly input?: EvaluationInput;
|
|
31
|
+
readonly env?: EvaluationEnv;
|
|
32
|
+
readonly ports?: EnginePorts;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A proposal a preview session can commit, with its report and form state narrowed.
|
|
36
|
+
*
|
|
37
|
+
* `Engine.preview` seals the report of the state the operations would produce, and a sealed
|
|
38
|
+
* report carries a digest. That digest is one of the two values a preview must not hand a
|
|
39
|
+
* caller, so the proposal states the report's body and nothing a build could be mistaken for.
|
|
40
|
+
* Commit maps this narrowed view back to the session's original owned candidate.
|
|
41
|
+
*/
|
|
42
|
+
export type PreviewCandidate = Omit<EngineCandidate, 'report' | 'form' | 'session'> & {
|
|
43
|
+
readonly report: PreviewReportFacts;
|
|
44
|
+
readonly form: PreviewFormState;
|
|
45
|
+
};
|
|
46
|
+
/** The audit trail behind one binding, without either digest a deployment is read from. */
|
|
47
|
+
export type PreviewFieldExplanation = Omit<EngineFieldExplanation, 'reportHash' | 'behaviorHash'>;
|
|
48
|
+
/**
|
|
49
|
+
* A delta stated by a preview, with the two report digests withheld.
|
|
50
|
+
*
|
|
51
|
+
* The candidate delta names the reports before and after a change set, and both are digests a
|
|
52
|
+
* build is read from. A preview states the same facts with those two members removed, exactly as
|
|
53
|
+
* it states a proposal without a sealed report's digest.
|
|
54
|
+
*/
|
|
55
|
+
export type PreviewCandidateDelta = Omit<CandidateDelta, 'baseReportHash' | 'candidateReportHash'>;
|
|
56
|
+
/** A proposal a preview session can commit, with its report, form state and delta narrowed. */
|
|
57
|
+
export type PreviewProposal = {
|
|
58
|
+
readonly outcome: 'proposed';
|
|
59
|
+
readonly candidate: PreviewCandidate;
|
|
60
|
+
/**
|
|
61
|
+
* The blockers the change set adds, computed without sealing either report.
|
|
62
|
+
*
|
|
63
|
+
* A host that only decides whether a write is worth confirming reads this and nothing else, so
|
|
64
|
+
* a staged write that is never inspected pays no canonicalisation or hash.
|
|
65
|
+
*/
|
|
66
|
+
readonly addedBlockers: readonly FormBlocker[];
|
|
67
|
+
/**
|
|
68
|
+
* The whole delta, built lazily on first read with the two report digests withheld.
|
|
69
|
+
*/
|
|
70
|
+
readonly delta: PreviewCandidateDelta;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* A live session over the preview artifact, with every hash a deployment could be read from
|
|
74
|
+
* removed.
|
|
75
|
+
*
|
|
76
|
+
* Every operation, subscription and derived state of `Engine` is available. Five members answer
|
|
77
|
+
* with a sealed report or a state that carries one — `report`, `getFormState`, `preview`,
|
|
78
|
+
* `propose` and `explainField` — and each is narrowed here to the report's digest-free body.
|
|
79
|
+
* `commit` maps the narrowed proposal to the original candidate, whose owning session checks its
|
|
80
|
+
* basis and operations.
|
|
81
|
+
*/
|
|
82
|
+
export type PreviewEngine = Omit<Engine, 'report' | 'getFormState' | 'preview' | 'propose' | 'explainField' | 'commit'> & {
|
|
83
|
+
readonly report: () => PreviewReportFacts;
|
|
84
|
+
readonly getFormState: () => PreviewFormState;
|
|
85
|
+
readonly preview: (operations: readonly EngineOperation[]) => PreviewCandidate | SessionRefusal;
|
|
86
|
+
readonly propose: (operations: readonly EngineOperation[]) => PreviewProposal | SessionRefusal;
|
|
87
|
+
readonly commit: (candidate: PreviewCandidate) => EngineOutcome;
|
|
88
|
+
readonly explainField: (fieldId: string, rowKey?: string | number) => PreviewFieldExplanation;
|
|
89
|
+
};
|
|
90
|
+
/** The preview could not be built: the document does not compile, or the locale is not carried. */
|
|
91
|
+
export interface PreviewFailure {
|
|
92
|
+
readonly ok: false;
|
|
93
|
+
readonly previewOnly: true;
|
|
94
|
+
/** Why no preview exists, in the compiler's own vocabulary, so an editor underlines them. */
|
|
95
|
+
readonly diagnostics: readonly SchemaDiagnostic[];
|
|
96
|
+
}
|
|
97
|
+
/** A live preview of the document, with every member opaque about the artifact beneath it. */
|
|
98
|
+
export interface PreviewSuccess {
|
|
99
|
+
readonly ok: true;
|
|
100
|
+
readonly previewOnly: true;
|
|
101
|
+
/**
|
|
102
|
+
* SHA-256 of the authored source document the preview was built from.
|
|
103
|
+
*
|
|
104
|
+
* It identifies *the draft*, not a build: two edits to one field produce two hashes, and the
|
|
105
|
+
* same draft always produces the same one. It is deliberately not a report hash.
|
|
106
|
+
*/
|
|
107
|
+
readonly sourceHash: string;
|
|
108
|
+
/** The form the preview's record evaluates to, with no digest in its report. */
|
|
109
|
+
readonly state: PreviewFormState;
|
|
110
|
+
/** Every declared locale a catalogue entry is missing, from the compiler's own walk. */
|
|
111
|
+
readonly translationGaps: readonly TranslationGap[];
|
|
112
|
+
/** Evaluates another record against the same preview artifact, purely. */
|
|
113
|
+
readonly evaluatePreview: (input: EvaluationInput, env?: EvaluationEnv) => PreviewFormState;
|
|
114
|
+
/** Opens a live session over the same preview artifact. */
|
|
115
|
+
readonly createPreviewEngine: (config?: PreviewEngineConfig) => PreviewEngine;
|
|
116
|
+
}
|
|
117
|
+
/** A preview or the reasons there is none. */
|
|
118
|
+
export type PreviewCompileResult = PreviewSuccess | PreviewFailure;
|
|
119
|
+
//# sourceMappingURL=handle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle.d.ts","sourceRoot":"","sources":["../../src/preview/handle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,MAAM,EACN,eAAe,EACf,sBAAsB,EACtB,eAAe,EACf,aAAa,EACb,WAAW,EACX,aAAa,EACb,eAAe,EACf,WAAW,EACX,SAAS,EACT,WAAW,EACX,cAAc,EACf,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEhF;;;;;;;;;;;;;;;;;GAiBG;AAEH,qEAAqE;AACrE,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;AAEnE,4FAA4F;AAC5F,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,GAAG;IACzD,QAAQ,CAAC,MAAM,EAAE,kBAAkB,CAAC;CACrC,CAAC;AAEF,mFAAmF;AACnF,MAAM,WAAW,mBAAmB;IAClC,uFAAuF;IACvF,QAAQ,CAAC,KAAK,CAAC,EAAE,eAAe,CAAC;IACjC,QAAQ,CAAC,GAAG,CAAC,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC;CAC9B;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,eAAe,EAAE,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAC,GAAG;IACpF,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