@crubal/engine 0.0.0-stage → 0.4.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.
Files changed (114) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +97 -2
  3. package/dist/bin/crubal.d.ts +2 -0
  4. package/dist/bin/crubal.js +103 -0
  5. package/dist/bin/crubal.js.map +1 -0
  6. package/dist/src/access.d.ts +149 -0
  7. package/dist/src/access.js +584 -0
  8. package/dist/src/access.js.map +1 -0
  9. package/dist/src/acts.d.ts +531 -0
  10. package/dist/src/acts.js +1466 -0
  11. package/dist/src/acts.js.map +1 -0
  12. package/dist/src/address.d.ts +29 -0
  13. package/dist/src/address.js +59 -0
  14. package/dist/src/address.js.map +1 -0
  15. package/dist/src/arrival.d.ts +55 -0
  16. package/dist/src/arrival.js +127 -0
  17. package/dist/src/arrival.js.map +1 -0
  18. package/dist/src/browser.d.ts +10 -0
  19. package/dist/src/browser.js +13 -0
  20. package/dist/src/browser.js.map +1 -0
  21. package/dist/src/bundle.d.ts +74 -0
  22. package/dist/src/bundle.js +1108 -0
  23. package/dist/src/bundle.js.map +1 -0
  24. package/dist/src/canonical.d.ts +6 -0
  25. package/dist/src/canonical.js +47 -0
  26. package/dist/src/canonical.js.map +1 -0
  27. package/dist/src/carriers.d.ts +7 -0
  28. package/dist/src/carriers.js +33 -0
  29. package/dist/src/carriers.js.map +1 -0
  30. package/dist/src/conditions.d.ts +28 -0
  31. package/dist/src/conditions.js +227 -0
  32. package/dist/src/conditions.js.map +1 -0
  33. package/dist/src/corpus.d.ts +8 -0
  34. package/dist/src/corpus.js +1207 -0
  35. package/dist/src/corpus.js.map +1 -0
  36. package/dist/src/defs.d.ts +174 -0
  37. package/dist/src/defs.js +690 -0
  38. package/dist/src/defs.js.map +1 -0
  39. package/dist/src/dictionary.d.ts +77 -0
  40. package/dist/src/dictionary.js +629 -0
  41. package/dist/src/dictionary.js.map +1 -0
  42. package/dist/src/exchange.d.ts +259 -0
  43. package/dist/src/exchange.js +1088 -0
  44. package/dist/src/exchange.js.map +1 -0
  45. package/dist/src/forms.d.ts +16 -0
  46. package/dist/src/forms.js +181 -0
  47. package/dist/src/forms.js.map +1 -0
  48. package/dist/src/index.d.ts +32 -0
  49. package/dist/src/index.js +34 -0
  50. package/dist/src/index.js.map +1 -0
  51. package/dist/src/lex.d.ts +21 -0
  52. package/dist/src/lex.js +142 -0
  53. package/dist/src/lex.js.map +1 -0
  54. package/dist/src/lifecycle.d.ts +92 -0
  55. package/dist/src/lifecycle.js +451 -0
  56. package/dist/src/lifecycle.js.map +1 -0
  57. package/dist/src/log.d.ts +91 -0
  58. package/dist/src/log.js +629 -0
  59. package/dist/src/log.js.map +1 -0
  60. package/dist/src/migrate.d.ts +129 -0
  61. package/dist/src/migrate.js +415 -0
  62. package/dist/src/migrate.js.map +1 -0
  63. package/dist/src/model.d.ts +81 -0
  64. package/dist/src/model.js +188 -0
  65. package/dist/src/model.js.map +1 -0
  66. package/dist/src/packages.d.ts +372 -0
  67. package/dist/src/packages.js +1158 -0
  68. package/dist/src/packages.js.map +1 -0
  69. package/dist/src/print-text.d.ts +7 -0
  70. package/dist/src/print-text.js +223 -0
  71. package/dist/src/print-text.js.map +1 -0
  72. package/dist/src/publish.d.ts +27 -0
  73. package/dist/src/publish.js +279 -0
  74. package/dist/src/publish.js.map +1 -0
  75. package/dist/src/read-text.d.ts +10 -0
  76. package/dist/src/read-text.js +400 -0
  77. package/dist/src/read-text.js.map +1 -0
  78. package/dist/src/records.d.ts +32 -0
  79. package/dist/src/records.js +104 -0
  80. package/dist/src/records.js.map +1 -0
  81. package/dist/src/review.d.ts +22 -0
  82. package/dist/src/review.js +198 -0
  83. package/dist/src/review.js.map +1 -0
  84. package/dist/src/rules.d.ts +101 -0
  85. package/dist/src/rules.js +670 -0
  86. package/dist/src/rules.js.map +1 -0
  87. package/dist/src/schedule.d.ts +24 -0
  88. package/dist/src/schedule.js +126 -0
  89. package/dist/src/schedule.js.map +1 -0
  90. package/dist/src/std-packages.d.ts +9 -0
  91. package/dist/src/std-packages.js +268 -0
  92. package/dist/src/std-packages.js.map +1 -0
  93. package/dist/src/store.d.ts +191 -0
  94. package/dist/src/store.js +671 -0
  95. package/dist/src/store.js.map +1 -0
  96. package/dist/src/surface.d.ts +47 -0
  97. package/dist/src/surface.js +92 -0
  98. package/dist/src/surface.js.map +1 -0
  99. package/dist/src/tree.d.ts +35 -0
  100. package/dist/src/tree.js +159 -0
  101. package/dist/src/tree.js.map +1 -0
  102. package/dist/src/units-table.d.ts +1 -0
  103. package/dist/src/units-table.js +200 -0
  104. package/dist/src/units-table.js.map +1 -0
  105. package/dist/src/units.d.ts +42 -0
  106. package/dist/src/units.js +98 -0
  107. package/dist/src/units.js.map +1 -0
  108. package/dist/src/versions.d.ts +10 -0
  109. package/dist/src/versions.js +27 -0
  110. package/dist/src/versions.js.map +1 -0
  111. package/dist/src/views.d.ts +372 -0
  112. package/dist/src/views.js +1170 -0
  113. package/dist/src/views.js.map +1 -0
  114. package/package.json +60 -4
@@ -0,0 +1 @@
1
+ {"version":3,"file":"units-table.js","sourceRoot":"","sources":["../../src/units-table.ts"],"names":[],"mappings":"AAAA,mHAAmH;AACnH,4FAA4F;AAE5F,MAAM,CAAC,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoM7B,CAAC"}
@@ -0,0 +1,42 @@
1
+ export type Unit = {
2
+ unit: string;
3
+ dimension: string;
4
+ factor: number;
5
+ offset: number;
6
+ rounding?: number;
7
+ spellings: string[];
8
+ uncefact?: string;
9
+ extension?: boolean;
10
+ };
11
+ export type Currency = {
12
+ code: string;
13
+ name: string;
14
+ places: number;
15
+ };
16
+ export type UnitsTable = {
17
+ units: Map<string, Unit>;
18
+ currencies: Map<string, Currency>;
19
+ version: string;
20
+ };
21
+ /** Read a units table's records (measure and currency) from the text form. */
22
+ export declare function readUnits(text: string, into?: UnitsTable, extension?: boolean): UnitsTable;
23
+ /** The table in force: the standard table at its version, plus any extension. */
24
+ export declare function unitsTable(): UnitsTable;
25
+ /** Add an owner's units extension (11.9): its own units under its prefix, and spellings for standard ones. */
26
+ export declare function extendUnits(text: string): UnitsTable;
27
+ /** Back to the standard table alone. */
28
+ export declare function resetUnits(): void;
29
+ /** The real unit a spelling names, or null: the unit itself, or one of its spellings, folded. */
30
+ export declare function unitOf(spelling: string, table?: UnitsTable): string | null;
31
+ /** Is this a unit the table knows, `currency`, or an ISO 4217 code (1.4.4)? */
32
+ export declare function knownUnit(u: string, table?: UnitsTable): boolean;
33
+ export declare function dimensionOf(unit: string, table?: UnitsTable): string | null;
34
+ /** A currency's minor-unit places (ISO 4217), for a border that asks for them; 2 when unknown. */
35
+ export declare function currencyPlaces(code: string, table?: UnitsTable): number;
36
+ /**
37
+ * Convert an amount between units of one dimension: through the base by factor and offset, rounded to
38
+ * `places`, else the dimension's rounding, else 6 places with trailing zeros dropped.
39
+ */
40
+ export declare function convert(amount: string, from: string, to: string, places?: number, table?: UnitsTable): string | null;
41
+ /** The standard table plus one owner's extension, as a table of its own (11.9): per dictionary, never global. */
42
+ export declare function unitsTableWith(extension?: string): UnitsTable;
@@ -0,0 +1,98 @@
1
+ // units.ts: the units table (spec 1.4.3, 11.9), read from the standard package's reference records
2
+ // (crubal.com/units, embedded as units-table.ts and checked against std/units/units.crubal) plus an owner's
3
+ // extension. Spellings fold to a unit; amounts convert within a dimension by factor and offset, rounded to
4
+ // the facet's places or the dimension's rounding. A spelling nobody knows is a unit question for review,
5
+ // never a unit minted on sight.
6
+ import { readTree } from "./tree.js";
7
+ import { STANDARD_UNITS } from "./units-table.js";
8
+ const foldSpelling = (s) => s.normalize("NFC").toLowerCase().replace(/\s+/g, " ").trim();
9
+ /** Read a units table's records (measure and currency) from the text form. */
10
+ export function readUnits(text, into, extension = false) {
11
+ const table = into ?? { units: new Map(), currencies: new Map(), version: "" };
12
+ for (const n of readTree(text)) {
13
+ if (n.kind !== "pair" || !n.key)
14
+ continue;
15
+ const get = (k) => n.children.find((c) => c.key === k)?.value.trim();
16
+ if (n.key === "package")
17
+ table.version = n.value.split(" /")[1]?.trim() ?? table.version;
18
+ if (n.key === "measure") {
19
+ const name = n.value.trim();
20
+ const have = table.units.get(name);
21
+ const spellings = (get("spellings") ?? "").split(",").map((s) => s.trim()).filter(Boolean);
22
+ // An extension may add spellings to a standard unit; it never changes its factor or dimension (11.9).
23
+ if (have && extension) {
24
+ have.spellings = [...have.spellings, ...spellings.filter((s) => !have.spellings.includes(s))];
25
+ continue;
26
+ }
27
+ const u = { unit: name, dimension: get("dimension") ?? "", factor: Number(get("factor") ?? 1), offset: Number(get("offset") ?? 0), spellings, ...(extension ? { extension: true } : {}) };
28
+ const r = get("rounding");
29
+ if (r !== undefined)
30
+ u.rounding = Number(r);
31
+ const code = get("uncefact");
32
+ if (code)
33
+ u.uncefact = code;
34
+ table.units.set(name, u);
35
+ }
36
+ if (n.key === "currency")
37
+ table.currencies.set(n.value.trim(), { code: n.value.trim(), name: get("name") ?? "", places: Number(get("places") ?? 2) });
38
+ }
39
+ return table;
40
+ }
41
+ let current = readUnits(STANDARD_UNITS);
42
+ /** The table in force: the standard table at its version, plus any extension. */
43
+ export function unitsTable() {
44
+ return current;
45
+ }
46
+ /** Add an owner's units extension (11.9): its own units under its prefix, and spellings for standard ones. */
47
+ export function extendUnits(text) {
48
+ current = readUnits(text, current, true);
49
+ return current;
50
+ }
51
+ /** Back to the standard table alone. */
52
+ export function resetUnits() {
53
+ current = readUnits(STANDARD_UNITS);
54
+ }
55
+ /** The real unit a spelling names, or null: the unit itself, or one of its spellings, folded. */
56
+ export function unitOf(spelling, table = current) {
57
+ if (table.units.has(spelling))
58
+ return spelling;
59
+ const k = foldSpelling(spelling);
60
+ for (const u of table.units.values())
61
+ if (u.unit.toLowerCase() === k || u.spellings.some((s) => foldSpelling(s) === k))
62
+ return u.unit;
63
+ return null;
64
+ }
65
+ /** Is this a unit the table knows, `currency`, or an ISO 4217 code (1.4.4)? */
66
+ export function knownUnit(u, table = current) {
67
+ return u === "currency" || /^[A-Z]{3}$/.test(u) || table.units.has(u);
68
+ }
69
+ export function dimensionOf(unit, table = current) {
70
+ return table.units.get(unit)?.dimension ?? null;
71
+ }
72
+ /** A currency's minor-unit places (ISO 4217), for a border that asks for them; 2 when unknown. */
73
+ export function currencyPlaces(code, table = current) {
74
+ return table.currencies.get(code)?.places ?? 2;
75
+ }
76
+ /**
77
+ * Convert an amount between units of one dimension: through the base by factor and offset, rounded to
78
+ * `places`, else the dimension's rounding, else 6 places with trailing zeros dropped.
79
+ */
80
+ export function convert(amount, from, to, places, table = current) {
81
+ const a = table.units.get(from);
82
+ const b = table.units.get(to);
83
+ if (!a || !b || a.dimension !== b.dimension)
84
+ return null;
85
+ const base = Number(amount) * a.factor + a.offset;
86
+ const v = (base - b.offset) / b.factor;
87
+ // The facet's places are kept exactly; the dimension's rounding is a most, trailing zeros dropped.
88
+ if (places !== undefined)
89
+ return v.toFixed(places);
90
+ const dimRounding = [...table.units.values()].find((u) => u.dimension === a.dimension && u.factor === 1 && u.offset === 0)?.rounding;
91
+ return String(Number(v.toFixed(dimRounding ?? 6)));
92
+ }
93
+ /** The standard table plus one owner's extension, as a table of its own (11.9): per dictionary, never global. */
94
+ export function unitsTableWith(extension) {
95
+ const table = readUnits(STANDARD_UNITS);
96
+ return extension ? readUnits(extension, table, true) : table;
97
+ }
98
+ //# sourceMappingURL=units.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"units.js","sourceRoot":"","sources":["../../src/units.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,4GAA4G;AAC5G,2GAA2G;AAC3G,yGAAyG;AAC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AAS;QAAE,OAAO,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACnD,MAAM,WAAW,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC;IACrI,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AACrD,CAAC;AAED,iHAAiH;AACjH,MAAM,UAAU,cAAc,CAAC,SAAkB;IAC/C,MAAM,KAAK,GAAG,SAAS,CAAC,cAAc,CAAC,CAAC;IACxC,OAAO,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AAC/D,CAAC"}
@@ -0,0 +1,10 @@
1
+ /** Negative when `a` is the earlier version, positive when it is the later, 0 when they are the same. */
2
+ export declare function compareVersions(a: string, b: string): number;
3
+ /** The latest of some versions, or undefined for none. */
4
+ export declare const latestVersion: (vs: string[]) => string | undefined;
5
+ /**
6
+ * The version a new cut takes: the date it is cut on, a suffix after a cut the same day; never earlier than
7
+ * the version it follows, whose date it carries on with the next suffix when the calendar is behind it (the
8
+ * versions written ahead of the calendar, 2026-11-03).
9
+ */
10
+ export declare function nextVersion(date: string, previous?: string): string;
@@ -0,0 +1,27 @@
1
+ // versions.ts: the order of a member's or a package's versions (11.4, 11.5): a date, `YYYY-MM-DD`, then a
2
+ // second cut that day as `.2`, `.3`… The date compares as text; the suffix as a number, none counting as 1, so
3
+ // `.10` follows `.9` (plain text put it before, 2026-11-03).
4
+ /** Negative when `a` is the earlier version, positive when it is the later, 0 when they are the same. */
5
+ export function compareVersions(a, b) {
6
+ const [ad = "", as = "1"] = String(a).split(".");
7
+ const [bd = "", bs = "1"] = String(b).split(".");
8
+ if (ad !== bd)
9
+ return ad < bd ? -1 : 1;
10
+ return Number(as) - Number(bs);
11
+ }
12
+ /** The latest of some versions, or undefined for none. */
13
+ export const latestVersion = (vs) => [...vs].sort(compareVersions).at(-1);
14
+ /**
15
+ * The version a new cut takes: the date it is cut on, a suffix after a cut the same day; never earlier than
16
+ * the version it follows, whose date it carries on with the next suffix when the calendar is behind it (the
17
+ * versions written ahead of the calendar, 2026-11-03).
18
+ */
19
+ export function nextVersion(date, previous) {
20
+ if (!previous)
21
+ return date;
22
+ const [pd = "", ps = "1"] = String(previous).split(".");
23
+ if (pd < date)
24
+ return date;
25
+ return `${pd}.${Number(ps) + 1}`;
26
+ }
27
+ //# sourceMappingURL=versions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"versions.js","sourceRoot":"","sources":["../../src/versions.ts"],"names":[],"mappings":"AAAA,0GAA0G;AAC1G,+GAA+G;AAC/G,6DAA6D;AAE7D,yGAAyG;AACzG,MAAM,UAAU,eAAe,CAAC,CAAS,EAAE,CAAS;IAClD,MAAM,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACjD,MAAM,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACjD,IAAI,EAAE,KAAK,EAAE;QAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACvC,OAAO,MAAM,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;AACjC,CAAC;AAED,0DAA0D;AAC1D,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,EAAY,EAAsB,EAAE,CAChE,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AAEvC;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,QAAiB;IACzD,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC3B,MAAM,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,GAAG,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACxD,IAAI,EAAE,GAAG,IAAI;QAAE,OAAO,IAAI,CAAC;IAC3B,OAAO,GAAG,EAAE,IAAI,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC;AACnC,CAAC"}
@@ -0,0 +1,372 @@
1
+ import type { Access } from "./access.ts";
2
+ import type { Dictionary } from "./defs.ts";
3
+ export { facetOf, leafOf } from "./address.ts";
4
+ import type { Json, JsonObject, Record } from "./model.ts";
5
+ import { type RecordSet } from "./records.ts";
6
+ export declare const AUDIENCES: readonly ["public", "member", "staff", "owner"];
7
+ export type Slot = {
8
+ from: string;
9
+ to: string;
10
+ required: boolean;
11
+ line: number;
12
+ };
13
+ export type Shape = {
14
+ name: string;
15
+ slots: Slot[];
16
+ line: number;
17
+ };
18
+ /**
19
+ * A display (12.9): a template for a screen over a view, designed once and carried by a package. It names
20
+ * the layout family it is built on, the slots it fills from the view's shape (`shapeSlot -> displaySlot`),
21
+ * its tokens (columns, interval, scale, colours: words the app reads, nothing the engine computes) and the
22
+ * words a screen shows for it.
23
+ */
24
+ export type Display = {
25
+ name: string;
26
+ label?: string;
27
+ describe?: string;
28
+ layout: string;
29
+ slots: {
30
+ from: string;
31
+ to: string;
32
+ line: number;
33
+ }[];
34
+ tokens: Map<string, string>;
35
+ line: number;
36
+ };
37
+ /** A box on a print's art, as fractions of its width (x, w) and height (y, h): 0 to 1 (12.12). */
38
+ export type PrintBox = {
39
+ x: number;
40
+ y: number;
41
+ w: number;
42
+ h: number;
43
+ };
44
+ /** What a print's text draws: a field of the print, or a literal with `{field}` places in it. */
45
+ export type PrintSource = {
46
+ field: string;
47
+ } | {
48
+ literal: string;
49
+ };
50
+ /** One element of a print (12.12): a rect, a barcode, a QR or a line of text, on the art's normalized boxes. */
51
+ export type PrintElement = {
52
+ type: "rect";
53
+ box: PrintBox;
54
+ fill: "white" | "black" | "none";
55
+ stroke?: number;
56
+ line: number;
57
+ } | {
58
+ type: "barcode";
59
+ box: PrintBox;
60
+ field: string;
61
+ rotate?: "cw" | "ccw";
62
+ text?: boolean;
63
+ line: number;
64
+ } | {
65
+ type: "qr";
66
+ box: PrintBox;
67
+ field: string;
68
+ gravity?: "bottom-right" | "top-left";
69
+ line: number;
70
+ }
71
+ /** Revision 28: a picture, the field's value an image's address, fit within the box. */
72
+ | {
73
+ type: "image";
74
+ box: PrintBox;
75
+ field: string;
76
+ line: number;
77
+ } | {
78
+ type: "text";
79
+ x: number;
80
+ y: number;
81
+ size: number;
82
+ source: PrintSource;
83
+ anchor?: "start" | "middle" | "end";
84
+ weight?: "bold";
85
+ clip?: PrintBox;
86
+ rotate?: "cw" | "ccw" | "180"; /** Revision 27: the words wrap into this many lines, 2 to 9. */
87
+ lines?: number;
88
+ line: number;
89
+ };
90
+ /** A print's field: the slot its elements name, and what fills it: a facet, `id`, or a brand slot `place:…`. */
91
+ export type PrintField = {
92
+ slot: string;
93
+ from: string;
94
+ line: number;
95
+ };
96
+ /**
97
+ * A print (12.12): a label design, a member carried by a package. What class or kind it prints, its intrinsic
98
+ * inches, whether it stretches to a stock of another aspect or keeps its own, its fields and its elements.
99
+ * The engine reads, checks and carries it; the app resolves it to a stock and renders it.
100
+ */
101
+ export type Print = {
102
+ name: string;
103
+ label?: string;
104
+ describe?: string;
105
+ for: string;
106
+ inches: {
107
+ w: number;
108
+ h: number;
109
+ };
110
+ stretch: boolean;
111
+ fields: PrintField[];
112
+ elements: PrintElement[];
113
+ line: number;
114
+ };
115
+ /** The brand slots a print's field may draw from the place that prints it (12.12). */
116
+ export declare const PRINT_PLACE_SLOTS: readonly ["name", "mark", "primary", "accent", "words"];
117
+ export type Period = "day" | "week" | "month" | "quarter" | "year";
118
+ export declare const PERIODS: readonly Period[];
119
+ /** The two buckets of a filter over a mark (12.3, revision 34): no real value, and one. */
120
+ export declare const MARK_OPEN = "open";
121
+ export declare const MARK_DONE = "done";
122
+ export type Bucket = {
123
+ name: string;
124
+ values?: string[];
125
+ range?: [number, number];
126
+ period?: Period;
127
+ marked?: "open" | "done";
128
+ };
129
+ export type Filter = {
130
+ name: string;
131
+ facet: string;
132
+ buckets?: Bucket[];
133
+ /** `buckets: by month`: one bucket per period the facet's dates fall in, named by the period (12.3). */
134
+ period?: Period;
135
+ /** `buckets: marked` (revision 34): two buckets, `open` (no real value for the facet) and `done` (one). */
136
+ marked?: true;
137
+ /** Facets totalled per bucket beside the count (12.3 `sum:`). */
138
+ sums: string[];
139
+ dependent: string[];
140
+ line: number;
141
+ bucketLines: number[];
142
+ };
143
+ /**
144
+ * The period a date or moment falls in, named: a day `2026-10-21`, a week `2026-W43` (ISO, Monday first), a
145
+ * month `2026-10`, a quarter `2026-Q4`, a year `2026`; undefined for a value with no date in it.
146
+ */
147
+ export declare function periodOf(value: string, period: Period): string | undefined;
148
+ export type View = {
149
+ name: string;
150
+ line: number;
151
+ level?: string;
152
+ wears: string[];
153
+ when?: string;
154
+ list?: string;
155
+ of?: string;
156
+ pin: string[];
157
+ hide: string[];
158
+ order: {
159
+ key: string;
160
+ dir: "after" | "before";
161
+ }[];
162
+ page: number;
163
+ shapes: string[];
164
+ filters: string[];
165
+ index: string[];
166
+ indexLine: number;
167
+ show: string;
168
+ fresh: string;
169
+ /** `administered`, `controlled`, `owned`, `relation <name>`, `linked <facet>` or `none` (12.2); absent takes the default. */
170
+ partition?: string;
171
+ /** The dated version; a new version starts the view's stream over (12.6). */
172
+ version?: string;
173
+ };
174
+ export type RoleDef = {
175
+ name: string;
176
+ audience: string;
177
+ see: string[];
178
+ seeLine: number;
179
+ line: number;
180
+ };
181
+ /** A show rule with a `for`: it decides for the records its class, kind or level covers (12.4). */
182
+ export type ShownFor = {
183
+ for: string;
184
+ audience: string;
185
+ };
186
+ export type ViewSet = {
187
+ shapes: Map<string, Shape>;
188
+ displays: Map<string, Display>;
189
+ prints: Map<string, Print>;
190
+ filters: Map<string, Filter>;
191
+ views: Map<string, View>;
192
+ roles: Map<string, RoleDef>;
193
+ shown: Map<string, string>;
194
+ shownFor: Map<string, ShownFor[]>;
195
+ };
196
+ /** The member maps of a view set, for merging one set onto another. */
197
+ export declare const VIEW_SET_KEYS: readonly ["shapes", "displays", "prints", "filters", "views", "roles", "shown", "shownFor"];
198
+ /** An empty view set. */
199
+ export declare const emptyViewSet: () => ViewSet;
200
+ /** The field names a print's text draws: its field, or the `{field}` places of its literal. */
201
+ export declare const printSourceFields: (s: PrintSource) => string[];
202
+ /** Read shapes, displays, filters, views (with a body), roles and `shown to` rules. */
203
+ export declare function readViews(source: string): ViewSet;
204
+ /**
205
+ * The lowest audience that may see a facet (12.4): a show rule whose `for` covers the record decides for it,
206
+ * a class over a kind or level, else the rule for everywhere; no rule, the public.
207
+ */
208
+ export declare function shownAudience(set: Pick<ViewSet, "shown" | "shownFor">, facet: string, record?: Pick<Record, "kind" | "level" | "wears">, dict?: Pick<Dictionary, "kinds">): string | undefined;
209
+ /** Can an audience see a facet, of this record when one is given? */
210
+ export declare function visibleTo(set: Pick<ViewSet, "shown" | "shownFor">, facet: string, audience: string, record?: Pick<Record, "kind" | "level" | "wears">, dict?: Pick<Dictionary, "kinds">): boolean;
211
+ export declare function checkViews(set: ViewSet, dict: Dictionary): void;
212
+ export type ProjectOptions = {
213
+ audience?: string;
214
+ caller?: Record;
215
+ context?: Record;
216
+ picks?: {
217
+ [filter: string]: string[];
218
+ };
219
+ page?: number;
220
+ /** Access (chapter 14) for partitioned views: the index serves a caller only the rows their edges match. */
221
+ access?: Access;
222
+ /** Only these records: a projector rebuilding the rows a write made stale (12.6) asks for them alone. */
223
+ only?: string[];
224
+ /**
225
+ * Every row in one pass, no page and no counts: a projector publishing the view (12.6) wants the rows,
226
+ * and a page at a time would select and count the whole view once per page (ME: 197 pages of 9,437 units).
227
+ */
228
+ all?: boolean;
229
+ };
230
+ export type Counts = {
231
+ [filter: string]: {
232
+ [bucket: string]: number;
233
+ };
234
+ };
235
+ /** Per filter and bucket, the facets a filter sums (12.3): the total of their numeric values over the bucket's records. */
236
+ export type Sums = {
237
+ [filter: string]: {
238
+ [bucket: string]: {
239
+ [facet: string]: number;
240
+ };
241
+ };
242
+ };
243
+ /** Dependent counts (12.3): filter → bucket → dependent facet → value → count. */
244
+ export type Nested = {
245
+ [filter: string]: {
246
+ [bucket: string]: {
247
+ [dependent: string]: {
248
+ [value: string]: number;
249
+ };
250
+ };
251
+ };
252
+ };
253
+ export type Projection = {
254
+ rows: JsonObject[];
255
+ records: string[];
256
+ counts: Counts;
257
+ sums?: Sums;
258
+ nested?: Nested;
259
+ pages: number;
260
+ indexable: boolean;
261
+ };
262
+ /** One entry of a view's projection stream (12.6, 12.7). */
263
+ export type StreamEntry = {
264
+ projection: string;
265
+ audience: string;
266
+ seq: number;
267
+ record: string;
268
+ row?: JsonObject;
269
+ buckets?: JsonObject;
270
+ sort?: string[];
271
+ pin?: number;
272
+ removed?: true;
273
+ reset?: true;
274
+ };
275
+ /** The shapes the core defines (12.1, 12.5): the portable one, and structured data for the public. */
276
+ export declare const CORE_SHAPES: string[];
277
+ /** A view's partition: what it declares, else `controlled` above member and `none` otherwise (12.2). */
278
+ export declare function partitionOf(v: View): string;
279
+ export declare class Views {
280
+ readonly dict: Dictionary;
281
+ readonly set: ViewSet;
282
+ private records;
283
+ private engine;
284
+ /** Over a record set of the caller's (a store's working set), or an empty memory set to `put` into. */
285
+ constructor(dict: Dictionary, set: ViewSet, records?: RecordSet);
286
+ put(r: Record): void;
287
+ private effective;
288
+ /** The classes a record wears, those of the records above it included (5.5). */
289
+ private wearsOf;
290
+ private below;
291
+ /**
292
+ * The records a link facet points at: shared parts, read through (1.6). A link into a vocabulary (`wd`,
293
+ * `gpc`) or to a url points at no record here and reads nothing.
294
+ */
295
+ private linked;
296
+ /** The rows of a compound on a record, as objects. */
297
+ private rowsOf;
298
+ /** The values an address reads, as a list: own values, or a lower level's (`unit::price`). */
299
+ private valuesAt;
300
+ /** Is a value fit for this audience's eyes? New, unknown and held values never reach the public. */
301
+ private fit;
302
+ private canSee;
303
+ private slot;
304
+ /**
305
+ * What a condition reads of a record (6.3): the envelope under `crubal:`, and bare `id` and `status`
306
+ * too unless a facet of that name holds a value, which then wins.
307
+ */
308
+ private conditionValues;
309
+ /** The values of the view's order keys as text, and the pin position: what an index orders rows by (12.7). */
310
+ sortOf(v: View, r: Record): {
311
+ sort: string[];
312
+ pin?: number;
313
+ };
314
+ /**
315
+ * An order key's text on a record: the record's own value, or (revision 34, erratum) the first value an address
316
+ * reads, so a view may sort by what a link reaches (`pickUnit.filedSlot`: the walking order).
317
+ */
318
+ private orderText;
319
+ /** The buckets a record falls into, per filter of the view (12.6): what an index counts from. */
320
+ bucketsFor(v: View, r: Record): JsonObject;
321
+ /** Dependent counts (12.3) over records already narrowed by the other filters. */
322
+ nestedCounts(v: View, pool: (f: string) => Record[]): Nested;
323
+ /** Does a view select this record (its own tests, before curation and the shape's required slots)? */
324
+ private selects;
325
+ /** The records a list holds, in its order (12.2): the links in its `crubal:items`. */
326
+ private listed;
327
+ private inBucket;
328
+ /**
329
+ * A filter's buckets: the ones it declares, else one per value of the facet's list. A facet with no list (a
330
+ * link into a vocabulary, a number, a text) buckets by the values the records carry, each its own bucket
331
+ * named by the value (12.3): given a record, its values; given none, nothing is known in advance.
332
+ */
333
+ private bucketsOf;
334
+ /** Does the filter bucket by the values records carry, with no list known in advance (12.3): a period, or a facet with no list? */
335
+ private unlisted;
336
+ /** A facet's numeric value on a record, summed over its values: money by its amount, a number as it is. */
337
+ private numberOf;
338
+ /** The records a view selects, curated and ordered, before filters and paging. */
339
+ select(v: View, opts?: ProjectOptions): Record[];
340
+ /** The roles whose `see` a slot needs above member (12.6 role marks): none when members may see it. */
341
+ private marksFor;
342
+ /** A view's projection for an audience (or a caller), with filter counts and a page. */
343
+ project(name: string, opts?: ProjectOptions): Projection;
344
+ /** One record in one shape: a core shape's object, or the shape's slots with their role marks. */
345
+ private shaped;
346
+ /** A nested view's rows for a page record (12.1, 12.2 `of`): every page, in the view's order. */
347
+ private nestedRows;
348
+ /**
349
+ * Structured data (12.5): schema.org JSON-LD for the public from the kind's type per level (11.2) and
350
+ * each facet's `same-as` in the schema prefix; nothing for any other audience.
351
+ */
352
+ jsonld(r: Record, audience?: string): JsonObject | undefined;
353
+ private streams;
354
+ /** A view's version, as its stream names it. */
355
+ versionOf(name: string): string;
356
+ /** A new version of a view: its stream starts over at the next publish (12.6). */
357
+ revise(name: string, version: string): void;
358
+ /**
359
+ * The projection stream (12.6): the entries since the last publish of this view for this audience, one
360
+ * per row that is new or changed, and one removal per row that left. Numbered per view and audience; a
361
+ * new version of the view starts over at 1, its first entry marked `reset`.
362
+ */
363
+ stream(name: string, opts?: Omit<ProjectOptions, "page" | "picks">): StreamEntry[];
364
+ /** The current version's entries after `seq`, for an index resuming from its cursor (12.6.2); at most `limit` when given. */
365
+ entriesSince(name: string, seq: number, audience?: string, limit?: number): StreamEntry[];
366
+ /** The portable shape (12.1): key, label, type and value for every value the audience may see. */
367
+ portable(r: Record, audience?: string, caller?: Record): Json[];
368
+ /** The keys a view reads (12.6), with level prefixes kept. */
369
+ readSet(name: string): Set<string>;
370
+ /** Which of a view's rows a write makes stale: the written record, or what reads it through. */
371
+ staleAfter(name: string, write: Record): string[];
372
+ }