Added
-
__uuid_gendirective — UUID generation indb.yml: setting any string field to__uuid_gen(or__uuid_gen:alias) causes yRest to replace it with a randomly generated UUID v4 at load time. yRest then rewritesdb.ymlwith the resolved values so IDs are stable across restarts — no manual UUID copy-paste required.users: - id: __uuid_gen:ana # generates a UUID, registers alias "ana" name: Ana - id: __uuid_gen:luis # generates a UUID, registers alias "luis" name: Luis
-
__fkdirective — cross-collection UUID references: setting a field to__fk.<collection>:<alias>resolves it to the UUID registered under that alias in the named collection. This wires FK relationships between collections whose IDs are generated at load time.posts: - id: __uuid_gen title: Hello World userId: __fk.users:ana # → same UUID as users[alias=ana].id
Resolution runs in two passes — all
__uuid_genvalues first, then all__fkreferences — so order in the file does not matter. Unresolvable aliases emit a console warning and leave the field value unchanged. -
--uuidCLI flag: shorthand for--id-strategy uuidonyrest serve. Applies to new items created viaPOST(not to the initial data indb.yml).npx @yrest/cli serve db.yml --uuid
Internal
src/storage/resolveDirectives.ts— new module; two-pass resolver operating on the parsedDataobject. Returnstruewhen any directive was resolved so callers know whether to persist.yrestStorage.ts— callsresolveDirectives(data)afterparseData()in bothcreateYrestStorageandreload(). Triggerspersist()immediately ifmodified = true.relationalinit template updated to demonstrate__uuid_gen:aliasand__fkacross all collections (users, profiles, posts, post_tags, comments).
Tests
tests/storage/resolveDirectives.test.ts— 19 unit tests: UUID generation, alias registration, FK resolution, cross-collection scope isolation, unresolvable alias warning, non-string field pass-through, nested object non-recursion.tests/routes/directives.test.ts— 6 integration tests: GET returns UUID IDs, single-item GET by generated UUID, write-back on disk after first load, FK consistency between collections, no re-write on second load of resolved file.