@ricsam/isolate-fetch 0.1.9 → 0.1.11

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,179 @@
1
+ /**
2
+ * Helper functions for creating web objects from different origins.
3
+ * Used to test that objects behave identically regardless of how they were created.
4
+ *
5
+ * Note: The `customFunction` origin is tested where supported. For Response and Request,
6
+ * this requires constructing the object in the isolate using parameters passed from
7
+ * a host custom function, since native objects cannot be serialized across the boundary.
8
+ */
9
+ import { type RuntimeHandle } from "@ricsam/isolate-runtime";
10
+ export type ResponseOrigin = "direct" | "customFunction" | "fetchCallback";
11
+ export type RequestOrigin = "direct" | "customFunction" | "serveRequest";
12
+ export type HeadersOrigin = "direct" | "fromResponse" | "fromRequest";
13
+ export type BlobOrigin = "direct";
14
+ export type FileOrigin = "direct";
15
+ export type URLOrigin = "direct" | "customFunction";
16
+ export type URLSearchParamsOrigin = "direct" | "fromURL" | "fromCustomFunctionURL";
17
+ export type FormDataOrigin = "direct" | "fromResponse";
18
+ export type ReadableStreamOrigin = "direct" | "responseBody" | "blobStream" | "transformReadable";
19
+ export type WritableStreamOrigin = "direct" | "transformWritable";
20
+ export type TransformStreamOrigin = "direct";
21
+ export type TextEncoderStreamOrigin = "direct";
22
+ export type TextDecoderStreamOrigin = "direct";
23
+ export type QueuingStrategyOrigin = "direct";
24
+ export declare const RESPONSE_ORIGINS: ResponseOrigin[];
25
+ export declare const REQUEST_ORIGINS: RequestOrigin[];
26
+ export declare const HEADERS_ORIGINS: HeadersOrigin[];
27
+ export declare const BLOB_ORIGINS: BlobOrigin[];
28
+ export declare const FILE_ORIGINS: FileOrigin[];
29
+ export declare const URL_ORIGINS: URLOrigin[];
30
+ export declare const URLSEARCHPARAMS_ORIGINS: URLSearchParamsOrigin[];
31
+ export declare const FORMDATA_ORIGINS: FormDataOrigin[];
32
+ export declare const READABLE_STREAM_ORIGINS: ReadableStreamOrigin[];
33
+ export declare const WRITABLE_STREAM_ORIGINS: WritableStreamOrigin[];
34
+ export declare const TRANSFORM_STREAM_ORIGINS: TransformStreamOrigin[];
35
+ export declare const TEXT_ENCODER_STREAM_ORIGINS: TextEncoderStreamOrigin[];
36
+ export declare const TEXT_DECODER_STREAM_ORIGINS: TextDecoderStreamOrigin[];
37
+ export declare const QUEUING_STRATEGY_ORIGINS: QueuingStrategyOrigin[];
38
+ export type AbortControllerOrigin = "direct";
39
+ export type AbortSignalOrigin = "direct";
40
+ export declare const ABORT_CONTROLLER_ORIGINS: AbortControllerOrigin[];
41
+ export declare const ABORT_SIGNAL_ORIGINS: AbortSignalOrigin[];
42
+ export interface ConsistencyTestContext {
43
+ /** The runtime handle */
44
+ runtime: RuntimeHandle;
45
+ /** Execute code in the runtime */
46
+ eval(code: string): Promise<void>;
47
+ /** Dispatch an HTTP request to the serve() handler */
48
+ dispatchRequest(request: Request): Promise<Response>;
49
+ /** Set the mock response for the next fetch call */
50
+ setMockResponse(response: MockResponse): void;
51
+ /** Get a result from the isolate via setResult() */
52
+ getResult<T = unknown>(): T | undefined;
53
+ /** Clear the stored result */
54
+ clearResult(): void;
55
+ /** Dispose all resources */
56
+ dispose(): Promise<void>;
57
+ }
58
+ export interface MockResponse {
59
+ status?: number;
60
+ statusText?: string;
61
+ body?: string;
62
+ headers?: Record<string, string>;
63
+ }
64
+ /**
65
+ * Create a test context for consistency tests.
66
+ * Provides helpers for creating objects from different origins.
67
+ */
68
+ export declare function createConsistencyTestContext(): Promise<ConsistencyTestContext>;
69
+ export interface ResponseOptions {
70
+ status?: number;
71
+ statusText?: string;
72
+ headers?: Record<string, string>;
73
+ }
74
+ /**
75
+ * Create a Response in the isolate from the specified origin.
76
+ * The Response is stored at globalThis.__testResponse.
77
+ */
78
+ export declare function getResponseFromOrigin(ctx: ConsistencyTestContext, origin: ResponseOrigin, body: string, options?: ResponseOptions): Promise<void>;
79
+ export interface RequestOptions {
80
+ method?: string;
81
+ headers?: Record<string, string>;
82
+ body?: string;
83
+ }
84
+ /**
85
+ * Create a Request in the isolate from the specified origin.
86
+ * The Request is stored at globalThis.__testRequest.
87
+ */
88
+ export declare function getRequestFromOrigin(ctx: ConsistencyTestContext, origin: RequestOrigin, url: string, options?: RequestOptions): Promise<void>;
89
+ /**
90
+ * Create Headers in the isolate from the specified origin.
91
+ * The Headers is stored at globalThis.__testHeaders.
92
+ */
93
+ export declare function getHeadersFromOrigin(ctx: ConsistencyTestContext, origin: HeadersOrigin, init: Record<string, string>): Promise<void>;
94
+ export interface BlobOptions {
95
+ type?: string;
96
+ }
97
+ /**
98
+ * Create a Blob in the isolate from the specified origin.
99
+ * The Blob is stored at globalThis.__testBlob.
100
+ */
101
+ export declare function getBlobFromOrigin(ctx: ConsistencyTestContext, origin: BlobOrigin, content: string, options?: BlobOptions): Promise<void>;
102
+ export interface FileOptions {
103
+ type?: string;
104
+ lastModified?: number;
105
+ }
106
+ /**
107
+ * Create a File in the isolate from the specified origin.
108
+ * The File is stored at globalThis.__testFile.
109
+ */
110
+ export declare function getFileFromOrigin(ctx: ConsistencyTestContext, origin: FileOrigin, content: string, filename: string, options?: FileOptions): Promise<void>;
111
+ /**
112
+ * Create FormData in the isolate from the specified origin.
113
+ * The FormData is stored at globalThis.__testFormData.
114
+ */
115
+ export declare function getFormDataFromOrigin(ctx: ConsistencyTestContext, origin: FormDataOrigin, entries: Array<[string, string]>): Promise<void>;
116
+ /**
117
+ * Setup a serve handler that returns the specified response.
118
+ */
119
+ export declare function setupServeHandler(ctx: ConsistencyTestContext, body: string, options?: ResponseOptions): Promise<void>;
120
+ /**
121
+ * Dispatch a request and get the Response on the host side.
122
+ * This tests the host-side conversion of Response from isolate.
123
+ */
124
+ export declare function getDispatchResponse(ctx: ConsistencyTestContext, body: string, options?: ResponseOptions): Promise<Response>;
125
+ /**
126
+ * Create a ReadableStream in the isolate from the specified origin.
127
+ * The ReadableStream is stored at globalThis.__testReadableStream.
128
+ */
129
+ export declare function getReadableStreamFromOrigin(ctx: ConsistencyTestContext, origin: ReadableStreamOrigin, chunks?: string[]): Promise<void>;
130
+ /**
131
+ * Create a WritableStream in the isolate from the specified origin.
132
+ * The WritableStream is stored at globalThis.__testWritableStream.
133
+ * Also stores written chunks at globalThis.__testWrittenChunks.
134
+ */
135
+ export declare function getWritableStreamFromOrigin(ctx: ConsistencyTestContext, origin: WritableStreamOrigin): Promise<void>;
136
+ /**
137
+ * Create a TransformStream in the isolate from the specified origin.
138
+ * The TransformStream is stored at globalThis.__testTransformStream.
139
+ */
140
+ export declare function getTransformStreamFromOrigin(ctx: ConsistencyTestContext, _origin: TransformStreamOrigin): Promise<void>;
141
+ /**
142
+ * Create a TextEncoderStream in the isolate from the specified origin.
143
+ * The TextEncoderStream is stored at globalThis.__testTextEncoderStream.
144
+ */
145
+ export declare function getTextEncoderStreamFromOrigin(ctx: ConsistencyTestContext, _origin: TextEncoderStreamOrigin): Promise<void>;
146
+ export interface TextDecoderStreamOptions {
147
+ fatal?: boolean;
148
+ ignoreBOM?: boolean;
149
+ }
150
+ /**
151
+ * Create a TextDecoderStream in the isolate from the specified origin.
152
+ * The TextDecoderStream is stored at globalThis.__testTextDecoderStream.
153
+ */
154
+ export declare function getTextDecoderStreamFromOrigin(ctx: ConsistencyTestContext, _origin: TextDecoderStreamOrigin, options?: TextDecoderStreamOptions): Promise<void>;
155
+ /**
156
+ * Create a ByteLengthQueuingStrategy or CountQueuingStrategy in the isolate.
157
+ * The strategy is stored at globalThis.__testQueuingStrategy.
158
+ */
159
+ export declare function getQueuingStrategyFromOrigin(ctx: ConsistencyTestContext, strategyType: "ByteLength" | "Count", highWaterMark?: number): Promise<void>;
160
+ /**
161
+ * Create a URL in the isolate from the specified origin.
162
+ * The URL is stored at globalThis.__testURL.
163
+ */
164
+ export declare function getURLFromOrigin(ctx: ConsistencyTestContext, origin: URLOrigin, urlString: string): Promise<void>;
165
+ /**
166
+ * Create URLSearchParams in the isolate from the specified origin.
167
+ * The URLSearchParams is stored at globalThis.__testURLSearchParams.
168
+ */
169
+ export declare function getURLSearchParamsFromOrigin(ctx: ConsistencyTestContext, origin: URLSearchParamsOrigin, init?: string): Promise<void>;
170
+ /**
171
+ * Create an AbortController in the isolate from the specified origin.
172
+ * The AbortController is stored at globalThis.__testAbortController.
173
+ */
174
+ export declare function getAbortControllerFromOrigin(ctx: ConsistencyTestContext, _origin: AbortControllerOrigin): Promise<void>;
175
+ /**
176
+ * Create an AbortSignal in the isolate from the specified origin.
177
+ * The AbortSignal is stored at globalThis.__testAbortSignal.
178
+ */
179
+ export declare function getAbortSignalFromOrigin(ctx: ConsistencyTestContext, _origin: AbortSignalOrigin): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ricsam/isolate-fetch",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "main": "./dist/cjs/index.cjs",
5
5
  "types": "./dist/types/index.d.ts",
6
6
  "exports": {