@leofcoin/peernet 1.1.76 → 1.1.77
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.js → browser-Ei0BXMlu.js} +1 -1
- package/exports/browser/browser-store.js +40 -308
- package/exports/browser/{client-UOCjJBGl.js → client-A009z8av.js} +3 -3
- package/exports/browser/identity.d.ts +1 -1
- package/exports/browser/{index-ub31QSed.js → index-G74WLzL7.js} +1 -1
- package/exports/browser/{index-K4Kwju30.js → index-YQrIDBUQ.js} +1 -1
- package/exports/browser/{messages-guyZfse6.js → messages-lWRTai7t.js} +1 -1
- package/exports/browser/{peernet-haqFwGMk.js → peernet-dyeDQR4X.js} +617 -615
- package/exports/browser/peernet.d.ts +7 -7
- package/exports/browser/peernet.js +1 -1
- package/exports/store.js +22 -10
- package/exports/types/identity.d.ts +1 -1
- package/exports/types/peernet.d.ts +7 -7
- package/package.json +1 -1
|
@@ -1,309 +1,27 @@
|
|
|
1
1
|
import { K as KeyPath, a as KeyValue } from './value-wzPYMxsX.js';
|
|
2
2
|
|
|
3
|
-
const
|
|
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 transactionDoneMap = 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
|
-
// This mapping exists in reverseTransformCache but doesn't doesn't exist in transformCache. This
|
|
48
|
-
// is because we create many promises from a single IDBRequest.
|
|
49
|
-
reverseTransformCache.set(promise, request);
|
|
50
|
-
return promise;
|
|
51
|
-
}
|
|
52
|
-
function cacheDonePromiseForTransaction(tx) {
|
|
53
|
-
// Early bail if we've already created a done promise for this transaction.
|
|
54
|
-
if (transactionDoneMap.has(tx))
|
|
55
|
-
return;
|
|
56
|
-
const done = new Promise((resolve, reject) => {
|
|
57
|
-
const unlisten = () => {
|
|
58
|
-
tx.removeEventListener('complete', complete);
|
|
59
|
-
tx.removeEventListener('error', error);
|
|
60
|
-
tx.removeEventListener('abort', error);
|
|
61
|
-
};
|
|
62
|
-
const complete = () => {
|
|
63
|
-
resolve();
|
|
64
|
-
unlisten();
|
|
65
|
-
};
|
|
66
|
-
const error = () => {
|
|
67
|
-
reject(tx.error || new DOMException('AbortError', 'AbortError'));
|
|
68
|
-
unlisten();
|
|
69
|
-
};
|
|
70
|
-
tx.addEventListener('complete', complete);
|
|
71
|
-
tx.addEventListener('error', error);
|
|
72
|
-
tx.addEventListener('abort', error);
|
|
73
|
-
});
|
|
74
|
-
// Cache it for later retrieval.
|
|
75
|
-
transactionDoneMap.set(tx, done);
|
|
76
|
-
}
|
|
77
|
-
let idbProxyTraps = {
|
|
78
|
-
get(target, prop, receiver) {
|
|
79
|
-
if (target instanceof IDBTransaction) {
|
|
80
|
-
// Special handling for transaction.done.
|
|
81
|
-
if (prop === 'done')
|
|
82
|
-
return transactionDoneMap.get(target);
|
|
83
|
-
// Make tx.store return the only store in the transaction, or undefined if there are many.
|
|
84
|
-
if (prop === 'store') {
|
|
85
|
-
return receiver.objectStoreNames[1]
|
|
86
|
-
? undefined
|
|
87
|
-
: receiver.objectStore(receiver.objectStoreNames[0]);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
// Else transform whatever we get back.
|
|
91
|
-
return wrap(target[prop]);
|
|
92
|
-
},
|
|
93
|
-
set(target, prop, value) {
|
|
94
|
-
target[prop] = value;
|
|
95
|
-
return true;
|
|
96
|
-
},
|
|
97
|
-
has(target, prop) {
|
|
98
|
-
if (target instanceof IDBTransaction &&
|
|
99
|
-
(prop === 'done' || prop === 'store')) {
|
|
100
|
-
return true;
|
|
101
|
-
}
|
|
102
|
-
return prop in target;
|
|
103
|
-
},
|
|
104
|
-
};
|
|
105
|
-
function replaceTraps(callback) {
|
|
106
|
-
idbProxyTraps = callback(idbProxyTraps);
|
|
107
|
-
}
|
|
108
|
-
function wrapFunction(func) {
|
|
109
|
-
// Due to expected object equality (which is enforced by the caching in `wrap`), we
|
|
110
|
-
// only create one new func per func.
|
|
111
|
-
// Cursor methods are special, as the behaviour is a little more different to standard IDB. In
|
|
112
|
-
// IDB, you advance the cursor and wait for a new 'success' on the IDBRequest that gave you the
|
|
113
|
-
// cursor. It's kinda like a promise that can resolve with many values. That doesn't make sense
|
|
114
|
-
// with real promises, so each advance methods returns a new promise for the cursor object, or
|
|
115
|
-
// undefined if the end of the cursor has been reached.
|
|
116
|
-
if (getCursorAdvanceMethods().includes(func)) {
|
|
117
|
-
return function (...args) {
|
|
118
|
-
// Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
|
|
119
|
-
// the original object.
|
|
120
|
-
func.apply(unwrap(this), args);
|
|
121
|
-
return wrap(this.request);
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
return function (...args) {
|
|
125
|
-
// Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
|
|
126
|
-
// the original object.
|
|
127
|
-
return wrap(func.apply(unwrap(this), args));
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
function transformCachableValue(value) {
|
|
131
|
-
if (typeof value === 'function')
|
|
132
|
-
return wrapFunction(value);
|
|
133
|
-
// This doesn't return, it just creates a 'done' promise for the transaction,
|
|
134
|
-
// which is later returned for transaction.done (see idbObjectHandler).
|
|
135
|
-
if (value instanceof IDBTransaction)
|
|
136
|
-
cacheDonePromiseForTransaction(value);
|
|
137
|
-
if (instanceOfAny(value, getIdbProxyableTypes()))
|
|
138
|
-
return new Proxy(value, idbProxyTraps);
|
|
139
|
-
// Return the same value back if we're not going to transform it.
|
|
140
|
-
return value;
|
|
141
|
-
}
|
|
142
|
-
function wrap(value) {
|
|
143
|
-
// We sometimes generate multiple promises from a single IDBRequest (eg when cursoring), because
|
|
144
|
-
// IDB is weird and a single IDBRequest can yield many responses, so these can't be cached.
|
|
145
|
-
if (value instanceof IDBRequest)
|
|
146
|
-
return promisifyRequest(value);
|
|
147
|
-
// If we've already transformed this value before, reuse the transformed value.
|
|
148
|
-
// This is faster, but it also provides object equality.
|
|
149
|
-
if (transformCache.has(value))
|
|
150
|
-
return transformCache.get(value);
|
|
151
|
-
const newValue = transformCachableValue(value);
|
|
152
|
-
// Not all types are transformed.
|
|
153
|
-
// These may be primitive types, so they can't be WeakMap keys.
|
|
154
|
-
if (newValue !== value) {
|
|
155
|
-
transformCache.set(value, newValue);
|
|
156
|
-
reverseTransformCache.set(newValue, value);
|
|
157
|
-
}
|
|
158
|
-
return newValue;
|
|
159
|
-
}
|
|
160
|
-
const unwrap = (value) => reverseTransformCache.get(value);
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Open a database.
|
|
164
|
-
*
|
|
165
|
-
* @param name Name of the database.
|
|
166
|
-
* @param version Schema version.
|
|
167
|
-
* @param callbacks Additional callbacks.
|
|
168
|
-
*/
|
|
169
|
-
function openDB(name, version, { blocked, upgrade, blocking, terminated } = {}) {
|
|
170
|
-
const request = indexedDB.open(name, version);
|
|
171
|
-
const openPromise = wrap(request);
|
|
172
|
-
if (upgrade) {
|
|
173
|
-
request.addEventListener('upgradeneeded', (event) => {
|
|
174
|
-
upgrade(wrap(request.result), event.oldVersion, event.newVersion, wrap(request.transaction), event);
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
if (blocked) {
|
|
178
|
-
request.addEventListener('blocked', (event) => blocked(
|
|
179
|
-
// Casting due to https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/1405
|
|
180
|
-
event.oldVersion, event.newVersion, event));
|
|
181
|
-
}
|
|
182
|
-
openPromise
|
|
183
|
-
.then((db) => {
|
|
184
|
-
if (terminated)
|
|
185
|
-
db.addEventListener('close', () => terminated());
|
|
186
|
-
if (blocking) {
|
|
187
|
-
db.addEventListener('versionchange', (event) => blocking(event.oldVersion, event.newVersion, event));
|
|
188
|
-
}
|
|
189
|
-
})
|
|
190
|
-
.catch(() => { });
|
|
191
|
-
return openPromise;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
const readMethods = ['get', 'getKey', 'getAll', 'getAllKeys', 'count'];
|
|
195
|
-
const writeMethods = ['put', 'add', 'delete', 'clear'];
|
|
196
|
-
const cachedMethods = new Map();
|
|
197
|
-
function getMethod(target, prop) {
|
|
198
|
-
if (!(target instanceof IDBDatabase &&
|
|
199
|
-
!(prop in target) &&
|
|
200
|
-
typeof prop === 'string')) {
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
if (cachedMethods.get(prop))
|
|
204
|
-
return cachedMethods.get(prop);
|
|
205
|
-
const targetFuncName = prop.replace(/FromIndex$/, '');
|
|
206
|
-
const useIndex = prop !== targetFuncName;
|
|
207
|
-
const isWrite = writeMethods.includes(targetFuncName);
|
|
208
|
-
if (
|
|
209
|
-
// Bail if the target doesn't exist on the target. Eg, getAll isn't in Edge.
|
|
210
|
-
!(targetFuncName in (useIndex ? IDBIndex : IDBObjectStore).prototype) ||
|
|
211
|
-
!(isWrite || readMethods.includes(targetFuncName))) {
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
const method = async function (storeName, ...args) {
|
|
215
|
-
// isWrite ? 'readwrite' : undefined gzipps better, but fails in Edge :(
|
|
216
|
-
const tx = this.transaction(storeName, isWrite ? 'readwrite' : 'readonly');
|
|
217
|
-
let target = tx.store;
|
|
218
|
-
if (useIndex)
|
|
219
|
-
target = target.index(args.shift());
|
|
220
|
-
// Must reject if op rejects.
|
|
221
|
-
// If it's a write operation, must reject if tx.done rejects.
|
|
222
|
-
// Must reject with op rejection first.
|
|
223
|
-
// Must resolve with op value.
|
|
224
|
-
// Must handle both promises (no unhandled rejections)
|
|
225
|
-
return (await Promise.all([
|
|
226
|
-
target[targetFuncName](...args),
|
|
227
|
-
isWrite && tx.done,
|
|
228
|
-
]))[0];
|
|
229
|
-
};
|
|
230
|
-
cachedMethods.set(prop, method);
|
|
231
|
-
return method;
|
|
232
|
-
}
|
|
233
|
-
replaceTraps((oldTraps) => ({
|
|
234
|
-
...oldTraps,
|
|
235
|
-
get: (target, prop, receiver) => getMethod(target, prop) || oldTraps.get(target, prop, receiver),
|
|
236
|
-
has: (target, prop) => !!getMethod(target, prop) || oldTraps.has(target, prop),
|
|
237
|
-
}));
|
|
238
|
-
|
|
239
|
-
const advanceMethodProps = ['continue', 'continuePrimaryKey', 'advance'];
|
|
240
|
-
const methodMap = {};
|
|
241
|
-
const advanceResults = new WeakMap();
|
|
242
|
-
const ittrProxiedCursorToOriginalProxy = new WeakMap();
|
|
243
|
-
const cursorIteratorTraps = {
|
|
244
|
-
get(target, prop) {
|
|
245
|
-
if (!advanceMethodProps.includes(prop))
|
|
246
|
-
return target[prop];
|
|
247
|
-
let cachedFunc = methodMap[prop];
|
|
248
|
-
if (!cachedFunc) {
|
|
249
|
-
cachedFunc = methodMap[prop] = function (...args) {
|
|
250
|
-
advanceResults.set(this, ittrProxiedCursorToOriginalProxy.get(this)[prop](...args));
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
return cachedFunc;
|
|
254
|
-
},
|
|
255
|
-
};
|
|
256
|
-
async function* iterate(...args) {
|
|
257
|
-
// tslint:disable-next-line:no-this-assignment
|
|
258
|
-
let cursor = this;
|
|
259
|
-
if (!(cursor instanceof IDBCursor)) {
|
|
260
|
-
cursor = await cursor.openCursor(...args);
|
|
261
|
-
}
|
|
262
|
-
if (!cursor)
|
|
263
|
-
return;
|
|
264
|
-
cursor = cursor;
|
|
265
|
-
const proxiedCursor = new Proxy(cursor, cursorIteratorTraps);
|
|
266
|
-
ittrProxiedCursorToOriginalProxy.set(proxiedCursor, cursor);
|
|
267
|
-
// Map this double-proxy back to the original, so other cursor methods work.
|
|
268
|
-
reverseTransformCache.set(proxiedCursor, unwrap(cursor));
|
|
269
|
-
while (cursor) {
|
|
270
|
-
yield proxiedCursor;
|
|
271
|
-
// If one of the advancing methods was not called, call continue().
|
|
272
|
-
cursor = await (advanceResults.get(proxiedCursor) || cursor.continue());
|
|
273
|
-
advanceResults.delete(proxiedCursor);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
function isIteratorProp(target, prop) {
|
|
277
|
-
return ((prop === Symbol.asyncIterator &&
|
|
278
|
-
instanceOfAny(target, [IDBIndex, IDBObjectStore, IDBCursor])) ||
|
|
279
|
-
(prop === 'iterate' && instanceOfAny(target, [IDBIndex, IDBObjectStore])));
|
|
280
|
-
}
|
|
281
|
-
replaceTraps((oldTraps) => ({
|
|
282
|
-
...oldTraps,
|
|
283
|
-
get(target, prop, receiver) {
|
|
284
|
-
if (isIteratorProp(target, prop))
|
|
285
|
-
return iterate;
|
|
286
|
-
return oldTraps.get(target, prop, receiver);
|
|
287
|
-
},
|
|
288
|
-
has(target, prop) {
|
|
289
|
-
return isIteratorProp(target, prop) || oldTraps.has(target, prop);
|
|
290
|
-
},
|
|
291
|
-
}));
|
|
292
|
-
|
|
3
|
+
const opfsRoot = await navigator.storage.getDirectory();
|
|
293
4
|
class BrowerStore {
|
|
294
5
|
db;
|
|
295
6
|
name;
|
|
296
7
|
root;
|
|
297
8
|
version;
|
|
298
|
-
init(name = 'storage', root = '.leofcoin', version = '1') {
|
|
9
|
+
async init(name = 'storage', root = '.leofcoin', version = '1') {
|
|
10
|
+
console.log('init');
|
|
299
11
|
this.version = version;
|
|
300
12
|
this.name = name;
|
|
301
|
-
this.root =
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
13
|
+
this.root = opfsRoot;
|
|
14
|
+
console.log(`${this.root}/${this.name}`);
|
|
15
|
+
let directoryHandle;
|
|
16
|
+
try {
|
|
17
|
+
directoryHandle = await opfsRoot.getDirectoryHandle(this.name, {
|
|
18
|
+
create: true
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
console.error(error);
|
|
23
|
+
}
|
|
24
|
+
this.db = directoryHandle;
|
|
307
25
|
}
|
|
308
26
|
toKeyPath(key) {
|
|
309
27
|
if (key instanceof KeyPath)
|
|
@@ -316,23 +34,38 @@ class BrowerStore {
|
|
|
316
34
|
// @ts-ignore
|
|
317
35
|
return value.uint8Array;
|
|
318
36
|
}
|
|
37
|
+
async has(key) {
|
|
38
|
+
try {
|
|
39
|
+
await this.db.getFileHandle(this.toKeyPath(key));
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
319
46
|
async get(key) {
|
|
320
|
-
|
|
47
|
+
const handle = await this.db.getFileHandle(this.toKeyPath(key));
|
|
48
|
+
const file = await handle.getFile();
|
|
49
|
+
return new Uint8Array(await file.arrayBuffer());
|
|
321
50
|
}
|
|
322
51
|
async put(key, value) {
|
|
323
|
-
|
|
52
|
+
const handle = await this.db.getFileHandle(this.toKeyPath(key), { create: true });
|
|
53
|
+
const writeable = handle.createWritable();
|
|
54
|
+
(await writeable).write(this.toKeyValue(value));
|
|
55
|
+
(await writeable).close();
|
|
324
56
|
}
|
|
325
57
|
async delete(key) {
|
|
326
|
-
return
|
|
58
|
+
return this.db.removeEntry(this.toKeyPath(key));
|
|
327
59
|
}
|
|
328
60
|
async clear() {
|
|
329
|
-
|
|
61
|
+
for await (const key of this.db.keys()) {
|
|
62
|
+
await this.db.removeEntry(key);
|
|
63
|
+
}
|
|
330
64
|
}
|
|
331
65
|
async values(limit = -1) {
|
|
332
66
|
const values = [];
|
|
333
|
-
const
|
|
334
|
-
|
|
335
|
-
values.push(cursor.value);
|
|
67
|
+
for await (const cursor of this.db.values()) {
|
|
68
|
+
values.push(cursor);
|
|
336
69
|
if (limit && values.length === limit)
|
|
337
70
|
return values;
|
|
338
71
|
}
|
|
@@ -340,16 +73,15 @@ class BrowerStore {
|
|
|
340
73
|
}
|
|
341
74
|
async keys(limit = -1) {
|
|
342
75
|
const keys = [];
|
|
343
|
-
const
|
|
344
|
-
|
|
345
|
-
keys.push(cursor.key);
|
|
76
|
+
for await (const cursor of this.db.keys()) {
|
|
77
|
+
keys.push(cursor);
|
|
346
78
|
if (limit && keys.length === limit)
|
|
347
79
|
return keys;
|
|
348
80
|
}
|
|
349
81
|
return keys;
|
|
350
82
|
}
|
|
351
83
|
async iterate() {
|
|
352
|
-
return
|
|
84
|
+
return this.db.entries();
|
|
353
85
|
}
|
|
354
86
|
}
|
|
355
87
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { L as LittlePubSub } from './peernet-
|
|
1
|
+
import { L as LittlePubSub } from './peernet-dyeDQR4X.js';
|
|
2
2
|
import './value-wzPYMxsX.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.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.js').then(function (n) { return n.i; })).default;
|
|
284
284
|
class Peer extends SimplePeer {
|
|
285
285
|
peerId;
|
|
286
286
|
channelName;
|
|
@@ -8,7 +8,7 @@ export default class Identity {
|
|
|
8
8
|
get accounts(): Promise<[[name: string, externalAddress: string, internalAddress: string]]>;
|
|
9
9
|
getAccounts(): Promise<[[name: string, externalAddress: string, internalAddress: string]]>;
|
|
10
10
|
load(password?: string): Promise<void>;
|
|
11
|
-
selectAccount(account: string): Promise<void> | Promise<
|
|
11
|
+
selectAccount(account: string): Promise<void> | Promise<any[]>;
|
|
12
12
|
sign(hash: Uint8Array): any;
|
|
13
13
|
lock(password: string): void;
|
|
14
14
|
unlock(password: string): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as commonjsGlobal, r as require$$3, i as inherits_browserExports, g as getDefaultExportFromCjs } from './peernet-
|
|
1
|
+
import { c as commonjsGlobal, r as require$$3, i as inherits_browserExports, g as getDefaultExportFromCjs } from './peernet-dyeDQR4X.js';
|
|
2
2
|
|
|
3
3
|
var browser$2 = {exports: {}};
|
|
4
4
|
|