@cruba/crubal 0.0.0-stage → 0.2.0
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 +202 -0
- package/README.md +97 -2
- package/dist/bin/crubal.d.ts +2 -0
- package/dist/bin/crubal.js +103 -0
- package/dist/bin/crubal.js.map +1 -0
- package/dist/src/access.d.ts +126 -0
- package/dist/src/access.js +517 -0
- package/dist/src/access.js.map +1 -0
- package/dist/src/arrival.d.ts +55 -0
- package/dist/src/arrival.js +124 -0
- package/dist/src/arrival.js.map +1 -0
- package/dist/src/browser.d.ts +10 -0
- package/dist/src/browser.js +13 -0
- package/dist/src/browser.js.map +1 -0
- package/dist/src/bundle.d.ts +66 -0
- package/dist/src/bundle.js +753 -0
- package/dist/src/bundle.js.map +1 -0
- package/dist/src/canonical.d.ts +6 -0
- package/dist/src/canonical.js +47 -0
- package/dist/src/canonical.js.map +1 -0
- package/dist/src/conditions.d.ts +28 -0
- package/dist/src/conditions.js +216 -0
- package/dist/src/conditions.js.map +1 -0
- package/dist/src/corpus.d.ts +8 -0
- package/dist/src/corpus.js +1207 -0
- package/dist/src/corpus.js.map +1 -0
- package/dist/src/defs.d.ts +151 -0
- package/dist/src/defs.js +611 -0
- package/dist/src/defs.js.map +1 -0
- package/dist/src/dictionary.d.ts +65 -0
- package/dist/src/dictionary.js +557 -0
- package/dist/src/dictionary.js.map +1 -0
- package/dist/src/exchange.d.ts +236 -0
- package/dist/src/exchange.js +1035 -0
- package/dist/src/exchange.js.map +1 -0
- package/dist/src/forms.d.ts +16 -0
- package/dist/src/forms.js +169 -0
- package/dist/src/forms.js.map +1 -0
- package/dist/src/index.d.ts +27 -0
- package/dist/src/index.js +29 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/lex.d.ts +21 -0
- package/dist/src/lex.js +142 -0
- package/dist/src/lex.js.map +1 -0
- package/dist/src/lifecycle.d.ts +84 -0
- package/dist/src/lifecycle.js +415 -0
- package/dist/src/lifecycle.js.map +1 -0
- package/dist/src/log.d.ts +78 -0
- package/dist/src/log.js +506 -0
- package/dist/src/log.js.map +1 -0
- package/dist/src/migrate.d.ts +111 -0
- package/dist/src/migrate.js +286 -0
- package/dist/src/migrate.js.map +1 -0
- package/dist/src/model.d.ts +68 -0
- package/dist/src/model.js +188 -0
- package/dist/src/model.js.map +1 -0
- package/dist/src/packages.d.ts +69 -0
- package/dist/src/packages.js +232 -0
- package/dist/src/packages.js.map +1 -0
- package/dist/src/print-text.d.ts +7 -0
- package/dist/src/print-text.js +216 -0
- package/dist/src/print-text.js.map +1 -0
- package/dist/src/publish.d.ts +27 -0
- package/dist/src/publish.js +275 -0
- package/dist/src/publish.js.map +1 -0
- package/dist/src/read-text.d.ts +10 -0
- package/dist/src/read-text.js +385 -0
- package/dist/src/read-text.js.map +1 -0
- package/dist/src/records.d.ts +31 -0
- package/dist/src/records.js +72 -0
- package/dist/src/records.js.map +1 -0
- package/dist/src/review.d.ts +22 -0
- package/dist/src/review.js +198 -0
- package/dist/src/review.js.map +1 -0
- package/dist/src/rules.d.ts +96 -0
- package/dist/src/rules.js +611 -0
- package/dist/src/rules.js.map +1 -0
- package/dist/src/schedule.d.ts +24 -0
- package/dist/src/schedule.js +126 -0
- package/dist/src/schedule.js.map +1 -0
- package/dist/src/std-packages.d.ts +9 -0
- package/dist/src/std-packages.js +268 -0
- package/dist/src/std-packages.js.map +1 -0
- package/dist/src/store.d.ts +164 -0
- package/dist/src/store.js +538 -0
- package/dist/src/store.js.map +1 -0
- package/dist/src/tree.d.ts +35 -0
- package/dist/src/tree.js +159 -0
- package/dist/src/tree.js.map +1 -0
- package/dist/src/units-table.d.ts +1 -0
- package/dist/src/units-table.js +200 -0
- package/dist/src/units-table.js.map +1 -0
- package/dist/src/units.d.ts +42 -0
- package/dist/src/units.js +98 -0
- package/dist/src/units.js.map +1 -0
- package/dist/src/views.d.ts +216 -0
- package/dist/src/views.js +761 -0
- package/dist/src/views.js.map +1 -0
- package/package.json +60 -4
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
// read-text.ts: CRUBAL data text (spec chapter 2) into the JSON form (chapter 3). The facet decides each
|
|
2
|
+
// value's shape (chapter 1.4); a key without a facet keeps its exact text as a raw value.
|
|
3
|
+
import { readList, readPiece, writeText } from "./lex.js";
|
|
4
|
+
import { CrubalError, innerText, readTree } from "./tree.js";
|
|
5
|
+
import {} from "./model.js";
|
|
6
|
+
import { itemText } from "./print-text.js";
|
|
7
|
+
const RESERVED_DETAIL = new Set(["row", "origin", "via", "owner"]);
|
|
8
|
+
const IMAGE_FIELDS = new Set(["sha256", "w", "h", "type"]);
|
|
9
|
+
const ENVELOPE = new Set(["crubal:wears", "crubal:parts", "crubal:kind", "crubal:owner", "crubal:within", "crubal:status", "crubal:applied", "crubal:created", "crubal:updated"]);
|
|
10
|
+
const NUMBER = /^-?(0|[1-9]\d*)(\.\d+)?$/;
|
|
11
|
+
const ORIGINS = new Set(["observed", "declared", "derived", "reported"]);
|
|
12
|
+
/** The language version this reader knows (11.8). */
|
|
13
|
+
export const LANGUAGE = 2;
|
|
14
|
+
function sourceOf(detail, line) {
|
|
15
|
+
const get = (n) => detail.find(([k]) => k === n)?.[1].text;
|
|
16
|
+
const origin = get("origin");
|
|
17
|
+
const via = get("via");
|
|
18
|
+
const owner = get("owner");
|
|
19
|
+
if (origin === undefined && via === undefined && owner === undefined)
|
|
20
|
+
return null;
|
|
21
|
+
if (!origin || !via)
|
|
22
|
+
throw new CrubalError("a source needs both origin and via", line);
|
|
23
|
+
if (!ORIGINS.has(origin))
|
|
24
|
+
throw new CrubalError(`unknown origin ${origin}`, line);
|
|
25
|
+
const s = { origin, via };
|
|
26
|
+
if (owner)
|
|
27
|
+
s.owner = owner;
|
|
28
|
+
return s;
|
|
29
|
+
}
|
|
30
|
+
function isEmptyMark(p) {
|
|
31
|
+
if (p.quoted)
|
|
32
|
+
return null;
|
|
33
|
+
if (p.text === "_")
|
|
34
|
+
return "unknown";
|
|
35
|
+
if (p.text === "-" || p.text === "n/a" || p.text === "N/A")
|
|
36
|
+
return "n/a";
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
/** Read one scalar piece under its facet: the shape the facet decides, falling back to text. */
|
|
40
|
+
function scalar(f, p) {
|
|
41
|
+
const t = p.text;
|
|
42
|
+
switch (f.type) {
|
|
43
|
+
case "link":
|
|
44
|
+
return !p.quoted && t.startsWith("&") ? { $link: t.slice(1) } : t;
|
|
45
|
+
case "number": {
|
|
46
|
+
const unit = f.unit;
|
|
47
|
+
if (!unit)
|
|
48
|
+
return t;
|
|
49
|
+
// A bare decimal under a facet with a unit is that number in the facet's unit (1.4.3, 1.4.4); a facet
|
|
50
|
+
// taking any currency can't guess one, so a bare amount stays text and contradicts.
|
|
51
|
+
if (NUMBER.test(t)) {
|
|
52
|
+
if (unit === "currency")
|
|
53
|
+
return t;
|
|
54
|
+
return /^[A-Z]{3}$/.test(unit) ? { $money: t, currency: unit } : { $qty: t, unit };
|
|
55
|
+
}
|
|
56
|
+
const m = t.match(/^(-?(?:0|[1-9]\d*)(?:\.\d+)?) ?(\S+)$/);
|
|
57
|
+
if (m && (unit === "currency" || /^[A-Z]{3}$/.test(unit)) && /^[A-Z]{3}$/.test(m[2] ?? "")) {
|
|
58
|
+
return { $money: m[1], currency: m[2] };
|
|
59
|
+
}
|
|
60
|
+
if (m)
|
|
61
|
+
return { $qty: m[1], unit: m[2] };
|
|
62
|
+
return t;
|
|
63
|
+
}
|
|
64
|
+
case "yes-no": {
|
|
65
|
+
const [yes, no] = f.words ?? ["yes", "no"];
|
|
66
|
+
if (!p.quoted && (t === "yes" || t === yes))
|
|
67
|
+
return true;
|
|
68
|
+
if (!p.quoted && (t === "no" || t === no))
|
|
69
|
+
return false;
|
|
70
|
+
return t;
|
|
71
|
+
}
|
|
72
|
+
case "image":
|
|
73
|
+
return { $image: t };
|
|
74
|
+
case "date":
|
|
75
|
+
// Canonical form writes a zero offset as Z (1.4.5).
|
|
76
|
+
return /T\d{2}(:\d{2}){0,2}[+-]00:00$/.test(t) ? t.replace(/[+-]00:00$/, "Z") : t;
|
|
77
|
+
default:
|
|
78
|
+
return t;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** A value with its detail: image fields, qualifiers (a `$value` wrapper), and its source. */
|
|
82
|
+
function value(f, p, ctx, address, line) {
|
|
83
|
+
let v = scalar(f, p);
|
|
84
|
+
const qualifiers = {};
|
|
85
|
+
for (const [name, d] of p.detail) {
|
|
86
|
+
if (name === "row")
|
|
87
|
+
throw new CrubalError("a row key belongs on the row's own line", line);
|
|
88
|
+
if (RESERVED_DETAIL.has(name))
|
|
89
|
+
continue;
|
|
90
|
+
if (f.type === "image" && IMAGE_FIELDS.has(name) && typeof v === "object" && v && "$image" in v) {
|
|
91
|
+
v[name] = name === "w" || name === "h" ? Number(d.text) : d.text;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
const qf = ctx.dict.facets.get(name);
|
|
95
|
+
qualifiers[name] = qf ? scalar(qf, d) : d.text;
|
|
96
|
+
}
|
|
97
|
+
if (Object.keys(qualifiers).length)
|
|
98
|
+
v = { $value: v, ...qualifiers };
|
|
99
|
+
const src = sourceOf(p.detail, line);
|
|
100
|
+
if (src) {
|
|
101
|
+
const at = address ?? "";
|
|
102
|
+
ctx.sources[at] = src;
|
|
103
|
+
}
|
|
104
|
+
return v;
|
|
105
|
+
}
|
|
106
|
+
function addressItem(key, f, item) {
|
|
107
|
+
return `${key}[${JSON.stringify(itemText(f, item))}]`;
|
|
108
|
+
}
|
|
109
|
+
/** Read a facet's value from its node: one value, a list, or a compound. */
|
|
110
|
+
function readValue(f, node, ctx, address) {
|
|
111
|
+
// A long-text block (2.4.1): the text as taken, with its detail from the `|` line.
|
|
112
|
+
if (node.block) {
|
|
113
|
+
if (f.type !== "text" || f.many)
|
|
114
|
+
throw new CrubalError(`a block holds one text value; ${f.key} is ${f.many ? "many-valued" : f.type}`, node.line);
|
|
115
|
+
const p = readPiece(node.detail ?? "", node.line);
|
|
116
|
+
return value(f, { text: node.value, quoted: true, detail: p.detail }, ctx, address, node.line);
|
|
117
|
+
}
|
|
118
|
+
const raw = node.value;
|
|
119
|
+
// An empty is the whole value (chapter 1.5).
|
|
120
|
+
if (raw && node.children.length === 0 && /^(_|-|n\/a|N\/A)( \[.*\])?$/.test(raw.trim())) {
|
|
121
|
+
const whole = readPiece(raw, node.line);
|
|
122
|
+
const empty = isEmptyMark(whole);
|
|
123
|
+
if (empty) {
|
|
124
|
+
const src = sourceOf(whole.detail, node.line);
|
|
125
|
+
if (src)
|
|
126
|
+
ctx.sources[address] = src;
|
|
127
|
+
return { $empty: empty };
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (f.type === "compound")
|
|
131
|
+
return readCompound(f, node, ctx, address);
|
|
132
|
+
if (!f.many) {
|
|
133
|
+
if (!raw)
|
|
134
|
+
return undefined;
|
|
135
|
+
return value(f, readPiece(raw, node.line), ctx, address, node.line);
|
|
136
|
+
}
|
|
137
|
+
const pieces = raw
|
|
138
|
+
? readList(raw, node.line).map((p) => ({ p, line: node.line }))
|
|
139
|
+
: node.children.map((c) => {
|
|
140
|
+
if (c.kind !== "item")
|
|
141
|
+
throw new CrubalError("a list's lines start with \"- \"", c.line);
|
|
142
|
+
return { p: readPiece(c.value, c.line), line: c.line };
|
|
143
|
+
});
|
|
144
|
+
const out = [];
|
|
145
|
+
for (const { p, line } of pieces) {
|
|
146
|
+
if (isEmptyMark(p) || (!p.quoted && p.text === ""))
|
|
147
|
+
throw new CrubalError("an empty can't be a list item", line);
|
|
148
|
+
const tmp = { dict: ctx.dict, sources: {} };
|
|
149
|
+
const v = value(f, p, tmp, "", line);
|
|
150
|
+
out.push(v);
|
|
151
|
+
if (tmp.sources[""])
|
|
152
|
+
ctx.sources[addressItem(f.key, f, v)] = tmp.sources[""];
|
|
153
|
+
}
|
|
154
|
+
return out.length ? out : undefined;
|
|
155
|
+
}
|
|
156
|
+
function readFields(children, within, ctx, prefix) {
|
|
157
|
+
const obj = {};
|
|
158
|
+
const seen = new Set();
|
|
159
|
+
for (const c of children) {
|
|
160
|
+
if (c.kind !== "pair" || !c.key)
|
|
161
|
+
throw new CrubalError(`expected "key: value": ${c.text}`, c.line);
|
|
162
|
+
if (seen.has(c.key))
|
|
163
|
+
throw new CrubalError(`the key ${c.key} twice`, c.line);
|
|
164
|
+
seen.add(c.key);
|
|
165
|
+
const f = within ? within.get(c.key) : ctx.dict.facets.get(c.key);
|
|
166
|
+
const address = prefix ? `${prefix}.${c.key}` : c.key;
|
|
167
|
+
if (!f) {
|
|
168
|
+
obj[c.key] = c.block ? c.value : c.children.length ? `${c.value}\n${innerText(c)}` : c.value;
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
const v = readValue(f, c, ctx, address);
|
|
172
|
+
if (v !== undefined)
|
|
173
|
+
obj[c.key] = v;
|
|
174
|
+
}
|
|
175
|
+
return obj;
|
|
176
|
+
}
|
|
177
|
+
function rowKeyOf(item) {
|
|
178
|
+
if (!item.value)
|
|
179
|
+
return { key: null, rest: item.children };
|
|
180
|
+
const p = readPiece(item.value, item.line);
|
|
181
|
+
if (p.text !== "")
|
|
182
|
+
throw new CrubalError(`a row starts with "[row: key]" or its first pair: ${item.value}`, item.line);
|
|
183
|
+
const row = p.detail.find(([k]) => k === "row");
|
|
184
|
+
if (!row || p.detail.length !== 1)
|
|
185
|
+
throw new CrubalError("a row's own line holds only [row: key]", item.line);
|
|
186
|
+
return { key: row[1].text, rest: item.children };
|
|
187
|
+
}
|
|
188
|
+
function readCompound(f, node, ctx, address) {
|
|
189
|
+
const children = f.children ?? new Map();
|
|
190
|
+
if (!f.many)
|
|
191
|
+
return readFields(node.children, children, ctx, address);
|
|
192
|
+
const rows = [];
|
|
193
|
+
const keys = new Set();
|
|
194
|
+
for (const item of node.children) {
|
|
195
|
+
if (item.kind !== "item")
|
|
196
|
+
throw new CrubalError("a compound's rows start with \"- \"", item.line);
|
|
197
|
+
const { key: written, rest } = rowKeyOf(item);
|
|
198
|
+
if (written && f.identity) {
|
|
199
|
+
throw new CrubalError(`a row key on ${f.key}, whose row keys come from ${f.identity}`, item.line);
|
|
200
|
+
}
|
|
201
|
+
let key = written;
|
|
202
|
+
if (f.identity) {
|
|
203
|
+
const idNode = rest.find((c) => c.key === f.identity);
|
|
204
|
+
const target = idNode?.value.trim();
|
|
205
|
+
if (!target?.startsWith("&"))
|
|
206
|
+
throw new CrubalError(`a row of ${f.key} needs its ${f.identity}`, item.line);
|
|
207
|
+
key = target.slice(1);
|
|
208
|
+
}
|
|
209
|
+
if (!key)
|
|
210
|
+
throw new CrubalError(`a row of ${f.key} needs [row: key]`, item.line);
|
|
211
|
+
if (keys.has(key))
|
|
212
|
+
throw new CrubalError(`the row key ${key} twice in one list`, item.line);
|
|
213
|
+
keys.add(key);
|
|
214
|
+
const row = readFields(rest, children, ctx, `${address}[${key}]`);
|
|
215
|
+
rows.push(f.identity ? row : { $row: key, ...row });
|
|
216
|
+
}
|
|
217
|
+
return rows.length ? rows : undefined;
|
|
218
|
+
}
|
|
219
|
+
function readParts(node, ctx) {
|
|
220
|
+
const parts = [];
|
|
221
|
+
const keys = new Set();
|
|
222
|
+
for (const item of node.children) {
|
|
223
|
+
if (item.kind !== "item")
|
|
224
|
+
throw new CrubalError("parts are list items", item.line);
|
|
225
|
+
const { key, rest } = rowKeyOf(item);
|
|
226
|
+
if (!key)
|
|
227
|
+
throw new CrubalError("every part needs [row: key]", item.line);
|
|
228
|
+
if (keys.has(key))
|
|
229
|
+
throw new CrubalError(`the row key ${key} twice in one list`, item.line);
|
|
230
|
+
keys.add(key);
|
|
231
|
+
const wearsNode = rest.find((c) => c.key === "crubal:wears");
|
|
232
|
+
const values = readFields(rest.filter((c) => c !== wearsNode), null, ctx, `parts[${key}]`);
|
|
233
|
+
const part = { $row: key };
|
|
234
|
+
if (wearsNode)
|
|
235
|
+
part.wears = readList(wearsNode.value, wearsNode.line).map((p) => p.text);
|
|
236
|
+
part.values = values;
|
|
237
|
+
parts.push(part);
|
|
238
|
+
}
|
|
239
|
+
return parts;
|
|
240
|
+
}
|
|
241
|
+
/** Read CRUBAL data text into a border wrapper (spec chapter 3.8). */
|
|
242
|
+
export function readText(source, dict) {
|
|
243
|
+
const nodes = readTree(source);
|
|
244
|
+
const wrapper = { crubal: "2", records: [] };
|
|
245
|
+
const lines = new Map();
|
|
246
|
+
let owner;
|
|
247
|
+
for (const node of nodes) {
|
|
248
|
+
if (node.kind !== "pair" || !node.key)
|
|
249
|
+
throw new CrubalError(`unexpected line: ${node.text}`, node.line);
|
|
250
|
+
if (node.key === "crubal") {
|
|
251
|
+
// A reader never reads above its language version (11.8): it refuses, naming the line.
|
|
252
|
+
if (!/^\d+$/.test(node.value.trim()) || Number(node.value) > LANGUAGE)
|
|
253
|
+
throw new CrubalError(`written in CRUBAL ${node.value}; this reader knows ${LANGUAGE}`, node.line);
|
|
254
|
+
wrapper.crubal = node.value;
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
if (node.key === "package") {
|
|
258
|
+
wrapper.package = node.value;
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
if (node.key === "owner") {
|
|
262
|
+
owner = node.value;
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
const kind = dict.levels.get(node.key);
|
|
266
|
+
if (!kind)
|
|
267
|
+
throw new CrubalError(`an unknown top-level key ${node.key}`, node.line);
|
|
268
|
+
const rec = readRecord(node, kind, owner);
|
|
269
|
+
lines.set(rec.id, node.line);
|
|
270
|
+
wrapper.records.push(rec);
|
|
271
|
+
}
|
|
272
|
+
// `of` names a record of the same kind at the level directly above (1.2), when that record is in the file.
|
|
273
|
+
const byId = new Map(wrapper.records.map((r) => [r.id, r]));
|
|
274
|
+
for (const r of wrapper.records) {
|
|
275
|
+
const up = r.of ? byId.get(r.of) : undefined;
|
|
276
|
+
if (!up)
|
|
277
|
+
continue;
|
|
278
|
+
if (up.kind !== r.kind)
|
|
279
|
+
throw new CrubalError(`${r.id} is of ${up.id}, a ${up.kind}, not a ${r.kind}`, lines.get(r.id));
|
|
280
|
+
const levels = dict.kinds.get(r.kind)?.levels ?? [];
|
|
281
|
+
if (levels.indexOf(up.level) !== levels.indexOf(r.level) - 1)
|
|
282
|
+
throw new CrubalError(`${r.id} is of ${up.id} at ${up.level}, not the level directly above ${r.level}`, lines.get(r.id));
|
|
283
|
+
}
|
|
284
|
+
return wrapper;
|
|
285
|
+
function readRecord(node, kind, fileOwner) {
|
|
286
|
+
const head = readPiece(node.value, node.line);
|
|
287
|
+
const m = head.text.match(/^(\S+)(?: of (\S+))?$/);
|
|
288
|
+
if (!m)
|
|
289
|
+
throw new CrubalError(`a record header is "level: id" or "level: id of parent": ${node.value}`, node.line);
|
|
290
|
+
const ctx = { dict, sources: {} };
|
|
291
|
+
const star = sourceOf(head.detail, node.line);
|
|
292
|
+
if (star)
|
|
293
|
+
ctx.sources["*"] = star;
|
|
294
|
+
const rec = { id: m[1], kind, level: node.key, owner: fileOwner ?? "", values: {} };
|
|
295
|
+
if (m[2])
|
|
296
|
+
rec.of = m[2];
|
|
297
|
+
const seen = new Set();
|
|
298
|
+
const valueNodes = [];
|
|
299
|
+
for (const c of node.children) {
|
|
300
|
+
if (c.kind !== "pair" || !c.key)
|
|
301
|
+
throw new CrubalError(`expected "key: value": ${c.text}`, c.line);
|
|
302
|
+
if (seen.has(c.key))
|
|
303
|
+
throw new CrubalError(`the key ${c.key} twice in one record`, c.line);
|
|
304
|
+
seen.add(c.key);
|
|
305
|
+
if (!ENVELOPE.has(c.key)) {
|
|
306
|
+
valueNodes.push(c);
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
if (c.key === "crubal:wears")
|
|
310
|
+
rec.wears = readList(c.value, c.line).map((p) => p.text);
|
|
311
|
+
else if (c.key === "crubal:parts")
|
|
312
|
+
rec.parts = readParts(c, ctx);
|
|
313
|
+
else if (c.key === "crubal:owner")
|
|
314
|
+
rec.owner = c.value;
|
|
315
|
+
else if (c.key === "crubal:within")
|
|
316
|
+
rec.within = c.value.trim();
|
|
317
|
+
else if (c.key === "crubal:status") {
|
|
318
|
+
// `archived [reason: sold, into: P-9]`; `active` is the same as leaving the line out.
|
|
319
|
+
const p = readPiece(c.value, c.line);
|
|
320
|
+
if (p.text !== "active" && p.text !== "archived")
|
|
321
|
+
throw new CrubalError(`a status is active or archived, not ${p.text}`, c.line);
|
|
322
|
+
if (p.text === "archived") {
|
|
323
|
+
const get = (n) => p.detail.find(([k]) => k === n)?.[1].text;
|
|
324
|
+
rec.status = { state: "archived" };
|
|
325
|
+
const reason = get("reason");
|
|
326
|
+
const into = get("into");
|
|
327
|
+
if (reason)
|
|
328
|
+
rec.status.reason = reason;
|
|
329
|
+
if (into)
|
|
330
|
+
rec.status.into = into;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
else if (c.key === "crubal:applied") {
|
|
334
|
+
// `[P-4QX7: 2, class:OpticalDisc/2026-11-01: 1]`: each issuer and the last instruction applied.
|
|
335
|
+
const p = readPiece(c.value, c.line);
|
|
336
|
+
if (p.text !== "" || !p.detail.length)
|
|
337
|
+
throw new CrubalError(`applied is "[issuer: n, …]", not ${c.value}`, c.line);
|
|
338
|
+
rec.applied = Object.fromEntries(p.detail.map(([k, v]) => [k, Number(v.text)]));
|
|
339
|
+
}
|
|
340
|
+
else if (c.key === "crubal:created")
|
|
341
|
+
rec.created = c.value;
|
|
342
|
+
else if (c.key === "crubal:updated")
|
|
343
|
+
rec.updated = c.value;
|
|
344
|
+
else if (c.key === "crubal:kind" && c.value !== kind) {
|
|
345
|
+
throw new CrubalError(`crubal:kind ${c.value} disagrees with the level's kind ${kind}`, c.line);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
rec.values = readFields(valueNodes, null, ctx, "");
|
|
349
|
+
if (Object.keys(ctx.sources).length)
|
|
350
|
+
rec.sources = ctx.sources;
|
|
351
|
+
return orderRecord(rec);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
/** Members in the order chapter 3.2 lists them, so output reads the same every time. */
|
|
355
|
+
function orderRecord(r) {
|
|
356
|
+
const o = { id: r.id, kind: r.kind, level: r.level };
|
|
357
|
+
if (r.of)
|
|
358
|
+
o.of = r.of;
|
|
359
|
+
o.owner = r.owner;
|
|
360
|
+
if (r.within)
|
|
361
|
+
o.within = r.within;
|
|
362
|
+
if (r.status)
|
|
363
|
+
o.status = r.status;
|
|
364
|
+
if (r.applied)
|
|
365
|
+
o.applied = r.applied;
|
|
366
|
+
if (r.wears)
|
|
367
|
+
o.wears = r.wears;
|
|
368
|
+
if (r.created)
|
|
369
|
+
o.created = r.created;
|
|
370
|
+
if (r.updated)
|
|
371
|
+
o.updated = r.updated;
|
|
372
|
+
o.values = r.values;
|
|
373
|
+
if (r.parts)
|
|
374
|
+
o.parts = r.parts;
|
|
375
|
+
if (r.sources)
|
|
376
|
+
o.sources = r.sources;
|
|
377
|
+
return o;
|
|
378
|
+
}
|
|
379
|
+
export { writeText };
|
|
380
|
+
/** Read one value's text under a facet, as if it had been written on that facet's line. */
|
|
381
|
+
export function readUnder(f, text, dict, line = 0) {
|
|
382
|
+
const node = { kind: "pair", key: f.key, value: text, text, line, indent: 0, children: [] };
|
|
383
|
+
return readValue(f, node, { dict, sources: {} }, f.key);
|
|
384
|
+
}
|
|
385
|
+
//# sourceMappingURL=read-text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-text.js","sourceRoot":"","sources":["../../src/read-text.ts"],"names":[],"mappings":"AAAA,yGAAyG;AACzG,0FAA0F;AAG1F,OAAO,EAAc,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAa,QAAQ,EAAE,MAAM,WAAW,CAAC;AACxE,OAAO,EAAsE,MAAM,YAAY,CAAC;AAChG,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,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OAAO;QAAE,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC;IACrC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;IACpB,IAAI,CAAC,CAAC,KAAK;QAAE,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC;IAC/B,IAAI,CAAC,CAAC,OAAO;QAAE,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAgC,CAAC;IAC9D,OAAO,CAAsB,CAAC;AAChC,CAAC;AAED,OAAO,EAAE,SAAS,EAAE,CAAC;AAErB,2FAA2F;AAC3F,MAAM,UAAU,SAAS,CAAC,CAAQ,EAAE,IAAY,EAAE,IAAgB,EAAE,IAAI,GAAG,CAAC;IAC1E,MAAM,IAAI,GAAS,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;IAClG,OAAO,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Json, Record } from "./model.ts";
|
|
2
|
+
export interface RecordSet extends Map<string, Record> {
|
|
3
|
+
/** Every record (an integrity check or a view over everything; a backend may answer in pages). */
|
|
4
|
+
all(): Record[];
|
|
5
|
+
/** The records at a level (1.2). */
|
|
6
|
+
atLevel(level: string): Record[];
|
|
7
|
+
/** The records whose `of` or `within` names the record, at a level when one is given. */
|
|
8
|
+
childrenOf(id: string, along: "of" | "within", level?: string): Record[];
|
|
9
|
+
/** The records a `for` names: wearers of a class, records at a level, or records of a kind (6.1, 7.2). */
|
|
10
|
+
forTarget(name: string): Record[];
|
|
11
|
+
/** The records at a level whose value for a key equals the value (6.6, 9.2a). */
|
|
12
|
+
byKey(key: string, value: Json, level?: string): Record[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The memory set: a map, with every question answered from it. Children and levels are indexed on first
|
|
16
|
+
* use and dropped on any change, so a projection over a catalog never scans the whole map per record.
|
|
17
|
+
*/
|
|
18
|
+
export declare class MemoryRecords extends Map<string, Record> implements RecordSet {
|
|
19
|
+
private byOf?;
|
|
20
|
+
private byWithin?;
|
|
21
|
+
private byLevel?;
|
|
22
|
+
set(id: string, r: Record): this;
|
|
23
|
+
delete(id: string): boolean;
|
|
24
|
+
clear(): void;
|
|
25
|
+
private index;
|
|
26
|
+
all(): Record[];
|
|
27
|
+
atLevel(level: string): Record[];
|
|
28
|
+
childrenOf(id: string, along: "of" | "within", level?: string): Record[];
|
|
29
|
+
forTarget(name: string): Record[];
|
|
30
|
+
byKey(key: string, value: Json, level?: string): Record[];
|
|
31
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// records.ts: the set of records an operation works over, behind one interface (docs/design/store.md).
|
|
2
|
+
// The engine reads records by ID and asks a few questions that a database answers with an index and a
|
|
3
|
+
// memory store answers by a scan: the records at a level, the children of a record along `of` or
|
|
4
|
+
// `within`, the records a contract or view targets, and the records holding a value for a key. Nothing in
|
|
5
|
+
// the engine scans a map directly, so a backend that loads only what an operation needs can stand in for
|
|
6
|
+
// the memory set without the engine knowing.
|
|
7
|
+
import { serialize } from "./canonical.js";
|
|
8
|
+
/**
|
|
9
|
+
* The memory set: a map, with every question answered from it. Children and levels are indexed on first
|
|
10
|
+
* use and dropped on any change, so a projection over a catalog never scans the whole map per record.
|
|
11
|
+
*/
|
|
12
|
+
export class MemoryRecords extends Map {
|
|
13
|
+
byOf;
|
|
14
|
+
byWithin;
|
|
15
|
+
byLevel;
|
|
16
|
+
set(id, r) {
|
|
17
|
+
this.byOf = this.byWithin = this.byLevel = undefined;
|
|
18
|
+
return super.set(id, r);
|
|
19
|
+
}
|
|
20
|
+
delete(id) {
|
|
21
|
+
this.byOf = this.byWithin = this.byLevel = undefined;
|
|
22
|
+
return super.delete(id);
|
|
23
|
+
}
|
|
24
|
+
clear() {
|
|
25
|
+
this.byOf = this.byWithin = this.byLevel = undefined;
|
|
26
|
+
super.clear();
|
|
27
|
+
}
|
|
28
|
+
index(by) {
|
|
29
|
+
const have = by === "of" ? this.byOf : by === "within" ? this.byWithin : this.byLevel;
|
|
30
|
+
if (have)
|
|
31
|
+
return have;
|
|
32
|
+
const m = new Map();
|
|
33
|
+
for (const r of this.values()) {
|
|
34
|
+
const k = r[by];
|
|
35
|
+
if (k === undefined)
|
|
36
|
+
continue;
|
|
37
|
+
const list = m.get(k);
|
|
38
|
+
if (list)
|
|
39
|
+
list.push(r);
|
|
40
|
+
else
|
|
41
|
+
m.set(k, [r]);
|
|
42
|
+
}
|
|
43
|
+
if (by === "of")
|
|
44
|
+
this.byOf = m;
|
|
45
|
+
else if (by === "within")
|
|
46
|
+
this.byWithin = m;
|
|
47
|
+
else
|
|
48
|
+
this.byLevel = m;
|
|
49
|
+
return m;
|
|
50
|
+
}
|
|
51
|
+
all() {
|
|
52
|
+
return [...this.values()];
|
|
53
|
+
}
|
|
54
|
+
atLevel(level) {
|
|
55
|
+
return [...(this.index("level").get(level) ?? [])];
|
|
56
|
+
}
|
|
57
|
+
childrenOf(id, along, level) {
|
|
58
|
+
const list = this.index(along).get(id) ?? [];
|
|
59
|
+
return level === undefined ? [...list] : list.filter((r) => r.level === level);
|
|
60
|
+
}
|
|
61
|
+
// Scans read the map's own rows, never `all()`: a working set (crubal-postgres) notes the narrow question
|
|
62
|
+
// it was asked and answers it from the rows it loaded for it; going through `all()` would ask for every
|
|
63
|
+
// record of the catalog on each `is unique` check.
|
|
64
|
+
forTarget(name) {
|
|
65
|
+
return [...this.values()].filter((r) => (r.wears ?? []).includes(name) || r.level === name || r.kind === name);
|
|
66
|
+
}
|
|
67
|
+
byKey(key, value, level) {
|
|
68
|
+
const want = serialize(value);
|
|
69
|
+
return [...this.values()].filter((r) => (level === undefined || r.level === level) && r.values[key] !== undefined && serialize(r.values[key]) === want);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=records.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"records.js","sourceRoot":"","sources":["../../src/records.ts"],"names":[],"mappings":"AAAA,uGAAuG;AACvG,sGAAsG;AACtG,iGAAiG;AACjG,0GAA0G;AAC1G,yGAAyG;AACzG,6CAA6C;AAG7C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAe3C;;;GAGG;AACH,MAAM,OAAO,aAAc,SAAQ,GAAmB;IAC5C,IAAI,CAAyB;IAC7B,QAAQ,CAAyB;IACjC,OAAO,CAAyB;IAE/B,GAAG,CAAC,EAAU,EAAE,CAAS;QAChC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;QACrD,OAAO,KAAK,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAC1B,CAAC;IAEQ,MAAM,CAAC,EAAU;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;QACrD,OAAO,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC1B,CAAC;IAEQ,KAAK;QACZ,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;QACrD,KAAK,CAAC,KAAK,EAAE,CAAC;IAChB,CAAC;IAEO,KAAK,CAAC,EAA6B;QACzC,MAAM,IAAI,GAAG,EAAE,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,I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AAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,CAAC;IACjF,CAAC;IAED,0GAA0G;IAC1G,wGAAwG;IACxG,mDAAmD;IACnD,SAAS,CAAC,IAAY;QACpB,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,KAAK,IAAI,IAAI,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;IACjH,CAAC;IAED,KAAK,CAAC,GAAW,EAAE,KAAW,EAAE,KAAc;QAC5C,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;QAC9B,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,SAAS,IAAI,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,SAAS,IAAI,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAS,CAAC,KAAK,IAAI,CAAC,CAAC;IAClK,CAAC;CACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Dictionary } from "./defs.ts";
|
|
2
|
+
import { type Store } from "./lifecycle.ts";
|
|
3
|
+
import type { JsonObject } from "./model.ts";
|
|
4
|
+
import type { Contract } from "./store.ts";
|
|
5
|
+
export type Decision = JsonObject & {
|
|
6
|
+
key: string;
|
|
7
|
+
decision: string;
|
|
8
|
+
};
|
|
9
|
+
export type Definitions = {
|
|
10
|
+
dict: Dictionary;
|
|
11
|
+
contracts: Map<string, Contract>;
|
|
12
|
+
units?: JsonObject[];
|
|
13
|
+
};
|
|
14
|
+
/** The units extension as text, for the units table (11.9). */
|
|
15
|
+
export declare function unitsExtensionText(measures: JsonObject[]): string;
|
|
16
|
+
/**
|
|
17
|
+
* Apply a decision to the draft and return the writes the entry carries beyond what the draft shows:
|
|
18
|
+
* the review write and any define. Throws a CrubalError for a decision that can't be made.
|
|
19
|
+
*/
|
|
20
|
+
export declare function decide(d: Decision, store: Store, defs: Definitions): JsonObject[];
|
|
21
|
+
/** The review items still open: every item without a decision that no later decision names. */
|
|
22
|
+
export declare function openItems(items: JsonObject[]): JsonObject[];
|