@atscript/odata-client 0.0.0-stage → 0.0.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Artem Maltsev <artem@maltsev.nl>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,405 @@
1
- # Temporary Holding Version
1
+ <p align="center">
2
+ <img src="https://odata.atscript.dev/logo.svg" alt="Atscript" width="120" />
3
+ </p>
2
4
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
5
+ <h1 align="center">@atscript/odata-client</h1>
6
+
7
+ <p align="center">
8
+ Browser client that talks OData directly and looks like an Atscript DB client.
9
+ </p>
10
+
11
+ <p align="center">
12
+ Part of Atscript OData. Works with SAP S/4HANA®, SAP Gateway and SAP RAP services, and with any standard OData v2/v4 service.
13
+ </p>
14
+
15
+ <p align="center">
16
+ <a href="https://odata.atscript.dev">Documentation</a>
17
+ </p>
18
+
19
+ ---
20
+
21
+ > Preview release (0.0.x) — APIs may still change between releases. This release reads, writes and calls operations (several rows as one `$batch`).
22
+
23
+ `ODataClient` stands in for the `Client` of `@atscript/db-client`: atscript-ui tables, filters,
24
+ paging, value-help pickers and forms work against an OData v2 or v4 service with no Atscript
25
+ server in between. It is a `ClientLike` of `@atscript/db-client` (every public member of
26
+ `Client`), not a subclass: `instanceof Client` is false, and code that types a client as
27
+ `ClientLike`, as atscript-ui's client factories do since 0.1.190, takes it as it is.
28
+
29
+ ## Installation
30
+
31
+ ```bash
32
+ pnpm add @atscript/odata-client @atscript/db-client @atscript/db @atscript/typescript @uniqu/core
33
+ ```
34
+
35
+ Needs `@atscript/db` and `@atscript/db-client` 0.1.200 or newer and `@atscript/typescript` 0.2.25
36
+ or newer.
37
+
38
+ The models come from the generator of `@atscript/odata`, and the screens from Atscript UI: see
39
+ the [installation guide](https://odata.atscript.dev/guide/installation). Every export is documented in the
40
+ [API reference](https://odata.atscript.dev/api/odata-client).
41
+
42
+ ## Use with atscript-ui
43
+
44
+ atscript-ui names every data source by a URL. Register your OData services with a client factory;
45
+ a URL of the form `<prefix>/<service>/<EntitySet>` is then served by OData, every other URL by a
46
+ plain `@atscript/db-client` `Client`.
47
+
48
+ Typed at build time, live at runtime: the models generated by the plugin of `@atscript/odata` give
49
+ the app its types; at runtime the factory reads the live `$metadata` (its value-help documents
50
+ included) and the generated module's classes become the live declarations:
51
+
52
+ ```ts
53
+ // src/main.ts
54
+ import { createODataClientFactory } from "@atscript/odata-client";
55
+ import { setDefaultClientFactory } from "@atscript/ui";
56
+ import { createApp } from "vue";
57
+ import App from "./App.vue";
58
+ import * as sales from "./odata/sales.as";
59
+ import { model } from "./odata/sales.model.gen";
60
+
61
+ const odata = createODataClientFactory({
62
+ services: [
63
+ {
64
+ baseUrl: "/sap/opu/odata/sap/ZDEMO_ORDERS_SRV",
65
+ query: { "sap-client": "100" },
66
+ model,
67
+ types: sales,
68
+ },
69
+ ],
70
+ });
71
+ setDefaultClientFactory(odata);
72
+ odata.connect().then(() => createApp(App).mount("#app"), showStartError);
73
+ ```
74
+
75
+ A table of the entity set `OrderSet` is then addressed as `/odata/sales/OrderSet` (`sales` is the
76
+ name the models were generated with; `showStartError` is the app's own). After `connect()` the
77
+ imported types are live:
78
+ `createAsFormDef(sales.Order)` builds its form from the live service.
79
+
80
+ A registration takes the transport options (`baseUrl`, `query`, `headers`, `credentials`,
81
+ `dialect`, `merge`, `session`, `fetch`), `model`, `types` (the whole generated module), and
82
+ optionally `name` (default: the name the models were generated with), `copies` (the app's
83
+ `annotate X as Y` copies that annotate properties) and, for a registration without `model`,
84
+ `language` and `entitySets`. A registration without `model`
85
+ and `types` builds its types from the live document alone (runtime-only, no TypeScript types).
86
+
87
+ - **`factory.connect(name?)`** reads now and resolves with the connections by name. Clients
88
+ connect on their first call anyway, all of a service sharing one read. Connect before the app
89
+ mounts: a type used before the connection is the saved one.
90
+ - **A failed read is not kept**: the next call reads again, so a user who signs in again needs no
91
+ reload. It fails as a data call does: a `ClientError` with the status, `401`
92
+ `UNEXPECTED_CONTENT` for a login page, a `TransportError` for no answer or an answer that is no
93
+ `$metadata`.
94
+ - **An entity set the live service lacks** answers every call with a `ClientError` 404
95
+ `NOT_FOUND`.
96
+ - **The browser runs on whatever the live service has**: no drift report, nothing logged about
97
+ a change. Code that uses a property the live service dropped fails at runtime; regenerate the
98
+ models to find it at build time.
99
+
100
+ The fixed form `{ name, service, types }` (an engine of `createODataService`, read from no
101
+ `$metadata`) remains for tests and tools. See
102
+ [Browser client](https://odata.atscript.dev/guide/browser-client) and
103
+ [Live metadata](https://odata.atscript.dev/guide/live-metadata).
104
+
105
+ How requests are written (case-insensitive text filters, literals, search) is the service's
106
+ dialect. It follows the `$metadata`: `sap` for an SAP Gateway or RAP service, `standard` for any
107
+ other OData service. Pass `dialect` (`"sap"` or `"standard"`) in the registration to choose the
108
+ preset yourself.
109
+
110
+ Once a service is connected, the factory writes each entity set's URL into its type as
111
+ `db.http.path`. This is how atscript-ui finds the target of a foreign key or of a `@ui.valueHelp`
112
+ binding. The value-help annotations the generator writes (`@ui.valueHelp` with its filter,
113
+ `.fill`, `.column`, `@ui.type 'select'`, `@ui.valueLabel`; see `@atscript/odata`) reach
114
+ atscript-ui in the metadata as they are.
115
+
116
+ ### Value helps in value-help services (OData v4, SAP RAP)
117
+
118
+ On SAP RAP v4 a value list lives in a separate value-help service (`Common.ValueListReferences`).
119
+ The generator takes their documents (`valueHelps`, see `@atscript/odata`) and emits an interface
120
+ per value-help entity set a binding targets, marked `@odata.valueHelpService`; at runtime the
121
+ factory reads the documents with the live `$metadata`. The factory registers those sets with the
122
+ service, nothing to list: a URL `<prefix>/<service>/<value-help service>/<EntitySet>` (each
123
+ segment URI-encoded, for example `/odata/sales/..%2F..%2Fsrvd_f4%2Fsap%2Fcountry_vh%2F0001/CountryVH`)
124
+ gets a client that reads the set at the value-help service's own root, with the service's options
125
+ and session. The URL is what atscript-ui routes by (`db.http.path`); it is never sent anywhere.
126
+
127
+ The value-help services are in the generated model module: register the service with its
128
+ `model`, as above.
129
+
130
+ ### Factory options
131
+
132
+ | Option | Default | Meaning |
133
+ | ------------ | ----------------------- | --------------------------------------------------------------- |
134
+ | `services` | | One registration per OData service (above) |
135
+ | `prefix` | `/odata` | URL prefix of OData entity sets |
136
+ | `fallback` | db-client `Client` | Client (any `ClientLike`) of every other URL |
137
+ | `locale` | `accept-language` | Send atscript-ui's locale as `Accept-Language`, or `ignore` it |
138
+ | `queryLimit` | `1000` | Rows `query()` returns without a `$limit`; `0` reads everything |
139
+ | `call` | one session per service | Session, headers and read options of every OData call |
140
+
141
+ ## What works
142
+
143
+ | `Client` member | `ODataClient` |
144
+ | ------------------------------------------------------------ | --------------------------------------------------------- |
145
+ | `meta()`, `metaEtag()`, `invalidateMeta()`, `getValidator()` | Built from the service model and the entity set's type |
146
+ | `query()`, `count()`, `pages()`, `one()` | OData reads; `one()` resolves `null` for a missing entity |
147
+ | `insert()`, `update()`, `replace()`, `remove()` | OData writes, where the service allows them (see below) |
148
+ | `aggregate()` | One OData v4 `$apply` request (see below) |
149
+ | `geoSearch()`, `geoPages()` | Reject: `ClientError` 400, code `NOT_SUPPORTED` |
150
+ | `action()`, `getActionForm()`, `availableActions()` | The service's operations bound to the set (see below) |
151
+ | `actionOnQuery()`, `countActionTarget()` | Reject: `ClientError` 400, code `NOT_SUPPORTED` |
152
+
153
+ Rows come in the order an atscript-db backend over the same service returns them: a sort gets the
154
+ key properties it leaves out appended in the direction of its last key, and `pages()` without a
155
+ sort (and without a search) is ordered by the key, ascending — as far as the entity set can sort
156
+ by the key. Consecutive pages therefore neither overlap nor skip rows.
157
+
158
+ A draft-enabled entity set (`Common.DraftRoot` / `Common.DraftNode`) is listed and counted for its
159
+ active entities: a read whose filter has no condition on `IsActiveEntity` of its own gets
160
+ `IsActiveEntity eq true`, so the user's drafts do not show up next to them. `one()` reads the key
161
+ it is given, draft or active.
162
+
163
+ The metadata advertises exactly that: `crud` lists the reads the entity set supports and the
164
+ writes it allows, `actions` the operations bound to the set, and every field carries the sort and filter capabilities
165
+ the service declares. An OData v4 set is searchable unless its `SearchRestrictions` say otherwise;
166
+ for a v4 service that refuses `$search` and declares nothing, register it with `search: false`:
167
+ its sets are then searchable only where the metadata declares it (a `SearchRestrictions` record
168
+ whose `Searchable` is not false). The served type keeps the `db.*` annotations moost-db serves, currency,
169
+ unit and precision among them.
170
+
171
+ Relations of `$with` are read through `$expand` in the same request, with their filter, selection
172
+ and sort on v4 (v2 takes only the selection; a filter or sort of a relation is refused there with
173
+ `ClientError` 400 `NOT_SUPPORTED`, as a Moost server answers it). A relation whose filter can never match
174
+ (an empty `$in`) is left out of the request and every row has it empty, `[]` or `null`.
175
+ `relations` in the metadata lists the navigations of the type the service expands, as moost-db
176
+ lists them: `direction` `to` / `from` for a navigation over a foreign key, `store` for one the
177
+ service declares no usable foreign key for (`@db.rel.store` in the generated type). Related rows
178
+ carry no version token.
179
+
180
+ ## Operations
181
+
182
+ The browser client is the live client: it offers and calls the operations the live service has.
183
+ The operations bound to a set's type are its client's db actions, as a Moost server's generated
184
+ base declares them, so atscript-ui shows them on the table as it shows a Moost server's: an
185
+ operation on rows on each row and on the selection, one on the table in the toolbar, with a form
186
+ where it takes parameters.
187
+
188
+ - `meta().actions` lists them: the local name, `rows` or `table`, the label of the live
189
+ `<Name>Params` type, `inputForm` where it has parameters; `getActionForm(name)` is that type.
190
+ - `action(name, ids, input)` validates the input against the form, reads the rows' version tokens
191
+ where the call writes (one read, the key filter) and sends each token as `If-Match` (a `412` on
192
+ it is that row's `VersionMismatchError`). Several rows go out as one `$batch` by the live
193
+ operation's grouping: `isolated` (each row on its own, the default; OData v2 metadata almost
194
+ never names another) or `changeSet` (all or none). On rows it answers what a Moost server
195
+ answers: moost-db's action target summary (`matched`, `processed`, `skipped`, `failed` with each
196
+ row's `status` and `code`) with one `value` per row; every row failed is the first row's error
197
+ with every row's entries at `[i]`, a refused `changeSet` run its one error.
198
+ - The service's availability (`sap:applicable-path`, `Core.OperationAvailable`) is a hint:
199
+ `$actions` on a read and `availableActions(id)` list the row actions it offers on a row. No call
200
+ is filtered by it: the service decides.
201
+
202
+ Any operation is callable through the factory, typed by its handle of the model module's `ops`, or
203
+ untyped by its name (one only the live service has):
204
+
205
+ ```ts
206
+ import { ops } from "./odata/sales.model.gen";
207
+
208
+ const { value: price } = await odata.call(ops.GetPrice, { params: { Material: "M-100" } });
209
+ const order = await odata("/odata/sales/OrderSet").one("4500000001");
210
+ await odata.call(ops.OrderSet.ReleaseOrder, { row: order!, params: { Note: "ok" } });
211
+ await odata.call("Z_RECALC", { params: { Plant: "1000" } });
212
+ ```
213
+
214
+ `row` sends its `__etag` as `If-Match` on a call that writes (a function, and a call on the
215
+ collection, sends `If-Match: *` on a set with a version token; a `412` to it is a `404`
216
+ `NOT_FOUND`: the row is gone); the third
217
+ argument takes `signal` and `locale` (sent as `Accept-Language`, as the clients send
218
+ atscript-ui's). The parameters are validated against the live type (`ClientValidationError`); `extra` sends
219
+ parameters an OData v2 import does not declare, untyped (OData v4 refuses it). An operation the
220
+ live service dropped fails when called: `ClientError` 400, `UNKNOWN_OPERATION` on the entry.
221
+
222
+ ## Aggregation
223
+
224
+ `aggregate()` sends one OData v4 `$apply` request, on an entity set the service declares `$apply`
225
+ for (`Aggregation.ApplySupported`), the same request the server sends for the same query:
226
+
227
+ ```ts
228
+ await client.aggregate({
229
+ filter: { CompanyCode: "1000" },
230
+ controls: {
231
+ $groupBy: ["Currency"],
232
+ $select: ["Currency", { $fn: "sum", $field: "Amount", $as: "total" }],
233
+ $having: { total: { $gt: 0 } },
234
+ },
235
+ });
236
+ // LineItems?$apply=filter(CompanyCode eq '1000')/groupby((Currency),
237
+ // aggregate(Amount with sum as total))/filter(total gt 0)
238
+ // → [{ Currency: "EUR", total: "1500.25" }]
239
+ ```
240
+
241
+ `$sort`, `$skip` and `$limit` apply to the groups; `$count` answers `[{ count }]`, the number of
242
+ groups, as moost-db does. The metadata lists the functions in `aggregateFns` (`sum`, `avg`, `min`,
243
+ `max` on an SAP service, which answers `$count` and `countdistinct` with `501`; also `count` and
244
+ `countDistinct` on any other), marks the filterable single values `groupable`, and `crud.query`
245
+ takes `groupBy`. A set without `$apply` (every set on OData v2) lists none.
246
+
247
+ Refused with `ClientError` 400, code `NOT_SUPPORTED`, before any call: a set without `$apply`; an
248
+ amount or quantity aggregated without its currency or unit in `$groupBy`; `sum` / `avg` of what is
249
+ no number; `count` of a field; calendar buckets, expressions, `first` / `last`, conditions, field
250
+ lists, two-level aggregates and `$search`. The entry's `path` names the field or control. A plain
251
+ `$select` field that is not in `$groupBy` is `INVALID_VALUE`. What only the service knows (which
252
+ properties it groups by or aggregates, an amount compared in `$having` without its currency) it
253
+ answers itself.
254
+
255
+ ## Writes
256
+
257
+ The write methods take what `Client` takes and answer what `Client` gets from moost-db:
258
+
259
+ | Call | OData | Result |
260
+ | ---------------------------- | ------------------------------------------ | -------------------------------------------------------------------- |
261
+ | `insert(row)` | `POST` to the entity set | `{ insertedId }`: the key value; the key object for a composite key |
262
+ | `insert(row, { returning })` | the same; v4 asks for the entity | `{ insertedId, row }` with the entity the service returned |
263
+ | `insert(rows)` | one `$batch`, a changeset per row | `{ insertedCount, insertedIds }` |
264
+ | `update(patch)` | `MERGE` (v2) / `PATCH` (v4) of the changes | `{ matchedCount, modifiedCount }`: `1, 1`; `0, 0` when it is missing |
265
+ | `replace(row)` | `PUT` of the whole entity | the same |
266
+ | `update(patches)` and so on | one call per row, counts summed | the same |
267
+ | `remove(id)` | `DELETE`, by the key value or a key object | `{ deletedCount: 1 }`; a missing entity is a `ClientError` 404 |
268
+
269
+ An update patch carries the key properties and the changed members, as an atscript-ui form's
270
+ `getPatch()` plus the row's key gives it; the key goes into the URL, the rest into the body. A
271
+ patch of nothing but the key writes nothing: it answers `{ 1, 0 }` when the entity exists, after a
272
+ read. An array write is not a transaction: when one row fails, the rows before it stay written,
273
+ and the error's paths name the row (`[2].City`). An array insert goes out as one `$batch`, each row
274
+ in a changeset of its own, so the rows after a refused one are created too: its error, as a Moost
275
+ server answers it, carries an `INSERTED` entry (`params.insertedId`) for each row created.
276
+
277
+ Before any request, a write is checked the way `Client` and moost-db check it:
278
+
279
+ - a write the entity set does not allow (not insertable, updatable or deletable, reached only
280
+ through a navigation, draft-enabled, the parameters of a parameterized view) is a `ClientError`
281
+ 400 `NOT_SUPPORTED`, the body a Moost server answers for it. The rule is `writeRefusal` of
282
+ `@atscript/odata`, which the server follows too, so `crud` in the metadata of both lists the
283
+ same writes;
284
+ - the payload is normalized and validated against the metadata's type, as db-client's preflight
285
+ does: a `ClientValidationError` with field paths;
286
+ - what OData cannot express is a `ClientError` 400 with a stable code: a `$cas` that is not the
287
+ set's version token (`CAS_NOT_SUPPORTED`; see [Concurrency](#concurrency-the-version-token)),
288
+ the array operators `$insert`, `$update`, `$upsert`, `$remove`
289
+ (`UNSUPPORTED_ARRAY_OPERATOR`; `$replace` is sent as the whole array), the field operators
290
+ `$inc`, `$dec`, `$mul` (`UNSUPPORTED_FIELD_OPERATOR`; these three are a `400` `NOT_SUPPORTED`
291
+ with the code on the entry, as the server answers `$inc` and an integer `$cas`), related entities in an update or replace
292
+ (`UNSUPPORTED_DEEP_UPDATE`, under `INVALID_QUERY`) and `onConflict: "ignore"` (`INVALID_QUERY`). Related
293
+ entities in an insert are created with it (deep insert) through a navigation with a foreign key;
294
+ a value in a navigation without one (`@db.rel.store`) is refused by the validation
295
+ (`NAV_STORE_WRITE`), as on the server.
296
+
297
+ Properties the service maintains are left out of the request: computed ones always, immutable
298
+ ones in an update or replace, update-only ones in an insert. A computed scalar carries
299
+ `@db.default.store` next to its `@meta.readonly` in the generated type, so an atscript-ui form
300
+ shows it read-only, and it and the preflight let an insert leave it out although the type requires
301
+ it (a key the service assigns, which the answer names). A GUID the service fills in when an insert
302
+ leaves it out (`Core.ComputedDefaultValue`, SAP CAP's `cuid` key) carries `@db.default.uuid`: a
303
+ form and the preflight do not demand it, an insert without it leaves it to the service, and one
304
+ that gives it sends it. Immutable and update-only properties carry no annotation: a form offers
305
+ them in both modes, and a change the service would refuse is dropped.
306
+
307
+ ### Concurrency: the version token
308
+
309
+ An entity set that declares optimistic concurrency (`ConcurrencyMode="Fixed"`,
310
+ `Core.OptimisticConcurrency`, also with no property listed except on an SAP service, whose
311
+ entities carry no ETag then) has a version token in its generated
312
+ type: `__etag: string` with `@db.column.version @db.column.version.token`. Every row the client
313
+ reads carries the entity's ETag there, the meta names it `versionColumn`, and it is never sent to
314
+ the service.
315
+
316
+ - **With the token, conflicts are detected.** An update or replace that carries it (the row as
317
+ read, or `$cas: { __etag: "<ETag>" }`) is sent with it as `If-Match`, without reading first.
318
+ After a `412` the client reads the entity, as moost-db does: one that is there is db-client's
319
+ `VersionMismatchError` (status 409, moost-db's body, the entity's current token as
320
+ `currentVersion`), a missing one a `ClientError` 404 `NOT_FOUND`. In an array write such a row
321
+ counts `{ matchedCount: 0 }`, as moost-db sums it.
322
+ - **Without it, last write wins.** An update or replace without the token, and every remove,
323
+ overwrites whatever changed since the caller read the row: the client reads the entity right
324
+ before the write and sends its current ETag as `If-Match`, which only satisfies the service's
325
+ If-Match requirement (it would answer `428` otherwise). A missing entity found by that read is
326
+ answered without a write; a `412` in the moment between the read and the write has both
327
+ repeated, three attempts in all, then a `ClientError` 503 `SERIALIZATION_FAILURE`, as a Moost
328
+ server answers it.
329
+
330
+ `$cas` on a set without a token, with an integer version, or on an insert is refused
331
+ (`CAS_NOT_SUPPORTED`). A token in the row of an insert is not sent. An atscript-ui edit form
332
+ (0.1.190 and later) sends the token of the row it loaded as `$cas`, so its save detects conflicts.
333
+
334
+ ### Sessions and CSRF
335
+
336
+ Every call is made with a session, so the CSRF token a write needs is fetched once and reused:
337
+ the `session` of the `call` option when it names one, else the `session` of the registration,
338
+ else one session per service that all its clients share. In a browser the cookies are the
339
+ browser's.
340
+
341
+ ## Batching
342
+
343
+ The calls made in one synchronous pass (a table page and its value-help dropdowns) go out as one
344
+ OData `$batch`, as UI5 does: each read a part of its own, each write a changeset of its own, each
345
+ call answering what it would alone; a pass of one call goes out alone. `batch: false` turns it off
346
+ for a registration or a call; a service whose `$metadata` says `Capabilities.BatchSupported` is
347
+ false, or that answers `$batch` with `404`, `405` or `501`, is not batched. `odata.createBatch()`
348
+ groups calls on purpose, with changesets applied all or none:
349
+
350
+ ```ts
351
+ const batch = odata.createBatch();
352
+ const changes = batch.changeset();
353
+ const a = orders.update({ ...first, Status: "R" }, { batch: changes });
354
+ const b = orders.update({ ...second, Status: "R" }, { batch: changes });
355
+ await batch.send();
356
+ ```
357
+
358
+ See [Batching](https://odata.atscript.dev/guide/browser-client#batching).
359
+
360
+ ## Errors
361
+
362
+ `ODataClient` throws the error classes of `@atscript/db-client`. What the engine refuses, and a
363
+ `400`, `409`, `429` or `5xx` of the service, goes through `dbFailureOf` of `@atscript/odata`, the one
364
+ mapping both hosts use: the same status and entries as a Moost server's answer (its envelope can
365
+ differ where moost-db's own controller checks refuse a field first, so branch on the entries'
366
+ codes):
367
+
368
+ - a read OData cannot express, or the service model does not allow, is a `ClientError` 400
369
+ `INVALID_QUERY` with one entry, coded as moost-db codes it (`UNKNOWN_FIELD`,
370
+ `FIELD_NOT_PERMITTED` with `params` at the field, `UNKNOWN_RELATION` at `$with`), else with the
371
+ engine's code (`UNSUPPORTED_REGEX`, `INVALID_VALUE`, `NOT_SEARCHABLE`, …); a write the
372
+ engine refuses for its payload is one too, the engine's code (`UNKNOWN_PROPERTY`,
373
+ `INVALID_VALUE`, …) on the entry at the payload path;
374
+ - a write the entity set does not allow, a grouped read it cannot answer and a v2 relation
375
+ filter or sort are a `ClientError` 400 `NOT_SUPPORTED`; a read past `maxPages` is 400
376
+ `INVALID_QUERY` on `$limit`;
377
+ - a `400` of the service is a `ClientError` 400 `INVALID_QUERY`, a `409` one 409 `CONFLICT`; any
378
+ other error the service answers keeps its HTTP status and code. Every one keeps the service's leading message as `message`; its
379
+ messages are listed in `errors` by the field their target names, the shape an atscript-ui form
380
+ maps onto its fields. The leading message is listed at its field when it names one, else at `""`
381
+ with the service's code when it has one no detail repeats; a detail without
382
+ a target is listed at the path `""`; a pseudo target like `/#TRANSIENT#` counts as none. The server
383
+ answers by the same rule, on v2 and v4;
384
+ - a `501` of the service (not implemented) is a `ClientError` 400 `NOT_SUPPORTED` with its message;
385
+ - any other `5xx` of the service is a `ClientError` 502 `STORE_FAILED` (`504`: 504 `STORE_TIMEOUT`), a
386
+ `429` one 429 `STORE_THROTTLED` with the service's `Retry-After` as `params.retryAfter` on the
387
+ entry: moost-db's answers, with a generic message;
388
+ - a stale version token is a `VersionMismatchError`, a missing entity on `remove` a `404`
389
+ `NOT_FOUND`, both with moost-db's body;
390
+ - parameters of an operation its type rejects are a `ClientValidationError`, before any call;
391
+ - a login page answered instead of data is a `ClientError` with status `401`
392
+ (`UNEXPECTED_CONTENT`), and so is a redirect answering a write: a write is never followed to
393
+ another address (a redirect to another origin without CORS headers is a network error, a
394
+ `TransportError`: the browser checks CORS on the `3xx` first);
395
+ - every call of an entity set the live service lacks is a `ClientError` 404 `NOT_FOUND`, the body
396
+ a Moost server answers;
397
+ - a network failure or an aborted call is a `TransportError`.
398
+
399
+ ## License
400
+
401
+ MIT
402
+
403
+ ---
404
+
405
+ SAP, SAP S/4HANA and the other SAP products named here are trademarks or registered trademarks of SAP SE (or an SAP affiliate company) in Germany and other countries. Atscript OData is not affiliated with or endorsed by SAP SE.