@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/README.md
CHANGED
|
@@ -1,3 +1,649 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @azx-pbc/axiom-builder
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A framework-free authoring store for Axiom schema documents, created in an explicit locale. Every
|
|
4
|
+
edit is a command over an immutable snapshot, so undo, redo, preview and diff read the same
|
|
5
|
+
history; what cannot be a draft is refused by the compiler's own check, and what can is reported as
|
|
6
|
+
the diagnostics a compile still states. A draft's rules are readable back as the when/then forms an
|
|
7
|
+
editor shows, exactly or as the source they were written as. It is the fourth package in the
|
|
8
|
+
lockstep graph (`builder -> compiler -> runtime <- react`), and it has no React, DOM, clock,
|
|
9
|
+
randomness or business domain in it: a starter template here would be one client's vocabulary
|
|
10
|
+
shipped to every client.
|
|
11
|
+
|
|
12
|
+
`getState` and `subscribe` are the store's `useSyncExternalStore`-compatible pair, so a React, Vue,
|
|
13
|
+
Svelte or plain-DOM UI subscribes to it without this package depending on any of them; what it
|
|
14
|
+
renders is a host's business.
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
pnpm add @azx-pbc/axiom-builder
|
|
20
|
+
# or: npm install @azx-pbc/axiom-builder
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The package states no `react-native` export condition and has no React dependency: it runs in a
|
|
24
|
+
browser preview, in a Node build step and in a server-side editor alike. Its only dependencies are
|
|
25
|
+
`@azx-pbc/axiom-compiler` and `@azx-pbc/axiom-runtime`.
|
|
26
|
+
|
|
27
|
+
## Quickstart
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import {
|
|
31
|
+
compilePreview,
|
|
32
|
+
createAuthoringStore,
|
|
33
|
+
createEmptySchema,
|
|
34
|
+
exportMissingTranslations,
|
|
35
|
+
} from '@azx-pbc/axiom-builder';
|
|
36
|
+
import { compile } from '@azx-pbc/axiom-compiler';
|
|
37
|
+
|
|
38
|
+
const store = createAuthoringStore(
|
|
39
|
+
createEmptySchema({ schemaId: 'measure_form', defaultLocale: 'en', locales: ['en', 'es'] }),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
store.dispatch({
|
|
43
|
+
kind: 'addField',
|
|
44
|
+
field: { fieldId: 'f_measure', label: 'Measure', primitive: 'decimal', control: 'decimal' },
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// The label is written in `en` only, so the document is not yet complete in `es`. The preview
|
|
48
|
+
// renders anyway; a build refuses until the text is translated.
|
|
49
|
+
const preview = compilePreview(store.getState().document);
|
|
50
|
+
if (preview.ok) {
|
|
51
|
+
console.log(
|
|
52
|
+
preview.state.fields.map((field) => field.fieldId),
|
|
53
|
+
preview.translationGaps,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
for (const gap of exportMissingTranslations(store.getState().document)) {
|
|
58
|
+
console.log(gap.locale, gap.messageKey, 'from', gap.sourceText);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
store.dispatch({
|
|
62
|
+
kind: 'importTranslations',
|
|
63
|
+
translations: [{ messageKey: 'field.f_measure', locale: 'es', text: 'Medida' }],
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const built = compile(JSON.stringify(store.getState().document));
|
|
67
|
+
console.log(built.ok, store.canUndo());
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Store state and history
|
|
71
|
+
|
|
72
|
+
`getState()` returns an `AuthoringState`: the document, the diagnostics a compile of it reports,
|
|
73
|
+
and `canUndo`/`canRedo` for the cursor. The flags are on the snapshot rather than only on the store
|
|
74
|
+
methods, so one `useSyncExternalStore(store.subscribe, store.getState, store.getState)` renders the
|
|
75
|
+
document and both buttons without a second read a render did not subscribe to; `store.canUndo()` and
|
|
76
|
+
`store.canRedo()` answer the same two flags for imperative code. Two cursor positions with the same
|
|
77
|
+
document are still different states (undoing to the document the store opened re-enables redo), so
|
|
78
|
+
the snapshot's identity carries the position as well as the content.
|
|
79
|
+
|
|
80
|
+
A committed dispatch returns `effects`. `effects.truncated` is true on the one commit that dropped
|
|
81
|
+
the oldest retained state because the chain reached `HISTORY_LIMIT` (200 steps). A host offering
|
|
82
|
+
"undo to the beginning" reads it to know that the beginning is no longer the document it opened;
|
|
83
|
+
`undo()` then answers `{ ok: false, reason: 'nothing_to_undo' }`. `effects.coalesced` reports a step
|
|
84
|
+
merged into the one before it, and `effects.clamped` names every field a narrower group had to
|
|
85
|
+
narrow.
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
const state = store.getState();
|
|
89
|
+
state.canUndo; // false at the document the store opened
|
|
90
|
+
state.canRedo; // true after an undo moved the cursor back
|
|
91
|
+
|
|
92
|
+
const committed = store.dispatch({
|
|
93
|
+
kind: 'setMessageText',
|
|
94
|
+
messageKey: 'field.f_note',
|
|
95
|
+
locale: 'en',
|
|
96
|
+
text: 'Note',
|
|
97
|
+
});
|
|
98
|
+
committed.ok && committed.effects.truncated; // true on the commit that dropped the oldest step
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Public surface
|
|
102
|
+
|
|
103
|
+
| Purpose | Exports |
|
|
104
|
+
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
105
|
+
| Start a document | `createEmptySchema`, `serializeDocument` |
|
|
106
|
+
| Load a stored draft | `readDocument` |
|
|
107
|
+
| Author with a store | `createAuthoringStore`, `HISTORY_LIMIT`, `parseCommand`, `MAX_MEMBER_NESTING`, `COMMAND_KINDS` |
|
|
108
|
+
| Start a dataset | `createDatasetTable`, `readDatasetDocument`, `datasetDigest` |
|
|
109
|
+
| Author a dataset | `createDatasetStore`, `parseDatasetCommand`, `DATASET_COMMAND_KINDS`, `DATASET_COMMAND_KIND_SET` |
|
|
110
|
+
| Keep a pin honest | `checkDatasetPin`, `datasetPinChecks`, `publishDataset` |
|
|
111
|
+
| Suggest an id | `suggestFieldId`, `FIELD_PALETTE` |
|
|
112
|
+
| Translations | `translationGaps`, `exportMissingTranslations`, `importTranslations` |
|
|
113
|
+
| Preview | `compilePreview` |
|
|
114
|
+
| Cards for a UI | `fieldCards`, `diagnosticCardField`, `unattachedDiagnostics` |
|
|
115
|
+
| Layout for an editor | `layoutIndex` |
|
|
116
|
+
| Visual rule forms | `projectRule`, `toVisual`, `emitVisual`, `visualSource`, `representVisual`, `parseVisual`, `documentIndex`, `MAX_VISUAL_NESTING` |
|
|
117
|
+
| Field impact | `referencesOf`, `ruleExpressionSlots` |
|
|
118
|
+
| Publish a revision | `diffAgainstPublished`, `declaredEvidenceRepairs`, `notCausalRepairs` |
|
|
119
|
+
| Types: document | `AuthoringDocument`, `AuthoringField`, `AuthoringOption`, `AuthoringRowKey`, `AuthoringItem`, `AuthoringRule`, `AuthoringGate`, `AuthoringGateItem`, `AuthoringScreenReason`, `AuthoringTestCase`, `AuthoringContext`, `AuthoringDatasetReference`, `AuthoringAnnotations`, `AuthoringLayoutNode`, `AuthoringCatalogue`, `CreateSchemaOptions`, `ScalarPrimitive` |
|
|
120
|
+
| Types: layout | `IndexedLayoutNode`, `IndexedReadout`, `LayoutIndex`, `LayoutKind`, `LayoutPlacement` |
|
|
121
|
+
| Types: commands | `AuthoringCommand`, `AddFieldSpec`, `AddOptionSpec`, `AddRecordArraySpec`, `AddRuleSpec`, `AddRuleTestCaseCommand`, `ContextRootSpec`, `DatasetPinSpec`, `EditFieldSpec`, `EditFieldCommand`, `FieldDeclarationSpec`, `DeprecateOptionCommand`, `EditLayoutNodeCommand`, `GateItemSpec`, `GateSpec`, `LayoutPath`, `MemberFieldSpec`, `MemberSpec`, `MoveLayoutNodeCommand`, `PinDatasetCommand`, `PlaceFieldCommand`, `RemoveContextRootCommand`, `RemoveLayoutNodeCommand`, `ScreenReasonSpec`, `SetContextRootCommand`, `SetDocumentTitleCommand`, `SetFieldDeclarationCommand`, `SetLocalesCommand`, `SetOnHideCommand`, `SetPrimaryCommand`, `SetRuleExprCommand`, `SetSignatureCoversCommand`, `TestCaseSpec`, `UnpinDatasetCommand`, `AuthoringRuleKind`, `CommandParse` |
|
|
122
|
+
| Types: evidence | `EvidenceAssertion`, `EvidenceRepair`, `NotCausalRepair`, `SuggestedCase`, `VerifiedEvidence` |
|
|
123
|
+
| Types: store | `AuthoringStore`, `AuthoringStoreOptions`, `AuthoringState`, `DispatchOutcome`, `DispatchEffects`, `HistoryOutcome`, `HistoryRefusal`, `ClampedField`, `PublishedBaseline`, `AuthoringRefusal`, `AuthoringRefusalCode` |
|
|
124
|
+
| Types: palette | `FieldPaletteEntry`, `PaletteNeeds` |
|
|
125
|
+
| Types: translations | `TranslationGap`, `MissingTranslation`, `TranslationEntry`, `TranslationImport` |
|
|
126
|
+
| Types: reading | `DocumentRead` |
|
|
127
|
+
| Types: preview | `PreviewOptions`, `PreviewCompileResult`, `PreviewSuccess`, `PreviewFailure`, `PreviewEngine`, `PreviewEngineConfig`, `PreviewCandidate`, `PreviewFieldExplanation`, `PreviewFormState`, `PreviewReportFacts` |
|
|
128
|
+
| Types: cards | `FieldCard`, `CardContext` |
|
|
129
|
+
| Types: visual forms | `VisualExpr`, `VisualValue`, `ScalarVisualValue`, `VisualList`, `RuleExpression`, `OrderedComparison`, `TextMatchOperator`, `PresenceCheck`, `FormatCheck`, `DateSpan`, `VisualRepresentation`, `VisualRefusal`, `VisualRefusalReason`, `VisualParse`; the closed operator lists `ORDERED_COMPARISONS`, `TEXT_MATCH_OPERATORS`, `PRESENCE_CHECKS`, `FORMAT_CHECKS`, `DATE_SPANS` |
|
|
130
|
+
| Types: impact | `FieldReferences`, `DependencyRead`, `FieldReference`, `FieldReferenceKind`, `UnparseableExpression`, `ExpressionSlot` |
|
|
131
|
+
| Types: revisions | `DiffAgainstPublishedOptions`, `PublishedDiff`, `PublishedDiffResult`, `RevisionRefusal`, `RevisionVerdict` |
|
|
132
|
+
| Types: dataset | `AuthoredDatasetDocument`, `AuthoredDatasetBinding`, `AuthoredDatasetIdentity`, `AuthoredLookupTable`, `AuthoredDecisionTable`, `AuthoredSetTable`, `AuthoredLookupRow`, `AuthoredDecisionRow`, `AuthoredHitPolicy`, `CreateDatasetOptions`, `DatasetDocumentRead`, `DatasetCommand`, `DatasetCommandParse`, `DatasetCellInput`, `DatasetRowSpec`, `AddDatasetRowCommand`, `ReplaceDatasetRowCommand`, `RemoveDatasetRowCommand`, `SetDatasetCellCommand`, `SetDatasetColumnsCommand`, `SetDatasetValuesCommand`, `SetDatasetHitPolicyCommand`, `SetDatasetEffectiveRangeCommand`, `DatasetStore`, `DatasetStoreOptions`, `DatasetState`, `DatasetDispatchOutcome`, `DatasetDispatchEffects`, `DatasetHistoryOutcome`, `DatasetPin`, `DatasetPinCheck`, `DatasetPublication` |
|
|
133
|
+
| Errors | `AuthoringError` |
|
|
134
|
+
|
|
135
|
+
## Reading a stored draft
|
|
136
|
+
|
|
137
|
+
`readDocument(value)` is the one door a draft from outside the process comes through: a file, a
|
|
138
|
+
stored document, another process's value. It takes `unknown` and answers `{ ok: true, document }` or
|
|
139
|
+
`{ ok: false, refusal }`, so a caller reaches every later entry with a document of the declared type
|
|
140
|
+
and never with a cast.
|
|
141
|
+
|
|
142
|
+
The runtime's restricted-profile reader first copies the value onto plain data without invoking
|
|
143
|
+
host accessors, then the closed metaschema answers, so its refusal is the compiler's own — its
|
|
144
|
+
failing keyword, document path and the detail an author repairs. Reading the validated tree adds
|
|
145
|
+
only the narrowing. Expression and catalogue slots are deliberately narrower than the metaschema,
|
|
146
|
+
which also admits the compiled form: an expression may be source text or the closed AST, and a
|
|
147
|
+
catalogue entry may be source text or a compiled message AST. A draft carries the text an author
|
|
148
|
+
writes, so a document holding the parsed form is refused with the repair. A test case's `values`
|
|
149
|
+
is required because the metaschema requires it: a case with no input decides nothing.
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
import { readDocument } from '@azx-pbc/axiom-builder';
|
|
153
|
+
|
|
154
|
+
const stored: unknown = JSON.parse(await draft.text());
|
|
155
|
+
const read = readDocument(stored);
|
|
156
|
+
if (!read.ok) return showRefusal(read.refusal);
|
|
157
|
+
const store = createAuthoringStore(read.document);
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Refusals
|
|
161
|
+
|
|
162
|
+
A refusal commits nothing: the state and the undo chain are untouched, by identity. Every refusal
|
|
163
|
+
carries the `code`, the `path`, the `detail` and a `repair` the store states for you. A command
|
|
164
|
+
refusal's path is rooted at `#` — `#.rule.message` for the member the command itself got wrong — and
|
|
165
|
+
`$` appears only where the refusal is about a location in the document the command would write.
|
|
166
|
+
|
|
167
|
+
| Code | Cause |
|
|
168
|
+
| ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
169
|
+
| `MALFORMED_COMMAND` | A command whose members are missing, wrong-typed, unknown, or name a value the contract does not pair; a `validate` rule with no `message`; a member tree nested deeper than `MAX_MEMBER_NESTING`. |
|
|
170
|
+
| `UNKNOWN_FIELD` | The command names a `fieldId` the document does not declare. |
|
|
171
|
+
| `UNKNOWN_OPTION` | The command names an option `code` the field's own `options` domain does not declare. |
|
|
172
|
+
| `UNKNOWN_MESSAGE` | A `setMessageText` or `importTranslations` key is named by no declaration, rule or layout node of the draft and `messages` does not already hold it. |
|
|
173
|
+
| `UNDECLARED_LOCALE` | A `setMessageText` or `importTranslations` names a locale the document's `locales` set does not declare; declare it with `setLocales` first. |
|
|
174
|
+
| `UNKNOWN_RULE` | A `setRuleExpr` or `addRuleTestCase` names a `ruleId` the document does not declare. |
|
|
175
|
+
| `UNKNOWN_GATE` | A `setPrimary` names a `ruleId` the document does not declare as a `gate`. |
|
|
176
|
+
| `UNKNOWN_SCREEN` | A `setPrimary` names a `ruleId` the document does not declare as a `screen`. |
|
|
177
|
+
| `UNKNOWN_DATASET` | An `unpinDataset` names a `tableId` the document does not pin. |
|
|
178
|
+
| `UNKNOWN_CONTEXT_ROOT` | A `removeContextRoot` names a `path` the document does not declare in `context.roots`. |
|
|
179
|
+
| `UNREPRESENTABLE_EXPRESSION` | A visual form reads a path this draft does not declare at that rule's scope, a form's operand type the vocabulary does not accept, a visual on a `defaultCompute` writer, or a tree the printer has no canonical source for. |
|
|
180
|
+
| `DUPLICATE_ID` | A field id, rule id, option code, step id, layout placement or minted message key is already taken; a translation batch repeats one `(messageKey, locale)`. |
|
|
181
|
+
| `PUBLISHED_FIELD` | The change would rewrite a declaration the `PublishedBaseline` already published. An `editField` of `descriptionKey` or `placeholderKey` is the exception: message copy is presentation, so a published field's help text and placeholder may change. |
|
|
182
|
+
| `ALREADY_DEPRECATED` | The field or option is already retired. |
|
|
183
|
+
| `UNKNOWN_LAYOUT` | The layout path names no node. |
|
|
184
|
+
| `INVALID_STRUCTURE` | The candidate is not a document the compiler's structural stage admits (a row key the contract refuses, a control the primitive does not pair with). |
|
|
185
|
+
| `UNKNOWN_PROPERTY` | A member the node does not declare, which is `unevaluatedProperties` in the closed metaschema. |
|
|
186
|
+
| `C11_VIOLATION` | `visibleWhen` on a node that cannot be hidden: a group, wizard, field, heading, divider or data-bearing step (a section is admitted). |
|
|
187
|
+
| `INVALID_LAYOUT` | An illegal containment, member, tone, or anchor reference. |
|
|
188
|
+
| `COLUMN_OVERFLOW` | A `colSpan` wider than the columns its layout parent lays out. |
|
|
189
|
+
| `UNKNOWN_TABLE` | A dataset command names a `tableId` the dataset store does not hold. |
|
|
190
|
+
| `UNKNOWN_ROW` | A dataset command names a `rowId` the table does not declare. |
|
|
191
|
+
| `UNKNOWN_COLUMN` | A dataset command names a `columnId` the table does not declare, or a row output member that is not an output column. |
|
|
192
|
+
| `INVALID_CELL` | A typed cell is not the canonical spelling of its column’s primitive, or is stated as another primitive. |
|
|
193
|
+
| `DUPLICATE_KEY` | A row’s composite key equals another row’s under a `UNIQUE` table; `FIRST` and `COLLECT` admit a repeated key. |
|
|
194
|
+
| `INVALID_ROW` | A row’s members do not fit the table kind: a lookup row’s `outcome`, a missing lookup `output`, a missing decision outcome, a `PASS` row with no output, or a key vector of the wrong arity. |
|
|
195
|
+
| `INVALID_COLUMNS` | A keyed table would declare no `key` column, or its column ids, primitives, roles or order would change while rows are addressed by them. |
|
|
196
|
+
| `INVALID_TABLE` | An edit the table’s `kind` or `binding` does not admit, or an empty half-open effective range. |
|
|
197
|
+
| `DATASET_PIN_MISMATCH` | The document no longer answers the pin: another version, another digest, or another table. `publishDataset` refuses rather than serialising rows under bytes the pin does not name. |
|
|
198
|
+
| `STALE_EDITION` | The pasted document states an edition older than the host published; opening it would put the draft behind its published revision. State the published edition or a later one: an edition only moves forward, and the host owns the number it published. |
|
|
199
|
+
|
|
200
|
+
Everything else a compile reports is a **diagnostic**, not a refusal: an unfinished expression, a
|
|
201
|
+
type error, an unresolved reference, a cycle, a duplicate writer and a missing translation are all
|
|
202
|
+
legal states of a draft. They arrive on the new state's `diagnostics` and are placed on cards, so an
|
|
203
|
+
editor can underline them while the author keeps typing. The stage order is the compiler's: a
|
|
204
|
+
document with a missing translation is refused before its expressions are read, so the gap is
|
|
205
|
+
reported first and an expression error appears once the text is translated.
|
|
206
|
+
|
|
207
|
+
## Commands
|
|
208
|
+
|
|
209
|
+
`dispatch` takes one command from a closed union and answers with a committed state or a refusal.
|
|
210
|
+
`parseCommand(value)` is the same narrowing without a store, for a host that persists a command or
|
|
211
|
+
receives one from a UI; its `CommandParse` is `{ ok: true, command }` or `{ ok: false, refusal }`.
|
|
212
|
+
|
|
213
|
+
| Command | What it authors |
|
|
214
|
+
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
215
|
+
| `addField` | A scalar field; a scalar/attachment array with its `options` domain, its `optionSource` or its `rowKey`; or a top-level `record` with at least one member, placed in the layout unless `placement: 'none'` leaves the declaration for a later `placeField` |
|
|
216
|
+
| `editField` | A declared field's `control`, `descriptionKey`, `placeholderKey`, `onHide` or `annotations`. An absent member is left alone and a `null` removes it, so one command changes, clears and ignores without three shapes. `primitive`, `items`, `rowKey` and `options` are declaration decisions with commands of their own, not edits |
|
|
217
|
+
| `addOption` | One option on a declared field, with its label in the default locale |
|
|
218
|
+
| `deprecateOption` | Retires one code of a declared field's option domain. The code stays a legal value: a renderer shows it as retired, while existing records and signatures still name it |
|
|
219
|
+
| `addRule` | One rule of any of the eight kinds the metaschema enumerates, with its `expression` as the editor holds it (a visual form or source). A `gate` carries its `items`, `hard`, `activeWhen` and `onReadOnlyError`; a `screen` its `reasons` and `referWhen`; a `defaultCompute` its `overrideFieldId`; a `visible`/`enabled` rule its `fieldIds`. A `validate`, `gate` or `screen` requires its `message` (minted as `rule.<ruleId>`), `validate` defaults `severity` to `block`, and a retired field gains none. An optional `note` records why the rule exists: author-facing text of 1 to 500 characters after trimming, never rendered and outside `behaviorHash` |
|
|
220
|
+
| `addRuleTestCase` | One embedded vector on a declared rule, as the metaschema's `testCase` states it: `caseId`, `values`, `expected`, and the optional `context`, `redacted`, `sessionWrites`, `accessOverlay`, `recordDate`, `capabilities` and `tier`. The publish gate executes it |
|
|
221
|
+
| `setRuleExpr` | One declared rule's expression: the visual form the editor holds, stored as the printer's canonical source, or source text stored byte for byte. Consecutive source edits of one rule coalesce into a single undo step |
|
|
222
|
+
| `setRuleNote` | One declared rule's author-facing `note`: why the rule exists, 1 to 500 characters after trimming. Never rendered, never translated and no message key; it travels into the compiled artifact and is outside `behaviorHash`. A blank note is refused at the member. Consecutive edits of one rule's note coalesce into a single undo step |
|
|
223
|
+
| `setMessageText` | The text of one message in one locale; consecutive edits of one slot coalesce into a single undo step. The key must be one the draft names — a declaration, a rule or a layout node — or one `messages` already holds (`UNKNOWN_MESSAGE`) |
|
|
224
|
+
| `deprecateField` | Retires a field; the only change a published declaration admits |
|
|
225
|
+
| `addLayoutNode` | One node of the closed ten-kind layout grammar, as wire JSON, under an optional parent path |
|
|
226
|
+
| `editLayoutNode` | The members of one node at a child-index path, merged over the node that is there: an absent member is left alone and a `null` removes it, as `editField` does. `kind` is its identity and is checked rather than replaced, and the tree below it stays: `children` belongs to `addLayoutNode` and `removeLayoutNode`, `columns` to `setGroupColumns` |
|
|
227
|
+
| `removeLayoutNode` | One node at a child-index path and everything below it. The declarations it placed stay declared, so the palette can place them again |
|
|
228
|
+
| `setGroupColumns` | A group's `columns`; every field child that no longer fits is narrowed and reported in `effects.clamped` |
|
|
229
|
+
| `placeField` | Places a declared field that was added with `placement: 'none'`, under an optional parent path and with an optional `colSpan`. A field that already has a placement is refused as `DUPLICATE_ID`; moving a placed leaf is `moveLayoutNode` |
|
|
230
|
+
| `moveLayoutNode` | Removes the node at `target` and places it under `parent` at `index` (append when absent). Both paths address the tree as it stands, so a removal that shifts a sibling is accounted for; a destination inside the moved subtree is refused as `INVALID_LAYOUT` |
|
|
231
|
+
| `setPrimary` | Designates the primary `gate` or `screen` a caller acts on when it names none. A document that declares a gate or a screen designates exactly one; the first rule of that kind a command adds is designated until this repoints it |
|
|
232
|
+
| `pinDataset` | Declares or replaces a `datasetRef` — a `tableId` and the `tableVersion` the document resolves against — keeping declaration order stable |
|
|
233
|
+
| `unpinDataset` | Removes a declared table pin by `tableId`; a pin the document does not state is `UNKNOWN_DATASET` |
|
|
234
|
+
| `setContextRoot` | Declares or replaces one read-only evaluation root — its dotted `path`, `primitive`, optional `nullability` and, for an array, its item declaration. A reserved root or a malformed path is refused at the member |
|
|
235
|
+
| `removeContextRoot` | Removes a declared context root by `path`, and the `context` block with it when the last root goes |
|
|
236
|
+
| `setOnHide` | The document-level hiding policy, `preserve` or `exclude`; `null` clears it back to the default |
|
|
237
|
+
| `setDocumentTitle` | The document's title text, minted under the `title` message key and stated as `titleKey` |
|
|
238
|
+
| `setSignatureCovers` | The field ids a `signature_ref` field's signature binds, in the order the signature declares them. Refused on a published declaration, on another primitive, on a self-cover, and on an empty or duplicate list |
|
|
239
|
+
| `setLocales` | The document's locale policy — the set every catalogue entry is complete in and the one a renderer shows by default — as one pair, so no intermediate state names a default the set does not carry. A dropped locale's texts go with it in the same undo step; a new language commits as a draft with the gaps a compile reports |
|
|
240
|
+
| `addRecordArray` | A record array with its row key and at least one row member, as one undo step |
|
|
241
|
+
| `addRowMember` | One member — a field or a nested record — of a record array |
|
|
242
|
+
| `addRecordMember` | One member of a record container |
|
|
243
|
+
| `setRowKey` | A record array's row identity; refused on a published array |
|
|
244
|
+
| `setSchemaVersion` | The edition the draft states: a whole number at least 2, and only forward past the one the draft holds |
|
|
245
|
+
| `importTranslations` | A batch of texts as one document change; every key must be one the draft names (or one `messages` already holds), and one batch may state a locale once per key |
|
|
246
|
+
|
|
247
|
+
A container command's member tree nests at most `MAX_MEMBER_NESTING` (16) records deep; a deeper
|
|
248
|
+
tree is refused as `MALFORMED_COMMAND` rather than walking a recursive structure its parser cannot
|
|
249
|
+
bound.
|
|
250
|
+
|
|
251
|
+
## Dataset row authoring
|
|
252
|
+
|
|
253
|
+
A dataset is a second closed document, so it has a second store and a second command union. The
|
|
254
|
+
document is `spec/metaschema/dataset.v1.json` — `tableId`, `tableVersion`, `binding` and `kind`, and
|
|
255
|
+
then, by kind, a set's `values` or a keyed table's `columns`, `rows` and `hitPolicy` — and the
|
|
256
|
+
`createDatasetStore` gate is the dataset compiler itself. A command either commits one undo step,
|
|
257
|
+
succeeds without a step because it restates the table, or refuses, exactly as the schema store does;
|
|
258
|
+
`serializeDocument` writes either document, so one save path and one undo/redo comparison serve both.
|
|
259
|
+
Consecutive edits of one cell coalesce into one step, and `seal()` ends that run so returning to the
|
|
260
|
+
cell is a step of its own.
|
|
261
|
+
|
|
262
|
+
```ts
|
|
263
|
+
import {
|
|
264
|
+
createDatasetStore,
|
|
265
|
+
createDatasetTable,
|
|
266
|
+
publishDataset,
|
|
267
|
+
serializeDocument,
|
|
268
|
+
} from '@azx-pbc/axiom-builder';
|
|
269
|
+
|
|
270
|
+
const store = createDatasetStore(
|
|
271
|
+
createDatasetTable({
|
|
272
|
+
tableId: 't_prices',
|
|
273
|
+
tableVersion: 2,
|
|
274
|
+
kind: 'lookup',
|
|
275
|
+
binding: 'data',
|
|
276
|
+
effectiveFrom: '2026-01-01',
|
|
277
|
+
effectiveTo: '2027-01-01',
|
|
278
|
+
hitPolicy: 'UNIQUE',
|
|
279
|
+
}),
|
|
280
|
+
// The pin the schema states. The state reports whether the rows still answer it.
|
|
281
|
+
{ pin: { tableId: 't_prices', tableVersion: 2 } },
|
|
282
|
+
);
|
|
283
|
+
|
|
284
|
+
store.dispatch({
|
|
285
|
+
kind: 'setDatasetColumns',
|
|
286
|
+
tableId: 't_prices',
|
|
287
|
+
columns: [
|
|
288
|
+
{ columnId: 'region', primitive: 'string', role: 'key' },
|
|
289
|
+
{ columnId: 'tier', primitive: 'integer', role: 'key' },
|
|
290
|
+
{ columnId: 'amount', primitive: 'money', role: 'output' },
|
|
291
|
+
],
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
store.dispatch({
|
|
295
|
+
kind: 'addDatasetRow',
|
|
296
|
+
tableId: 't_prices',
|
|
297
|
+
row: {
|
|
298
|
+
rowId: 'row_us_gold',
|
|
299
|
+
key: [
|
|
300
|
+
{ kind: 'string', value: 'US' },
|
|
301
|
+
{ kind: 'integer', value: 1 },
|
|
302
|
+
],
|
|
303
|
+
output: { amount: { kind: 'money', value: { minor: '1250', currency: 'USD', scale: 2 } } },
|
|
304
|
+
},
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
const bytes = publishDataset(store.getState().document, {
|
|
308
|
+
tableId: 't_prices',
|
|
309
|
+
tableVersion: 2,
|
|
310
|
+
});
|
|
311
|
+
if (bytes.ok) await save(bytes.text);
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
| Command | What it authors |
|
|
315
|
+
| -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
316
|
+
| `addDatasetRow` | One row: its `rowId`, one typed cell per key column in declaration order, and — for a decision table — its `outcome` and `output`. A lookup row states an `output` and no `outcome`; a `PASS` row states both. |
|
|
317
|
+
| `replaceDatasetRow` | One row’s values, addressed by `rowId` and never renamed by the edit. The key may move; a duplicate under `UNIQUE` is refused. |
|
|
318
|
+
| `removeDatasetRow` | One row, addressed by `rowId`. |
|
|
319
|
+
| `setDatasetCell` | One cell with typed input: the `kind` is the column’s primitive, so text in a money column is refused rather than coerced. A quantity cell is `{ value, unit }`, checked against the column’s declared units and scale. Consecutive edits of one cell coalesce into one undo step. |
|
|
320
|
+
| `setDatasetColumns` | A keyed table’s columns and with them its composite key. Refused while rows are addressed by them unless the declaration is unchanged, because a row’s key is positional and its output is keyed by column id. |
|
|
321
|
+
| `setDatasetValues` | A set table’s closed membership domain. |
|
|
322
|
+
| `setDatasetHitPolicy` | A keyed table’s `UNIQUE`/`FIRST`/`COLLECT` policy and, for `COLLECT`, its `collectLimit`; the cap goes when the policy does. |
|
|
323
|
+
| `setDatasetEffectiveRange` | A `data` table’s half-open `[effectiveFrom, effectiveTo)` range; refused on a `behavior` table and for an empty range. |
|
|
324
|
+
|
|
325
|
+
`createDatasetTable` supplies the members an edit never changes: the table id, the version, the
|
|
326
|
+
clock binding and the kind. A published version is not edited in place (`DATA-1.1.2`), so changing
|
|
327
|
+
the binding or the kind is a new table, not a command.
|
|
328
|
+
|
|
329
|
+
### Keeping the pin honest
|
|
330
|
+
|
|
331
|
+
A schema’s `datasetRef` pins a version; the artifact’s pin adds the restricted-JCS SHA-256 of the
|
|
332
|
+
bytes that version resolved (`DATA-4.1.6`). `checkDatasetPin` answers a discriminated union —
|
|
333
|
+
`match`, `version_mismatch`, `digest_mismatch`, `other_table`, `unserved` — because an edit to the
|
|
334
|
+
rows of a published version changes the digest without changing the version, and that state must be
|
|
335
|
+
reported rather than serialised over. `createDatasetStore(document, { pin })` puts the answer on
|
|
336
|
+
every state (`state.pin`), `datasetPinChecks(pins, documents)` answers a whole draft’s pins at once,
|
|
337
|
+
and `publishDataset` refuses with `DATASET_PIN_MISMATCH` — naming both versions or both digests —
|
|
338
|
+
instead of handing a caller bytes the pin does not name. With no pin stated it publishes, because a
|
|
339
|
+
table being authored for the first time has nothing to contradict. `serializeDocument` stays a
|
|
340
|
+
formatter — it writes the bytes of either document and judges no pin — so a host that publishes
|
|
341
|
+
through it owns that check; `publishDataset` is the door that already owns it.
|
|
342
|
+
|
|
343
|
+
`readDatasetDocument(text)` is the load door: the dataset compiler’s ingestion, closed metaschema and
|
|
344
|
+
semantic checks run first, and the walk that follows states the authored union (the conditional
|
|
345
|
+
`binding`, `hitPolicy` and row members the metaschema cannot express as a type). `datasetDigest`
|
|
346
|
+
reports the digest an artifact would pin.
|
|
347
|
+
|
|
348
|
+
## Published declarations
|
|
349
|
+
|
|
350
|
+
`createAuthoringStore(document, { published })` takes the host's `PublishedBaseline` — the version it
|
|
351
|
+
published and the field ids that version declared — and throws `AuthoringError` when the draft states
|
|
352
|
+
an older `schemaVersion` than the baseline: a draft is opened at or after the edition it continues.
|
|
353
|
+
Published-ness is derived per dispatch from that baseline and the draft's own declarations; the store
|
|
354
|
+
keeps no set that can drift. A published field cannot be deleted or rewritten: it is retired with
|
|
355
|
+
`deprecateField`. An edition is `deprecateField`, then `setSchemaVersion`, then `addField` with the
|
|
356
|
+
new field id — the version identifies the declaration set a device ships, so a retirement and its
|
|
357
|
+
replacement are a new edition rather than a rewrite of the old one, and `setSchemaVersion` only moves
|
|
358
|
+
forward. This is a workflow guard, not a security boundary — the store runs in the author's process,
|
|
359
|
+
and a client can always craft a document. What governs a submission is the compiled artifact and the
|
|
360
|
+
host's own authorisation, never the editor's opinion.
|
|
361
|
+
|
|
362
|
+
One exception is message copy. `editField` may still change a published field's `descriptionKey` and
|
|
363
|
+
`placeholderKey`: `diffAgainstPublished` classifies a revision that moves only presentation as
|
|
364
|
+
`none`, so the copy is not part of the declaration a device reads a value through. `control`,
|
|
365
|
+
`onHide` and `annotations` remain refused, and a spec that mixes copy with one of them is refused
|
|
366
|
+
whole rather than applied in part.
|
|
367
|
+
|
|
368
|
+
## Diffing against the published revision
|
|
369
|
+
|
|
370
|
+
`diffAgainstPublished(published, draft, { datasets?, catalogue?, upcasters? })` compiles the draft
|
|
371
|
+
strictly and compares it with the published artifact. Pass the compiled `DatasetDeclaration`s its
|
|
372
|
+
expressions read, just as for `compile`: a dataset reference alone does not describe the table's
|
|
373
|
+
columns or kind. The classification is the compiler's — `classifyArtifactDiff` and
|
|
374
|
+
`revisionRequirements`, the same answers `axiom-cli diff` prints — so this diff and
|
|
375
|
+
`verifyPublishReadiness()` cannot disagree about whether behaviour moved: both read
|
|
376
|
+
`artifactBehaviour`.
|
|
377
|
+
|
|
378
|
+
```ts
|
|
379
|
+
import { diffAgainstPublished } from '@azx-pbc/axiom-builder';
|
|
380
|
+
|
|
381
|
+
const result = diffAgainstPublished(publishedArtifact, store.getState().document, {
|
|
382
|
+
catalogue, // optional: the artifacts the host retains for editions the draft skips
|
|
383
|
+
upcasters, // optional: the transforms the host publishes, keyed by hop then fieldId
|
|
384
|
+
});
|
|
385
|
+
if (result.kind === 'refused') return showRefusal(result.refusal);
|
|
386
|
+
switch (result.diff.verdict) {
|
|
387
|
+
case 'none': // layout or copy alone: publish without moving the edition
|
|
388
|
+
case 'additive': // behaviour moved; the advanced edition carries it
|
|
389
|
+
case 'requires-migration': // lawful, not yet migratable: `migrations` names what is missing
|
|
390
|
+
}
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
`EVOL-1.1.1` is the contract. A revision that moves only `layout`, message text or a rule's vectors
|
|
394
|
+
reports `none` with equal `publishedBehaviorHash`/`draftBehaviorHash`, so it may publish without a
|
|
395
|
+
version bump. A behaviour change must advance the edition; the same change at the published edition
|
|
396
|
+
is refused as `version_not_advanced`, because a device resolving that edition would evaluate a form
|
|
397
|
+
it never named.
|
|
398
|
+
|
|
399
|
+
The transition is read **one edition at a time**, because each hop states its own requirements.
|
|
400
|
+
A consecutive edition is the one hop the call already holds both ends of; a draft that skips
|
|
401
|
+
editions needs the host's `catalogue`, and a skipped edition it does not hold is refused as
|
|
402
|
+
`version_not_retained` rather than assumed to be an identity.
|
|
403
|
+
|
|
404
|
+
A lawful revision can still be **not yet migratable**. `requires-migration` carries one entry per
|
|
405
|
+
kind the revision asks for, and the host supplies that transform, mapping or binding to publish:
|
|
406
|
+
|
|
407
|
+
| kind | when | what resolves it |
|
|
408
|
+
| -------------------------- | --------------------------------------------------------------------- | ------------------------------------------------------------------ |
|
|
409
|
+
| `requires-upcaster` | a primitive, or a money `(currency, scale)`, changed | an upcaster (`EVOL-2.1.4`) |
|
|
410
|
+
| `requires-mapping` | a published option code is gone, or an open/host domain became closed | a declared value mapping |
|
|
411
|
+
| `requires-identity-review` | an array's `rowKey` mode or natural-key member changed | the host re-establishing row identity (`EVOL-2.1.6`) |
|
|
412
|
+
| `requires-host-mapping` | a context root was re-typed or removed | the host mapping its archived context |
|
|
413
|
+
| `requires-measure-review` | the pinned tables changed | the host deciding against the new measurement basis (`EVOL-1.1.2`) |
|
|
414
|
+
|
|
415
|
+
Four states are **refused**, because no transform repairs them:
|
|
416
|
+
|
|
417
|
+
- `removal_forbidden` — the draft drops a published declaration. A retired field is marked
|
|
418
|
+
`annotations.deprecated` and kept; its `fieldId` is reserved forever, and the upcast refuses the
|
|
419
|
+
recorded value of a declaration a target does not name (`EVOL-3.1.2`, `EVOL-2.1.7`). The refusal
|
|
420
|
+
names every removed declaration the walk sees, including one dropped at an intermediate edition.
|
|
421
|
+
- `deprecated_field_rule` — a rule newly targets a deprecated field (`EVOL-3.1.3`).
|
|
422
|
+
- `row_scope_unpairable` — a declaration kept while moving into or out of an array: a row is never
|
|
423
|
+
an upcaster key, so its recorded values have no pairing (`EVOL-2.1.6`).
|
|
424
|
+
- `upcaster_unresolved` — a transform names no value-bearing declaration on both sides of its hop
|
|
425
|
+
(`EVOL-2.1.7`).
|
|
426
|
+
|
|
427
|
+
A draft that does not compile is refused as `draft_not_compiling` with the compiler's diagnostics
|
|
428
|
+
attached, and a draft of another `schemaId` as `different_schema`.
|
|
429
|
+
|
|
430
|
+
The classification must agree with `artifactBehaviour`, so a classifier that calls a moved revision
|
|
431
|
+
presentation-only — or an unchanged one a behaviour change — throws `AxiomError` (`ENGINE_ERROR`).
|
|
432
|
+
`classify` exists for a caller that already holds the answer and for the test that proves the
|
|
433
|
+
invariant; the default is the compiler's classifier, and the identities this call derived are handed
|
|
434
|
+
to it rather than derived twice.
|
|
435
|
+
|
|
436
|
+
## Publishing a draft
|
|
437
|
+
|
|
438
|
+
A command writes evidence as well as declarations. `addRule` takes `testCases` and
|
|
439
|
+
`addRuleTestCase` appends one vector to a declared rule, so a store-authored document can carry the
|
|
440
|
+
cases the publish gate executes. An external `ScenarioSuiteDocument` remains the channel for
|
|
441
|
+
whole-form evidence, and both are executed by `verifyPublishReadiness`:
|
|
442
|
+
|
|
443
|
+
```ts
|
|
444
|
+
import { compile, parseScenarioSuite, verifyPublishReadiness } from '@azx-pbc/axiom-compiler';
|
|
445
|
+
import { declaredEvidenceRepairs, notCausalRepairs } from '@azx-pbc/axiom-builder';
|
|
446
|
+
|
|
447
|
+
// One rule may embed both branches it can reach; the commands wrote them.
|
|
448
|
+
store.dispatch({
|
|
449
|
+
kind: 'addRuleTestCase',
|
|
450
|
+
ruleId: 'r_positive',
|
|
451
|
+
testCase: { caseId: 'c_negative', values: { f_measure: '-1' }, expected: 'FAIL' },
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
const compiled = compile(JSON.stringify(store.getState().document));
|
|
455
|
+
if (!compiled.ok) throw new Error(JSON.stringify(compiled.diagnostics));
|
|
456
|
+
|
|
457
|
+
const parsed = parseScenarioSuite(suiteSource);
|
|
458
|
+
const verification = verifyPublishReadiness(compiled.schema, {
|
|
459
|
+
suites: parsed.ok ? [parsed.suite] : [],
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
// The gaps a compile's own vectors leave, each with the exact case or assertion that closes it.
|
|
463
|
+
for (const repair of declaredEvidenceRepairs(compiled.declaredEvidence, compiled.schema)) {
|
|
464
|
+
console.log(repair.gap.path, repair.repair);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// A gate verdict assertion earns `not_causal`; this names the `expect.rules` assertion instead.
|
|
468
|
+
for (const repair of notCausalRepairs(verification, compiled.schema)) {
|
|
469
|
+
console.log(repair.repair, repair.assertions);
|
|
470
|
+
}
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
`compiled.declaredEvidence` names the branches a draft's embedded vectors leave — one entry per
|
|
474
|
+
rule, with `path` naming the member to repair — and it is never a readiness verdict. Only
|
|
475
|
+
`verifyPublishReadiness` (or `axiom-cli test`, which writes the same verdict) states `ready`, from the
|
|
476
|
+
evidence it executed. `declaredEvidenceRepairs` states the exact case for each gap; for a gate it
|
|
477
|
+
names the `expect.rules` assertion, because `expect.gates` reports the gate's verdict rather than one
|
|
478
|
+
rule's branch, and a `gateItems` assertion proves one item rather than the gate's own firing table.
|
|
479
|
+
|
|
480
|
+
## Palette
|
|
481
|
+
|
|
482
|
+
`FIELD_PALETTE` is a view of the compiler's control matrix, not a second list: one row per
|
|
483
|
+
`(primitive, control)` pair the matrix pairs, plus the container and scalar-array rows it derives.
|
|
484
|
+
Every row states `needs` (`options`, `moneyDomain`, `rowKey`, `members`) — the members the matching
|
|
485
|
+
`addField` or `addRecordArray` must also carry — so a UI builds a complete command from the row
|
|
486
|
+
instead of discovering the missing member from a refusal.
|
|
487
|
+
|
|
488
|
+
## Cards
|
|
489
|
+
|
|
490
|
+
`fieldCards(document, context)` projects each declaration, its diagnostics and its missing
|
|
491
|
+
translations into plain data a UI renders; `unattachedDiagnostics` is the remainder that names no
|
|
492
|
+
card. Both read one walk of the declarations — each declaration's own message keys, not a re-walk
|
|
493
|
+
of every container's subtree — and one pass over the diagnostics and the gaps, `O(F + D + G)`,
|
|
494
|
+
rather than re-walking the declaration tree per card and diagnostic. A diagnostic
|
|
495
|
+
reaches the card of the declaration it names: a rule's expression error lands on the card of the
|
|
496
|
+
field the rule targets, a message's locale gap on the card of the field whose label it is, and a
|
|
497
|
+
nested layout node's diagnostic on the card of the field that node places.
|
|
498
|
+
|
|
499
|
+
## Layout for an editor
|
|
500
|
+
|
|
501
|
+
`layoutIndex(document)` is the document's layout as an editor addresses it: one walk of the
|
|
502
|
+
compiler's own `readLayout`, not a second parser. It answers the questions a layout UI asks without
|
|
503
|
+
a cast into wire JSON:
|
|
504
|
+
|
|
505
|
+
- `root` and `nodes` — the tree and the same nodes in depth-first declaration order;
|
|
506
|
+
- `groups` — every node that lays its children out in columns;
|
|
507
|
+
- `placements` — every `field` leaf with its placement path and column facts;
|
|
508
|
+
- `wizard` — the one wizard the grammar admits at the top level, or `undefined`;
|
|
509
|
+
- `nodeAt(path)` and `placementOf(fieldId)` — exact lookups; a path that names no node, or a field
|
|
510
|
+
the layout does not place, answers `undefined`.
|
|
511
|
+
|
|
512
|
+
Each `IndexedLayoutNode` carries `kind`, the child-index `path` every layout command takes
|
|
513
|
+
(`addLayoutNode`'s `parent`, `editLayoutNode`/`removeLayoutNode`'s `target`, `setGroupColumns`'
|
|
514
|
+
`group`), its `parent`, `index` and `depth`, and the column facts `columns`, `parentColumns` and
|
|
515
|
+
`colSpan`. Presentation members — `sectionId`, `stepId`, `gateId`, `fieldId`, title/description/text
|
|
516
|
+
keys, a callout's `tone`, `hideWhenEmpty`, `summaryFields` and `readouts` — are typed members here.
|
|
517
|
+
A spelling the grammar does not admit is reported as `kind: 'unknown'` rather than dropped, because
|
|
518
|
+
a draft still occupies the path the author has to repair; expression slots (`visibleWhen`, `params`,
|
|
519
|
+
a readout's `value`) stay `unknown`, since the document type does not narrow authored source text or
|
|
520
|
+
a loaded draft's compiled form either.
|
|
521
|
+
|
|
522
|
+
```ts
|
|
523
|
+
import { layoutIndex } from '@azx-pbc/axiom-builder';
|
|
524
|
+
|
|
525
|
+
const index = layoutIndex(store.getState().document);
|
|
526
|
+
index.placementOf('f_note'); // { path, fieldId, colSpan, parentColumns, node } or undefined
|
|
527
|
+
index.nodeAt([0, 0])?.kind; // 'group' for a group at that child-index path
|
|
528
|
+
index.wizard?.path; // the one wizard's path, or undefined
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
## Visual rules
|
|
532
|
+
|
|
533
|
+
`projectRule(rule, documentIndex(document))` states one rule's expression as the editor shows it:
|
|
534
|
+
either the visual form, or the source the author stored — unchanged, byte for byte. The visual
|
|
535
|
+
vocabulary is closed and is the AST's own shape, so an edit cannot change what a rule means:
|
|
536
|
+
|
|
537
|
+
- a comparison (`==`, `!=`, `<`, `<=`, `>`, `>=`) over declared fields, row members (`$it.member`, on
|
|
538
|
+
an item-scoped rule only) and declared context roots, including `context.record_date`;
|
|
539
|
+
- a list membership (`in`), the text matches `contains`/`starts_with`/`ends_with`/`ascii_match`, the
|
|
540
|
+
presence checks `empty`/`present`/`absent`, the format checks `is_email`/`is_phone`/`is_url`, and
|
|
541
|
+
the two `is_unique` arities;
|
|
542
|
+
- a count (`len(path)` against a whole number) and a signed date window (`days_between` or
|
|
543
|
+
`months_between`, with the operand order the author wrote);
|
|
544
|
+
- `has_cap("…")`, shown as a capability flag;
|
|
545
|
+
- `and`, `or` and unary `not`, kept in the nesting and order the author wrote.
|
|
546
|
+
|
|
547
|
+
Nothing is normalised. `not (not (x))` stays two negations, `(a or b) and c` keeps its shape, and a
|
|
548
|
+
validate rule is shown as what makes it valid ("Valid when …") — the projection never injects a
|
|
549
|
+
negation, so no sentence becomes a silent `not(...)`.
|
|
550
|
+
|
|
551
|
+
Everything else — arithmetic, aggregates, comprehensions, a coalesce, a conditional, a
|
|
552
|
+
`defaultCompute` writer, or source that does not parse yet — opens as source. `emitVisual` turns a
|
|
553
|
+
visual form back into the tree it was read from, and `visualSource` spells that tree with the
|
|
554
|
+
compiler's printer: the builder holds no grammar and no second emitter, so switching a rule to
|
|
555
|
+
source hands the author canonical Expr v1 rather than another writer's text. `representVisual`
|
|
556
|
+
states the other direction — whether a form may be stored for this draft at this rule's scope, by
|
|
557
|
+
projecting its emission back and comparing the trees. A value a caller builds past the type — an
|
|
558
|
+
`undefined` member, a prototype, a negative zero — is refused as `non_canonical` rather than thrown:
|
|
559
|
+
the comparison is over canonical JSON, and the refusal is part of the public contract.
|
|
560
|
+
|
|
561
|
+
## Field impact
|
|
562
|
+
|
|
563
|
+
`referencesOf(document, fieldId)` answers "what happens if this field is deleted?" before the draft
|
|
564
|
+
compiles. It walks every rule's expression slots — the expression, its message `params`, a screen's
|
|
565
|
+
`referWhen` and reasons (only a screen's: the runtime folds no other kind's), a gate's activation
|
|
566
|
+
condition and items, and a layout node's `visibleWhen`, `params` and readout values — through the
|
|
567
|
+
same `parseExpr` and the runtime's `collectReadRefs` the compiled artifact's own dependency report
|
|
568
|
+
uses. `dependencyReads` is that half.
|
|
569
|
+
|
|
570
|
+
`references` is the other half: the members that name the field without holding an expression — a
|
|
571
|
+
rule's `fieldId`, `fieldIds`, `targetFieldId`, `overrideFieldId` and test-case values, redactions,
|
|
572
|
+
session writes and access rules; a layout node that places or lists it; a `signature_capture`
|
|
573
|
+
field's `covers`; an `optionSource` that keys on it; and a natural `rowKey.fieldId`. `messageKeys`
|
|
574
|
+
is the keys the declaration itself names; before deleting one, reconcile it with any other
|
|
575
|
+
declaration or layout node that shares it. A slot whose value does not parse — or is not text at
|
|
576
|
+
all, which a hand-edited file can hold — is named in `unparseable` instead of counting as no
|
|
577
|
+
reference: while that list is non-empty no field is proven unreferenced.
|
|
578
|
+
|
|
579
|
+
The rule-sourced half is exactly the compiled report's `ruleReads`: for a document that compiles,
|
|
580
|
+
`dependencyReads` entries whose `source` is `'rule'` equal `ruleReads` for that rule, same field set
|
|
581
|
+
and same row-scoped flags, because both walk the runtime's one `collectReadRefs`. The equality stops
|
|
582
|
+
there. `inspectDeps` maps every read to a bare `fieldId` and drops `rowScoped`, so it cannot state
|
|
583
|
+
row scope at all, and it has no layout reads: `dependencyReads` reports those additionally, and a
|
|
584
|
+
caller comparing the two must keep them out of the rule-sourced set.
|
|
585
|
+
|
|
586
|
+
One pass answers every field: the slot parses and read walks are held against the document's
|
|
587
|
+
identity, so asking about all 500 fields of a large draft parses each expression once rather than
|
|
588
|
+
once per field.
|
|
589
|
+
|
|
590
|
+
## Preview
|
|
591
|
+
|
|
592
|
+
`compilePreview(document, options?)` returns a handle over a live form, not a build. A draft with
|
|
593
|
+
missing translations cannot pass the strict compile a release runs, so the preview compiles a
|
|
594
|
+
multi-locale fallback copy in a closure scope that no member of the handle reaches: borrowed text
|
|
595
|
+
stays filed under its authored source locale (so ICU plural rules are judged against the language
|
|
596
|
+
the author wrote), unwritten slots hold an internal placeholder inside closure scope, and a draft
|
|
597
|
+
whose every entry already declares the requested locale takes the single-locale fast path with
|
|
598
|
+
`locales: [locale]`. The handle states:
|
|
599
|
+
|
|
600
|
+
- `ok` / `previewOnly`, so a caller can tell a preview from a compile result;
|
|
601
|
+
- `sourceHash`, a SHA-256 of the draft the preview was built from — deliberately not a report hash;
|
|
602
|
+
- `state`, a `PreviewFormState`: the runtime's derived form state with its report narrowed to
|
|
603
|
+
`PreviewReportFacts` (the report body without `behaviorHash`);
|
|
604
|
+
- `translationGaps`, the outstanding texts, from the compiler's own completeness walk;
|
|
605
|
+
- `evaluatePreview(input, env?)`, which evaluates another record against the same artifact and
|
|
606
|
+
answers the same `PreviewFormState`;
|
|
607
|
+
- `createPreviewEngine(config?)`, a live session whose every report-bearing member — `report()`,
|
|
608
|
+
`getFormState()`, `preview()` and `propose()` proposals, and an `explainField()` explanation — is narrowed to the
|
|
609
|
+
digest-free body. Its writes follow the access overlay the session's `input` supplies; with none,
|
|
610
|
+
the runtime's fail-closed `read_only` default applies and a write is refused, exactly as it is in
|
|
611
|
+
a host's own session.
|
|
612
|
+
|
|
613
|
+
The store supplies the only reusable artifact. A committed dispatch whose candidate reaches the
|
|
614
|
+
compile stage compiles it once, and the artifact is kept against the committed document together
|
|
615
|
+
with the source text the compile read;
|
|
616
|
+
the preview of that state reuses it when the draft serialises identically to the preview copy (as
|
|
617
|
+
on the single-locale fast path when every entry already declares the requested locale). So a
|
|
618
|
+
keystroke and the preview of its result cost one compile, not two, and the reuse
|
|
619
|
+
is still exact: a document mutated after the gate read it, a different locale, or a draft the strict
|
|
620
|
+
compile refused falls back to a compile. A caller cannot supply an artifact of its own: a stated
|
|
621
|
+
source hash and locale do not prove which document produced a schema, so an unproven artifact is
|
|
622
|
+
never evaluated as the draft's preview.
|
|
623
|
+
|
|
624
|
+
No member returns the compiled schema or the artifact, and the preview states neither digest: a
|
|
625
|
+
hashed report reads as a claim about what would ship, and a preview is not what ships. Locale
|
|
626
|
+
selection is the runtime's one selector, `resolveSchemaLocale`: an exact declared tag, then a
|
|
627
|
+
declared prefix, then the default — never a sibling region. A strict request for a tag the document
|
|
628
|
+
does not carry refuses with `MESSAGE_LOCALE` instead of showing another language's text.
|
|
629
|
+
|
|
630
|
+
## Environment
|
|
631
|
+
|
|
632
|
+
- Targets: browsers, Node `>=24` and any ECMAScript 2023 host. No Node built-in, DOM global, `Intl`,
|
|
633
|
+
clock or random source is referenced: `pnpm lint` enforces that with the same override the runtime
|
|
634
|
+
and the compiler use, and the packed tarball carries no such reference in its declarations or its
|
|
635
|
+
emitted code.
|
|
636
|
+
- Complexity: one compile per committed dispatch (the price of live diagnostics), and no second
|
|
637
|
+
compile for the preview of the state that dispatch produced when the draft serialises identically
|
|
638
|
+
to its preview copy (the single-locale fast path). Undo and redo are cursor moves over retained
|
|
639
|
+
states: O(1) each, with at most `HISTORY_LIMIT + 1` states retained.
|
|
640
|
+
- Memory: history holds structurally shared documents, so an edit retains only the declarations it
|
|
641
|
+
rebuilt along the path it touched. `HISTORY_LIMIT` is 200 undo steps.
|
|
642
|
+
|
|
643
|
+
## Links
|
|
644
|
+
|
|
645
|
+
- [`@azx-pbc/axiom-runtime`](https://github.com/AZX-PBC-OSS/axiom/blob/main/packages/runtime/README.md) — the artifact the preview evaluates.
|
|
646
|
+
- [`@azx-pbc/axiom-compiler`](https://github.com/AZX-PBC-OSS/axiom/blob/main/packages/compiler/README.md) — the strict compile and the predicates the
|
|
647
|
+
store refuses with.
|
|
648
|
+
- [`docs/adr/0003-axiom-builder-package.md`](https://github.com/AZX-PBC-OSS/axiom/blob/main/docs/adr/0003-axiom-builder-package.md) — why the
|
|
649
|
+
builder is a fourth leaf package and why the preview is opaque.
|