@fireproof/core 0.20.0-dev-preview-40 → 0.20.0-dev-preview-41

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 (38) hide show
  1. package/README.md +6 -4
  2. package/deno/index.js +2 -2
  3. package/deno/index.js.map +1 -1
  4. package/index.cjs +499 -370
  5. package/index.cjs.map +1 -1
  6. package/index.d.cts +162 -64
  7. package/index.d.ts +162 -64
  8. package/index.js +473 -344
  9. package/index.js.map +1 -1
  10. package/metafile-cjs.json +1 -1
  11. package/metafile-esm.json +1 -1
  12. package/package.json +3 -3
  13. package/react/index.cjs +17 -9
  14. package/react/index.cjs.map +1 -1
  15. package/react/index.d.cts +2 -1
  16. package/react/index.d.ts +2 -1
  17. package/react/index.js +17 -9
  18. package/react/index.js.map +1 -1
  19. package/react/metafile-cjs.json +1 -1
  20. package/react/metafile-esm.json +1 -1
  21. package/tests/blockstore/interceptor-gateway.test.ts +5 -1
  22. package/tests/blockstore/keyed-crypto-indexeddb-file.test.ts +8 -18
  23. package/tests/blockstore/keyed-crypto.test.ts +7 -30
  24. package/tests/blockstore/loader.test.ts +19 -17
  25. package/tests/blockstore/store.test.ts +48 -51
  26. package/tests/blockstore/transaction.test.ts +13 -11
  27. package/tests/fireproof/all-gateway.test.ts +49 -46
  28. package/tests/fireproof/attachable.test.ts +82 -0
  29. package/tests/fireproof/crdt.test.ts +49 -48
  30. package/tests/fireproof/database.test.ts +40 -40
  31. package/tests/fireproof/fireproof.test.ts +43 -42
  32. package/tests/fireproof/hello.test.ts +4 -4
  33. package/tests/fireproof/indexer.test.ts +44 -44
  34. package/tests/fireproof/utils.test.ts +4 -3
  35. package/tests/gateway/file/loader-config.test.ts +17 -17
  36. package/tests/gateway/indexeddb/loader-config.test.ts +4 -4
  37. package/tests/helpers.ts +80 -2
  38. package/tests/react/useFireproof.test.tsx +40 -4
@@ -20,7 +20,7 @@ describe("HOOK: useFireproof", () => {
20
20
  });
21
21
 
22
22
  describe("HOOK: useFireproof useLiveQuery has results", () => {
23
- const dbName = "dbnameuseFP";
23
+ const dbName = "useLiveQueryHasResults";
24
24
  let db: Database,
25
25
  query: LiveQueryResult<{ foo: string }, string>,
26
26
  database: ReturnType<typeof useFireproof>["database"],
@@ -269,9 +269,8 @@ describe("HOOK: useFireproof useDocument has results reset sync", () => {
269
269
 
270
270
  const allDocs = await db.allDocs<{ input: string }>();
271
271
  expect(allDocs.rows.length).toBe(3);
272
- expect(allDocs.rows[0].value.input).toBe("first");
273
- expect(allDocs.rows[1].value.input).toBe("new");
274
- expect(allDocs.rows[2].value.input).toBe("fresh");
272
+ const inputs = allDocs.rows.map((r) => r.value.input);
273
+ expect(inputs).toEqual(expect.arrayContaining(["first", "new", "fresh"]));
275
274
  });
276
275
 
277
276
  afterEach(async () => {
@@ -511,3 +510,40 @@ describe("HOOK: useFireproof race condition: calling save() without await overwr
511
510
  await db.destroy();
512
511
  });
513
512
  });
513
+
514
+ describe("useFireproo calling submit()", () => {
515
+ const dbName = "submitDb";
516
+ let db: Database, docResult: UseDocumentResult<{ input: string }>;
517
+
518
+ beforeEach(async () => {
519
+ db = fireproof(dbName);
520
+
521
+ // Render a new hook instance
522
+ renderHook(() => {
523
+ const { useDocument } = useFireproof(dbName);
524
+ docResult = useDocument<{ input: string }>({ input: "" });
525
+ });
526
+ });
527
+
528
+ it("demonstrates that calling docResult.save() and docResult.reset() in the same tick can overwrite reset", async () => {
529
+ // Merge some changes into doc
530
+ docResult.merge({ input: "some data" });
531
+
532
+ docResult.submit();
533
+
534
+ // Let the async subscription produce a new doc in case the doc is reloaded with an _id
535
+ await new Promise((resolve) => setTimeout(resolve, 500));
536
+
537
+ // If the reset worked, doc._id should STILL be undefined.
538
+ // If the subscription wins, doc._id will be defined => test fails.
539
+ await waitFor(() => {
540
+ expect(docResult.doc._id).toBeUndefined();
541
+ expect(docResult.doc.input).toBe("");
542
+ });
543
+ });
544
+
545
+ afterEach(async () => {
546
+ await db.close();
547
+ await db.destroy();
548
+ });
549
+ });