@atscript/moost-odata 0.0.1 → 0.0.3

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 CHANGED
@@ -49,8 +49,8 @@ pnpm add @atscript/moost-odata @atscript/db-odata @atscript/odata \
49
49
  moost @moostjs/event-http @wooksjs/event-core @wooksjs/event-http @wooksjs/http-body
50
50
  ```
51
51
 
52
- Needs `@atscript/db` and `@atscript/moost-db` 0.1.200 or newer, `@atscript/typescript` 0.2.25 or
53
- newer, Moost 0.7.12 or newer and Wooks 0.8.8 or newer.
52
+ Needs `@atscript/db` and `@atscript/moost-db` 0.1.201 or newer, `@atscript/typescript` 0.2.26 or
53
+ newer, Moost 0.7.13 or newer and Wooks 0.8.8 or newer.
54
54
 
55
55
  The models come from the generator of `@atscript/odata`: see the
56
56
  [installation guide](https://odata.atscript.dev/guide/installation). Every export is documented in the
@@ -306,12 +306,16 @@ await app.init();
306
306
  the technical user may read (with `own`, a set of the service is served whole). With Aooth, put
307
307
  `@ArbacResource` on `base` (the class name, the fallback, repeats across services); ARBAC row
308
308
  and field scopes do not apply.
309
- - **One route per path.** The helper throws for a route it already made for the space (a second
310
- call with the same prefix, or references that differ only by `.` / `..` segments): Moost's
311
- router keeps a second handler on one path without a word and runs it when the first one throws,
312
- so the twin would answer what the first one's guard refuses. Two spaces with one service name
313
- and one prefix make the same routes, which the helper cannot see: a guard bypass and reads
314
- across spaces. Give each space its own name, and create the adapter with
309
+ - **One route per path.** The helper throws for a route made twice for the space (a second call
310
+ with the same prefix and a base of another name, or references that differ only by `.` / `..`
311
+ segments): Moost's router keeps a second handler on one path without a word and runs it when
312
+ the first one throws, so the twin would answer what the first one's guard refuses. A call made
313
+ again with a base of the same name makes its routes again, as a dev server's reload does
314
+ (`@moostjs/vite` runs the entry again over the space it kept). Bases are told apart by name (a
315
+ class without a name only as itself), so give the classes a factory makes distinct names;
316
+ `disableDuplicatePath` is the guard that refuses duplicates at `app.init()`. Two spaces with one
317
+ service name and one prefix make the same routes, which the helper cannot see: a guard bypass
318
+ and reads across spaces. Give each space its own name, and create the adapter with
315
319
  `new MoostHttp({ router: { disableDuplicatePath: true } })`, which makes `app.init()` refuse any
316
320
  duplicate path.
317
321
  - **Limits.** Only direct `@ui.valueHelp` targets of the `own` types, no `@db.rel.FK` target
@@ -411,11 +415,11 @@ The adapter reports a failure of the service as one of atscript-db's store-failu
411
415
  atscript-db 0.1.197), which moost-db answers itself, on any controller over the space, in its
412
416
  envelope (`{ message, statusCode, code, errors }`, the code also on the one entry):
413
417
 
414
- | The service | Answer | `code` |
415
- | ----------------------------------------------------------------------------------------------------------------------------------- | ------ | ----------------- |
416
- | `5xx` but `501`, no answer, `401` / `403` (the server's credentials), an HTML login page, a write without a session, another status | `502` | `STORE_FAILED` |
417
- | timed out, or the call was aborted (`callTimeout`); `504` | `504` | `STORE_TIMEOUT` |
418
- | `429` | `429` | `STORE_THROTTLED` |
418
+ | The service | Answer | `code` |
419
+ | ------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | ----------------- |
420
+ | `5xx` but `501`, no answer, `401` / `403` (the server's credentials), an HTML login page, a redirected write, a write without a session, another status | `502` | `STORE_FAILED` |
421
+ | timed out, or the call was aborted (`callTimeout`); `504` | `504` | `STORE_TIMEOUT` |
422
+ | `429` | `429` | `STORE_THROTTLED` |
419
423
 
420
424
  - Refused credentials are always the server's fault: the server calls the service with
421
425
  credentials it was given, and the caller can do nothing about them.
@@ -465,7 +469,9 @@ The write endpoints are moost-db's, over the writes of [`@atscript/db-odata`](ht
465
469
  overwrites whatever changed since the caller read the entity, without a conflict. Where the
466
470
  service requires `If-Match`, the adapter reads the current ETag right before the write: that
467
471
  satisfies the service's If-Match requirement, nothing more. A change in the moment between that
468
- read and the write has both repeated, three attempts in all, then `503` `SERIALIZATION_FAILURE`. An atscript-ui edit form (0.1.190
472
+ read and the write has both repeated, three attempts in all, then `503` `SERIALIZATION_FAILURE`.
473
+ A set that declares no version token gets no read and no repeat: a `412` or `428` to its write
474
+ is `502` `STORE_FAILED`, entry code `PRECONDITION_REQUIRED`. An atscript-ui edit form (0.1.190
469
475
  and later) sends the token of the row it loaded, so its save detects conflicts.
470
476
  - **Sessions.** A write needs the session the space keeps for its credentials
471
477
  ([Sessions](#sessions)).
@@ -522,7 +528,7 @@ takes moost-db's `queryTarget` (atscript-ui's "all matching rows", at most 50).
522
528
  writes, it sends the version token the row load read right before it as `If-Match`; a `412` (the
523
529
  row changed in between) answers `409` `VERSION_MISMATCH` with the current token. A function, and
524
530
  any call on the collection, sends `If-Match: *` on a set with a version token (SAP CAP refuses a
525
- bound call without one). An operation
531
+ bound call without one); a `412` to it means the row is gone, `404` `NOT_FOUND`. An operation
526
532
  the live service no longer has answers `404`, one it changed so that the build no longer fits
527
533
  `500`, after your guards and before any call, and both are left out of `/meta`. If you override
528
534
  `prepareRequest`, call `await super.prepareRequest(ctx)` first. See
package/dist/index.cjs CHANGED
@@ -298,7 +298,6 @@ async function rowsAnswer(readable, rows, answer, stale) {
298
298
  const { failed: _failed, ...ran } = answer;
299
299
  return {
300
300
  ...summary,
301
- failed: summary.failed,
302
301
  ...ran
303
302
  };
304
303
  }
@@ -534,10 +533,23 @@ var ODataTableController = class extends _atscript_moost_db.AsDbController {
534
533
  const SEGMENT = /^[A-Za-z0-9_.~-]+$/;
535
534
  const metaOf = (type) => type.metadata;
536
535
  /**
537
- * The routes made for each space. Moost takes a second handler on one path without a word, and
538
- * runs it when the first one throws: a request its guard refuses would be answered by the twin.
536
+ * The routes made for each space, with the base each was made with. Moost takes a second handler
537
+ * on one path without a word, and runs it when the first one throws: a request its guard refuses
538
+ * would be answered by the twin. A route made again with the same base passes: a dev server that
539
+ * reloads the app (`@moostjs/vite`) runs the entry again over the space its unchanged module
540
+ * kept, the base made anew when its module changed (hence {@link sameBase}). A twin of one base
541
+ * in one app answers nothing the first one's guard refuses, but Moost runs it after any throw, so
542
+ * a stateful guard (a rate limit) counts twice and an upstream failure is read twice;
543
+ * `disableDuplicatePath` refuses it at `app.init()`.
539
544
  */
540
545
  const routesMade = /* @__PURE__ */ new WeakMap();
546
+ /**
547
+ * One base: the same class, or one of the same name (a reload makes it anew); a class without a
548
+ * name only as itself.
549
+ */
550
+ const sameBase = (a, b) => a === b || a.name !== "" && a.name === b.name;
551
+ /** A base as an error names it. */
552
+ const nameOf = (base) => base.name || "(a class without a name)";
541
553
  /** What tells an entity set apart: its service (`@db.space`), its value-help service, its name. */
542
554
  function setKey(type) {
543
555
  const metadata = metaOf(type);
@@ -610,15 +622,21 @@ function checkBase(base) {
610
622
  * A set with a name that is no plain route segment (`[A-Za-z0-9_.~-]`) gets no route, with a
611
623
  * warning on the console.
612
624
  *
613
- * Each route is made once per space: a second call with the same prefix throws, as do two
614
- * value-help services whose references differ only by `.` or `..` segments. Two spaces with one
615
- * service name and one prefix would make the same routes, which the helper cannot see: give each
616
- * space its own name, and let `new MoostHttp({ router: { disableDuplicatePath: true } })` make
617
- * `app.init()` refuse any path registered twice.
625
+ * Each route has one base per space: a second call with the same prefix and a base of another
626
+ * name throws, as do two value-help services whose references differ only by `.` or `..`
627
+ * segments. A call made again with a base of the same name makes its routes again, as a dev
628
+ * server's reload does (`@moostjs/vite` runs the entry again over the space it kept); a base
629
+ * without a name counts only as itself. Bases are told apart by name, so give the classes a
630
+ * factory makes distinct names; `disableDuplicatePath` is the guard that refuses duplicates at
631
+ * `app.init()`. Two spaces with one service name and one prefix would make the same routes, which
632
+ * the helper cannot see: give each space its own name, and let
633
+ * `new MoostHttp({ router: { disableDuplicatePath: true } })` make `app.init()` refuse any path
634
+ * registered twice.
618
635
  *
619
636
  * @throws Error before the space is connected, for a space over an engine at hand (it has no
620
637
  * types), for a `base` that is no `ODataReadableController` or misses `@Inherit()`, and for a
621
- * route already made for the space.
638
+ * route made twice for the space (by a base of another name, or by references that differ only
639
+ * by `.` or `..` segments).
622
640
  */
623
641
  function valueHelpControllers(space, options) {
624
642
  const { prefix, base = ODataReadableController, own } = options;
@@ -659,10 +677,14 @@ function valueHelpControllers(space, options) {
659
677
  route: [root, ...segments].filter(Boolean).join("/")
660
678
  }];
661
679
  });
662
- const made = new Set(routesMade.get(space));
680
+ const made = new Map(routesMade.get(space));
681
+ const now = /* @__PURE__ */ new Set();
663
682
  for (const { route } of planned) {
664
- if (made.has(route)) throw new Error(`valueHelpControllers: the route "${route}" is made twice for this space (a second call with the same prefix, or value-help services whose references differ only by "." or ".." segments): a request one handler's guard refuses would be answered by the other`);
665
- made.add(route);
683
+ if (now.has(route)) throw new Error(`valueHelpControllers: the route "${route}" is made twice for this space (value-help services whose references differ only by "." or ".." segments)`);
684
+ const earlier = made.get(route);
685
+ if (earlier !== void 0 && !sameBase(earlier, base)) throw new Error(`valueHelpControllers: the route "${route}" is made twice for this space, with the bases ${nameOf(earlier)} and ${nameOf(base)} (a second call with the same prefix): a request one base's guards refuse would be answered through the other`);
686
+ now.add(route);
687
+ made.set(route, base);
666
688
  }
667
689
  routesMade.set(space, made);
668
690
  return planned.map(({ type, entitySet, route }) => {
package/dist/index.d.cts CHANGED
@@ -386,15 +386,21 @@ interface ValueHelpControllerOptions {
386
386
  * A set with a name that is no plain route segment (`[A-Za-z0-9_.~-]`) gets no route, with a
387
387
  * warning on the console.
388
388
  *
389
- * Each route is made once per space: a second call with the same prefix throws, as do two
390
- * value-help services whose references differ only by `.` or `..` segments. Two spaces with one
391
- * service name and one prefix would make the same routes, which the helper cannot see: give each
392
- * space its own name, and let `new MoostHttp({ router: { disableDuplicatePath: true } })` make
393
- * `app.init()` refuse any path registered twice.
389
+ * Each route has one base per space: a second call with the same prefix and a base of another
390
+ * name throws, as do two value-help services whose references differ only by `.` or `..`
391
+ * segments. A call made again with a base of the same name makes its routes again, as a dev
392
+ * server's reload does (`@moostjs/vite` runs the entry again over the space it kept); a base
393
+ * without a name counts only as itself. Bases are told apart by name, so give the classes a
394
+ * factory makes distinct names; `disableDuplicatePath` is the guard that refuses duplicates at
395
+ * `app.init()`. Two spaces with one service name and one prefix would make the same routes, which
396
+ * the helper cannot see: give each space its own name, and let
397
+ * `new MoostHttp({ router: { disableDuplicatePath: true } })` make `app.init()` refuse any path
398
+ * registered twice.
394
399
  *
395
400
  * @throws Error before the space is connected, for a space over an engine at hand (it has no
396
401
  * types), for a `base` that is no `ODataReadableController` or misses `@Inherit()`, and for a
397
- * route already made for the space.
402
+ * route made twice for the space (by a base of another name, or by references that differ only
403
+ * by `.` or `..` segments).
398
404
  */
399
405
  declare function valueHelpControllers(space: ODataSpace, options: ValueHelpControllerOptions): Function[];
400
406
  //#endregion
package/dist/index.d.mts CHANGED
@@ -387,15 +387,21 @@ interface ValueHelpControllerOptions {
387
387
  * A set with a name that is no plain route segment (`[A-Za-z0-9_.~-]`) gets no route, with a
388
388
  * warning on the console.
389
389
  *
390
- * Each route is made once per space: a second call with the same prefix throws, as do two
391
- * value-help services whose references differ only by `.` or `..` segments. Two spaces with one
392
- * service name and one prefix would make the same routes, which the helper cannot see: give each
393
- * space its own name, and let `new MoostHttp({ router: { disableDuplicatePath: true } })` make
394
- * `app.init()` refuse any path registered twice.
390
+ * Each route has one base per space: a second call with the same prefix and a base of another
391
+ * name throws, as do two value-help services whose references differ only by `.` or `..`
392
+ * segments. A call made again with a base of the same name makes its routes again, as a dev
393
+ * server's reload does (`@moostjs/vite` runs the entry again over the space it kept); a base
394
+ * without a name counts only as itself. Bases are told apart by name, so give the classes a
395
+ * factory makes distinct names; `disableDuplicatePath` is the guard that refuses duplicates at
396
+ * `app.init()`. Two spaces with one service name and one prefix would make the same routes, which
397
+ * the helper cannot see: give each space its own name, and let
398
+ * `new MoostHttp({ router: { disableDuplicatePath: true } })` make `app.init()` refuse any path
399
+ * registered twice.
395
400
  *
396
401
  * @throws Error before the space is connected, for a space over an engine at hand (it has no
397
402
  * types), for a `base` that is no `ODataReadableController` or misses `@Inherit()`, and for a
398
- * route already made for the space.
403
+ * route made twice for the space (by a base of another name, or by references that differ only
404
+ * by `.` or `..` segments).
399
405
  */
400
406
  declare function valueHelpControllers(space: ODataSpace, options: ValueHelpControllerOptions): Function[];
401
407
  //#endregion
package/dist/index.mjs CHANGED
@@ -297,7 +297,6 @@ async function rowsAnswer(readable, rows, answer, stale) {
297
297
  const { failed: _failed, ...ran } = answer;
298
298
  return {
299
299
  ...summary,
300
- failed: summary.failed,
301
300
  ...ran
302
301
  };
303
302
  }
@@ -533,10 +532,23 @@ Inherit()(ODataTableController);
533
532
  const SEGMENT = /^[A-Za-z0-9_.~-]+$/;
534
533
  const metaOf = (type) => type.metadata;
535
534
  /**
536
- * The routes made for each space. Moost takes a second handler on one path without a word, and
537
- * runs it when the first one throws: a request its guard refuses would be answered by the twin.
535
+ * The routes made for each space, with the base each was made with. Moost takes a second handler
536
+ * on one path without a word, and runs it when the first one throws: a request its guard refuses
537
+ * would be answered by the twin. A route made again with the same base passes: a dev server that
538
+ * reloads the app (`@moostjs/vite`) runs the entry again over the space its unchanged module
539
+ * kept, the base made anew when its module changed (hence {@link sameBase}). A twin of one base
540
+ * in one app answers nothing the first one's guard refuses, but Moost runs it after any throw, so
541
+ * a stateful guard (a rate limit) counts twice and an upstream failure is read twice;
542
+ * `disableDuplicatePath` refuses it at `app.init()`.
538
543
  */
539
544
  const routesMade = /* @__PURE__ */ new WeakMap();
545
+ /**
546
+ * One base: the same class, or one of the same name (a reload makes it anew); a class without a
547
+ * name only as itself.
548
+ */
549
+ const sameBase = (a, b) => a === b || a.name !== "" && a.name === b.name;
550
+ /** A base as an error names it. */
551
+ const nameOf = (base) => base.name || "(a class without a name)";
540
552
  /** What tells an entity set apart: its service (`@db.space`), its value-help service, its name. */
541
553
  function setKey(type) {
542
554
  const metadata = metaOf(type);
@@ -609,15 +621,21 @@ function checkBase(base) {
609
621
  * A set with a name that is no plain route segment (`[A-Za-z0-9_.~-]`) gets no route, with a
610
622
  * warning on the console.
611
623
  *
612
- * Each route is made once per space: a second call with the same prefix throws, as do two
613
- * value-help services whose references differ only by `.` or `..` segments. Two spaces with one
614
- * service name and one prefix would make the same routes, which the helper cannot see: give each
615
- * space its own name, and let `new MoostHttp({ router: { disableDuplicatePath: true } })` make
616
- * `app.init()` refuse any path registered twice.
624
+ * Each route has one base per space: a second call with the same prefix and a base of another
625
+ * name throws, as do two value-help services whose references differ only by `.` or `..`
626
+ * segments. A call made again with a base of the same name makes its routes again, as a dev
627
+ * server's reload does (`@moostjs/vite` runs the entry again over the space it kept); a base
628
+ * without a name counts only as itself. Bases are told apart by name, so give the classes a
629
+ * factory makes distinct names; `disableDuplicatePath` is the guard that refuses duplicates at
630
+ * `app.init()`. Two spaces with one service name and one prefix would make the same routes, which
631
+ * the helper cannot see: give each space its own name, and let
632
+ * `new MoostHttp({ router: { disableDuplicatePath: true } })` make `app.init()` refuse any path
633
+ * registered twice.
617
634
  *
618
635
  * @throws Error before the space is connected, for a space over an engine at hand (it has no
619
636
  * types), for a `base` that is no `ODataReadableController` or misses `@Inherit()`, and for a
620
- * route already made for the space.
637
+ * route made twice for the space (by a base of another name, or by references that differ only
638
+ * by `.` or `..` segments).
621
639
  */
622
640
  function valueHelpControllers(space, options) {
623
641
  const { prefix, base = ODataReadableController, own } = options;
@@ -658,10 +676,14 @@ function valueHelpControllers(space, options) {
658
676
  route: [root, ...segments].filter(Boolean).join("/")
659
677
  }];
660
678
  });
661
- const made = new Set(routesMade.get(space));
679
+ const made = new Map(routesMade.get(space));
680
+ const now = /* @__PURE__ */ new Set();
662
681
  for (const { route } of planned) {
663
- if (made.has(route)) throw new Error(`valueHelpControllers: the route "${route}" is made twice for this space (a second call with the same prefix, or value-help services whose references differ only by "." or ".." segments): a request one handler's guard refuses would be answered by the other`);
664
- made.add(route);
682
+ if (now.has(route)) throw new Error(`valueHelpControllers: the route "${route}" is made twice for this space (value-help services whose references differ only by "." or ".." segments)`);
683
+ const earlier = made.get(route);
684
+ if (earlier !== void 0 && !sameBase(earlier, base)) throw new Error(`valueHelpControllers: the route "${route}" is made twice for this space, with the bases ${nameOf(earlier)} and ${nameOf(base)} (a second call with the same prefix): a request one base's guards refuse would be answered through the other`);
685
+ now.add(route);
686
+ made.set(route, base);
665
687
  }
666
688
  routesMade.set(space, made);
667
689
  return planned.map(({ type, entitySet, route }) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/moost-odata",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Moost integration for serving OData services as Atscript DB controllers.",
5
5
  "keywords": [
6
6
  "atscript",
@@ -36,34 +36,34 @@
36
36
  "access": "public"
37
37
  },
38
38
  "dependencies": {
39
- "@atscript/db-odata": "^0.0.1",
40
- "@atscript/odata": "^0.0.1"
39
+ "@atscript/db-odata": "^0.0.3",
40
+ "@atscript/odata": "^0.0.3"
41
41
  },
42
42
  "devDependencies": {
43
- "@atscript/core": "^0.2.25",
44
- "@atscript/db": "^0.1.200",
45
- "@atscript/db-client": "^0.1.200",
46
- "@atscript/moost-db": "^0.1.200",
47
- "@atscript/typescript": "^0.2.25",
48
- "@moostjs/event-http": "^0.7.12",
43
+ "@atscript/core": "^0.2.26",
44
+ "@atscript/db": "^0.1.201",
45
+ "@atscript/db-client": "^0.1.201",
46
+ "@atscript/moost-db": "^0.1.201",
47
+ "@atscript/typescript": "^0.2.26",
48
+ "@moostjs/event-http": "^0.7.13",
49
49
  "@uniqu/core": "^0.2.2",
50
50
  "@wooksjs/event-core": "^0.8.8",
51
51
  "@wooksjs/event-http": "^0.8.8",
52
52
  "@wooksjs/http-body": "^0.8.8",
53
- "moost": "^0.7.12",
53
+ "moost": "^0.7.13",
54
54
  "typescript": "^5",
55
- "unplugin-atscript": "^0.2.25"
55
+ "unplugin-atscript": "^0.2.26"
56
56
  },
57
57
  "peerDependencies": {
58
- "@atscript/db": "^0.1.200",
59
- "@atscript/moost-db": "^0.1.200",
60
- "@atscript/typescript": "^0.2.25",
61
- "@moostjs/event-http": "^0.7.12",
58
+ "@atscript/db": "^0.1.201",
59
+ "@atscript/moost-db": "^0.1.201",
60
+ "@atscript/typescript": "^0.2.26",
61
+ "@moostjs/event-http": "^0.7.13",
62
62
  "@uniqu/core": "^0.2.2",
63
63
  "@wooksjs/event-core": "^0.8.8",
64
64
  "@wooksjs/event-http": "^0.8.8",
65
65
  "@wooksjs/http-body": "^0.8.8",
66
- "moost": "^0.7.12"
66
+ "moost": "^0.7.13"
67
67
  },
68
68
  "scripts": {
69
69
  "build": "vp pack",