@fireproof/core 0.19.120 → 0.19.121
Sign up to get free protection for your applications and to get access to all the features.
- package/deno.json +2 -2
- package/index.cjs +624 -1026
- package/index.cjs.map +1 -1
- package/index.d.cts +26 -60
- package/index.d.ts +26 -60
- package/index.js +394 -97
- package/index.js.map +1 -1
- package/metafile-cjs.json +1 -1
- package/metafile-esm.json +1 -1
- package/node/index.cjs +374 -0
- package/node/index.cjs.map +1 -0
- package/node/index.d.cts +43 -0
- package/node/index.d.ts +43 -0
- package/node/index.js +279 -0
- package/node/index.js.map +1 -0
- package/node/{mem-filesystem.js → mem-filesystem-LPPT7QV5.js} +1 -1
- package/node/metafile-cjs.json +1 -1
- package/node/metafile-esm.json +1 -1
- package/package.json +16 -14
- package/react/index.cjs.map +1 -1
- package/react/index.d.cts +4 -33
- package/react/index.d.ts +4 -33
- package/react/index.js.map +1 -1
- package/react/metafile-cjs.json +1 -1
- package/react/metafile-esm.json +1 -1
- package/tests/blockstore/keyed-crypto.test.ts +4 -2
- package/tests/fireproof/config.test.ts +133 -142
- package/web/{gateway-impl.cjs → index.cjs} +58 -9
- package/web/index.cjs.map +1 -0
- package/web/index.d.cts +44 -0
- package/web/index.d.ts +44 -0
- package/web/{gateway-impl.js → index.js} +52 -5
- package/web/index.js.map +1 -0
- package/web/metafile-cjs.json +1 -1
- package/web/metafile-esm.json +1 -1
- package/chunk-7EWIAXTM.js +0 -7
- package/chunk-7EWIAXTM.js.map +0 -1
- package/chunk-F4FC6B2T.js +0 -63
- package/chunk-F4FC6B2T.js.map +0 -1
- package/chunk-PZ5AY32C.js +0 -10
- package/chunk-PZ5AY32C.js.map +0 -1
- package/chunk-RXC4JGJT.js +0 -301
- package/chunk-RXC4JGJT.js.map +0 -1
- package/gateway-C62S56GY.js +0 -66
- package/gateway-C62S56GY.js.map +0 -1
- package/gateway-VVS4QWDA.js +0 -145
- package/gateway-VVS4QWDA.js.map +0 -1
- package/key-bag-file-PWZ3QE7B.js +0 -55
- package/key-bag-file-PWZ3QE7B.js.map +0 -1
- package/key-bag-indexdb-SYG3YD4D.js +0 -51
- package/key-bag-indexdb-SYG3YD4D.js.map +0 -1
- package/node/mem-filesystem.cjs +0 -72
- package/node/mem-filesystem.cjs.map +0 -1
- package/node/mem-filesystem.d.cts +0 -25
- package/node/mem-filesystem.d.ts +0 -25
- package/node/node-filesystem.cjs +0 -86
- package/node/node-filesystem.cjs.map +0 -1
- package/node/node-filesystem.d.cts +0 -35
- package/node/node-filesystem.d.ts +0 -35
- package/node/node-filesystem.js +0 -44
- package/node/node-filesystem.js.map +0 -1
- package/utils-ZVVGAXFE.js +0 -13
- package/utils-ZVVGAXFE.js.map +0 -1
- package/web/gateway-impl.cjs.map +0 -1
- package/web/gateway-impl.d.cts +0 -31
- package/web/gateway-impl.d.ts +0 -31
- package/web/gateway-impl.js.map +0 -1
- /package/node/{mem-filesystem.js.map → mem-filesystem-LPPT7QV5.js.map} +0 -0
package/index.cjs
CHANGED
@@ -5,9 +5,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
-
var __esm = (fn, res) => function __init() {
|
9
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
10
|
-
};
|
11
8
|
var __export = (target, all) => {
|
12
9
|
for (var name in all)
|
13
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
@@ -30,977 +27,561 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
30
27
|
));
|
31
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
32
29
|
|
33
|
-
// src/
|
34
|
-
|
35
|
-
|
30
|
+
// src/index.ts
|
31
|
+
var index_exports = {};
|
32
|
+
__export(index_exports, {
|
33
|
+
CRDT: () => CRDT,
|
34
|
+
Database: () => Database,
|
35
|
+
Index: () => Index,
|
36
|
+
NotFoundError: () => NotFoundError,
|
37
|
+
PACKAGE_VERSION: () => PACKAGE_VERSION,
|
38
|
+
Result: () => import_cement.Result,
|
39
|
+
UInt8ArrayEqual: () => UInt8ArrayEqual,
|
40
|
+
blockstore: () => blockstore_exports,
|
41
|
+
bs: () => blockstore_exports,
|
42
|
+
dataDir: () => dataDir,
|
43
|
+
ensureLogger: () => ensureLogger,
|
44
|
+
ensureSuperLog: () => ensureSuperLog,
|
45
|
+
ensureSuperThis: () => ensureSuperThis,
|
46
|
+
exceptionWrapper: () => exceptionWrapper,
|
47
|
+
falsyToUndef: () => falsyToUndef,
|
48
|
+
fireproof: () => fireproof,
|
49
|
+
getKey: () => getKey,
|
50
|
+
getName: () => getName,
|
51
|
+
getStore: () => getStore,
|
52
|
+
index: () => index,
|
53
|
+
isFalsy: () => isFalsy,
|
54
|
+
isNotFoundError: () => isNotFoundError,
|
55
|
+
onSuperThis: () => onSuperThis,
|
56
|
+
rt: () => runtime_exports,
|
57
|
+
runtime: () => runtime_exports,
|
58
|
+
throwFalsy: () => throwFalsy
|
59
|
+
});
|
60
|
+
module.exports = __toCommonJS(index_exports);
|
61
|
+
|
62
|
+
// src/database.ts
|
63
|
+
var import_cement12 = require("@adviser/cement");
|
64
|
+
|
65
|
+
// src/write-queue.ts
|
66
|
+
function writeQueue(worker, payload = Infinity, unbounded = false) {
|
67
|
+
const queue = [];
|
68
|
+
let isProcessing = false;
|
69
|
+
async function process() {
|
70
|
+
if (isProcessing || queue.length === 0) return;
|
71
|
+
isProcessing = true;
|
72
|
+
const tasksToProcess = queue.splice(0, payload);
|
73
|
+
const updates = tasksToProcess.map((item) => item.task);
|
74
|
+
if (unbounded) {
|
75
|
+
const promises = updates.map(async (update, index2) => {
|
76
|
+
try {
|
77
|
+
const result = await worker([update]);
|
78
|
+
tasksToProcess[index2].resolve(result);
|
79
|
+
} catch (error) {
|
80
|
+
tasksToProcess[index2].reject(error);
|
81
|
+
}
|
82
|
+
});
|
83
|
+
await Promise.all(promises);
|
84
|
+
} else {
|
85
|
+
try {
|
86
|
+
const result = await worker(updates);
|
87
|
+
tasksToProcess.forEach((task) => task.resolve(result));
|
88
|
+
} catch (error) {
|
89
|
+
tasksToProcess.forEach((task) => task.reject(error));
|
90
|
+
}
|
91
|
+
}
|
92
|
+
isProcessing = false;
|
93
|
+
void process();
|
94
|
+
}
|
95
|
+
return {
|
96
|
+
push(task) {
|
97
|
+
return new Promise((resolve, reject) => {
|
98
|
+
queue.push({ task, resolve, reject });
|
99
|
+
void process();
|
100
|
+
});
|
101
|
+
}
|
102
|
+
};
|
36
103
|
}
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
104
|
+
|
105
|
+
// src/crdt.ts
|
106
|
+
var import_cement11 = require("@adviser/cement");
|
107
|
+
|
108
|
+
// src/runtime/wait-pr-multiformats/block.ts
|
109
|
+
var block_exports = {};
|
110
|
+
__export(block_exports, {
|
111
|
+
Block: () => Block,
|
112
|
+
create: () => create,
|
113
|
+
createUnsafe: () => createUnsafe,
|
114
|
+
decode: () => decode,
|
115
|
+
encode: () => encode
|
116
|
+
});
|
117
|
+
var import_multiformats = require("multiformats");
|
118
|
+
var import_block = require("multiformats/block");
|
119
|
+
var Block = import_block.Block;
|
120
|
+
async function decode({
|
121
|
+
bytes,
|
122
|
+
codec: codec3,
|
123
|
+
hasher: hasher7
|
124
|
+
}) {
|
125
|
+
if (bytes == null) throw new Error('Missing required argument "bytes"');
|
126
|
+
if (codec3 == null || hasher7 == null) throw new Error("Missing required argument: codec or hasher");
|
127
|
+
const value = await Promise.resolve(codec3.decode(bytes));
|
128
|
+
const hash = await hasher7.digest(bytes);
|
129
|
+
const cid = import_multiformats.CID.create(1, codec3.code, hash);
|
130
|
+
return new import_block.Block({ value, bytes, cid });
|
50
131
|
}
|
51
|
-
function
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
132
|
+
async function encode({
|
133
|
+
value,
|
134
|
+
codec: codec3,
|
135
|
+
hasher: hasher7
|
136
|
+
}) {
|
137
|
+
if (typeof value === "undefined") throw new Error('Missing required argument "value"');
|
138
|
+
if (codec3 == null || hasher7 == null) throw new Error("Missing required argument: codec or hasher");
|
139
|
+
const bytes = await Promise.resolve(codec3.encode(value));
|
140
|
+
const hash = await hasher7.digest(bytes);
|
141
|
+
const cid = import_multiformats.CID.create(1, codec3.code, hash);
|
142
|
+
return new import_block.Block({ value, bytes, cid });
|
57
143
|
}
|
58
|
-
function
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
144
|
+
async function create({
|
145
|
+
bytes,
|
146
|
+
cid,
|
147
|
+
hasher: hasher7,
|
148
|
+
codec: codec3
|
149
|
+
}) {
|
150
|
+
if (bytes == null) throw new Error('Missing required argument "bytes"');
|
151
|
+
if (hasher7 == null) throw new Error('Missing required argument "hasher"');
|
152
|
+
const value = await Promise.resolve(codec3.decode(bytes));
|
153
|
+
const hash = await hasher7.digest(bytes);
|
154
|
+
if (!import_multiformats.bytes.equals(cid.multihash.bytes, hash.bytes)) {
|
155
|
+
throw new Error("CID hash does not match bytes");
|
156
|
+
}
|
157
|
+
return createUnsafe({
|
158
|
+
bytes,
|
159
|
+
cid,
|
160
|
+
value,
|
161
|
+
codec: codec3
|
70
162
|
});
|
71
|
-
_onSuperThis.forEach((fn) => fn(ret));
|
72
|
-
return ret;
|
73
163
|
}
|
74
|
-
function
|
75
|
-
|
76
|
-
|
164
|
+
async function createUnsafe({
|
165
|
+
bytes,
|
166
|
+
cid,
|
167
|
+
value: maybeValue,
|
168
|
+
codec: codec3
|
169
|
+
}) {
|
170
|
+
const value = await Promise.resolve(maybeValue !== void 0 ? maybeValue : codec3?.decode(bytes));
|
171
|
+
if (value === void 0) throw new Error('Missing required argument, must either provide "value" or "codec"');
|
172
|
+
return new Block({
|
173
|
+
cid,
|
174
|
+
bytes,
|
175
|
+
value
|
77
176
|
});
|
78
177
|
}
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
break;
|
113
|
-
case "number":
|
114
|
-
cLogger.Uint64(key, value);
|
115
|
-
break;
|
116
|
-
default:
|
117
|
-
if (value instanceof Date) {
|
118
|
-
cLogger.Str(key, value.toISOString());
|
119
|
-
} else if ((0, import_cement.isURL)(value)) {
|
120
|
-
cLogger.Str(key, value.toString());
|
121
|
-
} else if (typeof value === "function") {
|
122
|
-
cLogger.Ref(key, value);
|
123
|
-
} else {
|
124
|
-
cLogger.Any(key, value);
|
125
|
-
}
|
126
|
-
break;
|
127
|
-
}
|
128
|
-
}
|
129
|
-
}
|
130
|
-
registerFP_DEBUG.once(async () => {
|
131
|
-
sthis.env.onSet(
|
132
|
-
(key, value) => {
|
133
|
-
switch (key) {
|
134
|
-
case "FP_FORMAT": {
|
135
|
-
switch (value) {
|
136
|
-
case "jsonice":
|
137
|
-
logger.SetFormatter(new import_cement.JSONFormatter(logger.TxtEnDe(), 2));
|
138
|
-
break;
|
139
|
-
case "yaml":
|
140
|
-
logger.SetFormatter(new import_cement.YAMLFormatter(logger.TxtEnDe(), 2));
|
141
|
-
break;
|
142
|
-
case "json":
|
143
|
-
default:
|
144
|
-
logger.SetFormatter(new import_cement.JSONFormatter(logger.TxtEnDe()));
|
145
|
-
break;
|
146
|
-
}
|
147
|
-
break;
|
148
|
-
}
|
149
|
-
case "FP_DEBUG":
|
150
|
-
logger.SetDebug(value || []);
|
151
|
-
break;
|
152
|
-
case "FP_STACK":
|
153
|
-
logger.SetExposeStack(!!value);
|
154
|
-
break;
|
155
|
-
}
|
156
|
-
},
|
157
|
-
"FP_FORMAT",
|
158
|
-
"FP_DEBUG",
|
159
|
-
"FP_STACK"
|
160
|
-
);
|
161
|
-
}).finally(() => {
|
162
|
-
});
|
163
|
-
if (debug.length > 0) {
|
164
|
-
logger.SetDebug(debug);
|
165
|
-
}
|
166
|
-
if (exposeStack) {
|
167
|
-
logger.SetExposeStack(true);
|
168
|
-
}
|
169
|
-
const out = cLogger.Logger();
|
170
|
-
return out;
|
178
|
+
|
179
|
+
// src/crdt-helpers.ts
|
180
|
+
var import_link = require("multiformats/link");
|
181
|
+
var import_sha25 = require("multiformats/hashes/sha2");
|
182
|
+
var codec = __toESM(require("@fireproof/vendor/@ipld/dag-cbor"), 1);
|
183
|
+
var import_crdt = require("@fireproof/vendor/@web3-storage/pail/crdt");
|
184
|
+
var import_clock2 = require("@fireproof/vendor/@web3-storage/pail/clock");
|
185
|
+
var Batch = __toESM(require("@fireproof/vendor/@web3-storage/pail/crdt/batch"), 1);
|
186
|
+
|
187
|
+
// src/blockstore/index.ts
|
188
|
+
var blockstore_exports = {};
|
189
|
+
__export(blockstore_exports, {
|
190
|
+
BaseBlockstore: () => BaseBlockstore,
|
191
|
+
CarTransaction: () => CarTransaction,
|
192
|
+
CompactionFetcher: () => CompactionFetcher,
|
193
|
+
ConnectionBase: () => ConnectionBase,
|
194
|
+
EncryptedBlockstore: () => EncryptedBlockstore,
|
195
|
+
FragmentGateway: () => FragmentGateway,
|
196
|
+
Loader: () => Loader,
|
197
|
+
addCryptoKeyToGatewayMetaPayload: () => addCryptoKeyToGatewayMetaPayload,
|
198
|
+
ensureStart: () => ensureStart,
|
199
|
+
getGatewayFromURL: () => getGatewayFromURL,
|
200
|
+
parseCarFile: () => parseCarFile,
|
201
|
+
registerStoreProtocol: () => registerStoreProtocol,
|
202
|
+
setCryptoKeyFromGatewayMetaPayload: () => setCryptoKeyFromGatewayMetaPayload,
|
203
|
+
testStoreFactory: () => testStoreFactory,
|
204
|
+
toCIDBlock: () => toCIDBlock,
|
205
|
+
toStoreRuntime: () => toStoreRuntime
|
206
|
+
});
|
207
|
+
|
208
|
+
// src/blockstore/types.ts
|
209
|
+
function toCIDBlock(block) {
|
210
|
+
return block;
|
171
211
|
}
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
212
|
+
|
213
|
+
// src/blockstore/store-factory.ts
|
214
|
+
var import_cement9 = require("@adviser/cement");
|
215
|
+
|
216
|
+
// src/runtime/files.ts
|
217
|
+
var files_exports = {};
|
218
|
+
__export(files_exports, {
|
219
|
+
decodeFile: () => decodeFile,
|
220
|
+
encodeFile: () => encodeFile
|
221
|
+
});
|
222
|
+
var UnixFS = __toESM(require("@ipld/unixfs"), 1);
|
223
|
+
var raw = __toESM(require("multiformats/codecs/raw"), 1);
|
224
|
+
var import_fixed = require("@ipld/unixfs/file/chunker/fixed");
|
225
|
+
var import_balanced = require("@ipld/unixfs/file/layout/balanced");
|
226
|
+
var import_ipfs_unixfs_exporter = require("@fireproof/vendor/ipfs-unixfs-exporter");
|
227
|
+
var queuingStrategy = UnixFS.withCapacity();
|
228
|
+
var settings = UnixFS.configure({
|
229
|
+
fileChunkEncoder: raw,
|
230
|
+
smallFileEncoder: raw,
|
231
|
+
chunker: (0, import_fixed.withMaxChunkSize)(1024 * 1024),
|
232
|
+
fileLayout: (0, import_balanced.withWidth)(1024)
|
233
|
+
});
|
234
|
+
async function collect(collectable) {
|
235
|
+
const chunks = [];
|
236
|
+
await collectable.pipeTo(
|
237
|
+
new WritableStream({
|
238
|
+
write(chunk) {
|
239
|
+
chunks.push(chunk);
|
240
|
+
}
|
241
|
+
})
|
242
|
+
);
|
243
|
+
return chunks;
|
187
244
|
}
|
188
|
-
function
|
189
|
-
const
|
190
|
-
|
191
|
-
return
|
245
|
+
async function encodeFile(blob) {
|
246
|
+
const readable = createFileEncoderStream(blob);
|
247
|
+
const blocks = await collect(readable);
|
248
|
+
return { cid: blocks.at(-1).cid, blocks };
|
192
249
|
}
|
193
|
-
function
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
throw sthis.logger.Error().Str("url", url.toString()).Msg(`name not found`).AsError();
|
199
|
-
}
|
250
|
+
async function decodeFile(blocks, cid, meta) {
|
251
|
+
const entry = await (0, import_ipfs_unixfs_exporter.exporter)(cid.toString(), blocks, { length: meta.size });
|
252
|
+
const chunks = [];
|
253
|
+
for await (const chunk of entry.content()) {
|
254
|
+
chunks.push(chunk);
|
200
255
|
}
|
201
|
-
return
|
256
|
+
return new File(chunks, entry.name, { type: meta.type, lastModified: 0 });
|
202
257
|
}
|
203
|
-
|
204
|
-
|
258
|
+
function createFileEncoderStream(blob) {
|
259
|
+
const { readable, writable } = new TransformStream({}, queuingStrategy);
|
260
|
+
const unixfsWriter = UnixFS.createWriter({ writable, settings });
|
261
|
+
const fileBuilder = new UnixFSFileBuilder("", blob);
|
262
|
+
void (async () => {
|
263
|
+
await fileBuilder.finalize(unixfsWriter);
|
264
|
+
await unixfsWriter.close();
|
265
|
+
})();
|
266
|
+
return readable;
|
205
267
|
}
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
268
|
+
var UnixFSFileBuilder = class {
|
269
|
+
#file;
|
270
|
+
constructor(name, file) {
|
271
|
+
this.name = name;
|
272
|
+
this.#file = file;
|
210
273
|
}
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
}
|
274
|
+
async finalize(writer) {
|
275
|
+
const unixfsFileWriter = UnixFS.createFileWriter(writer);
|
276
|
+
await this.#file.stream().pipeTo(
|
277
|
+
new WritableStream({
|
278
|
+
async write(chunk) {
|
279
|
+
await unixfsFileWriter.write(chunk);
|
280
|
+
}
|
281
|
+
})
|
282
|
+
);
|
283
|
+
return await unixfsFileWriter.close();
|
222
284
|
}
|
223
|
-
|
285
|
+
};
|
286
|
+
|
287
|
+
// src/blockstore/store.ts
|
288
|
+
var import_dag_json2 = require("@fireproof/vendor/@ipld/dag-json");
|
289
|
+
var import_cement8 = require("@adviser/cement");
|
290
|
+
|
291
|
+
// src/types.ts
|
292
|
+
function isFalsy(value) {
|
293
|
+
return value === false && value === null && value === void 0;
|
224
294
|
}
|
225
|
-
function
|
226
|
-
if (
|
227
|
-
|
295
|
+
function throwFalsy(value) {
|
296
|
+
if (isFalsy(value)) {
|
297
|
+
throw new Error("value is Falsy");
|
228
298
|
}
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
299
|
+
return value;
|
300
|
+
}
|
301
|
+
function falsyToUndef(value) {
|
302
|
+
if (isFalsy(value)) {
|
303
|
+
return void 0;
|
233
304
|
}
|
234
|
-
return
|
305
|
+
return value;
|
235
306
|
}
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
}
|
260
|
-
timeOrderedNextId(now) {
|
261
|
-
now = typeof now === "number" ? now : (/* @__PURE__ */ new Date()).getTime();
|
262
|
-
const t = (281474976710656 + now).toString(16).replace(/^1/, "");
|
263
|
-
const bin = this.crypto.randomBytes(10);
|
264
|
-
bin[1] = bin[1] & 240 | (bin[1] | 8 && 11);
|
265
|
-
const hex = Array.from(bin).map((i) => i.toString(16).padStart(2, "0")).join("");
|
266
|
-
return {
|
267
|
-
str: `${t.slice(0, 8)}-${t.slice(8)}-7${hex.slice(0, 3)}-${hex.slice(3, 7)}-${hex.slice(7, 19)}`
|
268
|
-
};
|
269
|
-
}
|
270
|
-
start() {
|
271
|
-
return Promise.resolve();
|
272
|
-
}
|
273
|
-
clone(override) {
|
274
|
-
return new _SuperThisImpl({
|
275
|
-
logger: override.logger || this.logger,
|
276
|
-
env: (0, import_cement.envFactory)(override.env) || this.env,
|
277
|
-
crypto: override.crypto || this.crypto,
|
278
|
-
pathOps: override.pathOps || this.pathOps,
|
279
|
-
txt: override.txt || this.txt,
|
280
|
-
ctx: { ...this.ctx, ...override.ctx }
|
281
|
-
});
|
282
|
-
}
|
283
|
-
};
|
284
|
-
pathOpsImpl = class {
|
285
|
-
join(...paths) {
|
286
|
-
return paths.map((i) => i.replace(/\/+$/, "")).join("/");
|
287
|
-
}
|
288
|
-
dirname(path) {
|
289
|
-
return path.split("/").slice(0, -1).join("/");
|
290
|
-
}
|
291
|
-
// homedir() {
|
292
|
-
// throw new Error("SysContainer:homedir is not available in seeded state");
|
293
|
-
// }
|
294
|
-
};
|
295
|
-
pathOps = new pathOpsImpl();
|
296
|
-
txtOps = {
|
297
|
-
// eslint-disable-next-line no-restricted-globals
|
298
|
-
encode: (input) => new TextEncoder().encode(input),
|
299
|
-
// eslint-disable-next-line no-restricted-globals
|
300
|
-
decode: (input) => new TextDecoder().decode(input)
|
301
|
-
};
|
302
|
-
_onSuperThis = /* @__PURE__ */ new Map();
|
303
|
-
NotFoundError = class extends Error {
|
304
|
-
constructor() {
|
305
|
-
super(...arguments);
|
306
|
-
this.code = "ENOENT";
|
307
|
-
}
|
307
|
+
|
308
|
+
// src/utils.ts
|
309
|
+
var import_cement = require("@adviser/cement");
|
310
|
+
var import_base58 = require("multiformats/bases/base58");
|
311
|
+
var _globalLogger = new import_cement.ResolveOnce();
|
312
|
+
function globalLogger() {
|
313
|
+
return _globalLogger.once(() => new import_cement.LoggerImpl());
|
314
|
+
}
|
315
|
+
var registerFP_DEBUG = new import_cement.ResolveOnce();
|
316
|
+
var SuperThisImpl = class _SuperThisImpl {
|
317
|
+
constructor(opts) {
|
318
|
+
this.logger = opts.logger;
|
319
|
+
this.env = opts.env;
|
320
|
+
this.crypto = opts.crypto;
|
321
|
+
this.pathOps = opts.pathOps;
|
322
|
+
this.txt = opts.txt;
|
323
|
+
this.ctx = { ...opts.ctx };
|
324
|
+
}
|
325
|
+
nextId(bytes = 6) {
|
326
|
+
const bin = this.crypto.randomBytes(bytes);
|
327
|
+
return {
|
328
|
+
str: import_base58.base58btc.encode(bin),
|
329
|
+
bin
|
308
330
|
};
|
309
331
|
}
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
const { MemFileSystem } = await import("@fireproof/core/mem");
|
320
|
-
return new MemFileSystem();
|
321
|
-
});
|
322
|
-
break;
|
323
|
-
// case 'deno': {
|
324
|
-
// const { DenoFileSystem } = await import("./deno-filesystem.js");
|
325
|
-
// fs = new DenoFileSystem();
|
326
|
-
// break;
|
327
|
-
// }
|
328
|
-
default:
|
329
|
-
fs = await externalLoaders.get(name).once(async () => {
|
330
|
-
const { NodeFileSystem } = await import("@fireproof/core/node");
|
331
|
-
return new NodeFileSystem();
|
332
|
-
});
|
332
|
+
timeOrderedNextId(now) {
|
333
|
+
now = typeof now === "number" ? now : (/* @__PURE__ */ new Date()).getTime();
|
334
|
+
const t = (281474976710656 + now).toString(16).replace(/^1/, "");
|
335
|
+
const bin = this.crypto.randomBytes(10);
|
336
|
+
bin[1] = bin[1] & 240 | (bin[1] | 8 && 11);
|
337
|
+
const hex = Array.from(bin).map((i) => i.toString(16).padStart(2, "0")).join("");
|
338
|
+
return {
|
339
|
+
str: `${t.slice(0, 8)}-${t.slice(8)}-7${hex.slice(0, 3)}-${hex.slice(3, 7)}-${hex.slice(7, 19)}`
|
340
|
+
};
|
333
341
|
}
|
334
|
-
|
335
|
-
|
336
|
-
var import_cement4, externalLoaders;
|
337
|
-
var init_get_file_system_static = __esm({
|
338
|
-
"src/runtime/gateways/file/get-file-system-static.ts"() {
|
339
|
-
"use strict";
|
340
|
-
import_cement4 = require("@adviser/cement");
|
341
|
-
externalLoaders = new import_cement4.KeyedResolvOnce();
|
342
|
+
start() {
|
343
|
+
return Promise.resolve();
|
342
344
|
}
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
});
|
352
|
-
function getPath(url, sthis) {
|
353
|
-
const basePath = url.pathname;
|
354
|
-
const name = url.getParam("name");
|
355
|
-
if (name) {
|
356
|
-
const version = url.getParam("version");
|
357
|
-
if (!version) throw sthis.logger.Error().Url(url).Msg(`version not found`).AsError();
|
358
|
-
return sthis.pathOps.join(basePath, version, name);
|
345
|
+
clone(override) {
|
346
|
+
return new _SuperThisImpl({
|
347
|
+
logger: override.logger || this.logger,
|
348
|
+
env: (0, import_cement.envFactory)(override.env) || this.env,
|
349
|
+
crypto: override.crypto || this.crypto,
|
350
|
+
pathOps: override.pathOps || this.pathOps,
|
351
|
+
txt: override.txt || this.txt,
|
352
|
+
ctx: { ...this.ctx, ...override.ctx }
|
353
|
+
});
|
359
354
|
}
|
360
|
-
|
355
|
+
};
|
356
|
+
function presetEnv() {
|
357
|
+
const penv = new Map([
|
358
|
+
// ["FP_DEBUG", "xxx"],
|
359
|
+
// ["FP_ENV", "development"],
|
360
|
+
...Array.from(
|
361
|
+
Object.entries(
|
362
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
363
|
+
globalThis[Symbol.for("FP_PRESET_ENV")] || {}
|
364
|
+
)
|
365
|
+
)
|
366
|
+
// .map(([k, v]) => [k, v as string])
|
367
|
+
]);
|
368
|
+
return penv;
|
361
369
|
}
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
const res = getStore(url, sthis, (...a) => a.join("-"));
|
366
|
-
switch (res.store) {
|
367
|
-
case "data":
|
368
|
-
return sthis.pathOps.join(res.name, key + ".car");
|
369
|
-
case "wal":
|
370
|
-
case "meta":
|
371
|
-
return sthis.pathOps.join(res.name, key + ".json");
|
372
|
-
default:
|
373
|
-
throw sthis.logger.Error().Url(url).Msg(`unsupported store type`).AsError();
|
370
|
+
var pathOpsImpl = class {
|
371
|
+
join(...paths) {
|
372
|
+
return paths.map((i) => i.replace(/\/+$/, "")).join("/");
|
374
373
|
}
|
375
|
-
|
376
|
-
|
377
|
-
"src/runtime/gateways/file/utils.ts"() {
|
378
|
-
"use strict";
|
379
|
-
init_utils();
|
380
|
-
init_get_file_system_static();
|
374
|
+
dirname(path) {
|
375
|
+
return path.split("/").slice(0, -1).join("/");
|
381
376
|
}
|
382
|
-
|
383
|
-
|
384
|
-
//
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
const { getFileSystem: getFileSystem2 } = await Promise.resolve().then(() => (init_utils2(), utils_exports));
|
401
|
-
sysFS = await getFileSystem2(this.url);
|
402
|
-
break;
|
403
|
-
}
|
404
|
-
default:
|
405
|
-
throw this.logger.Error().Url(this.url).Msg("unsupported protocol").AsError();
|
406
|
-
}
|
407
|
-
const dirName = this.url.pathname;
|
408
|
-
await sysFS.mkdir(dirName, { recursive: true });
|
409
|
-
return {
|
410
|
-
dirName,
|
411
|
-
sysFS,
|
412
|
-
fName: this.sthis.pathOps.join(dirName, `${id.replace(/[^a-zA-Z0-9]/g, "_")}.json`)
|
413
|
-
};
|
414
|
-
}
|
415
|
-
constructor(url, sthis) {
|
416
|
-
this.url = url;
|
417
|
-
this.sthis = sthis;
|
418
|
-
this.logger = sthis.logger;
|
419
|
-
}
|
420
|
-
async get(id) {
|
421
|
-
const ctx = await this._prepare(id);
|
422
|
-
try {
|
423
|
-
const p = await ctx.sysFS.readfile(ctx.fName);
|
424
|
-
const ki = JSON.parse(this.sthis.txt.decode(p));
|
425
|
-
return ki;
|
426
|
-
} catch (e) {
|
427
|
-
if (isNotFoundError(e)) {
|
428
|
-
return void 0;
|
429
|
-
}
|
430
|
-
throw this.logger.Error().Err(e).Str("file", ctx.dirName).Msg("read bag failed").AsError();
|
431
|
-
}
|
432
|
-
}
|
433
|
-
async set(id, item) {
|
434
|
-
const ctx = await this._prepare(id);
|
435
|
-
const p = this.sthis.txt.encode(JSON.stringify(item, null, 2));
|
436
|
-
await ctx.sysFS.writefile(ctx.fName, p);
|
437
|
-
}
|
438
|
-
};
|
439
|
-
}
|
440
|
-
});
|
441
|
-
|
442
|
-
// src/runtime/key-bag-indexdb.ts
|
443
|
-
var key_bag_indexdb_exports = {};
|
444
|
-
__export(key_bag_indexdb_exports, {
|
445
|
-
KeyBagProviderIndexDB: () => KeyBagProviderIndexDB
|
446
|
-
});
|
447
|
-
var import_idb, import_cement5, KeyBagProviderIndexDB;
|
448
|
-
var init_key_bag_indexdb = __esm({
|
449
|
-
"src/runtime/key-bag-indexdb.ts"() {
|
450
|
-
"use strict";
|
451
|
-
import_idb = require("idb");
|
452
|
-
init_utils2();
|
453
|
-
import_cement5 = require("@adviser/cement");
|
454
|
-
KeyBagProviderIndexDB = class {
|
455
|
-
constructor(url, sthis) {
|
456
|
-
this._db = new import_cement5.ResolveOnce();
|
457
|
-
this.sthis = sthis;
|
458
|
-
this.logger = sthis.logger;
|
459
|
-
this.url = url;
|
460
|
-
this.dbName = getPath(this.url, this.sthis);
|
461
|
-
}
|
462
|
-
async _prepare() {
|
463
|
-
return this._db.once(async () => {
|
464
|
-
return await (0, import_idb.openDB)(this.dbName, 1, {
|
465
|
-
upgrade(db) {
|
466
|
-
["bag"].map((store) => {
|
467
|
-
db.createObjectStore(store, {
|
468
|
-
autoIncrement: false
|
469
|
-
});
|
470
|
-
});
|
471
|
-
}
|
472
|
-
});
|
473
|
-
});
|
474
|
-
}
|
475
|
-
async get(id) {
|
476
|
-
const db = await this._prepare();
|
477
|
-
const tx = db.transaction(["bag"], "readonly");
|
478
|
-
const keyItem = await tx.objectStore("bag").get(id);
|
479
|
-
await tx.done;
|
480
|
-
if (!keyItem) {
|
481
|
-
return void 0;
|
482
|
-
}
|
483
|
-
return keyItem;
|
484
|
-
}
|
485
|
-
async set(id, item) {
|
486
|
-
const db = await this._prepare();
|
487
|
-
const tx = db.transaction(["bag"], "readwrite");
|
488
|
-
await tx.objectStore("bag").put(item, id);
|
489
|
-
await tx.done;
|
490
|
-
}
|
491
|
-
};
|
492
|
-
}
|
493
|
-
});
|
494
|
-
|
495
|
-
// src/runtime/gateways/file/version.ts
|
496
|
-
var FILESTORE_VERSION;
|
497
|
-
var init_version = __esm({
|
498
|
-
"src/runtime/gateways/file/version.ts"() {
|
499
|
-
"use strict";
|
500
|
-
FILESTORE_VERSION = "v0.19-file";
|
501
|
-
}
|
502
|
-
});
|
503
|
-
|
504
|
-
// src/runtime/gateways/file/gateway.ts
|
505
|
-
var gateway_exports = {};
|
506
|
-
__export(gateway_exports, {
|
507
|
-
FileGateway: () => FileGateway,
|
508
|
-
FileTestStore: () => FileTestStore
|
509
|
-
});
|
510
|
-
var import_cement11, versionFiles, FileGateway, FileTestStore;
|
511
|
-
var init_gateway = __esm({
|
512
|
-
"src/runtime/gateways/file/gateway.ts"() {
|
513
|
-
"use strict";
|
514
|
-
init_version();
|
515
|
-
import_cement11 = require("@adviser/cement");
|
516
|
-
init_utils();
|
517
|
-
init_utils2();
|
518
|
-
init_get_file_system_static();
|
519
|
-
versionFiles = new import_cement11.KeyedResolvOnce();
|
520
|
-
FileGateway = class {
|
521
|
-
get fs() {
|
522
|
-
if (!this._fs) throw this.logger.Error().Msg("fs not initialized").AsError();
|
523
|
-
return this._fs;
|
524
|
-
}
|
525
|
-
constructor(sthis) {
|
526
|
-
this.sthis = sthis;
|
527
|
-
this.logger = sthis.logger;
|
528
|
-
}
|
529
|
-
async getVersionFromFile(path, logger) {
|
530
|
-
return versionFiles.get(path).once(async () => {
|
531
|
-
await this.fs.mkdir(path, { recursive: true });
|
532
|
-
const vFile = this.sthis.pathOps.join(path, "version");
|
533
|
-
const vFileStat = await this.fs.stat(vFile).catch(() => void 0);
|
534
|
-
if (!vFileStat) {
|
535
|
-
await this.fs.writefile(this.sthis.pathOps.join(path, "version"), FILESTORE_VERSION);
|
536
|
-
return FILESTORE_VERSION;
|
537
|
-
} else if (!vFileStat.isFile()) {
|
538
|
-
throw logger.Error().Str("file", vFile).Msg(`version file is a directory`).AsError();
|
539
|
-
}
|
540
|
-
const v = await this.fs.readfile(vFile);
|
541
|
-
const vStr = this.sthis.txt.decode(v);
|
542
|
-
if (vStr !== FILESTORE_VERSION) {
|
543
|
-
logger.Warn().Str("file", vFile).Str("from", vStr).Str("expected", FILESTORE_VERSION).Msg(`version mismatch`);
|
544
|
-
}
|
545
|
-
return vStr;
|
546
|
-
});
|
547
|
-
}
|
548
|
-
start(baseURL) {
|
549
|
-
return (0, import_cement11.exception2Result)(async () => {
|
550
|
-
this._fs = await getFileSystem(baseURL);
|
551
|
-
await this.fs.start();
|
552
|
-
const url = baseURL.build();
|
553
|
-
url.defParam("version", FILESTORE_VERSION);
|
554
|
-
const dbUrl = await this.buildUrl(url.URI(), "dummy");
|
555
|
-
const dbdirFile = this.getFilePath(dbUrl.Ok());
|
556
|
-
await this.fs.mkdir(this.sthis.pathOps.dirname(dbdirFile), { recursive: true });
|
557
|
-
const dbroot = this.sthis.pathOps.dirname(dbdirFile);
|
558
|
-
this.logger.Debug().Url(url.URI()).Str("dbroot", dbroot).Msg("start");
|
559
|
-
url.setParam("version", await this.getVersionFromFile(dbroot, this.logger));
|
560
|
-
return url.URI();
|
561
|
-
});
|
562
|
-
}
|
563
|
-
async buildUrl(baseUrl, key) {
|
564
|
-
return import_cement11.Result.Ok(baseUrl.build().setParam("key", key).URI());
|
565
|
-
}
|
566
|
-
async close() {
|
567
|
-
return import_cement11.Result.Ok(void 0);
|
568
|
-
}
|
569
|
-
// abstract buildUrl(baseUrl: URL, key: string): Promise<Result<URL>>;
|
570
|
-
getFilePath(url) {
|
571
|
-
const key = url.getParam("key");
|
572
|
-
if (!key) throw this.logger.Error().Url(url).Msg(`key not found`).AsError();
|
573
|
-
return this.sthis.pathOps.join(getPath(url, this.sthis), getFileName(url, this.sthis));
|
574
|
-
}
|
575
|
-
async put(url, body) {
|
576
|
-
return (0, import_cement11.exception2Result)(async () => {
|
577
|
-
const file = await this.getFilePath(url);
|
578
|
-
this.logger.Debug().Str("url", url.toString()).Str("file", file).Msg("put");
|
579
|
-
await this.fs.writefile(file, body);
|
580
|
-
});
|
581
|
-
}
|
582
|
-
async get(url) {
|
583
|
-
return exceptionWrapper(async () => {
|
584
|
-
const file = this.getFilePath(url);
|
585
|
-
try {
|
586
|
-
const res = await this.fs.readfile(file);
|
587
|
-
this.logger.Debug().Url(url.asURL()).Str("file", file).Msg("get");
|
588
|
-
return import_cement11.Result.Ok(new Uint8Array(res));
|
589
|
-
} catch (e) {
|
590
|
-
if (isNotFoundError(e)) {
|
591
|
-
return import_cement11.Result.Err(new NotFoundError(`file not found: ${file}`));
|
592
|
-
}
|
593
|
-
return import_cement11.Result.Err(e);
|
594
|
-
}
|
595
|
-
});
|
596
|
-
}
|
597
|
-
async delete(url) {
|
598
|
-
return (0, import_cement11.exception2Result)(async () => {
|
599
|
-
await this.fs.unlink(this.getFilePath(url));
|
600
|
-
});
|
601
|
-
}
|
602
|
-
async destroy(baseURL) {
|
603
|
-
const url = await this.buildUrl(baseURL, "x");
|
604
|
-
if (url.isErr()) return url;
|
605
|
-
const filepath = this.sthis.pathOps.dirname(this.getFilePath(url.Ok()));
|
606
|
-
let files = [];
|
607
|
-
try {
|
608
|
-
files = await this.fs.readdir(filepath);
|
609
|
-
} catch (e) {
|
610
|
-
if (!isNotFoundError(e)) {
|
611
|
-
throw this.logger.Error().Err(e).Str("dir", filepath).Msg("destroy:readdir").AsError();
|
612
|
-
}
|
613
|
-
}
|
614
|
-
for (const file of files) {
|
615
|
-
const pathed = this.sthis.pathOps.join(filepath, file);
|
616
|
-
try {
|
617
|
-
await this.fs.unlink(pathed);
|
618
|
-
} catch (e) {
|
619
|
-
if (!isNotFoundError(e)) {
|
620
|
-
throw this.logger.Error().Err(e).Str("file", pathed).Msg("destroy:unlink").AsError();
|
621
|
-
}
|
622
|
-
}
|
623
|
-
}
|
624
|
-
return import_cement11.Result.Ok(void 0);
|
625
|
-
}
|
626
|
-
};
|
627
|
-
FileTestStore = class {
|
628
|
-
constructor(sthis) {
|
629
|
-
this.logger = ensureLogger(sthis, "FileTestStore");
|
630
|
-
this.sthis = sthis;
|
631
|
-
}
|
632
|
-
async get(iurl, key) {
|
633
|
-
const url = iurl.build().setParam("key", key).URI();
|
634
|
-
const dbFile = this.sthis.pathOps.join(getPath(url, this.sthis), getFileName(url, this.sthis));
|
635
|
-
this.logger.Debug().Url(url).Str("dbFile", dbFile).Msg("get");
|
636
|
-
const buffer = await (await getFileSystem(url)).readfile(dbFile);
|
637
|
-
this.logger.Debug().Url(url).Str("dbFile", dbFile).Len(buffer).Msg("got");
|
638
|
-
return buffer;
|
639
|
-
}
|
640
|
-
};
|
641
|
-
}
|
642
|
-
});
|
643
|
-
|
644
|
-
// src/runtime/gateways/indexdb/gateway-import-static.ts
|
645
|
-
function gatewayImport() {
|
646
|
-
return import("@fireproof/core/web");
|
377
|
+
// homedir() {
|
378
|
+
// throw new Error("SysContainer:homedir is not available in seeded state");
|
379
|
+
// }
|
380
|
+
};
|
381
|
+
var pathOps = new pathOpsImpl();
|
382
|
+
var txtOps = {
|
383
|
+
// eslint-disable-next-line no-restricted-globals
|
384
|
+
encode: (input) => new TextEncoder().encode(input),
|
385
|
+
// eslint-disable-next-line no-restricted-globals
|
386
|
+
decode: (input) => new TextDecoder().decode(input)
|
387
|
+
};
|
388
|
+
var _onSuperThis = /* @__PURE__ */ new Map();
|
389
|
+
function onSuperThis(fn) {
|
390
|
+
const key = `onSuperThis-${Math.random().toString(36).slice(2)}`;
|
391
|
+
_onSuperThis.set(key, fn);
|
392
|
+
return () => {
|
393
|
+
_onSuperThis.delete(key);
|
394
|
+
};
|
647
395
|
}
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
});
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
return this.getGateway().then((gw) => gw.buildUrl(baseUrl, key));
|
678
|
-
}
|
679
|
-
start(baseUrl) {
|
680
|
-
return this.getGateway().then((gw) => gw.start(baseUrl));
|
681
|
-
}
|
682
|
-
close(baseUrl) {
|
683
|
-
return this.getGateway().then((gw) => gw.close(baseUrl));
|
684
|
-
}
|
685
|
-
destroy(baseUrl) {
|
686
|
-
return this.getGateway().then((gw) => gw.destroy(baseUrl));
|
687
|
-
}
|
688
|
-
put(url, body) {
|
689
|
-
return this.getGateway().then((gw) => gw.put(url, body));
|
690
|
-
}
|
691
|
-
get(url) {
|
692
|
-
return this.getGateway().then((gw) => gw.get(url));
|
693
|
-
}
|
694
|
-
delete(url) {
|
695
|
-
return this.getGateway().then((gw) => gw.delete(url));
|
696
|
-
}
|
697
|
-
// subscribe?(url: URI, callback: (meta: Uint8Array) => void): Promise<UnsubscribeResult> {
|
698
|
-
// // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
699
|
-
// return this.getGateway().then(gw => gw.subscribe!(url, callback));
|
700
|
-
// }
|
701
|
-
};
|
702
|
-
IndexDBTestStore = class {
|
703
|
-
constructor(sthis) {
|
704
|
-
this.loadExternal = new import_cement12.ResolveOnce();
|
705
|
-
this.sthis = sthis;
|
706
|
-
}
|
707
|
-
getGateway() {
|
708
|
-
return this.loadExternal.once(() => {
|
709
|
-
return gatewayImport().then(({ IndexDBTestStore: IndexDBTestStore2 }) => new IndexDBTestStore2(this.sthis));
|
710
|
-
});
|
711
|
-
}
|
712
|
-
get(url, key) {
|
713
|
-
return this.getGateway().then((gw) => gw.get(url, key));
|
714
|
-
}
|
715
|
-
};
|
396
|
+
function ensureSuperThis(osthis) {
|
397
|
+
const env = (0, import_cement.envFactory)({
|
398
|
+
symbol: osthis?.env?.symbol || "FP_ENV",
|
399
|
+
presetEnv: osthis?.env?.presetEnv || presetEnv()
|
400
|
+
});
|
401
|
+
const ret = new SuperThisImpl({
|
402
|
+
logger: osthis?.logger || globalLogger(),
|
403
|
+
env,
|
404
|
+
crypto: osthis?.crypto || (0, import_cement.toCryptoRuntime)(),
|
405
|
+
ctx: osthis?.ctx || {},
|
406
|
+
pathOps,
|
407
|
+
txt: osthis?.txt || txtOps
|
408
|
+
});
|
409
|
+
_onSuperThis.forEach((fn) => fn(ret));
|
410
|
+
return ret;
|
411
|
+
}
|
412
|
+
function ensureSuperLog(sthis, componentName, ctx) {
|
413
|
+
return sthis.clone({
|
414
|
+
logger: ensureLogger(sthis, componentName, ctx)
|
415
|
+
});
|
416
|
+
}
|
417
|
+
function ensureLogger(sthis, componentName, ctx) {
|
418
|
+
let logger;
|
419
|
+
if ((0, import_cement.IsLogger)(sthis)) {
|
420
|
+
logger = sthis;
|
421
|
+
} else if (sthis && (0, import_cement.IsLogger)(sthis.logger)) {
|
422
|
+
logger = sthis.logger;
|
423
|
+
} else {
|
424
|
+
logger = globalLogger();
|
716
425
|
}
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
PACKAGE_VERSION: () => PACKAGE_VERSION,
|
727
|
-
Result: () => import_cement.Result,
|
728
|
-
UInt8ArrayEqual: () => UInt8ArrayEqual,
|
729
|
-
blockstore: () => blockstore_exports,
|
730
|
-
bs: () => blockstore_exports,
|
731
|
-
dataDir: () => dataDir,
|
732
|
-
ensureLogger: () => ensureLogger,
|
733
|
-
ensureSuperLog: () => ensureSuperLog,
|
734
|
-
ensureSuperThis: () => ensureSuperThis,
|
735
|
-
exceptionWrapper: () => exceptionWrapper,
|
736
|
-
falsyToUndef: () => falsyToUndef,
|
737
|
-
fireproof: () => fireproof,
|
738
|
-
getKey: () => getKey,
|
739
|
-
getName: () => getName,
|
740
|
-
getStore: () => getStore,
|
741
|
-
index: () => index,
|
742
|
-
isFalsy: () => isFalsy,
|
743
|
-
isNotFoundError: () => isNotFoundError,
|
744
|
-
onSuperThis: () => onSuperThis,
|
745
|
-
rt: () => runtime_exports,
|
746
|
-
runtime: () => runtime_exports,
|
747
|
-
throwFalsy: () => throwFalsy
|
748
|
-
});
|
749
|
-
module.exports = __toCommonJS(index_exports);
|
750
|
-
|
751
|
-
// src/database.ts
|
752
|
-
var import_cement16 = require("@adviser/cement");
|
753
|
-
|
754
|
-
// src/write-queue.ts
|
755
|
-
function writeQueue(worker, payload = Infinity, unbounded = false) {
|
756
|
-
const queue = [];
|
757
|
-
let isProcessing = false;
|
758
|
-
async function process() {
|
759
|
-
if (isProcessing || queue.length === 0) return;
|
760
|
-
isProcessing = true;
|
761
|
-
const tasksToProcess = queue.splice(0, payload);
|
762
|
-
const updates = tasksToProcess.map((item) => item.task);
|
763
|
-
if (unbounded) {
|
764
|
-
const promises = updates.map(async (update, index2) => {
|
765
|
-
try {
|
766
|
-
const result = await worker([update]);
|
767
|
-
tasksToProcess[index2].resolve(result);
|
768
|
-
} catch (error) {
|
769
|
-
tasksToProcess[index2].reject(error);
|
770
|
-
}
|
771
|
-
});
|
772
|
-
await Promise.all(promises);
|
773
|
-
} else {
|
774
|
-
try {
|
775
|
-
const result = await worker(updates);
|
776
|
-
tasksToProcess.forEach((task) => task.resolve(result));
|
777
|
-
} catch (error) {
|
778
|
-
tasksToProcess.forEach((task) => task.reject(error));
|
426
|
+
const cLogger = logger.With().Module(componentName);
|
427
|
+
const debug = [];
|
428
|
+
let exposeStack = false;
|
429
|
+
if (ctx) {
|
430
|
+
if ("debug" in ctx) {
|
431
|
+
if (typeof ctx.debug === "string" && ctx.debug.length > 0) {
|
432
|
+
debug.push(ctx.debug);
|
433
|
+
} else {
|
434
|
+
debug.push(componentName);
|
779
435
|
}
|
436
|
+
delete ctx.debug;
|
780
437
|
}
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
438
|
+
if ("exposeStack" in ctx) {
|
439
|
+
exposeStack = true;
|
440
|
+
delete ctx.exposeStack;
|
441
|
+
}
|
442
|
+
if ("this" in ctx) {
|
443
|
+
cLogger.Str("this", sthis.nextId(4).str);
|
444
|
+
delete ctx.this;
|
445
|
+
}
|
446
|
+
for (const [key, value] of Object.entries(ctx)) {
|
447
|
+
switch (typeof value) {
|
448
|
+
case "string":
|
449
|
+
cLogger.Str(key, value);
|
450
|
+
break;
|
451
|
+
case "number":
|
452
|
+
cLogger.Uint64(key, value);
|
453
|
+
break;
|
454
|
+
default:
|
455
|
+
if (value instanceof Date) {
|
456
|
+
cLogger.Str(key, value.toISOString());
|
457
|
+
} else if ((0, import_cement.isURL)(value)) {
|
458
|
+
cLogger.Str(key, value.toString());
|
459
|
+
} else if (typeof value === "function") {
|
460
|
+
cLogger.Ref(key, value);
|
461
|
+
} else {
|
462
|
+
cLogger.Any(key, value);
|
463
|
+
}
|
464
|
+
break;
|
465
|
+
}
|
790
466
|
}
|
791
|
-
};
|
792
|
-
}
|
793
|
-
|
794
|
-
// src/crdt.ts
|
795
|
-
var import_cement15 = require("@adviser/cement");
|
796
|
-
|
797
|
-
// src/runtime/wait-pr-multiformats/block.ts
|
798
|
-
var block_exports = {};
|
799
|
-
__export(block_exports, {
|
800
|
-
Block: () => Block,
|
801
|
-
create: () => create,
|
802
|
-
createUnsafe: () => createUnsafe,
|
803
|
-
decode: () => decode,
|
804
|
-
encode: () => encode
|
805
|
-
});
|
806
|
-
var import_multiformats = require("multiformats");
|
807
|
-
var import_block = require("multiformats/block");
|
808
|
-
var Block = import_block.Block;
|
809
|
-
async function decode({
|
810
|
-
bytes,
|
811
|
-
codec: codec3,
|
812
|
-
hasher: hasher7
|
813
|
-
}) {
|
814
|
-
if (bytes == null) throw new Error('Missing required argument "bytes"');
|
815
|
-
if (codec3 == null || hasher7 == null) throw new Error("Missing required argument: codec or hasher");
|
816
|
-
const value = await Promise.resolve(codec3.decode(bytes));
|
817
|
-
const hash = await hasher7.digest(bytes);
|
818
|
-
const cid = import_multiformats.CID.create(1, codec3.code, hash);
|
819
|
-
return new import_block.Block({ value, bytes, cid });
|
820
|
-
}
|
821
|
-
async function encode({
|
822
|
-
value,
|
823
|
-
codec: codec3,
|
824
|
-
hasher: hasher7
|
825
|
-
}) {
|
826
|
-
if (typeof value === "undefined") throw new Error('Missing required argument "value"');
|
827
|
-
if (codec3 == null || hasher7 == null) throw new Error("Missing required argument: codec or hasher");
|
828
|
-
const bytes = await Promise.resolve(codec3.encode(value));
|
829
|
-
const hash = await hasher7.digest(bytes);
|
830
|
-
const cid = import_multiformats.CID.create(1, codec3.code, hash);
|
831
|
-
return new import_block.Block({ value, bytes, cid });
|
832
|
-
}
|
833
|
-
async function create({
|
834
|
-
bytes,
|
835
|
-
cid,
|
836
|
-
hasher: hasher7,
|
837
|
-
codec: codec3
|
838
|
-
}) {
|
839
|
-
if (bytes == null) throw new Error('Missing required argument "bytes"');
|
840
|
-
if (hasher7 == null) throw new Error('Missing required argument "hasher"');
|
841
|
-
const value = await Promise.resolve(codec3.decode(bytes));
|
842
|
-
const hash = await hasher7.digest(bytes);
|
843
|
-
if (!import_multiformats.bytes.equals(cid.multihash.bytes, hash.bytes)) {
|
844
|
-
throw new Error("CID hash does not match bytes");
|
845
467
|
}
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
468
|
+
registerFP_DEBUG.once(async () => {
|
469
|
+
sthis.env.onSet(
|
470
|
+
(key, value) => {
|
471
|
+
switch (key) {
|
472
|
+
case "FP_FORMAT": {
|
473
|
+
switch (value) {
|
474
|
+
case "jsonice":
|
475
|
+
logger.SetFormatter(new import_cement.JSONFormatter(logger.TxtEnDe(), 2));
|
476
|
+
break;
|
477
|
+
case "yaml":
|
478
|
+
logger.SetFormatter(new import_cement.YAMLFormatter(logger.TxtEnDe(), 2));
|
479
|
+
break;
|
480
|
+
case "json":
|
481
|
+
default:
|
482
|
+
logger.SetFormatter(new import_cement.JSONFormatter(logger.TxtEnDe()));
|
483
|
+
break;
|
484
|
+
}
|
485
|
+
break;
|
486
|
+
}
|
487
|
+
case "FP_DEBUG":
|
488
|
+
logger.SetDebug(value || []);
|
489
|
+
break;
|
490
|
+
case "FP_STACK":
|
491
|
+
logger.SetExposeStack(!!value);
|
492
|
+
break;
|
493
|
+
}
|
494
|
+
},
|
495
|
+
"FP_FORMAT",
|
496
|
+
"FP_DEBUG",
|
497
|
+
"FP_STACK"
|
498
|
+
);
|
499
|
+
}).finally(() => {
|
865
500
|
});
|
501
|
+
if (debug.length > 0) {
|
502
|
+
logger.SetDebug(debug);
|
503
|
+
}
|
504
|
+
if (exposeStack) {
|
505
|
+
logger.SetExposeStack(true);
|
506
|
+
}
|
507
|
+
const out = cLogger.Logger();
|
508
|
+
return out;
|
866
509
|
}
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
ConnectionBase: () => ConnectionBase,
|
883
|
-
EncryptedBlockstore: () => EncryptedBlockstore,
|
884
|
-
FragmentGateway: () => FragmentGateway,
|
885
|
-
Loader: () => Loader,
|
886
|
-
addCryptoKeyToGatewayMetaPayload: () => addCryptoKeyToGatewayMetaPayload,
|
887
|
-
ensureStart: () => ensureStart,
|
888
|
-
getGatewayFromURL: () => getGatewayFromURL,
|
889
|
-
parseCarFile: () => parseCarFile,
|
890
|
-
registerStoreProtocol: () => registerStoreProtocol,
|
891
|
-
setCryptoKeyFromGatewayMetaPayload: () => setCryptoKeyFromGatewayMetaPayload,
|
892
|
-
testStoreFactory: () => testStoreFactory,
|
893
|
-
toCIDBlock: () => toCIDBlock,
|
894
|
-
toStoreRuntime: () => toStoreRuntime
|
895
|
-
});
|
896
|
-
|
897
|
-
// src/blockstore/types.ts
|
898
|
-
function toCIDBlock(block) {
|
899
|
-
return block;
|
900
|
-
}
|
901
|
-
|
902
|
-
// src/blockstore/store-factory.ts
|
903
|
-
var import_cement13 = require("@adviser/cement");
|
904
|
-
|
905
|
-
// src/runtime/files.ts
|
906
|
-
var files_exports = {};
|
907
|
-
__export(files_exports, {
|
908
|
-
decodeFile: () => decodeFile,
|
909
|
-
encodeFile: () => encodeFile
|
910
|
-
});
|
911
|
-
var UnixFS = __toESM(require("@ipld/unixfs"), 1);
|
912
|
-
var raw = __toESM(require("multiformats/codecs/raw"), 1);
|
913
|
-
var import_fixed = require("@ipld/unixfs/file/chunker/fixed");
|
914
|
-
var import_balanced = require("@ipld/unixfs/file/layout/balanced");
|
915
|
-
var import_ipfs_unixfs_exporter = require("@fireproof/vendor/ipfs-unixfs-exporter");
|
916
|
-
var queuingStrategy = UnixFS.withCapacity();
|
917
|
-
var settings = UnixFS.configure({
|
918
|
-
fileChunkEncoder: raw,
|
919
|
-
smallFileEncoder: raw,
|
920
|
-
chunker: (0, import_fixed.withMaxChunkSize)(1024 * 1024),
|
921
|
-
fileLayout: (0, import_balanced.withWidth)(1024)
|
922
|
-
});
|
923
|
-
async function collect(collectable) {
|
924
|
-
const chunks = [];
|
925
|
-
await collectable.pipeTo(
|
926
|
-
new WritableStream({
|
927
|
-
write(chunk) {
|
928
|
-
chunks.push(chunk);
|
929
|
-
}
|
930
|
-
})
|
931
|
-
);
|
932
|
-
return chunks;
|
510
|
+
function getStore(url, sthis, joiner) {
|
511
|
+
const store = url.getParam("store");
|
512
|
+
switch (store) {
|
513
|
+
case "data":
|
514
|
+
case "wal":
|
515
|
+
case "meta":
|
516
|
+
break;
|
517
|
+
default:
|
518
|
+
throw sthis.logger.Error().Url(url).Msg(`store not found`).AsError();
|
519
|
+
}
|
520
|
+
let name = store;
|
521
|
+
if (url.hasParam("index")) {
|
522
|
+
name = joiner(url.getParam("index") || "idx", name);
|
523
|
+
}
|
524
|
+
return { store, name };
|
933
525
|
}
|
934
|
-
|
935
|
-
const
|
936
|
-
|
937
|
-
return
|
526
|
+
function getKey(url, logger) {
|
527
|
+
const result = url.getParam("key");
|
528
|
+
if (!result) throw logger.Error().Str("url", url.toString()).Msg(`key not found`).AsError();
|
529
|
+
return result;
|
938
530
|
}
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
531
|
+
function getName(sthis, url) {
|
532
|
+
let result = url.getParam("name");
|
533
|
+
if (!result) {
|
534
|
+
result = sthis.pathOps.dirname(url.pathname);
|
535
|
+
if (result.length === 0) {
|
536
|
+
throw sthis.logger.Error().Str("url", url.toString()).Msg(`name not found`).AsError();
|
537
|
+
}
|
944
538
|
}
|
945
|
-
return
|
539
|
+
return result;
|
946
540
|
}
|
947
|
-
function
|
948
|
-
|
949
|
-
const unixfsWriter = UnixFS.createWriter({ writable, settings });
|
950
|
-
const fileBuilder = new UnixFSFileBuilder("", blob);
|
951
|
-
void (async () => {
|
952
|
-
await fileBuilder.finalize(unixfsWriter);
|
953
|
-
await unixfsWriter.close();
|
954
|
-
})();
|
955
|
-
return readable;
|
541
|
+
async function exceptionWrapper(fn) {
|
542
|
+
return fn().catch((e) => import_cement.Result.Err(e));
|
956
543
|
}
|
957
|
-
var
|
958
|
-
|
959
|
-
|
960
|
-
this.
|
961
|
-
this.#file = file;
|
962
|
-
}
|
963
|
-
async finalize(writer) {
|
964
|
-
const unixfsFileWriter = UnixFS.createFileWriter(writer);
|
965
|
-
await this.#file.stream().pipeTo(
|
966
|
-
new WritableStream({
|
967
|
-
async write(chunk) {
|
968
|
-
await unixfsFileWriter.write(chunk);
|
969
|
-
}
|
970
|
-
})
|
971
|
-
);
|
972
|
-
return await unixfsFileWriter.close();
|
544
|
+
var NotFoundError = class extends Error {
|
545
|
+
constructor() {
|
546
|
+
super(...arguments);
|
547
|
+
this.code = "ENOENT";
|
973
548
|
}
|
974
549
|
};
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
return value === false && value === null && value === void 0;
|
550
|
+
function isNotFoundError(e) {
|
551
|
+
if (import_cement.Result.Is(e)) {
|
552
|
+
if (e.isOk()) return false;
|
553
|
+
e = e.Err();
|
554
|
+
}
|
555
|
+
if (e.code === "ENOENT") return true;
|
556
|
+
return false;
|
983
557
|
}
|
984
|
-
function
|
985
|
-
if (
|
986
|
-
|
558
|
+
function dataDir(sthis, name, base) {
|
559
|
+
if (!base) {
|
560
|
+
if (!(0, import_cement.runtimeFn)().isBrowser) {
|
561
|
+
const home = sthis.env.get("HOME") || "./";
|
562
|
+
base = sthis.env.get("FP_STORAGE_URL") || `file://${sthis.pathOps.join(home, ".fireproof")}`;
|
563
|
+
} else {
|
564
|
+
base = sthis.env.get("FP_STORAGE_URL") || `indexdb://fp`;
|
565
|
+
}
|
987
566
|
}
|
988
|
-
return
|
567
|
+
return import_cement.URI.from(base.toString()).build().setParam("name", name || "").URI();
|
989
568
|
}
|
990
|
-
function
|
991
|
-
if (
|
992
|
-
return
|
569
|
+
function UInt8ArrayEqual(a, b) {
|
570
|
+
if (a.length !== b.length) {
|
571
|
+
return false;
|
993
572
|
}
|
994
|
-
|
573
|
+
for (let i = 0; i < a.length; i++) {
|
574
|
+
if (a[i] !== b[i]) {
|
575
|
+
return false;
|
576
|
+
}
|
577
|
+
}
|
578
|
+
return true;
|
995
579
|
}
|
996
580
|
|
997
|
-
// src/blockstore/store.ts
|
998
|
-
init_utils();
|
999
|
-
|
1000
581
|
// src/blockstore/loader.ts
|
1001
582
|
var import_p_limit = __toESM(require("p-limit"), 1);
|
1002
583
|
var import_reader = require("@fireproof/vendor/@ipld/car/reader");
|
1003
|
-
var
|
584
|
+
var import_cement5 = require("@adviser/cement");
|
1004
585
|
|
1005
586
|
// src/blockstore/loader-helpers.ts
|
1006
587
|
var import_sha2 = require("multiformats/hashes/sha2");
|
@@ -1020,7 +601,6 @@ async function parseCarFile(reader, logger) {
|
|
1020
601
|
// src/blockstore/transaction.ts
|
1021
602
|
var import_block3 = require("@fireproof/vendor/@web3-storage/pail/block");
|
1022
603
|
var import_cement2 = require("@adviser/cement");
|
1023
|
-
init_utils();
|
1024
604
|
var CarTransaction = class extends import_block3.MemoryBlockstore {
|
1025
605
|
constructor(parent, opts = { add: true, noLoader: false }) {
|
1026
606
|
super();
|
@@ -1289,14 +869,13 @@ __export(key_bag_exports, {
|
|
1289
869
|
getKeyBag: () => getKeyBag,
|
1290
870
|
registerKeyBagProviderFactory: () => registerKeyBagProviderFactory
|
1291
871
|
});
|
1292
|
-
var
|
1293
|
-
init_utils();
|
872
|
+
var import_cement4 = require("@adviser/cement");
|
1294
873
|
var import_base582 = require("multiformats/bases/base58");
|
1295
874
|
var KeyBag = class {
|
1296
875
|
constructor(rt) {
|
1297
876
|
this.rt = rt;
|
1298
|
-
this._warnOnce = new
|
1299
|
-
this._seq = new
|
877
|
+
this._warnOnce = new import_cement4.ResolveOnce();
|
878
|
+
this._seq = new import_cement4.ResolveSeq();
|
1300
879
|
this.logger = ensureLogger(rt.sthis, "KeyBag");
|
1301
880
|
this.logger.Debug().Msg("KeyBag created");
|
1302
881
|
}
|
@@ -1320,7 +899,7 @@ var KeyBag = class {
|
|
1320
899
|
async ensureKeyFromUrl(url, keyFactory) {
|
1321
900
|
const storeKey = url.getParam("storekey");
|
1322
901
|
if (storeKey === "insecure") {
|
1323
|
-
return
|
902
|
+
return import_cement4.Result.Ok(url);
|
1324
903
|
}
|
1325
904
|
if (!storeKey) {
|
1326
905
|
const keyName = `@${keyFactory()}@`;
|
@@ -1329,7 +908,7 @@ var KeyBag = class {
|
|
1329
908
|
return ret;
|
1330
909
|
}
|
1331
910
|
const urb = url.build().setParam("storekey", keyName);
|
1332
|
-
return
|
911
|
+
return import_cement4.Result.Ok(urb.URI());
|
1333
912
|
}
|
1334
913
|
if (storeKey.startsWith("@") && storeKey.endsWith("@")) {
|
1335
914
|
const ret = await this.getNamedKey(storeKey);
|
@@ -1337,13 +916,13 @@ var KeyBag = class {
|
|
1337
916
|
return ret;
|
1338
917
|
}
|
1339
918
|
}
|
1340
|
-
return
|
919
|
+
return import_cement4.Result.Ok(url);
|
1341
920
|
}
|
1342
921
|
async toKeyWithFingerPrint(keyStr) {
|
1343
922
|
const material = import_base582.base58btc.decode(keyStr);
|
1344
923
|
const key = await this.subtleKey(keyStr);
|
1345
924
|
const fpr = await this.rt.crypto.digestSHA256(material);
|
1346
|
-
return
|
925
|
+
return import_cement4.Result.Ok({
|
1347
926
|
key,
|
1348
927
|
fingerPrint: import_base582.base58btc.encode(new Uint8Array(fpr))
|
1349
928
|
});
|
@@ -1368,7 +947,7 @@ var KeyBag = class {
|
|
1368
947
|
return ret;
|
1369
948
|
}
|
1370
949
|
const named = ret.Ok();
|
1371
|
-
return
|
950
|
+
return import_cement4.Result.Ok({
|
1372
951
|
...named,
|
1373
952
|
extract: async () => {
|
1374
953
|
const ext = new Uint8Array(await this.rt.crypto.exportKey("raw", named.key));
|
@@ -1391,7 +970,7 @@ var KeyBag = class {
|
|
1391
970
|
}
|
1392
971
|
if (failIfNotFound) {
|
1393
972
|
this.logger.Debug().Str("id", id).Str("name", name).Msg("failIfNotFound getNamedKey");
|
1394
|
-
return
|
973
|
+
return import_cement4.Result.Err(new Error(`Key not found: ${name}`));
|
1395
974
|
}
|
1396
975
|
const ret = await this._setNamedKey(name, import_base582.base58btc.encode(this.rt.crypto.randomBytes(this.rt.keyLength)));
|
1397
976
|
this.logger.Debug().Str("id", id).Str("name", name).Result("fpr", ret).Msg("createKey getNamedKey-post");
|
@@ -1404,15 +983,15 @@ var keyBagProviderFactories = new Map(
|
|
1404
983
|
{
|
1405
984
|
protocol: "file:",
|
1406
985
|
factory: async (url, sthis) => {
|
1407
|
-
const {
|
1408
|
-
return new
|
986
|
+
const { KeyBagProviderImpl } = await import("@fireproof/core/node");
|
987
|
+
return new KeyBagProviderImpl(url, sthis);
|
1409
988
|
}
|
1410
989
|
},
|
1411
990
|
{
|
1412
991
|
protocol: "indexdb:",
|
1413
992
|
factory: async (url, sthis) => {
|
1414
|
-
const {
|
1415
|
-
return new
|
993
|
+
const { KeyBagProviderImpl } = await import("@fireproof/core/web");
|
994
|
+
return new KeyBagProviderImpl(url, sthis);
|
1416
995
|
}
|
1417
996
|
}
|
1418
997
|
].map((i) => [i.protocol, i])
|
@@ -1427,15 +1006,15 @@ function registerKeyBagProviderFactory(item) {
|
|
1427
1006
|
function defaultKeyBagUrl(sthis) {
|
1428
1007
|
let bagFnameOrUrl = sthis.env.get("FP_KEYBAG_URL");
|
1429
1008
|
let url;
|
1430
|
-
if ((0,
|
1431
|
-
url =
|
1009
|
+
if ((0, import_cement4.runtimeFn)().isBrowser) {
|
1010
|
+
url = import_cement4.URI.from(bagFnameOrUrl || "indexdb://fp-keybag");
|
1432
1011
|
} else {
|
1433
1012
|
if (!bagFnameOrUrl) {
|
1434
1013
|
const home = sthis.env.get("HOME");
|
1435
1014
|
bagFnameOrUrl = `${home}/.fireproof/keybag`;
|
1436
|
-
url =
|
1015
|
+
url = import_cement4.URI.from(`file://${bagFnameOrUrl}`);
|
1437
1016
|
} else {
|
1438
|
-
url =
|
1017
|
+
url = import_cement4.URI.from(bagFnameOrUrl);
|
1439
1018
|
}
|
1440
1019
|
}
|
1441
1020
|
const logger = ensureLogger(sthis, "defaultKeyBagUrl");
|
@@ -1449,7 +1028,7 @@ function defaultKeyBagOpts(sthis, kbo) {
|
|
1449
1028
|
const logger = ensureLogger(sthis, "KeyBag");
|
1450
1029
|
let url;
|
1451
1030
|
if (kbo.url) {
|
1452
|
-
url =
|
1031
|
+
url = import_cement4.URI.from(kbo.url);
|
1453
1032
|
logger.Debug().Url(url).Msg("from opts");
|
1454
1033
|
} else {
|
1455
1034
|
url = defaultKeyBagUrl(sthis);
|
@@ -1464,7 +1043,7 @@ function defaultKeyBagOpts(sthis, kbo) {
|
|
1464
1043
|
}
|
1465
1044
|
return {
|
1466
1045
|
url,
|
1467
|
-
crypto: kbo.crypto || (0,
|
1046
|
+
crypto: kbo.crypto || (0, import_cement4.toCryptoRuntime)({}),
|
1468
1047
|
sthis,
|
1469
1048
|
logger,
|
1470
1049
|
keyLength: kbo.keyLength || 16,
|
@@ -1474,7 +1053,7 @@ function defaultKeyBagOpts(sthis, kbo) {
|
|
1474
1053
|
}
|
1475
1054
|
};
|
1476
1055
|
}
|
1477
|
-
var _keyBags = new
|
1056
|
+
var _keyBags = new import_cement4.KeyedResolvOnce();
|
1478
1057
|
async function getKeyBag(sthis, kbo = {}) {
|
1479
1058
|
await sthis.start();
|
1480
1059
|
const rt = defaultKeyBagOpts(sthis, kbo);
|
@@ -1587,7 +1166,6 @@ async function prepareCarFiles(encoder, threshold, rootBlock, t) {
|
|
1587
1166
|
var import_sha23 = require("multiformats/hashes/sha2");
|
1588
1167
|
|
1589
1168
|
// src/blockstore/task-manager.ts
|
1590
|
-
init_utils();
|
1591
1169
|
var TaskManager = class {
|
1592
1170
|
constructor(sthis, callback) {
|
1593
1171
|
// we need to remove the events after some time
|
@@ -1659,7 +1237,7 @@ var Loader = class {
|
|
1659
1237
|
this.getBlockCache = /* @__PURE__ */ new Map();
|
1660
1238
|
this.seenMeta = /* @__PURE__ */ new Set();
|
1661
1239
|
this.writeLimit = (0, import_p_limit.default)(1);
|
1662
|
-
this.onceReady = new
|
1240
|
+
this.onceReady = new import_cement5.ResolveOnce();
|
1663
1241
|
this.name = name;
|
1664
1242
|
this.sthis = sthis;
|
1665
1243
|
this.ebOpts = defaultedBlockstoreRuntime(
|
@@ -1984,7 +1562,6 @@ __export(keyed_crypto_exports, {
|
|
1984
1562
|
BlockIvKeyIdCodec: () => BlockIvKeyIdCodec,
|
1985
1563
|
keyedCryptoFactory: () => keyedCryptoFactory
|
1986
1564
|
});
|
1987
|
-
init_utils();
|
1988
1565
|
var import_base583 = require("multiformats/bases/base58");
|
1989
1566
|
var import_sha24 = require("multiformats/hashes/sha2");
|
1990
1567
|
var CBOR = __toESM(require("@fireproof/vendor/cborg"), 1);
|
@@ -2152,10 +1729,9 @@ async function keyedCryptoFactory(url, kb, sthis) {
|
|
2152
1729
|
}
|
2153
1730
|
|
2154
1731
|
// src/blockstore/fragment-gateway.ts
|
2155
|
-
var
|
1732
|
+
var import_cement6 = require("@adviser/cement");
|
2156
1733
|
var import_base584 = require("multiformats/bases/base58");
|
2157
1734
|
var import_cborg = require("@fireproof/vendor/cborg");
|
2158
|
-
init_utils();
|
2159
1735
|
function getFragSize(url) {
|
2160
1736
|
const fragSize = url.getParam("fragSize");
|
2161
1737
|
let ret = 0;
|
@@ -2176,7 +1752,7 @@ async function getFrags(url, innerGW, headerSize, logger) {
|
|
2176
1752
|
}
|
2177
1753
|
const data = res.unwrap();
|
2178
1754
|
return [
|
2179
|
-
|
1755
|
+
import_cement6.Result.Ok({
|
2180
1756
|
fid: new Uint8Array(0),
|
2181
1757
|
ofs: 0,
|
2182
1758
|
len: data.length,
|
@@ -2190,7 +1766,7 @@ async function getFrags(url, innerGW, headerSize, logger) {
|
|
2190
1766
|
}
|
2191
1767
|
const firstFragment = (0, import_cborg.decode)(firstRaw.unwrap());
|
2192
1768
|
const blockSize = firstFragment.data.length;
|
2193
|
-
const ops = [Promise.resolve(
|
1769
|
+
const ops = [Promise.resolve(import_cement6.Result.Ok(firstFragment))];
|
2194
1770
|
const fidStr = import_base584.base58btc.encode(firstFragment.fid);
|
2195
1771
|
const fragUrl = url.build().setParam("fid", fidStr).setParam("len", firstFragment.len.toString()).setParam("headerSize", headerSize.toString());
|
2196
1772
|
for (let ofs = blockSize; ofs < firstFragment.len; ofs += blockSize) {
|
@@ -2202,12 +1778,12 @@ async function getFrags(url, innerGW, headerSize, logger) {
|
|
2202
1778
|
}
|
2203
1779
|
const fragment = (0, import_cborg.decode)(raw2.unwrap());
|
2204
1780
|
if (import_base584.base58btc.encode(fragment.fid) !== fidStr) {
|
2205
|
-
return
|
1781
|
+
return import_cement6.Result.Err(logger.Error().Msg("Fragment fid mismatch").AsError());
|
2206
1782
|
}
|
2207
1783
|
if (fragment.ofs !== ofs2) {
|
2208
|
-
return
|
1784
|
+
return import_cement6.Result.Err(logger.Error().Uint64("ofs", ofs2).Msg("Fragment ofs mismatch").AsError());
|
2209
1785
|
}
|
2210
|
-
return
|
1786
|
+
return import_cement6.Result.Ok(fragment);
|
2211
1787
|
})(fragUrl.setParam("ofs", ofs.toString()).URI(), ofs)
|
2212
1788
|
);
|
2213
1789
|
}
|
@@ -2269,40 +1845,40 @@ var FragmentGateway = class {
|
|
2269
1845
|
}
|
2270
1846
|
async put(url, body) {
|
2271
1847
|
await Promise.all(this.slicer(url, body));
|
2272
|
-
return
|
1848
|
+
return import_cement6.Result.Ok(void 0);
|
2273
1849
|
}
|
2274
1850
|
async get(url) {
|
2275
1851
|
const rfrags = await getFrags(url, this.innerGW, this.headerSize, this.logger);
|
2276
1852
|
let buffer = void 0;
|
2277
1853
|
for (const rfrag of rfrags) {
|
2278
1854
|
if (rfrag.isErr()) {
|
2279
|
-
return
|
1855
|
+
return import_cement6.Result.Err(rfrag.Err());
|
2280
1856
|
}
|
2281
1857
|
const frag = rfrag.Ok();
|
2282
1858
|
buffer = buffer || new Uint8Array(frag.len);
|
2283
1859
|
buffer.set(frag.data, frag.ofs);
|
2284
1860
|
}
|
2285
|
-
return
|
1861
|
+
return import_cement6.Result.Ok(buffer || new Uint8Array(0));
|
2286
1862
|
}
|
2287
1863
|
async subscribe(url, callback) {
|
2288
1864
|
if (this.innerGW.subscribe) {
|
2289
1865
|
return this.innerGW.subscribe(url, callback);
|
2290
1866
|
} else {
|
2291
|
-
return
|
1867
|
+
return import_cement6.Result.Err(this.logger.Error().Url(url).Msg("subscribe not supported").AsError());
|
2292
1868
|
}
|
2293
1869
|
}
|
2294
1870
|
async delete(url) {
|
2295
1871
|
const rfrags = await getFrags(url, this.innerGW, this.headerSize, this.logger);
|
2296
1872
|
for (const rfrag of rfrags) {
|
2297
1873
|
if (rfrag.isErr()) {
|
2298
|
-
return
|
1874
|
+
return import_cement6.Result.Err(rfrag.Err());
|
2299
1875
|
}
|
2300
1876
|
const frag = rfrag.Ok();
|
2301
1877
|
const fidStr = import_base584.base58btc.encode(frag.fid);
|
2302
1878
|
const fragUrl = url.build().setParam("fid", fidStr).setParam("len", frag.len.toString()).setParam("headerSize", this.headerSize.toString()).URI();
|
2303
1879
|
await this.innerGW.delete(fragUrl);
|
2304
1880
|
}
|
2305
|
-
return
|
1881
|
+
return import_cement6.Result.Ok(void 0);
|
2306
1882
|
}
|
2307
1883
|
};
|
2308
1884
|
|
@@ -2311,8 +1887,7 @@ var import_dag_json = require("@fireproof/vendor/@ipld/dag-json");
|
|
2311
1887
|
var import_clock = require("@fireproof/vendor/@web3-storage/pail/clock");
|
2312
1888
|
var import_multiformats2 = require("multiformats");
|
2313
1889
|
var import_base64 = require("multiformats/bases/base64");
|
2314
|
-
var
|
2315
|
-
init_utils();
|
1890
|
+
var import_cement7 = require("@adviser/cement");
|
2316
1891
|
async function decodeGatewayMetaBytesToDbMeta(sthis, byteHeads) {
|
2317
1892
|
const crdtEntries = JSON.parse(sthis.txt.decode(byteHeads));
|
2318
1893
|
if (!Array.isArray(crdtEntries)) {
|
@@ -2358,13 +1933,13 @@ async function setCryptoKeyFromGatewayMetaPayload(uri, sthis, data) {
|
|
2358
1933
|
}
|
2359
1934
|
}
|
2360
1935
|
sthis.logger.Debug().Str("dbMeta.key", dbMeta.key).Str("uri", uri.toString()).Msg("Set crypto key from gateway meta payload");
|
2361
|
-
return
|
1936
|
+
return import_cement7.Result.Ok(dbMeta);
|
2362
1937
|
}
|
2363
1938
|
sthis.logger.Debug().Any("data", data).Msg("No crypto in gateway meta payload");
|
2364
|
-
return
|
1939
|
+
return import_cement7.Result.Ok(void 0);
|
2365
1940
|
} catch (error) {
|
2366
1941
|
sthis.logger.Debug().Err(error).Msg("Failed to set crypto key from gateway meta payload");
|
2367
|
-
return
|
1942
|
+
return import_cement7.Result.Err(error);
|
2368
1943
|
}
|
2369
1944
|
}
|
2370
1945
|
async function addCryptoKeyToGatewayMetaPayload(uri, sthis, body) {
|
@@ -2385,10 +1960,10 @@ async function addCryptoKeyToGatewayMetaPayload(uri, sthis, body) {
|
|
2385
1960
|
const events = await Promise.all([dbMeta].map((dbMeta2) => createDbMetaEventBlock(sthis, dbMeta2, parentLinks)));
|
2386
1961
|
const encoded = await encodeEventsWithParents(sthis, events, parentLinks);
|
2387
1962
|
sthis.logger.Debug().Str("uri", uri.toString()).Msg("Added crypto key to gateway meta payload");
|
2388
|
-
return
|
1963
|
+
return import_cement7.Result.Ok(encoded);
|
2389
1964
|
} catch (error) {
|
2390
1965
|
sthis.logger.Error().Err(error).Msg("Failed to add crypto key to gateway meta payload");
|
2391
|
-
return
|
1966
|
+
return import_cement7.Result.Err(error);
|
2392
1967
|
}
|
2393
1968
|
}
|
2394
1969
|
function getStoreKeyName(url) {
|
@@ -2426,9 +2001,9 @@ var import_p_retry = __toESM(require("p-retry"), 1);
|
|
2426
2001
|
var import_p_map = __toESM(require("p-map"), 1);
|
2427
2002
|
function guardVersion(url) {
|
2428
2003
|
if (!url.hasParam("version")) {
|
2429
|
-
return
|
2004
|
+
return import_cement8.Result.Err(`missing version: ${url.toString()}`);
|
2430
2005
|
}
|
2431
|
-
return
|
2006
|
+
return import_cement8.Result.Ok(url);
|
2432
2007
|
}
|
2433
2008
|
var BaseStoreImpl = class {
|
2434
2009
|
constructor(name, url, opts, sthis, logger) {
|
@@ -2488,7 +2063,7 @@ var BaseStoreImpl = class {
|
|
2488
2063
|
}
|
2489
2064
|
if (this.ready) {
|
2490
2065
|
const fn = this.ready.bind(this);
|
2491
|
-
const ready = await (0,
|
2066
|
+
const ready = await (0, import_cement8.exception2Result)(fn);
|
2492
2067
|
if (ready.isErr()) {
|
2493
2068
|
await this.close();
|
2494
2069
|
return ready;
|
@@ -2570,7 +2145,7 @@ var MetaStoreImpl = class extends BaseStoreImpl {
|
|
2570
2145
|
async close() {
|
2571
2146
|
await this.gateway.close(this.url());
|
2572
2147
|
this._onClosed.forEach((fn) => fn());
|
2573
|
-
return
|
2148
|
+
return import_cement8.Result.Ok(void 0);
|
2574
2149
|
}
|
2575
2150
|
async destroy() {
|
2576
2151
|
return this.gateway.destroy(this.url());
|
@@ -2617,7 +2192,7 @@ var DataStoreImpl = class extends BaseStoreImpl {
|
|
2617
2192
|
async close() {
|
2618
2193
|
await this.gateway.close(this.url());
|
2619
2194
|
this._onClosed.forEach((fn) => fn());
|
2620
|
-
return
|
2195
|
+
return import_cement8.Result.Ok(void 0);
|
2621
2196
|
}
|
2622
2197
|
destroy() {
|
2623
2198
|
return this.gateway.destroy(this.url());
|
@@ -2627,7 +2202,7 @@ var WALStoreImpl = class extends BaseStoreImpl {
|
|
2627
2202
|
constructor(loader, url, opts) {
|
2628
2203
|
super(loader.name, url, { ...opts }, loader.sthis, ensureLogger(loader.sthis, "WALStoreImpl"));
|
2629
2204
|
this.storeType = "wal";
|
2630
|
-
this._ready = new
|
2205
|
+
this._ready = new import_cement8.ResolveOnce();
|
2631
2206
|
this.walState = { operations: [], noLoaderOps: [], fileOperations: [] };
|
2632
2207
|
this.processing = void 0;
|
2633
2208
|
this.processQueue = new CommitQueue();
|
@@ -2798,7 +2373,7 @@ var WALStoreImpl = class extends BaseStoreImpl {
|
|
2798
2373
|
async close() {
|
2799
2374
|
await this.gateway.close(this.url());
|
2800
2375
|
this._onClosed.forEach((fn) => fn());
|
2801
|
-
return
|
2376
|
+
return import_cement8.Result.Ok(void 0);
|
2802
2377
|
}
|
2803
2378
|
destroy() {
|
2804
2379
|
return this.gateway.destroy(this.url());
|
@@ -2806,7 +2381,6 @@ var WALStoreImpl = class extends BaseStoreImpl {
|
|
2806
2381
|
};
|
2807
2382
|
|
2808
2383
|
// src/blockstore/store-factory.ts
|
2809
|
-
init_utils();
|
2810
2384
|
function ensureIsIndex(url, isIndex) {
|
2811
2385
|
if (isIndex) {
|
2812
2386
|
return url.build().setParam("index", isIndex).URI();
|
@@ -2825,15 +2399,15 @@ function buildURL(optURL, loader) {
|
|
2825
2399
|
const obuItem = Array.from(storeFactory.values()).find((items) => items.overrideBaseURL);
|
2826
2400
|
let obuUrl;
|
2827
2401
|
if (obuItem && obuItem.overrideBaseURL) {
|
2828
|
-
obuUrl =
|
2402
|
+
obuUrl = import_cement9.URI.from(obuItem.overrideBaseURL);
|
2829
2403
|
}
|
2830
2404
|
const ret = ensureIsIndex(
|
2831
|
-
|
2405
|
+
import_cement9.URI.from(optURL || obuUrl || dataDir(loader.sthis, loader.name, storeOpts.stores?.base)),
|
2832
2406
|
storeOpts.isIndex
|
2833
2407
|
);
|
2834
2408
|
return ret;
|
2835
2409
|
}
|
2836
|
-
var onceGateway = new
|
2410
|
+
var onceGateway = new import_cement9.KeyedResolvOnce();
|
2837
2411
|
async function getGatewayFromURL(url, sthis) {
|
2838
2412
|
return onceGateway.get(url.toString()).once(async () => {
|
2839
2413
|
const item = storeFactory.get(url.protocol);
|
@@ -2875,7 +2449,7 @@ function registerStoreProtocol(item) {
|
|
2875
2449
|
storeFactory.delete(protocol);
|
2876
2450
|
};
|
2877
2451
|
}
|
2878
|
-
var onceDataStoreFactory = new
|
2452
|
+
var onceDataStoreFactory = new import_cement9.KeyedResolvOnce();
|
2879
2453
|
async function dataStoreFactory(loader) {
|
2880
2454
|
const url = ensureName(loader.name, buildURL(loader.ebOpts.store.stores?.data, loader)).build().setParam("store", "data").URI();
|
2881
2455
|
const sthis = ensureSuperLog(loader.sthis, "dataStoreFactory", { url: url.toString() });
|
@@ -2893,7 +2467,7 @@ async function dataStoreFactory(loader) {
|
|
2893
2467
|
return store;
|
2894
2468
|
});
|
2895
2469
|
}
|
2896
|
-
var onceMetaStoreFactory = new
|
2470
|
+
var onceMetaStoreFactory = new import_cement9.KeyedResolvOnce();
|
2897
2471
|
async function metaStoreFactory(loader) {
|
2898
2472
|
const url = ensureName(loader.name, buildURL(loader.ebOpts.store.stores?.meta, loader)).build().setParam("store", "meta").URI();
|
2899
2473
|
const sthis = ensureSuperLog(loader.sthis, "metaStoreFactory", { url: () => url.toString() });
|
@@ -2912,7 +2486,7 @@ async function metaStoreFactory(loader) {
|
|
2912
2486
|
return store;
|
2913
2487
|
});
|
2914
2488
|
}
|
2915
|
-
var onceRemoteWalFactory = new
|
2489
|
+
var onceRemoteWalFactory = new import_cement9.KeyedResolvOnce();
|
2916
2490
|
async function remoteWalFactory(loader) {
|
2917
2491
|
const url = ensureName(loader.name, buildURL(loader.ebOpts.store.stores?.wal, loader)).build().setParam("store", "wal").URI();
|
2918
2492
|
const sthis = ensureSuperLog(loader.sthis, "remoteWalFactory", { url: url.toString() });
|
@@ -2966,28 +2540,32 @@ function toStoreRuntime(opts, sthis) {
|
|
2966
2540
|
decodeFile: opts.decodeFile || decodeFile
|
2967
2541
|
};
|
2968
2542
|
}
|
2969
|
-
|
2970
|
-
|
2971
|
-
|
2972
|
-
|
2973
|
-
|
2974
|
-
|
2975
|
-
|
2976
|
-
|
2977
|
-
|
2978
|
-
|
2979
|
-
}
|
2980
|
-
|
2981
|
-
|
2982
|
-
|
2983
|
-
|
2984
|
-
|
2985
|
-
|
2986
|
-
|
2987
|
-
|
2988
|
-
|
2989
|
-
|
2990
|
-
});
|
2543
|
+
if ((0, import_cement9.runtimeFn)().isNodeIsh || (0, import_cement9.runtimeFn)().isDeno) {
|
2544
|
+
registerStoreProtocol({
|
2545
|
+
protocol: "file:",
|
2546
|
+
gateway: async (sthis) => {
|
2547
|
+
const { GatewayImpl } = await import("@fireproof/core/node");
|
2548
|
+
return new GatewayImpl(sthis);
|
2549
|
+
},
|
2550
|
+
test: async (sthis) => {
|
2551
|
+
const { GatewayTestImpl } = await import("@fireproof/core/node");
|
2552
|
+
return new GatewayTestImpl(sthis);
|
2553
|
+
}
|
2554
|
+
});
|
2555
|
+
}
|
2556
|
+
if ((0, import_cement9.runtimeFn)().isBrowser) {
|
2557
|
+
registerStoreProtocol({
|
2558
|
+
protocol: "indexdb:",
|
2559
|
+
gateway: async (sthis) => {
|
2560
|
+
const { GatewayImpl } = await import("@fireproof/core/web");
|
2561
|
+
return new GatewayImpl(sthis);
|
2562
|
+
},
|
2563
|
+
test: async (sthis) => {
|
2564
|
+
const { GatewayTestImpl } = await import("@fireproof/core/web");
|
2565
|
+
return new GatewayTestImpl(sthis);
|
2566
|
+
}
|
2567
|
+
});
|
2568
|
+
}
|
2991
2569
|
|
2992
2570
|
// src/blockstore/store-remote.ts
|
2993
2571
|
async function RemoteDataStore(sthis, name, url, opts) {
|
@@ -3362,7 +2940,7 @@ var import_sha26 = require("multiformats/hashes/sha2");
|
|
3362
2940
|
var codec2 = __toESM(require("@fireproof/vendor/@ipld/dag-cbor"), 1);
|
3363
2941
|
var import_charwise = __toESM(require("charwise"), 1);
|
3364
2942
|
var DbIndex = __toESM(require("prolly-trees/db-index"), 1);
|
3365
|
-
var
|
2943
|
+
var import_utils9 = require("prolly-trees/utils");
|
3366
2944
|
var import_cache = require("prolly-trees/cache");
|
3367
2945
|
var IndexTree = class {
|
3368
2946
|
};
|
@@ -3370,17 +2948,17 @@ function refCompare(aRef, bRef) {
|
|
3370
2948
|
if (Number.isNaN(aRef)) return -1;
|
3371
2949
|
if (Number.isNaN(bRef)) throw new Error("ref may not be Infinity or NaN");
|
3372
2950
|
if (aRef === Infinity) return 1;
|
3373
|
-
return (0,
|
2951
|
+
return (0, import_utils9.simpleCompare)(aRef, bRef);
|
3374
2952
|
}
|
3375
2953
|
function compare(a, b) {
|
3376
2954
|
const [aKey, aRef] = a;
|
3377
2955
|
const [bKey, bRef] = b;
|
3378
|
-
const comp = (0,
|
2956
|
+
const comp = (0, import_utils9.simpleCompare)(aKey, bKey);
|
3379
2957
|
if (comp !== 0) return comp;
|
3380
2958
|
return refCompare(aRef, bRef);
|
3381
2959
|
}
|
3382
|
-
var byKeyOpts = { cache: import_cache.nocache, chunker: (0,
|
3383
|
-
var byIdOpts = { cache: import_cache.nocache, chunker: (0,
|
2960
|
+
var byKeyOpts = { cache: import_cache.nocache, chunker: (0, import_utils9.bf)(30), codec: codec2, hasher: import_sha26.sha256, compare };
|
2961
|
+
var byIdOpts = { cache: import_cache.nocache, chunker: (0, import_utils9.bf)(30), codec: codec2, hasher: import_sha26.sha256, compare: import_utils9.simpleCompare };
|
3384
2962
|
function indexEntriesForChanges(changes, mapFn) {
|
3385
2963
|
const indexEntries = [];
|
3386
2964
|
changes.forEach(({ id: key, value, del }) => {
|
@@ -3479,7 +3057,6 @@ function encodeKey(key) {
|
|
3479
3057
|
}
|
3480
3058
|
|
3481
3059
|
// src/indexer.ts
|
3482
|
-
init_utils();
|
3483
3060
|
function index(sthis, { _crdt }, name, mapFn, meta) {
|
3484
3061
|
if (mapFn && meta) throw _crdt.logger.Error().Msg("cannot provide both mapFn and meta").AsError();
|
3485
3062
|
if (mapFn && mapFn.constructor.name !== "Function") throw _crdt.logger.Error().Msg("mapFn must be a function").AsError();
|
@@ -3688,7 +3265,7 @@ var Index = class {
|
|
3688
3265
|
// src/crdt-clock.ts
|
3689
3266
|
var import_clock3 = require("@fireproof/vendor/@web3-storage/pail/clock");
|
3690
3267
|
var import_crdt2 = require("@fireproof/vendor/@web3-storage/pail/crdt");
|
3691
|
-
var
|
3268
|
+
var import_cement10 = require("@adviser/cement");
|
3692
3269
|
|
3693
3270
|
// src/apply-head-queue.ts
|
3694
3271
|
function applyHeadQueue(worker, logger) {
|
@@ -3736,7 +3313,6 @@ function applyHeadQueue(worker, logger) {
|
|
3736
3313
|
}
|
3737
3314
|
|
3738
3315
|
// src/crdt-clock.ts
|
3739
|
-
init_utils();
|
3740
3316
|
var CRDTClock = class {
|
3741
3317
|
constructor(blockstore) {
|
3742
3318
|
// todo: track local and remote clocks independently, merge on read
|
@@ -3746,7 +3322,7 @@ var CRDTClock = class {
|
|
3746
3322
|
this.zoomers = /* @__PURE__ */ new Set();
|
3747
3323
|
this.watchers = /* @__PURE__ */ new Set();
|
3748
3324
|
this.emptyWatchers = /* @__PURE__ */ new Set();
|
3749
|
-
this._ready = new
|
3325
|
+
this._ready = new import_cement10.ResolveOnce();
|
3750
3326
|
this.blockstore = blockstore;
|
3751
3327
|
this.logger = ensureLogger(blockstore.sthis, "CRDTClock");
|
3752
3328
|
this.applyHeadQueue = applyHeadQueue(this.int_applyHead.bind(this), this.logger);
|
@@ -3856,11 +3432,10 @@ async function advanceBlocks(logger, newHead, tblocks, head) {
|
|
3856
3432
|
}
|
3857
3433
|
|
3858
3434
|
// src/crdt.ts
|
3859
|
-
init_utils();
|
3860
3435
|
var CRDT = class {
|
3861
3436
|
constructor(sthis, name, opts = {}) {
|
3862
3437
|
this.indexers = /* @__PURE__ */ new Map();
|
3863
|
-
this.onceReady = new
|
3438
|
+
this.onceReady = new import_cement11.ResolveOnce();
|
3864
3439
|
this.sthis = sthis;
|
3865
3440
|
this.name = name;
|
3866
3441
|
this.logger = ensureLogger(sthis, "CRDT");
|
@@ -3974,14 +3549,13 @@ var CRDT = class {
|
|
3974
3549
|
};
|
3975
3550
|
|
3976
3551
|
// src/database.ts
|
3977
|
-
init_utils();
|
3978
3552
|
var Database = class {
|
3979
3553
|
constructor(name, opts) {
|
3980
3554
|
this.opts = {};
|
3981
3555
|
this._listening = false;
|
3982
3556
|
this._listeners = /* @__PURE__ */ new Set();
|
3983
3557
|
this._noupdate_listeners = /* @__PURE__ */ new Set();
|
3984
|
-
this._ready = new
|
3558
|
+
this._ready = new import_cement12.ResolveOnce();
|
3985
3559
|
this.name = name;
|
3986
3560
|
this.opts = opts || this.opts;
|
3987
3561
|
this.sthis = ensureSuperThis(this.opts);
|
@@ -4188,14 +3762,39 @@ __export(runtime_exports, {
|
|
4188
3762
|
INDEXDB_VERSION: () => INDEXDB_VERSION,
|
4189
3763
|
files: () => files_exports,
|
4190
3764
|
getFileName: () => getFileName,
|
4191
|
-
getFileSystem: () => getFileSystem,
|
4192
3765
|
getPath: () => getPath,
|
4193
3766
|
kb: () => key_bag_exports,
|
4194
3767
|
kc: () => keyed_crypto_exports,
|
4195
3768
|
mf: () => wait_pr_multiformats_exports,
|
4196
|
-
runtimeFn: () =>
|
3769
|
+
runtimeFn: () => import_cement13.runtimeFn
|
4197
3770
|
});
|
4198
|
-
|
3771
|
+
|
3772
|
+
// src/runtime/gateways/file/node/utils.ts
|
3773
|
+
var import_core = require("@fireproof/core");
|
3774
|
+
function getPath(url, sthis) {
|
3775
|
+
const basePath = url.pathname;
|
3776
|
+
const name = url.getParam("name");
|
3777
|
+
if (name) {
|
3778
|
+
const version = url.getParam("version");
|
3779
|
+
if (!version) throw sthis.logger.Error().Url(url).Msg(`version not found`).AsError();
|
3780
|
+
return sthis.pathOps.join(basePath, version, name);
|
3781
|
+
}
|
3782
|
+
return sthis.pathOps.join(basePath);
|
3783
|
+
}
|
3784
|
+
function getFileName(url, sthis) {
|
3785
|
+
const key = url.getParam("key");
|
3786
|
+
if (!key) throw sthis.logger.Error().Url(url).Msg(`key not found`).AsError();
|
3787
|
+
const res = (0, import_core.getStore)(url, sthis, (...a) => a.join("-"));
|
3788
|
+
switch (res.store) {
|
3789
|
+
case "data":
|
3790
|
+
return sthis.pathOps.join(res.name, key + ".car");
|
3791
|
+
case "wal":
|
3792
|
+
case "meta":
|
3793
|
+
return sthis.pathOps.join(res.name, key + ".json");
|
3794
|
+
default:
|
3795
|
+
throw sthis.logger.Error().Url(url).Msg(`unsupported store type`).AsError();
|
3796
|
+
}
|
3797
|
+
}
|
4199
3798
|
|
4200
3799
|
// src/runtime/wait-pr-multiformats/index.ts
|
4201
3800
|
var wait_pr_multiformats_exports = {};
|
@@ -4208,17 +3807,16 @@ __export(wait_pr_multiformats_exports, {
|
|
4208
3807
|
var codec_interface_exports = {};
|
4209
3808
|
|
4210
3809
|
// src/runtime/index.ts
|
4211
|
-
var
|
4212
|
-
|
3810
|
+
var import_cement13 = require("@adviser/cement");
|
3811
|
+
|
3812
|
+
// src/runtime/gateways/file/version.ts
|
3813
|
+
var FILESTORE_VERSION = "v0.19-file";
|
4213
3814
|
|
4214
3815
|
// src/runtime/gateways/indexdb/version.ts
|
4215
3816
|
var INDEXDB_VERSION = "v0.19-indexdb";
|
4216
3817
|
|
4217
|
-
// src/index.ts
|
4218
|
-
init_utils();
|
4219
|
-
|
4220
3818
|
// src/version.ts
|
4221
3819
|
var PACKAGE_VERSION = Object.keys({
|
4222
|
-
"0.19.
|
3820
|
+
"0.19.121": "xxxx"
|
4223
3821
|
})[0];
|
4224
3822
|
//# sourceMappingURL=index.cjs.map
|