@fireproof/core 0.10.0-dev → 0.10.1-dev

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. package/package.json +5 -1
  2. package/.eslintrc.cjs +0 -37
  3. package/.vscode/launch.json +0 -12
  4. package/dist/crdt-helpers.browser.js +0 -4961
  5. package/dist/crdt-helpers.browser.js.map +0 -7
  6. package/dist/crdt-helpers.cjs.js +0 -4823
  7. package/dist/crdt-helpers.cjs.js.map +0 -7
  8. package/dist/crdt-helpers.esm.js +0 -4788
  9. package/dist/crdt-helpers.esm.js.map +0 -7
  10. package/dist/crdt.browser.js +0 -18214
  11. package/dist/crdt.browser.js.map +0 -7
  12. package/dist/crdt.cjs.js +0 -8692
  13. package/dist/crdt.cjs.js.map +0 -7
  14. package/dist/crdt.esm.js +0 -8682
  15. package/dist/crdt.esm.js.map +0 -7
  16. package/dist/database.browser.js +0 -18867
  17. package/dist/database.browser.js.map +0 -7
  18. package/dist/database.cjs.js +0 -9296
  19. package/dist/database.cjs.js.map +0 -7
  20. package/dist/database.esm.js +0 -9288
  21. package/dist/database.esm.js.map +0 -7
  22. package/dist/loader-helpers.browser.js +0 -6943
  23. package/dist/loader-helpers.browser.js.map +0 -7
  24. package/dist/loader-helpers.cjs.js +0 -4419
  25. package/dist/loader-helpers.cjs.js.map +0 -7
  26. package/dist/loader-helpers.esm.js +0 -4408
  27. package/dist/loader-helpers.esm.js.map +0 -7
  28. package/dist/loader.browser.js +0 -15968
  29. package/dist/loader.browser.js.map +0 -7
  30. package/dist/loader.cjs.js +0 -6667
  31. package/dist/loader.cjs.js.map +0 -7
  32. package/dist/loader.esm.js +0 -6657
  33. package/dist/loader.esm.js.map +0 -7
  34. package/dist/store-browser.browser.js +0 -1414
  35. package/dist/store-browser.browser.js.map +0 -7
  36. package/dist/store-browser.cjs.js +0 -1387
  37. package/dist/store-browser.cjs.js.map +0 -7
  38. package/dist/store-browser.esm.js +0 -1358
  39. package/dist/store-browser.esm.js.map +0 -7
  40. package/dist/store-fs.browser.js +0 -16142
  41. package/dist/store-fs.browser.js.map +0 -7
  42. package/dist/store-fs.cjs.js +0 -1171
  43. package/dist/store-fs.cjs.js.map +0 -7
  44. package/dist/store-fs.esm.js +0 -1143
  45. package/dist/store-fs.esm.js.map +0 -7
  46. package/dist/store.browser.js +0 -1113
  47. package/dist/store.browser.js.map +0 -7
  48. package/dist/store.cjs.js +0 -1126
  49. package/dist/store.cjs.js.map +0 -7
  50. package/dist/store.esm.js +0 -1097
  51. package/dist/store.esm.js.map +0 -7
  52. package/dist/transaction.browser.js +0 -17241
  53. package/dist/transaction.browser.js.map +0 -7
  54. package/dist/transaction.cjs.js +0 -7842
  55. package/dist/transaction.cjs.js.map +0 -7
  56. package/dist/transaction.esm.js +0 -7831
  57. package/dist/transaction.esm.js.map +0 -7
  58. package/dist/types.d.browser.js +0 -4
  59. package/dist/types.d.browser.js.map +0 -7
  60. package/dist/types.d.cjs.js +0 -19
  61. package/dist/types.d.cjs.js.map +0 -7
  62. package/dist/types.d.esm.js +0 -1
  63. package/dist/types.d.esm.js.map +0 -7
  64. package/scripts/analyze.js +0 -31
  65. package/scripts/build.js +0 -20
  66. package/scripts/serve.js +0 -20
  67. package/scripts/settings.js +0 -65
  68. package/scripts/test.js +0 -14
  69. package/src/crdt-helpers.ts +0 -89
  70. package/src/crdt.ts +0 -45
  71. package/src/database.ts +0 -61
  72. package/src/fireproof.ts +0 -6
  73. package/src/loader-helpers.ts +0 -53
  74. package/src/loader.ts +0 -66
  75. package/src/store-browser.ts +0 -76
  76. package/src/store-fs.ts +0 -51
  77. package/src/store.ts +0 -32
  78. package/src/transaction.ts +0 -68
  79. package/src/types.d.ts +0 -38
  80. package/test/crdt.test.js +0 -142
  81. package/test/database.test.js +0 -144
  82. package/test/fireproof.test.js +0 -50
  83. package/test/globals.d.ts +0 -4
  84. package/test/hello.test.js +0 -9
  85. package/test/helpers.js +0 -34
  86. package/test/loader.test.js +0 -112
  87. package/test/store-fs.test.js +0 -105
  88. package/test/transaction.test.js +0 -90
  89. package/tsconfig.json +0 -18
  90. package/webpack.config.cjs +0 -17
@@ -1,1387 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from2, except, desc) => {
11
- if (from2 && typeof from2 === "object" || typeof from2 === "function") {
12
- for (let key of __getOwnPropNames(from2))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from2[key], enumerable: !(desc = __getOwnPropDesc(from2, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/store-browser.ts
21
- var store_browser_exports = {};
22
- __export(store_browser_exports, {
23
- CarStoreIDB: () => CarStoreIDB,
24
- FORMAT: () => FORMAT,
25
- HeaderStoreLS: () => HeaderStoreLS
26
- });
27
- module.exports = __toCommonJS(store_browser_exports);
28
-
29
- // node_modules/idb/build/wrap-idb-value.js
30
- var instanceOfAny = (object, constructors) => constructors.some((c) => object instanceof c);
31
- var idbProxyableTypes;
32
- var cursorAdvanceMethods;
33
- function getIdbProxyableTypes() {
34
- return idbProxyableTypes || (idbProxyableTypes = [
35
- IDBDatabase,
36
- IDBObjectStore,
37
- IDBIndex,
38
- IDBCursor,
39
- IDBTransaction
40
- ]);
41
- }
42
- function getCursorAdvanceMethods() {
43
- return cursorAdvanceMethods || (cursorAdvanceMethods = [
44
- IDBCursor.prototype.advance,
45
- IDBCursor.prototype.continue,
46
- IDBCursor.prototype.continuePrimaryKey
47
- ]);
48
- }
49
- var cursorRequestMap = /* @__PURE__ */ new WeakMap();
50
- var transactionDoneMap = /* @__PURE__ */ new WeakMap();
51
- var transactionStoreNamesMap = /* @__PURE__ */ new WeakMap();
52
- var transformCache = /* @__PURE__ */ new WeakMap();
53
- var reverseTransformCache = /* @__PURE__ */ new WeakMap();
54
- function promisifyRequest(request) {
55
- const promise = new Promise((resolve, reject) => {
56
- const unlisten = () => {
57
- request.removeEventListener("success", success);
58
- request.removeEventListener("error", error);
59
- };
60
- const success = () => {
61
- resolve(wrap(request.result));
62
- unlisten();
63
- };
64
- const error = () => {
65
- reject(request.error);
66
- unlisten();
67
- };
68
- request.addEventListener("success", success);
69
- request.addEventListener("error", error);
70
- });
71
- promise.then((value) => {
72
- if (value instanceof IDBCursor) {
73
- cursorRequestMap.set(value, request);
74
- }
75
- }).catch(() => {
76
- });
77
- reverseTransformCache.set(promise, request);
78
- return promise;
79
- }
80
- function cacheDonePromiseForTransaction(tx) {
81
- if (transactionDoneMap.has(tx))
82
- return;
83
- const done = new Promise((resolve, reject) => {
84
- const unlisten = () => {
85
- tx.removeEventListener("complete", complete);
86
- tx.removeEventListener("error", error);
87
- tx.removeEventListener("abort", error);
88
- };
89
- const complete = () => {
90
- resolve();
91
- unlisten();
92
- };
93
- const error = () => {
94
- reject(tx.error || new DOMException("AbortError", "AbortError"));
95
- unlisten();
96
- };
97
- tx.addEventListener("complete", complete);
98
- tx.addEventListener("error", error);
99
- tx.addEventListener("abort", error);
100
- });
101
- transactionDoneMap.set(tx, done);
102
- }
103
- var idbProxyTraps = {
104
- get(target, prop, receiver) {
105
- if (target instanceof IDBTransaction) {
106
- if (prop === "done")
107
- return transactionDoneMap.get(target);
108
- if (prop === "objectStoreNames") {
109
- return target.objectStoreNames || transactionStoreNamesMap.get(target);
110
- }
111
- if (prop === "store") {
112
- return receiver.objectStoreNames[1] ? void 0 : receiver.objectStore(receiver.objectStoreNames[0]);
113
- }
114
- }
115
- return wrap(target[prop]);
116
- },
117
- set(target, prop, value) {
118
- target[prop] = value;
119
- return true;
120
- },
121
- has(target, prop) {
122
- if (target instanceof IDBTransaction && (prop === "done" || prop === "store")) {
123
- return true;
124
- }
125
- return prop in target;
126
- }
127
- };
128
- function replaceTraps(callback) {
129
- idbProxyTraps = callback(idbProxyTraps);
130
- }
131
- function wrapFunction(func) {
132
- if (func === IDBDatabase.prototype.transaction && !("objectStoreNames" in IDBTransaction.prototype)) {
133
- return function(storeNames, ...args) {
134
- const tx = func.call(unwrap(this), storeNames, ...args);
135
- transactionStoreNamesMap.set(tx, storeNames.sort ? storeNames.sort() : [storeNames]);
136
- return wrap(tx);
137
- };
138
- }
139
- if (getCursorAdvanceMethods().includes(func)) {
140
- return function(...args) {
141
- func.apply(unwrap(this), args);
142
- return wrap(cursorRequestMap.get(this));
143
- };
144
- }
145
- return function(...args) {
146
- return wrap(func.apply(unwrap(this), args));
147
- };
148
- }
149
- function transformCachableValue(value) {
150
- if (typeof value === "function")
151
- return wrapFunction(value);
152
- if (value instanceof IDBTransaction)
153
- cacheDonePromiseForTransaction(value);
154
- if (instanceOfAny(value, getIdbProxyableTypes()))
155
- return new Proxy(value, idbProxyTraps);
156
- return value;
157
- }
158
- function wrap(value) {
159
- if (value instanceof IDBRequest)
160
- return promisifyRequest(value);
161
- if (transformCache.has(value))
162
- return transformCache.get(value);
163
- const newValue = transformCachableValue(value);
164
- if (newValue !== value) {
165
- transformCache.set(value, newValue);
166
- reverseTransformCache.set(newValue, value);
167
- }
168
- return newValue;
169
- }
170
- var unwrap = (value) => reverseTransformCache.get(value);
171
-
172
- // node_modules/idb/build/index.js
173
- function openDB(name, version, { blocked, upgrade, blocking, terminated } = {}) {
174
- const request = indexedDB.open(name, version);
175
- const openPromise = wrap(request);
176
- if (upgrade) {
177
- request.addEventListener("upgradeneeded", (event) => {
178
- upgrade(wrap(request.result), event.oldVersion, event.newVersion, wrap(request.transaction), event);
179
- });
180
- }
181
- if (blocked) {
182
- request.addEventListener("blocked", (event) => blocked(
183
- // Casting due to https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/1405
184
- event.oldVersion,
185
- event.newVersion,
186
- event
187
- ));
188
- }
189
- openPromise.then((db) => {
190
- if (terminated)
191
- db.addEventListener("close", () => terminated());
192
- if (blocking) {
193
- db.addEventListener("versionchange", (event) => blocking(event.oldVersion, event.newVersion, event));
194
- }
195
- }).catch(() => {
196
- });
197
- return openPromise;
198
- }
199
- var readMethods = ["get", "getKey", "getAll", "getAllKeys", "count"];
200
- var writeMethods = ["put", "add", "delete", "clear"];
201
- var cachedMethods = /* @__PURE__ */ new Map();
202
- function getMethod(target, prop) {
203
- if (!(target instanceof IDBDatabase && !(prop in target) && typeof prop === "string")) {
204
- return;
205
- }
206
- if (cachedMethods.get(prop))
207
- return cachedMethods.get(prop);
208
- const targetFuncName = prop.replace(/FromIndex$/, "");
209
- const useIndex = prop !== targetFuncName;
210
- const isWrite = writeMethods.includes(targetFuncName);
211
- if (
212
- // Bail if the target doesn't exist on the target. Eg, getAll isn't in Edge.
213
- !(targetFuncName in (useIndex ? IDBIndex : IDBObjectStore).prototype) || !(isWrite || readMethods.includes(targetFuncName))
214
- ) {
215
- return;
216
- }
217
- const method = async function(storeName, ...args) {
218
- const tx = this.transaction(storeName, isWrite ? "readwrite" : "readonly");
219
- let target2 = tx.store;
220
- if (useIndex)
221
- target2 = target2.index(args.shift());
222
- return (await Promise.all([
223
- target2[targetFuncName](...args),
224
- isWrite && tx.done
225
- ]))[0];
226
- };
227
- cachedMethods.set(prop, method);
228
- return method;
229
- }
230
- replaceTraps((oldTraps) => ({
231
- ...oldTraps,
232
- get: (target, prop, receiver) => getMethod(target, prop) || oldTraps.get(target, prop, receiver),
233
- has: (target, prop) => !!getMethod(target, prop) || oldTraps.has(target, prop)
234
- }));
235
-
236
- // node_modules/multiformats/vendor/varint.js
237
- var encode_1 = encode;
238
- var MSB = 128;
239
- var REST = 127;
240
- var MSBALL = ~REST;
241
- var INT = Math.pow(2, 31);
242
- function encode(num, out, offset) {
243
- out = out || [];
244
- offset = offset || 0;
245
- var oldOffset = offset;
246
- while (num >= INT) {
247
- out[offset++] = num & 255 | MSB;
248
- num /= 128;
249
- }
250
- while (num & MSBALL) {
251
- out[offset++] = num & 255 | MSB;
252
- num >>>= 7;
253
- }
254
- out[offset] = num | 0;
255
- encode.bytes = offset - oldOffset + 1;
256
- return out;
257
- }
258
- var decode = read;
259
- var MSB$1 = 128;
260
- var REST$1 = 127;
261
- function read(buf, offset) {
262
- var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf.length;
263
- do {
264
- if (counter >= l) {
265
- read.bytes = 0;
266
- throw new RangeError("Could not decode varint");
267
- }
268
- b = buf[counter++];
269
- res += shift < 28 ? (b & REST$1) << shift : (b & REST$1) * Math.pow(2, shift);
270
- shift += 7;
271
- } while (b >= MSB$1);
272
- read.bytes = counter - offset;
273
- return res;
274
- }
275
- var N1 = Math.pow(2, 7);
276
- var N2 = Math.pow(2, 14);
277
- var N3 = Math.pow(2, 21);
278
- var N4 = Math.pow(2, 28);
279
- var N5 = Math.pow(2, 35);
280
- var N6 = Math.pow(2, 42);
281
- var N7 = Math.pow(2, 49);
282
- var N8 = Math.pow(2, 56);
283
- var N9 = Math.pow(2, 63);
284
- var length = function(value) {
285
- return value < N1 ? 1 : value < N2 ? 2 : value < N3 ? 3 : value < N4 ? 4 : value < N5 ? 5 : value < N6 ? 6 : value < N7 ? 7 : value < N8 ? 8 : value < N9 ? 9 : 10;
286
- };
287
- var varint = {
288
- encode: encode_1,
289
- decode,
290
- encodingLength: length
291
- };
292
- var _brrp_varint = varint;
293
- var varint_default = _brrp_varint;
294
-
295
- // node_modules/multiformats/src/varint.js
296
- var decode2 = (data, offset = 0) => {
297
- const code = varint_default.decode(data, offset);
298
- return [code, varint_default.decode.bytes];
299
- };
300
- var encodeTo = (int, target, offset = 0) => {
301
- varint_default.encode(int, target, offset);
302
- return target;
303
- };
304
- var encodingLength = (int) => {
305
- return varint_default.encodingLength(int);
306
- };
307
-
308
- // node_modules/multiformats/src/bytes.js
309
- var empty = new Uint8Array(0);
310
- var equals = (aa, bb) => {
311
- if (aa === bb)
312
- return true;
313
- if (aa.byteLength !== bb.byteLength) {
314
- return false;
315
- }
316
- for (let ii = 0; ii < aa.byteLength; ii++) {
317
- if (aa[ii] !== bb[ii]) {
318
- return false;
319
- }
320
- }
321
- return true;
322
- };
323
- var coerce = (o) => {
324
- if (o instanceof Uint8Array && o.constructor.name === "Uint8Array")
325
- return o;
326
- if (o instanceof ArrayBuffer)
327
- return new Uint8Array(o);
328
- if (ArrayBuffer.isView(o)) {
329
- return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
330
- }
331
- throw new Error("Unknown type, must be binary type");
332
- };
333
-
334
- // node_modules/multiformats/src/hashes/digest.js
335
- var create = (code, digest) => {
336
- const size = digest.byteLength;
337
- const sizeOffset = encodingLength(code);
338
- const digestOffset = sizeOffset + encodingLength(size);
339
- const bytes = new Uint8Array(digestOffset + size);
340
- encodeTo(code, bytes, 0);
341
- encodeTo(size, bytes, sizeOffset);
342
- bytes.set(digest, digestOffset);
343
- return new Digest(code, size, digest, bytes);
344
- };
345
- var decode3 = (multihash) => {
346
- const bytes = coerce(multihash);
347
- const [code, sizeOffset] = decode2(bytes);
348
- const [size, digestOffset] = decode2(bytes.subarray(sizeOffset));
349
- const digest = bytes.subarray(sizeOffset + digestOffset);
350
- if (digest.byteLength !== size) {
351
- throw new Error("Incorrect length");
352
- }
353
- return new Digest(code, size, digest, bytes);
354
- };
355
- var equals2 = (a, b) => {
356
- if (a === b) {
357
- return true;
358
- } else {
359
- const data = (
360
- /** @type {{code?:unknown, size?:unknown, bytes?:unknown}} */
361
- b
362
- );
363
- return a.code === data.code && a.size === data.size && data.bytes instanceof Uint8Array && equals(a.bytes, data.bytes);
364
- }
365
- };
366
- var Digest = class {
367
- /**
368
- * Creates a multihash digest.
369
- *
370
- * @param {Code} code
371
- * @param {Size} size
372
- * @param {Uint8Array} digest
373
- * @param {Uint8Array} bytes
374
- */
375
- constructor(code, size, digest, bytes) {
376
- this.code = code;
377
- this.size = size;
378
- this.digest = digest;
379
- this.bytes = bytes;
380
- }
381
- };
382
-
383
- // node_modules/multiformats/vendor/base-x.js
384
- function base(ALPHABET, name) {
385
- if (ALPHABET.length >= 255) {
386
- throw new TypeError("Alphabet too long");
387
- }
388
- var BASE_MAP = new Uint8Array(256);
389
- for (var j = 0; j < BASE_MAP.length; j++) {
390
- BASE_MAP[j] = 255;
391
- }
392
- for (var i = 0; i < ALPHABET.length; i++) {
393
- var x = ALPHABET.charAt(i);
394
- var xc = x.charCodeAt(0);
395
- if (BASE_MAP[xc] !== 255) {
396
- throw new TypeError(x + " is ambiguous");
397
- }
398
- BASE_MAP[xc] = i;
399
- }
400
- var BASE = ALPHABET.length;
401
- var LEADER = ALPHABET.charAt(0);
402
- var FACTOR = Math.log(BASE) / Math.log(256);
403
- var iFACTOR = Math.log(256) / Math.log(BASE);
404
- function encode3(source) {
405
- if (source instanceof Uint8Array)
406
- ;
407
- else if (ArrayBuffer.isView(source)) {
408
- source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
409
- } else if (Array.isArray(source)) {
410
- source = Uint8Array.from(source);
411
- }
412
- if (!(source instanceof Uint8Array)) {
413
- throw new TypeError("Expected Uint8Array");
414
- }
415
- if (source.length === 0) {
416
- return "";
417
- }
418
- var zeroes = 0;
419
- var length2 = 0;
420
- var pbegin = 0;
421
- var pend = source.length;
422
- while (pbegin !== pend && source[pbegin] === 0) {
423
- pbegin++;
424
- zeroes++;
425
- }
426
- var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
427
- var b58 = new Uint8Array(size);
428
- while (pbegin !== pend) {
429
- var carry = source[pbegin];
430
- var i2 = 0;
431
- for (var it1 = size - 1; (carry !== 0 || i2 < length2) && it1 !== -1; it1--, i2++) {
432
- carry += 256 * b58[it1] >>> 0;
433
- b58[it1] = carry % BASE >>> 0;
434
- carry = carry / BASE >>> 0;
435
- }
436
- if (carry !== 0) {
437
- throw new Error("Non-zero carry");
438
- }
439
- length2 = i2;
440
- pbegin++;
441
- }
442
- var it2 = size - length2;
443
- while (it2 !== size && b58[it2] === 0) {
444
- it2++;
445
- }
446
- var str = LEADER.repeat(zeroes);
447
- for (; it2 < size; ++it2) {
448
- str += ALPHABET.charAt(b58[it2]);
449
- }
450
- return str;
451
- }
452
- function decodeUnsafe(source) {
453
- if (typeof source !== "string") {
454
- throw new TypeError("Expected String");
455
- }
456
- if (source.length === 0) {
457
- return new Uint8Array();
458
- }
459
- var psz = 0;
460
- if (source[psz] === " ") {
461
- return;
462
- }
463
- var zeroes = 0;
464
- var length2 = 0;
465
- while (source[psz] === LEADER) {
466
- zeroes++;
467
- psz++;
468
- }
469
- var size = (source.length - psz) * FACTOR + 1 >>> 0;
470
- var b256 = new Uint8Array(size);
471
- while (source[psz]) {
472
- var carry = BASE_MAP[source.charCodeAt(psz)];
473
- if (carry === 255) {
474
- return;
475
- }
476
- var i2 = 0;
477
- for (var it3 = size - 1; (carry !== 0 || i2 < length2) && it3 !== -1; it3--, i2++) {
478
- carry += BASE * b256[it3] >>> 0;
479
- b256[it3] = carry % 256 >>> 0;
480
- carry = carry / 256 >>> 0;
481
- }
482
- if (carry !== 0) {
483
- throw new Error("Non-zero carry");
484
- }
485
- length2 = i2;
486
- psz++;
487
- }
488
- if (source[psz] === " ") {
489
- return;
490
- }
491
- var it4 = size - length2;
492
- while (it4 !== size && b256[it4] === 0) {
493
- it4++;
494
- }
495
- var vch = new Uint8Array(zeroes + (size - it4));
496
- var j2 = zeroes;
497
- while (it4 !== size) {
498
- vch[j2++] = b256[it4++];
499
- }
500
- return vch;
501
- }
502
- function decode5(string) {
503
- var buffer = decodeUnsafe(string);
504
- if (buffer) {
505
- return buffer;
506
- }
507
- throw new Error(`Non-${name} character`);
508
- }
509
- return {
510
- encode: encode3,
511
- decodeUnsafe,
512
- decode: decode5
513
- };
514
- }
515
- var src = base;
516
- var _brrp__multiformats_scope_baseX = src;
517
- var base_x_default = _brrp__multiformats_scope_baseX;
518
-
519
- // node_modules/multiformats/src/bases/base.js
520
- var Encoder = class {
521
- /**
522
- * @param {Base} name
523
- * @param {Prefix} prefix
524
- * @param {(bytes:Uint8Array) => string} baseEncode
525
- */
526
- constructor(name, prefix, baseEncode) {
527
- this.name = name;
528
- this.prefix = prefix;
529
- this.baseEncode = baseEncode;
530
- }
531
- /**
532
- * @param {Uint8Array} bytes
533
- * @returns {API.Multibase<Prefix>}
534
- */
535
- encode(bytes) {
536
- if (bytes instanceof Uint8Array) {
537
- return `${this.prefix}${this.baseEncode(bytes)}`;
538
- } else {
539
- throw Error("Unknown type, must be binary type");
540
- }
541
- }
542
- };
543
- var Decoder = class {
544
- /**
545
- * @param {Base} name
546
- * @param {Prefix} prefix
547
- * @param {(text:string) => Uint8Array} baseDecode
548
- */
549
- constructor(name, prefix, baseDecode) {
550
- this.name = name;
551
- this.prefix = prefix;
552
- if (prefix.codePointAt(0) === void 0) {
553
- throw new Error("Invalid prefix character");
554
- }
555
- this.prefixCodePoint = /** @type {number} */
556
- prefix.codePointAt(0);
557
- this.baseDecode = baseDecode;
558
- }
559
- /**
560
- * @param {string} text
561
- */
562
- decode(text) {
563
- if (typeof text === "string") {
564
- if (text.codePointAt(0) !== this.prefixCodePoint) {
565
- throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);
566
- }
567
- return this.baseDecode(text.slice(this.prefix.length));
568
- } else {
569
- throw Error("Can only multibase decode strings");
570
- }
571
- }
572
- /**
573
- * @template {string} OtherPrefix
574
- * @param {API.UnibaseDecoder<OtherPrefix>|ComposedDecoder<OtherPrefix>} decoder
575
- * @returns {ComposedDecoder<Prefix|OtherPrefix>}
576
- */
577
- or(decoder) {
578
- return or(this, decoder);
579
- }
580
- };
581
- var ComposedDecoder = class {
582
- /**
583
- * @param {Decoders<Prefix>} decoders
584
- */
585
- constructor(decoders) {
586
- this.decoders = decoders;
587
- }
588
- /**
589
- * @template {string} OtherPrefix
590
- * @param {API.UnibaseDecoder<OtherPrefix>|ComposedDecoder<OtherPrefix>} decoder
591
- * @returns {ComposedDecoder<Prefix|OtherPrefix>}
592
- */
593
- or(decoder) {
594
- return or(this, decoder);
595
- }
596
- /**
597
- * @param {string} input
598
- * @returns {Uint8Array}
599
- */
600
- decode(input) {
601
- const prefix = (
602
- /** @type {Prefix} */
603
- input[0]
604
- );
605
- const decoder = this.decoders[prefix];
606
- if (decoder) {
607
- return decoder.decode(input);
608
- } else {
609
- throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`);
610
- }
611
- }
612
- };
613
- var or = (left, right) => new ComposedDecoder(
614
- /** @type {Decoders<L|R>} */
615
- {
616
- ...left.decoders || { [
617
- /** @type API.UnibaseDecoder<L> */
618
- left.prefix
619
- ]: left },
620
- ...right.decoders || { [
621
- /** @type API.UnibaseDecoder<R> */
622
- right.prefix
623
- ]: right }
624
- }
625
- );
626
- var Codec = class {
627
- /**
628
- * @param {Base} name
629
- * @param {Prefix} prefix
630
- * @param {(bytes:Uint8Array) => string} baseEncode
631
- * @param {(text:string) => Uint8Array} baseDecode
632
- */
633
- constructor(name, prefix, baseEncode, baseDecode) {
634
- this.name = name;
635
- this.prefix = prefix;
636
- this.baseEncode = baseEncode;
637
- this.baseDecode = baseDecode;
638
- this.encoder = new Encoder(name, prefix, baseEncode);
639
- this.decoder = new Decoder(name, prefix, baseDecode);
640
- }
641
- /**
642
- * @param {Uint8Array} input
643
- */
644
- encode(input) {
645
- return this.encoder.encode(input);
646
- }
647
- /**
648
- * @param {string} input
649
- */
650
- decode(input) {
651
- return this.decoder.decode(input);
652
- }
653
- };
654
- var from = ({ name, prefix, encode: encode3, decode: decode5 }) => new Codec(name, prefix, encode3, decode5);
655
- var baseX = ({ prefix, name, alphabet }) => {
656
- const { encode: encode3, decode: decode5 } = base_x_default(alphabet, name);
657
- return from({
658
- prefix,
659
- name,
660
- encode: encode3,
661
- /**
662
- * @param {string} text
663
- */
664
- decode: (text) => coerce(decode5(text))
665
- });
666
- };
667
- var decode4 = (string, alphabet, bitsPerChar, name) => {
668
- const codes = {};
669
- for (let i = 0; i < alphabet.length; ++i) {
670
- codes[alphabet[i]] = i;
671
- }
672
- let end = string.length;
673
- while (string[end - 1] === "=") {
674
- --end;
675
- }
676
- const out = new Uint8Array(end * bitsPerChar / 8 | 0);
677
- let bits = 0;
678
- let buffer = 0;
679
- let written = 0;
680
- for (let i = 0; i < end; ++i) {
681
- const value = codes[string[i]];
682
- if (value === void 0) {
683
- throw new SyntaxError(`Non-${name} character`);
684
- }
685
- buffer = buffer << bitsPerChar | value;
686
- bits += bitsPerChar;
687
- if (bits >= 8) {
688
- bits -= 8;
689
- out[written++] = 255 & buffer >> bits;
690
- }
691
- }
692
- if (bits >= bitsPerChar || 255 & buffer << 8 - bits) {
693
- throw new SyntaxError("Unexpected end of data");
694
- }
695
- return out;
696
- };
697
- var encode2 = (data, alphabet, bitsPerChar) => {
698
- const pad = alphabet[alphabet.length - 1] === "=";
699
- const mask = (1 << bitsPerChar) - 1;
700
- let out = "";
701
- let bits = 0;
702
- let buffer = 0;
703
- for (let i = 0; i < data.length; ++i) {
704
- buffer = buffer << 8 | data[i];
705
- bits += 8;
706
- while (bits > bitsPerChar) {
707
- bits -= bitsPerChar;
708
- out += alphabet[mask & buffer >> bits];
709
- }
710
- }
711
- if (bits) {
712
- out += alphabet[mask & buffer << bitsPerChar - bits];
713
- }
714
- if (pad) {
715
- while (out.length * bitsPerChar & 7) {
716
- out += "=";
717
- }
718
- }
719
- return out;
720
- };
721
- var rfc4648 = ({ name, prefix, bitsPerChar, alphabet }) => {
722
- return from({
723
- prefix,
724
- name,
725
- encode(input) {
726
- return encode2(input, alphabet, bitsPerChar);
727
- },
728
- decode(input) {
729
- return decode4(input, alphabet, bitsPerChar, name);
730
- }
731
- });
732
- };
733
-
734
- // node_modules/multiformats/src/bases/base58.js
735
- var base58btc = baseX({
736
- name: "base58btc",
737
- prefix: "z",
738
- alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
739
- });
740
- var base58flickr = baseX({
741
- name: "base58flickr",
742
- prefix: "Z",
743
- alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
744
- });
745
-
746
- // node_modules/multiformats/src/bases/base32.js
747
- var base32 = rfc4648({
748
- prefix: "b",
749
- name: "base32",
750
- alphabet: "abcdefghijklmnopqrstuvwxyz234567",
751
- bitsPerChar: 5
752
- });
753
- var base32upper = rfc4648({
754
- prefix: "B",
755
- name: "base32upper",
756
- alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
757
- bitsPerChar: 5
758
- });
759
- var base32pad = rfc4648({
760
- prefix: "c",
761
- name: "base32pad",
762
- alphabet: "abcdefghijklmnopqrstuvwxyz234567=",
763
- bitsPerChar: 5
764
- });
765
- var base32padupper = rfc4648({
766
- prefix: "C",
767
- name: "base32padupper",
768
- alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
769
- bitsPerChar: 5
770
- });
771
- var base32hex = rfc4648({
772
- prefix: "v",
773
- name: "base32hex",
774
- alphabet: "0123456789abcdefghijklmnopqrstuv",
775
- bitsPerChar: 5
776
- });
777
- var base32hexupper = rfc4648({
778
- prefix: "V",
779
- name: "base32hexupper",
780
- alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV",
781
- bitsPerChar: 5
782
- });
783
- var base32hexpad = rfc4648({
784
- prefix: "t",
785
- name: "base32hexpad",
786
- alphabet: "0123456789abcdefghijklmnopqrstuv=",
787
- bitsPerChar: 5
788
- });
789
- var base32hexpadupper = rfc4648({
790
- prefix: "T",
791
- name: "base32hexpadupper",
792
- alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV=",
793
- bitsPerChar: 5
794
- });
795
- var base32z = rfc4648({
796
- prefix: "h",
797
- name: "base32z",
798
- alphabet: "ybndrfg8ejkmcpqxot1uwisza345h769",
799
- bitsPerChar: 5
800
- });
801
-
802
- // node_modules/multiformats/src/cid.js
803
- var format = (link, base2) => {
804
- const { bytes, version } = link;
805
- switch (version) {
806
- case 0:
807
- return toStringV0(
808
- bytes,
809
- baseCache(link),
810
- /** @type {API.MultibaseEncoder<"z">} */
811
- base2 || base58btc.encoder
812
- );
813
- default:
814
- return toStringV1(
815
- bytes,
816
- baseCache(link),
817
- /** @type {API.MultibaseEncoder<Prefix>} */
818
- base2 || base32.encoder
819
- );
820
- }
821
- };
822
- var cache = /* @__PURE__ */ new WeakMap();
823
- var baseCache = (cid) => {
824
- const baseCache2 = cache.get(cid);
825
- if (baseCache2 == null) {
826
- const baseCache3 = /* @__PURE__ */ new Map();
827
- cache.set(cid, baseCache3);
828
- return baseCache3;
829
- }
830
- return baseCache2;
831
- };
832
- var CID = class _CID {
833
- /**
834
- * @param {Version} version - Version of the CID
835
- * @param {Format} code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
836
- * @param {API.MultihashDigest<Alg>} multihash - (Multi)hash of the of the content.
837
- * @param {Uint8Array} bytes
838
- *
839
- */
840
- constructor(version, code, multihash, bytes) {
841
- this.code = code;
842
- this.version = version;
843
- this.multihash = multihash;
844
- this.bytes = bytes;
845
- this["/"] = bytes;
846
- }
847
- /**
848
- * Signalling `cid.asCID === cid` has been replaced with `cid['/'] === cid.bytes`
849
- * please either use `CID.asCID(cid)` or switch to new signalling mechanism
850
- *
851
- * @deprecated
852
- */
853
- get asCID() {
854
- return this;
855
- }
856
- // ArrayBufferView
857
- get byteOffset() {
858
- return this.bytes.byteOffset;
859
- }
860
- // ArrayBufferView
861
- get byteLength() {
862
- return this.bytes.byteLength;
863
- }
864
- /**
865
- * @returns {CID<Data, API.DAG_PB, API.SHA_256, 0>}
866
- */
867
- toV0() {
868
- switch (this.version) {
869
- case 0: {
870
- return (
871
- /** @type {CID<Data, API.DAG_PB, API.SHA_256, 0>} */
872
- this
873
- );
874
- }
875
- case 1: {
876
- const { code, multihash } = this;
877
- if (code !== DAG_PB_CODE) {
878
- throw new Error("Cannot convert a non dag-pb CID to CIDv0");
879
- }
880
- if (multihash.code !== SHA_256_CODE) {
881
- throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");
882
- }
883
- return (
884
- /** @type {CID<Data, API.DAG_PB, API.SHA_256, 0>} */
885
- _CID.createV0(
886
- /** @type {API.MultihashDigest<API.SHA_256>} */
887
- multihash
888
- )
889
- );
890
- }
891
- default: {
892
- throw Error(
893
- `Can not convert CID version ${this.version} to version 0. This is a bug please report`
894
- );
895
- }
896
- }
897
- }
898
- /**
899
- * @returns {CID<Data, Format, Alg, 1>}
900
- */
901
- toV1() {
902
- switch (this.version) {
903
- case 0: {
904
- const { code, digest } = this.multihash;
905
- const multihash = create(code, digest);
906
- return (
907
- /** @type {CID<Data, Format, Alg, 1>} */
908
- _CID.createV1(this.code, multihash)
909
- );
910
- }
911
- case 1: {
912
- return (
913
- /** @type {CID<Data, Format, Alg, 1>} */
914
- this
915
- );
916
- }
917
- default: {
918
- throw Error(
919
- `Can not convert CID version ${this.version} to version 1. This is a bug please report`
920
- );
921
- }
922
- }
923
- }
924
- /**
925
- * @param {unknown} other
926
- * @returns {other is CID<Data, Format, Alg, Version>}
927
- */
928
- equals(other) {
929
- return _CID.equals(this, other);
930
- }
931
- /**
932
- * @template {unknown} Data
933
- * @template {number} Format
934
- * @template {number} Alg
935
- * @template {API.Version} Version
936
- * @param {API.Link<Data, Format, Alg, Version>} self
937
- * @param {unknown} other
938
- * @returns {other is CID}
939
- */
940
- static equals(self, other) {
941
- const unknown = (
942
- /** @type {{code?:unknown, version?:unknown, multihash?:unknown}} */
943
- other
944
- );
945
- return unknown && self.code === unknown.code && self.version === unknown.version && equals2(self.multihash, unknown.multihash);
946
- }
947
- /**
948
- * @param {API.MultibaseEncoder<string>} [base]
949
- * @returns {string}
950
- */
951
- toString(base2) {
952
- return format(this, base2);
953
- }
954
- toJSON() {
955
- return { "/": format(this) };
956
- }
957
- link() {
958
- return this;
959
- }
960
- get [Symbol.toStringTag]() {
961
- return "CID";
962
- }
963
- // Legacy
964
- [Symbol.for("nodejs.util.inspect.custom")]() {
965
- return `CID(${this.toString()})`;
966
- }
967
- /**
968
- * Takes any input `value` and returns a `CID` instance if it was
969
- * a `CID` otherwise returns `null`. If `value` is instanceof `CID`
970
- * it will return value back. If `value` is not instance of this CID
971
- * class, but is compatible CID it will return new instance of this
972
- * `CID` class. Otherwise returns null.
973
- *
974
- * This allows two different incompatible versions of CID library to
975
- * co-exist and interop as long as binary interface is compatible.
976
- *
977
- * @template {unknown} Data
978
- * @template {number} Format
979
- * @template {number} Alg
980
- * @template {API.Version} Version
981
- * @template {unknown} U
982
- * @param {API.Link<Data, Format, Alg, Version>|U} input
983
- * @returns {CID<Data, Format, Alg, Version>|null}
984
- */
985
- static asCID(input) {
986
- if (input == null) {
987
- return null;
988
- }
989
- const value = (
990
- /** @type {any} */
991
- input
992
- );
993
- if (value instanceof _CID) {
994
- return value;
995
- } else if (value["/"] != null && value["/"] === value.bytes || value.asCID === value) {
996
- const { version, code, multihash, bytes } = value;
997
- return new _CID(
998
- version,
999
- code,
1000
- /** @type {API.MultihashDigest<Alg>} */
1001
- multihash,
1002
- bytes || encodeCID(version, code, multihash.bytes)
1003
- );
1004
- } else if (value[cidSymbol] === true) {
1005
- const { version, multihash, code } = value;
1006
- const digest = (
1007
- /** @type {API.MultihashDigest<Alg>} */
1008
- decode3(multihash)
1009
- );
1010
- return _CID.create(version, code, digest);
1011
- } else {
1012
- return null;
1013
- }
1014
- }
1015
- /**
1016
- *
1017
- * @template {unknown} Data
1018
- * @template {number} Format
1019
- * @template {number} Alg
1020
- * @template {API.Version} Version
1021
- * @param {Version} version - Version of the CID
1022
- * @param {Format} code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
1023
- * @param {API.MultihashDigest<Alg>} digest - (Multi)hash of the of the content.
1024
- * @returns {CID<Data, Format, Alg, Version>}
1025
- */
1026
- static create(version, code, digest) {
1027
- if (typeof code !== "number") {
1028
- throw new Error("String codecs are no longer supported");
1029
- }
1030
- if (!(digest.bytes instanceof Uint8Array)) {
1031
- throw new Error("Invalid digest");
1032
- }
1033
- switch (version) {
1034
- case 0: {
1035
- if (code !== DAG_PB_CODE) {
1036
- throw new Error(
1037
- `Version 0 CID must use dag-pb (code: ${DAG_PB_CODE}) block encoding`
1038
- );
1039
- } else {
1040
- return new _CID(version, code, digest, digest.bytes);
1041
- }
1042
- }
1043
- case 1: {
1044
- const bytes = encodeCID(version, code, digest.bytes);
1045
- return new _CID(version, code, digest, bytes);
1046
- }
1047
- default: {
1048
- throw new Error("Invalid version");
1049
- }
1050
- }
1051
- }
1052
- /**
1053
- * Simplified version of `create` for CIDv0.
1054
- *
1055
- * @template {unknown} [T=unknown]
1056
- * @param {API.MultihashDigest<typeof SHA_256_CODE>} digest - Multihash.
1057
- * @returns {CID<T, typeof DAG_PB_CODE, typeof SHA_256_CODE, 0>}
1058
- */
1059
- static createV0(digest) {
1060
- return _CID.create(0, DAG_PB_CODE, digest);
1061
- }
1062
- /**
1063
- * Simplified version of `create` for CIDv1.
1064
- *
1065
- * @template {unknown} Data
1066
- * @template {number} Code
1067
- * @template {number} Alg
1068
- * @param {Code} code - Content encoding format code.
1069
- * @param {API.MultihashDigest<Alg>} digest - Miltihash of the content.
1070
- * @returns {CID<Data, Code, Alg, 1>}
1071
- */
1072
- static createV1(code, digest) {
1073
- return _CID.create(1, code, digest);
1074
- }
1075
- /**
1076
- * Decoded a CID from its binary representation. The byte array must contain
1077
- * only the CID with no additional bytes.
1078
- *
1079
- * An error will be thrown if the bytes provided do not contain a valid
1080
- * binary representation of a CID.
1081
- *
1082
- * @template {unknown} Data
1083
- * @template {number} Code
1084
- * @template {number} Alg
1085
- * @template {API.Version} Ver
1086
- * @param {API.ByteView<API.Link<Data, Code, Alg, Ver>>} bytes
1087
- * @returns {CID<Data, Code, Alg, Ver>}
1088
- */
1089
- static decode(bytes) {
1090
- const [cid, remainder] = _CID.decodeFirst(bytes);
1091
- if (remainder.length) {
1092
- throw new Error("Incorrect length");
1093
- }
1094
- return cid;
1095
- }
1096
- /**
1097
- * Decoded a CID from its binary representation at the beginning of a byte
1098
- * array.
1099
- *
1100
- * Returns an array with the first element containing the CID and the second
1101
- * element containing the remainder of the original byte array. The remainder
1102
- * will be a zero-length byte array if the provided bytes only contained a
1103
- * binary CID representation.
1104
- *
1105
- * @template {unknown} T
1106
- * @template {number} C
1107
- * @template {number} A
1108
- * @template {API.Version} V
1109
- * @param {API.ByteView<API.Link<T, C, A, V>>} bytes
1110
- * @returns {[CID<T, C, A, V>, Uint8Array]}
1111
- */
1112
- static decodeFirst(bytes) {
1113
- const specs = _CID.inspectBytes(bytes);
1114
- const prefixSize = specs.size - specs.multihashSize;
1115
- const multihashBytes = coerce(
1116
- bytes.subarray(prefixSize, prefixSize + specs.multihashSize)
1117
- );
1118
- if (multihashBytes.byteLength !== specs.multihashSize) {
1119
- throw new Error("Incorrect length");
1120
- }
1121
- const digestBytes = multihashBytes.subarray(
1122
- specs.multihashSize - specs.digestSize
1123
- );
1124
- const digest = new Digest(
1125
- specs.multihashCode,
1126
- specs.digestSize,
1127
- digestBytes,
1128
- multihashBytes
1129
- );
1130
- const cid = specs.version === 0 ? _CID.createV0(
1131
- /** @type {API.MultihashDigest<API.SHA_256>} */
1132
- digest
1133
- ) : _CID.createV1(specs.codec, digest);
1134
- return [
1135
- /** @type {CID<T, C, A, V>} */
1136
- cid,
1137
- bytes.subarray(specs.size)
1138
- ];
1139
- }
1140
- /**
1141
- * Inspect the initial bytes of a CID to determine its properties.
1142
- *
1143
- * Involves decoding up to 4 varints. Typically this will require only 4 to 6
1144
- * bytes but for larger multicodec code values and larger multihash digest
1145
- * lengths these varints can be quite large. It is recommended that at least
1146
- * 10 bytes be made available in the `initialBytes` argument for a complete
1147
- * inspection.
1148
- *
1149
- * @template {unknown} T
1150
- * @template {number} C
1151
- * @template {number} A
1152
- * @template {API.Version} V
1153
- * @param {API.ByteView<API.Link<T, C, A, V>>} initialBytes
1154
- * @returns {{ version:V, codec:C, multihashCode:A, digestSize:number, multihashSize:number, size:number }}
1155
- */
1156
- static inspectBytes(initialBytes) {
1157
- let offset = 0;
1158
- const next = () => {
1159
- const [i, length2] = decode2(initialBytes.subarray(offset));
1160
- offset += length2;
1161
- return i;
1162
- };
1163
- let version = (
1164
- /** @type {V} */
1165
- next()
1166
- );
1167
- let codec = (
1168
- /** @type {C} */
1169
- DAG_PB_CODE
1170
- );
1171
- if (
1172
- /** @type {number} */
1173
- version === 18
1174
- ) {
1175
- version = /** @type {V} */
1176
- 0;
1177
- offset = 0;
1178
- } else {
1179
- codec = /** @type {C} */
1180
- next();
1181
- }
1182
- if (version !== 0 && version !== 1) {
1183
- throw new RangeError(`Invalid CID version ${version}`);
1184
- }
1185
- const prefixSize = offset;
1186
- const multihashCode = (
1187
- /** @type {A} */
1188
- next()
1189
- );
1190
- const digestSize = next();
1191
- const size = offset + digestSize;
1192
- const multihashSize = size - prefixSize;
1193
- return { version, codec, multihashCode, digestSize, multihashSize, size };
1194
- }
1195
- /**
1196
- * Takes cid in a string representation and creates an instance. If `base`
1197
- * decoder is not provided will use a default from the configuration. It will
1198
- * throw an error if encoding of the CID is not compatible with supplied (or
1199
- * a default decoder).
1200
- *
1201
- * @template {string} Prefix
1202
- * @template {unknown} Data
1203
- * @template {number} Code
1204
- * @template {number} Alg
1205
- * @template {API.Version} Ver
1206
- * @param {API.ToString<API.Link<Data, Code, Alg, Ver>, Prefix>} source
1207
- * @param {API.MultibaseDecoder<Prefix>} [base]
1208
- * @returns {CID<Data, Code, Alg, Ver>}
1209
- */
1210
- static parse(source, base2) {
1211
- const [prefix, bytes] = parseCIDtoBytes(source, base2);
1212
- const cid = _CID.decode(bytes);
1213
- if (cid.version === 0 && source[0] !== "Q") {
1214
- throw Error("Version 0 CID string must not include multibase prefix");
1215
- }
1216
- baseCache(cid).set(prefix, source);
1217
- return cid;
1218
- }
1219
- };
1220
- var parseCIDtoBytes = (source, base2) => {
1221
- switch (source[0]) {
1222
- case "Q": {
1223
- const decoder = base2 || base58btc;
1224
- return [
1225
- /** @type {Prefix} */
1226
- base58btc.prefix,
1227
- decoder.decode(`${base58btc.prefix}${source}`)
1228
- ];
1229
- }
1230
- case base58btc.prefix: {
1231
- const decoder = base2 || base58btc;
1232
- return [
1233
- /** @type {Prefix} */
1234
- base58btc.prefix,
1235
- decoder.decode(source)
1236
- ];
1237
- }
1238
- case base32.prefix: {
1239
- const decoder = base2 || base32;
1240
- return [
1241
- /** @type {Prefix} */
1242
- base32.prefix,
1243
- decoder.decode(source)
1244
- ];
1245
- }
1246
- default: {
1247
- if (base2 == null) {
1248
- throw Error(
1249
- "To parse non base32 or base58btc encoded CID multibase decoder must be provided"
1250
- );
1251
- }
1252
- return [
1253
- /** @type {Prefix} */
1254
- source[0],
1255
- base2.decode(source)
1256
- ];
1257
- }
1258
- }
1259
- };
1260
- var toStringV0 = (bytes, cache2, base2) => {
1261
- const { prefix } = base2;
1262
- if (prefix !== base58btc.prefix) {
1263
- throw Error(`Cannot string encode V0 in ${base2.name} encoding`);
1264
- }
1265
- const cid = cache2.get(prefix);
1266
- if (cid == null) {
1267
- const cid2 = base2.encode(bytes).slice(1);
1268
- cache2.set(prefix, cid2);
1269
- return cid2;
1270
- } else {
1271
- return cid;
1272
- }
1273
- };
1274
- var toStringV1 = (bytes, cache2, base2) => {
1275
- const { prefix } = base2;
1276
- const cid = cache2.get(prefix);
1277
- if (cid == null) {
1278
- const cid2 = base2.encode(bytes);
1279
- cache2.set(prefix, cid2);
1280
- return cid2;
1281
- } else {
1282
- return cid;
1283
- }
1284
- };
1285
- var DAG_PB_CODE = 112;
1286
- var SHA_256_CODE = 18;
1287
- var encodeCID = (version, code, multihash) => {
1288
- const codeOffset = encodingLength(version);
1289
- const hashOffset = codeOffset + encodingLength(code);
1290
- const bytes = new Uint8Array(hashOffset + multihash.byteLength);
1291
- encodeTo(version, bytes, 0);
1292
- encodeTo(code, bytes, codeOffset);
1293
- bytes.set(multihash, hashOffset);
1294
- return bytes;
1295
- };
1296
- var cidSymbol = Symbol.for("@ipld/js-cid/CID");
1297
-
1298
- // node_modules/multiformats/src/link.js
1299
- var parse = (source, base2) => CID.parse(source, base2);
1300
-
1301
- // src/store.ts
1302
- var StoredHeader = class {
1303
- car;
1304
- constructor(jsonHeader) {
1305
- this.car = parse(jsonHeader.car);
1306
- }
1307
- };
1308
- var HeaderStore = class {
1309
- name;
1310
- constructor(name) {
1311
- this.name = name;
1312
- }
1313
- makeHeader(car) {
1314
- return JSON.stringify({ car: car.toString() });
1315
- }
1316
- parseHeader(headerData) {
1317
- const header = JSON.parse(headerData);
1318
- return new StoredHeader(header);
1319
- }
1320
- };
1321
- var CarStore = class {
1322
- name;
1323
- constructor(name) {
1324
- this.name = name;
1325
- }
1326
- };
1327
-
1328
- // src/store-browser.ts
1329
- var FORMAT = "0.9";
1330
- var CarStoreIDB = class extends CarStore {
1331
- keyId = "public";
1332
- // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
1333
- idb = null;
1334
- name = "default";
1335
- async withDB(dbWorkFun) {
1336
- if (!this.idb) {
1337
- const dbName = `fp.${FORMAT}.${this.keyId}.${this.name}.valet`;
1338
- const options = {
1339
- upgrade(db) {
1340
- db.createObjectStore("cars");
1341
- }
1342
- };
1343
- this.idb = await openDB(dbName, 0, options);
1344
- }
1345
- return await dbWorkFun(this.idb);
1346
- }
1347
- async load(cid) {
1348
- return await this.withDB(async (db) => {
1349
- const tx = db.transaction(["cars"], "readonly");
1350
- const bytes = await tx.objectStore("cars").get(cid.toString());
1351
- if (!bytes)
1352
- throw new Error(`missing block ${cid.toString()}`);
1353
- return { cid, bytes };
1354
- });
1355
- }
1356
- async save(car) {
1357
- return await this.withDB(async (db) => {
1358
- const tx = db.transaction(["cars"], "readwrite");
1359
- await tx.objectStore("cars").put(car.bytes, car.cid.toString());
1360
- return await tx.done;
1361
- });
1362
- }
1363
- };
1364
- var HeaderStoreLS = class extends HeaderStore {
1365
- keyId = "public";
1366
- name = "default";
1367
- headerKey(branch) {
1368
- return `fp.${FORMAT}.${this.keyId}.${this.name}.${branch}`;
1369
- }
1370
- // eslint-disable-next-line @typescript-eslint/require-await
1371
- async load(branch = "main") {
1372
- const bytes = localStorage.getItem(this.headerKey(branch));
1373
- return bytes ? this.parseHeader(bytes.toString()) : null;
1374
- }
1375
- // eslint-disable-next-line @typescript-eslint/require-await
1376
- async save(carCid, branch = "main") {
1377
- const headerKey = this.headerKey(branch);
1378
- return localStorage.setItem(headerKey, this.makeHeader(carCid));
1379
- }
1380
- };
1381
- // Annotate the CommonJS export names for ESM import in node:
1382
- 0 && (module.exports = {
1383
- CarStoreIDB,
1384
- FORMAT,
1385
- HeaderStoreLS
1386
- });
1387
- //# sourceMappingURL=store-browser.cjs.js.map