@stonyx/orm 0.3.2-beta.154 → 0.3.2-beta.156
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 +301 -85
- package/dist/manage-record.js +234 -9
- package/dist/orm-request.d.ts +60 -25
- package/dist/orm-request.js +118 -30
- package/dist/standalone-db.js +17 -5
- package/dist/utils.d.ts +44 -0
- package/dist/utils.js +47 -0
- package/package.json +1 -1
- package/src/manage-record.ts +253 -9
- package/src/orm-request.ts +120 -30
- package/src/standalone-db.ts +17 -6
- package/src/utils.ts +50 -0
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 the
|
|
644
|
+
| `POST /:models` | `403`, and a record **this request inserted** is rolled back — see [Known limitations](#known-limitations) for why the rollback is conditional |
|
|
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,15 +675,78 @@ 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
|
-
|
|
678
|
+
Let the server assign the id and read it back from the response — and read it
|
|
679
|
+
back rather than predicting it, because the value it returns is documented but
|
|
680
|
+
not stable across model kinds: a numeric-id model gets `max + 1` (or, at the
|
|
681
|
+
numeric ceiling, the lowest free integer), and a string-id model gets
|
|
682
|
+
`<model>-<n>`. See breaking change 8.
|
|
683
|
+
|
|
684
|
+
**What a server-assigned id is not.** It is not a secret. On a string-id
|
|
685
|
+
collection it is dense and enumerable from `1`, where previously it inherited
|
|
686
|
+
whatever entropy the last-inserted id happened to carry — a UUID-seeded store
|
|
687
|
+
answered a UUID-derived key. If a collection has **no** `access` config its
|
|
688
|
+
record-level routes are ungated, so the id was the only thing standing between
|
|
689
|
+
an unauthenticated caller and `GET`/`PATCH`/`DELETE` on a record. That was never
|
|
690
|
+
a control and must not become one; configure `access`.
|
|
691
|
+
|
|
692
|
+
**And the id itself is an occupancy signal — on both model kinds.**
|
|
693
|
+
`assignRecordId` reads the whole store, not the caller's filtered view — it
|
|
694
|
+
never sees `state.filter` — so the id it returns is a function of records the
|
|
695
|
+
caller may not be permitted to read. **This applies to numeric-id collections
|
|
696
|
+
as well as string-id ones**, and the conditions differ, so read both:
|
|
697
|
+
|
|
698
|
+
- **String-id collections, always.** The assigned `n` is the smallest positive
|
|
699
|
+
integer whose landing key is free, which tells the caller that every key
|
|
700
|
+
below it is taken, hidden or not.
|
|
701
|
+
- **Numeric-id collections, once one record sits at the numeric ceiling.** The
|
|
702
|
+
normal answer is `max + 1`, which discloses only the maximum. But `max + 1`
|
|
703
|
+
is not representable at or above 2^53, so the walk restarts from `1` (see
|
|
704
|
+
breaking change 8) and the assigned id becomes the smallest free integer —
|
|
705
|
+
the same occupancy predicate, now over arbitrary low keys. Each subsequent
|
|
706
|
+
no-id `POST` names the next free one, so a caller can enumerate the holes in
|
|
707
|
+
a range it cannot read.
|
|
708
|
+
|
|
709
|
+
**A ceiling record reaches a filter-protected collection even though `POST`
|
|
710
|
+
refuses caller ids on one.** Breaking change 3 makes
|
|
711
|
+
`POST /animals {"id": 9007199254740992}` answer `403`, but the same id lands
|
|
712
|
+
through a *relationship write on another collection* —
|
|
713
|
+
`POST /owners` carrying `attributes: { pets: [{ "id": 9007199254740992 }] }`
|
|
714
|
+
creates the animal under that key
|
|
715
|
+
([#207](https://github.com/abofs/stonyx-orm/issues/207), the same channel the
|
|
716
|
+
**Known limitations** re-parenting note describes). So the precondition is
|
|
717
|
+
reachable by an unauthenticated caller on exactly the collections `access`
|
|
718
|
+
exists to protect. Measured on the sample fixture, with every animal hidden by
|
|
719
|
+
the `/animals` predicate and keys 4 and 7 deleted:
|
|
720
|
+
|
|
721
|
+
```
|
|
722
|
+
GET /animals -> 200 [] (nothing visible)
|
|
723
|
+
GET /animals/4 -> 404 (free — indistinguishable from hidden)
|
|
724
|
+
POST /animals {"id":4} -> 403 (breaking change 3)
|
|
725
|
+
POST /owners {... pets:[{"id":9007199254740992}]} -> 200 (#207 plants the ceiling record)
|
|
726
|
+
POST /animals (no id) -> 200 id=4 <- names a hole in the hidden range
|
|
727
|
+
POST /animals (no id) -> 200 id=7 <- and the other one
|
|
728
|
+
POST /animals (no id) -> 200 id=13
|
|
729
|
+
POST /animals (no id) -> 200 id=14
|
|
730
|
+
```
|
|
731
|
+
|
|
732
|
+
Closing this requires the assignment to be filter-aware, which is a change to
|
|
733
|
+
the `access` contract rather than a fix; it is stated here rather than left to
|
|
734
|
+
be discovered. Callers with no function-style filter are unaffected — there are
|
|
735
|
+
no hidden records to disclose.
|
|
621
736
|
|
|
622
737
|
### Identifying the collection
|
|
623
738
|
|
|
624
|
-
**Do not reconstruct the request path
|
|
625
|
-
|
|
626
|
-
|
|
739
|
+
**Do not reconstruct the request path — and since
|
|
740
|
+
[#202](https://github.com/abofs/stonyx-orm/issues/202) you do not have to
|
|
741
|
+
identify the collection at all.** Read `model` from
|
|
742
|
+
[the access context](#the-access-context-second-argument): it is fixed at mount
|
|
743
|
+
time, no request can influence it, and there is nothing left to parse.
|
|
744
|
+
|
|
745
|
+
**Everything below is the record of what happened when this sample did parse
|
|
746
|
+
it.** It is kept as history, not as a recipe — none of these matching strategies
|
|
747
|
+
should be written into a new predicate. Every version of this sample that tried
|
|
748
|
+
to identify the collection from the request target failed **open**, and each
|
|
749
|
+
variant was found only after the previous one was fixed:
|
|
627
750
|
|
|
628
751
|
| # | Variant | Why it fails open |
|
|
629
752
|
|---|---|---|
|
|
@@ -633,13 +756,27 @@ was fixed:
|
|
|
633
756
|
| 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. |
|
|
634
757
|
| 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. |
|
|
635
758
|
|
|
636
|
-
**The fix is not a sixth rule
|
|
637
|
-
|
|
638
|
-
**
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
759
|
+
**The fix is not a sixth rule, and it is not a better string to match.** It is
|
|
760
|
+
to stop identifying the collection at all. That is a statement about
|
|
761
|
+
**identifying the collection**, and it is not a statement about the sample as a
|
|
762
|
+
whole: the `/archived` sub-path rule *is* still a string match, and
|
|
763
|
+
[#228](https://github.com/abofs/stonyx-orm/issues/228) is a sixth spelling that
|
|
764
|
+
gets past it. Sub-path rules are the residue this fix does not cover, which is
|
|
765
|
+
why they must normalise the way the router does.
|
|
766
|
+
|
|
767
|
+
An intermediate revision read **`request.baseUrl`** — the mount Express
|
|
768
|
+
*actually matched*. That closed all five variants: it carries no query string
|
|
769
|
+
(variant 2), it is not mount-relative (variant 1), it already contains the
|
|
770
|
+
configured `ORM_REST_ROUTE` prefix (variant 4 — there is nothing left to derive,
|
|
771
|
+
so `/apiowners` is unconstructible), and it is unaffected by an absolute-form
|
|
772
|
+
target (variant 5). It was still a transport artifact standing in for a
|
|
773
|
+
structural fact, and it is **no longer what the sample does**: the sample reads
|
|
774
|
+
`model`, so variants 1, 2, 4 and 5 are unconstructible against it rather than
|
|
775
|
+
handled. **Variant 3 survives**, in the one string comparison the migration
|
|
776
|
+
leaves behind: the `/archived` sub-path deny folds case but does not decode
|
|
777
|
+
([#228](https://github.com/abofs/stonyx-orm/issues/228)). The table below is
|
|
778
|
+
retained as the measured evidence behind the five variants, not because any of
|
|
779
|
+
these values should be matched on:
|
|
643
780
|
|
|
644
781
|
| request | `request.url` | `request.originalUrl` | `request.baseUrl` | `request.path` |
|
|
645
782
|
|---|---|---|---|---|
|
|
@@ -650,21 +787,35 @@ unconstructible), and it is unaffected by an absolute-form target (variant 5).
|
|
|
650
787
|
| `GET http://anything.example/owners/angela` | `http://anything.example/angela` | `http://anything.example/owners/angela` | `/owners` | `/angela` |
|
|
651
788
|
| `GET /api/animals/22` (`ORM_REST_ROUTE=/api`) | `/22` | `/api/animals/22` | `/api/animals` | `/22` |
|
|
652
789
|
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
790
|
+
**One read of argument one survives, and it must: `request.path`.** It is
|
|
791
|
+
mount-relative and query-free, and it is for rules that distinguish **sub-paths**
|
|
792
|
+
beneath the mount — as the `/archived` deny in the sample above does. The context
|
|
793
|
+
names which model and which verb, **not which route**, so that deny *cannot be
|
|
794
|
+
expressed from the context alone*, and a context-only rewrite would silently turn
|
|
795
|
+
it into an allow.
|
|
796
|
+
|
|
797
|
+
**Normalise the way the router that dispatched the request does — and
|
|
798
|
+
case-folding alone does not.** A matcher stricter than the router can be stepped
|
|
799
|
+
around, so the sample lower-cases before comparing (the router matched
|
|
800
|
+
case-insensitively). That closes the case gap and **it is not the whole rule**:
|
|
801
|
+
Express sets `request.path` from the **raw, undecoded** pathname while the router
|
|
802
|
+
**decodes** `:id`, so `GET /owners/%61rchived` reaches a `path === '/archived'`
|
|
803
|
+
comparison as `/%61rchived`, walks past the deny, and is dispatched as the record
|
|
804
|
+
`archived`. That gap is live in the sample above and is tracked as
|
|
805
|
+
[#228](https://github.com/abofs/stonyx-orm/issues/228) — **do not read the
|
|
806
|
+
`.toLowerCase()` there as a complete normalisation recipe.** Record ids are
|
|
807
|
+
case-sensitive and must be compared at their real case.
|
|
808
|
+
|
|
809
|
+
**Fail closed on anything you cannot identify — on *either* argument.**
|
|
810
|
+
`String(request.originalUrl ?? '')` was once added here to stop a `TypeError`,
|
|
811
|
+
and it traded fail-closed for fail-**open**: an empty string matched no
|
|
812
|
+
collection, so `access()` fell through to the permission array and granted full
|
|
813
|
+
CRUD. The same rule applies to the context — the sample returns `false` for an
|
|
814
|
+
absent `model` rather than falling through. Since #202 the guard and the read can
|
|
815
|
+
sit on **different objects**, and a guard on argument two does not protect a read
|
|
816
|
+
of argument one: the sample therefore also returns `false` when `request.path` is
|
|
817
|
+
absent or is not a string, rather than letting `?? ''` fall through to the
|
|
818
|
+
per-record filter. An input you cannot identify must **deny**.
|
|
668
819
|
|
|
669
820
|
### Known limitations
|
|
670
821
|
|
|
@@ -687,11 +838,14 @@ sub-paths beneath the mount, as the `/archived` deny above does.
|
|
|
687
838
|
see [The access context](#the-access-context-second-argument):
|
|
688
839
|
`Orm.instance.getAccess(modelName)` makes another model's predicate
|
|
689
840
|
**reachable**, and `context.model` makes a **model-correct answer possible** —
|
|
690
|
-
possible, not guaranteed: the resolved predicate has to read the context
|
|
691
|
-
|
|
692
|
-
([#
|
|
693
|
-
|
|
694
|
-
|
|
841
|
+
possible, not guaranteed: the resolved predicate has to read the context. The
|
|
842
|
+
sample shipped with this repo now does
|
|
843
|
+
([#222](https://github.com/abofs/stonyx-orm/issues/222)), so
|
|
844
|
+
`getAccess('animal')` answers with the animal filter; a predicate that ignores
|
|
845
|
+
the second argument still answers about the collection the request is
|
|
846
|
+
addressed to, and the boot-time warning that surfaces one is
|
|
847
|
+
[#221](https://github.com/abofs/stonyx-orm/issues/221). **The mechanism
|
|
848
|
+
exists; the ORM does not yet use it on this path.** The re-parenting write above is still
|
|
695
849
|
**not refused** — that enforcement is
|
|
696
850
|
[#196](https://github.com/abofs/stonyx-orm/issues/196) and
|
|
697
851
|
[#207](https://github.com/abofs/stonyx-orm/issues/207), which were blocked on
|
|
@@ -743,9 +897,10 @@ sub-paths beneath the mount, as the `/archived` deny above does.
|
|
|
743
897
|
transform output differs from its lookup key is the same defect. Filtered
|
|
744
898
|
collections are unaffected — breaking change 3 refuses any client-supplied id
|
|
745
899
|
— so this reaches consumers with **no** function-style filter. Tracked as
|
|
746
|
-
[#205](https://github.com/abofs/stonyx-orm/issues/205)
|
|
747
|
-
[#203](https://github.com/abofs/stonyx-orm/issues/203)
|
|
748
|
-
|
|
900
|
+
[#205](https://github.com/abofs/stonyx-orm/issues/205). Its sibling
|
|
901
|
+
[#203](https://github.com/abofs/stonyx-orm/issues/203) — a **server-assigned**
|
|
902
|
+
id landing on an occupied slot — is **fixed**; see breaking change 8. #205 is
|
|
903
|
+
the client-supplied half and is still open.
|
|
749
904
|
- **`context.record` is `undefined` for an after-`create` hook when a string-id
|
|
750
905
|
model is given a numeric-looking id.** The post-create lookup uses the same id
|
|
751
906
|
coercion as every other surface, which resolves `'9107'` to the number `9107`,
|
|
@@ -755,15 +910,18 @@ sub-paths beneath the mount, as the `/archived` deny above does.
|
|
|
755
910
|
[#209](https://github.com/abofs/stonyx-orm/issues/209).
|
|
756
911
|
- **A denied `POST` rolls back only a record it *inserted*.** The rollback
|
|
757
912
|
requires the store to have grown, because removing by id alone is a write
|
|
758
|
-
primitive keyed by a caller-supplied value.
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
last-*inserted* + 1,
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
913
|
+
primitive keyed by a caller-supplied value. **The reachability condition this
|
|
914
|
+
bullet used to state is gone**: it was
|
|
915
|
+
[#203](https://github.com/abofs/stonyx-orm/issues/203) — `assignRecordId`
|
|
916
|
+
returned last-*inserted* + 1, so a server-assigned id could land on an
|
|
917
|
+
occupied slot and `createRecord` would update it in place — and #203 is fixed
|
|
918
|
+
(breaking change 8). A server-assigned create can no longer overwrite, so on a
|
|
919
|
+
collection whose only id channel is `createHandler` this guard has no
|
|
920
|
+
observable effect today. It is kept because a caller-supplied id reaching
|
|
921
|
+
`createRecord` from another route — a relationship write,
|
|
922
|
+
[#207](https://github.com/abofs/stonyx-orm/issues/207) — puts the condition
|
|
923
|
+
back, and without the guard a denied `403` would delete a record the request
|
|
924
|
+
did not create.
|
|
767
925
|
|
|
768
926
|
### Breaking changes
|
|
769
927
|
|
|
@@ -824,6 +982,64 @@ they are recorded here.
|
|
|
824
982
|
population breaking changes 3 and 4 explicitly exempt. If you were relying on
|
|
825
983
|
a hex-shaped or whitespace-padded id creating a second record, it never did.
|
|
826
984
|
|
|
985
|
+
8. **Server-assigned ids change value on string-id models, numeric ids stop
|
|
986
|
+
being monotonic at the numeric ceiling, and the create route gains a
|
|
987
|
+
`409`.** Three consumer-visible changes from
|
|
988
|
+
[#203](https://github.com/abofs/stonyx-orm/issues/203).
|
|
989
|
+
|
|
990
|
+
**The value.** A `POST` with no `id` against a model declaring
|
|
991
|
+
`id = attr('string')` previously produced the *last-inserted* id with `1`
|
|
992
|
+
concatenated onto it — an owner store holding `['gina', 'bob']` answered
|
|
993
|
+
`'bob1'`. It now answers `'owner-1'`: the model name, a hyphen, and the
|
|
994
|
+
lowest positive integer whose landing key is free. **No test in this repo
|
|
995
|
+
pinned the old value**, so a consumer relying on it gets no failing test, no
|
|
996
|
+
deprecation and no other signal — which is why it is recorded here. Numeric
|
|
997
|
+
id models (`id = attr('number')`, the default) are unaffected in shape: they
|
|
998
|
+
still get an integer, but it is now the **maximum** existing id plus one
|
|
999
|
+
rather than the last-inserted id plus one, which is the defect #203 is about.
|
|
1000
|
+
They are **not** unaffected in *sequence* — see the monotonicity half below.
|
|
1001
|
+
|
|
1002
|
+
The value is deliberately **not** numeric-looking, and that is not cosmetic.
|
|
1003
|
+
Every id-bearing surface resolves a numeric-looking string id to a **number**
|
|
1004
|
+
(`GET /owners/1` looks up `1`), while a string-id model files its records
|
|
1005
|
+
under the **string** key `'1'`. A server-assigned `'1'` would therefore be a
|
|
1006
|
+
record that was created successfully and could not be fetched, updated or
|
|
1007
|
+
deleted by id, and whose after-`create` hook received
|
|
1008
|
+
`context.record === undefined`
|
|
1009
|
+
([#209](https://github.com/abofs/stonyx-orm/issues/209)).
|
|
1010
|
+
|
|
1011
|
+
**Numeric ids are no longer monotonic, and deleted ids can be re-issued.**
|
|
1012
|
+
The precondition is narrow but it is reachable, and there is no signal when
|
|
1013
|
+
it is met: **one record filed at or above 2^53** (`9007199254740992`). `max
|
|
1014
|
+
+ 1` is not representable there, so assignment restarts from `1` and walks
|
|
1015
|
+
up to the lowest free key — which means the id of a *deleted* record is
|
|
1016
|
+
handed to the next `POST`. Both `dev` and every prior release were strictly
|
|
1017
|
+
monotonic and never re-issued a numeric id, so a consumer that relied on
|
|
1018
|
+
that — audit rows, cursors, cached authorization decisions, external
|
|
1019
|
+
references keyed on the id — now has a stale reference that silently points
|
|
1020
|
+
at a **different record, created by a different caller**, rather than at a
|
|
1021
|
+
deleted one. Nothing fails; the reference simply resolves to the wrong
|
|
1022
|
+
record.
|
|
1023
|
+
|
|
1024
|
+
The restart is deliberate and is not itself optional: without it, one record
|
|
1025
|
+
at the ceiling made every subsequent server-assigned create on that
|
|
1026
|
+
collection fail permanently. Re-use is the cost of keeping the collection
|
|
1027
|
+
writable. **If you need monotonic ids, assign them yourself** rather than
|
|
1028
|
+
letting the server assign, and note that a ceiling record can be planted by
|
|
1029
|
+
an unauthenticated caller — see *And the id itself is an occupancy signal*
|
|
1030
|
+
under [Filter functions](#filter-functions) for the reachability path.
|
|
1031
|
+
String-id models are unaffected by this half: their keys are
|
|
1032
|
+
`<model>-<n>` and were never monotonic over an integer sequence.
|
|
1033
|
+
|
|
1034
|
+
**The status.** `POST /{collection}` can now answer `409` for a reason other
|
|
1035
|
+
than a duplicate id: the server could not derive a free id. That requires a
|
|
1036
|
+
**non-injective** id transform — one that maps distinct candidates onto the
|
|
1037
|
+
same store key, such as `boolean`, or anything you registered on
|
|
1038
|
+
`Orm.instance.transforms` and named as an id type. It is a configuration
|
|
1039
|
+
fault rather than a request fault; the message is logged through
|
|
1040
|
+
`stonyx/log`. Previously this case threw out of the handler and express
|
|
1041
|
+
answered `500` with a stack trace.
|
|
1042
|
+
|
|
827
1043
|
### Include Parameter (Sideloading Relationships)
|
|
828
1044
|
|
|
829
1045
|
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.
|