@elaraai/e3 1.0.98 → 1.0.100
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 +4 -5
- package/dist/src/browser.d.ts +2 -0
- package/dist/src/browser.d.ts.map +1 -1
- package/dist/src/browser.js +6 -0
- package/dist/src/browser.js.map +1 -1
- package/dist/src/environment-capture.d.ts +21 -0
- package/dist/src/environment-capture.d.ts.map +1 -1
- package/dist/src/environment-capture.js +48 -0
- package/dist/src/environment-capture.js.map +1 -1
- package/dist/src/export.d.ts +10 -5
- package/dist/src/export.d.ts.map +1 -1
- package/dist/src/export.js +31 -47
- package/dist/src/export.js.map +1 -1
- package/dist/src/export.spec.js +27 -16
- package/dist/src/export.spec.js.map +1 -1
- package/dist/src/function.d.ts.map +1 -1
- package/dist/src/function.js.map +1 -1
- package/dist/src/functions-cache.d.ts +60 -0
- package/dist/src/functions-cache.d.ts.map +1 -0
- package/dist/src/functions-cache.js +165 -0
- package/dist/src/functions-cache.js.map +1 -0
- package/dist/src/functions-link.spec.js +191 -12
- package/dist/src/functions-link.spec.js.map +1 -1
- package/dist/src/functions-resolve.d.ts +52 -23
- package/dist/src/functions-resolve.d.ts.map +1 -1
- package/dist/src/functions-resolve.js +244 -96
- package/dist/src/functions-resolve.js.map +1 -1
- package/dist/src/index.d.ts +8 -61
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -8
- package/dist/src/index.js.map +1 -1
- package/dist/src/internal.d.ts +53 -0
- package/dist/src/internal.d.ts.map +1 -0
- package/dist/src/internal.js +29 -0
- package/dist/src/internal.js.map +1 -0
- package/dist/src/lazy-build.d.ts +25 -0
- package/dist/src/lazy-build.d.ts.map +1 -0
- package/dist/src/lazy-build.js +56 -0
- package/dist/src/lazy-build.js.map +1 -0
- package/dist/src/lazy-build.spec.d.ts +6 -0
- package/dist/src/lazy-build.spec.d.ts.map +1 -0
- package/dist/src/lazy-build.spec.js +153 -0
- package/dist/src/lazy-build.spec.js.map +1 -0
- package/dist/src/migration.d.ts +20 -163
- package/dist/src/migration.d.ts.map +1 -1
- package/dist/src/migration.js +37 -34
- package/dist/src/migration.js.map +1 -1
- package/dist/src/migration.spec.js +83 -78
- package/dist/src/migration.spec.js.map +1 -1
- package/dist/src/mutation-programs.spec.js +211 -118
- package/dist/src/mutation-programs.spec.js.map +1 -1
- package/dist/src/mutation.d.ts +37 -141
- package/dist/src/mutation.d.ts.map +1 -1
- package/dist/src/mutation.js +66 -28
- package/dist/src/mutation.js.map +1 -1
- package/dist/src/open-beast-link.spec.js +1 -1
- package/dist/src/open-beast-link.spec.js.map +1 -1
- package/dist/src/output.js.map +1 -1
- package/dist/src/package.d.ts +2 -38
- package/dist/src/package.d.ts.map +1 -1
- package/dist/src/package.js +42 -175
- package/dist/src/package.js.map +1 -1
- package/dist/src/record-area.d.ts +49 -37
- package/dist/src/record-area.d.ts.map +1 -1
- package/dist/src/record-area.js +211 -131
- package/dist/src/record-area.js.map +1 -1
- package/dist/src/record-area.spec.js +79 -62
- package/dist/src/record-area.spec.js.map +1 -1
- package/dist/src/record-arguments.d.ts +55 -0
- package/dist/src/record-arguments.d.ts.map +1 -0
- package/dist/src/record-arguments.js +72 -0
- package/dist/src/record-arguments.js.map +1 -0
- package/dist/src/record-builders.d.ts +547 -0
- package/dist/src/record-builders.d.ts.map +1 -0
- package/dist/src/record-builders.js +112 -0
- package/dist/src/record-builders.js.map +1 -0
- package/dist/src/record-declared.spec.d.ts +6 -0
- package/dist/src/record-declared.spec.d.ts.map +1 -0
- package/dist/src/record-declared.spec.js +251 -0
- package/dist/src/record-declared.spec.js.map +1 -0
- package/dist/src/record-guards.d.ts +114 -1
- package/dist/src/record-guards.d.ts.map +1 -1
- package/dist/src/record-guards.js +153 -2
- package/dist/src/record-guards.js.map +1 -1
- package/dist/src/record-index.d.ts +128 -350
- package/dist/src/record-index.d.ts.map +1 -1
- package/dist/src/record-index.js +44 -481
- package/dist/src/record-index.js.map +1 -1
- package/dist/src/record-index.spec.js +124 -90
- package/dist/src/record-index.spec.js.map +1 -1
- package/dist/src/record-interval.d.ts +57 -36
- package/dist/src/record-interval.d.ts.map +1 -1
- package/dist/src/record-interval.js +136 -94
- package/dist/src/record-interval.js.map +1 -1
- package/dist/src/record-interval.spec.js +48 -27
- package/dist/src/record-interval.spec.js.map +1 -1
- package/dist/src/record-keys.d.ts +146 -0
- package/dist/src/record-keys.d.ts.map +1 -0
- package/dist/src/record-keys.js +178 -0
- package/dist/src/record-keys.js.map +1 -0
- package/dist/src/record-nested-programs.d.ts +1457 -0
- package/dist/src/record-nested-programs.d.ts.map +1 -0
- package/dist/src/record-nested-programs.js +1974 -0
- package/dist/src/record-nested-programs.js.map +1 -0
- package/dist/src/record-nested.d.ts +284 -0
- package/dist/src/record-nested.d.ts.map +1 -0
- package/dist/src/record-nested.js +304 -0
- package/dist/src/record-nested.js.map +1 -0
- package/dist/src/record-nested.spec.d.ts +6 -0
- package/dist/src/record-nested.spec.d.ts.map +1 -0
- package/dist/src/record-nested.spec.js +1032 -0
- package/dist/src/record-nested.spec.js.map +1 -0
- package/dist/src/record-patches.d.ts +25 -0
- package/dist/src/record-patches.d.ts.map +1 -0
- package/dist/src/record-patches.js +27 -0
- package/dist/src/record-patches.js.map +1 -0
- package/dist/src/record-programs.d.ts +192 -26
- package/dist/src/record-programs.d.ts.map +1 -1
- package/dist/src/record-programs.js +858 -350
- package/dist/src/record-programs.js.map +1 -1
- package/dist/src/record-programs.spec.d.ts +6 -0
- package/dist/src/record-programs.spec.d.ts.map +1 -0
- package/dist/src/record-programs.spec.js +242 -0
- package/dist/src/record-programs.spec.js.map +1 -0
- package/dist/src/record-series.d.ts +101 -97
- package/dist/src/record-series.d.ts.map +1 -1
- package/dist/src/record-series.js +198 -149
- package/dist/src/record-series.js.map +1 -1
- package/dist/src/record-series.spec.js +241 -120
- package/dist/src/record-series.spec.js.map +1 -1
- package/dist/src/record-tiles.d.ts +328 -37
- package/dist/src/record-tiles.d.ts.map +1 -1
- package/dist/src/record-tiles.js +289 -100
- package/dist/src/record-tiles.js.map +1 -1
- package/dist/src/record.d.ts +66 -12
- package/dist/src/record.d.ts.map +1 -1
- package/dist/src/record.js +103 -34
- package/dist/src/record.js.map +1 -1
- package/dist/src/record.spec.js +48 -63
- package/dist/src/record.spec.js.map +1 -1
- package/dist/src/task.d.ts.map +1 -1
- package/dist/src/task.js +4 -1
- package/dist/src/task.js.map +1 -1
- package/dist/src/types.d.ts +103 -37
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +7 -3
|
@@ -3,23 +3,24 @@
|
|
|
3
3
|
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
-
* `
|
|
7
|
-
* event touches and its share of each,
|
|
8
|
-
* the
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
6
|
+
* A record's `index.series` and `index.summary` (#1039): the tiles an
|
|
7
|
+
* event touches and its share of each, and the places a series index files it
|
|
8
|
+
* — once, at the level its length fits, or once a year past a year (#1433) —
|
|
9
|
+
* each against a direct oracle written with the host's calendar rather than
|
|
10
|
+
* East's; the keys and contributions they generate; their declared types;
|
|
11
|
+
* their refusals; and how a write keeps them — a series index equals its
|
|
12
|
+
* rebuild, and a summary's changes, added to the totals it held, equal the
|
|
13
|
+
* totals a rebuild sums. That every runtime files an event alike is e3-core's
|
|
14
|
+
* series spec, which runs the programs on each.
|
|
13
15
|
*/
|
|
14
16
|
import { describe, it } from 'node:test';
|
|
15
17
|
import assert from 'node:assert/strict';
|
|
16
18
|
import { DateTimeType, DictType, East, IntegerType, NullType, OptionType, PatchType, SetType, SortedMap, SortedSet, StringType, StructType, compareFor, decodeBeast2For, encodeBeast2For, encodeBeast2PagedFor, equalFor, none, parseFor, printFor, printType, some, variant, } from '@elaraai/east';
|
|
17
|
-
import { RecordSummaryOpType, RecordSummaryTotalsType } from '@elaraai/e3-types';
|
|
19
|
+
import { RecordLevelType, RecordSummaryOpType, RecordSummaryTotalsType, } from '@elaraai/e3-types';
|
|
18
20
|
import { record } from './record.js';
|
|
19
|
-
import {
|
|
20
|
-
import { MAX_EVENT_TILES, RECORD_TILES, checkTile, tileNext, tileShares, tileStart } from './record-tiles.js';
|
|
21
|
+
import { MAX_EVENT_TILES, RECORD_TILES, SHORTEST_MS, TILE_FNS, checkTile, } from './record-tiles.js';
|
|
21
22
|
import { buildMutationProgram, indexBuildProgram, summaryMergeProgram } from './record-programs.js';
|
|
22
|
-
import {
|
|
23
|
+
import { functionAt } from './record-guards.js';
|
|
23
24
|
import { package_ } from './package.js';
|
|
24
25
|
/** A print job: the press it runs on, the crews on it, its state, and when it runs, or not yet. */
|
|
25
26
|
const JobRow = StructType({
|
|
@@ -27,13 +28,18 @@ const JobRow = StructType({
|
|
|
27
28
|
start: OptionType(DateTimeType), end: OptionType(DateTimeType), title: StringType,
|
|
28
29
|
});
|
|
29
30
|
const JobsType = DictType(StringType, JobRow);
|
|
30
|
-
const jobs = () => record('jobs', JobsType, new Map());
|
|
31
31
|
const keyOrder = compareFor(StringType);
|
|
32
32
|
const decodeJob = decodeBeast2For(JobRow);
|
|
33
33
|
const encodeJob = encodeBeast2For(JobRow);
|
|
34
34
|
/** A press's shift: always placed, its start and end plain DateTimes. */
|
|
35
35
|
const ShiftRow = StructType({ press: StringType, start: DateTimeType, end: DateTimeType });
|
|
36
|
-
const
|
|
36
|
+
const ShiftsType = DictType(StringType, ShiftRow);
|
|
37
|
+
/** The series index the jobs record declares under `name`, as `e3.record` builds it. */
|
|
38
|
+
const jobSeries = (name, spec) => record('jobs', JobsType, { indexes: (index) => ({ [name]: index.series(spec) }) }).indexes[name];
|
|
39
|
+
/** The summary index the jobs record declares under `name`, as `e3.record` builds it. */
|
|
40
|
+
const jobSummary = (name, spec) => record('jobs', JobsType, { indexes: (index) => ({ [name]: index.summary(spec) }) }).indexes[name];
|
|
41
|
+
/** The series index the shifts record declares under `name`, as `e3.record` builds it. */
|
|
42
|
+
const shiftSeries = (name, spec) => record('shifts', ShiftsType, { indexes: (index) => ({ [name]: index.series(spec) }) }).indexes[name];
|
|
37
43
|
const DAY = 86400000n;
|
|
38
44
|
const HOUR = 3600000n;
|
|
39
45
|
const WEEK = 7n * DAY;
|
|
@@ -119,18 +125,35 @@ function oracleShares(tile, from, to) {
|
|
|
119
125
|
}
|
|
120
126
|
return shares;
|
|
121
127
|
}
|
|
128
|
+
/** Where a series index declared at `tile` files `[from, to)`: once, at the finest level from `tile` whose shortest tile holds its length; past a year, under each year it touches. */
|
|
129
|
+
function oracleFilings(tile, from, to) {
|
|
130
|
+
const length = to - from;
|
|
131
|
+
for (const level of RECORD_TILES.slice(RECORD_TILES.indexOf(tile))) {
|
|
132
|
+
if (length <= SHORTEST_MS[level])
|
|
133
|
+
return [{ level, tile: oracleStart(level, from) }];
|
|
134
|
+
}
|
|
135
|
+
const years = [];
|
|
136
|
+
for (let start = oracleStart('year', from); start < to; start = oracleNext('year', start))
|
|
137
|
+
years.push({ level: 'year', tile: start });
|
|
138
|
+
return years;
|
|
139
|
+
}
|
|
122
140
|
/** An instant's milliseconds from the epoch, read by East. */
|
|
123
141
|
const millisecondsOf = East.compile(East.function([DateTimeType], IntegerType, (_$, t) => t.toEpochMilliseconds()), []);
|
|
124
|
-
/**
|
|
142
|
+
/** The tile functions, as each runtime computes them. */
|
|
143
|
+
const startOf = East.compile(TILE_FNS.tileStart, []);
|
|
144
|
+
const nextOf = East.compile(TILE_FNS.tileNext, []);
|
|
145
|
+
const sharesOf = East.compile(TILE_FNS.tileShares, []);
|
|
146
|
+
const filingsOf = East.compile(TILE_FNS.eventFilings, []);
|
|
147
|
+
/** A tile's functions over epoch milliseconds, its instants made and read by East. */
|
|
125
148
|
function compiled(tile) {
|
|
126
|
-
const
|
|
127
|
-
const nextOf = East.compile(tileNext(tile), []);
|
|
128
|
-
const sharesOf = East.compile(tileShares(tile), []);
|
|
149
|
+
const level = variant(tile, null);
|
|
129
150
|
return {
|
|
130
|
-
start: (ms) => millisecondsOf(startOf(instant(ms))),
|
|
131
|
-
next: (ms) => millisecondsOf(nextOf(instant(ms))),
|
|
132
|
-
shares: (from, to, what) => sharesOf(instant(from), instant(to), what)
|
|
151
|
+
start: (ms) => millisecondsOf(startOf(level, instant(ms))),
|
|
152
|
+
next: (ms) => millisecondsOf(nextOf(level, instant(ms))),
|
|
153
|
+
shares: (from, to, what) => sharesOf(level, instant(from), instant(to), what)
|
|
133
154
|
.map((share) => ({ tile: millisecondsOf(share.tile), ms: share.ms })),
|
|
155
|
+
filings: (from, to, what) => filingsOf(level, instant(from), instant(to), what)
|
|
156
|
+
.map((filing) => ({ level: filing.level.type, tile: millisecondsOf(filing.tile) })),
|
|
134
157
|
};
|
|
135
158
|
}
|
|
136
159
|
// ── The rows the writes carry ────────────────────────────────────────────────
|
|
@@ -265,9 +288,9 @@ describe('the tiles an event touches', () => {
|
|
|
265
288
|
it('takes the five tiles and refuses any other, naming them', () => {
|
|
266
289
|
assert.deepEqual([...RECORD_TILES], ['day', 'week', 'month', 'quarter', 'year']);
|
|
267
290
|
for (const tile of RECORD_TILES)
|
|
268
|
-
assert.equal(checkTile('
|
|
291
|
+
assert.equal(checkTile('index.series', 'by_tile', tile), tile);
|
|
269
292
|
for (const bad of ['hour', 'Day', '', 7, undefined]) {
|
|
270
|
-
assert.throws(() => checkTile('
|
|
293
|
+
assert.throws(() => checkTile('index.series', 'by_tile', bad), /index\.series 'by_tile' takes a tile: "day", "week", "month", "quarter", "year" — got /);
|
|
271
294
|
}
|
|
272
295
|
});
|
|
273
296
|
it('names the tiles a reader would: an ISO week from its Monday, a quarter from January, April, July or October', () => {
|
|
@@ -286,9 +309,9 @@ describe('the tiles an event touches', () => {
|
|
|
286
309
|
['year', '1969-07-20T20:17:00.000', '1969-01-01T00:00:00.000', '1970-01-01T00:00:00.000'],
|
|
287
310
|
];
|
|
288
311
|
for (const [tile, held, first, after] of cases) {
|
|
289
|
-
const start =
|
|
312
|
+
const start = startOf(variant(tile, null), at(held));
|
|
290
313
|
assert.ok(sameInstant(start, at(first)), `the ${tile} holding ${held} starts ${first}, not ${print(start)}`);
|
|
291
|
-
const next =
|
|
314
|
+
const next = nextOf(variant(tile, null), start);
|
|
292
315
|
assert.ok(sameInstant(next, at(after)), `the ${tile} after ${first} starts ${after}, not ${print(next)}`);
|
|
293
316
|
}
|
|
294
317
|
});
|
|
@@ -336,7 +359,7 @@ describe('the tiles an event touches', () => {
|
|
|
336
359
|
}
|
|
337
360
|
}
|
|
338
361
|
});
|
|
339
|
-
it(`refuses
|
|
362
|
+
it(`refuses a summary's event touching more than ${MAX_EVENT_TILES} of its tiles, naming it, its span and the tile`, () => {
|
|
340
363
|
const day = compiled('day');
|
|
341
364
|
const noon = monthStart(2026, 0) + DAY / 2n;
|
|
342
365
|
// Noon to noon 4,095 days on touches 4,096 days: the most an event may.
|
|
@@ -346,40 +369,115 @@ describe('the tiles an event touches', () => {
|
|
|
346
369
|
assert.deepEqual(compiled('week').shares(noon, noon + 4096n * DAY, 'job W-0001'), oracleShares('week', noon, noon + 4096n * DAY));
|
|
347
370
|
});
|
|
348
371
|
});
|
|
372
|
+
// ── Where a series index files an event (#1433) ──────────────────────────────
|
|
373
|
+
describe('the places a series index files an event', () => {
|
|
374
|
+
const noonOct5 = OCT_5 + DAY / 2n;
|
|
375
|
+
const YEAR = 365n * DAY;
|
|
376
|
+
it('files an event once, at the finest level from its tile whose shortest tile holds its length — or, past a year, under each year it touches', () => {
|
|
377
|
+
// The lengths the measures name, each from noon on Monday 5 October 2026, at each declared tile.
|
|
378
|
+
const lengths = [
|
|
379
|
+
['an instant', 0n], ['8 hours', 8n * HOUR], ['1 week', WEEK], ['28 days', 28n * DAY], ['29 days', 29n * DAY],
|
|
380
|
+
['90 days', 90n * DAY], ['91 days', 91n * DAY], ['365 days', YEAR], ['366 days', YEAR + DAY], ['3 years', 3n * YEAR], ['10 years', 10n * YEAR],
|
|
381
|
+
];
|
|
382
|
+
const expected = {
|
|
383
|
+
day: ['day', 'day', 'week', 'month', 'quarter', 'quarter', 'year', 'year', 'year×2', 'year×4', 'year×11'],
|
|
384
|
+
week: ['week', 'week', 'week', 'month', 'quarter', 'quarter', 'year', 'year', 'year×2', 'year×4', 'year×11'],
|
|
385
|
+
month: ['month', 'month', 'month', 'month', 'quarter', 'quarter', 'year', 'year', 'year×2', 'year×4', 'year×11'],
|
|
386
|
+
quarter: ['quarter', 'quarter', 'quarter', 'quarter', 'quarter', 'quarter', 'year', 'year', 'year×2', 'year×4', 'year×11'],
|
|
387
|
+
year: ['year', 'year', 'year', 'year', 'year', 'year', 'year', 'year', 'year×2', 'year×4', 'year×11'],
|
|
388
|
+
};
|
|
389
|
+
for (const tile of RECORD_TILES) {
|
|
390
|
+
const { filings } = compiled(tile);
|
|
391
|
+
const got = lengths.map(([what, length]) => {
|
|
392
|
+
const placed = filings(noonOct5, noonOct5 + length, what);
|
|
393
|
+
assert.deepEqual(placed, oracleFilings(tile, noonOct5, noonOct5 + length), `${tile}: ${what}`);
|
|
394
|
+
return placed.length === 1 ? placed[0].level : `${placed[0].level}×${placed.length}`;
|
|
395
|
+
});
|
|
396
|
+
assert.deepEqual(got, expected[tile], `at ${tile} tiles`);
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
it('files an instant, or an end at or before the start, at its tile; 23:59:59.999 on a Sunday under that Sunday\'s week; 366 days under both years it touches', () => {
|
|
400
|
+
const week = compiled('week');
|
|
401
|
+
const oct5 = OCT_5;
|
|
402
|
+
assert.deepEqual(week.filings(noonOct5, noonOct5, 'job'), [{ level: 'week', tile: oct5 }], 'an instant');
|
|
403
|
+
assert.deepEqual(week.filings(noonOct5, noonOct5 - HOUR, 'job'), [{ level: 'week', tile: oct5 }], 'an end before its start');
|
|
404
|
+
const sunday = oct5 + 7n * DAY - 1n;
|
|
405
|
+
assert.deepEqual(week.filings(sunday, sunday + 8n * HOUR, 'job'), [{ level: 'week', tile: oct5 }], 'the week holding its start, though it ends in the next');
|
|
406
|
+
const march = monthStart(2026, 2);
|
|
407
|
+
assert.deepEqual(week.filings(march, march + YEAR + DAY, 'job'), [{ level: 'year', tile: monthStart(2026, 0) }, { level: 'year', tile: monthStart(2027, 0) }], 'past a year: each year it touches');
|
|
408
|
+
});
|
|
409
|
+
it('files as the oracle does, before 1970 as after, every length from an instant to twelve years', () => {
|
|
410
|
+
for (const tile of RECORD_TILES) {
|
|
411
|
+
const { filings } = compiled(tile);
|
|
412
|
+
const draw = stream(RECORD_TILES.indexOf(tile) + 3039);
|
|
413
|
+
const events = [[MONDAY, MONDAY], [-1n, 1n], [monthStart(1969, 11), monthStart(1970, 1)]];
|
|
414
|
+
for (const level of RECORD_TILES) {
|
|
415
|
+
// Each level's edge: its shortest tile exactly, and a millisecond past it.
|
|
416
|
+
events.push([OCT_5, OCT_5 + SHORTEST_MS[level]], [OCT_5, OCT_5 + SHORTEST_MS[level] + 1n]);
|
|
417
|
+
}
|
|
418
|
+
for (let i = 0; i < 400; i++) {
|
|
419
|
+
const from = BigInt(Math.floor((draw() * 2 - 1) * SPAN));
|
|
420
|
+
const length = i % 10 === 0 ? 0n : BigInt(Math.floor(draw() ** 3 * 12 * 366)) * DAY + BigInt(Math.floor(draw() * 24)) * HOUR;
|
|
421
|
+
events.push([from, from + length], [from, from - length]);
|
|
422
|
+
}
|
|
423
|
+
for (const [from, to] of events) {
|
|
424
|
+
const got = filings(from, to, 'event');
|
|
425
|
+
assert.deepEqual(got, oracleFilings(tile, from, to), `${tile}: ${from} to ${to}`);
|
|
426
|
+
// An event filed at a level ends before the end of the tile after the one holding its start.
|
|
427
|
+
if (got.length === 1 && to > from) {
|
|
428
|
+
const level = got[0].level;
|
|
429
|
+
assert.ok(to <= oracleNext(level, oracleNext(level, got[0].tile)), `${tile}: ${from} to ${to} ends within the ${level} after its own`);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
it(`files an event under each of as many as ${MAX_EVENT_TILES} years it touches, and refuses one touching more, naming it and its span`, () => {
|
|
435
|
+
const day = compiled('day');
|
|
436
|
+
const first = monthStart(2026, 0) + DAY / 2n;
|
|
437
|
+
const last = monthStart(2026 + 4_095, 6);
|
|
438
|
+
const placed = day.filings(first, last, 'job W-0001');
|
|
439
|
+
assert.equal(placed.length, 4096, 'from 2026 to 6121: 4,096 years');
|
|
440
|
+
assert.deepEqual([placed[0], placed[4095]], [{ level: 'year', tile: monthStart(2026, 0) }, { level: 'year', tile: monthStart(6121, 0) }]);
|
|
441
|
+
assert.throws(() => day.filings(first, monthStart(2026 + 4_096, 6), 'job W-0001'), /job W-0001, from 2026-01-01T12:00:00\.000 to 6122-07-01T00:00:00\.000, touches more than 4096 year tiles: end it within 4096 years of its start/);
|
|
442
|
+
});
|
|
443
|
+
});
|
|
349
444
|
// ── The series index ─────────────────────────────────────────────────────────
|
|
350
|
-
describe('
|
|
445
|
+
describe('index.series — its keys', () => {
|
|
351
446
|
const scheduled = (start, end) => decodeJob(encodeJob({
|
|
352
447
|
press: 'P-1001', crews: new SortedSet(['north', 'south'], keyOrder), state: 'confirmed',
|
|
353
448
|
start: start === null ? none : some(at(start)), end: end === null ? none : some(at(end)), title: 'Brochure run',
|
|
354
449
|
}));
|
|
355
|
-
it('files an event under
|
|
356
|
-
const byPressWeek =
|
|
357
|
-
const byStatePressWeek =
|
|
358
|
-
const byCrewPressWeek =
|
|
359
|
-
const keysByPressWeek = East.compile(byPressWeek.keyFn, []);
|
|
360
|
-
const keysByStatePressWeek = East.compile(byStatePressWeek.keyFn, []);
|
|
361
|
-
const keysByCrewPressWeek = East.compile(byCrewPressWeek.keyFn, []);
|
|
362
|
-
// Wednesday 06:00 to the next Tuesday 06:00: the
|
|
450
|
+
it('files an event once, under the level its length fits and the tile holding its start, its leading fields first and a Set fanned out', () => {
|
|
451
|
+
const byPressWeek = jobSeries('jobs_by_press_week', { key: 'press', from: 'start', to: 'end', tile: 'week' });
|
|
452
|
+
const byStatePressWeek = jobSeries('jobs_by_state_press_week', { on: ['state'], key: 'press', from: 'start', to: 'end', tile: 'week' });
|
|
453
|
+
const byCrewPressWeek = jobSeries('jobs_by_crew_press_week', { on: ['crews'], key: 'press', from: 'start', to: 'end', tile: 'week' });
|
|
454
|
+
const keysByPressWeek = East.compile(functionAt(byPressWeek.keyFn, [StringType, JobRow], SetType(byPressWeek.keyType)), []);
|
|
455
|
+
const keysByStatePressWeek = East.compile(functionAt(byStatePressWeek.keyFn, [StringType, JobRow], SetType(byStatePressWeek.keyType)), []);
|
|
456
|
+
const keysByCrewPressWeek = East.compile(functionAt(byCrewPressWeek.keyFn, [StringType, JobRow], SetType(byCrewPressWeek.keyType)), []);
|
|
457
|
+
// Wednesday 06:00 to the next Tuesday 06:00: six days, a week's length, under the week of 5 October that holds its start.
|
|
363
458
|
const row = scheduled('2026-10-07T06:00:00.000', '2026-10-13T06:00:00.000');
|
|
364
459
|
const oct5 = at('2026-10-05T00:00:00.000');
|
|
365
|
-
const
|
|
460
|
+
const week = variant('week', null);
|
|
366
461
|
assertEast(SetType(byPressWeek.keyType), keysByPressWeek('W-0001', row), new SortedSet([
|
|
367
|
-
{
|
|
368
|
-
], compareFor(byPressWeek.keyType)), '
|
|
462
|
+
{ on: {}, key: 'P-1001', level: week, tile: oct5 },
|
|
463
|
+
], compareFor(byPressWeek.keyType)), 'once, under the week holding its start');
|
|
369
464
|
assertEast(SetType(byStatePressWeek.keyType), keysByStatePressWeek('W-0001', row), new SortedSet([
|
|
370
|
-
{ state: 'confirmed'
|
|
465
|
+
{ on: { state: 'confirmed' }, key: 'P-1001', level: week, tile: oct5 },
|
|
371
466
|
], compareFor(byStatePressWeek.keyType)), 'led by its state');
|
|
372
467
|
assertEast(SetType(byCrewPressWeek.keyType), keysByCrewPressWeek('W-0001', row), new SortedSet([
|
|
373
|
-
{ crews: 'north'
|
|
374
|
-
{ crews: 'south', __tile: oct5, press: 'P-1001' }, { crews: 'south', __tile: oct12, press: 'P-1001' },
|
|
468
|
+
{ on: { crews: 'north' }, key: 'P-1001', level: week, tile: oct5 }, { on: { crews: 'south' }, key: 'P-1001', level: week, tile: oct5 },
|
|
375
469
|
], compareFor(byCrewPressWeek.keyType)), 'once a crew');
|
|
470
|
+
// Five weeks long: past a month's 28 days, so under the quarter holding its start.
|
|
471
|
+
assertEast(SetType(byPressWeek.keyType), keysByPressWeek('W-0001', scheduled('2026-10-07T06:00:00.000', '2026-11-11T06:00:00.000')), new SortedSet([
|
|
472
|
+
{ on: {}, key: 'P-1001', level: variant('quarter', null), tile: at('2026-10-01T00:00:00.000') },
|
|
473
|
+
], compareFor(byPressWeek.keyType)), 'a longer event at a coarser level');
|
|
376
474
|
});
|
|
377
|
-
it('files an instant, or an end at or before the start, under the
|
|
378
|
-
const def =
|
|
475
|
+
it('files an instant, or an end at or before the start, at its tile under the tile holding its start; no start, under none', () => {
|
|
476
|
+
const def = jobSeries('jobs_by_press_week', { key: 'press', from: 'start', to: 'end', tile: 'week' });
|
|
379
477
|
const keysType = SetType(def.keyType);
|
|
380
478
|
const order = compareFor(def.keyType);
|
|
381
|
-
const oct5 = {
|
|
382
|
-
const keys = East.compile(def.keyFn, []);
|
|
479
|
+
const oct5 = { on: {}, key: 'P-1001', level: variant('week', null), tile: at('2026-10-05T00:00:00.000') };
|
|
480
|
+
const keys = East.compile(functionAt(def.keyFn, [StringType, JobRow], keysType), []);
|
|
383
481
|
assertEast(keysType, keys('W-0001', scheduled('2026-10-07T06:00:00.000', null)), new SortedSet([oct5], order), 'no end');
|
|
384
482
|
assertEast(keysType, keys('W-0001', scheduled('2026-10-07T06:00:00.000', '2026-10-01T00:00:00.000')), new SortedSet([oct5], order), 'an end before its start');
|
|
385
483
|
assertEast(keysType, keys('W-0001', scheduled('2026-10-07T06:00:00.000', '2026-10-07T06:00:00.000')), new SortedSet([oct5], order), 'an end at its start');
|
|
@@ -387,35 +485,37 @@ describe('e3.recordIndex.series — its keys', () => {
|
|
|
387
485
|
assertEast(keysType, keys('W-0001', scheduled(null, '2026-10-12T00:00:00.000')), new SortedSet([], order), 'no start');
|
|
388
486
|
});
|
|
389
487
|
it('reads a plain DateTime start and end as an Option\'s', () => {
|
|
390
|
-
const def =
|
|
488
|
+
const def = shiftSeries('shifts_by_press_day', { key: 'press', from: 'start', to: 'end', tile: 'day' });
|
|
391
489
|
const shift = decodeBeast2For(ShiftRow)(encodeBeast2For(ShiftRow)({ press: 'P-1002', start: at('2026-10-05T22:00:00.000'), end: at('2026-10-06T06:00:00.000') }));
|
|
392
|
-
const keys = East.compile(def.keyFn, []);
|
|
490
|
+
const keys = East.compile(functionAt(def.keyFn, [StringType, ShiftRow], SetType(def.keyType)), []);
|
|
393
491
|
assertEast(SetType(def.keyType), keys('S-1', shift), new SortedSet([
|
|
394
|
-
{
|
|
395
|
-
], compareFor(def.keyType)), 'a night shift is
|
|
492
|
+
{ on: {}, key: 'P-1002', level: variant('day', null), tile: at('2026-10-05T00:00:00.000') },
|
|
493
|
+
], compareFor(def.keyType)), 'a night shift, eight hours, is filed once, under the day it starts');
|
|
396
494
|
});
|
|
397
495
|
});
|
|
398
|
-
describe('
|
|
496
|
+
describe('index.series — its declaration', () => {
|
|
399
497
|
it('types its key, its fields and its projection from the spec, and carries its fields and tile', () => {
|
|
400
|
-
const def =
|
|
498
|
+
const def = jobSeries('jobs_by_state_press_week', { on: ['state'], key: 'press', from: 'start', to: 'end', tile: 'week' });
|
|
401
499
|
const keyType = def.keyType;
|
|
402
500
|
const fields = def.on;
|
|
403
501
|
const projection = def.valueType;
|
|
404
|
-
assert.equal(printType(keyType), printType(StructType({ state: StringType,
|
|
405
|
-
assert.deepEqual(fields, ['state'
|
|
502
|
+
assert.equal(printType(keyType), printType(StructType({ on: StructType({ state: StringType }), key: StringType, level: RecordLevelType, tile: DateTimeType })), 'its leading fields under on, the key, the level, then the tile');
|
|
503
|
+
assert.deepEqual(fields, ['state']);
|
|
406
504
|
assert.equal(printType(projection), printType(JobRow), 'it carries the whole row');
|
|
407
505
|
assert.deepEqual(def.series, { key: 'press', from: 'start', to: 'end', tile: 'week' });
|
|
408
|
-
assert.equal(def.multi, true, 'an entry a
|
|
506
|
+
assert.equal(def.multi, true, 'an entry a place it is filed');
|
|
409
507
|
assert.equal(def.summary, undefined);
|
|
410
|
-
const on = ['crews'
|
|
411
|
-
const key = StructType({ crews: StringType,
|
|
412
|
-
|
|
508
|
+
const on = ['crews'];
|
|
509
|
+
const key = StructType({ on: StructType({ crews: StringType }), key: StringType, level: RecordLevelType, tile: DateTimeType });
|
|
510
|
+
const totals = StructType({ on: StructType({ crews: StringType }), key: StringType, tile: DateTimeType });
|
|
511
|
+
assert.ok(on.length === 1 && key.type === 'Struct' && totals.type === 'Struct');
|
|
413
512
|
});
|
|
414
|
-
it('
|
|
415
|
-
const def =
|
|
513
|
+
it('files each scheduled job once, projecting each entry as its whole row', () => {
|
|
514
|
+
const def = jobSeries('jobs_by_press_week', { key: 'press', from: 'start', to: 'end', tile: 'week' });
|
|
416
515
|
const rows = seededJobs();
|
|
417
516
|
const out = emitted(def, rows);
|
|
418
|
-
|
|
517
|
+
const scheduled = [...rows.values()].filter((row) => row.start.type === 'some').length;
|
|
518
|
+
assert.equal(out.length, scheduled, 'none longer than a year: each once, the jobs across a week\'s edge among them');
|
|
419
519
|
const sameJob = equalFor(JobRow);
|
|
420
520
|
for (const [entry, value] of out) {
|
|
421
521
|
const k = entry.k;
|
|
@@ -425,48 +525,55 @@ describe('e3.recordIndex.series — its declaration', () => {
|
|
|
425
525
|
describe('refuses, at definition time', () => {
|
|
426
526
|
it('a field of the wrong type, or none, naming the option, the field and its type', () => {
|
|
427
527
|
// @ts-expect-error — from takes a DateTime or an Option<DateTime> field
|
|
428
|
-
assert.throws(() =>
|
|
528
|
+
assert.throws(() => jobSeries('bad_from', { key: 'press', from: 'title', to: 'end', tile: 'week' }), /from names 'title', of type \.String: from is a DateTime or an Option<DateTime> field/);
|
|
429
529
|
// @ts-expect-error — the row has no such field
|
|
430
|
-
assert.throws(() =>
|
|
530
|
+
assert.throws(() => jobSeries('bad_to', { key: 'press', from: 'start', to: 'missing', tile: 'week' }), /to names unknown row field 'missing'/);
|
|
431
531
|
// @ts-expect-error — the key is the one field naming what an event is on, never a Set
|
|
432
|
-
assert.throws(() =>
|
|
532
|
+
assert.throws(() => jobSeries('set_key', { key: 'crews', from: 'start', to: 'end', tile: 'week' }), /key names 'crews', a Set/);
|
|
433
533
|
// @ts-expect-error — the row has no such field
|
|
434
|
-
assert.throws(() =>
|
|
534
|
+
assert.throws(() => jobSeries('bad_key', { key: 'machine', from: 'start', to: 'end', tile: 'week' }), /key names unknown row field 'machine'/);
|
|
435
535
|
});
|
|
436
536
|
it('a tile that is not one of the five, and the key among the leading fields', () => {
|
|
437
537
|
// @ts-expect-error — a tile is one of the five
|
|
438
|
-
assert.throws(() =>
|
|
439
|
-
assert.throws(() =>
|
|
538
|
+
assert.throws(() => jobSeries('hourly', { key: 'press', from: 'start', to: 'end', tile: 'hour' }), /takes a tile: "day", "week", "month", "quarter", "year" — got "hour"/);
|
|
539
|
+
assert.throws(() => jobSeries('led_by_key', { on: ['press'], key: 'press', from: 'start', to: 'end', tile: 'week' }), /'press' follows the leading fields, and cannot be one/);
|
|
440
540
|
});
|
|
441
541
|
it('the start or the end among the leading fields: a leading field is matched exactly, before the tile they are cut by', () => {
|
|
442
542
|
// Led by its own start, a series' entries of one tile on a block of keys
|
|
443
543
|
// are a range for each instant an event starts at, never one range.
|
|
444
|
-
assert.throws(() =>
|
|
445
|
-
assert.throws(() =>
|
|
446
|
-
assert.throws(() =>
|
|
544
|
+
assert.throws(() => jobSeries('led_by_start', { on: ['start'], key: 'press', from: 'start', to: 'end', tile: 'week' }), /e3\.record 'jobs': index\.series 'led_by_start': 'start' is the event's start, which its tiles are cut by, and cannot be a leading field/);
|
|
545
|
+
assert.throws(() => jobSeries('led_by_end', { on: ['state', 'end'], key: 'press', from: 'start', to: 'end', tile: 'week' }), /e3\.record 'jobs': index\.series 'led_by_end': 'end' is the event's end, which its tiles are cut by, and cannot be a leading field/);
|
|
546
|
+
assert.throws(() => jobSummary('totals_led_by_start', { on: ['start'], key: 'press', from: 'start', to: 'end', tile: 'week' }), /e3\.record 'jobs': index\.summary 'totals_led_by_start': 'start' is the event's start, which its tiles are cut by, and cannot be a leading field/);
|
|
447
547
|
});
|
|
448
|
-
it('a value,
|
|
548
|
+
it('a value, and the guards every index applies to its name and its record — a row field may be named anything (#1432)', () => {
|
|
449
549
|
// @ts-expect-error — a series index carries the whole row, and takes no value
|
|
450
|
-
assert.throws(() =>
|
|
451
|
-
|
|
452
|
-
const
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
550
|
+
assert.throws(() => jobSeries('valued', { key: 'press', from: 'start', to: 'end', tile: 'week', value: East.function([StringType, JobRow], StringType, (_$, k) => k) }), /a series index carries the whole row as its projection, so it takes no value/);
|
|
551
|
+
// A row field named `__tile`, `tile` or `key` reserves nothing: the index builds, led by them.
|
|
552
|
+
const Named = StructType({ press: StringType, start: DateTimeType, end: DateTimeType, __tile: IntegerType, tile: StringType, key: StringType });
|
|
553
|
+
const named = record('named', DictType(StringType, Named), {
|
|
554
|
+
initial: new Map(),
|
|
555
|
+
indexes: (index) => ({
|
|
556
|
+
named_tile: index.series({ on: ['__tile', 'tile', 'key'], key: 'press', from: 'start', to: 'end', tile: 'day' }),
|
|
557
|
+
}),
|
|
558
|
+
});
|
|
559
|
+
const byNamed = named.indexes.named_tile;
|
|
560
|
+
assert.equal(printType(byNamed.keyType), printType(StructType({ on: StructType({ __tile: IntegerType, tile: StringType, key: StringType }), key: StringType, level: RecordLevelType, tile: DateTimeType })));
|
|
561
|
+
assert.throws(() => jobSeries('primary', { key: 'press', from: 'start', to: 'end', tile: 'day' }), /e3\.record 'jobs': index\.series cannot be named 'primary'/);
|
|
562
|
+
assert.throws(() => jobSeries('by tile', { key: 'press', from: 'start', to: 'end', tile: 'day' }), /must be an identifier/);
|
|
456
563
|
});
|
|
457
564
|
});
|
|
458
565
|
});
|
|
459
566
|
// ── The summary index ────────────────────────────────────────────────────────
|
|
460
|
-
describe('
|
|
567
|
+
describe('index.summary — its contributions and declaration', () => {
|
|
461
568
|
const scheduled = (start, end) => decodeJob(encodeJob({
|
|
462
569
|
press: 'P-1001', crews: new SortedSet(['north', 'south'], keyOrder), state: 'confirmed',
|
|
463
570
|
start: start === null ? none : some(at(start)), end: end === null ? none : some(at(end)), title: 'Brochure run',
|
|
464
571
|
}));
|
|
465
572
|
it('counts an event once under each tile it touches, with the milliseconds of it covered; an instant covers none; no start counts nowhere', () => {
|
|
466
|
-
const def =
|
|
467
|
-
const byCrew =
|
|
468
|
-
const contribute = East.compile(def.keyFn, []);
|
|
469
|
-
const contributeByCrew = East.compile(byCrew.keyFn, []);
|
|
573
|
+
const def = jobSummary('jobs_by_press_week_totals', { key: 'press', from: 'start', to: 'end', tile: 'week' });
|
|
574
|
+
const byCrew = jobSummary('jobs_by_crew_press_week_totals', { on: ['crews'], key: 'press', from: 'start', to: 'end', tile: 'week' });
|
|
575
|
+
const contribute = East.compile(functionAt(def.keyFn, [StringType, JobRow], DictType(def.keyType, RecordSummaryTotalsType)), []);
|
|
576
|
+
const contributeByCrew = East.compile(functionAt(byCrew.keyFn, [StringType, JobRow], DictType(byCrew.keyType, RecordSummaryTotalsType)), []);
|
|
470
577
|
const contributions = DictType(def.keyType, RecordSummaryTotalsType);
|
|
471
578
|
const order = compareFor(def.keyType);
|
|
472
579
|
const oct5 = at('2026-10-05T00:00:00.000');
|
|
@@ -474,26 +581,26 @@ describe('e3.recordIndex.summary — its contributions and declaration', () => {
|
|
|
474
581
|
// Wednesday 06:00 to the next Tuesday 06:00: 114 hours of one week, 30 of the next.
|
|
475
582
|
const row = scheduled('2026-10-07T06:00:00.000', '2026-10-13T06:00:00.000');
|
|
476
583
|
assertEast(contributions, contribute('W-0001', row), new SortedMap([
|
|
477
|
-
[{
|
|
478
|
-
[{
|
|
584
|
+
[{ on: {}, key: 'P-1001', tile: oct5 }, { count: 1n, ms: 114n * HOUR }],
|
|
585
|
+
[{ on: {}, key: 'P-1001', tile: oct12 }, { count: 1n, ms: 30n * HOUR }],
|
|
479
586
|
], order), 'a week and the next');
|
|
480
587
|
assertEast(DictType(byCrew.keyType, RecordSummaryTotalsType), contributeByCrew('W-0001', row), new SortedMap([
|
|
481
|
-
[{ crews: 'north'
|
|
482
|
-
[{ crews: 'north'
|
|
483
|
-
[{ crews: 'south'
|
|
484
|
-
[{ crews: 'south'
|
|
588
|
+
[{ on: { crews: 'north' }, key: 'P-1001', tile: oct5 }, { count: 1n, ms: 114n * HOUR }],
|
|
589
|
+
[{ on: { crews: 'north' }, key: 'P-1001', tile: oct12 }, { count: 1n, ms: 30n * HOUR }],
|
|
590
|
+
[{ on: { crews: 'south' }, key: 'P-1001', tile: oct5 }, { count: 1n, ms: 114n * HOUR }],
|
|
591
|
+
[{ on: { crews: 'south' }, key: 'P-1001', tile: oct12 }, { count: 1n, ms: 30n * HOUR }],
|
|
485
592
|
], compareFor(byCrew.keyType)), 'once a crew');
|
|
486
593
|
assertEast(contributions, contribute('W-0001', scheduled('2026-10-07T06:00:00.000', null)), new SortedMap([
|
|
487
|
-
[{
|
|
594
|
+
[{ on: {}, key: 'P-1001', tile: oct5 }, { count: 1n, ms: 0n }],
|
|
488
595
|
], order), 'an instant');
|
|
489
596
|
assertEast(contributions, contribute('W-0001', scheduled(null, null)), new SortedMap([], order), 'not yet scheduled');
|
|
490
597
|
});
|
|
491
598
|
it('types its key from the spec and holds its totals, with no projection to carry', () => {
|
|
492
|
-
const def =
|
|
599
|
+
const def = jobSummary('jobs_by_state_press_month_totals', { on: ['state'], key: 'press', from: 'start', to: 'end', tile: 'month' });
|
|
493
600
|
const keyType = def.keyType;
|
|
494
601
|
const fields = def.on;
|
|
495
|
-
assert.equal(printType(keyType), printType(StructType({ state: StringType,
|
|
496
|
-
assert.deepEqual(fields, ['state'
|
|
602
|
+
assert.equal(printType(keyType), printType(StructType({ on: StructType({ state: StringType }), key: StringType, tile: DateTimeType })), 'its leading fields under on, the key, then the tile');
|
|
603
|
+
assert.deepEqual(fields, ['state']);
|
|
497
604
|
assert.equal(printType(def.valueType), printType(RecordSummaryTotalsType), 'its value is its totals');
|
|
498
605
|
assert.deepEqual(def.summary, { key: 'press', from: 'start', to: 'end', tile: 'month' });
|
|
499
606
|
assert.equal(def.series, undefined);
|
|
@@ -502,25 +609,29 @@ describe('e3.recordIndex.summary — its contributions and declaration', () => {
|
|
|
502
609
|
});
|
|
503
610
|
it('refuses a value, and what a series index refuses', () => {
|
|
504
611
|
// @ts-expect-error — a summary index holds its totals, and takes no value
|
|
505
|
-
assert.throws(() =>
|
|
612
|
+
assert.throws(() => jobSummary('valued', { key: 'press', from: 'start', to: 'end', tile: 'week', value: East.function([StringType, JobRow], StringType, (_$, k) => k) }), /a summary index holds its totals, so it takes no value/);
|
|
506
613
|
// @ts-expect-error — the key is never a Set
|
|
507
|
-
assert.throws(() =>
|
|
614
|
+
assert.throws(() => jobSummary('set_key', { key: 'crews', from: 'start', to: 'end', tile: 'week' }), /e3\.record 'jobs': index\.summary 'set_key' key names 'crews', a Set/);
|
|
508
615
|
// @ts-expect-error — a tile is one of the five
|
|
509
|
-
assert.throws(() =>
|
|
510
|
-
assert.throws(() =>
|
|
616
|
+
assert.throws(() => jobSummary('hourly', { key: 'press', from: 'start', to: 'end', tile: 'hour' }), /e3\.record 'jobs': index\.summary 'hourly' takes a tile/);
|
|
617
|
+
assert.throws(() => jobSummary('primary', { key: 'press', from: 'start', to: 'end', tile: 'day' }), /e3\.record 'jobs': index\.summary cannot be named 'primary'/);
|
|
511
618
|
});
|
|
512
619
|
});
|
|
513
620
|
// ── Through a write and a rebuild ────────────────────────────────────────────
|
|
514
621
|
describe('series and summary indexes — through a write and a rebuild', () => {
|
|
515
622
|
it('maintains each series index as a rebuild emits it — inserts, moves, stretches, unscheduling, deletes — byte for byte', () => {
|
|
516
|
-
const rec = jobs
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
623
|
+
const rec = record('jobs', JobsType, {
|
|
624
|
+
initial: new Map(),
|
|
625
|
+
indexes: (index) => ({
|
|
626
|
+
jobs_by_press_day: index.series({ key: 'press', from: 'start', to: 'end', tile: 'day' }),
|
|
627
|
+
jobs_by_state_press_week: index.series({ on: ['state'], key: 'press', from: 'start', to: 'end', tile: 'week' }),
|
|
628
|
+
jobs_by_crew_press_month: index.series({ on: ['crews'], key: 'press', from: 'start', to: 'end', tile: 'month' }),
|
|
629
|
+
}),
|
|
630
|
+
mutations: (mutation) => ({ patch: mutation.patch() }),
|
|
631
|
+
});
|
|
632
|
+
const indexes = Object.values(rec.indexes);
|
|
633
|
+
const patch = rec.mutations.patch;
|
|
634
|
+
const assembled = package_('series_indexes', '1.0.0', rec).records.jobs;
|
|
524
635
|
const before = seededJobs();
|
|
525
636
|
const after = editedJobs(before);
|
|
526
637
|
const changes = written(assembled, patch, before, after);
|
|
@@ -540,14 +651,18 @@ describe('series and summary indexes — through a write and a rebuild', () => {
|
|
|
540
651
|
}
|
|
541
652
|
});
|
|
542
653
|
it('changes each summary by what its rows took away and gave, a key once and never by nothing — to the totals a rebuild sums', () => {
|
|
543
|
-
const rec = jobs
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
654
|
+
const rec = record('jobs', JobsType, {
|
|
655
|
+
initial: new Map(),
|
|
656
|
+
indexes: (index) => ({
|
|
657
|
+
jobs_by_press_day_totals: index.summary({ key: 'press', from: 'start', to: 'end', tile: 'day' }),
|
|
658
|
+
jobs_by_press_week_totals: index.summary({ key: 'press', from: 'start', to: 'end', tile: 'week' }),
|
|
659
|
+
jobs_by_crew_press_month_totals: index.summary({ on: ['crews'], key: 'press', from: 'start', to: 'end', tile: 'month' }),
|
|
660
|
+
}),
|
|
661
|
+
mutations: (mutation) => ({ patch: mutation.patch() }),
|
|
662
|
+
});
|
|
663
|
+
const summaries = Object.values(rec.indexes);
|
|
664
|
+
const patch = rec.mutations.patch;
|
|
665
|
+
const assembled = package_('summary_indexes', '1.0.0', rec).records.jobs;
|
|
551
666
|
const before = seededJobs();
|
|
552
667
|
const after = editedJobs(before);
|
|
553
668
|
const changes = written(assembled, patch, before, after);
|
|
@@ -580,11 +695,17 @@ describe('series and summary indexes — through a write and a rebuild', () => {
|
|
|
580
695
|
}
|
|
581
696
|
});
|
|
582
697
|
it('writes nothing to a summary when no event moves, and one change for a key two new rows share', () => {
|
|
583
|
-
const rec = jobs
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
698
|
+
const rec = record('jobs', JobsType, {
|
|
699
|
+
initial: new Map(),
|
|
700
|
+
indexes: (index) => ({
|
|
701
|
+
jobs_by_press_week: index.series({ key: 'press', from: 'start', to: 'end', tile: 'week' }),
|
|
702
|
+
jobs_by_press_week_totals: index.summary({ key: 'press', from: 'start', to: 'end', tile: 'week' }),
|
|
703
|
+
}),
|
|
704
|
+
mutations: (mutation) => ({ patch: mutation.patch() }),
|
|
705
|
+
});
|
|
706
|
+
const { jobs_by_press_week: series, jobs_by_press_week_totals: summary } = rec.indexes;
|
|
707
|
+
const patch = rec.mutations.patch;
|
|
708
|
+
const assembled = package_('summary_writes', '1.0.0', rec).records.jobs;
|
|
588
709
|
const scheduled = (title, start, end) => decodeJob(encodeJob({
|
|
589
710
|
press: 'P-1001', crews: new SortedSet([], keyOrder), state: 'confirmed', start: some(at(start)), end: some(at(end)), title,
|
|
590
711
|
}));
|
|
@@ -610,11 +731,11 @@ describe('series and summary indexes — through a write and a rebuild', () => {
|
|
|
610
731
|
added.set('W-0004', scheduled('Store flyers', '2026-10-08T06:00:00.000', '2026-10-08T16:00:00.000'));
|
|
611
732
|
const add = of(summary.name, written(assembled, patch, before, added));
|
|
612
733
|
assert.equal(add.length, 1, 'two new jobs in one week on one press are one change');
|
|
613
|
-
assertEast(StructType({ ik: summary.keyType, k: NullType }), add[0].key, { ik: {
|
|
734
|
+
assertEast(StructType({ ik: summary.keyType, k: NullType }), add[0].key, { ik: { on: {}, key: 'P-1001', tile: at('2026-10-05T00:00:00.000') }, k: null }, 'under their press and week');
|
|
614
735
|
assertEast(RecordSummaryOpType, add[0].op, variant('add', { count: 2n, ms: 15n * HOUR }), 'counting both, and their hours');
|
|
615
736
|
});
|
|
616
737
|
it('sums a build split into pieces, in any order, to the totals one piece sums', () => {
|
|
617
|
-
const def =
|
|
738
|
+
const def = jobSummary('jobs_by_press_week_totals', { key: 'press', from: 'start', to: 'end', tile: 'week' });
|
|
618
739
|
const rows = seededJobs();
|
|
619
740
|
const entries = [...rows];
|
|
620
741
|
const piece = (from, to) => new SortedMap(entries.slice(from, to), keyOrder);
|
|
@@ -628,12 +749,12 @@ describe('series and summary indexes — through a write and a rebuild', () => {
|
|
|
628
749
|
it('refuses a key\'s totals summed past the largest Integer, naming the summary, the key and a finer tile, rather than wrap', () => {
|
|
629
750
|
// East's Integer addition wraps, so a build summing past the largest
|
|
630
751
|
// Integer stored a total below none, which no write could then add to.
|
|
631
|
-
const def =
|
|
752
|
+
const def = jobSummary('jobs_by_press_year_totals', { key: 'press', from: 'start', to: 'end', tile: 'year' });
|
|
632
753
|
const merge = summaryMergeProgram(def).compile([]);
|
|
633
|
-
const entry = { ik: {
|
|
754
|
+
const entry = { ik: { on: {}, key: 'P-1001', tile: at('2026-01-01T00:00:00.000') }, k: null };
|
|
634
755
|
const most = (1n << 63n) - 1n;
|
|
635
756
|
assertEast(RecordSummaryTotalsType, merge(entry, { count: 2n, ms: most - 10n }, { count: 1n, ms: 10n }), { count: 3n, ms: most }, 'a sum at the largest Integer is a total');
|
|
636
|
-
const past = /^jobs_by_press_year_totals: the totals under \(ik=\(
|
|
757
|
+
const past = /^jobs_by_press_year_totals: the totals under \(ik=\(on=\(\), key="P-1001", tile=2026-01-01T00:00:00\.000\), k=null\) sum past the largest Integer: declare a finer tile, whose totals are smaller/;
|
|
637
758
|
assert.throws(() => merge(entry, { count: 2n, ms: most - 10n }, { count: 1n, ms: 11n }), past, 'the time they cover');
|
|
638
759
|
assert.throws(() => merge(entry, { count: most, ms: 0n }, { count: 1n, ms: 0n }), past, 'the rows touching it');
|
|
639
760
|
});
|