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

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.
@@ -7,7 +7,7 @@ describe("storage-content", () => {
7
7
  const sthis = mockSuperThis();
8
8
  it("car", async () => {
9
9
  const raw = new Uint8Array([55, 56, 57]);
10
- const res = await rt.gw.fpDeserialize(sthis, BuildURI.from("http://x.com?store=data&suffix=.car").URI(), Result.Ok(raw));
10
+ const res = await rt.gw.fpDeserialize(sthis, BuildURI.from("http://x.com?store=car&suffix=.car").URI(), Result.Ok(raw));
11
11
  expect(res.isOk()).toBeTruthy();
12
12
  expect(res.unwrap().type).toEqual(bs.FPEnvelopeTypes.CAR);
13
13
  expect(res.unwrap().payload).toEqual(raw);
@@ -15,7 +15,7 @@ describe("storage-content", () => {
15
15
 
16
16
  it("file", async () => {
17
17
  const raw = new Uint8Array([55, 56, 57]);
18
- const res = await rt.gw.fpDeserialize(sthis, BuildURI.from("http://x.com?store=data").URI(), Result.Ok(raw));
18
+ const res = await rt.gw.fpDeserialize(sthis, BuildURI.from("http://x.com?store=file").URI(), Result.Ok(raw));
19
19
  expect(res.isOk()).toBeTruthy();
20
20
  expect(res.unwrap().type).toEqual(bs.FPEnvelopeTypes.FILE);
21
21
  expect(res.unwrap().payload).toEqual(raw);
@@ -167,7 +167,7 @@ describe("de-serialize", () => {
167
167
 
168
168
  it("coerce into fpDeserialize Result", async () => {
169
169
  const raw = new Uint8Array([55, 56, 57]);
170
- const res = await rt.gw.fpDeserialize(sthis, BuildURI.from("http://x.com?store=data&suffix=.car").URI(), Result.Ok(raw));
170
+ const res = await rt.gw.fpDeserialize(sthis, BuildURI.from("http://x.com?store=car&suffix=.car").URI(), Result.Ok(raw));
171
171
  expect(res.isOk()).toBeTruthy();
172
172
  expect(res.unwrap().type).toEqual(bs.FPEnvelopeTypes.CAR);
173
173
  expect(res.unwrap().payload).toEqual(raw);
@@ -175,7 +175,7 @@ describe("de-serialize", () => {
175
175
 
176
176
  it("coerce into fpDeserialize Promise", async () => {
177
177
  const raw = new Uint8Array([55, 56, 57]);
178
- const res = await rt.gw.fpDeserialize(sthis, BuildURI.from("http://x.com?store=data&suffix=.car").URI(), Promise.resolve(raw));
178
+ const res = await rt.gw.fpDeserialize(sthis, BuildURI.from("http://x.com?store=car&suffix=.car").URI(), Promise.resolve(raw));
179
179
  expect(res.isOk()).toBeTruthy();
180
180
  expect(res.unwrap().type).toEqual(bs.FPEnvelopeTypes.CAR);
181
181
  expect(res.unwrap().payload).toEqual(raw);
@@ -185,7 +185,7 @@ describe("de-serialize", () => {
185
185
  const raw = new Uint8Array([55, 56, 57]);
186
186
  const res = await rt.gw.fpDeserialize(
187
187
  sthis,
188
- BuildURI.from("http://x.com?store=data&suffix=.car").URI(),
188
+ BuildURI.from("http://x.com?store=car&suffix=.car").URI(),
189
189
  Promise.resolve(Result.Ok(raw)),
190
190
  );
191
191
  expect(res.isOk()).toBeTruthy();
@@ -195,21 +195,21 @@ describe("de-serialize", () => {
195
195
 
196
196
  it("coerce into fpDeserialize Promise Result.Err", async () => {
197
197
  const raw = Promise.resolve(Result.Err<Uint8Array>("error"));
198
- const res = await rt.gw.fpDeserialize(sthis, BuildURI.from("http://x.com?store=data&suffix=.car").URI(), raw);
198
+ const res = await rt.gw.fpDeserialize(sthis, BuildURI.from("http://x.com?store=car&suffix=.car").URI(), raw);
199
199
  expect(res.isErr()).toBeTruthy();
200
200
  expect(res.unwrap_err().message).toEqual("error");
201
201
  });
202
202
 
203
203
  it("coerce into fpDeserialize Promise.reject", async () => {
204
204
  const raw = Promise.reject(new Error("error"));
205
- const res = await rt.gw.fpDeserialize(sthis, BuildURI.from("http://x.com?store=data&suffix=.car").URI(), raw);
205
+ const res = await rt.gw.fpDeserialize(sthis, BuildURI.from("http://x.com?store=car&suffix=.car").URI(), raw);
206
206
  expect(res.isErr()).toBeTruthy();
207
207
  expect(res.unwrap_err().message).toEqual("error");
208
208
  });
209
209
 
210
210
  it("coerce into fpDeserialize Result.Err", async () => {
211
211
  const raw = Result.Err<Uint8Array>("error");
212
- const res = await rt.gw.fpDeserialize(sthis, BuildURI.from("http://x.com?store=data&suffix=.car").URI(), raw);
212
+ const res = await rt.gw.fpDeserialize(sthis, BuildURI.from("http://x.com?store=car&suffix=.car").URI(), raw);
213
213
  expect(res.isErr()).toBeTruthy();
214
214
  expect(res.unwrap_err().message).toEqual("error");
215
215
  });
@@ -22,7 +22,7 @@ describe("fireproof config indexeddb", () => {
22
22
  protocol: "indexeddb:",
23
23
  searchParams: {
24
24
  name: "my-app",
25
- store: "data",
25
+ store: "file",
26
26
  runtime: "browser",
27
27
  storekey: "@my-app-data@",
28
28
  urlGen: "default",
@@ -37,7 +37,7 @@ describe("fireproof config indexeddb", () => {
37
37
  protocol: "indexeddb:",
38
38
  searchParams: {
39
39
  name: "my-app",
40
- store: "data",
40
+ store: "car",
41
41
  runtime: "browser",
42
42
  storekey: "@my-app-data@",
43
43
  suffix: ".car",
package/tests/helpers.ts CHANGED
@@ -14,8 +14,6 @@ import {
14
14
  import { CID } from "multiformats";
15
15
  import { sha256 } from "multiformats/hashes/sha2";
16
16
  import * as json from "multiformats/codecs/json";
17
- import { CarReader } from "@ipld/car";
18
- import { TaskManager } from "../src/blockstore/task-manager.js";
19
17
 
20
18
  export function sleep(ms: number) {
21
19
  return new Promise((resolve) => setTimeout(resolve, ms));
@@ -96,13 +94,16 @@ class MockLoader implements bs.Loadable {
96
94
  readonly ebOpts: bs.BlockstoreRuntime;
97
95
  readonly carLog: bs.CarLog;
98
96
  readonly attachedStores: bs.AttachedStores;
99
- readonly taskManager: TaskManager;
97
+ readonly taskManager: bs.TaskManager;
100
98
 
101
99
  constructor(sthis: SuperThis) {
102
100
  this.sthis = sthis;
103
101
  this.ebOpts = {} as bs.BlockstoreRuntime;
104
- this.carLog = [];
105
- this.taskManager = new TaskManager(sthis, () => Promise.resolve());
102
+ this.carLog = new bs.CarLog();
103
+ this.taskManager = new bs.TaskManager(sthis, () => Promise.resolve(), {
104
+ removeAfter: 3,
105
+ retryTimeout: 50,
106
+ });
106
107
  this.attachedStores = new bs.AttachedRemotesImpl(this);
107
108
  }
108
109
 
@@ -136,11 +137,11 @@ class MockLoader implements bs.Loadable {
136
137
  throw new Error("Method not implemented.");
137
138
  }
138
139
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
139
- loadFileCar(cid: bs.AnyLink, store: bs.ActiveStore): Promise<CarReader> {
140
+ loadFileCar(cid: bs.AnyLink, store: bs.ActiveStore): Promise<bs.CarCacheItem> {
140
141
  throw new Error("Method not implemented.");
141
142
  }
142
143
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
143
- loadCar(cid: bs.AnyLink, store: bs.ActiveStore): Promise<CarReader> {
144
+ loadCar(cid: bs.AnyLink, store: bs.ActiveStore): Promise<bs.CarCacheItem> {
144
145
  throw new Error("Method not implemented.");
145
146
  }
146
147
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -2,7 +2,7 @@ import { renderHook, waitFor } from "@testing-library/react";
2
2
  import { describe, expect, it } from "vitest";
3
3
 
4
4
  import { Database, fireproof, useFireproof } from "use-fireproof";
5
- import { LiveQueryResult, UseDocumentResult } from "../../src/react/useFireproof.js";
5
+ import { LiveQueryResult, UseDocumentResult } from "use-fireproof";
6
6
 
7
7
  describe("HOOK: useFireproof", () => {
8
8
  it("should be defined", () => {
@@ -26,18 +26,14 @@ describe("HOOK: useFireproof useLiveQuery has results", () => {
26
26
  database: ReturnType<typeof useFireproof>["database"],
27
27
  useLiveQuery: ReturnType<typeof useFireproof>["useLiveQuery"];
28
28
 
29
+ let cnt = 0;
30
+
29
31
  beforeEach(async () => {
30
32
  db = fireproof(dbName);
31
- await db.put({ foo: "aha" });
32
- await db.put({ foo: "bar" });
33
- await db.put({ foo: "caz" });
34
-
35
- renderHook(() => {
36
- const result = useFireproof(dbName);
37
- database = result.database;
38
- useLiveQuery = result.useLiveQuery;
39
- query = useLiveQuery<{ foo: string }>("foo");
40
- });
33
+ await db.put({ foo: "aha", cnt });
34
+ await db.put({ foo: "bar", cnt });
35
+ await db.put({ foo: "caz", cnt });
36
+ cnt++;
41
37
  });
42
38
 
43
39
  it("should have setup data", async () => {
@@ -49,19 +45,29 @@ describe("HOOK: useFireproof useLiveQuery has results", () => {
49
45
  });
50
46
 
51
47
  it("queries correctly", async () => {
48
+ renderHook(() => {
49
+ const result = useFireproof(dbName);
50
+ database = result.database;
51
+ useLiveQuery = result.useLiveQuery;
52
+ query = useLiveQuery<{ foo: string }>("foo");
53
+ });
54
+
52
55
  await waitFor(() => {
56
+ // act(() => {
57
+ // expect(query.rows).toBe([]);
53
58
  expect(query.rows.length).toBe(3);
54
59
  expect(query.rows[0].doc?.foo).toBe("aha");
55
60
  expect(query.rows[1].doc?.foo).toBe("bar");
56
61
  expect(query.rows[2].doc?.foo).toBe("caz");
62
+ // });
57
63
  });
58
64
  });
59
65
 
60
66
  afterEach(async () => {
61
67
  await db.close();
62
68
  await db.destroy();
63
- await database.close();
64
- await database.destroy();
69
+ await database?.close();
70
+ await database?.destroy();
65
71
  });
66
72
  });
67
73