toilscript 0.1.37 → 0.1.39

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.37";
1
+ var ASSEMBLYSCRIPT_VERSION = "0.1.39";
2
2
  var ASSEMBLYSCRIPT_IMPORTMAP = {
3
3
  "imports": {
4
- "toilscript": "https://cdn.jsdelivr.net/npm/toilscript@0.1.37/dist/toilscript.js",
5
- "toilscript/cli": "https://cdn.jsdelivr.net/npm/toilscript@0.1.37/dist/cli.js",
4
+ "toilscript": "https://cdn.jsdelivr.net/npm/toilscript@0.1.39/dist/toilscript.js",
5
+ "toilscript/cli": "https://cdn.jsdelivr.net/npm/toilscript@0.1.39/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.37",
11
+ "version": "0.1.39",
12
12
  "author": "Daniel Wirtz <dcode+assemblyscript@dcode.io>",
13
13
  "license": "Apache-2.0",
14
14
  "homepage": "https://github.com/dacely-cloud/toilscript",
@@ -80,7 +80,7 @@
80
80
  "prepublishOnly": "node scripts/build",
81
81
  "watch": "node scripts/build --watch",
82
82
  "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:dbstatic",
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:streams",
84
84
  "test:parser": "node --enable-source-maps tests/parser",
85
85
  "test:compiler": "node --enable-source-maps --no-warnings tests/compiler",
86
86
  "test:browser": "node --enable-source-maps tests/browser",
@@ -91,7 +91,10 @@
91
91
  "test:cli": "node tests/cli/options.js",
92
92
  "test:json": "node tests/json/run.mjs",
93
93
  "test:data": "node tests/data/run.mjs",
94
+ "test:dbresolve": "node tests/dbresolve/run.mjs",
94
95
  "test:dbstatic": "node tests/dbstatic/run.mjs",
96
+ "test:routekinds": "node tests/routekinds/run.mjs",
97
+ "test:streams": "node tests/streams/run.mjs && node tests/streams/catalog.mjs && node tests/streams/codegen.mjs",
95
98
  "asbuild": "npm run asbuild:debug && npm run asbuild:release",
96
99
  "asbuild:debug": "node bin/toilscript --config src/toilconfig.json --target debug",
97
100
  "asbuild:release": "node bin/toilscript --config src/toilconfig.json --target release",
@@ -35,8 +35,9 @@ export namespace toildbHost {
35
35
  export declare function get(handle: u32, keyPtr: usize, keyLen: i32): i32;
36
36
 
37
37
  // record bounded multi-get. Input at keysPtr: u32 count + per key (u32 len +
38
- // bytes). Result (stashed): u32 count + per item u8 present (+ u32 len + bytes
39
- // when present), in request order. Returns the stashed length | negative error.
38
+ // bytes). Result (stashed): u32 count + per item u8 present, and when present
39
+ // `u32 schema_version + u32 len + bytes`, in request order. Returns the
40
+ // stashed length | negative error.
40
41
  // @ts-ignore: decorator
41
42
  @external("env", "data.get_many")
42
43
  export declare function getMany(handle: u32, keysPtr: usize, keysLen: i32): i32;
@@ -148,7 +149,7 @@ export namespace toildbHost {
148
149
  ): i32;
149
150
 
150
151
  // membership.list(limit) -> framed-list length (stashed) | negative error.
151
- // The blob is `u32 count` then per member `u32 len + bytes`.
152
+ // The blob is `u32 count` then per member `u32 schema_version + u32 len + bytes`.
152
153
  // @ts-ignore: decorator
153
154
  @external("env", "data.membership_list")
154
155
  export declare function membershipList(handle: u32, setPtr: usize, setLen: i32, limit: i32): i32;
@@ -216,7 +217,8 @@ export namespace toildbHost {
216
217
  ): i32;
217
218
 
218
219
  // events.latest(limit) -> framed-list length (stashed) | negative error.
219
- // The blob is `u32 count` then per event `u32 len + bytes`, newest first.
220
+ // The blob is `u32 count` then per event `u32 schema_version + u32 len + bytes`,
221
+ // newest first.
220
222
  // @ts-ignore: decorator
221
223
  @external("env", "data.latest")
222
224
  export declare function latest(handle: u32, keyPtr: usize, keyLen: i32, limit: i32): i32;
@@ -21,7 +21,8 @@ import { DataWriter } from "data";
21
21
  export function __toildbResolve(name: string): u32 {
22
22
  const nb = Uint8Array.wrap(String.UTF8.encode(name));
23
23
  const out = new Uint8Array(4);
24
- toildbHost.resolveCollection(nb.dataStart, nb.byteLength, out.dataStart);
24
+ const status = toildbHost.resolveCollection(nb.dataStart, nb.byteLength, out.dataStart);
25
+ if (status < 0) abort("ToilDB collection resolve failed", "toildb", 0, 0);
25
26
  return load<u32>(out.dataStart);
26
27
  }
27
28
 
@@ -470,7 +471,8 @@ export class Events<K, V> {
470
471
  }
471
472
 
472
473
  /// The newest `limit` events, newest first. Decodes each framed event into a
473
- /// `V`. The host frames them as `u32 count` then per event `u32 len + bytes`.
474
+ /// `V`. The host frames them as `u32 count` then per event
475
+ /// `u32 schema_version + u32 len + bytes`.
474
476
  latest(key: K, limit: i32): V[] {
475
477
  const kb = key.encode();
476
478
  const status = toildbHost.latest(this.__handle, kb.dataStart, kb.byteLength, limit);
@@ -85,6 +85,101 @@ declare function auth(target: Object, propertyKey: string | symbol, descriptor:
85
85
  /** Declare the authenticated-user type (`@user class User { ... }`); enables `AuthService.getUser()`. */
86
86
  declare function user(target: Function): void;
87
87
 
88
+ // --- L4 daemon (@daemon / @scheduled) + streams (@stream + lifecycle hooks),
89
+ // handled natively by the compiler; typed here so editors accept the bare forms ---
90
+
91
+ /** Marks the single L4 daemon class: instantiated once on the global cold box,
92
+ * its instance fields preserved for the box lifetime. At most one `@daemon` per
93
+ * project. May declare a zero-arg `onStart(): void`, run once at boot. Cold
94
+ * artifact only (a `@daemon` is a compile error in the hot/request build). */
95
+ declare function daemon(target: Function): void;
96
+
97
+ /** Declares a `@daemon` method as a scheduled task fired on each due tick. `spec`
98
+ * is an interval (`"30s"` / `"5m"` / `"1h"` / `"1d"`) or a 5-field cron string
99
+ * (e.g. `"15 9 * * 1-5"`, weekdays 9:15). The handler must be `(): void` (no parameters, no return). */
100
+ declare function scheduled(spec: string): (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<any>) => void;
101
+
102
+ /** Stream placement scope for `@stream({ scope })`: `Regional` (0, L2) or
103
+ * `Continental` (1, L3). Values match the runtime stream codec. */
104
+ declare enum StreamScope { Regional, Continental }
105
+
106
+ /** Optional `@stream` config object. Set `message` to a `@data` class to receive
107
+ * decoded packets; omit it for the raw-bytes default (`StreamPacket`). */
108
+ interface StreamOptions {
109
+ scope?: StreamScope;
110
+ message?: Function;
111
+ maxFrameBytes?: i32;
112
+ ingressRingBytes?: i32;
113
+ }
114
+
115
+ /** Marks a class as a stream protocol handler (runs on L2/L3 nodes). Its
116
+ * `@connect`/`@message`/`@close`/`@disconnect`/`@channel` methods are the
117
+ * lifecycle hooks. A project that uses `@stream` may NOT declare any `@service`
118
+ * or `@remote` anywhere (compiler-enforced). Hot/stream artifact only. */
119
+ declare function stream(target: Function): void;
120
+ declare function stream(options: StreamOptions): (target: Function) => void;
121
+
122
+ /** Stream lifecycle-hook method decorators on a `@stream` class. `@connect` runs
123
+ * on open (returns `StreamOutbound`); `@message` handles an inbound packet;
124
+ * `@close` is a graceful close; `@disconnect` is an abrupt transport loss;
125
+ * `@channel` receives an opt-in fanned-out channel message. */
126
+ declare function connect(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<any>): void;
127
+ declare function message(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<any>): void;
128
+ declare function close(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<any>): void;
129
+ declare function disconnect(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<any>): void;
130
+ declare function channel(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<any>): void;
131
+
132
+ // Stream handler argument/return types. Ambient (like the bignum natives below):
133
+ // the compiler/runtime provides the real classes; declared here so `@stream`
134
+ // handler signatures type-check in any editor.
135
+
136
+ /** The connection-open context passed to `@connect`. Read-only. */
137
+ declare class StreamInbound {
138
+ get connectionId(): u64;
139
+ get streamName(): string;
140
+ get remoteIp(): string;
141
+ get path(): string;
142
+ header(name: string): string;
143
+ }
144
+
145
+ /** The accept/reject + optional first-frame decision returned by
146
+ * `@connect` / `@message`. */
147
+ declare class StreamOutbound {
148
+ static accept(): StreamOutbound;
149
+ static reply(body: Uint8Array): StreamOutbound;
150
+ static reject(reason: u16): StreamOutbound;
151
+ static empty(): StreamOutbound;
152
+ }
153
+
154
+ /** The close context passed to `@close` (a graceful or host-initiated close,
155
+ * distinct from `@disconnect`). */
156
+ declare class StreamConnectionEvent {
157
+ get connectionId(): u64;
158
+ get reason(): u16;
159
+ get durationMs(): u64;
160
+ }
161
+
162
+ /** The default (raw-bytes) `@message` parameter: a thin view over the host
163
+ * ingress ring. The ring slot is reused after the hook returns, so copy via
164
+ * `bytes()` to retain. */
165
+ declare class StreamPacket {
166
+ get connectionId(): u64;
167
+ get length(): i32;
168
+ bytes(): Uint8Array;
169
+ at(i: i32): u8;
170
+ }
171
+
172
+ /** The fanned-out channel message passed to `@channel`: the channel name plus
173
+ * the raw published bytes (no decode). */
174
+ declare class StreamChannelMessage {
175
+ get connectionId(): u64;
176
+ get channelHash(): u32;
177
+ get channelName(): string;
178
+ get length(): i32;
179
+ bytes(): Uint8Array;
180
+ at(i: i32): u8;
181
+ }
182
+
88
183
  // --- ToilDB (@database / @collection + the @query/@action/... function kinds),
89
184
  // handled natively by the compiler; typed here so editors accept the bare forms ---
90
185
 
@@ -92,6 +187,13 @@ declare function user(target: Function): void;
92
187
  * lazily-resolved collection handle (`App.users.get(...)`). */
93
188
  declare function database(target: Function): void;
94
189
 
190
+ declare interface CollectionOptions {
191
+ fillMaxWaitMs?: i32;
192
+ maxWaitMs?: i32;
193
+ fillStale?: string;
194
+ stale?: string;
195
+ }
196
+
95
197
  /** Declares a `@database` field as a collection - a `Documents`/`View`/`Unique`/
96
198
  * `Counter`/`Events`/`Membership`/`Capacity` handle. Prefer the `static` form,
97
199
  * `@collection static users: Documents<UserId, User>` (no `!` - a definite
@@ -101,6 +203,7 @@ declare function database(target: Function): void;
101
203
  * still works but needs the toilscript TS plugin to type the static `App.users`
102
204
  * access. */
103
205
  declare function collection(target: Object, propertyKey: string | symbol): void;
206
+ declare function collection(options: CollectionOptions): (target: Object, propertyKey: string | symbol) => void;
104
207
 
105
208
  /** ToilDB function kinds (spec 6) - the data ops a function may issue. `@query`
106
209
  * is read-only; `@action` adds bounded writes/claims; `@derive` publishes