@dxos/feed-store 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/chunk-feed-store.mjs +483 -0
- package/dist/lib/chunk-feed-store.mjs.map +1 -0
- package/dist/lib/index.mjs +487 -0
- package/dist/lib/index.mjs.map +1 -0
- package/dist/lib/testing.mjs +142 -0
- package/dist/lib/testing.mjs.map +1 -0
- package/dist/types/src/feed-factory.d.ts +21 -0
- package/dist/types/src/feed-factory.d.ts.map +1 -1
- package/dist/types/src/feed-store.d.ts +14 -1
- package/dist/types/src/feed-store.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +21 -22
- package/src/feed-factory.ts +41 -0
- package/src/feed-store.ts +25 -1
- package/dist/lib/browser/chunk-MB63GMGR.mjs +0 -410
- package/dist/lib/browser/chunk-MB63GMGR.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -424
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/testing/index.mjs +0 -152
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-VZUET36D.mjs +0 -410
- package/dist/lib/node-esm/chunk-VZUET36D.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -424
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/testing/index.mjs +0 -152
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
import * as EffectContext from "effect/Context";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Layer from "effect/Layer";
|
|
4
|
+
import defaultsDeep from "lodash.defaultsdeep";
|
|
5
|
+
import { subtleCrypto } from "@dxos/crypto";
|
|
6
|
+
import { StackTrace, failUndefined, inspectObject } from "@dxos/debug";
|
|
7
|
+
import { createCrypto, hypercore } from "@dxos/hypercore";
|
|
8
|
+
import { KeyringApiService } from "@dxos/keyring";
|
|
9
|
+
import { log } from "@dxos/log";
|
|
10
|
+
import { inspect, promisify } from "@dxos/node-std/util";
|
|
11
|
+
import { Readable, Transform } from "streamx";
|
|
12
|
+
import { Event, Mutex, Trigger } from "@dxos/async";
|
|
13
|
+
import { assertArgument, invariant } from "@dxos/invariant";
|
|
14
|
+
import { ComplexMap, arrayToBuffer, defaultMap, rangeFromTo } from "@dxos/util";
|
|
15
|
+
import { PublicKey } from "@dxos/keys";
|
|
16
|
+
//#region src/feed-wrapper.ts
|
|
17
|
+
var __dxlog_file$2 = "/__w/dxos/dxos/packages/common/feed-store/src/feed-wrapper.ts";
|
|
18
|
+
/**
|
|
19
|
+
* Async feed wrapper.
|
|
20
|
+
*/
|
|
21
|
+
var FeedWrapper = class {
|
|
22
|
+
_key;
|
|
23
|
+
_storageDirectory;
|
|
24
|
+
_hypercore;
|
|
25
|
+
_pendingWrites = /* @__PURE__ */ new Set();
|
|
26
|
+
_writeLock = new Trigger();
|
|
27
|
+
_closed = false;
|
|
28
|
+
constructor(hypercore, _key, _storageDirectory) {
|
|
29
|
+
this._key = _key;
|
|
30
|
+
this._storageDirectory = _storageDirectory;
|
|
31
|
+
assertArgument(hypercore, "hypercore");
|
|
32
|
+
this._hypercore = hypercore;
|
|
33
|
+
invariant(this._key, void 0, {
|
|
34
|
+
"~LogMeta": "~LogMeta",
|
|
35
|
+
F: __dxlog_file$2,
|
|
36
|
+
L: 40,
|
|
37
|
+
S: this,
|
|
38
|
+
A: ["this._key", ""]
|
|
39
|
+
});
|
|
40
|
+
this._writeLock.wake();
|
|
41
|
+
}
|
|
42
|
+
[inspect.custom]() {
|
|
43
|
+
return inspectObject(this);
|
|
44
|
+
}
|
|
45
|
+
toJSON() {
|
|
46
|
+
return {
|
|
47
|
+
feedKey: this._key,
|
|
48
|
+
length: this.properties.length,
|
|
49
|
+
opened: this.properties.opened,
|
|
50
|
+
closed: this.properties.closed
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
get key() {
|
|
54
|
+
return this._key;
|
|
55
|
+
}
|
|
56
|
+
get core() {
|
|
57
|
+
return this._hypercore;
|
|
58
|
+
}
|
|
59
|
+
get properties() {
|
|
60
|
+
return this._hypercore;
|
|
61
|
+
}
|
|
62
|
+
createReadableStream(opts) {
|
|
63
|
+
const self = this;
|
|
64
|
+
const transform = new Transform({ transform(data, cb) {
|
|
65
|
+
self._writeLock.wait().then(() => {
|
|
66
|
+
this.push(data);
|
|
67
|
+
cb();
|
|
68
|
+
});
|
|
69
|
+
} });
|
|
70
|
+
(opts?.batch !== void 0 && opts?.batch > 1 ? new BatchedReadStream(this._hypercore, opts) : this._hypercore.createReadStream(opts)).pipe(transform, (err) => {});
|
|
71
|
+
return transform;
|
|
72
|
+
}
|
|
73
|
+
createFeedWriter() {
|
|
74
|
+
return { write: async (data, { afterWrite } = {}) => {
|
|
75
|
+
log("write", {
|
|
76
|
+
feed: this._key,
|
|
77
|
+
seq: this._hypercore.length
|
|
78
|
+
}, {
|
|
79
|
+
"~LogMeta": "~LogMeta",
|
|
80
|
+
F: __dxlog_file$2,
|
|
81
|
+
L: 99,
|
|
82
|
+
S: this
|
|
83
|
+
});
|
|
84
|
+
invariant(!this._closed, "Feed closed", {
|
|
85
|
+
"~LogMeta": "~LogMeta",
|
|
86
|
+
F: __dxlog_file$2,
|
|
87
|
+
L: 100,
|
|
88
|
+
S: this,
|
|
89
|
+
A: ["!this._closed", "'Feed closed'"]
|
|
90
|
+
});
|
|
91
|
+
const stackTrace = new StackTrace();
|
|
92
|
+
try {
|
|
93
|
+
this._pendingWrites.add(stackTrace);
|
|
94
|
+
if (this._pendingWrites.size === 1) this._writeLock.reset();
|
|
95
|
+
const receipt = await this.appendWithReceipt(data);
|
|
96
|
+
await this.flushToDisk();
|
|
97
|
+
await afterWrite?.(receipt);
|
|
98
|
+
return receipt;
|
|
99
|
+
} finally {
|
|
100
|
+
this._pendingWrites.delete(stackTrace);
|
|
101
|
+
if (this._pendingWrites.size === 0) this._writeLock.wake();
|
|
102
|
+
}
|
|
103
|
+
} };
|
|
104
|
+
}
|
|
105
|
+
async appendWithReceipt(data) {
|
|
106
|
+
const seq = await this.append(data);
|
|
107
|
+
invariant(seq < this.length, "Invalid seq after write", {
|
|
108
|
+
"~LogMeta": "~LogMeta",
|
|
109
|
+
F: __dxlog_file$2,
|
|
110
|
+
L: 131,
|
|
111
|
+
S: this,
|
|
112
|
+
A: ["seq < this.length", "'Invalid seq after write'"]
|
|
113
|
+
});
|
|
114
|
+
log("write complete", {
|
|
115
|
+
feed: this._key,
|
|
116
|
+
seq
|
|
117
|
+
}, {
|
|
118
|
+
"~LogMeta": "~LogMeta",
|
|
119
|
+
F: __dxlog_file$2,
|
|
120
|
+
L: 132,
|
|
121
|
+
S: this
|
|
122
|
+
});
|
|
123
|
+
return {
|
|
124
|
+
feedKey: this.key,
|
|
125
|
+
seq
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Flush pending changes to disk.
|
|
130
|
+
* Calling this is not required unless you want to explicitly wait for data to be written.
|
|
131
|
+
*/
|
|
132
|
+
async flushToDisk() {
|
|
133
|
+
await this._storageDirectory.flush();
|
|
134
|
+
}
|
|
135
|
+
get opened() {
|
|
136
|
+
return this._hypercore.opened;
|
|
137
|
+
}
|
|
138
|
+
get closed() {
|
|
139
|
+
return this._hypercore.closed;
|
|
140
|
+
}
|
|
141
|
+
get readable() {
|
|
142
|
+
return this._hypercore.readable;
|
|
143
|
+
}
|
|
144
|
+
get length() {
|
|
145
|
+
return this._hypercore.length;
|
|
146
|
+
}
|
|
147
|
+
get byteLength() {
|
|
148
|
+
return this._hypercore.byteLength;
|
|
149
|
+
}
|
|
150
|
+
on(...args) {
|
|
151
|
+
return this._hypercore.on(...args);
|
|
152
|
+
}
|
|
153
|
+
off(...args) {
|
|
154
|
+
return this._hypercore.off(...args);
|
|
155
|
+
}
|
|
156
|
+
open(...args) {
|
|
157
|
+
return promisify(this._hypercore.open.bind(this._hypercore))(...args);
|
|
158
|
+
}
|
|
159
|
+
_close(...args) {
|
|
160
|
+
return promisify(this._hypercore.close.bind(this._hypercore))(...args);
|
|
161
|
+
}
|
|
162
|
+
close = async () => {
|
|
163
|
+
if (this._pendingWrites.size) log.warn("Closing feed with pending writes", {
|
|
164
|
+
feed: this._key,
|
|
165
|
+
count: this._pendingWrites.size,
|
|
166
|
+
pendingWrites: Array.from(this._pendingWrites.values()).map((stack) => stack.getStack())
|
|
167
|
+
}, {
|
|
168
|
+
"~LogMeta": "~LogMeta",
|
|
169
|
+
F: __dxlog_file$2,
|
|
170
|
+
L: 186,
|
|
171
|
+
S: this
|
|
172
|
+
});
|
|
173
|
+
this._closed = true;
|
|
174
|
+
await this.flushToDisk();
|
|
175
|
+
await this._close();
|
|
176
|
+
};
|
|
177
|
+
has(start, end) {
|
|
178
|
+
return this._hypercore.has(start, end);
|
|
179
|
+
}
|
|
180
|
+
get(index, options) {
|
|
181
|
+
return promisify(this._hypercore.get.bind(this._hypercore))(index, options);
|
|
182
|
+
}
|
|
183
|
+
append(data) {
|
|
184
|
+
return promisify(this._hypercore.append.bind(this._hypercore))(data);
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Will not resolve if `end` parameter is not specified and the feed is not closed.
|
|
188
|
+
*/
|
|
189
|
+
download(...args) {
|
|
190
|
+
return this._hypercore.download(...args);
|
|
191
|
+
}
|
|
192
|
+
undownload(...args) {
|
|
193
|
+
return this._hypercore.undownload(...args);
|
|
194
|
+
}
|
|
195
|
+
setDownloading(...args) {
|
|
196
|
+
return this._hypercore.setDownloading(...args);
|
|
197
|
+
}
|
|
198
|
+
replicate(...args) {
|
|
199
|
+
return this._hypercore.replicate(...args);
|
|
200
|
+
}
|
|
201
|
+
clear(start, end) {
|
|
202
|
+
return promisify(this._hypercore.clear.bind(this._hypercore))(start, end);
|
|
203
|
+
}
|
|
204
|
+
proof(index, options) {
|
|
205
|
+
return promisify(this._hypercore.proof.bind(this._hypercore))(index);
|
|
206
|
+
}
|
|
207
|
+
put(index, data, proof) {
|
|
208
|
+
return promisify(this._hypercore.put.bind(this._hypercore))(index, data, proof);
|
|
209
|
+
}
|
|
210
|
+
putBuffer(index, data, proof, peer) {
|
|
211
|
+
return promisify(this._hypercore._putBuffer.bind(this._hypercore))(index, data, proof, peer);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Clear and check for integrity.
|
|
215
|
+
*/
|
|
216
|
+
async safeClear(from, to) {
|
|
217
|
+
invariant(from >= 0 && from < to && to <= this.length, "Invalid range", {
|
|
218
|
+
"~LogMeta": "~LogMeta",
|
|
219
|
+
F: __dxlog_file$2,
|
|
220
|
+
L: 249,
|
|
221
|
+
S: this,
|
|
222
|
+
A: ["from >= 0 && from < to && to <= this.length", "'Invalid range'"]
|
|
223
|
+
});
|
|
224
|
+
const CHECK_MESSAGES = 20;
|
|
225
|
+
const checkBegin = to;
|
|
226
|
+
const checkEnd = Math.min(checkBegin + CHECK_MESSAGES, this.length);
|
|
227
|
+
const messagesBefore = await Promise.all(rangeFromTo(checkBegin, checkEnd).map((idx) => this.get(idx, { valueEncoding: { decode: (x) => x } })));
|
|
228
|
+
await this.clear(from, to);
|
|
229
|
+
const messagesAfter = await Promise.all(rangeFromTo(checkBegin, checkEnd).map((idx) => this.get(idx, { valueEncoding: { decode: (x) => x } })));
|
|
230
|
+
for (let i = 0; i < messagesBefore.length; i++) {
|
|
231
|
+
const before = arrayToBuffer(messagesBefore[i]);
|
|
232
|
+
const after = arrayToBuffer(messagesAfter[i]);
|
|
233
|
+
if (!before.equals(after)) throw new Error("Feed corruption on clear. There has likely been a data loss.");
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
var BatchedReadStream = class extends Readable {
|
|
238
|
+
_feed;
|
|
239
|
+
_batch;
|
|
240
|
+
_cursor;
|
|
241
|
+
_reading = false;
|
|
242
|
+
constructor(feed, opts = {}) {
|
|
243
|
+
super({ objectMode: true });
|
|
244
|
+
invariant(opts.live === true, "Only live mode supported", {
|
|
245
|
+
"~LogMeta": "~LogMeta",
|
|
246
|
+
F: __dxlog_file$2,
|
|
247
|
+
L: 291,
|
|
248
|
+
S: this,
|
|
249
|
+
A: ["opts.live === true", "'Only live mode supported'"]
|
|
250
|
+
});
|
|
251
|
+
invariant(opts.batch !== void 0 && opts.batch > 1, void 0, {
|
|
252
|
+
"~LogMeta": "~LogMeta",
|
|
253
|
+
F: __dxlog_file$2,
|
|
254
|
+
L: 292,
|
|
255
|
+
S: this,
|
|
256
|
+
A: ["opts.batch !== undefined && opts.batch > 1", ""]
|
|
257
|
+
});
|
|
258
|
+
this._feed = feed;
|
|
259
|
+
this._batch = opts.batch;
|
|
260
|
+
this._cursor = opts.start ?? 0;
|
|
261
|
+
}
|
|
262
|
+
_open(cb) {
|
|
263
|
+
this._feed.ready(cb);
|
|
264
|
+
}
|
|
265
|
+
_read(cb) {
|
|
266
|
+
if (this._reading) return;
|
|
267
|
+
if (this._feed.bitfield.total(this._cursor, this._cursor + this._batch) === this._batch) this._batchedRead(cb);
|
|
268
|
+
else this._nonBatchedRead(cb);
|
|
269
|
+
}
|
|
270
|
+
_nonBatchedRead(cb) {
|
|
271
|
+
this._feed.get(this._cursor, { wait: true }, (err, data) => {
|
|
272
|
+
if (err) cb(err);
|
|
273
|
+
else {
|
|
274
|
+
this._cursor++;
|
|
275
|
+
this._reading = false;
|
|
276
|
+
this.push(data);
|
|
277
|
+
cb(null);
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
_batchedRead(cb) {
|
|
282
|
+
this._feed.getBatch(this._cursor, this._cursor + this._batch, { wait: true }, (err, data) => {
|
|
283
|
+
if (err) cb(err);
|
|
284
|
+
else {
|
|
285
|
+
this._cursor += data.length;
|
|
286
|
+
this._reading = false;
|
|
287
|
+
for (const item of data) this.push(item);
|
|
288
|
+
cb(null);
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
//#endregion
|
|
294
|
+
//#region src/feed-factory.ts
|
|
295
|
+
var __dxlog_file$1 = "/__w/dxos/dxos/packages/common/feed-store/src/feed-factory.ts";
|
|
296
|
+
/**
|
|
297
|
+
* Effect service tag for {@link FeedFactory}.
|
|
298
|
+
*/
|
|
299
|
+
var FeedFactoryService = class extends EffectContext.Tag("@dxos/feed-store/FeedFactory")() {};
|
|
300
|
+
/**
|
|
301
|
+
* Root directory for hypercore feed files.
|
|
302
|
+
*/
|
|
303
|
+
var FeedStorageDirectoryService = class extends EffectContext.Tag("@dxos/feed-store/FeedStorageDirectory")() {};
|
|
304
|
+
/**
|
|
305
|
+
* Hypercore factory.
|
|
306
|
+
*/
|
|
307
|
+
var FeedFactory = class {
|
|
308
|
+
_root;
|
|
309
|
+
_signer;
|
|
310
|
+
_hypercoreOptions;
|
|
311
|
+
constructor({ root, signer, hypercore }) {
|
|
312
|
+
log("FeedFactory", { options: hypercore }, {
|
|
313
|
+
"~LogMeta": "~LogMeta",
|
|
314
|
+
F: __dxlog_file$1,
|
|
315
|
+
L: 63,
|
|
316
|
+
S: this
|
|
317
|
+
});
|
|
318
|
+
this._root = root ?? failUndefined();
|
|
319
|
+
this._signer = signer;
|
|
320
|
+
this._hypercoreOptions = hypercore;
|
|
321
|
+
}
|
|
322
|
+
get storageRoot() {
|
|
323
|
+
return this._root;
|
|
324
|
+
}
|
|
325
|
+
async createFeed(publicKey, options) {
|
|
326
|
+
if (options?.writable && !this._signer) throw new Error("Signer required to create writable feeds.");
|
|
327
|
+
if (options?.secretKey) log.warn("Secret key ignored due to signer.", void 0, {
|
|
328
|
+
"~LogMeta": "~LogMeta",
|
|
329
|
+
F: __dxlog_file$1,
|
|
330
|
+
L: 78,
|
|
331
|
+
S: this
|
|
332
|
+
});
|
|
333
|
+
const key = await subtleCrypto.digest("SHA-256", Buffer.from(publicKey.toHex()));
|
|
334
|
+
const opts = defaultsDeep({}, this._hypercoreOptions, {
|
|
335
|
+
secretKey: this._signer && options?.writable ? Buffer.from("secret") : void 0,
|
|
336
|
+
crypto: this._signer ? createCrypto(this._signer, publicKey) : void 0,
|
|
337
|
+
onwrite: options?.onwrite,
|
|
338
|
+
noiseKeyPair: {}
|
|
339
|
+
}, options);
|
|
340
|
+
const storageDir = this._root.createDirectory(publicKey.toHex());
|
|
341
|
+
const makeStorage = (filename) => {
|
|
342
|
+
const { type, native } = storageDir.getOrCreateFile(filename);
|
|
343
|
+
log("created", { path: `${type}:${this._root.path}/${publicKey.truncate()}/${filename}` }, {
|
|
344
|
+
"~LogMeta": "~LogMeta",
|
|
345
|
+
F: __dxlog_file$1,
|
|
346
|
+
L: 102,
|
|
347
|
+
S: this
|
|
348
|
+
});
|
|
349
|
+
return native;
|
|
350
|
+
};
|
|
351
|
+
return new FeedWrapper(hypercore(makeStorage, Buffer.from(key), opts), publicKey, storageDir);
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
/**
|
|
355
|
+
* Effect Layer constructing a {@link FeedFactory} from feed storage and keyring services.
|
|
356
|
+
*/
|
|
357
|
+
var FeedFactoryLayer = (options = {}) => Layer.effect(FeedFactoryService, Effect.gen(function* () {
|
|
358
|
+
return new FeedFactory({
|
|
359
|
+
root: yield* FeedStorageDirectoryService,
|
|
360
|
+
signer: yield* KeyringApiService,
|
|
361
|
+
hypercore: options.hypercore
|
|
362
|
+
});
|
|
363
|
+
}));
|
|
364
|
+
//#endregion
|
|
365
|
+
//#region src/feed-store.ts
|
|
366
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/common/feed-store/src/feed-store.ts";
|
|
367
|
+
/**
|
|
368
|
+
* Effect service tag for {@link FeedStore}.
|
|
369
|
+
*/
|
|
370
|
+
var FeedStoreService = class extends EffectContext.Tag("@dxos/feed-store/FeedStore")() {};
|
|
371
|
+
/**
|
|
372
|
+
* Persistent hypercore store.
|
|
373
|
+
*/
|
|
374
|
+
var FeedStore = class {
|
|
375
|
+
_feeds = new ComplexMap(PublicKey.hash);
|
|
376
|
+
_mutexes = new ComplexMap(PublicKey.hash);
|
|
377
|
+
_factory;
|
|
378
|
+
_closed = false;
|
|
379
|
+
feedOpened = new Event();
|
|
380
|
+
constructor({ factory }) {
|
|
381
|
+
this._factory = factory ?? failUndefined();
|
|
382
|
+
}
|
|
383
|
+
get size() {
|
|
384
|
+
return this._feeds.size;
|
|
385
|
+
}
|
|
386
|
+
get feeds() {
|
|
387
|
+
return Array.from(this._feeds.values());
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Get the open feed if it exists.
|
|
391
|
+
*/
|
|
392
|
+
getFeed(publicKey) {
|
|
393
|
+
return this._feeds.get(publicKey);
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Gets or opens a feed.
|
|
397
|
+
* The feed is readonly unless a secret key is provided.
|
|
398
|
+
*/
|
|
399
|
+
async openFeed(feedKey, { writable, sparse } = {}) {
|
|
400
|
+
log("opening feed", { feedKey }, {
|
|
401
|
+
"~LogMeta": "~LogMeta",
|
|
402
|
+
F: __dxlog_file,
|
|
403
|
+
L: 67,
|
|
404
|
+
S: this
|
|
405
|
+
});
|
|
406
|
+
invariant(feedKey, void 0, {
|
|
407
|
+
"~LogMeta": "~LogMeta",
|
|
408
|
+
F: __dxlog_file,
|
|
409
|
+
L: 68,
|
|
410
|
+
S: this,
|
|
411
|
+
A: ["feedKey", ""]
|
|
412
|
+
});
|
|
413
|
+
invariant(!this._closed, "Feed store is closed", {
|
|
414
|
+
"~LogMeta": "~LogMeta",
|
|
415
|
+
F: __dxlog_file,
|
|
416
|
+
L: 69,
|
|
417
|
+
S: this,
|
|
418
|
+
A: ["!this._closed", "'Feed store is closed'"]
|
|
419
|
+
});
|
|
420
|
+
return defaultMap(this._mutexes, feedKey, () => new Mutex()).executeSynchronized(async () => {
|
|
421
|
+
let feed = this.getFeed(feedKey);
|
|
422
|
+
if (feed) if (writable && !feed.properties.writable) throw new Error(`Read-only feed is already open: ${feedKey.truncate()}`);
|
|
423
|
+
else if ((sparse ?? false) !== feed.properties.sparse) throw new Error(`Feed already open with different sparse setting: ${feedKey.truncate()} [${sparse} !== ${feed.properties.sparse}]`);
|
|
424
|
+
else {
|
|
425
|
+
await feed.open();
|
|
426
|
+
return feed;
|
|
427
|
+
}
|
|
428
|
+
feed = await this._factory.createFeed(feedKey, {
|
|
429
|
+
writable,
|
|
430
|
+
sparse
|
|
431
|
+
});
|
|
432
|
+
this._feeds.set(feed.key, feed);
|
|
433
|
+
await feed.open();
|
|
434
|
+
this.feedOpened.emit(feed);
|
|
435
|
+
log("opened", { feedKey }, {
|
|
436
|
+
"~LogMeta": "~LogMeta",
|
|
437
|
+
F: __dxlog_file,
|
|
438
|
+
L: 97,
|
|
439
|
+
S: this
|
|
440
|
+
});
|
|
441
|
+
return feed;
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Close all feeds.
|
|
446
|
+
*/
|
|
447
|
+
async close() {
|
|
448
|
+
log("closing...", void 0, {
|
|
449
|
+
"~LogMeta": "~LogMeta",
|
|
450
|
+
F: __dxlog_file,
|
|
451
|
+
L: 106,
|
|
452
|
+
S: this
|
|
453
|
+
});
|
|
454
|
+
this._closed = true;
|
|
455
|
+
await Promise.all(Array.from(this._feeds.values()).map(async (feed) => {
|
|
456
|
+
await feed.close();
|
|
457
|
+
invariant(feed.closed, void 0, {
|
|
458
|
+
"~LogMeta": "~LogMeta",
|
|
459
|
+
F: __dxlog_file,
|
|
460
|
+
L: 111,
|
|
461
|
+
S: this,
|
|
462
|
+
A: ["feed.closed", ""]
|
|
463
|
+
});
|
|
464
|
+
}));
|
|
465
|
+
this._feeds.clear();
|
|
466
|
+
log("closed", void 0, {
|
|
467
|
+
"~LogMeta": "~LogMeta",
|
|
468
|
+
F: __dxlog_file,
|
|
469
|
+
L: 120,
|
|
470
|
+
S: this
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
/**
|
|
475
|
+
* Effect Layer constructing a {@link FeedStore} from a {@link FeedFactory} service.
|
|
476
|
+
*/
|
|
477
|
+
var FeedStoreLayer = () => Layer.effect(FeedStoreService, Effect.gen(function* () {
|
|
478
|
+
return new FeedStore({ factory: yield* FeedFactoryService });
|
|
479
|
+
}));
|
|
480
|
+
//#endregion
|
|
481
|
+
export { FeedFactoryLayer as a, FeedWrapper as c, FeedFactory as i, FeedStoreLayer as n, FeedFactoryService as o, FeedStoreService as r, FeedStorageDirectoryService as s, FeedStore as t };
|
|
482
|
+
|
|
483
|
+
//# sourceMappingURL=chunk-feed-store.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk-feed-store.mjs","names":[],"sources":["../../src/feed-wrapper.ts","../../src/feed-factory.ts","../../src/feed-store.ts"],"sourcesContent":["//\n// Copyright 2022 DXOS.org\n//\n\nimport { inspect } from 'node:util';\nimport { promisify } from 'node:util';\nimport { Readable, Transform } from 'streamx';\n\nimport { Trigger } from '@dxos/async';\nimport { StackTrace, inspectObject } from '@dxos/debug';\nimport type { Hypercore, HypercoreProperties, ReadStreamOptions } from '@dxos/hypercore';\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport { type PublicKey } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { type Directory } from '@dxos/random-access-storage';\nimport { arrayToBuffer, rangeFromTo } from '@dxos/util';\nimport type { GetOptions, Proof } from '@dxos/vendor-hypercore/hypercore';\n\nimport { type FeedWriter, type WriteReceipt } from './feed-writer';\n\n/**\n * Async feed wrapper.\n */\nexport class FeedWrapper<T extends {}> {\n private _hypercore: Hypercore<T>;\n private readonly _pendingWrites = new Set<StackTrace>();\n\n // Pending while writes are happening. Resolves when there are no pending writes.\n private readonly _writeLock = new Trigger();\n\n private _closed = false;\n\n constructor(\n hypercore: Hypercore<T>,\n private _key: PublicKey, // TODO(burdon): Required since currently patching the key inside factory.\n private _storageDirectory: Directory,\n ) {\n assertArgument(hypercore, 'hypercore');\n this._hypercore = hypercore;\n invariant(this._key);\n this._writeLock.wake();\n }\n\n [inspect.custom](): string {\n return inspectObject(this);\n }\n\n toJSON(): { feedKey: PublicKey; length: number; opened: boolean; closed: boolean } {\n return {\n feedKey: this._key,\n length: this.properties.length,\n opened: this.properties.opened,\n closed: this.properties.closed,\n };\n }\n\n get key(): PublicKey {\n return this._key;\n }\n\n get core(): Hypercore<T> {\n return this._hypercore;\n }\n\n // TODO(burdon): Create proxy.\n get properties(): HypercoreProperties {\n return this._hypercore;\n }\n\n createReadableStream(opts?: ReadStreamOptions): Readable {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const self = this;\n const transform = new Transform({\n transform(data: any, cb: (err?: Error | null, data?: any) => void) {\n // Delay until write is complete.\n void self._writeLock.wait().then(() => {\n this.push(data);\n cb();\n });\n },\n });\n const readStream =\n opts?.batch !== undefined && opts?.batch > 1\n ? new BatchedReadStream(this._hypercore, opts)\n : this._hypercore.createReadStream(opts);\n\n readStream.pipe(transform, (err: any) => {\n // Ignore errors.\n // We might get \"Writable stream closed prematurely\" error.\n // Its okay since the pipeline is closed and does not expect more messages.\n });\n\n return transform;\n }\n\n createFeedWriter(): FeedWriter<T> {\n return {\n write: async (data: T, { afterWrite } = {}) => {\n log('write', { feed: this._key, seq: this._hypercore.length });\n invariant(!this._closed, 'Feed closed');\n const stackTrace = new StackTrace();\n\n try {\n // Pending writes pause the read stream.\n this._pendingWrites.add(stackTrace);\n if (this._pendingWrites.size === 1) {\n this._writeLock.reset();\n }\n\n const receipt = await this.appendWithReceipt(data);\n\n // TODO(dmaretskyi): Removing this will make user-intiated writes faster but might result in a data-loss.\n await this.flushToDisk();\n\n await afterWrite?.(receipt);\n\n return receipt;\n } finally {\n // Unblock the read stream after the write (and callback) is complete.\n this._pendingWrites.delete(stackTrace);\n if (this._pendingWrites.size === 0) {\n this._writeLock.wake();\n }\n }\n },\n };\n }\n\n async appendWithReceipt(data: T): Promise<WriteReceipt> {\n const seq = await this.append(data);\n invariant(seq < this.length, 'Invalid seq after write');\n log('write complete', { feed: this._key, seq });\n const receipt: WriteReceipt = {\n feedKey: this.key,\n seq,\n };\n return receipt;\n }\n\n /**\n * Flush pending changes to disk.\n * Calling this is not required unless you want to explicitly wait for data to be written.\n */\n async flushToDisk(): Promise<void> {\n await this._storageDirectory.flush();\n }\n\n get opened(): boolean {\n return this._hypercore.opened;\n }\n\n get closed(): boolean {\n return this._hypercore.closed;\n }\n\n get readable(): boolean {\n return this._hypercore.readable;\n }\n\n get length(): number {\n return this._hypercore.length;\n }\n\n get byteLength(): number {\n return this._hypercore.byteLength;\n }\n\n on(...args: any[]) {\n return (this._hypercore as any).on(...args);\n }\n\n off(...args: any[]) {\n return (this._hypercore as any).off(...args);\n }\n\n open(...args: Parameters<Hypercore<T>['open']>) {\n return promisify(this._hypercore.open.bind(this._hypercore) as any)(...args);\n }\n\n _close(...args: Parameters<Hypercore<T>['close']>) {\n return promisify(this._hypercore.close.bind(this._hypercore) as any)(...args);\n }\n\n close = async () => {\n if (this._pendingWrites.size) {\n log.warn('Closing feed with pending writes', {\n feed: this._key,\n count: this._pendingWrites.size,\n pendingWrites: Array.from(this._pendingWrites.values()).map((stack) => stack.getStack()),\n });\n }\n this._closed = true;\n await this.flushToDisk();\n await this._close();\n };\n\n has(start: number, end?: number) {\n return this._hypercore.has(start, end);\n }\n\n get(index: number, options?: GetOptions) {\n return promisify(this._hypercore.get.bind(this._hypercore) as any)(index, options);\n }\n\n // TODO(dmaretskyi): Type better\n append(data: any | any[]): Promise<number> {\n return promisify(this._hypercore.append.bind(this._hypercore))(data);\n }\n\n /**\n * Will not resolve if `end` parameter is not specified and the feed is not closed.\n */\n download(...args: Parameters<Hypercore<T>['download']>) {\n return this._hypercore.download(...args);\n }\n\n undownload(...args: Parameters<Hypercore<T>['undownload']>) {\n return this._hypercore.undownload(...args);\n }\n\n setDownloading(...args: Parameters<Hypercore<T>['setDownloading']>) {\n return this._hypercore.setDownloading(...args);\n }\n\n replicate(...args: Parameters<Hypercore<T>['replicate']>) {\n return this._hypercore.replicate(...args);\n }\n\n clear(start: number, end?: number) {\n return promisify(this._hypercore.clear.bind(this._hypercore))(start, end);\n }\n\n proof(index: number, options?: any) {\n return promisify(this._hypercore.proof.bind(this._hypercore))(index);\n }\n\n put(index: number, data: T, proof: Proof) {\n return promisify(this._hypercore.put.bind(this._hypercore))(index, data, proof);\n }\n\n putBuffer(index: number, data: Buffer | Uint8Array, proof: Proof, peer: null): Promise<void> {\n return promisify((this._hypercore as any)._putBuffer.bind(this._hypercore) as any)(index, data, proof, peer);\n }\n\n /**\n * Clear and check for integrity.\n */\n async safeClear(from: number, to: number): Promise<void> {\n invariant(from >= 0 && from < to && to <= this.length, 'Invalid range');\n\n const CHECK_MESSAGES = 20;\n const checkBegin = to;\n const checkEnd = Math.min(checkBegin + CHECK_MESSAGES, this.length);\n\n const messagesBefore = await Promise.all(\n rangeFromTo(checkBegin, checkEnd).map((idx) =>\n this.get(idx, {\n valueEncoding: { decode: (x: Uint8Array) => x } as any,\n }),\n ),\n );\n\n await this.clear(from, to);\n\n const messagesAfter = await Promise.all(\n rangeFromTo(checkBegin, checkEnd).map((idx) =>\n this.get(idx, {\n valueEncoding: { decode: (x: Uint8Array) => x } as any,\n }),\n ),\n );\n\n for (let i = 0; i < messagesBefore.length; i++) {\n const before = arrayToBuffer(messagesBefore[i]);\n const after = arrayToBuffer(messagesAfter[i]);\n if (!before.equals(after)) {\n throw new Error('Feed corruption on clear. There has likely been a data loss.');\n }\n }\n }\n}\n\nclass BatchedReadStream extends Readable {\n private readonly _feed: Hypercore<any>;\n private readonly _batch: number;\n private _cursor: number;\n private _reading = false;\n\n constructor(feed: Hypercore<any>, opts: ReadStreamOptions = {}) {\n super({ objectMode: true });\n invariant(opts.live === true, 'Only live mode supported');\n invariant(opts.batch !== undefined && opts.batch > 1);\n this._feed = feed;\n this._batch = opts.batch;\n this._cursor = opts.start ?? 0;\n }\n\n override _open(cb: (err: Error | null) => void): void {\n this._feed.ready(cb);\n }\n\n override _read(cb: (err: Error | null) => void): void {\n if (this._reading) {\n return;\n }\n\n if (this._feed.bitfield!.total(this._cursor, this._cursor + this._batch) === this._batch) {\n this._batchedRead(cb);\n } else {\n this._nonBatchedRead(cb);\n }\n }\n\n private _nonBatchedRead(cb: (err: Error | null) => void): void {\n this._feed.get(this._cursor, { wait: true }, (err, data) => {\n if (err) {\n cb(err);\n } else {\n this._cursor++;\n this._reading = false;\n this.push(data);\n cb(null);\n }\n });\n }\n\n private _batchedRead(cb: (err: Error | null) => void): void {\n this._feed.getBatch(this._cursor, this._cursor + this._batch, { wait: true }, (err, data) => {\n if (err) {\n cb(err);\n } else {\n this._cursor += data.length;\n this._reading = false;\n for (const item of data) {\n this.push(item);\n }\n cb(null);\n }\n });\n }\n}\n","//\n// Copyright 2022 DXOS.org\n//\n\nimport * as EffectContext from 'effect/Context';\nimport * as Effect from 'effect/Effect';\nimport * as Layer from 'effect/Layer';\nimport defaultsDeep from 'lodash.defaultsdeep';\n\nimport { type Signer, subtleCrypto } from '@dxos/crypto';\nimport { failUndefined } from '@dxos/debug';\nimport type { HypercoreOptions } from '@dxos/hypercore';\nimport { createCrypto, hypercore } from '@dxos/hypercore';\nimport { KeyringApiService } from '@dxos/keyring';\nimport { type PublicKey } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { type Directory } from '@dxos/random-access-storage';\n\nimport { FeedWrapper } from './feed-wrapper';\n\nexport type FeedFactoryOptions = {\n root: Directory;\n signer?: Signer;\n hypercore?: HypercoreOptions;\n};\n\nexport type FeedOptions = HypercoreOptions & {\n writable?: boolean;\n /**\n * Optional hook called before data is written after being verified.\n * Called for writes done by this peer as well as for data replicated from other peers.\n * NOTE: The callback must be invoked to complete the write operation.\n * @param peer Always null in hypercore@9.12.0.\n */\n onwrite?: (index: number, data: any, peer: null, cb: (err: Error | null) => void) => void;\n};\n\n/**\n * Effect service tag for {@link FeedFactory}.\n */\nexport class FeedFactoryService extends EffectContext.Tag('@dxos/feed-store/FeedFactory')<\n FeedFactoryService,\n FeedFactory<any>\n>() {}\n\n/**\n * Root directory for hypercore feed files.\n */\nexport class FeedStorageDirectoryService extends EffectContext.Tag('@dxos/feed-store/FeedStorageDirectory')<\n FeedStorageDirectoryService,\n Directory\n>() {}\n\n/**\n * Hypercore factory.\n */\nexport class FeedFactory<T extends {}> {\n private readonly _root: Directory;\n private readonly _signer?: Signer;\n private readonly _hypercoreOptions?: HypercoreOptions;\n\n constructor({ root, signer, hypercore }: FeedFactoryOptions) {\n log('FeedFactory', { options: hypercore });\n this._root = root ?? failUndefined();\n this._signer = signer;\n this._hypercoreOptions = hypercore;\n }\n\n get storageRoot() {\n return this._root;\n }\n\n async createFeed(publicKey: PublicKey, options?: FeedOptions): Promise<FeedWrapper<T>> {\n if (options?.writable && !this._signer) {\n throw new Error('Signer required to create writable feeds.');\n }\n if (options?.secretKey) {\n log.warn('Secret key ignored due to signer.');\n }\n\n // Required due to hypercore's 32-byte key limit.\n const key = await subtleCrypto.digest('SHA-256', Buffer.from(publicKey.toHex()));\n\n const opts = defaultsDeep(\n {\n // sparse: false,\n // stats: false,\n },\n this._hypercoreOptions,\n {\n secretKey: this._signer && options?.writable ? Buffer.from('secret') : undefined,\n crypto: this._signer ? createCrypto(this._signer, publicKey) : undefined,\n onwrite: options?.onwrite,\n noiseKeyPair: {}, // We're not using noise.\n },\n options,\n );\n\n const storageDir = this._root.createDirectory(publicKey.toHex());\n const makeStorage = (filename: string) => {\n const { type, native } = storageDir.getOrCreateFile(filename);\n log('created', {\n path: `${type}:${this._root.path}/${publicKey.truncate()}/${filename}`,\n });\n\n return native;\n };\n\n const core = hypercore(makeStorage, Buffer.from(key), opts);\n return new FeedWrapper(core, publicKey, storageDir);\n }\n}\n\nexport type FeedFactoryLayerOptions = Pick<FeedFactoryOptions, 'hypercore'>;\n\n/**\n * Effect Layer constructing a {@link FeedFactory} from feed storage and keyring services.\n */\nexport const FeedFactoryLayer = (\n options: FeedFactoryLayerOptions = {},\n): Layer.Layer<FeedFactoryService, never, KeyringApiService | FeedStorageDirectoryService> =>\n Layer.effect(\n FeedFactoryService,\n Effect.gen(function* () {\n const root = yield* FeedStorageDirectoryService;\n const signer = yield* KeyringApiService;\n return new FeedFactory({\n root,\n signer,\n hypercore: options.hypercore,\n });\n }),\n );\n","//\n// Copyright 2019 DXOS.org\n//\n\nimport * as EffectContext from 'effect/Context';\nimport * as Effect from 'effect/Effect';\nimport * as Layer from 'effect/Layer';\n\nimport { Event, Mutex } from '@dxos/async';\nimport { failUndefined } from '@dxos/debug';\nimport { invariant } from '@dxos/invariant';\nimport { PublicKey } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { ComplexMap, defaultMap } from '@dxos/util';\n\nimport { type FeedFactory, FeedFactoryService, type FeedOptions } from './feed-factory';\nimport { type FeedWrapper } from './feed-wrapper';\n\nexport interface FeedStoreOptions<T extends {}> {\n factory: FeedFactory<T>;\n}\n\n/**\n * Effect service tag for {@link FeedStore}.\n */\nexport class FeedStoreService extends EffectContext.Tag('@dxos/feed-store/FeedStore')<\n FeedStoreService,\n FeedStore<any>\n>() {}\n\n/**\n * Persistent hypercore store.\n */\nexport class FeedStore<T extends {}> {\n private readonly _feeds: ComplexMap<PublicKey, FeedWrapper<T>> = new ComplexMap(PublicKey.hash);\n private readonly _mutexes = new ComplexMap<PublicKey, Mutex>(PublicKey.hash);\n private readonly _factory: FeedFactory<T>;\n\n private _closed = false;\n\n readonly feedOpened = new Event<FeedWrapper<T>>();\n\n constructor({ factory }: FeedStoreOptions<T>) {\n this._factory = factory ?? failUndefined();\n }\n\n get size() {\n return this._feeds.size;\n }\n\n get feeds() {\n return Array.from(this._feeds.values());\n }\n\n /**\n * Get the open feed if it exists.\n */\n getFeed(publicKey: PublicKey): FeedWrapper<T> | undefined {\n return this._feeds.get(publicKey);\n }\n\n /**\n * Gets or opens a feed.\n * The feed is readonly unless a secret key is provided.\n */\n async openFeed(feedKey: PublicKey, { writable, sparse }: FeedOptions = {}): Promise<FeedWrapper<T>> {\n log('opening feed', { feedKey });\n invariant(feedKey);\n invariant(!this._closed, 'Feed store is closed');\n\n const mutex = defaultMap(this._mutexes, feedKey, () => new Mutex());\n\n return mutex.executeSynchronized(async () => {\n let feed = this.getFeed(feedKey);\n if (feed) {\n // TODO(burdon): Need to check that there's another instance being used (create test and break this).\n // TODO(burdon): Remove from store if feed is closed externally? (remove wrapped open/close methods?)\n if (writable && !feed.properties.writable) {\n throw new Error(`Read-only feed is already open: ${feedKey.truncate()}`);\n } else if ((sparse ?? false) !== feed.properties.sparse) {\n throw new Error(\n `Feed already open with different sparse setting: ${feedKey.truncate()} [${sparse} !== ${\n feed.properties.sparse\n }]`,\n );\n } else {\n await feed.open();\n return feed;\n }\n }\n\n feed = await this._factory.createFeed(feedKey, { writable, sparse });\n this._feeds.set(feed.key, feed);\n\n await feed.open();\n this.feedOpened.emit(feed);\n log('opened', { feedKey });\n return feed;\n });\n }\n\n /**\n * Close all feeds.\n */\n async close(): Promise<void> {\n log('closing...');\n this._closed = true;\n await Promise.all(\n Array.from(this._feeds.values()).map(async (feed) => {\n await feed.close();\n invariant(feed.closed);\n // TODO(burdon): SpaceProxy still being initialized.\n // SpaceProxy.initialize => Database.createItem => ... => FeedWrapper.append\n // Uncaught Error: Closed [random-access-storage/index.js:181:38]\n // await sleep(100);\n }),\n );\n\n this._feeds.clear();\n log('closed');\n }\n}\n\n/**\n * Effect Layer constructing a {@link FeedStore} from a {@link FeedFactory} service.\n */\nexport const FeedStoreLayer = (): Layer.Layer<FeedStoreService, never, FeedFactoryService> =>\n Layer.effect(\n FeedStoreService,\n Effect.gen(function* () {\n const factory = yield* FeedFactoryService;\n return new FeedStore({ factory });\n }),\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAuBA,IAAa,cAAb,MAAuC;CAW3B;CACA;CAXV;CACA,iCAAkC,IAAI,IAAgB;CAGtD,aAA8B,IAAI,QAAQ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