@hehanlin/open-agent-bridge 0.6.3 → 0.6.4
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/node_modules/@byted/frontier-web-sdk/README.md +11 -0
- package/node_modules/@byted/frontier-web-sdk/lib/fws.esm.js +2438 -0
- package/node_modules/@byted/frontier-web-sdk/lib/fws.js +2535 -0
- package/node_modules/@byted/frontier-web-sdk/lib/fws.umd.js +2699 -0
- package/node_modules/@byted/frontier-web-sdk/lib/fws.umd.min.js +1 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/db/index.d.ts +5 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/db/qos-idb.d.ts +22 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/db/qos-localstorage.d.ts +20 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/db/qos-ministorage.d.ts +20 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/fws.d.ts +225 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/idl/bppb2.d.ts +27 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/idl/protobuf.d.ts +8 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/manager/cursor-manager.d.ts +25 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/manager/endpoint-manager.d.ts +15 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/manager/qos-manager.d.ts +17 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/manager/tnc-manager.d.ts +0 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/process/message/ack-process.d.ts +3 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/process/message/cursor-helper.d.ts +3 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/process/message/cursor-process.d.ts +3 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/process/message/decode-process.d.ts +2 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/process/message/dispatch-message-process.d.ts +3 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/process/message/finish-message-process.d.ts +3 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/process/message/index.d.ts +7 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/process/message/qos-helper.d.ts +12 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/process/message/qos-process.d.ts +3 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/process/open/finish-open-process.d.ts +2 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/process/open/index.d.ts +3 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/process/open/open-process.d.ts +2 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/process/open/open-success-process.d.ts +2 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/process/process-trigger.d.ts +3 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/utils/arraybuffer-trans.d.ts +2 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/utils/buffer.d.ts +115 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/utils/check-payload-type.d.ts +1 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/utils/cursor-serialize.d.ts +14 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/utils/env-params-gen.d.ts +5 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/utils/env.d.ts +5 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/utils/event-emitter.d.ts +39 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/utils/event.d.ts +88 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/utils/get-socket-error.d.ts +1 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/utils/header-key.d.ts +2 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/utils/log-id.d.ts +6 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/utils/long.d.ts +25 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/utils/pkg-loss-counter.d.ts +8 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/utils/pool.d.ts +29 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/utils/utf8.d.ts +24 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/utils/websocket.d.ts +2 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/websocket/mini-websocket.d.ts +20 -0
- package/node_modules/@byted/frontier-web-sdk/package.json +52 -0
- package/node_modules/idb/CHANGELOG.md +87 -0
- package/node_modules/idb/LICENSE +6 -0
- package/node_modules/idb/README.md +497 -0
- package/node_modules/idb/build/async-iterators.cjs +57 -0
- package/node_modules/idb/build/async-iterators.d.ts +1 -0
- package/node_modules/idb/build/async-iterators.js +55 -0
- package/node_modules/idb/build/database-extras.d.ts +1 -0
- package/node_modules/idb/build/entry.d.ts +615 -0
- package/node_modules/idb/build/index.cjs +94 -0
- package/node_modules/idb/build/index.d.ts +2 -0
- package/node_modules/idb/build/index.js +88 -0
- package/node_modules/idb/build/umd-with-async-ittr.js +1 -0
- package/node_modules/idb/build/umd.js +1 -0
- package/node_modules/idb/build/util.d.ts +3 -0
- package/node_modules/idb/build/wrap-idb-value.cjs +191 -0
- package/node_modules/idb/build/wrap-idb-value.d.ts +34 -0
- package/node_modules/idb/build/wrap-idb-value.js +185 -0
- package/node_modules/idb/package.json +59 -0
- package/node_modules/idb/with-async-ittr.cjs +2 -0
- package/node_modules/idb/with-async-ittr.d.ts +1 -0
- package/node_modules/idb/with-async-ittr.js +2 -0
- package/package.json +4 -1
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var wrapIdbValue = require('./wrap-idb-value.cjs');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Open a database.
|
|
9
|
+
*
|
|
10
|
+
* @param name Name of the database.
|
|
11
|
+
* @param version Schema version.
|
|
12
|
+
* @param callbacks Additional callbacks.
|
|
13
|
+
*/
|
|
14
|
+
function openDB(name, version, { blocked, upgrade, blocking, terminated } = {}) {
|
|
15
|
+
const request = indexedDB.open(name, version);
|
|
16
|
+
const openPromise = wrapIdbValue.wrap(request);
|
|
17
|
+
if (upgrade) {
|
|
18
|
+
request.addEventListener('upgradeneeded', (event) => {
|
|
19
|
+
upgrade(wrapIdbValue.wrap(request.result), event.oldVersion, event.newVersion, wrapIdbValue.wrap(request.transaction));
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if (blocked)
|
|
23
|
+
request.addEventListener('blocked', () => blocked());
|
|
24
|
+
openPromise
|
|
25
|
+
.then((db) => {
|
|
26
|
+
if (terminated)
|
|
27
|
+
db.addEventListener('close', () => terminated());
|
|
28
|
+
if (blocking)
|
|
29
|
+
db.addEventListener('versionchange', () => blocking());
|
|
30
|
+
})
|
|
31
|
+
.catch(() => { });
|
|
32
|
+
return openPromise;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Delete a database.
|
|
36
|
+
*
|
|
37
|
+
* @param name Name of the database.
|
|
38
|
+
*/
|
|
39
|
+
function deleteDB(name, { blocked } = {}) {
|
|
40
|
+
const request = indexedDB.deleteDatabase(name);
|
|
41
|
+
if (blocked)
|
|
42
|
+
request.addEventListener('blocked', () => blocked());
|
|
43
|
+
return wrapIdbValue.wrap(request).then(() => undefined);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const readMethods = ['get', 'getKey', 'getAll', 'getAllKeys', 'count'];
|
|
47
|
+
const writeMethods = ['put', 'add', 'delete', 'clear'];
|
|
48
|
+
const cachedMethods = new Map();
|
|
49
|
+
function getMethod(target, prop) {
|
|
50
|
+
if (!(target instanceof IDBDatabase &&
|
|
51
|
+
!(prop in target) &&
|
|
52
|
+
typeof prop === 'string')) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (cachedMethods.get(prop))
|
|
56
|
+
return cachedMethods.get(prop);
|
|
57
|
+
const targetFuncName = prop.replace(/FromIndex$/, '');
|
|
58
|
+
const useIndex = prop !== targetFuncName;
|
|
59
|
+
const isWrite = writeMethods.includes(targetFuncName);
|
|
60
|
+
if (
|
|
61
|
+
// Bail if the target doesn't exist on the target. Eg, getAll isn't in Edge.
|
|
62
|
+
!(targetFuncName in (useIndex ? IDBIndex : IDBObjectStore).prototype) ||
|
|
63
|
+
!(isWrite || readMethods.includes(targetFuncName))) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const method = async function (storeName, ...args) {
|
|
67
|
+
// isWrite ? 'readwrite' : undefined gzipps better, but fails in Edge :(
|
|
68
|
+
const tx = this.transaction(storeName, isWrite ? 'readwrite' : 'readonly');
|
|
69
|
+
let target = tx.store;
|
|
70
|
+
if (useIndex)
|
|
71
|
+
target = target.index(args.shift());
|
|
72
|
+
// Must reject if op rejects.
|
|
73
|
+
// If it's a write operation, must reject if tx.done rejects.
|
|
74
|
+
// Must reject with op rejection first.
|
|
75
|
+
// Must resolve with op value.
|
|
76
|
+
// Must handle both promises (no unhandled rejections)
|
|
77
|
+
return (await Promise.all([
|
|
78
|
+
target[targetFuncName](...args),
|
|
79
|
+
isWrite && tx.done,
|
|
80
|
+
]))[0];
|
|
81
|
+
};
|
|
82
|
+
cachedMethods.set(prop, method);
|
|
83
|
+
return method;
|
|
84
|
+
}
|
|
85
|
+
wrapIdbValue.replaceTraps((oldTraps) => ({
|
|
86
|
+
...oldTraps,
|
|
87
|
+
get: (target, prop, receiver) => getMethod(target, prop) || oldTraps.get(target, prop, receiver),
|
|
88
|
+
has: (target, prop) => !!getMethod(target, prop) || oldTraps.has(target, prop),
|
|
89
|
+
}));
|
|
90
|
+
|
|
91
|
+
exports.unwrap = wrapIdbValue.unwrap;
|
|
92
|
+
exports.wrap = wrapIdbValue.wrap;
|
|
93
|
+
exports.deleteDB = deleteDB;
|
|
94
|
+
exports.openDB = openDB;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { w as wrap, r as replaceTraps } from './wrap-idb-value.js';
|
|
2
|
+
export { u as unwrap, w as wrap } from './wrap-idb-value.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Open a database.
|
|
6
|
+
*
|
|
7
|
+
* @param name Name of the database.
|
|
8
|
+
* @param version Schema version.
|
|
9
|
+
* @param callbacks Additional callbacks.
|
|
10
|
+
*/
|
|
11
|
+
function openDB(name, version, { blocked, upgrade, blocking, terminated } = {}) {
|
|
12
|
+
const request = indexedDB.open(name, version);
|
|
13
|
+
const openPromise = wrap(request);
|
|
14
|
+
if (upgrade) {
|
|
15
|
+
request.addEventListener('upgradeneeded', (event) => {
|
|
16
|
+
upgrade(wrap(request.result), event.oldVersion, event.newVersion, wrap(request.transaction));
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
if (blocked)
|
|
20
|
+
request.addEventListener('blocked', () => blocked());
|
|
21
|
+
openPromise
|
|
22
|
+
.then((db) => {
|
|
23
|
+
if (terminated)
|
|
24
|
+
db.addEventListener('close', () => terminated());
|
|
25
|
+
if (blocking)
|
|
26
|
+
db.addEventListener('versionchange', () => blocking());
|
|
27
|
+
})
|
|
28
|
+
.catch(() => { });
|
|
29
|
+
return openPromise;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Delete a database.
|
|
33
|
+
*
|
|
34
|
+
* @param name Name of the database.
|
|
35
|
+
*/
|
|
36
|
+
function deleteDB(name, { blocked } = {}) {
|
|
37
|
+
const request = indexedDB.deleteDatabase(name);
|
|
38
|
+
if (blocked)
|
|
39
|
+
request.addEventListener('blocked', () => blocked());
|
|
40
|
+
return wrap(request).then(() => undefined);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const readMethods = ['get', 'getKey', 'getAll', 'getAllKeys', 'count'];
|
|
44
|
+
const writeMethods = ['put', 'add', 'delete', 'clear'];
|
|
45
|
+
const cachedMethods = new Map();
|
|
46
|
+
function getMethod(target, prop) {
|
|
47
|
+
if (!(target instanceof IDBDatabase &&
|
|
48
|
+
!(prop in target) &&
|
|
49
|
+
typeof prop === 'string')) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (cachedMethods.get(prop))
|
|
53
|
+
return cachedMethods.get(prop);
|
|
54
|
+
const targetFuncName = prop.replace(/FromIndex$/, '');
|
|
55
|
+
const useIndex = prop !== targetFuncName;
|
|
56
|
+
const isWrite = writeMethods.includes(targetFuncName);
|
|
57
|
+
if (
|
|
58
|
+
// Bail if the target doesn't exist on the target. Eg, getAll isn't in Edge.
|
|
59
|
+
!(targetFuncName in (useIndex ? IDBIndex : IDBObjectStore).prototype) ||
|
|
60
|
+
!(isWrite || readMethods.includes(targetFuncName))) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const method = async function (storeName, ...args) {
|
|
64
|
+
// isWrite ? 'readwrite' : undefined gzipps better, but fails in Edge :(
|
|
65
|
+
const tx = this.transaction(storeName, isWrite ? 'readwrite' : 'readonly');
|
|
66
|
+
let target = tx.store;
|
|
67
|
+
if (useIndex)
|
|
68
|
+
target = target.index(args.shift());
|
|
69
|
+
// Must reject if op rejects.
|
|
70
|
+
// If it's a write operation, must reject if tx.done rejects.
|
|
71
|
+
// Must reject with op rejection first.
|
|
72
|
+
// Must resolve with op value.
|
|
73
|
+
// Must handle both promises (no unhandled rejections)
|
|
74
|
+
return (await Promise.all([
|
|
75
|
+
target[targetFuncName](...args),
|
|
76
|
+
isWrite && tx.done,
|
|
77
|
+
]))[0];
|
|
78
|
+
};
|
|
79
|
+
cachedMethods.set(prop, method);
|
|
80
|
+
return method;
|
|
81
|
+
}
|
|
82
|
+
replaceTraps((oldTraps) => ({
|
|
83
|
+
...oldTraps,
|
|
84
|
+
get: (target, prop, receiver) => getMethod(target, prop) || oldTraps.get(target, prop, receiver),
|
|
85
|
+
has: (target, prop) => !!getMethod(target, prop) || oldTraps.has(target, prop),
|
|
86
|
+
}));
|
|
87
|
+
|
|
88
|
+
export { deleteDB, openDB };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).idb={})}(this,(function(e){"use strict";const t=(e,t)=>t.some((t=>e instanceof t));let n,r;const o=new WeakMap,s=new WeakMap,i=new WeakMap,a=new WeakMap,c=new WeakMap;let u={get(e,t,n){if(e instanceof IDBTransaction){if("done"===t)return s.get(e);if("objectStoreNames"===t)return e.objectStoreNames||i.get(e);if("store"===t)return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return p(e[t])},set:(e,t,n)=>(e[t]=n,!0),has:(e,t)=>e instanceof IDBTransaction&&("done"===t||"store"===t)||t in e};function d(e){u=e(u)}function f(e){return e!==IDBDatabase.prototype.transaction||"objectStoreNames"in IDBTransaction.prototype?(r||(r=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])).includes(e)?function(...t){return e.apply(D(this),t),p(o.get(this))}:function(...t){return p(e.apply(D(this),t))}:function(t,...n){const r=e.call(D(this),t,...n);return i.set(r,t.sort?t.sort():[t]),p(r)}}function l(e){return"function"==typeof e?f(e):(e instanceof IDBTransaction&&function(e){if(s.has(e))return;const t=new Promise(((t,n)=>{const r=()=>{e.removeEventListener("complete",o),e.removeEventListener("error",s),e.removeEventListener("abort",s)},o=()=>{t(),r()},s=()=>{n(e.error||new DOMException("AbortError","AbortError")),r()};e.addEventListener("complete",o),e.addEventListener("error",s),e.addEventListener("abort",s)}));s.set(e,t)}(e),t(e,n||(n=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction]))?new Proxy(e,u):e)}function p(e){if(e instanceof IDBRequest)return function(e){const t=new Promise(((t,n)=>{const r=()=>{e.removeEventListener("success",o),e.removeEventListener("error",s)},o=()=>{t(p(e.result)),r()},s=()=>{n(e.error),r()};e.addEventListener("success",o),e.addEventListener("error",s)}));return t.then((t=>{t instanceof IDBCursor&&o.set(t,e)})).catch((()=>{})),c.set(t,e),t}(e);if(a.has(e))return a.get(e);const t=l(e);return t!==e&&(a.set(e,t),c.set(t,e)),t}const D=e=>c.get(e);const I=["get","getKey","getAll","getAllKeys","count"],b=["put","add","delete","clear"],y=new Map;function B(e,t){if(!(e instanceof IDBDatabase)||t in e||"string"!=typeof t)return;if(y.get(t))return y.get(t);const n=t.replace(/FromIndex$/,""),r=t!==n,o=b.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!o&&!I.includes(n))return;const s=async function(e,...t){const s=this.transaction(e,o?"readwrite":"readonly");let i=s.store;return r&&(i=i.index(t.shift())),(await Promise.all([i[n](...t),o&&s.done]))[0]};return y.set(t,s),s}d((e=>({...e,get:(t,n,r)=>B(t,n)||e.get(t,n,r),has:(t,n)=>!!B(t,n)||e.has(t,n)})));const g=["continue","continuePrimaryKey","advance"],h={},v=new WeakMap,m=new WeakMap,w={get(e,t){if(!g.includes(t))return e[t];let n=h[t];return n||(n=h[t]=function(...e){v.set(this,m.get(this)[t](...e))}),n}};async function*E(...e){let t=this;if(t instanceof IDBCursor||(t=await t.openCursor(...e)),!t)return;const n=new Proxy(t,w);for(m.set(n,t),c.set(n,D(t));t;)yield n,t=await(v.get(n)||t.continue()),v.delete(n)}function L(e,n){return n===Symbol.asyncIterator&&t(e,[IDBIndex,IDBObjectStore,IDBCursor])||"iterate"===n&&t(e,[IDBIndex,IDBObjectStore])}d((e=>({...e,get:(t,n,r)=>L(t,n)?E:e.get(t,n,r),has:(t,n)=>L(t,n)||e.has(t,n)}))),e.deleteDB=function(e,{blocked:t}={}){const n=indexedDB.deleteDatabase(e);return t&&n.addEventListener("blocked",(()=>t())),p(n).then((()=>{}))},e.openDB=function(e,t,{blocked:n,upgrade:r,blocking:o,terminated:s}={}){const i=indexedDB.open(e,t),a=p(i);return r&&i.addEventListener("upgradeneeded",(e=>{r(p(i.result),e.oldVersion,e.newVersion,p(i.transaction))})),n&&i.addEventListener("blocked",(()=>n())),a.then((e=>{s&&e.addEventListener("close",(()=>s())),o&&e.addEventListener("versionchange",(()=>o()))})).catch((()=>{})),a},e.unwrap=D,e.wrap=p}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).idb={})}(this,(function(e){"use strict";let t,n;const r=new WeakMap,o=new WeakMap,s=new WeakMap,i=new WeakMap,a=new WeakMap;let c={get(e,t,n){if(e instanceof IDBTransaction){if("done"===t)return o.get(e);if("objectStoreNames"===t)return e.objectStoreNames||s.get(e);if("store"===t)return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return f(e[t])},set:(e,t,n)=>(e[t]=n,!0),has:(e,t)=>e instanceof IDBTransaction&&("done"===t||"store"===t)||t in e};function d(e){return e!==IDBDatabase.prototype.transaction||"objectStoreNames"in IDBTransaction.prototype?(n||(n=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])).includes(e)?function(...t){return e.apply(p(this),t),f(r.get(this))}:function(...t){return f(e.apply(p(this),t))}:function(t,...n){const r=e.call(p(this),t,...n);return s.set(r,t.sort?t.sort():[t]),f(r)}}function u(e){return"function"==typeof e?d(e):(e instanceof IDBTransaction&&function(e){if(o.has(e))return;const t=new Promise(((t,n)=>{const r=()=>{e.removeEventListener("complete",o),e.removeEventListener("error",s),e.removeEventListener("abort",s)},o=()=>{t(),r()},s=()=>{n(e.error||new DOMException("AbortError","AbortError")),r()};e.addEventListener("complete",o),e.addEventListener("error",s),e.addEventListener("abort",s)}));o.set(e,t)}(e),n=e,(t||(t=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])).some((e=>n instanceof e))?new Proxy(e,c):e);var n}function f(e){if(e instanceof IDBRequest)return function(e){const t=new Promise(((t,n)=>{const r=()=>{e.removeEventListener("success",o),e.removeEventListener("error",s)},o=()=>{t(f(e.result)),r()},s=()=>{n(e.error),r()};e.addEventListener("success",o),e.addEventListener("error",s)}));return t.then((t=>{t instanceof IDBCursor&&r.set(t,e)})).catch((()=>{})),a.set(t,e),t}(e);if(i.has(e))return i.get(e);const t=u(e);return t!==e&&(i.set(e,t),a.set(t,e)),t}const p=e=>a.get(e);const l=["get","getKey","getAll","getAllKeys","count"],D=["put","add","delete","clear"],b=new Map;function v(e,t){if(!(e instanceof IDBDatabase)||t in e||"string"!=typeof t)return;if(b.get(t))return b.get(t);const n=t.replace(/FromIndex$/,""),r=t!==n,o=D.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!o&&!l.includes(n))return;const s=async function(e,...t){const s=this.transaction(e,o?"readwrite":"readonly");let i=s.store;return r&&(i=i.index(t.shift())),(await Promise.all([i[n](...t),o&&s.done]))[0]};return b.set(t,s),s}c=(e=>({...e,get:(t,n,r)=>v(t,n)||e.get(t,n,r),has:(t,n)=>!!v(t,n)||e.has(t,n)}))(c),e.deleteDB=function(e,{blocked:t}={}){const n=indexedDB.deleteDatabase(e);return t&&n.addEventListener("blocked",(()=>t())),f(n).then((()=>{}))},e.openDB=function(e,t,{blocked:n,upgrade:r,blocking:o,terminated:s}={}){const i=indexedDB.open(e,t),a=f(i);return r&&i.addEventListener("upgradeneeded",(e=>{r(f(i.result),e.oldVersion,e.newVersion,f(i.transaction))})),n&&i.addEventListener("blocked",(()=>n())),a.then((e=>{s&&e.addEventListener("close",(()=>s())),o&&e.addEventListener("versionchange",(()=>o()))})).catch((()=>{})),a},e.unwrap=p,e.wrap=f}));
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const instanceOfAny = (object, constructors) => constructors.some((c) => object instanceof c);
|
|
4
|
+
|
|
5
|
+
let idbProxyableTypes;
|
|
6
|
+
let cursorAdvanceMethods;
|
|
7
|
+
// This is a function to prevent it throwing up in node environments.
|
|
8
|
+
function getIdbProxyableTypes() {
|
|
9
|
+
return (idbProxyableTypes ||
|
|
10
|
+
(idbProxyableTypes = [
|
|
11
|
+
IDBDatabase,
|
|
12
|
+
IDBObjectStore,
|
|
13
|
+
IDBIndex,
|
|
14
|
+
IDBCursor,
|
|
15
|
+
IDBTransaction,
|
|
16
|
+
]));
|
|
17
|
+
}
|
|
18
|
+
// This is a function to prevent it throwing up in node environments.
|
|
19
|
+
function getCursorAdvanceMethods() {
|
|
20
|
+
return (cursorAdvanceMethods ||
|
|
21
|
+
(cursorAdvanceMethods = [
|
|
22
|
+
IDBCursor.prototype.advance,
|
|
23
|
+
IDBCursor.prototype.continue,
|
|
24
|
+
IDBCursor.prototype.continuePrimaryKey,
|
|
25
|
+
]));
|
|
26
|
+
}
|
|
27
|
+
const cursorRequestMap = new WeakMap();
|
|
28
|
+
const transactionDoneMap = new WeakMap();
|
|
29
|
+
const transactionStoreNamesMap = new WeakMap();
|
|
30
|
+
const transformCache = new WeakMap();
|
|
31
|
+
const reverseTransformCache = new WeakMap();
|
|
32
|
+
function promisifyRequest(request) {
|
|
33
|
+
const promise = new Promise((resolve, reject) => {
|
|
34
|
+
const unlisten = () => {
|
|
35
|
+
request.removeEventListener('success', success);
|
|
36
|
+
request.removeEventListener('error', error);
|
|
37
|
+
};
|
|
38
|
+
const success = () => {
|
|
39
|
+
resolve(wrap(request.result));
|
|
40
|
+
unlisten();
|
|
41
|
+
};
|
|
42
|
+
const error = () => {
|
|
43
|
+
reject(request.error);
|
|
44
|
+
unlisten();
|
|
45
|
+
};
|
|
46
|
+
request.addEventListener('success', success);
|
|
47
|
+
request.addEventListener('error', error);
|
|
48
|
+
});
|
|
49
|
+
promise
|
|
50
|
+
.then((value) => {
|
|
51
|
+
// Since cursoring reuses the IDBRequest (*sigh*), we cache it for later retrieval
|
|
52
|
+
// (see wrapFunction).
|
|
53
|
+
if (value instanceof IDBCursor) {
|
|
54
|
+
cursorRequestMap.set(value, request);
|
|
55
|
+
}
|
|
56
|
+
// Catching to avoid "Uncaught Promise exceptions"
|
|
57
|
+
})
|
|
58
|
+
.catch(() => { });
|
|
59
|
+
// This mapping exists in reverseTransformCache but doesn't doesn't exist in transformCache. This
|
|
60
|
+
// is because we create many promises from a single IDBRequest.
|
|
61
|
+
reverseTransformCache.set(promise, request);
|
|
62
|
+
return promise;
|
|
63
|
+
}
|
|
64
|
+
function cacheDonePromiseForTransaction(tx) {
|
|
65
|
+
// Early bail if we've already created a done promise for this transaction.
|
|
66
|
+
if (transactionDoneMap.has(tx))
|
|
67
|
+
return;
|
|
68
|
+
const done = new Promise((resolve, reject) => {
|
|
69
|
+
const unlisten = () => {
|
|
70
|
+
tx.removeEventListener('complete', complete);
|
|
71
|
+
tx.removeEventListener('error', error);
|
|
72
|
+
tx.removeEventListener('abort', error);
|
|
73
|
+
};
|
|
74
|
+
const complete = () => {
|
|
75
|
+
resolve();
|
|
76
|
+
unlisten();
|
|
77
|
+
};
|
|
78
|
+
const error = () => {
|
|
79
|
+
reject(tx.error || new DOMException('AbortError', 'AbortError'));
|
|
80
|
+
unlisten();
|
|
81
|
+
};
|
|
82
|
+
tx.addEventListener('complete', complete);
|
|
83
|
+
tx.addEventListener('error', error);
|
|
84
|
+
tx.addEventListener('abort', error);
|
|
85
|
+
});
|
|
86
|
+
// Cache it for later retrieval.
|
|
87
|
+
transactionDoneMap.set(tx, done);
|
|
88
|
+
}
|
|
89
|
+
let idbProxyTraps = {
|
|
90
|
+
get(target, prop, receiver) {
|
|
91
|
+
if (target instanceof IDBTransaction) {
|
|
92
|
+
// Special handling for transaction.done.
|
|
93
|
+
if (prop === 'done')
|
|
94
|
+
return transactionDoneMap.get(target);
|
|
95
|
+
// Polyfill for objectStoreNames because of Edge.
|
|
96
|
+
if (prop === 'objectStoreNames') {
|
|
97
|
+
return target.objectStoreNames || transactionStoreNamesMap.get(target);
|
|
98
|
+
}
|
|
99
|
+
// Make tx.store return the only store in the transaction, or undefined if there are many.
|
|
100
|
+
if (prop === 'store') {
|
|
101
|
+
return receiver.objectStoreNames[1]
|
|
102
|
+
? undefined
|
|
103
|
+
: receiver.objectStore(receiver.objectStoreNames[0]);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// Else transform whatever we get back.
|
|
107
|
+
return wrap(target[prop]);
|
|
108
|
+
},
|
|
109
|
+
set(target, prop, value) {
|
|
110
|
+
target[prop] = value;
|
|
111
|
+
return true;
|
|
112
|
+
},
|
|
113
|
+
has(target, prop) {
|
|
114
|
+
if (target instanceof IDBTransaction &&
|
|
115
|
+
(prop === 'done' || prop === 'store')) {
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
return prop in target;
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
function replaceTraps(callback) {
|
|
122
|
+
idbProxyTraps = callback(idbProxyTraps);
|
|
123
|
+
}
|
|
124
|
+
function wrapFunction(func) {
|
|
125
|
+
// Due to expected object equality (which is enforced by the caching in `wrap`), we
|
|
126
|
+
// only create one new func per func.
|
|
127
|
+
// Edge doesn't support objectStoreNames (booo), so we polyfill it here.
|
|
128
|
+
if (func === IDBDatabase.prototype.transaction &&
|
|
129
|
+
!('objectStoreNames' in IDBTransaction.prototype)) {
|
|
130
|
+
return function (storeNames, ...args) {
|
|
131
|
+
const tx = func.call(unwrap(this), storeNames, ...args);
|
|
132
|
+
transactionStoreNamesMap.set(tx, storeNames.sort ? storeNames.sort() : [storeNames]);
|
|
133
|
+
return wrap(tx);
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
// Cursor methods are special, as the behaviour is a little more different to standard IDB. In
|
|
137
|
+
// IDB, you advance the cursor and wait for a new 'success' on the IDBRequest that gave you the
|
|
138
|
+
// cursor. It's kinda like a promise that can resolve with many values. That doesn't make sense
|
|
139
|
+
// with real promises, so each advance methods returns a new promise for the cursor object, or
|
|
140
|
+
// undefined if the end of the cursor has been reached.
|
|
141
|
+
if (getCursorAdvanceMethods().includes(func)) {
|
|
142
|
+
return function (...args) {
|
|
143
|
+
// Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
|
|
144
|
+
// the original object.
|
|
145
|
+
func.apply(unwrap(this), args);
|
|
146
|
+
return wrap(cursorRequestMap.get(this));
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
return function (...args) {
|
|
150
|
+
// Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
|
|
151
|
+
// the original object.
|
|
152
|
+
return wrap(func.apply(unwrap(this), args));
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
function transformCachableValue(value) {
|
|
156
|
+
if (typeof value === 'function')
|
|
157
|
+
return wrapFunction(value);
|
|
158
|
+
// This doesn't return, it just creates a 'done' promise for the transaction,
|
|
159
|
+
// which is later returned for transaction.done (see idbObjectHandler).
|
|
160
|
+
if (value instanceof IDBTransaction)
|
|
161
|
+
cacheDonePromiseForTransaction(value);
|
|
162
|
+
if (instanceOfAny(value, getIdbProxyableTypes()))
|
|
163
|
+
return new Proxy(value, idbProxyTraps);
|
|
164
|
+
// Return the same value back if we're not going to transform it.
|
|
165
|
+
return value;
|
|
166
|
+
}
|
|
167
|
+
function wrap(value) {
|
|
168
|
+
// We sometimes generate multiple promises from a single IDBRequest (eg when cursoring), because
|
|
169
|
+
// IDB is weird and a single IDBRequest can yield many responses, so these can't be cached.
|
|
170
|
+
if (value instanceof IDBRequest)
|
|
171
|
+
return promisifyRequest(value);
|
|
172
|
+
// If we've already transformed this value before, reuse the transformed value.
|
|
173
|
+
// This is faster, but it also provides object equality.
|
|
174
|
+
if (transformCache.has(value))
|
|
175
|
+
return transformCache.get(value);
|
|
176
|
+
const newValue = transformCachableValue(value);
|
|
177
|
+
// Not all types are transformed.
|
|
178
|
+
// These may be primitive types, so they can't be WeakMap keys.
|
|
179
|
+
if (newValue !== value) {
|
|
180
|
+
transformCache.set(value, newValue);
|
|
181
|
+
reverseTransformCache.set(newValue, value);
|
|
182
|
+
}
|
|
183
|
+
return newValue;
|
|
184
|
+
}
|
|
185
|
+
const unwrap = (value) => reverseTransformCache.get(value);
|
|
186
|
+
|
|
187
|
+
exports.instanceOfAny = instanceOfAny;
|
|
188
|
+
exports.replaceTraps = replaceTraps;
|
|
189
|
+
exports.reverseTransformCache = reverseTransformCache;
|
|
190
|
+
exports.unwrap = unwrap;
|
|
191
|
+
exports.wrap = wrap;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { IDBPCursor, IDBPCursorWithValue, IDBPDatabase, IDBPIndex, IDBPObjectStore, IDBPTransaction } from './entry.js';
|
|
2
|
+
export declare const reverseTransformCache: WeakMap<object, any>;
|
|
3
|
+
export declare function replaceTraps(callback: (currentTraps: ProxyHandler<any>) => ProxyHandler<any>): void;
|
|
4
|
+
/**
|
|
5
|
+
* Enhance an IDB object with helpers.
|
|
6
|
+
*
|
|
7
|
+
* @param value The thing to enhance.
|
|
8
|
+
*/
|
|
9
|
+
export declare function wrap(value: IDBDatabase): IDBPDatabase;
|
|
10
|
+
export declare function wrap(value: IDBIndex): IDBPIndex;
|
|
11
|
+
export declare function wrap(value: IDBObjectStore): IDBPObjectStore;
|
|
12
|
+
export declare function wrap(value: IDBTransaction): IDBPTransaction;
|
|
13
|
+
export declare function wrap(value: IDBOpenDBRequest): Promise<IDBPDatabase | undefined>;
|
|
14
|
+
export declare function wrap<T>(value: IDBRequest<T>): Promise<T>;
|
|
15
|
+
/**
|
|
16
|
+
* Revert an enhanced IDB object to a plain old miserable IDB one.
|
|
17
|
+
*
|
|
18
|
+
* Will also revert a promise back to an IDBRequest.
|
|
19
|
+
*
|
|
20
|
+
* @param value The enhanced object to revert.
|
|
21
|
+
*/
|
|
22
|
+
interface Unwrap {
|
|
23
|
+
(value: IDBPCursorWithValue<any, any, any, any, any>): IDBCursorWithValue;
|
|
24
|
+
(value: IDBPCursor<any, any, any, any, any>): IDBCursor;
|
|
25
|
+
(value: IDBPDatabase): IDBDatabase;
|
|
26
|
+
(value: IDBPIndex<any, any, any, any, any>): IDBIndex;
|
|
27
|
+
(value: IDBPObjectStore<any, any, any, any>): IDBObjectStore;
|
|
28
|
+
(value: IDBPTransaction<any, any, any>): IDBTransaction;
|
|
29
|
+
<T extends any>(value: Promise<IDBPDatabase<T>>): IDBOpenDBRequest;
|
|
30
|
+
(value: Promise<IDBPDatabase>): IDBOpenDBRequest;
|
|
31
|
+
<T>(value: Promise<T>): IDBRequest<T>;
|
|
32
|
+
}
|
|
33
|
+
export declare const unwrap: Unwrap;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
const instanceOfAny = (object, constructors) => constructors.some((c) => object instanceof c);
|
|
2
|
+
|
|
3
|
+
let idbProxyableTypes;
|
|
4
|
+
let cursorAdvanceMethods;
|
|
5
|
+
// This is a function to prevent it throwing up in node environments.
|
|
6
|
+
function getIdbProxyableTypes() {
|
|
7
|
+
return (idbProxyableTypes ||
|
|
8
|
+
(idbProxyableTypes = [
|
|
9
|
+
IDBDatabase,
|
|
10
|
+
IDBObjectStore,
|
|
11
|
+
IDBIndex,
|
|
12
|
+
IDBCursor,
|
|
13
|
+
IDBTransaction,
|
|
14
|
+
]));
|
|
15
|
+
}
|
|
16
|
+
// This is a function to prevent it throwing up in node environments.
|
|
17
|
+
function getCursorAdvanceMethods() {
|
|
18
|
+
return (cursorAdvanceMethods ||
|
|
19
|
+
(cursorAdvanceMethods = [
|
|
20
|
+
IDBCursor.prototype.advance,
|
|
21
|
+
IDBCursor.prototype.continue,
|
|
22
|
+
IDBCursor.prototype.continuePrimaryKey,
|
|
23
|
+
]));
|
|
24
|
+
}
|
|
25
|
+
const cursorRequestMap = new WeakMap();
|
|
26
|
+
const transactionDoneMap = new WeakMap();
|
|
27
|
+
const transactionStoreNamesMap = new WeakMap();
|
|
28
|
+
const transformCache = new WeakMap();
|
|
29
|
+
const reverseTransformCache = new WeakMap();
|
|
30
|
+
function promisifyRequest(request) {
|
|
31
|
+
const promise = new Promise((resolve, reject) => {
|
|
32
|
+
const unlisten = () => {
|
|
33
|
+
request.removeEventListener('success', success);
|
|
34
|
+
request.removeEventListener('error', error);
|
|
35
|
+
};
|
|
36
|
+
const success = () => {
|
|
37
|
+
resolve(wrap(request.result));
|
|
38
|
+
unlisten();
|
|
39
|
+
};
|
|
40
|
+
const error = () => {
|
|
41
|
+
reject(request.error);
|
|
42
|
+
unlisten();
|
|
43
|
+
};
|
|
44
|
+
request.addEventListener('success', success);
|
|
45
|
+
request.addEventListener('error', error);
|
|
46
|
+
});
|
|
47
|
+
promise
|
|
48
|
+
.then((value) => {
|
|
49
|
+
// Since cursoring reuses the IDBRequest (*sigh*), we cache it for later retrieval
|
|
50
|
+
// (see wrapFunction).
|
|
51
|
+
if (value instanceof IDBCursor) {
|
|
52
|
+
cursorRequestMap.set(value, request);
|
|
53
|
+
}
|
|
54
|
+
// Catching to avoid "Uncaught Promise exceptions"
|
|
55
|
+
})
|
|
56
|
+
.catch(() => { });
|
|
57
|
+
// This mapping exists in reverseTransformCache but doesn't doesn't exist in transformCache. This
|
|
58
|
+
// is because we create many promises from a single IDBRequest.
|
|
59
|
+
reverseTransformCache.set(promise, request);
|
|
60
|
+
return promise;
|
|
61
|
+
}
|
|
62
|
+
function cacheDonePromiseForTransaction(tx) {
|
|
63
|
+
// Early bail if we've already created a done promise for this transaction.
|
|
64
|
+
if (transactionDoneMap.has(tx))
|
|
65
|
+
return;
|
|
66
|
+
const done = new Promise((resolve, reject) => {
|
|
67
|
+
const unlisten = () => {
|
|
68
|
+
tx.removeEventListener('complete', complete);
|
|
69
|
+
tx.removeEventListener('error', error);
|
|
70
|
+
tx.removeEventListener('abort', error);
|
|
71
|
+
};
|
|
72
|
+
const complete = () => {
|
|
73
|
+
resolve();
|
|
74
|
+
unlisten();
|
|
75
|
+
};
|
|
76
|
+
const error = () => {
|
|
77
|
+
reject(tx.error || new DOMException('AbortError', 'AbortError'));
|
|
78
|
+
unlisten();
|
|
79
|
+
};
|
|
80
|
+
tx.addEventListener('complete', complete);
|
|
81
|
+
tx.addEventListener('error', error);
|
|
82
|
+
tx.addEventListener('abort', error);
|
|
83
|
+
});
|
|
84
|
+
// Cache it for later retrieval.
|
|
85
|
+
transactionDoneMap.set(tx, done);
|
|
86
|
+
}
|
|
87
|
+
let idbProxyTraps = {
|
|
88
|
+
get(target, prop, receiver) {
|
|
89
|
+
if (target instanceof IDBTransaction) {
|
|
90
|
+
// Special handling for transaction.done.
|
|
91
|
+
if (prop === 'done')
|
|
92
|
+
return transactionDoneMap.get(target);
|
|
93
|
+
// Polyfill for objectStoreNames because of Edge.
|
|
94
|
+
if (prop === 'objectStoreNames') {
|
|
95
|
+
return target.objectStoreNames || transactionStoreNamesMap.get(target);
|
|
96
|
+
}
|
|
97
|
+
// Make tx.store return the only store in the transaction, or undefined if there are many.
|
|
98
|
+
if (prop === 'store') {
|
|
99
|
+
return receiver.objectStoreNames[1]
|
|
100
|
+
? undefined
|
|
101
|
+
: receiver.objectStore(receiver.objectStoreNames[0]);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// Else transform whatever we get back.
|
|
105
|
+
return wrap(target[prop]);
|
|
106
|
+
},
|
|
107
|
+
set(target, prop, value) {
|
|
108
|
+
target[prop] = value;
|
|
109
|
+
return true;
|
|
110
|
+
},
|
|
111
|
+
has(target, prop) {
|
|
112
|
+
if (target instanceof IDBTransaction &&
|
|
113
|
+
(prop === 'done' || prop === 'store')) {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
return prop in target;
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
function replaceTraps(callback) {
|
|
120
|
+
idbProxyTraps = callback(idbProxyTraps);
|
|
121
|
+
}
|
|
122
|
+
function wrapFunction(func) {
|
|
123
|
+
// Due to expected object equality (which is enforced by the caching in `wrap`), we
|
|
124
|
+
// only create one new func per func.
|
|
125
|
+
// Edge doesn't support objectStoreNames (booo), so we polyfill it here.
|
|
126
|
+
if (func === IDBDatabase.prototype.transaction &&
|
|
127
|
+
!('objectStoreNames' in IDBTransaction.prototype)) {
|
|
128
|
+
return function (storeNames, ...args) {
|
|
129
|
+
const tx = func.call(unwrap(this), storeNames, ...args);
|
|
130
|
+
transactionStoreNamesMap.set(tx, storeNames.sort ? storeNames.sort() : [storeNames]);
|
|
131
|
+
return wrap(tx);
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
// Cursor methods are special, as the behaviour is a little more different to standard IDB. In
|
|
135
|
+
// IDB, you advance the cursor and wait for a new 'success' on the IDBRequest that gave you the
|
|
136
|
+
// cursor. It's kinda like a promise that can resolve with many values. That doesn't make sense
|
|
137
|
+
// with real promises, so each advance methods returns a new promise for the cursor object, or
|
|
138
|
+
// undefined if the end of the cursor has been reached.
|
|
139
|
+
if (getCursorAdvanceMethods().includes(func)) {
|
|
140
|
+
return function (...args) {
|
|
141
|
+
// Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
|
|
142
|
+
// the original object.
|
|
143
|
+
func.apply(unwrap(this), args);
|
|
144
|
+
return wrap(cursorRequestMap.get(this));
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
return function (...args) {
|
|
148
|
+
// Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
|
|
149
|
+
// the original object.
|
|
150
|
+
return wrap(func.apply(unwrap(this), args));
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function transformCachableValue(value) {
|
|
154
|
+
if (typeof value === 'function')
|
|
155
|
+
return wrapFunction(value);
|
|
156
|
+
// This doesn't return, it just creates a 'done' promise for the transaction,
|
|
157
|
+
// which is later returned for transaction.done (see idbObjectHandler).
|
|
158
|
+
if (value instanceof IDBTransaction)
|
|
159
|
+
cacheDonePromiseForTransaction(value);
|
|
160
|
+
if (instanceOfAny(value, getIdbProxyableTypes()))
|
|
161
|
+
return new Proxy(value, idbProxyTraps);
|
|
162
|
+
// Return the same value back if we're not going to transform it.
|
|
163
|
+
return value;
|
|
164
|
+
}
|
|
165
|
+
function wrap(value) {
|
|
166
|
+
// We sometimes generate multiple promises from a single IDBRequest (eg when cursoring), because
|
|
167
|
+
// IDB is weird and a single IDBRequest can yield many responses, so these can't be cached.
|
|
168
|
+
if (value instanceof IDBRequest)
|
|
169
|
+
return promisifyRequest(value);
|
|
170
|
+
// If we've already transformed this value before, reuse the transformed value.
|
|
171
|
+
// This is faster, but it also provides object equality.
|
|
172
|
+
if (transformCache.has(value))
|
|
173
|
+
return transformCache.get(value);
|
|
174
|
+
const newValue = transformCachableValue(value);
|
|
175
|
+
// Not all types are transformed.
|
|
176
|
+
// These may be primitive types, so they can't be WeakMap keys.
|
|
177
|
+
if (newValue !== value) {
|
|
178
|
+
transformCache.set(value, newValue);
|
|
179
|
+
reverseTransformCache.set(newValue, value);
|
|
180
|
+
}
|
|
181
|
+
return newValue;
|
|
182
|
+
}
|
|
183
|
+
const unwrap = (value) => reverseTransformCache.get(value);
|
|
184
|
+
|
|
185
|
+
export { reverseTransformCache as a, instanceOfAny as i, replaceTraps as r, unwrap as u, wrap as w };
|