@comity/cache-kv 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 +57 -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 +46 -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 +42 -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 +14 -0
- package/package.json +94 -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,57 @@
|
|
|
1
|
+
# @comity/cache-kv
|
|
2
|
+
|
|
3
|
+
Key-value cache adapter for the Comity cache module.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Purpose
|
|
8
|
+
|
|
9
|
+
Adapts a key-value cache store into the `@comity/cache` module wiring. Provides the kernel setup needed to connect a KV store to the standard cache lifecycle.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Scope
|
|
14
|
+
|
|
15
|
+
This package:
|
|
16
|
+
|
|
17
|
+
- provides a module that wires a KV cache into Comity
|
|
18
|
+
- exposes setup types for configuring the KV cache adapter
|
|
19
|
+
|
|
20
|
+
This package does NOT:
|
|
21
|
+
|
|
22
|
+
- define cache contracts or store abstractions
|
|
23
|
+
- implement the cache store itself
|
|
24
|
+
- manage cache TTL or serialization
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Public API
|
|
29
|
+
|
|
30
|
+
- `module` — kernel module metadata and setup function
|
|
31
|
+
- Setup — configuration types for the KV adapter (`@comity/cache-kv/setup`)
|
|
32
|
+
|
|
33
|
+
No exhaustive reference; see docs for constraints.
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Documentation
|
|
38
|
+
|
|
39
|
+
- docs/overview.md
|
|
40
|
+
- docs/conventions.md
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Related Packages
|
|
45
|
+
|
|
46
|
+
- @comity/cache — cache contracts and store abstractions
|
|
47
|
+
- @comity/kernel — module lifecycle runtime
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Status
|
|
52
|
+
|
|
53
|
+
Stable
|
|
54
|
+
|
|
55
|
+
_Review Completed: 2026-07-25_
|
|
56
|
+
_Reviewer: Hobiri MAGI (DeepSeek v4 Pro)_
|
|
57
|
+
_Compliance Score: 99.5% (Green)_
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KvCacheStore = void 0;
|
|
4
|
+
var store_js_1 = require("./store.js");
|
|
5
|
+
Object.defineProperty(exports, "KvCacheStore", { enumerable: true, get: function () { return store_js_1.KvCacheStore; } });
|
|
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-kv",
|
|
7
|
+
version: "0.9.0",
|
|
8
|
+
dependsOn: { "@comity/cache": { optional: false } },
|
|
9
|
+
incompatibleWith: [],
|
|
10
|
+
/** @inheritdoc */
|
|
11
|
+
setup: async (ctx, options) => {
|
|
12
|
+
if (options?.ns) {
|
|
13
|
+
const store = new store_js_1.KvCacheStore(options.ns);
|
|
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,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KvCacheStore = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* A cache store implementation that uses a key-value namespace for storage.
|
|
6
|
+
*/
|
|
7
|
+
class KvCacheStore {
|
|
8
|
+
/** The key-value namespace used for caching. */
|
|
9
|
+
#ns;
|
|
10
|
+
/**
|
|
11
|
+
* @param ns - The key-value namespace to use for caching.
|
|
12
|
+
*/
|
|
13
|
+
constructor(ns) {
|
|
14
|
+
this.#ns = ns;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* @inheritdoc
|
|
18
|
+
*/
|
|
19
|
+
async get(key) {
|
|
20
|
+
const v = await this.#ns.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.#ns.delete(key);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
await this.#ns.put(key, value, {
|
|
35
|
+
...(ttl !== undefined ? { expirationTtl: ttl } : {}),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @inheritdoc
|
|
40
|
+
*/
|
|
41
|
+
async delete(key) {
|
|
42
|
+
await this.#ns.delete(key);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.KvCacheStore = KvCacheStore;
|
|
46
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { success } from "@comity/primitives/result";
|
|
2
|
+
import { KvCacheStore } from "../store.js";
|
|
3
|
+
export default {
|
|
4
|
+
name: "@comity/cache-kv",
|
|
5
|
+
version: "0.9.0",
|
|
6
|
+
dependsOn: { "@comity/cache": { optional: false } },
|
|
7
|
+
incompatibleWith: [],
|
|
8
|
+
/** @inheritdoc */
|
|
9
|
+
setup: async (ctx, options) => {
|
|
10
|
+
if (options?.ns) {
|
|
11
|
+
const store = new KvCacheStore(options.ns);
|
|
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,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A cache store implementation that uses a key-value namespace for storage.
|
|
3
|
+
*/
|
|
4
|
+
export class KvCacheStore {
|
|
5
|
+
/** The key-value namespace used for caching. */
|
|
6
|
+
#ns;
|
|
7
|
+
/**
|
|
8
|
+
* @param ns - The key-value namespace to use for caching.
|
|
9
|
+
*/
|
|
10
|
+
constructor(ns) {
|
|
11
|
+
this.#ns = ns;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @inheritdoc
|
|
15
|
+
*/
|
|
16
|
+
async get(key) {
|
|
17
|
+
const v = await this.#ns.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.#ns.delete(key);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
await this.#ns.put(key, value, {
|
|
32
|
+
...(ttl !== undefined ? { expirationTtl: ttl } : {}),
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* @inheritdoc
|
|
37
|
+
*/
|
|
38
|
+
async delete(key) {
|
|
39
|
+
await this.#ns.delete(key);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { KvCacheStore } from "./store.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CacheModuleContext } from "@comity/cache/setup";
|
|
2
|
+
import type { KvCacheModuleContext, KvCacheModuleOptions } 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: KvCacheModuleContext & CacheModuleContext, options: KvCacheModuleOptions | 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 { KvNamespace } from "../types.js";
|
|
3
|
+
/** Hooks exposed by the module */
|
|
4
|
+
export type KvCacheModuleHooks = {};
|
|
5
|
+
/** Events emitted by the module */
|
|
6
|
+
export type KvCacheModuleEvents = {};
|
|
7
|
+
/**
|
|
8
|
+
* Services exposed by the module
|
|
9
|
+
*/
|
|
10
|
+
export type KvCacheModuleServices = {};
|
|
11
|
+
/**
|
|
12
|
+
* Context provided to the cache module setup function.
|
|
13
|
+
*/
|
|
14
|
+
export interface KvCacheModuleContext extends ModuleSetupContext<KvCacheModuleServices, KvCacheModuleEvents, KvCacheModuleHooks> {
|
|
15
|
+
}
|
|
16
|
+
/** Cache module setup options */
|
|
17
|
+
export type KvCacheModuleOptions = {
|
|
18
|
+
/** Namespace to use for cache storage. */
|
|
19
|
+
ns: KvNamespace;
|
|
20
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { CacheStore } from "@comity/cache";
|
|
2
|
+
import type { KvNamespace } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* A cache store implementation that uses a key-value namespace for storage.
|
|
5
|
+
*/
|
|
6
|
+
export declare class KvCacheStore implements CacheStore {
|
|
7
|
+
#private;
|
|
8
|
+
/**
|
|
9
|
+
* @param ns - The key-value namespace to use for caching.
|
|
10
|
+
*/
|
|
11
|
+
constructor(ns: KvNamespace);
|
|
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,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a namespace for key-value caching.
|
|
3
|
+
*/
|
|
4
|
+
export interface KvNamespace {
|
|
5
|
+
/** Retrieves a value by its key. */
|
|
6
|
+
get(key: string): Promise<string | null>;
|
|
7
|
+
/** Stores a value with an optional expiration time. */
|
|
8
|
+
put(key: string, value: string, options?: {
|
|
9
|
+
/** Time-to-live in seconds */
|
|
10
|
+
expirationTtl?: number;
|
|
11
|
+
}): Promise<void>;
|
|
12
|
+
/** Deletes a value by its key. */
|
|
13
|
+
delete(key: string): Promise<void>;
|
|
14
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@comity/cache-kv",
|
|
3
|
+
"version": "0.9.0",
|
|
4
|
+
"description": "Key-Value 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
|
+
"typescript"
|
|
30
|
+
],
|
|
31
|
+
"files": [
|
|
32
|
+
"./dist",
|
|
33
|
+
"!./dist/**/*.map"
|
|
34
|
+
],
|
|
35
|
+
"main": "./dist/cjs/index.js",
|
|
36
|
+
"module": "./dist/esm/index.js",
|
|
37
|
+
"types": "./dist/types/index.d.ts",
|
|
38
|
+
"exports": {
|
|
39
|
+
".": {
|
|
40
|
+
"import": {
|
|
41
|
+
"types": "./dist/types/index.d.ts",
|
|
42
|
+
"default": "./dist/esm/index.js"
|
|
43
|
+
},
|
|
44
|
+
"require": {
|
|
45
|
+
"types": "./dist/types/index.d.ts",
|
|
46
|
+
"default": "./dist/cjs/index.js"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"./setup": {
|
|
50
|
+
"import": {
|
|
51
|
+
"types": "./dist/types/setup/index.d.ts",
|
|
52
|
+
"default": "./dist/esm/setup/index.js"
|
|
53
|
+
},
|
|
54
|
+
"require": {
|
|
55
|
+
"types": "./dist/types/setup/index.d.ts",
|
|
56
|
+
"default": "./dist/cjs/setup/index.js"
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"./package.json": "./package.json"
|
|
60
|
+
},
|
|
61
|
+
"typesVersions": {
|
|
62
|
+
"*": {
|
|
63
|
+
"setup": [
|
|
64
|
+
"./dist/types/setup/index.d.ts"
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"publishConfig": {
|
|
69
|
+
"registry": "https://registry.npmjs.org",
|
|
70
|
+
"access": "public"
|
|
71
|
+
},
|
|
72
|
+
"sideEffects": false,
|
|
73
|
+
"peerDependencies": {
|
|
74
|
+
"@comity/cache": "0.9.0",
|
|
75
|
+
"@comity/primitives": "0.9.0",
|
|
76
|
+
"@comity/composition": "0.9.0"
|
|
77
|
+
},
|
|
78
|
+
"dependencies": {
|
|
79
|
+
"@comity/cache": "0.9.0",
|
|
80
|
+
"@comity/composition": "0.9.0",
|
|
81
|
+
"@comity/primitives": "0.9.0"
|
|
82
|
+
},
|
|
83
|
+
"devDependencies": {
|
|
84
|
+
"@types/node": "^24.13.4",
|
|
85
|
+
"typescript": "^5.9.3"
|
|
86
|
+
},
|
|
87
|
+
"scripts": {
|
|
88
|
+
"build": "node ../../scripts/build.mjs",
|
|
89
|
+
"dev": "node ../../scripts/build.mjs --watch",
|
|
90
|
+
"test": "vitest run --coverage",
|
|
91
|
+
"type-check": "tsc -p tsconfig.json --noEmit",
|
|
92
|
+
"lint": "eslint --ext .ts src"
|
|
93
|
+
}
|
|
94
|
+
}
|