@atscript/db-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 +7 -2
- package/dist/index.cjs +32 -11
- package/dist/index.d.cts +4 -1
- package/dist/index.d.mts +4 -1
- package/dist/index.mjs +33 -12
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
pnpm add @atscript/db-odata @atscript/odata @atscript/db @atscript/typescript @uniqu/core
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
Needs `@atscript/db` 0.1.
|
|
33
|
+
Needs `@atscript/db` 0.1.201 or newer and `@atscript/typescript` 0.2.26 or newer.
|
|
34
34
|
|
|
35
35
|
The models come from the generator of `@atscript/odata`: see the
|
|
36
36
|
[installation guide](https://odata.atscript.dev/guide/installation). Every export is documented in the
|
|
@@ -102,6 +102,10 @@ does not start.
|
|
|
102
102
|
controller bases of `@atscript/moost-odata` answer it `404` first.
|
|
103
103
|
- **Other options** of the live form: the transport options of `@atscript/odata`, `copies`
|
|
104
104
|
(`annotate X as Y` copies that annotate properties), `name`, `sessions`, `logger`, `onClose`.
|
|
105
|
+
`search: false` is for an OData v4 service that refuses `$search` and declares nothing: its
|
|
106
|
+
sets are then searchable only where the metadata declares it, a `SearchRestrictions` record
|
|
107
|
+
(`/meta` and
|
|
108
|
+
`isSearchable()` say so, and a search is refused before any request).
|
|
105
109
|
|
|
106
110
|
The fixed form `createODataSpace({ service, init })`, over an engine of `createODataService`, reads
|
|
107
111
|
no `$metadata`: for tests and tools. See [Moost Server](https://odata.atscript.dev/guide/server) and
|
|
@@ -345,7 +349,8 @@ it.)
|
|
|
345
349
|
- **Without the token, last write wins.** An update or replace without `$cas`, and every delete,
|
|
346
350
|
overwrites whatever changed since the caller read the entity. The service still requires
|
|
347
351
|
`If-Match`, so the adapter reads the entity right before the write and sends that ETag (`*`
|
|
348
|
-
for an entity that comes without one
|
|
352
|
+
for an entity that comes without one; a `412` to `*` matches nothing when one more read finds
|
|
353
|
+
the entity gone, and is `STORE_FAILED` when it finds it: the service does not take `*`). A `412`
|
|
349
354
|
(a change in the moment between that read and the write) has the ETag read and the write sent
|
|
350
355
|
again, three attempts in all; then the write fails with `SERIALIZATION_FAILURE` (moost-db `503`).
|
|
351
356
|
|
package/dist/index.cjs
CHANGED
|
@@ -51,9 +51,24 @@ function isODataNotSupportedError(value) {
|
|
|
51
51
|
* write without a session the CSRF token needs, answered another status, a page or a payload that
|
|
52
52
|
* is no OData answer, or a paging link that leads nowhere: `STORE_FAILED`; the call was aborted
|
|
53
53
|
* (`callTimeout`): `STORE_TIMEOUT`. The server calls the service with credentials it is given,
|
|
54
|
-
* never the caller's own, so each is a fault behind the server, not of the request.
|
|
54
|
+
* never the caller's own, so each is a fault behind the server, not of the request. A
|
|
55
|
+
* precondition the service demands and its metadata does not declare (`428`, or a `412` to a
|
|
56
|
+
* request without `If-Match`: `etag-required`) is `STORE_FAILED` with a message that says so, its
|
|
57
|
+
* entry coded `PRECONDITION_REQUIRED`.
|
|
55
58
|
*/
|
|
56
|
-
function serverFailureOf(error) {
|
|
59
|
+
function serverFailureOf(error, entitySet) {
|
|
60
|
+
if ((0, _atscript_odata.writeFailureOf)(error) === "etag-required") {
|
|
61
|
+
const message = `The data service accepts this request only with a precondition (If-Match) that its metadata does not declare for "${entitySet}": nothing was applied`;
|
|
62
|
+
return {
|
|
63
|
+
...(0, _atscript_odata.storeFailure)("STORE_FAILED"),
|
|
64
|
+
message,
|
|
65
|
+
entries: [{
|
|
66
|
+
path: "",
|
|
67
|
+
message,
|
|
68
|
+
code: "PRECONDITION_REQUIRED"
|
|
69
|
+
}]
|
|
70
|
+
};
|
|
71
|
+
}
|
|
57
72
|
if ((0, _atscript_odata.isODataError)(error)) return (0, _atscript_odata.storeFailure)(error.kind === "aborted" ? "STORE_TIMEOUT" : "STORE_FAILED");
|
|
58
73
|
if ((0, _atscript_odata.isODataServiceError)(error) || (0, _atscript_odata.isODataPayloadError)(error)) return (0, _atscript_odata.storeFailure)("STORE_FAILED");
|
|
59
74
|
}
|
|
@@ -73,6 +88,7 @@ function serverFailureOf(error) {
|
|
|
73
88
|
* other `5xx`
|
|
74
89
|
* - every other failure of the service, which `dbFailureOf` leaves to the host: `STORE_FAILED`
|
|
75
90
|
* (it could not be reached, refused the server's credentials or a write without a session,
|
|
91
|
+
* demanded a precondition its metadata does not declare (`PRECONDITION_REQUIRED` on the entry),
|
|
76
92
|
* answered another status or no OData answer; a `404` is one of them: a key read never gets here
|
|
77
93
|
* with it, the engine answers that with "no entity", and the adapter answers a write by key that
|
|
78
94
|
* meets one with "nothing matched"), `STORE_TIMEOUT` (the call was aborted)
|
|
@@ -82,12 +98,15 @@ function serverFailureOf(error) {
|
|
|
82
98
|
* Anything else (a `DbError`, an error of the `init` hook, a bug) is returned as it is.
|
|
83
99
|
*
|
|
84
100
|
* @param model the service model, which maps the targets of the service's messages to field paths
|
|
101
|
+
* @param parameters of a failed operation call: the parameters of the operation (`runParameters`
|
|
102
|
+
* of `@atscript/odata`), whose messages are then reported at the parameter they name
|
|
85
103
|
*/
|
|
86
|
-
function toDbError(error, entitySet, model) {
|
|
104
|
+
function toDbError(error, entitySet, model, parameters) {
|
|
87
105
|
const failure = (0, _atscript_odata.dbFailureOf)(error, {
|
|
88
106
|
model,
|
|
89
|
-
entitySet
|
|
90
|
-
|
|
107
|
+
entitySet,
|
|
108
|
+
parameters
|
|
109
|
+
}) ?? serverFailureOf(error, entitySet);
|
|
91
110
|
if (!failure) return error;
|
|
92
111
|
return new _atscript_db.DbError(failure.code, failure.entries, failure.message, { cause: error });
|
|
93
112
|
}
|
|
@@ -101,11 +120,11 @@ function toDbError(error, entitySet, model) {
|
|
|
101
120
|
* mapped by {@link toDbError}, as a refused `changeSet` run of several rows is.
|
|
102
121
|
*
|
|
103
122
|
* @param context `token`, the field the rows carry the version token in, where the call sends it
|
|
104
|
-
* as `If-Match` (`sendsRowToken`; none: no `null`); the entity set
|
|
105
|
-
* targets of the service's messages
|
|
123
|
+
* as `If-Match` (`sendsRowToken`; none: no `null`); the entity set, the model and the operation's
|
|
124
|
+
* `parameters` (`runParameters`) that map the targets of the service's messages
|
|
106
125
|
*/
|
|
107
126
|
async function operationAnswer(running, rows = [], context) {
|
|
108
|
-
const { token, entitySet, model } = context;
|
|
127
|
+
const { token, entitySet, model, parameters } = context;
|
|
109
128
|
const mapped = (error, row) => {
|
|
110
129
|
const failure = (0, _atscript_odata.writeFailureOf)(error);
|
|
111
130
|
if (token !== void 0 && typeof row?.[token] === "string" && row[token] !== "" && failure === "changed") return null;
|
|
@@ -113,7 +132,7 @@ async function operationAnswer(running, rows = [], context) {
|
|
|
113
132
|
path: "",
|
|
114
133
|
message: "Not found"
|
|
115
134
|
}], "Not found", { cause: error });
|
|
116
|
-
return toDbError(error, entitySet, model);
|
|
135
|
+
return toDbError(error, entitySet, model, parameters);
|
|
117
136
|
};
|
|
118
137
|
let answer;
|
|
119
138
|
try {
|
|
@@ -527,7 +546,8 @@ var ODataAdapter = class extends _atscript_db.BaseDbAdapter {
|
|
|
527
546
|
return operationAnswer((0, _atscript_odata.runOperation)(connection, run, init), input.rows, {
|
|
528
547
|
token: (0, _atscript_odata.sendsRowToken)(connection, run) ? this.token : void 0,
|
|
529
548
|
entitySet: this.entitySet.name,
|
|
530
|
-
model: this.service.model
|
|
549
|
+
model: this.service.model,
|
|
550
|
+
parameters: (0, _atscript_odata.runParameters)(connection, run)
|
|
531
551
|
});
|
|
532
552
|
}
|
|
533
553
|
registerReadable(...args) {
|
|
@@ -1291,7 +1311,8 @@ var ODataSpace = class extends _atscript_db.DbSpace {
|
|
|
1291
1311
|
return operationAnswer((0, _atscript_odata.runOperation)(connection, input, init), input.rows, {
|
|
1292
1312
|
token: (0, _atscript_odata.sendsRowToken)(connection, input) ? _atscript_odata.VERSION_TOKEN : void 0,
|
|
1293
1313
|
entitySet,
|
|
1294
|
-
model: connection.service.model
|
|
1314
|
+
model: connection.service.model,
|
|
1315
|
+
parameters: (0, _atscript_odata.runParameters)(connection, input)
|
|
1295
1316
|
});
|
|
1296
1317
|
}
|
|
1297
1318
|
};
|
package/dist/index.d.cts
CHANGED
|
@@ -566,6 +566,7 @@ declare function isODataNotSupportedError(value: unknown): value is ODataNotSupp
|
|
|
566
566
|
* other `5xx`
|
|
567
567
|
* - every other failure of the service, which `dbFailureOf` leaves to the host: `STORE_FAILED`
|
|
568
568
|
* (it could not be reached, refused the server's credentials or a write without a session,
|
|
569
|
+
* demanded a precondition its metadata does not declare (`PRECONDITION_REQUIRED` on the entry),
|
|
569
570
|
* answered another status or no OData answer; a `404` is one of them: a key read never gets here
|
|
570
571
|
* with it, the engine answers that with "no entity", and the adapter answers a write by key that
|
|
571
572
|
* meets one with "nothing matched"), `STORE_TIMEOUT` (the call was aborted)
|
|
@@ -575,7 +576,9 @@ declare function isODataNotSupportedError(value: unknown): value is ODataNotSupp
|
|
|
575
576
|
* Anything else (a `DbError`, an error of the `init` hook, a bug) is returned as it is.
|
|
576
577
|
*
|
|
577
578
|
* @param model the service model, which maps the targets of the service's messages to field paths
|
|
579
|
+
* @param parameters of a failed operation call: the parameters of the operation (`runParameters`
|
|
580
|
+
* of `@atscript/odata`), whose messages are then reported at the parameter they name
|
|
578
581
|
*/
|
|
579
|
-
declare function toDbError(error: unknown, entitySet: string, model?: ServiceModel): unknown;
|
|
582
|
+
declare function toDbError(error: unknown, entitySet: string, model?: ServiceModel, parameters?: readonly string[]): unknown;
|
|
580
583
|
//#endregion
|
|
581
584
|
export { DEFAULT_MAX_SESSIONS, DEFAULT_SESSION_TTL, ODATA_SEARCH_INDEX, ODataAdapter, type ODataAdapterOptions, type ODataFixedSpaceOptions, type ODataLiveSpaceOptions, ODataNotSupportedError, type ODataSessionOptions, ODataSpace, type ODataSpaceOptions, createODataSpace, isODataNotSupportedError, toDbError };
|
package/dist/index.d.mts
CHANGED
|
@@ -566,6 +566,7 @@ declare function isODataNotSupportedError(value: unknown): value is ODataNotSupp
|
|
|
566
566
|
* other `5xx`
|
|
567
567
|
* - every other failure of the service, which `dbFailureOf` leaves to the host: `STORE_FAILED`
|
|
568
568
|
* (it could not be reached, refused the server's credentials or a write without a session,
|
|
569
|
+
* demanded a precondition its metadata does not declare (`PRECONDITION_REQUIRED` on the entry),
|
|
569
570
|
* answered another status or no OData answer; a `404` is one of them: a key read never gets here
|
|
570
571
|
* with it, the engine answers that with "no entity", and the adapter answers a write by key that
|
|
571
572
|
* meets one with "nothing matched"), `STORE_TIMEOUT` (the call was aborted)
|
|
@@ -575,7 +576,9 @@ declare function isODataNotSupportedError(value: unknown): value is ODataNotSupp
|
|
|
575
576
|
* Anything else (a `DbError`, an error of the `init` hook, a bug) is returned as it is.
|
|
576
577
|
*
|
|
577
578
|
* @param model the service model, which maps the targets of the service's messages to field paths
|
|
579
|
+
* @param parameters of a failed operation call: the parameters of the operation (`runParameters`
|
|
580
|
+
* of `@atscript/odata`), whose messages are then reported at the parameter they name
|
|
578
581
|
*/
|
|
579
|
-
declare function toDbError(error: unknown, entitySet: string, model?: ServiceModel): unknown;
|
|
582
|
+
declare function toDbError(error: unknown, entitySet: string, model?: ServiceModel, parameters?: readonly string[]): unknown;
|
|
580
583
|
//#endregion
|
|
581
584
|
export { DEFAULT_MAX_SESSIONS, DEFAULT_SESSION_TTL, ODATA_SEARCH_INDEX, ODataAdapter, type ODataAdapterOptions, type ODataFixedSpaceOptions, type ODataLiveSpaceOptions, ODataNotSupportedError, type ODataSessionOptions, ODataSpace, type ODataSpaceOptions, createODataSpace, isODataNotSupportedError, toDbError };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseDbAdapter, DbError, DbSpace, isPlainObject, searchIndexNotFoundMessage } from "@atscript/db";
|
|
2
|
-
import { VERSION_TOKEN, allowedWrites, changeByKey, createODataSource, createSession, dbFailureOf, describeEntitySet, describeField, dialectFor, isODataError, isODataPayloadError, isODataQueryError, isODataServiceError, rowsFailure, runOperation, sendEach, sendsRowToken, storeFailure, withLocale, writeFailureOf, writeRefusal } from "@atscript/odata";
|
|
2
|
+
import { VERSION_TOKEN, allowedWrites, changeByKey, createODataSource, createSession, dbFailureOf, describeEntitySet, describeField, dialectFor, isODataError, isODataPayloadError, isODataQueryError, isODataServiceError, rowsFailure, runOperation, runParameters, sendEach, sendsRowToken, storeFailure, withLocale, writeFailureOf, writeRefusal } from "@atscript/odata";
|
|
3
3
|
import { resolveAlias } from "@uniqu/core";
|
|
4
4
|
import { createHash } from "node:crypto";
|
|
5
5
|
//#region src/errors.ts
|
|
@@ -50,9 +50,24 @@ function isODataNotSupportedError(value) {
|
|
|
50
50
|
* write without a session the CSRF token needs, answered another status, a page or a payload that
|
|
51
51
|
* is no OData answer, or a paging link that leads nowhere: `STORE_FAILED`; the call was aborted
|
|
52
52
|
* (`callTimeout`): `STORE_TIMEOUT`. The server calls the service with credentials it is given,
|
|
53
|
-
* never the caller's own, so each is a fault behind the server, not of the request.
|
|
53
|
+
* never the caller's own, so each is a fault behind the server, not of the request. A
|
|
54
|
+
* precondition the service demands and its metadata does not declare (`428`, or a `412` to a
|
|
55
|
+
* request without `If-Match`: `etag-required`) is `STORE_FAILED` with a message that says so, its
|
|
56
|
+
* entry coded `PRECONDITION_REQUIRED`.
|
|
54
57
|
*/
|
|
55
|
-
function serverFailureOf(error) {
|
|
58
|
+
function serverFailureOf(error, entitySet) {
|
|
59
|
+
if (writeFailureOf(error) === "etag-required") {
|
|
60
|
+
const message = `The data service accepts this request only with a precondition (If-Match) that its metadata does not declare for "${entitySet}": nothing was applied`;
|
|
61
|
+
return {
|
|
62
|
+
...storeFailure("STORE_FAILED"),
|
|
63
|
+
message,
|
|
64
|
+
entries: [{
|
|
65
|
+
path: "",
|
|
66
|
+
message,
|
|
67
|
+
code: "PRECONDITION_REQUIRED"
|
|
68
|
+
}]
|
|
69
|
+
};
|
|
70
|
+
}
|
|
56
71
|
if (isODataError(error)) return storeFailure(error.kind === "aborted" ? "STORE_TIMEOUT" : "STORE_FAILED");
|
|
57
72
|
if (isODataServiceError(error) || isODataPayloadError(error)) return storeFailure("STORE_FAILED");
|
|
58
73
|
}
|
|
@@ -72,6 +87,7 @@ function serverFailureOf(error) {
|
|
|
72
87
|
* other `5xx`
|
|
73
88
|
* - every other failure of the service, which `dbFailureOf` leaves to the host: `STORE_FAILED`
|
|
74
89
|
* (it could not be reached, refused the server's credentials or a write without a session,
|
|
90
|
+
* demanded a precondition its metadata does not declare (`PRECONDITION_REQUIRED` on the entry),
|
|
75
91
|
* answered another status or no OData answer; a `404` is one of them: a key read never gets here
|
|
76
92
|
* with it, the engine answers that with "no entity", and the adapter answers a write by key that
|
|
77
93
|
* meets one with "nothing matched"), `STORE_TIMEOUT` (the call was aborted)
|
|
@@ -81,12 +97,15 @@ function serverFailureOf(error) {
|
|
|
81
97
|
* Anything else (a `DbError`, an error of the `init` hook, a bug) is returned as it is.
|
|
82
98
|
*
|
|
83
99
|
* @param model the service model, which maps the targets of the service's messages to field paths
|
|
100
|
+
* @param parameters of a failed operation call: the parameters of the operation (`runParameters`
|
|
101
|
+
* of `@atscript/odata`), whose messages are then reported at the parameter they name
|
|
84
102
|
*/
|
|
85
|
-
function toDbError(error, entitySet, model) {
|
|
103
|
+
function toDbError(error, entitySet, model, parameters) {
|
|
86
104
|
const failure = dbFailureOf(error, {
|
|
87
105
|
model,
|
|
88
|
-
entitySet
|
|
89
|
-
|
|
106
|
+
entitySet,
|
|
107
|
+
parameters
|
|
108
|
+
}) ?? serverFailureOf(error, entitySet);
|
|
90
109
|
if (!failure) return error;
|
|
91
110
|
return new DbError(failure.code, failure.entries, failure.message, { cause: error });
|
|
92
111
|
}
|
|
@@ -100,11 +119,11 @@ function toDbError(error, entitySet, model) {
|
|
|
100
119
|
* mapped by {@link toDbError}, as a refused `changeSet` run of several rows is.
|
|
101
120
|
*
|
|
102
121
|
* @param context `token`, the field the rows carry the version token in, where the call sends it
|
|
103
|
-
* as `If-Match` (`sendsRowToken`; none: no `null`); the entity set
|
|
104
|
-
* targets of the service's messages
|
|
122
|
+
* as `If-Match` (`sendsRowToken`; none: no `null`); the entity set, the model and the operation's
|
|
123
|
+
* `parameters` (`runParameters`) that map the targets of the service's messages
|
|
105
124
|
*/
|
|
106
125
|
async function operationAnswer(running, rows = [], context) {
|
|
107
|
-
const { token, entitySet, model } = context;
|
|
126
|
+
const { token, entitySet, model, parameters } = context;
|
|
108
127
|
const mapped = (error, row) => {
|
|
109
128
|
const failure = writeFailureOf(error);
|
|
110
129
|
if (token !== void 0 && typeof row?.[token] === "string" && row[token] !== "" && failure === "changed") return null;
|
|
@@ -112,7 +131,7 @@ async function operationAnswer(running, rows = [], context) {
|
|
|
112
131
|
path: "",
|
|
113
132
|
message: "Not found"
|
|
114
133
|
}], "Not found", { cause: error });
|
|
115
|
-
return toDbError(error, entitySet, model);
|
|
134
|
+
return toDbError(error, entitySet, model, parameters);
|
|
116
135
|
};
|
|
117
136
|
let answer;
|
|
118
137
|
try {
|
|
@@ -526,7 +545,8 @@ var ODataAdapter = class extends BaseDbAdapter {
|
|
|
526
545
|
return operationAnswer(runOperation(connection, run, init), input.rows, {
|
|
527
546
|
token: sendsRowToken(connection, run) ? this.token : void 0,
|
|
528
547
|
entitySet: this.entitySet.name,
|
|
529
|
-
model: this.service.model
|
|
548
|
+
model: this.service.model,
|
|
549
|
+
parameters: runParameters(connection, run)
|
|
530
550
|
});
|
|
531
551
|
}
|
|
532
552
|
registerReadable(...args) {
|
|
@@ -1290,7 +1310,8 @@ var ODataSpace = class extends DbSpace {
|
|
|
1290
1310
|
return operationAnswer(runOperation(connection, input, init), input.rows, {
|
|
1291
1311
|
token: sendsRowToken(connection, input) ? VERSION_TOKEN : void 0,
|
|
1292
1312
|
entitySet,
|
|
1293
|
-
model: connection.service.model
|
|
1313
|
+
model: connection.service.model,
|
|
1314
|
+
parameters: runParameters(connection, input)
|
|
1294
1315
|
});
|
|
1295
1316
|
}
|
|
1296
1317
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/db-odata",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Atscript DB adapter that uses an OData v2/v4 service as the database.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adapter",
|
|
@@ -36,19 +36,19 @@
|
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@atscript/odata": "^0.0.
|
|
39
|
+
"@atscript/odata": "^0.0.3"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@atscript/core": "^0.2.
|
|
43
|
-
"@atscript/db": "^0.1.
|
|
44
|
-
"@atscript/db-client": "^0.1.
|
|
45
|
-
"@atscript/typescript": "^0.2.
|
|
42
|
+
"@atscript/core": "^0.2.26",
|
|
43
|
+
"@atscript/db": "^0.1.201",
|
|
44
|
+
"@atscript/db-client": "^0.1.201",
|
|
45
|
+
"@atscript/typescript": "^0.2.26",
|
|
46
46
|
"@uniqu/core": "^0.2.2",
|
|
47
|
-
"unplugin-atscript": "^0.2.
|
|
47
|
+
"unplugin-atscript": "^0.2.26"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@atscript/db": "^0.1.
|
|
51
|
-
"@atscript/typescript": "^0.2.
|
|
50
|
+
"@atscript/db": "^0.1.201",
|
|
51
|
+
"@atscript/typescript": "^0.2.26",
|
|
52
52
|
"@uniqu/core": "^0.2.2"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|