@andreiltd/componentize-qjs-binding-win32-arm64-msvc 0.4.2 → 0.4.4

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"` |
@@ -247,38 +248,82 @@ export async function greet(name) {
247
248
  }
248
249
  ```
249
250
 
251
+ Exported resource methods and static methods may also be async. Implement them
252
+ as `async` members on the exported JavaScript class; resource constructors
253
+ remain synchronous:
254
+
255
+ ```wit
256
+ package example:counter;
257
+
258
+ interface counter-api {
259
+ resource counter {
260
+ constructor(initial: u32);
261
+ add: async func(value: u32) -> u32;
262
+ create: static async func(initial: u32) -> counter;
263
+ }
264
+ }
265
+
266
+ world counter {
267
+ export counter-api;
268
+ }
269
+ ```
270
+
271
+ ```js
272
+ class Counter {
273
+ constructor(initial) { this.value = initial; }
274
+ async add(value) { this.value += value; return this.value; }
275
+ static async create(initial) { return new this(initial); }
276
+ }
277
+
278
+ export const counterApi = { Counter };
279
+ ```
280
+
250
281
  ### Streams
251
282
 
252
- Streams transfer a sequence of values between components.
253
- The `wit` global provides `Stream` and `Future` constructors for creating
254
- stream/future pairs. The type is automatically determined from the WIT definition:
283
+ Streams transfer a sequence of values between components. Lifted WIT streams
284
+ implement the JavaScript async-iterable protocol, and async or synchronous
285
+ iterables are lowered to WIT streams automatically. The stream type is inferred
286
+ from the function parameter or result:
255
287
 
256
288
  ```wit
257
289
  package example:streaming;
258
290
 
259
291
  world streaming {
260
- export produce: async func() -> stream<u8>;
292
+ export uppercase: async func(input: stream<string>) -> stream<string>;
261
293
  }
262
294
  ```
263
295
 
264
296
  ```js
265
- async function produce() {
266
- // When only one stream type exists in the WIT, no argument needed
267
- const { readable, writable } = wit.Stream();
268
-
269
- writable.write(new Uint8Array([1, 2, 3]));
270
- writable.drop();
271
-
272
- return readable;
297
+ export async function uppercase(input) {
298
+ return (async function* () {
299
+ for await (const value of input) {
300
+ yield value.toUpperCase();
301
+ }
302
+ })();
273
303
  }
274
304
  ```
275
305
 
276
- When the WIT defines multiple stream types, use the type constant:
306
+ Async iteration yields one element at a time, except for `stream<u8>`, which
307
+ yields bounded `Uint8Array` chunks to avoid one promise per byte.
308
+
309
+ Use the `wit.Stream` factory when direct access to both endpoints is needed. If
310
+ only one stream type exists in the WIT world, the type may be omitted:
277
311
 
278
312
  ```js
279
- // wit.Stream.U8, wit.Stream.STRING, wit.Stream.U32, etc.
280
313
  const { readable, writable } = wit.Stream(wit.Stream.U8);
281
- const { readable, writable } = wit.Stream(wit.Stream.STRING);
314
+ await writable.writeAll(new Uint8Array([1, 2, 3]));
315
+ writable.drop();
316
+ ```
317
+
318
+ `wit.Stream.from` adapts an iterable explicitly and exposes a completion
319
+ promise:
320
+
321
+ ```js
322
+ const source = (async function* () {
323
+ yield "one";
324
+ yield "two";
325
+ })();
326
+ const { readable, completion } = wit.Stream.from(source, wit.Stream.STRING);
282
327
  ```
283
328
 
284
329
  Available type constants (populated from WIT metadata):
@@ -311,6 +356,16 @@ wit.Stream(wit.Stream.TUPLE_U32_STRING);
311
356
  wit.Stream(wit.Stream.POINT);
312
357
  ```
313
358
 
359
+ Explicit WIT stream aliases are also exposed as constants:
360
+
361
+ ```wit
362
+ type prompt-stream = stream<message-chunk>;
363
+ ```
364
+
365
+ ```js
366
+ wit.Stream(wit.Stream.PROMPT_STREAM);
367
+ ```
368
+
314
369
  Use `wit.Stream.types` or `wit.Future.types` to discover all available type
315
370
  constants at runtime.
316
371
 
@@ -319,15 +374,20 @@ constants at runtime.
319
374
  | Method | Returns | Description |
320
375
  |--------|---------|-------------|
321
376
  | `read(count?)` | `Promise<T[]>` (or `Uint8Array` for `u8`) | Read up to `count` values |
377
+ | `next()` | `Promise<IteratorResult<T>>` | Read the next value (`Uint8Array` chunk for `u8`) |
378
+ | `return()` | `Promise<IteratorResult<T>>` | End iteration and release the readable handle |
322
379
  | `cancelRead()` | result or `undefined` | Cancel an in-progress read |
323
380
  | `drop()` | `void` | Release the stream handle |
381
+ | `[Symbol.asyncIterator]()` | `StreamReadable` | Consume the stream with `for await...of` |
324
382
 
325
383
  **StreamWritable methods:**
326
384
 
327
385
  | Method | Returns | Description |
328
386
  |--------|---------|-------------|
329
387
  | `write(data)` | `Promise<number>` | Write values, returns count written |
388
+ | `writeOne(value)` | `Promise<number>` | Write exactly one value, including array-shaped WIT values |
330
389
  | `writeAll(data)` | `Promise<number>` | Write all values, retrying as needed |
390
+ | `writeIterableItem(value)` | `Promise<boolean>` | Write one iterable yield, batching matching numeric typed arrays |
331
391
  | `cancelWrite()` | result or `undefined` | Cancel an in-progress write |
332
392
  | `drop()` | `void` | Release the stream handle |
333
393
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andreiltd/componentize-qjs-binding-win32-arm64-msvc",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "cpu": [
5
5
  "arm64"
6
6
  ],