@fireproof/core 0.19.8-dev-global → 0.19.8-dev-series-2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. package/README.md +34 -0
  2. package/chunk-7EWIAXTM.js +7 -0
  3. package/chunk-7EWIAXTM.js.map +1 -0
  4. package/chunk-OFGPKRCM.js +290 -0
  5. package/chunk-OFGPKRCM.js.map +1 -0
  6. package/chunk-PB4BKL4O.js +7 -0
  7. package/chunk-PB4BKL4O.js.map +1 -0
  8. package/chunk-WS3YRPIA.js +75 -0
  9. package/chunk-WS3YRPIA.js.map +1 -0
  10. package/deno.json +22 -0
  11. package/gateway-5FCWPX5W.js +144 -0
  12. package/gateway-5FCWPX5W.js.map +1 -0
  13. package/{store-indexdb-WLRSICCB.js → gateway-H7UD6TNB.js} +49 -82
  14. package/gateway-H7UD6TNB.js.map +1 -0
  15. package/index.cjs +2365 -1875
  16. package/index.cjs.map +1 -1
  17. package/index.d.cts +663 -535
  18. package/index.d.ts +663 -535
  19. package/index.global.js +26742 -20717
  20. package/index.global.js.map +1 -1
  21. package/index.js +1691 -1094
  22. package/index.js.map +1 -1
  23. package/key-bag-file-WADZBHYG.js +54 -0
  24. package/key-bag-file-WADZBHYG.js.map +1 -0
  25. package/key-bag-indexdb-PGVAI3FJ.js +50 -0
  26. package/key-bag-indexdb-PGVAI3FJ.js.map +1 -0
  27. package/mem-filesystem-YPPJV7Q2.js +41 -0
  28. package/mem-filesystem-YPPJV7Q2.js.map +1 -0
  29. package/metafile-cjs.json +1 -1
  30. package/metafile-esm.json +1 -1
  31. package/metafile-iife.json +1 -1
  32. package/node-filesystem-INX4ZTHE.js +45 -0
  33. package/node-filesystem-INX4ZTHE.js.map +1 -0
  34. package/package.json +14 -8
  35. package/tests/blockstore/fragment-gateway.test.ts +107 -0
  36. package/tests/blockstore/keyed-crypto.test.ts +332 -0
  37. package/tests/blockstore/loader.test.ts +24 -19
  38. package/tests/blockstore/store.test.ts +51 -40
  39. package/tests/blockstore/transaction.test.ts +19 -15
  40. package/tests/fireproof/all-gateway.test.ts +394 -0
  41. package/tests/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.car +0 -0
  42. package/tests/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.ts +316 -0
  43. package/tests/fireproof/config.test.ts +94 -78
  44. package/tests/fireproof/crdt.test.ts +34 -28
  45. package/tests/fireproof/database.test.ts +22 -14
  46. package/tests/fireproof/fireproof.test.fixture.ts +133 -0
  47. package/tests/fireproof/fireproof.test.ts +331 -219
  48. package/tests/fireproof/hello.test.ts +34 -18
  49. package/tests/fireproof/indexer.test.ts +34 -27
  50. package/tests/fireproof/utils.test.ts +84 -0
  51. package/tests/helpers.ts +28 -57
  52. package/tests/www/todo-local.html +1 -1
  53. package/tests/www/todo.html +12 -15
  54. package/utils-QO2HIWGI.js +14 -0
  55. package/utils-QO2HIWGI.js.map +1 -0
  56. package/chunk-BNL4PVBF.js +0 -314
  57. package/chunk-BNL4PVBF.js.map +0 -1
  58. package/chunk-JW2QT6BF.js +0 -184
  59. package/chunk-JW2QT6BF.js.map +0 -1
  60. package/node-sys-container-MIEX6ELJ.js +0 -29
  61. package/node-sys-container-MIEX6ELJ.js.map +0 -1
  62. package/store-file-VJ6BI4II.js +0 -191
  63. package/store-file-VJ6BI4II.js.map +0 -1
  64. package/store-indexdb-WLRSICCB.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { rt, fireproof as database, Database, DocResponse, DocWithId, index, Index, IndexRows } from "@fireproof/core";
1
+ import { fireproof as database, Database, DocResponse, DocWithId } from "@fireproof/core";
2
2
 
3
3
  describe("Hello World Test", function () {
4
4
  it("should pass the hello world test", function () {
@@ -7,37 +7,26 @@ describe("Hello World Test", function () {
7
7
  });
8
8
  });
9
9
 
10
- describe("public API", function () {
10
+ describe("hello public API", function () {
11
11
  interface TestDoc {
12
12
  foo: string;
13
13
  }
14
14
  let db: Database;
15
- let idx: Index<string, TestDoc>;
16
15
  let ok: DocResponse;
17
16
  let doc: DocWithId<TestDoc>;
18
- let query: IndexRows<string, TestDoc>;
19
17
  afterEach(async function () {
20
18
  await db.close();
21
19
  await db.destroy();
22
- await idx.close();
23
- await idx.destroy();
24
20
  });
25
21
  beforeEach(async function () {
26
- await rt.SysContainer.start();
27
22
  db = database("test-public-api");
28
- idx = index<string, TestDoc>(db, "test-index", (doc) => doc.foo);
29
23
  ok = await db.put({ _id: "test", foo: "bar" });
30
24
  doc = await db.get("test");
31
- query = await idx.query();
32
25
  });
33
26
  it("should have a database", function () {
34
27
  expect(db).toBeTruthy();
35
28
  expect(db instanceof Database).toBeTruthy();
36
29
  });
37
- it("should have an index", function () {
38
- expect(idx).toBeTruthy();
39
- expect(idx instanceof Index).toBeTruthy();
40
- });
41
30
  it("should put", function () {
42
31
  expect(ok).toBeTruthy();
43
32
  expect(ok.id).toBe("test");
@@ -45,10 +34,37 @@ describe("public API", function () {
45
34
  it("should get", function () {
46
35
  expect(doc.foo).toBe("bar");
47
36
  });
48
- it("should query", function () {
49
- expect(query).toBeTruthy();
50
- expect(query.rows).toBeTruthy();
51
- expect(query.rows.length).toBe(1);
52
- expect(query.rows[0].key).toBe("bar");
37
+ it("should get when you open it again", async function () {
38
+ await db.close();
39
+ await db.destroy();
40
+ const db2 = database("test-public-api");
41
+ doc = await db2.get("test");
42
+ expect(doc.foo).toBe("bar");
43
+ });
44
+ });
45
+
46
+ describe("Simplified Reopening a database", function () {
47
+ let db: Database;
48
+ afterEach(async function () {
49
+ await db.close();
50
+ await db.destroy();
51
+ });
52
+ beforeEach(async function () {
53
+ db = new Database("test-reopen-simple");
54
+ const ok = await db.put({ _id: "test", foo: "bar" });
55
+ expect(ok).toBeTruthy();
56
+ expect(ok.id).toBe("test");
57
+ });
58
+
59
+ it("should persist data", async function () {
60
+ const doc = await db.get<{ foo: string }>("test");
61
+ expect(doc.foo).toBe("bar");
62
+ });
63
+
64
+ it("should have the same data on reopen", async function () {
65
+ const db2 = new Database("test-reopen-simple");
66
+ const doc = await db2.get<{ foo: string }>("test");
67
+ expect(doc.foo).toBe("bar");
68
+ await db2.close();
53
69
  });
54
70
  });
@@ -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,84 @@
1
+ import { URI } from "@adviser/cement";
2
+ import { rt, getStore, ensureSuperLog } from "@fireproof/core";
3
+ import { mockSuperThis } from "../helpers";
4
+
5
+ // only for test
6
+ import { UUID } from "uuidv7";
7
+
8
+ describe("utils", () => {
9
+ const sthis = mockSuperThis({});
10
+ const logger = ensureSuperLog(sthis, "getfilename");
11
+
12
+ beforeAll(async () => {
13
+ await sthis.start();
14
+ });
15
+
16
+ it("sorts search params", () => {
17
+ const url = URI.from("http://example.com?z=1&y=2&x=3");
18
+ expect(url.toString()).toEqual("http://example.com/?x=3&y=2&z=1");
19
+ });
20
+
21
+ const storeOpts = [
22
+ {
23
+ type: "data",
24
+ suffix: ".car",
25
+ },
26
+ {
27
+ type: "wal",
28
+ suffix: ".json",
29
+ },
30
+ {
31
+ type: "meta",
32
+ suffix: ".json",
33
+ },
34
+ ];
35
+ it("getfilename plain", () => {
36
+ for (const store of storeOpts) {
37
+ const url = URI.from(`file://./x/path?store=${store.type}&name=name&key=key&version=version`);
38
+ expect(rt.getFileName(url, logger)).toEqual(`${store.type}/key${store.suffix}`);
39
+ }
40
+ });
41
+
42
+ it("getfilename index", () => {
43
+ for (const store of storeOpts) {
44
+ const url = URI.from(`file://./x/path?index=idx&store=${store.type}&name=name&key=key&version=version`);
45
+ expect(rt.getFileName(url, logger)).toEqual(`idx-${store.type}/key${store.suffix}`);
46
+ }
47
+ });
48
+
49
+ it("getstore", () => {
50
+ for (const store of storeOpts) {
51
+ const url = URI.from(`file://./x/path?store=${store.type}&name=name&key=key&version=version`);
52
+ expect(getStore(url, logger, (...toJoin) => toJoin.join("+"))).toEqual({
53
+ name: store.type,
54
+ store: store.type,
55
+ });
56
+ }
57
+ });
58
+
59
+ it("getstore idx", () => {
60
+ for (const store of storeOpts) {
61
+ const url = URI.from(`file://./x/path?index=ix&store=${store.type}&name=name&key=key&version=version`);
62
+ expect(getStore(url, logger, (...toJoin) => toJoin.join("+"))).toEqual({
63
+ name: `ix+${store.type}`,
64
+ store: store.type,
65
+ });
66
+ }
67
+ });
68
+
69
+ it("order timeorderednextid", () => {
70
+ let last = sthis.timeOrderedNextId().str;
71
+ for (let i = 0; i < 10; i++) {
72
+ const id = sthis.timeOrderedNextId().str;
73
+ const x = UUID.parse(id);
74
+ expect(x.getVariant()).toBe("VAR_10");
75
+ assert(id !== last, "id should be greater than last");
76
+ assert(id.slice(0, 13) >= last.slice(0, 13), `id should be greater than last ${id.slice(0, 13)} ${last.slice(0, 13)}`);
77
+ last = id;
78
+ }
79
+ });
80
+ it("timeorderednextid is uuidv7", () => {
81
+ const id = sthis.timeOrderedNextId(0xcafebabebeef).str;
82
+ expect(id.slice(0, 15)).toBe("cafebabe-beef-7");
83
+ });
84
+ });
package/tests/helpers.ts CHANGED
@@ -1,66 +1,12 @@
1
- import { rt } from "@fireproof/core";
1
+ import { LogCollector, 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,34 @@ 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
+ export type MockSuperThis = SuperThis & { logCollector: LogCollector };
41
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
42
+ export function mockSuperThis(sthis?: Partial<SuperThisOpts>): MockSuperThis {
43
+ const mockLog = MockLogger();
44
+ const ethis = ensureSuperThis({
45
+ logger: mockLog.logger,
46
+ ctx: {
47
+ logCollector: mockLog.logCollector,
48
+ },
49
+ }) as MockSuperThis;
50
+ ethis.logCollector = mockLog.logCollector;
51
+ return ethis;
52
+ }
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>Fireproof Test</title>
7
- <script src="./fireproof.iife.js"></script>
7
+ <script src="index.global.js"></script>
8
8
  <script type="text/javascript">
9
9
  function todoApp() {
10
10
  const actorTag = Math.random().toString(36).substring(2, 7);
@@ -4,13 +4,13 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>Fireproof Test</title>
7
- <script src="./fireproof.iife.js"></script>
8
- <script src="./connect-partykit.iife.js"></script>
7
+ <script src="index.global.js"></script>
8
+ <script src="partykit.global.js"></script>
9
9
  <script type="text/javascript">
10
10
  function todoApp() {
11
11
  const actorTag = Math.random().toString(36).substring(2, 7);
12
12
  const { fireproof, index } = Fireproof;
13
- const { connect } = FireproofConnect;
13
+ const { connect } = Connect;
14
14
 
15
15
  // console.log('connect', connect)
16
16
 
@@ -38,10 +38,11 @@
38
38
  } else {
39
39
  dbName = name;
40
40
  db = fireproof(name, { autoCompact: 100, threshold: 50000 });
41
- cx = connect.partykitRest(db);
42
- cx.ready.then(async () => {
41
+ cx = connect(db);
42
+ cx.loaded.then(async () => {
43
43
  const span = document.querySelector("#cxInfo");
44
- span.innerText = `📡 ${cx.party.id}`;
44
+ console.log("cx", cx);
45
+ span.innerText = `📡 ${cx.url.toString()}`;
45
46
  });
46
47
  }
47
48
 
@@ -52,7 +53,7 @@
52
53
  if (changes.clock.length > 0) {
53
54
  input.disabled = false;
54
55
  } else {
55
- cx.ready.then(async () => {
56
+ cx.loaded.then(async () => {
56
57
  input.disabled = false;
57
58
  });
58
59
  }
@@ -75,16 +76,12 @@
75
76
  let compactor = "🚗";
76
77
  function drawInfo() {
77
78
  document.querySelector("#carLog").innerText =
78
- ` ⏰ ${db._crdt.clock.head.length} ${compactor} ${cx.loader.carLog.length} 📩 ${cx.loader.remoteWAL.walState.operations.length}`;
79
+ ` ⏰ ${db._crdt.clock.head.length} ${compactor} ${cx.loader.carLog.length} 📩 ${1}`;
79
80
  }
80
81
  const doRedraw = async () => {
81
82
  drawInfo();
82
83
  const result = await db.allDocs().catch((e) => {
83
- console.error(
84
- "allDocs error",
85
- e,
86
- ` ⏰ ${db._crdt.clock.head.length} ${compactor} ${cx.loader.carLog.length} 📩 ${cx.loader.remoteWAL.walState.operations.length}`,
87
- );
84
+ console.error("allDocs error", e, ` ⏰ ${db._crdt.clock.head.length} ${compactor} ${cx.loader.carLog.length} 📩 ${1}`);
88
85
  return { rows: [] };
89
86
  });
90
87
  drawInfo();
@@ -166,8 +163,8 @@
166
163
  const goWorker = (dcs) => {
167
164
  const timeout =
168
165
  10 +
169
- Math.pow(db._crdt.clock.head.length + cx.loader.remoteWAL.walState.operations.length, 2) *
170
- (Math.floor(Math.random() * 1000) + 1000);
166
+ Math.pow(db._crdt.clock.head.length + cx.loader.taskManager.queue.length, 2) *
167
+ (Math.floor(Math.random() * 2000) + 2000);
171
168
  // console.log('go worker', timeout/ 1000)
172
169
  worker = setTimeout(async () => {
173
170
  await Promise.all(
@@ -0,0 +1,14 @@
1
+ import {
2
+ getFileName,
3
+ getFileSystem,
4
+ getPath,
5
+ toArrayBuffer
6
+ } from "./chunk-WS3YRPIA.js";
7
+ import "./chunk-OFGPKRCM.js";
8
+ export {
9
+ getFileName,
10
+ getFileSystem,
11
+ getPath,
12
+ toArrayBuffer
13
+ };
14
+ //# sourceMappingURL=utils-QO2HIWGI.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}