@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.
Files changed (161) hide show
  1. package/package.json +63 -0
  2. package/src/abort/AbortController.ts +23 -0
  3. package/src/abort/AbortSignal.ts +152 -0
  4. package/src/abort/index.ts +2 -0
  5. package/src/accessibility.ts +12 -0
  6. package/src/arraybuffer-detach.ts +109 -0
  7. package/src/base64/base64.ts +168 -0
  8. package/src/base64/index.ts +1 -0
  9. package/src/blob/Blob.ts +259 -0
  10. package/src/blob/File.ts +59 -0
  11. package/src/blob/FormData.ts +323 -0
  12. package/src/blob/index.ts +3 -0
  13. package/src/bootstrap.ts +1946 -0
  14. package/src/broadcast/BroadcastChannel.ts +280 -0
  15. package/src/broadcast/index.ts +5 -0
  16. package/src/cache/Cache.ts +349 -0
  17. package/src/cache/CacheStorage.ts +89 -0
  18. package/src/cache/index.ts +27 -0
  19. package/src/camera/index.ts +6202 -0
  20. package/src/camera/processor.worker.ts +194 -0
  21. package/src/camera/scene.ts +195 -0
  22. package/src/clipboard/Clipboard.ts +129 -0
  23. package/src/clipboard/ClipboardItem.ts +97 -0
  24. package/src/clipboard/index.ts +6 -0
  25. package/src/clone/index.ts +1 -0
  26. package/src/clone/structuredClone.ts +389 -0
  27. package/src/clone/transferableSymbols.ts +2 -0
  28. package/src/compression/CompressionStream.ts +146 -0
  29. package/src/compression/DecompressionStream.ts +342 -0
  30. package/src/compression/index.ts +4 -0
  31. package/src/console/Console.ts +341 -0
  32. package/src/console/index.ts +2 -0
  33. package/src/core/accessibility-state.ts +263 -0
  34. package/src/core/accessibility.ts +184 -0
  35. package/src/core/agent-state.ts +37 -0
  36. package/src/core/diagnostics-logs.ts +144 -0
  37. package/src/core/host-call-bridge.ts +16 -0
  38. package/src/core/i18n-helpers.ts +189 -0
  39. package/src/core/locale-state.ts +253 -0
  40. package/src/core/locale.ts +95 -0
  41. package/src/crypto/Crypto.ts +2743 -0
  42. package/src/crypto/index.ts +1 -0
  43. package/src/diagnostics/logs.ts +7 -0
  44. package/src/encoding/TextDecoder.ts +1181 -0
  45. package/src/encoding/TextDecoderStream.ts +58 -0
  46. package/src/encoding/TextEncoder.ts +180 -0
  47. package/src/encoding/TextEncoderStream.ts +39 -0
  48. package/src/encoding/index.ts +8 -0
  49. package/src/events/CloseEvent.ts +91 -0
  50. package/src/events/DOMException.ts +409 -0
  51. package/src/events/ErrorEvent.ts +39 -0
  52. package/src/events/Event.ts +151 -0
  53. package/src/events/EventTarget.ts +280 -0
  54. package/src/events/FocusEvent.ts +27 -0
  55. package/src/events/KeyboardEvent.ts +46 -0
  56. package/src/events/MessageEvent.ts +61 -0
  57. package/src/events/ProgressEvent.ts +33 -0
  58. package/src/events/PromiseRejectionEvent.ts +31 -0
  59. package/src/events/index.ts +52 -0
  60. package/src/eventsource/EventSource.ts +371 -0
  61. package/src/eventsource/index.ts +2 -0
  62. package/src/fetch/Headers.ts +642 -0
  63. package/src/fetch/Request.ts +760 -0
  64. package/src/fetch/Response.ts +543 -0
  65. package/src/fetch/body.ts +1256 -0
  66. package/src/fetch/cookie-jar.ts +566 -0
  67. package/src/fetch/demo.ts +207 -0
  68. package/src/fetch/errors.ts +101 -0
  69. package/src/fetch/fetch.ts +2610 -0
  70. package/src/fetch/index.ts +101 -0
  71. package/src/fetch/native-bridge.ts +65 -0
  72. package/src/fetch/types.ts +258 -0
  73. package/src/filereader/FileReader.ts +236 -0
  74. package/src/filereader/index.ts +1 -0
  75. package/src/fs/Dirent.ts +39 -0
  76. package/src/fs/ExactFile.ts +450 -0
  77. package/src/fs/Stats.ts +80 -0
  78. package/src/fs/index.ts +944 -0
  79. package/src/fs/promises.ts +386 -0
  80. package/src/fs/shared.ts +328 -0
  81. package/src/http-server/index.js +697 -0
  82. package/src/http-server/index.ts +27 -0
  83. package/src/identity.generated.ts +14 -0
  84. package/src/index.ts +283 -0
  85. package/src/indexeddb/IDBCursor.ts +188 -0
  86. package/src/indexeddb/IDBDatabase.ts +343 -0
  87. package/src/indexeddb/IDBFactory.ts +269 -0
  88. package/src/indexeddb/IDBIndex.ts +194 -0
  89. package/src/indexeddb/IDBKeyRange.ts +109 -0
  90. package/src/indexeddb/IDBObjectStore.ts +468 -0
  91. package/src/indexeddb/IDBRequest.ts +163 -0
  92. package/src/indexeddb/IDBTransaction.ts +207 -0
  93. package/src/indexeddb/index.ts +34 -0
  94. package/src/indexeddb/utils.ts +52 -0
  95. package/src/inspect/index.ts +1 -0
  96. package/src/inspect/inspect.ts +465 -0
  97. package/src/internal/detect.ts +104 -0
  98. package/src/locale.ts +10 -0
  99. package/src/location/index.ts +1059 -0
  100. package/src/locks/LockManager.ts +460 -0
  101. package/src/locks/index.ts +12 -0
  102. package/src/media/VideoFrame.ts +58 -0
  103. package/src/messaging/MessageChannel.ts +31 -0
  104. package/src/messaging/MessagePort.ts +180 -0
  105. package/src/messaging/index.ts +2 -0
  106. package/src/messaging.ts +247 -0
  107. package/src/native/NativeModules.ts +354 -0
  108. package/src/native/index.ts +1 -0
  109. package/src/navigator/Navigator.ts +351 -0
  110. package/src/navigator/index.ts +1 -0
  111. package/src/node/Buffer.ts +1786 -0
  112. package/src/node/index.ts +4 -0
  113. package/src/node/path.ts +495 -0
  114. package/src/node/process.ts +2528 -0
  115. package/src/performance/Performance.ts +532 -0
  116. package/src/performance/index.ts +21 -0
  117. package/src/polyfills/array.ts +236 -0
  118. package/src/polyfills/arraybuffer.ts +172 -0
  119. package/src/polyfills/groupby.ts +85 -0
  120. package/src/polyfills/index.ts +85 -0
  121. package/src/polyfills/intl.ts +1956 -0
  122. package/src/polyfills/iterator.ts +479 -0
  123. package/src/polyfills/promise.ts +37 -0
  124. package/src/polyfills/set.ts +245 -0
  125. package/src/polyfills/string.ts +85 -0
  126. package/src/polyfills/typedarray.ts +110 -0
  127. package/src/promise-rejection-tracking.ts +464 -0
  128. package/src/react-native/index.ts +388 -0
  129. package/src/runtime-entry.ts +55 -0
  130. package/src/scheduling/AnimationFrame.ts +105 -0
  131. package/src/scheduling/IdleCallback.ts +167 -0
  132. package/src/scheduling/index.ts +13 -0
  133. package/src/security/Capabilities.ts +1146 -0
  134. package/src/security/Permissions.ts +392 -0
  135. package/src/security/capability-bits.generated.ts +63 -0
  136. package/src/security/index.ts +16 -0
  137. package/src/sqlite/Database.ts +456 -0
  138. package/src/sqlite/Statement.ts +206 -0
  139. package/src/sqlite/constants.ts +79 -0
  140. package/src/sqlite/errors.ts +25 -0
  141. package/src/sqlite/index.ts +34 -0
  142. package/src/sqlite/module.js +438 -0
  143. package/src/storage/Storage.ts +291 -0
  144. package/src/storage/StorageManager.ts +91 -0
  145. package/src/storage/index.ts +3 -0
  146. package/src/stream-compat.ts +47 -0
  147. package/src/streams/ReadableStream.ts +4131 -0
  148. package/src/streams/TransformStream.ts +375 -0
  149. package/src/streams/WritableStream.ts +866 -0
  150. package/src/streams/index.ts +41 -0
  151. package/src/timers/Timers.ts +296 -0
  152. package/src/timers/index.ts +11 -0
  153. package/src/url/URL.ts +656 -0
  154. package/src/url/URLPattern.ts +850 -0
  155. package/src/url/URLSearchParams.ts +244 -0
  156. package/src/url/index.ts +9 -0
  157. package/src/websocket/WebSocket.ts +770 -0
  158. package/src/websocket/WebSocketError.ts +52 -0
  159. package/src/websocket/WebSocketStream.ts +628 -0
  160. package/src/websocket/index.ts +7 -0
  161. package/src/window/index.ts +872 -0
@@ -0,0 +1,41 @@
1
+ export {
2
+ ReadableStream,
3
+ ReadableStreamDefaultReader,
4
+ ReadableStreamDefaultController,
5
+ ReadableByteStreamController,
6
+ ReadableStreamBYOBReader,
7
+ ReadableStreamBYOBRequest,
8
+ isReadableStream,
9
+ ByteLengthQueuingStrategy,
10
+ CountQueuingStrategy,
11
+ } from './ReadableStream';
12
+
13
+ export type {
14
+ UnderlyingSource,
15
+ UnderlyingByteSource,
16
+ QueuingStrategy,
17
+ ReadableStreamReadResult,
18
+ ReadableStreamReadValueResult,
19
+ ReadableStreamReadDoneResult,
20
+ ReadableStreamBYOBReadResult,
21
+ } from './ReadableStream';
22
+
23
+ export {
24
+ WritableStream,
25
+ WritableStreamDefaultWriter,
26
+ WritableStreamDefaultController,
27
+ } from './WritableStream';
28
+
29
+ export type {
30
+ UnderlyingSink,
31
+ StreamPipeOptions,
32
+ } from './WritableStream';
33
+
34
+ export {
35
+ TransformStream,
36
+ TransformStreamDefaultController,
37
+ } from './TransformStream';
38
+
39
+ export type {
40
+ Transformer,
41
+ } from './TransformStream';
@@ -0,0 +1,296 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * Timers - Web Standard Timer Implementation
4
+ *
5
+ * @see https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html
6
+ */
7
+
8
+ export interface TimerModule {
9
+ setTimeout(callback: () => void, delay: number): number;
10
+ clearTimeout(id: number): void;
11
+ setInterval(callback: () => void, delay: number): number;
12
+ clearInterval(id: number): void;
13
+ }
14
+
15
+ const symbolDispose =
16
+ typeof Symbol === "function"
17
+ ? (Symbol.dispose ?? (typeof Symbol.for === "function" ? Symbol.for("nodejs.dispose") : undefined))
18
+ : undefined;
19
+
20
+ function validateTimerCallback<TArgs extends any[]>(callback: ((...args: TArgs) => void) | unknown): (...args: TArgs) => void {
21
+ if (typeof callback === "function") {
22
+ return callback;
23
+ }
24
+ const err = new TypeError(
25
+ `The "callback" argument must be of type function. Received type ${
26
+ callback === null ? "null" : typeof callback
27
+ }`,
28
+ ) as TypeError & { code?: string };
29
+ err.code = "ERR_INVALID_ARG_TYPE";
30
+ throw err;
31
+ }
32
+
33
+ class ImmediateHandle {
34
+ private _handle: unknown;
35
+ _destroyed = false;
36
+ private _refed = true;
37
+
38
+ constructor(handle: unknown) {
39
+ this._handle = handle;
40
+ }
41
+
42
+ ref(): this {
43
+ this._refed = true;
44
+ const handle = this._handle as { ref?: () => void } | number | null | undefined;
45
+ if (handle && typeof handle === "object" && typeof handle.ref === "function") {
46
+ handle.ref();
47
+ } else if (typeof (globalThis as any).__exactTimerRef === "function" && handle != null) {
48
+ (globalThis as any).__exactTimerRef(handle);
49
+ }
50
+ return this;
51
+ }
52
+
53
+ unref(): this {
54
+ this._refed = false;
55
+ const handle = this._handle as { unref?: () => void } | number | null | undefined;
56
+ if (handle && typeof handle === "object" && typeof handle.unref === "function") {
57
+ handle.unref();
58
+ } else if (typeof (globalThis as any).__exactTimerUnref === "function" && handle != null) {
59
+ (globalThis as any).__exactTimerUnref(handle);
60
+ }
61
+ return this;
62
+ }
63
+
64
+ hasRef(): boolean {
65
+ return this._refed;
66
+ }
67
+
68
+ close(): this {
69
+ if (!this._destroyed) {
70
+ this._destroyed = true;
71
+ globalThis.clearTimeout(this._handle as any);
72
+ }
73
+ return this;
74
+ }
75
+
76
+ [Symbol.toPrimitive](): number {
77
+ if (typeof this._handle === "number") {
78
+ return this._handle;
79
+ }
80
+ return 0;
81
+ }
82
+ }
83
+
84
+ if (symbolDispose) {
85
+ (ImmediateHandle.prototype as any)[symbolDispose] = function dispose(this: ImmediateHandle) {
86
+ this.close();
87
+ };
88
+ }
89
+
90
+ // Native module for timer operations (set from native side)
91
+ let nativeTimerModule: TimerModule | null = null;
92
+
93
+ export function setNativeTimerModule(module: TimerModule): void {
94
+ nativeTimerModule = module;
95
+ }
96
+
97
+ // Fallback implementation using JS-based timers
98
+ // This is used when native module is not available (e.g., in tests)
99
+ let nextId = 1;
100
+ const timeoutMap = new Map<number, ReturnType<typeof globalThis.setTimeout>>();
101
+ const intervalMap = new Map<number, ReturnType<typeof globalThis.setInterval>>();
102
+
103
+ const fallbackModule: TimerModule = {
104
+ setTimeout(callback: () => void, delay: number): number {
105
+ const id = nextId++;
106
+ const handle = globalThis.setTimeout(() => {
107
+ timeoutMap.delete(id);
108
+ callback();
109
+ }, delay);
110
+ timeoutMap.set(id, handle);
111
+ return id;
112
+ },
113
+ clearTimeout(id: number): void {
114
+ const handle = timeoutMap.get(id);
115
+ if (handle !== undefined) {
116
+ globalThis.clearTimeout(handle);
117
+ timeoutMap.delete(id);
118
+ }
119
+ },
120
+ setInterval(callback: () => void, delay: number): number {
121
+ const id = nextId++;
122
+ const handle = globalThis.setInterval(callback, delay);
123
+ intervalMap.set(id, handle);
124
+ return id;
125
+ },
126
+ clearInterval(id: number): void {
127
+ const handle = intervalMap.get(id);
128
+ if (handle !== undefined) {
129
+ globalThis.clearInterval(handle);
130
+ intervalMap.delete(id);
131
+ }
132
+ },
133
+ };
134
+
135
+ function getModule(): TimerModule {
136
+ return nativeTimerModule ?? fallbackModule;
137
+ }
138
+
139
+ function reportTimerError(error: unknown): void {
140
+ const processObj = (globalThis as any).process;
141
+ if (processObj && typeof processObj.emit === "function" && processObj.emit("uncaughtException", error)) {
142
+ return;
143
+ }
144
+
145
+ queueMicrotask(() => {
146
+ throw error;
147
+ });
148
+ }
149
+
150
+ /**
151
+ * setTimeout - Schedule a callback after a delay
152
+ *
153
+ * @param callback Function to call
154
+ * @param delay Delay in milliseconds (default: 0)
155
+ * @param args Additional arguments to pass to callback
156
+ * @returns Timer ID (number, per web standard)
157
+ */
158
+ export function setTimeout<TArgs extends any[]>(
159
+ callback: (...args: TArgs) => void,
160
+ delay?: number,
161
+ ...args: TArgs
162
+ ): number {
163
+ callback = validateTimerCallback(callback);
164
+ const ms = Math.max(0, Number(delay) || 0);
165
+
166
+ // Wrap callback to pass arguments
167
+ const wrappedCallback = () => {
168
+ try {
169
+ callback(...args);
170
+ } catch (error) {
171
+ reportTimerError(error);
172
+ }
173
+ };
174
+
175
+ return getModule().setTimeout(wrappedCallback, ms);
176
+ }
177
+
178
+ /**
179
+ * clearTimeout - Cancel a scheduled timeout
180
+ *
181
+ * @param id Timer ID returned by setTimeout
182
+ */
183
+ export function clearTimeout(id?: number): void {
184
+ if (id !== undefined && id !== null) {
185
+ getModule().clearTimeout(id);
186
+ }
187
+ }
188
+
189
+ /**
190
+ * setInterval - Schedule a recurring callback
191
+ *
192
+ * @param callback Function to call
193
+ * @param delay Delay between calls in milliseconds (default: 0)
194
+ * @param args Additional arguments to pass to callback
195
+ * @returns Timer ID (number, per web standard)
196
+ */
197
+ export function setInterval<TArgs extends any[]>(
198
+ callback: (...args: TArgs) => void,
199
+ delay?: number,
200
+ ...args: TArgs
201
+ ): number {
202
+ callback = validateTimerCallback(callback);
203
+ const ms = Math.max(0, Number(delay) || 0);
204
+
205
+ // Wrap callback to pass arguments
206
+ const wrappedCallback = () => {
207
+ try {
208
+ callback(...args);
209
+ } catch (error) {
210
+ reportTimerError(error);
211
+ }
212
+ };
213
+
214
+ return getModule().setInterval(wrappedCallback, ms);
215
+ }
216
+
217
+ /**
218
+ * clearInterval - Cancel a recurring interval
219
+ *
220
+ * @param id Timer ID returned by setInterval
221
+ */
222
+ export function clearInterval(id?: number): void {
223
+ if (id !== undefined && id !== null) {
224
+ getModule().clearInterval(id);
225
+ }
226
+ }
227
+
228
+ /**
229
+ * queueMicrotask - Schedule a microtask
230
+ *
231
+ * Microtasks run before the next macrotask (timer, I/O, etc.)
232
+ *
233
+ * @param callback Function to call
234
+ */
235
+ export function queueMicrotask(callback: () => void): void {
236
+ // Use native queueMicrotask if available
237
+ if (typeof globalThis.queueMicrotask === "function") {
238
+ globalThis.queueMicrotask(() => {
239
+ try {
240
+ callback();
241
+ } catch (error) {
242
+ console.error("Error in queueMicrotask callback:", error);
243
+ }
244
+ });
245
+ } else {
246
+ // Fallback using Promise
247
+ Promise.resolve().then(() => {
248
+ try {
249
+ callback();
250
+ } catch (error) {
251
+ console.error("Error in queueMicrotask callback:", error);
252
+ }
253
+ });
254
+ }
255
+ }
256
+
257
+ /**
258
+ * setImmediate - Schedule a macrotask (Node.js compatibility)
259
+ *
260
+ * In Exact, this is equivalent to setTimeout(fn, 0)
261
+ *
262
+ * @param callback Function to call
263
+ * @param args Additional arguments to pass to callback
264
+ * @returns Timer ID
265
+ */
266
+ export function setImmediate<TArgs extends any[]>(
267
+ callback: (...args: TArgs) => void,
268
+ ...args: TArgs
269
+ ): ImmediateHandle {
270
+ callback = validateTimerCallback(callback);
271
+ let immediate: ImmediateHandle;
272
+ const wrappedCallback = () => {
273
+ immediate._destroyed = true;
274
+ try {
275
+ callback(...args);
276
+ } catch (error) {
277
+ reportTimerError(error);
278
+ }
279
+ };
280
+ const handle = globalThis.setTimeout(wrappedCallback, 0);
281
+ immediate = new ImmediateHandle(handle);
282
+ return immediate;
283
+ }
284
+
285
+ /**
286
+ * clearImmediate - Cancel a scheduled immediate (Node.js compatibility)
287
+ *
288
+ * @param id Timer ID returned by setImmediate
289
+ */
290
+ export function clearImmediate(id?: number | ImmediateHandle): void {
291
+ if (id && typeof id === "object" && typeof (id as ImmediateHandle).close === "function") {
292
+ (id as ImmediateHandle).close();
293
+ return;
294
+ }
295
+ clearTimeout(id as number | undefined);
296
+ }
@@ -0,0 +1,11 @@
1
+ export {
2
+ setTimeout,
3
+ clearTimeout,
4
+ setInterval,
5
+ clearInterval,
6
+ queueMicrotask,
7
+ setImmediate,
8
+ clearImmediate,
9
+ setNativeTimerModule,
10
+ } from "./Timers";
11
+ export type { TimerModule } from "./Timers";