@fireproof/core-test 0.23.3 → 0.23.5

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.
@@ -0,0 +1,65 @@
1
+
2
+ describe("FPEnvelope", () => {
3
+ // const sthis = mockSuperThis();
4
+ // it("unknown bytes", () => {
5
+ // expect(bs.FPMsgMatch2Envelope(Uint8Array.from([1, 2, 3]), "bla").Err().message).toStrictEqual(
6
+ // "failed to decode envelope: Error: CBOR decode error: too many terminals, data makes no sense"
7
+ // );
8
+ // });
9
+
10
+ // it("unknown type", () => {
11
+ // expect(bs.FPMsgMatch2Envelope(encode({ type: "blax", payload: 4 }), "bla"))
12
+ // .toStrictEqual(Result.Err("expected type to be bla"));
13
+ // })
14
+
15
+ // it("no type", () => {
16
+ // expect(bs.FPMsgMatch2Envelope(encode({ type: "blax", payload: 4 })))
17
+ // .toStrictEqual(Result.Ok({ type: "blax", payload: 4 }));
18
+ // })
19
+
20
+ // it("car type", () => {
21
+ // expect(bs.FPMsg2Car(bs.Car2FPMsg(Uint8Array.from([1, 2, 3])).Ok().payload).Ok()).toStrictEqual(Uint8Array.from([1, 2, 3]));
22
+ // })
23
+
24
+ // it("file type", () => {
25
+ // expect(bs.FPMsg2File(bs.File2FPMsg(Uint8Array.from([1, 2, 3])).Ok().payload).Ok()).toStrictEqual(Uint8Array.from([1, 2, 3]));
26
+ // })
27
+
28
+ // it("meta type", async () => {
29
+ // const ref = {
30
+ // eventCid: await simpleCID(sthis),
31
+ // dbMeta: {
32
+ // cars: [
33
+ // await simpleCID(sthis)
34
+ // ]
35
+ // },
36
+ // parents: [
37
+ // await simpleCID(sthis),
38
+ // await simpleCID(sthis)
39
+ // ]
40
+ // } satisfies DbMetaEvent;
41
+ // expect(bs.FPMsg2Meta(bs.Meta2FPMsg([ref])).Ok()).toEqual(ref);
42
+ // })
43
+
44
+ // it("wal type", () => {
45
+ // const ref: bs.WALState = {
46
+ // fileOperations: [],
47
+ // noLoaderOps: [],
48
+ // operations: [
49
+ // {
50
+ // cars: [
51
+ // CID.parse("bag4yvqabciqdzvfxrxfi6feubspyz666zegmp3z5w556mr4ykya2kkdm22r7pyy")
52
+ // ]
53
+ // },
54
+ // {
55
+ // cars: [
56
+ // CID.parse("bag4yvqabciqd2ul2tw4mdcpvfq2pdqhvnqp2ktuyrtcl3j3gwhxbjzjt62xzeaq")
57
+ // ]
58
+ // }
59
+ // ]
60
+ // };
61
+ // const res = bs.FPMsg2WAL(bs.WAL2FPMsg(sthis, ref).Ok()).Ok();
62
+ // expect(res).toStrictEqual(ref);
63
+ // expect(res.operations[0].cars[0].version).toStrictEqual(1);
64
+ // })
65
+ })
@@ -0,0 +1,106 @@
1
+ import { Result, URI } from "@adviser/cement";
2
+ import { bs, ensureSuperThis } from "@fireproof/core";
3
+
4
+ class TraceGateway implements bs.Gateway {
5
+ readonly buildUrlFn = vitest.fn();
6
+
7
+ readonly fragSize: number;
8
+ constructor(fragSize = 0) {
9
+ this.fragSize = fragSize;
10
+ }
11
+
12
+ buildUrl(baseUrl: URI, key: string): Promise<Result<URI>> {
13
+ this.buildUrlFn(baseUrl, key);
14
+ return Promise.resolve(Result.Ok(baseUrl.build().setParam("key", key).URI()));
15
+ }
16
+ readonly startFn = vitest.fn();
17
+ start(baseUrl: URI): Promise<Result<URI>> {
18
+ this.startFn(baseUrl);
19
+ const burl = baseUrl.build();
20
+ if (this.fragSize) {
21
+ burl.setParam("fragSize", this.fragSize.toString());
22
+ }
23
+ return Promise.resolve(Result.Ok(burl.URI()));
24
+ }
25
+ readonly closeFn = vitest.fn();
26
+ close(baseUrl: URI): Promise<bs.VoidResult> {
27
+ this.closeFn(baseUrl);
28
+ return Promise.resolve(Result.Ok(undefined));
29
+ }
30
+ readonly destroyFn = vitest.fn();
31
+ destroy(baseUrl: URI): Promise<bs.VoidResult> {
32
+ this.destroyFn(baseUrl);
33
+ return Promise.resolve(Result.Ok(undefined));
34
+ }
35
+ readonly getFn = vitest.fn();
36
+ putCalls = 0;
37
+ async get(url: URI): Promise<Result<Uint8Array>> {
38
+ const idx = this.putCalls++;
39
+ this.getFn(url);
40
+ return Result.Ok(this.putFn.mock.calls[idx][1]);
41
+ }
42
+ readonly putFn = vitest.fn();
43
+ async put(url: URI, data: Uint8Array): Promise<Result<void>> {
44
+ this.putFn(url, data);
45
+ return Result.Ok(undefined);
46
+ }
47
+ readonly deleteFn = vitest.fn();
48
+ async delete(url: URI): Promise<Result<void>> {
49
+ this.deleteFn(url);
50
+ return Result.Ok(undefined);
51
+ }
52
+ }
53
+
54
+ describe("FragmentGateway", () => {
55
+ const sthis = ensureSuperThis();
56
+ it("passthrough", async () => {
57
+ const innerGW = new TraceGateway();
58
+ const fgw = new bs.FragmentGateway(sthis, innerGW);
59
+ const url = URI.from("http://example.com?key=3333");
60
+
61
+ expect(await fgw.put(url, new Uint8Array([1, 2, 3, 4]))).toEqual(Result.Ok(undefined));
62
+ expect(innerGW.putFn).toHaveBeenCalledWith(url, new Uint8Array([1, 2, 3, 4]));
63
+
64
+ expect(await fgw.get(url)).toEqual(Result.Ok(new Uint8Array([1, 2, 3, 4])));
65
+ expect(innerGW.getFn).toHaveBeenCalledWith(url);
66
+ });
67
+
68
+ function slice(total: number, headerSize: number, fragSize: number): { len?: string; ofs: string }[] {
69
+ const res = [];
70
+ for (let ofs = 0; ofs < total; ofs += fragSize - headerSize) {
71
+ res.push({ len: total.toString(), ofs: ofs.toString() });
72
+ }
73
+ return res;
74
+ }
75
+
76
+ it("enable frag", async () => {
77
+ const innerGW = new TraceGateway(128);
78
+ const fgw = new bs.FragmentGateway(sthis, innerGW);
79
+ const url = (await fgw.start(URI.from("http://example.com?key=3333"))).Ok();
80
+ const buf = new Uint8Array(1024).fill(1).map((_, i) => i);
81
+
82
+ expect(await fgw.put(url, buf)).toEqual(Result.Ok(undefined));
83
+
84
+ const ref = slice(1024, fgw.headerSize, 128);
85
+
86
+ expect(
87
+ innerGW.putFn.mock.calls.map((i) => {
88
+ return {
89
+ len: i[0].getParam("len"),
90
+ ofs: i[0].getParam("ofs"),
91
+ };
92
+ }),
93
+ ).toEqual(ref);
94
+
95
+ expect((await fgw.get(url)).Ok()).toEqual(buf);
96
+ ref[0].len = undefined;
97
+ expect(
98
+ innerGW.getFn.mock.calls.map((i) => {
99
+ return {
100
+ len: i[0].getParam("len"),
101
+ ofs: i[0].getParam("ofs"),
102
+ };
103
+ }),
104
+ ).toEqual(ref);
105
+ });
106
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fireproof/core-test",
3
- "version": "0.23.3",
3
+ "version": "0.23.5",
4
4
  "description": "Live ledger for the web.",
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -34,33 +34,33 @@
34
34
  "react": ">=18.0.0"
35
35
  },
36
36
  "dependencies": {
37
- "@adviser/cement": "^0.4.23",
38
- "@fireproof/core": "0.23.3",
39
- "@fireproof/core-base": "0.23.3",
40
- "@fireproof/core-blockstore": "0.23.3",
41
- "@fireproof/core-gateways-base": "0.23.3",
42
- "@fireproof/core-gateways-file": "0.23.3",
43
- "@fireproof/core-gateways-indexeddb": "0.23.3",
44
- "@fireproof/core-gateways-memory": "0.23.3",
45
- "@fireproof/core-keybag": "0.23.3",
46
- "@fireproof/core-protocols-cloud": "0.23.3",
47
- "@fireproof/core-runtime": "0.23.3",
48
- "@fireproof/core-types-base": "0.23.3",
49
- "@fireproof/core-types-blockstore": "0.23.3",
50
- "@fireproof/core-types-protocols-cloud": "0.23.3",
51
- "@fireproof/core-types-runtime": "0.23.3",
52
- "@fireproof/vendor": "0.23.3",
37
+ "@adviser/cement": "^0.4.25",
38
+ "@fireproof/core": "0.23.5",
39
+ "@fireproof/core-base": "0.23.5",
40
+ "@fireproof/core-blockstore": "0.23.5",
41
+ "@fireproof/core-gateways-base": "0.23.5",
42
+ "@fireproof/core-gateways-file": "0.23.5",
43
+ "@fireproof/core-gateways-indexeddb": "0.23.5",
44
+ "@fireproof/core-gateways-memory": "0.23.5",
45
+ "@fireproof/core-keybag": "0.23.5",
46
+ "@fireproof/core-protocols-cloud": "0.23.5",
47
+ "@fireproof/core-runtime": "0.23.5",
48
+ "@fireproof/core-types-base": "0.23.5",
49
+ "@fireproof/core-types-blockstore": "0.23.5",
50
+ "@fireproof/core-types-protocols-cloud": "0.23.5",
51
+ "@fireproof/core-types-runtime": "0.23.5",
52
+ "@fireproof/vendor": "0.23.5",
53
53
  "@ipld/car": "^5.4.2",
54
54
  "@ipld/dag-cbor": "^9.2.4",
55
55
  "@ipld/dag-json": "^10.2.5",
56
- "@types/node": "^24.1.0",
56
+ "@types/node": "^24.3.0",
57
57
  "cborg": "^4.2.12",
58
58
  "charwise": "^3.0.1",
59
- "use-fireproof": "0.23.3",
59
+ "use-fireproof": "0.23.5",
60
60
  "uuidv7": "^1.0.2"
61
61
  },
62
62
  "devDependencies": {
63
- "@fireproof/core-cli": "0.23.3",
63
+ "@fireproof/core-cli": "0.23.5",
64
64
  "@vitest/browser": "^3.2.4",
65
65
  "playwright": "^1.54.1",
66
66
  "playwright-chromium": "^1.54.1",
package/tsconfig.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "extends": [
3
+ "/home/runner/work/fireproof/fireproof/tsconfig.dist.json"
4
+ ],
5
+ "compilerOptions": {
6
+ "outDir": "../npm/",
7
+ "noEmit": false
8
+ },
9
+ "include": [
10
+ "**/*"
11
+ ],
12
+ "exclude": [
13
+ "node_modules",
14
+ "dist",
15
+ ".git",
16
+ ".vscode"
17
+ ]
18
+ }