@stonyx/orm 0.3.2-alpha.76 → 0.3.2-alpha.77

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.
@@ -65,9 +65,19 @@
65
65
  * warning below sanctions. This repo's own fixture has such a rule: its
66
66
  * `/archived` deny cannot be expressed from the context alone, and a predicate
67
67
  * migrated to context-only would silently drop it, turning a deny into an
68
- * allow. The related-resource and `?include=` surfaces serve ANOTHER model's
69
- * records under `model: 'owner'`, and the context gives no signal of that
70
- * (abofs/stonyx-orm#196).
68
+ * allow.
69
+ *
70
+ * THE RELATED-RESOURCE HALF OF THAT SENTENCE IS NOW OUT OF DATE AND IS
71
+ * CORRECTED HERE RATHER THAN DELETED. Both relationship route families resolve
72
+ * the RELATED model's own access class and ask it
73
+ * `{ model: <related>, operation: 'read', recordId: null }`
74
+ * (abofs/stonyx-orm#232), so those surfaces no longer serve another model's
75
+ * records under `model: 'owner'` unexamined. What the context still gives no
76
+ * signal of is WHICH related record is being asked about -- `recordId` is
77
+ * `null` there and `request.params` names a record of a different model. See
78
+ * `AccessContext.recordId` in ./types/orm-types.ts for the full statement of
79
+ * that limit. `?include=` is still unfiltered and is abofs/stonyx-orm#233 /
80
+ * #235.
71
81
  *
72
82
  * SUPERSEDED 2026-09-01 BY abofs/stonyx-orm#236/#237, AND KEPT FOR THE
73
83
  * CONSTRAINT IT STATES RATHER THAN AS A DESCRIPTION OF THE CODE. The context
@@ -424,7 +434,7 @@ function normalizeBodyId(id) {
424
434
  return coerceId(id);
425
435
  }
426
436
  function buildResponse(data, includeParam, recordOrRecords, options = {}) {
427
- const { links, baseUrl, linkage } = options;
437
+ const { links, baseUrl } = options;
428
438
  const response = { data };
429
439
  // Add top-level links
430
440
  if (links) {
@@ -437,49 +447,14 @@ function buildResponse(data, includeParam, recordOrRecords, options = {}) {
437
447
  return response;
438
448
  const includedRecords = collectIncludedRecords(recordOrRecords, includes);
439
449
  if (includedRecords.length > 0) {
440
- // LINKAGE, NOT MEMBERSHIP -- and the distinction is the whole reason this
441
- // line is one story's and the line above it is another's
442
- // (abofs/stonyx-orm#235 and #233 respectively).
443
- //
444
- // - WHICH RESOURCES REACH THIS ARRAY is decided by
445
- // `collectIncludedRecords` on the line above. That is MEMBERSHIP, it is
446
- // #233's, and it is deliberately untouched here: a hidden owner is
447
- // still a member of `included` after this change. Pinned green by
448
- // `[GUARD] #235 X1` so that #235 cannot close #233 incidentally.
449
- // - WHAT A RECORD ALREADY IN THIS ARRAY MAY NAME in its own
450
- // `relationships.*.data` is LINKAGE -- the same question #234 answers
451
- // for the primary document -- and that is what the `linkage` option
452
- // below decides. Before it, `GET /animals/1?include=owner,owner.pets`
453
- // filtered the primary document's `owner.data` to `null` and then
454
- // handed back nine PERMITTED animals in `included` each naming
455
- // `{"type":"owner","id":"angela"}`. Neither #233 nor #234 closes that.
456
- //
457
- // THE FILTER IS THE CALLER'S, PASSED IN, NOT BUILT HERE. Both call sites
458
- // already hold one for the primary document, and sharing it is what keeps
459
- // the per-type verdict cache and the per-(type, id) decision cache alive
460
- // across the primary document AND the sideload -- one verdict resolution
461
- // per type for the whole response, pinned by `[GUARD] #235 C1`. Building a
462
- // fresh filter here would resolve the consumer's `access()` once per
463
- // included record instead.
464
- //
465
- // `linkage` IS OPTIONAL IN THE TYPE AND IS NOT OPTIONAL IN PRACTICE.
466
- // Stating it precisely because the opposite claim stood here in an earlier
467
- // draft of this change: BOTH of this function's callers supply a filter
468
- // (`getCollectionHandler` and `getSingleHandler`, the only two), so the
469
- // `undefined` branch has no live caller in this module today. It is
470
- // optional so that omitting it degrades to the PRE-#234 document rather
471
- // than to a denial -- `Record.toJSON` reads an ABSENT option as "no verdict
472
- // was supplied" and emits linkage in full.
473
- //
474
- // WHAT IT MUST NEVER BE HANDED IS A NON-FUNCTION. `toJSON` does NOT read a
475
- // non-function as absent: `Object.prototype.toString.call(linkage)` must be
476
- // `'[object Function]'`, and anything else -- `null`, an `AsyncFunction`,
477
- // and INCLUDING the primitive `true` -- DENIES every relationship on the
478
- // document and logs once. `toJSON({ linkage: true })` emits `null` linkage.
479
- // So do not "simplify" this to a boolean, and do not make it default to
480
- // `true`: both spellings look like "allow everything" and mean the exact
481
- // opposite (abofs/stonyx-orm#224).
482
- response.included = includedRecords.map(record => record.toJSON?.({ baseUrl, linkage }));
450
+ // NO `linkage` ARGUMENT, deliberately, and abofs/stonyx-orm#235 owns adding
451
+ // one. Until it does, a PERMITTED record here emits the full pre-#234
452
+ // document: `GET /animals/1?include=owner` filters the primary document's
453
+ // `owner.data` to `null` and then names `owner:angela` in `included`.
454
+ // Whether a resource reaches this array at all is a different question
455
+ // (membership, abofs/stonyx-orm#233) and closing that one does not close
456
+ // this one.
457
+ response.included = includedRecords.map(record => record.toJSON?.({ baseUrl }));
483
458
  }
484
459
  return response;
485
460
  }
@@ -661,11 +636,7 @@ export default class OrmRequest extends Request {
661
636
  const data = recordsToReturn.map(record => record.toJSON?.({ fields: modelFields, baseUrl, linkage }));
662
637
  return buildResponse(data, request.query?.include, recordsToReturn, {
663
638
  links: { self: `${baseUrl}/${pluralizedModel}` },
664
- baseUrl,
665
- // THE SAME filter object the primary documents above were serialized
666
- // with, deliberately: it carries the caches, and rebuilding one here
667
- // would re-resolve every type (abofs/stonyx-orm#235).
668
- linkage
639
+ baseUrl
669
640
  });
670
641
  };
671
642
  const getSingleHandler = async (request, { filter }) => {
@@ -681,28 +652,28 @@ export default class OrmRequest extends Request {
681
652
  const modelFields = fieldsMap.get(pluralizedModel) || fieldsMap.get(model);
682
653
  const baseUrl = getBaseUrl(request);
683
654
  const linkage = createLinkageFilter(request);
684
- // `buildResponse` IS given the filter now (abofs/stonyx-orm#235), and it
685
- // is the SAME object the primary document is serialized with -- one
686
- // verdict per type for the whole response, sideload included.
655
+ // `buildResponse` is deliberately NOT given the linkage filter, and the
656
+ // residual that leaves is NOT the one #233 owns. Two different questions:
657
+ //
658
+ // - WHETHER A RESOURCE APPEARS in `included` at all is MEMBERSHIP ->
659
+ // abofs/stonyx-orm#233.
660
+ // - What a record already IN `included` may NAME is LINKAGE -- the same
661
+ // question #234 answers for the primary document -- and it is
662
+ // abofs/stonyx-orm#235, which also owns createHandler/updateHandler.
687
663
  //
688
- // The boundary that remains, so the next reader does not have to derive
689
- // it: this closes what a record already in `included` may NAME. WHETHER a
690
- // resource appears in `included` at all is MEMBERSHIP and it is
691
- // abofs/stonyx-orm#233's -- a hidden owner is still a member here.
692
- // Neither question closes the other.
664
+ // The residual, stated so the next reader does not have to derive it:
665
+ // `buildResponse` calls `record.toJSON?.({ baseUrl })` with no `linkage`
666
+ // argument, so a PERMITTED record in `included` emits the full pre-#234
667
+ // document. Measured: `GET /animals/1?include=owner` returns
668
+ // `owner.data: null` on the primary document and `owner:angela` in
669
+ // `included`. One query parameter deep. Only the PRIMARY document's
670
+ // linkage is filtered here.
693
671
  return buildResponse(record.toJSON?.({ fields: modelFields, baseUrl, linkage }), request.query?.include, record, {
694
672
  links: { self: `${baseUrl}/${pluralizedModel}/${request.params.id}` },
695
- baseUrl,
696
- linkage
673
+ baseUrl
697
674
  });
698
675
  };
699
- const createHandler = async (request, { filter }) => {
700
- // BOUND, not destructured (abofs/stonyx-orm#235). `HandlerFn` has always
701
- // delivered the request as argument one; this handler simply discarded
702
- // the binding, which is why its response document named ids every read
703
- // surface withholds. `createLinkageFilter` needs the live request and
704
- // there is no signature change involved in giving it one.
705
- const { body, query } = request;
676
+ const createHandler = async ({ body, query }, { filter }) => {
706
677
  const { type, id, attributes, relationships: rels } = (body?.data || {});
707
678
  if (!type)
708
679
  return 400; // Bad request
@@ -941,28 +912,9 @@ export default class OrmRequest extends Request {
941
912
  }
942
913
  return 403;
943
914
  }
944
- // The filter is built HERE, per invocation, and never hoisted into the
945
- // OrmRequest constructor where the other per-mount values live: a verdict
946
- // cached across requests answers a second caller with the first caller's
947
- // authorization (src/access-verdict.ts says so at the constructor an
948
- // implementer would reach for).
949
- //
950
- // AND IT IS BUILT AFTER `createRecord`, AFTER THE ROLLBACK WINDOW AND
951
- // AFTER `isDenied`, so the record is in its final form at the call. The
952
- // filter is lazy per type and per (type, id), so it cannot observe a
953
- // pre-write state even if it were built earlier.
954
- //
955
- // `fields` is passed here and NOT in `updateHandler`: the two handlers
956
- // are asymmetric on purpose (`updateHandler` has no `fieldsMap` in
957
- // scope), and a single copy-pasted wiring would drop it from one of them.
958
- return { data: record.toJSON?.({ fields: modelFields, linkage: createLinkageFilter(request) }) };
915
+ return { data: record.toJSON?.({ fields: modelFields }) };
959
916
  };
960
- const updateHandler = async (request, { filter }) => {
961
- // Bound rather than destructured, for the reason given in
962
- // `createHandler` above (abofs/stonyx-orm#235). `PATCH /animals/1`
963
- // returned 200 naming angela seconds after `GET /animals/1` returned
964
- // `owner.data: null` for the same record -- one HTTP verb apart.
965
- const { body, params } = request;
917
+ const updateHandler = async ({ body, params }, { filter }) => {
966
918
  const found = await store.find(model, getId(params));
967
919
  if (!found || !isOrmRecord(found))
968
920
  return 404;
@@ -1019,14 +971,7 @@ export default class OrmRequest extends Request {
1019
971
  updateRecord(record, relUpdates, { _skipAutoPersist: true });
1020
972
  }
1021
973
  }
1022
- // No `fields` and no `baseUrl`, both unchanged: `updateHandler` has no
1023
- // `fieldsMap` in scope, and adding `baseUrl` would put `links` on a
1024
- // document that has never carried them -- an unrelated behaviour change.
1025
- // #224 AC6's "emits `data: []` WITH links" is a statement about the READ
1026
- // surfaces; on these two handlers a filtered relationship and a
1027
- // genuinely-empty one are both a bare `{ data }`, which is what makes
1028
- // them indistinguishable here too.
1029
- return { data: record.toJSON?.({ linkage: createLinkageFilter(request) }) };
974
+ return { data: record.toJSON?.() };
1030
975
  };
1031
976
  const deleteHandler = async ({ params }, { filter }) => {
1032
977
  // Coerced ONCE. `getId(params)` was evaluated twice here -- once to find
@@ -1310,21 +1255,102 @@ export default class OrmRequest extends Request {
1310
1255
  return 404;
1311
1256
  const relatedData = record.__relationships[relationshipName];
1312
1257
  const baseUrl = getBaseUrl(request);
1313
- // LINKAGE ONLY. This filter decides which ids the emitted documents may
1314
- // NAME in their own `relationships.*.data`; it does NOT decide whether
1315
- // the related records themselves are served -- that is the parent-only
1316
- // filtering this route has done since #190, and widening it to the
1317
- // related record is abofs/stonyx-orm#196.
1258
+ // ONE FILTER, TWO JOBS, AND abofs/stonyx-orm#232 IS THE SECOND ONE.
1259
+ //
1260
+ // As LINKAGE (#234) it decides which ids the emitted documents may NAME
1261
+ // in their own `relationships.*.data`. As MEMBERSHIP (this issue) it
1262
+ // decides whether the related record is served here AT ALL -- the
1263
+ // related resource is PRIMARY data on this route, so there is no
1264
+ // linkage-consistency question to answer separately.
1265
+ //
1266
+ // Until #232 this route filtered only the PARENT, so a record its own
1267
+ // model's predicate hides was served in full from another model's
1268
+ // route, at ZERO query parameters. Measured on dev @ 8dda5d6:
1269
+ //
1270
+ // GET /owners/angela -> 404
1271
+ // GET /animals/1/owner -> 200, owner:angela, full attributes
1272
+ // GET /traits/2/tag -> 200, a model NO access class
1273
+ // claims, on a collection that has
1274
+ // no mounted route at all
1275
+ //
1276
+ // ARGUMENT ONE IS THE LIVE REQUEST, NOT A DERIVED ONE. A fabricated
1277
+ // request addressing the RELATED resource was the original design and
1278
+ // it is dropped: #241 removed the shipped fixture's read of argument
1279
+ // one, so a fabricated value changes nothing it could observe.
1280
+ // `createLinkageFilter` is also a published public export
1281
+ // (src/index.ts) whose resolution granularity is per TYPE; supplying a
1282
+ // per-RECORD request would mean widening it, which takes a consumer
1283
+ // `access()` from ~2 calls to ~7 on a plain `GET /animals`. That is a
1284
+ // separate, consumer-visible story.
1285
+ //
1286
+ // GUARDED BY OWN-PROPERTY IDENTITY, NOT BY THE #234 AC13 PIN. That pin
1287
+ // (test/unit/linkage-verdict-test.ts, `strictEqual(seen[0].request,
1288
+ // READ_REQUEST)`) calls `createLinkageFilter` DIRECTLY, so it pins the
1289
+ // function's pass-through and constrains no call site -- an earlier
1290
+ // revision of this comment cited it for this decision and was wrong.
1291
+ // `Object.create(request)` here measured 1015 / 0 with nothing red.
1292
+ // test/integration/orm-test.ts, `#232 AC9`, now asserts that the object
1293
+ // the predicate is handed OWNS `params` (`Object.hasOwn`) and has
1294
+ // nothing request-shaped behind it on the prototype chain. A derived
1295
+ // request inherits `params` -- so it satisfies every value assertion
1296
+ // there -- and reds on those two. Measured: with the derived request in
1297
+ // place, 1014 / 1, and that one is this guard.
1298
+ //
1299
+ // THE RESIDUAL THAT FOLLOWS FROM THAT IS DISCLOSED, NOT PAPERED OVER.
1300
+ // `recordId` is `null` here and the request names a record of a
1301
+ // DIFFERENT model, so a consumer predicate can express a model-level or
1302
+ // a request-level deny for a related resource, but NOT a per-record
1303
+ // one. README.md and docs/usage-patterns.md say so; a ledger assertion
1304
+ // in test/unit/relationship-route-access-test.ts keeps them saying it.
1318
1305
  const linkage = createLinkageFilter(request);
1306
+ // FAIL CLOSED ON A RECORD WHOSE TYPE CANNOT BE NAMED. `isLinkable` is
1307
+ // keyed on the model name; without one there is no predicate to ask,
1308
+ // and an unidentifiable input must never be the permissive path.
1309
+ const isLinkable = (r) => {
1310
+ const type = r.__model?.__name;
1311
+ return typeof type === 'string' && type !== '' && linkage(type, r);
1312
+ };
1319
1313
  let data;
1320
1314
  if (info.isArray) {
1321
- // hasMany - return array
1315
+ // hasMany - return array, MINUS the members this caller may not see.
1316
+ // Dropped, never errored: the result is byte-identical to a genuinely
1317
+ // empty relationship, so this route is not an existence oracle.
1322
1318
  const related = Array.isArray(relatedData) ? relatedData.filter(isOrmRecord) : [];
1323
- data = related.map(r => r.toJSON?.({ baseUrl, linkage }));
1319
+ data = related.filter(isLinkable).map(r => r.toJSON?.({ baseUrl, linkage }));
1324
1320
  }
1325
1321
  else {
1326
- // belongsTo - return single or null
1327
- data = isOrmRecord(relatedData) ? relatedData.toJSON?.({ baseUrl, linkage }) : null;
1322
+ // belongsTo - return single or null. A DENIED target is `data: null`,
1323
+ // BYTE-IDENTICAL to a relationship that is genuinely empty, for the
1324
+ // same reason the hasMany branch above drops rather than errors: this
1325
+ // route must not be an existence oracle for the RELATED record.
1326
+ //
1327
+ // THE OTHER SPELLING WAS 404 AND IT WAS MEASURED AS A DISCLOSURE.
1328
+ // Unauthenticated, zero query parameters, one request each, on `tag`
1329
+ // -- the model with no route mounted at all, which is exactly what
1330
+ // #240 AC5 exists to protect:
1331
+ //
1332
+ // GET /traits/1/tag [ABSENT] -> 200 application/json len 68
1333
+ // GET /traits/2/tag [DENIED] -> 404 text/plain len 9
1334
+ //
1335
+ // and `GET /traits/1` and `GET /traits/2` both report
1336
+ // `relationships.tag = {"data":null}` byte-identical modulo the id,
1337
+ // because #234 closed THAT oracle deliberately. A 404 here would let
1338
+ // a caller ask which of those two nulls was a denial. Under
1339
+ // `data: null` the pair closes completely: 200/200, same
1340
+ // content-type, same content-length, bodies identical modulo the
1341
+ // parent id the caller put in the URL. It opens nothing -- `links`
1342
+ // are entirely parent-derived, there is no `meta` and no counts.
1343
+ //
1344
+ // This is also what README.md's module-wide rule already demanded:
1345
+ // every status on a record route must be identical for filtered-out
1346
+ // and does-not-exist. The route now CONFORMS to that rule rather than
1347
+ // carving an exception out of it.
1348
+ if (!isOrmRecord(relatedData))
1349
+ data = null;
1350
+ else if (!isLinkable(relatedData))
1351
+ data = null;
1352
+ else
1353
+ data = relatedData.toJSON?.({ baseUrl, linkage });
1328
1354
  }
1329
1355
  return {
1330
1356
  links: { self: `${baseUrl}/${pluralizedModel}/${request.params.id}/${dasherizedName}` },
@@ -1332,47 +1358,6 @@ export default class OrmRequest extends Request {
1332
1358
  };
1333
1359
  };
1334
1360
  // Relationship linkage route: GET /:id/relationships/{relationship}
1335
- //
1336
- // NO `linkage` FILTER FROM abofs/stonyx-orm#235, AND THAT IS A SCOPE
1337
- // BOUNDARY RATHER THAN AN OVERSIGHT -- abofs/stonyx-orm#232 OWNS THIS
1338
- // ROUTE, and PR #247 is IN FLIGHT against it in this same sprint. If you
1339
- // are reading this after #247 landed, the filtering below is #232's and
1340
- // this note records why it was never #235's to add.
1341
- //
1342
- // The three sites #235 does own (`buildResponse`'s `included`, the
1343
- // related-resource branch above, and the two write handlers) all reach
1344
- // the filter through `record.toJSON()`, which is where the `linkage`
1345
- // OPTION is applied. This branch builds its `{ type, id }` objects BY
1346
- // HAND and never calls `toJSON` at all, so the `linkage` option cannot
1347
- // reach it -- whatever this route filters, it has to filter itself, which
1348
- // is precisely why doing so is a separate change with a separate owner.
1349
- //
1350
- // It is also a DIFFERENT QUESTION. Everywhere #235 touches, linkage is
1351
- // metadata ABOUT a document. Here the linkage IS the primary data, so
1352
- // dropping an entry is a MEMBERSHIP decision about what this route
1353
- // serves -- the same class as abofs/stonyx-orm#233 and #196, not the
1354
- // class #234/#235 close. That is why it is absent from #224 §2a's
1355
- // seven-site inventory.
1356
- //
1357
- // MEASURED, so the next person does not re-derive it. Against this
1358
- // branch's baseline of 1011/0, wiring `createLinkageFilter` into the
1359
- // belongsTo branch below takes the suite to 1009/2, reddening
1360
- // `[GUARD] #235 X2` and the
1361
- // `GET /animals/:id/relationships/owner returns relationship linkage`
1362
- // test -- the latter is #232's own reproduction, not a regression.
1363
- //
1364
- // THE BASELINE IS QUOTED WITH THE RESULT BECAUSE AN EARLIER REVISION OF
1365
- // THIS COMMENT SAID 993/2 AND SHIPPED IT. This file lands in consumers'
1366
- // `node_modules`, so a wrong number here is a wrong number in the
1367
- // published package. 993+2 = 995 is the DEV baseline, carried over from
1368
- // a branch on which `[GUARD] #235 X2` does not exist. A pass/fail pair
1369
- // with no baseline beside it cannot be checked by reading, which is how
1370
- // it survived three artifacts and a review; the qualitative claim was
1371
- // right the whole time and only the count was wrong.
1372
- //
1373
- // `[GUARD] #235 X2` in test/integration/orm-test.ts pins the OWNERSHIP
1374
- // BOUNDARY here rather than this route's current answer, so that it
1375
- // survives #247 landing. Read its comment before changing it.
1376
1361
  routes[`/:id/relationships/${dasherizedName}`] = async (request, { filter } = {}) => {
1377
1362
  const record = await store.find(model, getId(request.params));
1378
1363
  if (!record)
@@ -1381,17 +1366,43 @@ export default class OrmRequest extends Request {
1381
1366
  return 404;
1382
1367
  const relatedData = record.__relationships[relationshipName];
1383
1368
  const baseUrl = getBaseUrl(request);
1369
+ // THE ONE READ SURFACE THAT DOES NOT GO THROUGH `toJSON()`. It builds
1370
+ // `{ type, id }` BY HAND, which is why #234's linkage filter never
1371
+ // reached it and why this half belongs to abofs/stonyx-orm#232 rather
1372
+ // than to #234: on this route the linkage IS the primary data of an
1373
+ // opt-in request, so filtering it changes the route's MEMBERSHIP
1374
+ // semantics, not the ids named inside somebody else's document.
1375
+ //
1376
+ // DELIBERATELY NOT STATED AS A COUNT. README.md's Consumer Contracts
1377
+ // section enumerates the surfaces on which the framework resolves a
1378
+ // verdict and hands it to `toJSON()`, and that enumeration GROWS --
1379
+ // abofs/stonyx-orm#235 adds the two write handlers and the `included`
1380
+ // records. This route is not on that list under any count, because it
1381
+ // never calls `toJSON()`: whatever it filters, it filters here. A
1382
+ // number written into this comment would be false the next time that
1383
+ // list changes, and the README already carries the enumeration.
1384
+ //
1385
+ // Same filter, same argument-one decision, same residual as
1386
+ // `/:id/{relationship}` above -- read the block there.
1387
+ const linkage = createLinkageFilter(request);
1388
+ const isLinkable = (r) => {
1389
+ const type = r.__model?.__name;
1390
+ return typeof type === 'string' && type !== '' && linkage(type, r);
1391
+ };
1384
1392
  let data;
1385
1393
  if (info.isArray) {
1386
1394
  // hasMany - return array of linkage objects
1387
1395
  const related = Array.isArray(relatedData) ? relatedData.filter(isOrmRecord) : [];
1388
1396
  data = related
1389
1397
  .filter((r) => Boolean(r.__model))
1398
+ .filter(isLinkable)
1390
1399
  .map(r => ({ type: r.__model.__name, id: r.id }));
1391
1400
  }
1392
1401
  else {
1393
- // belongsTo - return single linkage or null
1394
- if (isOrmRecord(relatedData) && relatedData.__model) {
1402
+ // belongsTo - return single linkage or null. A DENIED target is
1403
+ // `data: null`, indistinguishable from a genuinely empty one -- see
1404
+ // the measured oracle in the `/:id/{relationship}` block above.
1405
+ if (isOrmRecord(relatedData) && relatedData.__model && isLinkable(relatedData)) {
1395
1406
  data = { type: relatedData.__model.__name, id: relatedData.id };
1396
1407
  }
1397
1408
  else {
@@ -340,10 +340,36 @@ export interface AccessContext {
340
340
  * repaired here. A predicate must not read `undefined` here as "collection",
341
341
  * and nothing in this contract makes it safe to read the two keys as one key.
342
342
  *
343
- * IT NAMES WHICH RECORD, NOT WHICH SURFACE. `GET /owners/gina`,
344
- * `GET /owners/gina/pets` and `GET /owners/gina/relationships/pets` all
345
- * carry `recordId: 'gina'`; the related-resource gap is abofs/stonyx-orm#196
346
- * and is untouched by this key.
343
+ * IT NAMES WHICH RECORD OF THE MODEL BEING ASKED ABOUT, NOT WHICH SURFACE,
344
+ * AND THE ANSWER DEPENDS ON WHICH MODEL IS BEING ASKED ABOUT.
345
+ *
346
+ * For the ask about the ROUTE'S OWN model, all three of `GET /owners/gina`,
347
+ * `GET /owners/gina/pets` and `GET /owners/gina/relationships/pets` carry
348
+ * `recordId: 'gina'` -- `auth()` reads it off `request.params`.
349
+ *
350
+ * FOR THE ASK ABOUT A RELATED MODEL, IT IS `null`, AND THAT IS A LIMIT ON
351
+ * WHAT A PREDICATE CAN EXPRESS (abofs/stonyx-orm#232). The two relationship
352
+ * route families resolve the RELATED model's own predicate -- `animal` on
353
+ * `GET /owners/gina/pets`, `owner` on `GET /animals/4/owner` -- and that ask
354
+ * carries `recordId: null` while `request.params` names a record of a
355
+ * DIFFERENT model. So a predicate answering about a related model gets the
356
+ * model name, the operation and the request, and CANNOT branch on which
357
+ * related record it is being asked about.
358
+ *
359
+ * The rule, so it is not re-derived wrong: `recordId` may name a record only
360
+ * where the route addresses exactly one record OF THE MODEL BEING ASKED
361
+ * ABOUT. A `hasMany` related-resource route returns many records of one type
362
+ * and the verdict is resolved ONCE PER TYPE, before any record is examined --
363
+ * seeding it from a record would let the first one decide for all of them.
364
+ *
365
+ * What still works, and what does not, is pinned as behaviour by `#232 AC10`
366
+ * in test/integration/orm-test.ts and stated for consumers in README.md:
367
+ * model-level denies work, request-level denies work, and the per-record
368
+ * FILTER shape works because `access()` may return a function and that
369
+ * function receives the whole record. Branching on identity BEFORE returning
370
+ * does not.
371
+ *
372
+ * `?include=` is a separate surface and is abofs/stonyx-orm#233 / #235.
347
373
  */
348
374
  recordId: string | number | null;
349
375
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "stonyx-async",
5
5
  "stonyx-module"
6
6
  ],
7
- "version": "0.3.2-alpha.76",
7
+ "version": "0.3.2-alpha.77",
8
8
  "description": "",
9
9
  "main": "dist/index.js",
10
10
  "type": "module",