@atscript/moost-odata 0.0.2 → 0.0.4
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 +13 -9
- package/dist/client.cjs +51 -0
- package/dist/client.d.cts +43 -0
- package/dist/client.d.mts +43 -0
- package/dist/client.mjs +50 -0
- package/dist/index.cjs +34 -12
- package/dist/index.d.cts +13 -7
- package/dist/index.d.mts +12 -6
- package/dist/index.mjs +34 -12
- package/package.json +33 -17
package/README.md
CHANGED
|
@@ -45,12 +45,12 @@ Typed at build time, live at runtime: the controllers are declared over the gene
|
|
|
45
45
|
|
|
46
46
|
```bash
|
|
47
47
|
pnpm add @atscript/moost-odata @atscript/db-odata @atscript/odata \
|
|
48
|
-
@atscript/moost-db @atscript/db @atscript/typescript @uniqu/core \
|
|
48
|
+
@atscript/moost-db @atscript/db @atscript/core @atscript/typescript @uniqu/core \
|
|
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.
|
|
53
|
-
newer, Moost 0.7.
|
|
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
|
|
310
|
-
|
|
311
|
-
router keeps a second handler on one path without a word and runs it when
|
|
312
|
-
so the twin would answer what the first one's guard refuses.
|
|
313
|
-
|
|
314
|
-
|
|
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
|
package/dist/client.cjs
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _atscript_db_client = require("@atscript/db-client");
|
|
3
|
+
//#region src/client.ts
|
|
4
|
+
/**
|
|
5
|
+
* The browser's caller of a Moost server's operations controller, the leaf you declare over the
|
|
6
|
+
* generated operations base (`@Controller("api/sales/ops")`): `baseUrl` is that controller's
|
|
7
|
+
* path. It ships no OData and no server code, only `fetch`:
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { operationsClient } from "@atscript/moost-odata/client";
|
|
11
|
+
* import { ops } from "./odata/sales.model.gen";
|
|
12
|
+
*
|
|
13
|
+
* const salesOps = operationsClient("/api/sales/ops");
|
|
14
|
+
* const { value } = await salesOps.call(ops.GetPrice, { Material: "M-100" });
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* Importing `ops` costs the page the handles only: the bundler drops the model they sit next to.
|
|
18
|
+
*/
|
|
19
|
+
function operationsClient(baseUrl, options = {}) {
|
|
20
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
21
|
+
return { async call(operation, params) {
|
|
22
|
+
if (operation.entitySet !== void 0) throw new Error(`operationsClient: "${operation.operation}" is bound to "${operation.entitySet}"; the operations controller serves unbound operations only, a bound one is a db action of its table's controller`);
|
|
23
|
+
const url = `${base}/${encodeURIComponent(operation.operation)}`;
|
|
24
|
+
const init = {
|
|
25
|
+
method: "POST",
|
|
26
|
+
headers: {
|
|
27
|
+
...typeof options.headers === "function" ? await options.headers() : options.headers,
|
|
28
|
+
"Content-Type": "application/json"
|
|
29
|
+
},
|
|
30
|
+
body: JSON.stringify(params ?? {})
|
|
31
|
+
};
|
|
32
|
+
let res;
|
|
33
|
+
try {
|
|
34
|
+
res = await (options.fetch ?? fetch)(url, init);
|
|
35
|
+
} catch (cause) {
|
|
36
|
+
throw new _atscript_db_client.TransportError("POST", url, cause instanceof Error ? cause.message : String(cause), cause);
|
|
37
|
+
}
|
|
38
|
+
if (!res.ok) {
|
|
39
|
+
const body = await res.json().catch(() => ({
|
|
40
|
+
message: res.statusText || `HTTP ${res.status}`,
|
|
41
|
+
statusCode: res.status
|
|
42
|
+
}));
|
|
43
|
+
throw new _atscript_db_client.ClientError(res.status, body);
|
|
44
|
+
}
|
|
45
|
+
return res.json().catch((cause) => {
|
|
46
|
+
throw new _atscript_db_client.TransportError("POST", url, `HTTP ${res.status} body is not JSON`, cause);
|
|
47
|
+
});
|
|
48
|
+
} };
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
exports.operationsClient = operationsClient;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ClientOptions } from "@atscript/db-client";
|
|
2
|
+
import { ODataCallAnswer, ODataOperationRef } from "@atscript/odata";
|
|
3
|
+
|
|
4
|
+
//#region src/client.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Options of {@link operationsClient}: the `fetch` and `headers` of `@atscript/db-client`'s
|
|
7
|
+
* `ClientOptions`, as the page's tables have them.
|
|
8
|
+
*/
|
|
9
|
+
type ODataOperationsClientOptions = Pick<ClientOptions, "fetch" | "headers">;
|
|
10
|
+
/** The caller of a Moost server's operations routes; see {@link operationsClient}. */
|
|
11
|
+
interface ODataOperationsClient {
|
|
12
|
+
/**
|
|
13
|
+
* Calls an unbound operation by its handle of the model module's `ops` (`ops.GetPrice`):
|
|
14
|
+
* `POST <baseUrl>/<operation>`, the parameters as the JSON body. The handle types the call:
|
|
15
|
+
* `params` is required when the operation has a required parameter, and the answer's `value`
|
|
16
|
+
* is its result. Answers what the route answers, `{ value, message?, messages?, details? }`.
|
|
17
|
+
*
|
|
18
|
+
* @throws `ClientError` of `@atscript/db-client` for an answer that is not `2xx` (its JSON body,
|
|
19
|
+
* the status text for a body that is none: a `400` with the parameters' entries, `404` for an
|
|
20
|
+
* operation the live service no longer has), `TransportError` when the server cannot be reached
|
|
21
|
+
* or its answer is no JSON, and `Error` for a handle of a bound operation (a db action of its
|
|
22
|
+
* table's controller: `client.action(name, ids, input)`).
|
|
23
|
+
*/
|
|
24
|
+
call<P, R>(operation: ODataOperationRef<P, R>, ...params: {} extends P ? [params?: NoInfer<P>] : [params: NoInfer<P>]): Promise<ODataCallAnswer<R>>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The browser's caller of a Moost server's operations controller, the leaf you declare over the
|
|
28
|
+
* generated operations base (`@Controller("api/sales/ops")`): `baseUrl` is that controller's
|
|
29
|
+
* path. It ships no OData and no server code, only `fetch`:
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { operationsClient } from "@atscript/moost-odata/client";
|
|
33
|
+
* import { ops } from "./odata/sales.model.gen";
|
|
34
|
+
*
|
|
35
|
+
* const salesOps = operationsClient("/api/sales/ops");
|
|
36
|
+
* const { value } = await salesOps.call(ops.GetPrice, { Material: "M-100" });
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* Importing `ops` costs the page the handles only: the bundler drops the model they sit next to.
|
|
40
|
+
*/
|
|
41
|
+
declare function operationsClient(baseUrl: string, options?: ODataOperationsClientOptions): ODataOperationsClient;
|
|
42
|
+
//#endregion
|
|
43
|
+
export { ODataOperationsClient, ODataOperationsClientOptions, operationsClient };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ODataCallAnswer, ODataOperationRef } from "@atscript/odata";
|
|
2
|
+
import { ClientOptions } from "@atscript/db-client";
|
|
3
|
+
|
|
4
|
+
//#region src/client.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Options of {@link operationsClient}: the `fetch` and `headers` of `@atscript/db-client`'s
|
|
7
|
+
* `ClientOptions`, as the page's tables have them.
|
|
8
|
+
*/
|
|
9
|
+
type ODataOperationsClientOptions = Pick<ClientOptions, "fetch" | "headers">;
|
|
10
|
+
/** The caller of a Moost server's operations routes; see {@link operationsClient}. */
|
|
11
|
+
interface ODataOperationsClient {
|
|
12
|
+
/**
|
|
13
|
+
* Calls an unbound operation by its handle of the model module's `ops` (`ops.GetPrice`):
|
|
14
|
+
* `POST <baseUrl>/<operation>`, the parameters as the JSON body. The handle types the call:
|
|
15
|
+
* `params` is required when the operation has a required parameter, and the answer's `value`
|
|
16
|
+
* is its result. Answers what the route answers, `{ value, message?, messages?, details? }`.
|
|
17
|
+
*
|
|
18
|
+
* @throws `ClientError` of `@atscript/db-client` for an answer that is not `2xx` (its JSON body,
|
|
19
|
+
* the status text for a body that is none: a `400` with the parameters' entries, `404` for an
|
|
20
|
+
* operation the live service no longer has), `TransportError` when the server cannot be reached
|
|
21
|
+
* or its answer is no JSON, and `Error` for a handle of a bound operation (a db action of its
|
|
22
|
+
* table's controller: `client.action(name, ids, input)`).
|
|
23
|
+
*/
|
|
24
|
+
call<P, R>(operation: ODataOperationRef<P, R>, ...params: {} extends P ? [params?: NoInfer<P>] : [params: NoInfer<P>]): Promise<ODataCallAnswer<R>>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The browser's caller of a Moost server's operations controller, the leaf you declare over the
|
|
28
|
+
* generated operations base (`@Controller("api/sales/ops")`): `baseUrl` is that controller's
|
|
29
|
+
* path. It ships no OData and no server code, only `fetch`:
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { operationsClient } from "@atscript/moost-odata/client";
|
|
33
|
+
* import { ops } from "./odata/sales.model.gen";
|
|
34
|
+
*
|
|
35
|
+
* const salesOps = operationsClient("/api/sales/ops");
|
|
36
|
+
* const { value } = await salesOps.call(ops.GetPrice, { Material: "M-100" });
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* Importing `ops` costs the page the handles only: the bundler drops the model they sit next to.
|
|
40
|
+
*/
|
|
41
|
+
declare function operationsClient(baseUrl: string, options?: ODataOperationsClientOptions): ODataOperationsClient;
|
|
42
|
+
//#endregion
|
|
43
|
+
export { ODataOperationsClient, ODataOperationsClientOptions, operationsClient };
|
package/dist/client.mjs
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ClientError, TransportError } from "@atscript/db-client";
|
|
2
|
+
//#region src/client.ts
|
|
3
|
+
/**
|
|
4
|
+
* The browser's caller of a Moost server's operations controller, the leaf you declare over the
|
|
5
|
+
* generated operations base (`@Controller("api/sales/ops")`): `baseUrl` is that controller's
|
|
6
|
+
* path. It ships no OData and no server code, only `fetch`:
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { operationsClient } from "@atscript/moost-odata/client";
|
|
10
|
+
* import { ops } from "./odata/sales.model.gen";
|
|
11
|
+
*
|
|
12
|
+
* const salesOps = operationsClient("/api/sales/ops");
|
|
13
|
+
* const { value } = await salesOps.call(ops.GetPrice, { Material: "M-100" });
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* Importing `ops` costs the page the handles only: the bundler drops the model they sit next to.
|
|
17
|
+
*/
|
|
18
|
+
function operationsClient(baseUrl, options = {}) {
|
|
19
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
20
|
+
return { async call(operation, params) {
|
|
21
|
+
if (operation.entitySet !== void 0) throw new Error(`operationsClient: "${operation.operation}" is bound to "${operation.entitySet}"; the operations controller serves unbound operations only, a bound one is a db action of its table's controller`);
|
|
22
|
+
const url = `${base}/${encodeURIComponent(operation.operation)}`;
|
|
23
|
+
const init = {
|
|
24
|
+
method: "POST",
|
|
25
|
+
headers: {
|
|
26
|
+
...typeof options.headers === "function" ? await options.headers() : options.headers,
|
|
27
|
+
"Content-Type": "application/json"
|
|
28
|
+
},
|
|
29
|
+
body: JSON.stringify(params ?? {})
|
|
30
|
+
};
|
|
31
|
+
let res;
|
|
32
|
+
try {
|
|
33
|
+
res = await (options.fetch ?? fetch)(url, init);
|
|
34
|
+
} catch (cause) {
|
|
35
|
+
throw new TransportError("POST", url, cause instanceof Error ? cause.message : String(cause), cause);
|
|
36
|
+
}
|
|
37
|
+
if (!res.ok) {
|
|
38
|
+
const body = await res.json().catch(() => ({
|
|
39
|
+
message: res.statusText || `HTTP ${res.status}`,
|
|
40
|
+
statusCode: res.status
|
|
41
|
+
}));
|
|
42
|
+
throw new ClientError(res.status, body);
|
|
43
|
+
}
|
|
44
|
+
return res.json().catch((cause) => {
|
|
45
|
+
throw new TransportError("POST", url, `HTTP ${res.status} body is not JSON`, cause);
|
|
46
|
+
});
|
|
47
|
+
} };
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
export { operationsClient };
|
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
|
|
538
|
-
* runs it when the first one throws: a request its guard refuses
|
|
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
|
|
614
|
-
* value-help services whose references differ only by `.` or `..`
|
|
615
|
-
*
|
|
616
|
-
*
|
|
617
|
-
*
|
|
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
|
|
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
|
|
680
|
+
const made = new Map(routesMade.get(space));
|
|
681
|
+
const now = /* @__PURE__ */ new Set();
|
|
663
682
|
for (const { route } of planned) {
|
|
664
|
-
if (
|
|
665
|
-
made.
|
|
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
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EventContext } from "@wooksjs/event-core";
|
|
2
1
|
import { ODataCallAnswer, ODataCallInit, ODataExtraParams, ODataOperationGrouping, ODataOperationRef, ODataRowsAnswer } from "@atscript/odata";
|
|
2
|
+
import { EventContext } from "@wooksjs/event-core";
|
|
3
3
|
import { AtscriptDbReadable, FilterExpr, TCrudPermissions } from "@atscript/db";
|
|
4
4
|
import { ODataSpace } from "@atscript/db-odata";
|
|
5
5
|
import { AsDbController, AsDbReadableController, TDbActionInfo, TDbRequestContext } from "@atscript/moost-db";
|
|
@@ -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
|
|
390
|
-
* value-help services whose references differ only by `.` or `..`
|
|
391
|
-
*
|
|
392
|
-
*
|
|
393
|
-
*
|
|
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
|
|
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
|
|
391
|
-
* value-help services whose references differ only by `.` or `..`
|
|
392
|
-
*
|
|
393
|
-
*
|
|
394
|
-
*
|
|
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
|
|
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
|
|
537
|
-
* runs it when the first one throws: a request its guard refuses
|
|
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
|
|
613
|
-
* value-help services whose references differ only by `.` or `..`
|
|
614
|
-
*
|
|
615
|
-
*
|
|
616
|
-
*
|
|
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
|
|
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
|
|
679
|
+
const made = new Map(routesMade.get(space));
|
|
680
|
+
const now = /* @__PURE__ */ new Set();
|
|
662
681
|
for (const { route } of planned) {
|
|
663
|
-
if (
|
|
664
|
-
made.
|
|
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.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Moost integration for serving OData services as Atscript DB controllers.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"atscript",
|
|
@@ -30,45 +30,61 @@
|
|
|
30
30
|
"default": "./dist/index.cjs"
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
|
+
"./client": {
|
|
34
|
+
"import": {
|
|
35
|
+
"types": "./dist/client.d.mts",
|
|
36
|
+
"default": "./dist/client.mjs"
|
|
37
|
+
},
|
|
38
|
+
"require": {
|
|
39
|
+
"types": "./dist/client.d.cts",
|
|
40
|
+
"default": "./dist/client.cjs"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
33
43
|
"./package.json": "./package.json"
|
|
34
44
|
},
|
|
35
45
|
"publishConfig": {
|
|
36
46
|
"access": "public"
|
|
37
47
|
},
|
|
38
48
|
"dependencies": {
|
|
39
|
-
"@atscript/db-odata": "^0.0.
|
|
40
|
-
"@atscript/odata": "^0.0.
|
|
49
|
+
"@atscript/db-odata": "^0.0.4",
|
|
50
|
+
"@atscript/odata": "^0.0.4"
|
|
41
51
|
},
|
|
42
52
|
"devDependencies": {
|
|
43
|
-
"@atscript/core": "^0.2.
|
|
44
|
-
"@atscript/db": "^0.1.
|
|
45
|
-
"@atscript/db-client": "^0.1.
|
|
46
|
-
"@atscript/moost-db": "^0.1.
|
|
47
|
-
"@atscript/typescript": "^0.2.
|
|
48
|
-
"@moostjs/event-http": "^0.7.
|
|
53
|
+
"@atscript/core": "^0.2.28",
|
|
54
|
+
"@atscript/db": "^0.1.204",
|
|
55
|
+
"@atscript/db-client": "^0.1.204",
|
|
56
|
+
"@atscript/moost-db": "^0.1.204",
|
|
57
|
+
"@atscript/typescript": "^0.2.28",
|
|
58
|
+
"@moostjs/event-http": "^0.7.13",
|
|
49
59
|
"@uniqu/core": "^0.2.2",
|
|
50
60
|
"@wooksjs/event-core": "^0.8.8",
|
|
51
61
|
"@wooksjs/event-http": "^0.8.8",
|
|
52
62
|
"@wooksjs/http-body": "^0.8.8",
|
|
53
|
-
"moost": "^0.7.
|
|
63
|
+
"moost": "^0.7.13",
|
|
54
64
|
"typescript": "^5",
|
|
55
|
-
"unplugin-atscript": "^0.2.
|
|
65
|
+
"unplugin-atscript": "^0.2.28"
|
|
56
66
|
},
|
|
57
67
|
"peerDependencies": {
|
|
58
|
-
"@atscript/db": "^0.1.
|
|
59
|
-
"@atscript/
|
|
60
|
-
"@atscript/
|
|
61
|
-
"@
|
|
68
|
+
"@atscript/db": "^0.1.204",
|
|
69
|
+
"@atscript/db-client": "^0.1.204",
|
|
70
|
+
"@atscript/moost-db": "^0.1.204",
|
|
71
|
+
"@atscript/typescript": "^0.2.28",
|
|
72
|
+
"@moostjs/event-http": "^0.7.13",
|
|
62
73
|
"@uniqu/core": "^0.2.2",
|
|
63
74
|
"@wooksjs/event-core": "^0.8.8",
|
|
64
75
|
"@wooksjs/event-http": "^0.8.8",
|
|
65
76
|
"@wooksjs/http-body": "^0.8.8",
|
|
66
|
-
"moost": "^0.7.
|
|
77
|
+
"moost": "^0.7.13"
|
|
78
|
+
},
|
|
79
|
+
"peerDependenciesMeta": {
|
|
80
|
+
"@atscript/db-client": {
|
|
81
|
+
"optional": true
|
|
82
|
+
}
|
|
67
83
|
},
|
|
68
84
|
"scripts": {
|
|
69
85
|
"build": "vp pack",
|
|
70
86
|
"dev": "vp pack --watch",
|
|
71
|
-
"test": "vp test",
|
|
87
|
+
"test": "vp test --typecheck",
|
|
72
88
|
"check": "vp check"
|
|
73
89
|
}
|
|
74
90
|
}
|