@leofcoin/peernet 1.1.49 → 1.1.51
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-store.js +58 -141
- package/exports/browser/client-3221a5d7.js +17580 -0
- package/exports/browser/dht/dht.d.ts +29 -7
- package/exports/browser/identity.d.ts +15 -0
- package/exports/browser/{index-5f6ba5a4.js → index-36ed3c80.js} +2 -2
- package/exports/browser/{messages-5569e6ce.js → messages-b7f50660.js} +2 -2
- package/exports/browser/{peernet-9c2a381a.js → peernet-1b30b405.js} +433 -532
- package/exports/browser/peernet.d.ts +25 -32
- package/exports/browser/peernet.js +2 -2
- package/exports/browser/types.d.ts +16 -0
- package/exports/browser/value-4e80eeeb.js +73 -0
- package/exports/peernet.js +36 -35
- package/exports/store.js +117 -193
- package/exports/types/dht/dht.d.ts +29 -7
- package/exports/types/identity.d.ts +15 -0
- package/exports/types/peernet.d.ts +25 -32
- package/exports/types/types.d.ts +16 -0
- package/package.json +2 -2
- package/src/dht/dht.ts +36 -16
- package/src/peernet.ts +48 -61
- package/src/types.ts +28 -0
- package/exports/browser/client-6072af1a.js +0 -41092
- package/exports/browser/value-157ab062.js +0 -64
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { K as KeyValue } from './value-
|
|
1
|
+
import { K as KeyPath, a as KeyValue } from './value-4e80eeeb.js';
|
|
2
2
|
|
|
3
3
|
const instanceOfAny = (object, constructors) => constructors.some((c) => object instanceof c);
|
|
4
4
|
|
|
@@ -315,149 +315,66 @@ replaceTraps((oldTraps) => ({
|
|
|
315
315
|
},
|
|
316
316
|
}));
|
|
317
317
|
|
|
318
|
-
// import base32 from '@vandeurenglenn/base32'
|
|
319
|
-
// import base58 from '@vandeurenglenn/base58'
|
|
320
|
-
|
|
321
|
-
// export const encodings = {
|
|
322
|
-
// base58,
|
|
323
|
-
// base32
|
|
324
|
-
// }
|
|
325
|
-
|
|
326
|
-
const encode = (string, encoding = 'utf-8') => {
|
|
327
|
-
if (typeof string === 'string') {
|
|
328
|
-
let encoded;
|
|
329
|
-
|
|
330
|
-
// if (encodings[encoding]) encoded = encodings[encoding].encode(encoded)
|
|
331
|
-
encoded = new TextEncoder().encode(string);
|
|
332
|
-
return encoded
|
|
333
|
-
}
|
|
334
|
-
throw Error(`expected typeof String instead got ${string}`)
|
|
335
|
-
};
|
|
336
|
-
|
|
337
|
-
const decode = (uint8Array, encoding) => {
|
|
338
|
-
if (uint8Array instanceof Uint8Array) {
|
|
339
|
-
let decoded;
|
|
340
|
-
// if (encodings[encoding]) decoded = encodings[encoding].decode(decoded)
|
|
341
|
-
decoded = new TextDecoder().decode(uint8Array);
|
|
342
|
-
|
|
343
|
-
return decoded
|
|
344
|
-
}
|
|
345
|
-
throw Error(`expected typeof uint8Array instead got ${uint8Array}`)
|
|
346
|
-
};
|
|
347
|
-
|
|
348
|
-
const pathSepS = '/';
|
|
349
|
-
class KeyPath {
|
|
350
|
-
|
|
351
|
-
/**
|
|
352
|
-
* @param {string | Uint8Array} input
|
|
353
|
-
*/
|
|
354
|
-
constructor(input) {
|
|
355
|
-
if (typeof input === 'string') {
|
|
356
|
-
this.uint8Array = encode(input);
|
|
357
|
-
} else if (input instanceof Uint8Array) {
|
|
358
|
-
this.uint8Array = input;
|
|
359
|
-
} else if (input instanceof KeyPath) {
|
|
360
|
-
this.uint8Array = input.uint8Array;
|
|
361
|
-
} else {
|
|
362
|
-
throw new Error('Invalid keyPath, should be a String, Uint8Array or KeyPath')
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
isKeyPath() {
|
|
367
|
-
return true
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* Convert to the string representation
|
|
372
|
-
*
|
|
373
|
-
* @param {import('uint8arrays/to-string').SupportedEncodings} [encoding='utf8'] - The encoding to use.
|
|
374
|
-
* @returns {string}
|
|
375
|
-
*/
|
|
376
|
-
toString(encoding = 'hex') {
|
|
377
|
-
return decode(this.uint8Array)
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
/**
|
|
381
|
-
* Returns the `list` representation of this path.
|
|
382
|
-
*
|
|
383
|
-
* @returns string[]
|
|
384
|
-
*
|
|
385
|
-
* @example
|
|
386
|
-
* ```js
|
|
387
|
-
* new Key('/Comedy/MontyPython/Actor:JohnCleese').list()
|
|
388
|
-
* // => ['Comedy', 'MontyPythong', 'Actor:JohnCleese']
|
|
389
|
-
* ```
|
|
390
|
-
*/
|
|
391
|
-
list() {
|
|
392
|
-
return this.toString().split(pathSepS).slice(1)
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
}
|
|
396
|
-
|
|
397
318
|
class BrowerStore {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
return key.toString('base32')
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
toKeyValue(value) {
|
|
415
|
-
if (!value.isKeyValue()) value = new KeyValue(value);
|
|
416
|
-
return value.uint8Array
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
async get(key) {
|
|
420
|
-
return (await this.db).get(this.name, this.toKeyPath(key))
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
async put(key, value) {
|
|
424
|
-
return (await this.db).put(this.name, this.toKeyValue(value), this.toKeyPath(key))
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
async delete(key) {
|
|
428
|
-
return (await this.db).delete(this.name, this.toKeyPath(key))
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
async clear() {
|
|
432
|
-
return (await this.db).clear(this.name)
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
async values(limit = -1) {
|
|
436
|
-
const values = [];
|
|
437
|
-
const tx = (await this.db).transaction(this.name);
|
|
438
|
-
|
|
439
|
-
for await (const cursor of tx.store) {
|
|
440
|
-
values.push(cursor.value);
|
|
441
|
-
if (limit && values.length === limit) return values
|
|
319
|
+
db;
|
|
320
|
+
name;
|
|
321
|
+
root;
|
|
322
|
+
version;
|
|
323
|
+
constructor(name = 'storage', root = '.leofcoin', version = '1') {
|
|
324
|
+
this.version = version;
|
|
325
|
+
this.name = name;
|
|
326
|
+
this.root = root;
|
|
327
|
+
this.db = openDB(`${root}/${name}`, Number(version), {
|
|
328
|
+
upgrade(db) {
|
|
329
|
+
db.createObjectStore(name);
|
|
330
|
+
}
|
|
331
|
+
});
|
|
442
332
|
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
333
|
+
toKeyPath(key) {
|
|
334
|
+
if (!key.isKeyPath())
|
|
335
|
+
key = new KeyPath(key);
|
|
336
|
+
return key.toString('base32');
|
|
337
|
+
}
|
|
338
|
+
toKeyValue(value) {
|
|
339
|
+
if (!value.isKeyValue())
|
|
340
|
+
value = new KeyValue(value);
|
|
341
|
+
return value.uint8Array;
|
|
342
|
+
}
|
|
343
|
+
async get(key) {
|
|
344
|
+
return (await this.db).get(this.name, this.toKeyPath(key));
|
|
345
|
+
}
|
|
346
|
+
async put(key, value) {
|
|
347
|
+
return (await this.db).put(this.name, this.toKeyValue(value), this.toKeyPath(key));
|
|
348
|
+
}
|
|
349
|
+
async delete(key) {
|
|
350
|
+
return (await this.db).delete(this.name, this.toKeyPath(key));
|
|
351
|
+
}
|
|
352
|
+
async clear() {
|
|
353
|
+
return (await this.db).clear(this.name);
|
|
354
|
+
}
|
|
355
|
+
async values(limit = -1) {
|
|
356
|
+
const values = [];
|
|
357
|
+
const tx = (await this.db).transaction(this.name);
|
|
358
|
+
for await (const cursor of tx.store) {
|
|
359
|
+
values.push(cursor.value);
|
|
360
|
+
if (limit && values.length === limit)
|
|
361
|
+
return values;
|
|
362
|
+
}
|
|
363
|
+
return values;
|
|
364
|
+
}
|
|
365
|
+
async keys(limit = -1) {
|
|
366
|
+
const keys = [];
|
|
367
|
+
const tx = (await this.db).transaction(this.name);
|
|
368
|
+
for await (const cursor of tx.store) {
|
|
369
|
+
keys.push(cursor.key);
|
|
370
|
+
if (limit && keys.length === limit)
|
|
371
|
+
return keys;
|
|
372
|
+
}
|
|
373
|
+
return keys;
|
|
374
|
+
}
|
|
375
|
+
async iterate() {
|
|
376
|
+
return (await this.db).transaction(this.name).store;
|
|
453
377
|
}
|
|
454
|
-
return keys
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
async iterate() {
|
|
458
|
-
return (await this.db).transaction(this.name).store
|
|
459
|
-
}
|
|
460
|
-
|
|
461
378
|
}
|
|
462
379
|
|
|
463
380
|
export { BrowerStore as default };
|