@azx-pbc/axiom-builder 0.0.0-stage → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (231) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +648 -2
  3. package/dist/cards/selectors.d.ts +70 -0
  4. package/dist/cards/selectors.d.ts.map +1 -0
  5. package/dist/cards/selectors.js +194 -0
  6. package/dist/cards/selectors.js.map +1 -0
  7. package/dist/definition.d.ts +36 -0
  8. package/dist/definition.d.ts.map +1 -0
  9. package/dist/definition.js +48 -0
  10. package/dist/definition.js.map +1 -0
  11. package/dist/evidence/cases.d.ts +44 -0
  12. package/dist/evidence/cases.d.ts.map +1 -0
  13. package/dist/evidence/cases.js +578 -0
  14. package/dist/evidence/cases.js.map +1 -0
  15. package/dist/evidence/repairs.d.ts +99 -0
  16. package/dist/evidence/repairs.d.ts.map +1 -0
  17. package/dist/evidence/repairs.js +181 -0
  18. package/dist/evidence/repairs.js.map +1 -0
  19. package/dist/evidence/summary.d.ts +35 -0
  20. package/dist/evidence/summary.d.ts.map +1 -0
  21. package/dist/evidence/summary.js +38 -0
  22. package/dist/evidence/summary.js.map +1 -0
  23. package/dist/i18n/gaps.d.ts +3 -0
  24. package/dist/i18n/gaps.d.ts.map +1 -0
  25. package/dist/i18n/gaps.js +2 -0
  26. package/dist/i18n/gaps.js.map +1 -0
  27. package/dist/i18n/message-slots.d.ts +19 -0
  28. package/dist/i18n/message-slots.d.ts.map +1 -0
  29. package/dist/i18n/message-slots.js +101 -0
  30. package/dist/i18n/message-slots.js.map +1 -0
  31. package/dist/i18n/text-locale.d.ts +13 -0
  32. package/dist/i18n/text-locale.d.ts.map +1 -0
  33. package/dist/i18n/text-locale.js +14 -0
  34. package/dist/i18n/text-locale.js.map +1 -0
  35. package/dist/i18n/translations.d.ts +56 -0
  36. package/dist/i18n/translations.d.ts.map +1 -0
  37. package/dist/i18n/translations.js +103 -0
  38. package/dist/i18n/translations.js.map +1 -0
  39. package/dist/impact/references.d.ts +143 -0
  40. package/dist/impact/references.d.ts.map +1 -0
  41. package/dist/impact/references.js +429 -0
  42. package/dist/impact/references.js.map +1 -0
  43. package/dist/index.d.ts +86 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +58 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/preview/compile-preview.d.ts +67 -0
  48. package/dist/preview/compile-preview.d.ts.map +1 -0
  49. package/dist/preview/compile-preview.js +286 -0
  50. package/dist/preview/compile-preview.js.map +1 -0
  51. package/dist/preview/handle.d.ts +119 -0
  52. package/dist/preview/handle.d.ts.map +1 -0
  53. package/dist/preview/handle.js +2 -0
  54. package/dist/preview/handle.js.map +1 -0
  55. package/dist/preview/held.d.ts +39 -0
  56. package/dist/preview/held.d.ts.map +1 -0
  57. package/dist/preview/held.js +15 -0
  58. package/dist/preview/held.js.map +1 -0
  59. package/dist/preview/measurement.d.ts +5 -0
  60. package/dist/preview/measurement.d.ts.map +1 -0
  61. package/dist/preview/measurement.js +18 -0
  62. package/dist/preview/measurement.js.map +1 -0
  63. package/dist/publish/build.d.ts +33 -0
  64. package/dist/publish/build.d.ts.map +1 -0
  65. package/dist/publish/build.js +15 -0
  66. package/dist/publish/build.js.map +1 -0
  67. package/dist/publish/diff.d.ts +208 -0
  68. package/dist/publish/diff.d.ts.map +1 -0
  69. package/dist/publish/diff.js +227 -0
  70. package/dist/publish/diff.js.map +1 -0
  71. package/dist/publish/review.d.ts +41 -0
  72. package/dist/publish/review.d.ts.map +1 -0
  73. package/dist/publish/review.js +22 -0
  74. package/dist/publish/review.js.map +1 -0
  75. package/dist/schema/dataset-input.d.ts +30 -0
  76. package/dist/schema/dataset-input.d.ts.map +1 -0
  77. package/dist/schema/dataset-input.js +58 -0
  78. package/dist/schema/dataset-input.js.map +1 -0
  79. package/dist/schema/dataset.d.ts +166 -0
  80. package/dist/schema/dataset.d.ts.map +1 -0
  81. package/dist/schema/dataset.js +281 -0
  82. package/dist/schema/dataset.js.map +1 -0
  83. package/dist/schema/declarations.d.ts +15 -0
  84. package/dist/schema/declarations.d.ts.map +1 -0
  85. package/dist/schema/declarations.js +47 -0
  86. package/dist/schema/declarations.js.map +1 -0
  87. package/dist/schema/document.d.ts +504 -0
  88. package/dist/schema/document.d.ts.map +1 -0
  89. package/dist/schema/document.js +337 -0
  90. package/dist/schema/document.js.map +1 -0
  91. package/dist/schema/error.d.ts +15 -0
  92. package/dist/schema/error.d.ts.map +1 -0
  93. package/dist/schema/error.js +18 -0
  94. package/dist/schema/error.js.map +1 -0
  95. package/dist/schema/field-id.d.ts +8 -0
  96. package/dist/schema/field-id.d.ts.map +1 -0
  97. package/dist/schema/field-id.js +47 -0
  98. package/dist/schema/field-id.js.map +1 -0
  99. package/dist/schema/layout.d.ts +118 -0
  100. package/dist/schema/layout.d.ts.map +1 -0
  101. package/dist/schema/layout.js +101 -0
  102. package/dist/schema/layout.js.map +1 -0
  103. package/dist/schema/palette.d.ts +103 -0
  104. package/dist/schema/palette.d.ts.map +1 -0
  105. package/dist/schema/palette.js +140 -0
  106. package/dist/schema/palette.js.map +1 -0
  107. package/dist/schema/read.d.ts +49 -0
  108. package/dist/schema/read.d.ts.map +1 -0
  109. package/dist/schema/read.js +942 -0
  110. package/dist/schema/read.js.map +1 -0
  111. package/dist/store/apply-dataset.d.ts +14 -0
  112. package/dist/store/apply-dataset.d.ts.map +1 -0
  113. package/dist/store/apply-dataset.js +513 -0
  114. package/dist/store/apply-dataset.js.map +1 -0
  115. package/dist/store/apply.d.ts +37 -0
  116. package/dist/store/apply.d.ts.map +1 -0
  117. package/dist/store/apply.js +2269 -0
  118. package/dist/store/apply.js.map +1 -0
  119. package/dist/store/candidate.d.ts +37 -0
  120. package/dist/store/candidate.d.ts.map +1 -0
  121. package/dist/store/candidate.js +178 -0
  122. package/dist/store/candidate.js.map +1 -0
  123. package/dist/store/commands/coverage.d.ts +58 -0
  124. package/dist/store/commands/coverage.d.ts.map +1 -0
  125. package/dist/store/commands/coverage.js +354 -0
  126. package/dist/store/commands/coverage.js.map +1 -0
  127. package/dist/store/commands/dataset.d.ts +26 -0
  128. package/dist/store/commands/dataset.d.ts.map +1 -0
  129. package/dist/store/commands/dataset.js +368 -0
  130. package/dist/store/commands/dataset.js.map +1 -0
  131. package/dist/store/commands/document.d.ts +21 -0
  132. package/dist/store/commands/document.d.ts.map +1 -0
  133. package/dist/store/commands/document.js +160 -0
  134. package/dist/store/commands/document.js.map +1 -0
  135. package/dist/store/commands/field.d.ts +32 -0
  136. package/dist/store/commands/field.d.ts.map +1 -0
  137. package/dist/store/commands/field.js +572 -0
  138. package/dist/store/commands/field.js.map +1 -0
  139. package/dist/store/commands/layout.d.ts +16 -0
  140. package/dist/store/commands/layout.d.ts.map +1 -0
  141. package/dist/store/commands/layout.js +70 -0
  142. package/dist/store/commands/layout.js.map +1 -0
  143. package/dist/store/commands/parse.d.ts +19 -0
  144. package/dist/store/commands/parse.d.ts.map +1 -0
  145. package/dist/store/commands/parse.js +328 -0
  146. package/dist/store/commands/parse.js.map +1 -0
  147. package/dist/store/commands/readers.d.ts +198 -0
  148. package/dist/store/commands/readers.d.ts.map +1 -0
  149. package/dist/store/commands/readers.js +711 -0
  150. package/dist/store/commands/readers.js.map +1 -0
  151. package/dist/store/commands/rule.d.ts +24 -0
  152. package/dist/store/commands/rule.d.ts.map +1 -0
  153. package/dist/store/commands/rule.js +379 -0
  154. package/dist/store/commands/rule.js.map +1 -0
  155. package/dist/store/commands/shapes.d.ts +900 -0
  156. package/dist/store/commands/shapes.d.ts.map +1 -0
  157. package/dist/store/commands/shapes.js +166 -0
  158. package/dist/store/commands/shapes.js.map +1 -0
  159. package/dist/store/commands/suggestions.d.ts +37 -0
  160. package/dist/store/commands/suggestions.d.ts.map +1 -0
  161. package/dist/store/commands/suggestions.js +177 -0
  162. package/dist/store/commands/suggestions.js.map +1 -0
  163. package/dist/store/commands.d.ts +16 -0
  164. package/dist/store/commands.d.ts.map +1 -0
  165. package/dist/store/commands.js +13 -0
  166. package/dist/store/commands.js.map +1 -0
  167. package/dist/store/dataset-candidate.d.ts +33 -0
  168. package/dist/store/dataset-candidate.d.ts.map +1 -0
  169. package/dist/store/dataset-candidate.js +31 -0
  170. package/dist/store/dataset-candidate.js.map +1 -0
  171. package/dist/store/dataset-pin.d.ts +93 -0
  172. package/dist/store/dataset-pin.d.ts.map +1 -0
  173. package/dist/store/dataset-pin.js +86 -0
  174. package/dist/store/dataset-pin.js.map +1 -0
  175. package/dist/store/dataset-store.d.ts +96 -0
  176. package/dist/store/dataset-store.d.ts.map +1 -0
  177. package/dist/store/dataset-store.js +112 -0
  178. package/dist/store/dataset-store.js.map +1 -0
  179. package/dist/store/history.d.ts +149 -0
  180. package/dist/store/history.d.ts.map +1 -0
  181. package/dist/store/history.js +173 -0
  182. package/dist/store/history.js.map +1 -0
  183. package/dist/store/measurement.d.ts +5 -0
  184. package/dist/store/measurement.d.ts.map +1 -0
  185. package/dist/store/measurement.js +20 -0
  186. package/dist/store/measurement.js.map +1 -0
  187. package/dist/store/notify.d.ts +11 -0
  188. package/dist/store/notify.d.ts.map +1 -0
  189. package/dist/store/notify.js +26 -0
  190. package/dist/store/notify.js.map +1 -0
  191. package/dist/store/published.d.ts +50 -0
  192. package/dist/store/published.d.ts.map +1 -0
  193. package/dist/store/published.js +27 -0
  194. package/dist/store/published.js.map +1 -0
  195. package/dist/store/refusals.d.ts +175 -0
  196. package/dist/store/refusals.d.ts.map +1 -0
  197. package/dist/store/refusals.js +160 -0
  198. package/dist/store/refusals.js.map +1 -0
  199. package/dist/store/steps.d.ts +14 -0
  200. package/dist/store/steps.d.ts.map +1 -0
  201. package/dist/store/steps.js +124 -0
  202. package/dist/store/steps.js.map +1 -0
  203. package/dist/store/store.d.ts +142 -0
  204. package/dist/store/store.d.ts.map +1 -0
  205. package/dist/store/store.js +136 -0
  206. package/dist/store/store.js.map +1 -0
  207. package/dist/store/unchanged.d.ts +12 -0
  208. package/dist/store/unchanged.d.ts.map +1 -0
  209. package/dist/store/unchanged.js +35 -0
  210. package/dist/store/unchanged.js.map +1 -0
  211. package/dist/visual/emit.d.ts +21 -0
  212. package/dist/visual/emit.d.ts.map +1 -0
  213. package/dist/visual/emit.js +133 -0
  214. package/dist/visual/emit.js.map +1 -0
  215. package/dist/visual/parse.d.ts +32 -0
  216. package/dist/visual/parse.d.ts.map +1 -0
  217. package/dist/visual/parse.js +330 -0
  218. package/dist/visual/parse.js.map +1 -0
  219. package/dist/visual/project.d.ts +40 -0
  220. package/dist/visual/project.d.ts.map +1 -0
  221. package/dist/visual/project.js +349 -0
  222. package/dist/visual/project.js.map +1 -0
  223. package/dist/visual/represent.d.ts +50 -0
  224. package/dist/visual/represent.d.ts.map +1 -0
  225. package/dist/visual/represent.js +66 -0
  226. package/dist/visual/represent.js.map +1 -0
  227. package/dist/visual/vocabulary.d.ts +121 -0
  228. package/dist/visual/vocabulary.d.ts.map +1 -0
  229. package/dist/visual/vocabulary.js +32 -0
  230. package/dist/visual/vocabulary.js.map +1 -0
  231. package/package.json +52 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commands.js","sourceRoot":"","sources":["../../src/store/commands.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,aAAa,EACb,qBAAqB,EACrB,wBAAwB,EACxB,aAAa,EACb,oBAAoB,GACrB,MAAM,sBAAsB,CAAC;AAgE9B,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC","sourcesContent":["/**\n * The command surface of the authoring store, kept as one public entry.\n *\n * The union and its specs live in `commands/shapes.ts`, the narrowing in `commands/parse.ts` and\n * one reader per family beside it. A caller imports from this module exactly as before: a split\n * for readability is not a second door, and nothing here re-validates what `parseCommand`\n * narrowed.\n */\nexport {\n COMMAND_KINDS,\n DATASET_COMMAND_KINDS,\n DATASET_COMMAND_KIND_SET,\n coalesceKeyOf,\n datasetCoalesceKeyOf,\n} from './commands/shapes.js';\nexport type {\n AddDatasetRowCommand,\n AddFieldSpec,\n AddOptionSpec,\n AddRecordArrayCommand,\n AddRecordArraySpec,\n AddRuleCommand,\n AddRuleSpec,\n AddRuleTestCaseCommand,\n AuthoringCommand,\n AuthoringRuleKind,\n ContextRootSpec,\n DatasetCellInput,\n DatasetCommand,\n DatasetPinSpec,\n DatasetRowSpec,\n DeprecateOptionCommand,\n EditFieldCommand,\n EditFieldSpec,\n EditLayoutNodeCommand,\n EditRuleCommand,\n EditRuleSpec,\n FieldDeclarationSpec,\n FieldPrimitiveSpec,\n GateEditSpec,\n GateItemSpec,\n GateSpec,\n LayoutPath,\n MemberFieldSpec,\n MemberSpec,\n MoveLayoutNodeCommand,\n OptionAvailabilitySpec,\n PinDatasetCommand,\n PlaceFieldCommand,\n RemoveContextRootCommand,\n RemoveDatasetRowCommand,\n RemoveFieldCommand,\n RemoveLayoutNodeCommand,\n RemoveRuleCommand,\n ReplaceDatasetRowCommand,\n ScreenReasonSpec,\n SetContextRootCommand,\n SetDatasetCellCommand,\n SetDatasetColumnsCommand,\n SetDatasetEffectiveRangeCommand,\n SetDatasetHitPolicyCommand,\n SetDatasetValuesCommand,\n SetDocumentTitleCommand,\n SetFieldDeclarationCommand,\n SetFieldPrimitiveCommand,\n SetLocalesCommand,\n SetOnHideCommand,\n SetOptionAvailabilityCommand,\n SetPrimaryCommand,\n SetRuleExprCommand,\n SetRuleNoteCommand,\n SetRuleSuggestsCommand,\n SetSignatureCoversCommand,\n SuggestionOperationSpec,\n SuggestionSpec,\n TestCaseSpec,\n UnpinDatasetCommand,\n} from './commands/shapes.js';\nexport { parseCommand } from './commands/parse.js';\nexport type { CommandParse } from './commands/parse.js';\nexport { parseDatasetCommand } from './commands/dataset.js';\nexport type { DatasetCommandParse } from './commands/dataset.js';\nexport { MAX_MEMBER_NESTING } from './commands/readers.js';\n"]}
@@ -0,0 +1,33 @@
1
+ import type { DatasetDiagnostic } from '@azx-pbc/axiom-compiler';
2
+ import type { AuthoredDatasetDocument } from '../schema/dataset.js';
3
+ import type { AuthoringRefusal } from './refusals.js';
4
+ /**
5
+ * The gate a candidate dataset passes before it becomes the dataset store's state.
6
+ *
7
+ * The dataset compiler is the authority: its restricted-JSON ingestion, closed metaschema and
8
+ * semantic checks all run over the exact text the store would hand a build, so a state the store
9
+ * commits is a table the compiler admits. The refusals re-state the compiler's answer in the
10
+ * store's vocabulary; nothing here is a second copy of a rule.
11
+ *
12
+ * The store's starting document is the one exception: `createDatasetTable` returns a draft with no
13
+ * `values` or `columns` yet, so its diagnostics are reported on the state rather than refusing an
14
+ * open. Every dispatch that follows is held to the full gate.
15
+ */
16
+ /** Whether a candidate dataset may become the store's state, and why it may not. */
17
+ export type DatasetCandidateCheck = {
18
+ readonly ok: true;
19
+ } | {
20
+ readonly ok: false;
21
+ readonly refusal: AuthoringRefusal;
22
+ };
23
+ /** Checks one candidate table against the dataset compiler. */
24
+ export declare function checkDatasetCandidate(document: AuthoredDatasetDocument): DatasetCandidateCheck;
25
+ /**
26
+ * The diagnostics a starting table reports.
27
+ *
28
+ * A caller may hand the store a draft it built itself; the state has to describe what a build would
29
+ * say about it, so the compiler's whole verdict is read here rather than only on the first dispatch
30
+ * that is refused.
31
+ */
32
+ export declare function initialDatasetDiagnostics(document: AuthoredDatasetDocument): readonly DatasetDiagnostic[];
33
+ //# sourceMappingURL=dataset-candidate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataset-candidate.d.ts","sourceRoot":"","sources":["../../src/store/dataset-candidate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAGpE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD;;;;;;;;;;;GAWG;AAEH,oFAAoF;AACpF,MAAM,MAAM,qBAAqB,GAC7B;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAA;CAAE,GACrB;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAA;CAAE,CAAC;AAkB/D,+DAA+D;AAC/D,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,uBAAuB,GAAG,qBAAqB,CAG9F;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,uBAAuB,GAChC,SAAS,iBAAiB,EAAE,CAG9B"}
@@ -0,0 +1,31 @@
1
+ import { compileDataset } from '@azx-pbc/axiom-compiler';
2
+ import { serializeDocument } from '../schema/document.js';
3
+ import { authoringRefusal, datasetDiagnosticRefusal } from './refusals.js';
4
+ /** The first reason the compiler refuses one document, as the store's refusal. */
5
+ function refused(diagnostics) {
6
+ const first = diagnostics[0];
7
+ if (first === undefined) {
8
+ return {
9
+ ok: false,
10
+ refusal: authoringRefusal('INVALID_STRUCTURE', '$', 'the dataset compiler refused the document and stated no reason'),
11
+ };
12
+ }
13
+ return { ok: false, refusal: datasetDiagnosticRefusal(first) };
14
+ }
15
+ /** Checks one candidate table against the dataset compiler. */
16
+ export function checkDatasetCandidate(document) {
17
+ const compiled = compileDataset({ format: 'json', text: serializeDocument(document) });
18
+ return compiled.ok ? { ok: true } : refused(compiled.diagnostics);
19
+ }
20
+ /**
21
+ * The diagnostics a starting table reports.
22
+ *
23
+ * A caller may hand the store a draft it built itself; the state has to describe what a build would
24
+ * say about it, so the compiler's whole verdict is read here rather than only on the first dispatch
25
+ * that is refused.
26
+ */
27
+ export function initialDatasetDiagnostics(document) {
28
+ const compiled = compileDataset({ format: 'json', text: serializeDocument(document) });
29
+ return compiled.ok ? [] : compiled.diagnostics;
30
+ }
31
+ //# sourceMappingURL=dataset-candidate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data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","sourcesContent":["import { compileDataset } from '@azx-pbc/axiom-compiler';\nimport type { DatasetDiagnostic } from '@azx-pbc/axiom-compiler';\nimport type { AuthoredDatasetDocument } from '../schema/dataset.js';\nimport { serializeDocument } from '../schema/document.js';\nimport { authoringRefusal, datasetDiagnosticRefusal } from './refusals.js';\nimport type { AuthoringRefusal } from './refusals.js';\n\n/**\n * The gate a candidate dataset passes before it becomes the dataset store's state.\n *\n * The dataset compiler is the authority: its restricted-JSON ingestion, closed metaschema and\n * semantic checks all run over the exact text the store would hand a build, so a state the store\n * commits is a table the compiler admits. The refusals re-state the compiler's answer in the\n * store's vocabulary; nothing here is a second copy of a rule.\n *\n * The store's starting document is the one exception: `createDatasetTable` returns a draft with no\n * `values` or `columns` yet, so its diagnostics are reported on the state rather than refusing an\n * open. Every dispatch that follows is held to the full gate.\n */\n\n/** Whether a candidate dataset may become the store's state, and why it may not. */\nexport type DatasetCandidateCheck =\n | { readonly ok: true }\n | { readonly ok: false; readonly refusal: AuthoringRefusal };\n\n/** The first reason the compiler refuses one document, as the store's refusal. */\nfunction refused(diagnostics: readonly DatasetDiagnostic[]): DatasetCandidateCheck {\n const first = diagnostics[0];\n if (first === undefined) {\n return {\n ok: false,\n refusal: authoringRefusal(\n 'INVALID_STRUCTURE',\n '$',\n 'the dataset compiler refused the document and stated no reason',\n ),\n };\n }\n return { ok: false, refusal: datasetDiagnosticRefusal(first) };\n}\n\n/** Checks one candidate table against the dataset compiler. */\nexport function checkDatasetCandidate(document: AuthoredDatasetDocument): DatasetCandidateCheck {\n const compiled = compileDataset({ format: 'json', text: serializeDocument(document) });\n return compiled.ok ? { ok: true } : refused(compiled.diagnostics);\n}\n\n/**\n * The diagnostics a starting table reports.\n *\n * A caller may hand the store a draft it built itself; the state has to describe what a build would\n * say about it, so the compiler's whole verdict is read here rather than only on the first dispatch\n * that is refused.\n */\nexport function initialDatasetDiagnostics(\n document: AuthoredDatasetDocument,\n): readonly DatasetDiagnostic[] {\n const compiled = compileDataset({ format: 'json', text: serializeDocument(document) });\n return compiled.ok ? [] : compiled.diagnostics;\n}\n"]}
@@ -0,0 +1,93 @@
1
+ import type { AuthoredDatasetDocument } from '../schema/dataset.js';
2
+ import type { AuthoringRefusal } from './refusals.js';
3
+ /**
4
+ * Whether the table a store holds is the table a schema pinned.
5
+ *
6
+ * A schema's `datasetRef` names a version (`DATA-4.1.4`) and the artifact's pin adds the digest of
7
+ * the bytes that version resolved (`DATA-4.1.6`), so "the pin still matches" is two questions:
8
+ * whether the store's document states the pinned edition, and whether its restricted-JCS digest is
9
+ * the one the artifact pins. A store that edited the rows of a published version answers *no* to the
10
+ * second without changing the version, and that is exactly the state an authoring surface must show
11
+ * rather than serialise over: the same `tableVersion` with different bytes is an edit in place,
12
+ * which `DATA-1.1.2` forbids.
13
+ *
14
+ * The answer is a discriminated union rather than a boolean, because each arm carries the facts the
15
+ * surface reports — both versions, both digests, or the table that was served instead.
16
+ */
17
+ /** A pin as the schema or the published artifact states it. */
18
+ export interface DatasetPin {
19
+ readonly tableId: string;
20
+ readonly tableVersion: number;
21
+ /**
22
+ * The restricted-JCS SHA-256 the artifact pinned, when the caller holds one. A schema's own
23
+ * `datasetRef` states only the version, so a check against a draft's pin omits this and compares
24
+ * versions alone.
25
+ */
26
+ readonly sha256?: string;
27
+ }
28
+ /** The ways the document a store holds answers, or fails to answer, a pin. */
29
+ export type DatasetPinCheck = {
30
+ readonly status: 'match';
31
+ readonly tableId: string;
32
+ readonly tableVersion: number;
33
+ readonly sha256: string;
34
+ } | {
35
+ readonly status: 'version_mismatch';
36
+ readonly tableId: string;
37
+ readonly pinnedTableVersion: number;
38
+ readonly servedTableVersion: number;
39
+ readonly servedSha256: string;
40
+ } | {
41
+ readonly status: 'digest_mismatch';
42
+ readonly tableId: string;
43
+ readonly tableVersion: number;
44
+ readonly pinnedSha256: string;
45
+ readonly servedSha256: string;
46
+ } | {
47
+ readonly status: 'other_table';
48
+ readonly pinnedTableId: string;
49
+ readonly servedTableId: string;
50
+ readonly servedTableVersion: number;
51
+ readonly servedSha256: string;
52
+ } | {
53
+ readonly status: 'unserved';
54
+ readonly tableId: string;
55
+ readonly tableVersion: number;
56
+ };
57
+ /**
58
+ * The pin's answer for one document, or `unserved` when the store holds no document for it.
59
+ *
60
+ * The table id is checked before the version so a document wired to the wrong pin is reported as
61
+ * that, rather than as an edition mismatch the author would chase in the wrong table.
62
+ */
63
+ export declare function checkDatasetPin(pin: DatasetPin, document: AuthoredDatasetDocument | undefined): DatasetPinCheck;
64
+ /**
65
+ * Every pin a draft states, answered against the documents a store holds.
66
+ *
67
+ * A Studio shows one row per pin — `match` as a note, every other arm as a repair — and a pin whose
68
+ * table the store does not hold is `unserved` rather than absent, so the surface cannot silently
69
+ * show nothing where the schema depends on a table.
70
+ */
71
+ export declare function datasetPinChecks(pins: readonly DatasetPin[], served: readonly AuthoredDatasetDocument[]): readonly DatasetPinCheck[];
72
+ /** The bytes a table publishes, or the reason they are not the bytes the pin names. */
73
+ export type DatasetPublication = {
74
+ readonly ok: true;
75
+ readonly text: string;
76
+ readonly sha256: string;
77
+ /** The answer the pin received, absent when the caller stated no pin. */
78
+ readonly pin?: DatasetPinCheck;
79
+ } | {
80
+ readonly ok: false;
81
+ readonly refusal: AuthoringRefusal;
82
+ };
83
+ /**
84
+ * The document's text as a publication, refused when the pin no longer answers it.
85
+ *
86
+ * This is the door that keeps the pin honest. Serialising the document and letting the caller carry
87
+ * on would publish rows under a version and digest they are not; a `digest_mismatch` is the edit in
88
+ * place `DATA-1.1.2` forbids, and the refusal names both digests so the author can repin the schema
89
+ * or advance the edition. With no pin stated there is nothing to contradict, so the bytes are
90
+ * returned and the caller's own publish gate judges them.
91
+ */
92
+ export declare function publishDataset(document: AuthoredDatasetDocument, pin?: DatasetPin): DatasetPublication;
93
+ //# sourceMappingURL=dataset-pin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataset-pin.d.ts","sourceRoot":"","sources":["../../src/store/dataset-pin.ts"],"names":[],"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Q,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B,GACD;IACE,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B,CAAC;AAEN;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,GAAG,EAAE,UAAU,EACf,QAAQ,EAAE,uBAAuB,GAAG,SAAS,GAC5C,eAAe,CAiCjB;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,SAAS,UAAU,EAAE,EAC3B,MAAM,EAAE,SAAS,uBAAuB,EAAE,GACzC,SAAS,eAAe,EAAE,CAO5B;AAED,uFAAuF;AACvF,MAAM,MAAM,kBAAkB,GAC1B;IACE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAClB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,yEAAyE;IACzE,QAAQ,CAAC,GAAG,CAAC,EAAE,eAAe,CAAC;CAChC,GACD;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAA;CAAE,CAAC;AAE/D;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,uBAAuB,EACjC,GAAG,CAAC,EAAE,UAAU,GACf,kBAAkB,CAOpB"}
@@ -0,0 +1,86 @@
1
+ import { datasetDigest } from '../schema/dataset.js';
2
+ import { serializeDocument } from '../schema/document.js';
3
+ import { datasetRefusal } from './refusals.js';
4
+ /**
5
+ * The pin's answer for one document, or `unserved` when the store holds no document for it.
6
+ *
7
+ * The table id is checked before the version so a document wired to the wrong pin is reported as
8
+ * that, rather than as an edition mismatch the author would chase in the wrong table.
9
+ */
10
+ export function checkDatasetPin(pin, document) {
11
+ if (document === undefined) {
12
+ return { status: 'unserved', tableId: pin.tableId, tableVersion: pin.tableVersion };
13
+ }
14
+ const sha256 = datasetDigest(document);
15
+ if (document.tableId !== pin.tableId) {
16
+ return {
17
+ status: 'other_table',
18
+ pinnedTableId: pin.tableId,
19
+ servedTableId: document.tableId,
20
+ servedTableVersion: document.tableVersion,
21
+ servedSha256: sha256,
22
+ };
23
+ }
24
+ if (document.tableVersion !== pin.tableVersion) {
25
+ return {
26
+ status: 'version_mismatch',
27
+ tableId: pin.tableId,
28
+ pinnedTableVersion: pin.tableVersion,
29
+ servedTableVersion: document.tableVersion,
30
+ servedSha256: sha256,
31
+ };
32
+ }
33
+ if (pin.sha256 !== undefined && pin.sha256 !== sha256) {
34
+ return {
35
+ status: 'digest_mismatch',
36
+ tableId: pin.tableId,
37
+ tableVersion: pin.tableVersion,
38
+ pinnedSha256: pin.sha256,
39
+ servedSha256: sha256,
40
+ };
41
+ }
42
+ return { status: 'match', tableId: pin.tableId, tableVersion: pin.tableVersion, sha256 };
43
+ }
44
+ /**
45
+ * Every pin a draft states, answered against the documents a store holds.
46
+ *
47
+ * A Studio shows one row per pin — `match` as a note, every other arm as a repair — and a pin whose
48
+ * table the store does not hold is `unserved` rather than absent, so the surface cannot silently
49
+ * show nothing where the schema depends on a table.
50
+ */
51
+ export function datasetPinChecks(pins, served) {
52
+ return pins.map((pin) => checkDatasetPin(pin, served.find((document) => document.tableId === pin.tableId)));
53
+ }
54
+ /**
55
+ * The document's text as a publication, refused when the pin no longer answers it.
56
+ *
57
+ * This is the door that keeps the pin honest. Serialising the document and letting the caller carry
58
+ * on would publish rows under a version and digest they are not; a `digest_mismatch` is the edit in
59
+ * place `DATA-1.1.2` forbids, and the refusal names both digests so the author can repin the schema
60
+ * or advance the edition. With no pin stated there is nothing to contradict, so the bytes are
61
+ * returned and the caller's own publish gate judges them.
62
+ */
63
+ export function publishDataset(document, pin) {
64
+ const text = serializeDocument(document);
65
+ const sha256 = datasetDigest(document);
66
+ if (pin === undefined)
67
+ return { ok: true, text, sha256 };
68
+ const check = checkDatasetPin(pin, document);
69
+ if (check.status === 'match')
70
+ return { ok: true, text, sha256, pin: check };
71
+ return { ok: false, refusal: pinRefusal(check) };
72
+ }
73
+ /** The refusal one non-matching pin earns, naming both facts the author repins. */
74
+ function pinRefusal(check) {
75
+ switch (check.status) {
76
+ case 'other_table':
77
+ return datasetRefusal('DATASET_PIN_MISMATCH', '$.tableId', `the pin names table \`${check.pinnedTableId}\` and the document states \`${check.servedTableId}\`; a table version is published under the id it was written for`);
78
+ case 'version_mismatch':
79
+ return datasetRefusal('DATASET_PIN_MISMATCH', '$.tableVersion', `the pin names table \`${check.tableId}\` version ${String(check.pinnedTableVersion)} and the document states version ${String(check.servedTableVersion)}; a published version is never edited in place`);
80
+ case 'digest_mismatch':
81
+ return datasetRefusal('DATASET_PIN_MISMATCH', '$', `the document hashes to \`${check.servedSha256}\` and the pin names \`${check.pinnedSha256}\` for table \`${check.tableId}\` version ${String(check.tableVersion)}; the rows changed after the pin was taken`);
82
+ case 'unserved':
83
+ return datasetRefusal('UNKNOWN_TABLE', '$.tableId', `this store holds no document for table \`${check.tableId}\` version ${String(check.tableVersion)}`);
84
+ }
85
+ }
86
+ //# sourceMappingURL=dataset-pin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataset-pin.js","sourceRoot":"","sources":["../../src/store/dataset-pin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAiE/C;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAC7B,GAAe,EACf,QAA6C;IAE7C,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,CAAC,YAAY,EAAE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Y,0BAA0B,KAAK,CAAC,YAAY,kBAAkB,KAAK,CAAC,OAAO,cAAc,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,4CAA4C,CAC9M,CAAC;QACJ,KAAK,UAAU;YACb,OAAO,cAAc,CACnB,eAAe,EACf,WAAW,EACX,4CAA4C,KAAK,CAAC,OAAO,cAAc,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,CACpG,CAAC;IACN,CAAC;AACH,CAAC","sourcesContent":["import type { AuthoredDatasetDocument } from '../schema/dataset.js';\nimport { datasetDigest } from '../schema/dataset.js';\nimport { serializeDocument } from '../schema/document.js';\nimport { datasetRefusal } from './refusals.js';\nimport type { AuthoringRefusal } from './refusals.js';\n\n/**\n * Whether the table a store holds is the table a schema pinned.\n *\n * A schema's `datasetRef` names a version (`DATA-4.1.4`) and the artifact's pin adds the digest of\n * the bytes that version resolved (`DATA-4.1.6`), so \"the pin still matches\" is two questions:\n * whether the store's document states the pinned edition, and whether its restricted-JCS digest is\n * the one the artifact pins. A store that edited the rows of a published version answers *no* to the\n * second without changing the version, and that is exactly the state an authoring surface must show\n * rather than serialise over: the same `tableVersion` with different bytes is an edit in place,\n * which `DATA-1.1.2` forbids.\n *\n * The answer is a discriminated union rather than a boolean, because each arm carries the facts the\n * surface reports — both versions, both digests, or the table that was served instead.\n */\n\n/** A pin as the schema or the published artifact states it. */\nexport interface DatasetPin {\n readonly tableId: string;\n readonly tableVersion: number;\n /**\n * The restricted-JCS SHA-256 the artifact pinned, when the caller holds one. A schema's own\n * `datasetRef` states only the version, so a check against a draft's pin omits this and compares\n * versions alone.\n */\n readonly sha256?: string;\n}\n\n/** The ways the document a store holds answers, or fails to answer, a pin. */\nexport type DatasetPinCheck =\n | {\n readonly status: 'match';\n readonly tableId: string;\n readonly tableVersion: number;\n readonly sha256: string;\n }\n | {\n readonly status: 'version_mismatch';\n readonly tableId: string;\n readonly pinnedTableVersion: number;\n readonly servedTableVersion: number;\n readonly servedSha256: string;\n }\n | {\n readonly status: 'digest_mismatch';\n readonly tableId: string;\n readonly tableVersion: number;\n readonly pinnedSha256: string;\n readonly servedSha256: string;\n }\n | {\n readonly status: 'other_table';\n readonly pinnedTableId: string;\n readonly servedTableId: string;\n readonly servedTableVersion: number;\n readonly servedSha256: string;\n }\n | {\n readonly status: 'unserved';\n readonly tableId: string;\n readonly tableVersion: number;\n };\n\n/**\n * The pin's answer for one document, or `unserved` when the store holds no document for it.\n *\n * The table id is checked before the version so a document wired to the wrong pin is reported as\n * that, rather than as an edition mismatch the author would chase in the wrong table.\n */\nexport function checkDatasetPin(\n pin: DatasetPin,\n document: AuthoredDatasetDocument | undefined,\n): DatasetPinCheck {\n if (document === undefined) {\n return { status: 'unserved', tableId: pin.tableId, tableVersion: pin.tableVersion };\n }\n const sha256 = datasetDigest(document);\n if (document.tableId !== pin.tableId) {\n return {\n status: 'other_table',\n pinnedTableId: pin.tableId,\n servedTableId: document.tableId,\n servedTableVersion: document.tableVersion,\n servedSha256: sha256,\n };\n }\n if (document.tableVersion !== pin.tableVersion) {\n return {\n status: 'version_mismatch',\n tableId: pin.tableId,\n pinnedTableVersion: pin.tableVersion,\n servedTableVersion: document.tableVersion,\n servedSha256: sha256,\n };\n }\n if (pin.sha256 !== undefined && pin.sha256 !== sha256) {\n return {\n status: 'digest_mismatch',\n tableId: pin.tableId,\n tableVersion: pin.tableVersion,\n pinnedSha256: pin.sha256,\n servedSha256: sha256,\n };\n }\n return { status: 'match', tableId: pin.tableId, tableVersion: pin.tableVersion, sha256 };\n}\n\n/**\n * Every pin a draft states, answered against the documents a store holds.\n *\n * A Studio shows one row per pin — `match` as a note, every other arm as a repair — and a pin whose\n * table the store does not hold is `unserved` rather than absent, so the surface cannot silently\n * show nothing where the schema depends on a table.\n */\nexport function datasetPinChecks(\n pins: readonly DatasetPin[],\n served: readonly AuthoredDatasetDocument[],\n): readonly DatasetPinCheck[] {\n return pins.map((pin) =>\n checkDatasetPin(\n pin,\n served.find((document) => document.tableId === pin.tableId),\n ),\n );\n}\n\n/** The bytes a table publishes, or the reason they are not the bytes the pin names. */\nexport type DatasetPublication =\n | {\n readonly ok: true;\n readonly text: string;\n readonly sha256: string;\n /** The answer the pin received, absent when the caller stated no pin. */\n readonly pin?: DatasetPinCheck;\n }\n | { readonly ok: false; readonly refusal: AuthoringRefusal };\n\n/**\n * The document's text as a publication, refused when the pin no longer answers it.\n *\n * This is the door that keeps the pin honest. Serialising the document and letting the caller carry\n * on would publish rows under a version and digest they are not; a `digest_mismatch` is the edit in\n * place `DATA-1.1.2` forbids, and the refusal names both digests so the author can repin the schema\n * or advance the edition. With no pin stated there is nothing to contradict, so the bytes are\n * returned and the caller's own publish gate judges them.\n */\nexport function publishDataset(\n document: AuthoredDatasetDocument,\n pin?: DatasetPin,\n): DatasetPublication {\n const text = serializeDocument(document);\n const sha256 = datasetDigest(document);\n if (pin === undefined) return { ok: true, text, sha256 };\n const check = checkDatasetPin(pin, document);\n if (check.status === 'match') return { ok: true, text, sha256, pin: check };\n return { ok: false, refusal: pinRefusal(check) };\n}\n\n/** The refusal one non-matching pin earns, naming both facts the author repins. */\nfunction pinRefusal(\n check: Exclude<DatasetPinCheck, { readonly status: 'match' }>,\n): AuthoringRefusal {\n switch (check.status) {\n case 'other_table':\n return datasetRefusal(\n 'DATASET_PIN_MISMATCH',\n '$.tableId',\n `the pin names table \\`${check.pinnedTableId}\\` and the document states \\`${check.servedTableId}\\`; a table version is published under the id it was written for`,\n );\n case 'version_mismatch':\n return datasetRefusal(\n 'DATASET_PIN_MISMATCH',\n '$.tableVersion',\n `the pin names table \\`${check.tableId}\\` version ${String(check.pinnedTableVersion)} and the document states version ${String(check.servedTableVersion)}; a published version is never edited in place`,\n );\n case 'digest_mismatch':\n return datasetRefusal(\n 'DATASET_PIN_MISMATCH',\n '$',\n `the document hashes to \\`${check.servedSha256}\\` and the pin names \\`${check.pinnedSha256}\\` for table \\`${check.tableId}\\` version ${String(check.tableVersion)}; the rows changed after the pin was taken`,\n );\n case 'unserved':\n return datasetRefusal(\n 'UNKNOWN_TABLE',\n '$.tableId',\n `this store holds no document for table \\`${check.tableId}\\` version ${String(check.tableVersion)}`,\n );\n }\n}\n"]}
@@ -0,0 +1,96 @@
1
+ import type { DatasetDiagnostic } from '@azx-pbc/axiom-compiler';
2
+ import type { AuthoredDatasetDocument } from '../schema/dataset.js';
3
+ import type { AuthoringState, HistoryRefusal, HistoryStep } from './history.js';
4
+ import type { DatasetCommand } from './commands.js';
5
+ import type { DatasetPin, DatasetPinCheck } from './dataset-pin.js';
6
+ import type { AuthoringRefusal } from './refusals.js';
7
+ import type { DispatchContext } from './store.js';
8
+ /**
9
+ * The headless dataset store.
10
+ *
11
+ * It is the editing surface of one table: the rows, columns, policies and effective range a Studio's
12
+ * grid writes, with the same dispatch/undo/redo contract as the schema store and no React, DOM,
13
+ * clock or randomness. The document is `spec/metaschema/dataset.v1.json`, the candidate gate is the
14
+ * dataset compiler, and the undo chain is the schema store's own `history.ts` — one chain
15
+ * implementation serves both documents.
16
+ *
17
+ * A dispatch either commits exactly one undo step, succeeds without a step because it restates
18
+ * the table, or refuses and leaves the document and the chain untouched, by identity. Between the
19
+ * two there is no state: a table the compiler would refuse is a table the store never commits, so
20
+ * what `getState()` answers is what a build reads.
21
+ *
22
+ * The pin is optional and read-only here. A Studio that edits a table its schema pins supplies the
23
+ * pin, and the state carries the answer on every commit: `pin.status !== 'match'` is the edit in
24
+ * place the surface reports, and `publishDataset` refuses to serialise it under the pinned bytes.
25
+ */
26
+ export interface DatasetStoreOptions {
27
+ /** The pin the schema states, so the state reports whether its bytes still answer it. */
28
+ readonly pin?: DatasetPin;
29
+ }
30
+ /** What the dataset store's state adds to the shared authoring state. */
31
+ export interface DatasetState extends AuthoringState<AuthoredDatasetDocument, DatasetDiagnostic> {
32
+ /** The pin's answer for the document at the cursor, absent when the caller stated no pin. */
33
+ readonly pin?: DatasetPinCheck;
34
+ }
35
+ /** What a committed dataset dispatch did beyond the command's own intent. */
36
+ export interface DatasetDispatchEffects {
37
+ /** Whether the step merged into the one before it (consecutive edits of one cell). */
38
+ readonly coalesced: boolean;
39
+ /** Whether this commit dropped the oldest retained state (`HISTORY_LIMIT`). */
40
+ readonly truncated: boolean;
41
+ }
42
+ /** The outcome of one dataset dispatch. */
43
+ export type DatasetDispatchOutcome = {
44
+ readonly ok: true;
45
+ readonly state: DatasetState;
46
+ readonly effects: DatasetDispatchEffects;
47
+ } | {
48
+ readonly ok: false;
49
+ readonly refusal: AuthoringRefusal;
50
+ };
51
+ /** The outcome of an undo or redo. */
52
+ export type DatasetHistoryOutcome = {
53
+ readonly ok: true;
54
+ readonly state: DatasetState;
55
+ } | {
56
+ readonly ok: false;
57
+ readonly reason: HistoryRefusal;
58
+ };
59
+ /** The dataset store's whole surface. */
60
+ export interface DatasetStore {
61
+ /** The current state: the table, the diagnostics a compile reports, and the pin's answer. */
62
+ getState(): DatasetState;
63
+ /** Applies one command, or refuses it without touching the document or the history. */
64
+ dispatch(command: DatasetCommand, context?: DispatchContext): DatasetDispatchOutcome;
65
+ /** The commands that produced the state at the cursor, oldest first, with the host's attribution. */
66
+ history(): readonly HistoryStep[];
67
+ /** Registers a listener; the returned function releases it and may be called twice. */
68
+ subscribe(listener: () => void): () => void;
69
+ /** Moves the cursor to the previous retained state. */
70
+ undo(): DatasetHistoryOutcome;
71
+ /** Moves the cursor to the next retained state. */
72
+ redo(): DatasetHistoryOutcome;
73
+ /** Whether a previous state is retained; the same flag `getState().canUndo` states. */
74
+ canUndo(): boolean;
75
+ /** Whether a state the cursor moved back over is still ahead of it; `getState().canRedo`. */
76
+ canRedo(): boolean;
77
+ /**
78
+ * Ends the coalescing run at the cursor, so the next edit of the same cell is a new step.
79
+ *
80
+ * `setDatasetCell` merges consecutive edits to one `(tableId, rowId, columnId)`, which is what
81
+ * makes typing one cell one undo step. A host that has left the cell (a blur, a selection
82
+ * change) knows the run ended even though no other command was dispatched, and calls this so a
83
+ * second visit does not merge into the first. The table, the cursor and the pin do not move.
84
+ */
85
+ seal(): void;
86
+ }
87
+ /**
88
+ * Opens a dataset store over one table.
89
+ *
90
+ * The starting document is the chain's first node and its diagnostics are what a compile says about
91
+ * it. A caller that starts from `createDatasetTable` starts from a draft with no columns or values,
92
+ * which the compile reports; the first `setDatasetColumns` or `setDatasetValues` is the dispatch that
93
+ * completes it.
94
+ */
95
+ export declare function createDatasetStore(document: AuthoredDatasetDocument, options?: DatasetStoreOptions): DatasetStore;
96
+ //# sourceMappingURL=dataset-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataset-store.d.ts","sourceRoot":"","sources":["../../src/store/dataset-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,KAAK,EAAoB,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAWlG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAIpD,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGpE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAGlD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,mBAAmB;IAClC,yFAAyF;IACzF,QAAQ,CAAC,GAAG,CAAC,EAAE,UAAU,CAAC;CAC3B;AAED,yEAAyE;AACzE,MAAM,WAAW,YAAa,SAAQ,cAAc,CAAC,uBAAuB,EAAE,iBAAiB,CAAC;IAC9F,6FAA6F;IAC7F,QAAQ,CAAC,GAAG,CAAC,EAAE,eAAe,CAAC;CAChC;AAED,6EAA6E;AAC7E,MAAM,WAAW,sBAAsB;IACrC,sFAAsF;IACtF,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IA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E,uBAAuB,EACjC,OAAO,GAAE,mBAAwB,GAChC,YAAY,CA4Fd"}
@@ -0,0 +1,112 @@
1
+ import { commitHistory, createHistory, historyState, historySteps, redoHistory, sealHistory, shareDiagnostics, undoHistory, } from './history.js';
2
+ import { datasetCoalesceKeyOf, parseDatasetCommand } from './commands.js';
3
+ import { applyDatasetCommand } from './apply-dataset.js';
4
+ import { checkDatasetCandidate, initialDatasetDiagnostics } from './dataset-candidate.js';
5
+ import { checkDatasetPin } from './dataset-pin.js';
6
+ import { notifyAll } from './notify.js';
7
+ import { describeDatasetCommand } from './steps.js';
8
+ /** The state the store answers, with the pin's answer computed for the document at the cursor. */
9
+ function datasetState(history, pin) {
10
+ const state = historyState(history);
11
+ return pin === undefined ? state : { ...state, pin: checkDatasetPin(pin, state.document) };
12
+ }
13
+ /**
14
+ * Opens a dataset store over one table.
15
+ *
16
+ * The starting document is the chain's first node and its diagnostics are what a compile says about
17
+ * it. A caller that starts from `createDatasetTable` starts from a draft with no columns or values,
18
+ * which the compile reports; the first `setDatasetColumns` or `setDatasetValues` is the dispatch that
19
+ * completes it.
20
+ */
21
+ export function createDatasetStore(document, options = {}) {
22
+ const pin = options.pin;
23
+ let history = createHistory({
24
+ document,
25
+ diagnostics: initialDatasetDiagnostics(document),
26
+ });
27
+ let state = datasetState(history, pin);
28
+ const listeners = new Set();
29
+ const notify = () => {
30
+ notifyAll(listeners);
31
+ };
32
+ return {
33
+ getState() {
34
+ return state;
35
+ },
36
+ dispatch(command, context = {}) {
37
+ const parsed = parseDatasetCommand(command);
38
+ if (!parsed.ok)
39
+ return { ok: false, refusal: parsed.refusal };
40
+ const previous = state;
41
+ const applied = applyDatasetCommand(previous.document, parsed.command);
42
+ if (!applied.ok)
43
+ return { ok: false, refusal: applied.refusal };
44
+ // A command that returns the table at the cursor states no edit: retain the pin, the cursor,
45
+ // the history and the subscribers rather than committing a step that changes no bytes.
46
+ if (applied.document === previous.document) {
47
+ return {
48
+ ok: true,
49
+ state: previous,
50
+ effects: { coalesced: false, truncated: false },
51
+ };
52
+ }
53
+ const checked = checkDatasetCandidate(applied.document);
54
+ if (!checked.ok)
55
+ return { ok: false, refusal: checked.refusal };
56
+ const committed = commitHistory(history, {
57
+ document: applied.document,
58
+ diagnostics: shareDiagnostics(previous.diagnostics, []),
59
+ }, datasetCoalesceKeyOf(parsed.command), {
60
+ kind: parsed.command.kind,
61
+ summary: describeDatasetCommand(parsed.command),
62
+ ...(context.actor === undefined ? {} : { actor: context.actor }),
63
+ ...(context.at === undefined ? {} : { at: context.at }),
64
+ });
65
+ history = committed.history;
66
+ state = datasetState(history, pin);
67
+ notify();
68
+ return {
69
+ ok: true,
70
+ state,
71
+ effects: { coalesced: committed.coalesced, truncated: committed.truncated },
72
+ };
73
+ },
74
+ subscribe(listener) {
75
+ listeners.add(listener);
76
+ return () => {
77
+ listeners.delete(listener);
78
+ };
79
+ },
80
+ history() {
81
+ return historySteps(history);
82
+ },
83
+ undo() {
84
+ const moved = undoHistory(history);
85
+ if (moved === undefined)
86
+ return { ok: false, reason: 'nothing_to_undo' };
87
+ history = moved;
88
+ state = datasetState(history, pin);
89
+ notify();
90
+ return { ok: true, state };
91
+ },
92
+ redo() {
93
+ const moved = redoHistory(history);
94
+ if (moved === undefined)
95
+ return { ok: false, reason: 'nothing_to_redo' };
96
+ history = moved;
97
+ state = datasetState(history, pin);
98
+ notify();
99
+ return { ok: true, state };
100
+ },
101
+ canUndo() {
102
+ return state.canUndo;
103
+ },
104
+ canRedo() {
105
+ return state.canRedo;
106
+ },
107
+ seal() {
108
+ history = sealHistory(history);
109
+ },
110
+ };
111
+ }
112
+ //# sourceMappingURL=dataset-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataset-store.js","sourceRoot":"","sources":["../../src/store/dataset-store.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,aAAa,EACb,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,WAAW,GAC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K,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,EAAE,GAAG,CAAC,CAAC;YACnC,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 type { DatasetDiagnostic } from '@azx-pbc/axiom-compiler';\nimport type { AuthoredDatasetDocument } from '../schema/dataset.js';\nimport type { AuthoringHistory, AuthoringState, 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 { DatasetCommand } from './commands.js';\nimport { datasetCoalesceKeyOf, parseDatasetCommand } from './commands.js';\nimport { applyDatasetCommand } from './apply-dataset.js';\nimport { checkDatasetCandidate, initialDatasetDiagnostics } from './dataset-candidate.js';\nimport type { DatasetPin, DatasetPinCheck } from './dataset-pin.js';\nimport { checkDatasetPin } from './dataset-pin.js';\nimport { notifyAll } from './notify.js';\nimport type { AuthoringRefusal } from './refusals.js';\nimport type { DispatchContext } from './store.js';\nimport { describeDatasetCommand } from './steps.js';\n\n/**\n * The headless dataset store.\n *\n * It is the editing surface of one table: the rows, columns, policies and effective range a Studio's\n * grid writes, with the same dispatch/undo/redo contract as the schema store and no React, DOM,\n * clock or randomness. The document is `spec/metaschema/dataset.v1.json`, the candidate gate is the\n * dataset compiler, and the undo chain is the schema store's own `history.ts` — one chain\n * implementation serves both documents.\n *\n * A dispatch either commits exactly one undo step, succeeds without a step because it restates\n * the table, or refuses and leaves the document and the chain untouched, by identity. Between the\n * two there is no state: a table the compiler would refuse is a table the store never commits, so\n * what `getState()` answers is what a build reads.\n *\n * The pin is optional and read-only here. A Studio that edits a table its schema pins supplies the\n * pin, and the state carries the answer on every commit: `pin.status !== 'match'` is the edit in\n * place the surface reports, and `publishDataset` refuses to serialise it under the pinned bytes.\n */\nexport interface DatasetStoreOptions {\n /** The pin the schema states, so the state reports whether its bytes still answer it. */\n readonly pin?: DatasetPin;\n}\n\n/** What the dataset store's state adds to the shared authoring state. */\nexport interface DatasetState extends AuthoringState<AuthoredDatasetDocument, DatasetDiagnostic> {\n /** The pin's answer for the document at the cursor, absent when the caller stated no pin. */\n readonly pin?: DatasetPinCheck;\n}\n\n/** What a committed dataset dispatch did beyond the command's own intent. */\nexport interface DatasetDispatchEffects {\n /** Whether the step merged into the one before it (consecutive edits of one cell). */\n readonly coalesced: boolean;\n /** Whether this commit dropped the oldest retained state (`HISTORY_LIMIT`). */\n readonly truncated: boolean;\n}\n\n/** The outcome of one dataset dispatch. */\nexport type DatasetDispatchOutcome =\n | {\n readonly ok: true;\n readonly state: DatasetState;\n readonly effects: DatasetDispatchEffects;\n }\n | { readonly ok: false; readonly refusal: AuthoringRefusal };\n\n/** The outcome of an undo or redo. */\nexport type DatasetHistoryOutcome =\n | { readonly ok: true; readonly state: DatasetState }\n | { readonly ok: false; readonly reason: HistoryRefusal };\n\n/** The dataset store's whole surface. */\nexport interface DatasetStore {\n /** The current state: the table, the diagnostics a compile reports, and the pin's answer. */\n getState(): DatasetState;\n /** Applies one command, or refuses it without touching the document or the history. */\n dispatch(command: DatasetCommand, context?: DispatchContext): DatasetDispatchOutcome;\n /** The commands that produced the state at the cursor, oldest first, with the host's attribution. */\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(): DatasetHistoryOutcome;\n /** Moves the cursor to the next retained state. */\n redo(): DatasetHistoryOutcome;\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 cell is a new step.\n *\n * `setDatasetCell` merges consecutive edits to one `(tableId, rowId, columnId)`, which is what\n * makes typing one cell one undo step. A host that has left the cell (a blur, a selection\n * change) knows the run ended even though no other command was dispatched, and calls this so a\n * second visit does not merge into the first. The table, the cursor and the pin do not move.\n */\n seal(): void;\n}\n\n/** The state the store answers, with the pin's answer computed for the document at the cursor. */\nfunction datasetState(\n history: AuthoringHistory<AuthoredDatasetDocument, DatasetDiagnostic>,\n pin: DatasetPin | undefined,\n): DatasetState {\n const state = historyState(history);\n return pin === undefined ? state : { ...state, pin: checkDatasetPin(pin, state.document) };\n}\n\n/**\n * Opens a dataset store over one table.\n *\n * The starting document is the chain's first node and its diagnostics are what a compile says about\n * it. A caller that starts from `createDatasetTable` starts from a draft with no columns or values,\n * which the compile reports; the first `setDatasetColumns` or `setDatasetValues` is the dispatch that\n * completes it.\n */\nexport function createDatasetStore(\n document: AuthoredDatasetDocument,\n options: DatasetStoreOptions = {},\n): DatasetStore {\n const pin = options.pin;\n let history: AuthoringHistory<AuthoredDatasetDocument, DatasetDiagnostic> = createHistory({\n document,\n diagnostics: initialDatasetDiagnostics(document),\n });\n let state: DatasetState = datasetState(history, pin);\n const listeners = new Set<() => void>();\n\n const notify = (): void => {\n notifyAll(listeners);\n };\n\n return {\n getState(): DatasetState {\n return state;\n },\n dispatch(command: DatasetCommand, context: DispatchContext = {}): DatasetDispatchOutcome {\n const parsed = parseDatasetCommand(command);\n if (!parsed.ok) return { ok: false, refusal: parsed.refusal };\n const previous = state;\n const applied = applyDatasetCommand(previous.document, parsed.command);\n if (!applied.ok) return { ok: false, refusal: applied.refusal };\n // A command that returns the table at the cursor states no edit: retain the pin, the cursor,\n // the history and the subscribers rather than committing a step that changes no bytes.\n if (applied.document === previous.document) {\n return {\n ok: true,\n state: previous,\n effects: { coalesced: false, truncated: false },\n };\n }\n const checked = checkDatasetCandidate(applied.document);\n if (!checked.ok) return { ok: false, refusal: checked.refusal };\n const committed = commitHistory(\n history,\n {\n document: applied.document,\n diagnostics: shareDiagnostics(previous.diagnostics, []),\n },\n datasetCoalesceKeyOf(parsed.command),\n {\n kind: parsed.command.kind,\n summary: describeDatasetCommand(parsed.command),\n ...(context.actor === undefined ? {} : { actor: context.actor }),\n ...(context.at === undefined ? {} : { at: context.at }),\n },\n );\n history = committed.history;\n state = datasetState(history, pin);\n notify();\n return {\n ok: true,\n state,\n effects: { coalesced: committed.coalesced, truncated: committed.truncated },\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(): DatasetHistoryOutcome {\n const moved = undoHistory(history);\n if (moved === undefined) return { ok: false, reason: 'nothing_to_undo' };\n history = moved;\n state = datasetState(history, pin);\n notify();\n return { ok: true, state };\n },\n redo(): DatasetHistoryOutcome {\n const moved = redoHistory(history);\n if (moved === undefined) return { ok: false, reason: 'nothing_to_redo' };\n history = moved;\n state = datasetState(history, pin);\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"]}