@fireproof/core 0.19.121-dev → 0.20.0-dev-preview-05

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.
Files changed (103) hide show
  1. package/README.md +13 -12
  2. package/deno/index.d.ts +7 -0
  3. package/deno/index.js +66 -0
  4. package/deno/index.js.map +1 -0
  5. package/deno/metafile-esm.json +1 -0
  6. package/deno.json +3 -4
  7. package/index.cjs +1797 -1431
  8. package/index.cjs.map +1 -1
  9. package/index.d.cts +760 -381
  10. package/index.d.ts +760 -381
  11. package/index.js +1976 -913
  12. package/index.js.map +1 -1
  13. package/metafile-cjs.json +1 -1
  14. package/metafile-esm.json +1 -1
  15. package/node/{node-filesystem.cjs → index.cjs} +17 -6
  16. package/node/index.cjs.map +1 -0
  17. package/node/index.d.cts +7 -0
  18. package/node/index.d.ts +7 -0
  19. package/node/{node-filesystem.js → index.js} +25 -5
  20. package/node/index.js.map +1 -0
  21. package/node/metafile-cjs.json +1 -1
  22. package/node/metafile-esm.json +1 -1
  23. package/package.json +27 -17
  24. package/react/index.cjs +22 -22
  25. package/react/index.cjs.map +1 -1
  26. package/react/index.d.cts +7 -7
  27. package/react/index.d.ts +7 -7
  28. package/react/index.js +22 -22
  29. package/react/index.js.map +1 -1
  30. package/react/metafile-cjs.json +1 -1
  31. package/react/metafile-esm.json +1 -1
  32. package/tests/blockstore/fp-envelope.test.ts-off +65 -0
  33. package/tests/blockstore/interceptor-gateway.test.ts +122 -0
  34. package/tests/blockstore/keyed-crypto-indexdb-file.test.ts +130 -0
  35. package/tests/blockstore/keyed-crypto.test.ts +75 -118
  36. package/tests/blockstore/loader.test.ts +18 -9
  37. package/tests/blockstore/store.test.ts +40 -31
  38. package/tests/blockstore/transaction.test.ts +14 -13
  39. package/tests/fireproof/all-gateway.test.ts +286 -216
  40. package/tests/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.ts +324 -316
  41. package/tests/fireproof/crdt.test.ts +78 -19
  42. package/tests/fireproof/fireproof.test.ts +111 -92
  43. package/tests/fireproof/hello.test.ts +21 -17
  44. package/tests/fireproof/indexer.test.ts +74 -50
  45. package/tests/fireproof/{database.test.ts → ledger.test.ts} +241 -45
  46. package/tests/fireproof/multiple-ledger.test.ts +2 -2
  47. package/tests/fireproof/utils.test.ts +47 -6
  48. package/tests/gateway/file/loader-config.test.ts +307 -0
  49. package/tests/gateway/fp-envelope-serialize.test.ts +256 -0
  50. package/tests/gateway/indexdb/loader-config.test.ts +79 -0
  51. package/tests/helpers.ts +44 -17
  52. package/tests/react/useFireproof.test.tsx +2 -2
  53. package/tests/www/gallery.html +2 -2
  54. package/tests/www/todo-aws.html +1 -1
  55. package/tests/www/todo-ipfs.html +1 -1
  56. package/tests/www/todo-local.html +1 -1
  57. package/tests/www/todo.html +25 -4
  58. package/web/index.cjs +218 -0
  59. package/web/index.cjs.map +1 -0
  60. package/web/index.d.cts +30 -0
  61. package/web/index.d.ts +30 -0
  62. package/web/index.js +195 -0
  63. package/web/index.js.map +1 -0
  64. package/web/metafile-cjs.json +1 -1
  65. package/web/metafile-esm.json +1 -1
  66. package/chunk-7EWIAXTM.js +0 -7
  67. package/chunk-7EWIAXTM.js.map +0 -1
  68. package/chunk-F4FC6B2T.js +0 -63
  69. package/chunk-F4FC6B2T.js.map +0 -1
  70. package/chunk-PZ5AY32C.js +0 -10
  71. package/chunk-PZ5AY32C.js.map +0 -1
  72. package/chunk-RXC4JGJT.js +0 -301
  73. package/chunk-RXC4JGJT.js.map +0 -1
  74. package/gateway-C62S56GY.js +0 -66
  75. package/gateway-C62S56GY.js.map +0 -1
  76. package/gateway-VVS4QWDA.js +0 -145
  77. package/gateway-VVS4QWDA.js.map +0 -1
  78. package/key-bag-file-PWZ3QE7B.js +0 -55
  79. package/key-bag-file-PWZ3QE7B.js.map +0 -1
  80. package/key-bag-indexdb-SYG3YD4D.js +0 -51
  81. package/key-bag-indexdb-SYG3YD4D.js.map +0 -1
  82. package/node/chunk-4A4RAVNS.js +0 -17
  83. package/node/chunk-4A4RAVNS.js.map +0 -1
  84. package/node/mem-filesystem.cjs +0 -72
  85. package/node/mem-filesystem.cjs.map +0 -1
  86. package/node/mem-filesystem.d.cts +0 -25
  87. package/node/mem-filesystem.d.ts +0 -25
  88. package/node/mem-filesystem.js +0 -40
  89. package/node/mem-filesystem.js.map +0 -1
  90. package/node/node-filesystem.cjs.map +0 -1
  91. package/node/node-filesystem.d.cts +0 -35
  92. package/node/node-filesystem.d.ts +0 -35
  93. package/node/node-filesystem.js.map +0 -1
  94. package/tests/fireproof/config.test.ts +0 -172
  95. package/utils-ZVVGAXFE.js +0 -13
  96. package/utils-ZVVGAXFE.js.map +0 -1
  97. package/web/gateway-impl.cjs +0 -183
  98. package/web/gateway-impl.cjs.map +0 -1
  99. package/web/gateway-impl.d.cts +0 -31
  100. package/web/gateway-impl.d.ts +0 -31
  101. package/web/gateway-impl.js +0 -162
  102. package/web/gateway-impl.js.map +0 -1
  103. /package/tests/blockstore/{fragment-gateway.test.ts → fragment-gateway.test.ts-off} +0 -0
@@ -1,4 +1,17 @@
1
- import { Index, index, Database, CRDT, IndexRows, ensureSuperThis } from "@fireproof/core";
1
+ import {
2
+ Index,
3
+ index,
4
+ Ledger,
5
+ CRDT,
6
+ IndexRows,
7
+ toStoreURIRuntime,
8
+ bs,
9
+ rt,
10
+ LedgerFactory,
11
+ defaultWriteQueueOpts,
12
+ ensureSuperThis,
13
+ LedgerOpts,
14
+ } from "@fireproof/core";
2
15
 
3
16
  interface TestType {
4
17
  readonly title: string;
@@ -6,31 +19,31 @@ interface TestType {
6
19
  }
7
20
 
8
21
  describe("basic Index", () => {
9
- let db: Database<TestType>;
22
+ let db: Ledger<TestType>;
10
23
  let indexer: Index<string, TestType>;
11
24
  let didMap: boolean;
12
25
  const sthis = ensureSuperThis();
13
26
  afterEach(async function () {
14
27
  await db.close();
15
28
  await db.destroy();
16
- await indexer.close();
17
- await indexer.destroy();
29
+ // await indexer.close();
30
+ // await indexer.destroy();
18
31
  });
19
32
  beforeEach(async function () {
20
33
  await sthis.start();
21
- db = new Database("test-indexer");
34
+ db = LedgerFactory("test-indexer");
22
35
  await db.put({ title: "amazing" });
23
36
  await db.put({ title: "creative" });
24
37
  await db.put({ title: "bazillas" });
25
- indexer = new Index<string, TestType>(sthis, db._crdt, "hello", (doc) => {
38
+ indexer = new Index<string, TestType>(sthis, db.crdt, "hello", (doc) => {
26
39
  didMap = true;
27
40
  return doc.title;
28
41
  });
29
42
  await indexer.ready();
30
43
  });
31
44
  it("should have properties", function () {
32
- expect(indexer.crdt).toBe(db._crdt);
33
- expect(indexer.crdt.name).toBe("test-indexer");
45
+ expect(indexer.crdt).toBe(db.crdt);
46
+ // expect(indexer.crdt.name).toBe("test-indexer");
34
47
  expect(indexer.name).toBe("hello");
35
48
  expect(indexer.mapFn).toBeTruthy();
36
49
  });
@@ -94,23 +107,23 @@ describe("basic Index", () => {
94
107
  });
95
108
 
96
109
  describe("Index query with compound key", function () {
97
- let db: Database<TestType>;
110
+ let db: Ledger<TestType>;
98
111
  let indexer: Index<[string, number], TestType>;
99
112
  const sthis = ensureSuperThis();
100
113
  afterEach(async function () {
101
114
  await db.close();
102
115
  await db.destroy();
103
- await indexer.close();
104
- await indexer.destroy();
116
+ // await indexer.close();
117
+ // await indexer.destroy();
105
118
  });
106
119
  beforeEach(async function () {
107
120
  await sthis.start();
108
- db = new Database("test-indexer");
121
+ db = LedgerFactory("test-indexer");
109
122
  await db.put({ title: "amazing", score: 1 });
110
123
  await db.put({ title: "creative", score: 2 });
111
124
  await db.put({ title: "creative", score: 20 });
112
125
  await db.put({ title: "bazillas", score: 3 });
113
- indexer = new Index<[string, number], TestType>(sthis, db._crdt, "hello", (doc) => {
126
+ indexer = new Index<[string, number], TestType>(sthis, db.crdt, "hello", (doc) => {
114
127
  return [doc.title, doc.score];
115
128
  });
116
129
  await indexer.ready();
@@ -124,22 +137,22 @@ describe("Index query with compound key", function () {
124
137
  });
125
138
 
126
139
  describe("basic Index with map fun", function () {
127
- let db: Database<TestType>;
140
+ let db: Ledger<TestType>;
128
141
  let indexer: Index<string, TestType>;
129
142
  const sthis = ensureSuperThis();
130
143
  afterEach(async function () {
131
144
  await db.close();
132
145
  await db.destroy();
133
- await indexer.close();
134
- await indexer.destroy();
146
+ // await indexer.close();
147
+ // await indexer.destroy();
135
148
  });
136
149
  beforeEach(async function () {
137
150
  await sthis.start();
138
- db = new Database("test-indexer");
151
+ db = LedgerFactory("test-indexer");
139
152
  await db.put({ title: "amazing" });
140
153
  await db.put({ title: "creative" });
141
154
  await db.put({ title: "bazillas" });
142
- indexer = new Index<string, TestType>(sthis, db._crdt, "hello", (doc, map) => {
155
+ indexer = new Index<string, TestType>(sthis, db.crdt, "hello", (doc, map) => {
143
156
  map(doc.title);
144
157
  });
145
158
  await indexer.ready();
@@ -154,7 +167,7 @@ describe("basic Index with map fun", function () {
154
167
  });
155
168
 
156
169
  describe("basic Index with map fun with value", function () {
157
- let db: Database<TestType>;
170
+ let db: Ledger<TestType>;
158
171
  let indexer: Index<string, TestType, number>;
159
172
  const sthis = ensureSuperThis();
160
173
  afterEach(async function () {
@@ -163,11 +176,11 @@ describe("basic Index with map fun with value", function () {
163
176
  });
164
177
  beforeEach(async function () {
165
178
  await sthis.start();
166
- db = new Database("test-indexer");
179
+ db = LedgerFactory("test-indexer");
167
180
  await db.put({ title: "amazing" });
168
181
  await db.put({ title: "creative" });
169
182
  await db.put({ title: "bazillas" });
170
- indexer = new Index<string, TestType, number>(sthis, db._crdt, "hello", (doc, map) => {
183
+ indexer = new Index<string, TestType, number>(sthis, db.crdt, "hello", (doc, map) => {
171
184
  map(doc.title, doc.title.length);
172
185
  });
173
186
  });
@@ -192,23 +205,23 @@ describe("basic Index with map fun with value", function () {
192
205
  });
193
206
 
194
207
  describe("Index query with map and compound key", function () {
195
- let db: Database<TestType>;
208
+ let db: Ledger<TestType>;
196
209
  let indexer: Index<[string, number], TestType>;
197
210
  const sthis = ensureSuperThis();
198
211
  afterEach(async function () {
199
212
  await db.close();
200
213
  await db.destroy();
201
- await indexer.close();
202
- await indexer.destroy();
214
+ // await indexer.close();
215
+ // await indexer.destroy();
203
216
  });
204
217
  beforeEach(async function () {
205
218
  await sthis.start();
206
- db = new Database("test-indexer");
219
+ db = LedgerFactory("test-indexer");
207
220
  await db.put({ title: "amazing", score: 1 });
208
221
  await db.put({ title: "creative", score: 2 });
209
222
  await db.put({ title: "creative", score: 20 });
210
223
  await db.put({ title: "bazillas", score: 3 });
211
- indexer = new Index<[string, number], TestType>(sthis, db._crdt, "hello", (doc, emit) => {
224
+ indexer = new Index<[string, number], TestType>(sthis, db.crdt, "hello", (doc, emit) => {
212
225
  emit([doc.title, doc.score]);
213
226
  });
214
227
  await indexer.ready();
@@ -222,22 +235,22 @@ describe("Index query with map and compound key", function () {
222
235
  });
223
236
 
224
237
  describe("basic Index with string fun", function () {
225
- let db: Database<TestType>;
238
+ let db: Ledger<TestType>;
226
239
  let indexer: Index<string, TestType>;
227
240
  const sthis = ensureSuperThis();
228
241
  afterEach(async function () {
229
242
  await db.close();
230
243
  await db.destroy();
231
- await indexer.close();
232
- await indexer.destroy();
244
+ // await indexer.close();
245
+ // await indexer.destroy();
233
246
  });
234
247
  beforeEach(async function () {
235
248
  await sthis.start();
236
- db = new Database("test-indexer");
249
+ db = LedgerFactory("test-indexer");
237
250
  await db.put({ title: "amazing" });
238
251
  await db.put({ title: "creative" });
239
252
  await db.put({ title: "bazillas" });
240
- indexer = new Index(sthis, db._crdt, "title");
253
+ indexer = new Index(sthis, db.crdt, "title");
241
254
  await indexer.ready();
242
255
  });
243
256
  it("should get results", async function () {
@@ -264,31 +277,44 @@ describe("basic Index upon cold start", function () {
264
277
  let mapFn: (doc: TestType) => string;
265
278
  let result: IndexRows<string, TestType>;
266
279
  const sthis = ensureSuperThis();
280
+ let dbOpts: LedgerOpts;
267
281
  // result, mapFn;
268
282
  afterEach(async function () {
269
283
  await crdt.close();
270
284
  await crdt.destroy();
271
- await indexer.close();
272
- await indexer.destroy();
285
+ // await indexer.close();
286
+ // await indexer.destroy();
273
287
  });
274
288
  beforeEach(async function () {
275
289
  await sthis.start();
276
- // db = database()
277
- crdt = new CRDT<TestType>(sthis, "test-indexer-cold", { persistIndexes: true });
290
+ const logger = sthis.logger.With().Module("IndexerTest").Logger();
291
+ logger.Debug().Msg("enter beforeEach");
292
+ dbOpts = {
293
+ writeQueue: defaultWriteQueueOpts({}),
294
+ keyBag: rt.kb.defaultKeyBagOpts(sthis),
295
+ storeUrls: toStoreURIRuntime(sthis, "test-indexer-cold"),
296
+ storeEnDe: bs.ensureStoreEnDeFile({}),
297
+ };
298
+ crdt = new CRDT<TestType>(sthis, dbOpts);
278
299
  await crdt.bulk([
279
300
  { id: "abc1", value: { title: "amazing" } },
280
301
  { id: "abc2", value: { title: "creative" } },
281
302
  { id: "abc3", value: { title: "bazillas" } },
282
303
  ]);
304
+ logger.Debug().Msg("post bulk beforeEach");
283
305
  didMap = 0;
284
306
  mapFn = (doc) => {
285
307
  didMap++;
286
308
  return doc.title;
287
309
  };
288
- indexer = await index<string, TestType>(sthis, { _crdt: crdt }, "hello", mapFn);
310
+ indexer = await index<string, TestType>({ crdt: crdt }, "hello", mapFn);
311
+ logger.Debug().Msg("post index beforeEach");
289
312
  await indexer.ready();
313
+ logger.Debug().Msg("post indexer.ready beforeEach");
290
314
  // new Index(db._crdt.indexBlockstore, db._crdt, 'hello', mapFn)
291
315
  result = await indexer.query();
316
+
317
+ logger.Debug().Msg("post indexer.query beforeEach");
292
318
  expect(indexer.indexHead).toEqual(crdt.clock.head);
293
319
  });
294
320
  it("should call map on first query", function () {
@@ -301,12 +327,12 @@ describe("basic Index upon cold start", function () {
301
327
  expect(result.rows.length).toEqual(3);
302
328
  });
303
329
  it("should work on cold load", async function () {
304
- const crdt2 = new CRDT<TestType>(sthis, "test-indexer-cold", { persistIndexes: true });
330
+ const crdt2 = new CRDT<TestType>(sthis, dbOpts);
305
331
  await crdt2.ready();
306
332
  const { result, head } = await crdt2.changes();
307
333
  expect(result).toBeTruthy();
308
334
  await crdt2.ready();
309
- const indexer2 = await index<string, TestType>(sthis, { _crdt: crdt2 }, "hello", mapFn);
335
+ const indexer2 = await index<string, TestType>({ crdt: crdt2 }, "hello", mapFn);
310
336
  await indexer2.ready();
311
337
  const result2 = await indexer2.query();
312
338
  expect(indexer2.indexHead).toEqual(head);
@@ -316,8 +342,8 @@ describe("basic Index upon cold start", function () {
316
342
  });
317
343
  it.skip("should not rerun the map function on seen changes", async function () {
318
344
  didMap = 0;
319
- const crdt2 = new CRDT<TestType>(sthis, "test-indexer-cold", { persistIndexes: true });
320
- const indexer2 = await index(sthis, { _crdt: crdt2 }, "hello", mapFn);
345
+ const crdt2 = new CRDT<TestType>(sthis, dbOpts);
346
+ const indexer2 = await index({ crdt: crdt2 }, "hello", mapFn);
321
347
  const { result, head } = await crdt2.changes([]);
322
348
  expect(result.length).toEqual(3);
323
349
  expect(head.length).toEqual(1);
@@ -341,37 +367,35 @@ describe("basic Index upon cold start", function () {
341
367
  expect(didMap).toEqual(1);
342
368
  });
343
369
  it("should ignore meta when map function definiton changes", async function () {
344
- const crdt2 = new CRDT<TestType>(sthis, "test-indexer-cold");
345
- const result = await index<string, TestType>(sthis, { _crdt: crdt2 }, "hello", (doc) =>
346
- doc.title.split("").reverse().join(""),
347
- ).query();
370
+ const crdt2 = new CRDT<TestType>(sthis, dbOpts);
371
+ const result = await index<string, TestType>({ crdt: crdt2 }, "hello", (doc) => doc.title.split("").reverse().join("")).query();
348
372
  expect(result.rows.length).toEqual(3);
349
373
  expect(result.rows[0].key).toEqual("evitaerc"); // creative
350
374
  });
351
375
  });
352
376
 
353
377
  describe("basic Index with no data", function () {
354
- let db: Database<TestType>;
378
+ let db: Ledger<TestType>;
355
379
  let indexer: Index<string, TestType>;
356
380
  let didMap: boolean;
357
381
  const sthis = ensureSuperThis();
358
382
  afterEach(async function () {
359
383
  await db.close();
360
384
  await db.destroy();
361
- await indexer.close();
362
- await indexer.destroy();
385
+ // await indexer.close();
386
+ // await indexer.destroy();
363
387
  });
364
388
  beforeEach(async function () {
365
389
  await sthis.start();
366
- db = new Database("test-indexer");
367
- indexer = new Index<string, TestType>(sthis, db._crdt, "hello", (doc) => {
390
+ db = LedgerFactory("test-indexer");
391
+ indexer = new Index<string, TestType>(sthis, db.crdt, "hello", (doc) => {
368
392
  didMap = true;
369
393
  return doc.title;
370
394
  });
371
395
  await indexer.ready();
372
396
  });
373
397
  it("should have properties", function () {
374
- expect(indexer.crdt).toEqual(db._crdt);
398
+ expect(indexer.crdt).toEqual(db.crdt);
375
399
  expect(indexer.name).toEqual("hello");
376
400
  expect(indexer.mapFn).toBeTruthy();
377
401
  });