@anaemia/core 0.3.2 → 0.3.4
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.
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/config.ts +1 -1
- package/test/rpc-client.test.mjs +71 -0
package/dist/config.d.ts
CHANGED
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,aAAa,CAAC;IAE9D;;OAEG;IACH,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,aAAa,CAAC;IAE9D;;OAEG;IACH,YAAY,CAAC,EAAE;QACb,MAAM,CAAC,EAAE,UAAU,EAAE,CAAC;QACtB,MAAM,CAAC,EAAE,UAAU,EAAE,CAAC;KACvB,CAAC;IAEF;;OAEG;IACH,eAAe,CAAC,EAAE,CAAC,GAAG,EAAE,IAAI,KAAK,IAAI,CAAC;IAEtC;;OAEG;IACH,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC5D;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE;QACP,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;IACF,MAAM,CAAC,EAAE;QACP,IAAI,CAAC,EAAE,OAAO,CAAC;QACf,OAAO,CAAC,EAAE,OAAO,CAAC;KACnB,CAAC;IACF,YAAY,CAAC,EAAE;QACb,YAAY,CAAC,EAAE,OAAO,CAAC;KACxB,CAAC;IAEF;;OAEG;IACH,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC;IAE1B;;;;;;;;MAQE;IACF,MAAM,CAAC,EAAE;QACP,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAChC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACjC,CAAC;CACH;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,aAAa,CAEjE"}
|
package/package.json
CHANGED
package/src/config.ts
CHANGED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { $$executeClientRpc } from "../dist/runtime/rpc-client.js";
|
|
4
|
+
|
|
5
|
+
test("$$executeClientRpc returns a callable function with correct id", () => {
|
|
6
|
+
const fn = $$executeClientRpc("myFn");
|
|
7
|
+
assert.equal(typeof fn, "function");
|
|
8
|
+
assert.equal(fn.id, "myFn");
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test("$$executeClientRpc has readHydrationCache method", () => {
|
|
12
|
+
const fn = $$executeClientRpc("myFn");
|
|
13
|
+
assert.equal(typeof fn.readHydrationCache, "function");
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test("readHydrationCache returns undefined when no cache exists", () => {
|
|
17
|
+
const fn = $$executeClientRpc("noCache");
|
|
18
|
+
const result = fn.readHydrationCache("someArg");
|
|
19
|
+
assert.equal(result, undefined);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test("readHydrationCache reads from SSR store on server", async () => {
|
|
23
|
+
const store = new Map();
|
|
24
|
+
store.set("__SERVER_FUNCTION_DATA__", {
|
|
25
|
+
greet: { '["Ada"]': "hello Ada" },
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const { ssrStorage } = await import("../dist/runtime/context.js");
|
|
29
|
+
const fn = $$executeClientRpc("greet");
|
|
30
|
+
|
|
31
|
+
await ssrStorage.run(store, async () => {
|
|
32
|
+
const result = fn.readHydrationCache("Ada");
|
|
33
|
+
assert.equal(result, "hello Ada");
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test("findLooseCacheMatch falls back to prefix match", async () => {
|
|
38
|
+
const store = new Map();
|
|
39
|
+
store.set("__SERVER_FUNCTION_DATA__", {
|
|
40
|
+
greet: { '["Ada", "extra"]': "hello Ada" },
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const { ssrStorage } = await import("../dist/runtime/context.js");
|
|
44
|
+
const fn = $$executeClientRpc("greet");
|
|
45
|
+
|
|
46
|
+
await ssrStorage.run(store, async () => {
|
|
47
|
+
const result = fn.readHydrationCache("Ada");
|
|
48
|
+
assert.equal(result, "hello Ada");
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("asyncRpcCall reads from SSR store and returns cached result on server", async () => {
|
|
53
|
+
const store = new Map();
|
|
54
|
+
store.set("__SERVER_FUNCTION_DATA__", {
|
|
55
|
+
getData: { '["key1"]': { value: 42 } },
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const { ssrStorage } = await import("../dist/runtime/context.js");
|
|
59
|
+
const fn = $$executeClientRpc("getData");
|
|
60
|
+
|
|
61
|
+
await ssrStorage.run(store, async () => {
|
|
62
|
+
const result = await fn("key1");
|
|
63
|
+
assert.deepEqual(result, { value: 42 });
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("asyncRpcCall returns undefined when no SSR store exists", async () => {
|
|
68
|
+
const fn = $$executeClientRpc("missing");
|
|
69
|
+
const result = await fn("someArg");
|
|
70
|
+
assert.equal(result, undefined);
|
|
71
|
+
});
|