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

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.
@@ -44,7 +44,7 @@ describe("config file gateway", () => {
44
44
  searchParams: {
45
45
  // ...isMemFS,
46
46
  name: "my-app",
47
- store: "data",
47
+ store: "file",
48
48
  storekey: "@my-app-data@",
49
49
  urlGen: "fromEnv",
50
50
  version: "v0.19-file",
@@ -59,7 +59,7 @@ describe("config file gateway", () => {
59
59
  searchParams: {
60
60
  // ...isMemFS,
61
61
  name: "my-app",
62
- store: "data",
62
+ store: "car",
63
63
  suffix: ".car",
64
64
  storekey: "@my-app-data@",
65
65
  urlGen: "fromEnv",
@@ -121,7 +121,7 @@ describe("config file gateway", () => {
121
121
  searchParams: {
122
122
  // ...isMemFS,
123
123
  name: "my-app",
124
- store: "data",
124
+ store: "car",
125
125
  storekey: "@my-app-data@",
126
126
  suffix: ".car",
127
127
  version: "v0.19-file",
@@ -135,7 +135,7 @@ describe("config file gateway", () => {
135
135
  searchParams: {
136
136
  // ...isMemFS,
137
137
  name: "my-app",
138
- store: "data",
138
+ store: "file",
139
139
  storekey: "@my-app-data@",
140
140
  version: "v0.19-file",
141
141
  },
@@ -191,7 +191,7 @@ describe("config file gateway", () => {
191
191
  suffix: ".car",
192
192
  runtime: runtimeFn().isDeno ? "deno" : "node",
193
193
  urlGen: "default",
194
- store: "data",
194
+ store: "car",
195
195
  name: my_app(),
196
196
  storekey: `@${my_app()}-data@`,
197
197
  version: rt.FILESTORE_VERSION,
@@ -209,7 +209,7 @@ describe("config file gateway", () => {
209
209
  // ...isMemFS,
210
210
  runtime: runtimeFn().isDeno ? "deno" : "node",
211
211
  urlGen: "default",
212
- store: "data",
212
+ store: "file",
213
213
  name: my_app(),
214
214
  storekey: `@${my_app()}-data@`,
215
215
  version: rt.FILESTORE_VERSION,
@@ -261,7 +261,7 @@ describe("config file gateway", () => {
261
261
  searchParams: {
262
262
  // ...isMemFS,
263
263
  urlGen: "fromEnv",
264
- store: "data",
264
+ store: "car",
265
265
  // runtime: "node",
266
266
  suffix: ".car",
267
267
  name: my_app(),
@@ -279,7 +279,7 @@ describe("config file gateway", () => {
279
279
  searchParams: {
280
280
  // ...isMemFS,
281
281
  urlGen: "fromEnv",
282
- store: "data",
282
+ store: "file",
283
283
  name: my_app(),
284
284
  storekey: `@${my_app()}-data@`,
285
285
  version: rt.FILESTORE_VERSION,
@@ -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