@ricsam/quickjs-fetch 0.2.8 → 0.2.10

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.
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Upload stream queue management for bridging native ReadableStreams to QuickJS.
3
+ *
4
+ * This module implements the "Inverted Direct State Access" pattern:
5
+ * - Native stream reader reads data and pushes directly to QuickJS stream's internal queue
6
+ * - QuickJS stream's read() method reads from the queue
7
+ * - No async callbacks with QuickJS handles, avoiding handle lifetime issues
8
+ *
9
+ * The pattern is the reverse of download streaming (handle.ts:createNativeStreamFromState):
10
+ * - Download: QuickJS enqueues → host polls queue
11
+ * - Upload: Host pushes to queue → QuickJS reads
12
+ */
13
+ import type { UploadStreamQueue } from "./types.ts";
14
+ /**
15
+ * Create a new upload queue and register it in instance state.
16
+ * Returns the instance ID for accessing the queue via getUploadQueue().
17
+ */
18
+ export declare function createUploadQueue(): number;
19
+ /**
20
+ * Get an upload queue by its instance ID.
21
+ */
22
+ export declare function getUploadQueue(instanceId: number): UploadStreamQueue | undefined;
23
+ /**
24
+ * Clean up an upload queue when no longer needed.
25
+ */
26
+ export declare function cleanupUploadQueue(instanceId: number): void;
27
+ /**
28
+ * Push a chunk to a QuickJS ReadableStream's internal queue.
29
+ * If there are pending read requests, fulfills the first one immediately.
30
+ *
31
+ * @param streamInstanceId The instance ID of the QuickJS ReadableStream
32
+ * @param chunk The data chunk to enqueue
33
+ * @returns true if the chunk was successfully enqueued
34
+ */
35
+ export declare function pushToQuickJSStream(streamInstanceId: number, chunk: Uint8Array): boolean;
36
+ /**
37
+ * Close a QuickJS ReadableStream.
38
+ * If there are pending read requests, fulfills them with done: true.
39
+ *
40
+ * @param streamInstanceId The instance ID of the QuickJS ReadableStream
41
+ */
42
+ export declare function closeQuickJSStream(streamInstanceId: number): void;
43
+ /**
44
+ * Error a QuickJS ReadableStream.
45
+ *
46
+ * @param streamInstanceId The instance ID of the QuickJS ReadableStream
47
+ * @param error The error to propagate
48
+ */
49
+ export declare function errorQuickJSStream(streamInstanceId: number, error: Error): void;
50
+ /**
51
+ * Check if a QuickJS ReadableStream's queue is full (for backpressure).
52
+ *
53
+ * @param streamInstanceId The instance ID of the QuickJS ReadableStream
54
+ * @returns true if the queue has reached capacity
55
+ */
56
+ export declare function isQuickJSStreamQueueFull(streamInstanceId: number): boolean;
57
+ /**
58
+ * Start a background reader that reads from a native ReadableStream
59
+ * and pushes chunks directly to a QuickJS ReadableStream.
60
+ *
61
+ * The reader respects backpressure by pausing when the QuickJS queue is full
62
+ * (10+ chunks) and resuming when QuickJS consumes chunks.
63
+ *
64
+ * @param nativeStream The native ReadableStream to read from
65
+ * @param quickjsStreamInstanceId The instance ID of the QuickJS ReadableStream
66
+ * @param onChunkPushed Optional callback called after each chunk is pushed
67
+ * @returns A cleanup function to cancel the reader
68
+ */
69
+ export declare function startNativeStreamReader(nativeStream: ReadableStream<Uint8Array>, quickjsStreamInstanceId: number, onChunkPushed?: () => void): () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ricsam/quickjs-fetch",
3
- "version": "0.2.8",
3
+ "version": "0.2.10",
4
4
  "main": "./dist/cjs/index.cjs",
5
5
  "types": "./dist/types/index.d.ts",
6
6
  "exports": {
@@ -16,7 +16,7 @@
16
16
  "typecheck": "tsc --noEmit"
17
17
  },
18
18
  "dependencies": {
19
- "@ricsam/quickjs-core": "^0.2.7",
19
+ "@ricsam/quickjs-core": "^0.2.9",
20
20
  "quickjs-emscripten": "^0.31.0"
21
21
  },
22
22
  "peerDependencies": {