@reventlessdev/reventless-local 3.0.0-alpha.223 → 3.0.0-alpha.225

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.
@@ -167,11 +167,11 @@ function Make(Bus) {
167
167
  };
168
168
  let publishSaved = (changeKind, id, state) => {
169
169
  let subKey = getSubKey(state, subIdField);
170
- let descriptor = LocalStateChangeDescriptor$ReventlessLocal.make(changeKind, entityKeyFor(id, subKey), state, LocalStateChangeDescriptor$ReventlessLocal.nextSequence());
170
+ let descriptor = LocalStateChangeDescriptor$ReventlessLocal.make(changeKind, entityKeyFor(id, subKey), state, LocalStateChangeDescriptor$ReventlessLocal.nextSequence(), Stdlib_Option.map(LocalStateChangeDescriptor$ReventlessLocal.retiredSpecFor(name), r => r.field), Stdlib_Option.flatMap(LocalStateChangeDescriptor$ReventlessLocal.retiredSpecFor(name), r => r.values));
171
171
  Bus.publishStateChange(name, descriptor);
172
172
  };
173
173
  let publishRemoved = (id, subKey) => {
174
- let descriptor = LocalStateChangeDescriptor$ReventlessLocal.make("Removed", entityKeyFor(id, subKey), undefined, LocalStateChangeDescriptor$ReventlessLocal.nextSequence());
174
+ let descriptor = LocalStateChangeDescriptor$ReventlessLocal.make("Removed", entityKeyFor(id, subKey), undefined, LocalStateChangeDescriptor$ReventlessLocal.nextSequence(), undefined, undefined);
175
175
  Bus.publishStateChange(name, descriptor);
176
176
  };
177
177
  let save = async (id, state, _saveMode, ttl) => {
@@ -147,6 +147,7 @@ type busCallbacks = {
147
147
  ~capability: GraphQL_FragmentGenerator.serverCapability,
148
148
  ~labelField: string,
149
149
  ~ownerScope: (string, string)=?,
150
+ ~retiredScope: Reventless.OwnerScope.retiredScope=?,
150
151
  ) => option<JSON.t>,
151
152
  ) => unit,
152
153
  }
@@ -263,6 +264,8 @@ let makeStorage = (
263
264
  ~id=entityKeyFor(id, subKey),
264
265
  ~state=Some(state),
265
266
  ~seq=LocalStateChangeDescriptor.nextSequence(),
267
+ ~retiredField=?LocalStateChangeDescriptor.retiredSpecFor(name)->Option.map(r => r.field),
268
+ ~retiredValues=?LocalStateChangeDescriptor.retiredSpecFor(name)->Option.flatMap(r => r.values),
266
269
  )
267
270
  bus.publishStateChange(~name, ~descriptor)
268
271
  }
@@ -428,6 +431,7 @@ let makeStorage = (
428
431
  ~capability: GraphQL_FragmentGenerator.serverCapability,
429
432
  ~labelField as _,
430
433
  ~ownerScope: option<(string, string)>=?,
434
+ ~retiredScope: option<Reventless.OwnerScope.retiredScope>=?,
431
435
  ): option<JSON.t> => {
432
436
  let filterDict =
433
437
  argsDict->Dict.get("filter")->Option.flatMap(JSON.Decode.object)->Option.getOr(Dict.make())
@@ -451,6 +455,39 @@ let makeStorage = (
451
455
  params->Array.push(JSON.Encode.string(required))
452
456
  | None => ()
453
457
  }
458
+ // `IS NOT 1`, not `= 0`, and on the raw extraction rather than through
459
+ // `jsonText`. SQLite renders a JSON true as the integer 1 and a missing
460
+ // path as NULL, and `IS NOT` is the comparison that treats NULL as a value
461
+ // rather than poisoning the predicate. Three cases have to land the way the
462
+ // in-memory spec lands them: absent keeps the row (a row written before the
463
+ // annotation is not retired), false keeps it, and a value that is not a
464
+ // JSON boolean keeps it too — which `= 0` would get wrong, since a string
465
+ // `'true'` compares unequal to 0 and the row would vanish on this backend
466
+ // only. `QueryDbListPushdownParityTest` is what holds the two together.
467
+ //
468
+ // The state form compares against the states' text instead of 1, and the
469
+ // three cases land identically: absent is NULL, a state outside the set
470
+ // compares unequal to every member, and a non-string value is none of them
471
+ // either.
472
+ //
473
+ // Written as a conjunction of `IS NOT` rather than as `NOT IN`: `IN` is
474
+ // ordinary equality, so a NULL path makes the predicate NULL and the row
475
+ // vanishes — the absent case, which has to keep the row. `IS NOT` is the
476
+ // comparison that treats NULL as a value, and it does not have an `IN`
477
+ // spelling. A set naming nothing pushes no predicate down, which is the
478
+ // same answer `isRetiredValue` gives it.
479
+ switch retiredScope {
480
+ | Some(scope) =>
481
+ let path = `json_extract(item, '$.${scope.field->String.replaceAll("'", "''")}')`
482
+ switch scope.values {
483
+ | None => whereParts->Array.push(`${path} IS NOT 1`)
484
+ | Some(states) =>
485
+ states->Array.forEach(state =>
486
+ whereParts->Array.push(`${path} IS NOT '${state->String.replaceAll("'", "''")}'`)
487
+ )
488
+ }
489
+ | None => ()
490
+ }
454
491
  let valString = v =>
455
492
  switch v->JSON.Decode.string {
456
493
  | Some(s) => Some(s)
@@ -194,7 +194,7 @@ function makeStorage(db, bus, name, indexes, subIdField) {
194
194
  };
195
195
  let publishSaved = (changeKind, id, state) => {
196
196
  let subKey = computeSubKey(state, subIdField);
197
- let descriptor = LocalStateChangeDescriptor$ReventlessLocal.make(changeKind, entityKeyFor(id, subKey), state, LocalStateChangeDescriptor$ReventlessLocal.nextSequence());
197
+ let descriptor = LocalStateChangeDescriptor$ReventlessLocal.make(changeKind, entityKeyFor(id, subKey), state, LocalStateChangeDescriptor$ReventlessLocal.nextSequence(), Stdlib_Option.map(LocalStateChangeDescriptor$ReventlessLocal.retiredSpecFor(name), r => r.field), Stdlib_Option.flatMap(LocalStateChangeDescriptor$ReventlessLocal.retiredSpecFor(name), r => r.values));
198
198
  bus.publishStateChange(name, descriptor);
199
199
  };
200
200
  let saveKind = (id, state) => {
@@ -209,7 +209,7 @@ function makeStorage(db, bus, name, indexes, subIdField) {
209
209
  }
210
210
  };
211
211
  let publishRemoved = (id, subKey) => {
212
- let descriptor = LocalStateChangeDescriptor$ReventlessLocal.make("Removed", entityKeyFor(id, subKey), undefined, LocalStateChangeDescriptor$ReventlessLocal.nextSequence());
212
+ let descriptor = LocalStateChangeDescriptor$ReventlessLocal.make("Removed", entityKeyFor(id, subKey), undefined, LocalStateChangeDescriptor$ReventlessLocal.nextSequence(), undefined, undefined);
213
213
  bus.publishStateChange(name, descriptor);
214
214
  };
215
215
  let rowKeysForPartition = id => SqliteDriver$ReventlessLocal.all(selectByPartitionStmt, [id]).map(row => {
@@ -337,7 +337,7 @@ function makeStorage(db, bus, name, indexes, subIdField) {
337
337
  };
338
338
  let jsonText = field => `CAST(json_extract(item, '$.` + field.replaceAll("'", "''") + `') AS TEXT)`;
339
339
  let idExpr = "COALESCE(json_extract(item, '$.id'), partition_key)";
340
- let listPage = (argsDict, capability, param, ownerScope) => {
340
+ let listPage = (argsDict, capability, param, ownerScope, retiredScope) => {
341
341
  let filterDict = Stdlib_Option.getOr(Stdlib_Option.flatMap(argsDict["filter"], Stdlib_JSON.Decode.object), {});
342
342
  let strNonEmpty = k => Stdlib_Option.mapOr(Stdlib_Option.flatMap(filterDict[k], Stdlib_JSON.Decode.string), false, s => s.length > 0);
343
343
  let hasIds = Stdlib_Option.mapOr(Stdlib_Option.flatMap(filterDict["ids"], Stdlib_JSON.Decode.array), false, a => a.length !== 0);
@@ -352,6 +352,17 @@ function makeStorage(db, bus, name, indexes, subIdField) {
352
352
  whereParts.push(jsonText(ownerScope[0]) + ` = ?`);
353
353
  params.push(ownerScope[1]);
354
354
  }
355
+ if (retiredScope !== undefined) {
356
+ let path = `json_extract(item, '$.` + retiredScope.field.replaceAll("'", "''") + `')`;
357
+ let states = retiredScope.values;
358
+ if (states !== undefined) {
359
+ states.forEach(state => {
360
+ whereParts.push(path + ` IS NOT '` + state.replaceAll("'", "''") + `'`);
361
+ });
362
+ } else {
363
+ whereParts.push(path + ` IS NOT 1`);
364
+ }
365
+ }
355
366
  let valString = v => {
356
367
  let s = Stdlib_JSON.Decode.string(v);
357
368
  if (s !== undefined) {
@@ -11,9 +11,20 @@
11
11
  // unlink leaves it on the orphaned inode still serving every row it had, the
12
12
  // delete looks like it worked, and the seed then fails against the untouched
13
13
  // server with "the target store is not empty". Deleting ROWS through a second
14
- // connection is visible to the running server immediately (its reads go to
15
- // these tables; there is no in-process cache), so a reset needs no restart and
16
- // no stopping of the platform.
14
+ // connection is what works instead a query issued after the delete reads
15
+ // the emptied tables, so the platform need not be STOPPED for the reset.
16
+ //
17
+ // It does need RESTARTING before the re-seed, and this comment claimed
18
+ // otherwise for a while on the strength of "there is no in-process cache".
19
+ // There is: a DCB slice's decision state is held per partition in the
20
+ // running process, and a delete behind its back does not invalidate it. The
21
+ // slice goes on refusing writes for ids whose state it still remembers, so
22
+ // the re-seed fails with `…AlreadyExists` naming rows the store visibly does
23
+ // not hold — verified by the same id being refused before a restart and
24
+ // accepted after, against byte-identical tables.
25
+ //
26
+ // So: reset with the platform up, then restart it, then seed. Emptying the
27
+ // store and emptying the process are two steps, and only the first is here.
17
28
  //
18
29
  // • It is SCOPED. Wiping domain data leaves the plugin registry intact, so a
19
30
  // re-seed just works — the same reason the deployed default is `domain`.
@@ -543,15 +554,21 @@ let run = (~dbPath: option<string>=?): unit => {
543
554
  if total(plan) == 0 {
544
555
  Console.log("Nothing to do.")
545
556
  } else {
557
+ // Set at all ⇒ it is the answer, affirmative or not. Falling through to
558
+ // the prompt on an unrecognised value would ask for a TTY the runs this
559
+ // variable exists for do not have, so `SEED_RESET_CONFIRM=no` would
560
+ // throw where it plainly means "don't". Both arms read the reply
561
+ // through one predicate, which is what keeps the typed `y` and the
562
+ // env var speaking the same language.
546
563
  let confirmed = switch Seed.Prompt.envValue("SEED_RESET_CONFIRM") {
547
- | Some("1") | Some("yes") => true
548
- | _ =>
564
+ | Some(answer) => Seed.Prompt.isAffirmative(answer)
565
+ | None =>
549
566
  let answer = await Seed.Prompt.ask(
550
567
  `Empty ${total(
551
568
  plan,
552
569
  )->Int.toString} row(s)/object(s) in the "${plan.scope->scopeLabel}" scope? [y/N]: `,
553
570
  )
554
- answer->String.trim->String.toLowerCase == "y"
571
+ Seed.Prompt.isAffirmative(answer)
555
572
  }
556
573
  if confirmed {
557
574
  execute(db, plan)
@@ -499,25 +499,8 @@ function run(dbPath) {
499
499
  if (total(plan) === 0) {
500
500
  console.log("Nothing to do.");
501
501
  } else {
502
- let match$1 = Seed_Prompt$ReventlessSeed.envValue("SEED_RESET_CONFIRM");
503
- let confirmed;
504
- let exit = 0;
505
- if (match$1 !== undefined) {
506
- switch (match$1) {
507
- case "1" :
508
- case "yes" :
509
- confirmed = true;
510
- break;
511
- default:
512
- exit = 1;
513
- }
514
- } else {
515
- exit = 1;
516
- }
517
- if (exit === 1) {
518
- let answer = await Seed_Prompt$ReventlessSeed.ask(`Empty ` + total(plan).toString() + ` row(s)/object(s) in the "` + scopeLabel(plan.scope) + `" scope? [y/N]: `);
519
- confirmed = answer.trim().toLowerCase() === "y";
520
- }
502
+ let answer = Seed_Prompt$ReventlessSeed.envValue("SEED_RESET_CONFIRM");
503
+ let confirmed = answer !== undefined ? Seed_Prompt$ReventlessSeed.isAffirmative(answer) : Seed_Prompt$ReventlessSeed.isAffirmative(await Seed_Prompt$ReventlessSeed.ask(`Empty ` + total(plan).toString() + ` row(s)/object(s) in the "` + scopeLabel(plan.scope) + `" scope? [y/N]: `));
521
504
  if (confirmed) {
522
505
  execute(db, plan);
523
506
  console.log(`Reset complete — the "` + scopeLabel(plan.scope) + `" scope reads empty and is re-seedable.`);
@@ -109,10 +109,11 @@ let indexedStateSchemaWithAnnotations = indexedStateSchema->S.Metadata.set(
109
109
  scanSort: [],
110
110
  semantic: [],
111
111
  metric: [],
112
- status: None,
112
+ lifecycle: None,
113
113
  groupBy: None,
114
114
  visibility: None,
115
115
  live: None,
116
+ retired: None,
116
117
  },
117
118
  )
118
119
 
@@ -139,10 +140,11 @@ let orderedStateSchemaWithAnnotations = orderedStateSchema->S.Metadata.set(
139
140
  scanSort: [],
140
141
  semantic: [],
141
142
  metric: [],
142
- status: None,
143
+ lifecycle: None,
143
144
  groupBy: None,
144
145
  visibility: None,
145
146
  live: None,
147
+ retired: None,
146
148
  },
147
149
  )
148
150
 
@@ -170,10 +172,11 @@ let scanStateSchemaWithAnnotations = scanStateSchema->S.Metadata.set(
170
172
  scanSort: ["name"],
171
173
  semantic: [],
172
174
  metric: [],
173
- status: None,
175
+ lifecycle: None,
174
176
  groupBy: None,
175
177
  visibility: None,
176
178
  live: None,
179
+ retired: None,
177
180
  },
178
181
  )
179
182
 
@@ -429,7 +432,7 @@ describe("GraphQL_SchemaInspector", () => {
429
432
  // Query field should use filter + first/after/last/before args (Phase 4)
430
433
  expect(
431
434
  sdl->String.includes(
432
- "Relay_Products(filter: RelayProductFilter, first: Int, after: String, last: Int, before: String): RelayProductConnection!",
435
+ "Relay_Products(filter: RelayProductFilter, first: Int, after: String, last: Int, before: String, includeRetired: Boolean): RelayProductConnection!",
433
436
  ),
434
437
  )->toBe(true)
435
438
  // Connection filter input with search/searchPrefix/ids
@@ -114,10 +114,11 @@ let indexedStateSchemaWithAnnotations = S.Metadata.set(indexedStateSchema, State
114
114
  scanSort: [],
115
115
  semantic: [],
116
116
  metric: [],
117
- status: undefined,
117
+ lifecycle: undefined,
118
118
  groupBy: undefined,
119
119
  visibility: undefined,
120
- live: undefined
120
+ live: undefined,
121
+ retired: undefined
121
122
  });
122
123
 
123
124
  let orderedStateSchema = S.schema(s => ({
@@ -141,10 +142,11 @@ let orderedStateSchemaWithAnnotations = S.Metadata.set(orderedStateSchema, State
141
142
  scanSort: [],
142
143
  semantic: [],
143
144
  metric: [],
144
- status: undefined,
145
+ lifecycle: undefined,
145
146
  groupBy: undefined,
146
147
  visibility: undefined,
147
- live: undefined
148
+ live: undefined,
149
+ retired: undefined
148
150
  });
149
151
 
150
152
  let scanStateSchema = S.schema(s => ({
@@ -169,10 +171,11 @@ let scanStateSchemaWithAnnotations = S.Metadata.set(scanStateSchema, StateAnnota
169
171
  scanSort: ["name"],
170
172
  semantic: [],
171
173
  metric: [],
172
- status: undefined,
174
+ lifecycle: undefined,
173
175
  groupBy: undefined,
174
176
  visibility: undefined,
175
- live: undefined
177
+ live: undefined,
178
+ retired: undefined
176
179
  });
177
180
 
178
181
  globalThis.describe("GraphQL_SchemaInspector", () => {
@@ -350,7 +353,7 @@ globalThis.describe("GraphQL_SchemaInspector", () => {
350
353
  globalThis.expect(sdl.includes("edges: [RelayProductEdge!]!")).toBe(true);
351
354
  globalThis.expect(sdl.includes("pageInfo: PageInfo!")).toBe(true);
352
355
  globalThis.expect(sdl.includes("totalCount")).toBe(false);
353
- globalThis.expect(sdl.includes("Relay_Products(filter: RelayProductFilter, first: Int, after: String, last: Int, before: String): RelayProductConnection!")).toBe(true);
356
+ globalThis.expect(sdl.includes("Relay_Products(filter: RelayProductFilter, first: Int, after: String, last: Int, before: String, includeRetired: Boolean): RelayProductConnection!")).toBe(true);
354
357
  globalThis.expect(sdl.includes("input RelayProductFilter")).toBe(true);
355
358
  globalThis.expect(sdl.includes("search: String")).toBe(true);
356
359
  globalThis.expect(sdl.includes("searchPrefix: String")).toBe(true);
@@ -69,7 +69,7 @@ globalThis.describe("LocalGraphQL_SubscriptionResolvers", () => {
69
69
  "2026-05-19T12:00:00Z"
70
70
  ]
71
71
  ]);
72
- let descriptor = LocalStateChangeDescriptor$ReventlessLocal.make("Updated", "prod-1", state, LocalStateChangeDescriptor$ReventlessLocal.nextSequence());
72
+ let descriptor = LocalStateChangeDescriptor$ReventlessLocal.make("Updated", "prod-1", state, LocalStateChangeDescriptor$ReventlessLocal.nextSequence(), undefined, undefined);
73
73
  TestBus.publishStateChange("Product", descriptor);
74
74
  let received = await consumerPromise;
75
75
  if (received !== null) {
@@ -88,7 +88,7 @@ globalThis.describe("LocalGraphQL_SubscriptionResolvers", () => {
88
88
  let foreignDescriptor = LocalStateChangeDescriptor$ReventlessLocal.make("Updated", "cat-1", Object.fromEntries([[
89
89
  "id",
90
90
  "cat-1"
91
- ]]), LocalStateChangeDescriptor$ReventlessLocal.nextSequence());
91
+ ]]), LocalStateChangeDescriptor$ReventlessLocal.nextSequence(), undefined, undefined);
92
92
  TestBus.publishStateChange("Category", foreignDescriptor);
93
93
  let received = await consumerPromise;
94
94
  globalThis.expect(received === null ? undefined : Primitive_option.some(received)).toEqual(undefined);
@@ -21,13 +21,21 @@ let capability: ReventlessCore.GraphQL_FragmentGenerator.serverCapability = {
21
21
  sortFields: ["name", "qty", "status"],
22
22
  }
23
23
 
24
- let mk = (id, status, name, qty, owner) => {
24
+ let mk = (id, status, name, qty, owner, archived) => {
25
25
  let o = Dict.make()
26
26
  o->Dict.set("id", JSON.Encode.string(id))
27
27
  o->Dict.set("status", JSON.Encode.string(status))
28
28
  o->Dict.set("name", JSON.Encode.string(name))
29
29
  o->Dict.set("qty", JSON.Encode.int(qty))
30
30
  o->Dict.set("owner", JSON.Encode.string(owner))
31
+ // `archived` is absent on p-5, not false. A row written before the annotation
32
+ // existed has no such attribute, and "absent means not retired" is the rule
33
+ // both the spec and every push-down have to land on — get it wrong and the
34
+ // view empties the day someone adds `@retired`.
35
+ switch archived {
36
+ | Some(b) => o->Dict.set("archived", JSON.Encode.bool(b))
37
+ | None => ()
38
+ }
31
39
  JSON.Encode.object(o)
32
40
  }
33
41
 
@@ -40,11 +48,11 @@ let mk = (id, status, name, qty, owner) => {
40
48
  // to work on a field the client-visible filter surface does not admit, which is
41
49
  // the normal case and the reason the predicate travels separately.
42
50
  let rows = [
43
- ("p-1", "active", "Charlie", 3, "u-a"),
44
- ("p-2", "active", "Alpha", 1, "u-b"),
45
- ("p-3", "inactive", "Echo", 5, "u-a"),
46
- ("p-4", "active", "Bravo", 2, "u-c"),
47
- ("p-5", "inactive", "Delta", 4, "u-a"),
51
+ ("p-1", "active", "Charlie", 3, "u-a", Some(false)),
52
+ ("p-2", "active", "Alpha", 1, "u-b", Some(true)),
53
+ ("p-3", "inactive", "Echo", 5, "u-a", Some(false)),
54
+ ("p-4", "active", "Bravo", 2, "u-c", Some(true)),
55
+ ("p-5", "inactive", "Delta", 4, "u-a", None),
48
56
  ]
49
57
 
50
58
  type setup = {
@@ -53,6 +61,7 @@ type setup = {
53
61
  ~capability: ReventlessCore.GraphQL_FragmentGenerator.serverCapability,
54
62
  ~labelField: string,
55
63
  ~ownerScope: (string, string)=?,
64
+ ~retiredScope: Reventless.OwnerScope.retiredScope=?,
56
65
  ) => option<JSON.t>,
57
66
  fullScan: unit => array<JSON.t>,
58
67
  }
@@ -66,8 +75,13 @@ let build = async (): setup => {
66
75
  let s = Storage.make(~name="items", ~indexes=[], ~api=(), ~apiRole=(), ~owner=None, ~opts)
67
76
  let ops = await s.operations->TestRunner.resolve
68
77
  for i in 0 to rows->Array.length - 1 {
69
- let (id, status, name, qty, owner) = rows->Array.getUnsafe(i)
70
- let _ = await ops.save(id, mk(id, status, name, qty, owner), ReventlessCore.QueryDb.Any, None)
78
+ let (id, status, name, qty, owner, archived) = rows->Array.getUnsafe(i)
79
+ let _ = await ops.save(
80
+ id,
81
+ mk(id, status, name, qty, owner, archived),
82
+ ReventlessCore.QueryDb.Any,
83
+ None,
84
+ )
71
85
  }
72
86
  {
73
87
  listPage: TestBus.getQueryDbListPage("items")->Option.getOrThrow,
@@ -118,7 +132,7 @@ let orderBy = (f, dir) =>
118
132
  let cur = ReventlessCore.QueryDbListQuery.encodeCursor
119
133
 
120
134
  // Assert the push-down serves this shape AND matches the spec exactly.
121
- let checkPushed = async (~label, ~ownerScope=?, args) => {
135
+ let checkPushed = async (~label, ~ownerScope=?, ~retiredScope=?, args) => {
122
136
  let s = await build()
123
137
  let argsDict = argsOf(args)
124
138
  let expected =
@@ -129,8 +143,9 @@ let checkPushed = async (~label, ~ownerScope=?, args) => {
129
143
  ~labelField="name",
130
144
  ~decodeLocalId=_ => None,
131
145
  ~ownerScope?,
146
+ ~retiredScope?,
132
147
  )->norm
133
- switch s.listPage(~argsDict, ~capability, ~labelField="name", ~ownerScope?) {
148
+ switch s.listPage(~argsDict, ~capability, ~labelField="name", ~ownerScope?, ~retiredScope?) {
134
149
  | Some(actual) => expect(actual->norm)->toEqual(expected)
135
150
  | None => expect("push-down for " ++ label)->toBe("returned None")
136
151
  }
@@ -142,6 +157,15 @@ let checkFallback = async args => {
142
157
  expect(s.listPage(~argsDict=argsOf(args), ~capability, ~labelField="name")->Option.isSome)->toBe(false)
143
158
  }
144
159
 
160
+ // The ids a retirement-narrowed read returns, from the push-down.
161
+ let liveIds = async args => {
162
+ let s = await build()
163
+ switch s.listPage(~argsDict=argsOf(args), ~capability, ~labelField="name", ~retiredScope={field: "archived", values: None}) {
164
+ | Some(conn) => (conn->norm).edges->Array.map(e => e.id)
165
+ | None => []
166
+ }
167
+ }
168
+
145
169
  // The ids a scoped read actually returns, from the push-down.
146
170
  let scopedIds = async (~owner, args) => {
147
171
  let s = await build()
@@ -218,6 +242,54 @@ describe("QueryDb list push-down parity (SQLite ≡ QueryDbListQuery spec)", ()
218
242
  checkFallback([("last", JSON.Encode.int(2)), ("before", JSON.Encode.string(cur("p-4")))])
219
243
  )
220
244
 
245
+ // ── Retirement narrowing ──────────────────────────────────────────────────
246
+ // Same parity argument as owner scoping below: the push-down is the path a
247
+ // deployment takes and the spec is the path the tests reach, so a predicate
248
+ // implemented in one of them is a hole every fallback-based test calls green.
249
+ describe("retirement narrowing", () => {
250
+ testPromise("bare page, narrowed", () =>
251
+ checkPushed(~label="retired-bare", ~retiredScope={field: "archived", values: None}, [])
252
+ )
253
+ testPromise("narrowed + orderBy", () =>
254
+ checkPushed(
255
+ ~label="retired-order",
256
+ ~retiredScope={field: "archived", values: None},
257
+ [("orderBy", orderBy("name", "DESC"))],
258
+ )
259
+ )
260
+ testPromise("narrowed + the caller's own filter", () =>
261
+ checkPushed(
262
+ ~label="retired-filter",
263
+ ~retiredScope={field: "archived", values: None},
264
+ [("filter", filterOf([("statusEq", JSON.Encode.string("active"))]))],
265
+ )
266
+ )
267
+ testPromise("narrowed + owner-scoped together", () =>
268
+ checkPushed(
269
+ ~label="retired-owner",
270
+ ~ownerScope=("owner", "u-a"),
271
+ ~retiredScope={field: "archived", values: None},
272
+ [],
273
+ )
274
+ )
275
+
276
+ // The rows, not just the parity: p-2 and p-4 are archived, p-5 carries no
277
+ // flag at all. Parity alone would pass if BOTH implementations were wrong
278
+ // the same way.
279
+ testPromise("drops the archived rows and keeps the one with no flag", async () => {
280
+ let ids = await liveIds([])
281
+ expect(ids)->toEqual(["p-1", "p-3", "p-5"])
282
+ })
283
+
284
+ // The reason the predicate is pushed into the SQL rather than applied to the
285
+ // page: `first: 2` must yield two LIVE rows, not two rows of which some were
286
+ // filtered away afterwards.
287
+ testPromise("a page of first:2 is two live rows, not two rows minus the archived", async () => {
288
+ let ids = await liveIds([("first", JSON.Encode.int(2))])
289
+ expect(ids)->toEqual(["p-1", "p-3"])
290
+ })
291
+ })
292
+
221
293
  // ── Owner scoping ─────────────────────────────────────────────────────────
222
294
  // Parity matters more here than anywhere else in this file. The push-down is
223
295
  // the path a deployment actually takes; the spec is the path the tests most