@andreiltd/componentize-qjs-binding-win32-arm64-msvc 0.4.3 → 0.4.5

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/README.md CHANGED
@@ -197,6 +197,7 @@ a project root that contains shared files or `node_modules`.
197
197
  |----------|---------|---------|
198
198
  | `list<T>` | `Array` | `[1, 2, 3]` |
199
199
  | `list<u8>` | `Uint8Array` or `Array` | `new Uint8Array([1, 2, 3])` |
200
+ | `map<K, V>` | `Map` | `new Map([["key", value]])` |
200
201
  | `tuple<T, U, ...>` | `Array` | `[42, "hello"]` |
201
202
  | `option<T>` | `T \| null` (nested: `{ tag: "some"\|"none", val }`) | `null` for none; `option<option<T>>` is wrapped |
202
203
  | `result<T, E>` | top-level function result: return `T` or throw `E`; nested result: `{ tag: "ok"\|"err", val?: T\|E }` | `return 42` / `throw "error"` |
@@ -226,6 +227,15 @@ output.blockingWriteAndFlush(chunk);
226
227
  `[static]` methods are exposed on the resource class and `[constructor]` makes
227
228
  the class callable with `new`.
228
229
 
230
+ Owned imported resources support `[Symbol.dispose]()` for deterministic
231
+ cleanup. Passing one to a WIT `own<T>` parameter transfers ownership and
232
+ invalidates the original wrapper. Borrowed wrappers expire when their component
233
+ call completes and cannot be transferred or disposed as owners. Resources lent
234
+ to an in-flight import remain alive and cannot be disposed or transferred until
235
+ that import completes. Ownership is restored for unconsumed stream/future writes
236
+ and for imported calls cancelled before they start. Await imports using an
237
+ incoming borrowed resource before returning from its export.
238
+
229
239
  ### Async Exports
230
240
 
231
241
  Async exports are declared with the `async` keyword in WIT and implemented
@@ -247,6 +257,36 @@ export async function greet(name) {
247
257
  }
248
258
  ```
249
259
 
260
+ Exported resource methods and static methods may also be async. Implement them
261
+ as `async` members on the exported JavaScript class; resource constructors
262
+ remain synchronous:
263
+
264
+ ```wit
265
+ package example:counter;
266
+
267
+ interface counter-api {
268
+ resource counter {
269
+ constructor(initial: u32);
270
+ add: async func(value: u32) -> u32;
271
+ create: static async func(initial: u32) -> counter;
272
+ }
273
+ }
274
+
275
+ world counter {
276
+ export counter-api;
277
+ }
278
+ ```
279
+
280
+ ```js
281
+ class Counter {
282
+ constructor(initial) { this.value = initial; }
283
+ async add(value) { this.value += value; return this.value; }
284
+ static async create(initial) { return new this(initial); }
285
+ }
286
+
287
+ export const counterApi = { Counter };
288
+ ```
289
+
250
290
  ### Streams
251
291
 
252
292
  Streams transfer a sequence of values between components. Lifted WIT streams
@@ -374,7 +414,7 @@ world async-value {
374
414
  ```
375
415
 
376
416
  ```js
377
- async function compute() {
417
+ export async function compute() {
378
418
  const { readable, writable } = wit.Future();
379
419
 
380
420
  // Write the value (fire-and-forget; completes when reader reads)
@@ -387,6 +427,16 @@ async function compute() {
387
427
  **Future type constants** follow the same pattern: `wit.Future.U32`,
388
428
  `wit.Future.STRING`, etc.
389
429
 
430
+ Future handles are deliberately not thenable: use `await readable.read()` to
431
+ obtain the payload. This keeps `return readable` in an async export from
432
+ implicitly consuming the future, and preserves nested future handles.
433
+ Repeated `read()` calls share the same Promise; a cancelled read rejects that
434
+ Promise and allows a subsequent read to retry.
435
+
436
+ `wit.Future.from(value, type)` adapts a value or Promise and returns
437
+ `{ readable, completion }`. Return its `readable` from an async export rather
438
+ than returning the payload Promise directly, which JavaScript would await.
439
+
390
440
  **FutureReadable methods:**
391
441
 
392
442
  | Method | Returns | Description |
@@ -405,17 +455,25 @@ async function compute() {
405
455
 
406
456
  ### Resource Cleanup
407
457
 
408
- Stream and future handles support
458
+ Owned imported resources, stream endpoints, and future endpoints support
409
459
  [Explicit Resource Management](https://github.com/tc39/proposal-explicit-resource-management)
410
460
  via `Symbol.dispose`. In environments that support `using`:
411
461
 
412
462
  ```js
413
463
  {
414
- using stream = wit.Stream();
415
- // stream.writable and stream.readable are auto-dropped when leaving scope
464
+ const stream = wit.Stream();
465
+ using writable = stream.writable;
466
+ using readable = stream.readable;
467
+ // Each endpoint is disposed when leaving scope.
416
468
  }
417
469
  ```
418
470
 
471
+ The factory's `{ readable, writable }` pair is not itself disposable.
472
+ Complete an endpoint's pending operation (or cancel it and await its
473
+ settlement) before leaving its `using` scope or calling `.drop()`.
474
+ Host-requested task cancellation retains pending ABI buffers until the host
475
+ acknowledges each operation's completion or cancellation.
476
+
419
477
  Otherwise, call `.drop()` explicitly to release handles.
420
478
 
421
479
  ## Node.js API
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andreiltd/componentize-qjs-binding-win32-arm64-msvc",
3
- "version": "0.4.3",
3
+ "version": "0.4.5",
4
4
  "cpu": [
5
5
  "arm64"
6
6
  ],