@andreiltd/componentize-qjs-binding-win32-x64-msvc 0.4.2 → 0.4.3

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
@@ -249,36 +249,50 @@ export async function greet(name) {
249
249
 
250
250
  ### Streams
251
251
 
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:
252
+ Streams transfer a sequence of values between components. Lifted WIT streams
253
+ implement the JavaScript async-iterable protocol, and async or synchronous
254
+ iterables are lowered to WIT streams automatically. The stream type is inferred
255
+ from the function parameter or result:
255
256
 
256
257
  ```wit
257
258
  package example:streaming;
258
259
 
259
260
  world streaming {
260
- export produce: async func() -> stream<u8>;
261
+ export uppercase: async func(input: stream<string>) -> stream<string>;
261
262
  }
262
263
  ```
263
264
 
264
265
  ```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;
266
+ export async function uppercase(input) {
267
+ return (async function* () {
268
+ for await (const value of input) {
269
+ yield value.toUpperCase();
270
+ }
271
+ })();
273
272
  }
274
273
  ```
275
274
 
276
- When the WIT defines multiple stream types, use the type constant:
275
+ Async iteration yields one element at a time, except for `stream<u8>`, which
276
+ yields bounded `Uint8Array` chunks to avoid one promise per byte.
277
+
278
+ Use the `wit.Stream` factory when direct access to both endpoints is needed. If
279
+ only one stream type exists in the WIT world, the type may be omitted:
277
280
 
278
281
  ```js
279
- // wit.Stream.U8, wit.Stream.STRING, wit.Stream.U32, etc.
280
282
  const { readable, writable } = wit.Stream(wit.Stream.U8);
281
- const { readable, writable } = wit.Stream(wit.Stream.STRING);
283
+ await writable.writeAll(new Uint8Array([1, 2, 3]));
284
+ writable.drop();
285
+ ```
286
+
287
+ `wit.Stream.from` adapts an iterable explicitly and exposes a completion
288
+ promise:
289
+
290
+ ```js
291
+ const source = (async function* () {
292
+ yield "one";
293
+ yield "two";
294
+ })();
295
+ const { readable, completion } = wit.Stream.from(source, wit.Stream.STRING);
282
296
  ```
283
297
 
284
298
  Available type constants (populated from WIT metadata):
@@ -311,6 +325,16 @@ wit.Stream(wit.Stream.TUPLE_U32_STRING);
311
325
  wit.Stream(wit.Stream.POINT);
312
326
  ```
313
327
 
328
+ Explicit WIT stream aliases are also exposed as constants:
329
+
330
+ ```wit
331
+ type prompt-stream = stream<message-chunk>;
332
+ ```
333
+
334
+ ```js
335
+ wit.Stream(wit.Stream.PROMPT_STREAM);
336
+ ```
337
+
314
338
  Use `wit.Stream.types` or `wit.Future.types` to discover all available type
315
339
  constants at runtime.
316
340
 
@@ -319,15 +343,20 @@ constants at runtime.
319
343
  | Method | Returns | Description |
320
344
  |--------|---------|-------------|
321
345
  | `read(count?)` | `Promise<T[]>` (or `Uint8Array` for `u8`) | Read up to `count` values |
346
+ | `next()` | `Promise<IteratorResult<T>>` | Read the next value (`Uint8Array` chunk for `u8`) |
347
+ | `return()` | `Promise<IteratorResult<T>>` | End iteration and release the readable handle |
322
348
  | `cancelRead()` | result or `undefined` | Cancel an in-progress read |
323
349
  | `drop()` | `void` | Release the stream handle |
350
+ | `[Symbol.asyncIterator]()` | `StreamReadable` | Consume the stream with `for await...of` |
324
351
 
325
352
  **StreamWritable methods:**
326
353
 
327
354
  | Method | Returns | Description |
328
355
  |--------|---------|-------------|
329
356
  | `write(data)` | `Promise<number>` | Write values, returns count written |
357
+ | `writeOne(value)` | `Promise<number>` | Write exactly one value, including array-shaped WIT values |
330
358
  | `writeAll(data)` | `Promise<number>` | Write all values, retrying as needed |
359
+ | `writeIterableItem(value)` | `Promise<boolean>` | Write one iterable yield, batching matching numeric typed arrays |
331
360
  | `cancelWrite()` | result or `undefined` | Cancel an in-progress write |
332
361
  | `drop()` | `void` | Release the stream handle |
333
362
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andreiltd/componentize-qjs-binding-win32-x64-msvc",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "cpu": [
5
5
  "x64"
6
6
  ],