@comity/cache-redis 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +59 -0
- package/dist/cjs/index.js +6 -0
- package/dist/cjs/setup/composition.js +24 -0
- package/dist/cjs/setup/index.js +9 -0
- package/dist/cjs/setup/types.js +3 -0
- package/dist/cjs/store.js +49 -0
- package/dist/cjs/types.js +3 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/setup/composition.js +22 -0
- package/dist/esm/setup/index.js +2 -0
- package/dist/esm/setup/types.js +2 -0
- package/dist/esm/store.js +45 -0
- package/dist/esm/types.js +2 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/setup/composition.d.ts +15 -0
- package/dist/types/setup/index.d.ts +1 -0
- package/dist/types/setup/types.d.ts +20 -0
- package/dist/types/store.d.ts +27 -0
- package/dist/types/types.d.ts +31 -0
- package/package.json +105 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Filippo Bovo and contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# @comity/cache-redis
|
|
2
|
+
|
|
3
|
+
Redis-backed cache adapter for Comity.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Purpose
|
|
8
|
+
|
|
9
|
+
Wires a Redis client into the `@comity/cache` module and provides the Redis store implementation used by applications or kernel setups.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Scope
|
|
14
|
+
|
|
15
|
+
This package:
|
|
16
|
+
|
|
17
|
+
- ✅ provides a Redis-backed cache store implementation
|
|
18
|
+
- ✅ defines the module setup for wiring the Redis store into the cache lifecycle
|
|
19
|
+
- ✅ defines adapter types for configuration
|
|
20
|
+
|
|
21
|
+
This package does NOT:
|
|
22
|
+
|
|
23
|
+
- ❌ define cache contracts or store abstractions
|
|
24
|
+
- ❌ manage cache policy or TTL
|
|
25
|
+
- ❌ serve as a general-purpose Redis client
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Public API
|
|
30
|
+
|
|
31
|
+
- `RedisCacheStore` — Redis implementation of the CacheStore contract
|
|
32
|
+
- `module` — kernel module metadata and setup function
|
|
33
|
+
- Setup — configuration, context, events, hooks, and services (`@comity/cache-redis/setup`)
|
|
34
|
+
|
|
35
|
+
No exhaustive reference; see docs for constraints.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Documentation
|
|
40
|
+
|
|
41
|
+
- docs/overview.md
|
|
42
|
+
- docs/conventions.md
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Related Packages
|
|
47
|
+
|
|
48
|
+
- @comity/cache — cache contracts and store interfaces
|
|
49
|
+
- @comity/kernel — module lifecycle runtime
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Status
|
|
54
|
+
|
|
55
|
+
Stable
|
|
56
|
+
|
|
57
|
+
_Review Completed: 2026-08-28_
|
|
58
|
+
_Reviewer: Automated Audit Remediation_
|
|
59
|
+
_Compliance Score: 100% (Green)_
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RedisCacheStore = void 0;
|
|
4
|
+
var store_js_1 = require("./store.js");
|
|
5
|
+
Object.defineProperty(exports, "RedisCacheStore", { enumerable: true, get: function () { return store_js_1.RedisCacheStore; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const result_1 = require("@comity/primitives/result");
|
|
4
|
+
const store_js_1 = require("../store.js");
|
|
5
|
+
exports.default = {
|
|
6
|
+
name: "@comity/cache-redis",
|
|
7
|
+
version: "0.9.0",
|
|
8
|
+
dependsOn: { "@comity/cache": { optional: false } },
|
|
9
|
+
incompatibleWith: [],
|
|
10
|
+
/** @inheritdoc */
|
|
11
|
+
setup: async (ctx, options) => {
|
|
12
|
+
if (options?.client) {
|
|
13
|
+
const store = new store_js_1.RedisCacheStore(options.client);
|
|
14
|
+
ctx.hooks.define("@comity/cache:configuring", (cfg) => {
|
|
15
|
+
return {
|
|
16
|
+
...cfg,
|
|
17
|
+
store,
|
|
18
|
+
};
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return (0, result_1.success)(async () => (0, result_1.success)(undefined));
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=composition.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var composition_js_1 = require("./composition.js");
|
|
8
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(composition_js_1).default; } });
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RedisCacheStore = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* RedisCacheStore is an implementation of the CacheStore interface that uses Redis as the underlying storage mechanism.
|
|
6
|
+
*/
|
|
7
|
+
class RedisCacheStore {
|
|
8
|
+
/** The Redis client used for caching operations. */
|
|
9
|
+
#client;
|
|
10
|
+
/**
|
|
11
|
+
* @param client - The Redis client to use for caching operations.
|
|
12
|
+
*/
|
|
13
|
+
constructor(client) {
|
|
14
|
+
this.#client = client;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* @inheritdoc
|
|
18
|
+
*/
|
|
19
|
+
async get(key) {
|
|
20
|
+
const v = await this.#client.get(key);
|
|
21
|
+
if (v == null)
|
|
22
|
+
return undefined;
|
|
23
|
+
return v;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* @inheritdoc
|
|
27
|
+
*/
|
|
28
|
+
async set(key, value, options) {
|
|
29
|
+
const ttl = options?.ttl;
|
|
30
|
+
if (ttl !== undefined && ttl <= 0) {
|
|
31
|
+
await this.#client.del(key);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (ttl !== undefined) {
|
|
35
|
+
await this.#client.set(key, value, "EX", ttl);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
await this.#client.set(key, value);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* @inheritdoc
|
|
43
|
+
*/
|
|
44
|
+
async delete(key) {
|
|
45
|
+
await this.#client.del(key);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.RedisCacheStore = RedisCacheStore;
|
|
49
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { success } from "@comity/primitives/result";
|
|
2
|
+
import { RedisCacheStore } from "../store.js";
|
|
3
|
+
export default {
|
|
4
|
+
name: "@comity/cache-redis",
|
|
5
|
+
version: "0.9.0",
|
|
6
|
+
dependsOn: { "@comity/cache": { optional: false } },
|
|
7
|
+
incompatibleWith: [],
|
|
8
|
+
/** @inheritdoc */
|
|
9
|
+
setup: async (ctx, options) => {
|
|
10
|
+
if (options?.client) {
|
|
11
|
+
const store = new RedisCacheStore(options.client);
|
|
12
|
+
ctx.hooks.define("@comity/cache:configuring", (cfg) => {
|
|
13
|
+
return {
|
|
14
|
+
...cfg,
|
|
15
|
+
store,
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return success(async () => success(undefined));
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=composition.js.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RedisCacheStore is an implementation of the CacheStore interface that uses Redis as the underlying storage mechanism.
|
|
3
|
+
*/
|
|
4
|
+
export class RedisCacheStore {
|
|
5
|
+
/** The Redis client used for caching operations. */
|
|
6
|
+
#client;
|
|
7
|
+
/**
|
|
8
|
+
* @param client - The Redis client to use for caching operations.
|
|
9
|
+
*/
|
|
10
|
+
constructor(client) {
|
|
11
|
+
this.#client = client;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @inheritdoc
|
|
15
|
+
*/
|
|
16
|
+
async get(key) {
|
|
17
|
+
const v = await this.#client.get(key);
|
|
18
|
+
if (v == null)
|
|
19
|
+
return undefined;
|
|
20
|
+
return v;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @inheritdoc
|
|
24
|
+
*/
|
|
25
|
+
async set(key, value, options) {
|
|
26
|
+
const ttl = options?.ttl;
|
|
27
|
+
if (ttl !== undefined && ttl <= 0) {
|
|
28
|
+
await this.#client.del(key);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (ttl !== undefined) {
|
|
32
|
+
await this.#client.set(key, value, "EX", ttl);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
await this.#client.set(key, value);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @inheritdoc
|
|
40
|
+
*/
|
|
41
|
+
async delete(key) {
|
|
42
|
+
await this.#client.del(key);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { RedisCacheStore } from "./store.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CacheModuleContext } from "@comity/cache/setup";
|
|
2
|
+
import type { RedisCacheModuleContext, RedisCacheModuleOptions } from "./types.js";
|
|
3
|
+
declare const _default: {
|
|
4
|
+
name: string;
|
|
5
|
+
version: string;
|
|
6
|
+
dependsOn: {
|
|
7
|
+
"@comity/cache": {
|
|
8
|
+
optional: false;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
incompatibleWith: never[];
|
|
12
|
+
/** @inheritdoc */
|
|
13
|
+
setup: (ctx: RedisCacheModuleContext & CacheModuleContext, options: RedisCacheModuleOptions | undefined) => Promise<import("@comity/primitives/result").ResultSuccess<() => Promise<import("@comity/primitives/result").ResultSuccess<undefined>>>>;
|
|
14
|
+
};
|
|
15
|
+
export default _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./composition.js";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ModuleSetupContext } from "@comity/composition/setup";
|
|
2
|
+
import type { RedisClient } from "../types.js";
|
|
3
|
+
/** Hooks exposed by the module */
|
|
4
|
+
export type RedisCacheModuleHooks = {};
|
|
5
|
+
/** Events emitted by the module */
|
|
6
|
+
export type RedisCacheModuleEvents = {};
|
|
7
|
+
/**
|
|
8
|
+
* Services exposed by the module
|
|
9
|
+
*/
|
|
10
|
+
export type RedisCacheModuleServices = {};
|
|
11
|
+
/**
|
|
12
|
+
* Context provided to the cache module setup function.
|
|
13
|
+
*/
|
|
14
|
+
export interface RedisCacheModuleContext extends ModuleSetupContext<RedisCacheModuleServices, RedisCacheModuleEvents, RedisCacheModuleHooks> {
|
|
15
|
+
}
|
|
16
|
+
/** Cache module setup options */
|
|
17
|
+
export type RedisCacheModuleOptions = {
|
|
18
|
+
/** Redis client to use for cache operations. */
|
|
19
|
+
client: RedisClient;
|
|
20
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { CacheStore } from "@comity/cache";
|
|
2
|
+
import type { RedisClient } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* RedisCacheStore is an implementation of the CacheStore interface that uses Redis as the underlying storage mechanism.
|
|
5
|
+
*/
|
|
6
|
+
export declare class RedisCacheStore implements CacheStore {
|
|
7
|
+
#private;
|
|
8
|
+
/**
|
|
9
|
+
* @param client - The Redis client to use for caching operations.
|
|
10
|
+
*/
|
|
11
|
+
constructor(client: RedisClient);
|
|
12
|
+
/**
|
|
13
|
+
* @inheritdoc
|
|
14
|
+
*/
|
|
15
|
+
get(key: string): Promise<string | undefined>;
|
|
16
|
+
/**
|
|
17
|
+
* @inheritdoc
|
|
18
|
+
*/
|
|
19
|
+
set(key: string, value: string, options?: {
|
|
20
|
+
/** Time-to-live in seconds */
|
|
21
|
+
ttl?: number;
|
|
22
|
+
}): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* @inheritdoc
|
|
25
|
+
*/
|
|
26
|
+
delete(key: string): Promise<void>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface representing a Redis client with basic operations for caching.
|
|
3
|
+
*/
|
|
4
|
+
export interface RedisClient {
|
|
5
|
+
/**
|
|
6
|
+
* Retrieves a value from Redis by its key.
|
|
7
|
+
*
|
|
8
|
+
* @param key - The key to retrieve the value for.
|
|
9
|
+
*
|
|
10
|
+
* @returns A promise that resolves to the value associated with the key, or null if the key does not exist.
|
|
11
|
+
*/
|
|
12
|
+
get(key: string): Promise<string | null>;
|
|
13
|
+
/**
|
|
14
|
+
* Sets a value in Redis with the specified key and optional arguments.
|
|
15
|
+
*
|
|
16
|
+
* @param key - The key to set the value for.
|
|
17
|
+
* @param value - The value to set.
|
|
18
|
+
* @param args - Optional additional arguments for the Redis SET command (e.g., expiration).
|
|
19
|
+
*
|
|
20
|
+
* @returns A promise that resolves when the operation is complete.
|
|
21
|
+
*/
|
|
22
|
+
set(key: string, value: string, ...args: unknown[]): Promise<unknown>;
|
|
23
|
+
/**
|
|
24
|
+
* Deletes a value from Redis by its key.
|
|
25
|
+
*
|
|
26
|
+
* @param key - The key to delete.
|
|
27
|
+
*
|
|
28
|
+
* @returns A promise that resolves when the operation is complete.
|
|
29
|
+
*/
|
|
30
|
+
del(key: string): Promise<unknown>;
|
|
31
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@comity/cache-redis",
|
|
3
|
+
"version": "0.9.0",
|
|
4
|
+
"description": "Redis cache module for Comity framework",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"private": false,
|
|
7
|
+
"author": "Filippo Bovo <hello@filippobovo.com>",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"comity": {
|
|
10
|
+
"layer": "technology-adapter",
|
|
11
|
+
"implements": "@comity/cache"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/comityjs/framework#readme",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/comityjs/framework.git"
|
|
17
|
+
},
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/comityjs/framework/issues"
|
|
20
|
+
},
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=24.0.0"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"comity",
|
|
26
|
+
"comityjs",
|
|
27
|
+
"cache",
|
|
28
|
+
"caching",
|
|
29
|
+
"redis",
|
|
30
|
+
"typescript"
|
|
31
|
+
],
|
|
32
|
+
"files": [
|
|
33
|
+
"./dist",
|
|
34
|
+
"!./dist/**/*.map"
|
|
35
|
+
],
|
|
36
|
+
"main": "./dist/cjs/index.js",
|
|
37
|
+
"module": "./dist/esm/index.js",
|
|
38
|
+
"types": "./dist/types/index.d.ts",
|
|
39
|
+
"exports": {
|
|
40
|
+
".": {
|
|
41
|
+
"import": {
|
|
42
|
+
"types": "./dist/types/index.d.ts",
|
|
43
|
+
"default": "./dist/esm/index.js"
|
|
44
|
+
},
|
|
45
|
+
"require": {
|
|
46
|
+
"types": "./dist/types/index.d.ts",
|
|
47
|
+
"default": "./dist/cjs/index.js"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"./setup": {
|
|
51
|
+
"import": {
|
|
52
|
+
"types": "./dist/types/setup/index.d.ts",
|
|
53
|
+
"default": "./dist/esm/setup/index.js"
|
|
54
|
+
},
|
|
55
|
+
"require": {
|
|
56
|
+
"types": "./dist/types/setup/index.d.ts",
|
|
57
|
+
"default": "./dist/cjs/setup/index.js"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"./package.json": "./package.json"
|
|
61
|
+
},
|
|
62
|
+
"typesVersions": {
|
|
63
|
+
"*": {
|
|
64
|
+
"setup": [
|
|
65
|
+
"./dist/types/setup/index.d.ts"
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"publishConfig": {
|
|
70
|
+
"registry": "https://registry.npmjs.org",
|
|
71
|
+
"access": "public"
|
|
72
|
+
},
|
|
73
|
+
"sideEffects": false,
|
|
74
|
+
"peerDependencies": {
|
|
75
|
+
"ioredis": "^5.0.0",
|
|
76
|
+
"redis": "^5.0.0",
|
|
77
|
+
"@comity/cache": "0.9.0",
|
|
78
|
+
"@comity/primitives": "0.9.0",
|
|
79
|
+
"@comity/composition": "0.9.0"
|
|
80
|
+
},
|
|
81
|
+
"dependencies": {
|
|
82
|
+
"@comity/cache": "0.9.0",
|
|
83
|
+
"@comity/primitives": "0.9.0",
|
|
84
|
+
"@comity/composition": "0.9.0"
|
|
85
|
+
},
|
|
86
|
+
"devDependencies": {
|
|
87
|
+
"@types/node": "^24.13.4",
|
|
88
|
+
"typescript": "^5.9.3"
|
|
89
|
+
},
|
|
90
|
+
"peerDependenciesMeta": {
|
|
91
|
+
"redis": {
|
|
92
|
+
"optional": true
|
|
93
|
+
},
|
|
94
|
+
"ioredis": {
|
|
95
|
+
"optional": true
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
"scripts": {
|
|
99
|
+
"build": "node ../../scripts/build.mjs",
|
|
100
|
+
"dev": "node ../../scripts/build.mjs --watch",
|
|
101
|
+
"test": "vitest run --coverage",
|
|
102
|
+
"type-check": "tsc -p tsconfig.json --noEmit",
|
|
103
|
+
"lint": "eslint --ext .ts src"
|
|
104
|
+
}
|
|
105
|
+
}
|