@fireproof/core 0.19.8-dev-getcon → 0.19.9-dev-frag

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. package/README.md +7 -0
  2. package/chunk-7EWIAXTM.js +7 -0
  3. package/chunk-7EWIAXTM.js.map +1 -0
  4. package/chunk-JO5AVWG7.js +67 -0
  5. package/chunk-JO5AVWG7.js.map +1 -0
  6. package/chunk-PB4BKL4O.js +7 -0
  7. package/chunk-PB4BKL4O.js.map +1 -0
  8. package/chunk-YS4GL6OK.js +266 -0
  9. package/chunk-YS4GL6OK.js.map +1 -0
  10. package/{store-indexdb-WLRSICCB.js → gateway-IZRHJWPE.js} +48 -80
  11. package/gateway-IZRHJWPE.js.map +1 -0
  12. package/gateway-YSNUK2L3.js +145 -0
  13. package/gateway-YSNUK2L3.js.map +1 -0
  14. package/index.cjs +2132 -1783
  15. package/index.cjs.map +1 -1
  16. package/index.d.cts +613 -513
  17. package/index.d.ts +613 -513
  18. package/index.global.js +19367 -20108
  19. package/index.global.js.map +1 -1
  20. package/index.js +1512 -1022
  21. package/index.js.map +1 -1
  22. package/key-bag-file-NMEBFSPM.js +54 -0
  23. package/key-bag-file-NMEBFSPM.js.map +1 -0
  24. package/key-bag-indexdb-X5V6GNBZ.js +50 -0
  25. package/key-bag-indexdb-X5V6GNBZ.js.map +1 -0
  26. package/mem-filesystem-B6C6QOIP.js +41 -0
  27. package/mem-filesystem-B6C6QOIP.js.map +1 -0
  28. package/metafile-cjs.json +1 -1
  29. package/metafile-esm.json +1 -1
  30. package/metafile-iife.json +1 -1
  31. package/node-filesystem-5JLBSHKQ.js +41 -0
  32. package/node-filesystem-5JLBSHKQ.js.map +1 -0
  33. package/package.json +8 -7
  34. package/tests/blockstore/fragment-gateway.test.ts +107 -0
  35. package/tests/blockstore/keyed-crypto.test.ts +302 -0
  36. package/tests/blockstore/loader.test.ts +24 -19
  37. package/tests/blockstore/store.test.ts +34 -28
  38. package/tests/blockstore/transaction.test.ts +19 -15
  39. package/tests/fireproof/config.test.ts +94 -78
  40. package/tests/fireproof/crdt.test.ts +34 -28
  41. package/tests/fireproof/database.test.ts +22 -14
  42. package/tests/fireproof/fireproof.test.fixture.ts +133 -0
  43. package/tests/fireproof/fireproof.test.ts +331 -219
  44. package/tests/fireproof/hello.test.ts +6 -4
  45. package/tests/fireproof/indexer.test.ts +34 -27
  46. package/tests/fireproof/utils.test.ts +65 -0
  47. package/tests/helpers.ts +25 -57
  48. package/utils-IZPK4QS7.js +14 -0
  49. package/utils-IZPK4QS7.js.map +1 -0
  50. package/chunk-BNL4PVBF.js +0 -314
  51. package/chunk-BNL4PVBF.js.map +0 -1
  52. package/chunk-JW2QT6BF.js +0 -184
  53. package/chunk-JW2QT6BF.js.map +0 -1
  54. package/node-sys-container-MIEX6ELJ.js +0 -29
  55. package/node-sys-container-MIEX6ELJ.js.map +0 -1
  56. package/store-file-VJ6BI4II.js +0 -191
  57. package/store-file-VJ6BI4II.js.map +0 -1
  58. package/store-indexdb-WLRSICCB.js.map +0 -1
@@ -1,4 +1,5 @@
1
- import { rt, fireproof as database, Database, DocResponse, DocWithId, index, Index, IndexRows } from "@fireproof/core";
1
+ import { fireproof as database, Database, DocResponse, DocWithId, index, Index, IndexRows } from "@fireproof/core";
2
+ import { mockSuperThis } from "../helpers";
2
3
 
3
4
  describe("Hello World Test", function () {
4
5
  it("should pass the hello world test", function () {
@@ -7,7 +8,7 @@ describe("Hello World Test", function () {
7
8
  });
8
9
  });
9
10
 
10
- describe("public API", function () {
11
+ describe("hello public API", function () {
11
12
  interface TestDoc {
12
13
  foo: string;
13
14
  }
@@ -16,6 +17,7 @@ describe("public API", function () {
16
17
  let ok: DocResponse;
17
18
  let doc: DocWithId<TestDoc>;
18
19
  let query: IndexRows<string, TestDoc>;
20
+ const sthis = mockSuperThis();
19
21
  afterEach(async function () {
20
22
  await db.close();
21
23
  await db.destroy();
@@ -23,9 +25,9 @@ describe("public API", function () {
23
25
  await idx.destroy();
24
26
  });
25
27
  beforeEach(async function () {
26
- await rt.SysContainer.start();
28
+ await sthis.start();
27
29
  db = database("test-public-api");
28
- idx = index<string, TestDoc>(db, "test-index", (doc) => doc.foo);
30
+ idx = index<string, TestDoc>(sthis, db, "test-index", (doc) => doc.foo);
29
31
  ok = await db.put({ _id: "test", foo: "bar" });
30
32
  doc = await db.get("test");
31
33
  query = await idx.query();
@@ -1,6 +1,5 @@
1
- import { itSkip } from "../helpers.js";
2
-
3
- import { rt, Index, index, Database, CRDT, IndexRows } from "@fireproof/core";
1
+ import { Index, index, Database, CRDT, IndexRows } from "@fireproof/core";
2
+ import { mockSuperThis } from "../helpers";
4
3
 
5
4
  interface TestType {
6
5
  readonly title: string;
@@ -11,6 +10,7 @@ describe("basic Index", () => {
11
10
  let db: Database<TestType>;
12
11
  let indexer: Index<string, TestType>;
13
12
  let didMap: boolean;
13
+ const sthis = mockSuperThis();
14
14
  afterEach(async function () {
15
15
  await db.close();
16
16
  await db.destroy();
@@ -18,12 +18,12 @@ describe("basic Index", () => {
18
18
  await indexer.destroy();
19
19
  });
20
20
  beforeEach(async function () {
21
- await rt.SysContainer.start();
21
+ await sthis.start();
22
22
  db = new Database("test-indexer");
23
23
  await db.put({ title: "amazing" });
24
24
  await db.put({ title: "creative" });
25
25
  await db.put({ title: "bazillas" });
26
- indexer = new Index<string, TestType>(db._crdt, "hello", (doc) => {
26
+ indexer = new Index<string, TestType>(sthis, db._crdt, "hello", (doc) => {
27
27
  didMap = true;
28
28
  return doc.title;
29
29
  });
@@ -97,6 +97,7 @@ describe("basic Index", () => {
97
97
  describe("Index query with compound key", function () {
98
98
  let db: Database<TestType>;
99
99
  let indexer: Index<[string, number], TestType>;
100
+ const sthis = mockSuperThis();
100
101
  afterEach(async function () {
101
102
  await db.close();
102
103
  await db.destroy();
@@ -104,13 +105,13 @@ describe("Index query with compound key", function () {
104
105
  await indexer.destroy();
105
106
  });
106
107
  beforeEach(async function () {
107
- await rt.SysContainer.start();
108
+ await sthis.start();
108
109
  db = new Database("test-indexer");
109
110
  await db.put({ title: "amazing", score: 1 });
110
111
  await db.put({ title: "creative", score: 2 });
111
112
  await db.put({ title: "creative", score: 20 });
112
113
  await db.put({ title: "bazillas", score: 3 });
113
- indexer = new Index<[string, number], TestType>(db._crdt, "hello", (doc) => {
114
+ indexer = new Index<[string, number], TestType>(sthis, db._crdt, "hello", (doc) => {
114
115
  return [doc.title, doc.score];
115
116
  });
116
117
  await indexer.ready();
@@ -126,6 +127,7 @@ describe("Index query with compound key", function () {
126
127
  describe("basic Index with map fun", function () {
127
128
  let db: Database<TestType>;
128
129
  let indexer: Index<string, TestType>;
130
+ const sthis = mockSuperThis();
129
131
  afterEach(async function () {
130
132
  await db.close();
131
133
  await db.destroy();
@@ -133,12 +135,12 @@ describe("basic Index with map fun", function () {
133
135
  await indexer.destroy();
134
136
  });
135
137
  beforeEach(async function () {
136
- await rt.SysContainer.start();
138
+ await sthis.start();
137
139
  db = new Database("test-indexer");
138
140
  await db.put({ title: "amazing" });
139
141
  await db.put({ title: "creative" });
140
142
  await db.put({ title: "bazillas" });
141
- indexer = new Index<string, TestType>(db._crdt, "hello", (doc, map) => {
143
+ indexer = new Index<string, TestType>(sthis, db._crdt, "hello", (doc, map) => {
142
144
  map(doc.title);
143
145
  });
144
146
  await indexer.ready();
@@ -155,17 +157,18 @@ describe("basic Index with map fun", function () {
155
157
  describe("basic Index with map fun with value", function () {
156
158
  let db: Database<TestType>;
157
159
  let indexer: Index<string, TestType, number>;
160
+ const sthis = mockSuperThis();
158
161
  afterEach(async function () {
159
162
  await db.close();
160
163
  await db.destroy();
161
164
  });
162
165
  beforeEach(async function () {
163
- await rt.SysContainer.start();
166
+ await sthis.start();
164
167
  db = new Database("test-indexer");
165
168
  await db.put({ title: "amazing" });
166
169
  await db.put({ title: "creative" });
167
170
  await db.put({ title: "bazillas" });
168
- indexer = new Index<string, TestType, number>(db._crdt, "hello", (doc, map) => {
171
+ indexer = new Index<string, TestType, number>(sthis, db._crdt, "hello", (doc, map) => {
169
172
  map(doc.title, doc.title.length);
170
173
  });
171
174
  });
@@ -192,6 +195,7 @@ describe("basic Index with map fun with value", function () {
192
195
  describe("Index query with map and compound key", function () {
193
196
  let db: Database<TestType>;
194
197
  let indexer: Index<[string, number], TestType>;
198
+ const sthis = mockSuperThis();
195
199
  afterEach(async function () {
196
200
  await db.close();
197
201
  await db.destroy();
@@ -199,13 +203,13 @@ describe("Index query with map and compound key", function () {
199
203
  await indexer.destroy();
200
204
  });
201
205
  beforeEach(async function () {
202
- await rt.SysContainer.start();
206
+ await sthis.start();
203
207
  db = new Database("test-indexer");
204
208
  await db.put({ title: "amazing", score: 1 });
205
209
  await db.put({ title: "creative", score: 2 });
206
210
  await db.put({ title: "creative", score: 20 });
207
211
  await db.put({ title: "bazillas", score: 3 });
208
- indexer = new Index<[string, number], TestType>(db._crdt, "hello", (doc, emit) => {
212
+ indexer = new Index<[string, number], TestType>(sthis, db._crdt, "hello", (doc, emit) => {
209
213
  emit([doc.title, doc.score]);
210
214
  });
211
215
  await indexer.ready();
@@ -221,6 +225,7 @@ describe("Index query with map and compound key", function () {
221
225
  describe("basic Index with string fun", function () {
222
226
  let db: Database<TestType>;
223
227
  let indexer: Index<string, TestType>;
228
+ const sthis = mockSuperThis();
224
229
  afterEach(async function () {
225
230
  await db.close();
226
231
  await db.destroy();
@@ -228,12 +233,12 @@ describe("basic Index with string fun", function () {
228
233
  await indexer.destroy();
229
234
  });
230
235
  beforeEach(async function () {
231
- await rt.SysContainer.start();
236
+ await sthis.start();
232
237
  db = new Database("test-indexer");
233
238
  await db.put({ title: "amazing" });
234
239
  await db.put({ title: "creative" });
235
240
  await db.put({ title: "bazillas" });
236
- indexer = new Index(db._crdt, "title");
241
+ indexer = new Index(sthis, db._crdt, "title");
237
242
  await indexer.ready();
238
243
  });
239
244
  it("should get results", async function () {
@@ -259,6 +264,7 @@ describe("basic Index upon cold start", function () {
259
264
  let didMap: number;
260
265
  let mapFn: (doc: TestType) => string;
261
266
  let result: IndexRows<string, TestType>;
267
+ const sthis = mockSuperThis();
262
268
  // result, mapFn;
263
269
  afterEach(async function () {
264
270
  await crdt.close();
@@ -267,9 +273,9 @@ describe("basic Index upon cold start", function () {
267
273
  await indexer.destroy();
268
274
  });
269
275
  beforeEach(async function () {
270
- await rt.SysContainer.start();
276
+ await sthis.start();
271
277
  // db = database()
272
- crdt = new CRDT<TestType>("test-indexer-cold", { persistIndexes: true });
278
+ crdt = new CRDT<TestType>(sthis, "test-indexer-cold", { persistIndexes: true });
273
279
  await crdt.bulk([
274
280
  { id: "abc1", value: { title: "amazing" } },
275
281
  { id: "abc2", value: { title: "creative" } },
@@ -280,7 +286,7 @@ describe("basic Index upon cold start", function () {
280
286
  didMap++;
281
287
  return doc.title;
282
288
  };
283
- indexer = await index<string, TestType>({ _crdt: crdt }, "hello", mapFn);
289
+ indexer = await index<string, TestType>(sthis, { _crdt: crdt }, "hello", mapFn);
284
290
  await indexer.ready();
285
291
  // new Index(db._crdt.indexBlockstore, db._crdt, 'hello', mapFn)
286
292
  result = await indexer.query();
@@ -296,12 +302,12 @@ describe("basic Index upon cold start", function () {
296
302
  expect(result.rows.length).toEqual(3);
297
303
  });
298
304
  it("should work on cold load", async function () {
299
- const crdt2 = new CRDT<TestType>("test-indexer-cold", { persistIndexes: true });
305
+ const crdt2 = new CRDT<TestType>(sthis, "test-indexer-cold", { persistIndexes: true });
300
306
  await crdt2.ready();
301
307
  const { result, head } = await crdt2.changes();
302
308
  expect(result).toBeTruthy();
303
309
  await crdt2.ready();
304
- const indexer2 = await index<string, TestType>({ _crdt: crdt2 }, "hello", mapFn);
310
+ const indexer2 = await index<string, TestType>(sthis, { _crdt: crdt2 }, "hello", mapFn);
305
311
  await indexer2.ready();
306
312
  const result2 = await indexer2.query();
307
313
  expect(indexer2.indexHead).toEqual(head);
@@ -309,10 +315,10 @@ describe("basic Index upon cold start", function () {
309
315
  expect(result2.rows.length).toEqual(3);
310
316
  expect(indexer2.indexHead).toEqual(head);
311
317
  });
312
- itSkip("should not rerun the map function on seen changes", async function () {
318
+ it.skip("should not rerun the map function on seen changes", async function () {
313
319
  didMap = 0;
314
- const crdt2 = new CRDT<TestType>("test-indexer-cold", { persistIndexes: true });
315
- const indexer2 = await index({ _crdt: crdt2 }, "hello", mapFn);
320
+ const crdt2 = new CRDT<TestType>(sthis, "test-indexer-cold", { persistIndexes: true });
321
+ const indexer2 = await index(sthis, { _crdt: crdt2 }, "hello", mapFn);
316
322
  const { result, head } = await crdt2.changes([]);
317
323
  expect(result.length).toEqual(3);
318
324
  expect(head.length).toEqual(1);
@@ -336,8 +342,8 @@ describe("basic Index upon cold start", function () {
336
342
  expect(didMap).toEqual(1);
337
343
  });
338
344
  it("should ignore meta when map function definiton changes", async function () {
339
- const crdt2 = new CRDT<TestType>("test-indexer-cold");
340
- const result = await index<string, TestType>({ _crdt: crdt2 }, "hello", (doc) =>
345
+ const crdt2 = new CRDT<TestType>(sthis, "test-indexer-cold");
346
+ const result = await index<string, TestType>(sthis, { _crdt: crdt2 }, "hello", (doc) =>
341
347
  doc.title.split("").reverse().join(""),
342
348
  ).query();
343
349
  expect(result.rows.length).toEqual(3);
@@ -349,6 +355,7 @@ describe("basic Index with no data", function () {
349
355
  let db: Database<TestType>;
350
356
  let indexer: Index<string, TestType>;
351
357
  let didMap: boolean;
358
+ const sthis = mockSuperThis();
352
359
  afterEach(async function () {
353
360
  await db.close();
354
361
  await db.destroy();
@@ -356,9 +363,9 @@ describe("basic Index with no data", function () {
356
363
  await indexer.destroy();
357
364
  });
358
365
  beforeEach(async function () {
359
- await rt.SysContainer.start();
366
+ await sthis.start();
360
367
  db = new Database("test-indexer");
361
- indexer = new Index<string, TestType>(db._crdt, "hello", (doc) => {
368
+ indexer = new Index<string, TestType>(sthis, db._crdt, "hello", (doc) => {
362
369
  didMap = true;
363
370
  return doc.title;
364
371
  });
@@ -0,0 +1,65 @@
1
+ import { URI } from "@adviser/cement";
2
+ import { rt, getStore, ensureSuperLog } from "@fireproof/core";
3
+ import { mockSuperThis } from "../helpers";
4
+
5
+ describe("utils", () => {
6
+ const sthis = mockSuperThis({});
7
+ const logger = ensureSuperLog(sthis, "getfilename");
8
+
9
+ beforeAll(async () => {
10
+ await sthis.start();
11
+ });
12
+
13
+ it("sorts search params", () => {
14
+ const url = URI.from("http://example.com?z=1&y=2&x=3");
15
+ expect(url.toString()).toEqual("http://example.com/?x=3&y=2&z=1");
16
+ });
17
+
18
+ const storeOpts = [
19
+ {
20
+ type: "data",
21
+ suffix: ".car",
22
+ },
23
+ {
24
+ type: "wal",
25
+ suffix: ".json",
26
+ },
27
+ {
28
+ type: "meta",
29
+ suffix: ".json",
30
+ },
31
+ ];
32
+ it("getfilename plain", () => {
33
+ for (const store of storeOpts) {
34
+ const url = URI.from(`file://./x/path?store=${store.type}&name=name&key=key&version=version`);
35
+ expect(rt.getFileName(url, logger)).toEqual(`${store.type}/key${store.suffix}`);
36
+ }
37
+ });
38
+
39
+ it("getfilename index", () => {
40
+ for (const store of storeOpts) {
41
+ const url = URI.from(`file://./x/path?index=idx&store=${store.type}&name=name&key=key&version=version`);
42
+ expect(rt.getFileName(url, logger)).toEqual(`idx-${store.type}/key${store.suffix}`);
43
+ }
44
+ });
45
+
46
+ it("getstore", () => {
47
+ for (const store of storeOpts) {
48
+ const url = URI.from(`file://./x/path?store=${store.type}&name=name&key=key&version=version`);
49
+ expect(getStore(url, logger, (...toJoin) => toJoin.join("+"))).toEqual({
50
+ name: store.type,
51
+ store: store.type,
52
+ });
53
+ }
54
+ });
55
+
56
+ it("getstore idx", () => {
57
+ for (const store of storeOpts) {
58
+ const url = URI.from(`file://./x/path?index=ix&store=${store.type}&name=name&key=key&version=version`);
59
+ expect(getStore(url, logger, (...toJoin) => toJoin.join("+"))).toEqual({
60
+ name: `ix+${store.type}`,
61
+ store: store.type,
62
+ });
63
+ }
64
+ });
65
+ });
package/tests/helpers.ts CHANGED
@@ -1,66 +1,12 @@
1
- import { rt } from "@fireproof/core";
1
+ import { MockLogger, runtimeFn, toCryptoRuntime, URI } from "@adviser/cement";
2
+ import { dataDir, ensureSuperThis, rt, SuperThis, SuperThisOpts } from "@fireproof/core";
2
3
 
3
- const dataDir = rt.dataDir;
4
4
  export { dataDir };
5
5
 
6
6
  export function sleep(ms: number) {
7
7
  return new Promise((resolve) => setTimeout(resolve, ms));
8
8
  }
9
9
 
10
- export function itSkip(value: string, fn: () => unknown, options?: number) {
11
- if (typeof it !== "function") {
12
- return;
13
- }
14
- const mit = it as unknown as { skip: (value: string, fn: () => unknown, options?: unknown) => unknown };
15
- if (mit && typeof mit.skip === "function") {
16
- mit.skip(value, fn, options);
17
- return;
18
- }
19
- console.warn("itSkip of " + value);
20
- }
21
-
22
- //
23
-
24
- // // Function to copy a directory
25
- // export async function copyDirectory(source: string, destination: string) {
26
- // // Ensure the destination directory exists
27
- // await rt.SysContainer.mkdir(destination, { recursive: true });
28
-
29
- // // Read the source directory
30
- // const entries = await SysContainer.readdirent(source, { withFileTypes: true });
31
-
32
- // // Iterate through each entry in the directory
33
- // for (const entry of entries) {
34
- // const sourcePath = SysContainer.join(source, entry.name);
35
- // const destinationPath = SysContainer.join(destination, entry.name);
36
-
37
- // if (entry.isDirectory()) {
38
- // // If the entry is a directory, copy it recursively
39
- // await copyDirectory(sourcePath, destinationPath);
40
- // } else if (entry.isFile()) {
41
- // // If the entry is a file, copy it
42
- // await SysContainer.copyFile(sourcePath, destinationPath);
43
- // }
44
- // }
45
- // }
46
-
47
- // export function getDirectoryName(url: string) {
48
- // let path: string;
49
- // try {
50
- // path = SysContainer.fileURLToPath(url);
51
- // } catch (e) {
52
- // path = url;
53
- // }
54
- // if (process && typeof process.cwd === "function") {
55
- // const cwd = process.cwd();
56
- // if (cwd.endsWith("dist/esm")) {
57
- // path = "../../" + path;
58
- // }
59
- // }
60
- // const dir_name = SysContainer.dirname(path);
61
- // return dir_name;
62
- // }
63
-
64
10
  async function toFileWithCid(buffer: Uint8Array, name: string, opts: FilePropertyBag): Promise<FileWithCid> {
65
11
  return {
66
12
  file: new File([new Blob([buffer])], name, opts),
@@ -73,9 +19,31 @@ export interface FileWithCid {
73
19
  cid: string;
74
20
  }
75
21
  export async function buildBlobFiles(): Promise<FileWithCid[]> {
76
- const cp = rt.crypto.toCryptoOpts();
22
+ const cp = toCryptoRuntime();
77
23
  return [
78
24
  await toFileWithCid(cp.randomBytes(Math.random() * 51283), `image.jpg`, { type: "image/jpeg" }),
79
25
  await toFileWithCid(cp.randomBytes(Math.random() * 51283), `fireproof.png`, { type: "image/png" }),
80
26
  ];
81
27
  }
28
+
29
+ export function storageURL(sthis: SuperThis): URI {
30
+ const old = sthis.env.get("FP_STORAGE_URL");
31
+ let merged: URI;
32
+ if (runtimeFn().isBrowser) {
33
+ merged = URI.merge(`indexdb://fp`, old, "indexdb:");
34
+ } else {
35
+ merged = URI.merge(`./dist/env`, old);
36
+ }
37
+ return merged;
38
+ }
39
+
40
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
41
+ export function mockSuperThis(sthis?: Partial<SuperThisOpts>): SuperThis {
42
+ const mockLog = MockLogger();
43
+ return ensureSuperThis({
44
+ logger: mockLog.logger,
45
+ ctx: {
46
+ logCollector: mockLog.logCollector,
47
+ },
48
+ });
49
+ }
@@ -0,0 +1,14 @@
1
+ import {
2
+ getFileName,
3
+ getFileSystem,
4
+ getPath,
5
+ toArrayBuffer
6
+ } from "./chunk-JO5AVWG7.js";
7
+ import "./chunk-YS4GL6OK.js";
8
+ export {
9
+ getFileName,
10
+ getFileSystem,
11
+ getPath,
12
+ toArrayBuffer
13
+ };
14
+ //# sourceMappingURL=utils-IZPK4QS7.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}