@stonyx/orm 0.3.2-alpha.65 → 0.3.2-alpha.66
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 +184 -202
- package/dist/manage-record.js +9 -234
- package/dist/orm-request.d.ts +60 -25
- package/dist/orm-request.js +65 -83
- package/dist/standalone-db.js +5 -17
- package/dist/utils.d.ts +0 -44
- package/dist/utils.js +0 -47
- package/package.json +1 -1
- package/src/manage-record.ts +9 -253
- package/src/orm-request.ts +65 -85
- package/src/standalone-db.ts +6 -17
- package/src/utils.ts +0 -50
package/README.md
CHANGED
|
@@ -315,15 +315,28 @@ Access classes define models and provide custom filtering/authorization logic.
|
|
|
315
315
|
> [Identifying the collection](#identifying-the-collection) before copying this.**
|
|
316
316
|
> Every attempt to identify the collection by parsing the request target has
|
|
317
317
|
> failed **open** — five distinct variants of this same example, each found only
|
|
318
|
-
> after the previous was fixed, by five different people.
|
|
319
|
-
> not
|
|
320
|
-
>
|
|
318
|
+
> after the previous was fixed, by five different people. That section is now a
|
|
319
|
+
> record of what not to do, not a matching recipe: the sample below reads `model`
|
|
320
|
+
> from [the access context](#the-access-context-second-argument) and never looks
|
|
321
|
+
> at the mount at all, so variants 1, 2, 4 and 5 are **unconstructible** against
|
|
322
|
+
> it rather than merely handled. **Variant 3 survives.** It is the general shape
|
|
323
|
+
> "a hand-written matcher normalises differently from the router", and the
|
|
324
|
+
> migrated sample still runs one string comparison — the `/archived` sub-path
|
|
325
|
+
> deny — which folds case but does not decode, so `GET /owners/%61rchived` steps
|
|
326
|
+
> past it ([#228](https://github.com/abofs/stonyx-orm/issues/228)).
|
|
321
327
|
>
|
|
322
328
|
> That is still a stopgap. **The real fix is
|
|
323
329
|
> [#202](https://github.com/abofs/stonyx-orm/issues/202)** — `access()` should
|
|
324
330
|
> receive the model, the operation and the record, so there is nothing to
|
|
325
331
|
> identify. Until it lands, prefer the array shape (`['read']`) or `false` where
|
|
326
332
|
> you can: the **function** shape is the one that requires any matching at all.
|
|
333
|
+
>
|
|
334
|
+
> The one read of argument **one** that survives is `request.path`, for the
|
|
335
|
+
> `/archived` sub-path deny — and it has to. The context names which model and
|
|
336
|
+
> which verb, not which route, so that deny **cannot be expressed from the
|
|
337
|
+
> context alone** and a context-only rewrite would silently turn it into an
|
|
338
|
+
> allow.
|
|
339
|
+
>
|
|
327
340
|
> The same warning is repeated at the top of `src/orm-request.ts`, which ships;
|
|
328
341
|
> the longer write-up in `docs/usage-patterns.md` does **not** ship, so this
|
|
329
342
|
> README and that source header are the two copies a consumer sees.
|
|
@@ -337,27 +350,65 @@ Access classes define models and provide custom filtering/authorization logic.
|
|
|
337
350
|
export default class GlobalAccess {
|
|
338
351
|
models = ['owner', 'animal'];
|
|
339
352
|
|
|
340
|
-
access(request) {
|
|
341
|
-
// `
|
|
342
|
-
//
|
|
343
|
-
//
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
//
|
|
347
|
-
//
|
|
348
|
-
//
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
//
|
|
352
|
-
//
|
|
353
|
-
//
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
//
|
|
357
|
-
//
|
|
358
|
-
|
|
353
|
+
access(request, { model, operation }) {
|
|
354
|
+
// `model` is the model this route was mounted for. It is assigned once, at
|
|
355
|
+
// mount time, and no request can influence it — not a mount prefix, not a
|
|
356
|
+
// query string, not a case-varied path, not an absolute-form request
|
|
357
|
+
// target. Nothing below parses anything, so variants 1, 2, 4 and 5 are not
|
|
358
|
+
// constructible against this predicate any more — they are history, not
|
|
359
|
+
// rules to follow. VARIANT 3 IS THE EXCEPTION AND THE CLAIM IS NARROWER
|
|
360
|
+
// THAN IT WAS: a matcher stricter than the router can still be stepped
|
|
361
|
+
// around, because the sub-path rule below is still a string comparison.
|
|
362
|
+
// Case is handled; percent-encoding is not — abofs/stonyx-orm#228.
|
|
363
|
+
//
|
|
364
|
+
// `operation` is destructured to name the whole contract at the point of
|
|
365
|
+
// use. This sample's rules are per-model and per-sub-path rather than
|
|
366
|
+
// per-verb, so it does not branch on it; the permission array at the bottom
|
|
367
|
+
// is where the verb is answered.
|
|
368
|
+
|
|
369
|
+
// FAIL CLOSED ON ARGUMENT TWO. `model` is absent for any caller that
|
|
370
|
+
// resolved this predicate without supplying the context, and a request this
|
|
371
|
+
// function cannot identify DENIES rather than falling through to the CRUD
|
|
372
|
+
// grant at the bottom. An unidentifiable input must never be the permissive
|
|
373
|
+
// path. Argument ONE is guarded at its own read, below — this guard does
|
|
374
|
+
// not cover it.
|
|
375
|
+
if (typeof model !== 'string' || model === '') return false;
|
|
376
|
+
|
|
377
|
+
if (model === 'owner') {
|
|
378
|
+
// The context names WHICH MODEL and WHICH VERB — not which route. Six
|
|
379
|
+
// distinct owner surfaces produce one identical context, so a rule that
|
|
380
|
+
// depends on the SUB-PATH still needs argument one. `request.path` is
|
|
381
|
+
// mount-relative and query-free, and it is the one read of the raw
|
|
382
|
+
// request the README sanctions. false → 403 for the whole request.
|
|
383
|
+
//
|
|
384
|
+
// THIS DENY CANNOT BE EXPRESSED FROM THE CONTEXT ALONE. Migrating it away
|
|
385
|
+
// does not remove a rule, it turns a deny into an ALLOW, silently.
|
|
386
|
+
//
|
|
387
|
+
// FAIL CLOSED ON ARGUMENT ONE TOO. The guard above covers the context;
|
|
388
|
+
// this one covers the request, and since #202 they are two different
|
|
389
|
+
// objects. A caller that resolves this predicate through the documented
|
|
390
|
+
// `Orm.instance.getAccess()` path and hand-assembles a request can supply
|
|
391
|
+
// a perfectly valid context with no usable `path` — and
|
|
392
|
+
// `String(request.path ?? '')` is then `''`, which matches no sub-path
|
|
393
|
+
// rule and falls straight through to the per-record filter below. That is
|
|
394
|
+
// a DENY becoming an ALLOW. An input this function cannot identify DENIES,
|
|
395
|
+
// whichever ARGUMENT it arrived on — which is also why the `?? ''` this
|
|
396
|
+
// file's header condemns does not appear below.
|
|
397
|
+
if (typeof request?.path !== 'string' || request.path === '') return false;
|
|
398
|
+
|
|
399
|
+
// Lower-cased because the router matched case-insensitively, so a
|
|
400
|
+
// case-sensitive rule here would be stricter than the router and could be
|
|
401
|
+
// stepped around.
|
|
402
|
+
//
|
|
403
|
+
// CASE-FOLDING ALONE IS NOT A SUFFICIENT NORMALISATION, and this line is
|
|
404
|
+
// not a recipe for one. Express sets `request.path` from the RAW pathname
|
|
405
|
+
// while the router DECODES `:id`, so `GET /owners/%61rchived` reaches this
|
|
406
|
+
// comparison as `/%61rchived`, walks past the deny, and is dispatched as
|
|
407
|
+
// the record `archived` — abofs/stonyx-orm#228. A matcher must normalise
|
|
408
|
+
// the way the router that dispatched the request does. Record ids are
|
|
409
|
+
// case-sensitive and must be compared at their real case.
|
|
410
|
+
const path = request.path.toLowerCase();
|
|
359
411
|
|
|
360
|
-
if (collection.endsWith('/owners')) {
|
|
361
412
|
if (path === '/archived' || path.startsWith('/archived/')) return false;
|
|
362
413
|
|
|
363
414
|
// Returning a function plugs it in as a per-record filter, and it is
|
|
@@ -373,7 +424,7 @@ export default class GlobalAccess {
|
|
|
373
424
|
// inert. Deliberately NO `?? record.owner` fallback: accepting the raw
|
|
374
425
|
// shape as well as the resolved one would absorb a resolution regression
|
|
375
426
|
// silently, which is exactly what blinded this fixture before.
|
|
376
|
-
if (
|
|
427
|
+
if (model === 'animal') return record => record.owner?.id !== 'restricted';
|
|
377
428
|
|
|
378
429
|
// Allows full access to all calls that don't match any of the above conditions
|
|
379
430
|
return ['read', 'create', 'update', 'delete'];
|
|
@@ -523,9 +574,10 @@ sample, `getAccess('owner') === getAccess('animal')`.
|
|
|
523
574
|
#### Passing the context makes a model-correct answer *possible*
|
|
524
575
|
|
|
525
576
|
It does not make the answer model-correct on its own. **The resolved predicate
|
|
526
|
-
has to read the context.**
|
|
527
|
-
|
|
528
|
-
**animals
|
|
577
|
+
has to read the context.** Against a predicate that ignores it the failure is
|
|
578
|
+
measurable. On a request Express dispatched to `GET /owners/angela`, asked about
|
|
579
|
+
**animals**, the sample as it shipped before
|
|
580
|
+
[#222](https://github.com/abofs/stonyx-orm/issues/222) answered:
|
|
529
581
|
|
|
530
582
|
```
|
|
531
583
|
getAccess('animal')(ownersRequest, { model: 'animal', operation: 'read' })
|
|
@@ -533,18 +585,26 @@ getAccess('animal')(ownersRequest, { model: 'animal', operation: 'read' })
|
|
|
533
585
|
```
|
|
534
586
|
|
|
535
587
|
That is the **owners** filter, and it returns `true` for animal 21 — the record
|
|
536
|
-
hidden on every animal surface. Under a mount
|
|
537
|
-
way it is worse still: it falls through to
|
|
538
|
-
`['read', 'create', 'update', 'delete']`, a full CRUD grant.
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
588
|
+
hidden on every animal surface. Under a mount such a predicate recognizes
|
|
589
|
+
neither way it is worse still: it falls through to
|
|
590
|
+
`['read', 'create', 'update', 'delete']`, a full CRUD grant. Either way the
|
|
591
|
+
context was supplied and the answer is not the animal answer, and it is wrong in
|
|
592
|
+
the direction that **grants** — because that predicate was single-argument and
|
|
593
|
+
identified its collection from the request, so it answered about the collection
|
|
594
|
+
the request was *addressed to* while being asked about another one.
|
|
595
|
+
|
|
596
|
+
The sample shipped with this repo has since been migrated to read the context,
|
|
597
|
+
and the same call now answers with the **animal** filter:
|
|
598
|
+
|
|
599
|
+
```
|
|
600
|
+
getAccess('animal')(ownersRequest, { model: 'animal', operation: 'read' })
|
|
601
|
+
-> record => record.owner?.id !== 'restricted'
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
A single-argument predicate remains the default in every consumer tree, and a
|
|
605
|
+
caller has no supported way to tell which kind it resolved. The boot-time arity
|
|
606
|
+
warning that surfaces one is
|
|
607
|
+
[#221](https://github.com/abofs/stonyx-orm/issues/221).
|
|
548
608
|
|
|
549
609
|
So: pass the context, and do not treat a resolved predicate's answer as
|
|
550
610
|
model-specific until that predicate has been migrated to read it.
|
|
@@ -581,7 +641,7 @@ a write to a *different* collection can still re-parent one. See
|
|
|
581
641
|
| `GET /:models/:id/relationships/{relationship}` | `404` — same |
|
|
582
642
|
| `PATCH /:models/:id` | `404`, no attribute is applied |
|
|
583
643
|
| `DELETE /:models/:id` | `404`, the record is not removed and no SQL `DELETE` is issued |
|
|
584
|
-
| `POST /:models` | `403`, and a record **this request inserted** is rolled back — see [Known limitations](#known-limitations) for
|
|
644
|
+
| `POST /:models` | `403`, and a record **this request inserted** is rolled back — see [Known limitations](#known-limitations) for the case where it did not insert one |
|
|
585
645
|
|
|
586
646
|
**Denied record-level requests return 404, not 403.** This is deliberate and it
|
|
587
647
|
is the property most easily "improved" away. 403 would confirm that the record
|
|
@@ -615,70 +675,23 @@ chooses the id and learns whether the create succeeded — so under a filter the
|
|
|
615
675
|
caller does not choose the id. The refusal happens before any store lookup, so
|
|
616
676
|
neither the status nor the response time depends on whether the id exists.
|
|
617
677
|
|
|
618
|
-
Let the server assign the id and read it back from the response
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
numeric ceiling, the lowest free integer), and a string-id model gets
|
|
622
|
-
`<model>-<n>`. See breaking change 8.
|
|
623
|
-
|
|
624
|
-
**What a server-assigned id is not.** It is not a secret. On a string-id
|
|
625
|
-
collection it is dense and enumerable from `1`, where previously it inherited
|
|
626
|
-
whatever entropy the last-inserted id happened to carry — a UUID-seeded store
|
|
627
|
-
answered a UUID-derived key. If a collection has **no** `access` config its
|
|
628
|
-
record-level routes are ungated, so the id was the only thing standing between
|
|
629
|
-
an unauthenticated caller and `GET`/`PATCH`/`DELETE` on a record. That was never
|
|
630
|
-
a control and must not become one; configure `access`.
|
|
631
|
-
|
|
632
|
-
**And the id itself is an occupancy signal — on both model kinds.**
|
|
633
|
-
`assignRecordId` reads the whole store, not the caller's filtered view — it
|
|
634
|
-
never sees `state.filter` — so the id it returns is a function of records the
|
|
635
|
-
caller may not be permitted to read. **This applies to numeric-id collections
|
|
636
|
-
as well as string-id ones**, and the conditions differ, so read both:
|
|
637
|
-
|
|
638
|
-
- **String-id collections, always.** The assigned `n` is the smallest positive
|
|
639
|
-
integer whose landing key is free, which tells the caller that every key
|
|
640
|
-
below it is taken, hidden or not.
|
|
641
|
-
- **Numeric-id collections, once one record sits at the numeric ceiling.** The
|
|
642
|
-
normal answer is `max + 1`, which discloses only the maximum. But `max + 1`
|
|
643
|
-
is not representable at or above 2^53, so the walk restarts from `1` (see
|
|
644
|
-
breaking change 8) and the assigned id becomes the smallest free integer —
|
|
645
|
-
the same occupancy predicate, now over arbitrary low keys. Each subsequent
|
|
646
|
-
no-id `POST` names the next free one, so a caller can enumerate the holes in
|
|
647
|
-
a range it cannot read.
|
|
648
|
-
|
|
649
|
-
**A ceiling record reaches a filter-protected collection even though `POST`
|
|
650
|
-
refuses caller ids on one.** Breaking change 3 makes
|
|
651
|
-
`POST /animals {"id": 9007199254740992}` answer `403`, but the same id lands
|
|
652
|
-
through a *relationship write on another collection* —
|
|
653
|
-
`POST /owners` carrying `attributes: { pets: [{ "id": 9007199254740992 }] }`
|
|
654
|
-
creates the animal under that key
|
|
655
|
-
([#207](https://github.com/abofs/stonyx-orm/issues/207), the same channel the
|
|
656
|
-
**Known limitations** re-parenting note describes). So the precondition is
|
|
657
|
-
reachable by an unauthenticated caller on exactly the collections `access`
|
|
658
|
-
exists to protect. Measured on the sample fixture, with every animal hidden by
|
|
659
|
-
the `/animals` predicate and keys 4 and 7 deleted:
|
|
660
|
-
|
|
661
|
-
```
|
|
662
|
-
GET /animals -> 200 [] (nothing visible)
|
|
663
|
-
GET /animals/4 -> 404 (free — indistinguishable from hidden)
|
|
664
|
-
POST /animals {"id":4} -> 403 (breaking change 3)
|
|
665
|
-
POST /owners {... pets:[{"id":9007199254740992}]} -> 200 (#207 plants the ceiling record)
|
|
666
|
-
POST /animals (no id) -> 200 id=4 <- names a hole in the hidden range
|
|
667
|
-
POST /animals (no id) -> 200 id=7 <- and the other one
|
|
668
|
-
POST /animals (no id) -> 200 id=13
|
|
669
|
-
POST /animals (no id) -> 200 id=14
|
|
670
|
-
```
|
|
671
|
-
|
|
672
|
-
Closing this requires the assignment to be filter-aware, which is a change to
|
|
673
|
-
the `access` contract rather than a fix; it is stated here rather than left to
|
|
674
|
-
be discovered. Callers with no function-style filter are unaffected — there are
|
|
675
|
-
no hidden records to disclose.
|
|
678
|
+
Let the server assign the id and read it back from the response. Callers with no
|
|
679
|
+
function-style filter are unaffected: `409` on a duplicate id and `200` on a free
|
|
680
|
+
one both behave exactly as before.
|
|
676
681
|
|
|
677
682
|
### Identifying the collection
|
|
678
683
|
|
|
679
|
-
**Do not reconstruct the request path
|
|
680
|
-
|
|
681
|
-
|
|
684
|
+
**Do not reconstruct the request path — and since
|
|
685
|
+
[#202](https://github.com/abofs/stonyx-orm/issues/202) you do not have to
|
|
686
|
+
identify the collection at all.** Read `model` from
|
|
687
|
+
[the access context](#the-access-context-second-argument): it is fixed at mount
|
|
688
|
+
time, no request can influence it, and there is nothing left to parse.
|
|
689
|
+
|
|
690
|
+
**Everything below is the record of what happened when this sample did parse
|
|
691
|
+
it.** It is kept as history, not as a recipe — none of these matching strategies
|
|
692
|
+
should be written into a new predicate. Every version of this sample that tried
|
|
693
|
+
to identify the collection from the request target failed **open**, and each
|
|
694
|
+
variant was found only after the previous one was fixed:
|
|
682
695
|
|
|
683
696
|
| # | Variant | Why it fails open |
|
|
684
697
|
|---|---|---|
|
|
@@ -688,13 +701,27 @@ was fixed:
|
|
|
688
701
|
| 4 | hard-coded `/owners` | With `ORM_REST_ROUTE=/api` every url becomes `/api/owners/...` and the sample matches nothing — environment-specifically, which is harder to notice than failing everywhere. The remediation this document used to give was itself broken: `` `${config.orm.restServer.route}owners` `` evaluates to **`/apiowners`**, so a reader who followed the correction exactly still failed open and believed they had handled it. |
|
|
689
702
|
| 5 | any match on `originalUrl` at all | HTTP/1.1 permits an **absolute-form** request-target. Express routes on `parseurl(req).pathname`, so the request dispatches normally — but `originalUrl` is the raw target. `GET http://anything.example/owners/angela` yields `originalUrl === 'http://anything.example/owners/angela'`, which has no `/owners` prefix. Measured: the record came back in full, `DELETE` succeeded, and it walked past a hard `return false` deny the same way. |
|
|
690
703
|
|
|
691
|
-
**The fix is not a sixth rule
|
|
692
|
-
|
|
693
|
-
**
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
704
|
+
**The fix is not a sixth rule, and it is not a better string to match.** It is
|
|
705
|
+
to stop identifying the collection at all. That is a statement about
|
|
706
|
+
**identifying the collection**, and it is not a statement about the sample as a
|
|
707
|
+
whole: the `/archived` sub-path rule *is* still a string match, and
|
|
708
|
+
[#228](https://github.com/abofs/stonyx-orm/issues/228) is a sixth spelling that
|
|
709
|
+
gets past it. Sub-path rules are the residue this fix does not cover, which is
|
|
710
|
+
why they must normalise the way the router does.
|
|
711
|
+
|
|
712
|
+
An intermediate revision read **`request.baseUrl`** — the mount Express
|
|
713
|
+
*actually matched*. That closed all five variants: it carries no query string
|
|
714
|
+
(variant 2), it is not mount-relative (variant 1), it already contains the
|
|
715
|
+
configured `ORM_REST_ROUTE` prefix (variant 4 — there is nothing left to derive,
|
|
716
|
+
so `/apiowners` is unconstructible), and it is unaffected by an absolute-form
|
|
717
|
+
target (variant 5). It was still a transport artifact standing in for a
|
|
718
|
+
structural fact, and it is **no longer what the sample does**: the sample reads
|
|
719
|
+
`model`, so variants 1, 2, 4 and 5 are unconstructible against it rather than
|
|
720
|
+
handled. **Variant 3 survives**, in the one string comparison the migration
|
|
721
|
+
leaves behind: the `/archived` sub-path deny folds case but does not decode
|
|
722
|
+
([#228](https://github.com/abofs/stonyx-orm/issues/228)). The table below is
|
|
723
|
+
retained as the measured evidence behind the five variants, not because any of
|
|
724
|
+
these values should be matched on:
|
|
698
725
|
|
|
699
726
|
| request | `request.url` | `request.originalUrl` | `request.baseUrl` | `request.path` |
|
|
700
727
|
|---|---|---|---|---|
|
|
@@ -705,21 +732,35 @@ unconstructible), and it is unaffected by an absolute-form target (variant 5).
|
|
|
705
732
|
| `GET http://anything.example/owners/angela` | `http://anything.example/angela` | `http://anything.example/owners/angela` | `/owners` | `/angela` |
|
|
706
733
|
| `GET /api/animals/22` (`ORM_REST_ROUTE=/api`) | `/22` | `/api/animals/22` | `/api/animals` | `/22` |
|
|
707
734
|
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
735
|
+
**One read of argument one survives, and it must: `request.path`.** It is
|
|
736
|
+
mount-relative and query-free, and it is for rules that distinguish **sub-paths**
|
|
737
|
+
beneath the mount — as the `/archived` deny in the sample above does. The context
|
|
738
|
+
names which model and which verb, **not which route**, so that deny *cannot be
|
|
739
|
+
expressed from the context alone*, and a context-only rewrite would silently turn
|
|
740
|
+
it into an allow.
|
|
741
|
+
|
|
742
|
+
**Normalise the way the router that dispatched the request does — and
|
|
743
|
+
case-folding alone does not.** A matcher stricter than the router can be stepped
|
|
744
|
+
around, so the sample lower-cases before comparing (the router matched
|
|
745
|
+
case-insensitively). That closes the case gap and **it is not the whole rule**:
|
|
746
|
+
Express sets `request.path` from the **raw, undecoded** pathname while the router
|
|
747
|
+
**decodes** `:id`, so `GET /owners/%61rchived` reaches a `path === '/archived'`
|
|
748
|
+
comparison as `/%61rchived`, walks past the deny, and is dispatched as the record
|
|
749
|
+
`archived`. That gap is live in the sample above and is tracked as
|
|
750
|
+
[#228](https://github.com/abofs/stonyx-orm/issues/228) — **do not read the
|
|
751
|
+
`.toLowerCase()` there as a complete normalisation recipe.** Record ids are
|
|
752
|
+
case-sensitive and must be compared at their real case.
|
|
753
|
+
|
|
754
|
+
**Fail closed on anything you cannot identify — on *either* argument.**
|
|
755
|
+
`String(request.originalUrl ?? '')` was once added here to stop a `TypeError`,
|
|
756
|
+
and it traded fail-closed for fail-**open**: an empty string matched no
|
|
757
|
+
collection, so `access()` fell through to the permission array and granted full
|
|
758
|
+
CRUD. The same rule applies to the context — the sample returns `false` for an
|
|
759
|
+
absent `model` rather than falling through. Since #202 the guard and the read can
|
|
760
|
+
sit on **different objects**, and a guard on argument two does not protect a read
|
|
761
|
+
of argument one: the sample therefore also returns `false` when `request.path` is
|
|
762
|
+
absent or is not a string, rather than letting `?? ''` fall through to the
|
|
763
|
+
per-record filter. An input you cannot identify must **deny**.
|
|
723
764
|
|
|
724
765
|
### Known limitations
|
|
725
766
|
|
|
@@ -742,11 +783,14 @@ sub-paths beneath the mount, as the `/archived` deny above does.
|
|
|
742
783
|
see [The access context](#the-access-context-second-argument):
|
|
743
784
|
`Orm.instance.getAccess(modelName)` makes another model's predicate
|
|
744
785
|
**reachable**, and `context.model` makes a **model-correct answer possible** —
|
|
745
|
-
possible, not guaranteed: the resolved predicate has to read the context
|
|
746
|
-
|
|
747
|
-
([#
|
|
748
|
-
|
|
749
|
-
|
|
786
|
+
possible, not guaranteed: the resolved predicate has to read the context. The
|
|
787
|
+
sample shipped with this repo now does
|
|
788
|
+
([#222](https://github.com/abofs/stonyx-orm/issues/222)), so
|
|
789
|
+
`getAccess('animal')` answers with the animal filter; a predicate that ignores
|
|
790
|
+
the second argument still answers about the collection the request is
|
|
791
|
+
addressed to, and the boot-time warning that surfaces one is
|
|
792
|
+
[#221](https://github.com/abofs/stonyx-orm/issues/221). **The mechanism
|
|
793
|
+
exists; the ORM does not yet use it on this path.** The re-parenting write above is still
|
|
750
794
|
**not refused** — that enforcement is
|
|
751
795
|
[#196](https://github.com/abofs/stonyx-orm/issues/196) and
|
|
752
796
|
[#207](https://github.com/abofs/stonyx-orm/issues/207), which were blocked on
|
|
@@ -798,10 +842,9 @@ sub-paths beneath the mount, as the `/archived` deny above does.
|
|
|
798
842
|
transform output differs from its lookup key is the same defect. Filtered
|
|
799
843
|
collections are unaffected — breaking change 3 refuses any client-supplied id
|
|
800
844
|
— so this reaches consumers with **no** function-style filter. Tracked as
|
|
801
|
-
[#205](https://github.com/abofs/stonyx-orm/issues/205)
|
|
802
|
-
[#203](https://github.com/abofs/stonyx-orm/issues/203)
|
|
803
|
-
|
|
804
|
-
the client-supplied half and is still open.
|
|
845
|
+
[#205](https://github.com/abofs/stonyx-orm/issues/205), alongside
|
|
846
|
+
[#203](https://github.com/abofs/stonyx-orm/issues/203), which is the other way
|
|
847
|
+
a create can land on an id nobody named.
|
|
805
848
|
- **`context.record` is `undefined` for an after-`create` hook when a string-id
|
|
806
849
|
model is given a numeric-looking id.** The post-create lookup uses the same id
|
|
807
850
|
coercion as every other surface, which resolves `'9107'` to the number `9107`,
|
|
@@ -811,18 +854,15 @@ sub-paths beneath the mount, as the `/archived` deny above does.
|
|
|
811
854
|
[#209](https://github.com/abofs/stonyx-orm/issues/209).
|
|
812
855
|
- **A denied `POST` rolls back only a record it *inserted*.** The rollback
|
|
813
856
|
requires the store to have grown, because removing by id alone is a write
|
|
814
|
-
primitive keyed by a caller-supplied value.
|
|
815
|
-
|
|
816
|
-
[#203](https://github.com/abofs/stonyx-orm/issues/203) —
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
[#207](https://github.com/abofs/stonyx-orm/issues/207) — puts the condition
|
|
824
|
-
back, and without the guard a denied `403` would delete a record the request
|
|
825
|
-
did not create.
|
|
857
|
+
primitive keyed by a caller-supplied value. When `assignRecordId` lands a
|
|
858
|
+
**server-assigned** id on an occupied slot
|
|
859
|
+
([#203](https://github.com/abofs/stonyx-orm/issues/203) — it returns
|
|
860
|
+
last-*inserted* + 1, not max + 1, so a store whose insertion order is not
|
|
861
|
+
ascending collides), `createRecord` updates that record **in place**: the map
|
|
862
|
+
does not grow, the rollback correctly declines to remove a record this request
|
|
863
|
+
did not create, and the `403` leaves the caller's attributes on someone else's
|
|
864
|
+
record. Narrow — it needs a non-ascending insertion order — but it is the
|
|
865
|
+
reachability condition, so it is stated rather than implied.
|
|
826
866
|
|
|
827
867
|
### Breaking changes
|
|
828
868
|
|
|
@@ -883,64 +923,6 @@ they are recorded here.
|
|
|
883
923
|
population breaking changes 3 and 4 explicitly exempt. If you were relying on
|
|
884
924
|
a hex-shaped or whitespace-padded id creating a second record, it never did.
|
|
885
925
|
|
|
886
|
-
8. **Server-assigned ids change value on string-id models, numeric ids stop
|
|
887
|
-
being monotonic at the numeric ceiling, and the create route gains a
|
|
888
|
-
`409`.** Three consumer-visible changes from
|
|
889
|
-
[#203](https://github.com/abofs/stonyx-orm/issues/203).
|
|
890
|
-
|
|
891
|
-
**The value.** A `POST` with no `id` against a model declaring
|
|
892
|
-
`id = attr('string')` previously produced the *last-inserted* id with `1`
|
|
893
|
-
concatenated onto it — an owner store holding `['gina', 'bob']` answered
|
|
894
|
-
`'bob1'`. It now answers `'owner-1'`: the model name, a hyphen, and the
|
|
895
|
-
lowest positive integer whose landing key is free. **No test in this repo
|
|
896
|
-
pinned the old value**, so a consumer relying on it gets no failing test, no
|
|
897
|
-
deprecation and no other signal — which is why it is recorded here. Numeric
|
|
898
|
-
id models (`id = attr('number')`, the default) are unaffected in shape: they
|
|
899
|
-
still get an integer, but it is now the **maximum** existing id plus one
|
|
900
|
-
rather than the last-inserted id plus one, which is the defect #203 is about.
|
|
901
|
-
They are **not** unaffected in *sequence* — see the monotonicity half below.
|
|
902
|
-
|
|
903
|
-
The value is deliberately **not** numeric-looking, and that is not cosmetic.
|
|
904
|
-
Every id-bearing surface resolves a numeric-looking string id to a **number**
|
|
905
|
-
(`GET /owners/1` looks up `1`), while a string-id model files its records
|
|
906
|
-
under the **string** key `'1'`. A server-assigned `'1'` would therefore be a
|
|
907
|
-
record that was created successfully and could not be fetched, updated or
|
|
908
|
-
deleted by id, and whose after-`create` hook received
|
|
909
|
-
`context.record === undefined`
|
|
910
|
-
([#209](https://github.com/abofs/stonyx-orm/issues/209)).
|
|
911
|
-
|
|
912
|
-
**Numeric ids are no longer monotonic, and deleted ids can be re-issued.**
|
|
913
|
-
The precondition is narrow but it is reachable, and there is no signal when
|
|
914
|
-
it is met: **one record filed at or above 2^53** (`9007199254740992`). `max
|
|
915
|
-
+ 1` is not representable there, so assignment restarts from `1` and walks
|
|
916
|
-
up to the lowest free key — which means the id of a *deleted* record is
|
|
917
|
-
handed to the next `POST`. Both `dev` and every prior release were strictly
|
|
918
|
-
monotonic and never re-issued a numeric id, so a consumer that relied on
|
|
919
|
-
that — audit rows, cursors, cached authorization decisions, external
|
|
920
|
-
references keyed on the id — now has a stale reference that silently points
|
|
921
|
-
at a **different record, created by a different caller**, rather than at a
|
|
922
|
-
deleted one. Nothing fails; the reference simply resolves to the wrong
|
|
923
|
-
record.
|
|
924
|
-
|
|
925
|
-
The restart is deliberate and is not itself optional: without it, one record
|
|
926
|
-
at the ceiling made every subsequent server-assigned create on that
|
|
927
|
-
collection fail permanently. Re-use is the cost of keeping the collection
|
|
928
|
-
writable. **If you need monotonic ids, assign them yourself** rather than
|
|
929
|
-
letting the server assign, and note that a ceiling record can be planted by
|
|
930
|
-
an unauthenticated caller — see *And the id itself is an occupancy signal*
|
|
931
|
-
under [Filter functions](#filter-functions) for the reachability path.
|
|
932
|
-
String-id models are unaffected by this half: their keys are
|
|
933
|
-
`<model>-<n>` and were never monotonic over an integer sequence.
|
|
934
|
-
|
|
935
|
-
**The status.** `POST /{collection}` can now answer `409` for a reason other
|
|
936
|
-
than a duplicate id: the server could not derive a free id. That requires a
|
|
937
|
-
**non-injective** id transform — one that maps distinct candidates onto the
|
|
938
|
-
same store key, such as `boolean`, or anything you registered on
|
|
939
|
-
`Orm.instance.transforms` and named as an id type. It is a configuration
|
|
940
|
-
fault rather than a request fault; the message is logged through
|
|
941
|
-
`stonyx/log`. Previously this case threw out of the handler and express
|
|
942
|
-
answered `500` with a stack trace.
|
|
943
|
-
|
|
944
926
|
### Include Parameter (Sideloading Relationships)
|
|
945
927
|
|
|
946
928
|
The ORM supports JSON API-compliant relationship sideloading via the `include` query parameter. This reduces the need for multiple API requests by embedding related records in a single response.
|