@jam-overture/loom 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/application/application.d.ts +109 -0
- package/dist/application/application.js +97 -0
- package/dist/application/memory.d.ts +20 -0
- package/dist/application/memory.js +79 -0
- package/dist/application/store.d.ts +101 -0
- package/dist/application/store.js +25 -0
- package/dist/audience/audience.d.ts +36 -0
- package/dist/audience/audience.js +41 -0
- package/dist/cli/templates.js +19 -0
- package/dist/data/plan.js +0 -0
- package/dist/data/resolution.d.ts +23 -1
- package/dist/data/resolve.d.ts +30 -3
- package/dist/data/resolve.js +11 -3
- package/dist/ids.d.ts +10 -0
- package/dist/ids.js +11 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/patch.d.ts +54 -0
- package/dist/patch.js +44 -0
- package/dist/project/closing.d.ts +51 -0
- package/dist/project/closing.js +53 -0
- package/dist/project/memory.d.ts +20 -0
- package/dist/project/memory.js +97 -0
- package/dist/project/project.d.ts +90 -0
- package/dist/project/project.js +91 -0
- package/dist/project/store.d.ts +135 -0
- package/dist/project/store.js +41 -0
- package/dist/registered.d.ts +64 -0
- package/dist/registered.js +118 -0
- package/dist/render/behaviour-adjust.d.ts +11 -19
- package/dist/render/behaviour-adjust.js +75 -21
- package/dist/render/behaviour-present.d.ts +8 -0
- package/dist/render/behaviour-present.js +57 -6
- package/dist/render/behaviour.d.ts +98 -17
- package/dist/render/behaviour.js +91 -26
- package/dist/render/control-name.d.ts +68 -0
- package/dist/render/control-name.js +37 -0
- package/dist/render/diagnostics.d.ts +72 -0
- package/dist/render/diagnostics.js +7 -0
- package/dist/render/index.d.ts +2 -0
- package/dist/render/index.js +2 -0
- package/dist/render/reads.d.ts +11 -0
- package/dist/render/reads.js +12 -1
- package/dist/render/render.js +102 -7
- package/dist/render/slots.d.ts +52 -0
- package/dist/render/slots.js +24 -0
- package/dist/render/theme.d.ts +54 -1
- package/dist/render/theme.js +23 -1
- package/dist/render/unshown.d.ts +152 -0
- package/dist/render/unshown.js +80 -0
- package/dist/runtime/analysis.d.ts +94 -9
- package/dist/runtime/analysis.js +54 -9
- package/dist/runtime/assessment.d.ts +36 -2
- package/dist/runtime/assessment.js +27 -2
- package/dist/runtime/checks.d.ts +148 -0
- package/dist/runtime/checks.js +112 -0
- package/dist/runtime/disposition.d.ts +96 -0
- package/dist/runtime/disposition.js +46 -0
- package/dist/runtime/gate.js +22 -0
- package/dist/runtime/index.d.ts +3 -0
- package/dist/runtime/index.js +3 -0
- package/dist/runtime/irreversibility.d.ts +64 -0
- package/dist/runtime/irreversibility.js +45 -0
- package/dist/runtime/pipeline.d.ts +43 -0
- package/dist/runtime/pipeline.js +10 -2
- package/dist/runtime/policy-change.d.ts +93 -0
- package/dist/runtime/policy-change.js +299 -0
- package/dist/runtime/policy-log.d.ts +406 -0
- package/dist/runtime/policy-log.js +285 -0
- package/dist/runtime/reversibility.d.ts +11 -9
- package/dist/runtime/stakes.d.ts +129 -1
- package/dist/runtime/stakes.js +240 -26
- package/dist/runtime/vocabulary.d.ts +164 -7
- package/dist/runtime/vocabulary.js +181 -8
- package/dist/sdk/audit.d.ts +174 -3
- package/dist/sdk/audit.js +176 -17
- package/dist/sdk/catalogue.d.ts +9 -1
- package/dist/sdk/conformance.d.ts +37 -3
- package/dist/sdk/conformance.js +25 -4
- package/dist/sdk/definition.d.ts +65 -0
- package/dist/sdk/definition.js +22 -0
- package/dist/sdk/registry.d.ts +29 -2
- package/dist/sdk/registry.js +63 -1
- package/dist/signals/action-change.d.ts +507 -0
- package/dist/signals/action-change.js +265 -0
- package/dist/signals/action.d.ts +331 -0
- package/dist/signals/action.js +182 -0
- package/dist/signals/applied-window.contract.d.ts +23 -0
- package/dist/signals/applied-window.contract.js +160 -0
- package/dist/signals/arriving.d.ts +210 -0
- package/dist/signals/arriving.js +133 -0
- package/dist/signals/audiences.d.ts +528 -0
- package/dist/signals/audiences.js +255 -0
- package/dist/signals/broadcast.d.ts +8 -2
- package/dist/signals/broadcast.js +58 -8
- package/dist/signals/change.d.ts +378 -0
- package/dist/signals/change.js +327 -0
- package/dist/signals/collect.d.ts +41 -0
- package/dist/signals/collect.js +88 -7
- package/dist/signals/copy-change.d.ts +553 -0
- package/dist/signals/copy-change.js +377 -0
- package/dist/signals/copy.d.ts +337 -0
- package/dist/signals/copy.js +211 -0
- package/dist/signals/counters.d.ts +46 -0
- package/dist/signals/counters.js +102 -0
- package/dist/signals/deliver.d.ts +23 -4
- package/dist/signals/deliver.js +34 -6
- package/dist/signals/deployment-change.d.ts +371 -0
- package/dist/signals/deployment-change.js +268 -0
- package/dist/signals/deployment.d.ts +265 -0
- package/dist/signals/deployment.js +152 -0
- package/dist/signals/door.d.ts +92 -0
- package/dist/signals/door.js +53 -0
- package/dist/signals/fold.d.ts +10 -0
- package/dist/signals/fold.js +5 -1
- package/dist/signals/form-action.d.ts +302 -0
- package/dist/signals/form-action.js +169 -0
- package/dist/signals/form-copy.d.ts +523 -0
- package/dist/signals/form-copy.js +346 -0
- package/dist/signals/forms.d.ts +247 -0
- package/dist/signals/forms.js +147 -0
- package/dist/signals/funnel-change.d.ts +548 -0
- package/dist/signals/funnel-change.js +361 -0
- package/dist/signals/funnel.d.ts +532 -0
- package/dist/signals/funnel.js +216 -0
- package/dist/signals/health.d.ts +497 -0
- package/dist/signals/health.js +361 -0
- package/dist/signals/index.d.ts +41 -0
- package/dist/signals/index.js +41 -0
- package/dist/signals/ingest.d.ts +56 -1
- package/dist/signals/ingest.js +91 -1
- package/dist/signals/journal.d.ts +11 -0
- package/dist/signals/kinds.d.ts +8 -6
- package/dist/signals/kinds.js +14 -6
- package/dist/signals/library-action.d.ts +430 -0
- package/dist/signals/library-action.js +336 -0
- package/dist/signals/library-change.d.ts +477 -0
- package/dist/signals/library-change.js +335 -0
- package/dist/signals/library-copy-change.d.ts +498 -0
- package/dist/signals/library-copy-change.js +476 -0
- package/dist/signals/library-pace.d.ts +319 -0
- package/dist/signals/library-pace.js +305 -0
- package/dist/signals/library-reach-change.d.ts +636 -0
- package/dist/signals/library-reach-change.js +534 -0
- package/dist/signals/library-reach.d.ts +377 -0
- package/dist/signals/library-reach.js +227 -0
- package/dist/signals/library-word-reach-change.d.ts +567 -0
- package/dist/signals/library-word-reach-change.js +568 -0
- package/dist/signals/library.d.ts +306 -0
- package/dist/signals/library.js +178 -0
- package/dist/signals/memory.d.ts +9 -0
- package/dist/signals/memory.js +105 -14
- package/dist/signals/migrate.d.ts +17 -2
- package/dist/signals/migrate.js +122 -5
- package/dist/signals/notice.d.ts +334 -0
- package/dist/signals/notice.js +228 -0
- package/dist/signals/pace-change.d.ts +501 -0
- package/dist/signals/pace-change.js +310 -0
- package/dist/signals/pace.d.ts +296 -0
- package/dist/signals/pace.js +291 -0
- package/dist/signals/page-views.d.ts +365 -0
- package/dist/signals/page-views.js +218 -0
- package/dist/signals/parts.d.ts +344 -0
- package/dist/signals/parts.js +273 -0
- package/dist/signals/postgres.d.ts +16 -2
- package/dist/signals/postgres.js +390 -87
- package/dist/signals/progress.d.ts +212 -0
- package/dist/signals/progress.js +150 -0
- package/dist/signals/ratios.d.ts +108 -0
- package/dist/signals/ratios.js +40 -0
- package/dist/signals/reach.d.ts +309 -0
- package/dist/signals/reach.js +93 -0
- package/dist/signals/readable.d.ts +34 -0
- package/dist/signals/readable.js +34 -0
- package/dist/signals/readership.d.ts +381 -0
- package/dist/signals/readership.js +308 -0
- package/dist/signals/region-pages.d.ts +173 -0
- package/dist/signals/region-pages.js +62 -0
- package/dist/signals/region.d.ts +287 -0
- package/dist/signals/region.js +198 -0
- package/dist/signals/retention.d.ts +141 -0
- package/dist/signals/retention.js +58 -0
- package/dist/signals/rollup.d.ts +67 -3
- package/dist/signals/rollup.js +0 -0
- package/dist/signals/schema.d.ts +432 -1
- package/dist/signals/schema.js +157 -3
- package/dist/signals/signal.d.ts +237 -11
- package/dist/signals/signal.js +70 -10
- package/dist/signals/silence-census.d.ts +205 -0
- package/dist/signals/silence-census.js +87 -0
- package/dist/signals/silences.d.ts +848 -0
- package/dist/signals/silences.js +753 -0
- package/dist/signals/tally.d.ts +140 -11
- package/dist/signals/window-figures.d.ts +148 -0
- package/dist/signals/window-figures.js +42 -0
- package/dist/signals/window.d.ts +866 -0
- package/dist/signals/window.js +693 -0
- package/dist/signals/words.d.ts +24 -0
- package/dist/signals/words.js +24 -0
- package/dist/store/index.d.ts +19 -0
- package/dist/store/index.js +19 -0
- package/dist/store/memory.d.ts +2 -1
- package/dist/store/memory.js +48 -12
- package/dist/store/migrate.d.ts +80 -0
- package/dist/store/migrate.js +259 -7
- package/dist/store/postgres-applications.d.ts +4 -0
- package/dist/store/postgres-applications.js +197 -0
- package/dist/store/postgres-holds.d.ts +10 -1
- package/dist/store/postgres-holds.js +116 -101
- package/dist/store/postgres-policy-log.d.ts +14 -0
- package/dist/store/postgres-policy-log.js +240 -0
- package/dist/store/postgres-projects.d.ts +4 -0
- package/dist/store/postgres-projects.js +217 -0
- package/dist/store/postgres.d.ts +16 -1
- package/dist/store/postgres.js +59 -9
- package/dist/store/replay.d.ts +102 -1
- package/dist/store/replay.js +190 -19
- package/dist/store/reseed.d.ts +238 -0
- package/dist/store/reseed.js +308 -0
- package/dist/store/schema.d.ts +450 -2
- package/dist/store/schema.js +141 -5
- package/dist/store/store.d.ts +29 -6
- package/dist/submit/resolve.js +2 -1
- package/dist/telemetry/calibration.d.ts +25 -0
- package/dist/telemetry/calibration.js +27 -1
- package/dist/telemetry/event.d.ts +391 -33
- package/dist/telemetry/event.js +84 -20
- package/dist/telemetry/index.d.ts +1 -0
- package/dist/telemetry/index.js +1 -0
- package/dist/telemetry/journal.d.ts +72 -3
- package/dist/telemetry/journal.js +9 -0
- package/dist/telemetry/lookup.d.ts +27 -0
- package/dist/telemetry/lookup.js +18 -0
- package/dist/telemetry/memory.js +23 -0
- package/dist/telemetry/migrate.js +22 -1
- package/dist/telemetry/postgres.d.ts +10 -1
- package/dist/telemetry/postgres.js +172 -90
- package/dist/telemetry/remeasure.d.ts +78 -0
- package/dist/telemetry/remeasure.js +83 -0
- package/dist/telemetry/retention.d.ts +2 -2
- package/dist/telemetry/schema.d.ts +17 -0
- package/dist/telemetry/schema.js +27 -1
- package/dist/telemetry/sink.d.ts +2 -2
- package/dist/testing/application-contract.d.ts +14 -0
- package/dist/testing/application-contract.js +270 -0
- package/dist/testing/contracts.d.ts +12 -7
- package/dist/testing/contracts.js +12 -7
- package/dist/testing/definitions.d.ts +78 -0
- package/dist/testing/definitions.js +134 -9
- package/dist/testing/doubles.d.ts +103 -0
- package/dist/testing/doubles.js +143 -0
- package/dist/testing/index.d.ts +2 -2
- package/dist/testing/index.js +2 -2
- package/dist/testing/journal-contract.js +140 -2
- package/dist/testing/model-contract.d.ts +110 -0
- package/dist/testing/model-contract.js +150 -0
- package/dist/testing/policy-log-contract.d.ts +26 -0
- package/dist/testing/policy-log-contract.js +344 -0
- package/dist/testing/project-contract.d.ts +14 -0
- package/dist/testing/project-contract.js +266 -0
- package/dist/testing/reader-signal-contract.d.ts +27 -2
- package/dist/testing/reader-signal-contract.js +475 -5
- package/dist/testing/store-contract.d.ts +7 -1
- package/dist/testing/store-contract.js +84 -3
- package/dist/theme/apply.d.ts +20 -1
- package/dist/theme/apply.js +5 -3
- package/dist/theme/derive.d.ts +22 -0
- package/dist/theme/derive.js +54 -1
- package/dist/theme/library.js +1 -1
- package/dist/theme/measure.d.ts +34 -0
- package/dist/theme/measure.js +30 -1
- package/dist/theme/palettes.js +7 -7
- package/dist/theme/ramp.d.ts +64 -0
- package/dist/theme/ramp.js +114 -0
- package/dist/theme/registry.d.ts +9 -0
- package/dist/theme/registry.js +11 -1
- package/dist/theme/separation.d.ts +97 -3
- package/dist/theme/separation.js +75 -0
- package/dist/tree/compare.d.ts +9 -0
- package/dist/tree/compare.js +18 -0
- package/dist/write/computed.d.ts +60 -0
- package/dist/write/computed.js +61 -0
- package/dist/write/held.d.ts +59 -0
- package/dist/write/index.d.ts +5 -2
- package/dist/write/index.js +5 -2
- package/dist/write/reseed.d.ts +151 -0
- package/dist/write/reseed.js +184 -0
- package/dist/write/revert.js +2 -16
- package/package.json +98 -19
|
@@ -0,0 +1,693 @@
|
|
|
1
|
+
import { everyMemberOf } from "../closed-set.js";
|
|
2
|
+
import { ok } from "../result.js";
|
|
3
|
+
import { audiencesIn, formKeyOf, formOf, inFormOrder, readingKeyOf, } from "./audiences.js";
|
|
4
|
+
import { pageReadingOf } from "./parts.js";
|
|
5
|
+
import { regionReadingOf, } from "./region.js";
|
|
6
|
+
/**
|
|
7
|
+
* Read one window from the stores, with one scope rather than four.
|
|
8
|
+
*
|
|
9
|
+
* The four reads are independent and are made together. The first failure is
|
|
10
|
+
* the answer: a window half of whose rows arrived is not a narrower window, it
|
|
11
|
+
* is a reading whose every rate has a denominator from one read and a numerator
|
|
12
|
+
* from another, and the figures would look plausible.
|
|
13
|
+
*
|
|
14
|
+
* The request is the stores' own {@link TallyReadRequest}, passed through
|
|
15
|
+
* unchanged to each of them, so scoping a screen to one page, one revision or
|
|
16
|
+
* one audience is the one argument it already was.
|
|
17
|
+
*/
|
|
18
|
+
export const readReaderWindow = async (sources, request) => {
|
|
19
|
+
const [tallies, funnels, pageViews, regions] = await Promise.all([
|
|
20
|
+
sources.tallies.tallies(request),
|
|
21
|
+
sources.tallies.funnels(request),
|
|
22
|
+
sources.tallies.pageViews(request),
|
|
23
|
+
sources.regions?.regions(request),
|
|
24
|
+
]);
|
|
25
|
+
if (!tallies.ok)
|
|
26
|
+
return tallies;
|
|
27
|
+
if (!funnels.ok)
|
|
28
|
+
return funnels;
|
|
29
|
+
if (!pageViews.ok)
|
|
30
|
+
return pageViews;
|
|
31
|
+
if (regions !== undefined && !regions.ok)
|
|
32
|
+
return regions;
|
|
33
|
+
return ok({
|
|
34
|
+
tallies: tallies.value,
|
|
35
|
+
funnels: funnels.value,
|
|
36
|
+
pageViews: pageViews.value,
|
|
37
|
+
regions: regions?.value,
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
const revisionKeyOf = (where) => `${where.treeId}\u0000${where.revision}`;
|
|
41
|
+
const inRevisionOrder = (one, other) => one.treeId.localeCompare(other.treeId) || one.revision - other.revision;
|
|
42
|
+
/**
|
|
43
|
+
* Rows filed under each revision, in one pass over them.
|
|
44
|
+
*
|
|
45
|
+
* A pass per revision would be a walk of the whole window per page a deployment
|
|
46
|
+
* has, which is the quadratic shape rule 4 holds this subsystem to — the ledger
|
|
47
|
+
* was that once and a 6,000-node page took 314 ms. A window is the nodes of
|
|
48
|
+
* every revision a deployment keeps counters for, so the factor here is the
|
|
49
|
+
* number of pages and the input is already the largest thing in the subsystem.
|
|
50
|
+
*/
|
|
51
|
+
const byRevision = (rows) => {
|
|
52
|
+
const filed = new Map();
|
|
53
|
+
for (const row of rows) {
|
|
54
|
+
const key = revisionKeyOf(row);
|
|
55
|
+
const held = filed.get(key);
|
|
56
|
+
if (held === undefined)
|
|
57
|
+
filed.set(key, [row]);
|
|
58
|
+
else
|
|
59
|
+
held.push(row);
|
|
60
|
+
}
|
|
61
|
+
return filed;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Every revision the window's rows name, deduplicated and in a stable order.
|
|
65
|
+
*
|
|
66
|
+
* **Taken over all four row sets and not only the counters.** A revision whose
|
|
67
|
+
* door opened and whose window no rollup has folded yet has page view rows and
|
|
68
|
+
* no tallies, and it is a page a deployment most wants to see rather than one
|
|
69
|
+
* to leave out: it is the difference between *nobody read this* and *nothing
|
|
70
|
+
* has counted this yet*, which the reach reading publishes as `uncounted` and
|
|
71
|
+
* can only publish about a revision it was handed.
|
|
72
|
+
*
|
|
73
|
+
* The audience is deliberately not part of this. A tree is one tree at one
|
|
74
|
+
* revision however many forms of it are served — two forms are the deltas an
|
|
75
|
+
* audience earns over one base (0263) — so asking for a tree per form would be
|
|
76
|
+
* asking the caller for the same tree twice.
|
|
77
|
+
*/
|
|
78
|
+
export const revisionsIn = (window) => {
|
|
79
|
+
const found = new Map();
|
|
80
|
+
const note = (rows) => {
|
|
81
|
+
for (const row of rows) {
|
|
82
|
+
const where = { treeId: row.treeId, revision: row.revision };
|
|
83
|
+
const key = revisionKeyOf(where);
|
|
84
|
+
if (!found.has(key))
|
|
85
|
+
found.set(key, where);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
note(window.tallies);
|
|
89
|
+
note(window.funnels);
|
|
90
|
+
note(window.pageViews);
|
|
91
|
+
note(window.regions ?? []);
|
|
92
|
+
return [...found.values()].sort(inRevisionOrder);
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* The trees a caller already holds, as a source.
|
|
96
|
+
*
|
|
97
|
+
* Keyed by tree **and** revision, because two revisions of one page are two
|
|
98
|
+
* trees to this join and keying by the page would answer one of them for both.
|
|
99
|
+
* The first of two trees at one revision wins and the second is ignored: they
|
|
100
|
+
* disagree about what a revision is, nothing here can say which is right, and
|
|
101
|
+
* a silent last-wins would make the answer depend on the order a store
|
|
102
|
+
* returned.
|
|
103
|
+
*/
|
|
104
|
+
export const treesIn = (trees) => {
|
|
105
|
+
const held = new Map();
|
|
106
|
+
for (const tree of trees) {
|
|
107
|
+
const key = revisionKeyOf(tree);
|
|
108
|
+
if (!held.has(key))
|
|
109
|
+
held.set(key, tree);
|
|
110
|
+
}
|
|
111
|
+
return { treeFor: (where) => held.get(revisionKeyOf(where)) };
|
|
112
|
+
};
|
|
113
|
+
/** The closed set, for a surface accounting for every revision it cannot draw. */
|
|
114
|
+
export const UNJOINED_CAUSES = everyMemberOf()([
|
|
115
|
+
"no-tree",
|
|
116
|
+
"mismatched",
|
|
117
|
+
]);
|
|
118
|
+
/** One line per cause, for a surface saying why a page is not on the screen. */
|
|
119
|
+
export const describeUnjoinedCause = (cause) => {
|
|
120
|
+
switch (cause) {
|
|
121
|
+
case "no-tree":
|
|
122
|
+
return "there are counters for this revision and no tree to read them against";
|
|
123
|
+
case "mismatched":
|
|
124
|
+
return "the tree offered for this revision was of another one, so the counters were not read";
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* The rows of a window with the repeats of one bucket dropped, which is the one
|
|
129
|
+
* thing every reading of a region row set has to do first.
|
|
130
|
+
*
|
|
131
|
+
* A store keeps one row per tree, revision, form and region, so this cannot
|
|
132
|
+
* come out of one read: it is a caller concatenating two windows whose counts
|
|
133
|
+
* are already running totals. **Adding them doubles a bucket**, which is the one
|
|
134
|
+
* error in this subsystem that cannot be undone afterwards (0158), and a doubled
|
|
135
|
+
* bucket is worse than a wrong number — it clears a floor it should not have
|
|
136
|
+
* cleared, so a place with too few readers to name gets named.
|
|
137
|
+
*
|
|
138
|
+
* Published because it is used twice and was written once. {@link
|
|
139
|
+
* WindowRegionReadings} folds it into the maps it builds; a reading that takes
|
|
140
|
+
* the **rows** rather than the maps — which is `regionPagesOf`, because a
|
|
141
|
+
* breakdown by page needs the cells and a map does not hold them — has to apply
|
|
142
|
+
* the same rule to the same rows or the two answers disagree about one window.
|
|
143
|
+
* Two spellings of one rule that agree today are a thing this subsystem has
|
|
144
|
+
* been bitten by before (0265).
|
|
145
|
+
*
|
|
146
|
+
* Linear in the rows, with one set.
|
|
147
|
+
*/
|
|
148
|
+
export const distinctRegionRows = (rows) => {
|
|
149
|
+
const kept = [];
|
|
150
|
+
const seen = new Set();
|
|
151
|
+
let duplicated = 0;
|
|
152
|
+
for (const row of rows) {
|
|
153
|
+
const key = `${revisionKeyOf(row)}\u0000${row.audienceId ?? ""}\u0000${row.region}`;
|
|
154
|
+
if (seen.has(key)) {
|
|
155
|
+
duplicated += 1;
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
seen.add(key);
|
|
159
|
+
kept.push(row);
|
|
160
|
+
}
|
|
161
|
+
return { kept, duplicated };
|
|
162
|
+
};
|
|
163
|
+
const regionGroupsOf = (rows) => {
|
|
164
|
+
const groups = new Map();
|
|
165
|
+
const { kept, duplicated } = distinctRegionRows(rows);
|
|
166
|
+
for (const row of kept) {
|
|
167
|
+
const key = `${revisionKeyOf(row)}\u0000${row.audienceId ?? ""}`;
|
|
168
|
+
const held = groups.get(key);
|
|
169
|
+
if (held === undefined) {
|
|
170
|
+
groups.set(key, {
|
|
171
|
+
where: { treeId: row.treeId, revision: row.revision },
|
|
172
|
+
audienceId: row.audienceId ?? null,
|
|
173
|
+
rows: [row],
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
else
|
|
177
|
+
held.rows.push(row);
|
|
178
|
+
}
|
|
179
|
+
return { groups: [...groups.values()], kept, duplicated };
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* Nulls first, then by name, so two reads of one window are in one order.
|
|
183
|
+
*
|
|
184
|
+
* Orders **audiences** and not forms, which is what it is named for now: the
|
|
185
|
+
* published rule that orders forms is {@link inFormOrder}, this file imports it
|
|
186
|
+
* for the pairs below, and the two cannot carry one name. A form is a tree and
|
|
187
|
+
* an audience (0293) and this takes neither tree, so the old spelling claimed a
|
|
188
|
+
* rule it was not.
|
|
189
|
+
*/
|
|
190
|
+
const inAudienceOrder = (one, other) => {
|
|
191
|
+
if (one === other)
|
|
192
|
+
return 0;
|
|
193
|
+
if (one === null)
|
|
194
|
+
return -1;
|
|
195
|
+
if (other === null)
|
|
196
|
+
return 1;
|
|
197
|
+
return one.localeCompare(other);
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* Read a window's region rows into the maps they hold.
|
|
201
|
+
*
|
|
202
|
+
* The floor is handed in rather than read, which is the line §7 draws: it is
|
|
203
|
+
* per-deployment configuration, `regionFloorOf` is raise-only, and a rung that
|
|
204
|
+
* went looking for it would be a reading path that depends on a configuration
|
|
205
|
+
* store. What this closes is the other half — a caller that passed **no** floor
|
|
206
|
+
* got the default rather than the deployment's, and nothing in the types said
|
|
207
|
+
* so.
|
|
208
|
+
*/
|
|
209
|
+
const windowRegionsOf = (rows, options) => {
|
|
210
|
+
const { groups, kept, duplicated } = regionGroupsOf(rows);
|
|
211
|
+
const maps = groups.map(({ where, audienceId, rows: held }) => ({
|
|
212
|
+
...where,
|
|
213
|
+
audienceId,
|
|
214
|
+
reading: { ...regionReadingOf(held, options), audienceId },
|
|
215
|
+
}));
|
|
216
|
+
return {
|
|
217
|
+
maps: maps.sort((one, other) => inRevisionOrder(one, other) || inAudienceOrder(one.audienceId, other.audienceId)),
|
|
218
|
+
readership: regionReadingOf(kept, options),
|
|
219
|
+
duplicated,
|
|
220
|
+
};
|
|
221
|
+
};
|
|
222
|
+
/**
|
|
223
|
+
* Join a window of counters to the pages it is about.
|
|
224
|
+
*
|
|
225
|
+
* **One reading per form, rather than one per revision read as neither.** A
|
|
226
|
+
* window holding two audiences at one revision is ambiguous to the join
|
|
227
|
+
* underneath — it reads neither, names both, and `health.ts` reports the fault
|
|
228
|
+
* (0290, 0300) — and that refusal is right for a caller that was handed a
|
|
229
|
+
* window and asked nothing. Here the question is *what does this window hold*,
|
|
230
|
+
* and the answer is both forms: the ambiguity was never in the rows, which say
|
|
231
|
+
* which form each belongs to, it was in asking one question of two
|
|
232
|
+
* populations. So the split is made rather than refused, and each form's
|
|
233
|
+
* reading is of its own readers.
|
|
234
|
+
*
|
|
235
|
+
* **The region maps are joined beside the pages and not under them.** They are
|
|
236
|
+
* maps of arrivals rather than of nodes, so they need no tree: a revision whose
|
|
237
|
+
* tree is gone is `unjoined` for its counters and still has its readers
|
|
238
|
+
* counted. See {@link WindowReadings.regions}.
|
|
239
|
+
*
|
|
240
|
+
* **Each reading is handed its revision's rows and told which form to read.**
|
|
241
|
+
* Not the window — a reading handed the whole of one would count every other
|
|
242
|
+
* page's rows as `foreign`, which is exactly what that field exists to report —
|
|
243
|
+
* and not one form's rows either, because then a reading could not say that the
|
|
244
|
+
* page has another form at all. `foreign` is therefore nought on every reading
|
|
245
|
+
* this produces, `audiences` is what the revision really holds, and
|
|
246
|
+
* `otherAudience` is the other form's rows, counted apart and not read.
|
|
247
|
+
*/
|
|
248
|
+
export const windowReadingsOf = (window, trees, declarations, options = {}) => {
|
|
249
|
+
const pages = [];
|
|
250
|
+
const unjoined = [];
|
|
251
|
+
const counters = byRevision(window.tallies);
|
|
252
|
+
const funnels = byRevision(window.funnels);
|
|
253
|
+
const doors = byRevision(window.pageViews);
|
|
254
|
+
const regions = byRevision(window.regions ?? []);
|
|
255
|
+
for (const where of revisionsIn(window)) {
|
|
256
|
+
const key = revisionKeyOf(where);
|
|
257
|
+
const here = counters.get(key) ?? [];
|
|
258
|
+
const tree = trees.treeFor(where);
|
|
259
|
+
if (tree === undefined) {
|
|
260
|
+
unjoined.push({ ...where, cause: "no-tree", tallies: here.length });
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
if (revisionKeyOf(tree) !== key) {
|
|
264
|
+
unjoined.push({ ...where, cause: "mismatched", tallies: here.length });
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* The forms this revision was served in, taken over every row set rather
|
|
269
|
+
* than over the counters alone. A form whose readers arrived and whose
|
|
270
|
+
* window has not been folded is named by a door row and by nothing else,
|
|
271
|
+
* and leaving it out would publish one form's readers as the page's, which
|
|
272
|
+
* is the mistake the region map had one rung further up (0290).
|
|
273
|
+
*/
|
|
274
|
+
const named = [
|
|
275
|
+
...here,
|
|
276
|
+
...(funnels.get(key) ?? []),
|
|
277
|
+
...(doors.get(key) ?? []),
|
|
278
|
+
...(regions.get(key) ?? []),
|
|
279
|
+
];
|
|
280
|
+
const forms = audiencesIn(named);
|
|
281
|
+
/**
|
|
282
|
+
* No row named a form, so the window is one population by construction and
|
|
283
|
+
* is read whole — which is every window written before the column existed
|
|
284
|
+
* (0284) and every one a test builds by hand. Asking for `aud_everyone`
|
|
285
|
+
* here would assert what no row said.
|
|
286
|
+
*/
|
|
287
|
+
if (forms.length === 0) {
|
|
288
|
+
pages.push(pageReadingOf(tree, here, declarations));
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
for (const form of forms)
|
|
292
|
+
pages.push(pageReadingOf(tree, here, declarations, form));
|
|
293
|
+
}
|
|
294
|
+
return {
|
|
295
|
+
pages,
|
|
296
|
+
unjoined,
|
|
297
|
+
regions: window.regions === undefined ? undefined : windowRegionsOf(window.regions, options),
|
|
298
|
+
};
|
|
299
|
+
};
|
|
300
|
+
/**
|
|
301
|
+
* Pair a window's readings into the before-and-afters the comparisons take.
|
|
302
|
+
*
|
|
303
|
+
* The second step of this rung and the one it left undone. Nine comparisons in
|
|
304
|
+
* this subsystem take two sides — `readingChangeOf`, `copyChangeOf`,
|
|
305
|
+
* `paceChangeOf`, `actionChangeOf`, `funnelChangeOf` and the four library
|
|
306
|
+
* comparisons — and not one of them could be reached from a store, because
|
|
307
|
+
* nothing turned a window into a pair. `deploymentChangeOf` says so in its own
|
|
308
|
+
* words: *a caller with two windows of counters reads each page's parts, then
|
|
309
|
+
* its progress, then its comparison, then this.* The pairing was the step with
|
|
310
|
+
* no owner, and a caller writing it is a caller writing 0293 again.
|
|
311
|
+
*
|
|
312
|
+
* After this the deployment-wide order over what a change did is three lines:
|
|
313
|
+
*
|
|
314
|
+
* ```ts
|
|
315
|
+
* const { pages } = windowReadingsOf(window, treesIn(trees), registry)
|
|
316
|
+
* const { pairs } = windowPairsOf(pages)
|
|
317
|
+
* const order = deploymentChangeOf(
|
|
318
|
+
* pairs.map(({ was, now }) => readingChangeOf(was, now)),
|
|
319
|
+
* window.pageViews
|
|
320
|
+
* )
|
|
321
|
+
* ```
|
|
322
|
+
*
|
|
323
|
+
* ## One pair per form, and it is the latest two revisions
|
|
324
|
+
*
|
|
325
|
+
* A form with revisions 3, 5 and 9 in the window has two consecutive pairs in
|
|
326
|
+
* it and this produces one: 5 against 9. Publishing both would make the page
|
|
327
|
+
* unreadable by the only consumer there is — `deploymentChangeOf` gates a form
|
|
328
|
+
* handed two different revision pairs as `ambiguous` and drops it, which is
|
|
329
|
+
* right of it, because *which page did the change hurt most* cannot be answered
|
|
330
|
+
* about a form that changed twice. So every page a deployment published three
|
|
331
|
+
* times inside one window would vanish from the order, and the figure it
|
|
332
|
+
* vanished out of would go on looking right (0158).
|
|
333
|
+
*
|
|
334
|
+
* The latest pair rather than the widest one, for the same reason: 3 against 9
|
|
335
|
+
* is two changes added together and labelled as one, and *what did this change
|
|
336
|
+
* do* is a question about the change that was made. What the window holds below
|
|
337
|
+
* `was` is on the pair as {@link WindowPair.superseded}, so nothing is hidden
|
|
338
|
+
* and an older pair is two readings and one call away.
|
|
339
|
+
*
|
|
340
|
+
* ## Paired by the form rule and nothing else, so no pair here can be refused
|
|
341
|
+
*
|
|
342
|
+
* The grouping is `formKeyOf` (0293), so both sides of every pair are of one
|
|
343
|
+
* tree and one audience by construction. Three of the four states
|
|
344
|
+
* `readingChangeOf` refuses are therefore unreachable from a pair this makes:
|
|
345
|
+
* `different-trees` needs two trees, `different-audiences` needs two named
|
|
346
|
+
* audiences, and `audiences-mixed` needs a side that holds two forms and names
|
|
347
|
+
* none, which is a reading {@link windowReadingsOf} does not produce — it
|
|
348
|
+
* splits a revision serving two forms into one reading each. What is left is
|
|
349
|
+
* `nothing-measured`, which is about the readers rather than about the pairing,
|
|
350
|
+
* and that is the division this rung is for: a comparison that comes back
|
|
351
|
+
* silent from here is silent about a deployment's readers and not about its
|
|
352
|
+
* caller.
|
|
353
|
+
*
|
|
354
|
+
* **The one pair it will not make, which is deliberate.** A deployment that
|
|
355
|
+
* upgraded across 0284 has revisions whose rows name no audience and revisions
|
|
356
|
+
* whose rows name one, and those are two forms under the published rule. So the
|
|
357
|
+
* comparison spanning the upgrade is not produced, and both of its sides are in
|
|
358
|
+
* {@link WindowPairs.unpaired}. It is the pair `crossesAudiences` deliberately
|
|
359
|
+
* allows — unprovable rather than proven alike — and allowing it is not the
|
|
360
|
+
* same as asserting it: nothing in the rows says the two are one population, a
|
|
361
|
+
* rung that paired them would be a tenth spelling of the pairing rule, and the
|
|
362
|
+
* caller who knows its own history makes that comparison in one call, where
|
|
363
|
+
* `audiences` on the result says what it was read across.
|
|
364
|
+
*
|
|
365
|
+
* ## It adds no figure of its own
|
|
366
|
+
*
|
|
367
|
+
* Nothing here counts, divides, sums or withholds, which is the rule the first
|
|
368
|
+
* step of this rung set: it decides **which pairs a window holds** and hands
|
|
369
|
+
* each of them the two readings it is a pair of. Every one of the nine
|
|
370
|
+
* comparisons is one call off a pair.
|
|
371
|
+
*
|
|
372
|
+
* **It does not assemble the two windows the four library comparisons take.**
|
|
373
|
+
* Those compare a whole library before against a whole library after, and a
|
|
374
|
+
* form with one revision cannot be put on a side out of anything here: a page
|
|
375
|
+
* published inside the window belongs to the later one, a page nobody has
|
|
376
|
+
* changed belongs to both, and nothing in the counters tells them apart.
|
|
377
|
+
* {@link windowLibrariesOf} is that step, and it asks the caller — the only
|
|
378
|
+
* party that knows what it published when — rather than guessing, because
|
|
379
|
+
* guessing publishes a page nobody touched as a page gained (0295). What this
|
|
380
|
+
* owes it is the two lists, which is why {@link WindowPairs.unpaired} is
|
|
381
|
+
* published rather than dropped.
|
|
382
|
+
*
|
|
383
|
+
* Linear in the readings but for one sort per form, which is a sort of that
|
|
384
|
+
* form's revisions and not of the window: the window sorted whole would be the
|
|
385
|
+
* shape rule 4 holds this subsystem to, and a deployment's revisions per page
|
|
386
|
+
* are a handful where its pages are not.
|
|
387
|
+
*/
|
|
388
|
+
export const windowPairsOf = (readings) => {
|
|
389
|
+
const forms = new Map();
|
|
390
|
+
const seen = new Set();
|
|
391
|
+
let duplicated = 0;
|
|
392
|
+
for (const reading of readings) {
|
|
393
|
+
const key = readingKeyOf(reading);
|
|
394
|
+
/**
|
|
395
|
+
* The first of two readings of one key wins and the second is counted, for
|
|
396
|
+
* the reason it does in `treesIn`: they disagree about what one reading of
|
|
397
|
+
* one revision is, nothing here can say which is right, and a silent
|
|
398
|
+
* last-wins would make the answer depend on the order a store returned.
|
|
399
|
+
*/
|
|
400
|
+
if (seen.has(key)) {
|
|
401
|
+
duplicated += 1;
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
seen.add(key);
|
|
405
|
+
const form = formKeyOf(reading);
|
|
406
|
+
const held = forms.get(form);
|
|
407
|
+
if (held === undefined)
|
|
408
|
+
forms.set(form, [reading]);
|
|
409
|
+
else
|
|
410
|
+
held.push(reading);
|
|
411
|
+
}
|
|
412
|
+
const pairs = [];
|
|
413
|
+
const unpaired = [];
|
|
414
|
+
for (const held of forms.values()) {
|
|
415
|
+
const inOrder = [...held].sort((one, other) => one.revision - other.revision);
|
|
416
|
+
const now = inOrder.at(-1);
|
|
417
|
+
const was = inOrder.at(-2);
|
|
418
|
+
if (now === undefined)
|
|
419
|
+
continue;
|
|
420
|
+
if (was === undefined) {
|
|
421
|
+
unpaired.push({ ...formOf(now), reading: now });
|
|
422
|
+
continue;
|
|
423
|
+
}
|
|
424
|
+
pairs.push({
|
|
425
|
+
...formOf(now),
|
|
426
|
+
was,
|
|
427
|
+
now,
|
|
428
|
+
superseded: inOrder.slice(0, -2).map((reading) => reading.revision),
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
return {
|
|
432
|
+
pairs: pairs.sort(inFormOrder),
|
|
433
|
+
unpaired: unpaired.sort(inFormOrder),
|
|
434
|
+
duplicated,
|
|
435
|
+
};
|
|
436
|
+
};
|
|
437
|
+
/** The closed set, for a surface accounting for every form it was asked about. */
|
|
438
|
+
export const FORM_PLACINGS = everyMemberOf()([
|
|
439
|
+
"published",
|
|
440
|
+
"withdrawn",
|
|
441
|
+
"unchanged",
|
|
442
|
+
]);
|
|
443
|
+
/** One line per placing, for a surface saying which library a page is in and why. */
|
|
444
|
+
export const describeFormPlacing = (placing) => {
|
|
445
|
+
switch (placing) {
|
|
446
|
+
case "published":
|
|
447
|
+
return "this page was first served inside the window, so only the later library holds it";
|
|
448
|
+
case "withdrawn":
|
|
449
|
+
return "this page stopped being served inside the window, so only the earlier library holds it";
|
|
450
|
+
case "unchanged":
|
|
451
|
+
return "this page was served throughout the window and never republished, so both hold it";
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
/**
|
|
455
|
+
* The placings a caller already holds, as a source.
|
|
456
|
+
*
|
|
457
|
+
* Keyed by the published form rule (0293), so a page served in two forms is
|
|
458
|
+
* placed twice and a caller that placed only one of them has the other
|
|
459
|
+
* reported rather than carried along with it: a page can be published in a
|
|
460
|
+
* second form while its first form stands unchanged, which is the distinction
|
|
461
|
+
* `formsGained` exists for.
|
|
462
|
+
*
|
|
463
|
+
* The first placing of a form wins and the second is ignored, as in
|
|
464
|
+
* {@link treesIn}: two answers disagree about one page, nothing here can say
|
|
465
|
+
* which is right, and a silent last-wins would make the libraries depend on the
|
|
466
|
+
* order a caller's history came back in.
|
|
467
|
+
*/
|
|
468
|
+
export const placingsIn = (placed) => {
|
|
469
|
+
const held = new Map();
|
|
470
|
+
for (const form of placed) {
|
|
471
|
+
const key = formKeyOf(form);
|
|
472
|
+
if (!held.has(key))
|
|
473
|
+
held.set(key, form.placing);
|
|
474
|
+
}
|
|
475
|
+
return { placingFor: (form) => held.get(formKeyOf(form)) };
|
|
476
|
+
};
|
|
477
|
+
/**
|
|
478
|
+
* Assemble a window's pairs into the two libraries the library comparisons
|
|
479
|
+
* take.
|
|
480
|
+
*
|
|
481
|
+
* The third step of this rung, and the one {@link windowPairsOf} named as a gap
|
|
482
|
+
* the day it was built. Five of the nine comparisons take two **readings**, and
|
|
483
|
+
* a pair is one of those; the four library comparisons take two whole
|
|
484
|
+
* **libraries** — every page as it stood before against every page as it stands
|
|
485
|
+
* now — and a window holds both of those too, but not by any arrangement of its
|
|
486
|
+
* pairs alone.
|
|
487
|
+
*
|
|
488
|
+
* After this, every one of the nine is one call off a window:
|
|
489
|
+
*
|
|
490
|
+
* ```ts
|
|
491
|
+
* const { pages } = windowReadingsOf(window, treesIn(trees), registry)
|
|
492
|
+
* const held = windowPairsOf(pages)
|
|
493
|
+
* const { was, now } = windowLibrariesOf(held, window.pageViews, placingsIn(history))
|
|
494
|
+
*
|
|
495
|
+
* const kinds = libraryChangeOf(was.readings, now.readings)
|
|
496
|
+
* const reach = libraryReachChangeOf(was, now)
|
|
497
|
+
* ```
|
|
498
|
+
*
|
|
499
|
+
* ## The one line that composes and is wrong
|
|
500
|
+
*
|
|
501
|
+
* ```ts
|
|
502
|
+
* libraryChangeOf(pairs.map(({ was }) => was), pairs.map(({ now }) => now))
|
|
503
|
+
* ```
|
|
504
|
+
*
|
|
505
|
+
* That type-checks, it runs, and the result does not say what it left out. It
|
|
506
|
+
* drops every form in {@link WindowPairs.unpaired} — which is exactly where **a
|
|
507
|
+
* page published inside the window** lands, because a page published inside the
|
|
508
|
+
* window has one revision in it. So a deployment that published two pages this
|
|
509
|
+
* week reads `pagesGained: 0`, which is the figure `libraryChangeOf` exists to
|
|
510
|
+
* report, beside a `pages` count that looks right.
|
|
511
|
+
*
|
|
512
|
+
* ## So the placing is asked for, and a form nobody can place is named
|
|
513
|
+
*
|
|
514
|
+
* A form with one revision is a page published, a page withdrawn, or a page
|
|
515
|
+
* nobody touched, and the counters cannot tell them apart —
|
|
516
|
+
* `StoredTally.updatedAt` is when the fold ran, not when the page went up. The
|
|
517
|
+
* revision numbers cannot either: a revision number is a count of revisions
|
|
518
|
+
* rather than a date, and a deployment that has pruned old counters has a form
|
|
519
|
+
* at revision 7 with nothing below it.
|
|
520
|
+
*
|
|
521
|
+
* So {@link FormPlacings} is handed in, which is the line §7 draws and the
|
|
522
|
+
* shape the region floor took: hold configuration you were handed rather than
|
|
523
|
+
* configuration you went looking for. A form the source cannot place is in
|
|
524
|
+
* {@link WindowLibraries.unplaced} and on neither side, because **both guesses
|
|
525
|
+
* are assertions** — the later side says a page nobody touched was published,
|
|
526
|
+
* and both sides say a page published this week was always there.
|
|
527
|
+
*
|
|
528
|
+
* Paired forms are never asked about. A form with two revisions in the window
|
|
529
|
+
* has its earlier revision in the earlier library and its later one in the
|
|
530
|
+
* later library, by construction, so there is nothing for a caller to answer
|
|
531
|
+
* and nothing of its answer to ignore.
|
|
532
|
+
*
|
|
533
|
+
* ## Two generations of revisions, which is not two moments
|
|
534
|
+
*
|
|
535
|
+
* The sides are the library at its earlier revisions against the library at its
|
|
536
|
+
* later ones, and `republished` on the comparison is the published count of how
|
|
537
|
+
* many pages that moved. It is **not** a window split in half: an `unchanged`
|
|
538
|
+
* form carries one reading onto both sides, so its views are the window's views
|
|
539
|
+
* on both — the page contributed no change because it was not changed, and
|
|
540
|
+
* `LibraryChange.viewsWas` and `viewsNow` are the floors a reader checks the
|
|
541
|
+
* comparability of two windows against rather than numbers to subtract.
|
|
542
|
+
*
|
|
543
|
+
* One consequence worth stating, because it is a limit rather than a rule: a
|
|
544
|
+
* page published **and** then revised inside one window has two revisions, so it
|
|
545
|
+
* is paired and lands on both sides rather than being counted as a page gained.
|
|
546
|
+
* `pagesGained` is therefore a count of the forms whose only revision is new.
|
|
547
|
+
*
|
|
548
|
+
* ## The rows are the window's own, and both sides read them
|
|
549
|
+
*
|
|
550
|
+
* {@link LibraryWindow.rows} is the whole window of door rows on each side, not
|
|
551
|
+
* a slice of them. Each page's own row is picked out by `pageViewsFor` on the
|
|
552
|
+
* revision and the form the reading names (0290), and the two sides name
|
|
553
|
+
* different revisions, so one array answers both without either side borrowing
|
|
554
|
+
* the other's arrivals.
|
|
555
|
+
*
|
|
556
|
+
* ## It adds no figure of its own
|
|
557
|
+
*
|
|
558
|
+
* Nothing here counts, divides, sums or withholds, which is the rule the first
|
|
559
|
+
* two steps set. It decides **which library each form is in** out of what it was
|
|
560
|
+
* told, and hands each side the readings it holds.
|
|
561
|
+
*
|
|
562
|
+
* Linear in the forms, but for the two sorts that publish them in one order.
|
|
563
|
+
*/
|
|
564
|
+
export const windowLibrariesOf = (held, rows, placings) => {
|
|
565
|
+
const was = [];
|
|
566
|
+
const now = [];
|
|
567
|
+
const unplaced = [];
|
|
568
|
+
const seen = new Set();
|
|
569
|
+
let duplicated = 0;
|
|
570
|
+
const first = (form) => {
|
|
571
|
+
const key = formKeyOf(form);
|
|
572
|
+
if (seen.has(key)) {
|
|
573
|
+
duplicated += 1;
|
|
574
|
+
return false;
|
|
575
|
+
}
|
|
576
|
+
seen.add(key);
|
|
577
|
+
return true;
|
|
578
|
+
};
|
|
579
|
+
for (const pair of held.pairs) {
|
|
580
|
+
if (!first(pair))
|
|
581
|
+
continue;
|
|
582
|
+
was.push(pair.was);
|
|
583
|
+
now.push(pair.now);
|
|
584
|
+
}
|
|
585
|
+
for (const form of held.unpaired) {
|
|
586
|
+
if (!first(form))
|
|
587
|
+
continue;
|
|
588
|
+
const placing = placings.placingFor(form);
|
|
589
|
+
if (placing === undefined) {
|
|
590
|
+
unplaced.push(form);
|
|
591
|
+
continue;
|
|
592
|
+
}
|
|
593
|
+
switch (placing) {
|
|
594
|
+
case "published":
|
|
595
|
+
now.push(form.reading);
|
|
596
|
+
break;
|
|
597
|
+
case "withdrawn":
|
|
598
|
+
was.push(form.reading);
|
|
599
|
+
break;
|
|
600
|
+
case "unchanged":
|
|
601
|
+
was.push(form.reading);
|
|
602
|
+
now.push(form.reading);
|
|
603
|
+
break;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
/**
|
|
607
|
+
* One published order for both sides, rather than pairs first and then the
|
|
608
|
+
* forms a placing put there. The comparisons key their pages by form and do
|
|
609
|
+
* not read the order, so this is for the caller that prints a side.
|
|
610
|
+
*/
|
|
611
|
+
const inOneOrder = (readings) => [...readings].sort((one, other) => inFormOrder(formOf(one), formOf(other)));
|
|
612
|
+
return {
|
|
613
|
+
was: { readings: inOneOrder(was), rows },
|
|
614
|
+
now: { readings: inOneOrder(now), rows },
|
|
615
|
+
unplaced: unplaced.sort(inFormOrder),
|
|
616
|
+
duplicated,
|
|
617
|
+
};
|
|
618
|
+
};
|
|
619
|
+
/**
|
|
620
|
+
* Assemble a window into every subject a reading or a comparison of it takes.
|
|
621
|
+
*
|
|
622
|
+
* The fourth step of this rung and the one that makes the first three a
|
|
623
|
+
* question rather than a recipe. Each of them is published and each is
|
|
624
|
+
* separately useful; what is published nowhere is **the one order they compose
|
|
625
|
+
* in**, and that order is not free.
|
|
626
|
+
*
|
|
627
|
+
* ```ts
|
|
628
|
+
* const { readings, pairs, libraries } = windowAssemblyOf(window, context)
|
|
629
|
+
*
|
|
630
|
+
* const order = deploymentChangeOf(
|
|
631
|
+
* pairs.pairs.map(({ was, now }) => readingChangeOf(was, now)),
|
|
632
|
+
* window.pageViews
|
|
633
|
+
* )
|
|
634
|
+
* const kinds = libraryChangeOf(libraries.was.readings, libraries.now.readings)
|
|
635
|
+
* ```
|
|
636
|
+
*
|
|
637
|
+
* ## What a caller writing those three lines had to get right
|
|
638
|
+
*
|
|
639
|
+
* **The libraries take the pairs that `windowPairsOf` produced**, and the
|
|
640
|
+
* tempting one-liner over `pairs` alone drops every unpaired form — which is
|
|
641
|
+
* where a page published inside the window lands, and `pagesGained` is the
|
|
642
|
+
* figure a library comparison exists to report (0319). **The door rows are the
|
|
643
|
+
* window's whole set on both sides**, not a slice per side, because each page's
|
|
644
|
+
* own row is picked out on the revision and the form its reading names. **And
|
|
645
|
+
* the floor reaches the regions through the readings**, which is the one of the
|
|
646
|
+
* four context fields with no step of its own to be handed to.
|
|
647
|
+
*
|
|
648
|
+
* None of those is hard. All of them are invisible when wrong: the result of
|
|
649
|
+
* getting any of them wrong is a figure that is plausible and a total that goes
|
|
650
|
+
* on looking right, which is the one error in this subsystem that cannot be
|
|
651
|
+
* undone afterwards (0158).
|
|
652
|
+
*
|
|
653
|
+
* ## The two repeats it cannot have, which is the only safety it adds
|
|
654
|
+
*
|
|
655
|
+
* `WindowPairs.duplicated` and `WindowLibraries.duplicated` are **nought from
|
|
656
|
+
* here, by construction.** `windowReadingsOf` never produces two readings of
|
|
657
|
+
* one `readingKeyOf`, and `windowPairsOf` files each form in exactly one of its
|
|
658
|
+
* two lists — so nothing this hands on can put two readings of one form on one
|
|
659
|
+
* side of a library, which is the repeat that makes a page `ambiguous` to
|
|
660
|
+
* `pairedWindowOf` and takes it out of every figure in the comparison while the
|
|
661
|
+
* counts above it look unchanged.
|
|
662
|
+
*
|
|
663
|
+
* Both fields stay published and are carried as they come, because they are not
|
|
664
|
+
* nought for the callers they exist for: a surface that concatenated two
|
|
665
|
+
* windows' readings, or assembled a {@link WindowPairs} of its own, still has
|
|
666
|
+
* them counted. {@link WindowRegionReadings.duplicated} is the one that can be
|
|
667
|
+
* other than nought from here, because a region row repeated under one bucket
|
|
668
|
+
* key is a repeat in the rows a caller was handed rather than one this made.
|
|
669
|
+
*
|
|
670
|
+
* ## It adds no figure, and publishes no total of what was dropped
|
|
671
|
+
*
|
|
672
|
+
* Nothing here counts, divides, sums or withholds — the rule all three steps
|
|
673
|
+
* under it keep. In particular there is deliberately **no one number for what
|
|
674
|
+
* the assembly left out**: the three `duplicated` counts are a count of region
|
|
675
|
+
* rows, a count of readings and a count of forms, and `unjoined`, `unpaired`
|
|
676
|
+
* and `unplaced` are three different reasons a page is absent from three
|
|
677
|
+
* different answers. A sum over them would be a figure in no unit at all, and
|
|
678
|
+
* the shortest way to a screen that reports *4 pages dropped* about one page.
|
|
679
|
+
*
|
|
680
|
+
* Linear in the window, being three linear passes over it.
|
|
681
|
+
*/
|
|
682
|
+
export const windowAssemblyOf = (window, context) => {
|
|
683
|
+
const readings = windowReadingsOf(window, context.trees, context.declarations, {
|
|
684
|
+
floor: context.floor,
|
|
685
|
+
});
|
|
686
|
+
const pairs = windowPairsOf(readings.pages);
|
|
687
|
+
return {
|
|
688
|
+
readings,
|
|
689
|
+
pairs,
|
|
690
|
+
libraries: windowLibrariesOf(pairs, window.pageViews, context.placings),
|
|
691
|
+
};
|
|
692
|
+
};
|
|
693
|
+
//# sourceMappingURL=window.js.map
|