@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,291 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage implementation for Ibex runtime (localStorage/sessionStorage)
|
|
3
|
+
*
|
|
4
|
+
* Implements the Web Storage API.
|
|
5
|
+
* @see https://html.spec.whatwg.org/multipage/webstorage.html
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { DOMException, createQuotaExceededError } from '../events/DOMException';
|
|
9
|
+
import { getNativeModule } from '../native/NativeModules';
|
|
10
|
+
import { requireCapability, Capabilities, type Capability } from '../security/Capabilities';
|
|
11
|
+
|
|
12
|
+
// Default quota: 10MB
|
|
13
|
+
const DEFAULT_QUOTA = 10 * 1024 * 1024;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Storage provides synchronous key-value storage.
|
|
17
|
+
*
|
|
18
|
+
* Note: In Exact, localStorage is per-app, not per-origin (since there's no
|
|
19
|
+
* concept of origins in a native app context).
|
|
20
|
+
*/
|
|
21
|
+
export class Storage {
|
|
22
|
+
#data: Map<string, string>;
|
|
23
|
+
#quota: number;
|
|
24
|
+
#persistent: boolean;
|
|
25
|
+
#nativeStorage: any;
|
|
26
|
+
#capability: Capability;
|
|
27
|
+
|
|
28
|
+
constructor(persistent: boolean = true, quota: number = DEFAULT_QUOTA, capability?: Capability) {
|
|
29
|
+
this.#data = new Map();
|
|
30
|
+
this.#quota = quota;
|
|
31
|
+
this.#persistent = persistent;
|
|
32
|
+
this.#capability = capability ?? (persistent ? Capabilities.STORAGE_LOCAL : Capabilities.STORAGE_SESSION);
|
|
33
|
+
this.#nativeStorage = getNativeModule('storage');
|
|
34
|
+
|
|
35
|
+
// If native storage is available and this is persistent, load existing data
|
|
36
|
+
if (this.#nativeStorage && persistent) {
|
|
37
|
+
this.#loadFromNative();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Check capability before any storage operation.
|
|
43
|
+
* @throws NotAllowedError if capability is not granted
|
|
44
|
+
*/
|
|
45
|
+
#checkCapability(): void {
|
|
46
|
+
requireCapability(this.#capability);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Returns the number of key/value pairs.
|
|
51
|
+
*/
|
|
52
|
+
get length(): number {
|
|
53
|
+
this.#checkCapability();
|
|
54
|
+
if (this.#nativeStorage && this.#persistent) {
|
|
55
|
+
return this.#nativeStorage.length();
|
|
56
|
+
}
|
|
57
|
+
return this.#data.size;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Returns the name of the nth key, or null if n >= length.
|
|
62
|
+
*/
|
|
63
|
+
key(index: number): string | null {
|
|
64
|
+
this.#checkCapability();
|
|
65
|
+
if (this.#nativeStorage && this.#persistent) {
|
|
66
|
+
return this.#nativeStorage.key(index);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (index < 0 || index >= this.#data.size) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
const keys = [...this.#data.keys()];
|
|
73
|
+
return keys[index] ?? null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Returns the current value associated with the given key.
|
|
78
|
+
*/
|
|
79
|
+
getItem(key: string): string | null {
|
|
80
|
+
this.#checkCapability();
|
|
81
|
+
if (this.#nativeStorage && this.#persistent) {
|
|
82
|
+
return this.#nativeStorage.getItem(String(key));
|
|
83
|
+
}
|
|
84
|
+
return this.#data.get(String(key)) ?? null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Sets the value of the pair identified by key.
|
|
89
|
+
* Throws QuotaExceededError if the quota is exceeded.
|
|
90
|
+
*/
|
|
91
|
+
setItem(key: string, value: string): void {
|
|
92
|
+
this.#checkCapability();
|
|
93
|
+
const keyStr = String(key);
|
|
94
|
+
const valueStr = String(value);
|
|
95
|
+
|
|
96
|
+
if (this.#nativeStorage && this.#persistent) {
|
|
97
|
+
try {
|
|
98
|
+
this.#nativeStorage.setItem(keyStr, valueStr);
|
|
99
|
+
} catch (e: any) {
|
|
100
|
+
// Native module should throw QuotaExceededError
|
|
101
|
+
if (e.name === 'QuotaExceededError') {
|
|
102
|
+
throw e;
|
|
103
|
+
}
|
|
104
|
+
throw createQuotaExceededError('Storage quota exceeded');
|
|
105
|
+
}
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Check quota for in-memory storage
|
|
110
|
+
const currentSize = this.#calculateSize();
|
|
111
|
+
const oldValue = this.#data.get(keyStr);
|
|
112
|
+
const oldSize = oldValue ? keyStr.length + oldValue.length : 0;
|
|
113
|
+
const newSize = keyStr.length + valueStr.length;
|
|
114
|
+
|
|
115
|
+
if (currentSize - oldSize + newSize > this.#quota) {
|
|
116
|
+
throw createQuotaExceededError('Storage quota exceeded');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
this.#data.set(keyStr, valueStr);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Removes the key/value pair with the given key.
|
|
124
|
+
*/
|
|
125
|
+
removeItem(key: string): void {
|
|
126
|
+
this.#checkCapability();
|
|
127
|
+
const keyStr = String(key);
|
|
128
|
+
|
|
129
|
+
if (this.#nativeStorage && this.#persistent) {
|
|
130
|
+
this.#nativeStorage.removeItem(keyStr);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
this.#data.delete(keyStr);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Removes all key/value pairs.
|
|
139
|
+
*/
|
|
140
|
+
clear(): void {
|
|
141
|
+
this.#checkCapability();
|
|
142
|
+
if (this.#nativeStorage && this.#persistent) {
|
|
143
|
+
this.#nativeStorage.clear();
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
this.#data.clear();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Calculate total size of stored data.
|
|
152
|
+
*/
|
|
153
|
+
#calculateSize(): number {
|
|
154
|
+
let size = 0;
|
|
155
|
+
for (const [key, value] of this.#data) {
|
|
156
|
+
size += key.length + value.length;
|
|
157
|
+
}
|
|
158
|
+
return size;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Load data from native storage.
|
|
163
|
+
*/
|
|
164
|
+
#loadFromNative(): void {
|
|
165
|
+
if (!this.#nativeStorage) return;
|
|
166
|
+
|
|
167
|
+
const length = this.#nativeStorage.length();
|
|
168
|
+
for (let i = 0; i < length; i++) {
|
|
169
|
+
const key = this.#nativeStorage.key(i);
|
|
170
|
+
if (key !== null) {
|
|
171
|
+
const value = this.#nativeStorage.getItem(key);
|
|
172
|
+
if (value !== null) {
|
|
173
|
+
this.#data.set(key, value);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
get [Symbol.toStringTag](): string {
|
|
180
|
+
return 'Storage';
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Create singleton instances
|
|
185
|
+
let _localStorage: Storage | null = null;
|
|
186
|
+
let _sessionStorage: Storage | null = null;
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Get the localStorage instance.
|
|
190
|
+
* localStorage persists across sessions.
|
|
191
|
+
*/
|
|
192
|
+
export function getLocalStorage(): Storage {
|
|
193
|
+
if (!_localStorage) {
|
|
194
|
+
_localStorage = new Storage(true, DEFAULT_QUOTA, Capabilities.STORAGE_LOCAL);
|
|
195
|
+
}
|
|
196
|
+
return _localStorage;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Get the sessionStorage instance.
|
|
201
|
+
* sessionStorage is cleared when the app is closed.
|
|
202
|
+
*/
|
|
203
|
+
export function getSessionStorage(): Storage {
|
|
204
|
+
if (!_sessionStorage) {
|
|
205
|
+
_sessionStorage = new Storage(false, DEFAULT_QUOTA, Capabilities.STORAGE_SESSION);
|
|
206
|
+
}
|
|
207
|
+
return _sessionStorage;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function createLazyStorageProxy(factory: () => Storage): Storage {
|
|
211
|
+
let storage: Storage | null = null;
|
|
212
|
+
|
|
213
|
+
const getStorage = (): Storage => {
|
|
214
|
+
if (!storage) {
|
|
215
|
+
storage = factory();
|
|
216
|
+
}
|
|
217
|
+
return storage;
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
return new Proxy({} as Storage, {
|
|
221
|
+
get(target, prop, receiver) {
|
|
222
|
+
target = getStorage();
|
|
223
|
+
if (typeof prop === 'string') {
|
|
224
|
+
// Check if it's a Storage method/property first
|
|
225
|
+
if (prop in target || prop === 'length') {
|
|
226
|
+
const value = Reflect.get(target, prop, target);
|
|
227
|
+
return typeof value === 'function' ? value.bind(target) : value;
|
|
228
|
+
}
|
|
229
|
+
// Otherwise treat as getItem
|
|
230
|
+
return target.getItem(prop);
|
|
231
|
+
}
|
|
232
|
+
const value = Reflect.get(target, prop, target);
|
|
233
|
+
return typeof value === 'function' ? value.bind(target) : value;
|
|
234
|
+
},
|
|
235
|
+
set(target, prop, value) {
|
|
236
|
+
target = getStorage();
|
|
237
|
+
if (typeof prop === 'string') {
|
|
238
|
+
target.setItem(prop, String(value));
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
return false;
|
|
242
|
+
},
|
|
243
|
+
deleteProperty(target, prop) {
|
|
244
|
+
target = getStorage();
|
|
245
|
+
if (typeof prop === 'string') {
|
|
246
|
+
target.removeItem(prop);
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
249
|
+
return false;
|
|
250
|
+
},
|
|
251
|
+
has(target, prop) {
|
|
252
|
+
target = getStorage();
|
|
253
|
+
if (typeof prop === 'string') {
|
|
254
|
+
return target.getItem(prop) !== null;
|
|
255
|
+
}
|
|
256
|
+
return prop in target;
|
|
257
|
+
},
|
|
258
|
+
ownKeys(target) {
|
|
259
|
+
target = getStorage();
|
|
260
|
+
const keys: string[] = [];
|
|
261
|
+
for (let i = 0; i < target.length; i++) {
|
|
262
|
+
const key = target.key(i);
|
|
263
|
+
if (key !== null) {
|
|
264
|
+
keys.push(key);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return keys;
|
|
268
|
+
},
|
|
269
|
+
getOwnPropertyDescriptor(target, prop) {
|
|
270
|
+
target = getStorage();
|
|
271
|
+
if (typeof prop === 'string') {
|
|
272
|
+
const value = target.getItem(prop);
|
|
273
|
+
if (value !== null) {
|
|
274
|
+
return {
|
|
275
|
+
value,
|
|
276
|
+
writable: true,
|
|
277
|
+
enumerable: true,
|
|
278
|
+
configurable: true,
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return undefined;
|
|
283
|
+
},
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// Export proxy-wrapped singletons
|
|
288
|
+
export const localStorage = createLazyStorageProxy(getLocalStorage);
|
|
289
|
+
export const sessionStorage = createLazyStorageProxy(getSessionStorage);
|
|
290
|
+
|
|
291
|
+
export default Storage;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StorageManager - navigator.storage API
|
|
3
|
+
*
|
|
4
|
+
* Provides methods for estimating storage usage/quota and
|
|
5
|
+
* requesting persistent storage.
|
|
6
|
+
* @see https://storage.spec.whatwg.org/#storagemanager
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { getNativeModule } from '../native/NativeModules';
|
|
10
|
+
import { requireCapability, Capabilities } from '../security/Capabilities';
|
|
11
|
+
|
|
12
|
+
// Default quota: 100MB (typical for native apps)
|
|
13
|
+
const DEFAULT_QUOTA = 100 * 1024 * 1024;
|
|
14
|
+
|
|
15
|
+
export interface StorageEstimate {
|
|
16
|
+
usage: number;
|
|
17
|
+
quota: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export class StorageManager {
|
|
21
|
+
_nativeStorage: any;
|
|
22
|
+
|
|
23
|
+
constructor() {
|
|
24
|
+
this._nativeStorage = getNativeModule('storage');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Returns an estimate of the total storage used and the available quota.
|
|
29
|
+
*
|
|
30
|
+
* @returns A promise that resolves to a StorageEstimate with usage and quota.
|
|
31
|
+
*/
|
|
32
|
+
async estimate(): Promise<StorageEstimate> {
|
|
33
|
+
if (this._nativeStorage?.estimate) {
|
|
34
|
+
return this._nativeStorage.estimate();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Fallback: return a default estimate
|
|
38
|
+
return {
|
|
39
|
+
usage: 0,
|
|
40
|
+
quota: DEFAULT_QUOTA,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Requests permission to use persistent storage.
|
|
46
|
+
*
|
|
47
|
+
* In the Ibex runtime, persistent storage is granted based on the
|
|
48
|
+
* STORAGE_PERSIST capability.
|
|
49
|
+
*
|
|
50
|
+
* @returns A promise that resolves to true if persistent storage is granted.
|
|
51
|
+
*/
|
|
52
|
+
async persist(): Promise<boolean> {
|
|
53
|
+
try {
|
|
54
|
+
requireCapability(Capabilities.STORAGE_PERSIST);
|
|
55
|
+
} catch {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (this._nativeStorage?.persist) {
|
|
60
|
+
return this._nativeStorage.persist();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Default: grant persistence if capability is available
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Checks whether persistent storage has been granted.
|
|
69
|
+
*
|
|
70
|
+
* @returns A promise that resolves to true if storage is persistent.
|
|
71
|
+
*/
|
|
72
|
+
async persisted(): Promise<boolean> {
|
|
73
|
+
if (this._nativeStorage?.persisted) {
|
|
74
|
+
return this._nativeStorage.persisted();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Default: check if the capability is available
|
|
78
|
+
try {
|
|
79
|
+
requireCapability(Capabilities.STORAGE_PERSIST);
|
|
80
|
+
return true;
|
|
81
|
+
} catch {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
get [Symbol.toStringTag](): string {
|
|
87
|
+
return 'StorageManager';
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export default StorageManager;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stub for ReadableStream compatibility installs.
|
|
3
|
+
* This file exists to satisfy imports when building the runtime bundle.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
declare const globalThis: any;
|
|
7
|
+
|
|
8
|
+
export function installExactReadableStreamCompat(): void {
|
|
9
|
+
const g = globalThis;
|
|
10
|
+
|
|
11
|
+
// Fix CountQueuingStrategy.name and ByteLengthQueuingStrategy.name.
|
|
12
|
+
// When Babel transpiles class declarations and terser minifies them, the
|
|
13
|
+
// function .name property ends up as a single-char identifier instead of
|
|
14
|
+
// the class name. Fix this eagerly after the lazy globals are installed.
|
|
15
|
+
//
|
|
16
|
+
// We access the global to trigger the lazy getter (if it's still lazy),
|
|
17
|
+
// then redefine the name property on the constructor function.
|
|
18
|
+
const nameFixes: [string, string][] = [
|
|
19
|
+
['CountQueuingStrategy', 'CountQueuingStrategy'],
|
|
20
|
+
['ByteLengthQueuingStrategy', 'ByteLengthQueuingStrategy'],
|
|
21
|
+
['ReadableStream', 'ReadableStream'],
|
|
22
|
+
['WritableStream', 'WritableStream'],
|
|
23
|
+
['TransformStream', 'TransformStream'],
|
|
24
|
+
['ReadableStreamDefaultReader', 'ReadableStreamDefaultReader'],
|
|
25
|
+
['ReadableStreamBYOBReader', 'ReadableStreamBYOBReader'],
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
for (const [globalName, expectedName] of nameFixes) {
|
|
29
|
+
try {
|
|
30
|
+
const ctor = g[globalName];
|
|
31
|
+
if (typeof ctor === 'function' && ctor.name !== expectedName) {
|
|
32
|
+
try {
|
|
33
|
+
Object.defineProperty(ctor, 'name', {
|
|
34
|
+
value: expectedName,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: false,
|
|
37
|
+
enumerable: false,
|
|
38
|
+
});
|
|
39
|
+
} catch (_) {
|
|
40
|
+
// Ignore if name is not configurable
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
} catch (_) {
|
|
44
|
+
// Ignore errors
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|