Live Metadata
Typed at build time, live at runtime. The saved $metadata gives the .as models and the TypeScript types your app is built against. At runtime both hosts read the service's live $metadata, value-help documents included, and run on it. The generated module's own classes become the live declarations, so every import of ./odata/sales.as is live once the host is connected.
// Browser (src/main.ts): connect, then mount
odata.connect().then(() => createApp(App).mount("#app"), showStartError);
// Moost server (server/main.ts): connect, then let Moost create the controllers
await space.connect();
await app.init();2
3
4
5
6
Browser Client and Moost Server show the registration and the space these lines connect.
See it live
The browser app reads the live $metadata before its first screen, the Moost server app before app.init(). Code: src/main.ts; src/server/main.ts.
The language
Labels are texts of the $metadata, and an SAP® service writes them in the language of the caller. Name the language the file was saved in, so the live documents come in the same one:
// atscript.config.ts
odataPlugin({
services: [{ name: "sales", metadata: "odata/sales.xml", language: "EN" }],
});2
3
4
- Every metadata read (the CLI, both hosts, the value-help documents) asks for it as the query option
sap-languageand as the headerAccept-Language. A service that is not SAP ignoressap-language. - The value is what the service takes: an SAP language code (
EN,DE) or a language tag (en). - Saved with the CLI:
atscript-odata fetch … --language ENreads every document in that language and writes it into the manifest beside the file. The plugin takes it from there when the service has nolanguageoption. - Saved from a signed-in browser: set
languageto the language that browser session was in. - Not set: nothing is sent, and the service picks the language of each caller. Labels may then follow the user, and the generated
.asfile ends with a note saying so. Set it. - Data calls: a Moost server also sends
Accept-Languagewith the language on every data call (unless itsinitsends one), so labels and data texts come in one language. The browser client sends Atscript UI's locale with its data calls (see Locale).
Connecting
On connect a host reads $metadata and every value-help document the build recorded, all at once. It compares them with the model module's model.build: what the plugin built from (the service name, entitySets, language, and a digest of each document). You never write model.build.
| The live documents | Path |
|---|---|
| Every document has the saved digest, and every document the build could not read still cannot be read | Fast: nothing is parsed or rebuilt. The compiled classes are used as they are. |
| Anything else | Slow: the live documents are parsed and planned as at build time, the generated classes are rebuilt in place, and the changes of your annotate blocks are written on them again. |
- What counts as a difference. Line ends, a byte order mark and whitespace between tags do not: a file a browser saved, or one checked out with other line ends, takes the fast path. Every other difference does.
- Labels are live. A label that changed is used as it is; the drift report does not list it.
- One read per host. All callers share it. A failed read is not kept: the browser reads again with the next call, the server does not start. What each host reports is listed in Errors.
- The server reads once, at start. Restart it to pick up a changed service. The browser reads on every page load.
typesneed the generatedmodel. The model module records what it was built from (model.build); a host giventypeswith a model that has no such record (one built by hand or byparseMetadata) refuses it. Generate both withasc.
In the browser
The browser runs on whatever the live service has. It takes the fast or the slow path above and stops there: no drift report, no diff against the saved model, nothing hidden, nothing logged.
- What the live service added is there: a property, an entity set, a value-help set, a write a set now allows. The client's
meta(), the tables and the forms show it. - Operations follow the live service too: one only it has is listed and callable by name, one it dropped is gone (see Operations).
- What it dropped is gone. Code of yours that still uses a property the live service dropped fails at runtime: a read that names it is refused with
ClientError400 (UNKNOWN_FIELDon the entry), before any request. An entity set gone live answers every call withClientError404NOT_FOUND, and a write the set no longer allows is refused withClientError400NOT_SUPPORTED(see Errors). - To find such code, save the
$metadataagain and rebuild: the TypeScript compiler then names every use of what is gone.
Drift report
The drift report is a Moost server feature. When the live $metadata differs from the saved one in more than its texts, space.connect() warns once through the space's logger (else console.warn):
OData service "sales": the live $metadata differs from the saved one (1 property(ies) added, 1 change(s)). The app runs on the live one; regenerate the models to build against it.
- property(ies) added: Order.DeliveryDate
- change(s): Order.Name: expect.maxLength 40 → 602
3
The report lists:
- entity sets gone and added (a set of a value-help service as
<value-help service>/<EntitySet>); - entity sets that allow fewer writes than they did (
OrderSet: insert, delete); - properties added and removed;
- changes of a property's type, optionality or other non-text annotations (
Order.Name: expect.maxLength 40 → 60); - changes of your
annotateblocks that could not be carried over, with their path and keys; - operations added, removed and incompatible with the build, with the reason (
ReleaseOrder: parameter Note Edm.String → Edm.Int32).
The server keeps running on the live model: validation and /meta follow it. An entity set gone live answers 404, a write the live service no longer allows is refused (see Moost Server), and an operation removed or changed against the build answers 404 or 500 (see Operations). Regenerate the models to build against the live service.
onDrift(drift, message) in the space replaces the warning, for example to send it to your monitoring. space.connection.drift carries the same report. Signatures: ODataDrift.
Your annotate blocks
Your annotate blocks keep working on the slow path: the host takes the changes they made to the generated classes before it rebuilds them, and writes them on the rebuilt classes again. A change whose property is gone live is dropped; on the Moost server the drift report lists it. Import your annotate files before the host connects, as before the first table, form or space.
| Your declaration | On the slow path |
|---|---|
annotate Order { … } | Written on the live Order again |
A property typed with a whole declaration (order: Order, items: OrderItem[]) | Follows the live type by itself |
annotate Order as OrderForm without property entries | Follows the live Order by itself |
annotate Order as OrderForm with property entries | List it in the registration's or the space's copies: [OrderForm], then it follows |
interface MyOrder extends Order, or a property reference (orderId: Order.OrderId) | Keeps the saved structure |
Limits
- A type used before the connection is the saved one. Atscript UI keeps some facts per type object: connect before the app mounts (browser) and before
app.init()(server). extendsand property references in your own declarations keep the saved structure.- A copy with property entries follows the live type only when it is listed in
copies. - One live version per generated module and process. A second registration or space over the same module that reads other documents throws: connect a generated module to one service.
- An OData v4 RAP service means one read per value-help document on every connect: every page load in the browser, every start of the server.
- A file saved by hand whose bytes differ beyond whitespace (entities, attribute order, quotes) always takes the slow path. Save it with the CLI, or save the raw response.
Without generated models
A browser registration without model and types builds the types from the live document: no build step, but no types to import either (see Browser Client). For a host of your own, createODataSource of @atscript/odata is what both hosts connect with.
DOs and DON'Ts
- Set
languagefor every service — without it the labels follow whoever is signed in. - Connect before the app mounts or before
app.init()— don't hand Atscript UI a type before its service is connected. - Regenerate when the service changed (on the Moost server the drift report says so; the browser says nothing) — the app runs on the live model, but your code is typed against the saved one.
- Save with the CLI or the raw response — a reformatted file always takes the slow path.
- List
annotate … ascopies that annotate properties incopies— unlisted, they keep the saved structure. - Connect each generated module to one service per process — a second, different one throws.
See also
- Generating Models: the plugin's
languageoption andatscript-odata fetch --language. createODataSource,ODataConnection,ServiceModelBuild: the signatures.- Errors: what each host does when the
$metadatacannot be read.