@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.
- package/LICENSE +21 -0
- package/README.md +648 -2
- package/dist/cards/selectors.d.ts +70 -0
- package/dist/cards/selectors.d.ts.map +1 -0
- package/dist/cards/selectors.js +194 -0
- package/dist/cards/selectors.js.map +1 -0
- package/dist/definition.d.ts +36 -0
- package/dist/definition.d.ts.map +1 -0
- package/dist/definition.js +48 -0
- package/dist/definition.js.map +1 -0
- package/dist/evidence/cases.d.ts +44 -0
- package/dist/evidence/cases.d.ts.map +1 -0
- package/dist/evidence/cases.js +578 -0
- package/dist/evidence/cases.js.map +1 -0
- package/dist/evidence/repairs.d.ts +99 -0
- package/dist/evidence/repairs.d.ts.map +1 -0
- package/dist/evidence/repairs.js +181 -0
- package/dist/evidence/repairs.js.map +1 -0
- package/dist/evidence/summary.d.ts +35 -0
- package/dist/evidence/summary.d.ts.map +1 -0
- package/dist/evidence/summary.js +38 -0
- package/dist/evidence/summary.js.map +1 -0
- package/dist/i18n/gaps.d.ts +3 -0
- package/dist/i18n/gaps.d.ts.map +1 -0
- package/dist/i18n/gaps.js +2 -0
- package/dist/i18n/gaps.js.map +1 -0
- package/dist/i18n/message-slots.d.ts +19 -0
- package/dist/i18n/message-slots.d.ts.map +1 -0
- package/dist/i18n/message-slots.js +101 -0
- package/dist/i18n/message-slots.js.map +1 -0
- package/dist/i18n/text-locale.d.ts +13 -0
- package/dist/i18n/text-locale.d.ts.map +1 -0
- package/dist/i18n/text-locale.js +14 -0
- package/dist/i18n/text-locale.js.map +1 -0
- package/dist/i18n/translations.d.ts +56 -0
- package/dist/i18n/translations.d.ts.map +1 -0
- package/dist/i18n/translations.js +103 -0
- package/dist/i18n/translations.js.map +1 -0
- package/dist/impact/references.d.ts +143 -0
- package/dist/impact/references.d.ts.map +1 -0
- package/dist/impact/references.js +429 -0
- package/dist/impact/references.js.map +1 -0
- package/dist/index.d.ts +86 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +58 -0
- package/dist/index.js.map +1 -0
- package/dist/preview/compile-preview.d.ts +67 -0
- package/dist/preview/compile-preview.d.ts.map +1 -0
- package/dist/preview/compile-preview.js +286 -0
- package/dist/preview/compile-preview.js.map +1 -0
- package/dist/preview/handle.d.ts +119 -0
- package/dist/preview/handle.d.ts.map +1 -0
- package/dist/preview/handle.js +2 -0
- package/dist/preview/handle.js.map +1 -0
- package/dist/preview/held.d.ts +39 -0
- package/dist/preview/held.d.ts.map +1 -0
- package/dist/preview/held.js +15 -0
- package/dist/preview/held.js.map +1 -0
- package/dist/preview/measurement.d.ts +5 -0
- package/dist/preview/measurement.d.ts.map +1 -0
- package/dist/preview/measurement.js +18 -0
- package/dist/preview/measurement.js.map +1 -0
- package/dist/publish/build.d.ts +33 -0
- package/dist/publish/build.d.ts.map +1 -0
- package/dist/publish/build.js +15 -0
- package/dist/publish/build.js.map +1 -0
- package/dist/publish/diff.d.ts +208 -0
- package/dist/publish/diff.d.ts.map +1 -0
- package/dist/publish/diff.js +227 -0
- package/dist/publish/diff.js.map +1 -0
- package/dist/publish/review.d.ts +41 -0
- package/dist/publish/review.d.ts.map +1 -0
- package/dist/publish/review.js +22 -0
- package/dist/publish/review.js.map +1 -0
- package/dist/schema/dataset-input.d.ts +30 -0
- package/dist/schema/dataset-input.d.ts.map +1 -0
- package/dist/schema/dataset-input.js +58 -0
- package/dist/schema/dataset-input.js.map +1 -0
- package/dist/schema/dataset.d.ts +166 -0
- package/dist/schema/dataset.d.ts.map +1 -0
- package/dist/schema/dataset.js +281 -0
- package/dist/schema/dataset.js.map +1 -0
- package/dist/schema/declarations.d.ts +15 -0
- package/dist/schema/declarations.d.ts.map +1 -0
- package/dist/schema/declarations.js +47 -0
- package/dist/schema/declarations.js.map +1 -0
- package/dist/schema/document.d.ts +504 -0
- package/dist/schema/document.d.ts.map +1 -0
- package/dist/schema/document.js +337 -0
- package/dist/schema/document.js.map +1 -0
- package/dist/schema/error.d.ts +15 -0
- package/dist/schema/error.d.ts.map +1 -0
- package/dist/schema/error.js +18 -0
- package/dist/schema/error.js.map +1 -0
- package/dist/schema/field-id.d.ts +8 -0
- package/dist/schema/field-id.d.ts.map +1 -0
- package/dist/schema/field-id.js +47 -0
- package/dist/schema/field-id.js.map +1 -0
- package/dist/schema/layout.d.ts +118 -0
- package/dist/schema/layout.d.ts.map +1 -0
- package/dist/schema/layout.js +101 -0
- package/dist/schema/layout.js.map +1 -0
- package/dist/schema/palette.d.ts +103 -0
- package/dist/schema/palette.d.ts.map +1 -0
- package/dist/schema/palette.js +140 -0
- package/dist/schema/palette.js.map +1 -0
- package/dist/schema/read.d.ts +49 -0
- package/dist/schema/read.d.ts.map +1 -0
- package/dist/schema/read.js +942 -0
- package/dist/schema/read.js.map +1 -0
- package/dist/store/apply-dataset.d.ts +14 -0
- package/dist/store/apply-dataset.d.ts.map +1 -0
- package/dist/store/apply-dataset.js +513 -0
- package/dist/store/apply-dataset.js.map +1 -0
- package/dist/store/apply.d.ts +37 -0
- package/dist/store/apply.d.ts.map +1 -0
- package/dist/store/apply.js +2269 -0
- package/dist/store/apply.js.map +1 -0
- package/dist/store/candidate.d.ts +37 -0
- package/dist/store/candidate.d.ts.map +1 -0
- package/dist/store/candidate.js +178 -0
- package/dist/store/candidate.js.map +1 -0
- package/dist/store/commands/coverage.d.ts +58 -0
- package/dist/store/commands/coverage.d.ts.map +1 -0
- package/dist/store/commands/coverage.js +354 -0
- package/dist/store/commands/coverage.js.map +1 -0
- package/dist/store/commands/dataset.d.ts +26 -0
- package/dist/store/commands/dataset.d.ts.map +1 -0
- package/dist/store/commands/dataset.js +368 -0
- package/dist/store/commands/dataset.js.map +1 -0
- package/dist/store/commands/document.d.ts +21 -0
- package/dist/store/commands/document.d.ts.map +1 -0
- package/dist/store/commands/document.js +160 -0
- package/dist/store/commands/document.js.map +1 -0
- package/dist/store/commands/field.d.ts +32 -0
- package/dist/store/commands/field.d.ts.map +1 -0
- package/dist/store/commands/field.js +572 -0
- package/dist/store/commands/field.js.map +1 -0
- package/dist/store/commands/layout.d.ts +16 -0
- package/dist/store/commands/layout.d.ts.map +1 -0
- package/dist/store/commands/layout.js +70 -0
- package/dist/store/commands/layout.js.map +1 -0
- package/dist/store/commands/parse.d.ts +19 -0
- package/dist/store/commands/parse.d.ts.map +1 -0
- package/dist/store/commands/parse.js +328 -0
- package/dist/store/commands/parse.js.map +1 -0
- package/dist/store/commands/readers.d.ts +198 -0
- package/dist/store/commands/readers.d.ts.map +1 -0
- package/dist/store/commands/readers.js +711 -0
- package/dist/store/commands/readers.js.map +1 -0
- package/dist/store/commands/rule.d.ts +24 -0
- package/dist/store/commands/rule.d.ts.map +1 -0
- package/dist/store/commands/rule.js +379 -0
- package/dist/store/commands/rule.js.map +1 -0
- package/dist/store/commands/shapes.d.ts +900 -0
- package/dist/store/commands/shapes.d.ts.map +1 -0
- package/dist/store/commands/shapes.js +166 -0
- package/dist/store/commands/shapes.js.map +1 -0
- package/dist/store/commands/suggestions.d.ts +37 -0
- package/dist/store/commands/suggestions.d.ts.map +1 -0
- package/dist/store/commands/suggestions.js +177 -0
- package/dist/store/commands/suggestions.js.map +1 -0
- package/dist/store/commands.d.ts +16 -0
- package/dist/store/commands.d.ts.map +1 -0
- package/dist/store/commands.js +13 -0
- package/dist/store/commands.js.map +1 -0
- package/dist/store/dataset-candidate.d.ts +33 -0
- package/dist/store/dataset-candidate.d.ts.map +1 -0
- package/dist/store/dataset-candidate.js +31 -0
- package/dist/store/dataset-candidate.js.map +1 -0
- package/dist/store/dataset-pin.d.ts +93 -0
- package/dist/store/dataset-pin.d.ts.map +1 -0
- package/dist/store/dataset-pin.js +86 -0
- package/dist/store/dataset-pin.js.map +1 -0
- package/dist/store/dataset-store.d.ts +96 -0
- package/dist/store/dataset-store.d.ts.map +1 -0
- package/dist/store/dataset-store.js +112 -0
- package/dist/store/dataset-store.js.map +1 -0
- package/dist/store/history.d.ts +149 -0
- package/dist/store/history.d.ts.map +1 -0
- package/dist/store/history.js +173 -0
- package/dist/store/history.js.map +1 -0
- package/dist/store/measurement.d.ts +5 -0
- package/dist/store/measurement.d.ts.map +1 -0
- package/dist/store/measurement.js +20 -0
- package/dist/store/measurement.js.map +1 -0
- package/dist/store/notify.d.ts +11 -0
- package/dist/store/notify.d.ts.map +1 -0
- package/dist/store/notify.js +26 -0
- package/dist/store/notify.js.map +1 -0
- package/dist/store/published.d.ts +50 -0
- package/dist/store/published.d.ts.map +1 -0
- package/dist/store/published.js +27 -0
- package/dist/store/published.js.map +1 -0
- package/dist/store/refusals.d.ts +175 -0
- package/dist/store/refusals.d.ts.map +1 -0
- package/dist/store/refusals.js +160 -0
- package/dist/store/refusals.js.map +1 -0
- package/dist/store/steps.d.ts +14 -0
- package/dist/store/steps.d.ts.map +1 -0
- package/dist/store/steps.js +124 -0
- package/dist/store/steps.js.map +1 -0
- package/dist/store/store.d.ts +142 -0
- package/dist/store/store.d.ts.map +1 -0
- package/dist/store/store.js +136 -0
- package/dist/store/store.js.map +1 -0
- package/dist/store/unchanged.d.ts +12 -0
- package/dist/store/unchanged.d.ts.map +1 -0
- package/dist/store/unchanged.js +35 -0
- package/dist/store/unchanged.js.map +1 -0
- package/dist/visual/emit.d.ts +21 -0
- package/dist/visual/emit.d.ts.map +1 -0
- package/dist/visual/emit.js +133 -0
- package/dist/visual/emit.js.map +1 -0
- package/dist/visual/parse.d.ts +32 -0
- package/dist/visual/parse.d.ts.map +1 -0
- package/dist/visual/parse.js +330 -0
- package/dist/visual/parse.js.map +1 -0
- package/dist/visual/project.d.ts +40 -0
- package/dist/visual/project.d.ts.map +1 -0
- package/dist/visual/project.js +349 -0
- package/dist/visual/project.js.map +1 -0
- package/dist/visual/represent.d.ts +50 -0
- package/dist/visual/represent.d.ts.map +1 -0
- package/dist/visual/represent.js +66 -0
- package/dist/visual/represent.js.map +1 -0
- package/dist/visual/vocabulary.d.ts +121 -0
- package/dist/visual/vocabulary.d.ts.map +1 -0
- package/dist/visual/vocabulary.js +32 -0
- package/dist/visual/vocabulary.js.map +1 -0
- package/package.json +52 -3
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { compileDataset } from '@azx-pbc/axiom-compiler';
|
|
2
|
+
import { AxiomError, canonicalHash, DATASET_SCALAR_PRIMITIVES, daysFromCivil, IDENTIFIER_PATTERN, isRecord, parsePlainDate, toMoneyValue, tryDecimalString, UNIT_CODE_PATTERN, } from '@azx-pbc/axiom-runtime';
|
|
3
|
+
import { authoringRefusal, datasetDiagnosticRefusal } from '../store/refusals.js';
|
|
4
|
+
import { AuthoringError } from './error.js';
|
|
5
|
+
/** One civil date a command or the constructor states, as its own refusal names it. */
|
|
6
|
+
function civilDay(member, text) {
|
|
7
|
+
try {
|
|
8
|
+
const date = parsePlainDate(text, member);
|
|
9
|
+
return daysFromCivil(date.year, date.month, date.day);
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
throw new AuthoringError(`\`${member}\` is \`${text}\`; write a civil date that exists, as \`2026-01-31\`.`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/** The window a `data` binding states, which is half-open and therefore non-empty. */
|
|
16
|
+
function checkedWindow(effectiveFrom, effectiveTo) {
|
|
17
|
+
if (civilDay('effectiveFrom', effectiveFrom) >= civilDay('effectiveTo', effectiveTo)) {
|
|
18
|
+
throw new AuthoringError(`\`effectiveFrom\` is \`${effectiveFrom}\` and \`effectiveTo\` is \`${effectiveTo}\`; the range is half-open \`[effectiveFrom, effectiveTo)\` and must not be empty.`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** The cap a `COLLECT` policy states: the metaschema bounds it to 1–1000. */
|
|
22
|
+
function checkedCollectLimit(collectLimit) {
|
|
23
|
+
if (!Number.isSafeInteger(collectLimit) || collectLimit < 1 || collectLimit > 1000) {
|
|
24
|
+
throw new AuthoringError(`\`collectLimit\` is ${String(collectLimit)}; a \`COLLECT\` table states a whole number from 1 to 1000.`);
|
|
25
|
+
}
|
|
26
|
+
return collectLimit;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Starts a table in an explicit identity, binding and policy.
|
|
30
|
+
*
|
|
31
|
+
* The document it returns is a draft, not a table a compiler admits: a `set` has no `values` yet
|
|
32
|
+
* and a keyed table declares no `columns`, so the first `setDatasetValues` or `setDatasetColumns`
|
|
33
|
+
* is the dispatch that completes it. That is the same starting state `createEmptySchema` states,
|
|
34
|
+
* and the store reports what the compiler says about it rather than inventing a default domain.
|
|
35
|
+
*/
|
|
36
|
+
export function createDatasetTable(options) {
|
|
37
|
+
const { tableId, tableVersion } = options;
|
|
38
|
+
if (!IDENTIFIER_PATTERN.test(tableId)) {
|
|
39
|
+
throw new AuthoringError(`\`tableId\` is \`${tableId}\`; write a lower-case identifier: a letter first, then up to 63 lower-case letters, digits or underscores.`);
|
|
40
|
+
}
|
|
41
|
+
if (!Number.isSafeInteger(tableVersion) || tableVersion < 1) {
|
|
42
|
+
throw new AuthoringError(`\`tableVersion\` is ${String(tableVersion)}; write a positive whole number.`);
|
|
43
|
+
}
|
|
44
|
+
const identity = { tableId, tableVersion };
|
|
45
|
+
const binding = options.binding === 'data'
|
|
46
|
+
? {
|
|
47
|
+
binding: 'data',
|
|
48
|
+
effectiveFrom: options.effectiveFrom,
|
|
49
|
+
effectiveTo: options.effectiveTo,
|
|
50
|
+
}
|
|
51
|
+
: { binding: 'behavior' };
|
|
52
|
+
if (binding.binding === 'data')
|
|
53
|
+
checkedWindow(binding.effectiveFrom, binding.effectiveTo);
|
|
54
|
+
if (options.kind === 'set') {
|
|
55
|
+
return { ...identity, ...binding, kind: 'set', values: [] };
|
|
56
|
+
}
|
|
57
|
+
const policy = options.hitPolicy === 'COLLECT'
|
|
58
|
+
? { hitPolicy: 'COLLECT', collectLimit: checkedCollectLimit(options.collectLimit) }
|
|
59
|
+
: { hitPolicy: options.hitPolicy };
|
|
60
|
+
return { ...identity, ...binding, ...policy, kind: options.kind, columns: [], rows: [] };
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The restricted-JCS SHA-256 of the document, `DATA-4.1.2`.
|
|
64
|
+
*
|
|
65
|
+
* This is the digest an artifact pins and a resolution records. The authored document states the
|
|
66
|
+
* metaschema's own members, so the hash is computed over the document itself by the one canonical
|
|
67
|
+
* authority in the repository rather than a second serializer.
|
|
68
|
+
*/
|
|
69
|
+
export function datasetDigest(document) {
|
|
70
|
+
return canonicalHash(document);
|
|
71
|
+
}
|
|
72
|
+
function unreadable(detail) {
|
|
73
|
+
return { ok: false, refusal: authoringRefusal('INVALID_STRUCTURE', '$', detail) };
|
|
74
|
+
}
|
|
75
|
+
/** One wire cell as a dataset scalar, or `undefined` when it is outside the scalar set. */
|
|
76
|
+
function scalarCell(value) {
|
|
77
|
+
return value !== undefined && isDatasetScalar(value) ? value : undefined;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* A measured quantity as a dataset scalar states it, `MODEL-2.1.21`.
|
|
81
|
+
*
|
|
82
|
+
* The dataset declares no unit domain on a column, so the value carries its own unit and the
|
|
83
|
+
* metaschema checks the pair's spelling only: canonical decimal text and a lower-case unit code.
|
|
84
|
+
* The member set is closed, because `unevaluatedProperties: false` is the contract's.
|
|
85
|
+
*/
|
|
86
|
+
export function isQuantityValue(value) {
|
|
87
|
+
if (!isRecord(value))
|
|
88
|
+
return false;
|
|
89
|
+
const keys = Object.keys(value);
|
|
90
|
+
if (keys.length !== 2 || !Object.hasOwn(value, 'value') || !Object.hasOwn(value, 'unit')) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
const text = value['value'];
|
|
94
|
+
const unit = value['unit'];
|
|
95
|
+
return (typeof text === 'string' &&
|
|
96
|
+
tryDecimalString(text) !== undefined &&
|
|
97
|
+
typeof unit === 'string' &&
|
|
98
|
+
UNIT_CODE_PATTERN.test(unit));
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Whether a value is a dataset scalar, `spec/metaschema/dataset.v1.json` `$defs/scalar`.
|
|
102
|
+
*
|
|
103
|
+
* The runtime decides this for its own store, but the predicate is not on its public entry; the
|
|
104
|
+
* decision is restated here through the runtime's own money reader, so a value the wire boundary
|
|
105
|
+
* refuses as money is refused here too. Anything that is not an `AxiomError` is a programmer error
|
|
106
|
+
* in the reader and is rethrown rather than reported as "not a scalar".
|
|
107
|
+
*/
|
|
108
|
+
export function isDatasetScalar(value) {
|
|
109
|
+
if (typeof value === 'string' || typeof value === 'boolean')
|
|
110
|
+
return true;
|
|
111
|
+
if (typeof value === 'number')
|
|
112
|
+
return Number.isSafeInteger(value) && !Object.is(value, -0);
|
|
113
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
114
|
+
return false;
|
|
115
|
+
try {
|
|
116
|
+
toMoneyValue(value);
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
catch (cause) {
|
|
120
|
+
if (!(cause instanceof AxiomError))
|
|
121
|
+
throw cause;
|
|
122
|
+
return isQuantityValue(value);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function outputRecord(output) {
|
|
126
|
+
const members = [];
|
|
127
|
+
for (const [name, value] of Object.entries(output)) {
|
|
128
|
+
const cell = scalarCell(value);
|
|
129
|
+
if (cell === undefined)
|
|
130
|
+
return undefined;
|
|
131
|
+
members.push([name, cell]);
|
|
132
|
+
}
|
|
133
|
+
// Define own properties rather than assigning them, so a `__proto__` member stays data.
|
|
134
|
+
return Object.fromEntries(members);
|
|
135
|
+
}
|
|
136
|
+
function loadedRow(row) {
|
|
137
|
+
const key = [];
|
|
138
|
+
for (const value of row.key) {
|
|
139
|
+
const cell = scalarCell(value);
|
|
140
|
+
if (cell === undefined)
|
|
141
|
+
return undefined;
|
|
142
|
+
key.push(cell);
|
|
143
|
+
}
|
|
144
|
+
return key;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* The authored document a `dataset.v1.json` states, or the reason the compiler refuses it.
|
|
148
|
+
*
|
|
149
|
+
* The compiler is the door: its restricted-JSON ingestion, closed metaschema and semantic checks
|
|
150
|
+
* run before this walk, so an accepted document is one an editable store can hold. The walk then
|
|
151
|
+
* states the closed shape as the authored union — the two conditional facts the metaschema cannot
|
|
152
|
+
* express as a type are checked here, and a disagreement is a refusal rather than a cast.
|
|
153
|
+
*/
|
|
154
|
+
export function readDatasetDocument(source) {
|
|
155
|
+
const compiled = compileDataset({ format: 'json', text: source });
|
|
156
|
+
if (!compiled.ok) {
|
|
157
|
+
const first = compiled.diagnostics[0];
|
|
158
|
+
if (first === undefined)
|
|
159
|
+
return unreadable('the dataset compiler refused the text and stated no reason');
|
|
160
|
+
return { ok: false, refusal: datasetDiagnosticRefusal(first) };
|
|
161
|
+
}
|
|
162
|
+
const table = compiled.dataset.document;
|
|
163
|
+
const identity = {
|
|
164
|
+
tableId: table.tableId,
|
|
165
|
+
tableVersion: table.tableVersion,
|
|
166
|
+
};
|
|
167
|
+
const binding = table.binding === 'data'
|
|
168
|
+
? table.effectiveFrom === undefined || table.effectiveTo === undefined
|
|
169
|
+
? undefined
|
|
170
|
+
: { binding: 'data', effectiveFrom: table.effectiveFrom, effectiveTo: table.effectiveTo }
|
|
171
|
+
: { binding: 'behavior' };
|
|
172
|
+
if (binding === undefined) {
|
|
173
|
+
return unreadable(`table ${table.tableId} binds to \`data\` and states no effective range; the compiler's metaschema admitted it, which is a disagreement between the two`);
|
|
174
|
+
}
|
|
175
|
+
if (table.kind === 'set') {
|
|
176
|
+
const values = [];
|
|
177
|
+
for (const value of table.values ?? []) {
|
|
178
|
+
const cell = scalarCell(value);
|
|
179
|
+
if (cell === undefined)
|
|
180
|
+
return unreadable(`table ${table.tableId} states a non-scalar membership value`);
|
|
181
|
+
values.push(cell);
|
|
182
|
+
}
|
|
183
|
+
return { ok: true, document: { ...identity, ...binding, kind: 'set', values } };
|
|
184
|
+
}
|
|
185
|
+
const columns = table.columns;
|
|
186
|
+
const compiledRows = table.rows;
|
|
187
|
+
const hitPolicy = table.hitPolicy;
|
|
188
|
+
if (columns === undefined || compiledRows === undefined || hitPolicy === undefined) {
|
|
189
|
+
return unreadable(`table ${table.tableId} is a \`${table.kind}\` and states no columns, rows or hit policy; the compiled document must carry all three`);
|
|
190
|
+
}
|
|
191
|
+
const policy = hitPolicyFrom(table.collectLimit, hitPolicy);
|
|
192
|
+
if (policy === undefined) {
|
|
193
|
+
return unreadable(`table ${table.tableId} states \`collectLimit\` ${String(table.collectLimit)} for \`${hitPolicy}\`; only \`COLLECT\` states a cap and it states one`);
|
|
194
|
+
}
|
|
195
|
+
if (table.kind === 'lookup') {
|
|
196
|
+
const rows = lookupRows(compiledRows);
|
|
197
|
+
if (rows === undefined) {
|
|
198
|
+
return unreadable(`table ${table.tableId} states a row outside the lookup contract: every lookup row carries an output and no outcome`);
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
ok: true,
|
|
202
|
+
document: {
|
|
203
|
+
...identity,
|
|
204
|
+
...binding,
|
|
205
|
+
...policy,
|
|
206
|
+
kind: 'lookup',
|
|
207
|
+
columns,
|
|
208
|
+
rows,
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
const rows = decisionRows(compiledRows);
|
|
213
|
+
if (rows === undefined) {
|
|
214
|
+
return unreadable(`table ${table.tableId} states a row outside the decision-table contract: every row carries an outcome, and a PASS row also carries an output`);
|
|
215
|
+
}
|
|
216
|
+
return {
|
|
217
|
+
ok: true,
|
|
218
|
+
document: { ...identity, ...binding, ...policy, kind: 'decision_table', columns, rows },
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
function hitPolicyFrom(collectLimit, hitPolicy) {
|
|
222
|
+
if (hitPolicy === 'COLLECT') {
|
|
223
|
+
return collectLimit === undefined ? undefined : { hitPolicy, collectLimit };
|
|
224
|
+
}
|
|
225
|
+
return collectLimit === undefined ? { hitPolicy } : undefined;
|
|
226
|
+
}
|
|
227
|
+
function lookupRows(rows) {
|
|
228
|
+
const loaded = [];
|
|
229
|
+
for (const row of rows) {
|
|
230
|
+
if (row.outcome !== undefined || row.output === undefined)
|
|
231
|
+
return undefined;
|
|
232
|
+
const key = loadedRow(row);
|
|
233
|
+
const output = outputRecord(row.output);
|
|
234
|
+
if (key === undefined || output === undefined)
|
|
235
|
+
return undefined;
|
|
236
|
+
loaded.push({ rowId: row.rowId, key, output });
|
|
237
|
+
}
|
|
238
|
+
return loaded;
|
|
239
|
+
}
|
|
240
|
+
function decisionRows(rows) {
|
|
241
|
+
const loaded = [];
|
|
242
|
+
for (const row of rows) {
|
|
243
|
+
if (row.outcome === undefined)
|
|
244
|
+
return undefined;
|
|
245
|
+
const key = loadedRow(row);
|
|
246
|
+
if (key === undefined)
|
|
247
|
+
return undefined;
|
|
248
|
+
const output = row.output === undefined ? undefined : outputRecord(row.output);
|
|
249
|
+
if (row.output !== undefined && output === undefined)
|
|
250
|
+
return undefined;
|
|
251
|
+
if (row.outcome === 'PASS') {
|
|
252
|
+
if (output === undefined)
|
|
253
|
+
return undefined;
|
|
254
|
+
loaded.push({ rowId: row.rowId, key, outcome: 'PASS', output });
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
loaded.push({
|
|
258
|
+
rowId: row.rowId,
|
|
259
|
+
key,
|
|
260
|
+
outcome: row.outcome,
|
|
261
|
+
...(output === undefined ? {} : { output }),
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
return loaded;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* The primitives a dataset column may declare, from the runtime's one registry.
|
|
268
|
+
*
|
|
269
|
+
* A dataset scalar is the runtime's vocabulary (`DATASET_SCALAR_PRIMITIVES`, derived from the
|
|
270
|
+
* metaschema enum), not a list this package maintains: a record or an array is never a column,
|
|
271
|
+
* and `quantity` is a scalar a column may declare. The store's cell kinds read the same registry,
|
|
272
|
+
* so a host can write every column the compiler admits.
|
|
273
|
+
*/
|
|
274
|
+
export const DATASET_PRIMITIVES = DATASET_SCALAR_PRIMITIVES;
|
|
275
|
+
/** The roles a column states, `DATA-1.2.2`. */
|
|
276
|
+
export const DATASET_COLUMN_ROLES = ['key', 'output'];
|
|
277
|
+
/** The hit policies the closed contract enumerates. */
|
|
278
|
+
export const DATASET_HIT_POLICIES = ['UNIQUE', 'FIRST', 'COLLECT'];
|
|
279
|
+
/** The outcomes a decision row states. */
|
|
280
|
+
export const DATASET_OUTCOMES = ['PASS', 'FAIL', 'UNKNOWN', 'DEFERRED'];
|
|
281
|
+
//# sourceMappingURL=dataset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataset.js","sourceRoot":"","sources":["../../src/schema/dataset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,EACL,UAAU,EACV,aAAa,EACb,yBAAyB,EACzB,aAAa,EACb,kBAAkB,EAClB,QAAQ,EACR,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,wBAAwB,CAAC;AAUhC,OAAO,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAElF,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAoH5C,uFAAuF;AACvF,SAAS,QAAQ,CAAC,MAAc,EAAE,IAAY;IAC5C,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC1C,OAAO,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IACxD,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,cAAc,CACtB,KAAK,MAAM,WAAW,IAAI,wDAAwD,CACnF,CAAC;IACJ,CAAC;AACH,CAAC;AAED,sFAAsF;AACtF,SAAS,aAAa,CAAC,aAAqB,EAAE,WAAmB;IAC/D,IAAI,QAAQ,CAAC,e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["import { compileDataset } from '@azx-pbc/axiom-compiler';\nimport type { DatasetDiagnostic } from '@azx-pbc/axiom-compiler';\nimport {\n AxiomError,\n canonicalHash,\n DATASET_SCALAR_PRIMITIVES,\n daysFromCivil,\n IDENTIFIER_PATTERN,\n isRecord,\n parsePlainDate,\n toMoneyValue,\n tryDecimalString,\n UNIT_CODE_PATTERN,\n} from '@azx-pbc/axiom-runtime';\nimport type {\n DatasetColumn,\n HitPolicy,\n LookupRow,\n Outcome,\n QuantityValue,\n ScalarWireValue,\n WireValue,\n} from '@azx-pbc/axiom-runtime';\nimport { authoringRefusal, datasetDiagnosticRefusal } from '../store/refusals.js';\nimport type { AuthoringRefusal } from '../store/refusals.js';\nimport { AuthoringError } from './error.js';\n\n/**\n * The authored dataset document, as an authoring store holds it.\n *\n * It is `spec/metaschema/dataset.v1.json` in the author's own state: the table's identity, its\n * clock binding, its kind and — for a keyed table — the declared columns, the rows and the hit\n * policy. The shape is the closed contract rather than a second one, and the two facts the\n * metaschema states conditionally are stated by the type instead of left to a runtime check:\n *\n * - a `data` table carries `[effectiveFrom, effectiveTo)` and a `behavior` table carries no range\n * at all (`DATA-2.1.2`, `DATA-2.1.3`), so the binding is a discriminated union;\n * - `COLLECT` carries its `collectLimit` and the other policies carry none (`DATA-3.1.5`);\n * - a `PASS` decision row carries its `output` and a lookup row carries no `outcome`\n * (`DATA-1.2.4`).\n *\n * A value no state of the contract admits is therefore unrepresentable here, and the compiler's\n * own dataset stage is the candidate gate the store holds every rewrite to.\n */\n\n/** The identity every table states, `DATA-1.1.1`. */\nexport interface AuthoredDatasetIdentity {\n readonly tableId: string;\n readonly tableVersion: number;\n}\n\n/** Which clock a table binds to, and the half-open window a `data` table must declare. */\nexport type AuthoredDatasetBinding =\n | { readonly binding: 'behavior' }\n | {\n readonly binding: 'data';\n /** The first civil date the table answers for, inclusive. */\n readonly effectiveFrom: string;\n /** The first civil date it no longer answers for, exclusive. */\n readonly effectiveTo: string;\n };\n\n/** The hit policy a keyed table resolves with, and the cap `COLLECT` must state. */\nexport type AuthoredHitPolicy =\n | { readonly hitPolicy: 'UNIQUE' }\n | { readonly hitPolicy: 'FIRST' }\n | { readonly hitPolicy: 'COLLECT'; readonly collectLimit: number };\n\n/** One lookup row: a composite key and the output every hit returns. */\nexport interface AuthoredLookupRow {\n readonly rowId: string;\n /** One scalar per key column, in declaration order. */\n readonly key: readonly ScalarWireValue[];\n readonly output: Readonly<Record<string, ScalarWireValue>>;\n}\n\n/**\n * One decision-table row.\n *\n * A `PASS` row states an output because it is the row that decides a result; another verdict may\n * carry one, because the metaschema admits it, but need not.\n */\nexport type AuthoredDecisionRow =\n | {\n readonly rowId: string;\n readonly key: readonly ScalarWireValue[];\n readonly outcome: 'PASS';\n readonly output: Readonly<Record<string, ScalarWireValue>>;\n }\n | {\n readonly rowId: string;\n readonly key: readonly ScalarWireValue[];\n readonly outcome: Exclude<Outcome, 'PASS'>;\n readonly output?: Readonly<Record<string, ScalarWireValue>>;\n };\n\n/** A `set` table: its closed membership domain and nothing else (`DATA-1.2.1`). */\nexport type AuthoredSetTable = AuthoredDatasetIdentity &\n AuthoredDatasetBinding & {\n readonly kind: 'set';\n readonly values: readonly ScalarWireValue[];\n };\n\n/** A keyed table that resolves without a verdict: every row carries an output. */\nexport type AuthoredLookupTable = AuthoredDatasetIdentity &\n AuthoredDatasetBinding &\n AuthoredHitPolicy & {\n readonly kind: 'lookup';\n readonly columns: readonly DatasetColumn[];\n readonly rows: readonly AuthoredLookupRow[];\n };\n\n/** A keyed table whose rows state a verdict. */\nexport type AuthoredDecisionTable = AuthoredDatasetIdentity &\n AuthoredDatasetBinding &\n AuthoredHitPolicy & {\n readonly kind: 'decision_table';\n readonly columns: readonly DatasetColumn[];\n readonly rows: readonly AuthoredDecisionRow[];\n };\n\n/** Every dataset document the authoring store holds. */\nexport type AuthoredDatasetDocument =\n | AuthoredSetTable\n | AuthoredLookupTable\n | AuthoredDecisionTable;\n\n/**\n * What a caller states to start a table.\n *\n * The kind, the clock binding and the hit policy are design decisions, so they are constructor\n * arguments rather than edits: a published table's policy is part of what its rows mean, and\n * `binding` decides whether a range exists at all. The `set` arm states no policy because a set has\n * no rows to resolve; the keyed arm must state one.\n */\nexport type CreateDatasetOptions = AuthoredDatasetIdentity &\n (\n | ({ readonly kind: 'set' } & AuthoredDatasetBinding)\n | ({ readonly kind: 'lookup' | 'decision_table' } & AuthoredDatasetBinding & AuthoredHitPolicy)\n );\n\n/** One civil date a command or the constructor states, as its own refusal names it. */\nfunction civilDay(member: string, text: string): number {\n try {\n const date = parsePlainDate(text, member);\n return daysFromCivil(date.year, date.month, date.day);\n } catch {\n throw new AuthoringError(\n `\\`${member}\\` is \\`${text}\\`; write a civil date that exists, as \\`2026-01-31\\`.`,\n );\n }\n}\n\n/** The window a `data` binding states, which is half-open and therefore non-empty. */\nfunction checkedWindow(effectiveFrom: string, effectiveTo: string): void {\n if (civilDay('effectiveFrom', effectiveFrom) >= civilDay('effectiveTo', effectiveTo)) {\n throw new AuthoringError(\n `\\`effectiveFrom\\` is \\`${effectiveFrom}\\` and \\`effectiveTo\\` is \\`${effectiveTo}\\`; the range is half-open \\`[effectiveFrom, effectiveTo)\\` and must not be empty.`,\n );\n }\n}\n\n/** The cap a `COLLECT` policy states: the metaschema bounds it to 1–1000. */\nfunction checkedCollectLimit(collectLimit: number): number {\n if (!Number.isSafeInteger(collectLimit) || collectLimit < 1 || collectLimit > 1000) {\n throw new AuthoringError(\n `\\`collectLimit\\` is ${String(collectLimit)}; a \\`COLLECT\\` table states a whole number from 1 to 1000.`,\n );\n }\n return collectLimit;\n}\n\n/**\n * Starts a table in an explicit identity, binding and policy.\n *\n * The document it returns is a draft, not a table a compiler admits: a `set` has no `values` yet\n * and a keyed table declares no `columns`, so the first `setDatasetValues` or `setDatasetColumns`\n * is the dispatch that completes it. That is the same starting state `createEmptySchema` states,\n * and the store reports what the compiler says about it rather than inventing a default domain.\n */\nexport function createDatasetTable(options: CreateDatasetOptions): AuthoredDatasetDocument {\n const { tableId, tableVersion } = options;\n if (!IDENTIFIER_PATTERN.test(tableId)) {\n throw new AuthoringError(\n `\\`tableId\\` is \\`${tableId}\\`; write a lower-case identifier: a letter first, then up to 63 lower-case letters, digits or underscores.`,\n );\n }\n if (!Number.isSafeInteger(tableVersion) || tableVersion < 1) {\n throw new AuthoringError(\n `\\`tableVersion\\` is ${String(tableVersion)}; write a positive whole number.`,\n );\n }\n const identity: AuthoredDatasetIdentity = { tableId, tableVersion };\n const binding: AuthoredDatasetBinding =\n options.binding === 'data'\n ? {\n binding: 'data',\n effectiveFrom: options.effectiveFrom,\n effectiveTo: options.effectiveTo,\n }\n : { binding: 'behavior' };\n if (binding.binding === 'data') checkedWindow(binding.effectiveFrom, binding.effectiveTo);\n if (options.kind === 'set') {\n return { ...identity, ...binding, kind: 'set', values: [] };\n }\n const policy: AuthoredHitPolicy =\n options.hitPolicy === 'COLLECT'\n ? { hitPolicy: 'COLLECT', collectLimit: checkedCollectLimit(options.collectLimit) }\n : { hitPolicy: options.hitPolicy };\n return { ...identity, ...binding, ...policy, kind: options.kind, columns: [], rows: [] };\n}\n\n/**\n * The restricted-JCS SHA-256 of the document, `DATA-4.1.2`.\n *\n * This is the digest an artifact pins and a resolution records. The authored document states the\n * metaschema's own members, so the hash is computed over the document itself by the one canonical\n * authority in the repository rather than a second serializer.\n */\nexport function datasetDigest(document: AuthoredDatasetDocument): string {\n return canonicalHash(document);\n}\n\n/** One loaded dataset document, or the reason the text is not one. */\nexport type DatasetDocumentRead =\n | { readonly ok: true; readonly document: AuthoredDatasetDocument }\n | { readonly ok: false; readonly refusal: AuthoringRefusal };\n\nfunction unreadable(detail: string): DatasetDocumentRead {\n return { ok: false, refusal: authoringRefusal('INVALID_STRUCTURE', '$', detail) };\n}\n\n/** One wire cell as a dataset scalar, or `undefined` when it is outside the scalar set. */\nfunction scalarCell(value: WireValue | undefined): ScalarWireValue | undefined {\n return value !== undefined && isDatasetScalar(value) ? value : undefined;\n}\n\n/**\n * A measured quantity as a dataset scalar states it, `MODEL-2.1.21`.\n *\n * The dataset declares no unit domain on a column, so the value carries its own unit and the\n * metaschema checks the pair's spelling only: canonical decimal text and a lower-case unit code.\n * The member set is closed, because `unevaluatedProperties: false` is the contract's.\n */\nexport function isQuantityValue(value: unknown): value is QuantityValue {\n if (!isRecord(value)) return false;\n const keys = Object.keys(value);\n if (keys.length !== 2 || !Object.hasOwn(value, 'value') || !Object.hasOwn(value, 'unit')) {\n return false;\n }\n const text = value['value'];\n const unit = value['unit'];\n return (\n typeof text === 'string' &&\n tryDecimalString(text) !== undefined &&\n typeof unit === 'string' &&\n UNIT_CODE_PATTERN.test(unit)\n );\n}\n\n/**\n * Whether a value is a dataset scalar, `spec/metaschema/dataset.v1.json` `$defs/scalar`.\n *\n * The runtime decides this for its own store, but the predicate is not on its public entry; the\n * decision is restated here through the runtime's own money reader, so a value the wire boundary\n * refuses as money is refused here too. Anything that is not an `AxiomError` is a programmer error\n * in the reader and is rethrown rather than reported as \"not a scalar\".\n */\nexport function isDatasetScalar(value: unknown): value is ScalarWireValue {\n if (typeof value === 'string' || typeof value === 'boolean') return true;\n if (typeof value === 'number') return Number.isSafeInteger(value) && !Object.is(value, -0);\n if (typeof value !== 'object' || value === null || Array.isArray(value)) return false;\n try {\n toMoneyValue(value);\n return true;\n } catch (cause) {\n if (!(cause instanceof AxiomError)) throw cause;\n return isQuantityValue(value);\n }\n}\n\nfunction outputRecord(\n output: Readonly<Record<string, WireValue>>,\n): Readonly<Record<string, ScalarWireValue>> | undefined {\n const members: [string, ScalarWireValue][] = [];\n for (const [name, value] of Object.entries(output)) {\n const cell = scalarCell(value);\n if (cell === undefined) return undefined;\n members.push([name, cell]);\n }\n // Define own properties rather than assigning them, so a `__proto__` member stays data.\n return Object.fromEntries(members);\n}\n\nfunction loadedRow(row: {\n readonly rowId: string;\n readonly key: readonly WireValue[];\n}): readonly ScalarWireValue[] | undefined {\n const key: ScalarWireValue[] = [];\n for (const value of row.key) {\n const cell = scalarCell(value);\n if (cell === undefined) return undefined;\n key.push(cell);\n }\n return key;\n}\n\n/**\n * The authored document a `dataset.v1.json` states, or the reason the compiler refuses it.\n *\n * The compiler is the door: its restricted-JSON ingestion, closed metaschema and semantic checks\n * run before this walk, so an accepted document is one an editable store can hold. The walk then\n * states the closed shape as the authored union — the two conditional facts the metaschema cannot\n * express as a type are checked here, and a disagreement is a refusal rather than a cast.\n */\nexport function readDatasetDocument(source: string): DatasetDocumentRead {\n const compiled = compileDataset({ format: 'json', text: source });\n if (!compiled.ok) {\n const first: DatasetDiagnostic | undefined = compiled.diagnostics[0];\n if (first === undefined)\n return unreadable('the dataset compiler refused the text and stated no reason');\n return { ok: false, refusal: datasetDiagnosticRefusal(first) };\n }\n const table = compiled.dataset.document;\n const identity: AuthoredDatasetIdentity = {\n tableId: table.tableId,\n tableVersion: table.tableVersion,\n };\n const binding: AuthoredDatasetBinding | undefined =\n table.binding === 'data'\n ? table.effectiveFrom === undefined || table.effectiveTo === undefined\n ? undefined\n : { binding: 'data', effectiveFrom: table.effectiveFrom, effectiveTo: table.effectiveTo }\n : { binding: 'behavior' };\n if (binding === undefined) {\n return unreadable(\n `table ${table.tableId} binds to \\`data\\` and states no effective range; the compiler's metaschema admitted it, which is a disagreement between the two`,\n );\n }\n if (table.kind === 'set') {\n const values: ScalarWireValue[] = [];\n for (const value of table.values ?? []) {\n const cell = scalarCell(value);\n if (cell === undefined)\n return unreadable(`table ${table.tableId} states a non-scalar membership value`);\n values.push(cell);\n }\n return { ok: true, document: { ...identity, ...binding, kind: 'set', values } };\n }\n const columns = table.columns;\n const compiledRows = table.rows;\n const hitPolicy = table.hitPolicy;\n if (columns === undefined || compiledRows === undefined || hitPolicy === undefined) {\n return unreadable(\n `table ${table.tableId} is a \\`${table.kind}\\` and states no columns, rows or hit policy; the compiled document must carry all three`,\n );\n }\n const policy: AuthoredHitPolicy | undefined = hitPolicyFrom(table.collectLimit, hitPolicy);\n if (policy === undefined) {\n return unreadable(\n `table ${table.tableId} states \\`collectLimit\\` ${String(table.collectLimit)} for \\`${hitPolicy}\\`; only \\`COLLECT\\` states a cap and it states one`,\n );\n }\n if (table.kind === 'lookup') {\n const rows = lookupRows(compiledRows);\n if (rows === undefined) {\n return unreadable(\n `table ${table.tableId} states a row outside the lookup contract: every lookup row carries an output and no outcome`,\n );\n }\n return {\n ok: true,\n document: {\n ...identity,\n ...binding,\n ...policy,\n kind: 'lookup',\n columns,\n rows,\n },\n };\n }\n const rows = decisionRows(compiledRows);\n if (rows === undefined) {\n return unreadable(\n `table ${table.tableId} states a row outside the decision-table contract: every row carries an outcome, and a PASS row also carries an output`,\n );\n }\n return {\n ok: true,\n document: { ...identity, ...binding, ...policy, kind: 'decision_table', columns, rows },\n };\n}\n\nfunction hitPolicyFrom(\n collectLimit: number | undefined,\n hitPolicy: HitPolicy,\n): AuthoredHitPolicy | undefined {\n if (hitPolicy === 'COLLECT') {\n return collectLimit === undefined ? undefined : { hitPolicy, collectLimit };\n }\n return collectLimit === undefined ? { hitPolicy } : undefined;\n}\n\nfunction lookupRows(rows: readonly LookupRow[]): readonly AuthoredLookupRow[] | undefined {\n const loaded: AuthoredLookupRow[] = [];\n for (const row of rows) {\n if (row.outcome !== undefined || row.output === undefined) return undefined;\n const key = loadedRow(row);\n const output = outputRecord(row.output);\n if (key === undefined || output === undefined) return undefined;\n loaded.push({ rowId: row.rowId, key, output });\n }\n return loaded;\n}\n\nfunction decisionRows(rows: readonly LookupRow[]): readonly AuthoredDecisionRow[] | undefined {\n const loaded: AuthoredDecisionRow[] = [];\n for (const row of rows) {\n if (row.outcome === undefined) return undefined;\n const key = loadedRow(row);\n if (key === undefined) return undefined;\n const output = row.output === undefined ? undefined : outputRecord(row.output);\n if (row.output !== undefined && output === undefined) return undefined;\n if (row.outcome === 'PASS') {\n if (output === undefined) return undefined;\n loaded.push({ rowId: row.rowId, key, outcome: 'PASS', output });\n continue;\n }\n loaded.push({\n rowId: row.rowId,\n key,\n outcome: row.outcome,\n ...(output === undefined ? {} : { output }),\n });\n }\n return loaded;\n}\n\n/**\n * The primitives a dataset column may declare, from the runtime's one registry.\n *\n * A dataset scalar is the runtime's vocabulary (`DATASET_SCALAR_PRIMITIVES`, derived from the\n * metaschema enum), not a list this package maintains: a record or an array is never a column,\n * and `quantity` is a scalar a column may declare. The store's cell kinds read the same registry,\n * so a host can write every column the compiler admits.\n */\nexport const DATASET_PRIMITIVES: readonly DatasetColumn['primitive'][] = DATASET_SCALAR_PRIMITIVES;\n\n/** The roles a column states, `DATA-1.2.2`. */\nexport const DATASET_COLUMN_ROLES: readonly DatasetColumn['role'][] = ['key', 'output'];\n\n/** The hit policies the closed contract enumerates. */\nexport const DATASET_HIT_POLICIES: readonly HitPolicy[] = ['UNIQUE', 'FIRST', 'COLLECT'];\n\n/** The outcomes a decision row states. */\nexport const DATASET_OUTCOMES: readonly Outcome[] = ['PASS', 'FAIL', 'UNKNOWN', 'DEFERRED'];\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { RecordIndex } from '@azx-pbc/axiom-runtime';
|
|
2
|
+
import type { AuthoringDocument } from './document.js';
|
|
3
|
+
/**
|
|
4
|
+
* The index a draft's expressions are read against.
|
|
5
|
+
*
|
|
6
|
+
* A draft may not compile, so the index is derived from the declarations it holds rather than
|
|
7
|
+
* from an artifact. It is the runtime's own reader index — the fields by dotted path and the
|
|
8
|
+
* context roots a path may name — so a projection, an impact report and an evaluation resolve a
|
|
9
|
+
* path to the same declaration instead of each carrying a resolver.
|
|
10
|
+
*
|
|
11
|
+
* The root set carries the reserved `record_date` and `schema_version` the runtime always
|
|
12
|
+
* resolves, so a rule may read `context.record_date` without the document declaring it.
|
|
13
|
+
*/
|
|
14
|
+
export declare function documentIndex(document: AuthoringDocument): RecordIndex;
|
|
15
|
+
//# sourceMappingURL=declarations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declarations.d.ts","sourceRoot":"","sources":["../../src/schema/declarations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA8B,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACtF,OAAO,KAAK,EAAE,iBAAiB,EAAmC,MAAM,eAAe,CAAC;AAmCxF;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,iBAAiB,GAAG,WAAW,CAEtE"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { recordIndexFromDeclarations } from '@azx-pbc/axiom-runtime';
|
|
2
|
+
/**
|
|
3
|
+
* One authored option as the index reads it.
|
|
4
|
+
*
|
|
5
|
+
* The index decides which codes a field's domain offers and what each one's label is; a code's
|
|
6
|
+
* availability, its reason and its alternatives are decided at evaluation, so they are dropped here
|
|
7
|
+
* rather than forcing the authored source text and the compiled AST into one type (see
|
|
8
|
+
* `indexableField` for the same split on `rowsFrom`).
|
|
9
|
+
*/
|
|
10
|
+
function indexableOption(option) {
|
|
11
|
+
return {
|
|
12
|
+
code: option.code,
|
|
13
|
+
labelKey: option.labelKey,
|
|
14
|
+
...(option.deprecated === undefined ? {} : { deprecated: option.deprecated }),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* One authored declaration as the index reads it.
|
|
19
|
+
*
|
|
20
|
+
* A draft's `rowsFrom` is the Expr v1 source an author wrote, while the artifact's `rowsFrom` is
|
|
21
|
+
* the AST the compiler derives from it; the reader index never consults the member, so it is
|
|
22
|
+
* dropped here rather than forcing the two representations into one type. Every other member is
|
|
23
|
+
* shared with the compiled declaration.
|
|
24
|
+
*/
|
|
25
|
+
function indexableField(field) {
|
|
26
|
+
const { rowsFrom: _rowsFrom, fields: members, options, ...rest } = field;
|
|
27
|
+
return {
|
|
28
|
+
...rest,
|
|
29
|
+
...(options === undefined ? {} : { options: options.map(indexableOption) }),
|
|
30
|
+
...(members === undefined ? {} : { fields: members.map(indexableField) }),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The index a draft's expressions are read against.
|
|
35
|
+
*
|
|
36
|
+
* A draft may not compile, so the index is derived from the declarations it holds rather than
|
|
37
|
+
* from an artifact. It is the runtime's own reader index — the fields by dotted path and the
|
|
38
|
+
* context roots a path may name — so a projection, an impact report and an evaluation resolve a
|
|
39
|
+
* path to the same declaration instead of each carrying a resolver.
|
|
40
|
+
*
|
|
41
|
+
* The root set carries the reserved `record_date` and `schema_version` the runtime always
|
|
42
|
+
* resolves, so a rule may read `context.record_date` without the document declaring it.
|
|
43
|
+
*/
|
|
44
|
+
export function documentIndex(document) {
|
|
45
|
+
return recordIndexFromDeclarations(document.fields.map(indexableField), document.context?.roots);
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=declarations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declarations.js","sourceRoot":"","sources":["../../src/schema/declarations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAIrE;;;;;;;GAOG;AACH,SAAS,eAAe,CAAC,MAAuB;IAC9C,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,GAAG,CAAC,MAAM,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC;KAC9E,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,cAAc,CAAC,KAAqB;IAC3C,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;IACzE,OAAO;QACL,GAAG,IAAI;QACP,GAAG,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,CAAC;QAC3E,GAAG,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,CAAC;KAC1E,CAAC;AACJ,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,aAAa,CAAC,QAA2B;IACvD,OAAO,2BAA2B,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AACnG,CAAC","sourcesContent":["import { recordIndexFromDeclarations } from '@azx-pbc/axiom-runtime';\nimport type { CompiledField, FieldOption, RecordIndex } from '@azx-pbc/axiom-runtime';\nimport type { AuthoringDocument, AuthoringField, AuthoringOption } from './document.js';\n\n/**\n * One authored option as the index reads it.\n *\n * The index decides which codes a field's domain offers and what each one's label is; a code's\n * availability, its reason and its alternatives are decided at evaluation, so they are dropped here\n * rather than forcing the authored source text and the compiled AST into one type (see\n * `indexableField` for the same split on `rowsFrom`).\n */\nfunction indexableOption(option: AuthoringOption): FieldOption {\n return {\n code: option.code,\n labelKey: option.labelKey,\n ...(option.deprecated === undefined ? {} : { deprecated: option.deprecated }),\n };\n}\n\n/**\n * One authored declaration as the index reads it.\n *\n * A draft's `rowsFrom` is the Expr v1 source an author wrote, while the artifact's `rowsFrom` is\n * the AST the compiler derives from it; the reader index never consults the member, so it is\n * dropped here rather than forcing the two representations into one type. Every other member is\n * shared with the compiled declaration.\n */\nfunction indexableField(field: AuthoringField): CompiledField {\n const { rowsFrom: _rowsFrom, fields: members, options, ...rest } = field;\n return {\n ...rest,\n ...(options === undefined ? {} : { options: options.map(indexableOption) }),\n ...(members === undefined ? {} : { fields: members.map(indexableField) }),\n };\n}\n\n/**\n * The index a draft's expressions are read against.\n *\n * A draft may not compile, so the index is derived from the declarations it holds rather than\n * from an artifact. It is the runtime's own reader index — the fields by dotted path and the\n * context roots a path may name — so a projection, an impact report and an evaluation resolve a\n * path to the same declaration instead of each carrying a resolver.\n *\n * The root set carries the reserved `record_date` and `schema_version` the runtime always\n * resolves, so a rule may read `context.record_date` without the document declaring it.\n */\nexport function documentIndex(document: AuthoringDocument): RecordIndex {\n return recordIndexFromDeclarations(document.fields.map(indexableField), document.context?.roots);\n}\n"]}
|