mikser-io 9.21.1 → 9.23.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.
@@ -59,20 +59,39 @@ snapshot: if you have edited a file and not yet built, the verdict is
59
59
  `source differs from the catalog` — the edit has not been imported yet, so
60
60
  there is nothing to attribute. Build, then ask.
61
61
 
62
- Each `refClosure` edge shows the name that was asked for and the entity
63
- it bound to, and flags the ones that bound to nothing:
62
+ Each `refClosure` edge shows what was asked for and what answers to it,
63
+ and flags the ones nothing answers to:
64
64
 
65
65
  ```
66
- refClosure 4 edges
66
+ refClosure 6 edges
67
67
  ref /hero.txt → /files/hero.txt 24dc5b87
68
68
  ref /does-not-exist [UNRESOLVED — nothing answers to this name]
69
69
  layout /layouts/page.hbs f274678c
70
70
  lookup /contacts [UNRESOLVED — nothing answers to this name]
71
+ query {"meta.href":"/system/navigation"} → /documents/navigation.yml
72
+ query {"meta.href":"/cosmetics/celestetic"} [MATCHES NOTHING]
71
73
  ```
72
74
 
73
- An `[UNRESOLVED]` edge is usually the answer on its own. Add `--json` for
74
- the same report as a machine-readable object. Exits `3` when the entity
75
- cannot be found.
75
+ A dangling edge is usually the answer on its own, and `query` edges are
76
+ where most of it hides on a site whose references go through a sidecar's
77
+ `findEntity` — there, `ref` and `lookup` may be zero and `query`
78
+ everything.
79
+
80
+ Query counts are computed when you ask, not when the edge was recorded.
81
+ That is deliberate: an edge stores the filter WITHOUT its results, so an
82
+ entity appearing tomorrow still invalidates the page that links to it
83
+ today. An edge that recorded its bindings would record nothing for a query
84
+ matching nothing, and creating the target later would re-render nothing.
85
+
86
+ In `--json`, every query edge carries `matched` explicitly — an integer,
87
+ or `null` for a predicate that could not be serialized (`findEntities()`
88
+ with no argument, or a function filter), which invalidates on any mutation
89
+ by design. `matched: 1` also carries `sample` with the id. The field is
90
+ always present, so a consumer never has to read absence as meaning
91
+ anything.
92
+
93
+ Add `--json` for the whole report as a machine-readable object. Exits `3`
94
+ when the entity cannot be found.
76
95
 
77
96
  ### `--json`
78
97
 
@@ -96,8 +115,34 @@ Four buckets, and the distinction between them is the point:
96
115
  `never-rendered`, `inputs-changed`, `ref-changed`, `query-matched`,
97
116
  `cache-disabled`, `postprocessor`, `force`, `no-manifest`.
98
117
 
99
- `inputs-changed` carries a `changed` array naming **which** input moved,
100
- so you do not have to go to the database to find out:
118
+ Each reason carries the detail behind it, so the answer does not require a
119
+ database query. The key is per-reason — `changed`, `matched`,
120
+ `dependency` — because each means something specific:
121
+
122
+ | reason | detail | says |
123
+ | --- | --- | --- |
124
+ | `inputs-changed` | `changed: ["meta.title"]` | which of the entity's own inputs moved |
125
+ | `query-matched` | `matched: { filter, by }` | which query fired, and which mutated entity tripped it |
126
+ | `ref-changed` | `dependency: { kind, target, key, cause }` | which dependency, and whether it `changed`, was `deleted`, or was `unhashed` (nothing resolved when the edge was recorded) |
127
+
128
+ `query-matched` is the one worth reading. It fires on pages you were not
129
+ thinking about — a listing whose filter happens to cover the document you
130
+ just edited — and on a page with a dozen query edges, *which* one fired is
131
+ the whole question:
132
+
133
+ ```json
134
+ { "destination": "/index.html", "reason": "query-matched",
135
+ "matched": { "filter": { "id": { "$regex": "^/documents/devices/" } },
136
+ "by": "/documents/devices/hera.md" } }
137
+ ```
138
+
139
+ A `matched.filter` of `null` is a different statement: the page's predicate
140
+ could not be serialized (`findEntities()` with no argument, or a function
141
+ filter), so it re-renders on **any** mutation. That is not a query that
142
+ matched — it is a page with no filter, and narrowing it is the fix the
143
+ catalog already warns about at record time.
144
+
145
+ `inputs-changed` carries a `changed` array naming **which** input moved:
101
146
 
102
147
  ```json
103
148
  { "id": "/files/hero.jpg", "reason": "inputs-changed", "changed": ["checksum"] }
@@ -113,9 +158,14 @@ reads as `meta.weight (added)` / `(removed)`, which is the answer when a
113
158
  document gains or loses front-matter.
114
159
 
115
160
  The array is absent on a first render — there is no prior snapshot to
116
- compare against — and on `ref-changed`, because that is a dependency
117
- moving rather than the entity's own inputs. Conflating the two would make
118
- the attribution misleading.
161
+ compare against. It never appears alongside `matched` or `dependency`
162
+ either: a consumer switches on `reason` and reads one field, so a stray
163
+ key from another branch would make that switch wrong.
164
+
165
+ The same detail appears at `--debug` for a watch run, one line per render.
166
+ It is deliberately not in the build's normal output — the counts are the
167
+ summary and `--json` is the record — but when you are watching one page
168
+ misbehave, the trigger is the point.
119
169
 
120
170
  `unchanged` is the interesting one. It means invalidation was coarser
121
171
  than it needed to be — the render was scheduled, ran, and produced
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mikser-io",
3
- "version": "9.21.1",
3
+ "version": "9.23.0",
4
4
  "description": "<p align=\"center\"> <img src=\"mikser-lockup-stacked.svg\" alt=\"mikser\" width=\"198\" /> </p>",
5
5
  "main": "index.js",
6
6
  "exports": {
package/src/engine.js CHANGED
@@ -374,7 +374,20 @@ export async function setup(options) {
374
374
  logger.debug('Manifest skip: %s → %s', entity.name || entity.id, entity.destination)
375
375
  return
376
376
  }
377
- reportRendered(entity, decision.reason, decision.changed)
377
+ reportRendered(entity, decision.reason, decision)
378
+ // Same detail at debug, for tailing a watch run. One line per
379
+ // render is too much for a build's normal output — the counts
380
+ // are the summary and --json is the record — but when you are
381
+ // watching one page misbehave, the trigger is the whole point.
382
+ if (logger.isLevelEnabled?.('debug') ?? true) {
383
+ logger.debug('Render %s: %s%s', entity.id, decision.reason,
384
+ decision.changed?.length ? ` (${decision.changed.join(', ')})`
385
+ : decision.matched ? ` (${JSON.stringify(decision.matched.filter)}`
386
+ + `${decision.matched.by ? ` ← ${decision.matched.by}` : ''})`
387
+ : decision.dependency ? ` (${decision.dependency.kind} `
388
+ + `${decision.dependency.target} ${decision.dependency.cause})`
389
+ : '')
390
+ }
378
391
  // Project reference-marker keys (`$author`, `$hero`, …)
379
392
  // into their normalized form (`author`, `hero`) before
380
393
  // the entity crosses into the renderer — applies whether
package/src/explain.js CHANGED
@@ -9,7 +9,8 @@
9
9
  //
10
10
  // Follows --verify's shape: report and exit, no build phases run.
11
11
  import { inputHashOf, inputPartsOf, diffInputParts, lookupKeys, checksum as fileChecksum } from './utils.js'
12
- import { findEntity } from './catalog.js'
12
+ import { filterKey } from './track.js'
13
+ import { findEntity, findEntities } from './catalog.js'
13
14
  import runtime from './runtime.js'
14
15
 
15
16
  const shortHash = (h) => (h ? String(h).slice(0, 8) : null)
@@ -28,6 +29,62 @@ async function resolve(reference) {
28
29
  return like ?? null
29
30
  }
30
31
 
32
+ // How many entities each recorded query filter matches RIGHT NOW.
33
+ //
34
+ // A query edge is a predicate — "any entity matching this" — and the
35
+ // recording layer deliberately stores the filter without its results, so
36
+ // that an entity appearing later still invalidates the render. That is the
37
+ // property that makes aggregate pages work and it must not change.
38
+ //
39
+ // Explaining is a different situation: read-only, reporting instead of
40
+ // building, with the catalog already open. So the count is computed here,
41
+ // at read time, where it costs nothing and answers "is this reference
42
+ // dangling?" for the edge kind that carries most of a real site's
43
+ // references.
44
+ //
45
+ // Run through findEntities rather than hand-rolled SQL: stored filters
46
+ // include $regex and anything else sift accepts, and one code path is the
47
+ // only way the count means the same thing the render meant.
48
+ //
49
+ // A null filter is the sentinel for a predicate that could not be
50
+ // serialized (a function filter, or findEntities() with no argument). It
51
+ // invalidates on any mutation by design, and there is nothing to evaluate,
52
+ // so it reports null rather than a misleading zero.
53
+ async function countQueryMatches(snapshots) {
54
+ const counts = new Map()
55
+ for (const snap of snapshots) {
56
+ for (const entry of snap.refClosure ?? []) {
57
+ if (entry.kind !== 'query') continue
58
+ const key = filterKey(entry.filter ?? null)
59
+ if (counts.has(key)) continue
60
+ if (entry.filter == null) {
61
+ counts.set(key, null)
62
+ continue
63
+ }
64
+ try {
65
+ // recordQuery no-ops outside a render's queryContext, so
66
+ // explaining a page cannot record edges onto it.
67
+ const matches = await findEntities(entry.filter)
68
+ counts.set(key, { count: matches.length, sample: matches[0]?.id ?? null })
69
+ } catch {
70
+ // A stored filter the catalog can no longer evaluate is worth
71
+ // saying so about, not worth failing the whole report for.
72
+ counts.set(key, 'unevaluable')
73
+ }
74
+ }
75
+ }
76
+ return counts
77
+ }
78
+
79
+ // Project a counted filter into the report's shape.
80
+ function queryCount(counts, filter) {
81
+ const hit = counts.get(filterKey(filter ?? null))
82
+ if (hit === null) return { matched: null }
83
+ if (hit === 'unevaluable') return { matched: null, unevaluable: true }
84
+ if (!hit) return { matched: null }
85
+ return { matched: hit.count, ...(hit.count === 1 && hit.sample ? { sample: hit.sample } : {}) }
86
+ }
87
+
31
88
  // The verdict line names what moved when it can. That line is the one
32
89
  // people read, so "the input hash differs" there is the answer stopping one
33
90
  // step short of useful.
@@ -60,6 +117,7 @@ export async function explain(reference) {
60
117
  const snapshots = runtime.manifest?.snapshotsFor(entity.id) ?? []
61
118
  const currentHash = inputHashOf(entity)
62
119
  const currentParts = inputPartsOf(entity)
120
+ const queryMatches = await countQueryMatches(snapshots)
63
121
 
64
122
  // The catalog is as of the LAST BUILD. If the file has been edited since,
65
123
  // nothing here knows it yet — the hashes would all agree and the verdict
@@ -141,7 +199,17 @@ export async function explain(reference) {
141
199
  parent: snap.parent ?? null,
142
200
  refClosure: (snap.refClosure ?? []).map(entry =>
143
201
  entry.kind === 'query'
144
- ? { kind: 'query', filter: entry.filter }
202
+ ? {
203
+ kind: 'query',
204
+ filter: entry.filter,
205
+ // An explicit integer, because a MISSING key is
206
+ // ambiguous to a consumer: an audit script reading
207
+ // absence as "unresolved" reports every query edge
208
+ // as dangling. `null` means the filter could not be
209
+ // evaluated (unserializable predicate); a number is
210
+ // a number.
211
+ ...queryCount(queryMatches, entry.filter),
212
+ }
145
213
  : {
146
214
  kind: entry.kind,
147
215
  target: entry.target,
@@ -222,7 +290,16 @@ export function formatExplain(report) {
222
290
  row('refClosure', `${closure.length} edge${closure.length === 1 ? '' : 's'}`)
223
291
  for (const e of closure) {
224
292
  if (e.kind === 'query') {
225
- out.push(` query ${JSON.stringify(e.filter)}`)
293
+ // The count is the point: a query matching nothing is the
294
+ // dangling-reference case for the edge kind that carries most
295
+ // of a real site's references, and it printed identically to
296
+ // one that matched.
297
+ const state = e.unevaluable ? ' [FILTER CANNOT BE EVALUATED]'
298
+ : e.matched === null ? ' (untracked predicate — any mutation invalidates)'
299
+ : e.matched === 0 ? ' [MATCHES NOTHING]'
300
+ : e.matched === 1 ? ` → ${e.sample ?? '1 entity'}`
301
+ : ` → ${e.matched} entities`
302
+ out.push(` query ${JSON.stringify(e.filter)}${state}`)
226
303
  continue
227
304
  }
228
305
  // Show the name asked for and the entity it bound to, since
package/src/manifest.js CHANGED
@@ -389,11 +389,36 @@ export function createManifest(db) {
389
389
  const sourceLang = entity?.meta?.lang ?? null
390
390
  for (const entry of snapshot.refClosure) {
391
391
  if (entry.kind === 'query') {
392
- if (!entry.filter) return { skip: false, reason: 'query-matched' }
392
+ // A null filter is the sentinel for a predicate that
393
+ // could not be serialized — findEntities() with no
394
+ // argument, or a function filter. It re-renders on ANY
395
+ // mutation, which is a materially different situation
396
+ // from "this specific query matched" and is reported as
397
+ // such: an aggregate page that always re-renders is a
398
+ // filter worth narrowing, which is what catalog.js
399
+ // already warns about at record time.
400
+ if (!entry.filter) {
401
+ return {
402
+ skip: false,
403
+ reason: 'query-matched',
404
+ matched: { filter: null, by: null },
405
+ }
406
+ }
393
407
  if (!mutatedEntities?.size) continue
394
408
  const matcher = sift(entry.filter)
395
409
  for (const mutated of mutatedEntities.values()) {
396
- if (matcher(mutated)) return { skip: false, reason: 'query-matched' }
410
+ // Both the filter and the entity that tripped it are
411
+ // live here. Reporting only "a query matched" throws
412
+ // away the two facts the reader needs — on a page with
413
+ // eighteen query edges, which one fired and what set
414
+ // it off is the entire question.
415
+ if (matcher(mutated)) {
416
+ return {
417
+ skip: false,
418
+ reason: 'query-matched',
419
+ matched: { filter: entry.filter, by: mutated.id ?? null },
420
+ }
421
+ }
397
422
  }
398
423
  continue
399
424
  }
@@ -433,11 +458,26 @@ export function createManifest(db) {
433
458
  continue
434
459
  }
435
460
  }
436
- if (!entry.hash) return { skip: false, reason: 'ref-changed' }
461
+ // Which dependency, and why. Three distinct causes reach
462
+ // the same reason, and the difference is what the reader
463
+ // is after: a layout whose bytes moved, a $-ref whose
464
+ // target was deleted, and an edge recorded with no hash
465
+ // are three different things to go and look at.
466
+ //
467
+ // unhashed nothing resolved when the edge was recorded,
468
+ // so any mutation of that name re-renders
469
+ // deleted the target is gone from the catalog
470
+ // changed the target's own input hash moved
471
+ const dependency = (cause) => ({
472
+ skip: false,
473
+ reason: 'ref-changed',
474
+ dependency: { kind: entry.kind, target: entry.target, key, cause },
475
+ })
476
+ if (!entry.hash) return dependency('unhashed')
437
477
  const currentHash = currentHashes?.get(key)
438
478
  if (currentHash === undefined) continue
439
- if (currentHash === null) return { skip: false, reason: 'ref-changed' }
440
- if (currentHash !== entry.hash) return { skip: false, reason: 'ref-changed' }
479
+ if (currentHash === null) return dependency('deleted')
480
+ if (currentHash !== entry.hash) return dependency('changed')
441
481
  }
442
482
  }
443
483
  return { skip: true, reason: 'unchanged' }
package/src/report.js CHANGED
@@ -28,15 +28,25 @@ export function reportGated(count = 1) {
28
28
  store().gated += count
29
29
  }
30
30
 
31
- export function reportRendered(entity, reason, changed) {
31
+ // `decision` is the skipDecision that led here. Its detail travels with the
32
+ // reason, because a reason on its own answers a question nobody asked: WHICH
33
+ // input moved, WHICH query matched and what tripped it, WHICH dependency
34
+ // changed and how. All of it is in hand where the decision is made, and a
35
+ // consumer that has to go to the database for it is one the report failed.
36
+ //
37
+ // Detail keys are per-reason rather than one generic field — `changed`,
38
+ // `matched`, `dependency` each mean something specific, and a single
39
+ // polymorphic key would push the type switch onto every consumer.
40
+ export function reportRendered(entity, reason, decision = {}) {
32
41
  if (!runtime.options?.json) return
33
42
  store().rendered.push({
34
43
  id: entity?.id,
35
44
  destination: entity?.destination ?? null,
36
45
  reason,
37
- // Which input moved, when the reason is inputs-changed. Omitted
38
- // rather than empty so a consumer can test for its presence.
39
- ...(changed?.length ? { changed } : {}),
46
+ // Omitted rather than empty, so presence is meaningful.
47
+ ...(decision.changed?.length ? { changed: decision.changed } : {}),
48
+ ...(decision.matched ? { matched: decision.matched } : {}),
49
+ ...(decision.dependency ? { dependency: decision.dependency } : {}),
40
50
  })
41
51
  }
42
52