@geekmidas/cache 10.0.0-alpha.6 → 10.0.0-alpha.61
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 +27 -4
- 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 +23 -2
- package/dist/postgres.mjs.map +1 -1
- package/dist/redis.cjs +19 -8
- 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 +17 -6
- 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/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 +1 -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/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
|
+
});
|
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
|
package/dist/upstash.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upstash.mjs","names":[
|
|
1
|
+
{"version":3,"file":"upstash.mjs","names":[],"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,IAAI,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/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index-1sNRIo6N.d.mts","names":[],"sources":["../src/registry.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;ACgC4B,UDhBX,WAAA,CCgBW;EAAC;EAAwB,MAM/B,EAAA,MAAA;EAAO,MAQV,CAAA,GAAA,EAAA,MAAA,CAAA,ED3BG,KC2BH;AAAO;;iBDrBV,mBAAA,SAA4B;;iBAK5B,sBAAA,CAAA;;;;;;;;iBAWA,iBAAA,eAAgC;;cAYnC,uBAAA,SAAgC,KAAK;;;;;;;;;cCnDrC,sDACiB;ADab,UCCA,KAAA,CDDW;EASZ;AAKhB;AAWA;AAYA;;;uBC7BsB,QAAQ;EAtBjB;AAeb;;;;;;EAeqD,GAM/B,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,EAAA,KAAA,EANM,CAMN,EAAA,GAAA,CAAA,EAAA,MAAA,CAAA,EANwB,OAMxB,CAAA,IAAA,CAAA;EAAO;AAQH;;;;uBARJ;;;;;;;oBAQH"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index-CNQ50bVk.d.cts","names":[],"sources":["../src/registry.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;ACgC4B,UDhBX,WAAA,CCgBW;EAAC;EAAwB,MAM/B,EAAA,MAAA;EAAO,MAQV,CAAA,GAAA,EAAA,MAAA,CAAA,ED3BG,KC2BH;AAAO;;iBDrBV,mBAAA,SAA4B;;iBAK5B,sBAAA,CAAA;;;;;;;;iBAWA,iBAAA,eAAgC;;cAYnC,uBAAA,SAAgC,KAAK;;;;;;;;;cCnDrC,sDACiB;ADab,UCCA,KAAA,CDDW;EASZ;AAKhB;AAWA;AAYA;;;uBC7BsB,QAAQ;EAtBjB;AAeb;;;;;;EAeqD,GAM/B,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,EAAA,KAAA,EANM,CAMN,EAAA,GAAA,CAAA,EAAA,MAAA,CAAA,EANwB,OAMxB,CAAA,IAAA,CAAA;EAAO;AAQH;;;;uBARJ;;;;;;;oBAQH"}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
|
|
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
|
-
constructor(url, scheme, registered) {
|
|
28
|
-
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.");
|
|
29
|
-
this.url = url;
|
|
30
|
-
this.scheme = scheme;
|
|
31
|
-
this.registered = registered;
|
|
32
|
-
this.name = "UnregisteredCacheScheme";
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
function schemeOf(url) {
|
|
36
|
-
const separator = url.indexOf(":");
|
|
37
|
-
return separator === -1 ? "" : url.slice(0, separator + 1);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
//#endregion
|
|
41
|
-
Object.defineProperty(exports, 'UnregisteredCacheScheme', {
|
|
42
|
-
enumerable: true,
|
|
43
|
-
get: function () {
|
|
44
|
-
return UnregisteredCacheScheme;
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
Object.defineProperty(exports, 'createCacheClient', {
|
|
48
|
-
enumerable: true,
|
|
49
|
-
get: function () {
|
|
50
|
-
return createCacheClient;
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
Object.defineProperty(exports, 'registerCacheDriver', {
|
|
54
|
-
enumerable: true,
|
|
55
|
-
get: function () {
|
|
56
|
-
return registerCacheDriver;
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
Object.defineProperty(exports, 'registeredCacheSchemes', {
|
|
60
|
-
enumerable: true,
|
|
61
|
-
get: function () {
|
|
62
|
-
return registeredCacheSchemes;
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
//# sourceMappingURL=registry-CITg73zW.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"registry-CITg73zW.cjs","names":["driver: CacheDriver","url: string","scheme: string","registered: readonly string[]"],"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;;AAGpB,SAAgB,oBAAoBA,QAA2B;AAC9D,SAAQ,IAAI,OAAO,QAAQ,OAAO;AAClC;;AAGD,SAAgB,yBAAmC;AAClD,QAAO,CAAC,GAAG,QAAQ,MAAM,AAAC,EAAC,MAAM;AACjC;;;;;;;;AASD,SAAgB,kBAAkBC,KAAoB;CACrD,MAAM,SAAS,SAAS,IAAI;CAC5B,MAAM,SAAS,QAAQ,IAAI,OAAO;AAElC,MAAK,OACJ,OAAM,IAAI,wBAAwB,KAAK,QAAQ,wBAAwB;AAGxE,QAAO,OAAO,OAAO,IAAI;AACzB;;AAGD,IAAa,0BAAb,cAA6C,MAAM;CAClD,YACUA,KACAC,QACAC,YACR;AACD,SACE,2BAA2B,OAAO,QACjC,WAAW,UACR,cAAc,WAAW,KAAK,KAAK,CAAC,KACrC,4BACH,yHAED;EAXQ;EACA;EACA;AAUT,OAAK,OAAO;CACZ;AACD;AAED,SAAS,SAASF,KAAqB;CACtC,MAAM,YAAY,IAAI,QAAQ,IAAI;AAClC,QAAO,cAAc,KAAK,KAAK,IAAI,MAAM,GAAG,YAAY,EAAE;AAC1D"}
|
|
@@ -1,41 +0,0 @@
|
|
|
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
|
-
constructor(url, scheme, registered) {
|
|
27
|
-
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.");
|
|
28
|
-
this.url = url;
|
|
29
|
-
this.scheme = scheme;
|
|
30
|
-
this.registered = registered;
|
|
31
|
-
this.name = "UnregisteredCacheScheme";
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
function schemeOf(url) {
|
|
35
|
-
const separator = url.indexOf(":");
|
|
36
|
-
return separator === -1 ? "" : url.slice(0, separator + 1);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
//#endregion
|
|
40
|
-
export { UnregisteredCacheScheme, createCacheClient, registerCacheDriver, registeredCacheSchemes };
|
|
41
|
-
//# sourceMappingURL=registry-CT0b-rjB.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"registry-CT0b-rjB.mjs","names":["driver: CacheDriver","url: string","scheme: string","registered: readonly string[]"],"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;;AAGpB,SAAgB,oBAAoBA,QAA2B;AAC9D,SAAQ,IAAI,OAAO,QAAQ,OAAO;AAClC;;AAGD,SAAgB,yBAAmC;AAClD,QAAO,CAAC,GAAG,QAAQ,MAAM,AAAC,EAAC,MAAM;AACjC;;;;;;;;AASD,SAAgB,kBAAkBC,KAAoB;CACrD,MAAM,SAAS,SAAS,IAAI;CAC5B,MAAM,SAAS,QAAQ,IAAI,OAAO;AAElC,MAAK,OACJ,OAAM,IAAI,wBAAwB,KAAK,QAAQ,wBAAwB;AAGxE,QAAO,OAAO,OAAO,IAAI;AACzB;;AAGD,IAAa,0BAAb,cAA6C,MAAM;CAClD,YACUA,KACAC,QACAC,YACR;AACD,SACE,2BAA2B,OAAO,QACjC,WAAW,UACR,cAAc,WAAW,KAAK,KAAK,CAAC,KACrC,4BACH,yHAED;EAXQ;EACA;EACA;AAUT,OAAK,OAAO;CACZ;AACD;AAED,SAAS,SAASF,KAAqB;CACtC,MAAM,YAAY,IAAI,QAAQ,IAAI;AAClC,QAAO,cAAc,KAAK,KAAK,IAAI,MAAM,GAAG,YAAY,EAAE;AAC1D"}
|
package/dist/src-DVpoP03o.mjs
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { differenceInSeconds } from "date-fns";
|
|
2
|
-
|
|
3
|
-
//#region src/index.ts
|
|
4
|
-
const getExpirationInSeconds = (expiresAt) => {
|
|
5
|
-
if (!expiresAt) return 0;
|
|
6
|
-
const expirationDate = new Date(expiresAt);
|
|
7
|
-
const now = /* @__PURE__ */ new Date();
|
|
8
|
-
const secondsLeft = differenceInSeconds(expirationDate, now);
|
|
9
|
-
return Math.max(secondsLeft, 0);
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
//#endregion
|
|
13
|
-
export { getExpirationInSeconds };
|
|
14
|
-
//# sourceMappingURL=src-DVpoP03o.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"src-DVpoP03o.mjs","names":["expiresAt: string | number | Date | undefined | null"],"sources":["../src/index.ts"],"sourcesContent":["import { differenceInSeconds } from 'date-fns';\n\nexport const getExpirationInSeconds = (\n\texpiresAt: string | number | Date | undefined | null,\n): number => {\n\tif (!expiresAt) {\n\t\treturn 0;\n\t}\n\n\tconst expirationDate = new Date(expiresAt);\n\tconst now = new Date();\n\n\tconst secondsLeft = differenceInSeconds(expirationDate, now);\n\n\treturn Math.max(secondsLeft, 0);\n};\n\nexport interface Cache {\n\t/**\n\t * Retrieves a value from the cache.\n\t *\n\t * @param key The key to retrieve the value for.\n\t * @returns The cached value, or undefined if not found.\n\t */\n\tget<T>(key: string): Promise<T | undefined>;\n\t/**\n\t * Sets a value in the cache.\n\t *\n\t * @param key The key to set the value for.\n\t * @param value The value to cache.\n\t * @param ttl Optional time-to-live in seconds. If not provided, the value will not expire.\n\t */\n\tset<T>(key: string, value: T, ttl?: number): Promise<void>;\n\t/**\n\t * Deletes a value from the cache.\n\t *\n\t * @param key The key to delete from the cache.\n\t */\n\tdelete(key: string): Promise<void>;\n\n\t/**\n\t * Retrieves the time-to-live (TTL) for a cached value.\n\t *\n\t * @param key The key to retrieve the TTL for.\n\t * @returns The TTL in seconds, or 0 if the key does not exist.\n\t */\n\tttl(key: string): Promise<number>;\n}\n\nexport type { CacheDriver } from './registry';\nexport {\n\tcreateCacheClient,\n\tregisterCacheDriver,\n\tregisteredCacheSchemes,\n\tUnregisteredCacheScheme,\n} from './registry';\n"],"mappings":";;;AAEA,MAAa,yBAAyB,CACrCA,cACY;AACZ,MAAK,UACJ,QAAO;CAGR,MAAM,iBAAiB,IAAI,KAAK;CAChC,MAAM,sBAAM,IAAI;CAEhB,MAAM,cAAc,oBAAoB,gBAAgB,IAAI;AAE5D,QAAO,KAAK,IAAI,aAAa,EAAE;AAC/B"}
|
package/dist/src-ysNIqjnr.cjs
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
-
const date_fns = require_chunk.__toESM(require("date-fns"));
|
|
3
|
-
|
|
4
|
-
//#region src/index.ts
|
|
5
|
-
const getExpirationInSeconds = (expiresAt) => {
|
|
6
|
-
if (!expiresAt) return 0;
|
|
7
|
-
const expirationDate = new Date(expiresAt);
|
|
8
|
-
const now = /* @__PURE__ */ new Date();
|
|
9
|
-
const secondsLeft = (0, date_fns.differenceInSeconds)(expirationDate, now);
|
|
10
|
-
return Math.max(secondsLeft, 0);
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
//#endregion
|
|
14
|
-
Object.defineProperty(exports, 'getExpirationInSeconds', {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: function () {
|
|
17
|
-
return getExpirationInSeconds;
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
//# sourceMappingURL=src-ysNIqjnr.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"src-ysNIqjnr.cjs","names":["expiresAt: string | number | Date | undefined | null"],"sources":["../src/index.ts"],"sourcesContent":["import { differenceInSeconds } from 'date-fns';\n\nexport const getExpirationInSeconds = (\n\texpiresAt: string | number | Date | undefined | null,\n): number => {\n\tif (!expiresAt) {\n\t\treturn 0;\n\t}\n\n\tconst expirationDate = new Date(expiresAt);\n\tconst now = new Date();\n\n\tconst secondsLeft = differenceInSeconds(expirationDate, now);\n\n\treturn Math.max(secondsLeft, 0);\n};\n\nexport interface Cache {\n\t/**\n\t * Retrieves a value from the cache.\n\t *\n\t * @param key The key to retrieve the value for.\n\t * @returns The cached value, or undefined if not found.\n\t */\n\tget<T>(key: string): Promise<T | undefined>;\n\t/**\n\t * Sets a value in the cache.\n\t *\n\t * @param key The key to set the value for.\n\t * @param value The value to cache.\n\t * @param ttl Optional time-to-live in seconds. If not provided, the value will not expire.\n\t */\n\tset<T>(key: string, value: T, ttl?: number): Promise<void>;\n\t/**\n\t * Deletes a value from the cache.\n\t *\n\t * @param key The key to delete from the cache.\n\t */\n\tdelete(key: string): Promise<void>;\n\n\t/**\n\t * Retrieves the time-to-live (TTL) for a cached value.\n\t *\n\t * @param key The key to retrieve the TTL for.\n\t * @returns The TTL in seconds, or 0 if the key does not exist.\n\t */\n\tttl(key: string): Promise<number>;\n}\n\nexport type { CacheDriver } from './registry';\nexport {\n\tcreateCacheClient,\n\tregisterCacheDriver,\n\tregisteredCacheSchemes,\n\tUnregisteredCacheScheme,\n} from './registry';\n"],"mappings":";;;;AAEA,MAAa,yBAAyB,CACrCA,cACY;AACZ,MAAK,UACJ,QAAO;CAGR,MAAM,iBAAiB,IAAI,KAAK;CAChC,MAAM,sBAAM,IAAI;CAEhB,MAAM,cAAc,kCAAoB,gBAAgB,IAAI;AAE5D,QAAO,KAAK,IAAI,aAAa,EAAE;AAC/B"}
|