@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.
Files changed (231) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +648 -2
  3. package/dist/cards/selectors.d.ts +70 -0
  4. package/dist/cards/selectors.d.ts.map +1 -0
  5. package/dist/cards/selectors.js +194 -0
  6. package/dist/cards/selectors.js.map +1 -0
  7. package/dist/definition.d.ts +36 -0
  8. package/dist/definition.d.ts.map +1 -0
  9. package/dist/definition.js +48 -0
  10. package/dist/definition.js.map +1 -0
  11. package/dist/evidence/cases.d.ts +44 -0
  12. package/dist/evidence/cases.d.ts.map +1 -0
  13. package/dist/evidence/cases.js +578 -0
  14. package/dist/evidence/cases.js.map +1 -0
  15. package/dist/evidence/repairs.d.ts +99 -0
  16. package/dist/evidence/repairs.d.ts.map +1 -0
  17. package/dist/evidence/repairs.js +181 -0
  18. package/dist/evidence/repairs.js.map +1 -0
  19. package/dist/evidence/summary.d.ts +35 -0
  20. package/dist/evidence/summary.d.ts.map +1 -0
  21. package/dist/evidence/summary.js +38 -0
  22. package/dist/evidence/summary.js.map +1 -0
  23. package/dist/i18n/gaps.d.ts +3 -0
  24. package/dist/i18n/gaps.d.ts.map +1 -0
  25. package/dist/i18n/gaps.js +2 -0
  26. package/dist/i18n/gaps.js.map +1 -0
  27. package/dist/i18n/message-slots.d.ts +19 -0
  28. package/dist/i18n/message-slots.d.ts.map +1 -0
  29. package/dist/i18n/message-slots.js +101 -0
  30. package/dist/i18n/message-slots.js.map +1 -0
  31. package/dist/i18n/text-locale.d.ts +13 -0
  32. package/dist/i18n/text-locale.d.ts.map +1 -0
  33. package/dist/i18n/text-locale.js +14 -0
  34. package/dist/i18n/text-locale.js.map +1 -0
  35. package/dist/i18n/translations.d.ts +56 -0
  36. package/dist/i18n/translations.d.ts.map +1 -0
  37. package/dist/i18n/translations.js +103 -0
  38. package/dist/i18n/translations.js.map +1 -0
  39. package/dist/impact/references.d.ts +143 -0
  40. package/dist/impact/references.d.ts.map +1 -0
  41. package/dist/impact/references.js +429 -0
  42. package/dist/impact/references.js.map +1 -0
  43. package/dist/index.d.ts +86 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +58 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/preview/compile-preview.d.ts +67 -0
  48. package/dist/preview/compile-preview.d.ts.map +1 -0
  49. package/dist/preview/compile-preview.js +286 -0
  50. package/dist/preview/compile-preview.js.map +1 -0
  51. package/dist/preview/handle.d.ts +119 -0
  52. package/dist/preview/handle.d.ts.map +1 -0
  53. package/dist/preview/handle.js +2 -0
  54. package/dist/preview/handle.js.map +1 -0
  55. package/dist/preview/held.d.ts +39 -0
  56. package/dist/preview/held.d.ts.map +1 -0
  57. package/dist/preview/held.js +15 -0
  58. package/dist/preview/held.js.map +1 -0
  59. package/dist/preview/measurement.d.ts +5 -0
  60. package/dist/preview/measurement.d.ts.map +1 -0
  61. package/dist/preview/measurement.js +18 -0
  62. package/dist/preview/measurement.js.map +1 -0
  63. package/dist/publish/build.d.ts +33 -0
  64. package/dist/publish/build.d.ts.map +1 -0
  65. package/dist/publish/build.js +15 -0
  66. package/dist/publish/build.js.map +1 -0
  67. package/dist/publish/diff.d.ts +208 -0
  68. package/dist/publish/diff.d.ts.map +1 -0
  69. package/dist/publish/diff.js +227 -0
  70. package/dist/publish/diff.js.map +1 -0
  71. package/dist/publish/review.d.ts +41 -0
  72. package/dist/publish/review.d.ts.map +1 -0
  73. package/dist/publish/review.js +22 -0
  74. package/dist/publish/review.js.map +1 -0
  75. package/dist/schema/dataset-input.d.ts +30 -0
  76. package/dist/schema/dataset-input.d.ts.map +1 -0
  77. package/dist/schema/dataset-input.js +58 -0
  78. package/dist/schema/dataset-input.js.map +1 -0
  79. package/dist/schema/dataset.d.ts +166 -0
  80. package/dist/schema/dataset.d.ts.map +1 -0
  81. package/dist/schema/dataset.js +281 -0
  82. package/dist/schema/dataset.js.map +1 -0
  83. package/dist/schema/declarations.d.ts +15 -0
  84. package/dist/schema/declarations.d.ts.map +1 -0
  85. package/dist/schema/declarations.js +47 -0
  86. package/dist/schema/declarations.js.map +1 -0
  87. package/dist/schema/document.d.ts +504 -0
  88. package/dist/schema/document.d.ts.map +1 -0
  89. package/dist/schema/document.js +337 -0
  90. package/dist/schema/document.js.map +1 -0
  91. package/dist/schema/error.d.ts +15 -0
  92. package/dist/schema/error.d.ts.map +1 -0
  93. package/dist/schema/error.js +18 -0
  94. package/dist/schema/error.js.map +1 -0
  95. package/dist/schema/field-id.d.ts +8 -0
  96. package/dist/schema/field-id.d.ts.map +1 -0
  97. package/dist/schema/field-id.js +47 -0
  98. package/dist/schema/field-id.js.map +1 -0
  99. package/dist/schema/layout.d.ts +118 -0
  100. package/dist/schema/layout.d.ts.map +1 -0
  101. package/dist/schema/layout.js +101 -0
  102. package/dist/schema/layout.js.map +1 -0
  103. package/dist/schema/palette.d.ts +103 -0
  104. package/dist/schema/palette.d.ts.map +1 -0
  105. package/dist/schema/palette.js +140 -0
  106. package/dist/schema/palette.js.map +1 -0
  107. package/dist/schema/read.d.ts +49 -0
  108. package/dist/schema/read.d.ts.map +1 -0
  109. package/dist/schema/read.js +942 -0
  110. package/dist/schema/read.js.map +1 -0
  111. package/dist/store/apply-dataset.d.ts +14 -0
  112. package/dist/store/apply-dataset.d.ts.map +1 -0
  113. package/dist/store/apply-dataset.js +513 -0
  114. package/dist/store/apply-dataset.js.map +1 -0
  115. package/dist/store/apply.d.ts +37 -0
  116. package/dist/store/apply.d.ts.map +1 -0
  117. package/dist/store/apply.js +2269 -0
  118. package/dist/store/apply.js.map +1 -0
  119. package/dist/store/candidate.d.ts +37 -0
  120. package/dist/store/candidate.d.ts.map +1 -0
  121. package/dist/store/candidate.js +178 -0
  122. package/dist/store/candidate.js.map +1 -0
  123. package/dist/store/commands/coverage.d.ts +58 -0
  124. package/dist/store/commands/coverage.d.ts.map +1 -0
  125. package/dist/store/commands/coverage.js +354 -0
  126. package/dist/store/commands/coverage.js.map +1 -0
  127. package/dist/store/commands/dataset.d.ts +26 -0
  128. package/dist/store/commands/dataset.d.ts.map +1 -0
  129. package/dist/store/commands/dataset.js +368 -0
  130. package/dist/store/commands/dataset.js.map +1 -0
  131. package/dist/store/commands/document.d.ts +21 -0
  132. package/dist/store/commands/document.d.ts.map +1 -0
  133. package/dist/store/commands/document.js +160 -0
  134. package/dist/store/commands/document.js.map +1 -0
  135. package/dist/store/commands/field.d.ts +32 -0
  136. package/dist/store/commands/field.d.ts.map +1 -0
  137. package/dist/store/commands/field.js +572 -0
  138. package/dist/store/commands/field.js.map +1 -0
  139. package/dist/store/commands/layout.d.ts +16 -0
  140. package/dist/store/commands/layout.d.ts.map +1 -0
  141. package/dist/store/commands/layout.js +70 -0
  142. package/dist/store/commands/layout.js.map +1 -0
  143. package/dist/store/commands/parse.d.ts +19 -0
  144. package/dist/store/commands/parse.d.ts.map +1 -0
  145. package/dist/store/commands/parse.js +328 -0
  146. package/dist/store/commands/parse.js.map +1 -0
  147. package/dist/store/commands/readers.d.ts +198 -0
  148. package/dist/store/commands/readers.d.ts.map +1 -0
  149. package/dist/store/commands/readers.js +711 -0
  150. package/dist/store/commands/readers.js.map +1 -0
  151. package/dist/store/commands/rule.d.ts +24 -0
  152. package/dist/store/commands/rule.d.ts.map +1 -0
  153. package/dist/store/commands/rule.js +379 -0
  154. package/dist/store/commands/rule.js.map +1 -0
  155. package/dist/store/commands/shapes.d.ts +900 -0
  156. package/dist/store/commands/shapes.d.ts.map +1 -0
  157. package/dist/store/commands/shapes.js +166 -0
  158. package/dist/store/commands/shapes.js.map +1 -0
  159. package/dist/store/commands/suggestions.d.ts +37 -0
  160. package/dist/store/commands/suggestions.d.ts.map +1 -0
  161. package/dist/store/commands/suggestions.js +177 -0
  162. package/dist/store/commands/suggestions.js.map +1 -0
  163. package/dist/store/commands.d.ts +16 -0
  164. package/dist/store/commands.d.ts.map +1 -0
  165. package/dist/store/commands.js +13 -0
  166. package/dist/store/commands.js.map +1 -0
  167. package/dist/store/dataset-candidate.d.ts +33 -0
  168. package/dist/store/dataset-candidate.d.ts.map +1 -0
  169. package/dist/store/dataset-candidate.js +31 -0
  170. package/dist/store/dataset-candidate.js.map +1 -0
  171. package/dist/store/dataset-pin.d.ts +93 -0
  172. package/dist/store/dataset-pin.d.ts.map +1 -0
  173. package/dist/store/dataset-pin.js +86 -0
  174. package/dist/store/dataset-pin.js.map +1 -0
  175. package/dist/store/dataset-store.d.ts +96 -0
  176. package/dist/store/dataset-store.d.ts.map +1 -0
  177. package/dist/store/dataset-store.js +112 -0
  178. package/dist/store/dataset-store.js.map +1 -0
  179. package/dist/store/history.d.ts +149 -0
  180. package/dist/store/history.d.ts.map +1 -0
  181. package/dist/store/history.js +173 -0
  182. package/dist/store/history.js.map +1 -0
  183. package/dist/store/measurement.d.ts +5 -0
  184. package/dist/store/measurement.d.ts.map +1 -0
  185. package/dist/store/measurement.js +20 -0
  186. package/dist/store/measurement.js.map +1 -0
  187. package/dist/store/notify.d.ts +11 -0
  188. package/dist/store/notify.d.ts.map +1 -0
  189. package/dist/store/notify.js +26 -0
  190. package/dist/store/notify.js.map +1 -0
  191. package/dist/store/published.d.ts +50 -0
  192. package/dist/store/published.d.ts.map +1 -0
  193. package/dist/store/published.js +27 -0
  194. package/dist/store/published.js.map +1 -0
  195. package/dist/store/refusals.d.ts +175 -0
  196. package/dist/store/refusals.d.ts.map +1 -0
  197. package/dist/store/refusals.js +160 -0
  198. package/dist/store/refusals.js.map +1 -0
  199. package/dist/store/steps.d.ts +14 -0
  200. package/dist/store/steps.d.ts.map +1 -0
  201. package/dist/store/steps.js +124 -0
  202. package/dist/store/steps.js.map +1 -0
  203. package/dist/store/store.d.ts +142 -0
  204. package/dist/store/store.d.ts.map +1 -0
  205. package/dist/store/store.js +136 -0
  206. package/dist/store/store.js.map +1 -0
  207. package/dist/store/unchanged.d.ts +12 -0
  208. package/dist/store/unchanged.d.ts.map +1 -0
  209. package/dist/store/unchanged.js +35 -0
  210. package/dist/store/unchanged.js.map +1 -0
  211. package/dist/visual/emit.d.ts +21 -0
  212. package/dist/visual/emit.d.ts.map +1 -0
  213. package/dist/visual/emit.js +133 -0
  214. package/dist/visual/emit.js.map +1 -0
  215. package/dist/visual/parse.d.ts +32 -0
  216. package/dist/visual/parse.d.ts.map +1 -0
  217. package/dist/visual/parse.js +330 -0
  218. package/dist/visual/parse.js.map +1 -0
  219. package/dist/visual/project.d.ts +40 -0
  220. package/dist/visual/project.d.ts.map +1 -0
  221. package/dist/visual/project.js +349 -0
  222. package/dist/visual/project.js.map +1 -0
  223. package/dist/visual/represent.d.ts +50 -0
  224. package/dist/visual/represent.d.ts.map +1 -0
  225. package/dist/visual/represent.js +66 -0
  226. package/dist/visual/represent.js.map +1 -0
  227. package/dist/visual/vocabulary.d.ts +121 -0
  228. package/dist/visual/vocabulary.d.ts.map +1 -0
  229. package/dist/visual/vocabulary.js +32 -0
  230. package/dist/visual/vocabulary.js.map +1 -0
  231. package/package.json +52 -3
@@ -0,0 +1,142 @@
1
+ import type { AuthoringDocument } from '../schema/document.js';
2
+ import type { AuthoringCommand } from './commands.js';
3
+ import type { ClampedField } from './apply.js';
4
+ import type { AuthoringState, HistoryRefusal, HistoryStep } from './history.js';
5
+ import type { PublishedBaseline } from './published.js';
6
+ import type { AuthoringRefusal } from './refusals.js';
7
+ /**
8
+ * The headless authoring store.
9
+ *
10
+ * It is the whole editing surface of a builder UI, and it has no opinion about the UI: no React,
11
+ * no DOM, no clock, no randomness. `getState` and `subscribe` are the
12
+ * `useSyncExternalStore`-compatible pair, so a React binding subscribes without the store
13
+ * depending on React; a Vue, Svelte or plain-DOM binding uses the same two methods. The snapshot
14
+ * states the history position beside the document, so one subscription renders Undo and Redo.
15
+ *
16
+ * Editing is a command dispatch. A dispatch either commits exactly one undo step (with the
17
+ * candidate checked against the compiler's own predicates and the diagnostics it still reports
18
+ * attached to the new state) or refuses and leaves the document and the history untouched, by
19
+ * identity. A command that restates the document is not a third outcome: it succeeds without a
20
+ * step, returning the snapshot the host already holds. A change the store accepted is one an
21
+ * author can undo, and a change it declined is one nothing happened to.
22
+ */
23
+ /** What a caller supplies once, when the store opens. */
24
+ export interface AuthoringStoreOptions {
25
+ /**
26
+ * The version the host published, so its declarations are immutable here. Absent means the
27
+ * document has never been published and every declaration is still the author's to change.
28
+ *
29
+ * The draft must state that edition or a later one: an older draft is a host handing the store
30
+ * the wrong document, and `setSchemaVersion` is the command that advances the edition.
31
+ */
32
+ readonly published?: PublishedBaseline;
33
+ }
34
+ /** What a committed dispatch did beyond the command's own intent. */
35
+ export interface DispatchEffects {
36
+ /** Whether the step merged into the one before it (consecutive text edits of one message). */
37
+ readonly coalesced: boolean;
38
+ /** Every field whose `colSpan` a group's narrower column count had to reduce. */
39
+ readonly clamped: readonly ClampedField[];
40
+ /**
41
+ * Whether this commit was the one that dropped the oldest retained state.
42
+ *
43
+ * The undo chain is bounded by `HISTORY_LIMIT` steps, so a long enough run of edits eventually
44
+ * forgets where the draft started. A host that says "undo to the beginning" reads this to know
45
+ * when that beginning is no longer the document it opened.
46
+ */
47
+ readonly truncated: boolean;
48
+ }
49
+ /** The outcome of one dispatch. */
50
+ export type DispatchOutcome = {
51
+ readonly ok: true;
52
+ readonly state: AuthoringState;
53
+ readonly effects: DispatchEffects;
54
+ } | {
55
+ readonly ok: false;
56
+ readonly refusal: AuthoringRefusal;
57
+ };
58
+ /**
59
+ * What the host attributes one dispatch to.
60
+ *
61
+ * The store reads no clock and knows no user: `actor` and `at` are the caller's facts, recorded
62
+ * verbatim on the step the history retains. A host that omits them gets a trail of changes that
63
+ * says what moved but not who moved it.
64
+ */
65
+ export interface DispatchContext {
66
+ /** The identity the host attributes the change to. */
67
+ readonly actor?: string;
68
+ /** The host's clock reading for the change, in the host's own spelling. */
69
+ readonly at?: string;
70
+ }
71
+ /** Why an undo or redo moved nothing. */
72
+ export type { HistoryRefusal };
73
+ /** The outcome of an undo or redo. */
74
+ export type HistoryOutcome = {
75
+ readonly ok: true;
76
+ readonly state: AuthoringState;
77
+ } | {
78
+ readonly ok: false;
79
+ readonly reason: HistoryRefusal;
80
+ };
81
+ /** The store's whole surface. */
82
+ export interface AuthoringStore {
83
+ /**
84
+ * The current state: the document, the diagnostics a compile of it reports, and the history
85
+ * position.
86
+ *
87
+ * The object is rebuilt only when the document or the cursor moves and is returned by identity
88
+ * otherwise, so `useSyncExternalStore(store.subscribe, store.getState)` renders the draft and
89
+ * whether undo and redo are available from one snapshot. A host that is not rendering can read
90
+ * the same two flags from `canUndo()` and `canRedo()`.
91
+ */
92
+ getState(): AuthoringState;
93
+ /**
94
+ * Applies one command, or refuses it without touching the document or the history.
95
+ *
96
+ * The command is parsed here too, so a host that holds a form state or a stored draft can call
97
+ * `parseCommand` first and decide what to show before it dispatches, or dispatch the narrowed
98
+ * command it received. `context` is the host's attribution for the retained step; the store
99
+ * supplies neither a clock nor an identity of its own.
100
+ */
101
+ dispatch(command: AuthoringCommand, context?: DispatchContext): DispatchOutcome;
102
+ /**
103
+ * The commands that produced the state at the cursor, oldest first, with the actor and time the
104
+ * host supplied. A coalesced run of keystrokes is one entry.
105
+ */
106
+ history(): readonly HistoryStep[];
107
+ /** Registers a listener; the returned function releases it and may be called twice. */
108
+ subscribe(listener: () => void): () => void;
109
+ /** Moves the cursor to the previous retained state. */
110
+ undo(): HistoryOutcome;
111
+ /** Moves the cursor to the next retained state. */
112
+ redo(): HistoryOutcome;
113
+ /** Whether a previous state is retained; the same flag `getState().canUndo` states. */
114
+ canUndo(): boolean;
115
+ /** Whether a state the cursor moved back over is still ahead of it; `getState().canRedo`. */
116
+ canRedo(): boolean;
117
+ /**
118
+ * Ends the coalescing run at the cursor, so the next edit of the same message is a new step.
119
+ *
120
+ * The store coalesces consecutive `setMessageText` dispatches for one `(messageKey, locale)`,
121
+ * which is what makes typing one field one undo step. A host that has left the field — a blur,
122
+ * a selection change — knows the run ended even though no other command was dispatched, and
123
+ * calls this so a second visit does not merge into the first. The document and the cursor do
124
+ * not move.
125
+ */
126
+ seal(): void;
127
+ }
128
+ /**
129
+ * Opens a store over a document.
130
+ *
131
+ * The starting document is the history's first node, and its diagnostics are what a compile says
132
+ * about it. A caller that starts from `createEmptySchema` starts from an empty field list, which
133
+ * no compile admits: that is reported as a diagnostic, and the first `addField` (or
134
+ * `addRecordArray`) is the dispatch that makes the document compilable.
135
+ *
136
+ * A baseline is the host's record of what it published, so it is read rather than carried: a
137
+ * draft that states an *older* edition than the published one is a host that handed the store the
138
+ * wrong document, and no command can repair it (an edition only moves forward). That is a
139
+ * programmer error at construction, refused the way `createEmptySchema` refuses its arguments.
140
+ */
141
+ export declare function createAuthoringStore(document: AuthoringDocument, options?: AuthoringStoreOptions): AuthoringStore;
142
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/store/store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG/C,OAAO,KAAK,EAAE,cAAc,EAAoB,cAAc,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAWlG,OAAO,KAAK,EAAE,iBAAiB,EAAyB,MAAM,gBAAgB,CAAC;AAG/E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGtD;;;;;;;;;;;;;;;GAeG;AAEH,yDAAyD;AACzD,MAAM,WAAW,qBAAqB;IACpC;;;;;;OAMG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,iBAAiB,CAAC;CACxC;AACD,qEAAqE;AACrE,MAAM,WAAW,eAAe;IAC9B,8FAA8F;IAC9F,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,iFAAiF;IAC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D,IAAI,IAAI,cAAc,CAAC;IACvB,mDAAmD;IACnD,IAAI,IAAI,cAAc,CAAC;IACvB,uFAAuF;IACvF,OAAO,IAAI,OAAO,CAAC;IACnB,6FAA6F;IAC7F,OAAO,IAAI,OAAO,CAAC;IACnB;;;;;;;;OAQG;IACH,IAAI,IAAI,IAAI,CAAC;CACd;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,iBAAiB,EAC3B,OAAO,GAAE,qBAA0B,GAClC,cAAc,CAsHhB"}
@@ -0,0 +1,136 @@
1
+ import { AuthoringError } from '../schema/document.js';
2
+ import { coalesceKeyOf, parseCommand } from './commands.js';
3
+ import { applyCommand } from './apply.js';
4
+ import { checkCandidate, initialDiagnostics } from './candidate.js';
5
+ import { holdPreviewArtifact } from '../preview/held.js';
6
+ import { commitHistory, createHistory, historyState, historySteps, redoHistory, sealHistory, shareDiagnostics, undoHistory, } from './history.js';
7
+ import { publishedDeclarations } from './published.js';
8
+ import { notifyAll } from './notify.js';
9
+ import { describeCommand } from './steps.js';
10
+ /**
11
+ * Opens a store over a document.
12
+ *
13
+ * The starting document is the history's first node, and its diagnostics are what a compile says
14
+ * about it. A caller that starts from `createEmptySchema` starts from an empty field list, which
15
+ * no compile admits: that is reported as a diagnostic, and the first `addField` (or
16
+ * `addRecordArray`) is the dispatch that makes the document compilable.
17
+ *
18
+ * A baseline is the host's record of what it published, so it is read rather than carried: a
19
+ * draft that states an *older* edition than the published one is a host that handed the store the
20
+ * wrong document, and no command can repair it (an edition only moves forward). That is a
21
+ * programmer error at construction, refused the way `createEmptySchema` refuses its arguments.
22
+ */
23
+ export function createAuthoringStore(document, options = {}) {
24
+ const published = options.published;
25
+ if (published !== undefined && published.schemaVersion > document.schemaVersion) {
26
+ throw new AuthoringError(`the published baseline states \`schemaVersion\` ${String(published.schemaVersion)} and the draft states ${String(document.schemaVersion)}; a draft is opened at or after the edition it continues, and \`setSchemaVersion\` only moves forward.`);
27
+ }
28
+ let history = createHistory({
29
+ document,
30
+ diagnostics: initialDiagnostics(document),
31
+ });
32
+ // The snapshot the store answers with. It is rebuilt only when the chain or the cursor moves,
33
+ // so `getState()` returns the same object between changes and `useSyncExternalStore` compares it
34
+ // by identity — including the history position a host renders from.
35
+ let state = historyState(history);
36
+ const listeners = new Set();
37
+ const notify = () => {
38
+ notifyAll(listeners);
39
+ };
40
+ const publishedOf = (candidate) => publishedDeclarations(candidate, published);
41
+ return {
42
+ getState() {
43
+ return state;
44
+ },
45
+ dispatch(command, context = {}) {
46
+ const parsed = parseCommand(command);
47
+ if (!parsed.ok)
48
+ return { ok: false, refusal: parsed.refusal };
49
+ const previous = state;
50
+ const current = previous.document;
51
+ const applied = applyCommand(current, parsed.command, publishedOf(current));
52
+ if (!applied.ok)
53
+ return { ok: false, refusal: applied.refusal };
54
+ // A command that returns the current snapshot states no edit: retain the cursor, history and
55
+ // subscribers rather than adding an undo step that cannot change the document.
56
+ if (applied.applied.document === current) {
57
+ return {
58
+ ok: true,
59
+ state: previous,
60
+ effects: {
61
+ coalesced: false,
62
+ clamped: applied.applied.clamped,
63
+ truncated: false,
64
+ },
65
+ };
66
+ }
67
+ const checked = checkCandidate(applied.applied.document);
68
+ if (!checked.ok)
69
+ return { ok: false, refusal: checked.refusal };
70
+ const committed = commitHistory(history, {
71
+ document: applied.applied.document,
72
+ // The reasons this step did not change are the objects the previous step already holds,
73
+ // so a retained chain costs the document's delta rather than a compile's whole verdict
74
+ // per step.
75
+ diagnostics: shareDiagnostics(previous.diagnostics, checked.diagnostics),
76
+ }, coalesceKeyOf(parsed.command), {
77
+ kind: parsed.command.kind,
78
+ summary: describeCommand(parsed.command),
79
+ ...(context.actor === undefined ? {} : { actor: context.actor }),
80
+ ...(context.at === undefined ? {} : { at: context.at }),
81
+ });
82
+ if (checked.artifact !== undefined) {
83
+ holdPreviewArtifact(applied.applied.document, checked.artifact);
84
+ }
85
+ history = committed.history;
86
+ state = historyState(history);
87
+ notify();
88
+ return {
89
+ ok: true,
90
+ state,
91
+ effects: {
92
+ coalesced: committed.coalesced,
93
+ clamped: applied.applied.clamped,
94
+ truncated: committed.truncated,
95
+ },
96
+ };
97
+ },
98
+ subscribe(listener) {
99
+ listeners.add(listener);
100
+ return () => {
101
+ listeners.delete(listener);
102
+ };
103
+ },
104
+ history() {
105
+ return historySteps(history);
106
+ },
107
+ undo() {
108
+ const moved = undoHistory(history);
109
+ if (moved === undefined)
110
+ return { ok: false, reason: 'nothing_to_undo' };
111
+ history = moved;
112
+ state = historyState(history);
113
+ notify();
114
+ return { ok: true, state };
115
+ },
116
+ redo() {
117
+ const moved = redoHistory(history);
118
+ if (moved === undefined)
119
+ return { ok: false, reason: 'nothing_to_redo' };
120
+ history = moved;
121
+ state = historyState(history);
122
+ notify();
123
+ return { ok: true, state };
124
+ },
125
+ canUndo() {
126
+ return state.canUndo;
127
+ },
128
+ canRedo() {
129
+ return state.canRedo;
130
+ },
131
+ seal() {
132
+ history = sealHistory(history);
133
+ },
134
+ };
135
+ }
136
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/store/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAGvD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EACL,aAAa,EACb,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,WAAW,GACZ,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,SAAS,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B,MAAM,EAAE,CAAC;YACT,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;QAC7B,CAAC;QACD,IAAI;YACF,MAAM,KAAK,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;YACnC,IAAI,KAAK,KAAK,SAAS;gBAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,CAAC;YACzE,OAAO,GAAG,KAAK,CAAC;YAChB,KAAK,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;YAC9B,MAAM,EAAE,CAAC;YACT,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;QAC7B,CAAC;QACD,OAAO;YACL,OAAO,KAAK,CAAC,OAAO,CAAC;QACvB,CAAC;QACD,OAAO;YACL,OAAO,KAAK,CAAC,OAAO,CAAC;QACvB,CAAC;QACD,IAAI;YACF,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;QACjC,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { AuthoringError } from '../schema/document.js';\nimport type { AuthoringDocument } from '../schema/document.js';\nimport type { AuthoringCommand } from './commands.js';\nimport { coalesceKeyOf, parseCommand } from './commands.js';\nimport { applyCommand } from './apply.js';\nimport type { ClampedField } from './apply.js';\nimport { checkCandidate, initialDiagnostics } from './candidate.js';\nimport { holdPreviewArtifact } from '../preview/held.js';\nimport type { AuthoringState, AuthoringHistory, HistoryRefusal, HistoryStep } from './history.js';\nimport {\n commitHistory,\n createHistory,\n historyState,\n historySteps,\n redoHistory,\n sealHistory,\n shareDiagnostics,\n undoHistory,\n} from './history.js';\nimport type { PublishedBaseline, PublishedDeclarations } from './published.js';\nimport { publishedDeclarations } from './published.js';\nimport { notifyAll } from './notify.js';\nimport type { AuthoringRefusal } from './refusals.js';\nimport { describeCommand } from './steps.js';\n\n/**\n * The headless authoring store.\n *\n * It is the whole editing surface of a builder UI, and it has no opinion about the UI: no React,\n * no DOM, no clock, no randomness. `getState` and `subscribe` are the\n * `useSyncExternalStore`-compatible pair, so a React binding subscribes without the store\n * depending on React; a Vue, Svelte or plain-DOM binding uses the same two methods. The snapshot\n * states the history position beside the document, so one subscription renders Undo and Redo.\n *\n * Editing is a command dispatch. A dispatch either commits exactly one undo step (with the\n * candidate checked against the compiler's own predicates and the diagnostics it still reports\n * attached to the new state) or refuses and leaves the document and the history untouched, by\n * identity. A command that restates the document is not a third outcome: it succeeds without a\n * step, returning the snapshot the host already holds. A change the store accepted is one an\n * author can undo, and a change it declined is one nothing happened to.\n */\n\n/** What a caller supplies once, when the store opens. */\nexport interface AuthoringStoreOptions {\n /**\n * The version the host published, so its declarations are immutable here. Absent means the\n * document has never been published and every declaration is still the author's to change.\n *\n * The draft must state that edition or a later one: an older draft is a host handing the store\n * the wrong document, and `setSchemaVersion` is the command that advances the edition.\n */\n readonly published?: PublishedBaseline;\n}\n/** What a committed dispatch did beyond the command's own intent. */\nexport interface DispatchEffects {\n /** Whether the step merged into the one before it (consecutive text edits of one message). */\n readonly coalesced: boolean;\n /** Every field whose `colSpan` a group's narrower column count had to reduce. */\n readonly clamped: readonly ClampedField[];\n /**\n * Whether this commit was the one that dropped the oldest retained state.\n *\n * The undo chain is bounded by `HISTORY_LIMIT` steps, so a long enough run of edits eventually\n * forgets where the draft started. A host that says \"undo to the beginning\" reads this to know\n * when that beginning is no longer the document it opened.\n */\n readonly truncated: boolean;\n}\n\n/** The outcome of one dispatch. */\nexport type DispatchOutcome =\n | {\n readonly ok: true;\n readonly state: AuthoringState;\n readonly effects: DispatchEffects;\n }\n | { readonly ok: false; readonly refusal: AuthoringRefusal };\n\n/**\n * What the host attributes one dispatch to.\n *\n * The store reads no clock and knows no user: `actor` and `at` are the caller's facts, recorded\n * verbatim on the step the history retains. A host that omits them gets a trail of changes that\n * says what moved but not who moved it.\n */\nexport interface DispatchContext {\n /** The identity the host attributes the change to. */\n readonly actor?: string;\n /** The host's clock reading for the change, in the host's own spelling. */\n readonly at?: string;\n}\n\n/** Why an undo or redo moved nothing. */\nexport type { HistoryRefusal };\n\n/** The outcome of an undo or redo. */\nexport type HistoryOutcome =\n | { readonly ok: true; readonly state: AuthoringState }\n | { readonly ok: false; readonly reason: HistoryRefusal };\n\n/** The store's whole surface. */\nexport interface AuthoringStore {\n /**\n * The current state: the document, the diagnostics a compile of it reports, and the history\n * position.\n *\n * The object is rebuilt only when the document or the cursor moves and is returned by identity\n * otherwise, so `useSyncExternalStore(store.subscribe, store.getState)` renders the draft and\n * whether undo and redo are available from one snapshot. A host that is not rendering can read\n * the same two flags from `canUndo()` and `canRedo()`.\n */\n getState(): AuthoringState;\n /**\n * Applies one command, or refuses it without touching the document or the history.\n *\n * The command is parsed here too, so a host that holds a form state or a stored draft can call\n * `parseCommand` first and decide what to show before it dispatches, or dispatch the narrowed\n * command it received. `context` is the host's attribution for the retained step; the store\n * supplies neither a clock nor an identity of its own.\n */\n dispatch(command: AuthoringCommand, context?: DispatchContext): DispatchOutcome;\n /**\n * The commands that produced the state at the cursor, oldest first, with the actor and time the\n * host supplied. A coalesced run of keystrokes is one entry.\n */\n history(): readonly HistoryStep[];\n /** Registers a listener; the returned function releases it and may be called twice. */\n subscribe(listener: () => void): () => void;\n /** Moves the cursor to the previous retained state. */\n undo(): HistoryOutcome;\n /** Moves the cursor to the next retained state. */\n redo(): HistoryOutcome;\n /** Whether a previous state is retained; the same flag `getState().canUndo` states. */\n canUndo(): boolean;\n /** Whether a state the cursor moved back over is still ahead of it; `getState().canRedo`. */\n canRedo(): boolean;\n /**\n * Ends the coalescing run at the cursor, so the next edit of the same message is a new step.\n *\n * The store coalesces consecutive `setMessageText` dispatches for one `(messageKey, locale)`,\n * which is what makes typing one field one undo step. A host that has left the field — a blur,\n * a selection change — knows the run ended even though no other command was dispatched, and\n * calls this so a second visit does not merge into the first. The document and the cursor do\n * not move.\n */\n seal(): void;\n}\n\n/**\n * Opens a store over a document.\n *\n * The starting document is the history's first node, and its diagnostics are what a compile says\n * about it. A caller that starts from `createEmptySchema` starts from an empty field list, which\n * no compile admits: that is reported as a diagnostic, and the first `addField` (or\n * `addRecordArray`) is the dispatch that makes the document compilable.\n *\n * A baseline is the host's record of what it published, so it is read rather than carried: a\n * draft that states an *older* edition than the published one is a host that handed the store the\n * wrong document, and no command can repair it (an edition only moves forward). That is a\n * programmer error at construction, refused the way `createEmptySchema` refuses its arguments.\n */\nexport function createAuthoringStore(\n document: AuthoringDocument,\n options: AuthoringStoreOptions = {},\n): AuthoringStore {\n const published = options.published;\n if (published !== undefined && published.schemaVersion > document.schemaVersion) {\n throw new AuthoringError(\n `the published baseline states \\`schemaVersion\\` ${String(published.schemaVersion)} and the draft states ${String(document.schemaVersion)}; a draft is opened at or after the edition it continues, and \\`setSchemaVersion\\` only moves forward.`,\n );\n }\n let history: AuthoringHistory = createHistory({\n document,\n diagnostics: initialDiagnostics(document),\n });\n // The snapshot the store answers with. It is rebuilt only when the chain or the cursor moves,\n // so `getState()` returns the same object between changes and `useSyncExternalStore` compares it\n // by identity — including the history position a host renders from.\n let state: AuthoringState = historyState(history);\n const listeners = new Set<() => void>();\n\n const notify = (): void => {\n notifyAll(listeners);\n };\n\n const publishedOf = (candidate: AuthoringDocument): PublishedDeclarations =>\n publishedDeclarations(candidate, published);\n\n return {\n getState(): AuthoringState {\n return state;\n },\n dispatch(command: AuthoringCommand, context: DispatchContext = {}): DispatchOutcome {\n const parsed = parseCommand(command);\n if (!parsed.ok) return { ok: false, refusal: parsed.refusal };\n const previous = state;\n const current = previous.document;\n const applied = applyCommand(current, parsed.command, publishedOf(current));\n if (!applied.ok) return { ok: false, refusal: applied.refusal };\n // A command that returns the current snapshot states no edit: retain the cursor, history and\n // subscribers rather than adding an undo step that cannot change the document.\n if (applied.applied.document === current) {\n return {\n ok: true,\n state: previous,\n effects: {\n coalesced: false,\n clamped: applied.applied.clamped,\n truncated: false,\n },\n };\n }\n const checked = checkCandidate(applied.applied.document);\n if (!checked.ok) return { ok: false, refusal: checked.refusal };\n const committed = commitHistory(\n history,\n {\n document: applied.applied.document,\n // The reasons this step did not change are the objects the previous step already holds,\n // so a retained chain costs the document's delta rather than a compile's whole verdict\n // per step.\n diagnostics: shareDiagnostics(previous.diagnostics, checked.diagnostics),\n },\n coalesceKeyOf(parsed.command),\n {\n kind: parsed.command.kind,\n summary: describeCommand(parsed.command),\n ...(context.actor === undefined ? {} : { actor: context.actor }),\n ...(context.at === undefined ? {} : { at: context.at }),\n },\n );\n if (checked.artifact !== undefined) {\n holdPreviewArtifact(applied.applied.document, checked.artifact);\n }\n history = committed.history;\n state = historyState(history);\n notify();\n return {\n ok: true,\n state,\n effects: {\n coalesced: committed.coalesced,\n clamped: applied.applied.clamped,\n truncated: committed.truncated,\n },\n };\n },\n subscribe(listener: () => void): () => void {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n history(): readonly HistoryStep[] {\n return historySteps(history);\n },\n undo(): HistoryOutcome {\n const moved = undoHistory(history);\n if (moved === undefined) return { ok: false, reason: 'nothing_to_undo' };\n history = moved;\n state = historyState(history);\n notify();\n return { ok: true, state };\n },\n redo(): HistoryOutcome {\n const moved = redoHistory(history);\n if (moved === undefined) return { ok: false, reason: 'nothing_to_redo' };\n history = moved;\n state = historyState(history);\n notify();\n return { ok: true, state };\n },\n canUndo(): boolean {\n return state.canUndo;\n },\n canRedo(): boolean {\n return state.canRedo;\n },\n seal(): void {\n history = sealHistory(history);\n },\n };\n}\n"]}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Whether two authored values state the same content.
3
+ *
4
+ * Every command builds a new tree and shares every untouched subtree with the document it was
5
+ * handed, so this walk stops at the first identical subtree: an edit that restates one member
6
+ * visits that member's path and no other, and the whole document is never serialised to decide a
7
+ * no-op. A document is plain data by construction (no `Date`, `Map` or class instance survives the
8
+ * restricted JSON profile), so reference identity for subtrees and structural equality for leaves
9
+ * is the whole comparison.
10
+ */
11
+ export declare function unchanged(left: unknown, right: unknown): boolean;
12
+ //# sourceMappingURL=unchanged.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unchanged.d.ts","sourceRoot":"","sources":["../../src/store/unchanged.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAgBhE"}
@@ -0,0 +1,35 @@
1
+ import { isRecord } from '@azx-pbc/axiom-runtime';
2
+ /**
3
+ * Whether two authored values state the same content.
4
+ *
5
+ * Every command builds a new tree and shares every untouched subtree with the document it was
6
+ * handed, so this walk stops at the first identical subtree: an edit that restates one member
7
+ * visits that member's path and no other, and the whole document is never serialised to decide a
8
+ * no-op. A document is plain data by construction (no `Date`, `Map` or class instance survives the
9
+ * restricted JSON profile), so reference identity for subtrees and structural equality for leaves
10
+ * is the whole comparison.
11
+ */
12
+ export function unchanged(left, right) {
13
+ if (left === right)
14
+ return true;
15
+ if (Array.isArray(left)) {
16
+ if (!Array.isArray(right) || left.length !== right.length)
17
+ return false;
18
+ for (let index = 0; index < left.length; index += 1) {
19
+ if (!unchanged(left[index], right[index]))
20
+ return false;
21
+ }
22
+ return true;
23
+ }
24
+ if (!isRecord(left) || !isRecord(right))
25
+ return false;
26
+ const members = Object.keys(left);
27
+ if (members.length !== Object.keys(right).length)
28
+ return false;
29
+ for (const member of members) {
30
+ if (!Object.hasOwn(right, member) || !unchanged(left[member], right[member]))
31
+ return false;
32
+ }
33
+ return true;
34
+ }
35
+ //# sourceMappingURL=unchanged.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unchanged.js","sourceRoot":"","sources":["../../src/store/unchanged.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAElD;;;;;;;;;GASG;AACH,MAAM,UAAU,SAAS,CAAC,IAAa,EAAE,KAAc;IACrD,IAAI,IAAI,KAAK,KAAK;QAAE,OAAO,IAAI,CAAC;IAChC,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM;YAAE,OAAO,KAAK,CAAC;QACxE,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;YACpD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;gBAAE,OAAO,KAAK,CAAC;QAC1D,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACtD,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClC,IAAI,OAAO,CAAC,MAAM,KAAK,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAC/D,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;IAC7F,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { isRecord } from '@azx-pbc/axiom-runtime';\n\n/**\n * Whether two authored values state the same content.\n *\n * Every command builds a new tree and shares every untouched subtree with the document it was\n * handed, so this walk stops at the first identical subtree: an edit that restates one member\n * visits that member's path and no other, and the whole document is never serialised to decide a\n * no-op. A document is plain data by construction (no `Date`, `Map` or class instance survives the\n * restricted JSON profile), so reference identity for subtrees and structural equality for leaves\n * is the whole comparison.\n */\nexport function unchanged(left: unknown, right: unknown): boolean {\n if (left === right) return true;\n if (Array.isArray(left)) {\n if (!Array.isArray(right) || left.length !== right.length) return false;\n for (let index = 0; index < left.length; index += 1) {\n if (!unchanged(left[index], right[index])) return false;\n }\n return true;\n }\n if (!isRecord(left) || !isRecord(right)) return false;\n const members = Object.keys(left);\n if (members.length !== Object.keys(right).length) return false;\n for (const member of members) {\n if (!Object.hasOwn(right, member) || !unchanged(left[member], right[member])) return false;\n }\n return true;\n}\n"]}
@@ -0,0 +1,21 @@
1
+ import type { PrintResult } from '@azx-pbc/axiom-compiler';
2
+ import type { ExprNode } from '@azx-pbc/axiom-runtime';
3
+ import type { VisualExpr } from './vocabulary.js';
4
+ /**
5
+ * The AST one visual expression stands for.
6
+ *
7
+ * Every arm states the node the projection recognises, so a round trip is a rebuild of the same
8
+ * tree rather than a translation between two shapes. The post-order walk is iterative: a
9
+ * hand-built tree must reach the printer's budget refusal rather than overflowing the host stack
10
+ * during the emission that precedes it.
11
+ */
12
+ export declare function emitVisual(visual: VisualExpr): ExprNode;
13
+ /**
14
+ * The canonical source of one visual expression, or the printer's refusal.
15
+ *
16
+ * The refusal is reachable from a visual a caller built by hand — a path segment that is an Expr
17
+ * v1 reserved word has no source form, and neither has a tree past the expression budget — which
18
+ * is why the store's visual door can refuse rather than write source nothing can read back.
19
+ */
20
+ export declare function visualSource(visual: VisualExpr): PrintResult;
21
+ //# sourceMappingURL=emit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../../src/visual/emit.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,iBAAiB,CAAC;AAwF9D;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,QAAQ,CA6BvD;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,WAAW,CAE5D"}
@@ -0,0 +1,133 @@
1
+ import { printExpr } from '@azx-pbc/axiom-compiler';
2
+ import { assertNever } from '@azx-pbc/axiom-runtime';
3
+ /**
4
+ * Visual to AST, exactly.
5
+ *
6
+ * The vocabulary is the tree's own shape, so emission builds the nodes the projection read and
7
+ * nothing else: operand order, nesting and list order are carried through, and no rewrite — no
8
+ * flattening, no De Morgan, no double-negation collapse, no "within N days" normalisation — has
9
+ * anywhere to happen. `emitVisual` is the inverse of `toVisual` for every tree the projection
10
+ * admits, which is what makes `emitVisual(toVisual(node))` deep-equal `node`.
11
+ *
12
+ * `visualSource` is the only place the builder turns a visual expression into text, and it does
13
+ * so by applying the compiler's printer to the emitted tree. The builder ships no second
14
+ * spelling of Expr v1: a caller that switches a rule to advanced mode receives the printer's
15
+ * canonical source, verified by re-parsing its own output.
16
+ */
17
+ /** A visual list is the AST list's own shape, so its items are the nodes it holds. */
18
+ function emitList(list) {
19
+ return { kind: 'list', items: list.items };
20
+ }
21
+ /** Takes one node's already-emitted children without disturbing any preceding siblings. */
22
+ function takeEmitted(emitted, count) {
23
+ return emitted.splice(emitted.length - count, count);
24
+ }
25
+ /** Rebuilds one node after its children have been emitted. */
26
+ function emitNode(visual, emitted) {
27
+ switch (visual.kind) {
28
+ case 'and':
29
+ return { kind: 'and', args: takeEmitted(emitted, visual.args.length) };
30
+ case 'or':
31
+ return { kind: 'or', args: takeEmitted(emitted, visual.args.length) };
32
+ case 'not': {
33
+ const [operand] = takeEmitted(emitted, 1);
34
+ if (operand === undefined)
35
+ throw new Error('visual negation emission lost its operand');
36
+ return { kind: 'not', args: [operand] };
37
+ }
38
+ case 'comparison':
39
+ return {
40
+ kind: 'compare',
41
+ op: visual.op,
42
+ args: [visual.left, visual.right],
43
+ };
44
+ case 'membership':
45
+ return {
46
+ kind: 'compare',
47
+ op: 'in',
48
+ args: [visual.left, emitList(visual.candidates)],
49
+ };
50
+ case 'text_match':
51
+ return {
52
+ kind: 'call',
53
+ op: visual.op,
54
+ args: [visual.subject, visual.text],
55
+ };
56
+ case 'check':
57
+ return { kind: 'call', op: visual.check, args: [visual.path] };
58
+ case 'format_check':
59
+ return { kind: 'call', op: visual.check, args: [visual.value] };
60
+ case 'unique_value':
61
+ return { kind: 'call', op: 'is_unique', args: [visual.array] };
62
+ case 'unique_member':
63
+ return { kind: 'call', op: 'is_unique', args: [visual.array, visual.member] };
64
+ case 'count':
65
+ return {
66
+ kind: 'compare',
67
+ op: visual.op,
68
+ args: [{ kind: 'call', op: 'len', args: [visual.path] }, visual.count],
69
+ };
70
+ case 'date_window':
71
+ return {
72
+ kind: 'compare',
73
+ op: visual.op,
74
+ args: [{ kind: 'call', op: visual.span, args: [visual.from, visual.to] }, visual.amount],
75
+ };
76
+ case 'capability':
77
+ return {
78
+ kind: 'call',
79
+ op: 'has_cap',
80
+ args: [{ kind: 'literal', domain: 'string', value: visual.cap }],
81
+ };
82
+ default:
83
+ return assertNever(visual);
84
+ }
85
+ }
86
+ /**
87
+ * The AST one visual expression stands for.
88
+ *
89
+ * Every arm states the node the projection recognises, so a round trip is a rebuild of the same
90
+ * tree rather than a translation between two shapes. The post-order walk is iterative: a
91
+ * hand-built tree must reach the printer's budget refusal rather than overflowing the host stack
92
+ * during the emission that precedes it.
93
+ */
94
+ export function emitVisual(visual) {
95
+ const stack = [
96
+ { visual, expanded: false },
97
+ ];
98
+ const emitted = [];
99
+ while (stack.length > 0) {
100
+ const frame = stack.pop();
101
+ if (frame === undefined)
102
+ break;
103
+ const current = frame.visual;
104
+ if (!frame.expanded &&
105
+ (current.kind === 'and' || current.kind === 'or' || current.kind === 'not')) {
106
+ stack.push({ visual: current, expanded: true });
107
+ const children = current.kind === 'not' ? [current.operand] : current.args;
108
+ for (let index = children.length - 1; index >= 0; index -= 1) {
109
+ const child = children[index];
110
+ if (child !== undefined)
111
+ stack.push({ visual: child, expanded: false });
112
+ }
113
+ continue;
114
+ }
115
+ emitted.push(emitNode(current, emitted));
116
+ }
117
+ const result = emitted.pop();
118
+ if (result === undefined || emitted.length !== 0) {
119
+ throw new Error('visual emission did not produce exactly one tree');
120
+ }
121
+ return result;
122
+ }
123
+ /**
124
+ * The canonical source of one visual expression, or the printer's refusal.
125
+ *
126
+ * The refusal is reachable from a visual a caller built by hand — a path segment that is an Expr
127
+ * v1 reserved word has no source form, and neither has a tree past the expression budget — which
128
+ * is why the store's visual door can refuse rather than write source nothing can read back.
129
+ */
130
+ export function visualSource(visual) {
131
+ return printExpr(emitVisual(visual));
132
+ }
133
+ //# sourceMappingURL=emit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emit.js","sourceRoot":"","sources":["../../src/visual/emit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAIrD;;;;;;;;;;;;;GAaG;AAEH,sFAAsF;AACtF,SAAS,QAAQ,CAAC,IAAgB;IAChC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;AAC7C,CAAC;AAED,2FAA2F;AAC3F,SAAS,WAAW,CAAC,OAAmB,EAAE,KAAa;IACrD,OAAO,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,KAAK,EAAE,KAAK,CAAC,CAAC;AACvD,CAAC;AAED,8DAA8D;AAC9D,SAAS,QAAQ,CAAC,MAAkB,EAAE,OAAmB;IACvD,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,KAAK;YACR,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QACzE,KAAK,IAAI;YACP,OA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AAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACjD,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACtE,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,MAAkB;IAC7C,OAAO,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;AACvC,CAAC","sourcesContent":["import { printExpr } from '@azx-pbc/axiom-compiler';\nimport type { PrintResult } from '@azx-pbc/axiom-compiler';\nimport { assertNever } from '@azx-pbc/axiom-runtime';\nimport type { ExprNode } from '@azx-pbc/axiom-runtime';\nimport type { VisualExpr, VisualList } from './vocabulary.js';\n\n/**\n * Visual to AST, exactly.\n *\n * The vocabulary is the tree's own shape, so emission builds the nodes the projection read and\n * nothing else: operand order, nesting and list order are carried through, and no rewrite — no\n * flattening, no De Morgan, no double-negation collapse, no \"within N days\" normalisation — has\n * anywhere to happen. `emitVisual` is the inverse of `toVisual` for every tree the projection\n * admits, which is what makes `emitVisual(toVisual(node))` deep-equal `node`.\n *\n * `visualSource` is the only place the builder turns a visual expression into text, and it does\n * so by applying the compiler's printer to the emitted tree. The builder ships no second\n * spelling of Expr v1: a caller that switches a rule to advanced mode receives the printer's\n * canonical source, verified by re-parsing its own output.\n */\n\n/** A visual list is the AST list's own shape, so its items are the nodes it holds. */\nfunction emitList(list: VisualList): ExprNode {\n return { kind: 'list', items: list.items };\n}\n\n/** Takes one node's already-emitted children without disturbing any preceding siblings. */\nfunction takeEmitted(emitted: ExprNode[], count: number): ExprNode[] {\n return emitted.splice(emitted.length - count, count);\n}\n\n/** Rebuilds one node after its children have been emitted. */\nfunction emitNode(visual: VisualExpr, emitted: ExprNode[]): ExprNode {\n switch (visual.kind) {\n case 'and':\n return { kind: 'and', args: takeEmitted(emitted, visual.args.length) };\n case 'or':\n return { kind: 'or', args: takeEmitted(emitted, visual.args.length) };\n case 'not': {\n const [operand] = takeEmitted(emitted, 1);\n if (operand === undefined) throw new Error('visual negation emission lost its operand');\n return { kind: 'not', args: [operand] };\n }\n case 'comparison':\n return {\n kind: 'compare',\n op: visual.op,\n args: [visual.left, visual.right],\n };\n case 'membership':\n return {\n kind: 'compare',\n op: 'in',\n args: [visual.left, emitList(visual.candidates)],\n };\n case 'text_match':\n return {\n kind: 'call',\n op: visual.op,\n args: [visual.subject, visual.text],\n };\n case 'check':\n return { kind: 'call', op: visual.check, args: [visual.path] };\n case 'format_check':\n return { kind: 'call', op: visual.check, args: [visual.value] };\n case 'unique_value':\n return { kind: 'call', op: 'is_unique', args: [visual.array] };\n case 'unique_member':\n return { kind: 'call', op: 'is_unique', args: [visual.array, visual.member] };\n case 'count':\n return {\n kind: 'compare',\n op: visual.op,\n args: [{ kind: 'call', op: 'len', args: [visual.path] }, visual.count],\n };\n case 'date_window':\n return {\n kind: 'compare',\n op: visual.op,\n args: [{ kind: 'call', op: visual.span, args: [visual.from, visual.to] }, visual.amount],\n };\n case 'capability':\n return {\n kind: 'call',\n op: 'has_cap',\n args: [{ kind: 'literal', domain: 'string', value: visual.cap }],\n };\n default:\n return assertNever(visual);\n }\n}\n\n/**\n * The AST one visual expression stands for.\n *\n * Every arm states the node the projection recognises, so a round trip is a rebuild of the same\n * tree rather than a translation between two shapes. The post-order walk is iterative: a\n * hand-built tree must reach the printer's budget refusal rather than overflowing the host stack\n * during the emission that precedes it.\n */\nexport function emitVisual(visual: VisualExpr): ExprNode {\n const stack: { readonly visual: VisualExpr; readonly expanded: boolean }[] = [\n { visual, expanded: false },\n ];\n const emitted: ExprNode[] = [];\n while (stack.length > 0) {\n const frame = stack.pop();\n if (frame === undefined) break;\n const current = frame.visual;\n if (\n !frame.expanded &&\n (current.kind === 'and' || current.kind === 'or' || current.kind === 'not')\n ) {\n stack.push({ visual: current, expanded: true });\n const children: readonly VisualExpr[] =\n current.kind === 'not' ? [current.operand] : current.args;\n for (let index = children.length - 1; index >= 0; index -= 1) {\n const child = children[index];\n if (child !== undefined) stack.push({ visual: child, expanded: false });\n }\n continue;\n }\n emitted.push(emitNode(current, emitted));\n }\n const result = emitted.pop();\n if (result === undefined || emitted.length !== 0) {\n throw new Error('visual emission did not produce exactly one tree');\n }\n return result;\n}\n\n/**\n * The canonical source of one visual expression, or the printer's refusal.\n *\n * The refusal is reachable from a visual a caller built by hand — a path segment that is an Expr\n * v1 reserved word has no source form, and neither has a tree past the expression budget — which\n * is why the store's visual door can refuse rather than write source nothing can read back.\n */\nexport function visualSource(visual: VisualExpr): PrintResult {\n return printExpr(emitVisual(visual));\n}\n"]}
@@ -0,0 +1,32 @@
1
+ import type { VisualExpr } from './vocabulary.js';
2
+ /**
3
+ * The boundary read of one visual expression.
4
+ *
5
+ * A store command arrives as whatever a host's form state holds: a value the store must narrow,
6
+ * not one the types state. This module is that narrowing — it turns `unknown` into the closed
7
+ * vocabulary or names the first place the value is not one of its forms, and it does so without a
8
+ * cast. Everything downstream (`emit.ts`, `project.ts`) is then a total switch over the type.
9
+ *
10
+ * The nesting bound is the reader's own: a recursive reader on a hostile value would exhaust the
11
+ * host stack before any later stage could refuse it. A tree past the compiler's expression budget
12
+ * is refused when it is emitted, by the printer, which is where that budget belongs.
13
+ */
14
+ /** The deepest a visual expression may nest before the reader refuses it. */
15
+ export declare const MAX_VISUAL_NESTING = 64;
16
+ /** One boundary read's outcome: the narrowed visual, or the location and reason it is not one. */
17
+ export type VisualParse = {
18
+ readonly ok: true;
19
+ readonly visual: VisualExpr;
20
+ } | {
21
+ readonly ok: false;
22
+ readonly path: string;
23
+ readonly detail: string;
24
+ };
25
+ /**
26
+ * Narrows an untrusted value into a visual expression.
27
+ *
28
+ * `path` is the location a refusal is reported at, so the caller's command path reaches the host
29
+ * unchanged.
30
+ */
31
+ export declare function parseVisual(value: unknown, path?: string): VisualParse;
32
+ //# sourceMappingURL=parse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/visual/parse.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAIV,UAAU,EAEX,MAAM,iBAAiB,CAAC;AASzB;;;;;;;;;;;GAWG;AAEH,6EAA6E;AAC7E,eAAO,MAAM,kBAAkB,KAAK,CAAC;AAErC,kGAAkG;AAClG,MAAM,MAAM,WAAW,GACnB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAA;CAAE,GAClD;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAa3E;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,SAAM,GAAG,WAAW,CAEnE"}