@elaraai/e3 1.0.108 → 1.0.109
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/dist/src/export.d.ts.map +1 -1
- package/dist/src/export.js +13 -6
- package/dist/src/export.js.map +1 -1
- package/dist/src/export.spec.js +25 -3
- package/dist/src/export.spec.js.map +1 -1
- package/dist/src/function.d.ts +136 -57
- package/dist/src/function.d.ts.map +1 -1
- package/dist/src/function.js +47 -12
- package/dist/src/function.js.map +1 -1
- package/dist/src/function.spec.d.ts +3 -1
- package/dist/src/function.spec.d.ts.map +1 -1
- package/dist/src/function.spec.js +246 -3
- package/dist/src/function.spec.js.map +1 -1
- package/dist/src/index-input.d.ts +162 -0
- package/dist/src/index-input.d.ts.map +1 -0
- package/dist/src/index-input.js +216 -0
- package/dist/src/index-input.js.map +1 -0
- package/dist/src/index-input.spec.d.ts +6 -0
- package/dist/src/index-input.spec.d.ts.map +1 -0
- package/dist/src/index-input.spec.js +269 -0
- package/dist/src/index-input.spec.js.map +1 -0
- package/dist/src/index-read.d.ts +428 -0
- package/dist/src/index-read.d.ts.map +1 -0
- package/dist/src/index-read.js +747 -0
- package/dist/src/index-read.js.map +1 -0
- package/dist/src/index-read.spec.d.ts +6 -0
- package/dist/src/index-read.spec.d.ts.map +1 -0
- package/dist/src/index-read.spec.js +1447 -0
- package/dist/src/index-read.spec.js.map +1 -0
- package/dist/src/index.d.ts +10 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/package.d.ts.map +1 -1
- package/dist/src/package.js +3 -4
- package/dist/src/package.js.map +1 -1
- package/dist/src/record-area.d.ts +12 -0
- package/dist/src/record-area.d.ts.map +1 -1
- package/dist/src/record-area.js +26 -0
- package/dist/src/record-area.js.map +1 -1
- package/dist/src/record-area.spec.js +4 -14
- package/dist/src/record-area.spec.js.map +1 -1
- package/dist/src/record-builders.d.ts +39 -14
- package/dist/src/record-builders.d.ts.map +1 -1
- package/dist/src/record-builders.js.map +1 -1
- package/dist/src/record-entries.spec.js +2 -15
- package/dist/src/record-entries.spec.js.map +1 -1
- package/dist/src/record-index.d.ts +11 -5
- package/dist/src/record-index.d.ts.map +1 -1
- package/dist/src/record-index.js.map +1 -1
- package/dist/src/record-interval.d.ts +7 -0
- package/dist/src/record-interval.d.ts.map +1 -1
- package/dist/src/record-interval.js +7 -0
- package/dist/src/record-interval.js.map +1 -1
- package/dist/src/record-nested-programs.d.ts +63 -511
- package/dist/src/record-nested-programs.d.ts.map +1 -1
- package/dist/src/record-nested-programs.js +403 -222
- package/dist/src/record-nested-programs.js.map +1 -1
- package/dist/src/record-nested.d.ts +60 -10
- package/dist/src/record-nested.d.ts.map +1 -1
- package/dist/src/record-nested.js +65 -23
- package/dist/src/record-nested.js.map +1 -1
- package/dist/src/record-nested.spec.js +113 -34
- package/dist/src/record-nested.spec.js.map +1 -1
- package/dist/src/record-series.spec.js +6 -31
- package/dist/src/record-series.spec.js.map +1 -1
- package/dist/src/record.d.ts +9 -0
- package/dist/src/record.d.ts.map +1 -1
- package/dist/src/record.js +14 -0
- package/dist/src/record.js.map +1 -1
- package/dist/src/task.d.ts +28 -16
- package/dist/src/task.d.ts.map +1 -1
- package/dist/src/task.js +33 -5
- package/dist/src/task.js.map +1 -1
- package/dist/src/test-helpers.d.ts +35 -0
- package/dist/src/test-helpers.d.ts.map +1 -0
- package/dist/src/test-helpers.js +56 -0
- package/dist/src/test-helpers.js.map +1 -0
- package/dist/src/types.d.ts +86 -13
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +3 -3
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
* @packageDocumentation
|
|
45
45
|
*/
|
|
46
46
|
import { ArrayType, BooleanType, DateTimeType, DictType, East, FloatType, FunctionType, IntegerType, NullType, OptionType, SetType, StringType, StructType, VariantType, none, printType, some, variant, } from '@elaraai/east';
|
|
47
|
-
import { NestedEntryKeyType, NestedEntryType, NestedSpanKeyType, RecordLevelType,
|
|
47
|
+
import { NestedEntryKeyType, NestedEntryType, NestedSpanKeyType, RecordLevelType, RecordNestedPathType, RecordNestedRunType, RecordNestedTotalsType, RecordRollupType, RecordSummaryTotalsType, nestedPathValue, nestedSpanName, } from '@elaraai/e3-types';
|
|
48
48
|
import { checkNested } from './record-nested.js';
|
|
49
49
|
import { INDEX_PURITY, checkEntryParams, checkPure, functionAt, indexRunner, indexedEntry, onlyOptions, sameEastType, signatureOf, } from './record-guards.js';
|
|
50
50
|
import { fieldReader } from './record-keys.js';
|
|
@@ -53,29 +53,59 @@ import { RECORD_TILES, TILE_FNS, TileFilingType, TileShareType, TileStepFnType,
|
|
|
53
53
|
import { summaryMerge } from './record-series.js';
|
|
54
54
|
import { lazyBuilds } from './lazy-build.js';
|
|
55
55
|
// ── Fixed shapes ──────────────────────────────────────────────────────────────
|
|
56
|
-
/** A node's keys, from the row down to it, as a row's tree is walked: an Array, which a key may not hold. */
|
|
57
|
-
const KeysType = ArrayType(StringType);
|
|
58
|
-
/** A node of a row's tree: its keys, and its group, which tells nodes of two groups at one path apart. */
|
|
59
|
-
const NodeKeyType = StructType({ path: KeysType, group: IntegerType });
|
|
60
56
|
/**
|
|
61
57
|
* A node of a group, as the walk gives it: its keys, the node above it — none
|
|
62
58
|
* for the row — and the node itself.
|
|
63
59
|
*
|
|
60
|
+
* @param shapes - The index's shapes
|
|
64
61
|
* @param node - The group's node type
|
|
65
62
|
* @returns The struct type
|
|
66
63
|
*/
|
|
67
|
-
function NodeAtType(node) {
|
|
68
|
-
return StructType({ path: KeysType, parent: OptionType(NodeKeyType), node });
|
|
64
|
+
function NodeAtType(shapes, node) {
|
|
65
|
+
return StructType({ path: shapes.KeysType, parent: OptionType(shapes.NodeKeyType), node });
|
|
69
66
|
}
|
|
70
67
|
/**
|
|
71
68
|
* A node of a group: `(keys, parent, node) → NodeAt`.
|
|
72
69
|
*
|
|
70
|
+
* @param shapes - The index's shapes
|
|
73
71
|
* @param node - The group's node type
|
|
74
72
|
* @returns The constructor
|
|
75
73
|
*/
|
|
76
|
-
function nodeAtOf(node) {
|
|
77
|
-
const type = NodeAtType(node);
|
|
78
|
-
return East.function([KeysType, OptionType(NodeKeyType), node], type, (_$, path, parent, at) => ({ path, parent, node: at }));
|
|
74
|
+
function nodeAtOf(shapes, node) {
|
|
75
|
+
const type = NodeAtType(shapes, node);
|
|
76
|
+
return East.function([shapes.KeysType, OptionType(shapes.NodeKeyType), node], type, (_$, path, parent, at) => ({ path, parent, node: at }));
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* A collection's place as an entry's key holds it (e3-types'
|
|
80
|
+
* `RecordNestedPathType`): its field names, folded from the last.
|
|
81
|
+
*
|
|
82
|
+
* @param place - The field names from the row down to the collection
|
|
83
|
+
* @returns The place, as a key's value
|
|
84
|
+
*/
|
|
85
|
+
export function placePath(place) {
|
|
86
|
+
return nestedPathValue(place);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* `(keys) → Path` for an index's readers: a node's keys — each an id of the
|
|
90
|
+
* index's — as its entry key holds them ({@link shapesFor}'s `pathOf`).
|
|
91
|
+
*
|
|
92
|
+
* @param decl - The checked declaration
|
|
93
|
+
* @param entryKey - The entry key, `IK`
|
|
94
|
+
* @returns The function, and the keys' Array type it takes
|
|
95
|
+
*/
|
|
96
|
+
export function nestedPathOf(decl, entryKey) {
|
|
97
|
+
const shapes = shapesOf(decl, entryKey);
|
|
98
|
+
return { pathOf: shapes.fns.pathOf, KeysType: shapes.KeysType, ItemType: shapes.ItemType };
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* `(keys) → Option<keys>`: the keys of the node above, within a walk of a
|
|
102
|
+
* Dict's rows; none for one of its own.
|
|
103
|
+
*
|
|
104
|
+
* @param keys - The keys' Array type
|
|
105
|
+
* @returns The function, over those keys
|
|
106
|
+
*/
|
|
107
|
+
function keysAboveOf(keys) {
|
|
108
|
+
return East.function([keys], OptionType(keys), (_$, at) => East.greater(at.size(), 1n).ifElse(() => some(at.slice(0n, at.size().subtract(1n))), () => none));
|
|
79
109
|
}
|
|
80
110
|
/** No totals: a tile's before any item touches it. */
|
|
81
111
|
const NO_TOTALS = { count: 0n, ms: 0n, values: none };
|
|
@@ -99,14 +129,8 @@ const EPOCH = new Date(0);
|
|
|
99
129
|
*/
|
|
100
130
|
const SubtotalTilesType = VariantType({ all: NullType, only: DictType(RecordLevelType, SpanType) });
|
|
101
131
|
// ── Parents' subtotals: composed bottom-up ────────────────────────────────────
|
|
102
|
-
/** A node of the tree from a row down to a collection of values rolled up: where it is, the node above it, and its own values as Floats. */
|
|
103
|
-
const SubtotalNodeType = StructType({ key: NodeKeyType, parent: OptionType(NodeKeyType), own: DictType(DateTimeType, FloatType) });
|
|
104
132
|
/** What a node draws by one rollup, at one level, in one tile. */
|
|
105
133
|
const DrawKeyType = StructType({ rollup: RecordRollupType, level: RecordLevelType, tile: DateTimeType });
|
|
106
|
-
/** A parent's subtotal: its path, the rollup, the level and the tile. */
|
|
107
|
-
const SubtotalKeyType = StructType({ path: RecordNestedPathType, rollup: RecordRollupType, level: RecordLevelType, tile: DateTimeType });
|
|
108
|
-
/** A node's result, carried to its parent: what it draws, and the subtotals of every parent at or beneath it. */
|
|
109
|
-
const ComposedType = StructType({ draws: DictType(DrawKeyType, FloatType), subtotals: DictType(SubtotalKeyType, FloatType) });
|
|
110
134
|
/** What a node's own values in a tile come to, before a rollup's fold picks one: their sum and how many, the least, the greatest and the latest. */
|
|
111
135
|
const FoldedType = StructType({ sum: FloatType, n: IntegerType, min: FloatType, max: FloatType, last: FloatType });
|
|
112
136
|
/** What a parent's children draw in a tile come to, before a rollup's aggregate picks one. */
|
|
@@ -236,11 +260,11 @@ function noValues(nodeType) {
|
|
|
236
260
|
* field — beside `recursive()`, with every row beneath them through it, by
|
|
237
261
|
* `flattenTree` — each with its keys and the node above it.
|
|
238
262
|
*/
|
|
239
|
-
function groupNodes(decl, rowType) {
|
|
263
|
+
function groupNodes(decl, shapes, rowType) {
|
|
240
264
|
const nodes = [];
|
|
241
265
|
for (const group of decl.groups) {
|
|
242
|
-
const nodeAt = ArrayType(NodeAtType(group.type));
|
|
243
|
-
const make = nodeAtOf(group.type);
|
|
266
|
+
const nodeAt = ArrayType(NodeAtType(shapes, group.type));
|
|
267
|
+
const make = nodeAtOf(shapes, group.type);
|
|
244
268
|
if (group.parent === undefined) {
|
|
245
269
|
nodes.push(East.function([rowType], nodeAt, ($, row) => {
|
|
246
270
|
const at = $.const(make);
|
|
@@ -250,42 +274,81 @@ function groupNodes(decl, rowType) {
|
|
|
250
274
|
}
|
|
251
275
|
const parent = decl.groups[group.parent.group];
|
|
252
276
|
const above = nodes[parent.index];
|
|
253
|
-
|
|
277
|
+
// The group's rows by their keys, each key an id of the index's under the group's case (#1540).
|
|
278
|
+
const keyed = keyedOf(group);
|
|
279
|
+
const rowsType = DictType(keyed.type, group.type);
|
|
280
|
+
const rowsOf = fieldOf(parent.type, group.parent.field, rowsType);
|
|
281
|
+
const idOf = idIn(decl, keyed.idCase, keyed.type);
|
|
254
282
|
const parentGroup = BigInt(parent.index);
|
|
255
283
|
const ownGroup = BigInt(group.index);
|
|
256
284
|
if (group.through === undefined) {
|
|
257
285
|
nodes.push(East.function([rowType], nodeAt, ($, row) => {
|
|
258
286
|
const up = $.const(above);
|
|
259
287
|
const rows = $.const(rowsOf);
|
|
288
|
+
const id = $.const(idOf);
|
|
260
289
|
const nodeAt = $.const(make);
|
|
261
|
-
return up(row).flatMap((_$, at) => rows(at.node).toArray((_$, node, key) => nodeAt(at.path.concat([key]), some({ path: at.path, group: parentGroup }), node)));
|
|
290
|
+
return up(row).flatMap((_$, at) => rows(at.node).toArray((_$, node, key) => nodeAt(at.path.concat([id(key)]), some({ path: at.path, group: parentGroup }), node)));
|
|
262
291
|
}));
|
|
263
292
|
continue;
|
|
264
293
|
}
|
|
265
|
-
const deeper = fieldOf(group.type, group.through,
|
|
294
|
+
const deeper = fieldOf(group.type, group.through, rowsType);
|
|
266
295
|
nodes.push(East.function([rowType], nodeAt, ($, row) => {
|
|
267
296
|
const up = $.const(above);
|
|
268
297
|
const rows = $.const(rowsOf);
|
|
269
298
|
const beneath = $.const(deeper);
|
|
270
|
-
const
|
|
299
|
+
const id = $.const(idOf);
|
|
300
|
+
const keysOver = $.const(shapes.fns.keysAbove);
|
|
271
301
|
const nodeAt = $.const(make);
|
|
272
|
-
return up(row).flatMap((_$, at) => rows(at.node).flattenTree((_$, node) => beneath(node)).map((
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
302
|
+
return up(row).flatMap((_$, at) => rows(at.node).flattenTree((_$, node) => beneath(node)).map(($2, entry) => {
|
|
303
|
+
const ids = $2.let(entry.path.map((_$, key) => id(key)), shapes.KeysType);
|
|
304
|
+
return nodeAt(at.path.concat(ids),
|
|
305
|
+
// A node's parent: the row above it in this walk, or the parent group's node holding the walk's root.
|
|
306
|
+
some(keysOver(ids).match({
|
|
307
|
+
some: (_$, keys) => ({ path: at.path.concat(keys), group: ownGroup }),
|
|
308
|
+
none: () => ({ path: at.path, group: parentGroup }),
|
|
309
|
+
})), entry.node);
|
|
310
|
+
}));
|
|
278
311
|
}));
|
|
279
312
|
}
|
|
280
313
|
return nodes;
|
|
281
314
|
}
|
|
282
315
|
/** A group's nodes from a row, as a function a part is given: `(V) → Array<NodeAt>`. */
|
|
283
|
-
function WalkType(
|
|
284
|
-
return FunctionType([rowType], ArrayType(NodeAtType(group.type)));
|
|
316
|
+
function WalkType(types, group) {
|
|
317
|
+
return FunctionType([types.rowType], ArrayType(NodeAtType(types.shapes, group.type)));
|
|
318
|
+
}
|
|
319
|
+
/** What a group's nodes are keyed by beneath the node holding them: every group's but the row's. */
|
|
320
|
+
function keyedOf(group) {
|
|
321
|
+
if (group.keyed === undefined)
|
|
322
|
+
throw new Error('a nested series index\'s row is keyed by its record, not beneath a node');
|
|
323
|
+
return group.keyed;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* A key as the index's id (#1540): `(K) → Id`, the key under its collection's
|
|
327
|
+
* case of the index's ids, in its own type.
|
|
328
|
+
*
|
|
329
|
+
* @param decl - The checked declaration
|
|
330
|
+
* @param idCase - The collection's case of the index's ids
|
|
331
|
+
* @param keyType - The collection's Dict's key type
|
|
332
|
+
* @returns The wrapping
|
|
333
|
+
*/
|
|
334
|
+
function idIn(decl, idCase, keyType) {
|
|
335
|
+
const idType = decl.idType;
|
|
336
|
+
return East.function([keyType], idType, (_$, key) => East.inCase(idType, idCase, key));
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* An id's key (#1540): `(Id) → K`, the key out of its collection's case of the
|
|
340
|
+
* index's ids. The inverse of {@link idIn}.
|
|
341
|
+
*
|
|
342
|
+
* @param decl - The checked declaration
|
|
343
|
+
* @param idCase - The collection's case of the index's ids
|
|
344
|
+
* @param keyType - The collection's Dict's key type
|
|
345
|
+
* @returns The unwrapping
|
|
346
|
+
*/
|
|
347
|
+
function idOut(decl, idCase, keyType) {
|
|
348
|
+
const idType = decl.idType;
|
|
349
|
+
return East.function([idType], keyType, (_$, id) => id.unwrap(idCase));
|
|
285
350
|
}
|
|
286
351
|
// ── A program's kit ───────────────────────────────────────────────────────────
|
|
287
|
-
/** `(keys) → Path`: `pathOf`'s type. */
|
|
288
|
-
const PathFnType = FunctionType([KeysType], RecordNestedPathType);
|
|
289
352
|
/** `(tile, start, end, what, startOf, nextOf) → Array<TileFiling>`: `placedFilingsOver`'s type. */
|
|
290
353
|
const FileFnType = FunctionType([RecordLevelType, OptionType(DateTimeType), OptionType(DateTimeType), StringType, TileStepFnType, TileStepFnType], ArrayType(TileFilingType));
|
|
291
354
|
/** `(tile, start, end, what, startOf, nextOf) → Array<TileShare>`: `placedSharesOver`'s type. */
|
|
@@ -302,41 +365,147 @@ const KeptFnType = FunctionType([SpanType, RecordLevelType, DateTimeType, TileSt
|
|
|
302
365
|
const WithinFnType = FunctionType([SetType(DateTimeType), RecordLevelType, TileStepFnType], WithinType);
|
|
303
366
|
/** `(instants, levels, startOf, nextOf) → SubtotalTiles`: `subtotalTiles`' type. */
|
|
304
367
|
const LevelsWithinFnType = FunctionType([SetType(DateTimeType), ArrayType(RecordLevelType), TileStepFnType, TileStepFnType], SubtotalTilesType);
|
|
305
|
-
|
|
306
|
-
const SubtotalsFnType = FunctionType([ArrayType(SubtotalNodeType), ArrayType(RecordRollupType), ArrayType(RecordLevelType), SubtotalTilesType, TileStepFnType], DictType(SubtotalKeyType, FloatType));
|
|
368
|
+
// ── The shapes an index's ids make ────────────────────────────────────────────
|
|
307
369
|
/**
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
370
|
+
* The shapes of a nested series index that hold its ids (#1540): a child
|
|
371
|
+
* row's key on the way from a row down to a node, each in its own type under
|
|
372
|
+
* its collection's case. They are the index's own, made once of its ids and
|
|
373
|
+
* of its key's path and item types, with the functions over them, each built
|
|
374
|
+
* the first time it is read.
|
|
375
|
+
*
|
|
376
|
+
* @param id - The index's ids (e3-types' `NestedIdType`)
|
|
377
|
+
* @param PathType - Its key's path type, over those ids
|
|
378
|
+
* @param ItemType - Its key's item type, over them
|
|
379
|
+
* @returns The shapes, and the functions over them
|
|
312
380
|
*/
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
|
|
316
|
-
/**
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
path:
|
|
320
|
-
/**
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
|
|
324
|
-
/**
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
|
|
328
|
-
/** `
|
|
329
|
-
|
|
330
|
-
/** `
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
/**
|
|
381
|
+
function shapesFor(id, PathType, ItemType) {
|
|
382
|
+
/** A node's keys, from the row down to it, as a row's tree is walked: an Array, which a key may not hold. */
|
|
383
|
+
const KeysType = ArrayType(id);
|
|
384
|
+
/** A node of a row's tree: its keys, and its group, which tells nodes of two groups at one path apart. */
|
|
385
|
+
const NodeKeyType = StructType({ path: KeysType, group: IntegerType });
|
|
386
|
+
/** A node's items' shares of the summary tiles they touch. */
|
|
387
|
+
const NodeSharesType = StructType({ path: KeysType, shares: ArrayType(TileShareType) });
|
|
388
|
+
/** A node of the tree from a row down to a collection of values rolled up: where it is, the node above it, and its own values as Floats. */
|
|
389
|
+
const SubtotalNodeType = StructType({ key: NodeKeyType, parent: OptionType(NodeKeyType), own: DictType(DateTimeType, FloatType) });
|
|
390
|
+
/** A parent's subtotal: its path, the rollup, the level and the tile. */
|
|
391
|
+
const SubtotalKeyType = StructType({ path: PathType, rollup: RecordRollupType, level: RecordLevelType, tile: DateTimeType });
|
|
392
|
+
/** A node's result, carried to its parent: what it draws, and the subtotals of every parent at or beneath it. */
|
|
393
|
+
const ComposedType = StructType({ draws: DictType(DrawKeyType, FloatType), subtotals: DictType(SubtotalKeyType, FloatType) });
|
|
394
|
+
/** Where a node's items are filed: its collection's place and its path, as an entry's key holds them. */
|
|
395
|
+
const NodePlaceType = StructType({ collection: RecordNestedPathType, path: PathType });
|
|
396
|
+
/** `(keys) → Path`: `pathOf`'s type. */
|
|
397
|
+
const PathFnType = FunctionType([KeysType], PathType);
|
|
398
|
+
/** `(nodes, rollups, levels, tiles, startOf) → Dict<SubtotalKey, Float>`: `subtotalsOf`' type. */
|
|
399
|
+
const SubtotalsFnType = FunctionType([ArrayType(SubtotalNodeType), ArrayType(RecordRollupType), ArrayType(RecordLevelType), SubtotalTilesType, TileStepFnType], DictType(SubtotalKeyType, FloatType));
|
|
400
|
+
/**
|
|
401
|
+
* A program's kit: the functions its parts call, bound once in the program's
|
|
402
|
+
* body and handed to every part ({@link programKit}), so a program holds each
|
|
403
|
+
* once, however many of its parts call it. A function stepping through the
|
|
404
|
+
* tiles is given the kit's `startOf` and `nextOf` by its caller.
|
|
405
|
+
*/
|
|
406
|
+
const KitType = StructType({
|
|
407
|
+
/** `tileStart` */
|
|
408
|
+
startOf: TileStepFnType,
|
|
409
|
+
/** `tileNext` */
|
|
410
|
+
nextOf: TileStepFnType,
|
|
411
|
+
/** `pathOf` */
|
|
412
|
+
path: PathFnType,
|
|
413
|
+
/** Where an item is filed: `placedFilingsOver` */
|
|
414
|
+
file: FileFnType,
|
|
415
|
+
/** An item's shares of the tiles it touches: `placedSharesOver` */
|
|
416
|
+
share: ShareFnType,
|
|
417
|
+
/** `sharedTotals` */
|
|
418
|
+
totalled: TotalledFnType,
|
|
419
|
+
/** `instantTotals` */
|
|
420
|
+
counted: CountedFnType,
|
|
421
|
+
/** `valueTotals` */
|
|
422
|
+
summed: SummedFnType,
|
|
423
|
+
/** `inSpan` */
|
|
424
|
+
kept: KeptFnType,
|
|
425
|
+
/** `tilesWithin` */
|
|
426
|
+
within: WithinFnType,
|
|
427
|
+
/** `subtotalTiles` */
|
|
428
|
+
levelsWithin: LevelsWithinFnType,
|
|
429
|
+
/** `subtotalsOf` */
|
|
430
|
+
subtotals: SubtotalsFnType,
|
|
431
|
+
});
|
|
432
|
+
const fns = lazyBuilds({
|
|
433
|
+
/** `(keys) → Path`: a node's keys as a key holds them, folded from the last. */
|
|
434
|
+
get pathOf() {
|
|
435
|
+
return East.function([KeysType], PathType, ($, keys) => {
|
|
436
|
+
const end = $.const(variant('end', null), PathType);
|
|
437
|
+
return keys.reverse().reduce((_$, rest, key) => variant('step', { key, rest }), end);
|
|
438
|
+
});
|
|
439
|
+
},
|
|
440
|
+
/** `(path) → keys`: a node's keys out of a key's path, from the row down — the inverse of `pathOf`. */
|
|
441
|
+
get keysOf() {
|
|
442
|
+
return East.function([PathType], KeysType, ($, path) => {
|
|
443
|
+
const keys = $.let([], KeysType);
|
|
444
|
+
const at = $.let(path);
|
|
445
|
+
$.while(true, ($2, label) => {
|
|
446
|
+
$2.match(at.unwrap(), {
|
|
447
|
+
step: ($3, step) => {
|
|
448
|
+
$3(keys.pushLast(step.key));
|
|
449
|
+
$3.assign(at, step.rest);
|
|
450
|
+
},
|
|
451
|
+
end: ($3) => {
|
|
452
|
+
$3.break(label);
|
|
453
|
+
},
|
|
454
|
+
});
|
|
455
|
+
});
|
|
456
|
+
return keys;
|
|
457
|
+
});
|
|
458
|
+
},
|
|
459
|
+
/** `(keys) → Option<keys>`: the keys of the node above, within a walk of a Dict's rows; none for one of its own. */
|
|
460
|
+
get keysAbove() {
|
|
461
|
+
return keysAboveOf(KeysType);
|
|
462
|
+
},
|
|
463
|
+
/**
|
|
464
|
+
* `(node, children, rollups, levels, tiles, startOf) → Composed`: a node's
|
|
465
|
+
* result, at the tiles asked for. One holding values of its own draws them,
|
|
466
|
+
* and keeps no subtotal; one holding none draws its children's, and keeps what
|
|
467
|
+
* it draws, where it draws, as its subtotals. Either way, it carries every
|
|
468
|
+
* subtotal beneath it on to its parent.
|
|
469
|
+
*/
|
|
470
|
+
get composed() {
|
|
471
|
+
return East.function([SubtotalNodeType, ArrayType(ComposedType), ArrayType(RecordRollupType), ArrayType(RecordLevelType), SubtotalTilesType, TileStepFnType], ComposedType, ($, node, children, rollups, levels, tiles, startOf) => {
|
|
472
|
+
const own = $.const(NESTED_FNS.ownDraws);
|
|
473
|
+
const gathered = $.const(NESTED_FNS.childDraws);
|
|
474
|
+
const path = $.const(fns.pathOf);
|
|
475
|
+
const beneath = $.let(children.flatMap((_$, child) => child.subtotals.toArray((_$, value, key) => ({ key, value })))
|
|
476
|
+
.toDict((_$, subtotal) => subtotal.key, (_$, subtotal) => subtotal.value));
|
|
477
|
+
$.if(East.greater(node.own.size(), 0n), ($) => {
|
|
478
|
+
$.return({ draws: own(node.own, rollups, levels, tiles, startOf), subtotals: beneath });
|
|
479
|
+
});
|
|
480
|
+
const draws = $.let(gathered(children.map((_$, child) => child.draws)));
|
|
481
|
+
const here = $.let(path(node.key.path));
|
|
482
|
+
$(beneath.unionInPlace(draws.toDict((_$, _value, key) => ({ path: here, rollup: key.rollup, level: key.level, tile: key.tile }), (_$, value) => value)));
|
|
483
|
+
return { draws, subtotals: beneath };
|
|
484
|
+
});
|
|
485
|
+
},
|
|
486
|
+
/**
|
|
487
|
+
* `(nodes, rollups, levels, tiles, startOf) → Dict<SubtotalKey, Float>`:
|
|
488
|
+
* every parent's subtotals of a collection of values at the tiles asked for,
|
|
489
|
+
* composed bottom-up by `toTree` over the nodes from the row down to the
|
|
490
|
+
* collection, each node's result carried to its parent. A tile no
|
|
491
|
+
* descendant's value touches has none.
|
|
492
|
+
*/
|
|
493
|
+
get subtotalsOf() {
|
|
494
|
+
return East.function(SubtotalsFnType.inputs, SubtotalsFnType.output, ($, nodes, rollups, levels, tiles, startOf) => {
|
|
495
|
+
const compose = $.const(fns.composed);
|
|
496
|
+
const roots = $.let(nodes.toTree(ComposedType, (_$, node) => node.key, (_$, node) => node.parent, (_$, node, _i, children) => compose(node, children, rollups, levels, tiles, startOf)));
|
|
497
|
+
return roots.flatMap((_$, root) => root.subtotals.toArray((_$, value, key) => ({ key, value })))
|
|
498
|
+
.toDict((_$, subtotal) => subtotal.key, (_$, subtotal) => subtotal.value);
|
|
499
|
+
});
|
|
500
|
+
},
|
|
501
|
+
/** `subtotalsOf`, as a kit holds it where none of its program's parts calls it: one of its type making nothing. */
|
|
502
|
+
get noSubtotals() {
|
|
503
|
+
return East.function(SubtotalsFnType.inputs, SubtotalsFnType.output, () => new Map());
|
|
504
|
+
},
|
|
505
|
+
});
|
|
506
|
+
return { id, KeysType, PathType, ItemType, NodeKeyType, NodeSharesType, SubtotalNodeType, SubtotalKeyType, ComposedType, NodePlaceType, KitType, fns };
|
|
507
|
+
}
|
|
508
|
+
/** Each function of a kit only some parts call that every index shares, as they call it: each read the first time a kit holds it (#1466). */
|
|
340
509
|
export const KIT_CALLED = lazyBuilds({
|
|
341
510
|
get file() { return TILE_FNS.placedFilingsOver; },
|
|
342
511
|
get share() { return TILE_FNS.placedSharesOver; },
|
|
@@ -346,13 +515,13 @@ export const KIT_CALLED = lazyBuilds({
|
|
|
346
515
|
get kept() { return NESTED_FNS.inSpan; },
|
|
347
516
|
get within() { return NESTED_FNS.tilesWithin; },
|
|
348
517
|
get levelsWithin() { return NESTED_FNS.subtotalTiles; },
|
|
349
|
-
get subtotals() { return NESTED_FNS.subtotalsOf; },
|
|
350
518
|
});
|
|
351
519
|
/**
|
|
352
|
-
* Each function of a kit only some parts call
|
|
353
|
-
* its program's parts calls it: one of its type
|
|
354
|
-
* holds only the functions its parts call. Each
|
|
355
|
-
* holds it ({@link lazyBuilds}, #1466).
|
|
520
|
+
* Each function of a kit only some parts call that every index shares, as a
|
|
521
|
+
* kit holds it where none of its program's parts calls it: one of its type
|
|
522
|
+
* making nothing, so a program holds only the functions its parts call. Each
|
|
523
|
+
* built the first time a kit holds it ({@link lazyBuilds}, #1466). A parent's
|
|
524
|
+
* subtotals are an index's own, over its ids ({@link shapesFor}).
|
|
356
525
|
*/
|
|
357
526
|
export const KIT_UNCALLED = lazyBuilds({
|
|
358
527
|
get file() { return East.function(FileFnType.inputs, FileFnType.output, () => []); },
|
|
@@ -363,21 +532,22 @@ export const KIT_UNCALLED = lazyBuilds({
|
|
|
363
532
|
get kept() { return East.function(KeptFnType.inputs, KeptFnType.output, () => false); },
|
|
364
533
|
get within() { return East.function(WithinFnType.inputs, WithinFnType.output, () => variant('all', null)); },
|
|
365
534
|
get levelsWithin() { return East.function(LevelsWithinFnType.inputs, LevelsWithinFnType.output, () => variant('all', null)); },
|
|
366
|
-
get subtotals() { return East.function(SubtotalsFnType.inputs, SubtotalsFnType.output, () => new Map()); },
|
|
367
535
|
});
|
|
368
536
|
/**
|
|
369
|
-
* A program's kit ({@link
|
|
370
|
-
* bound once — the tiles' steps and a path's always, each other the parts
|
|
537
|
+
* A program's kit ({@link shapesFor}): `() → Kit`, each function its parts
|
|
538
|
+
* call bound once — the tiles' steps and a path's always, each other the parts
|
|
371
539
|
* name, and in place of each they do not, one making nothing.
|
|
372
540
|
*
|
|
541
|
+
* @param shapes - The index's shapes
|
|
373
542
|
* @param calls - What the program's parts call of the kit, beside the tiles' steps and a path's
|
|
374
543
|
* @returns The kit
|
|
375
544
|
*/
|
|
376
|
-
function programKit(calls) {
|
|
545
|
+
function programKit(shapes, calls) {
|
|
546
|
+
const { KitType, fns } = shapes;
|
|
377
547
|
const kit = {
|
|
378
548
|
startOf: TILE_FNS.tileStart,
|
|
379
549
|
nextOf: TILE_FNS.tileNext,
|
|
380
|
-
path:
|
|
550
|
+
path: fns.pathOf,
|
|
381
551
|
file: calls.has('file') ? KIT_CALLED.file : KIT_UNCALLED.file,
|
|
382
552
|
share: calls.has('share') ? KIT_CALLED.share : KIT_UNCALLED.share,
|
|
383
553
|
totalled: calls.has('totalled') ? KIT_CALLED.totalled : KIT_UNCALLED.totalled,
|
|
@@ -386,7 +556,7 @@ function programKit(calls) {
|
|
|
386
556
|
kept: calls.has('kept') ? KIT_CALLED.kept : KIT_UNCALLED.kept,
|
|
387
557
|
within: calls.has('within') ? KIT_CALLED.within : KIT_UNCALLED.within,
|
|
388
558
|
levelsWithin: calls.has('levelsWithin') ? KIT_CALLED.levelsWithin : KIT_UNCALLED.levelsWithin,
|
|
389
|
-
subtotals: calls.has('subtotals') ?
|
|
559
|
+
subtotals: calls.has('subtotals') ? fns.subtotalsOf : fns.noSubtotals,
|
|
390
560
|
};
|
|
391
561
|
return East.function([], KitType, () => kit);
|
|
392
562
|
}
|
|
@@ -459,13 +629,14 @@ function touchedItems(keyType, itemType) {
|
|
|
459
629
|
* updated as its own walk leaves it — and none where one on the way was
|
|
460
630
|
* replaced.
|
|
461
631
|
*
|
|
632
|
+
* @param keyType - The child rows' Dict's key type
|
|
462
633
|
* @param nodeType - The child rows' type
|
|
463
634
|
* @param walk - Their walk
|
|
464
635
|
* @returns The walk
|
|
465
636
|
*/
|
|
466
|
-
function touchedRows(nodeType, walk) {
|
|
467
|
-
const rowsType = DictType(
|
|
468
|
-
const patchType = dictPatchType(
|
|
637
|
+
function touchedRows(keyType, nodeType, walk) {
|
|
638
|
+
const rowsType = DictType(keyType, nodeType);
|
|
639
|
+
const patchType = dictPatchType(keyType, nodeType);
|
|
469
640
|
const pairType = StructType({ held: rowsType, next: rowsType });
|
|
470
641
|
return East.function([rowsType, rowsType, patchType], OptionType(pairType), ($, held, next, patch) => {
|
|
471
642
|
const child = $.const(walk);
|
|
@@ -616,12 +787,13 @@ function rowWalk(decl) {
|
|
|
616
787
|
}
|
|
617
788
|
walks[group.index] = touchedStruct(group.type, [
|
|
618
789
|
...group.collections.map((collection) => {
|
|
619
|
-
const type =
|
|
790
|
+
const type = filledType(collection);
|
|
620
791
|
return { field: collection.field, type, walk: touchedItems(type.key, type.value) };
|
|
621
792
|
}),
|
|
622
793
|
...group.rows.map((child) => {
|
|
623
|
-
const
|
|
624
|
-
|
|
794
|
+
const childGroup = decl.groups[child.group];
|
|
795
|
+
const keyType = keyedOf(childGroup).type;
|
|
796
|
+
return { field: child.field, type: DictType(keyType, childGroup.type), walk: touchedRows(keyType, childGroup.type, walks[child.group]) };
|
|
625
797
|
}),
|
|
626
798
|
]);
|
|
627
799
|
}
|
|
@@ -632,8 +804,6 @@ function rowWalk(decl) {
|
|
|
632
804
|
function whatWords(collection) {
|
|
633
805
|
return collection.place.join(' ');
|
|
634
806
|
}
|
|
635
|
-
/** A node's items' shares of the summary tiles they touch. */
|
|
636
|
-
const NodeSharesType = StructType({ path: KeysType, shares: ArrayType(TileShareType) });
|
|
637
807
|
/** No items or values: a tile's totals before any is counted. */
|
|
638
808
|
const NO_SPAN_TOTALS = { count: 0n, ms: 0n };
|
|
639
809
|
/** The tile a nested series index's span counts by: a Plan's horizon spans whole months. */
|
|
@@ -642,6 +812,7 @@ const SPAN_TILE = 'month';
|
|
|
642
812
|
const SpanTotalsType = DictType(NestedSpanKeyType, RecordSummaryTotalsType);
|
|
643
813
|
/** `(K, V, Nodes, Kit) → Dict<IK, P>`: parts' entries, one after another, each a function calling the parts before it. */
|
|
644
814
|
function nodesUnion(types, nodesType, parts) {
|
|
815
|
+
const { KitType } = types.shapes;
|
|
645
816
|
const [first, ...rest] = parts;
|
|
646
817
|
if (first === undefined)
|
|
647
818
|
return East.function([types.keyType, types.rowType, nodesType, KitType], types.entries, () => new Map());
|
|
@@ -653,6 +824,7 @@ function nodesUnion(types, nodesType, parts) {
|
|
|
653
824
|
}
|
|
654
825
|
/** `(K, shares, Kit) → Dict<IK, P>`: two parts' entries from the same shares, one's then the other's. */
|
|
655
826
|
function sharedBoth(types, first, second) {
|
|
827
|
+
const { NodeSharesType, KitType } = types.shapes;
|
|
656
828
|
return East.function([types.keyType, ArrayType(NodeSharesType), KitType], types.entries, ($, key, shared, kit) => {
|
|
657
829
|
const all = $.let(first(key, shared, kit));
|
|
658
830
|
$(all.unionInPlace(second(key, shared, kit)));
|
|
@@ -661,6 +833,7 @@ function sharedBoth(types, first, second) {
|
|
|
661
833
|
}
|
|
662
834
|
/** `(K, V, V, V, V, Nodes, Kit) → { before, after }`: what parts change, one after another, each a function calling the parts before it. */
|
|
663
835
|
function changedUnion(types, nodesType, parts) {
|
|
836
|
+
const { KitType } = types.shapes;
|
|
664
837
|
const { keyType, rowType, changed } = types;
|
|
665
838
|
const [first, ...rest] = parts;
|
|
666
839
|
if (first === undefined) {
|
|
@@ -676,6 +849,7 @@ function changedUnion(types, nodesType, parts) {
|
|
|
676
849
|
}
|
|
677
850
|
/** `(K, V, Nodes, Kit) → Dict<{ collection, tile }, Totals>`: parts' months, one after another, each a function calling the parts before it. */
|
|
678
851
|
function spanNodesUnion(types, nodesType, parts) {
|
|
852
|
+
const { KitType } = types.shapes;
|
|
679
853
|
const [first, ...rest] = parts;
|
|
680
854
|
if (first === undefined)
|
|
681
855
|
return East.function([types.keyType, types.rowType, nodesType, KitType], SpanTotalsType, () => new Map());
|
|
@@ -695,6 +869,7 @@ function spanNodesUnion(types, nodesType, parts) {
|
|
|
695
869
|
* @returns The part
|
|
696
870
|
*/
|
|
697
871
|
function groupEntries(types, nodes, entries) {
|
|
872
|
+
const { KitType } = types.shapes;
|
|
698
873
|
return East.function([types.keyType, types.rowType, KitType], types.entries, ($, key, row, kit) => {
|
|
699
874
|
const walk = $.const(nodes);
|
|
700
875
|
return entries(key, row, walk, kit);
|
|
@@ -710,6 +885,7 @@ function groupEntries(types, nodes, entries) {
|
|
|
710
885
|
* @returns The part
|
|
711
886
|
*/
|
|
712
887
|
function groupPatched(types, nodes, changed) {
|
|
888
|
+
const { KitType } = types.shapes;
|
|
713
889
|
const { keyType, rowType } = types;
|
|
714
890
|
return East.function([keyType, rowType, rowType, rowType, rowType, KitType], types.changed, ($, key, held, next, heldTouched, nextTouched, kit) => {
|
|
715
891
|
const walk = $.const(nodes);
|
|
@@ -726,6 +902,7 @@ function groupPatched(types, nodes, changed) {
|
|
|
726
902
|
* @returns The part
|
|
727
903
|
*/
|
|
728
904
|
function groupSpan(types, nodes, span) {
|
|
905
|
+
const { KitType } = types.shapes;
|
|
729
906
|
return East.function([types.keyType, types.rowType, KitType], SpanTotalsType, ($, key, row, kit) => {
|
|
730
907
|
const walk = $.const(nodes);
|
|
731
908
|
return span(key, row, walk, kit);
|
|
@@ -744,6 +921,7 @@ function groupSpan(types, nodes, span) {
|
|
|
744
921
|
* @returns The collection's part
|
|
745
922
|
*/
|
|
746
923
|
function patchedWith(types, nodesType, filed, moved) {
|
|
924
|
+
const { KitType } = types.shapes;
|
|
747
925
|
const { keyType, rowType, changed } = types;
|
|
748
926
|
if (moved === undefined) {
|
|
749
927
|
return East.function([keyType, rowType, rowType, rowType, rowType, nodesType, KitType], changed, ($, key, _held, _next, heldTouched, nextTouched, nodes, kit) => {
|
|
@@ -766,12 +944,15 @@ function patchedWith(types, nodesType, filed, moved) {
|
|
|
766
944
|
}
|
|
767
945
|
/** Things people drag, filed: `(K, V, Nodes, Kit) → Dict<IK, P>`, each item once (or once a year past a year), at the level its length fits, under its node. */
|
|
768
946
|
function itemEntries(decl, types, collection, nodesType) {
|
|
947
|
+
const placed = placePath(collection.place);
|
|
948
|
+
const { KitType, ItemType } = types.shapes;
|
|
769
949
|
const group = decl.groups[collection.group];
|
|
770
950
|
const { keyType, rowType, entryKey, entries, tile } = types;
|
|
771
|
-
const holding = fieldOf(group.type, collection.field, DictType(
|
|
772
|
-
const readStart = fieldReader(
|
|
773
|
-
const readEnd = fieldReader(
|
|
951
|
+
const holding = fieldOf(group.type, collection.field, DictType(collection.keyType, collection.itemType));
|
|
952
|
+
const readStart = fieldReader(collection.keyType, collection.itemType, { option: collection.start });
|
|
953
|
+
const readEnd = fieldReader(collection.keyType, collection.itemType, { option: collection.end });
|
|
774
954
|
const place = placedItem(decl, collection, collection.itemType, types.entryValue);
|
|
955
|
+
const asId = idIn(decl, collection.idCase, collection.keyType);
|
|
775
956
|
const words = whatWords(collection);
|
|
776
957
|
return East.function([keyType, rowType, nodesType, KitType], entries, ($, key, row, nodes, kit) => {
|
|
777
958
|
const startOf = $.const(kit.startOf);
|
|
@@ -782,14 +963,16 @@ function itemEntries(decl, types, collection, nodesType) {
|
|
|
782
963
|
const begins = $.const(readStart);
|
|
783
964
|
const ends = $.const(readEnd);
|
|
784
965
|
const into = $.const(place);
|
|
785
|
-
const
|
|
966
|
+
const idOf = $.const(asId);
|
|
967
|
+
const collectionPath = $.let(placed, RecordNestedPathType);
|
|
786
968
|
return nodes(row).flattenToDict(($, node) => {
|
|
787
969
|
const here = $.let(path(node.path));
|
|
788
970
|
return held(node.node).flattenToDict(($, item, id) => {
|
|
789
971
|
const value = $.let(into(item));
|
|
972
|
+
const filed = $.let(variant('id', idOf(id)), ItemType);
|
|
790
973
|
return file(tile, begins(id, item), ends(id, item), East.str `${East.print(key)} ${words} ${East.print(id)}`, startOf, nextOf).toDict((_$, filing) => East.value({
|
|
791
974
|
collection: collectionPath, row: key, path: here, run: variant('items', null), level: filing.level, tile: filing.tile,
|
|
792
|
-
item:
|
|
975
|
+
item: filed,
|
|
793
976
|
}, entryKey), () => value);
|
|
794
977
|
});
|
|
795
978
|
});
|
|
@@ -802,12 +985,15 @@ function itemEntries(decl, types, collection, nodesType) {
|
|
|
802
985
|
* the ancestor down naming the item.
|
|
803
986
|
*/
|
|
804
987
|
function itemSubtreeEntries(decl, types, collection, nodesType) {
|
|
988
|
+
const placed = placePath(collection.place);
|
|
989
|
+
const { KitType, ItemType } = types.shapes;
|
|
805
990
|
const group = decl.groups[collection.group];
|
|
806
991
|
const { keyType, rowType, entryKey, entries, tile } = types;
|
|
807
|
-
const holding = fieldOf(group.type, collection.field, DictType(
|
|
808
|
-
const readStart = fieldReader(
|
|
809
|
-
const readEnd = fieldReader(
|
|
992
|
+
const holding = fieldOf(group.type, collection.field, DictType(collection.keyType, collection.itemType));
|
|
993
|
+
const readStart = fieldReader(collection.keyType, collection.itemType, { option: collection.start });
|
|
994
|
+
const readEnd = fieldReader(collection.keyType, collection.itemType, { option: collection.end });
|
|
810
995
|
const place = placedItem(decl, collection, collection.itemType, types.entryValue);
|
|
996
|
+
const asId = idIn(decl, collection.idCase, collection.keyType);
|
|
811
997
|
const words = whatWords(collection);
|
|
812
998
|
return East.function([keyType, rowType, nodesType, KitType], entries, ($, key, row, nodes, kit) => {
|
|
813
999
|
const startOf = $.const(kit.startOf);
|
|
@@ -818,13 +1004,15 @@ function itemSubtreeEntries(decl, types, collection, nodesType) {
|
|
|
818
1004
|
const begins = $.const(readStart);
|
|
819
1005
|
const ends = $.const(readEnd);
|
|
820
1006
|
const into = $.const(place);
|
|
821
|
-
const
|
|
1007
|
+
const idOf = $.const(asId);
|
|
1008
|
+
const collectionPath = $.let(placed, RecordNestedPathType);
|
|
822
1009
|
return nodes(row).flattenToDict(($, node) => held(node.node).flattenToDict(($, item, id) => {
|
|
823
1010
|
const value = $.let(into(item));
|
|
824
1011
|
const filings = $.let(file(tile, begins(id, item), ends(id, item), East.str `${East.print(key)} ${words} ${East.print(id)}`, startOf, nextOf));
|
|
1012
|
+
const itemId = $.let(idOf(id));
|
|
825
1013
|
return East.Array.range(0n, node.path.size()).flattenToDict(($, depth) => {
|
|
826
1014
|
const ancestor = $.let(path(node.path.slice(0n, depth)));
|
|
827
|
-
const under = $.let(variant('under', { path: path(node.path.slice(depth, node.path.size())), id }));
|
|
1015
|
+
const under = $.let(variant('under', { path: path(node.path.slice(depth, node.path.size())), id: itemId }), ItemType);
|
|
828
1016
|
return filings.toDict((_$, filing) => East.value({
|
|
829
1017
|
collection: collectionPath, row: key, path: ancestor, run: variant('subtree', null), level: filing.level, tile: filing.tile,
|
|
830
1018
|
item: under,
|
|
@@ -844,10 +1032,11 @@ function itemsFiled(decl, types, collection, nodesType) {
|
|
|
844
1032
|
* shared out at all — an item with no start touching none.
|
|
845
1033
|
*/
|
|
846
1034
|
function itemShares(decl, types, collection, nodesType, level) {
|
|
1035
|
+
const { NodeSharesType, KitType } = types.shapes;
|
|
847
1036
|
const group = decl.groups[collection.group];
|
|
848
|
-
const holding = fieldOf(group.type, collection.field, DictType(
|
|
849
|
-
const readStart = fieldReader(
|
|
850
|
-
const readEnd = fieldReader(
|
|
1037
|
+
const holding = fieldOf(group.type, collection.field, DictType(collection.keyType, collection.itemType));
|
|
1038
|
+
const readStart = fieldReader(collection.keyType, collection.itemType, { option: collection.start });
|
|
1039
|
+
const readEnd = fieldReader(collection.keyType, collection.itemType, { option: collection.end });
|
|
851
1040
|
const words = whatWords(collection);
|
|
852
1041
|
return East.function([types.keyType, types.rowType, WithinType, nodesType, KitType], ArrayType(NodeSharesType), ($, key, row, within, nodes, kit) => {
|
|
853
1042
|
const startOf = $.const(kit.startOf);
|
|
@@ -874,11 +1063,13 @@ function itemShares(decl, types, collection, nodesType, level) {
|
|
|
874
1063
|
}
|
|
875
1064
|
/** Things people drag, totalled from their shares ({@link SharedEntries}): each node's items' count and milliseconds in each summary tile they touch. */
|
|
876
1065
|
function itemTotals(types, collection, summary) {
|
|
1066
|
+
const placed = placePath(collection.place);
|
|
1067
|
+
const { NodeSharesType, KitType } = types.shapes;
|
|
877
1068
|
const { keyType, entryKey, entryValue, entries } = types;
|
|
878
1069
|
return East.function([keyType, ArrayType(NodeSharesType), KitType], entries, ($, key, shared, kit) => {
|
|
879
1070
|
const totalled = $.const(kit.totalled);
|
|
880
1071
|
const path = $.const(kit.path);
|
|
881
|
-
const collectionPath = $.let(
|
|
1072
|
+
const collectionPath = $.let(placed, RecordNestedPathType);
|
|
882
1073
|
return shared.flattenToDict(($, node) => {
|
|
883
1074
|
const here = $.let(path(node.path));
|
|
884
1075
|
return totalled(node.shares).toDict((_$, _totals, tile) => East.value({
|
|
@@ -892,11 +1083,13 @@ function itemTotals(types, collection, summary) {
|
|
|
892
1083
|
* from their shares ({@link SharedEntries}): in the run `subtreeTotals`.
|
|
893
1084
|
*/
|
|
894
1085
|
function itemSubtreeTotals(types, collection, summary) {
|
|
1086
|
+
const placed = placePath(collection.place);
|
|
1087
|
+
const { NodeSharesType, KitType } = types.shapes;
|
|
895
1088
|
const { keyType, entryKey, entryValue, entries } = types;
|
|
896
1089
|
return East.function([keyType, ArrayType(NodeSharesType), KitType], entries, ($, key, shared, kit) => {
|
|
897
1090
|
const totalled = $.const(kit.totalled);
|
|
898
1091
|
const path = $.const(kit.path);
|
|
899
|
-
const collectionPath = $.let(
|
|
1092
|
+
const collectionPath = $.let(placed, RecordNestedPathType);
|
|
900
1093
|
// Every node's shares, under each of its ancestors: the row, and each node on the way.
|
|
901
1094
|
const beneath = $.let(shared.flatMap((_$, node) => East.Array.range(0n, node.path.size()).flatMap((_$, depth) => node.shares.map((_$, share) => ({ ancestor: path(node.path.slice(0n, depth)), share })))));
|
|
902
1095
|
return beneath.groupToArrays((_$, at) => at.ancestor, (_$, at) => at.share).flattenToDict((_$, shares, ancestor) => totalled(shares).toDict((_$, _totals, tile) => East.value({
|
|
@@ -912,6 +1105,7 @@ function itemsTotalled(types, collection, summary) {
|
|
|
912
1105
|
}
|
|
913
1106
|
/** `(K, V, Nodes, Kit) → Dict<IK, P>`: things people drag's totals at every summary tile — their shares, totalled. */
|
|
914
1107
|
function itemsTotalledAll(types, nodesType, shares, totals) {
|
|
1108
|
+
const { KitType } = types.shapes;
|
|
915
1109
|
return East.function([types.keyType, types.rowType, nodesType, KitType], types.entries, (_$, key, row, nodes, kit) => totals(key, shares(key, row, variant('all', null), nodes, kit), kit));
|
|
916
1110
|
}
|
|
917
1111
|
/**
|
|
@@ -920,6 +1114,7 @@ function itemsTotalledAll(types, nodesType, shares, totals) {
|
|
|
920
1114
|
* and after.
|
|
921
1115
|
*/
|
|
922
1116
|
function itemsMoved(types, nodesType, summary, shares, totals) {
|
|
1117
|
+
const { KitType } = types.shapes;
|
|
923
1118
|
const { keyType, rowType, changed } = types;
|
|
924
1119
|
return East.function([keyType, rowType, rowType, rowType, rowType, nodesType, KitType], changed, ($, key, held, next, heldTouched, nextTouched, nodes, kit) => {
|
|
925
1120
|
const shared = $.const(shares);
|
|
@@ -938,19 +1133,22 @@ function itemsMoved(types, nodesType, summary, shares, totals) {
|
|
|
938
1133
|
* across a month's end counted in each.
|
|
939
1134
|
*/
|
|
940
1135
|
function itemsSpan(types, collection, nodesType, shares) {
|
|
1136
|
+
const placed = placePath(collection.place);
|
|
1137
|
+
const { KitType } = types.shapes;
|
|
941
1138
|
return East.function([types.keyType, types.rowType, nodesType, KitType], SpanTotalsType, ($, key, row, nodes, kit) => {
|
|
942
|
-
const
|
|
943
|
-
const at = $.let(path(East.value([...collection.place], KeysType)));
|
|
1139
|
+
const at = $.let(placed, RecordNestedPathType);
|
|
944
1140
|
return shares(key, row, variant('all', null), nodes, kit).flatMap((_$, node) => node.shares).groupReduce((_$, share) => ({ collection: at, tile: share.tile }), ($) => $.const(NO_SPAN_TOTALS, RecordSummaryTotalsType), (_$, totals, share) => ({ count: totals.count.add(1n), ms: totals.ms.add(share.ms) }));
|
|
945
1141
|
});
|
|
946
1142
|
}
|
|
947
1143
|
/** A collection of values, filed: `(K, V, Nodes, Kit) → Dict<IK, P>`, each value at its instant, at the index's tile. */
|
|
948
1144
|
function valueEntries(decl, types, collection, nodesType) {
|
|
1145
|
+
const { KitType } = types.shapes;
|
|
949
1146
|
const group = decl.groups[collection.group];
|
|
950
1147
|
const { keyType, rowType, entryKey, entries, tile } = types;
|
|
951
1148
|
const holding = fieldOf(group.type, collection.field, DictType(DateTimeType, collection.valueType));
|
|
952
1149
|
const place = placedItem(decl, collection, collection.valueType, types.entryValue);
|
|
953
1150
|
const words = whatWords(collection);
|
|
1151
|
+
const collectionPlace = placePath(collection.place);
|
|
954
1152
|
return East.function([keyType, rowType, nodesType, KitType], entries, ($, key, row, nodes, kit) => {
|
|
955
1153
|
const startOf = $.const(kit.startOf);
|
|
956
1154
|
const nextOf = $.const(kit.nextOf);
|
|
@@ -958,7 +1156,7 @@ function valueEntries(decl, types, collection, nodesType) {
|
|
|
958
1156
|
const path = $.const(kit.path);
|
|
959
1157
|
const held = $.const(holding);
|
|
960
1158
|
const into = $.const(place);
|
|
961
|
-
const collectionPath = $.let(
|
|
1159
|
+
const collectionPath = $.let(collectionPlace, RecordNestedPathType);
|
|
962
1160
|
return nodes(row).flattenToDict(($, node) => {
|
|
963
1161
|
const here = $.let(path(node.path));
|
|
964
1162
|
return held(node.node).flattenToDict(($, value, at) => {
|
|
@@ -977,7 +1175,8 @@ function valueEntries(decl, types, collection, nodesType) {
|
|
|
977
1175
|
* Dict<tile, Totals>` — numbers' carry their values (`valueTotals`);
|
|
978
1176
|
* any other's count them (`instantTotals`).
|
|
979
1177
|
*/
|
|
980
|
-
function valuesTotalled(collection) {
|
|
1178
|
+
function valuesTotalled(types, collection) {
|
|
1179
|
+
const { KitType } = types.shapes;
|
|
981
1180
|
const valuesType = DictType(DateTimeType, collection.valueType);
|
|
982
1181
|
const totalsType = DictType(DateTimeType, RecordNestedTotalsType);
|
|
983
1182
|
if (collection.numeric === undefined) {
|
|
@@ -1001,17 +1200,19 @@ function valuesTotalled(collection) {
|
|
|
1001
1200
|
* numbers, their sum, the least, the greatest and the latest.
|
|
1002
1201
|
*/
|
|
1003
1202
|
function valueTotalsOf(decl, types, collection, nodesType, summary) {
|
|
1203
|
+
const placed = placePath(collection.place);
|
|
1204
|
+
const { KitType } = types.shapes;
|
|
1004
1205
|
const group = decl.groups[collection.group];
|
|
1005
1206
|
const { keyType, rowType, entryKey, entryValue, entries } = types;
|
|
1006
1207
|
const holding = fieldOf(group.type, collection.field, DictType(DateTimeType, collection.valueType));
|
|
1007
|
-
const totalsOf = valuesTotalled(collection);
|
|
1208
|
+
const totalsOf = valuesTotalled(types, collection);
|
|
1008
1209
|
return East.function([keyType, rowType, WithinType, nodesType, KitType], entries, ($, key, row, within, nodes, kit) => {
|
|
1009
1210
|
const startOf = $.const(kit.startOf);
|
|
1010
1211
|
const kept = $.const(kit.kept);
|
|
1011
1212
|
const path = $.const(kit.path);
|
|
1012
1213
|
const held = $.const(holding);
|
|
1013
1214
|
const totalled = $.const(totalsOf);
|
|
1014
|
-
const collectionPath = $.let(
|
|
1215
|
+
const collectionPath = $.let(placed, RecordNestedPathType);
|
|
1015
1216
|
return nodes(row).flattenToDict(($, node) => {
|
|
1016
1217
|
const here = $.let(path(node.path));
|
|
1017
1218
|
const values = $.let(held(node.node));
|
|
@@ -1027,6 +1228,7 @@ function valueTotalsOf(decl, types, collection, nodesType, summary) {
|
|
|
1027
1228
|
}
|
|
1028
1229
|
/** `(K, V, Nodes, Kit) → Dict<IK, P>`: a collection of values' totals at every summary tile. */
|
|
1029
1230
|
function valuesTotalledAll(types, nodesType, totals) {
|
|
1231
|
+
const { KitType } = types.shapes;
|
|
1030
1232
|
return East.function([types.keyType, types.rowType, nodesType, KitType], types.entries, (_$, key, row, nodes, kit) => totals(key, row, variant('all', null), nodes, kit));
|
|
1031
1233
|
}
|
|
1032
1234
|
/**
|
|
@@ -1035,6 +1237,7 @@ function valuesTotalledAll(types, nodesType, totals) {
|
|
|
1035
1237
|
* and after.
|
|
1036
1238
|
*/
|
|
1037
1239
|
function valuesMoved(decl, types, collection, nodesType, summary, totals) {
|
|
1240
|
+
const { KitType } = types.shapes;
|
|
1038
1241
|
const group = decl.groups[collection.group];
|
|
1039
1242
|
const { keyType, rowType, changed } = types;
|
|
1040
1243
|
const holding = fieldOf(group.type, collection.field, DictType(DateTimeType, collection.valueType));
|
|
@@ -1056,6 +1259,7 @@ function valuesMoved(decl, types, collection, nodesType, summary, totals) {
|
|
|
1056
1259
|
* group's, holding its values as Floats.
|
|
1057
1260
|
*/
|
|
1058
1261
|
function valuesGathered(decl, types, collection, nodesOf, numeric) {
|
|
1262
|
+
const { SubtotalNodeType } = types.shapes;
|
|
1059
1263
|
const { rowType } = types;
|
|
1060
1264
|
const group = decl.groups[collection.group];
|
|
1061
1265
|
// The nodes of each group above the collection's, from the row down.
|
|
@@ -1074,7 +1278,7 @@ function valuesGathered(decl, types, collection, nodesOf, numeric) {
|
|
|
1074
1278
|
}, East.function([rowType], ArrayType(SubtotalNodeType), () => []));
|
|
1075
1279
|
const own = valuesAsFloats(group.type, collection, numeric);
|
|
1076
1280
|
const ownGroup = BigInt(group.index);
|
|
1077
|
-
const nodesType = WalkType(
|
|
1281
|
+
const nodesType = WalkType(types, group);
|
|
1078
1282
|
return East.function([rowType, nodesType], ArrayType(SubtotalNodeType), ($, row, nodes) => {
|
|
1079
1283
|
const earlier = $.const(above);
|
|
1080
1284
|
const values = $.const(own);
|
|
@@ -1083,12 +1287,13 @@ function valuesGathered(decl, types, collection, nodesOf, numeric) {
|
|
|
1083
1287
|
}
|
|
1084
1288
|
/** A collection of values rolled up, every parent's subtotals at the tiles asked for ({@link SubtotalEntries}), composed bottom-up (`subtotalsOf`). */
|
|
1085
1289
|
function valueSubtotals(types, collection) {
|
|
1290
|
+
const placed = placePath(collection.place);
|
|
1291
|
+
const { SubtotalNodeType, KitType } = types.shapes;
|
|
1086
1292
|
const { keyType, entryKey, entryValue, entries, levels } = types;
|
|
1087
1293
|
return East.function([keyType, ArrayType(SubtotalNodeType), SubtotalTilesType, KitType], entries, ($, key, nodes, tiles, kit) => {
|
|
1088
1294
|
const startOf = $.const(kit.startOf);
|
|
1089
1295
|
const compose = $.const(kit.subtotals);
|
|
1090
|
-
const
|
|
1091
|
-
const collectionPath = $.let(path(East.value([...collection.place], KeysType)));
|
|
1296
|
+
const collectionPath = $.let(placed, RecordNestedPathType);
|
|
1092
1297
|
const rollups = $.let([...collection.rollups], ArrayType(RecordRollupType));
|
|
1093
1298
|
const tiers = $.let([...levels], ArrayType(RecordLevelType));
|
|
1094
1299
|
return compose(nodes, rollups, tiers, tiles, startOf).toDict((_$, _value, subtotal) => East.value({
|
|
@@ -1099,6 +1304,7 @@ function valueSubtotals(types, collection) {
|
|
|
1099
1304
|
}
|
|
1100
1305
|
/** `(K, V, Nodes, Kit) → Dict<IK, P>`: a collection of values rolled up, every parent's subtotals at every tile. */
|
|
1101
1306
|
function valuesSubtotalledAll(types, nodesType, gathered, subtotals) {
|
|
1307
|
+
const { KitType } = types.shapes;
|
|
1102
1308
|
return East.function([types.keyType, types.rowType, nodesType, KitType], types.entries, (_$, key, row, nodes, kit) => subtotals(key, gathered(row, nodes), variant('all', null), kit));
|
|
1103
1309
|
}
|
|
1104
1310
|
/**
|
|
@@ -1110,6 +1316,7 @@ function valuesSubtotalledAll(types, nodesType, gathered, subtotals) {
|
|
|
1110
1316
|
* one losing its last begins to at every tile.
|
|
1111
1317
|
*/
|
|
1112
1318
|
function valuesSubtotalsMoved(decl, types, collection, nodesType, gathered, subtotals) {
|
|
1319
|
+
const { KitType } = types.shapes;
|
|
1113
1320
|
const { keyType, rowType, changed, levels } = types;
|
|
1114
1321
|
if (decl.groups[collection.group].through !== undefined) {
|
|
1115
1322
|
return East.function([keyType, rowType, rowType, rowType, rowType, nodesType, KitType], changed, ($, key, held, next, _heldTouched, _nextTouched, nodes, kit) => {
|
|
@@ -1133,14 +1340,15 @@ function valuesSubtotalsMoved(decl, types, collection, nodesType, gathered, subt
|
|
|
1133
1340
|
}
|
|
1134
1341
|
/** The months a row's values are in, each with how many are in it ({@link SpanPart}), a value covering no milliseconds. */
|
|
1135
1342
|
function valuesSpan(decl, types, collection, nodesType) {
|
|
1343
|
+
const placed = placePath(collection.place);
|
|
1344
|
+
const { KitType } = types.shapes;
|
|
1136
1345
|
const group = decl.groups[collection.group];
|
|
1137
1346
|
const holding = fieldOf(group.type, collection.field, DictType(DateTimeType, collection.valueType));
|
|
1138
1347
|
const month = levelOf(SPAN_TILE);
|
|
1139
1348
|
return East.function([types.keyType, types.rowType, nodesType, KitType], SpanTotalsType, ($, _key, row, nodes, kit) => {
|
|
1140
1349
|
const startOf = $.const(kit.startOf);
|
|
1141
|
-
const path = $.const(kit.path);
|
|
1142
1350
|
const held = $.const(holding);
|
|
1143
|
-
const at = $.let(
|
|
1351
|
+
const at = $.let(placed, RecordNestedPathType);
|
|
1144
1352
|
return nodes(row).flatMap((_$, node) => held(node.node).toArray((_$, _value, instant) => startOf(month, instant))).groupReduce((_$, tile) => ({ collection: at, tile }), ($) => $.const(NO_SPAN_TOTALS, RecordSummaryTotalsType), (_$, totals) => ({ count: totals.count.add(1n), ms: totals.ms }));
|
|
1145
1353
|
});
|
|
1146
1354
|
}
|
|
@@ -1157,7 +1365,7 @@ function valuesSpan(decl, types, collection, nodesType) {
|
|
|
1157
1365
|
* @returns Its entries
|
|
1158
1366
|
*/
|
|
1159
1367
|
function collectionEntries(decl, types, collection, nodesOf) {
|
|
1160
|
-
const nodesType = WalkType(types
|
|
1368
|
+
const nodesType = WalkType(types, decl.groups[collection.group]);
|
|
1161
1369
|
const { summary } = types;
|
|
1162
1370
|
if (collection.kind === 'items') {
|
|
1163
1371
|
const filed = itemsFiled(decl, types, collection, nodesType);
|
|
@@ -1185,7 +1393,7 @@ function collectionEntries(decl, types, collection, nodesOf) {
|
|
|
1185
1393
|
* @returns Its part
|
|
1186
1394
|
*/
|
|
1187
1395
|
function collectionPatched(decl, types, collection, nodesOf) {
|
|
1188
|
-
const nodesType = WalkType(types
|
|
1396
|
+
const nodesType = WalkType(types, decl.groups[collection.group]);
|
|
1189
1397
|
const { summary } = types;
|
|
1190
1398
|
if (collection.kind === 'items') {
|
|
1191
1399
|
const filed = itemsFiled(decl, types, collection, nodesType);
|
|
@@ -1202,7 +1410,7 @@ function collectionPatched(decl, types, collection, nodesOf) {
|
|
|
1202
1410
|
}
|
|
1203
1411
|
/** A collection's months of a row, for the index's span, given its group's nodes ({@link NodesSpan}). */
|
|
1204
1412
|
function collectionSpan(decl, types, collection) {
|
|
1205
|
-
const nodesType = WalkType(types
|
|
1413
|
+
const nodesType = WalkType(types, decl.groups[collection.group]);
|
|
1206
1414
|
if (collection.kind === 'items')
|
|
1207
1415
|
return itemsSpan(types, collection, nodesType, itemShares(decl, types, collection, nodesType, levelOf(SPAN_TILE)));
|
|
1208
1416
|
return valuesSpan(decl, types, collection, nodesType);
|
|
@@ -1246,6 +1454,7 @@ function kitCalls(decl, types, collection, program) {
|
|
|
1246
1454
|
// ── The programs ──────────────────────────────────────────────────────────────
|
|
1247
1455
|
/** `(K, V, Kit) → Dict<IK, P>`: parts' entries, one after another, each a function calling the parts before it. */
|
|
1248
1456
|
function entriesUnion(types, parts) {
|
|
1457
|
+
const { KitType } = types.shapes;
|
|
1249
1458
|
const [first, ...rest] = parts;
|
|
1250
1459
|
if (first === undefined)
|
|
1251
1460
|
return East.function([types.keyType, types.rowType, KitType], types.entries, () => new Map());
|
|
@@ -1257,6 +1466,7 @@ function entriesUnion(types, parts) {
|
|
|
1257
1466
|
}
|
|
1258
1467
|
/** `(K, V, V, V, V, Kit) → { before, after }`: parts of a write's entries, one after another, each a function calling the parts before it. */
|
|
1259
1468
|
function patchedUnion(types, parts) {
|
|
1469
|
+
const { KitType } = types.shapes;
|
|
1260
1470
|
const { keyType, rowType, changed } = types;
|
|
1261
1471
|
const [first, ...rest] = parts;
|
|
1262
1472
|
if (first === undefined) {
|
|
@@ -1272,6 +1482,7 @@ function patchedUnion(types, parts) {
|
|
|
1272
1482
|
}
|
|
1273
1483
|
/** `(K, V, Kit) → Dict<{ collection, tile }, Totals>`: parts of the span, one after another, each a function calling the parts before it. */
|
|
1274
1484
|
function spanUnion(types, parts) {
|
|
1485
|
+
const { KitType } = types.shapes;
|
|
1275
1486
|
const [first, ...rest] = parts;
|
|
1276
1487
|
if (first === undefined)
|
|
1277
1488
|
return East.function([types.keyType, types.rowType, KitType], SpanTotalsType, () => new Map());
|
|
@@ -1283,11 +1494,12 @@ function spanUnion(types, parts) {
|
|
|
1283
1494
|
}
|
|
1284
1495
|
/** The types a nested series index's programs are built over ({@link NestedTypes}). */
|
|
1285
1496
|
function nestedTypes(decl, keyType, rowType, tile, summary) {
|
|
1286
|
-
const entryKey = NestedEntryKeyType(keyType);
|
|
1497
|
+
const entryKey = NestedEntryKeyType(keyType, decl.idType);
|
|
1287
1498
|
const entryValue = NestedEntryType(decl.places);
|
|
1288
1499
|
const entries = DictType(entryKey, entryValue);
|
|
1289
1500
|
return {
|
|
1290
1501
|
keyType, rowType, entryKey, entryValue, entries,
|
|
1502
|
+
shapes: shapesOf(decl, entryKey),
|
|
1291
1503
|
changed: StructType({ before: entries, after: entries }),
|
|
1292
1504
|
tile: levelOf(tile),
|
|
1293
1505
|
summary: summary === undefined ? undefined : levelOf(summary),
|
|
@@ -1296,12 +1508,25 @@ function nestedTypes(decl, keyType, rowType, tile, summary) {
|
|
|
1296
1508
|
}
|
|
1297
1509
|
/** A program's kit, holding each function its collections' parts call ({@link kitCalls}). */
|
|
1298
1510
|
function kitOf(decl, types, program) {
|
|
1299
|
-
return programKit(new Set(decl.collections.flatMap((collection) => kitCalls(decl, types, collection, program))));
|
|
1511
|
+
return programKit(types.shapes, new Set(decl.collections.flatMap((collection) => kitCalls(decl, types, collection, program))));
|
|
1512
|
+
}
|
|
1513
|
+
/**
|
|
1514
|
+
* The shapes of an index's ids ({@link shapesFor}), over the path and the item
|
|
1515
|
+
* its entry key holds: the key's own types, so a path the programs make is
|
|
1516
|
+
* the key's.
|
|
1517
|
+
*
|
|
1518
|
+
* @param decl - The checked declaration
|
|
1519
|
+
* @param entryKey - The entry key, `IK`
|
|
1520
|
+
* @returns The shapes
|
|
1521
|
+
*/
|
|
1522
|
+
function shapesOf(decl, entryKey) {
|
|
1523
|
+
const fields = entryKey.fields;
|
|
1524
|
+
return shapesFor(decl.idType, fields.path, fields.item);
|
|
1300
1525
|
}
|
|
1301
1526
|
/** A row's entries: `(K, V) → Dict<IK, P>`, each group's part's, over a kit binding once each function they call. */
|
|
1302
1527
|
function entriesProgram(decl, types, nodesOf) {
|
|
1303
1528
|
const kit = kitOf(decl, types, 'entries');
|
|
1304
|
-
const parts = entriesUnion(types, groupsHolding(decl).map((group) => groupEntries(types, nodesOf[group.index], nodesUnion(types, WalkType(types
|
|
1529
|
+
const parts = entriesUnion(types, groupsHolding(decl).map((group) => groupEntries(types, nodesOf[group.index], nodesUnion(types, WalkType(types, group), group.collections.map((collection) => collectionEntries(decl, types, collection, nodesOf))))));
|
|
1305
1530
|
return East.function([types.keyType, types.rowType], types.entries, ($, key, row) => {
|
|
1306
1531
|
const tools = $.const(kit());
|
|
1307
1532
|
return parts(key, row, tools);
|
|
@@ -1335,7 +1560,7 @@ function nestedByPatch(decl, types, nodesOf) {
|
|
|
1335
1560
|
const { keyType, rowType, entries } = types;
|
|
1336
1561
|
const walk = rowWalk(decl);
|
|
1337
1562
|
const kit = kitOf(decl, types, 'byPatch');
|
|
1338
|
-
const parts = patchedUnion(types, groupsHolding(decl).map((group) => groupPatched(types, nodesOf[group.index], changedUnion(types, WalkType(
|
|
1563
|
+
const parts = patchedUnion(types, groupsHolding(decl).map((group) => groupPatched(types, nodesOf[group.index], changedUnion(types, WalkType(types, group), group.collections.map((collection) => collectionPatched(decl, types, collection, nodesOf))))));
|
|
1339
1564
|
const patchType = patchTypeOf(rowType);
|
|
1340
1565
|
const patchedType = NestedPatchedType(entries);
|
|
1341
1566
|
return East.function([keyType, rowType, rowType, patchType], patchedType, ($, key, held, next, patch) => {
|
|
@@ -1372,7 +1597,7 @@ function nestedByPatch(decl, types, nodesOf) {
|
|
|
1372
1597
|
*/
|
|
1373
1598
|
export function nestedEntries(decl, keyType, rowType, tile, summary) {
|
|
1374
1599
|
const types = nestedTypes(decl, keyType, rowType, tile, summary);
|
|
1375
|
-
const nodesOf = groupNodes(decl, rowType);
|
|
1600
|
+
const nodesOf = groupNodes(decl, types.shapes, rowType);
|
|
1376
1601
|
return {
|
|
1377
1602
|
entries: entriesProgram(decl, types, nodesOf),
|
|
1378
1603
|
byPatch: nestedByPatch(decl, types, nodesOf),
|
|
@@ -1399,9 +1624,9 @@ export function nestedEntries(decl, keyType, rowType, tile, summary) {
|
|
|
1399
1624
|
*/
|
|
1400
1625
|
export function nestedSpan(decl, keyType, rowType, tile) {
|
|
1401
1626
|
const types = nestedTypes(decl, keyType, rowType, tile, undefined);
|
|
1402
|
-
const nodesOf = groupNodes(decl, rowType);
|
|
1627
|
+
const nodesOf = groupNodes(decl, types.shapes, rowType);
|
|
1403
1628
|
const kit = kitOf(decl, types, 'span');
|
|
1404
|
-
const parts = spanUnion(types, groupsHolding(decl).map((group) => groupSpan(types, nodesOf[group.index], spanNodesUnion(types, WalkType(
|
|
1629
|
+
const parts = spanUnion(types, groupsHolding(decl).map((group) => groupSpan(types, nodesOf[group.index], spanNodesUnion(types, WalkType(types, group), group.collections.map((collection) => collectionSpan(decl, types, collection))))));
|
|
1405
1630
|
return East.function([keyType, rowType], SpanTotalsType, ($, key, row) => {
|
|
1406
1631
|
const tools = $.const(kit());
|
|
1407
1632
|
return parts(key, row, tools);
|
|
@@ -1440,8 +1665,6 @@ function nestedSpanDefinition(name, rec, decl, keyType, rowType, tile, runner) {
|
|
|
1440
1665
|
runner,
|
|
1441
1666
|
};
|
|
1442
1667
|
}
|
|
1443
|
-
/** Where a node's items are filed: its collection's place and its path, as an entry's key holds them. */
|
|
1444
|
-
const NodePlaceType = StructType({ collection: RecordNestedPathType, path: RecordNestedPathType });
|
|
1445
1668
|
/**
|
|
1446
1669
|
* An item out of its entry's value: `(P) → I`, from the outside in — the
|
|
1447
1670
|
* `item` case, then each child rows' field from the row down, then the
|
|
@@ -1454,7 +1677,7 @@ const NodePlaceType = StructType({ collection: RecordNestedPathType, path: Recor
|
|
|
1454
1677
|
* @param entryValue - The entry value, `P`
|
|
1455
1678
|
* @returns The item
|
|
1456
1679
|
*/
|
|
1457
|
-
function itemOf(decl, collection, itemType, entryValue) {
|
|
1680
|
+
export function itemOf(decl, collection, itemType, entryValue) {
|
|
1458
1681
|
const names = [];
|
|
1459
1682
|
for (let group = decl.groups[collection.group], name = collection.field;;) {
|
|
1460
1683
|
names.unshift(name);
|
|
@@ -1472,30 +1695,37 @@ function itemOf(decl, collection, itemType, entryValue) {
|
|
|
1472
1695
|
* filed in several tiles once.
|
|
1473
1696
|
*
|
|
1474
1697
|
* @param decl - The declaration
|
|
1698
|
+
* @param shapes - The index's shapes
|
|
1475
1699
|
* @param collection - The collection
|
|
1476
1700
|
* @param entry - An entry's type, `{ ik, value }`
|
|
1477
1701
|
* @param entryValue - The entry value, `P`
|
|
1478
1702
|
* @returns The filling
|
|
1479
1703
|
*/
|
|
1480
|
-
function collectionFill(decl, collection, entry, entryValue) {
|
|
1704
|
+
function collectionFill(decl, shapes, collection, entry, entryValue) {
|
|
1705
|
+
const placed = placePath(collection.place);
|
|
1706
|
+
const { KeysType, NodePlaceType, ItemType } = shapes;
|
|
1481
1707
|
const byPlace = DictType(NodePlaceType, ArrayType(entry));
|
|
1482
1708
|
const itemType = collection.kind === 'items' ? collection.itemType : collection.valueType;
|
|
1483
1709
|
const filled = filledType(collection);
|
|
1484
1710
|
const item = itemOf(decl, collection, itemType, entryValue);
|
|
1711
|
+
// An item by its id, out of its collection's case of the index's ids, in the collection's own key type (#1540).
|
|
1485
1712
|
const keyOf = collection.kind === 'items'
|
|
1486
|
-
? East.function([entry],
|
|
1487
|
-
|
|
1713
|
+
? ((unwrap) => East.function([entry], collection.keyType, ($, filed) => {
|
|
1714
|
+
const key = $.const(unwrap);
|
|
1715
|
+
return key(East.field(East.field(filed, 'ik'), 'item', ItemType).unwrap('id'));
|
|
1716
|
+
}))(idOut(decl, collection.idCase, collection.keyType))
|
|
1717
|
+
: East.function([entry], DateTimeType, (_$, filed) => East.field(East.field(filed, 'ik'), 'item', ItemType).unwrap('at'));
|
|
1488
1718
|
return East.function([KeysType, byPlace], filled, ($, keys, entries) => {
|
|
1489
|
-
const path = $.const(
|
|
1719
|
+
const path = $.const(shapes.fns.pathOf);
|
|
1490
1720
|
const itemFrom = $.const(item);
|
|
1491
1721
|
const key = $.const(keyOf);
|
|
1492
|
-
const here = $.let({ collection:
|
|
1722
|
+
const here = $.let({ collection: placed, path: path(keys) }, NodePlaceType);
|
|
1493
1723
|
return entries.get(here, () => East.value([], ArrayType(entry))).toDict((_$, filed) => key(filed), (_$, filed) => itemFrom(East.field(filed, 'value', entryValue)), (_$, kept) => kept);
|
|
1494
1724
|
});
|
|
1495
1725
|
}
|
|
1496
|
-
/** A collection's type: its items by their ids, or its values by their instants. */
|
|
1726
|
+
/** A collection's type: its items by their ids, in its own key type, or its values by their instants. */
|
|
1497
1727
|
function filledType(collection) {
|
|
1498
|
-
return collection.kind === 'items' ? DictType(
|
|
1728
|
+
return collection.kind === 'items' ? DictType(collection.keyType, collection.itemType) : DictType(DateTimeType, collection.valueType);
|
|
1499
1729
|
}
|
|
1500
1730
|
/**
|
|
1501
1731
|
* An entry as a fill puts its item back: `(entry) → Option<entry>` — one filed
|
|
@@ -1503,19 +1733,21 @@ function filledType(collection) {
|
|
|
1503
1733
|
* holding it, its path the parent's then the keys down to it, its item its id;
|
|
1504
1734
|
* a total or a subtotal none.
|
|
1505
1735
|
*
|
|
1736
|
+
* @param shapes - The index's shapes
|
|
1506
1737
|
* @param entry - An entry's type, `{ ik, value }`
|
|
1507
1738
|
* @returns The placing
|
|
1508
1739
|
*/
|
|
1509
|
-
function fillingEntry(entry) {
|
|
1740
|
+
function fillingEntry(shapes, entry) {
|
|
1741
|
+
const { PathType, ItemType } = shapes;
|
|
1510
1742
|
return East.function([entry], OptionType(entry), ($, filed) => {
|
|
1511
|
-
const keys = $.const(
|
|
1743
|
+
const keys = $.const(shapes.fns.keysOf);
|
|
1512
1744
|
const ik = $.let(filed.ik);
|
|
1513
1745
|
return East.field(ik, 'run', RecordNestedRunType).match({
|
|
1514
1746
|
items: () => some(filed),
|
|
1515
1747
|
subtree: ($2) => {
|
|
1516
|
-
const under = $2.let(East.field(ik, 'item',
|
|
1517
|
-
const path = $2.let(keys(East.field(ik, 'path',
|
|
1518
|
-
const item = $2.let(variant('id', under.id),
|
|
1748
|
+
const under = $2.let(East.field(ik, 'item', ItemType).unwrap('under'));
|
|
1749
|
+
const path = $2.let(keys(East.field(ik, 'path', PathType)).reverse().reduce((_$, rest, key) => variant('step', { key, rest }), under.path));
|
|
1750
|
+
const item = $2.let(variant('id', under.id), ItemType);
|
|
1519
1751
|
return some({ ik: East.withField(East.withField(ik, 'path', path), 'item', item), value: filed.value });
|
|
1520
1752
|
},
|
|
1521
1753
|
}, () => none);
|
|
@@ -1540,16 +1772,18 @@ function fillingEntry(entry) {
|
|
|
1540
1772
|
* @returns The filling
|
|
1541
1773
|
*/
|
|
1542
1774
|
export function nestedFill(decl, keyType, rowType, entryKey, entryValue) {
|
|
1775
|
+
const shapes = shapesOf(decl, entryKey);
|
|
1776
|
+
const { KeysType, NodePlaceType, PathType } = shapes;
|
|
1543
1777
|
const entry = StructType({ ik: entryKey, value: entryValue });
|
|
1544
1778
|
const byPlace = DictType(NodePlaceType, ArrayType(entry));
|
|
1545
|
-
// Each group's node filled, `(N, keys, byPlace) → N`, and its rows filled under a node at keys, `(Dict<
|
|
1779
|
+
// Each group's node filled, `(N, keys, byPlace) → N`, and its rows filled under a node at keys, `(Dict<K, N>, keys, byPlace) → Dict`:
|
|
1546
1780
|
// its child groups' first.
|
|
1547
1781
|
const fillOf = [];
|
|
1548
1782
|
const rowsFillOf = [];
|
|
1549
1783
|
for (const group of [...decl.groups].reverse()) {
|
|
1550
1784
|
const fields = [];
|
|
1551
1785
|
for (const collection of group.collections) {
|
|
1552
|
-
const filled = collectionFill(decl, collection, entry, entryValue);
|
|
1786
|
+
const filled = collectionFill(decl, shapes, collection, entry, entryValue);
|
|
1553
1787
|
const type = filledType(collection);
|
|
1554
1788
|
fields.push({ field: collection.field, fill: East.function([group.type, KeysType, byPlace], type, ($, _node, keys, entries) => {
|
|
1555
1789
|
const fill = $.const(filled);
|
|
@@ -1557,7 +1791,8 @@ export function nestedFill(decl, keyType, rowType, entryKey, entryValue) {
|
|
|
1557
1791
|
}) });
|
|
1558
1792
|
}
|
|
1559
1793
|
for (const child of group.rows) {
|
|
1560
|
-
const
|
|
1794
|
+
const childGroup = decl.groups[child.group];
|
|
1795
|
+
const rowsType = DictType(keyedOf(childGroup).type, childGroup.type);
|
|
1561
1796
|
const rowsOf = fieldOf(group.type, child.field, rowsType);
|
|
1562
1797
|
const rowsFill = rowsFillOf[child.group];
|
|
1563
1798
|
fields.push({ field: child.field, fill: East.function([group.type, KeysType, byPlace], rowsType, ($, node, keys, entries) => {
|
|
@@ -1573,32 +1808,39 @@ export function nestedFill(decl, keyType, rowType, entryKey, entryValue) {
|
|
|
1573
1808
|
return East.withField(held, field, value(node, keys, entries));
|
|
1574
1809
|
}), East.function([group.type, KeysType, byPlace], group.type, (_$, node) => node));
|
|
1575
1810
|
fillOf[group.index] = own;
|
|
1576
|
-
|
|
1811
|
+
// The row's own group is the record's row, held by no node: no rows of it are filled.
|
|
1812
|
+
if (group.keyed === undefined)
|
|
1813
|
+
continue;
|
|
1814
|
+
const rowsType = DictType(group.keyed.type, group.type);
|
|
1815
|
+
const idOf = idIn(decl, group.keyed.idCase, group.keyed.type);
|
|
1577
1816
|
if (group.through === undefined) {
|
|
1578
1817
|
rowsFillOf[group.index] = East.function([rowsType, KeysType, byPlace], rowsType, ($, rows, keys, entries) => {
|
|
1579
1818
|
const fill = $.const(own);
|
|
1580
|
-
|
|
1819
|
+
const id = $.const(idOf);
|
|
1820
|
+
return rows.map((_$, node, key) => fill(node, keys.concat([id(key)]), entries));
|
|
1581
1821
|
});
|
|
1582
1822
|
continue;
|
|
1583
1823
|
}
|
|
1584
1824
|
// Beside recursive(): every row beneath, flattened, each filled at its keys, then rebuilt bottom-up, holding its own rebuilt rows.
|
|
1585
|
-
const keyed = StructType({ key:
|
|
1825
|
+
const keyed = StructType({ key: group.keyed.type, node: group.type });
|
|
1586
1826
|
const deeper = fieldOf(group.type, group.through, rowsType);
|
|
1587
1827
|
const holding = withField(group.type, group.through, rowsType);
|
|
1828
|
+
const keysAbove = keysAboveOf(ArrayType(group.keyed.type));
|
|
1588
1829
|
rowsFillOf[group.index] = East.function([rowsType, KeysType, byPlace], rowsType, ($, rows, keys, entries) => {
|
|
1589
1830
|
const beneath = $.const(deeper);
|
|
1590
1831
|
const fill = $.const(own);
|
|
1591
1832
|
const hold = $.const(holding);
|
|
1592
|
-
const
|
|
1833
|
+
const id = $.const(idOf);
|
|
1834
|
+
const above = $.const(keysAbove);
|
|
1593
1835
|
const roots = $.let(rows.flattenTree((_$, node) => beneath(node)).toTree(keyed, (_$, at) => at.path, (_$, at) => above(at.path), (_$, at, _i, children) => ({
|
|
1594
1836
|
key: at.path.get(at.path.size().subtract(1n)),
|
|
1595
|
-
node: hold(fill(at.node, keys.concat(at.path), entries), children.toDict((_$, child) => child.key, (_$, child) => child.node)),
|
|
1837
|
+
node: hold(fill(at.node, keys.concat(at.path.map((_$, key) => id(key))), entries), children.toDict((_$, child) => child.key, (_$, child) => child.node)),
|
|
1596
1838
|
})));
|
|
1597
1839
|
return roots.toDict((_$, root) => root.key, (_$, root) => root.node);
|
|
1598
1840
|
});
|
|
1599
1841
|
}
|
|
1600
1842
|
const rowFill = fillOf[0];
|
|
1601
|
-
const filling = fillingEntry(entry);
|
|
1843
|
+
const filling = fillingEntry(shapes, entry);
|
|
1602
1844
|
return East.function([keyType, rowType, ArrayType(entry)], rowType, ($, _key, row, entries) => {
|
|
1603
1845
|
const fill = $.const(rowFill);
|
|
1604
1846
|
const place = $.const(filling);
|
|
@@ -1606,7 +1848,7 @@ export function nestedFill(decl, keyType, rowType, entryKey, entryValue) {
|
|
|
1606
1848
|
.filterMap((_$, filed) => place(filed))
|
|
1607
1849
|
.groupToArrays(($2, filed) => {
|
|
1608
1850
|
const ik = $2.let(East.field(filed, 'ik'));
|
|
1609
|
-
const place = $2.let({ collection: East.field(ik, 'collection', RecordNestedPathType), path: East.field(ik, 'path',
|
|
1851
|
+
const place = $2.let({ collection: East.field(ik, 'collection', RecordNestedPathType), path: East.field(ik, 'path', PathType) }, NodePlaceType);
|
|
1610
1852
|
return place;
|
|
1611
1853
|
}));
|
|
1612
1854
|
return fill(row, East.value([], KeysType), own);
|
|
@@ -1635,7 +1877,8 @@ export function nestedLean(decl, keyType, rowType) {
|
|
|
1635
1877
|
for (const collection of group.collections)
|
|
1636
1878
|
fields[collection.field] = emptied(group.type, struct.fields[collection.field]);
|
|
1637
1879
|
for (const child of group.rows) {
|
|
1638
|
-
const
|
|
1880
|
+
const childGroup = decl.groups[child.group];
|
|
1881
|
+
const rowsType = DictType(keyedOf(childGroup).type, childGroup.type);
|
|
1639
1882
|
const rowsOf = fieldOf(group.type, child.field, rowsType);
|
|
1640
1883
|
const leanRows = rowsLeanOf[child.group];
|
|
1641
1884
|
fields[child.field] = East.function([group.type], rowsType, ($, node) => {
|
|
@@ -1646,7 +1889,10 @@ export function nestedLean(decl, keyType, rowType) {
|
|
|
1646
1889
|
}
|
|
1647
1890
|
const own = rebuiltNode(group.type, fields);
|
|
1648
1891
|
leanOf[group.index] = own;
|
|
1649
|
-
|
|
1892
|
+
// The row's own group is the record's row, held by no node: no rows of it are made lean.
|
|
1893
|
+
if (group.keyed === undefined)
|
|
1894
|
+
continue;
|
|
1895
|
+
const rowsType = DictType(group.keyed.type, group.type);
|
|
1650
1896
|
if (group.through === undefined) {
|
|
1651
1897
|
rowsLeanOf[group.index] = East.function([rowsType], rowsType, ($, rows) => {
|
|
1652
1898
|
const lean = $.const(own);
|
|
@@ -1655,14 +1901,15 @@ export function nestedLean(decl, keyType, rowType) {
|
|
|
1655
1901
|
continue;
|
|
1656
1902
|
}
|
|
1657
1903
|
// Beside recursive(): every row beneath, flattened, then rebuilt bottom-up, each lean and holding its own rebuilt rows.
|
|
1658
|
-
const keyed = StructType({ key:
|
|
1904
|
+
const keyed = StructType({ key: group.keyed.type, node: group.type });
|
|
1659
1905
|
const deeper = fieldOf(group.type, group.through, rowsType);
|
|
1660
1906
|
const holding = withField(group.type, group.through, rowsType);
|
|
1907
|
+
const keysAbove = keysAboveOf(ArrayType(group.keyed.type));
|
|
1661
1908
|
rowsLeanOf[group.index] = East.function([rowsType], rowsType, ($, rows) => {
|
|
1662
1909
|
const beneath = $.const(deeper);
|
|
1663
1910
|
const lean = $.const(own);
|
|
1664
1911
|
const hold = $.const(holding);
|
|
1665
|
-
const above = $.const(
|
|
1912
|
+
const above = $.const(keysAbove);
|
|
1666
1913
|
const roots = $.let(rows.flattenTree((_$, node) => beneath(node)).toTree(keyed, (_$, entry) => entry.path, (_$, entry) => above(entry.path), (_$, entry, _i, children) => ({
|
|
1667
1914
|
key: entry.path.get(entry.path.size().subtract(1n)),
|
|
1668
1915
|
node: hold(lean(entry.node), children.toDict((_$, child) => child.key, (_$, child) => child.node)),
|
|
@@ -1743,35 +1990,11 @@ export function nestedDefinition(constructor, name, rec, spec, config) {
|
|
|
1743
1990
|
/**
|
|
1744
1991
|
* A nested series index's shared East functions, each built the first time it
|
|
1745
1992
|
* is read, with no location captured ({@link lazyBuilds}, #1466): importing
|
|
1746
|
-
* the SDK builds none of them.
|
|
1993
|
+
* the SDK builds none of them. The functions over an index's ids — a path of
|
|
1994
|
+
* its keys, and a parent's subtotals by path — are the index's own
|
|
1995
|
+
* ({@link shapesFor}).
|
|
1747
1996
|
*/
|
|
1748
1997
|
export const NESTED_FNS = lazyBuilds({
|
|
1749
|
-
/** `(keys) → Path`: a node's keys as a key holds them (e3-types' `RecordNestedPathType`), folded from the last. */
|
|
1750
|
-
get pathOf() {
|
|
1751
|
-
return East.function([KeysType], RecordNestedPathType, ($, keys) => {
|
|
1752
|
-
const end = $.const(variant('end', null), RecordNestedPathType);
|
|
1753
|
-
return keys.reverse().reduce((_$, rest, key) => variant('step', { key, rest }), end);
|
|
1754
|
-
});
|
|
1755
|
-
},
|
|
1756
|
-
/** `(path) → keys`: a node's keys out of a key's path, from the row down — the inverse of `pathOf`. */
|
|
1757
|
-
get keysOf() {
|
|
1758
|
-
return East.function([RecordNestedPathType], KeysType, ($, path) => {
|
|
1759
|
-
const keys = $.let([], KeysType);
|
|
1760
|
-
const at = $.let(path);
|
|
1761
|
-
$.while(true, ($2, label) => {
|
|
1762
|
-
$2.match(at.unwrap(), {
|
|
1763
|
-
step: ($3, step) => {
|
|
1764
|
-
$3(keys.pushLast(step.key));
|
|
1765
|
-
$3.assign(at, step.rest);
|
|
1766
|
-
},
|
|
1767
|
-
end: ($3) => {
|
|
1768
|
-
$3.break(label);
|
|
1769
|
-
},
|
|
1770
|
-
});
|
|
1771
|
-
});
|
|
1772
|
-
return keys;
|
|
1773
|
-
});
|
|
1774
|
-
},
|
|
1775
1998
|
/** `(shares) → Dict<tile, Totals>`: items' totals in each summary tile they touch — how many, and the milliseconds they cover. */
|
|
1776
1999
|
get sharedTotals() {
|
|
1777
2000
|
return East.function([ArrayType(TileShareType)], DictType(DateTimeType, RecordNestedTotalsType), (_$, shares) => shares.groupReduce((_$, share) => share.tile, ($) => $.const(NO_TOTALS, RecordNestedTotalsType), (_$, totals, share) => ({ count: totals.count.add(1n), ms: totals.ms.add(share.ms), values: totals.values })));
|
|
@@ -1807,10 +2030,6 @@ export const NESTED_FNS = lazyBuilds({
|
|
|
1807
2030
|
get floatsAsFloats() {
|
|
1808
2031
|
return East.function([DictType(DateTimeType, FloatType)], DictType(DateTimeType, FloatType), (_$, values) => values);
|
|
1809
2032
|
},
|
|
1810
|
-
/** `(keys) → Option<keys>`: the keys of the node above, within a walk of a Dict's rows; none for one of its own. */
|
|
1811
|
-
get keysAbove() {
|
|
1812
|
-
return East.function([KeysType], OptionType(KeysType), (_$, keys) => East.greater(keys.size(), 1n).ifElse(() => some(keys.slice(0n, keys.size().subtract(1n))), () => none));
|
|
1813
|
-
},
|
|
1814
2033
|
/** `(tiles, level, nextOf) → Within`: a write's tiles of a level, and their span. */
|
|
1815
2034
|
get tilesWithin() {
|
|
1816
2035
|
return East.function([SetType(DateTimeType), RecordLevelType, TileStepFnType], WithinType, ($, tiles, level, after) => {
|
|
@@ -1910,14 +2129,14 @@ export const NESTED_FNS = lazyBuilds({
|
|
|
1910
2129
|
});
|
|
1911
2130
|
},
|
|
1912
2131
|
/**
|
|
1913
|
-
* `(children) → Dict<DrawKey, Float>`: what a parent draws, by each rollup, at
|
|
2132
|
+
* `(children's draws) → Dict<DrawKey, Float>`: what a parent draws, by each rollup, at
|
|
1914
2133
|
* each level, in each tile one of its children draws in: what they draw there,
|
|
1915
2134
|
* in key order, by the rollup's aggregate — their sum, mean, least or
|
|
1916
2135
|
* greatest; under a count, their counts' sum.
|
|
1917
2136
|
*/
|
|
1918
2137
|
get childDraws() {
|
|
1919
|
-
return East.function([ArrayType(
|
|
1920
|
-
const drawn = $.let(children.flatMap((_$,
|
|
2138
|
+
return East.function([ArrayType(DictType(DrawKeyType, FloatType))], DictType(DrawKeyType, FloatType), ($, children) => {
|
|
2139
|
+
const drawn = $.let(children.flatMap((_$, draws) => draws.toArray((_$, value, key) => ({ key, value }))));
|
|
1921
2140
|
const gathered = $.let(drawn.groupReduce((_$, draw) => draw.key, ($) => $.const({ sum: 0.0, n: 0n, min: 0.0, max: 0.0 }, GatheredType), (_$, all, draw) => ({
|
|
1922
2141
|
sum: all.sum.add(draw.value),
|
|
1923
2142
|
n: all.n.add(1n),
|
|
@@ -1933,43 +2152,5 @@ export const NESTED_FNS = lazyBuilds({
|
|
|
1933
2152
|
}));
|
|
1934
2153
|
});
|
|
1935
2154
|
},
|
|
1936
|
-
/**
|
|
1937
|
-
* `(node, children, rollups, levels, tiles, startOf) → Composed`: a node's
|
|
1938
|
-
* result, at the tiles asked for. One holding values of its own draws them,
|
|
1939
|
-
* and keeps no subtotal; one holding none draws its children's, and keeps what
|
|
1940
|
-
* it draws, where it draws, as its subtotals. Either way, it carries every
|
|
1941
|
-
* subtotal beneath it on to its parent.
|
|
1942
|
-
*/
|
|
1943
|
-
get composed() {
|
|
1944
|
-
return East.function([SubtotalNodeType, ArrayType(ComposedType), ArrayType(RecordRollupType), ArrayType(RecordLevelType), SubtotalTilesType, TileStepFnType], ComposedType, ($, node, children, rollups, levels, tiles, startOf) => {
|
|
1945
|
-
const own = $.const(NESTED_FNS.ownDraws);
|
|
1946
|
-
const gathered = $.const(NESTED_FNS.childDraws);
|
|
1947
|
-
const path = $.const(NESTED_FNS.pathOf);
|
|
1948
|
-
const beneath = $.let(children.flatMap((_$, child) => child.subtotals.toArray((_$, value, key) => ({ key, value })))
|
|
1949
|
-
.toDict((_$, subtotal) => subtotal.key, (_$, subtotal) => subtotal.value));
|
|
1950
|
-
$.if(East.greater(node.own.size(), 0n), ($) => {
|
|
1951
|
-
$.return({ draws: own(node.own, rollups, levels, tiles, startOf), subtotals: beneath });
|
|
1952
|
-
});
|
|
1953
|
-
const draws = $.let(gathered(children));
|
|
1954
|
-
const here = $.let(path(node.key.path));
|
|
1955
|
-
$(beneath.unionInPlace(draws.toDict((_$, _value, key) => ({ path: here, rollup: key.rollup, level: key.level, tile: key.tile }), (_$, value) => value)));
|
|
1956
|
-
return { draws, subtotals: beneath };
|
|
1957
|
-
});
|
|
1958
|
-
},
|
|
1959
|
-
/**
|
|
1960
|
-
* `(nodes, rollups, levels, tiles, startOf) → Dict<SubtotalKey, Float>`:
|
|
1961
|
-
* every parent's subtotals of a collection of values at the tiles asked for,
|
|
1962
|
-
* composed bottom-up by `toTree` over the nodes from the row down to the
|
|
1963
|
-
* collection, each node's result carried to its parent. A tile no
|
|
1964
|
-
* descendant's value touches has none.
|
|
1965
|
-
*/
|
|
1966
|
-
get subtotalsOf() {
|
|
1967
|
-
return East.function([ArrayType(SubtotalNodeType), ArrayType(RecordRollupType), ArrayType(RecordLevelType), SubtotalTilesType, TileStepFnType], DictType(SubtotalKeyType, FloatType), ($, nodes, rollups, levels, tiles, startOf) => {
|
|
1968
|
-
const compose = $.const(NESTED_FNS.composed);
|
|
1969
|
-
const roots = $.let(nodes.toTree(ComposedType, (_$, node) => node.key, (_$, node) => node.parent, (_$, node, _i, children) => compose(node, children, rollups, levels, tiles, startOf)));
|
|
1970
|
-
return roots.flatMap((_$, root) => root.subtotals.toArray((_$, value, key) => ({ key, value })))
|
|
1971
|
-
.toDict((_$, subtotal) => subtotal.key, (_$, subtotal) => subtotal.value);
|
|
1972
|
-
});
|
|
1973
|
-
},
|
|
1974
2155
|
});
|
|
1975
2156
|
//# sourceMappingURL=record-nested-programs.js.map
|