toilscript 0.1.33 → 0.1.34

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/dist/web.js CHANGED
@@ -1,8 +1,8 @@
1
- var ASSEMBLYSCRIPT_VERSION = "0.1.33";
1
+ var ASSEMBLYSCRIPT_VERSION = "0.1.34";
2
2
  var ASSEMBLYSCRIPT_IMPORTMAP = {
3
3
  "imports": {
4
- "toilscript": "https://cdn.jsdelivr.net/npm/toilscript@0.1.33/dist/toilscript.js",
5
- "toilscript/cli": "https://cdn.jsdelivr.net/npm/toilscript@0.1.33/dist/cli.js",
4
+ "toilscript": "https://cdn.jsdelivr.net/npm/toilscript@0.1.34/dist/toilscript.js",
5
+ "toilscript/cli": "https://cdn.jsdelivr.net/npm/toilscript@0.1.34/dist/cli.js",
6
6
  "binaryen": "https://cdn.jsdelivr.net/npm/binaryen@130.0.0-nightly.20260609/index.js",
7
7
  "long": "https://cdn.jsdelivr.net/npm/long@5.3.2/index.js"
8
8
  }
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "toilscript",
9
9
  "wasm"
10
10
  ],
11
- "version": "0.1.33",
11
+ "version": "0.1.34",
12
12
  "author": "Daniel Wirtz <dcode+assemblyscript@dcode.io>",
13
13
  "license": "Apache-2.0",
14
14
  "homepage": "https://github.com/dacely-cloud/toilscript",
@@ -227,4 +227,20 @@ export namespace toildbHost {
227
227
  // @ts-ignore: decorator
228
228
  @external("env", "data.take_result")
229
229
  export declare function takeResult(outPtr: usize, outLen: i32): i32;
230
+
231
+ // The schema version the LAST value-returning read's row was written under, so
232
+ // the generated decoder can default fields added since / reject an unknown
233
+ // layout. A u32 version rides in the non-negative range; -1 means the last op
234
+ // returned no value (or the host does not track a version). Does not drain the
235
+ // result stash, so it may be read before or after `takeResult`.
236
+ // @ts-ignore: decorator
237
+ @external("env", "data.result_schema_version")
238
+ export declare function resultSchemaVersion(): i64;
239
+
240
+ // 1 if the current call's kind may issue a record write, else 0. The generated
241
+ // reader uses it to skip the rewrite-on-read convergence write in a read-only
242
+ // `@query` (where it would be rejected) rather than attempt a doomed write.
243
+ // @ts-ignore: decorator
244
+ @external("env", "data.write_allowed")
245
+ export declare function writeAllowed(): i32;
230
246
  }
@@ -25,6 +25,24 @@ export function __toildbResolve(name: string): u32 {
25
25
  return load<u32>(out.dataStart);
26
26
  }
27
27
 
28
+ /// The schema version of the last value-returning read's row (or -1). The
29
+ /// generated `decodeInto` of a `@migrate`-d value type calls this to dispatch an
30
+ /// old-layout row through its transform. Global so generated user-code reaches it
31
+ /// (like `__toildbResolve`).
32
+ export function __toildbReadVersion(): i64 {
33
+ return toildbHost.resultSchemaVersion();
34
+ }
35
+
36
+ /// Set true by a woven `decodeInto` when it migrates an old-layout row, so the
37
+ /// reading handle can converge the row (rewrite-on-read). The handle resets it
38
+ /// before each decode and reads it after; the dispatch marks it AFTER the
39
+ /// transform runs, so a transform that itself reads (resetting the flag) does not
40
+ /// clear the outer migration.
41
+ let __toildbMigratedFlag: bool = false;
42
+ export function __toildbResetMigrated(): void { __toildbMigratedFlag = false; }
43
+ export function __toildbMarkMigrated(): void { __toildbMigratedFlag = true; }
44
+ export function __toildbWasMigrated(): bool { return __toildbMigratedFlag; }
45
+
28
46
  /// Pull the last stashed variable-length result of `len` bytes into a buffer.
29
47
  function __toildbTake(len: i32): Uint8Array {
30
48
  const buf = new Uint8Array(len);
@@ -61,8 +79,17 @@ export class Documents<K, V> {
61
79
  const kb = key.encode();
62
80
  const status = toildbHost.get(this.__handle, kb.dataStart, kb.byteLength);
63
81
  if (status < 0) return null;
82
+ __toildbResetMigrated();
64
83
  const v = instantiate<V>();
65
84
  v.decodeInto(__toildbTake(status));
85
+ // Rewrite-on-read convergence: if this row was lazily migrated from an older
86
+ // layout AND the current call may write, persist the migrated value so it
87
+ // stops being re-migrated. Best-effort: a read-only kind skips it, and a
88
+ // failed patch is ignored (the in-memory value is already correct).
89
+ if (__toildbWasMigrated() && toildbHost.writeAllowed() == 1) {
90
+ const nb = v.encode();
91
+ toildbHost.patch(this.__handle, kb.dataStart, kb.byteLength, nb.dataStart, nb.byteLength, 0);
92
+ }
66
93
  return v;
67
94
  }
68
95
 
@@ -94,10 +94,12 @@ declare function database(target: Function): void;
94
94
 
95
95
  /** Declares a `@database` field as a collection - a `Documents`/`View`/`Unique`/
96
96
  * `Counter`/`Events`/`Membership`/`Capacity` handle. Prefer the `static` form,
97
- * `@collection static users!: Documents<UserId, User>`, so `App.users` type-checks
98
- * in any editor with no language-service plugin; the instance form
99
- * (`@collection users!: ...`) still works but needs the toilscript TS plugin to
100
- * type the static `App.users` access. */
97
+ * `@collection static users: Documents<UserId, User>` (no `!` - a definite
98
+ * assignment assertion on a static field is a TS1255 error, and the compiler
99
+ * demotes the field so none is needed), so `App.users` type-checks in any editor
100
+ * with no language-service plugin. The instance form (`@collection users!: ...`)
101
+ * still works but needs the toilscript TS plugin to type the static `App.users`
102
+ * access. */
101
103
  declare function collection(target: Object, propertyKey: string | symbol): void;
102
104
 
103
105
  /** ToilDB function kinds (spec 6) - the data ops a function may issue. `@query`