@cruba/crubal 0.1.0 → 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/README.md +30 -2
- package/dist/bin/crubal.js +70 -4
- package/dist/bin/crubal.js.map +1 -1
- 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/bundle.d.ts +66 -0
- package/dist/src/bundle.js +753 -0
- package/dist/src/bundle.js.map +1 -0
- package/dist/src/conditions.d.ts +7 -1
- package/dist/src/conditions.js +52 -11
- package/dist/src/conditions.js.map +1 -1
- package/dist/src/corpus.js +568 -34
- package/dist/src/corpus.js.map +1 -1
- package/dist/src/defs.d.ts +37 -2
- package/dist/src/defs.js +95 -14
- package/dist/src/defs.js.map +1 -1
- package/dist/src/dictionary.d.ts +15 -0
- package/dist/src/dictionary.js +72 -13
- package/dist/src/dictionary.js.map +1 -1
- package/dist/src/exchange.d.ts +202 -11
- package/dist/src/exchange.js +759 -45
- package/dist/src/exchange.js.map +1 -1
- 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 +18 -6
- package/dist/src/index.js +17 -5
- package/dist/src/index.js.map +1 -1
- 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 +24 -1
- package/dist/src/migrate.js +104 -9
- package/dist/src/migrate.js.map +1 -1
- package/dist/src/model.d.ts +33 -1
- package/dist/src/model.js +158 -2
- package/dist/src/model.js.map +1 -1
- package/dist/src/packages.d.ts +44 -0
- package/dist/src/packages.js +137 -3
- package/dist/src/packages.js.map +1 -1
- package/dist/src/print-text.js +22 -0
- package/dist/src/print-text.js.map +1 -1
- 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 +2 -0
- package/dist/src/read-text.js +72 -4
- package/dist/src/read-text.js.map +1 -1
- 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 +34 -2
- package/dist/src/rules.js +147 -22
- package/dist/src/rules.js.map +1 -1
- 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 +38 -7
- package/dist/src/store.js +166 -24
- package/dist/src/store.js.map +1 -1
- package/dist/src/tree.d.ts +3 -0
- package/dist/src/tree.js +36 -0
- package/dist/src/tree.js.map +1 -1
- 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 -4
- package/dist/src/units.js +91 -30
- package/dist/src/units.js.map +1 -1
- package/dist/src/views.d.ts +108 -6
- package/dist/src/views.js +389 -64
- package/dist/src/views.js.map +1 -1
- package/package.json +5 -3
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
// units-table.ts: the standard units table, crubal.com/units, as published in std/units/units.crubal. Generated by
|
|
2
|
+
// `npm run embed` in packages/crubal; a test refuses a copy that has drifted from the file.
|
|
3
|
+
export const STANDARD_UNITS = `// The units table's records (11.9). The base unit of each dimension has factor 1 and states the rounding a
|
|
4
|
+
// conversion keeps when the facet states none.
|
|
5
|
+
crubal: 2
|
|
6
|
+
package: crubal.com/units /2026-10-15
|
|
7
|
+
owner: crubal.com
|
|
8
|
+
|
|
9
|
+
measure: s
|
|
10
|
+
dimension: time
|
|
11
|
+
factor: 1
|
|
12
|
+
rounding: 3
|
|
13
|
+
spellings: sec, secs, second, seconds
|
|
14
|
+
uncefact: SEC
|
|
15
|
+
measure: min
|
|
16
|
+
dimension: time
|
|
17
|
+
factor: 60
|
|
18
|
+
spellings: MIN., mins, minute, minutes
|
|
19
|
+
uncefact: MIN
|
|
20
|
+
measure: h
|
|
21
|
+
dimension: time
|
|
22
|
+
factor: 3600
|
|
23
|
+
spellings: hr, hrs, hour, hours
|
|
24
|
+
uncefact: HUR
|
|
25
|
+
measure: d
|
|
26
|
+
dimension: time
|
|
27
|
+
factor: 86400
|
|
28
|
+
spellings: day, days
|
|
29
|
+
uncefact: DAY
|
|
30
|
+
|
|
31
|
+
measure: m
|
|
32
|
+
dimension: length
|
|
33
|
+
factor: 1
|
|
34
|
+
rounding: 4
|
|
35
|
+
spellings: meter, meters, metre, metres
|
|
36
|
+
uncefact: MTR
|
|
37
|
+
measure: mm
|
|
38
|
+
dimension: length
|
|
39
|
+
factor: 0.001
|
|
40
|
+
uncefact: MMT
|
|
41
|
+
measure: cm
|
|
42
|
+
dimension: length
|
|
43
|
+
factor: 0.01
|
|
44
|
+
uncefact: CMT
|
|
45
|
+
measure: km
|
|
46
|
+
dimension: length
|
|
47
|
+
factor: 1000
|
|
48
|
+
uncefact: KMT
|
|
49
|
+
measure: in
|
|
50
|
+
dimension: length
|
|
51
|
+
factor: 0.0254
|
|
52
|
+
spellings: inch, inches
|
|
53
|
+
uncefact: INH
|
|
54
|
+
measure: ft
|
|
55
|
+
dimension: length
|
|
56
|
+
factor: 0.3048
|
|
57
|
+
spellings: foot, feet
|
|
58
|
+
uncefact: FOT
|
|
59
|
+
measure: mi
|
|
60
|
+
dimension: length
|
|
61
|
+
factor: 1609.344
|
|
62
|
+
spellings: mile, miles
|
|
63
|
+
uncefact: SMI
|
|
64
|
+
|
|
65
|
+
measure: kg
|
|
66
|
+
dimension: mass
|
|
67
|
+
factor: 1
|
|
68
|
+
rounding: 4
|
|
69
|
+
spellings: kilogram, kilograms
|
|
70
|
+
uncefact: KGM
|
|
71
|
+
measure: g
|
|
72
|
+
dimension: mass
|
|
73
|
+
factor: 0.001
|
|
74
|
+
spellings: gram, grams
|
|
75
|
+
uncefact: GRM
|
|
76
|
+
measure: oz
|
|
77
|
+
dimension: mass
|
|
78
|
+
factor: 0.028349523125
|
|
79
|
+
spellings: ounce, ounces
|
|
80
|
+
uncefact: ONZ
|
|
81
|
+
measure: lb
|
|
82
|
+
dimension: mass
|
|
83
|
+
factor: 0.45359237
|
|
84
|
+
spellings: lbs, pound, pounds
|
|
85
|
+
uncefact: LBR
|
|
86
|
+
|
|
87
|
+
measure: L
|
|
88
|
+
dimension: volume
|
|
89
|
+
factor: 1
|
|
90
|
+
rounding: 3
|
|
91
|
+
spellings: l, liter, liters, litre, litres
|
|
92
|
+
uncefact: LTR
|
|
93
|
+
measure: mL
|
|
94
|
+
dimension: volume
|
|
95
|
+
factor: 0.001
|
|
96
|
+
spellings: ml, milliliter, milliliters, millilitre, millilitres
|
|
97
|
+
uncefact: MLT
|
|
98
|
+
measure: floz
|
|
99
|
+
dimension: volume
|
|
100
|
+
factor: 0.0295735295625
|
|
101
|
+
spellings: fl oz, fl. oz., fluid ounce, fluid ounces
|
|
102
|
+
uncefact: OZA
|
|
103
|
+
measure: gal
|
|
104
|
+
dimension: volume
|
|
105
|
+
factor: 3.785411784
|
|
106
|
+
spellings: gallon, gallons
|
|
107
|
+
uncefact: GLL
|
|
108
|
+
|
|
109
|
+
measure: m2
|
|
110
|
+
dimension: area
|
|
111
|
+
factor: 1
|
|
112
|
+
rounding: 4
|
|
113
|
+
spellings: m², sqm, square meter, square meters
|
|
114
|
+
uncefact: MTK
|
|
115
|
+
measure: ft2
|
|
116
|
+
dimension: area
|
|
117
|
+
factor: 0.09290304
|
|
118
|
+
spellings: ft², sqft, square foot, square feet
|
|
119
|
+
uncefact: FTK
|
|
120
|
+
|
|
121
|
+
measure: K
|
|
122
|
+
dimension: temperature
|
|
123
|
+
factor: 1
|
|
124
|
+
rounding: 2
|
|
125
|
+
spellings: kelvin
|
|
126
|
+
uncefact: KEL
|
|
127
|
+
measure: °C
|
|
128
|
+
dimension: temperature
|
|
129
|
+
factor: 1
|
|
130
|
+
offset: 273.15
|
|
131
|
+
spellings: C, degC, celsius
|
|
132
|
+
uncefact: CEL
|
|
133
|
+
measure: °F
|
|
134
|
+
dimension: temperature
|
|
135
|
+
factor: 0.5555555555555556
|
|
136
|
+
offset: 255.37222222222223
|
|
137
|
+
spellings: F, degF, fahrenheit
|
|
138
|
+
uncefact: FAH
|
|
139
|
+
|
|
140
|
+
measure: B
|
|
141
|
+
dimension: data
|
|
142
|
+
factor: 1
|
|
143
|
+
rounding: 0
|
|
144
|
+
spellings: byte, bytes
|
|
145
|
+
uncefact: AD
|
|
146
|
+
measure: KB
|
|
147
|
+
dimension: data
|
|
148
|
+
factor: 1000
|
|
149
|
+
uncefact: 2P
|
|
150
|
+
measure: MB
|
|
151
|
+
dimension: data
|
|
152
|
+
factor: 1000000
|
|
153
|
+
uncefact: 4L
|
|
154
|
+
measure: GB
|
|
155
|
+
dimension: data
|
|
156
|
+
factor: 1000000000
|
|
157
|
+
uncefact: E34
|
|
158
|
+
measure: TB
|
|
159
|
+
dimension: data
|
|
160
|
+
factor: 1000000000000
|
|
161
|
+
uncefact: E35
|
|
162
|
+
|
|
163
|
+
measure: each
|
|
164
|
+
dimension: count
|
|
165
|
+
factor: 1
|
|
166
|
+
rounding: 0
|
|
167
|
+
spellings: ea, pc, pcs, piece, pieces
|
|
168
|
+
uncefact: EA
|
|
169
|
+
measure: dozen
|
|
170
|
+
dimension: count
|
|
171
|
+
factor: 12
|
|
172
|
+
spellings: dz, doz
|
|
173
|
+
uncefact: DZN
|
|
174
|
+
|
|
175
|
+
currency: USD
|
|
176
|
+
name: US dollar
|
|
177
|
+
places: 2
|
|
178
|
+
currency: EUR
|
|
179
|
+
name: Euro
|
|
180
|
+
places: 2
|
|
181
|
+
currency: GBP
|
|
182
|
+
name: Pound sterling
|
|
183
|
+
places: 2
|
|
184
|
+
currency: CAD
|
|
185
|
+
name: Canadian dollar
|
|
186
|
+
places: 2
|
|
187
|
+
currency: AUD
|
|
188
|
+
name: Australian dollar
|
|
189
|
+
places: 2
|
|
190
|
+
currency: MXN
|
|
191
|
+
name: Mexican peso
|
|
192
|
+
places: 2
|
|
193
|
+
currency: JPY
|
|
194
|
+
name: Yen
|
|
195
|
+
places: 0
|
|
196
|
+
currency: BHD
|
|
197
|
+
name: Bahraini dinar
|
|
198
|
+
places: 3
|
|
199
|
+
`;
|
|
200
|
+
//# sourceMappingURL=units-table.js.map
|
|
@@ -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"}
|
package/dist/src/units.d.ts
CHANGED
|
@@ -1,4 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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;
|
package/dist/src/units.js
CHANGED
|
@@ -1,37 +1,98 @@
|
|
|
1
|
-
// units.ts:
|
|
2
|
-
//
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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))
|
|
20
58
|
return spelling;
|
|
21
|
-
const
|
|
22
|
-
for (const
|
|
23
|
-
if (
|
|
24
|
-
return u;
|
|
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;
|
|
25
63
|
return null;
|
|
26
64
|
}
|
|
27
|
-
/**
|
|
28
|
-
export function
|
|
29
|
-
|
|
30
|
-
|
|
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);
|
|
31
83
|
if (!a || !b || a.dimension !== b.dimension)
|
|
32
84
|
return null;
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
|
|
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;
|
|
36
97
|
}
|
|
37
98
|
//# sourceMappingURL=units.js.map
|
package/dist/src/units.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"units.js","sourceRoot":"","sources":["../../src/units.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"units.js","sourceRoot":"","sources":["../../src/units.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,4GAA4G;AAC5G,2GAA2G;AAC3G,yGAAyG;AACzG,gCAAgC;AAEhC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAMlD,MAAM,YAAY,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;AAEjG,8EAA8E;AAC9E,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,IAAiB,EAAE,SAAS,GAAG,KAAK;IAC1E,MAAM,KAAK,GAAe,IAAI,IAAI,EAAE,KAAK,EAAE,IAAI,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,GAAG,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IAC3F,KAAK,MAAM,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAC/B,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM,IAAI,CAAC,CAAC,CAAC,GAAG;YAAE,SAAS;QAC1C,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;QAC7E,IAAI,CAAC,CAAC,GAAG,KAAK,SAAS;YAAE,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,I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AM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;IAClD,MAAM,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,mGAAmG;IACnG,IAAI,MAAM,KAAK,SAAS;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"}
|
package/dist/src/views.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type { Access } from "./access.ts";
|
|
1
2
|
import type { Dictionary } from "./defs.ts";
|
|
2
3
|
import type { Json, JsonObject, Record } from "./model.ts";
|
|
4
|
+
import { type RecordSet } from "./records.ts";
|
|
3
5
|
export declare const AUDIENCES: readonly ["public", "member", "staff", "owner"];
|
|
4
6
|
export type Slot = {
|
|
5
7
|
from: string;
|
|
@@ -46,6 +48,10 @@ export type View = {
|
|
|
46
48
|
indexLine: number;
|
|
47
49
|
show: string;
|
|
48
50
|
fresh: string;
|
|
51
|
+
/** `administered`, `controlled`, `owned`, `relation <name>` or `none` (12.2); absent takes the default. */
|
|
52
|
+
partition?: string;
|
|
53
|
+
/** The dated version; a new version starts the view's stream over (12.6). */
|
|
54
|
+
version?: string;
|
|
49
55
|
};
|
|
50
56
|
export type RoleDef = {
|
|
51
57
|
name: string;
|
|
@@ -54,15 +60,28 @@ export type RoleDef = {
|
|
|
54
60
|
seeLine: number;
|
|
55
61
|
line: number;
|
|
56
62
|
};
|
|
63
|
+
/** A show rule with a `for`: it decides for the records its class, kind or level covers (12.4). */
|
|
64
|
+
export type ShownFor = {
|
|
65
|
+
for: string;
|
|
66
|
+
audience: string;
|
|
67
|
+
};
|
|
57
68
|
export type ViewSet = {
|
|
58
69
|
shapes: Map<string, Shape>;
|
|
59
70
|
filters: Map<string, Filter>;
|
|
60
71
|
views: Map<string, View>;
|
|
61
72
|
roles: Map<string, RoleDef>;
|
|
62
73
|
shown: Map<string, string>;
|
|
74
|
+
shownFor: Map<string, ShownFor[]>;
|
|
63
75
|
};
|
|
64
76
|
/** Read shapes, filters, views (with a body), roles and `shown to` rules. */
|
|
65
77
|
export declare function readViews(source: string): ViewSet;
|
|
78
|
+
/**
|
|
79
|
+
* The lowest audience that may see a facet (12.4): a show rule whose `for` covers the record decides for it,
|
|
80
|
+
* a class over a kind or level, else the rule for everywhere; no rule, the public.
|
|
81
|
+
*/
|
|
82
|
+
export declare function shownAudience(set: Pick<ViewSet, "shown" | "shownFor">, facet: string, record?: Pick<Record, "kind" | "level" | "wears">, dict?: Pick<Dictionary, "kinds">): string | undefined;
|
|
83
|
+
/** Can an audience see a facet, of this record when one is given? */
|
|
84
|
+
export declare function visibleTo(set: Pick<ViewSet, "shown" | "shownFor">, facet: string, audience: string, record?: Pick<Record, "kind" | "level" | "wears">, dict?: Pick<Dictionary, "kinds">): boolean;
|
|
66
85
|
export declare function checkViews(set: ViewSet, dict: Dictionary): void;
|
|
67
86
|
export type ProjectOptions = {
|
|
68
87
|
audience?: string;
|
|
@@ -72,26 +91,67 @@ export type ProjectOptions = {
|
|
|
72
91
|
[filter: string]: string[];
|
|
73
92
|
};
|
|
74
93
|
page?: number;
|
|
94
|
+
/** Access (chapter 14) for partitioned views: the index serves a caller only the rows their edges match. */
|
|
95
|
+
access?: Access;
|
|
96
|
+
/** Only these records: a projector rebuilding the rows a write made stale (12.6) asks for them alone. */
|
|
97
|
+
only?: string[];
|
|
98
|
+
/**
|
|
99
|
+
* Every row in one pass, no page and no counts: a projector publishing the view (12.6) wants the rows,
|
|
100
|
+
* and a page at a time would select and count the whole view once per page (ME: 197 pages of 9,437 units).
|
|
101
|
+
*/
|
|
102
|
+
all?: boolean;
|
|
103
|
+
};
|
|
104
|
+
export type Counts = {
|
|
105
|
+
[filter: string]: {
|
|
106
|
+
[bucket: string]: number;
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
/** Dependent counts (12.3): filter → bucket → dependent facet → value → count. */
|
|
110
|
+
export type Nested = {
|
|
111
|
+
[filter: string]: {
|
|
112
|
+
[bucket: string]: {
|
|
113
|
+
[dependent: string]: {
|
|
114
|
+
[value: string]: number;
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
};
|
|
75
118
|
};
|
|
76
119
|
export type Projection = {
|
|
77
120
|
rows: JsonObject[];
|
|
78
121
|
records: string[];
|
|
79
|
-
counts:
|
|
80
|
-
|
|
81
|
-
[bucket: string]: number;
|
|
82
|
-
};
|
|
83
|
-
};
|
|
122
|
+
counts: Counts;
|
|
123
|
+
nested?: Nested;
|
|
84
124
|
pages: number;
|
|
85
125
|
indexable: boolean;
|
|
86
126
|
};
|
|
127
|
+
/** One entry of a view's projection stream (12.6, 12.7). */
|
|
128
|
+
export type StreamEntry = {
|
|
129
|
+
projection: string;
|
|
130
|
+
audience: string;
|
|
131
|
+
seq: number;
|
|
132
|
+
record: string;
|
|
133
|
+
row?: JsonObject;
|
|
134
|
+
buckets?: JsonObject;
|
|
135
|
+
sort?: string[];
|
|
136
|
+
pin?: number;
|
|
137
|
+
removed?: true;
|
|
138
|
+
reset?: true;
|
|
139
|
+
};
|
|
140
|
+
/** The shapes the core defines (12.1, 12.5): the portable one, and structured data for the public. */
|
|
141
|
+
export declare const CORE_SHAPES: string[];
|
|
142
|
+
/** A view's partition: what it declares, else `controlled` above member and `none` otherwise (12.2). */
|
|
143
|
+
export declare function partitionOf(v: View): string;
|
|
87
144
|
export declare class Views {
|
|
88
145
|
readonly dict: Dictionary;
|
|
89
146
|
readonly set: ViewSet;
|
|
90
147
|
private records;
|
|
91
148
|
private engine;
|
|
92
|
-
|
|
149
|
+
/** Over a record set of the caller's (a store's working set), or an empty memory set to `put` into. */
|
|
150
|
+
constructor(dict: Dictionary, set: ViewSet, records?: RecordSet);
|
|
93
151
|
put(r: Record): void;
|
|
94
152
|
private effective;
|
|
153
|
+
/** The classes a record wears, those of the records above it included (5.5). */
|
|
154
|
+
private wearsOf;
|
|
95
155
|
private below;
|
|
96
156
|
/** The values an address reads, as a list: own values, or a lower level's (`unit::price`). */
|
|
97
157
|
private valuesAt;
|
|
@@ -99,12 +159,54 @@ export declare class Views {
|
|
|
99
159
|
private fit;
|
|
100
160
|
private canSee;
|
|
101
161
|
private slot;
|
|
162
|
+
/**
|
|
163
|
+
* What a condition reads of a record (6.3): the envelope under `crubal:`, and bare `id` and `status`
|
|
164
|
+
* too unless a facet of that name holds a value, which then wins.
|
|
165
|
+
*/
|
|
166
|
+
private conditionValues;
|
|
167
|
+
/** The values of the view's order keys as text, and the pin position: what an index orders rows by (12.7). */
|
|
168
|
+
sortOf(v: View, r: Record): {
|
|
169
|
+
sort: string[];
|
|
170
|
+
pin?: number;
|
|
171
|
+
};
|
|
172
|
+
/** The buckets a record falls into, per filter of the view (12.6): what an index counts from. */
|
|
173
|
+
bucketsFor(v: View, r: Record): JsonObject;
|
|
174
|
+
/** Dependent counts (12.3) over records already narrowed by the other filters. */
|
|
175
|
+
nestedCounts(v: View, pool: (f: string) => Record[]): Nested;
|
|
176
|
+
/** Does a view select this record (its own tests, before curation and the shape's required slots)? */
|
|
177
|
+
private selects;
|
|
178
|
+
/** The records a list holds, in its order (12.2): the links in its `crubal:items`. */
|
|
179
|
+
private listed;
|
|
102
180
|
private inBucket;
|
|
103
181
|
private bucketsOf;
|
|
104
182
|
/** The records a view selects, curated and ordered, before filters and paging. */
|
|
105
183
|
select(v: View, opts?: ProjectOptions): Record[];
|
|
184
|
+
/** The roles whose `see` a slot needs above member (12.6 role marks): none when members may see it. */
|
|
185
|
+
private marksFor;
|
|
106
186
|
/** A view's projection for an audience (or a caller), with filter counts and a page. */
|
|
107
187
|
project(name: string, opts?: ProjectOptions): Projection;
|
|
188
|
+
/** One record in one shape: a core shape's object, or the shape's slots with their role marks. */
|
|
189
|
+
private shaped;
|
|
190
|
+
/** A nested view's rows for a page record (12.1, 12.2 `of`): every page, in the view's order. */
|
|
191
|
+
private nestedRows;
|
|
192
|
+
/**
|
|
193
|
+
* Structured data (12.5): schema.org JSON-LD for the public from the kind's type per level (11.2) and
|
|
194
|
+
* each facet's `same-as` in the schema prefix; nothing for any other audience.
|
|
195
|
+
*/
|
|
196
|
+
jsonld(r: Record, audience?: string): JsonObject | undefined;
|
|
197
|
+
private streams;
|
|
198
|
+
/** A view's version, as its stream names it. */
|
|
199
|
+
versionOf(name: string): string;
|
|
200
|
+
/** A new version of a view: its stream starts over at the next publish (12.6). */
|
|
201
|
+
revise(name: string, version: string): void;
|
|
202
|
+
/**
|
|
203
|
+
* The projection stream (12.6): the entries since the last publish of this view for this audience, one
|
|
204
|
+
* per row that is new or changed, and one removal per row that left. Numbered per view and audience; a
|
|
205
|
+
* new version of the view starts over at 1, its first entry marked `reset`.
|
|
206
|
+
*/
|
|
207
|
+
stream(name: string, opts?: Omit<ProjectOptions, "page" | "picks">): StreamEntry[];
|
|
208
|
+
/** The current version's entries after `seq`, for an index resuming from its cursor (12.6.2). */
|
|
209
|
+
entriesSince(name: string, seq: number, audience?: string): StreamEntry[];
|
|
108
210
|
/** The portable shape (12.1): key, label, type and value for every value the audience may see. */
|
|
109
211
|
portable(r: Record, audience?: string, caller?: Record): Json[];
|
|
110
212
|
/** The keys a view reads (12.6), with level prefixes kept. */
|