toilscript 0.1.61 → 0.1.63

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.61";
1
+ var ASSEMBLYSCRIPT_VERSION = "0.1.63";
2
2
  var ASSEMBLYSCRIPT_IMPORTMAP = {
3
3
  "imports": {
4
- "toilscript": "https://cdn.jsdelivr.net/npm/toilscript@0.1.61/dist/toilscript.js",
5
- "toilscript/cli": "https://cdn.jsdelivr.net/npm/toilscript@0.1.61/dist/cli.js",
4
+ "toilscript": "https://cdn.jsdelivr.net/npm/toilscript@0.1.63/dist/toilscript.js",
5
+ "toilscript/cli": "https://cdn.jsdelivr.net/npm/toilscript@0.1.63/dist/cli.js",
6
6
  "binaryen": "https://cdn.jsdelivr.net/npm/binaryen@130.0.0/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.61",
11
+ "version": "0.1.63",
12
12
  "author": "Daniel Wirtz <dcode+assemblyscript@dcode.io>",
13
13
  "license": "Apache-2.0",
14
14
  "homepage": "https://github.com/dacely-cloud/toilscript",
@@ -72,6 +72,7 @@
72
72
  "toilinit": "./bin/toilinit.js"
73
73
  },
74
74
  "scripts": {
75
+ "prepare": "node scripts/build",
75
76
  "check": "npm run check:config && npm run check:import && npm run lint",
76
77
  "check:config": "tsc --noEmit -p src --diagnostics --listFiles",
77
78
  "check:import": "tsc --noEmit --skipLibCheck --target ESNEXT --module nodenext --moduleResolution nodenext --experimentalDecorators tests/import/index",
@@ -80,7 +81,7 @@
80
81
  "prepublishOnly": "node scripts/build",
81
82
  "watch": "node scripts/build --watch",
82
83
  "coverage": "npx c8 -- npm test",
83
- "test": "npm run test:parser && npm run test:compiler -- --parallel && npm run test:browser && npm run test:toilconfig && npm run test:transform && npm run test:cli && npm run test:json && npm run test:data && npm run test:dbresolve && npm run test:dbstatic && npm run test:routekinds && npm run test:derive && npm run test:streams && npm run test:daemon && npm run test:dberror",
84
+ "test": "npm run test:parser && npm run test:compiler -- --parallel && npm run test:browser && npm run test:toilconfig && npm run test:transform && npm run test:cli && npm run test:json && npm run test:data && npm run test:dbresolve && npm run test:dbstatic && npm run test:dbtypes && npm run test:routekinds && npm run test:derive && npm run test:streams && npm run test:daemon && npm run test:dberror && npm run test:events && npm run test:uniquebatch",
84
85
  "test:parser": "node --enable-source-maps tests/parser",
85
86
  "test:compiler": "node --enable-source-maps --no-warnings tests/compiler",
86
87
  "test:browser": "node --enable-source-maps tests/browser",
@@ -93,10 +94,13 @@
93
94
  "test:data": "node tests/data/run.mjs",
94
95
  "test:dbresolve": "node tests/dbresolve/run.mjs",
95
96
  "test:dbstatic": "node tests/dbstatic/run.mjs",
97
+ "test:dbtypes": "node tests/dbtypes/run.mjs",
96
98
  "test:routekinds": "node tests/routekinds/run.mjs",
97
99
  "test:derive": "node tests/derive/run.mjs",
98
100
  "test:streams": "node tests/streams/run.mjs && node tests/streams/catalog.mjs && node tests/streams/codegen.mjs",
99
101
  "test:daemon": "node tests/daemon/run.mjs",
102
+ "test:uniquebatch": "node tests/uniquebatch/run.mjs",
103
+ "test:events": "node tests/events/run.mjs",
100
104
  "test:dberror": "node tests/dberror/run.mjs",
101
105
  "asbuild": "npm run asbuild:debug && npm run asbuild:release",
102
106
  "asbuild:debug": "node bin/toilscript --config src/toilconfig.json --target debug",
@@ -230,6 +230,16 @@ export namespace toildbHost {
230
230
  idemPtr: usize
231
231
  ): i32;
232
232
 
233
+ // Point reads: stashed value length | -2 absent | typed negative error.
234
+ // result_schema_version exposes the stored event's schema version.
235
+ // @ts-ignore: decorator
236
+ @external("env", "data.events_get")
237
+ export declare function eventsGet(handle: u32, keyPtr: usize, keyLen: i32, evidPtr: usize, evidLen: i32): i32;
238
+
239
+ // @ts-ignore: decorator
240
+ @external("env", "data.events_last")
241
+ export declare function eventsLast(handle: u32, keyPtr: usize, keyLen: i32): i32;
242
+
233
243
  // events.latest(limit) -> framed-list length (stashed) | negative error.
234
244
  // The blob is `u32 count` then per event `u32 schema_version + u32 len + bytes`,
235
245
  // newest first.
@@ -186,7 +186,8 @@ function __toildbMiss(status: i32): void {
186
186
  /// }
187
187
  /// ```
188
188
  ///
189
- /// ONLY `Documents.get`, `Documents.getDelete`, `View.get` and `Unique.lookup`
189
+ /// `Documents.get`, `Documents.getDelete`, `View.get`, `Unique.lookup`,
190
+ /// `Events.get` and `Events.last`
190
191
  /// record into this. Every other ToilDB op either succeeds or traps. The `Analytics`
191
192
  /// reads also answer `null`, but on their own `-2 absent` / `-3 forbidden` statuses
192
193
  /// rather than a `TDLnnn`, so they leave `lastError()` untouched: do not consult it
@@ -325,8 +326,9 @@ export class Documents<K, V> {
325
326
  /// conflict or retry - the later one wins and overwrites the earlier. Correct
326
327
  /// for writing a whole value (a profile, a settings blob); wrong for a
327
328
  /// read-modify-write of accumulating state (a balance, a like count), where a
328
- /// concurrent write would be lost - use `counter.add` or version-checked
329
- /// `patch` there. A lost write is a data-integrity concern, not a boundary one:
329
+ /// concurrent write would be lost - use `counter.add` or a caller-observed
330
+ /// conditional write there. A lost write is a data-integrity concern, not a
331
+ /// boundary one:
330
332
  /// the key is tenant-scoped, so a race is only ever one tenant's own concurrent
331
333
  /// writes, and `@unique` stays race-safe (claim-once at the value's home).
332
334
  upsert(key: K, value: V): UpsertResult {
@@ -352,9 +354,9 @@ export class Documents<K, V> {
352
354
  return v;
353
355
  }
354
356
 
355
- /// Atomically replace an EXISTING record's value, version-checked: returns true
356
- /// if applied, false if a concurrent write changed the record first (optimistic
357
- /// concurrency - re-read and retry) or the record is absent.
357
+ /// Submit a replacement of an EXISTING record: true when accepted, false on
358
+ /// absence or rejection. The ABI carries no caller-observed version or value,
359
+ /// so this cannot protect a read-modify-write based on an earlier application read.
358
360
  enqueue(key: K, value: V): bool {
359
361
  const kb = key.encode();
360
362
  const vb = value.encode();
@@ -446,6 +448,12 @@ export class Unique<K, V> {
446
448
  return v;
447
449
  }
448
450
 
451
+ /// Bounded owner lookup in input order, with null for each unclaimed key.
452
+ /// Uses one read operation; the host enforces the per-request batch limit.
453
+ lookupMany(keys: K[]): Array<V | null> {
454
+ return new Documents<K, V>(this.__handle).getMany(keys);
455
+ }
456
+
449
457
  /// Claim `key` for `value`. Returns whether the caller owns it, and (when
450
458
  /// another owns it) who.
451
459
  claim(key: K, value: V): ClaimResult<V> {
@@ -944,6 +952,27 @@ export class Events<K, V> {
944
952
  this.__handle = handle;
945
953
  }
946
954
 
955
+ /// Read an event by its appendOnce eventId, or null if absent. Bounded request-path read.
956
+ get(key: K, eventId: string): V | null {
957
+ const kb = key.encode();
958
+ const idb = Uint8Array.wrap(String.UTF8.encode(eventId));
959
+ const status = toildbHost.eventsGet(this.__handle, kb.dataStart, kb.byteLength, idb.dataStart, idb.byteLength);
960
+ if (status < 0) { __toildbMiss(status); return null; }
961
+ const v = instantiate<V>();
962
+ v.decodeInto(__toildbTake(status));
963
+ return v;
964
+ }
965
+
966
+ /// Read the newest appended event, or null for an empty stream. Does not scan.
967
+ last(key: K): V | null {
968
+ const kb = key.encode();
969
+ const status = toildbHost.eventsLast(this.__handle, kb.dataStart, kb.byteLength);
970
+ if (status < 0) { __toildbMiss(status); return null; }
971
+ const v = instantiate<V>();
972
+ v.decodeInto(__toildbTake(status));
973
+ return v;
974
+ }
975
+
947
976
  /// Append an event to the stream.
948
977
  append(key: K, event: V): void {
949
978
  const kb = key.encode();
@@ -250,10 +250,13 @@ declare class Documents<K, V> {
250
250
  /** Create-or-overwrite in one op (blind last-writer-wins); replaces the two-op
251
251
  * `if (!create(k,v)) patch(k,v)` idiom. Right for writing a whole value; wrong
252
252
  * for read-modify-write of accumulating state (a balance/count), where a
253
- * concurrent write would be lost - use `counter.add` or version-checked
254
- * `patch` there. The key is tenant-scoped, so a race is only ever the same
255
- * tenant's own writes. See {@link UpsertResult}. */
253
+ * concurrent write would be lost - use `counter.add` or a caller-observed
254
+ * conditional write there. The key is tenant-scoped, so a race is only ever
255
+ * the same tenant's own writes. See {@link UpsertResult}. */
256
256
  upsert(key: K, value: V): UpsertResult;
257
+ /** Submit a replacement of an existing record; true when accepted, false on
258
+ * absence or rejection. Does not compare against an earlier application read. */
259
+ enqueue(key: K, value: V): bool;
257
260
  delete(key: K): void;
258
261
  getDelete(key: K): V | null;
259
262
  }
@@ -275,6 +278,8 @@ declare class ClaimResult<V> {
275
278
  /** A globally-unique claim collection (spec 7.6): usernames, emails, slugs. */
276
279
  declare class Unique<K, V> {
277
280
  lookup(key: K): V | null;
281
+ /** Bounded owner lookup in input order; null for unclaimed keys. */
282
+ lookupMany(keys: K[]): Array<V | null>;
278
283
  claim(key: K, value: V): ClaimResult<V>;
279
284
  release(key: K, value: V): void;
280
285
  }
@@ -304,6 +309,11 @@ declare class Counter<K> {
304
309
 
305
310
  /** An append-only event log (spec 7.5): activity feeds, audit trails. */
306
311
  declare class Events<K, V> {
312
+ /** Read an event by its appendOnce eventId, or null if absent. */
313
+ get(key: K, eventId: string): V | null;
314
+ /** Read the newest appended event, or null for an empty stream. */
315
+ last(key: K): V | null;
316
+ appendOnce(key: K, eventId: string, event: V): bool;
307
317
  append(key: K, event: V): void;
308
318
  latest(key: K, limit: i32): V[];
309
319
  since(key: K, limit: i32): V[];