Repository navigation
v0.21.0: Live mock rule changes
What's new
Mock rules change while the server runs
In 0.20.0, a change to the mock rules in config.json showed only after a restart, and the restart dropped every write made since. Now the server watches config.json, and the files it extends: save a rule, refresh the app, and the generated rows follow it. The log says what was done:
MySrv/config.json: mock rules changed
Shippers: regenerated
Categories: has your changes, kept (restart to regenerate it)
- Your writes are kept. A set changed by a write since the start keeps its rows. A write that failed, such as a
$batchchangeset rolled back, doesn't count. - References stay valid. When the new rules change a set's keys, the rows that point at it are regenerated with it. If those rows have your changes, the set is kept instead:
Orders: kept, Order_Details refers to it and has your changes. - Only the sets that come out different are replaced. Their delta links answer
410 Gone, as after a restart. - A mistake doesn't stop the server. It's logged with how to fix it, and the rows stay as they were:
MySrv/config.json: a mock rule that doesn't fit the model:
mock "Shippers.CompnyName": Shippers has no property CompnyName. Did you mean "CompanyName"?
The rows are as they were: fix it and save again
A config.json created after the start is picked up too, so pasting the block --explain proposes into a new file works without a restart.
Saved data keeps up with the rules
With --persist, the generated rows were saved at the first start and never generated again: a changed rule showed only after --persist-reset, which dropped your writes too. Now each start generates the saved generated sets again, and replaces the ones that come out different, keeping the sets with your writes:
Saved state: loaded from MySrv.db (the rows above are not used)
The mock rules or the generator changed since the state was saved:
PurchaseOrderSet: regenerated
PurchaseOrderItemSet: has your changes, kept (--persist-reset to regenerate it)
The same happens when --mock-rows changes, or a new version generates rows differently. A set whose keys would change under rows with your writes that point at them is kept, as when the server runs. With replicas on PostgreSQL, the first server that starts regenerates, and the others load what it saved. Two servers starting at once agree on one state.
The rules apply at the next start, not while the server runs: several servers sharing a database would each regenerate.
Fixes
Found by fuzz testing: random rules, requests, metadata documents, data files, command lines and file edits, against every example and test model.
- A data file with two rows of the same key was loaded, and with
--persistone of them was lost at the next start. The start now says which rows:Orders.csv: rows 2 and 7 have the same key, ID 4. - A resource path with characters no segment has was read as another path:
Products(1)CategoryasProducts(1)/Category, and a lone(was a 500. Both are now a400. - A
Locationfor a key with a line break, a space or a non-ASCII character was a 500. It's now percent-encoded, and leads to the entity. - A metadata.xml that can't be used stopped the start with
Cannot read properties of undefined. It now says what's wrong:metadata.xml: EntityType Orders: Property OrderNo has no Type, a key that names no property, a set whose type has no key, XML that isn't well-formed (with its line). - A JSON data file that isn't a list of rows crashed the start. It now says so, with the row.
- Mock rules that can't fit are refused at the start with why: a date that doesn't exist (
2025-02-30), a number out of an integer's range or over a Decimal's Precision, or""on a property that can't be empty. - Generated rows: a set whose key is its parent's whole key (a product's detail) left some of its rows pointing at nothing; a Binary key is generated, where it was empty.
Upgrading
- Without
--persist, a running server watches its model folder, and the folders of the filesconfig.jsonextends. Saving changed mock rules regenerates the sets nothing has written to. - A regenerated set's delta links answer
410 Gone. Clients read the set again, as after a restart. - With
--persist, a start regenerates the saved generated sets that have no writes, when the rules,--mock-rowsor the generator changed. Tests that relied on saved generated rows staying as first generated will see the new ones. - A state saved by 0.20.0 or before doesn't record which sets are as generated: its sets are all kept. Start once with
--persist-resetfor the rules to apply from then on. It drops your writes. - A data file with two rows of the same key, or a JSON data file that isn't a list of objects, now stops the start, naming the rows.
- A path like
Products(1)Category, which was served asProducts(1)/Category, is now a400. - Mock rules that were accepted and generated values that don't fit (an impossible date, an Int16 of 40000) now stop the start with what's wrong.
- A set whose key is its parent's whole key (1:1) gets one row per parent: its generated rows differ from 0.20.0.
- A change to
operations,metadata.xmlor a data file still needs a restart. - Used as a library,
createAppdoesn't watch unless givenwatchRules: true.
Install
npx odata-prova@0.21.0 ./MySrv
docker run -p 3000:3000 -v "$PWD/MySrv:/models/MySrv:ro" ghcr.io/jaravan/odata-prova:0.21.0Details: Changing rules while the server runs, With --persist, Keeping the data.