@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,27 @@
1
+ /**
2
+ * `exact:http` runtime surface for JS adapters and examples.
3
+ *
4
+ * The canonical runtime implementation is provided from Rust module loader via
5
+ * `exact:http`, and this file exposes the same API contract for
6
+ * TypeScript-aware consumers.
7
+ */
8
+
9
+ import { serve as runtimeServe } from './index.js';
10
+
11
+ export type ServeHandle = {
12
+ close: (opts?: { force?: boolean }) => Promise<void>;
13
+ ref: () => void;
14
+ unref: () => void;
15
+ address: () => { port: number; family: string; address: string } | string | null;
16
+ };
17
+
18
+ export type ServeOptions = {
19
+ fetch: (request: Request) => Promise<Response> | Response;
20
+ port?: number;
21
+ hostname?: string;
22
+ };
23
+
24
+ // Bun resolves this workspace package through the TypeScript facade during
25
+ // development, so the facade must forward the live implementation instead of
26
+ // only carrying types.
27
+ export const serve: (options: ServeOptions) => Promise<ServeHandle> = runtimeServe;
@@ -0,0 +1,14 @@
1
+ // GENERATED FILE - DO NOT EDIT.
2
+ // Source authority: runtime-identity.json (LLP 0012)
3
+ // Generator: bun packages/ibex-devtools/src/scripts/generate-runtime-identity.ts
4
+
5
+ export const RUNTIME_NAME = "ibex";
6
+ export const PROCESS_TITLE = "ibex";
7
+ export const USER_AGENT = "Ibex/0.1.0 (Hermes)";
8
+ export const RELEASE_NAME = "node";
9
+ export const RUNTIME_VERSIONS: ReadonlyArray<readonly [string, string]> = [
10
+ ["ibex", "0.1.0"],
11
+ ["node", "24.13.1"],
12
+ ["hermes", "1.0.0"],
13
+ ] as const;
14
+ export const BUN_COMPAT_VERSION = "1.2.0";
package/src/index.ts ADDED
@@ -0,0 +1,283 @@
1
+ // @ts-nocheck
2
+ // @system @ref LLP 0003#the-bootstrap-sequence — Web-standard runtime globals on Ibex.
3
+ /**
4
+ * Ibex Runtime
5
+ *
6
+ * Web-standard APIs for the Ibex runtime environment.
7
+ * These APIs are implemented to match browser standards while
8
+ * running on top of native platform code.
9
+ */
10
+
11
+ // =============================================================================
12
+ // Bootstrap - Install all globals
13
+ // =============================================================================
14
+
15
+ export { installGlobals, areGlobalsInstalled, getRuntimeVersion, runtimeInfo } from "./bootstrap";
16
+
17
+ // =============================================================================
18
+ // Events & Errors (Phase 0)
19
+ // =============================================================================
20
+
21
+ export {
22
+ Event,
23
+ CustomEvent,
24
+ EventTarget,
25
+ DOMException,
26
+ KeyboardEvent,
27
+ FocusEvent,
28
+ } from "./events";
29
+ export type {
30
+ EventInit,
31
+ CustomEventInit,
32
+ EventListener,
33
+ EventListenerObject,
34
+ EventListenerOrEventListenerObject,
35
+ AddEventListenerOptions,
36
+ EventListenerOptions,
37
+ KeyboardEventInit,
38
+ FocusEventInit,
39
+ } from "./events";
40
+
41
+ // =============================================================================
42
+ // Console (Phase 0)
43
+ // =============================================================================
44
+
45
+ export { Console, console, setConsoleOutput } from "./console";
46
+ export type { LogLevel, ConsoleOutput } from "./console";
47
+
48
+ // =============================================================================
49
+ // Accessibility / Preferences
50
+ // =============================================================================
51
+
52
+ export {
53
+ announceForAccessibility,
54
+ focusElementForAccessibility,
55
+ getExactAccessibilitySnapshot,
56
+ installExactAccessibilityGlobal,
57
+ refreshExactAccessibility,
58
+ subscribeExactAccessibilityChanges,
59
+ type AccessibilityInfoEvent,
60
+ type AccessibilityInfoKey,
61
+ type ExactAccessibilitySnapshot,
62
+ } from "./accessibility";
63
+
64
+ // =============================================================================
65
+ // Timers (Phase 0)
66
+ // =============================================================================
67
+
68
+ export {
69
+ setTimeout,
70
+ clearTimeout,
71
+ setInterval,
72
+ clearInterval,
73
+ queueMicrotask,
74
+ setImmediate,
75
+ clearImmediate,
76
+ setNativeTimerModule,
77
+ } from "./timers";
78
+ export type { TimerModule } from "./timers";
79
+
80
+ // =============================================================================
81
+ // Encoding (Phase 0)
82
+ // =============================================================================
83
+
84
+ export { TextEncoder, TextDecoder } from "./encoding";
85
+ export type { TextEncoderEncodeIntoResult, TextDecoderOptions, TextDecodeOptions } from "./encoding";
86
+
87
+ // =============================================================================
88
+ // Performance (Phase 0)
89
+ // =============================================================================
90
+
91
+ export {
92
+ Performance,
93
+ PerformanceEntry,
94
+ PerformanceMark,
95
+ PerformanceMeasure,
96
+ performance,
97
+ setNativePerformanceModule,
98
+ } from "./performance";
99
+ export type { PerformanceModule, PerformanceMarkOptions, PerformanceMeasureOptions } from "./performance";
100
+
101
+ // =============================================================================
102
+ // Base64 (Phase 0)
103
+ // =============================================================================
104
+
105
+ export { atob, btoa } from "./base64";
106
+
107
+ // =============================================================================
108
+ // Inspect (Object Pretty-Printing)
109
+ // =============================================================================
110
+
111
+ export { inspect, type InspectOptions } from "./inspect";
112
+
113
+ // =============================================================================
114
+ // URL (Phase 1)
115
+ // =============================================================================
116
+
117
+ export { URL, URLSearchParams, URLPattern } from "./url";
118
+ export type { URLPatternInit, URLPatternInput, URLPatternResult, URLPatternComponentResult } from "./url";
119
+
120
+ // =============================================================================
121
+ // Abort (Phase 1)
122
+ // =============================================================================
123
+
124
+ export { AbortController, AbortSignal } from "./abort";
125
+
126
+ // =============================================================================
127
+ // Crypto (Phase 3)
128
+ // =============================================================================
129
+
130
+ export { Crypto, SubtleCrypto, crypto } from "./crypto";
131
+
132
+ // =============================================================================
133
+ // Streams (Web Streams API)
134
+ // =============================================================================
135
+
136
+ export {
137
+ ReadableStream,
138
+ ReadableStreamDefaultReader,
139
+ ReadableStreamDefaultController,
140
+ ReadableByteStreamController,
141
+ WritableStream,
142
+ WritableStreamDefaultWriter,
143
+ WritableStreamDefaultController,
144
+ TransformStream,
145
+ TransformStreamDefaultController,
146
+ ByteLengthQueuingStrategy,
147
+ CountQueuingStrategy,
148
+ } from "./streams";
149
+
150
+ export type {
151
+ UnderlyingSource,
152
+ UnderlyingByteSource,
153
+ UnderlyingSink,
154
+ Transformer,
155
+ QueuingStrategy,
156
+ StreamPipeOptions,
157
+ ReadableStreamReadResult,
158
+ ReadableStreamReadValueResult,
159
+ ReadableStreamReadDoneResult,
160
+ } from "./streams";
161
+
162
+ // =============================================================================
163
+ // Web Locks API
164
+ // =============================================================================
165
+
166
+ export { LockManager } from "./locks";
167
+ export type { Lock, LockMode, LockOptions, LockGrantedCallback, LockManagerSnapshot } from "./locks";
168
+
169
+ // =============================================================================
170
+ // HTTP Server (exact:http)
171
+ // =============================================================================
172
+
173
+ export type {
174
+ ServeHandle,
175
+ ServeOptions,
176
+ } from "./http-server/index.js";
177
+
178
+ // =============================================================================
179
+ // EventSource (Server-Sent Events)
180
+ // =============================================================================
181
+
182
+ export { EventSource } from "./eventsource";
183
+ export type { EventSourceInit } from "./eventsource";
184
+
185
+ // =============================================================================
186
+ // Native Module Interfaces
187
+ // =============================================================================
188
+
189
+ export {
190
+ setNativeCryptoModule,
191
+ setNativeEncodingModule,
192
+ setNativeConsoleModule,
193
+ setNativeFetchModule as setNativeFetchBridge,
194
+ setNativeWebSocketModule,
195
+ setNativeStorageModule,
196
+ setNativeFileSystemModule,
197
+ getNativeCryptoModule,
198
+ getNativeEncodingModule,
199
+ getNativeConsoleModule,
200
+ getNativeFetchModule,
201
+ getNativeWebSocketModule,
202
+ getNativeStorageModule,
203
+ getNativeFileSystemModule,
204
+ hasRequiredNativeModules,
205
+ getMissingNativeModules,
206
+ } from "./native";
207
+
208
+ export type {
209
+ NativeTimerModule,
210
+ NativePerformanceModule,
211
+ NativeCryptoModule,
212
+ NativeEncodingModule,
213
+ NativeConsoleModule,
214
+ NativeWebSocketModule,
215
+ NativeStorageModule,
216
+ NativeFileSystemModule,
217
+ } from "./native";
218
+
219
+ // =============================================================================
220
+ // Fetch API (Phase 2 - existing implementation)
221
+ // =============================================================================
222
+
223
+ export {
224
+ // Main fetch function
225
+ fetch,
226
+ fetchPolyfill,
227
+ setNativeFetchModule,
228
+ installFetchGlobals,
229
+
230
+ // Classes
231
+ Headers,
232
+ Request,
233
+ Response,
234
+
235
+ // Errors
236
+ FetchError,
237
+ AbortError,
238
+ NetworkError,
239
+ URLError,
240
+ BodyConsumedError,
241
+
242
+ // Body utilities
243
+ bodyToUint8Array,
244
+ readableStreamToUint8Array,
245
+ concatUint8Arrays,
246
+ parseJson,
247
+ parseText,
248
+ isBlob,
249
+ isFormData,
250
+ isArrayBuffer,
251
+ isArrayBufferView,
252
+ isReadableStream,
253
+ } from './fetch/index.js';
254
+
255
+ export type {
256
+ // Request types
257
+ RequestInput,
258
+ RequestInit,
259
+ RequestMethod,
260
+ RequestMode,
261
+ RequestCredentials,
262
+ RequestCache,
263
+ RequestRedirect,
264
+ ReferrerPolicy,
265
+ RequestDuplex,
266
+
267
+ // Response types
268
+ ResponseInit,
269
+ ResponseType,
270
+
271
+ // Headers types
272
+ HeadersInit,
273
+
274
+ // Body types
275
+ BodyInit,
276
+ BufferSource,
277
+
278
+ // Native bridge types
279
+ NativeRequestInit,
280
+ NativeResponse,
281
+ NativeStreamingResponse,
282
+ NativeFetchModule,
283
+ } from './fetch/index.js';
@@ -0,0 +1,188 @@
1
+ /**
2
+ * IDBCursor - IndexedDB Cursor
3
+ *
4
+ * Iterates over records in an object store or index.
5
+ *
6
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/IDBCursor
7
+ */
8
+
9
+ import { IDBRequest } from './IDBRequest';
10
+ import { compareKeys } from './IDBKeyRange';
11
+
12
+ export type IDBCursorDirection = 'next' | 'nextunique' | 'prev' | 'prevunique';
13
+
14
+ export class IDBCursor {
15
+ private _source: any;
16
+ private _direction: IDBCursorDirection;
17
+ private _records: Array<{ key: any; primaryKey: any; value: any }>;
18
+ private _position: number;
19
+ private _request: IDBRequest;
20
+ private _gotValue: boolean = false;
21
+
22
+ constructor(
23
+ source: any,
24
+ direction: IDBCursorDirection,
25
+ records: Array<{ key: any; primaryKey: any; value: any }>,
26
+ request: IDBRequest,
27
+ ) {
28
+ this._source = source;
29
+ this._direction = direction;
30
+ this._request = request;
31
+
32
+ // Sort records based on direction
33
+ const sorted = [...records];
34
+ if (direction === 'prev' || direction === 'prevunique') {
35
+ sorted.sort((a, b) => compareKeys(b.key, a.key));
36
+ } else {
37
+ sorted.sort((a, b) => compareKeys(a.key, b.key));
38
+ }
39
+
40
+ // For unique directions, deduplicate by key
41
+ if (direction === 'nextunique' || direction === 'prevunique') {
42
+ const seen = new Set<string>();
43
+ this._records = sorted.filter(r => {
44
+ const keyStr = JSON.stringify(r.key);
45
+ if (seen.has(keyStr)) return false;
46
+ seen.add(keyStr);
47
+ return true;
48
+ });
49
+ } else {
50
+ this._records = sorted;
51
+ }
52
+
53
+ this._position = 0;
54
+ this._gotValue = this._records.length > 0;
55
+ }
56
+
57
+ get source(): any {
58
+ return this._source;
59
+ }
60
+
61
+ get direction(): IDBCursorDirection {
62
+ return this._direction;
63
+ }
64
+
65
+ get key(): any {
66
+ if (!this._gotValue || this._position >= this._records.length) return undefined;
67
+ return this._records[this._position].key;
68
+ }
69
+
70
+ get primaryKey(): any {
71
+ if (!this._gotValue || this._position >= this._records.length) return undefined;
72
+ return this._records[this._position].primaryKey;
73
+ }
74
+
75
+ get request(): IDBRequest {
76
+ return this._request;
77
+ }
78
+
79
+ /**
80
+ * Advances the cursor to the next position.
81
+ */
82
+ continue(key?: any): void {
83
+ this._position++;
84
+ if (key !== undefined) {
85
+ // Skip to the first record with key >= given key (or <= for prev)
86
+ while (this._position < this._records.length) {
87
+ const cmp = compareKeys(this._records[this._position].key, key);
88
+ if (this._direction === 'prev' || this._direction === 'prevunique') {
89
+ if (cmp <= 0) break;
90
+ } else {
91
+ if (cmp >= 0) break;
92
+ }
93
+ this._position++;
94
+ }
95
+ }
96
+
97
+ if (this._position < this._records.length) {
98
+ this._gotValue = true;
99
+ this._request._resolve(this as any);
100
+ } else {
101
+ this._gotValue = false;
102
+ this._request._resolve(null as any);
103
+ }
104
+ }
105
+
106
+ /**
107
+ * Advances the cursor by a given number of positions.
108
+ */
109
+ advance(count: number): void {
110
+ if (count <= 0) {
111
+ throw new TypeError('count must be greater than 0');
112
+ }
113
+ this._position += count;
114
+ if (this._position < this._records.length) {
115
+ this._gotValue = true;
116
+ this._request._resolve(this as any);
117
+ } else {
118
+ this._gotValue = false;
119
+ this._request._resolve(null as any);
120
+ }
121
+ }
122
+
123
+ /**
124
+ * Updates the value at the current cursor position.
125
+ */
126
+ update(value: any): IDBRequest {
127
+ const request = new IDBRequest();
128
+ if (!this._gotValue || this._position >= this._records.length) {
129
+ request._reject(new Error('Cursor is not pointing to a record'));
130
+ return request;
131
+ }
132
+ const record = this._records[this._position];
133
+ // Update via the source's object store
134
+ try {
135
+ const store = this._source._objectStore || this._source;
136
+ store._putRecord(record.primaryKey, value);
137
+ record.value = value;
138
+ request._resolve(record.primaryKey);
139
+ } catch (e: any) {
140
+ request._reject(e);
141
+ }
142
+ return request;
143
+ }
144
+
145
+ /**
146
+ * Deletes the record at the current cursor position.
147
+ */
148
+ delete(): IDBRequest {
149
+ const request = new IDBRequest();
150
+ if (!this._gotValue || this._position >= this._records.length) {
151
+ request._reject(new Error('Cursor is not pointing to a record'));
152
+ return request;
153
+ }
154
+ const record = this._records[this._position];
155
+ try {
156
+ const store = this._source._objectStore || this._source;
157
+ store._deleteRecord(record.primaryKey);
158
+ request._resolve(undefined);
159
+ } catch (e: any) {
160
+ request._reject(e);
161
+ }
162
+ return request;
163
+ }
164
+ }
165
+
166
+ /**
167
+ * IDBCursorWithValue extends IDBCursor with a value property.
168
+ */
169
+ export class IDBCursorWithValue extends IDBCursor {
170
+ private _valueRecords: Array<{ key: any; primaryKey: any; value: any }>;
171
+
172
+ constructor(
173
+ source: any,
174
+ direction: IDBCursorDirection,
175
+ records: Array<{ key: any; primaryKey: any; value: any }>,
176
+ request: IDBRequest,
177
+ ) {
178
+ super(source, direction, records, request);
179
+ this._valueRecords = (this as any)._records;
180
+ }
181
+
182
+ get value(): any {
183
+ const pos = (this as any)._position;
184
+ const records = (this as any)._records;
185
+ if (pos >= records.length) return undefined;
186
+ return records[pos].value;
187
+ }
188
+ }