@atscript/db-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 +2 -2
- package/dist/index.cjs +84 -16
- package/dist/index.d.cts +53 -14
- package/dist/index.d.mts +53 -14
- package/dist/index.mjs +85 -17
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
## Installation
|
|
28
28
|
|
|
29
29
|
```bash
|
|
30
|
-
pnpm add @atscript/db-odata @atscript/odata @atscript/db @atscript/typescript @uniqu/core
|
|
30
|
+
pnpm add @atscript/db-odata @atscript/odata @atscript/db @atscript/core @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
|
package/dist/index.cjs
CHANGED
|
@@ -532,9 +532,25 @@ var ODataAdapter = class extends _atscript_db.BaseDbAdapter {
|
|
|
532
532
|
* mapped so (`SERIALIZATION_FAILURE` for a `412`, `CONFLICT` for a `404`: nothing was applied;
|
|
533
533
|
* the entries of a message that names a row at that row, `[1]`).
|
|
534
534
|
*
|
|
535
|
+
* The handle types the call: `params` is required when the operation has a required parameter,
|
|
536
|
+
* `rows` when it is called on rows, and the answer's `value` is its result (one per row on
|
|
537
|
+
* rows). An operation only the live service has is called with {@link callOperationByName}.
|
|
538
|
+
*
|
|
539
|
+
* @throws Error for an entity set the live service no longer has.
|
|
540
|
+
*/
|
|
541
|
+
callOperation(input) {
|
|
542
|
+
return this.run(input);
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Calls an operation bound to this entity set by its name, untyped, as {@link callOperation}
|
|
546
|
+
* calls one by its handle: an operation only the live service has.
|
|
547
|
+
*
|
|
535
548
|
* @throws Error for an entity set the live service no longer has.
|
|
536
549
|
*/
|
|
537
|
-
|
|
550
|
+
callOperationByName(input) {
|
|
551
|
+
return this.run(input);
|
|
552
|
+
}
|
|
553
|
+
async run(input) {
|
|
538
554
|
this.refuseGone();
|
|
539
555
|
const connection = this.options.connection?.();
|
|
540
556
|
if (!connection) throw new Error(`Table "${this.entitySet.name}": an operation runs on the connection of an OData space (createODataSpace), which it has not`);
|
|
@@ -589,6 +605,18 @@ var ODataAdapter = class extends _atscript_db.BaseDbAdapter {
|
|
|
589
605
|
supportsWithInRead() {
|
|
590
606
|
return true;
|
|
591
607
|
}
|
|
608
|
+
/**
|
|
609
|
+
* Reads (rows, counts, grouped reads) filter by a related row of a to-one navigation of the same
|
|
610
|
+
* service: `{ order: { $some: { status_code: { $ne: "X" } } } }` is the navigation path,
|
|
611
|
+
* guarded by the related entity's presence, `(order ne null and order/status_code ne 'X')`, in
|
|
612
|
+
* `$filter` and in the `filter()` of an `$apply`; `$none` is its negation, a row with no related
|
|
613
|
+
* one included. Refused (`REL_FILTER_NOT_SUPPORTED`): a
|
|
614
|
+
* predicate on a to-many navigation, one on OData v2 or on a navigation the set does not let a
|
|
615
|
+
* filter use, and every predicate of a write (there is no write by query).
|
|
616
|
+
*/
|
|
617
|
+
supportsRelationFilters(mode) {
|
|
618
|
+
return mode === "read";
|
|
619
|
+
}
|
|
592
620
|
/** A relation is read through `$expand`: only to a table of the same service. */
|
|
593
621
|
sharesStoreWith(other) {
|
|
594
622
|
return super.sharesStoreWith(other) && other.service === this.service;
|
|
@@ -1105,12 +1133,38 @@ var ODataAdapter = class extends _atscript_db.BaseDbAdapter {
|
|
|
1105
1133
|
return this._leaves;
|
|
1106
1134
|
}
|
|
1107
1135
|
/**
|
|
1136
|
+
* A filter as the table layer hands it over, as the query layer of `@atscript/odata` takes it:
|
|
1137
|
+
* each relational predicate the table layer resolved back to `{ nav: { $some | $none: filter } }`,
|
|
1138
|
+
* the related table's filter (its own predicates in turn) as its adapter has it. A predicate on a
|
|
1139
|
+
* to-many navigation is refused before any request.
|
|
1140
|
+
*/
|
|
1141
|
+
odataFilter(filter, path = "") {
|
|
1142
|
+
if (!filter || !(0, _atscript_db.containsRelationFilter)(filter)) return filter;
|
|
1143
|
+
const entries = Object.entries(filter).map(([key, value]) => {
|
|
1144
|
+
if ((key === "$and" || key === "$or") && Array.isArray(value)) return [key, value.map((child) => this.odataFilter(child, path))];
|
|
1145
|
+
if (key === "$not") return [key, this.odataFilter(value, path)];
|
|
1146
|
+
if (key.startsWith("$") || !(0, _atscript_db.hasRelationOp)(value)) return [key, value];
|
|
1147
|
+
const at = path ? `${path}.${key}` : key;
|
|
1148
|
+
const navigation = this.entitySet.navigations.find((nav) => nav.name === key);
|
|
1149
|
+
if (!navigation?.filterable || navigation.collection) throw new _atscript_db.DbError("REL_FILTER_NOT_SUPPORTED", [{
|
|
1150
|
+
path: at,
|
|
1151
|
+
message: `Cannot filter by related "${at}" rows: ${navigation?.filterable ? `"${key}" is a to-many navigation, and only a to-one one is filtered by on the server; read the related set and filter by its key` : `the service does not filter by "${key}" (OData v2, or a restriction of the set)`}`
|
|
1152
|
+
}]);
|
|
1153
|
+
const ops = Object.entries(value).map(([op, operand]) => [op, (0, _atscript_db.isResolvedRelationFilter)(operand) ? operand.target.adapter.odataFilter(operand.filter, at) : operand]);
|
|
1154
|
+
return [key, Object.fromEntries(ops)];
|
|
1155
|
+
});
|
|
1156
|
+
return Object.fromEntries(entries);
|
|
1157
|
+
}
|
|
1158
|
+
/**
|
|
1108
1159
|
* The read of a query, with the `$with` entries as expansions: each translated by the adapter
|
|
1109
1160
|
* of its table (one of the same service, see {@link sharesStoreWith}), nested entries included.
|
|
1110
1161
|
* Related rows keep their key at every depth, whatever their selection.
|
|
1111
1162
|
*/
|
|
1112
1163
|
shapeOf(query) {
|
|
1113
|
-
return withRelations(readShapeOf(
|
|
1164
|
+
return withRelations(readShapeOf({
|
|
1165
|
+
...query,
|
|
1166
|
+
filter: this.odataFilter(query.filter)
|
|
1167
|
+
}, this.context), (query.controls.$with ?? []).map(({ nav, isArray, target, query: related }) => {
|
|
1114
1168
|
const adapter = target.adapter;
|
|
1115
1169
|
return {
|
|
1116
1170
|
nav,
|
|
@@ -1131,7 +1185,7 @@ var ODataAdapter = class extends _atscript_db.BaseDbAdapter {
|
|
|
1131
1185
|
alias: (0, _uniqu_core.resolveAlias)(expr)
|
|
1132
1186
|
}))
|
|
1133
1187
|
};
|
|
1134
|
-
if (query.filter && Object.keys(query.filter).length > 0) spec.filter = query.filter;
|
|
1188
|
+
if (query.filter && Object.keys(query.filter).length > 0) spec.filter = this.odataFilter(query.filter);
|
|
1135
1189
|
const having = controls.$having;
|
|
1136
1190
|
if (having && Object.keys(having).length > 0) spec.having = having;
|
|
1137
1191
|
const sort = Object.entries(controls.$sort ?? {});
|
|
@@ -1151,7 +1205,7 @@ var ODataAdapter = class extends _atscript_db.BaseDbAdapter {
|
|
|
1151
1205
|
}
|
|
1152
1206
|
countSpecOf(query) {
|
|
1153
1207
|
const spec = { entitySet: this.entitySet.name };
|
|
1154
|
-
if (query.filter && Object.keys(query.filter).length > 0) spec.filter = query.filter;
|
|
1208
|
+
if (query.filter && Object.keys(query.filter).length > 0) spec.filter = this.odataFilter(query.filter);
|
|
1155
1209
|
return spec;
|
|
1156
1210
|
}
|
|
1157
1211
|
searchShapeOf(text, query, indexName) {
|
|
@@ -1288,21 +1342,35 @@ var ODataSpace = class extends _atscript_db.DbSpace {
|
|
|
1288
1342
|
return refusalIn(this._connection, operation);
|
|
1289
1343
|
}
|
|
1290
1344
|
/**
|
|
1291
|
-
* Calls an operation of the service
|
|
1292
|
-
*
|
|
1293
|
-
* unbound one, or a bound one
|
|
1294
|
-
* `ODataAdapter.callOperation`).
|
|
1295
|
-
*
|
|
1296
|
-
*
|
|
1297
|
-
*
|
|
1298
|
-
*
|
|
1299
|
-
*
|
|
1300
|
-
*
|
|
1301
|
-
* `
|
|
1345
|
+
* Calls an operation of the service by its handle of the model module's `ops`
|
|
1346
|
+
* (`runOperation` of `@atscript/odata`), with the space's credentials, the session it keeps for
|
|
1347
|
+
* them and its language, as the tables' calls are made: an unbound one, or a bound one (a set's
|
|
1348
|
+
* table calls its own with `ODataAdapter.callOperation`). The handle types the call: `params`
|
|
1349
|
+
* is required when the operation has a required parameter, `rows` when it is called on rows, and
|
|
1350
|
+
* the answer's `value` is its result (one per row on rows). An operation the live service no
|
|
1351
|
+
* longer fits is refused first (see {@link refusalOf}); the parameters are validated against
|
|
1352
|
+
* the live operation type (the validator's `ValidatorError`). What the call throws, and the
|
|
1353
|
+
* error of each row in `failed`, is mapped as the adapter's `callOperation` maps it: a call that
|
|
1354
|
+
* sends the caller's version token (a call that writes, on a row with its `__etag`) refused with
|
|
1355
|
+
* `412` is that row's version mismatch, for the caller to answer (one row resolves `null`, a
|
|
1356
|
+
* row of several is `{ index, error: null }` in `failed`), a row the service has no entity for
|
|
1357
|
+
* a `DbError` `NOT_FOUND`, the rest as the tables' calls (`toDbError`).
|
|
1358
|
+
*
|
|
1359
|
+
* @throws Error before the space is connected.
|
|
1360
|
+
*/
|
|
1361
|
+
callOperation(input) {
|
|
1362
|
+
return this.run(input);
|
|
1363
|
+
}
|
|
1364
|
+
/**
|
|
1365
|
+
* Calls an operation by its name, untyped, as {@link callOperation} calls one by its handle:
|
|
1366
|
+
* an operation only the live service has. A bound one names its entity set in `entitySet`.
|
|
1302
1367
|
*
|
|
1303
1368
|
* @throws Error before the space is connected.
|
|
1304
1369
|
*/
|
|
1305
|
-
|
|
1370
|
+
callOperationByName(input) {
|
|
1371
|
+
return this.run(input);
|
|
1372
|
+
}
|
|
1373
|
+
async run(input) {
|
|
1306
1374
|
const connection = this._connection;
|
|
1307
1375
|
if (!connection) throw notConnected();
|
|
1308
1376
|
const init = sendInit(await this.callInit?.() ?? {});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseDbAdapter, DbError, DbQuery, DbSpace, FilterExpr, TDbDefaultFn, TDbDeleteResult, TDbFieldMeta, TDbInsertManyResult, TDbInsertResult, TDbSpaceOptions, TDbUpdateResult, TDbVersion, TFieldOps, TSearchIndexInfo } from "@atscript/db";
|
|
2
|
-
import { EntitySetDescription, EntitySetWrite, ODataCallAnswer, ODataCallInit, ODataConnection, ODataOperationRef, ODataOperationVerdict,
|
|
2
|
+
import { EntitySetDescription, EntitySetWrite, ODataCallAnswer, ODataCallInit, ODataConnection, ODataNamedRunInput, ODataOperationRef, ODataOperationVerdict, ODataRunValue, ODataService, ODataSource, ODataSourceOptions, ODataTypedRunInput, ServiceModel } from "@atscript/odata";
|
|
3
3
|
import { AggregateFn, ComparisonOp } from "@uniqu/core";
|
|
4
4
|
|
|
5
5
|
//#region src/odata-adapter.d.ts
|
|
@@ -125,9 +125,21 @@ declare class ODataAdapter extends BaseDbAdapter {
|
|
|
125
125
|
* mapped so (`SERIALIZATION_FAILURE` for a `412`, `CONFLICT` for a `404`: nothing was applied;
|
|
126
126
|
* the entries of a message that names a row at that row, `[1]`).
|
|
127
127
|
*
|
|
128
|
+
* The handle types the call: `params` is required when the operation has a required parameter,
|
|
129
|
+
* `rows` when it is called on rows, and the answer's `value` is its result (one per row on
|
|
130
|
+
* rows). An operation only the live service has is called with {@link callOperationByName}.
|
|
131
|
+
*
|
|
128
132
|
* @throws Error for an entity set the live service no longer has.
|
|
129
133
|
*/
|
|
130
|
-
callOperation(input:
|
|
134
|
+
callOperation<P, R, K>(input: ODataTypedRunInput<P, R, K>): Promise<ODataCallAnswer<ODataRunValue<R, K>> | null>;
|
|
135
|
+
/**
|
|
136
|
+
* Calls an operation bound to this entity set by its name, untyped, as {@link callOperation}
|
|
137
|
+
* calls one by its handle: an operation only the live service has.
|
|
138
|
+
*
|
|
139
|
+
* @throws Error for an entity set the live service no longer has.
|
|
140
|
+
*/
|
|
141
|
+
callOperationByName(input: Omit<ODataNamedRunInput, "entitySet">): Promise<ODataCallAnswer | null>;
|
|
142
|
+
private run;
|
|
131
143
|
registerReadable(...args: Parameters<BaseDbAdapter["registerReadable"]>): void;
|
|
132
144
|
/**
|
|
133
145
|
* The entity set this adapter reads, as the query layer describes it: from the live model, or,
|
|
@@ -150,6 +162,16 @@ declare class ODataAdapter extends BaseDbAdapter {
|
|
|
150
162
|
* A navigation the service declares no foreign key for (`@db.rel.store`) is read the same way.
|
|
151
163
|
*/
|
|
152
164
|
supportsWithInRead(): boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Reads (rows, counts, grouped reads) filter by a related row of a to-one navigation of the same
|
|
167
|
+
* service: `{ order: { $some: { status_code: { $ne: "X" } } } }` is the navigation path,
|
|
168
|
+
* guarded by the related entity's presence, `(order ne null and order/status_code ne 'X')`, in
|
|
169
|
+
* `$filter` and in the `filter()` of an `$apply`; `$none` is its negation, a row with no related
|
|
170
|
+
* one included. Refused (`REL_FILTER_NOT_SUPPORTED`): a
|
|
171
|
+
* predicate on a to-many navigation, one on OData v2 or on a navigation the set does not let a
|
|
172
|
+
* filter use, and every predicate of a write (there is no write by query).
|
|
173
|
+
*/
|
|
174
|
+
supportsRelationFilters(mode: "read" | "write"): boolean;
|
|
153
175
|
/** A relation is read through `$expand`: only to a table of the same service. */
|
|
154
176
|
sharesStoreWith(other: BaseDbAdapter): boolean;
|
|
155
177
|
/**
|
|
@@ -368,6 +390,13 @@ declare class ODataAdapter extends BaseDbAdapter {
|
|
|
368
390
|
* field.
|
|
369
391
|
*/
|
|
370
392
|
private get leaves();
|
|
393
|
+
/**
|
|
394
|
+
* A filter as the table layer hands it over, as the query layer of `@atscript/odata` takes it:
|
|
395
|
+
* each relational predicate the table layer resolved back to `{ nav: { $some | $none: filter } }`,
|
|
396
|
+
* the related table's filter (its own predicates in turn) as its adapter has it. A predicate on a
|
|
397
|
+
* to-many navigation is refused before any request.
|
|
398
|
+
*/
|
|
399
|
+
private odataFilter;
|
|
371
400
|
/**
|
|
372
401
|
* The read of a query, with the `$with` entries as expansions: each translated by the adapter
|
|
373
402
|
* of its table (one of the same service, see {@link sharesStoreWith}), nested entries included.
|
|
@@ -474,21 +503,31 @@ declare class ODataSpace extends DbSpace {
|
|
|
474
503
|
*/
|
|
475
504
|
refusalOf(operation: ODataOperationRef<any, unknown, unknown>): ODataOperationVerdict | undefined;
|
|
476
505
|
/**
|
|
477
|
-
* Calls an operation of the service
|
|
478
|
-
*
|
|
479
|
-
* unbound one, or a bound one
|
|
480
|
-
* `ODataAdapter.callOperation`).
|
|
481
|
-
*
|
|
482
|
-
*
|
|
483
|
-
*
|
|
484
|
-
*
|
|
485
|
-
*
|
|
486
|
-
*
|
|
487
|
-
* `
|
|
506
|
+
* Calls an operation of the service by its handle of the model module's `ops`
|
|
507
|
+
* (`runOperation` of `@atscript/odata`), with the space's credentials, the session it keeps for
|
|
508
|
+
* them and its language, as the tables' calls are made: an unbound one, or a bound one (a set's
|
|
509
|
+
* table calls its own with `ODataAdapter.callOperation`). The handle types the call: `params`
|
|
510
|
+
* is required when the operation has a required parameter, `rows` when it is called on rows, and
|
|
511
|
+
* the answer's `value` is its result (one per row on rows). An operation the live service no
|
|
512
|
+
* longer fits is refused first (see {@link refusalOf}); the parameters are validated against
|
|
513
|
+
* the live operation type (the validator's `ValidatorError`). What the call throws, and the
|
|
514
|
+
* error of each row in `failed`, is mapped as the adapter's `callOperation` maps it: a call that
|
|
515
|
+
* sends the caller's version token (a call that writes, on a row with its `__etag`) refused with
|
|
516
|
+
* `412` is that row's version mismatch, for the caller to answer (one row resolves `null`, a
|
|
517
|
+
* row of several is `{ index, error: null }` in `failed`), a row the service has no entity for
|
|
518
|
+
* a `DbError` `NOT_FOUND`, the rest as the tables' calls (`toDbError`).
|
|
519
|
+
*
|
|
520
|
+
* @throws Error before the space is connected.
|
|
521
|
+
*/
|
|
522
|
+
callOperation<P, R, K>(input: ODataTypedRunInput<P, R, K>): Promise<ODataCallAnswer<ODataRunValue<R, K>> | null>;
|
|
523
|
+
/**
|
|
524
|
+
* Calls an operation by its name, untyped, as {@link callOperation} calls one by its handle:
|
|
525
|
+
* an operation only the live service has. A bound one names its entity set in `entitySet`.
|
|
488
526
|
*
|
|
489
527
|
* @throws Error before the space is connected.
|
|
490
528
|
*/
|
|
491
|
-
|
|
529
|
+
callOperationByName(input: ODataNamedRunInput): Promise<ODataCallAnswer | null>;
|
|
530
|
+
private run;
|
|
492
531
|
}
|
|
493
532
|
/**
|
|
494
533
|
* Creates a `DbSpace` over an OData service: `space.getTable(Type)` returns a table that reads the
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseDbAdapter, DbError, DbQuery, DbSpace, FilterExpr, TDbDefaultFn, TDbDeleteResult, TDbFieldMeta, TDbInsertManyResult, TDbInsertResult, TDbSpaceOptions, TDbUpdateResult, TDbVersion, TFieldOps, TSearchIndexInfo } from "@atscript/db";
|
|
2
|
-
import { EntitySetDescription, EntitySetWrite, ODataCallAnswer, ODataCallInit, ODataConnection, ODataOperationRef, ODataOperationVerdict,
|
|
2
|
+
import { EntitySetDescription, EntitySetWrite, ODataCallAnswer, ODataCallInit, ODataConnection, ODataNamedRunInput, ODataOperationRef, ODataOperationVerdict, ODataRunValue, ODataService, ODataSource, ODataSourceOptions, ODataTypedRunInput, ServiceModel } from "@atscript/odata";
|
|
3
3
|
import { AggregateFn, ComparisonOp } from "@uniqu/core";
|
|
4
4
|
|
|
5
5
|
//#region src/odata-adapter.d.ts
|
|
@@ -125,9 +125,21 @@ declare class ODataAdapter extends BaseDbAdapter {
|
|
|
125
125
|
* mapped so (`SERIALIZATION_FAILURE` for a `412`, `CONFLICT` for a `404`: nothing was applied;
|
|
126
126
|
* the entries of a message that names a row at that row, `[1]`).
|
|
127
127
|
*
|
|
128
|
+
* The handle types the call: `params` is required when the operation has a required parameter,
|
|
129
|
+
* `rows` when it is called on rows, and the answer's `value` is its result (one per row on
|
|
130
|
+
* rows). An operation only the live service has is called with {@link callOperationByName}.
|
|
131
|
+
*
|
|
128
132
|
* @throws Error for an entity set the live service no longer has.
|
|
129
133
|
*/
|
|
130
|
-
callOperation(input:
|
|
134
|
+
callOperation<P, R, K>(input: ODataTypedRunInput<P, R, K>): Promise<ODataCallAnswer<ODataRunValue<R, K>> | null>;
|
|
135
|
+
/**
|
|
136
|
+
* Calls an operation bound to this entity set by its name, untyped, as {@link callOperation}
|
|
137
|
+
* calls one by its handle: an operation only the live service has.
|
|
138
|
+
*
|
|
139
|
+
* @throws Error for an entity set the live service no longer has.
|
|
140
|
+
*/
|
|
141
|
+
callOperationByName(input: Omit<ODataNamedRunInput, "entitySet">): Promise<ODataCallAnswer | null>;
|
|
142
|
+
private run;
|
|
131
143
|
registerReadable(...args: Parameters<BaseDbAdapter["registerReadable"]>): void;
|
|
132
144
|
/**
|
|
133
145
|
* The entity set this adapter reads, as the query layer describes it: from the live model, or,
|
|
@@ -150,6 +162,16 @@ declare class ODataAdapter extends BaseDbAdapter {
|
|
|
150
162
|
* A navigation the service declares no foreign key for (`@db.rel.store`) is read the same way.
|
|
151
163
|
*/
|
|
152
164
|
supportsWithInRead(): boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Reads (rows, counts, grouped reads) filter by a related row of a to-one navigation of the same
|
|
167
|
+
* service: `{ order: { $some: { status_code: { $ne: "X" } } } }` is the navigation path,
|
|
168
|
+
* guarded by the related entity's presence, `(order ne null and order/status_code ne 'X')`, in
|
|
169
|
+
* `$filter` and in the `filter()` of an `$apply`; `$none` is its negation, a row with no related
|
|
170
|
+
* one included. Refused (`REL_FILTER_NOT_SUPPORTED`): a
|
|
171
|
+
* predicate on a to-many navigation, one on OData v2 or on a navigation the set does not let a
|
|
172
|
+
* filter use, and every predicate of a write (there is no write by query).
|
|
173
|
+
*/
|
|
174
|
+
supportsRelationFilters(mode: "read" | "write"): boolean;
|
|
153
175
|
/** A relation is read through `$expand`: only to a table of the same service. */
|
|
154
176
|
sharesStoreWith(other: BaseDbAdapter): boolean;
|
|
155
177
|
/**
|
|
@@ -368,6 +390,13 @@ declare class ODataAdapter extends BaseDbAdapter {
|
|
|
368
390
|
* field.
|
|
369
391
|
*/
|
|
370
392
|
private get leaves();
|
|
393
|
+
/**
|
|
394
|
+
* A filter as the table layer hands it over, as the query layer of `@atscript/odata` takes it:
|
|
395
|
+
* each relational predicate the table layer resolved back to `{ nav: { $some | $none: filter } }`,
|
|
396
|
+
* the related table's filter (its own predicates in turn) as its adapter has it. A predicate on a
|
|
397
|
+
* to-many navigation is refused before any request.
|
|
398
|
+
*/
|
|
399
|
+
private odataFilter;
|
|
371
400
|
/**
|
|
372
401
|
* The read of a query, with the `$with` entries as expansions: each translated by the adapter
|
|
373
402
|
* of its table (one of the same service, see {@link sharesStoreWith}), nested entries included.
|
|
@@ -474,21 +503,31 @@ declare class ODataSpace extends DbSpace {
|
|
|
474
503
|
*/
|
|
475
504
|
refusalOf(operation: ODataOperationRef<any, unknown, unknown>): ODataOperationVerdict | undefined;
|
|
476
505
|
/**
|
|
477
|
-
* Calls an operation of the service
|
|
478
|
-
*
|
|
479
|
-
* unbound one, or a bound one
|
|
480
|
-
* `ODataAdapter.callOperation`).
|
|
481
|
-
*
|
|
482
|
-
*
|
|
483
|
-
*
|
|
484
|
-
*
|
|
485
|
-
*
|
|
486
|
-
*
|
|
487
|
-
* `
|
|
506
|
+
* Calls an operation of the service by its handle of the model module's `ops`
|
|
507
|
+
* (`runOperation` of `@atscript/odata`), with the space's credentials, the session it keeps for
|
|
508
|
+
* them and its language, as the tables' calls are made: an unbound one, or a bound one (a set's
|
|
509
|
+
* table calls its own with `ODataAdapter.callOperation`). The handle types the call: `params`
|
|
510
|
+
* is required when the operation has a required parameter, `rows` when it is called on rows, and
|
|
511
|
+
* the answer's `value` is its result (one per row on rows). An operation the live service no
|
|
512
|
+
* longer fits is refused first (see {@link refusalOf}); the parameters are validated against
|
|
513
|
+
* the live operation type (the validator's `ValidatorError`). What the call throws, and the
|
|
514
|
+
* error of each row in `failed`, is mapped as the adapter's `callOperation` maps it: a call that
|
|
515
|
+
* sends the caller's version token (a call that writes, on a row with its `__etag`) refused with
|
|
516
|
+
* `412` is that row's version mismatch, for the caller to answer (one row resolves `null`, a
|
|
517
|
+
* row of several is `{ index, error: null }` in `failed`), a row the service has no entity for
|
|
518
|
+
* a `DbError` `NOT_FOUND`, the rest as the tables' calls (`toDbError`).
|
|
519
|
+
*
|
|
520
|
+
* @throws Error before the space is connected.
|
|
521
|
+
*/
|
|
522
|
+
callOperation<P, R, K>(input: ODataTypedRunInput<P, R, K>): Promise<ODataCallAnswer<ODataRunValue<R, K>> | null>;
|
|
523
|
+
/**
|
|
524
|
+
* Calls an operation by its name, untyped, as {@link callOperation} calls one by its handle:
|
|
525
|
+
* an operation only the live service has. A bound one names its entity set in `entitySet`.
|
|
488
526
|
*
|
|
489
527
|
* @throws Error before the space is connected.
|
|
490
528
|
*/
|
|
491
|
-
|
|
529
|
+
callOperationByName(input: ODataNamedRunInput): Promise<ODataCallAnswer | null>;
|
|
530
|
+
private run;
|
|
492
531
|
}
|
|
493
532
|
/**
|
|
494
533
|
* Creates a `DbSpace` over an OData service: `space.getTable(Type)` returns a table that reads the
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseDbAdapter, DbError, DbSpace, isPlainObject, searchIndexNotFoundMessage } from "@atscript/db";
|
|
1
|
+
import { BaseDbAdapter, DbError, DbSpace, containsRelationFilter, hasRelationOp, isPlainObject, isResolvedRelationFilter, searchIndexNotFoundMessage } from "@atscript/db";
|
|
2
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";
|
|
@@ -531,9 +531,25 @@ var ODataAdapter = class extends BaseDbAdapter {
|
|
|
531
531
|
* mapped so (`SERIALIZATION_FAILURE` for a `412`, `CONFLICT` for a `404`: nothing was applied;
|
|
532
532
|
* the entries of a message that names a row at that row, `[1]`).
|
|
533
533
|
*
|
|
534
|
+
* The handle types the call: `params` is required when the operation has a required parameter,
|
|
535
|
+
* `rows` when it is called on rows, and the answer's `value` is its result (one per row on
|
|
536
|
+
* rows). An operation only the live service has is called with {@link callOperationByName}.
|
|
537
|
+
*
|
|
538
|
+
* @throws Error for an entity set the live service no longer has.
|
|
539
|
+
*/
|
|
540
|
+
callOperation(input) {
|
|
541
|
+
return this.run(input);
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* Calls an operation bound to this entity set by its name, untyped, as {@link callOperation}
|
|
545
|
+
* calls one by its handle: an operation only the live service has.
|
|
546
|
+
*
|
|
534
547
|
* @throws Error for an entity set the live service no longer has.
|
|
535
548
|
*/
|
|
536
|
-
|
|
549
|
+
callOperationByName(input) {
|
|
550
|
+
return this.run(input);
|
|
551
|
+
}
|
|
552
|
+
async run(input) {
|
|
537
553
|
this.refuseGone();
|
|
538
554
|
const connection = this.options.connection?.();
|
|
539
555
|
if (!connection) throw new Error(`Table "${this.entitySet.name}": an operation runs on the connection of an OData space (createODataSpace), which it has not`);
|
|
@@ -588,6 +604,18 @@ var ODataAdapter = class extends BaseDbAdapter {
|
|
|
588
604
|
supportsWithInRead() {
|
|
589
605
|
return true;
|
|
590
606
|
}
|
|
607
|
+
/**
|
|
608
|
+
* Reads (rows, counts, grouped reads) filter by a related row of a to-one navigation of the same
|
|
609
|
+
* service: `{ order: { $some: { status_code: { $ne: "X" } } } }` is the navigation path,
|
|
610
|
+
* guarded by the related entity's presence, `(order ne null and order/status_code ne 'X')`, in
|
|
611
|
+
* `$filter` and in the `filter()` of an `$apply`; `$none` is its negation, a row with no related
|
|
612
|
+
* one included. Refused (`REL_FILTER_NOT_SUPPORTED`): a
|
|
613
|
+
* predicate on a to-many navigation, one on OData v2 or on a navigation the set does not let a
|
|
614
|
+
* filter use, and every predicate of a write (there is no write by query).
|
|
615
|
+
*/
|
|
616
|
+
supportsRelationFilters(mode) {
|
|
617
|
+
return mode === "read";
|
|
618
|
+
}
|
|
591
619
|
/** A relation is read through `$expand`: only to a table of the same service. */
|
|
592
620
|
sharesStoreWith(other) {
|
|
593
621
|
return super.sharesStoreWith(other) && other.service === this.service;
|
|
@@ -1104,12 +1132,38 @@ var ODataAdapter = class extends BaseDbAdapter {
|
|
|
1104
1132
|
return this._leaves;
|
|
1105
1133
|
}
|
|
1106
1134
|
/**
|
|
1135
|
+
* A filter as the table layer hands it over, as the query layer of `@atscript/odata` takes it:
|
|
1136
|
+
* each relational predicate the table layer resolved back to `{ nav: { $some | $none: filter } }`,
|
|
1137
|
+
* the related table's filter (its own predicates in turn) as its adapter has it. A predicate on a
|
|
1138
|
+
* to-many navigation is refused before any request.
|
|
1139
|
+
*/
|
|
1140
|
+
odataFilter(filter, path = "") {
|
|
1141
|
+
if (!filter || !containsRelationFilter(filter)) return filter;
|
|
1142
|
+
const entries = Object.entries(filter).map(([key, value]) => {
|
|
1143
|
+
if ((key === "$and" || key === "$or") && Array.isArray(value)) return [key, value.map((child) => this.odataFilter(child, path))];
|
|
1144
|
+
if (key === "$not") return [key, this.odataFilter(value, path)];
|
|
1145
|
+
if (key.startsWith("$") || !hasRelationOp(value)) return [key, value];
|
|
1146
|
+
const at = path ? `${path}.${key}` : key;
|
|
1147
|
+
const navigation = this.entitySet.navigations.find((nav) => nav.name === key);
|
|
1148
|
+
if (!navigation?.filterable || navigation.collection) throw new DbError("REL_FILTER_NOT_SUPPORTED", [{
|
|
1149
|
+
path: at,
|
|
1150
|
+
message: `Cannot filter by related "${at}" rows: ${navigation?.filterable ? `"${key}" is a to-many navigation, and only a to-one one is filtered by on the server; read the related set and filter by its key` : `the service does not filter by "${key}" (OData v2, or a restriction of the set)`}`
|
|
1151
|
+
}]);
|
|
1152
|
+
const ops = Object.entries(value).map(([op, operand]) => [op, isResolvedRelationFilter(operand) ? operand.target.adapter.odataFilter(operand.filter, at) : operand]);
|
|
1153
|
+
return [key, Object.fromEntries(ops)];
|
|
1154
|
+
});
|
|
1155
|
+
return Object.fromEntries(entries);
|
|
1156
|
+
}
|
|
1157
|
+
/**
|
|
1107
1158
|
* The read of a query, with the `$with` entries as expansions: each translated by the adapter
|
|
1108
1159
|
* of its table (one of the same service, see {@link sharesStoreWith}), nested entries included.
|
|
1109
1160
|
* Related rows keep their key at every depth, whatever their selection.
|
|
1110
1161
|
*/
|
|
1111
1162
|
shapeOf(query) {
|
|
1112
|
-
return withRelations(readShapeOf(
|
|
1163
|
+
return withRelations(readShapeOf({
|
|
1164
|
+
...query,
|
|
1165
|
+
filter: this.odataFilter(query.filter)
|
|
1166
|
+
}, this.context), (query.controls.$with ?? []).map(({ nav, isArray, target, query: related }) => {
|
|
1113
1167
|
const adapter = target.adapter;
|
|
1114
1168
|
return {
|
|
1115
1169
|
nav,
|
|
@@ -1130,7 +1184,7 @@ var ODataAdapter = class extends BaseDbAdapter {
|
|
|
1130
1184
|
alias: resolveAlias(expr)
|
|
1131
1185
|
}))
|
|
1132
1186
|
};
|
|
1133
|
-
if (query.filter && Object.keys(query.filter).length > 0) spec.filter = query.filter;
|
|
1187
|
+
if (query.filter && Object.keys(query.filter).length > 0) spec.filter = this.odataFilter(query.filter);
|
|
1134
1188
|
const having = controls.$having;
|
|
1135
1189
|
if (having && Object.keys(having).length > 0) spec.having = having;
|
|
1136
1190
|
const sort = Object.entries(controls.$sort ?? {});
|
|
@@ -1150,7 +1204,7 @@ var ODataAdapter = class extends BaseDbAdapter {
|
|
|
1150
1204
|
}
|
|
1151
1205
|
countSpecOf(query) {
|
|
1152
1206
|
const spec = { entitySet: this.entitySet.name };
|
|
1153
|
-
if (query.filter && Object.keys(query.filter).length > 0) spec.filter = query.filter;
|
|
1207
|
+
if (query.filter && Object.keys(query.filter).length > 0) spec.filter = this.odataFilter(query.filter);
|
|
1154
1208
|
return spec;
|
|
1155
1209
|
}
|
|
1156
1210
|
searchShapeOf(text, query, indexName) {
|
|
@@ -1287,21 +1341,35 @@ var ODataSpace = class extends DbSpace {
|
|
|
1287
1341
|
return refusalIn(this._connection, operation);
|
|
1288
1342
|
}
|
|
1289
1343
|
/**
|
|
1290
|
-
* Calls an operation of the service
|
|
1291
|
-
*
|
|
1292
|
-
* unbound one, or a bound one
|
|
1293
|
-
* `ODataAdapter.callOperation`).
|
|
1294
|
-
*
|
|
1295
|
-
*
|
|
1296
|
-
*
|
|
1297
|
-
*
|
|
1298
|
-
*
|
|
1299
|
-
*
|
|
1300
|
-
* `
|
|
1344
|
+
* Calls an operation of the service by its handle of the model module's `ops`
|
|
1345
|
+
* (`runOperation` of `@atscript/odata`), with the space's credentials, the session it keeps for
|
|
1346
|
+
* them and its language, as the tables' calls are made: an unbound one, or a bound one (a set's
|
|
1347
|
+
* table calls its own with `ODataAdapter.callOperation`). The handle types the call: `params`
|
|
1348
|
+
* is required when the operation has a required parameter, `rows` when it is called on rows, and
|
|
1349
|
+
* the answer's `value` is its result (one per row on rows). An operation the live service no
|
|
1350
|
+
* longer fits is refused first (see {@link refusalOf}); the parameters are validated against
|
|
1351
|
+
* the live operation type (the validator's `ValidatorError`). What the call throws, and the
|
|
1352
|
+
* error of each row in `failed`, is mapped as the adapter's `callOperation` maps it: a call that
|
|
1353
|
+
* sends the caller's version token (a call that writes, on a row with its `__etag`) refused with
|
|
1354
|
+
* `412` is that row's version mismatch, for the caller to answer (one row resolves `null`, a
|
|
1355
|
+
* row of several is `{ index, error: null }` in `failed`), a row the service has no entity for
|
|
1356
|
+
* a `DbError` `NOT_FOUND`, the rest as the tables' calls (`toDbError`).
|
|
1357
|
+
*
|
|
1358
|
+
* @throws Error before the space is connected.
|
|
1359
|
+
*/
|
|
1360
|
+
callOperation(input) {
|
|
1361
|
+
return this.run(input);
|
|
1362
|
+
}
|
|
1363
|
+
/**
|
|
1364
|
+
* Calls an operation by its name, untyped, as {@link callOperation} calls one by its handle:
|
|
1365
|
+
* an operation only the live service has. A bound one names its entity set in `entitySet`.
|
|
1301
1366
|
*
|
|
1302
1367
|
* @throws Error before the space is connected.
|
|
1303
1368
|
*/
|
|
1304
|
-
|
|
1369
|
+
callOperationByName(input) {
|
|
1370
|
+
return this.run(input);
|
|
1371
|
+
}
|
|
1372
|
+
async run(input) {
|
|
1305
1373
|
const connection = this._connection;
|
|
1306
1374
|
if (!connection) throw notConnected();
|
|
1307
1375
|
const init = sendInit(await this.callInit?.() ?? {});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/db-odata",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Atscript DB adapter that uses an OData v2/v4 service as the database.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adapter",
|
|
@@ -36,25 +36,25 @@
|
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@atscript/odata": "^0.0.
|
|
39
|
+
"@atscript/odata": "^0.0.4"
|
|
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.28",
|
|
43
|
+
"@atscript/db": "^0.1.204",
|
|
44
|
+
"@atscript/db-client": "^0.1.204",
|
|
45
|
+
"@atscript/typescript": "^0.2.28",
|
|
46
46
|
"@uniqu/core": "^0.2.2",
|
|
47
|
-
"unplugin-atscript": "^0.2.
|
|
47
|
+
"unplugin-atscript": "^0.2.28"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@atscript/db": "^0.1.
|
|
51
|
-
"@atscript/typescript": "^0.2.
|
|
50
|
+
"@atscript/db": "^0.1.204",
|
|
51
|
+
"@atscript/typescript": "^0.2.28",
|
|
52
52
|
"@uniqu/core": "^0.2.2"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"build": "vp pack",
|
|
56
56
|
"dev": "vp pack --watch",
|
|
57
|
-
"test": "vp test",
|
|
57
|
+
"test": "vp test --typecheck",
|
|
58
58
|
"check": "vp check"
|
|
59
59
|
}
|
|
60
60
|
}
|