@fireproof/core 0.20.0-dev-preview-06 → 0.20.0-dev-preview-11
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +9 -9
- package/index.cjs +3221 -3166
- package/index.cjs.map +1 -1
- package/index.d.cts +241 -189
- package/index.d.ts +241 -189
- package/index.js +3211 -3156
- package/index.js.map +1 -1
- package/metafile-cjs.json +1 -1
- package/metafile-esm.json +1 -1
- package/package.json +3 -3
- package/react/index.cjs.map +1 -1
- package/react/index.js.map +1 -1
- package/tests/blockstore/loader.test.ts +6 -6
- package/tests/blockstore/transaction.test.ts +8 -8
- package/tests/fireproof/all-gateway.test.ts +7 -7
- package/tests/fireproof/crdt.test.ts +35 -45
- package/tests/fireproof/database.test.ts +34 -33
- package/tests/fireproof/fireproof.test.ts +58 -60
- package/tests/fireproof/hello.test.ts +3 -3
- package/tests/fireproof/indexer.test.ts +37 -36
- package/tests/gateway/file/loader-config.test.ts +17 -17
- package/tests/gateway/indexdb/loader-config.test.ts +5 -5
- package/tests/www/gallery.html +2 -2
- package/tests/www/todo-aws.html +1 -1
- package/tests/www/todo-ipfs.html +1 -1
- package/tests/www/todo-local.html +1 -1
- package/tests/www/todo.html +1 -1
- /package/tests/fireproof/{multiple-database.test.ts → multiple-ledger.test.ts} +0 -0
@@ -1,10 +1,10 @@
|
|
1
|
-
import { CRDT, defaultWriteQueueOpts, ensureSuperThis,
|
1
|
+
import { CRDT, defaultWriteQueueOpts, ensureSuperThis, LedgerOpts, toStoreURIRuntime, rt, CRDTImpl } from "@fireproof/core";
|
2
2
|
import { bs } from "@fireproof/core";
|
3
3
|
import { CRDTMeta, DocValue } from "@fireproof/core";
|
4
4
|
import { Index, index } from "@fireproof/core";
|
5
5
|
|
6
6
|
describe("Fresh crdt", function () {
|
7
|
-
let crdt: CRDT
|
7
|
+
let crdt: CRDT;
|
8
8
|
const sthis = ensureSuperThis();
|
9
9
|
afterEach(async function () {
|
10
10
|
await crdt.close();
|
@@ -12,13 +12,13 @@ describe("Fresh crdt", function () {
|
|
12
12
|
});
|
13
13
|
beforeEach(async function () {
|
14
14
|
await sthis.start();
|
15
|
-
const dbOpts:
|
15
|
+
const dbOpts: LedgerOpts = {
|
16
16
|
writeQueue: defaultWriteQueueOpts({}),
|
17
17
|
keyBag: rt.defaultKeyBagOpts(sthis),
|
18
18
|
storeUrls: toStoreURIRuntime(sthis, "test-crdt-cold"),
|
19
19
|
storeEnDe: bs.ensureStoreEnDeFile({}),
|
20
20
|
};
|
21
|
-
crdt = new
|
21
|
+
crdt = new CRDTImpl(sthis, dbOpts);
|
22
22
|
});
|
23
23
|
it("should have an empty head", async function () {
|
24
24
|
const head = crdt.clock.head;
|
@@ -44,7 +44,7 @@ describe("CRDT with one record", function () {
|
|
44
44
|
readonly hello: string;
|
45
45
|
readonly nice: string;
|
46
46
|
}
|
47
|
-
let crdt: CRDT
|
47
|
+
let crdt: CRDT;
|
48
48
|
let firstPut: CRDTMeta;
|
49
49
|
const sthis = ensureSuperThis();
|
50
50
|
|
@@ -55,13 +55,13 @@ describe("CRDT with one record", function () {
|
|
55
55
|
|
56
56
|
beforeEach(async function () {
|
57
57
|
await sthis.start();
|
58
|
-
const dbOpts:
|
58
|
+
const dbOpts: LedgerOpts = {
|
59
59
|
writeQueue: defaultWriteQueueOpts({}),
|
60
60
|
keyBag: rt.defaultKeyBagOpts(sthis),
|
61
61
|
storeUrls: toStoreURIRuntime(sthis, `test@${sthis.nextId().str}`),
|
62
62
|
storeEnDe: bs.ensureStoreEnDeFile({}),
|
63
63
|
};
|
64
|
-
crdt = new
|
64
|
+
crdt = new CRDTImpl(sthis, dbOpts);
|
65
65
|
firstPut = await crdt.bulk([{ id: "hello", value: { hello: "world" } }]);
|
66
66
|
});
|
67
67
|
it("should have a one-element head", async function () {
|
@@ -90,7 +90,7 @@ describe("CRDT with one record", function () {
|
|
90
90
|
expect(got).toBeFalsy();
|
91
91
|
});
|
92
92
|
it("should offer changes", async function () {
|
93
|
-
const { result } = await crdt.changes([]);
|
93
|
+
const { result } = await crdt.changes<Partial<CRDTTestType>>([]);
|
94
94
|
expect(result.length).toBe(1);
|
95
95
|
expect(result[0].id).toBe("hello");
|
96
96
|
expect(result[0].value?.hello).toBe("world");
|
@@ -101,7 +101,7 @@ describe("CRDT with a multi-write", function () {
|
|
101
101
|
interface CRDTTestType {
|
102
102
|
readonly points: number;
|
103
103
|
}
|
104
|
-
let crdt: CRDT
|
104
|
+
let crdt: CRDT;
|
105
105
|
let firstPut: CRDTMeta;
|
106
106
|
const sthis = ensureSuperThis();
|
107
107
|
|
@@ -111,13 +111,13 @@ describe("CRDT with a multi-write", function () {
|
|
111
111
|
});
|
112
112
|
beforeEach(async function () {
|
113
113
|
await sthis.start();
|
114
|
-
const dbOpts:
|
114
|
+
const dbOpts: LedgerOpts = {
|
115
115
|
writeQueue: defaultWriteQueueOpts({}),
|
116
116
|
keyBag: rt.defaultKeyBagOpts(sthis),
|
117
117
|
storeUrls: toStoreURIRuntime(sthis, "test-crdt-cold"),
|
118
118
|
storeEnDe: bs.ensureStoreEnDeFile({}),
|
119
119
|
};
|
120
|
-
crdt = new
|
120
|
+
crdt = new CRDTImpl(sthis, dbOpts);
|
121
121
|
firstPut = await crdt.bulk([
|
122
122
|
{ id: "ace", value: { points: 11 } },
|
123
123
|
{ id: "king", value: { points: 10 } },
|
@@ -145,7 +145,7 @@ describe("CRDT with a multi-write", function () {
|
|
145
145
|
expect(got.doc.points).toBe(10);
|
146
146
|
});
|
147
147
|
it("should offer changes", async function () {
|
148
|
-
const { result } = await crdt.changes([]);
|
148
|
+
const { result } = await crdt.changes<CRDTTestType>([]);
|
149
149
|
expect(result.length).toBe(2);
|
150
150
|
expect(result[0].id).toBe("ace");
|
151
151
|
expect(result[0].value?.points).toBe(11);
|
@@ -158,7 +158,7 @@ describe("CRDT with a multi-write", function () {
|
|
158
158
|
{ id: "jack", value: { points: 10 } },
|
159
159
|
]);
|
160
160
|
expect(secondPut.head).toBeTruthy();
|
161
|
-
const { result: r2, head: h2 } = await crdt.changes();
|
161
|
+
const { result: r2, head: h2 } = await crdt.changes<CRDTTestType>();
|
162
162
|
expect(r2.length).toBe(4);
|
163
163
|
const { result: r3 } = await crdt.changes(firstPut.head);
|
164
164
|
expect(r3.length).toBe(2);
|
@@ -171,8 +171,7 @@ interface CRDTTestType {
|
|
171
171
|
readonly points: number;
|
172
172
|
}
|
173
173
|
describe("CRDT with two multi-writes", function () {
|
174
|
-
|
175
|
-
let crdt: CRDT<CRDTTestType>;
|
174
|
+
let crdt: CRDT;
|
176
175
|
let firstPut: CRDTMeta;
|
177
176
|
let secondPut: CRDTMeta;
|
178
177
|
const sthis = ensureSuperThis();
|
@@ -182,13 +181,13 @@ describe("CRDT with two multi-writes", function () {
|
|
182
181
|
});
|
183
182
|
beforeEach(async () => {
|
184
183
|
await sthis.start();
|
185
|
-
const dbOpts:
|
184
|
+
const dbOpts: LedgerOpts = {
|
186
185
|
writeQueue: defaultWriteQueueOpts({}),
|
187
186
|
keyBag: rt.defaultKeyBagOpts(sthis),
|
188
187
|
storeUrls: toStoreURIRuntime(sthis, `test-multiple-writes@${sthis.nextId().str}`),
|
189
188
|
storeEnDe: bs.ensureStoreEnDeFile({}),
|
190
189
|
};
|
191
|
-
crdt = new
|
190
|
+
crdt = new CRDTImpl(sthis, dbOpts);
|
192
191
|
firstPut = await crdt.bulk([
|
193
192
|
{ id: "ace", value: { points: 11 } },
|
194
193
|
{ id: "king", value: { points: 10 } },
|
@@ -217,7 +216,7 @@ describe("CRDT with two multi-writes", function () {
|
|
217
216
|
}
|
218
217
|
});
|
219
218
|
it("should offer changes", async function () {
|
220
|
-
const { result } = await crdt.changes();
|
219
|
+
const { result } = await crdt.changes<CRDTTestType>();
|
221
220
|
expect(result.length).toBe(4);
|
222
221
|
expect(result[0].id).toBe("ace");
|
223
222
|
expect(result[0].value?.points).toBe(11);
|
@@ -228,7 +227,7 @@ describe("CRDT with two multi-writes", function () {
|
|
228
227
|
});
|
229
228
|
|
230
229
|
describe("Compact a named CRDT with writes", function () {
|
231
|
-
let crdt: CRDT
|
230
|
+
let crdt: CRDT;
|
232
231
|
const sthis = ensureSuperThis();
|
233
232
|
afterEach(async function () {
|
234
233
|
await crdt.close();
|
@@ -236,13 +235,13 @@ describe("Compact a named CRDT with writes", function () {
|
|
236
235
|
});
|
237
236
|
beforeEach(async function () {
|
238
237
|
await sthis.start();
|
239
|
-
const dbOpts:
|
238
|
+
const dbOpts: LedgerOpts = {
|
240
239
|
writeQueue: defaultWriteQueueOpts({}),
|
241
240
|
keyBag: rt.defaultKeyBagOpts(sthis),
|
242
241
|
storeUrls: toStoreURIRuntime(sthis, `named-crdt-compaction`),
|
243
242
|
storeEnDe: bs.ensureStoreEnDeFile({}),
|
244
243
|
};
|
245
|
-
crdt = new
|
244
|
+
crdt = new CRDTImpl(sthis, dbOpts);
|
246
245
|
for (let i = 0; i < 10; i++) {
|
247
246
|
const bulk = [
|
248
247
|
{ id: "ace", value: { points: 11 } },
|
@@ -289,7 +288,7 @@ describe("Compact a named CRDT with writes", function () {
|
|
289
288
|
});
|
290
289
|
|
291
290
|
describe("CRDT with an index", function () {
|
292
|
-
let crdt: CRDT
|
291
|
+
let crdt: CRDT;
|
293
292
|
let idx: Index<number, CRDTTestType>;
|
294
293
|
const sthis = ensureSuperThis();
|
295
294
|
afterEach(async function () {
|
@@ -298,18 +297,18 @@ describe("CRDT with an index", function () {
|
|
298
297
|
});
|
299
298
|
beforeEach(async function () {
|
300
299
|
await sthis.start();
|
301
|
-
const dbOpts:
|
300
|
+
const dbOpts: LedgerOpts = {
|
302
301
|
writeQueue: defaultWriteQueueOpts({}),
|
303
302
|
keyBag: rt.defaultKeyBagOpts(sthis),
|
304
303
|
storeUrls: toStoreURIRuntime(sthis, "test-crdt-cold"),
|
305
304
|
storeEnDe: bs.ensureStoreEnDeFile({}),
|
306
305
|
};
|
307
|
-
crdt = new
|
306
|
+
crdt = new CRDTImpl(sthis, dbOpts);
|
308
307
|
await crdt.bulk([
|
309
308
|
{ id: "ace", value: { points: 11 } },
|
310
309
|
{ id: "king", value: { points: 10 } },
|
311
310
|
]);
|
312
|
-
idx = await index<number, CRDTTestType>(
|
311
|
+
idx = await index<number, CRDTTestType>(crdt, "points");
|
313
312
|
});
|
314
313
|
it("should query the data", async function () {
|
315
314
|
const got = await idx.query({ range: [9, 12] });
|
@@ -318,7 +317,7 @@ describe("CRDT with an index", function () {
|
|
318
317
|
expect(got.rows[0].key).toBe(10);
|
319
318
|
});
|
320
319
|
it("should register the index", async function () {
|
321
|
-
const rIdx = await index<number, CRDTTestType>(
|
320
|
+
const rIdx = await index<number, CRDTTestType>(crdt, "points");
|
322
321
|
expect(rIdx).toBeTruthy();
|
323
322
|
expect(rIdx.name).toBe("points");
|
324
323
|
const got = await rIdx.query({ range: [9, 12] });
|
@@ -327,7 +326,7 @@ describe("CRDT with an index", function () {
|
|
327
326
|
expect(got.rows[0].key).toBe(10);
|
328
327
|
});
|
329
328
|
it("creating a different index with same name should not work", async function () {
|
330
|
-
const e = await index(
|
329
|
+
const e = await index(crdt, "points", (doc) => doc._id)
|
331
330
|
.query()
|
332
331
|
.catch((err) => err);
|
333
332
|
expect(e.message).toMatch(/cannot apply/);
|
@@ -335,12 +334,9 @@ describe("CRDT with an index", function () {
|
|
335
334
|
});
|
336
335
|
|
337
336
|
describe("Loader with a committed transaction", function () {
|
338
|
-
interface CRDTTestType {
|
339
|
-
readonly foo: string;
|
340
|
-
}
|
341
337
|
let loader: bs.Loader;
|
342
338
|
let blockstore: bs.EncryptedBlockstore;
|
343
|
-
let crdt: CRDT
|
339
|
+
let crdt: CRDT;
|
344
340
|
let done: CRDTMeta;
|
345
341
|
const dbname = "test-loader";
|
346
342
|
const sthis = ensureSuperThis();
|
@@ -350,13 +346,13 @@ describe("Loader with a committed transaction", function () {
|
|
350
346
|
});
|
351
347
|
beforeEach(async function () {
|
352
348
|
await sthis.start();
|
353
|
-
const dbOpts:
|
349
|
+
const dbOpts: LedgerOpts = {
|
354
350
|
writeQueue: defaultWriteQueueOpts({}),
|
355
351
|
keyBag: rt.defaultKeyBagOpts(sthis),
|
356
352
|
storeUrls: toStoreURIRuntime(sthis, dbname),
|
357
353
|
storeEnDe: bs.ensureStoreEnDeFile({}),
|
358
354
|
};
|
359
|
-
crdt = new
|
355
|
+
crdt = new CRDTImpl(sthis, dbOpts);
|
360
356
|
blockstore = crdt.blockstore as bs.EncryptedBlockstore;
|
361
357
|
expect(blockstore.loader).toBeTruthy();
|
362
358
|
loader = blockstore.loader as bs.Loader;
|
@@ -389,11 +385,8 @@ describe("Loader with a committed transaction", function () {
|
|
389
385
|
});
|
390
386
|
|
391
387
|
describe("Loader with two committed transactions", function () {
|
392
|
-
interface CRDTTestType {
|
393
|
-
readonly foo: string;
|
394
|
-
}
|
395
388
|
let loader: bs.Loader;
|
396
|
-
let crdt: CRDT
|
389
|
+
let crdt: CRDT;
|
397
390
|
let blockstore: bs.EncryptedBlockstore;
|
398
391
|
let done1: CRDTMeta;
|
399
392
|
let done2: CRDTMeta;
|
@@ -404,13 +397,13 @@ describe("Loader with two committed transactions", function () {
|
|
404
397
|
});
|
405
398
|
beforeEach(async function () {
|
406
399
|
await sthis.start();
|
407
|
-
const dbOpts:
|
400
|
+
const dbOpts: LedgerOpts = {
|
408
401
|
writeQueue: defaultWriteQueueOpts({}),
|
409
402
|
keyBag: rt.defaultKeyBagOpts(sthis),
|
410
403
|
storeUrls: toStoreURIRuntime(sthis, "test-loader"),
|
411
404
|
storeEnDe: bs.ensureStoreEnDeFile({}),
|
412
405
|
};
|
413
|
-
crdt = new
|
406
|
+
crdt = new CRDTImpl(sthis, dbOpts);
|
414
407
|
blockstore = crdt.blockstore as bs.EncryptedBlockstore;
|
415
408
|
expect(blockstore.loader).toBeTruthy();
|
416
409
|
loader = blockstore.loader as bs.Loader;
|
@@ -445,12 +438,9 @@ describe("Loader with two committed transactions", function () {
|
|
445
438
|
});
|
446
439
|
|
447
440
|
describe("Loader with many committed transactions", function () {
|
448
|
-
interface Doc {
|
449
|
-
foo: string;
|
450
|
-
}
|
451
441
|
let loader: bs.Loader;
|
452
442
|
let blockstore: bs.EncryptedBlockstore;
|
453
|
-
let crdt: CRDT
|
443
|
+
let crdt: CRDT;
|
454
444
|
let dones: CRDTMeta[];
|
455
445
|
const count = 10;
|
456
446
|
const sthis = ensureSuperThis();
|
@@ -460,13 +450,13 @@ describe("Loader with many committed transactions", function () {
|
|
460
450
|
});
|
461
451
|
beforeEach(async function () {
|
462
452
|
await sthis.start();
|
463
|
-
const dbOpts:
|
453
|
+
const dbOpts: LedgerOpts = {
|
464
454
|
writeQueue: defaultWriteQueueOpts({}),
|
465
455
|
keyBag: rt.defaultKeyBagOpts(sthis),
|
466
456
|
storeUrls: toStoreURIRuntime(sthis, "test-loader-many"),
|
467
457
|
storeEnDe: bs.ensureStoreEnDeFile({}),
|
468
458
|
};
|
469
|
-
crdt = new
|
459
|
+
crdt = new CRDTImpl(sthis, dbOpts);
|
470
460
|
blockstore = crdt.blockstore as bs.EncryptedBlockstore;
|
471
461
|
expect(blockstore.loader).toBeTruthy();
|
472
462
|
loader = blockstore.loader as bs.Loader;
|
@@ -2,19 +2,19 @@ import { URI } from "@adviser/cement";
|
|
2
2
|
import { buildBlobFiles, FileWithCid, mockSuperThis } from "../helpers.js";
|
3
3
|
import {
|
4
4
|
bs,
|
5
|
-
Database,
|
6
5
|
DocResponse,
|
7
6
|
DocFileMeta,
|
8
7
|
DocWithId,
|
9
8
|
DocFiles,
|
10
9
|
toStoreURIRuntime,
|
11
10
|
keyConfigOpts,
|
12
|
-
DatabaseFactory,
|
13
|
-
DatabaseShell,
|
14
11
|
ensureSuperThis,
|
12
|
+
Database,
|
13
|
+
fireproof,
|
14
|
+
LedgerShell,
|
15
15
|
} from "@fireproof/core";
|
16
16
|
|
17
|
-
describe("basic
|
17
|
+
describe("basic Ledger", () => {
|
18
18
|
let db: Database;
|
19
19
|
const sthis = mockSuperThis();
|
20
20
|
afterEach(async () => {
|
@@ -23,7 +23,7 @@ describe("basic Database", () => {
|
|
23
23
|
});
|
24
24
|
beforeEach(async () => {
|
25
25
|
await sthis.start();
|
26
|
-
db =
|
26
|
+
db = fireproof(undefined as unknown as string, {
|
27
27
|
logger: sthis.logger,
|
28
28
|
});
|
29
29
|
});
|
@@ -49,11 +49,11 @@ describe("basic Database", () => {
|
|
49
49
|
});
|
50
50
|
});
|
51
51
|
|
52
|
-
describe("basic
|
52
|
+
describe("basic Ledger with record", function () {
|
53
53
|
interface Doc {
|
54
54
|
readonly value: string;
|
55
55
|
}
|
56
|
-
let db:
|
56
|
+
let db: Database;
|
57
57
|
const sthis = ensureSuperThis();
|
58
58
|
afterEach(async () => {
|
59
59
|
await db.close();
|
@@ -61,7 +61,7 @@ describe("basic Database with record", function () {
|
|
61
61
|
});
|
62
62
|
beforeEach(async function () {
|
63
63
|
await sthis.start();
|
64
|
-
db =
|
64
|
+
db = fireproof("factory-name");
|
65
65
|
const ok = await db.put<Doc>({ _id: "hello", value: "world" });
|
66
66
|
expect(ok.id).toBe("hello");
|
67
67
|
});
|
@@ -93,17 +93,18 @@ describe("basic Database with record", function () {
|
|
93
93
|
expect(rows[0].value._id).toBe("hello");
|
94
94
|
});
|
95
95
|
it("is not persisted", async function () {
|
96
|
-
const db2 =
|
96
|
+
const db2 = fireproof("factory-name");
|
97
97
|
const { rows } = await db2.changes([]);
|
98
98
|
expect(rows.length).toBe(1);
|
99
|
-
|
99
|
+
// assert((db.ledger.ref === db2.ledger.ref, "should be the same ledger");
|
100
|
+
expect((db.ledger as LedgerShell).ref).toBe((db2.ledger as LedgerShell).ref);
|
100
101
|
const doc = await db2.get<Doc>("hello").catch((e) => e);
|
101
102
|
expect(doc.value).toBe("world");
|
102
103
|
await db2.close();
|
103
104
|
});
|
104
105
|
});
|
105
106
|
|
106
|
-
describe("named
|
107
|
+
describe("named Ledger with record", function () {
|
107
108
|
interface Doc {
|
108
109
|
readonly value: string;
|
109
110
|
}
|
@@ -115,7 +116,7 @@ describe("named Database with record", function () {
|
|
115
116
|
});
|
116
117
|
beforeEach(async function () {
|
117
118
|
await sthis.start();
|
118
|
-
db =
|
119
|
+
db = fireproof("test-db-name");
|
119
120
|
/** @type {Doc} */
|
120
121
|
const doc = { _id: "hello", value: "world" };
|
121
122
|
const ok = await db.put(doc);
|
@@ -151,7 +152,7 @@ describe("named Database with record", function () {
|
|
151
152
|
it("should have a key", async function () {
|
152
153
|
const { rows } = await db.changes([]);
|
153
154
|
expect(rows.length).toBe(1);
|
154
|
-
const blocks = db.crdt.blockstore as bs.EncryptedBlockstore;
|
155
|
+
const blocks = db.ledger.crdt.blockstore as bs.EncryptedBlockstore;
|
155
156
|
const loader = blocks.loader;
|
156
157
|
expect(loader).toBeTruthy();
|
157
158
|
await loader.ready();
|
@@ -217,13 +218,13 @@ describe("named Database with record", function () {
|
|
217
218
|
});
|
218
219
|
});
|
219
220
|
|
220
|
-
// describe('basic
|
221
|
-
// /** @type {
|
221
|
+
// describe('basic Ledger parallel writes / public', function () {
|
222
|
+
// /** @type {Ledger} */
|
222
223
|
// let db
|
223
224
|
// const writes = []
|
224
225
|
// beforeEach(async function () {
|
225
226
|
// await resetDirectory(dataDir, 'test-parallel-writes')
|
226
|
-
// db = new
|
227
|
+
// db = new Ledger('test-parallel-writes', { public: true })
|
227
228
|
// /** @type {Doc} */
|
228
229
|
// for (let i = 0; i < 10; i++) {
|
229
230
|
// const doc = { _id: `id-${i}`, hello: 'world' }
|
@@ -232,7 +233,7 @@ describe("named Database with record", function () {
|
|
232
233
|
// await Promise.all(writes)
|
233
234
|
// })
|
234
235
|
|
235
|
-
describe("basic
|
236
|
+
describe("basic Ledger parallel writes / public ordered", () => {
|
236
237
|
let db: Database;
|
237
238
|
const writes: Promise<DocResponse>[] = [];
|
238
239
|
const sthis = mockSuperThis();
|
@@ -242,7 +243,7 @@ describe("basic Database parallel writes / public ordered", () => {
|
|
242
243
|
});
|
243
244
|
beforeEach(async () => {
|
244
245
|
await sthis.start();
|
245
|
-
db =
|
246
|
+
db = fireproof("test-parallel-writes-ordered", { writeQueue: { chunkSize: 1 } });
|
246
247
|
for (let i = 0; i < 10; i++) {
|
247
248
|
const doc = { _id: `id-${i}`, hello: "world" };
|
248
249
|
writes.push(db.put(doc));
|
@@ -251,13 +252,13 @@ describe("basic Database parallel writes / public ordered", () => {
|
|
251
252
|
});
|
252
253
|
|
253
254
|
it("should have one head", () => {
|
254
|
-
const crdt = db.crdt;
|
255
|
+
const crdt = db.ledger.crdt;
|
255
256
|
expect(crdt.clock.head.length).toBe(1);
|
256
257
|
});
|
257
258
|
|
258
259
|
it("has changes ordered", async function () {
|
259
260
|
const { rows, clock } = await db.changes([]);
|
260
|
-
expect(clock[0]).toBe(db.crdt.clock.head[0]);
|
261
|
+
expect(clock[0]).toBe(db.ledger.crdt.clock.head[0]);
|
261
262
|
expect(rows.length).toBe(10);
|
262
263
|
for (let i = 0; i < 10; i++) {
|
263
264
|
expect(rows[i].key).toBe("id-" + i);
|
@@ -266,7 +267,7 @@ describe("basic Database parallel writes / public ordered", () => {
|
|
266
267
|
});
|
267
268
|
});
|
268
269
|
|
269
|
-
describe("basic
|
270
|
+
describe("basic Ledger parallel writes / public", () => {
|
270
271
|
let db: Database;
|
271
272
|
const writes: Promise<DocResponse>[] = [];
|
272
273
|
const sthis = ensureSuperThis();
|
@@ -276,7 +277,7 @@ describe("basic Database parallel writes / public", () => {
|
|
276
277
|
});
|
277
278
|
beforeEach(async () => {
|
278
279
|
await sthis.start();
|
279
|
-
db =
|
280
|
+
db = fireproof("test-parallel-writes", { writeQueue: { chunkSize: 32 } });
|
280
281
|
for (let i = 0; i < 10; i++) {
|
281
282
|
const doc = { _id: `id-${i}`, hello: "world" };
|
282
283
|
writes.push(db.put(doc));
|
@@ -284,7 +285,7 @@ describe("basic Database parallel writes / public", () => {
|
|
284
285
|
await Promise.all(writes);
|
285
286
|
});
|
286
287
|
it("should resolve to one head", async () => {
|
287
|
-
const crdt = db.crdt;
|
288
|
+
const crdt = db.ledger.crdt;
|
288
289
|
expect(crdt.clock.head.length).toBe(9);
|
289
290
|
await db.put({ _id: "id-10", hello: "world" });
|
290
291
|
expect(crdt.clock.head.length).toBe(1);
|
@@ -323,7 +324,7 @@ describe("basic Database parallel writes / public", () => {
|
|
323
324
|
});
|
324
325
|
it("has changes not ordered", async function () {
|
325
326
|
const { rows, clock } = await db.changes([]);
|
326
|
-
expect(clock[0]).toBe(db.crdt.clock.head[0]);
|
327
|
+
expect(clock[0]).toBe(db.ledger.crdt.clock.head[0]);
|
327
328
|
expect(rows.length).toBe(10);
|
328
329
|
rows.sort((a, b) => a.key.localeCompare(b.key));
|
329
330
|
// console.log(rows);
|
@@ -337,7 +338,7 @@ describe("basic Database parallel writes / public", () => {
|
|
337
338
|
expect(rows.length).toBe(10);
|
338
339
|
// expect(db.opts.public).toBeTruthy();
|
339
340
|
// expect(db._crdt.opts.public).toBeTruthy();
|
340
|
-
const blocks = db.crdt.blockstore as bs.EncryptedBlockstore;
|
341
|
+
const blocks = db.ledger.crdt.blockstore as bs.EncryptedBlockstore;
|
341
342
|
const loader = blocks.loader;
|
342
343
|
expect(loader).toBeTruthy();
|
343
344
|
await loader.ready();
|
@@ -346,7 +347,7 @@ describe("basic Database parallel writes / public", () => {
|
|
346
347
|
});
|
347
348
|
});
|
348
349
|
|
349
|
-
describe("basic
|
350
|
+
describe("basic Ledger with subscription", function () {
|
350
351
|
let db: Database;
|
351
352
|
let didRun: number;
|
352
353
|
let unsubscribe: () => void;
|
@@ -359,7 +360,7 @@ describe("basic Database with subscription", function () {
|
|
359
360
|
});
|
360
361
|
beforeEach(async function () {
|
361
362
|
await sthis.start();
|
362
|
-
db =
|
363
|
+
db = fireproof("factory-name");
|
363
364
|
didRun = 0;
|
364
365
|
waitForSub = new Promise((resolve) => {
|
365
366
|
unsubscribe = db.subscribe((docs) => {
|
@@ -392,18 +393,17 @@ describe("basic Database with subscription", function () {
|
|
392
393
|
});
|
393
394
|
});
|
394
395
|
|
395
|
-
describe("basic
|
396
|
+
describe("basic Ledger with no update subscription", function () {
|
396
397
|
let db: Database;
|
397
398
|
let didRun: number;
|
398
399
|
let unsubscribe: () => void;
|
399
|
-
const sthis = ensureSuperThis();
|
400
|
+
// const sthis = ensureSuperThis();
|
400
401
|
afterEach(async () => {
|
401
402
|
await db.close();
|
402
403
|
await db.destroy();
|
403
404
|
});
|
404
405
|
beforeEach(async function () {
|
405
|
-
|
406
|
-
db = DatabaseFactory("factory-name");
|
406
|
+
db = fireproof("factory-name");
|
407
407
|
didRun = 0;
|
408
408
|
unsubscribe = db.subscribe(() => {
|
409
409
|
didRun++;
|
@@ -428,7 +428,7 @@ describe("basic Database with no update subscription", function () {
|
|
428
428
|
});
|
429
429
|
});
|
430
430
|
|
431
|
-
describe("
|
431
|
+
describe("ledger with files input", () => {
|
432
432
|
let db: Database;
|
433
433
|
let imagefiles: FileWithCid[] = [];
|
434
434
|
let result: DocResponse;
|
@@ -441,7 +441,7 @@ describe("database with files input", () => {
|
|
441
441
|
beforeEach(async function () {
|
442
442
|
await sthis.start();
|
443
443
|
imagefiles = await buildBlobFiles();
|
444
|
-
db =
|
444
|
+
db = fireproof("fireproof-with-images");
|
445
445
|
const doc = {
|
446
446
|
_id: "images-main",
|
447
447
|
type: "files",
|
@@ -532,6 +532,7 @@ describe("StoreURIRuntime", () => {
|
|
532
532
|
await sthis.start();
|
533
533
|
safeEnv = sthis.env.get("FP_STORAGE_URL");
|
534
534
|
sthis.env.set("FP_STORAGE_URL", "my://bla/storage");
|
535
|
+
// console.log(">>>>>>>>>>", bs, bs.registerStoreProtocol)
|
535
536
|
unreg = bs.registerStoreProtocol({
|
536
537
|
protocol: "murks",
|
537
538
|
isDefault: true,
|