@geekmidas/cache 10.0.0-alpha.9 → 10.0.0-alpha.91
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/expo.cjs +10 -11
- package/dist/expo.cjs.map +1 -1
- package/dist/expo.d.cts +2 -6
- package/dist/expo.d.cts.map +1 -1
- package/dist/expo.d.mts +2 -6
- package/dist/expo.d.mts.map +1 -1
- package/dist/expo.mjs +4 -7
- package/dist/expo.mjs.map +1 -1
- package/dist/file.cjs +16 -20
- package/dist/file.cjs.map +1 -1
- package/dist/file.d.cts +3 -6
- package/dist/file.d.cts.map +1 -1
- package/dist/file.d.mts +3 -6
- package/dist/file.d.mts.map +1 -1
- package/dist/file.mjs +7 -13
- package/dist/file.mjs.map +1 -1
- package/dist/{index-1sNRIo6N.d.mts → index-BbdGhmWP.d.cts} +2 -4
- package/dist/index-BbdGhmWP.d.cts.map +1 -0
- package/dist/{index-CNQ50bVk.d.cts → index-BbdGhmWP.d.mts} +2 -4
- package/dist/index-BbdGhmWP.d.mts.map +1 -0
- package/dist/index.cjs +15 -5
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +12 -3
- package/dist/index.mjs.map +1 -0
- package/dist/memory.cjs +8 -12
- package/dist/memory.cjs.map +1 -1
- package/dist/memory.d.cts +2 -6
- package/dist/memory.d.cts.map +1 -1
- package/dist/memory.d.mts +2 -6
- package/dist/memory.d.mts.map +1 -1
- package/dist/memory.mjs +5 -9
- package/dist/memory.mjs.map +1 -1
- package/dist/postgres.cjs +46 -16
- package/dist/postgres.cjs.map +1 -1
- package/dist/postgres.d.cts +5 -9
- package/dist/postgres.d.cts.map +1 -1
- package/dist/postgres.d.mts +5 -9
- package/dist/postgres.d.mts.map +1 -1
- package/dist/postgres.mjs +42 -14
- package/dist/postgres.mjs.map +1 -1
- package/dist/redis.cjs +40 -22
- package/dist/redis.cjs.map +1 -1
- package/dist/redis.d.cts +4 -8
- package/dist/redis.d.cts.map +1 -1
- package/dist/redis.d.mts +4 -8
- package/dist/redis.d.mts.map +1 -1
- package/dist/redis.mjs +38 -20
- package/dist/redis.mjs.map +1 -1
- package/dist/registry.cjs +47 -5
- package/dist/registry.cjs.map +1 -0
- package/dist/registry.d.cts +1 -1
- package/dist/registry.d.mts +1 -1
- package/dist/registry.mjs +43 -2
- package/dist/registry.mjs.map +1 -0
- package/dist/{chunk-CUT6urMc.cjs → rolldown-runtime-VH7oDXx4.cjs} +8 -10
- package/dist/telemetry.cjs +38 -0
- package/dist/telemetry.cjs.map +1 -0
- package/dist/telemetry.d.cts +6 -0
- package/dist/telemetry.d.cts.map +1 -0
- package/dist/telemetry.d.mts +6 -0
- package/dist/telemetry.d.mts.map +1 -0
- package/dist/telemetry.mjs +37 -0
- package/dist/telemetry.mjs.map +1 -0
- package/dist/upstash.cjs +5 -6
- package/dist/upstash.cjs.map +1 -1
- package/dist/upstash.d.cts +6 -9
- package/dist/upstash.d.cts.map +1 -1
- package/dist/upstash.d.mts +6 -9
- package/dist/upstash.d.mts.map +1 -1
- package/dist/upstash.mjs +2 -3
- package/dist/upstash.mjs.map +1 -1
- package/package.json +6 -1
- package/dist/index-1sNRIo6N.d.mts.map +0 -1
- package/dist/index-CNQ50bVk.d.cts.map +0 -1
- package/dist/registry-CITg73zW.cjs +0 -65
- package/dist/registry-CITg73zW.cjs.map +0 -1
- package/dist/registry-CT0b-rjB.mjs +0 -41
- package/dist/registry-CT0b-rjB.mjs.map +0 -1
- package/dist/src-DVpoP03o.mjs +0 -14
- package/dist/src-DVpoP03o.mjs.map +0 -1
- package/dist/src-ysNIqjnr.cjs +0 -20
- package/dist/src-ysNIqjnr.cjs.map +0 -1
package/dist/redis.d.cts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { r as CacheDriver, t as Cache } from "./index-BbdGhmWP.cjs";
|
|
2
2
|
import { Redis } from "ioredis";
|
|
3
|
-
|
|
4
3
|
//#region src/redis.d.ts
|
|
5
|
-
|
|
6
|
-
declare class RedisCache implements Cache {
|
|
4
|
+
export declare class RedisCache implements Cache {
|
|
7
5
|
private readonly client;
|
|
8
6
|
constructor(client: Redis);
|
|
9
7
|
get<T>(key: string): Promise<T | undefined>;
|
|
@@ -22,10 +20,8 @@ declare class RedisCache implements Cache {
|
|
|
22
20
|
* lazy boundary: an app caching in Postgres never imports
|
|
23
21
|
* `@geekmidas/cache/redis`, and so never resolves it.
|
|
24
22
|
*/
|
|
25
|
-
declare const redisCacheDriver: CacheDriver;
|
|
23
|
+
export declare const redisCacheDriver: CacheDriver;
|
|
26
24
|
/** The TLS form. ElastiCache Serverless requires it; the same client handles both. */
|
|
27
|
-
declare const redissCacheDriver: CacheDriver;
|
|
28
|
-
//# sourceMappingURL=redis.d.ts.map
|
|
25
|
+
export declare const redissCacheDriver: CacheDriver;
|
|
29
26
|
//#endregion
|
|
30
|
-
export { RedisCache, redisCacheDriver, redissCacheDriver };
|
|
31
27
|
//# sourceMappingURL=redis.d.cts.map
|
package/dist/redis.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis.d.cts","names":[],"sources":["../src/redis.ts"],"
|
|
1
|
+
{"version":3,"file":"redis.d.cts","names":[],"sources":["../src/redis.ts"],"mappings":";;;qBAoBa,sBAAsB;mBACL;EAA7B,YAA6B,QAAQ;EAE/B,IAAI,GAAG,cAAc,QAAQ;EAgB7B,IAAI,GAAG,aAAa,OAAO,GAAG,eAAe;EAa7C,OAAO,cAAc;EAMrB,IAAI,cAAc;;;;;;;;;;;;;qBAsBZ,kBAAkB;;qBAMlB,mBAAmB"}
|
package/dist/redis.d.mts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { r as CacheDriver, t as Cache } from "./index-BbdGhmWP.mjs";
|
|
2
2
|
import { Redis } from "ioredis";
|
|
3
|
-
|
|
4
3
|
//#region src/redis.d.ts
|
|
5
|
-
|
|
6
|
-
declare class RedisCache implements Cache {
|
|
4
|
+
export declare class RedisCache implements Cache {
|
|
7
5
|
private readonly client;
|
|
8
6
|
constructor(client: Redis);
|
|
9
7
|
get<T>(key: string): Promise<T | undefined>;
|
|
@@ -22,10 +20,8 @@ declare class RedisCache implements Cache {
|
|
|
22
20
|
* lazy boundary: an app caching in Postgres never imports
|
|
23
21
|
* `@geekmidas/cache/redis`, and so never resolves it.
|
|
24
22
|
*/
|
|
25
|
-
declare const redisCacheDriver: CacheDriver;
|
|
23
|
+
export declare const redisCacheDriver: CacheDriver;
|
|
26
24
|
/** The TLS form. ElastiCache Serverless requires it; the same client handles both. */
|
|
27
|
-
declare const redissCacheDriver: CacheDriver;
|
|
28
|
-
//# sourceMappingURL=redis.d.ts.map
|
|
25
|
+
export declare const redissCacheDriver: CacheDriver;
|
|
29
26
|
//#endregion
|
|
30
|
-
export { RedisCache, redisCacheDriver, redissCacheDriver };
|
|
31
27
|
//# sourceMappingURL=redis.d.mts.map
|
package/dist/redis.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis.d.mts","names":[],"sources":["../src/redis.ts"],"
|
|
1
|
+
{"version":3,"file":"redis.d.mts","names":[],"sources":["../src/redis.ts"],"mappings":";;;qBAoBa,sBAAsB;mBACL;EAA7B,YAA6B,QAAQ;EAE/B,IAAI,GAAG,cAAc,QAAQ;EAgB7B,IAAI,GAAG,aAAa,OAAO,GAAG,eAAe;EAa7C,OAAO,cAAc;EAMrB,IAAI,cAAc;;;;;;;;;;;;;qBAsBZ,kBAAkB;;qBAMlB,mBAAmB"}
|
package/dist/redis.mjs
CHANGED
|
@@ -1,29 +1,50 @@
|
|
|
1
|
+
import { traceCache } from "./telemetry.mjs";
|
|
1
2
|
import { Redis } from "ioredis";
|
|
2
|
-
|
|
3
3
|
//#region src/redis.ts
|
|
4
|
+
/**
|
|
5
|
+
* A cache over the Redis wire protocol — ElastiCache, Valkey, or a Redis you run.
|
|
6
|
+
*
|
|
7
|
+
* The sibling of the Upstash client rather than a replacement for it. Upstash
|
|
8
|
+
* speaks HTTP, which is what makes it reachable from a Lambda with no VPC and
|
|
9
|
+
* no connection pool; this speaks the wire protocol, which is what ElastiCache
|
|
10
|
+
* offers and what a container next to your app is cheapest on.
|
|
11
|
+
*
|
|
12
|
+
* Choosing one is a deployment decision, and the local target follows it: pick
|
|
13
|
+
* `elasticache` and dev runs plain Redis, pick `upstash` and dev runs the HTTP
|
|
14
|
+
* proxy in front of it. Either way dev and prod speak the same protocol, which
|
|
15
|
+
* is the property that matters — a cache that behaves differently in the two
|
|
16
|
+
* places is worse than a slower one.
|
|
17
|
+
*/
|
|
4
18
|
var RedisCache = class {
|
|
19
|
+
client;
|
|
5
20
|
constructor(client) {
|
|
6
21
|
this.client = client;
|
|
7
22
|
}
|
|
8
23
|
async get(key) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
24
|
+
return traceCache("redis", "get", async () => {
|
|
25
|
+
const value = await this.client.get(key);
|
|
26
|
+
if (value === null) return void 0;
|
|
27
|
+
try {
|
|
28
|
+
return JSON.parse(value);
|
|
29
|
+
} catch {
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
16
33
|
}
|
|
17
34
|
async set(key, value, ttl) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
35
|
+
return traceCache("redis", "set", async () => {
|
|
36
|
+
const encoded = JSON.stringify(value);
|
|
37
|
+
if (ttl === void 0) {
|
|
38
|
+
await this.client.set(key, encoded);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
await this.client.set(key, encoded, "EX", ttl);
|
|
42
|
+
});
|
|
24
43
|
}
|
|
25
44
|
async delete(key) {
|
|
26
|
-
|
|
45
|
+
return traceCache("redis", "delete", async () => {
|
|
46
|
+
await this.client.del(key);
|
|
47
|
+
});
|
|
27
48
|
}
|
|
28
49
|
async ttl(key) {
|
|
29
50
|
const seconds = await this.client.ttl(key);
|
|
@@ -54,14 +75,11 @@ const clients = /* @__PURE__ */ new Map();
|
|
|
54
75
|
function clientFor(url) {
|
|
55
76
|
const existing = clients.get(url);
|
|
56
77
|
if (existing) return existing;
|
|
57
|
-
const client = new Redis(url, {
|
|
58
|
-
maxRetriesPerRequest: 2,
|
|
59
|
-
enableOfflineQueue: false
|
|
60
|
-
});
|
|
78
|
+
const client = new Redis(url, { maxRetriesPerRequest: 2 });
|
|
61
79
|
clients.set(url, client);
|
|
62
80
|
return client;
|
|
63
81
|
}
|
|
64
|
-
|
|
65
82
|
//#endregion
|
|
66
83
|
export { RedisCache, redisCacheDriver, redissCacheDriver };
|
|
84
|
+
|
|
67
85
|
//# sourceMappingURL=redis.mjs.map
|
package/dist/redis.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis.mjs","names":[
|
|
1
|
+
{"version":3,"file":"redis.mjs","names":[],"sources":["../src/redis.ts"],"sourcesContent":["/**\n * A cache over the Redis wire protocol — ElastiCache, Valkey, or a Redis you run.\n *\n * The sibling of the Upstash client rather than a replacement for it. Upstash\n * speaks HTTP, which is what makes it reachable from a Lambda with no VPC and\n * no connection pool; this speaks the wire protocol, which is what ElastiCache\n * offers and what a container next to your app is cheapest on.\n *\n * Choosing one is a deployment decision, and the local target follows it: pick\n * `elasticache` and dev runs plain Redis, pick `upstash` and dev runs the HTTP\n * proxy in front of it. Either way dev and prod speak the same protocol, which\n * is the property that matters — a cache that behaves differently in the two\n * places is worse than a slower one.\n */\n\nimport { Redis } from 'ioredis';\nimport type { Cache } from './index';\nimport type { CacheDriver } from './registry';\nimport { traceCache } from './telemetry';\n\nexport class RedisCache implements Cache {\n\tconstructor(private readonly client: Redis) {}\n\n\tasync get<T>(key: string): Promise<T | undefined> {\n\t\treturn traceCache('redis', 'get', async () => {\n\t\t\tconst value = await this.client.get(key);\n\t\t\tif (value === null) return undefined;\n\n\t\t\ttry {\n\t\t\t\treturn JSON.parse(value) as T;\n\t\t\t} catch {\n\t\t\t\t// Written by something that did not go through `set`. Returning the\n\t\t\t\t// raw string is more useful than throwing on a value somebody put\n\t\t\t\t// there on purpose.\n\t\t\t\treturn value as unknown as T;\n\t\t\t}\n\t\t});\n\t}\n\n\tasync set<T>(key: string, value: T, ttl?: number): Promise<void> {\n\t\treturn traceCache('redis', 'set', async () => {\n\t\t\tconst encoded = JSON.stringify(value);\n\n\t\t\tif (ttl === undefined) {\n\t\t\t\tawait this.client.set(key, encoded);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tawait this.client.set(key, encoded, 'EX', ttl);\n\t\t});\n\t}\n\n\tasync delete(key: string): Promise<void> {\n\t\treturn traceCache('redis', 'delete', async () => {\n\t\t\tawait this.client.del(key);\n\t\t});\n\t}\n\n\tasync ttl(key: string): Promise<number> {\n\t\tconst seconds = await this.client.ttl(key);\n\n\t\t// Redis reports -2 for a key that does not exist and -1 for one with no\n\t\t// expiry. The interface says zero for a missing key, and \"never expires\"\n\t\t// has no time left to report either — so both become zero rather than\n\t\t// leaking sentinel values a caller would have to know about.\n\t\treturn seconds < 0 ? 0 : seconds;\n\t}\n}\n\n/**\n * The `redis://` and `rediss://` driver.\n *\n * One client per URL for the life of the process — a Redis connection is a\n * socket, and opening one per cache call is the thing that makes people\n * conclude a cache is not worth having.\n *\n * `ioredis` is imported at the top of this module because the *module* is the\n * lazy boundary: an app caching in Postgres never imports\n * `@geekmidas/cache/redis`, and so never resolves it.\n */\nexport const redisCacheDriver: CacheDriver = {\n\tscheme: 'redis:',\n\tcreate: (url) => new RedisCache(clientFor(url)),\n};\n\n/** The TLS form. ElastiCache Serverless requires it; the same client handles both. */\nexport const redissCacheDriver: CacheDriver = {\n\tscheme: 'rediss:',\n\tcreate: (url) => new RedisCache(clientFor(url)),\n};\n\nconst clients = new Map<string, Redis>();\n\nfunction clientFor(url: string): Redis {\n\tconst existing = clients.get(url);\n\tif (existing) return existing;\n\n\tconst client = new Redis(url, {\n\t\t// A cache miss is recoverable and a hung request is not. Failing fast and\n\t\t// letting the caller treat it as a miss is the behaviour a cache should\n\t\t// have; retrying forever turns a degraded cache into a degraded app.\n\t\t//\n\t\t// The offline queue stays on: the socket connects after the constructor\n\t\t// returns, so without it the first command of every fresh client — every\n\t\t// cold start — is rejected before the connection has had a chance. The\n\t\t// retry bound above is what keeps a queued command from waiting forever.\n\t\tmaxRetriesPerRequest: 2,\n\t});\n\n\tclients.set(url, client);\n\n\treturn client;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAoBA,IAAa,aAAb,MAAyC;CACX;CAA7B,YAAY,QAAgC;EAAf,KAAA,SAAA;CAAgB;CAE7C,MAAM,IAAO,KAAqC;EACjD,OAAO,WAAW,SAAS,OAAO,YAAY;GAC7C,MAAM,QAAQ,MAAM,KAAK,OAAO,IAAI,GAAG;GACvC,IAAI,UAAU,MAAM,OAAO,KAAA;GAE3B,IAAI;IACH,OAAO,KAAK,MAAM,KAAK;GACxB,QAAQ;IAIP,OAAO;GACR;EACD,CAAC;CACF;CAEA,MAAM,IAAO,KAAa,OAAU,KAA6B;EAChE,OAAO,WAAW,SAAS,OAAO,YAAY;GAC7C,MAAM,UAAU,KAAK,UAAU,KAAK;GAEpC,IAAI,QAAQ,KAAA,GAAW;IACtB,MAAM,KAAK,OAAO,IAAI,KAAK,OAAO;IAClC;GACD;GAEA,MAAM,KAAK,OAAO,IAAI,KAAK,SAAS,MAAM,GAAG;EAC9C,CAAC;CACF;CAEA,MAAM,OAAO,KAA4B;EACxC,OAAO,WAAW,SAAS,UAAU,YAAY;GAChD,MAAM,KAAK,OAAO,IAAI,GAAG;EAC1B,CAAC;CACF;CAEA,MAAM,IAAI,KAA8B;EACvC,MAAM,UAAU,MAAM,KAAK,OAAO,IAAI,GAAG;EAMzC,OAAO,UAAU,IAAI,IAAI;CAC1B;AACD;;;;;;;;;;;;AAaA,MAAa,mBAAgC;CAC5C,QAAQ;CACR,SAAS,QAAQ,IAAI,WAAW,UAAU,GAAG,CAAC;AAC/C;;AAGA,MAAa,oBAAiC;CAC7C,QAAQ;CACR,SAAS,QAAQ,IAAI,WAAW,UAAU,GAAG,CAAC;AAC/C;AAEA,MAAM,0BAAU,IAAI,IAAmB;AAEvC,SAAS,UAAU,KAAoB;CACtC,MAAM,WAAW,QAAQ,IAAI,GAAG;CAChC,IAAI,UAAU,OAAO;CAErB,MAAM,SAAS,IAAI,MAAM,KAAK,EAS7B,sBAAsB,EACvB,CAAC;CAED,QAAQ,IAAI,KAAK,MAAM;CAEvB,OAAO;AACR"}
|
package/dist/registry.cjs
CHANGED
|
@@ -1,6 +1,48 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/registry.ts
|
|
3
|
+
const drivers = /* @__PURE__ */ new Map();
|
|
4
|
+
/** Make a driver available to {@link createCacheClient}. Idempotent. */
|
|
5
|
+
function registerCacheDriver(driver) {
|
|
6
|
+
drivers.set(driver.scheme, driver);
|
|
7
|
+
}
|
|
8
|
+
/** Which schemes are currently registered — the useful half of a failure. */
|
|
9
|
+
function registeredCacheSchemes() {
|
|
10
|
+
return [...drivers.keys()].sort();
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Build a client for a URL.
|
|
14
|
+
*
|
|
15
|
+
* @throws {UnregisteredCacheScheme} when no driver handles the scheme, which in
|
|
16
|
+
* practice means the entry point registered a different one — the backend and
|
|
17
|
+
* the build disagreeing, caught at the first cache call rather than never.
|
|
18
|
+
*/
|
|
19
|
+
function createCacheClient(url) {
|
|
20
|
+
const scheme = schemeOf(url);
|
|
21
|
+
const driver = drivers.get(scheme);
|
|
22
|
+
if (!driver) throw new UnregisteredCacheScheme(url, scheme, registeredCacheSchemes());
|
|
23
|
+
return driver.create(url);
|
|
24
|
+
}
|
|
25
|
+
/** No driver handles the scheme in a cache URL. */
|
|
26
|
+
var UnregisteredCacheScheme = class extends Error {
|
|
27
|
+
url;
|
|
28
|
+
scheme;
|
|
29
|
+
registered;
|
|
30
|
+
constructor(url, scheme, registered) {
|
|
31
|
+
super(`No cache driver handles '${scheme}'. ` + (registered.length ? `Registered: ${registered.join(", ")}.` : "Nothing is registered.") + " The scheme comes from the backend the target provisioned, so this is usually a build that registered a different one.");
|
|
32
|
+
this.url = url;
|
|
33
|
+
this.scheme = scheme;
|
|
34
|
+
this.registered = registered;
|
|
35
|
+
this.name = "UnregisteredCacheScheme";
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
function schemeOf(url) {
|
|
39
|
+
const separator = url.indexOf(":");
|
|
40
|
+
return separator === -1 ? "" : url.slice(0, separator + 1);
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
exports.UnregisteredCacheScheme = UnregisteredCacheScheme;
|
|
44
|
+
exports.createCacheClient = createCacheClient;
|
|
45
|
+
exports.registerCacheDriver = registerCacheDriver;
|
|
46
|
+
exports.registeredCacheSchemes = registeredCacheSchemes;
|
|
2
47
|
|
|
3
|
-
|
|
4
|
-
exports.createCacheClient = require_registry.createCacheClient;
|
|
5
|
-
exports.registerCacheDriver = require_registry.registerCacheDriver;
|
|
6
|
-
exports.registeredCacheSchemes = require_registry.registeredCacheSchemes;
|
|
48
|
+
//# sourceMappingURL=registry.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.cjs","names":[],"sources":["../src/registry.ts"],"sourcesContent":["/**\n * Cache drivers, keyed by URL scheme.\n *\n * The same shape `@geekmidas/storage` uses, for the same reason: a construct is\n * handed one URL and the scheme in it picks the client. That is what lets the\n * *backend* be a deployment choice rather than an application one — an app\n * caching in Postgres and an app caching in Upstash are the same code.\n *\n * Registration is explicit rather than an import side effect, because a\n * side-effecting module is exactly what a bundler is entitled to drop — and\n * because an app that caches in Postgres should never resolve a Redis client.\n */\n\nimport type { Cache } from './index';\n\n/** What a driver has to supply: a scheme it answers to, and a client for a URL. */\nexport interface CacheDriver {\n\t/** Including the colon, as `URL.protocol` reports it — `redis:`, `https:`. */\n\tscheme: string;\n\tcreate(url: string): Cache;\n}\n\nconst drivers = new Map<string, CacheDriver>();\n\n/** Make a driver available to {@link createCacheClient}. Idempotent. */\nexport function registerCacheDriver(driver: CacheDriver): void {\n\tdrivers.set(driver.scheme, driver);\n}\n\n/** Which schemes are currently registered — the useful half of a failure. */\nexport function registeredCacheSchemes(): string[] {\n\treturn [...drivers.keys()].sort();\n}\n\n/**\n * Build a client for a URL.\n *\n * @throws {UnregisteredCacheScheme} when no driver handles the scheme, which in\n * practice means the entry point registered a different one — the backend and\n * the build disagreeing, caught at the first cache call rather than never.\n */\nexport function createCacheClient(url: string): Cache {\n\tconst scheme = schemeOf(url);\n\tconst driver = drivers.get(scheme);\n\n\tif (!driver) {\n\t\tthrow new UnregisteredCacheScheme(url, scheme, registeredCacheSchemes());\n\t}\n\n\treturn driver.create(url);\n}\n\n/** No driver handles the scheme in a cache URL. */\nexport class UnregisteredCacheScheme extends Error {\n\tconstructor(\n\t\treadonly url: string,\n\t\treadonly scheme: string,\n\t\treadonly registered: readonly string[],\n\t) {\n\t\tsuper(\n\t\t\t`No cache driver handles '${scheme}'. ` +\n\t\t\t\t(registered.length\n\t\t\t\t\t? `Registered: ${registered.join(', ')}.`\n\t\t\t\t\t: 'Nothing is registered.') +\n\t\t\t\t' The scheme comes from the backend the target provisioned, so this ' +\n\t\t\t\t'is usually a build that registered a different one.',\n\t\t);\n\t\tthis.name = 'UnregisteredCacheScheme';\n\t}\n}\n\nfunction schemeOf(url: string): string {\n\tconst separator = url.indexOf(':');\n\treturn separator === -1 ? '' : url.slice(0, separator + 1);\n}\n"],"mappings":";;AAsBA,MAAM,0BAAU,IAAI,IAAyB;;AAG7C,SAAgB,oBAAoB,QAA2B;CAC9D,QAAQ,IAAI,OAAO,QAAQ,MAAM;AAClC;;AAGA,SAAgB,yBAAmC;CAClD,OAAO,CAAC,GAAG,QAAQ,KAAK,CAAC,CAAC,CAAC,KAAK;AACjC;;;;;;;;AASA,SAAgB,kBAAkB,KAAoB;CACrD,MAAM,SAAS,SAAS,GAAG;CAC3B,MAAM,SAAS,QAAQ,IAAI,MAAM;CAEjC,IAAI,CAAC,QACJ,MAAM,IAAI,wBAAwB,KAAK,QAAQ,uBAAuB,CAAC;CAGxE,OAAO,OAAO,OAAO,GAAG;AACzB;;AAGA,IAAa,0BAAb,cAA6C,MAAM;CAExC;CACA;CACA;CAHV,YACC,KACA,QACA,YACC;EACD,MACC,4BAA4B,OAAO,QACjC,WAAW,SACT,eAAe,WAAW,KAAK,IAAI,EAAE,KACrC,4BACH,wHAEF;EAXS,KAAA,MAAA;EACA,KAAA,SAAA;EACA,KAAA,aAAA;EAUT,KAAK,OAAO;CACb;AACD;AAEA,SAAS,SAAS,KAAqB;CACtC,MAAM,YAAY,IAAI,QAAQ,GAAG;CACjC,OAAO,cAAc,KAAK,KAAK,IAAI,MAAM,GAAG,YAAY,CAAC;AAC1D"}
|
package/dist/registry.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as createCacheClient, i as UnregisteredCacheScheme, o as registerCacheDriver, r as CacheDriver, s as registeredCacheSchemes } from "./index-BbdGhmWP.cjs";
|
|
2
2
|
export { CacheDriver, UnregisteredCacheScheme, createCacheClient, registerCacheDriver, registeredCacheSchemes };
|
package/dist/registry.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as createCacheClient, i as UnregisteredCacheScheme, o as registerCacheDriver, r as CacheDriver, s as registeredCacheSchemes } from "./index-BbdGhmWP.mjs";
|
|
2
2
|
export { CacheDriver, UnregisteredCacheScheme, createCacheClient, registerCacheDriver, registeredCacheSchemes };
|
package/dist/registry.mjs
CHANGED
|
@@ -1,3 +1,44 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/registry.ts
|
|
2
|
+
const drivers = /* @__PURE__ */ new Map();
|
|
3
|
+
/** Make a driver available to {@link createCacheClient}. Idempotent. */
|
|
4
|
+
function registerCacheDriver(driver) {
|
|
5
|
+
drivers.set(driver.scheme, driver);
|
|
6
|
+
}
|
|
7
|
+
/** Which schemes are currently registered — the useful half of a failure. */
|
|
8
|
+
function registeredCacheSchemes() {
|
|
9
|
+
return [...drivers.keys()].sort();
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Build a client for a URL.
|
|
13
|
+
*
|
|
14
|
+
* @throws {UnregisteredCacheScheme} when no driver handles the scheme, which in
|
|
15
|
+
* practice means the entry point registered a different one — the backend and
|
|
16
|
+
* the build disagreeing, caught at the first cache call rather than never.
|
|
17
|
+
*/
|
|
18
|
+
function createCacheClient(url) {
|
|
19
|
+
const scheme = schemeOf(url);
|
|
20
|
+
const driver = drivers.get(scheme);
|
|
21
|
+
if (!driver) throw new UnregisteredCacheScheme(url, scheme, registeredCacheSchemes());
|
|
22
|
+
return driver.create(url);
|
|
23
|
+
}
|
|
24
|
+
/** No driver handles the scheme in a cache URL. */
|
|
25
|
+
var UnregisteredCacheScheme = class extends Error {
|
|
26
|
+
url;
|
|
27
|
+
scheme;
|
|
28
|
+
registered;
|
|
29
|
+
constructor(url, scheme, registered) {
|
|
30
|
+
super(`No cache driver handles '${scheme}'. ` + (registered.length ? `Registered: ${registered.join(", ")}.` : "Nothing is registered.") + " The scheme comes from the backend the target provisioned, so this is usually a build that registered a different one.");
|
|
31
|
+
this.url = url;
|
|
32
|
+
this.scheme = scheme;
|
|
33
|
+
this.registered = registered;
|
|
34
|
+
this.name = "UnregisteredCacheScheme";
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
function schemeOf(url) {
|
|
38
|
+
const separator = url.indexOf(":");
|
|
39
|
+
return separator === -1 ? "" : url.slice(0, separator + 1);
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
export { UnregisteredCacheScheme, createCacheClient, registerCacheDriver, registeredCacheSchemes };
|
|
2
43
|
|
|
3
|
-
|
|
44
|
+
//# sourceMappingURL=registry.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.mjs","names":[],"sources":["../src/registry.ts"],"sourcesContent":["/**\n * Cache drivers, keyed by URL scheme.\n *\n * The same shape `@geekmidas/storage` uses, for the same reason: a construct is\n * handed one URL and the scheme in it picks the client. That is what lets the\n * *backend* be a deployment choice rather than an application one — an app\n * caching in Postgres and an app caching in Upstash are the same code.\n *\n * Registration is explicit rather than an import side effect, because a\n * side-effecting module is exactly what a bundler is entitled to drop — and\n * because an app that caches in Postgres should never resolve a Redis client.\n */\n\nimport type { Cache } from './index';\n\n/** What a driver has to supply: a scheme it answers to, and a client for a URL. */\nexport interface CacheDriver {\n\t/** Including the colon, as `URL.protocol` reports it — `redis:`, `https:`. */\n\tscheme: string;\n\tcreate(url: string): Cache;\n}\n\nconst drivers = new Map<string, CacheDriver>();\n\n/** Make a driver available to {@link createCacheClient}. Idempotent. */\nexport function registerCacheDriver(driver: CacheDriver): void {\n\tdrivers.set(driver.scheme, driver);\n}\n\n/** Which schemes are currently registered — the useful half of a failure. */\nexport function registeredCacheSchemes(): string[] {\n\treturn [...drivers.keys()].sort();\n}\n\n/**\n * Build a client for a URL.\n *\n * @throws {UnregisteredCacheScheme} when no driver handles the scheme, which in\n * practice means the entry point registered a different one — the backend and\n * the build disagreeing, caught at the first cache call rather than never.\n */\nexport function createCacheClient(url: string): Cache {\n\tconst scheme = schemeOf(url);\n\tconst driver = drivers.get(scheme);\n\n\tif (!driver) {\n\t\tthrow new UnregisteredCacheScheme(url, scheme, registeredCacheSchemes());\n\t}\n\n\treturn driver.create(url);\n}\n\n/** No driver handles the scheme in a cache URL. */\nexport class UnregisteredCacheScheme extends Error {\n\tconstructor(\n\t\treadonly url: string,\n\t\treadonly scheme: string,\n\t\treadonly registered: readonly string[],\n\t) {\n\t\tsuper(\n\t\t\t`No cache driver handles '${scheme}'. ` +\n\t\t\t\t(registered.length\n\t\t\t\t\t? `Registered: ${registered.join(', ')}.`\n\t\t\t\t\t: 'Nothing is registered.') +\n\t\t\t\t' The scheme comes from the backend the target provisioned, so this ' +\n\t\t\t\t'is usually a build that registered a different one.',\n\t\t);\n\t\tthis.name = 'UnregisteredCacheScheme';\n\t}\n}\n\nfunction schemeOf(url: string): string {\n\tconst separator = url.indexOf(':');\n\treturn separator === -1 ? '' : url.slice(0, separator + 1);\n}\n"],"mappings":";AAsBA,MAAM,0BAAU,IAAI,IAAyB;;AAG7C,SAAgB,oBAAoB,QAA2B;CAC9D,QAAQ,IAAI,OAAO,QAAQ,MAAM;AAClC;;AAGA,SAAgB,yBAAmC;CAClD,OAAO,CAAC,GAAG,QAAQ,KAAK,CAAC,CAAC,CAAC,KAAK;AACjC;;;;;;;;AASA,SAAgB,kBAAkB,KAAoB;CACrD,MAAM,SAAS,SAAS,GAAG;CAC3B,MAAM,SAAS,QAAQ,IAAI,MAAM;CAEjC,IAAI,CAAC,QACJ,MAAM,IAAI,wBAAwB,KAAK,QAAQ,uBAAuB,CAAC;CAGxE,OAAO,OAAO,OAAO,GAAG;AACzB;;AAGA,IAAa,0BAAb,cAA6C,MAAM;CAExC;CACA;CACA;CAHV,YACC,KACA,QACA,YACC;EACD,MACC,4BAA4B,OAAO,QACjC,WAAW,SACT,eAAe,WAAW,KAAK,IAAI,EAAE,KACrC,4BACH,wHAEF;EAXS,KAAA,MAAA;EACA,KAAA,SAAA;EACA,KAAA,aAAA;EAUT,KAAK,OAAO;CACb;AACD;AAEA,SAAS,SAAS,KAAqB;CACtC,MAAM,YAAY,IAAI,QAAQ,GAAG;CACjC,OAAO,cAAc,KAAK,KAAK,IAAI,MAAM,GAAG,YAAY,CAAC;AAC1D"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
2
|
var __create = Object.create;
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -15,16 +15,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
}
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
19
19
|
value: mod,
|
|
20
20
|
enumerable: true
|
|
21
21
|
}) : target, mod));
|
|
22
|
-
|
|
23
22
|
//#endregion
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
});
|
|
23
|
+
Object.defineProperty(exports, "__toESM", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function() {
|
|
26
|
+
return __toESM;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _opentelemetry_api = require("@opentelemetry/api");
|
|
3
|
+
//#region src/telemetry.ts
|
|
4
|
+
/**
|
|
5
|
+
* A span per cache call, through the global OpenTelemetry tracer — a no-op
|
|
6
|
+
* without a registered provider.
|
|
7
|
+
*
|
|
8
|
+
* `cache.get`, `cache.set` and `cache.delete`, each with the backend as
|
|
9
|
+
* `db.system` and, on a read, whether it hit. Never the key or the value: a key
|
|
10
|
+
* often names a user, and a value is whatever was cached.
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
/** Run `fn` inside a `cache.<operation>` span for a backend. */
|
|
15
|
+
async function traceCache(system, operation, fn) {
|
|
16
|
+
const span = _opentelemetry_api.trace.getTracer("@geekmidas/cache").startSpan(`cache.${operation}`, {
|
|
17
|
+
kind: _opentelemetry_api.SpanKind.CLIENT,
|
|
18
|
+
attributes: {
|
|
19
|
+
"db.system": system,
|
|
20
|
+
"cache.operation": operation
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
try {
|
|
24
|
+
const result = await fn();
|
|
25
|
+
if (operation === "get") span.setAttribute("cache.hit", result !== void 0);
|
|
26
|
+
return result;
|
|
27
|
+
} catch (error) {
|
|
28
|
+
if (error instanceof Error) span.recordException(error);
|
|
29
|
+
span.setStatus({ code: _opentelemetry_api.SpanStatusCode.ERROR });
|
|
30
|
+
throw error;
|
|
31
|
+
} finally {
|
|
32
|
+
span.end();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
exports.traceCache = traceCache;
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=telemetry.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetry.cjs","names":["trace","SpanKind","SpanStatusCode"],"sources":["../src/telemetry.ts"],"sourcesContent":["/**\n * A span per cache call, through the global OpenTelemetry tracer — a no-op\n * without a registered provider.\n *\n * `cache.get`, `cache.set` and `cache.delete`, each with the backend as\n * `db.system` and, on a read, whether it hit. Never the key or the value: a key\n * often names a user, and a value is whatever was cached.\n *\n * @module\n */\nimport { SpanKind, SpanStatusCode, trace } from '@opentelemetry/api';\n\nexport type CacheOperation = 'get' | 'set' | 'delete';\n\n/** Run `fn` inside a `cache.<operation>` span for a backend. */\nexport async function traceCache<T>(\n\tsystem: string,\n\toperation: CacheOperation,\n\tfn: () => Promise<T>,\n): Promise<T> {\n\tconst span = trace\n\t\t.getTracer('@geekmidas/cache')\n\t\t.startSpan(`cache.${operation}`, {\n\t\t\tkind: SpanKind.CLIENT,\n\t\t\tattributes: { 'db.system': system, 'cache.operation': operation },\n\t\t});\n\ttry {\n\t\tconst result = await fn();\n\t\tif (operation === 'get')\n\t\t\tspan.setAttribute('cache.hit', result !== undefined);\n\t\treturn result;\n\t} catch (error) {\n\t\tif (error instanceof Error) span.recordException(error);\n\t\tspan.setStatus({ code: SpanStatusCode.ERROR });\n\t\tthrow error;\n\t} finally {\n\t\tspan.end();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;AAeA,eAAsB,WACrB,QACA,WACA,IACa;CACb,MAAM,OAAOA,mBAAAA,MACX,UAAU,kBAAkB,CAAC,CAC7B,UAAU,SAAS,aAAa;EAChC,MAAMC,mBAAAA,SAAS;EACf,YAAY;GAAE,aAAa;GAAQ,mBAAmB;EAAU;CACjE,CAAC;CACF,IAAI;EACH,MAAM,SAAS,MAAM,GAAG;EACxB,IAAI,cAAc,OACjB,KAAK,aAAa,aAAa,WAAW,KAAA,CAAS;EACpD,OAAO;CACR,SAAS,OAAO;EACf,IAAI,iBAAiB,OAAO,KAAK,gBAAgB,KAAK;EACtD,KAAK,UAAU,EAAE,MAAMC,mBAAAA,eAAe,MAAM,CAAC;EAC7C,MAAM;CACP,UAAU;EACT,KAAK,IAAI;CACV;AACD"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
//#region src/telemetry.d.ts
|
|
2
|
+
export type CacheOperation = 'get' | 'set' | 'delete';
|
|
3
|
+
/** Run `fn` inside a `cache.<operation>` span for a backend. */
|
|
4
|
+
export declare function traceCache<T>(system: string, operation: CacheOperation, fn: () => Promise<T>): Promise<T>;
|
|
5
|
+
//#endregion
|
|
6
|
+
//# sourceMappingURL=telemetry.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetry.d.cts","names":[],"sources":["../src/telemetry.ts"],"mappings":";YAYY;;wBAGU,WAAW,GAChC,gBACA,WAAW,gBACX,UAAU,QAAQ,KAChB,QAAQ"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
//#region src/telemetry.d.ts
|
|
2
|
+
export type CacheOperation = 'get' | 'set' | 'delete';
|
|
3
|
+
/** Run `fn` inside a `cache.<operation>` span for a backend. */
|
|
4
|
+
export declare function traceCache<T>(system: string, operation: CacheOperation, fn: () => Promise<T>): Promise<T>;
|
|
5
|
+
//#endregion
|
|
6
|
+
//# sourceMappingURL=telemetry.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetry.d.mts","names":[],"sources":["../src/telemetry.ts"],"mappings":";YAYY;;wBAGU,WAAW,GAChC,gBACA,WAAW,gBACX,UAAU,QAAQ,KAChB,QAAQ"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
|
|
2
|
+
//#region src/telemetry.ts
|
|
3
|
+
/**
|
|
4
|
+
* A span per cache call, through the global OpenTelemetry tracer — a no-op
|
|
5
|
+
* without a registered provider.
|
|
6
|
+
*
|
|
7
|
+
* `cache.get`, `cache.set` and `cache.delete`, each with the backend as
|
|
8
|
+
* `db.system` and, on a read, whether it hit. Never the key or the value: a key
|
|
9
|
+
* often names a user, and a value is whatever was cached.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
/** Run `fn` inside a `cache.<operation>` span for a backend. */
|
|
14
|
+
async function traceCache(system, operation, fn) {
|
|
15
|
+
const span = trace.getTracer("@geekmidas/cache").startSpan(`cache.${operation}`, {
|
|
16
|
+
kind: SpanKind.CLIENT,
|
|
17
|
+
attributes: {
|
|
18
|
+
"db.system": system,
|
|
19
|
+
"cache.operation": operation
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
try {
|
|
23
|
+
const result = await fn();
|
|
24
|
+
if (operation === "get") span.setAttribute("cache.hit", result !== void 0);
|
|
25
|
+
return result;
|
|
26
|
+
} catch (error) {
|
|
27
|
+
if (error instanceof Error) span.recordException(error);
|
|
28
|
+
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
29
|
+
throw error;
|
|
30
|
+
} finally {
|
|
31
|
+
span.end();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
export { traceCache };
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=telemetry.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetry.mjs","names":[],"sources":["../src/telemetry.ts"],"sourcesContent":["/**\n * A span per cache call, through the global OpenTelemetry tracer — a no-op\n * without a registered provider.\n *\n * `cache.get`, `cache.set` and `cache.delete`, each with the backend as\n * `db.system` and, on a read, whether it hit. Never the key or the value: a key\n * often names a user, and a value is whatever was cached.\n *\n * @module\n */\nimport { SpanKind, SpanStatusCode, trace } from '@opentelemetry/api';\n\nexport type CacheOperation = 'get' | 'set' | 'delete';\n\n/** Run `fn` inside a `cache.<operation>` span for a backend. */\nexport async function traceCache<T>(\n\tsystem: string,\n\toperation: CacheOperation,\n\tfn: () => Promise<T>,\n): Promise<T> {\n\tconst span = trace\n\t\t.getTracer('@geekmidas/cache')\n\t\t.startSpan(`cache.${operation}`, {\n\t\t\tkind: SpanKind.CLIENT,\n\t\t\tattributes: { 'db.system': system, 'cache.operation': operation },\n\t\t});\n\ttry {\n\t\tconst result = await fn();\n\t\tif (operation === 'get')\n\t\t\tspan.setAttribute('cache.hit', result !== undefined);\n\t\treturn result;\n\t} catch (error) {\n\t\tif (error instanceof Error) span.recordException(error);\n\t\tspan.setStatus({ code: SpanStatusCode.ERROR });\n\t\tthrow error;\n\t} finally {\n\t\tspan.end();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;AAeA,eAAsB,WACrB,QACA,WACA,IACa;CACb,MAAM,OAAO,MACX,UAAU,kBAAkB,CAAC,CAC7B,UAAU,SAAS,aAAa;EAChC,MAAM,SAAS;EACf,YAAY;GAAE,aAAa;GAAQ,mBAAmB;EAAU;CACjE,CAAC;CACF,IAAI;EACH,MAAM,SAAS,MAAM,GAAG;EACxB,IAAI,cAAc,OACjB,KAAK,aAAa,aAAa,WAAW,KAAA,CAAS;EACpD,OAAO;CACR,SAAS,OAAO;EACf,IAAI,iBAAiB,OAAO,KAAK,gBAAgB,KAAK;EACtD,KAAK,UAAU,EAAE,MAAM,eAAe,MAAM,CAAC;EAC7C,MAAM;CACP,UAAU;EACT,KAAK,IAAI;CACV;AACD"}
|
package/dist/upstash.cjs
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _upstash_redis = require("@upstash/redis");
|
|
4
3
|
//#region src/upstash.ts
|
|
5
4
|
var UpstashCache = class {
|
|
6
5
|
client;
|
|
7
6
|
constructor(url, token) {
|
|
8
|
-
this.client = new
|
|
7
|
+
this.client = new _upstash_redis.Redis({
|
|
9
8
|
url,
|
|
10
9
|
token
|
|
11
10
|
});
|
|
@@ -17,7 +16,7 @@ var UpstashCache = class {
|
|
|
17
16
|
}
|
|
18
17
|
async get(key) {
|
|
19
18
|
const v = await this.client.get(key);
|
|
20
|
-
if (v === null) return
|
|
19
|
+
if (v === null) return;
|
|
21
20
|
return v;
|
|
22
21
|
}
|
|
23
22
|
async set(key, value, ttl = 3600) {
|
|
@@ -65,10 +64,10 @@ function parseUpstashUrl(url) {
|
|
|
65
64
|
token
|
|
66
65
|
};
|
|
67
66
|
}
|
|
68
|
-
|
|
69
67
|
//#endregion
|
|
70
68
|
exports.UpstashCache = UpstashCache;
|
|
71
69
|
exports.parseUpstashUrl = parseUpstashUrl;
|
|
72
70
|
exports.upstashCacheDriver = upstashCacheDriver;
|
|
73
71
|
exports.upstashInsecureCacheDriver = upstashInsecureCacheDriver;
|
|
72
|
+
|
|
74
73
|
//# sourceMappingURL=upstash.cjs.map
|
package/dist/upstash.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upstash.cjs","names":["
|
|
1
|
+
{"version":3,"file":"upstash.cjs","names":["Redis"],"sources":["../src/upstash.ts"],"sourcesContent":["import { Redis } from '@upstash/redis';\nimport type { Cache } from './';\nimport type { CacheDriver } from './registry';\n\nexport class UpstashCache implements Cache {\n\tprivate client: Redis;\n\n\tconstructor(url: string, token: string) {\n\t\tthis.client = new Redis({\n\t\t\turl,\n\t\t\ttoken,\n\t\t});\n\t}\n\n\tasync ttl(key: string): Promise<number> {\n\t\tconst ttl = await this.client.ttl(key);\n\n\t\tif (ttl === -2) {\n\t\t\treturn 0; // Key does not exist\n\t\t}\n\n\t\treturn ttl; // Returns TTL in seconds\n\t}\n\n\tasync get<T>(key: string): Promise<T | undefined> {\n\t\tconst v = await this.client.get(key);\n\n\t\tif (v === null) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn v as T;\n\t}\n\n\tasync set<T>(key: string, value: T, ttl = 3600): Promise<void> {\n\t\tawait this.client.set(key, value, { ex: ttl });\n\t}\n\n\tasync delete(key: string): Promise<void> {\n\t\tawait this.client.del(key);\n\t}\n}\n\n/**\n * The `https://` and `http://` driver.\n *\n * The token travels in the URL's userinfo, because an address and the\n * credential that opens it are one fact — see {@link parseUpstashUrl}. Deployed\n * that is Upstash's host over TLS; locally it is the `serverless-redis-http`\n * proxy in front of a Redis container, and the client cannot tell the\n * difference. That is the whole point of choosing this backend.\n */\nexport const upstashCacheDriver: CacheDriver = {\n\tscheme: 'https:',\n\tcreate: (url) => {\n\t\tconst { endpoint, token } = parseUpstashUrl(url);\n\t\treturn new UpstashCache(endpoint, token);\n\t},\n};\n\n/** The same driver for plain HTTP, which is what the local proxy speaks. */\nexport const upstashInsecureCacheDriver: CacheDriver = {\n\t...upstashCacheDriver,\n\tscheme: 'http:',\n};\n\n/** What an Upstash cache URL addresses: an HTTP endpoint and the token for it. */\nexport interface UpstashAddress {\n\tendpoint: string;\n\ttoken: string;\n}\n\n/**\n * Split a cache URL into what the client takes.\n *\n * `http://:token@localhost:20705` becomes `{ endpoint: 'http://localhost:20705',\n * token }`. Deployed the scheme is `https` and the host is Upstash's; nothing\n * else differs.\n */\nexport function parseUpstashUrl(url: string): UpstashAddress {\n\tconst parsed = new URL(url);\n\tconst token = decodeURIComponent(parsed.password || parsed.username);\n\n\tparsed.username = '';\n\tparsed.password = '';\n\n\treturn {\n\t\t// `origin` drops the trailing slash `toString()` would add, which the\n\t\t// client would otherwise send as part of every path.\n\t\tendpoint: parsed.origin,\n\t\ttoken,\n\t};\n}\n"],"mappings":";;;AAIA,IAAa,eAAb,MAA2C;CAC1C;CAEA,YAAY,KAAa,OAAe;EACvC,KAAK,SAAS,IAAIA,eAAAA,MAAM;GACvB;GACA;EACD,CAAC;CACF;CAEA,MAAM,IAAI,KAA8B;EACvC,MAAM,MAAM,MAAM,KAAK,OAAO,IAAI,GAAG;EAErC,IAAI,QAAQ,IACX,OAAO;EAGR,OAAO;CACR;CAEA,MAAM,IAAO,KAAqC;EACjD,MAAM,IAAI,MAAM,KAAK,OAAO,IAAI,GAAG;EAEnC,IAAI,MAAM,MACT;EAGD,OAAO;CACR;CAEA,MAAM,IAAO,KAAa,OAAU,MAAM,MAAqB;EAC9D,MAAM,KAAK,OAAO,IAAI,KAAK,OAAO,EAAE,IAAI,IAAI,CAAC;CAC9C;CAEA,MAAM,OAAO,KAA4B;EACxC,MAAM,KAAK,OAAO,IAAI,GAAG;CAC1B;AACD;;;;;;;;;;AAWA,MAAa,qBAAkC;CAC9C,QAAQ;CACR,SAAS,QAAQ;EAChB,MAAM,EAAE,UAAU,UAAU,gBAAgB,GAAG;EAC/C,OAAO,IAAI,aAAa,UAAU,KAAK;CACxC;AACD;;AAGA,MAAa,6BAA0C;CACtD,GAAG;CACH,QAAQ;AACT;;;;;;;;AAeA,SAAgB,gBAAgB,KAA6B;CAC5D,MAAM,SAAS,IAAI,IAAI,GAAG;CAC1B,MAAM,QAAQ,mBAAmB,OAAO,YAAY,OAAO,QAAQ;CAEnE,OAAO,WAAW;CAClB,OAAO,WAAW;CAElB,OAAO;EAGN,UAAU,OAAO;EACjB;CACD;AACD"}
|
package/dist/upstash.d.cts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { r as CacheDriver, t as Cache } from "./index-BbdGhmWP.cjs";
|
|
3
2
|
//#region src/upstash.d.ts
|
|
4
|
-
declare class UpstashCache implements Cache {
|
|
3
|
+
export declare class UpstashCache implements Cache {
|
|
5
4
|
private client;
|
|
6
5
|
constructor(url: string, token: string);
|
|
7
6
|
ttl(key: string): Promise<number>;
|
|
@@ -18,11 +17,11 @@ declare class UpstashCache implements Cache {
|
|
|
18
17
|
* proxy in front of a Redis container, and the client cannot tell the
|
|
19
18
|
* difference. That is the whole point of choosing this backend.
|
|
20
19
|
*/
|
|
21
|
-
declare const upstashCacheDriver: CacheDriver;
|
|
20
|
+
export declare const upstashCacheDriver: CacheDriver;
|
|
22
21
|
/** The same driver for plain HTTP, which is what the local proxy speaks. */
|
|
23
|
-
declare const upstashInsecureCacheDriver: CacheDriver;
|
|
22
|
+
export declare const upstashInsecureCacheDriver: CacheDriver;
|
|
24
23
|
/** What an Upstash cache URL addresses: an HTTP endpoint and the token for it. */
|
|
25
|
-
interface UpstashAddress {
|
|
24
|
+
export interface UpstashAddress {
|
|
26
25
|
endpoint: string;
|
|
27
26
|
token: string;
|
|
28
27
|
}
|
|
@@ -33,8 +32,6 @@ interface UpstashAddress {
|
|
|
33
32
|
* token }`. Deployed the scheme is `https` and the host is Upstash's; nothing
|
|
34
33
|
* else differs.
|
|
35
34
|
*/
|
|
36
|
-
declare function parseUpstashUrl(url: string): UpstashAddress;
|
|
37
|
-
//# sourceMappingURL=upstash.d.ts.map
|
|
35
|
+
export declare function parseUpstashUrl(url: string): UpstashAddress;
|
|
38
36
|
//#endregion
|
|
39
|
-
export { UpstashAddress, UpstashCache, parseUpstashUrl, upstashCacheDriver, upstashInsecureCacheDriver };
|
|
40
37
|
//# sourceMappingURL=upstash.d.cts.map
|
package/dist/upstash.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upstash.d.cts","names":[],"sources":["../src/upstash.ts"],"
|
|
1
|
+
{"version":3,"file":"upstash.d.cts","names":[],"sources":["../src/upstash.ts"],"mappings":";;qBAIa,wBAAwB;UAC5B;EAER,YAAY,aAAa;EAOnB,IAAI,cAAc;EAUlB,IAAI,GAAG,cAAc,QAAQ;EAU7B,IAAI,GAAG,aAAa,OAAO,GAAG,eAAa;EAI3C,OAAO,cAAc;;;;;;;;;;;qBAcf,oBAAoB;;qBASpB,4BAA4B;;iBAMxB;EAChB;EACA;;;;;;;;;wBAUe,gBAAgB,cAAc"}
|
package/dist/upstash.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { r as CacheDriver, t as Cache } from "./index-BbdGhmWP.mjs";
|
|
3
2
|
//#region src/upstash.d.ts
|
|
4
|
-
declare class UpstashCache implements Cache {
|
|
3
|
+
export declare class UpstashCache implements Cache {
|
|
5
4
|
private client;
|
|
6
5
|
constructor(url: string, token: string);
|
|
7
6
|
ttl(key: string): Promise<number>;
|
|
@@ -18,11 +17,11 @@ declare class UpstashCache implements Cache {
|
|
|
18
17
|
* proxy in front of a Redis container, and the client cannot tell the
|
|
19
18
|
* difference. That is the whole point of choosing this backend.
|
|
20
19
|
*/
|
|
21
|
-
declare const upstashCacheDriver: CacheDriver;
|
|
20
|
+
export declare const upstashCacheDriver: CacheDriver;
|
|
22
21
|
/** The same driver for plain HTTP, which is what the local proxy speaks. */
|
|
23
|
-
declare const upstashInsecureCacheDriver: CacheDriver;
|
|
22
|
+
export declare const upstashInsecureCacheDriver: CacheDriver;
|
|
24
23
|
/** What an Upstash cache URL addresses: an HTTP endpoint and the token for it. */
|
|
25
|
-
interface UpstashAddress {
|
|
24
|
+
export interface UpstashAddress {
|
|
26
25
|
endpoint: string;
|
|
27
26
|
token: string;
|
|
28
27
|
}
|
|
@@ -33,8 +32,6 @@ interface UpstashAddress {
|
|
|
33
32
|
* token }`. Deployed the scheme is `https` and the host is Upstash's; nothing
|
|
34
33
|
* else differs.
|
|
35
34
|
*/
|
|
36
|
-
declare function parseUpstashUrl(url: string): UpstashAddress;
|
|
37
|
-
//# sourceMappingURL=upstash.d.ts.map
|
|
35
|
+
export declare function parseUpstashUrl(url: string): UpstashAddress;
|
|
38
36
|
//#endregion
|
|
39
|
-
export { UpstashAddress, UpstashCache, parseUpstashUrl, upstashCacheDriver, upstashInsecureCacheDriver };
|
|
40
37
|
//# sourceMappingURL=upstash.d.mts.map
|
package/dist/upstash.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upstash.d.mts","names":[],"sources":["../src/upstash.ts"],"
|
|
1
|
+
{"version":3,"file":"upstash.d.mts","names":[],"sources":["../src/upstash.ts"],"mappings":";;qBAIa,wBAAwB;UAC5B;EAER,YAAY,aAAa;EAOnB,IAAI,cAAc;EAUlB,IAAI,GAAG,cAAc,QAAQ;EAU7B,IAAI,GAAG,aAAa,OAAO,GAAG,eAAa;EAI3C,OAAO,cAAc;;;;;;;;;;;qBAcf,oBAAoB;;qBASpB,4BAA4B;;iBAMxB;EAChB;EACA;;;;;;;;;wBAUe,gBAAgB,cAAc"}
|
package/dist/upstash.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Redis } from "@upstash/redis";
|
|
2
|
-
|
|
3
2
|
//#region src/upstash.ts
|
|
4
3
|
var UpstashCache = class {
|
|
5
4
|
client;
|
|
@@ -16,7 +15,7 @@ var UpstashCache = class {
|
|
|
16
15
|
}
|
|
17
16
|
async get(key) {
|
|
18
17
|
const v = await this.client.get(key);
|
|
19
|
-
if (v === null) return
|
|
18
|
+
if (v === null) return;
|
|
20
19
|
return v;
|
|
21
20
|
}
|
|
22
21
|
async set(key, value, ttl = 3600) {
|
|
@@ -64,7 +63,7 @@ function parseUpstashUrl(url) {
|
|
|
64
63
|
token
|
|
65
64
|
};
|
|
66
65
|
}
|
|
67
|
-
|
|
68
66
|
//#endregion
|
|
69
67
|
export { UpstashCache, parseUpstashUrl, upstashCacheDriver, upstashInsecureCacheDriver };
|
|
68
|
+
|
|
70
69
|
//# sourceMappingURL=upstash.mjs.map
|