@fireproof/core 0.19.8-dev-global → 0.19.8-dev-series-2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. package/README.md +34 -0
  2. package/chunk-7EWIAXTM.js +7 -0
  3. package/chunk-7EWIAXTM.js.map +1 -0
  4. package/chunk-OFGPKRCM.js +290 -0
  5. package/chunk-OFGPKRCM.js.map +1 -0
  6. package/chunk-PB4BKL4O.js +7 -0
  7. package/chunk-PB4BKL4O.js.map +1 -0
  8. package/chunk-WS3YRPIA.js +75 -0
  9. package/chunk-WS3YRPIA.js.map +1 -0
  10. package/deno.json +22 -0
  11. package/gateway-5FCWPX5W.js +144 -0
  12. package/gateway-5FCWPX5W.js.map +1 -0
  13. package/{store-indexdb-WLRSICCB.js → gateway-H7UD6TNB.js} +49 -82
  14. package/gateway-H7UD6TNB.js.map +1 -0
  15. package/index.cjs +2365 -1875
  16. package/index.cjs.map +1 -1
  17. package/index.d.cts +663 -535
  18. package/index.d.ts +663 -535
  19. package/index.global.js +26742 -20717
  20. package/index.global.js.map +1 -1
  21. package/index.js +1691 -1094
  22. package/index.js.map +1 -1
  23. package/key-bag-file-WADZBHYG.js +54 -0
  24. package/key-bag-file-WADZBHYG.js.map +1 -0
  25. package/key-bag-indexdb-PGVAI3FJ.js +50 -0
  26. package/key-bag-indexdb-PGVAI3FJ.js.map +1 -0
  27. package/mem-filesystem-YPPJV7Q2.js +41 -0
  28. package/mem-filesystem-YPPJV7Q2.js.map +1 -0
  29. package/metafile-cjs.json +1 -1
  30. package/metafile-esm.json +1 -1
  31. package/metafile-iife.json +1 -1
  32. package/node-filesystem-INX4ZTHE.js +45 -0
  33. package/node-filesystem-INX4ZTHE.js.map +1 -0
  34. package/package.json +14 -8
  35. package/tests/blockstore/fragment-gateway.test.ts +107 -0
  36. package/tests/blockstore/keyed-crypto.test.ts +332 -0
  37. package/tests/blockstore/loader.test.ts +24 -19
  38. package/tests/blockstore/store.test.ts +51 -40
  39. package/tests/blockstore/transaction.test.ts +19 -15
  40. package/tests/fireproof/all-gateway.test.ts +394 -0
  41. package/tests/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.car +0 -0
  42. package/tests/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.ts +316 -0
  43. package/tests/fireproof/config.test.ts +94 -78
  44. package/tests/fireproof/crdt.test.ts +34 -28
  45. package/tests/fireproof/database.test.ts +22 -14
  46. package/tests/fireproof/fireproof.test.fixture.ts +133 -0
  47. package/tests/fireproof/fireproof.test.ts +331 -219
  48. package/tests/fireproof/hello.test.ts +34 -18
  49. package/tests/fireproof/indexer.test.ts +34 -27
  50. package/tests/fireproof/utils.test.ts +84 -0
  51. package/tests/helpers.ts +28 -57
  52. package/tests/www/todo-local.html +1 -1
  53. package/tests/www/todo.html +12 -15
  54. package/utils-QO2HIWGI.js +14 -0
  55. package/utils-QO2HIWGI.js.map +1 -0
  56. package/chunk-BNL4PVBF.js +0 -314
  57. package/chunk-BNL4PVBF.js.map +0 -1
  58. package/chunk-JW2QT6BF.js +0 -184
  59. package/chunk-JW2QT6BF.js.map +0 -1
  60. package/node-sys-container-MIEX6ELJ.js +0 -29
  61. package/node-sys-container-MIEX6ELJ.js.map +0 -1
  62. package/store-file-VJ6BI4II.js +0 -191
  63. package/store-file-VJ6BI4II.js.map +0 -1
  64. package/store-indexdb-WLRSICCB.js.map +0 -1
@@ -1,21 +1,19 @@
1
- import { itSkip } from "../helpers.js";
2
-
3
- import { uuidv4 } from "uuidv7";
4
-
5
1
  import { CRDT } from "@fireproof/core";
6
- import { bs, rt } from "@fireproof/core";
2
+ import { bs } from "@fireproof/core";
7
3
  import { CRDTMeta, DocValue } from "@fireproof/core";
8
4
  import { Index, index } from "@fireproof/core";
5
+ import { mockSuperThis } from "../helpers";
9
6
 
10
7
  describe("Fresh crdt", function () {
11
8
  let crdt: CRDT<{ hello: string } | { points: number }>;
9
+ const sthis = mockSuperThis();
12
10
  afterEach(async function () {
13
11
  await crdt.close();
14
12
  await crdt.destroy();
15
13
  });
16
14
  beforeEach(async function () {
17
- await rt.SysContainer.start();
18
- crdt = new CRDT();
15
+ await sthis.start();
16
+ crdt = new CRDT(sthis);
19
17
  });
20
18
  it("should have an empty head", async function () {
21
19
  const head = crdt.clock.head;
@@ -43,6 +41,7 @@ describe("CRDT with one record", function () {
43
41
  }
44
42
  let crdt: CRDT<Partial<CRDTTestType>>;
45
43
  let firstPut: CRDTMeta;
44
+ const sthis = mockSuperThis();
46
45
 
47
46
  afterEach(async function () {
48
47
  await crdt.close();
@@ -50,8 +49,8 @@ describe("CRDT with one record", function () {
50
49
  });
51
50
 
52
51
  beforeEach(async function () {
53
- await rt.SysContainer.start();
54
- crdt = new CRDT(`test@${uuidv4()}`);
52
+ await sthis.start();
53
+ crdt = new CRDT(sthis, `test@${sthis.nextId()}`);
55
54
  firstPut = await crdt.bulk([{ id: "hello", value: { hello: "world" } }]);
56
55
  });
57
56
  it("should have a one-element head", async function () {
@@ -93,14 +92,15 @@ describe("CRDT with a multi-write", function () {
93
92
  }
94
93
  let crdt: CRDT<CRDTTestType>;
95
94
  let firstPut: CRDTMeta;
95
+ const sthis = mockSuperThis();
96
96
 
97
97
  afterEach(async function () {
98
98
  await crdt.close();
99
99
  await crdt.destroy();
100
100
  });
101
101
  beforeEach(async function () {
102
- await rt.SysContainer.start();
103
- crdt = new CRDT();
102
+ await sthis.start();
103
+ crdt = new CRDT(sthis);
104
104
  firstPut = await crdt.bulk([
105
105
  { id: "ace", value: { points: 11 } },
106
106
  { id: "king", value: { points: 10 } },
@@ -158,13 +158,14 @@ describe("CRDT with two multi-writes", function () {
158
158
  let crdt: CRDT<CRDTTestType>;
159
159
  let firstPut: CRDTMeta;
160
160
  let secondPut: CRDTMeta;
161
+ const sthis = mockSuperThis();
161
162
  afterEach(async function () {
162
163
  await crdt.close();
163
164
  await crdt.destroy();
164
165
  });
165
166
  beforeEach(async () => {
166
- await rt.SysContainer.start();
167
- crdt = new CRDT();
167
+ await sthis.start();
168
+ crdt = new CRDT(sthis);
168
169
  firstPut = await crdt.bulk([
169
170
  { id: "ace", value: { points: 11 } },
170
171
  { id: "king", value: { points: 10 } },
@@ -205,13 +206,14 @@ describe("CRDT with two multi-writes", function () {
205
206
 
206
207
  describe("Compact a named CRDT with writes", function () {
207
208
  let crdt: CRDT<CRDTTestType>;
209
+ const sthis = mockSuperThis();
208
210
  afterEach(async function () {
209
211
  await crdt.close();
210
212
  await crdt.destroy();
211
213
  });
212
214
  beforeEach(async function () {
213
- await rt.SysContainer.start();
214
- crdt = new CRDT("named-crdt-compaction");
215
+ await sthis.start();
216
+ crdt = new CRDT(sthis, "named-crdt-compaction");
215
217
  for (let i = 0; i < 10; i++) {
216
218
  const bulk = [
217
219
  { id: "ace", value: { points: 11 } },
@@ -237,7 +239,7 @@ describe("Compact a named CRDT with writes", function () {
237
239
  expect(result.length).toBe(2);
238
240
  expect(result[0].id).toBe("ace");
239
241
  });
240
- itSkip("should have fewer blocks after compact", async function () {
242
+ it.skip("should have fewer blocks after compact", async function () {
241
243
  await crdt.compact();
242
244
  const blz: bs.AnyBlock[] = [];
243
245
  for await (const blk of crdt.blockstore.entries()) {
@@ -260,18 +262,19 @@ describe("Compact a named CRDT with writes", function () {
260
262
  describe("CRDT with an index", function () {
261
263
  let crdt: CRDT<CRDTTestType>;
262
264
  let idx: Index<number, CRDTTestType>;
265
+ const sthis = mockSuperThis();
263
266
  afterEach(async function () {
264
267
  await crdt.close();
265
268
  await crdt.destroy();
266
269
  });
267
270
  beforeEach(async function () {
268
- await rt.SysContainer.start();
269
- crdt = new CRDT<CRDTTestType>();
271
+ await sthis.start();
272
+ crdt = new CRDT<CRDTTestType>(sthis);
270
273
  await crdt.bulk([
271
274
  { id: "ace", value: { points: 11 } },
272
275
  { id: "king", value: { points: 10 } },
273
276
  ]);
274
- idx = await index<number, CRDTTestType>({ _crdt: crdt }, "points");
277
+ idx = await index<number, CRDTTestType>(sthis, { _crdt: crdt }, "points");
275
278
  });
276
279
  it("should query the data", async function () {
277
280
  const got = await idx.query({ range: [9, 12] });
@@ -280,7 +283,7 @@ describe("CRDT with an index", function () {
280
283
  expect(got.rows[0].key).toBe(10);
281
284
  });
282
285
  it("should register the index", async function () {
283
- const rIdx = await index<number, CRDTTestType>({ _crdt: crdt }, "points");
286
+ const rIdx = await index<number, CRDTTestType>(sthis, { _crdt: crdt }, "points");
284
287
  expect(rIdx).toBeTruthy();
285
288
  expect(rIdx.name).toBe("points");
286
289
  const got = await rIdx.query({ range: [9, 12] });
@@ -289,7 +292,7 @@ describe("CRDT with an index", function () {
289
292
  expect(got.rows[0].key).toBe(10);
290
293
  });
291
294
  it("creating a different index with same name should not work", async function () {
292
- const e = await index({ _crdt: crdt }, "points", (doc) => doc._id)
295
+ const e = await index(sthis, { _crdt: crdt }, "points", (doc) => doc._id)
293
296
  .query()
294
297
  .catch((err) => err);
295
298
  expect(e.message).toMatch(/cannot apply/);
@@ -305,13 +308,14 @@ describe("Loader with a committed transaction", function () {
305
308
  let crdt: CRDT<CRDTTestType>;
306
309
  let done: CRDTMeta;
307
310
  const dbname = "test-loader";
311
+ const sthis = mockSuperThis();
308
312
  afterEach(async function () {
309
313
  await crdt.close();
310
314
  await crdt.destroy();
311
315
  });
312
316
  beforeEach(async function () {
313
- await rt.SysContainer.start();
314
- crdt = new CRDT(dbname);
317
+ await sthis.start();
318
+ crdt = new CRDT(sthis, dbname);
315
319
  blockstore = crdt.blockstore as bs.EncryptedBlockstore;
316
320
  expect(blockstore.loader).toBeTruthy();
317
321
  loader = blockstore.loader;
@@ -325,7 +329,7 @@ describe("Loader with a committed transaction", function () {
325
329
  // expect(done.cars).toBeTruthy();
326
330
  expect(loader.carLog.length).toBe(1);
327
331
  });
328
- it("can load the car", async function () {
332
+ it("can load the car", async () => {
329
333
  const blk = loader.carLog[0][0];
330
334
  expect(blk).toBeTruthy();
331
335
  const reader = await loader.loadCar(blk);
@@ -347,13 +351,14 @@ describe("Loader with two committed transactions", function () {
347
351
  let blockstore: bs.EncryptedBlockstore;
348
352
  let done1: CRDTMeta;
349
353
  let done2: CRDTMeta;
354
+ const sthis = mockSuperThis();
350
355
  afterEach(async function () {
351
356
  await crdt.close();
352
357
  await crdt.destroy();
353
358
  });
354
359
  beforeEach(async function () {
355
- await rt.SysContainer.start();
356
- crdt = new CRDT("test-loader");
360
+ await sthis.start();
361
+ crdt = new CRDT(sthis, "test-loader");
357
362
  blockstore = crdt.blockstore as bs.EncryptedBlockstore;
358
363
  expect(blockstore.loader).toBeTruthy();
359
364
  loader = blockstore.loader;
@@ -396,13 +401,14 @@ describe("Loader with many committed transactions", function () {
396
401
  let crdt: CRDT<Doc>;
397
402
  let dones: CRDTMeta[];
398
403
  const count = 10;
404
+ const sthis = mockSuperThis();
399
405
  afterEach(async function () {
400
406
  await crdt.close();
401
407
  await crdt.destroy();
402
408
  });
403
409
  beforeEach(async function () {
404
- await rt.SysContainer.start();
405
- crdt = new CRDT("test-loader-many");
410
+ await sthis.start();
411
+ crdt = new CRDT(sthis, "test-loader-many");
406
412
  blockstore = crdt.blockstore as bs.EncryptedBlockstore;
407
413
  expect(blockstore.loader).toBeTruthy();
408
414
  loader = blockstore.loader;
@@ -1,14 +1,15 @@
1
- import { buildBlobFiles, FileWithCid } from "../helpers.js";
2
- import { rt, bs, Database, DocResponse, DocFileMeta, DocWithId, DocFiles } from "@fireproof/core";
1
+ import { buildBlobFiles, FileWithCid, mockSuperThis } from "../helpers.js";
2
+ import { bs, Database, DocResponse, DocFileMeta, DocWithId, DocFiles } from "@fireproof/core";
3
3
 
4
4
  describe("basic Database", () => {
5
5
  let db: Database;
6
+ const sthis = mockSuperThis();
6
7
  afterEach(async () => {
7
8
  await db.close();
8
9
  await db.destroy();
9
10
  });
10
11
  beforeEach(async () => {
11
- await rt.SysContainer.start();
12
+ await sthis.start();
12
13
  db = new Database();
13
14
  });
14
15
  it("should put", async () => {
@@ -38,12 +39,13 @@ describe("basic Database with record", function () {
38
39
  readonly value: string;
39
40
  }
40
41
  let db: Database;
42
+ const sthis = mockSuperThis();
41
43
  afterEach(async () => {
42
44
  await db.close();
43
45
  await db.destroy();
44
46
  });
45
47
  beforeEach(async function () {
46
- await rt.SysContainer.start();
48
+ await sthis.start();
47
49
  db = new Database();
48
50
  const ok = await db.put<Doc>({ _id: "hello", value: "world" });
49
51
  expect(ok.id).toBe("hello");
@@ -91,12 +93,13 @@ describe("named Database with record", function () {
91
93
  readonly value: string;
92
94
  }
93
95
  let db: Database;
96
+ const sthis = mockSuperThis();
94
97
  afterEach(async () => {
95
98
  await db.close();
96
99
  await db.destroy();
97
100
  });
98
101
  beforeEach(async function () {
99
- await rt.SysContainer.start();
102
+ await sthis.start();
100
103
  db = new Database("test-db-name");
101
104
  /** @type {Doc} */
102
105
  const doc = { _id: "hello", value: "world" };
@@ -137,9 +140,10 @@ describe("named Database with record", function () {
137
140
  const loader = blocks.loader;
138
141
  expect(loader).toBeTruthy();
139
142
  await loader.ready();
140
- expect(loader.key?.length).toBe(64);
141
- expect(loader.keyId?.length).toBe(64);
142
- expect(loader.key).not.toBe(loader.keyId);
143
+
144
+ // expect(loader.key?.length).toBe(64);
145
+ // expect(loader.keyId?.length).toBe(64);
146
+ // expect(loader.key).not.toBe(loader.keyId);
143
147
  });
144
148
  it("should work right with a sequence of changes", async function () {
145
149
  const numDocs = 10;
@@ -216,12 +220,13 @@ describe("named Database with record", function () {
216
220
  describe("basic Database parallel writes / public", function () {
217
221
  let db: Database;
218
222
  const writes: Promise<DocResponse>[] = [];
223
+ const sthis = mockSuperThis();
219
224
  afterEach(async () => {
220
225
  await db.close();
221
226
  await db.destroy();
222
227
  });
223
228
  beforeEach(async function () {
224
- await rt.SysContainer.start();
229
+ await sthis.start();
225
230
  db = new Database("test-parallel-writes", { public: true });
226
231
  for (let i = 0; i < 10; i++) {
227
232
  const doc = { _id: `id-${i}`, hello: "world" };
@@ -284,8 +289,8 @@ describe("basic Database parallel writes / public", function () {
284
289
  const loader = blocks.loader;
285
290
  expect(loader).toBeTruthy();
286
291
  await loader.ready();
287
- expect(loader.key).toBeUndefined();
288
- expect(loader.keyId).toBeUndefined();
292
+ // expect(loader.key).toBeUndefined();
293
+ // expect(loader.keyId).toBeUndefined();
289
294
  });
290
295
  });
291
296
 
@@ -295,12 +300,13 @@ describe("basic Database with subscription", function () {
295
300
  let unsubscribe: () => void;
296
301
  let lastDoc: DocWithId<NonNullable<unknown>>;
297
302
  let waitForSub: Promise<void>;
303
+ const sthis = mockSuperThis();
298
304
  afterEach(async () => {
299
305
  await db.close();
300
306
  await db.destroy();
301
307
  });
302
308
  beforeEach(async function () {
303
- await rt.SysContainer.start();
309
+ await sthis.start();
304
310
  db = new Database();
305
311
  didRun = 0;
306
312
  waitForSub = new Promise((resolve) => {
@@ -338,12 +344,13 @@ describe("basic Database with no update subscription", function () {
338
344
  let db: Database;
339
345
  let didRun: number;
340
346
  let unsubscribe: () => void;
347
+ const sthis = mockSuperThis();
341
348
  afterEach(async () => {
342
349
  await db.close();
343
350
  await db.destroy();
344
351
  });
345
352
  beforeEach(async function () {
346
- await rt.SysContainer.start();
353
+ await sthis.start();
347
354
  db = new Database();
348
355
  didRun = 0;
349
356
 
@@ -374,13 +381,14 @@ describe("database with files input", () => {
374
381
  let db: Database;
375
382
  let imagefiles: FileWithCid[] = [];
376
383
  let result: DocResponse;
384
+ const sthis = mockSuperThis();
377
385
 
378
386
  afterEach(async () => {
379
387
  await db.close();
380
388
  await db.destroy();
381
389
  });
382
390
  beforeEach(async function () {
383
- await rt.SysContainer.start();
391
+ await sthis.start();
384
392
  imagefiles = await buildBlobFiles();
385
393
  db = new Database("fireproof-with-images");
386
394
  const doc = {
@@ -0,0 +1,133 @@
1
+ export const docs = [
2
+ {
3
+ _id: "02pkji8",
4
+ type: "todo",
5
+ title: "On the browser",
6
+ listId: "0k23ulso",
7
+ completed: false,
8
+ createdAt: "2024-06-30T15:15:01.482Z",
9
+ },
10
+ { _id: "0k23ulso", type: "list", title: "Building Apps" },
11
+ { _id: "1ctdt28g", type: "list", title: "Having Fun" },
12
+ { _id: "294n3m2o", type: "list", title: "Getting Groceries" },
13
+ {
14
+ _id: "63eheg8",
15
+ type: "todo",
16
+ title: "Macadamia nut milk",
17
+ listId: "294n3m2o",
18
+ completed: false,
19
+ createdAt: "2024-06-30T15:15:03.282Z",
20
+ },
21
+ {
22
+ _id: "65e459g",
23
+ type: "todo",
24
+ title: "Fruit salad",
25
+ listId: "294n3m2o",
26
+ completed: false,
27
+ createdAt: "2024-06-30T15:15:04.144Z",
28
+ },
29
+ {
30
+ _id: "6icqlvg",
31
+ type: "todo",
32
+ title: "Bacon",
33
+ listId: "294n3m2o",
34
+ completed: false,
35
+ createdAt: "2024-06-30T15:15:05.282Z",
36
+ },
37
+ {
38
+ _id: "7terjo",
39
+ type: "todo",
40
+ title: "Rollerskating meetup",
41
+ listId: "1ctdt28g",
42
+ completed: false,
43
+ createdAt: "2024-06-30T15:15:06.282Z",
44
+ },
45
+ {
46
+ _id: "8vr6cc",
47
+ type: "todo",
48
+ title: "With or without Redux",
49
+ listId: "0k23ulso",
50
+ completed: false,
51
+ createdAt: "2024-06-30T15:15:07.282Z",
52
+ },
53
+ {
54
+ _id: "ck2sb08",
55
+ type: "todo",
56
+ title: "Write a sci-fi story with ChatGPT",
57
+ listId: "1ctdt28g",
58
+ completed: true,
59
+ createdAt: "2024-06-30T15:15:08.282Z",
60
+ },
61
+ {
62
+ _id: "dlkeeoo",
63
+ type: "todo",
64
+ title: "Avocado toast",
65
+ listId: "294n3m2o",
66
+ completed: false,
67
+ createdAt: "2024-06-30T15:15:09.282Z",
68
+ },
69
+ {
70
+ _id: "f9i8tx7nxswo",
71
+ type: "todo",
72
+ title: "nice",
73
+ listId: "0k23ulso",
74
+ completed: true,
75
+ createdAt: "2024-06-30T15:15:01.482Z",
76
+ },
77
+ {
78
+ _id: "fkgjmbg",
79
+ type: "todo",
80
+ title: "Automatic replication and versioning",
81
+ listId: "0k23ulso",
82
+ completed: true,
83
+ createdAt: "2024-06-30T15:15:10.282Z",
84
+ },
85
+ {
86
+ _id: "fks8hig",
87
+ type: "todo",
88
+ title: "Motorcycle ride",
89
+ listId: "1ctdt28g",
90
+ completed: false,
91
+ createdAt: "2024-06-30T15:15:11.282Z",
92
+ },
93
+ {
94
+ _id: "hf60rf",
95
+ type: "todo",
96
+ title: "Sourdough bread",
97
+ listId: "294n3m2o",
98
+ completed: true,
99
+ createdAt: "2024-06-30T15:15:12.282Z",
100
+ },
101
+ {
102
+ _id: "n219un",
103
+ type: "todo",
104
+ title: "Login components",
105
+ listId: "0k23ulso",
106
+ completed: true,
107
+ createdAt: "2024-06-30T15:15:13.282Z",
108
+ },
109
+ {
110
+ _id: "phr936g",
111
+ type: "todo",
112
+ title: "Coffee",
113
+ listId: "294n3m2o",
114
+ completed: false,
115
+ createdAt: "2024-06-30T15:15:14.282Z",
116
+ },
117
+ {
118
+ _id: "vcj2fv8",
119
+ type: "todo",
120
+ title: "On the phone",
121
+ listId: "0k23ulso",
122
+ completed: false,
123
+ createdAt: "2024-06-30T15:15:15.282Z",
124
+ },
125
+ {
126
+ _id: "vqmbes8",
127
+ type: "todo",
128
+ title: "GraphQL queries",
129
+ listId: "0k23ulso",
130
+ completed: false,
131
+ createdAt: "2024-06-30T15:15:16.282Z",
132
+ },
133
+ ];