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