@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,207 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * IDBTransaction - IndexedDB Transaction
4
+ *
5
+ * Groups database operations that must succeed or fail as a unit.
6
+ *
7
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/IDBTransaction
8
+ */
9
+
10
+ import { IDBObjectStore } from './IDBObjectStore';
11
+ import { DOMException } from './utils';
12
+
13
+ export type IDBTransactionMode = 'readonly' | 'readwrite' | 'versionchange';
14
+
15
+ export class IDBTransaction {
16
+ private _db: any;
17
+ private _mode: IDBTransactionMode;
18
+ private _storeNames: string[];
19
+ private _stores: Map<string, IDBObjectStore> = new Map();
20
+ private _committed = false;
21
+ private _aborted = false;
22
+ private _error: DOMException | null = null;
23
+ /** @internal */
24
+ _state: 'active' | 'inactive' | 'committing' | 'finished' = 'active';
25
+ /** @internal - Whether a SQLite BEGIN has been issued for this transaction */
26
+ private _sqliteBegan = false;
27
+ /** @internal - EventTarget listeners keyed by event type */
28
+ private _listeners: Record<string, Function[]> = {};
29
+
30
+ oncomplete: ((event: any) => void) | null = null;
31
+ onerror: ((event: any) => void) | null = null;
32
+ onabort: ((event: any) => void) | null = null;
33
+
34
+ constructor(db: any, storeNames: string[], mode: IDBTransactionMode) {
35
+ this._db = db;
36
+ this._storeNames = storeNames;
37
+ this._mode = mode;
38
+
39
+ // Begin a SQLite transaction for readwrite transactions to enable rollback
40
+ if (mode === 'readwrite') {
41
+ this._beginSqlite();
42
+ }
43
+ }
44
+
45
+ get db(): any {
46
+ return this._db;
47
+ }
48
+
49
+ get mode(): IDBTransactionMode {
50
+ return this._mode;
51
+ }
52
+
53
+ get objectStoreNames(): string[] {
54
+ return [...this._storeNames].sort();
55
+ }
56
+
57
+ get error(): DOMException | null {
58
+ return this._error;
59
+ }
60
+
61
+ addEventListener(type: string, fn: Function): void {
62
+ if (!this._listeners[type]) this._listeners[type] = [];
63
+ this._listeners[type].push(fn);
64
+ }
65
+
66
+ removeEventListener(type: string, fn: Function): void {
67
+ const list = this._listeners[type];
68
+ if (list) this._listeners[type] = list.filter(f => f !== fn);
69
+ }
70
+
71
+ /** @internal */
72
+ private _fireListeners(type: string, event: any): void {
73
+ const list = this._listeners[type];
74
+ if (list) {
75
+ for (const fn of list) {
76
+ try { fn(event); } catch (_) { /* swallow */ }
77
+ }
78
+ }
79
+ }
80
+
81
+ /**
82
+ * Get an object store from this transaction.
83
+ */
84
+ objectStore(name: string): IDBObjectStore {
85
+ if (!this._storeNames.includes(name)) {
86
+ throw new DOMException(
87
+ `Object store "${name}" is not in this transaction's scope`,
88
+ 'NotFoundError',
89
+ );
90
+ }
91
+ if (this._aborted) {
92
+ throw new DOMException(
93
+ 'Transaction has been aborted',
94
+ 'InvalidStateError',
95
+ );
96
+ }
97
+
98
+ let store = this._stores.get(name);
99
+ if (!store) {
100
+ store = this._db._getObjectStore(name, this);
101
+ if (!store) {
102
+ throw new DOMException(
103
+ `Object store "${name}" does not exist`,
104
+ 'NotFoundError',
105
+ );
106
+ }
107
+ this._stores.set(name, store);
108
+ }
109
+ return store;
110
+ }
111
+
112
+ /**
113
+ * Commit the transaction.
114
+ */
115
+ commit(): void {
116
+ if (this._committed || this._aborted) return;
117
+ this._committed = true;
118
+ this._state = 'finished';
119
+ // Commit SQLite transaction if one was started
120
+ this._commitSqlite();
121
+ // Fire oncomplete asynchronously
122
+ const event = { type: 'complete', target: this };
123
+ queueMicrotask(() => {
124
+ if (this.oncomplete) {
125
+ this.oncomplete(event);
126
+ }
127
+ this._fireListeners('complete', event);
128
+ });
129
+ }
130
+
131
+ /**
132
+ * Abort the transaction.
133
+ */
134
+ abort(): void {
135
+ if (this._committed || this._aborted) return;
136
+ this._aborted = true;
137
+ this._state = 'finished';
138
+ this._error = new DOMException('Transaction was aborted', 'AbortError');
139
+ // Rollback SQLite transaction if one was started
140
+ this._rollbackSqlite();
141
+ const event = { type: 'abort', target: this };
142
+ queueMicrotask(() => {
143
+ if (this.onabort) {
144
+ this.onabort(event);
145
+ }
146
+ this._fireListeners('abort', event);
147
+ });
148
+ }
149
+
150
+ /** @internal - Handle an error from a request */
151
+ _handleError(error: any): void {
152
+ this._error = error instanceof DOMException
153
+ ? error
154
+ : new DOMException(error?.message ?? 'Unknown error', 'UnknownError');
155
+ const event = { type: 'error', target: this };
156
+ queueMicrotask(() => {
157
+ if (this.onerror) {
158
+ this.onerror(event);
159
+ }
160
+ this._fireListeners('error', event);
161
+ });
162
+ }
163
+
164
+ /** @internal - Auto-commit if no abort was called (called after all microtasks drain) */
165
+ _autoCommit(): void {
166
+ if (!this._committed && !this._aborted) {
167
+ this.commit();
168
+ }
169
+ }
170
+
171
+ // ================================================================
172
+ // SQLite transaction wrapping
173
+ // ================================================================
174
+
175
+ /** @internal - Begin a SQLite transaction */
176
+ private _beginSqlite(): void {
177
+ if (this._sqliteBegan) return;
178
+ try {
179
+ this._db._exec('BEGIN TRANSACTION');
180
+ this._sqliteBegan = true;
181
+ } catch (_) {
182
+ // Some environments may not support explicit transactions; that's OK
183
+ }
184
+ }
185
+
186
+ /** @internal - Commit the SQLite transaction */
187
+ private _commitSqlite(): void {
188
+ if (!this._sqliteBegan) return;
189
+ try {
190
+ this._db._exec('COMMIT');
191
+ } catch (_) {
192
+ // Ignore
193
+ }
194
+ this._sqliteBegan = false;
195
+ }
196
+
197
+ /** @internal - Rollback the SQLite transaction */
198
+ private _rollbackSqlite(): void {
199
+ if (!this._sqliteBegan) return;
200
+ try {
201
+ this._db._exec('ROLLBACK');
202
+ } catch (_) {
203
+ // Ignore
204
+ }
205
+ this._sqliteBegan = false;
206
+ }
207
+ }
@@ -0,0 +1,34 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * IndexedDB implementation for the Ibex runtime
4
+ *
5
+ * Provides a server-side IndexedDB API backed by exact:sqlite.
6
+ * Many npm packages use IndexedDB for caching/storage, and this
7
+ * implementation enables those packages to work in the Ibex runtime.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const request = indexedDB.open('myDatabase', 1);
12
+ * request.onupgradeneeded = (event) => {
13
+ * const db = event.target.result;
14
+ * db.createObjectStore('users', { keyPath: 'id', autoIncrement: true });
15
+ * };
16
+ * request.onsuccess = (event) => {
17
+ * const db = event.target.result;
18
+ * const txn = db.transaction('users', 'readwrite');
19
+ * const store = txn.objectStore('users');
20
+ * store.put({ name: 'Alice' });
21
+ * };
22
+ * ```
23
+ *
24
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API
25
+ */
26
+
27
+ export { IDBFactory, type SQLiteDatabaseProvider } from './IDBFactory';
28
+ export { IDBDatabase } from './IDBDatabase';
29
+ export { IDBTransaction, type IDBTransactionMode } from './IDBTransaction';
30
+ export { IDBObjectStore, type IDBObjectStoreParameters } from './IDBObjectStore';
31
+ export { IDBIndex, type IDBIndexParameters } from './IDBIndex';
32
+ export { IDBRequest, IDBOpenDBRequest } from './IDBRequest';
33
+ export { IDBKeyRange, compareKeys } from './IDBKeyRange';
34
+ export { IDBCursor, IDBCursorWithValue, type IDBCursorDirection } from './IDBCursor';
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Shared utilities for the IndexedDB implementation.
3
+ *
4
+ * Consolidates DOMException and helper functions to avoid
5
+ * duplicate definitions across modules and enable cross-module
6
+ * instanceof checks.
7
+ */
8
+
9
+ /**
10
+ * DOMException polyfill.
11
+ *
12
+ * Uses globalThis.DOMException when available (e.g. if the runtime bootstrap
13
+ * has already installed one) and falls back to a simple Error subclass.
14
+ */
15
+ export const DOMException: {
16
+ new (message: string, name: string): Error & { code: number; name: string };
17
+ } = (() => {
18
+ if (typeof globalThis !== 'undefined' && (globalThis as any).DOMException) {
19
+ return (globalThis as any).DOMException;
20
+ }
21
+ // Fallback polyfill
22
+ class DOMExceptionPolyfill extends Error {
23
+ readonly code: number;
24
+ constructor(message: string, name: string) {
25
+ super(message);
26
+ this.name = name;
27
+ this.code = 0;
28
+ }
29
+ }
30
+ return DOMExceptionPolyfill as any;
31
+ })();
32
+
33
+ /**
34
+ * Create a DOMStringList-like object from a string array.
35
+ *
36
+ * The returned value extends Array<string> with `.contains()` and `.item()`
37
+ * methods, matching the DOMStringList interface that IndexedDB consumers
38
+ * expect.
39
+ */
40
+ export function makeDOMStringList(names: string[]): string[] & { contains(name: string): boolean; item(index: number): string | null } {
41
+ const list = [...names] as string[] & { contains(name: string): boolean; item(index: number): string | null };
42
+ list.contains = (name: string) => list.includes(name);
43
+ list.item = (index: number) => list[index] ?? null;
44
+ return list;
45
+ }
46
+
47
+ /**
48
+ * Sanitize a name for use as a SQL table/column identifier.
49
+ */
50
+ export function sanitizeName(name: string): string {
51
+ return name.replace(/[^a-zA-Z0-9_]/g, '_');
52
+ }
@@ -0,0 +1 @@
1
+ export { inspect, type InspectOptions } from './inspect';