@ccheever/exact-ibex-runtime 0.1.0
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/package.json +63 -0
- package/src/abort/AbortController.ts +23 -0
- package/src/abort/AbortSignal.ts +152 -0
- package/src/abort/index.ts +2 -0
- package/src/accessibility.ts +12 -0
- package/src/arraybuffer-detach.ts +109 -0
- package/src/base64/base64.ts +168 -0
- package/src/base64/index.ts +1 -0
- package/src/blob/Blob.ts +259 -0
- package/src/blob/File.ts +59 -0
- package/src/blob/FormData.ts +323 -0
- package/src/blob/index.ts +3 -0
- package/src/bootstrap.ts +1946 -0
- package/src/broadcast/BroadcastChannel.ts +280 -0
- package/src/broadcast/index.ts +5 -0
- package/src/cache/Cache.ts +349 -0
- package/src/cache/CacheStorage.ts +89 -0
- package/src/cache/index.ts +27 -0
- package/src/camera/index.ts +6202 -0
- package/src/camera/processor.worker.ts +194 -0
- package/src/camera/scene.ts +195 -0
- package/src/clipboard/Clipboard.ts +129 -0
- package/src/clipboard/ClipboardItem.ts +97 -0
- package/src/clipboard/index.ts +6 -0
- package/src/clone/index.ts +1 -0
- package/src/clone/structuredClone.ts +389 -0
- package/src/clone/transferableSymbols.ts +2 -0
- package/src/compression/CompressionStream.ts +146 -0
- package/src/compression/DecompressionStream.ts +342 -0
- package/src/compression/index.ts +4 -0
- package/src/console/Console.ts +341 -0
- package/src/console/index.ts +2 -0
- package/src/core/accessibility-state.ts +263 -0
- package/src/core/accessibility.ts +184 -0
- package/src/core/agent-state.ts +37 -0
- package/src/core/diagnostics-logs.ts +144 -0
- package/src/core/host-call-bridge.ts +16 -0
- package/src/core/i18n-helpers.ts +189 -0
- package/src/core/locale-state.ts +253 -0
- package/src/core/locale.ts +95 -0
- package/src/crypto/Crypto.ts +2743 -0
- package/src/crypto/index.ts +1 -0
- package/src/diagnostics/logs.ts +7 -0
- package/src/encoding/TextDecoder.ts +1181 -0
- package/src/encoding/TextDecoderStream.ts +58 -0
- package/src/encoding/TextEncoder.ts +180 -0
- package/src/encoding/TextEncoderStream.ts +39 -0
- package/src/encoding/index.ts +8 -0
- package/src/events/CloseEvent.ts +91 -0
- package/src/events/DOMException.ts +409 -0
- package/src/events/ErrorEvent.ts +39 -0
- package/src/events/Event.ts +151 -0
- package/src/events/EventTarget.ts +280 -0
- package/src/events/FocusEvent.ts +27 -0
- package/src/events/KeyboardEvent.ts +46 -0
- package/src/events/MessageEvent.ts +61 -0
- package/src/events/ProgressEvent.ts +33 -0
- package/src/events/PromiseRejectionEvent.ts +31 -0
- package/src/events/index.ts +52 -0
- package/src/eventsource/EventSource.ts +371 -0
- package/src/eventsource/index.ts +2 -0
- package/src/fetch/Headers.ts +642 -0
- package/src/fetch/Request.ts +760 -0
- package/src/fetch/Response.ts +543 -0
- package/src/fetch/body.ts +1256 -0
- package/src/fetch/cookie-jar.ts +566 -0
- package/src/fetch/demo.ts +207 -0
- package/src/fetch/errors.ts +101 -0
- package/src/fetch/fetch.ts +2610 -0
- package/src/fetch/index.ts +101 -0
- package/src/fetch/native-bridge.ts +65 -0
- package/src/fetch/types.ts +258 -0
- package/src/filereader/FileReader.ts +236 -0
- package/src/filereader/index.ts +1 -0
- package/src/fs/Dirent.ts +39 -0
- package/src/fs/ExactFile.ts +450 -0
- package/src/fs/Stats.ts +80 -0
- package/src/fs/index.ts +944 -0
- package/src/fs/promises.ts +386 -0
- package/src/fs/shared.ts +328 -0
- package/src/http-server/index.js +697 -0
- package/src/http-server/index.ts +27 -0
- package/src/identity.generated.ts +14 -0
- package/src/index.ts +283 -0
- package/src/indexeddb/IDBCursor.ts +188 -0
- package/src/indexeddb/IDBDatabase.ts +343 -0
- package/src/indexeddb/IDBFactory.ts +269 -0
- package/src/indexeddb/IDBIndex.ts +194 -0
- package/src/indexeddb/IDBKeyRange.ts +109 -0
- package/src/indexeddb/IDBObjectStore.ts +468 -0
- package/src/indexeddb/IDBRequest.ts +163 -0
- package/src/indexeddb/IDBTransaction.ts +207 -0
- package/src/indexeddb/index.ts +34 -0
- package/src/indexeddb/utils.ts +52 -0
- package/src/inspect/index.ts +1 -0
- package/src/inspect/inspect.ts +465 -0
- package/src/internal/detect.ts +104 -0
- package/src/locale.ts +10 -0
- package/src/location/index.ts +1059 -0
- package/src/locks/LockManager.ts +460 -0
- package/src/locks/index.ts +12 -0
- package/src/media/VideoFrame.ts +58 -0
- package/src/messaging/MessageChannel.ts +31 -0
- package/src/messaging/MessagePort.ts +180 -0
- package/src/messaging/index.ts +2 -0
- package/src/messaging.ts +247 -0
- package/src/native/NativeModules.ts +354 -0
- package/src/native/index.ts +1 -0
- package/src/navigator/Navigator.ts +351 -0
- package/src/navigator/index.ts +1 -0
- package/src/node/Buffer.ts +1786 -0
- package/src/node/index.ts +4 -0
- package/src/node/path.ts +495 -0
- package/src/node/process.ts +2528 -0
- package/src/performance/Performance.ts +532 -0
- package/src/performance/index.ts +21 -0
- package/src/polyfills/array.ts +236 -0
- package/src/polyfills/arraybuffer.ts +172 -0
- package/src/polyfills/groupby.ts +85 -0
- package/src/polyfills/index.ts +85 -0
- package/src/polyfills/intl.ts +1956 -0
- package/src/polyfills/iterator.ts +479 -0
- package/src/polyfills/promise.ts +37 -0
- package/src/polyfills/set.ts +245 -0
- package/src/polyfills/string.ts +85 -0
- package/src/polyfills/typedarray.ts +110 -0
- package/src/promise-rejection-tracking.ts +464 -0
- package/src/react-native/index.ts +388 -0
- package/src/runtime-entry.ts +55 -0
- package/src/scheduling/AnimationFrame.ts +105 -0
- package/src/scheduling/IdleCallback.ts +167 -0
- package/src/scheduling/index.ts +13 -0
- package/src/security/Capabilities.ts +1146 -0
- package/src/security/Permissions.ts +392 -0
- package/src/security/capability-bits.generated.ts +63 -0
- package/src/security/index.ts +16 -0
- package/src/sqlite/Database.ts +456 -0
- package/src/sqlite/Statement.ts +206 -0
- package/src/sqlite/constants.ts +79 -0
- package/src/sqlite/errors.ts +25 -0
- package/src/sqlite/index.ts +34 -0
- package/src/sqlite/module.js +438 -0
- package/src/storage/Storage.ts +291 -0
- package/src/storage/StorageManager.ts +91 -0
- package/src/storage/index.ts +3 -0
- package/src/stream-compat.ts +47 -0
- package/src/streams/ReadableStream.ts +4131 -0
- package/src/streams/TransformStream.ts +375 -0
- package/src/streams/WritableStream.ts +866 -0
- package/src/streams/index.ts +41 -0
- package/src/timers/Timers.ts +296 -0
- package/src/timers/index.ts +11 -0
- package/src/url/URL.ts +656 -0
- package/src/url/URLPattern.ts +850 -0
- package/src/url/URLSearchParams.ts +244 -0
- package/src/url/index.ts +9 -0
- package/src/websocket/WebSocket.ts +770 -0
- package/src/websocket/WebSocketError.ts +52 -0
- package/src/websocket/WebSocketStream.ts +628 -0
- package/src/websocket/index.ts +7 -0
- package/src/window/index.ts +872 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Demo script to test the fetch implementation.
|
|
3
|
+
*
|
|
4
|
+
* Run with: bun src/runtime/fetch/demo.ts
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
fetch,
|
|
9
|
+
setNativeFetchModule,
|
|
10
|
+
Headers,
|
|
11
|
+
Request,
|
|
12
|
+
Response,
|
|
13
|
+
type NativeFetchModule,
|
|
14
|
+
type NativeResponse,
|
|
15
|
+
} from './index.js';
|
|
16
|
+
|
|
17
|
+
// =============================================================================
|
|
18
|
+
// Mock Native Module (simulates what Swift/Kotlin would provide)
|
|
19
|
+
// =============================================================================
|
|
20
|
+
|
|
21
|
+
const mockNativeModule: NativeFetchModule = {
|
|
22
|
+
async fetch(url, init, body) {
|
|
23
|
+
console.log(`[Native] ${init.method} ${url}`);
|
|
24
|
+
if (body) {
|
|
25
|
+
console.log(`[Native] Body: ${new TextDecoder().decode(body)}`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Simulate different responses based on URL
|
|
29
|
+
if (url.includes('jsonplaceholder')) {
|
|
30
|
+
// Simulate a real API response
|
|
31
|
+
const mockData = { userId: 1, id: 1, title: 'Test Post', completed: false };
|
|
32
|
+
return {
|
|
33
|
+
status: 200,
|
|
34
|
+
statusText: 'OK',
|
|
35
|
+
headers: [['content-type', 'application/json']],
|
|
36
|
+
url,
|
|
37
|
+
redirected: false,
|
|
38
|
+
body: new TextEncoder().encode(JSON.stringify(mockData)).buffer,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (url.includes('/error')) {
|
|
43
|
+
return {
|
|
44
|
+
status: 500,
|
|
45
|
+
statusText: 'Internal Server Error',
|
|
46
|
+
headers: [],
|
|
47
|
+
url,
|
|
48
|
+
redirected: false,
|
|
49
|
+
body: new TextEncoder().encode('Something went wrong').buffer,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Default mock response
|
|
54
|
+
return {
|
|
55
|
+
status: 200,
|
|
56
|
+
statusText: 'OK',
|
|
57
|
+
headers: [['content-type', 'text/plain']],
|
|
58
|
+
url,
|
|
59
|
+
redirected: false,
|
|
60
|
+
body: new TextEncoder().encode('Hello from mock!').buffer,
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// Initialize the native module
|
|
66
|
+
setNativeFetchModule(mockNativeModule);
|
|
67
|
+
|
|
68
|
+
// =============================================================================
|
|
69
|
+
// Test Cases
|
|
70
|
+
// =============================================================================
|
|
71
|
+
|
|
72
|
+
async function testHeaders() {
|
|
73
|
+
console.log('\n=== Testing Headers ===');
|
|
74
|
+
|
|
75
|
+
const headers = new Headers({
|
|
76
|
+
'Content-Type': 'application/json',
|
|
77
|
+
'Authorization': 'Bearer token123',
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
console.log('Content-Type:', headers.get('content-type'));
|
|
81
|
+
console.log('Has Authorization:', headers.has('authorization'));
|
|
82
|
+
|
|
83
|
+
headers.append('Accept', 'application/json');
|
|
84
|
+
headers.append('Accept', 'text/plain');
|
|
85
|
+
console.log('Accept (combined):', headers.get('accept'));
|
|
86
|
+
|
|
87
|
+
console.log('All headers:');
|
|
88
|
+
for (const [name, value] of headers) {
|
|
89
|
+
console.log(` ${name}: ${value}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function testRequest() {
|
|
94
|
+
console.log('\n=== Testing Request ===');
|
|
95
|
+
|
|
96
|
+
const request = new Request('https://api.example.com/users', {
|
|
97
|
+
method: 'POST',
|
|
98
|
+
headers: { 'Content-Type': 'application/json' },
|
|
99
|
+
body: JSON.stringify({ name: 'John Doe' }),
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
console.log('Method:', request.method);
|
|
103
|
+
console.log('URL:', request.url);
|
|
104
|
+
console.log('Content-Type:', request.headers.get('content-type'));
|
|
105
|
+
console.log('Body:', await request.text());
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function testResponse() {
|
|
109
|
+
console.log('\n=== Testing Response ===');
|
|
110
|
+
|
|
111
|
+
// String body
|
|
112
|
+
const textResponse = new Response('Hello, World!');
|
|
113
|
+
console.log('Text response:', await textResponse.text());
|
|
114
|
+
|
|
115
|
+
// JSON response
|
|
116
|
+
const jsonResponse = Response.json({ message: 'Success', code: 200 });
|
|
117
|
+
console.log('JSON response:', await jsonResponse.json());
|
|
118
|
+
|
|
119
|
+
// Redirect response
|
|
120
|
+
const redirectResponse = Response.redirect('https://example.com/new-location', 302);
|
|
121
|
+
console.log('Redirect status:', redirectResponse.status);
|
|
122
|
+
console.log('Redirect location:', redirectResponse.headers.get('location'));
|
|
123
|
+
|
|
124
|
+
// Error response
|
|
125
|
+
const errorResponse = Response.error();
|
|
126
|
+
console.log('Error response type:', errorResponse.type);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async function testFetch() {
|
|
130
|
+
console.log('\n=== Testing fetch() ===');
|
|
131
|
+
|
|
132
|
+
// Simple GET request
|
|
133
|
+
console.log('\n--- GET Request ---');
|
|
134
|
+
const getResponse = await fetch('https://jsonplaceholder.typicode.com/todos/1');
|
|
135
|
+
console.log('Status:', getResponse.status);
|
|
136
|
+
console.log('OK:', getResponse.ok);
|
|
137
|
+
const getData = await getResponse.json();
|
|
138
|
+
console.log('Data:', getData);
|
|
139
|
+
|
|
140
|
+
// POST request with body
|
|
141
|
+
console.log('\n--- POST Request ---');
|
|
142
|
+
const postResponse = await fetch('https://api.example.com/users', {
|
|
143
|
+
method: 'POST',
|
|
144
|
+
headers: { 'Content-Type': 'application/json' },
|
|
145
|
+
body: JSON.stringify({ name: 'Jane Doe', email: 'jane@example.com' }),
|
|
146
|
+
});
|
|
147
|
+
console.log('Status:', postResponse.status);
|
|
148
|
+
|
|
149
|
+
// Request with custom headers
|
|
150
|
+
console.log('\n--- Request with Headers ---');
|
|
151
|
+
const authResponse = await fetch('https://api.example.com/protected', {
|
|
152
|
+
headers: {
|
|
153
|
+
'Authorization': 'Bearer my-secret-token',
|
|
154
|
+
'X-Custom-Header': 'custom-value',
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
console.log('Status:', authResponse.status);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async function testAbort() {
|
|
161
|
+
console.log('\n=== Testing AbortController ===');
|
|
162
|
+
|
|
163
|
+
const controller = new AbortController();
|
|
164
|
+
|
|
165
|
+
// Abort immediately
|
|
166
|
+
controller.abort();
|
|
167
|
+
|
|
168
|
+
try {
|
|
169
|
+
await fetch('https://api.example.com/slow', {
|
|
170
|
+
signal: controller.signal,
|
|
171
|
+
});
|
|
172
|
+
} catch (error) {
|
|
173
|
+
console.log('Caught abort error:', (error as Error).message);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
async function testClone() {
|
|
178
|
+
console.log('\n=== Testing clone() ===');
|
|
179
|
+
|
|
180
|
+
const response = await fetch('https://api.example.com/data');
|
|
181
|
+
const clone = response.clone();
|
|
182
|
+
|
|
183
|
+
// Both can be read independently
|
|
184
|
+
const text1 = await response.text();
|
|
185
|
+
const text2 = await clone.text();
|
|
186
|
+
|
|
187
|
+
console.log('Original:', text1);
|
|
188
|
+
console.log('Clone:', text2);
|
|
189
|
+
console.log('Match:', text1 === text2);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Run all tests
|
|
193
|
+
async function main() {
|
|
194
|
+
console.log('Fetch API Implementation Demo');
|
|
195
|
+
console.log('==============================');
|
|
196
|
+
|
|
197
|
+
await testHeaders();
|
|
198
|
+
await testRequest();
|
|
199
|
+
await testResponse();
|
|
200
|
+
await testFetch();
|
|
201
|
+
await testAbort();
|
|
202
|
+
await testClone();
|
|
203
|
+
|
|
204
|
+
console.log('\n✅ All demos completed!');
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
main().catch(console.error);
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetch API Errors
|
|
3
|
+
*
|
|
4
|
+
* Custom error types for the Fetch API implementation.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Error thrown when a fetch request fails.
|
|
9
|
+
*/
|
|
10
|
+
export class FetchError implements Error {
|
|
11
|
+
name = 'FetchError';
|
|
12
|
+
message: string;
|
|
13
|
+
stack?: string;
|
|
14
|
+
cause?: unknown;
|
|
15
|
+
|
|
16
|
+
constructor(
|
|
17
|
+
message: string,
|
|
18
|
+
options?: { cause?: unknown; stack?: string }
|
|
19
|
+
) {
|
|
20
|
+
this.message = `fetch failed: ${message}`;
|
|
21
|
+
this.cause = options?.cause;
|
|
22
|
+
this.stack = options?.stack ?? new Error(this.message).stack;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Create a FetchError from an existing Error.
|
|
27
|
+
*/
|
|
28
|
+
static createFromError(error: Error): FetchError {
|
|
29
|
+
return new FetchError(error.message, {
|
|
30
|
+
cause: (error as Error & { cause?: unknown }).cause,
|
|
31
|
+
stack: error.stack,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
Object.setPrototypeOf(FetchError.prototype, Error.prototype);
|
|
36
|
+
Object.setPrototypeOf(FetchError, Error);
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Error thrown when a request is aborted.
|
|
40
|
+
*/
|
|
41
|
+
export class AbortError implements Error {
|
|
42
|
+
name = 'AbortError';
|
|
43
|
+
message: string;
|
|
44
|
+
stack?: string;
|
|
45
|
+
|
|
46
|
+
constructor(message = 'The operation was aborted') {
|
|
47
|
+
this.message = message;
|
|
48
|
+
this.stack = new Error(this.message).stack;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
Object.setPrototypeOf(AbortError.prototype, Error.prototype);
|
|
52
|
+
Object.setPrototypeOf(AbortError, Error);
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Error thrown for network failures.
|
|
56
|
+
*/
|
|
57
|
+
export class NetworkError implements Error {
|
|
58
|
+
name = 'NetworkError';
|
|
59
|
+
message: string;
|
|
60
|
+
stack?: string;
|
|
61
|
+
|
|
62
|
+
constructor(message = 'Network request failed') {
|
|
63
|
+
this.message = message;
|
|
64
|
+
this.stack = new Error(this.message).stack;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
Object.setPrototypeOf(NetworkError.prototype, Error.prototype);
|
|
68
|
+
Object.setPrototypeOf(NetworkError, Error);
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Error thrown for invalid URLs.
|
|
72
|
+
*/
|
|
73
|
+
export class URLError implements Error {
|
|
74
|
+
name = 'URLError';
|
|
75
|
+
message: string;
|
|
76
|
+
stack?: string;
|
|
77
|
+
|
|
78
|
+
constructor(url: string) {
|
|
79
|
+
this.message = `Invalid URL: ${url}`;
|
|
80
|
+
this.stack = new Error(this.message).stack;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
Object.setPrototypeOf(URLError.prototype, Error.prototype);
|
|
84
|
+
Object.setPrototypeOf(URLError, Error);
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Error thrown when body has already been consumed.
|
|
88
|
+
* Extends TypeError per the Fetch spec.
|
|
89
|
+
*/
|
|
90
|
+
export class BodyConsumedError implements Error {
|
|
91
|
+
name = 'TypeError';
|
|
92
|
+
message: string;
|
|
93
|
+
stack?: string;
|
|
94
|
+
|
|
95
|
+
constructor() {
|
|
96
|
+
this.message = 'Body already used';
|
|
97
|
+
this.stack = new TypeError(this.message).stack;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
Object.setPrototypeOf(BodyConsumedError.prototype, TypeError.prototype);
|
|
101
|
+
Object.setPrototypeOf(BodyConsumedError, TypeError);
|