@geekmidas/cache 9.0.2 → 10.0.0-alpha.1
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 +2 -1
- package/dist/expo.cjs.map +1 -1
- package/dist/expo.d.cts +1 -1
- package/dist/expo.d.mts +1 -1
- package/dist/expo.mjs +2 -1
- package/dist/expo.mjs.map +1 -1
- package/dist/file.cjs +2 -1
- package/dist/file.cjs.map +1 -1
- package/dist/file.d.cts +1 -1
- package/dist/file.d.mts +1 -1
- package/dist/file.mjs +2 -1
- package/dist/file.mjs.map +1 -1
- package/dist/index-1sNRIo6N.d.mts +64 -0
- package/dist/index-1sNRIo6N.d.mts.map +1 -0
- package/dist/index-CNQ50bVk.d.cts +64 -0
- package/dist/index-CNQ50bVk.d.cts.map +1 -0
- package/dist/index.cjs +7 -2
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +3 -2
- package/dist/memory.cjs +2 -1
- package/dist/memory.cjs.map +1 -1
- package/dist/memory.d.cts +1 -1
- package/dist/memory.d.mts +1 -1
- package/dist/memory.mjs +2 -1
- package/dist/memory.mjs.map +1 -1
- package/dist/postgres.cjs +155 -0
- package/dist/postgres.cjs.map +1 -0
- package/dist/postgres.d.cts +75 -0
- package/dist/postgres.d.cts.map +1 -0
- package/dist/postgres.d.mts +75 -0
- package/dist/postgres.d.mts.map +1 -0
- package/dist/postgres.mjs +152 -0
- package/dist/postgres.mjs.map +1 -0
- package/dist/redis.cjs +70 -0
- package/dist/redis.cjs.map +1 -0
- package/dist/redis.d.cts +31 -0
- package/dist/redis.d.cts.map +1 -0
- package/dist/redis.d.mts +31 -0
- package/dist/redis.d.mts.map +1 -0
- package/dist/redis.mjs +67 -0
- package/dist/redis.mjs.map +1 -0
- package/dist/registry-CITg73zW.cjs +65 -0
- package/dist/registry-CITg73zW.cjs.map +1 -0
- package/dist/registry-CT0b-rjB.mjs +41 -0
- package/dist/registry-CT0b-rjB.mjs.map +1 -0
- package/dist/registry.cjs +6 -0
- package/dist/registry.d.cts +2 -0
- package/dist/registry.d.mts +2 -0
- package/dist/registry.mjs +3 -0
- package/dist/{src-CrE4Nl5T.mjs → src-DVpoP03o.mjs} +1 -1
- package/dist/{src-CrE4Nl5T.mjs.map → src-DVpoP03o.mjs.map} +1 -1
- package/dist/{src-zfYb7mdS.cjs → src-ysNIqjnr.cjs} +1 -1
- package/dist/{src-zfYb7mdS.cjs.map → src-ysNIqjnr.cjs.map} +1 -1
- package/dist/upstash.cjs +41 -0
- package/dist/upstash.cjs.map +1 -1
- package/dist/upstash.d.cts +27 -3
- package/dist/upstash.d.cts.map +1 -1
- package/dist/upstash.d.mts +27 -3
- package/dist/upstash.d.mts.map +1 -1
- package/dist/upstash.mjs +39 -1
- package/dist/upstash.mjs.map +1 -1
- package/package.json +45 -3
- package/CHANGELOG.md +0 -50
- package/dist/index-BSYYdwRm.d.cts +0 -36
- package/dist/index-BSYYdwRm.d.cts.map +0 -1
- package/dist/index-Dx96gr-9.d.mts +0 -36
- package/dist/index-Dx96gr-9.d.mts.map +0 -1
- package/src/__benchmarks__/memory.bench.ts +0 -51
- package/src/__tests__/cache.spec.ts +0 -144
- package/src/__tests__/file.spec.ts +0 -192
- package/src/__tests__/integration.spec.ts +0 -282
- package/src/__tests__/memory.spec.ts +0 -134
- package/src/__tests__/upstash.spec.ts +0 -276
- package/src/expo.ts +0 -50
- package/src/file.ts +0 -126
- package/src/index.ts +0 -48
- package/src/memory.ts +0 -38
- package/src/upstash.ts +0 -41
- package/tsconfig.json +0 -9
- package/tsdown.config.ts +0 -5
|
@@ -0,0 +1,41 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
const require_registry = require('./registry-CITg73zW.cjs');
|
|
2
|
+
|
|
3
|
+
exports.UnregisteredCacheScheme = require_registry.UnregisteredCacheScheme;
|
|
4
|
+
exports.createCacheClient = require_registry.createCacheClient;
|
|
5
|
+
exports.registerCacheDriver = require_registry.registerCacheDriver;
|
|
6
|
+
exports.registeredCacheSchemes = require_registry.registeredCacheSchemes;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"src-
|
|
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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"src-
|
|
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"}
|
package/dist/upstash.cjs
CHANGED
|
@@ -27,7 +27,48 @@ var UpstashCache = class {
|
|
|
27
27
|
await this.client.del(key);
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
|
+
/**
|
|
31
|
+
* The `https://` and `http://` driver.
|
|
32
|
+
*
|
|
33
|
+
* The token travels in the URL's userinfo, because an address and the
|
|
34
|
+
* credential that opens it are one fact — see {@link parseUpstashUrl}. Deployed
|
|
35
|
+
* that is Upstash's host over TLS; locally it is the `serverless-redis-http`
|
|
36
|
+
* proxy in front of a Redis container, and the client cannot tell the
|
|
37
|
+
* difference. That is the whole point of choosing this backend.
|
|
38
|
+
*/
|
|
39
|
+
const upstashCacheDriver = {
|
|
40
|
+
scheme: "https:",
|
|
41
|
+
create: (url) => {
|
|
42
|
+
const { endpoint, token } = parseUpstashUrl(url);
|
|
43
|
+
return new UpstashCache(endpoint, token);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
/** The same driver for plain HTTP, which is what the local proxy speaks. */
|
|
47
|
+
const upstashInsecureCacheDriver = {
|
|
48
|
+
...upstashCacheDriver,
|
|
49
|
+
scheme: "http:"
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Split a cache URL into what the client takes.
|
|
53
|
+
*
|
|
54
|
+
* `http://:token@localhost:20705` becomes `{ endpoint: 'http://localhost:20705',
|
|
55
|
+
* token }`. Deployed the scheme is `https` and the host is Upstash's; nothing
|
|
56
|
+
* else differs.
|
|
57
|
+
*/
|
|
58
|
+
function parseUpstashUrl(url) {
|
|
59
|
+
const parsed = new URL(url);
|
|
60
|
+
const token = decodeURIComponent(parsed.password || parsed.username);
|
|
61
|
+
parsed.username = "";
|
|
62
|
+
parsed.password = "";
|
|
63
|
+
return {
|
|
64
|
+
endpoint: parsed.origin,
|
|
65
|
+
token
|
|
66
|
+
};
|
|
67
|
+
}
|
|
30
68
|
|
|
31
69
|
//#endregion
|
|
32
70
|
exports.UpstashCache = UpstashCache;
|
|
71
|
+
exports.parseUpstashUrl = parseUpstashUrl;
|
|
72
|
+
exports.upstashCacheDriver = upstashCacheDriver;
|
|
73
|
+
exports.upstashInsecureCacheDriver = upstashInsecureCacheDriver;
|
|
33
74
|
//# sourceMappingURL=upstash.cjs.map
|
package/dist/upstash.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upstash.cjs","names":["url: string","token: string","Redis","key: string","value: T"],"sources":["../src/upstash.ts"],"sourcesContent":["import { Redis } from '@upstash/redis';\nimport type { Cache } from './';\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"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"upstash.cjs","names":["url: string","token: string","Redis","key: string","value: T","upstashCacheDriver: CacheDriver","upstashInsecureCacheDriver: CacheDriver"],"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,AAAQ;CAER,YAAYA,KAAaC,OAAe;AACvC,OAAK,SAAS,IAAIC,sBAAM;GACvB;GACA;EACA;CACD;CAED,MAAM,IAAIC,KAA8B;EACvC,MAAM,MAAM,MAAM,KAAK,OAAO,IAAI,IAAI;AAEtC,MAAI,QAAQ,GACX,QAAO;AAGR,SAAO;CACP;CAED,MAAM,IAAOA,KAAqC;EACjD,MAAM,IAAI,MAAM,KAAK,OAAO,IAAI,IAAI;AAEpC,MAAI,MAAM,KACT;AAGD,SAAO;CACP;CAED,MAAM,IAAOA,KAAaC,OAAU,MAAM,MAAqB;AAC9D,QAAM,KAAK,OAAO,IAAI,KAAK,OAAO,EAAE,IAAI,IAAK,EAAC;CAC9C;CAED,MAAM,OAAOD,KAA4B;AACxC,QAAM,KAAK,OAAO,IAAI,IAAI;CAC1B;AACD;;;;;;;;;;AAWD,MAAaE,qBAAkC;CAC9C,QAAQ;CACR,QAAQ,CAAC,QAAQ;EAChB,MAAM,EAAE,UAAU,OAAO,GAAG,gBAAgB,IAAI;AAChD,SAAO,IAAI,aAAa,UAAU;CAClC;AACD;;AAGD,MAAaC,6BAA0C;CACtD,GAAG;CACH,QAAQ;AACR;;;;;;;;AAeD,SAAgB,gBAAgBN,KAA6B;CAC5D,MAAM,SAAS,IAAI,IAAI;CACvB,MAAM,QAAQ,mBAAmB,OAAO,YAAY,OAAO,SAAS;AAEpE,QAAO,WAAW;AAClB,QAAO,WAAW;AAElB,QAAO;EAGN,UAAU,OAAO;EACjB;CACA;AACD"}
|
package/dist/upstash.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Cache } from "./index-
|
|
1
|
+
import { Cache, CacheDriver } from "./index-CNQ50bVk.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/upstash.d.ts
|
|
4
4
|
declare class UpstashCache implements Cache {
|
|
@@ -9,8 +9,32 @@ declare class UpstashCache implements Cache {
|
|
|
9
9
|
set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
10
10
|
delete(key: string): Promise<void>;
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* The `https://` and `http://` driver.
|
|
14
|
+
*
|
|
15
|
+
* The token travels in the URL's userinfo, because an address and the
|
|
16
|
+
* credential that opens it are one fact — see {@link parseUpstashUrl}. Deployed
|
|
17
|
+
* that is Upstash's host over TLS; locally it is the `serverless-redis-http`
|
|
18
|
+
* proxy in front of a Redis container, and the client cannot tell the
|
|
19
|
+
* difference. That is the whole point of choosing this backend.
|
|
20
|
+
*/
|
|
21
|
+
declare const upstashCacheDriver: CacheDriver;
|
|
22
|
+
/** The same driver for plain HTTP, which is what the local proxy speaks. */
|
|
23
|
+
declare const upstashInsecureCacheDriver: CacheDriver;
|
|
24
|
+
/** What an Upstash cache URL addresses: an HTTP endpoint and the token for it. */
|
|
25
|
+
interface UpstashAddress {
|
|
26
|
+
endpoint: string;
|
|
27
|
+
token: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Split a cache URL into what the client takes.
|
|
31
|
+
*
|
|
32
|
+
* `http://:token@localhost:20705` becomes `{ endpoint: 'http://localhost:20705',
|
|
33
|
+
* token }`. Deployed the scheme is `https` and the host is Upstash's; nothing
|
|
34
|
+
* else differs.
|
|
35
|
+
*/
|
|
36
|
+
declare function parseUpstashUrl(url: string): UpstashAddress;
|
|
12
37
|
//# sourceMappingURL=upstash.d.ts.map
|
|
13
|
-
|
|
14
38
|
//#endregion
|
|
15
|
-
export { UpstashCache };
|
|
39
|
+
export { UpstashAddress, UpstashCache, parseUpstashUrl, upstashCacheDriver, upstashInsecureCacheDriver };
|
|
16
40
|
//# 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"],"sourcesContent":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"upstash.d.cts","names":[],"sources":["../src/upstash.ts"],"sourcesContent":[],"mappings":";;;cAIa,YAAA,YAAwB;EAAxB,QAAA,MAAA;EAAa,WAAA,CAAA,GAAA,EAAA,MAAA,EAAA,KAAA,EAAA,MAAA;EAAA,GAUD,CAAA,GAAA,EAAA,MAAA,CAAA,EAAA,OAAA,CAAA,MAAA,CAAA;EAAO,GAUI,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAAR,OAAQ,CAAA,CAAA,GAAA,SAAA,CAAA;EAAC,GAAT,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,EAAA,KAAA,EAUM,CAVN,EAAA,GAAA,CAAA,EAAA,MAAA,CAAA,EAUsB,OAVtB,CAAA,IAAA,CAAA;EAAO,MAUD,CAAA,GAAA,EAAA,MAAA,CAAA,EAIN,OAJM,CAAA,IAAA,CAAA;;;;AA9BQ;AAgD1C;AASA;AAMA;AAYA;;;cA3Ba,oBAAoB;;cASpB,4BAA4B;;UAMxB,cAAA;;;;;;;;;;;iBAYD,eAAA,eAA8B"}
|
package/dist/upstash.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Cache } from "./index-
|
|
1
|
+
import { Cache, CacheDriver } from "./index-1sNRIo6N.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/upstash.d.ts
|
|
4
4
|
declare class UpstashCache implements Cache {
|
|
@@ -9,8 +9,32 @@ declare class UpstashCache implements Cache {
|
|
|
9
9
|
set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
10
10
|
delete(key: string): Promise<void>;
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* The `https://` and `http://` driver.
|
|
14
|
+
*
|
|
15
|
+
* The token travels in the URL's userinfo, because an address and the
|
|
16
|
+
* credential that opens it are one fact — see {@link parseUpstashUrl}. Deployed
|
|
17
|
+
* that is Upstash's host over TLS; locally it is the `serverless-redis-http`
|
|
18
|
+
* proxy in front of a Redis container, and the client cannot tell the
|
|
19
|
+
* difference. That is the whole point of choosing this backend.
|
|
20
|
+
*/
|
|
21
|
+
declare const upstashCacheDriver: CacheDriver;
|
|
22
|
+
/** The same driver for plain HTTP, which is what the local proxy speaks. */
|
|
23
|
+
declare const upstashInsecureCacheDriver: CacheDriver;
|
|
24
|
+
/** What an Upstash cache URL addresses: an HTTP endpoint and the token for it. */
|
|
25
|
+
interface UpstashAddress {
|
|
26
|
+
endpoint: string;
|
|
27
|
+
token: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Split a cache URL into what the client takes.
|
|
31
|
+
*
|
|
32
|
+
* `http://:token@localhost:20705` becomes `{ endpoint: 'http://localhost:20705',
|
|
33
|
+
* token }`. Deployed the scheme is `https` and the host is Upstash's; nothing
|
|
34
|
+
* else differs.
|
|
35
|
+
*/
|
|
36
|
+
declare function parseUpstashUrl(url: string): UpstashAddress;
|
|
12
37
|
//# sourceMappingURL=upstash.d.ts.map
|
|
13
|
-
|
|
14
38
|
//#endregion
|
|
15
|
-
export { UpstashCache };
|
|
39
|
+
export { UpstashAddress, UpstashCache, parseUpstashUrl, upstashCacheDriver, upstashInsecureCacheDriver };
|
|
16
40
|
//# 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"],"sourcesContent":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"upstash.d.mts","names":[],"sources":["../src/upstash.ts"],"sourcesContent":[],"mappings":";;;cAIa,YAAA,YAAwB;EAAxB,QAAA,MAAA;EAAa,WAAA,CAAA,GAAA,EAAA,MAAA,EAAA,KAAA,EAAA,MAAA;EAAA,GAUD,CAAA,GAAA,EAAA,MAAA,CAAA,EAAA,OAAA,CAAA,MAAA,CAAA;EAAO,GAUI,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAAR,OAAQ,CAAA,CAAA,GAAA,SAAA,CAAA;EAAC,GAAT,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,EAAA,KAAA,EAUM,CAVN,EAAA,GAAA,CAAA,EAAA,MAAA,CAAA,EAUsB,OAVtB,CAAA,IAAA,CAAA;EAAO,MAUD,CAAA,GAAA,EAAA,MAAA,CAAA,EAIN,OAJM,CAAA,IAAA,CAAA;;;;AA9BQ;AAgD1C;AASA;AAMA;AAYA;;;cA3Ba,oBAAoB;;cASpB,4BAA4B;;UAMxB,cAAA;;;;;;;;;;;iBAYD,eAAA,eAA8B"}
|
package/dist/upstash.mjs
CHANGED
|
@@ -26,7 +26,45 @@ var UpstashCache = class {
|
|
|
26
26
|
await this.client.del(key);
|
|
27
27
|
}
|
|
28
28
|
};
|
|
29
|
+
/**
|
|
30
|
+
* The `https://` and `http://` driver.
|
|
31
|
+
*
|
|
32
|
+
* The token travels in the URL's userinfo, because an address and the
|
|
33
|
+
* credential that opens it are one fact — see {@link parseUpstashUrl}. Deployed
|
|
34
|
+
* that is Upstash's host over TLS; locally it is the `serverless-redis-http`
|
|
35
|
+
* proxy in front of a Redis container, and the client cannot tell the
|
|
36
|
+
* difference. That is the whole point of choosing this backend.
|
|
37
|
+
*/
|
|
38
|
+
const upstashCacheDriver = {
|
|
39
|
+
scheme: "https:",
|
|
40
|
+
create: (url) => {
|
|
41
|
+
const { endpoint, token } = parseUpstashUrl(url);
|
|
42
|
+
return new UpstashCache(endpoint, token);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
/** The same driver for plain HTTP, which is what the local proxy speaks. */
|
|
46
|
+
const upstashInsecureCacheDriver = {
|
|
47
|
+
...upstashCacheDriver,
|
|
48
|
+
scheme: "http:"
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Split a cache URL into what the client takes.
|
|
52
|
+
*
|
|
53
|
+
* `http://:token@localhost:20705` becomes `{ endpoint: 'http://localhost:20705',
|
|
54
|
+
* token }`. Deployed the scheme is `https` and the host is Upstash's; nothing
|
|
55
|
+
* else differs.
|
|
56
|
+
*/
|
|
57
|
+
function parseUpstashUrl(url) {
|
|
58
|
+
const parsed = new URL(url);
|
|
59
|
+
const token = decodeURIComponent(parsed.password || parsed.username);
|
|
60
|
+
parsed.username = "";
|
|
61
|
+
parsed.password = "";
|
|
62
|
+
return {
|
|
63
|
+
endpoint: parsed.origin,
|
|
64
|
+
token
|
|
65
|
+
};
|
|
66
|
+
}
|
|
29
67
|
|
|
30
68
|
//#endregion
|
|
31
|
-
export { UpstashCache };
|
|
69
|
+
export { UpstashCache, parseUpstashUrl, upstashCacheDriver, upstashInsecureCacheDriver };
|
|
32
70
|
//# sourceMappingURL=upstash.mjs.map
|
package/dist/upstash.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upstash.mjs","names":["url: string","token: string","key: string","value: T"],"sources":["../src/upstash.ts"],"sourcesContent":["import { Redis } from '@upstash/redis';\nimport type { Cache } from './';\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"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"upstash.mjs","names":["url: string","token: string","key: string","value: T","upstashCacheDriver: CacheDriver","upstashInsecureCacheDriver: CacheDriver"],"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,AAAQ;CAER,YAAYA,KAAaC,OAAe;AACvC,OAAK,SAAS,IAAI,MAAM;GACvB;GACA;EACA;CACD;CAED,MAAM,IAAIC,KAA8B;EACvC,MAAM,MAAM,MAAM,KAAK,OAAO,IAAI,IAAI;AAEtC,MAAI,QAAQ,GACX,QAAO;AAGR,SAAO;CACP;CAED,MAAM,IAAOA,KAAqC;EACjD,MAAM,IAAI,MAAM,KAAK,OAAO,IAAI,IAAI;AAEpC,MAAI,MAAM,KACT;AAGD,SAAO;CACP;CAED,MAAM,IAAOA,KAAaC,OAAU,MAAM,MAAqB;AAC9D,QAAM,KAAK,OAAO,IAAI,KAAK,OAAO,EAAE,IAAI,IAAK,EAAC;CAC9C;CAED,MAAM,OAAOD,KAA4B;AACxC,QAAM,KAAK,OAAO,IAAI,IAAI;CAC1B;AACD;;;;;;;;;;AAWD,MAAaE,qBAAkC;CAC9C,QAAQ;CACR,QAAQ,CAAC,QAAQ;EAChB,MAAM,EAAE,UAAU,OAAO,GAAG,gBAAgB,IAAI;AAChD,SAAO,IAAI,aAAa,UAAU;CAClC;AACD;;AAGD,MAAaC,6BAA0C;CACtD,GAAG;CACH,QAAQ;AACR;;;;;;;;AAeD,SAAgB,gBAAgBL,KAA6B;CAC5D,MAAM,SAAS,IAAI,IAAI;CACvB,MAAM,QAAQ,mBAAmB,OAAO,YAAY,OAAO,SAAS;AAEpE,QAAO,WAAW;AAClB,QAAO,WAAW;AAElB,QAAO;EAGN,UAAU,OAAO;EACjB;CACA;AACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geekmidas/cache",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.0-alpha.1",
|
|
4
4
|
"description": "Unified cache interface with multiple storage implementations",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -35,6 +35,26 @@
|
|
|
35
35
|
"default": "./dist/upstash.cjs"
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
|
+
"./redis": {
|
|
39
|
+
"import": {
|
|
40
|
+
"types": "./dist/redis.d.mts",
|
|
41
|
+
"default": "./dist/redis.mjs"
|
|
42
|
+
},
|
|
43
|
+
"require": {
|
|
44
|
+
"types": "./dist/redis.d.cts",
|
|
45
|
+
"default": "./dist/redis.cjs"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"./postgres": {
|
|
49
|
+
"import": {
|
|
50
|
+
"types": "./dist/postgres.d.mts",
|
|
51
|
+
"default": "./dist/postgres.mjs"
|
|
52
|
+
},
|
|
53
|
+
"require": {
|
|
54
|
+
"types": "./dist/postgres.d.cts",
|
|
55
|
+
"default": "./dist/postgres.cjs"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
38
58
|
"./expo": {
|
|
39
59
|
"import": {
|
|
40
60
|
"types": "./dist/expo.d.mts",
|
|
@@ -56,6 +76,9 @@
|
|
|
56
76
|
}
|
|
57
77
|
}
|
|
58
78
|
},
|
|
79
|
+
"files": [
|
|
80
|
+
"dist"
|
|
81
|
+
],
|
|
59
82
|
"repository": {
|
|
60
83
|
"type": "git",
|
|
61
84
|
"url": "https://github.com/geekmidas/toolbox"
|
|
@@ -70,9 +93,28 @@
|
|
|
70
93
|
},
|
|
71
94
|
"peerDependencies": {
|
|
72
95
|
"@upstash/redis": "~1.35.1",
|
|
73
|
-
"expo-secure-store": "^14.2.3"
|
|
96
|
+
"expo-secure-store": "^14.2.3",
|
|
97
|
+
"ioredis": "^5.4.0",
|
|
98
|
+
"pg": "^8.13.0"
|
|
74
99
|
},
|
|
75
100
|
"devDependencies": {
|
|
76
|
-
"@types/
|
|
101
|
+
"@types/pg": "~8.15.5",
|
|
102
|
+
"@types/proper-lockfile": "^4.1.4",
|
|
103
|
+
"ioredis": "~5.8.2",
|
|
104
|
+
"pg": "~8.16.3"
|
|
105
|
+
},
|
|
106
|
+
"peerDependenciesMeta": {
|
|
107
|
+
"@upstash/redis": {
|
|
108
|
+
"optional": true
|
|
109
|
+
},
|
|
110
|
+
"expo-secure-store": {
|
|
111
|
+
"optional": true
|
|
112
|
+
},
|
|
113
|
+
"ioredis": {
|
|
114
|
+
"optional": true
|
|
115
|
+
},
|
|
116
|
+
"pg": {
|
|
117
|
+
"optional": true
|
|
118
|
+
}
|
|
77
119
|
}
|
|
78
120
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
# @geekmidas/cache
|
|
2
|
-
|
|
3
|
-
## 9.0.2
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- [#12](https://github.com/geekmidas/toolbox/pull/12) [`d53863a`](https://github.com/geekmidas/toolbox/commit/d53863a84db2e4ab5420e08f79128b637043fc42) Thanks [@geekmidas](https://github.com/geekmidas)! - Align every published package on a single version and keep them in step.
|
|
8
|
-
|
|
9
|
-
All packages now share one version, enforced by a changesets `fixed` group. The
|
|
10
|
-
baseline is 9.0.1 — @geekmidas/client's published version — so nothing moves
|
|
11
|
-
backwards; this release takes the whole set to 9.0.2 together.
|
|
12
|
-
|
|
13
|
-
Independent versions made "which version of the docs applies to me"
|
|
14
|
-
unanswerable: a reader on constructs@7 and cli@2 was on no version at all. One
|
|
15
|
-
number per release makes versioned documentation possible, and lets 9 freeze as
|
|
16
|
-
the current paradigm while the constructs rework is developed against it.
|
|
17
|
-
|
|
18
|
-
Every release now publishes every package, and a major anywhere is a major
|
|
19
|
-
everywhere. Peer ranges get simpler in return.
|
|
20
|
-
|
|
21
|
-
## 1.1.2
|
|
22
|
-
|
|
23
|
-
### Patch Changes
|
|
24
|
-
|
|
25
|
-
- 🐛 [#11](https://github.com/geekmidas/toolbox/pull/11) [`40f4dc0`](https://github.com/geekmidas/toolbox/commit/40f4dc095911b2223a255029d8f776caf7781309) Thanks [@geekmidas](https://github.com/geekmidas)! - Patch release across all packages to realign published versions with the
|
|
26
|
-
registry. The previous release only published the four packages that had
|
|
27
|
-
version bumps; the remaining packages failed with "cannot publish over the
|
|
28
|
-
previously published versions" because their versions were unchanged.
|
|
29
|
-
|
|
30
|
-
## 1.1.1
|
|
31
|
-
|
|
32
|
-
### Patch Changes
|
|
33
|
-
|
|
34
|
-
- 🐛 [`d70c6c0`](https://github.com/geekmidas/toolbox/commit/d70c6c0aeb8a79da2473ac77dbd8255a4a2f5651) Thanks [@geekmidas](https://github.com/geekmidas)! - Fix `package.json` exports so TypeScript declarations resolve correctly under NodeNext/Bundler module resolution. Each subpath export now nests `types` inside its `import`/`require` condition, pointing at the `.d.mts` and `.d.cts` files that `tsdown` actually emits (previously the exports referenced non-existent `.d.ts` files, causing type-resolution failures for consumers). Both ESM (`.mjs`) and CJS (`.cjs`) runtime entry points are preserved. Additionally, `@geekmidas/ui` had `import` paths pointing at `.js` files that were never emitted — those are corrected to `.mjs`.
|
|
35
|
-
|
|
36
|
-
## 1.1.0
|
|
37
|
-
|
|
38
|
-
### Minor Changes
|
|
39
|
-
|
|
40
|
-
- ✨ [`be4f7a9`](https://github.com/geekmidas/toolbox/commit/be4f7a9bd5de7f08adbca582916d6902e0c24de2) Thanks [@geekmidas](https://github.com/geekmidas)! - Add partition support for manifest generation. Users can now group constructs (routes, functions, crons, subscribers) into named partitions by providing a `partition` callback per construct type in the config. Manifests output partitioned fields as `Record<string, T[]>` while remaining flat `T[]` arrays when no partitions are configured.
|
|
41
|
-
|
|
42
|
-
Fix mutation type inference in endpoint hooks by using `UseMutationResult` and `UseQueryResult` types directly instead of `ReturnType<typeof useMutation>`, which could resolve to `never` for complex path definitions.
|
|
43
|
-
|
|
44
|
-
Add `FileCache` implementation that persists cache entries to a JSON file on disk. Default location is `process.cwd()/.gkm/cache.json`. Uses an in-process mutex combined with `proper-lockfile` for safe concurrent and cross-process writes.
|
|
45
|
-
|
|
46
|
-
## 1.0.0
|
|
47
|
-
|
|
48
|
-
### Major Changes
|
|
49
|
-
|
|
50
|
-
- [`ff7b115`](https://github.com/geekmidas/toolbox/commit/ff7b11599f60f84ac6cdc73714c853ecf786b2e8) Thanks [@geekmidas](https://github.com/geekmidas)! - Version 1 Stable release
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
//#region src/index.d.ts
|
|
2
|
-
declare const getExpirationInSeconds: (expiresAt: string | number | Date | undefined | null) => number;
|
|
3
|
-
interface Cache {
|
|
4
|
-
/**
|
|
5
|
-
* Retrieves a value from the cache.
|
|
6
|
-
*
|
|
7
|
-
* @param key The key to retrieve the value for.
|
|
8
|
-
* @returns The cached value, or undefined if not found.
|
|
9
|
-
*/
|
|
10
|
-
get<T>(key: string): Promise<T | undefined>;
|
|
11
|
-
/**
|
|
12
|
-
* Sets a value in the cache.
|
|
13
|
-
*
|
|
14
|
-
* @param key The key to set the value for.
|
|
15
|
-
* @param value The value to cache.
|
|
16
|
-
* @param ttl Optional time-to-live in seconds. If not provided, the value will not expire.
|
|
17
|
-
*/
|
|
18
|
-
set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
19
|
-
/**
|
|
20
|
-
* Deletes a value from the cache.
|
|
21
|
-
*
|
|
22
|
-
* @param key The key to delete from the cache.
|
|
23
|
-
*/
|
|
24
|
-
delete(key: string): Promise<void>;
|
|
25
|
-
/**
|
|
26
|
-
* Retrieves the time-to-live (TTL) for a cached value.
|
|
27
|
-
*
|
|
28
|
-
* @param key The key to retrieve the TTL for.
|
|
29
|
-
* @returns The TTL in seconds, or 0 if the key does not exist.
|
|
30
|
-
*/
|
|
31
|
-
ttl(key: string): Promise<number>;
|
|
32
|
-
}
|
|
33
|
-
//# sourceMappingURL=index.d.ts.map
|
|
34
|
-
//#endregion
|
|
35
|
-
export { Cache, getExpirationInSeconds };
|
|
36
|
-
//# sourceMappingURL=index-BSYYdwRm.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index-BSYYdwRm.d.cts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";cAEa,sDACiB;AADjB,UAeI,KAAA,CAfJ;EAeI;;;;;;EAeoC,GAM/B,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAdA,OAcA,CAdQ,CAcR,GAAA,SAAA,CAAA;EAAO;AAQH;;;;;;6BAdE,kBAAkB;;;;;;uBAMxB;;;;;;;oBAQH"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
//#region src/index.d.ts
|
|
2
|
-
declare const getExpirationInSeconds: (expiresAt: string | number | Date | undefined | null) => number;
|
|
3
|
-
interface Cache {
|
|
4
|
-
/**
|
|
5
|
-
* Retrieves a value from the cache.
|
|
6
|
-
*
|
|
7
|
-
* @param key The key to retrieve the value for.
|
|
8
|
-
* @returns The cached value, or undefined if not found.
|
|
9
|
-
*/
|
|
10
|
-
get<T>(key: string): Promise<T | undefined>;
|
|
11
|
-
/**
|
|
12
|
-
* Sets a value in the cache.
|
|
13
|
-
*
|
|
14
|
-
* @param key The key to set the value for.
|
|
15
|
-
* @param value The value to cache.
|
|
16
|
-
* @param ttl Optional time-to-live in seconds. If not provided, the value will not expire.
|
|
17
|
-
*/
|
|
18
|
-
set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
19
|
-
/**
|
|
20
|
-
* Deletes a value from the cache.
|
|
21
|
-
*
|
|
22
|
-
* @param key The key to delete from the cache.
|
|
23
|
-
*/
|
|
24
|
-
delete(key: string): Promise<void>;
|
|
25
|
-
/**
|
|
26
|
-
* Retrieves the time-to-live (TTL) for a cached value.
|
|
27
|
-
*
|
|
28
|
-
* @param key The key to retrieve the TTL for.
|
|
29
|
-
* @returns The TTL in seconds, or 0 if the key does not exist.
|
|
30
|
-
*/
|
|
31
|
-
ttl(key: string): Promise<number>;
|
|
32
|
-
}
|
|
33
|
-
//# sourceMappingURL=index.d.ts.map
|
|
34
|
-
//#endregion
|
|
35
|
-
export { Cache, getExpirationInSeconds };
|
|
36
|
-
//# sourceMappingURL=index-Dx96gr-9.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index-Dx96gr-9.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";cAEa,sDACiB;AADjB,UAeI,KAAA,CAfJ;EAeI;;;;;;EAeoC,GAM/B,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAdA,OAcA,CAdQ,CAcR,GAAA,SAAA,CAAA;EAAO;AAQH;;;;;;6BAdE,kBAAkB;;;;;;uBAMxB;;;;;;;oBAQH"}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { bench, describe } from 'vitest';
|
|
2
|
-
import { InMemoryCache } from '../memory';
|
|
3
|
-
|
|
4
|
-
describe('InMemoryCache', () => {
|
|
5
|
-
const cache = new InMemoryCache();
|
|
6
|
-
|
|
7
|
-
bench('set with TTL', async () => {
|
|
8
|
-
await cache.set('key', 'value', 3600);
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
bench('get (cache hit)', async () => {
|
|
12
|
-
await cache.set('hit-key', 'value', 3600);
|
|
13
|
-
await cache.get('hit-key');
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
bench('get (cache miss)', async () => {
|
|
17
|
-
await cache.get('nonexistent-key');
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
bench('delete', async () => {
|
|
21
|
-
await cache.set('delete-key', 'value', 3600);
|
|
22
|
-
await cache.delete('delete-key');
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
bench('set + get cycle', async () => {
|
|
26
|
-
const key = `cycle-${Math.random()}`;
|
|
27
|
-
await cache.set(key, 'value', 3600);
|
|
28
|
-
await cache.get(key);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
describe('InMemoryCache - Large Scale', () => {
|
|
33
|
-
bench('1000 sequential sets', async () => {
|
|
34
|
-
const cache = new InMemoryCache();
|
|
35
|
-
for (let i = 0; i < 1000; i++) {
|
|
36
|
-
await cache.set(`key-${i}`, `value-${i}`, 3600);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
bench('1000 sequential gets', async () => {
|
|
41
|
-
const cache = new InMemoryCache();
|
|
42
|
-
// Pre-populate
|
|
43
|
-
for (let i = 0; i < 1000; i++) {
|
|
44
|
-
await cache.set(`key-${i}`, `value-${i}`, 3600);
|
|
45
|
-
}
|
|
46
|
-
// Benchmark gets
|
|
47
|
-
for (let i = 0; i < 1000; i++) {
|
|
48
|
-
await cache.get(`key-${i}`);
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
});
|