@leofcoin/chain 1.5.65 → 1.5.66
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/exports/browser/{browser-1GyRaZxg-C9SpI6hG.js → browser-Ei0BXMlu-irDJ6Blw.js} +1 -1
- package/exports/browser/browser-store.js +40 -308
- package/exports/browser/{client-UOCjJBGl-pbv-pTHd.js → client-A009z8av-uBa1w1TW.js} +3 -3
- package/exports/browser/{index-ub31QSed-EMPr2oeb.js → index-G74WLzL7-tmiSHjUc.js} +1 -1
- package/exports/browser/{index-K4Kwju30-vS3fNpxy.js → index-YQrIDBUQ-OXiMI4eT.js} +1 -1
- package/exports/browser/{messages-guyZfse6-JeAlT5Nb.js → messages-lWRTai7t-Bc6ghkkt.js} +1 -1
- package/exports/browser/{node-browser-0Ly80awM.js → node-browser-TcXF8FDB.js} +621 -619
- package/exports/browser/node-browser.js +1 -1
- package/package.json +1 -1
|
@@ -70,310 +70,28 @@ class KeyValue {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
let idbProxyableTypes;
|
|
76
|
-
let cursorAdvanceMethods;
|
|
77
|
-
// This is a function to prevent it throwing up in node environments.
|
|
78
|
-
function getIdbProxyableTypes() {
|
|
79
|
-
return (idbProxyableTypes ||
|
|
80
|
-
(idbProxyableTypes = [
|
|
81
|
-
IDBDatabase,
|
|
82
|
-
IDBObjectStore,
|
|
83
|
-
IDBIndex,
|
|
84
|
-
IDBCursor,
|
|
85
|
-
IDBTransaction,
|
|
86
|
-
]));
|
|
87
|
-
}
|
|
88
|
-
// This is a function to prevent it throwing up in node environments.
|
|
89
|
-
function getCursorAdvanceMethods() {
|
|
90
|
-
return (cursorAdvanceMethods ||
|
|
91
|
-
(cursorAdvanceMethods = [
|
|
92
|
-
IDBCursor.prototype.advance,
|
|
93
|
-
IDBCursor.prototype.continue,
|
|
94
|
-
IDBCursor.prototype.continuePrimaryKey,
|
|
95
|
-
]));
|
|
96
|
-
}
|
|
97
|
-
const transactionDoneMap = new WeakMap();
|
|
98
|
-
const transformCache = new WeakMap();
|
|
99
|
-
const reverseTransformCache = new WeakMap();
|
|
100
|
-
function promisifyRequest(request) {
|
|
101
|
-
const promise = new Promise((resolve, reject) => {
|
|
102
|
-
const unlisten = () => {
|
|
103
|
-
request.removeEventListener('success', success);
|
|
104
|
-
request.removeEventListener('error', error);
|
|
105
|
-
};
|
|
106
|
-
const success = () => {
|
|
107
|
-
resolve(wrap(request.result));
|
|
108
|
-
unlisten();
|
|
109
|
-
};
|
|
110
|
-
const error = () => {
|
|
111
|
-
reject(request.error);
|
|
112
|
-
unlisten();
|
|
113
|
-
};
|
|
114
|
-
request.addEventListener('success', success);
|
|
115
|
-
request.addEventListener('error', error);
|
|
116
|
-
});
|
|
117
|
-
// This mapping exists in reverseTransformCache but doesn't doesn't exist in transformCache. This
|
|
118
|
-
// is because we create many promises from a single IDBRequest.
|
|
119
|
-
reverseTransformCache.set(promise, request);
|
|
120
|
-
return promise;
|
|
121
|
-
}
|
|
122
|
-
function cacheDonePromiseForTransaction(tx) {
|
|
123
|
-
// Early bail if we've already created a done promise for this transaction.
|
|
124
|
-
if (transactionDoneMap.has(tx))
|
|
125
|
-
return;
|
|
126
|
-
const done = new Promise((resolve, reject) => {
|
|
127
|
-
const unlisten = () => {
|
|
128
|
-
tx.removeEventListener('complete', complete);
|
|
129
|
-
tx.removeEventListener('error', error);
|
|
130
|
-
tx.removeEventListener('abort', error);
|
|
131
|
-
};
|
|
132
|
-
const complete = () => {
|
|
133
|
-
resolve();
|
|
134
|
-
unlisten();
|
|
135
|
-
};
|
|
136
|
-
const error = () => {
|
|
137
|
-
reject(tx.error || new DOMException('AbortError', 'AbortError'));
|
|
138
|
-
unlisten();
|
|
139
|
-
};
|
|
140
|
-
tx.addEventListener('complete', complete);
|
|
141
|
-
tx.addEventListener('error', error);
|
|
142
|
-
tx.addEventListener('abort', error);
|
|
143
|
-
});
|
|
144
|
-
// Cache it for later retrieval.
|
|
145
|
-
transactionDoneMap.set(tx, done);
|
|
146
|
-
}
|
|
147
|
-
let idbProxyTraps = {
|
|
148
|
-
get(target, prop, receiver) {
|
|
149
|
-
if (target instanceof IDBTransaction) {
|
|
150
|
-
// Special handling for transaction.done.
|
|
151
|
-
if (prop === 'done')
|
|
152
|
-
return transactionDoneMap.get(target);
|
|
153
|
-
// Make tx.store return the only store in the transaction, or undefined if there are many.
|
|
154
|
-
if (prop === 'store') {
|
|
155
|
-
return receiver.objectStoreNames[1]
|
|
156
|
-
? undefined
|
|
157
|
-
: receiver.objectStore(receiver.objectStoreNames[0]);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
// Else transform whatever we get back.
|
|
161
|
-
return wrap(target[prop]);
|
|
162
|
-
},
|
|
163
|
-
set(target, prop, value) {
|
|
164
|
-
target[prop] = value;
|
|
165
|
-
return true;
|
|
166
|
-
},
|
|
167
|
-
has(target, prop) {
|
|
168
|
-
if (target instanceof IDBTransaction &&
|
|
169
|
-
(prop === 'done' || prop === 'store')) {
|
|
170
|
-
return true;
|
|
171
|
-
}
|
|
172
|
-
return prop in target;
|
|
173
|
-
},
|
|
174
|
-
};
|
|
175
|
-
function replaceTraps(callback) {
|
|
176
|
-
idbProxyTraps = callback(idbProxyTraps);
|
|
177
|
-
}
|
|
178
|
-
function wrapFunction(func) {
|
|
179
|
-
// Due to expected object equality (which is enforced by the caching in `wrap`), we
|
|
180
|
-
// only create one new func per func.
|
|
181
|
-
// Cursor methods are special, as the behaviour is a little more different to standard IDB. In
|
|
182
|
-
// IDB, you advance the cursor and wait for a new 'success' on the IDBRequest that gave you the
|
|
183
|
-
// cursor. It's kinda like a promise that can resolve with many values. That doesn't make sense
|
|
184
|
-
// with real promises, so each advance methods returns a new promise for the cursor object, or
|
|
185
|
-
// undefined if the end of the cursor has been reached.
|
|
186
|
-
if (getCursorAdvanceMethods().includes(func)) {
|
|
187
|
-
return function (...args) {
|
|
188
|
-
// Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
|
|
189
|
-
// the original object.
|
|
190
|
-
func.apply(unwrap(this), args);
|
|
191
|
-
return wrap(this.request);
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
return function (...args) {
|
|
195
|
-
// Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
|
|
196
|
-
// the original object.
|
|
197
|
-
return wrap(func.apply(unwrap(this), args));
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
function transformCachableValue(value) {
|
|
201
|
-
if (typeof value === 'function')
|
|
202
|
-
return wrapFunction(value);
|
|
203
|
-
// This doesn't return, it just creates a 'done' promise for the transaction,
|
|
204
|
-
// which is later returned for transaction.done (see idbObjectHandler).
|
|
205
|
-
if (value instanceof IDBTransaction)
|
|
206
|
-
cacheDonePromiseForTransaction(value);
|
|
207
|
-
if (instanceOfAny(value, getIdbProxyableTypes()))
|
|
208
|
-
return new Proxy(value, idbProxyTraps);
|
|
209
|
-
// Return the same value back if we're not going to transform it.
|
|
210
|
-
return value;
|
|
211
|
-
}
|
|
212
|
-
function wrap(value) {
|
|
213
|
-
// We sometimes generate multiple promises from a single IDBRequest (eg when cursoring), because
|
|
214
|
-
// IDB is weird and a single IDBRequest can yield many responses, so these can't be cached.
|
|
215
|
-
if (value instanceof IDBRequest)
|
|
216
|
-
return promisifyRequest(value);
|
|
217
|
-
// If we've already transformed this value before, reuse the transformed value.
|
|
218
|
-
// This is faster, but it also provides object equality.
|
|
219
|
-
if (transformCache.has(value))
|
|
220
|
-
return transformCache.get(value);
|
|
221
|
-
const newValue = transformCachableValue(value);
|
|
222
|
-
// Not all types are transformed.
|
|
223
|
-
// These may be primitive types, so they can't be WeakMap keys.
|
|
224
|
-
if (newValue !== value) {
|
|
225
|
-
transformCache.set(value, newValue);
|
|
226
|
-
reverseTransformCache.set(newValue, value);
|
|
227
|
-
}
|
|
228
|
-
return newValue;
|
|
229
|
-
}
|
|
230
|
-
const unwrap = (value) => reverseTransformCache.get(value);
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Open a database.
|
|
234
|
-
*
|
|
235
|
-
* @param name Name of the database.
|
|
236
|
-
* @param version Schema version.
|
|
237
|
-
* @param callbacks Additional callbacks.
|
|
238
|
-
*/
|
|
239
|
-
function openDB(name, version, { blocked, upgrade, blocking, terminated } = {}) {
|
|
240
|
-
const request = indexedDB.open(name, version);
|
|
241
|
-
const openPromise = wrap(request);
|
|
242
|
-
if (upgrade) {
|
|
243
|
-
request.addEventListener('upgradeneeded', (event) => {
|
|
244
|
-
upgrade(wrap(request.result), event.oldVersion, event.newVersion, wrap(request.transaction), event);
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
if (blocked) {
|
|
248
|
-
request.addEventListener('blocked', (event) => blocked(
|
|
249
|
-
// Casting due to https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/1405
|
|
250
|
-
event.oldVersion, event.newVersion, event));
|
|
251
|
-
}
|
|
252
|
-
openPromise
|
|
253
|
-
.then((db) => {
|
|
254
|
-
if (terminated)
|
|
255
|
-
db.addEventListener('close', () => terminated());
|
|
256
|
-
if (blocking) {
|
|
257
|
-
db.addEventListener('versionchange', (event) => blocking(event.oldVersion, event.newVersion, event));
|
|
258
|
-
}
|
|
259
|
-
})
|
|
260
|
-
.catch(() => { });
|
|
261
|
-
return openPromise;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
const readMethods = ['get', 'getKey', 'getAll', 'getAllKeys', 'count'];
|
|
265
|
-
const writeMethods = ['put', 'add', 'delete', 'clear'];
|
|
266
|
-
const cachedMethods = new Map();
|
|
267
|
-
function getMethod(target, prop) {
|
|
268
|
-
if (!(target instanceof IDBDatabase &&
|
|
269
|
-
!(prop in target) &&
|
|
270
|
-
typeof prop === 'string')) {
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
if (cachedMethods.get(prop))
|
|
274
|
-
return cachedMethods.get(prop);
|
|
275
|
-
const targetFuncName = prop.replace(/FromIndex$/, '');
|
|
276
|
-
const useIndex = prop !== targetFuncName;
|
|
277
|
-
const isWrite = writeMethods.includes(targetFuncName);
|
|
278
|
-
if (
|
|
279
|
-
// Bail if the target doesn't exist on the target. Eg, getAll isn't in Edge.
|
|
280
|
-
!(targetFuncName in (useIndex ? IDBIndex : IDBObjectStore).prototype) ||
|
|
281
|
-
!(isWrite || readMethods.includes(targetFuncName))) {
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
const method = async function (storeName, ...args) {
|
|
285
|
-
// isWrite ? 'readwrite' : undefined gzipps better, but fails in Edge :(
|
|
286
|
-
const tx = this.transaction(storeName, isWrite ? 'readwrite' : 'readonly');
|
|
287
|
-
let target = tx.store;
|
|
288
|
-
if (useIndex)
|
|
289
|
-
target = target.index(args.shift());
|
|
290
|
-
// Must reject if op rejects.
|
|
291
|
-
// If it's a write operation, must reject if tx.done rejects.
|
|
292
|
-
// Must reject with op rejection first.
|
|
293
|
-
// Must resolve with op value.
|
|
294
|
-
// Must handle both promises (no unhandled rejections)
|
|
295
|
-
return (await Promise.all([
|
|
296
|
-
target[targetFuncName](...args),
|
|
297
|
-
isWrite && tx.done,
|
|
298
|
-
]))[0];
|
|
299
|
-
};
|
|
300
|
-
cachedMethods.set(prop, method);
|
|
301
|
-
return method;
|
|
302
|
-
}
|
|
303
|
-
replaceTraps((oldTraps) => ({
|
|
304
|
-
...oldTraps,
|
|
305
|
-
get: (target, prop, receiver) => getMethod(target, prop) || oldTraps.get(target, prop, receiver),
|
|
306
|
-
has: (target, prop) => !!getMethod(target, prop) || oldTraps.has(target, prop),
|
|
307
|
-
}));
|
|
308
|
-
|
|
309
|
-
const advanceMethodProps = ['continue', 'continuePrimaryKey', 'advance'];
|
|
310
|
-
const methodMap = {};
|
|
311
|
-
const advanceResults = new WeakMap();
|
|
312
|
-
const ittrProxiedCursorToOriginalProxy = new WeakMap();
|
|
313
|
-
const cursorIteratorTraps = {
|
|
314
|
-
get(target, prop) {
|
|
315
|
-
if (!advanceMethodProps.includes(prop))
|
|
316
|
-
return target[prop];
|
|
317
|
-
let cachedFunc = methodMap[prop];
|
|
318
|
-
if (!cachedFunc) {
|
|
319
|
-
cachedFunc = methodMap[prop] = function (...args) {
|
|
320
|
-
advanceResults.set(this, ittrProxiedCursorToOriginalProxy.get(this)[prop](...args));
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
|
-
return cachedFunc;
|
|
324
|
-
},
|
|
325
|
-
};
|
|
326
|
-
async function* iterate(...args) {
|
|
327
|
-
// tslint:disable-next-line:no-this-assignment
|
|
328
|
-
let cursor = this;
|
|
329
|
-
if (!(cursor instanceof IDBCursor)) {
|
|
330
|
-
cursor = await cursor.openCursor(...args);
|
|
331
|
-
}
|
|
332
|
-
if (!cursor)
|
|
333
|
-
return;
|
|
334
|
-
cursor = cursor;
|
|
335
|
-
const proxiedCursor = new Proxy(cursor, cursorIteratorTraps);
|
|
336
|
-
ittrProxiedCursorToOriginalProxy.set(proxiedCursor, cursor);
|
|
337
|
-
// Map this double-proxy back to the original, so other cursor methods work.
|
|
338
|
-
reverseTransformCache.set(proxiedCursor, unwrap(cursor));
|
|
339
|
-
while (cursor) {
|
|
340
|
-
yield proxiedCursor;
|
|
341
|
-
// If one of the advancing methods was not called, call continue().
|
|
342
|
-
cursor = await (advanceResults.get(proxiedCursor) || cursor.continue());
|
|
343
|
-
advanceResults.delete(proxiedCursor);
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
function isIteratorProp(target, prop) {
|
|
347
|
-
return ((prop === Symbol.asyncIterator &&
|
|
348
|
-
instanceOfAny(target, [IDBIndex, IDBObjectStore, IDBCursor])) ||
|
|
349
|
-
(prop === 'iterate' && instanceOfAny(target, [IDBIndex, IDBObjectStore])));
|
|
350
|
-
}
|
|
351
|
-
replaceTraps((oldTraps) => ({
|
|
352
|
-
...oldTraps,
|
|
353
|
-
get(target, prop, receiver) {
|
|
354
|
-
if (isIteratorProp(target, prop))
|
|
355
|
-
return iterate;
|
|
356
|
-
return oldTraps.get(target, prop, receiver);
|
|
357
|
-
},
|
|
358
|
-
has(target, prop) {
|
|
359
|
-
return isIteratorProp(target, prop) || oldTraps.has(target, prop);
|
|
360
|
-
},
|
|
361
|
-
}));
|
|
362
|
-
|
|
73
|
+
const opfsRoot = await navigator.storage.getDirectory();
|
|
363
74
|
class BrowerStore {
|
|
364
75
|
db;
|
|
365
76
|
name;
|
|
366
77
|
root;
|
|
367
78
|
version;
|
|
368
|
-
init(name = 'storage', root = '.leofcoin', version = '1') {
|
|
79
|
+
async init(name = 'storage', root = '.leofcoin', version = '1') {
|
|
80
|
+
console.log('init');
|
|
369
81
|
this.version = version;
|
|
370
82
|
this.name = name;
|
|
371
|
-
this.root =
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
83
|
+
this.root = opfsRoot;
|
|
84
|
+
console.log(`${this.root}/${this.name}`);
|
|
85
|
+
let directoryHandle;
|
|
86
|
+
try {
|
|
87
|
+
directoryHandle = await opfsRoot.getDirectoryHandle(this.name, {
|
|
88
|
+
create: true
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
console.error(error);
|
|
93
|
+
}
|
|
94
|
+
this.db = directoryHandle;
|
|
377
95
|
}
|
|
378
96
|
toKeyPath(key) {
|
|
379
97
|
if (key instanceof KeyPath)
|
|
@@ -386,23 +104,38 @@ class BrowerStore {
|
|
|
386
104
|
// @ts-ignore
|
|
387
105
|
return value.uint8Array;
|
|
388
106
|
}
|
|
107
|
+
async has(key) {
|
|
108
|
+
try {
|
|
109
|
+
await this.db.getFileHandle(this.toKeyPath(key));
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
389
116
|
async get(key) {
|
|
390
|
-
|
|
117
|
+
const handle = await this.db.getFileHandle(this.toKeyPath(key));
|
|
118
|
+
const file = await handle.getFile();
|
|
119
|
+
return new Uint8Array(await file.arrayBuffer());
|
|
391
120
|
}
|
|
392
121
|
async put(key, value) {
|
|
393
|
-
|
|
122
|
+
const handle = await this.db.getFileHandle(this.toKeyPath(key), { create: true });
|
|
123
|
+
const writeable = handle.createWritable();
|
|
124
|
+
(await writeable).write(this.toKeyValue(value));
|
|
125
|
+
(await writeable).close();
|
|
394
126
|
}
|
|
395
127
|
async delete(key) {
|
|
396
|
-
return
|
|
128
|
+
return this.db.removeEntry(this.toKeyPath(key));
|
|
397
129
|
}
|
|
398
130
|
async clear() {
|
|
399
|
-
|
|
131
|
+
for await (const key of this.db.keys()) {
|
|
132
|
+
await this.db.removeEntry(key);
|
|
133
|
+
}
|
|
400
134
|
}
|
|
401
135
|
async values(limit = -1) {
|
|
402
136
|
const values = [];
|
|
403
|
-
const
|
|
404
|
-
|
|
405
|
-
values.push(cursor.value);
|
|
137
|
+
for await (const cursor of this.db.values()) {
|
|
138
|
+
values.push(cursor);
|
|
406
139
|
if (limit && values.length === limit)
|
|
407
140
|
return values;
|
|
408
141
|
}
|
|
@@ -410,16 +143,15 @@ class BrowerStore {
|
|
|
410
143
|
}
|
|
411
144
|
async keys(limit = -1) {
|
|
412
145
|
const keys = [];
|
|
413
|
-
const
|
|
414
|
-
|
|
415
|
-
keys.push(cursor.key);
|
|
146
|
+
for await (const cursor of this.db.keys()) {
|
|
147
|
+
keys.push(cursor);
|
|
416
148
|
if (limit && keys.length === limit)
|
|
417
149
|
return keys;
|
|
418
150
|
}
|
|
419
151
|
return keys;
|
|
420
152
|
}
|
|
421
153
|
async iterate() {
|
|
422
|
-
return
|
|
154
|
+
return this.db.entries();
|
|
423
155
|
}
|
|
424
156
|
}
|
|
425
157
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { L as LittlePubSub } from './node-browser-
|
|
1
|
+
import { L as LittlePubSub } from './node-browser-TcXF8FDB.js';
|
|
2
2
|
import './_polyfill-node.child_process-rc1HO9Xs.js';
|
|
3
3
|
|
|
4
4
|
class Api {
|
|
@@ -206,7 +206,7 @@ class SocketRequestClient {
|
|
|
206
206
|
const init = async () => {
|
|
207
207
|
// @ts-ignore
|
|
208
208
|
if (!globalThis.WebSocket)
|
|
209
|
-
globalThis.WebSocket = (await import('./browser-
|
|
209
|
+
globalThis.WebSocket = (await import('./browser-Ei0BXMlu-irDJ6Blw.js').then(function (n) { return n.b; })).default.w3cwebsocket;
|
|
210
210
|
const client = new WebSocket(this.#url, this.#protocol);
|
|
211
211
|
client.onmessage = this.onmessage;
|
|
212
212
|
client.onerror = this.onerror;
|
|
@@ -280,7 +280,7 @@ const iceServers = [
|
|
|
280
280
|
credential: 'openrelayproject'
|
|
281
281
|
}
|
|
282
282
|
];
|
|
283
|
-
const SimplePeer = (await import('./index-
|
|
283
|
+
const SimplePeer = (await import('./index-YQrIDBUQ-OXiMI4eT.js').then(function (n) { return n.i; })).default;
|
|
284
284
|
class Peer extends SimplePeer {
|
|
285
285
|
peerId;
|
|
286
286
|
channelName;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as inherits_browserExports, c as commonjsGlobal, g as getDefaultExportFromCjs, r as require$$3 } from './node-browser-
|
|
1
|
+
import { i as inherits_browserExports, c as commonjsGlobal, g as getDefaultExportFromCjs, r as require$$3 } from './node-browser-TcXF8FDB.js';
|
|
2
2
|
import './_polyfill-node.child_process-rc1HO9Xs.js';
|
|
3
3
|
|
|
4
4
|
var browser$2 = {exports: {}};
|