toilscript 0.1.36 → 0.1.38

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "imports": {
3
- "toilscript": "https://cdn.jsdelivr.net/npm/toilscript@0.1.36/dist/toilscript.js",
4
- "toilscript/cli": "https://cdn.jsdelivr.net/npm/toilscript@0.1.36/dist/cli.js",
3
+ "toilscript": "https://cdn.jsdelivr.net/npm/toilscript@0.1.38/dist/toilscript.js",
4
+ "toilscript/cli": "https://cdn.jsdelivr.net/npm/toilscript@0.1.38/dist/cli.js",
5
5
  "binaryen": "https://cdn.jsdelivr.net/npm/binaryen@130.0.0-nightly.20260609/index.js",
6
6
  "long": "https://cdn.jsdelivr.net/npm/long@5.3.2/index.js"
7
7
  }
@@ -2994,8 +2994,30 @@ declare module "types:toilscript/src/parser" {
2994
2994
  /** Finishes parsing. */
2995
2995
  finish(): void;
2996
2996
  weaveDataMigrations(): void;
2997
- /** Replace `newType`'s generated `decodeInto` with a version-dispatching one. */
2997
+ /** Enforce the migration-file convention (folder AND extension): every `@migrate`
2998
+ * must live in a `*.migration.ts` file under a `migrations/` directory. Keeping
2999
+ * migrations in one discoverable place is what lets the build auto-parse them and
3000
+ * the weave inject the cross-file imports; a stray `@migrate` elsewhere would not
3001
+ * be discovered (silently never run), so it is a hard error. */
3002
+ private checkMigrationLocations;
3003
+ /** Replace `target`'s generated `decodeInto` with a version-dispatching one: a
3004
+ * row at any chain-reachable old version is decoded as its shape and run forward
3005
+ * through every transform until it reaches `target`. */
2998
3006
  private weaveDecodeInto;
3007
+ /** Record that `sym` (an old `@data` shape or a transform fn) must be imported
3008
+ * into the value type's source from `srcPath`. A blank or same-file source is a
3009
+ * no-op (the symbol is already in scope). Deduped per source via parallel arrays. */
3010
+ private addMigrationImport;
3011
+ /** Internal path of the source declaring the `@data` class `name`, or "" if it
3012
+ * isn't a known `@data` type (then there is nothing to import). */
3013
+ private typeSourcePath;
3014
+ /** A `"./.."`-style module specifier from importing file `fromInternal` to target
3015
+ * module `toInternal` (both extension-less internal paths), e.g.
3016
+ * `("models/User","migrations/User.migration") -> "../migrations/User.migration"`. */
3017
+ private relativeModulePath;
3018
+ /** Copy the fields a delta-step's old and new layouts SHARE (same name + type +
3019
+ * array-ness) from `prevVar` into `nextVar`. */
3020
+ private migrationCarry;
2999
3021
  private checkToilDbKinds;
3000
3022
  /** Map every `@database` class (incl. inside namespaces) to its
3001
3023
  * collection-name -> handle-family-name. */
@@ -4296,11 +4318,31 @@ declare module "types:toilscript/src/dbcatalog" {
4296
4318
  * `schema_version`: a hash over the ORDERED field layout (name, type, is_array),
4297
4319
  * NOT the value-type name. Adding, removing, retyping, or REORDERING a field
4298
4320
  * changes it - so the runtime can tell a compatible (append-only) change from a
4299
- * breaking one, instead of silently misreading old rows. (Flat, like toildb's
4300
- * `SchemaDescriptor::layout_hash`: a change to a NESTED `@data` type's own fields
4301
- * does not bump the parent - that lands with recursive layouts later.)
4321
+ * breaking one, instead of silently misreading old rows.
4322
+ *
4323
+ * RECURSIVE into nested `@data` types: when a field's `typeName` is a KNOWN
4324
+ * `@data` type (a key of `typeMap`) and not already on the `seen` set (cycle
4325
+ * guard), the SAME running hash continues over that nested type's fields - so a
4326
+ * breaking change to a NESTED type bumps the OUTER `schema_version` and can be
4327
+ * `@migrate`d (instead of being refuse-only). This MUST stay byte-identical to
4328
+ * toildb's `SchemaDescriptor::layout_hash` (the runtime side): the algorithm,
4329
+ * the `seen` add/remove, and the declaration-order traversal are pinned in lock
4330
+ * step. A FLAT type (no field whose type is in `typeMap`) hashes to the SAME
4331
+ * value as the old flat hash, so existing pinned vectors stay green; an absent
4332
+ * `typeMap` (undefined) is flat/back-compatible.
4333
+ *
4334
+ * `typeMap` MUST contain the SAME set of `@data` types as the runtime's
4335
+ * `toildb.types` registry (collection value types + their nested types, EXCLUDING
4336
+ * old `*.migration.ts` shapes), or the two hashes diverge: a nested field whose
4337
+ * type is absent from the map on either side is treated as a LEAF on both sides.
4302
4338
  */
4303
- export function layoutHash(fields: FieldLayout[]): number;
4339
+ export function layoutHash(fields: FieldLayout[], typeMap?: Map<string, FieldLayout[]> | null, seen?: Set<string> | null): number;
4340
+ /** The recursion type map for `layoutHash`: every `@data` type the runtime's
4341
+ * `toildb.types` registry also contains (collection value types + their nested
4342
+ * types), EXCLUDING old `*.migration.ts` shapes (which the runtime registry
4343
+ * excludes by design). Both sides must recurse through the SAME set, so a
4344
+ * nested field whose type is NOT here is a leaf on both sides. */
4345
+ export function recursionTypeMap(sources: Source[]): Map<string, FieldLayout[]>;
4304
4346
  /** Extract the encoded field layout of a `@data` class, in declaration order,
4305
4347
  * mirroring `injectDataCodec` (skip static; `Array<T>` -> element + array flag;
4306
4348
  * else scalar/string/`Uint8Array`/nested-`@data` by its type name). */
@@ -4314,17 +4356,37 @@ declare module "types:toilscript/src/dbcatalog" {
4314
4356
  fnName: string;
4315
4357
  oldVersion: number;
4316
4358
  delta: boolean;
4359
+ sourceInternalPath: string;
4317
4360
  }
4318
4361
  /** Every `@migrate` function across the (non-library) sources. `layouts` maps a
4319
- * `@data` class name to its field layout, for the old-version hash. A migration
4320
- * whose param/return is not a single named type, or whose old type has no
4321
- * layout, is skipped. */
4322
- export function collectMigrations(sources: Source[], layouts: Map<string, FieldLayout[]>): DataMigration[];
4362
+ * `@data` class name to its field layout, for the old-version hash. `typeMap`
4363
+ * (optional) is the recursion type map (see [`recursionTypeMap`]) so the old
4364
+ * version hashes RECURSIVELY through its nested `@data` fields - matching the
4365
+ * `schema_version` that old layout was deployed under (or the migratable old
4366
+ * version would never match a deployed recursive hash). Absent = flat. A
4367
+ * migration whose param/return is not a single named type, or whose old type
4368
+ * has no layout, is skipped. */
4369
+ export function collectMigrations(sources: Source[], layouts: Map<string, FieldLayout[]>, typeMap?: Map<string, FieldLayout[]> | null): DataMigration[];
4370
+ /** A resolved chain that migrates a stored OLD value all the way to a target
4371
+ * type: decode `oldType`, then apply `steps` in order (each `@migrate`). For a
4372
+ * direct migration `steps` has one entry; a chain `V0 -> V1 -> V2` has two. */
4373
+ export class MigrationChain {
4374
+ oldType: string;
4375
+ oldVersion: number;
4376
+ steps: DataMigration[];
4377
+ }
4378
+ /** Every old type that reaches `target` through a chain of `@migrate` edges, with
4379
+ * the ordered transforms to apply. A backward breadth-first walk of the migration
4380
+ * graph (edges OLD -> NEW), so the SHORTEST chain wins and cycles terminate; a
4381
+ * direct migration is just a one-step chain. This is what lets a row written under
4382
+ * version 0 reach the current version 2 via `0->1` then `1->2`. */
4383
+ export function chainsTo(target: string, migrations: DataMigration[]): MigrationChain[];
4323
4384
  /**
4324
4385
  * Build the `toildb.catalog` section bytes, or `null` if the program declares
4325
4386
  * no `@database`.
4326
4387
  */
4327
4388
  export function buildToilDbCatalog(program: Program): Uint8Array | null;
4389
+ export function buildToilDbTypes(program: Program): Uint8Array | null;
4328
4390
  }
4329
4391
  declare module "types:toilscript/src/passes/pass" {
4330
4392
  /**