@cardonjs/cache 0.0.0-stage → 0.0.0
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/LICENSE +21 -0
- package/README.md +414 -2
- package/dist/cache.d.ts +136 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +503 -0
- package/dist/cache.js.map +1 -0
- package/dist/contract.d.ts +26 -0
- package/dist/contract.d.ts.map +1 -0
- package/dist/contract.js +158 -0
- package/dist/contract.js.map +1 -0
- package/dist/duration.d.ts +13 -0
- package/dist/duration.d.ts.map +1 -0
- package/dist/duration.js +21 -0
- package/dist/duration.js.map +1 -0
- package/dist/envelope.d.ts +21 -0
- package/dist/envelope.d.ts.map +1 -0
- package/dist/envelope.js +89 -0
- package/dist/envelope.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/keys.d.ts +35 -0
- package/dist/keys.d.ts.map +1 -0
- package/dist/keys.js +88 -0
- package/dist/keys.js.map +1 -0
- package/dist/store.d.ts +26 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +2 -0
- package/dist/store.js.map +1 -0
- package/dist/testing.d.ts +16 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +44 -0
- package/dist/testing.js.map +1 -0
- package/llms.txt +210 -0
- package/package.json +61 -3
package/dist/contract.js
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shared contract every `CacheStore` must pass. Import it from `@cardonjs/cache/contract` in
|
|
3
|
+
* the store's tests (it needs `@cardonjs/testing`) and run each case with the store's own runner
|
|
4
|
+
* against a harness over a real store (e.g. a KV namespace from Miniflare).
|
|
5
|
+
*
|
|
6
|
+
* The cases check what `createCache` relies on: a string comes back exactly as it was stored, a
|
|
7
|
+
* missing key is `undefined`, `set` overwrites, `delete` removes, keys are compared exactly, and
|
|
8
|
+
* any `ttlSeconds` from 1 second to 60 days is accepted (a store may keep an entry longer than
|
|
9
|
+
* asked, e.g. KV's 60-second minimum, because `createCache` checks every entry's own expiry).
|
|
10
|
+
* Expiry itself is not checked: a store may keep an entry past its time.
|
|
11
|
+
*
|
|
12
|
+
* Two rules no case can check from outside, which every store must still follow:
|
|
13
|
+
*
|
|
14
|
+
* - **Keep a key at least `ttlSeconds`.** Evicting earlier only costs misses (a tag whose version
|
|
15
|
+
* is gone makes its entries misses), but it costs them.
|
|
16
|
+
* - **Reject from `set` and `delete` whenever the write did not happen.** A store that swallows
|
|
17
|
+
* its own errors makes `invalidateTags` resolve with nothing written, so stale entries stay.
|
|
18
|
+
*/
|
|
19
|
+
import { defineContract, fail } from "@cardonjs/testing";
|
|
20
|
+
/** Calls `run` and reports how it settled; a synchronous throw counts as a rejection. */
|
|
21
|
+
async function settle(run) {
|
|
22
|
+
try {
|
|
23
|
+
return { ok: true, value: await run() };
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
return { ok: false, error };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function describeError(error) {
|
|
30
|
+
return error instanceof Error ? `${error.name}: ${error.message}` : String(error);
|
|
31
|
+
}
|
|
32
|
+
function show(value) {
|
|
33
|
+
if (typeof value !== "string")
|
|
34
|
+
return `${typeof value} ${String(value)}`;
|
|
35
|
+
return value.length > 80
|
|
36
|
+
? `a string of ${value.length} characters starting ${JSON.stringify(value.slice(0, 40))}`
|
|
37
|
+
: JSON.stringify(value);
|
|
38
|
+
}
|
|
39
|
+
async function mustSet(store, key, value, ttl, what) {
|
|
40
|
+
const result = await settle(() => store.set(key, value, ttl));
|
|
41
|
+
if (!result.ok)
|
|
42
|
+
fail(`set must accept ${what}`, [`rejected with ${describeError(result.error)}`]);
|
|
43
|
+
}
|
|
44
|
+
async function expectValue(store, key, expected, title) {
|
|
45
|
+
const result = await settle(() => store.get(key));
|
|
46
|
+
if (!result.ok)
|
|
47
|
+
fail(title, [`get rejected with ${describeError(result.error)}`]);
|
|
48
|
+
if (result.value !== expected) {
|
|
49
|
+
fail(title, [`expected ${show(expected)}`, `got ${show(result.value)}`]);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/** Printable ASCII without spaces, as `createCache` builds keys. */
|
|
53
|
+
const PUNCTUATION = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
|
|
54
|
+
/** The longest store key `createCache` builds: a 64-character namespace, `:e:`, 200 characters. */
|
|
55
|
+
const LONGEST_KEY = `${"n".repeat(64)}:e:${`${PUNCTUATION}k`.repeat(200)}`.slice(0, 267);
|
|
56
|
+
const VALUES = [
|
|
57
|
+
["an envelope", '{"v":1,"expiresAt":1764201600000,"tags":[],"value":{"a":[1,null,"x"]}}'],
|
|
58
|
+
["non-ASCII text", "héllo, cardón ✓ 🌵 日本語"],
|
|
59
|
+
["quotes, backslashes and line breaks", 'a "b" \\ c\n\td\r\n'],
|
|
60
|
+
["a 128 KiB string", "x".repeat(128 * 1024)],
|
|
61
|
+
];
|
|
62
|
+
export const cacheStoreContract = defineContract([
|
|
63
|
+
{
|
|
64
|
+
name: "get of a key that was never set resolves undefined (not null)",
|
|
65
|
+
run: async (h) => {
|
|
66
|
+
const store = await h.create();
|
|
67
|
+
await expectValue(store, "ns:e:missing", undefined, "get of a missing key");
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: "set then get returns the same string",
|
|
72
|
+
run: async (h) => {
|
|
73
|
+
const store = await h.create();
|
|
74
|
+
for (const [what, value] of VALUES) {
|
|
75
|
+
const key = `ns:e:${what.replaceAll(" ", "-")}`;
|
|
76
|
+
await mustSet(store, key, value, 300, what);
|
|
77
|
+
await expectValue(store, key, value, `get must return ${what} exactly as it was set`);
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: "set overwrites the previous value",
|
|
83
|
+
run: async (h) => {
|
|
84
|
+
const store = await h.create();
|
|
85
|
+
await mustSet(store, "ns:t:products", "first", 300, "a first value");
|
|
86
|
+
await mustSet(store, "ns:t:products", "second", 300, "a second value for the same key");
|
|
87
|
+
await expectValue(store, "ns:t:products", "second", "get after a second set");
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: "delete removes the value, and a missing key deletes without error",
|
|
92
|
+
run: async (h) => {
|
|
93
|
+
const store = await h.create();
|
|
94
|
+
await mustSet(store, "ns:e:a", "value", 300, "a value");
|
|
95
|
+
await mustSet(store, "ns:e:b", "other", 300, "another value");
|
|
96
|
+
const deleted = await settle(() => store.delete("ns:e:a"));
|
|
97
|
+
if (!deleted.ok)
|
|
98
|
+
fail("delete must resolve", [describeError(deleted.error)]);
|
|
99
|
+
await expectValue(store, "ns:e:a", undefined, "get after delete");
|
|
100
|
+
await expectValue(store, "ns:e:b", "other", "delete must remove only its key");
|
|
101
|
+
const again = await settle(() => store.delete("ns:e:a"));
|
|
102
|
+
if (!again.ok)
|
|
103
|
+
fail("delete of a missing key must resolve", [describeError(again.error)]);
|
|
104
|
+
const never = await settle(() => store.delete("ns:e:never-set"));
|
|
105
|
+
if (!never.ok)
|
|
106
|
+
fail("delete of a key never set must resolve", [describeError(never.error)]);
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: "keys are compared exactly (no prefix match, case folding or decoding)",
|
|
111
|
+
run: async (h) => {
|
|
112
|
+
const store = await h.create();
|
|
113
|
+
const stored = ["ns:e:a", "ns:e:A", "ns:e:a:b", "ns:e:a%3Ab", "ns:t:a", "ns2:e:a"];
|
|
114
|
+
for (const key of stored)
|
|
115
|
+
await mustSet(store, key, `value of ${key}`, 300, "a value");
|
|
116
|
+
for (const key of stored) {
|
|
117
|
+
await expectValue(store, key, `value of ${key}`, `each key must keep its own value`);
|
|
118
|
+
}
|
|
119
|
+
await expectValue(store, "ns:e:a ", undefined, "a key with a trailing space is another key");
|
|
120
|
+
await expectValue(store, "ns:e:", undefined, "a prefix of a stored key is another key");
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
name: "any ttlSeconds from 1 second to 60 days is accepted and the value is readable at once",
|
|
125
|
+
run: async (h) => {
|
|
126
|
+
const store = await h.create();
|
|
127
|
+
for (const ttl of [1, 10, 59, 60, 61, 86_400, 30 * 86_400, 60 * 86_400]) {
|
|
128
|
+
const key = `ns:e:ttl-${ttl}`;
|
|
129
|
+
await mustSet(store, key, `ttl ${ttl}`, ttl, `a ttl of ${ttl} seconds`);
|
|
130
|
+
await expectValue(store, key, `ttl ${ttl}`, `get right after a set with a ttl of ${ttl}`);
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
name: "the longest key createCache builds (267 printable ASCII characters) works",
|
|
136
|
+
run: async (h) => {
|
|
137
|
+
const store = await h.create();
|
|
138
|
+
if (LONGEST_KEY.length !== 267)
|
|
139
|
+
fail("the contract's own key is wrong", []);
|
|
140
|
+
await mustSet(store, LONGEST_KEY, "long", 300, "a 267-character key");
|
|
141
|
+
await expectValue(store, LONGEST_KEY, "long", "get of a 267-character key");
|
|
142
|
+
const deleted = await settle(() => store.delete(LONGEST_KEY));
|
|
143
|
+
if (!deleted.ok)
|
|
144
|
+
fail("delete of a 267-character key", [describeError(deleted.error)]);
|
|
145
|
+
await expectValue(store, LONGEST_KEY, undefined, "get after deleting a 267-character key");
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
name: "a value over 1 MiB (the default value cap plus its envelope) round-trips",
|
|
150
|
+
run: async (h) => {
|
|
151
|
+
const store = await h.create();
|
|
152
|
+
const value = `${"é".repeat(512 * 1024)}${"x".repeat(8 * 1024)}`; // 1 MiB + 8 KiB of UTF-8
|
|
153
|
+
await mustSet(store, "ns:e:large", value, 300, "a value of 1 MiB and 8 KiB");
|
|
154
|
+
await expectValue(store, "ns:e:large", value, "get of a value of 1 MiB and 8 KiB");
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
]);
|
|
158
|
+
//# sourceMappingURL=contract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EAAqB,cAAc,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAY5E,yFAAyF;AACzF,KAAK,UAAU,MAAM,CAAC,GAAkB;IACtC,IAAI,CAAC;QACH,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,EAAE,EAAE,CAAC;IAC1C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IAC9B,CAAC;AACH,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACpF,CAAC;AAED,SAAS,IAAI,CAAC,KAAc;IAC1B,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,GAAG,OAAO,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;IACzE,OAAO,KAAK,CAAC,MAAM,GAAG,EAAE;QACtB,CAAC,CAAC,eAAe,KAAK,CAAC,MAAM,wBAAwB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE;QACzF,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAC5B,CAAC;AAED,KAAK,UAAU,OAAO,CACpB,KAAiB,EACjB,GAAW,EACX,KAAa,EACb,GAAW,EACX,IAAY;IAEZ,MAAM,MA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AM,OAAO,CAAC,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,GAAG,EAAE,4BAA4B,CAAC,CAAC;YAC7E,MAAM,WAAW,CAAC,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,mCAAmC,CAAC,CAAC;QACrF,CAAC;KACF;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A length of time: whole seconds as a number, or a string of a whole number and a unit,
|
|
3
|
+
* `s` (seconds), `m` (minutes), `h` (hours) or `d` (days), e.g. `"5m"` or `"1d"`.
|
|
4
|
+
* The same grammar as `@cardonjs/access-tokens`, `@cardonjs/storage` and `@cardonjs/audit`
|
|
5
|
+
* (mirrored, not imported: none is a dependency of this package).
|
|
6
|
+
*/
|
|
7
|
+
export type Duration = number | `${number}${"s" | "m" | "h" | "d"}`;
|
|
8
|
+
/**
|
|
9
|
+
* The seconds of a {@link Duration}, or `undefined` when it is not one: a number must be a
|
|
10
|
+
* positive safe integer; a string has no sign, spaces, decimals or leading zeros.
|
|
11
|
+
*/
|
|
12
|
+
export declare function durationSeconds(value: unknown): number | undefined;
|
|
13
|
+
//# sourceMappingURL=duration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duration.d.ts","sourceRoot":"","sources":["../src/duration.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,GAAG,MAAM,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,EAAE,CAAC;AAKpE;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAWlE"}
|
package/dist/duration.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const DURATION = /^([1-9][0-9]{0,8})([smhd])$/;
|
|
2
|
+
const UNIT_SECONDS = { s: 1, m: 60, h: 3_600, d: 86_400 };
|
|
3
|
+
/**
|
|
4
|
+
* The seconds of a {@link Duration}, or `undefined` when it is not one: a number must be a
|
|
5
|
+
* positive safe integer; a string has no sign, spaces, decimals or leading zeros.
|
|
6
|
+
*/
|
|
7
|
+
export function durationSeconds(value) {
|
|
8
|
+
if (typeof value === "number") {
|
|
9
|
+
return Number.isSafeInteger(value) && value > 0 ? value : undefined;
|
|
10
|
+
}
|
|
11
|
+
if (typeof value !== "string")
|
|
12
|
+
return undefined;
|
|
13
|
+
const match = DURATION.exec(value);
|
|
14
|
+
const amount = match?.[1];
|
|
15
|
+
const unit = match?.[2];
|
|
16
|
+
if (amount === undefined || unit === undefined)
|
|
17
|
+
return undefined;
|
|
18
|
+
const seconds = Number(amount) * (UNIT_SECONDS[unit] ?? 0);
|
|
19
|
+
return Number.isSafeInteger(seconds) && seconds > 0 ? seconds : undefined;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=duration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duration.js","sourceRoot":"","sources":["../src/duration.ts"],"names":[],"mappings":"AAQA,MAAM,QAAQ,GAAG,6BAA6B,CAAC;AAC/C,MAAM,YAAY,GAAqC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC;AAE5F;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IACtE,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IAChD,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnC,MAAM,MAAM,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;IAC1B,MAAM,IAAI,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;IACxB,IAAI,MAAM,KAAK,SAAS,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACjE,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC3D,OAAO,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;AAC5E,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** The envelope's format version. An envelope with another one is a miss. */
|
|
2
|
+
export declare const FORMAT_VERSION = 1;
|
|
3
|
+
/** Most tags on one entry. */
|
|
4
|
+
export declare const MAX_TAGS = 8;
|
|
5
|
+
/** A tag version as `invalidateTags` writes it: 128 random bits in lowercase hex. */
|
|
6
|
+
export declare const VERSION_PATTERN: RegExp;
|
|
7
|
+
export type TagPair = readonly [tag: string, version: string];
|
|
8
|
+
export interface Envelope {
|
|
9
|
+
readonly expiresAt: number;
|
|
10
|
+
readonly tags: readonly TagPair[];
|
|
11
|
+
readonly value: unknown;
|
|
12
|
+
}
|
|
13
|
+
/** `JSON.parse` without `__proto__` keys, or `undefined` when `text` is not JSON. Never throws. */
|
|
14
|
+
export declare function parseJson(text: string): {
|
|
15
|
+
readonly value: unknown;
|
|
16
|
+
} | undefined;
|
|
17
|
+
/** The envelope text for a value already serialized to JSON (`valueJson`). */
|
|
18
|
+
export declare function encodeEnvelope(valueJson: string, expiresAt: number, tags: readonly TagPair[]): string;
|
|
19
|
+
/** The envelope in `text`, or `undefined` for anything else. Never throws. */
|
|
20
|
+
export declare function decodeEnvelope(text: unknown): Envelope | undefined;
|
|
21
|
+
//# sourceMappingURL=envelope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../src/envelope.ts"],"names":[],"mappings":"AAoBA,6EAA6E;AAC7E,eAAO,MAAM,cAAc,IAAI,CAAC;AAChC,8BAA8B;AAC9B,eAAO,MAAM,QAAQ,IAAI,CAAC;AAC1B,qFAAqF;AACrF,eAAO,MAAM,eAAe,QAAmB,CAAC;AAEhD,MAAM,MAAM,OAAO,GAAG,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;AAE9D,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,SAAS,OAAO,EAAE,CAAC;IAClC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAQD,mGAAmG;AACnG,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG,SAAS,CAO/E;AAED,8EAA8E;AAC9E,wBAAgB,cAAc,CAC5B,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,SAAS,OAAO,EAAE,GACvB,MAAM,CAER;AAuBD,8EAA8E;AAC9E,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,GAAG,QAAQ,GAAG,SAAS,CAiBlE"}
|
package/dist/envelope.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The envelope `createCache` stores around a value:
|
|
3
|
+
*
|
|
4
|
+
* ```json
|
|
5
|
+
* {"v":1,"expiresAt":1764201600000,"tags":[["products","<32 hex>"],["menu","<32 hex>"]],"value":...}
|
|
6
|
+
* ```
|
|
7
|
+
*
|
|
8
|
+
* `expiresAt` is epoch milliseconds; `tags` pairs each tag with the version it had when the entry
|
|
9
|
+
* was computed (always a version string: a pair with `null` or anything else is a miss, so a
|
|
10
|
+
* tag whose version the store lost never matches). Tags are pairs, not an object, so a
|
|
11
|
+
* tag named `__proto__` is plain data.
|
|
12
|
+
*
|
|
13
|
+
* What a store returns is untrusted input: anything that is not exactly this shape (not JSON,
|
|
14
|
+
* another format version, missing or extra fields, a bad tag list) decodes to `undefined`, a miss,
|
|
15
|
+
* and decoding never throws. JSON is parsed with every `__proto__` key dropped, so no value the
|
|
16
|
+
* schema later sees can carry one (a schema that copies keys, like `z.record`, would otherwise
|
|
17
|
+
* assign it).
|
|
18
|
+
*/
|
|
19
|
+
import { isValidKey } from "./keys.js";
|
|
20
|
+
/** The envelope's format version. An envelope with another one is a miss. */
|
|
21
|
+
export const FORMAT_VERSION = 1;
|
|
22
|
+
/** Most tags on one entry. */
|
|
23
|
+
export const MAX_TAGS = 8;
|
|
24
|
+
/** A tag version as `invalidateTags` writes it: 128 random bits in lowercase hex. */
|
|
25
|
+
export const VERSION_PATTERN = /^[0-9a-f]{32}$/;
|
|
26
|
+
const FIELDS = ["v", "expiresAt", "tags", "value"];
|
|
27
|
+
function dropProto(key, value) {
|
|
28
|
+
return key === "__proto__" ? undefined : value;
|
|
29
|
+
}
|
|
30
|
+
/** `JSON.parse` without `__proto__` keys, or `undefined` when `text` is not JSON. Never throws. */
|
|
31
|
+
export function parseJson(text) {
|
|
32
|
+
try {
|
|
33
|
+
return { value: JSON.parse(text, dropProto) };
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// Not JSON, or nested deeper than the engine's stack.
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** The envelope text for a value already serialized to JSON (`valueJson`). */
|
|
41
|
+
export function encodeEnvelope(valueJson, expiresAt, tags) {
|
|
42
|
+
return `{"v":${FORMAT_VERSION},"expiresAt":${expiresAt},"tags":${JSON.stringify(tags)},"value":${valueJson}}`;
|
|
43
|
+
}
|
|
44
|
+
function isRecord(value) {
|
|
45
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
46
|
+
}
|
|
47
|
+
function decodeTags(value) {
|
|
48
|
+
if (!Array.isArray(value) || value.length > MAX_TAGS)
|
|
49
|
+
return undefined;
|
|
50
|
+
const seen = new Set();
|
|
51
|
+
const pairs = [];
|
|
52
|
+
for (const pair of value) {
|
|
53
|
+
if (!Array.isArray(pair) || pair.length !== 2)
|
|
54
|
+
return undefined;
|
|
55
|
+
const [tag, version] = pair;
|
|
56
|
+
if (!isValidKey(tag) || seen.has(tag))
|
|
57
|
+
return undefined;
|
|
58
|
+
if (typeof version !== "string" || !VERSION_PATTERN.test(version)) {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
seen.add(tag);
|
|
62
|
+
pairs.push([tag, version]);
|
|
63
|
+
}
|
|
64
|
+
return pairs;
|
|
65
|
+
}
|
|
66
|
+
/** The envelope in `text`, or `undefined` for anything else. Never throws. */
|
|
67
|
+
export function decodeEnvelope(text) {
|
|
68
|
+
if (typeof text !== "string" || text === "")
|
|
69
|
+
return undefined;
|
|
70
|
+
const parsed = parseJson(text);
|
|
71
|
+
if (parsed === undefined || !isRecord(parsed.value))
|
|
72
|
+
return undefined;
|
|
73
|
+
const record = parsed.value;
|
|
74
|
+
const keys = Object.keys(record);
|
|
75
|
+
if (keys.length !== FIELDS.length || !FIELDS.every((field) => Object.hasOwn(record, field))) {
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
if (record.v !== FORMAT_VERSION)
|
|
79
|
+
return undefined;
|
|
80
|
+
const expiresAt = record.expiresAt;
|
|
81
|
+
if (typeof expiresAt !== "number" || !Number.isSafeInteger(expiresAt) || expiresAt <= 0) {
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
const tags = decodeTags(record.tags);
|
|
85
|
+
if (tags === undefined)
|
|
86
|
+
return undefined;
|
|
87
|
+
return { expiresAt, tags, value: record.value };
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=envelope.js.map
|
|
@@ -0,0 +1 @@
|
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I,IAAI,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC;QAC5F,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IAAI,MAAM,CAAC,CAAC,KAAK,cAAc;QAAE,OAAO,SAAS,CAAC;IAClD,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;IACnC,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI,SAAS,IAAI,CAAC,EAAE,CAAC;QACxF,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,IAAI,GAAG,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACrC,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACzC,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;AAClD,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { type Cache, type CacheGetOptions, type CacheOperation, type CacheRememberOptions, type CacheSetOptions, type CacheSetWithSchemaOptions, type CreateCacheOptions, createCache, } from "./cache.js";
|
|
2
|
+
export type { Duration } from "./duration.js";
|
|
3
|
+
export { cacheKey, hashedKeyPart } from "./keys.js";
|
|
4
|
+
export type { CacheStore } from "./store.js";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,KAAK,EACV,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,yBAAyB,EAC9B,KAAK,kBAAkB,EACvB,WAAW,GACZ,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AACpD,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,WAAW,GACZ,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/keys.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keys, tags and namespaces. A key or a tag is 1 to {@link MAX_KEY_LENGTH} printable ASCII
|
|
3
|
+
* characters without spaces; a namespace is shorter and has no `:`, so the store keys built from
|
|
4
|
+
* them (`<namespace>:e:<key>` for an entry, `<namespace>:t:<tag>` for a tag version) never
|
|
5
|
+
* collide across namespaces or between entries and tags. Error messages never include the value:
|
|
6
|
+
* a key may hold an id.
|
|
7
|
+
*/
|
|
8
|
+
/** Longest key or tag, in characters (all ASCII, so also in bytes). */
|
|
9
|
+
export declare const MAX_KEY_LENGTH = 200;
|
|
10
|
+
/** True for a valid key or tag: 1 to 200 printable ASCII characters, no spaces. */
|
|
11
|
+
export declare function isValidKey(value: unknown): value is string;
|
|
12
|
+
/** True for a valid namespace: 1 to 64 of `A-Z a-z 0-9 . _ -`, starting with a letter or digit. */
|
|
13
|
+
export declare function isValidNamespace(value: unknown): value is string;
|
|
14
|
+
/** Throws a `TypeError` (without the value) unless `key` is a valid key. */
|
|
15
|
+
export declare function assertValidKey(key: unknown, where: string): asserts key is string;
|
|
16
|
+
/**
|
|
17
|
+
* Joins `parts` into a key with `:`, percent-encoding each part (`encodeURIComponent`), so a part
|
|
18
|
+
* that holds a `:` cannot make two different lists of parts the same key:
|
|
19
|
+
* `cacheKey("a:b", "c")` is `"a%3Ab:c"` and `cacheKey("a", "b:c")` is `"a:b%3Ac"`.
|
|
20
|
+
*
|
|
21
|
+
* Parts are strings or finite numbers. Throws a `TypeError` for no parts, an empty part, another
|
|
22
|
+
* type, a string with an unpaired surrogate, or a key over 200 characters (after encoding). The
|
|
23
|
+
* message never includes a part.
|
|
24
|
+
*/
|
|
25
|
+
export declare function cacheKey(...parts: readonly (string | number)[]): string;
|
|
26
|
+
/**
|
|
27
|
+
* A fixed-length key part for any text: the SHA-256 of its UTF-8 bytes in lowercase hex (64
|
|
28
|
+
* characters). For parts that come from a request (a search query, a filter) and may be long or
|
|
29
|
+
* hold personal data: `cacheKey("search", await hashedKeyPart(query))` stays within the key limit
|
|
30
|
+
* and keeps the text out of key names. Different texts give different parts (barring a SHA-256
|
|
31
|
+
* collision). Throws a `TypeError` for a non-string or a string with an unpaired surrogate (its
|
|
32
|
+
* UTF-8 would be ambiguous); the message never includes the text.
|
|
33
|
+
*/
|
|
34
|
+
export declare function hashedKeyPart(text: string): Promise<string>;
|
|
35
|
+
//# sourceMappingURL=keys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,uEAAuE;AACvE,eAAO,MAAM,cAAc,MAAM,CAAC;AAKlC,mFAAmF;AACnF,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAO1D;AAED,mGAAmG;AACnG,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAEhE;AAED,4EAA4E;AAC5E,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,IAAI,MAAM,CAOjF;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,GAAG,KAAK,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,GAAG,MAAM,CAyBvE;AAID;;;;;;;GAOG;AACH,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAMjE"}
|
package/dist/keys.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keys, tags and namespaces. A key or a tag is 1 to {@link MAX_KEY_LENGTH} printable ASCII
|
|
3
|
+
* characters without spaces; a namespace is shorter and has no `:`, so the store keys built from
|
|
4
|
+
* them (`<namespace>:e:<key>` for an entry, `<namespace>:t:<tag>` for a tag version) never
|
|
5
|
+
* collide across namespaces or between entries and tags. Error messages never include the value:
|
|
6
|
+
* a key may hold an id.
|
|
7
|
+
*/
|
|
8
|
+
/** Longest key or tag, in characters (all ASCII, so also in bytes). */
|
|
9
|
+
export const MAX_KEY_LENGTH = 200;
|
|
10
|
+
const PRINTABLE = /^[\x21-\x7e]+$/;
|
|
11
|
+
const NAMESPACE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
|
|
12
|
+
/** True for a valid key or tag: 1 to 200 printable ASCII characters, no spaces. */
|
|
13
|
+
export function isValidKey(value) {
|
|
14
|
+
return (typeof value === "string" &&
|
|
15
|
+
value.length >= 1 &&
|
|
16
|
+
value.length <= MAX_KEY_LENGTH &&
|
|
17
|
+
PRINTABLE.test(value));
|
|
18
|
+
}
|
|
19
|
+
/** True for a valid namespace: 1 to 64 of `A-Z a-z 0-9 . _ -`, starting with a letter or digit. */
|
|
20
|
+
export function isValidNamespace(value) {
|
|
21
|
+
return typeof value === "string" && NAMESPACE.test(value);
|
|
22
|
+
}
|
|
23
|
+
/** Throws a `TypeError` (without the value) unless `key` is a valid key. */
|
|
24
|
+
export function assertValidKey(key, where) {
|
|
25
|
+
if (!isValidKey(key)) {
|
|
26
|
+
throw new TypeError(`${where}: the key must be 1 to ${MAX_KEY_LENGTH} printable ASCII characters without ` +
|
|
27
|
+
"spaces (build it with cacheKey)");
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Joins `parts` into a key with `:`, percent-encoding each part (`encodeURIComponent`), so a part
|
|
32
|
+
* that holds a `:` cannot make two different lists of parts the same key:
|
|
33
|
+
* `cacheKey("a:b", "c")` is `"a%3Ab:c"` and `cacheKey("a", "b:c")` is `"a:b%3Ac"`.
|
|
34
|
+
*
|
|
35
|
+
* Parts are strings or finite numbers. Throws a `TypeError` for no parts, an empty part, another
|
|
36
|
+
* type, a string with an unpaired surrogate, or a key over 200 characters (after encoding). The
|
|
37
|
+
* message never includes a part.
|
|
38
|
+
*/
|
|
39
|
+
export function cacheKey(...parts) {
|
|
40
|
+
if (parts.length === 0)
|
|
41
|
+
throw new TypeError("cacheKey: give at least one part");
|
|
42
|
+
const encoded = [];
|
|
43
|
+
for (const part of parts) {
|
|
44
|
+
let text;
|
|
45
|
+
if (typeof part === "number") {
|
|
46
|
+
if (!Number.isFinite(part))
|
|
47
|
+
throw new TypeError("cacheKey: a number part must be finite");
|
|
48
|
+
text = String(part);
|
|
49
|
+
}
|
|
50
|
+
else if (typeof part === "string") {
|
|
51
|
+
if (part === "")
|
|
52
|
+
throw new TypeError("cacheKey: a part must not be empty");
|
|
53
|
+
text = part;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
throw new TypeError("cacheKey: a part must be a string or a finite number");
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
encoded.push(encodeURIComponent(text));
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
throw new TypeError("cacheKey: a part holds an unpaired surrogate");
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const key = encoded.join(":");
|
|
66
|
+
if (key.length > MAX_KEY_LENGTH) {
|
|
67
|
+
throw new TypeError(`cacheKey: the key is longer than ${MAX_KEY_LENGTH} characters`);
|
|
68
|
+
}
|
|
69
|
+
return key;
|
|
70
|
+
}
|
|
71
|
+
const UNPAIRED = /[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/;
|
|
72
|
+
/**
|
|
73
|
+
* A fixed-length key part for any text: the SHA-256 of its UTF-8 bytes in lowercase hex (64
|
|
74
|
+
* characters). For parts that come from a request (a search query, a filter) and may be long or
|
|
75
|
+
* hold personal data: `cacheKey("search", await hashedKeyPart(query))` stays within the key limit
|
|
76
|
+
* and keeps the text out of key names. Different texts give different parts (barring a SHA-256
|
|
77
|
+
* collision). Throws a `TypeError` for a non-string or a string with an unpaired surrogate (its
|
|
78
|
+
* UTF-8 would be ambiguous); the message never includes the text.
|
|
79
|
+
*/
|
|
80
|
+
export async function hashedKeyPart(text) {
|
|
81
|
+
if (typeof text !== "string")
|
|
82
|
+
throw new TypeError("hashedKeyPart: the text must be a string");
|
|
83
|
+
if (UNPAIRED.test(text))
|
|
84
|
+
throw new TypeError("hashedKeyPart: the text holds an unpaired surrogate");
|
|
85
|
+
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(text));
|
|
86
|
+
return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=keys.js.map
|
package/dist/keys.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,uEAAuE;AACvE,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,CAAC;AAElC,MAAM,SAAS,GAAG,gBAAgB,CAAC;AACnC,MAAM,SAAS,GAAG,mCAAmC,CAAC;AAEtD,mFAAmF;AACnF,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,CAAC,MAAM,IAAI,CAAC;QACjB,KAAK,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O,CAAC,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC;QACzC,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,SAAS,CAAC,8CAA8C,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;IACD,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC9B,IAAI,GAAG,CAAC,MAAM,GAAG,cAAc,EAAE,CAAC;QAChC,MAAM,IAAI,SAAS,CAAC,oCAAoC,cAAc,aAAa,CAAC,CAAC;IACvF,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,QAAQ,GAAG,wEAAwE,CAAC;AAE1F;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,IAAY;IAC9C,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,MAAM,IAAI,SAAS,CAAC,0CAA0C,CAAC,CAAC;IAC9F,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC;QACrB,MAAM,IAAI,SAAS,CAAC,qDAAqD,CAAC,CAAC;IAC7E,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IACrF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACnG,CAAC"}
|
package/dist/store.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a cache keeps its entries. A store sees opaque strings: the envelope around a value (its
|
|
3
|
+
* expiry, its tag versions, a format version) belongs to `createCache`, which checks it on every
|
|
4
|
+
* read. Keep a store small: get, set and delete.
|
|
5
|
+
*
|
|
6
|
+
* A store may fail (reject) on any call. `createCache` turns a failed read or write into a miss
|
|
7
|
+
* and rejects only on a failed `delete` and a failed tag invalidation (a `set` of a tag version).
|
|
8
|
+
* Two rules every store must follow (the contract suite cannot check them from outside):
|
|
9
|
+
*
|
|
10
|
+
* - Keep a key at least `ttlSeconds` (longer is fine, never forever). A tag version evicted early
|
|
11
|
+
* makes that tag's entries misses: safe, but it costs reloads.
|
|
12
|
+
* - Reject from `set` and `delete` whenever the write did not happen. A store that swallows its
|
|
13
|
+
* own errors makes `invalidateTags` resolve with nothing written, and stale entries stay.
|
|
14
|
+
*/
|
|
15
|
+
export interface CacheStore {
|
|
16
|
+
/** The stored string, or `undefined`. May return an entry past its time: `cache` checks it. */
|
|
17
|
+
get(key: string): Promise<string | undefined>;
|
|
18
|
+
/**
|
|
19
|
+
* Stores for at least `ttlSeconds` (a store may keep it longer, never forever). Rejects when
|
|
20
|
+
* the value was not stored.
|
|
21
|
+
*/
|
|
22
|
+
set(key: string, value: string, ttlSeconds: number): Promise<void>;
|
|
23
|
+
/** Removes the key; a missing key resolves. Rejects when the key could not be removed. */
|
|
24
|
+
delete(key: string): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,UAAU;IACzB,+FAA+F;IAC/F,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAC9C;;;OAGG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnE,0FAA0F;IAC1F,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACpC"}
|
package/dist/store.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test-only in-memory cache store. Never use it in production: entries live in the isolate's
|
|
3
|
+
* memory and are lost on restart. Import it from `@cardonjs/cache/testing`.
|
|
4
|
+
*/
|
|
5
|
+
import type { CacheStore } from "./store.js";
|
|
6
|
+
export interface MemoryCacheStoreOptions {
|
|
7
|
+
/** The clock (default `() => new Date()`): an entry is gone `ttlSeconds` after it was set. */
|
|
8
|
+
readonly now?: () => Date;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A `CacheStore` in a `Map`. Keeps an entry for exactly `ttlSeconds` (by `now`), and rejects a
|
|
12
|
+
* call with a `TypeError` when the key is not a non-empty string, the value not a string, or
|
|
13
|
+
* `ttlSeconds` not a positive whole number. Passes `cacheStoreContract`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function memoryCacheStore(options?: MemoryCacheStoreOptions): CacheStore;
|
|
16
|
+
//# sourceMappingURL=testing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,WAAW,uBAAuB;IACtC,8FAA8F;IAC9F,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;CAC3B;AAOD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,GAAE,uBAA4B,GAAG,UAAU,CAqClF"}
|
package/dist/testing.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `CacheStore` in a `Map`. Keeps an entry for exactly `ttlSeconds` (by `now`), and rejects a
|
|
3
|
+
* call with a `TypeError` when the key is not a non-empty string, the value not a string, or
|
|
4
|
+
* `ttlSeconds` not a positive whole number. Passes `cacheStoreContract`.
|
|
5
|
+
*/
|
|
6
|
+
export function memoryCacheStore(options = {}) {
|
|
7
|
+
const now = options.now ?? (() => new Date());
|
|
8
|
+
if (typeof now !== "function")
|
|
9
|
+
throw new TypeError("memoryCacheStore: now must be a function");
|
|
10
|
+
const entries = new Map();
|
|
11
|
+
const checkKey = (key, where) => {
|
|
12
|
+
if (typeof key !== "string" || key === "") {
|
|
13
|
+
throw new TypeError(`memoryCacheStore.${where}: the key must be a non-empty string`);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
return {
|
|
17
|
+
async get(key) {
|
|
18
|
+
checkKey(key, "get");
|
|
19
|
+
const entry = entries.get(key);
|
|
20
|
+
if (entry === undefined)
|
|
21
|
+
return undefined;
|
|
22
|
+
if (now().getTime() >= entry.expiresAt) {
|
|
23
|
+
entries.delete(key);
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
return entry.value;
|
|
27
|
+
},
|
|
28
|
+
async set(key, value, ttlSeconds) {
|
|
29
|
+
checkKey(key, "set");
|
|
30
|
+
if (typeof value !== "string") {
|
|
31
|
+
throw new TypeError("memoryCacheStore.set: the value must be a string");
|
|
32
|
+
}
|
|
33
|
+
if (!Number.isSafeInteger(ttlSeconds) || ttlSeconds < 1) {
|
|
34
|
+
throw new TypeError("memoryCacheStore.set: ttlSeconds must be a positive whole number");
|
|
35
|
+
}
|
|
36
|
+
entries.set(key, { value, expiresAt: now().getTime() + ttlSeconds * 1000 });
|
|
37
|
+
},
|
|
38
|
+
async delete(key) {
|
|
39
|
+
checkKey(key, "delete");
|
|
40
|
+
entries.delete(key);
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=testing.js.map
|
|
@@ -0,0 +1 @@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