@aomex/cache 3.30.7 → 3.30.8-alpha.62.sha-92b25bb
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/adapters/cache-file-adapter.d.ts +72 -0
- package/dist/adapters/cache-file-adapter.js +198 -0
- package/dist/adapters/cache-file-adapter.js.map +1 -0
- package/dist/adapters/cache-memory-adapter.d.ts +18 -0
- package/dist/adapters/cache-memory-adapter.js +106 -0
- package/dist/adapters/cache-memory-adapter.js.map +1 -0
- package/dist/cache-adapter-4n2JTK4Y.js +8 -0
- package/dist/cache-adapter-4n2JTK4Y.js.map +1 -0
- package/dist/cache-adapter-CVIt9DB_.d.ts +17 -0
- package/dist/i18n-BKvtLTPF.js +20 -0
- package/dist/i18n-BKvtLTPF.js.map +1 -0
- package/dist/index.d.ts +202 -158
- package/dist/index.js +326 -412
- package/dist/index.js.map +1 -1
- package/package.json +30 -15
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { t as CacheAdapter } from "../cache-adapter-CVIt9DB_.js";
|
|
2
|
+
import { DatabaseSync, StatementSync } from "node:sqlite";
|
|
3
|
+
export interface CacheFileAdapterOptions {
|
|
4
|
+
/**
|
|
5
|
+
* SQLite 数据库路径。传入 `':memory:'` 使用内存库。
|
|
6
|
+
*/
|
|
7
|
+
filename: string;
|
|
8
|
+
/**
|
|
9
|
+
* 获取写锁的最长等待时间(毫秒),对应 `node:sqlite` 的 `timeout`。
|
|
10
|
+
* @default 5000
|
|
11
|
+
*/
|
|
12
|
+
timeout?: number;
|
|
13
|
+
}
|
|
14
|
+
type CacheKind = 'string' | 'list';
|
|
15
|
+
type CacheRow = {
|
|
16
|
+
key: string;
|
|
17
|
+
value: string;
|
|
18
|
+
kind: CacheKind;
|
|
19
|
+
expires: number | null;
|
|
20
|
+
};
|
|
21
|
+
type Statements = {
|
|
22
|
+
get: StatementSync;
|
|
23
|
+
upsert: StatementSync;
|
|
24
|
+
/** 只改 value/kind,保留 TTL(对齐 Redis 对已有 key 的就地更新) */
|
|
25
|
+
updateValue: StatementSync;
|
|
26
|
+
delete: StatementSync;
|
|
27
|
+
deleteAll: StatementSync;
|
|
28
|
+
expire: StatementSync;
|
|
29
|
+
/** 对齐 Redis INCR/DECR:只改 value,保留 TTL */
|
|
30
|
+
incr: StatementSync;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* 基于 `node:sqlite` 的文件缓存适配器。
|
|
34
|
+
*
|
|
35
|
+
* key 只作为表主键存储,不拼进文件系统路径。
|
|
36
|
+
* NX / incr / list 等读改写使用 `BEGIN IMMEDIATE`,多进程共库时保持原子语义。
|
|
37
|
+
*/
|
|
38
|
+
export declare class CacheFileAdapter extends CacheAdapter {
|
|
39
|
+
readonly filename: string;
|
|
40
|
+
protected readonly timeout: number;
|
|
41
|
+
protected db?: DatabaseSync;
|
|
42
|
+
protected stmts?: Statements;
|
|
43
|
+
constructor(options: CacheFileAdapterOptions);
|
|
44
|
+
connect(): Promise<void>;
|
|
45
|
+
disconnect(): Promise<void>;
|
|
46
|
+
existsKey(key: string): Promise<boolean>;
|
|
47
|
+
getValue(key: string): Promise<string | null>;
|
|
48
|
+
setValue(key: string, value: string, durationMS?: number): Promise<boolean>;
|
|
49
|
+
setNotExistValue(key: string, value: string, durationMS?: number): Promise<boolean>;
|
|
50
|
+
deleteValue(key: string): Promise<boolean>;
|
|
51
|
+
deleteAllValues(): Promise<boolean>;
|
|
52
|
+
increaseValue(key: string): Promise<number>;
|
|
53
|
+
decreaseValue(key: string): Promise<number>;
|
|
54
|
+
expireKey(key: string, durationMS: number): Promise<boolean>;
|
|
55
|
+
ttlKey(key: string): Promise<number>;
|
|
56
|
+
leftPushValue(key: string, ...values: string[]): Promise<boolean>;
|
|
57
|
+
rightPopValue(key: string): Promise<string | null>;
|
|
58
|
+
/** 写锁事务;已在事务中则直接执行,避免嵌套 BEGIN。 */
|
|
59
|
+
protected withImmediateTransaction<T>(fn: () => T): T;
|
|
60
|
+
protected ensureConnected(): void;
|
|
61
|
+
protected getRow(key: string, assertType: 'string'): CacheRow | null;
|
|
62
|
+
protected getRow(key: string, assertType: 'list'): CacheRow | null;
|
|
63
|
+
protected getRow(key: string, assertType: 'any'): CacheRow | null;
|
|
64
|
+
/**
|
|
65
|
+
* @param preserveExpires 为 true 时只改 value/kind(list 就地更新、对齐 Redis 保留 TTL)
|
|
66
|
+
*/
|
|
67
|
+
protected write(key: string, value: string, kind: CacheKind, durationMS?: number, preserveExpires?: boolean): void;
|
|
68
|
+
/** 对齐 Redis INCR/DECR */
|
|
69
|
+
protected changeInteger(key: string, delta: number): number;
|
|
70
|
+
protected parseList(value: string): string[];
|
|
71
|
+
}
|
|
72
|
+
export {};
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { t as CacheAdapter } from "../cache-adapter-4n2JTK4Y.js";
|
|
2
|
+
import { t as i18n } from "../i18n-BKvtLTPF.js";
|
|
3
|
+
import { mkdirSync } from "node:fs";
|
|
4
|
+
import { dirname, resolve } from "node:path";
|
|
5
|
+
import { DatabaseSync } from "node:sqlite";
|
|
6
|
+
// src/adapters/cache-file-adapter.ts
|
|
7
|
+
/**
|
|
8
|
+
* 基于 `node:sqlite` 的文件缓存适配器。
|
|
9
|
+
*
|
|
10
|
+
* key 只作为表主键存储,不拼进文件系统路径。
|
|
11
|
+
* NX / incr / list 等读改写使用 `BEGIN IMMEDIATE`,多进程共库时保持原子语义。
|
|
12
|
+
*/
|
|
13
|
+
var CacheFileAdapter = class extends CacheAdapter {
|
|
14
|
+
filename;
|
|
15
|
+
timeout;
|
|
16
|
+
db;
|
|
17
|
+
stmts;
|
|
18
|
+
constructor(options) {
|
|
19
|
+
super();
|
|
20
|
+
this.filename = options.filename === ":memory:" ? options.filename : resolve(options.filename);
|
|
21
|
+
this.timeout = options.timeout ?? 5e3;
|
|
22
|
+
}
|
|
23
|
+
async connect() {
|
|
24
|
+
this.ensureConnected();
|
|
25
|
+
}
|
|
26
|
+
async disconnect() {
|
|
27
|
+
const { db } = this;
|
|
28
|
+
if (!db) return;
|
|
29
|
+
if (db.isOpen) db.close();
|
|
30
|
+
this.db = void 0;
|
|
31
|
+
this.stmts = void 0;
|
|
32
|
+
}
|
|
33
|
+
async existsKey(key) {
|
|
34
|
+
return this.getRow(key, "any") !== null;
|
|
35
|
+
}
|
|
36
|
+
async getValue(key) {
|
|
37
|
+
return this.getRow(key, "string")?.value ?? null;
|
|
38
|
+
}
|
|
39
|
+
async setValue(key, value, durationMS) {
|
|
40
|
+
this.write(key, value, "string", durationMS);
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
async setNotExistValue(key, value, durationMS) {
|
|
44
|
+
return this.withImmediateTransaction(() => {
|
|
45
|
+
if (this.getRow(key, "any")) return false;
|
|
46
|
+
this.write(key, value, "string", durationMS);
|
|
47
|
+
return true;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
async deleteValue(key) {
|
|
51
|
+
this.ensureConnected();
|
|
52
|
+
this.stmts.delete.run(key);
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
async deleteAllValues() {
|
|
56
|
+
this.ensureConnected();
|
|
57
|
+
this.stmts.deleteAll.run();
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
async increaseValue(key) {
|
|
61
|
+
return this.changeInteger(key, 1);
|
|
62
|
+
}
|
|
63
|
+
async decreaseValue(key) {
|
|
64
|
+
return this.changeInteger(key, -1);
|
|
65
|
+
}
|
|
66
|
+
async expireKey(key, durationMS) {
|
|
67
|
+
this.ensureConnected();
|
|
68
|
+
const now = Date.now();
|
|
69
|
+
const { changes } = this.stmts.expire.run(now + durationMS, key, now);
|
|
70
|
+
return changes === 1;
|
|
71
|
+
}
|
|
72
|
+
async ttlKey(key) {
|
|
73
|
+
const row = this.getRow(key, "any");
|
|
74
|
+
if (!row) return -2;
|
|
75
|
+
if (row.expires == null) return -1;
|
|
76
|
+
return row.expires - Date.now();
|
|
77
|
+
}
|
|
78
|
+
async leftPushValue(key, ...values) {
|
|
79
|
+
return this.withImmediateTransaction(() => {
|
|
80
|
+
const row = this.getRow(key, "list");
|
|
81
|
+
const list = row ? this.parseList(row.value) : [];
|
|
82
|
+
list.push(...values);
|
|
83
|
+
this.write(key, JSON.stringify(list), "list", void 0, !!row);
|
|
84
|
+
return true;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
async rightPopValue(key) {
|
|
88
|
+
return this.withImmediateTransaction(() => {
|
|
89
|
+
const row = this.getRow(key, "list");
|
|
90
|
+
if (!row) return null;
|
|
91
|
+
const list = this.parseList(row.value);
|
|
92
|
+
const value = list.pop() ?? null;
|
|
93
|
+
if (!list.length) this.stmts.delete.run(key);
|
|
94
|
+
else this.write(key, JSON.stringify(list), "list", void 0, true);
|
|
95
|
+
return value;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/** 写锁事务;已在事务中则直接执行,避免嵌套 BEGIN。 */
|
|
99
|
+
withImmediateTransaction(fn) {
|
|
100
|
+
this.ensureConnected();
|
|
101
|
+
const db = this.db;
|
|
102
|
+
if (db.isTransaction) return fn();
|
|
103
|
+
db.exec("BEGIN IMMEDIATE");
|
|
104
|
+
try {
|
|
105
|
+
const result = fn();
|
|
106
|
+
db.exec("COMMIT");
|
|
107
|
+
return result;
|
|
108
|
+
} catch (error) {
|
|
109
|
+
if (db.isTransaction) db.exec("ROLLBACK");
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
ensureConnected() {
|
|
114
|
+
if (this.db?.isOpen && this.stmts) return;
|
|
115
|
+
if (this.filename !== ":memory:") mkdirSync(dirname(this.filename), { recursive: true });
|
|
116
|
+
const db = new DatabaseSync(this.filename, { timeout: this.timeout });
|
|
117
|
+
db.exec(`
|
|
118
|
+
PRAGMA journal_mode = WAL;
|
|
119
|
+
CREATE TABLE IF NOT EXISTS cache (
|
|
120
|
+
key TEXT PRIMARY KEY NOT NULL,
|
|
121
|
+
value TEXT NOT NULL,
|
|
122
|
+
kind TEXT NOT NULL CHECK (kind IN ('string', 'list')),
|
|
123
|
+
expires INTEGER
|
|
124
|
+
) STRICT;
|
|
125
|
+
CREATE INDEX IF NOT EXISTS cache_expires_idx ON cache (expires);
|
|
126
|
+
`);
|
|
127
|
+
this.db = db;
|
|
128
|
+
this.stmts = {
|
|
129
|
+
get: db.prepare("SELECT key, value, kind, expires FROM cache WHERE key = ?"),
|
|
130
|
+
upsert: db.prepare(`
|
|
131
|
+
INSERT INTO cache (key, value, kind, expires)
|
|
132
|
+
VALUES (?, ?, ?, ?)
|
|
133
|
+
ON CONFLICT(key) DO UPDATE SET
|
|
134
|
+
value = excluded.value,
|
|
135
|
+
kind = excluded.kind,
|
|
136
|
+
expires = excluded.expires
|
|
137
|
+
`),
|
|
138
|
+
updateValue: db.prepare(`
|
|
139
|
+
UPDATE cache SET value = ?, kind = ? WHERE key = ?
|
|
140
|
+
`),
|
|
141
|
+
delete: db.prepare("DELETE FROM cache WHERE key = ?"),
|
|
142
|
+
deleteAll: db.prepare("DELETE FROM cache"),
|
|
143
|
+
expire: db.prepare(`
|
|
144
|
+
UPDATE cache SET expires = ?
|
|
145
|
+
WHERE key = ? AND (expires IS NULL OR expires >= ?)
|
|
146
|
+
`),
|
|
147
|
+
incr: db.prepare(`
|
|
148
|
+
UPDATE cache
|
|
149
|
+
SET value = CAST(CAST(value AS INTEGER) + ? AS INTEGER)
|
|
150
|
+
WHERE key = ?
|
|
151
|
+
RETURNING value
|
|
152
|
+
`)
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
getRow(key, assertType) {
|
|
156
|
+
this.ensureConnected();
|
|
157
|
+
const row = this.stmts.get.get(key);
|
|
158
|
+
if (!row) return null;
|
|
159
|
+
if (row.expires != null && row.expires < Date.now()) {
|
|
160
|
+
this.stmts.delete.run(key);
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
if (assertType !== "any" && row.kind !== assertType) throw new Error(i18n.t("wrong_type"));
|
|
164
|
+
return row;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* @param preserveExpires 为 true 时只改 value/kind(list 就地更新、对齐 Redis 保留 TTL)
|
|
168
|
+
*/
|
|
169
|
+
write(key, value, kind, durationMS, preserveExpires = false) {
|
|
170
|
+
this.ensureConnected();
|
|
171
|
+
if (preserveExpires) {
|
|
172
|
+
this.stmts.updateValue.run(value, kind, key);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
this.stmts.upsert.run(key, value, kind, durationMS === void 0 ? null : Date.now() + durationMS);
|
|
176
|
+
}
|
|
177
|
+
/** 对齐 Redis INCR/DECR */
|
|
178
|
+
changeInteger(key, delta) {
|
|
179
|
+
return this.withImmediateTransaction(() => {
|
|
180
|
+
const row = this.getRow(key, "string");
|
|
181
|
+
if (row) {
|
|
182
|
+
if (!/^-?\d+$/.test(row.value)) throw new Error(i18n.t("not_integer"));
|
|
183
|
+
const updated = this.stmts.incr.get(delta, key);
|
|
184
|
+
return Number(updated.value);
|
|
185
|
+
}
|
|
186
|
+
this.write(key, String(delta), "string");
|
|
187
|
+
return delta;
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
parseList(value) {
|
|
191
|
+
const parsed = JSON.parse(value);
|
|
192
|
+
if (!Array.isArray(parsed) || parsed.some((item) => typeof item !== "string")) throw new Error(i18n.t("wrong_type"));
|
|
193
|
+
return parsed;
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
export { CacheFileAdapter };
|
|
197
|
+
|
|
198
|
+
//# sourceMappingURL=cache-file-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-file-adapter.js","names":[],"sources":["../../src/adapters/cache-file-adapter.ts"],"sourcesContent":["import { mkdirSync } from 'node:fs';\nimport { dirname, resolve } from 'node:path';\nimport { DatabaseSync, type StatementSync } from 'node:sqlite';\nimport { CacheAdapter } from '../cache-adapter';\nimport { i18n } from '../i18n';\n\nexport interface CacheFileAdapterOptions {\n /**\n * SQLite 数据库路径。传入 `':memory:'` 使用内存库。\n */\n filename: string;\n /**\n * 获取写锁的最长等待时间(毫秒),对应 `node:sqlite` 的 `timeout`。\n * @default 5000\n */\n timeout?: number;\n}\n\ntype CacheKind = 'string' | 'list';\n\ntype CacheRow = {\n key: string;\n value: string;\n kind: CacheKind;\n expires: number | null;\n};\n\ntype Statements = {\n get: StatementSync;\n upsert: StatementSync;\n /** 只改 value/kind,保留 TTL(对齐 Redis 对已有 key 的就地更新) */\n updateValue: StatementSync;\n delete: StatementSync;\n deleteAll: StatementSync;\n expire: StatementSync;\n /** 对齐 Redis INCR/DECR:只改 value,保留 TTL */\n incr: StatementSync;\n};\n\n/**\n * 基于 `node:sqlite` 的文件缓存适配器。\n *\n * key 只作为表主键存储,不拼进文件系统路径。\n * NX / incr / list 等读改写使用 `BEGIN IMMEDIATE`,多进程共库时保持原子语义。\n */\nexport class CacheFileAdapter extends CacheAdapter {\n public readonly filename: string;\n protected readonly timeout: number;\n protected db?: DatabaseSync;\n protected stmts?: Statements;\n\n constructor(options: CacheFileAdapterOptions) {\n super();\n this.filename =\n options.filename === ':memory:' ? options.filename : resolve(options.filename);\n this.timeout = options.timeout ?? 5_000;\n }\n\n override async connect(): Promise<void> {\n this.ensureConnected();\n }\n\n override async disconnect(): Promise<void> {\n const { db } = this;\n if (!db) return;\n if (db.isOpen) db.close();\n this.db = undefined;\n this.stmts = undefined;\n }\n\n override async existsKey(key: string): Promise<boolean> {\n return this.getRow(key, 'any') !== null;\n }\n\n override async getValue(key: string): Promise<string | null> {\n return this.getRow(key, 'string')?.value ?? null;\n }\n\n override async setValue(\n key: string,\n value: string,\n durationMS?: number,\n ): Promise<boolean> {\n this.write(key, value, 'string', durationMS);\n return true;\n }\n\n override async setNotExistValue(\n key: string,\n value: string,\n durationMS?: number,\n ): Promise<boolean> {\n return this.withImmediateTransaction(() => {\n if (this.getRow(key, 'any')) return false;\n this.write(key, value, 'string', durationMS);\n return true;\n });\n }\n\n override async deleteValue(key: string): Promise<boolean> {\n this.ensureConnected();\n this.stmts!.delete.run(key);\n return true;\n }\n\n override async deleteAllValues(): Promise<boolean> {\n this.ensureConnected();\n this.stmts!.deleteAll.run();\n return true;\n }\n\n override async increaseValue(key: string): Promise<number> {\n return this.changeInteger(key, 1);\n }\n\n override async decreaseValue(key: string): Promise<number> {\n return this.changeInteger(key, -1);\n }\n\n override async expireKey(key: string, durationMS: number): Promise<boolean> {\n this.ensureConnected();\n const now = Date.now();\n const { changes } = this.stmts!.expire.run(now + durationMS, key, now);\n return changes === 1;\n }\n\n override async ttlKey(key: string): Promise<number> {\n const row = this.getRow(key, 'any');\n if (!row) return -2;\n if (row.expires == null) return -1;\n return row.expires - Date.now();\n }\n\n override async leftPushValue(key: string, ...values: string[]): Promise<boolean> {\n return this.withImmediateTransaction(() => {\n const row = this.getRow(key, 'list');\n const list = row ? this.parseList(row.value) : [];\n list.push(...values);\n this.write(key, JSON.stringify(list), 'list', undefined, !!row);\n return true;\n });\n }\n\n override async rightPopValue(key: string): Promise<string | null> {\n return this.withImmediateTransaction(() => {\n const row = this.getRow(key, 'list');\n if (!row) return null;\n const list = this.parseList(row.value);\n const value = list.pop() ?? null;\n if (!list.length) {\n this.stmts!.delete.run(key);\n } else {\n this.write(key, JSON.stringify(list), 'list', undefined, true);\n }\n return value;\n });\n }\n\n /** 写锁事务;已在事务中则直接执行,避免嵌套 BEGIN。 */\n protected withImmediateTransaction<T>(fn: () => T): T {\n this.ensureConnected();\n const db = this.db!;\n if (db.isTransaction) return fn();\n\n db.exec('BEGIN IMMEDIATE');\n try {\n const result = fn();\n db.exec('COMMIT');\n return result;\n } catch (error) {\n if (db.isTransaction) db.exec('ROLLBACK');\n throw error;\n }\n }\n\n protected ensureConnected(): void {\n if (this.db?.isOpen && this.stmts) return;\n\n if (this.filename !== ':memory:') {\n mkdirSync(dirname(this.filename), { recursive: true });\n }\n\n const db = new DatabaseSync(this.filename, { timeout: this.timeout });\n db.exec(`\n PRAGMA journal_mode = WAL;\n CREATE TABLE IF NOT EXISTS cache (\n key TEXT PRIMARY KEY NOT NULL,\n value TEXT NOT NULL,\n kind TEXT NOT NULL CHECK (kind IN ('string', 'list')),\n expires INTEGER\n ) STRICT;\n CREATE INDEX IF NOT EXISTS cache_expires_idx ON cache (expires);\n `);\n\n this.db = db;\n this.stmts = {\n get: db.prepare('SELECT key, value, kind, expires FROM cache WHERE key = ?'),\n upsert: db.prepare(`\n INSERT INTO cache (key, value, kind, expires)\n VALUES (?, ?, ?, ?)\n ON CONFLICT(key) DO UPDATE SET\n value = excluded.value,\n kind = excluded.kind,\n expires = excluded.expires\n `),\n updateValue: db.prepare(`\n UPDATE cache SET value = ?, kind = ? WHERE key = ?\n `),\n delete: db.prepare('DELETE FROM cache WHERE key = ?'),\n deleteAll: db.prepare('DELETE FROM cache'),\n expire: db.prepare(`\n UPDATE cache SET expires = ?\n WHERE key = ? AND (expires IS NULL OR expires >= ?)\n `),\n incr: db.prepare(`\n UPDATE cache\n SET value = CAST(CAST(value AS INTEGER) + ? AS INTEGER)\n WHERE key = ?\n RETURNING value\n `),\n };\n }\n\n protected getRow(key: string, assertType: 'string'): CacheRow | null;\n protected getRow(key: string, assertType: 'list'): CacheRow | null;\n protected getRow(key: string, assertType: 'any'): CacheRow | null;\n protected getRow(key: string, assertType: 'string' | 'list' | 'any'): CacheRow | null {\n this.ensureConnected();\n const row = this.stmts!.get.get(key) as CacheRow | undefined;\n if (!row) return null;\n if (row.expires != null && row.expires < Date.now()) {\n this.stmts!.delete.run(key);\n return null;\n }\n if (assertType !== 'any' && row.kind !== assertType) {\n throw new Error(i18n.t('wrong_type'));\n }\n return row;\n }\n\n /**\n * @param preserveExpires 为 true 时只改 value/kind(list 就地更新、对齐 Redis 保留 TTL)\n */\n protected write(\n key: string,\n value: string,\n kind: CacheKind,\n durationMS?: number,\n preserveExpires = false,\n ): void {\n this.ensureConnected();\n if (preserveExpires) {\n this.stmts!.updateValue.run(value, kind, key);\n return;\n }\n this.stmts!.upsert.run(\n key,\n value,\n kind,\n durationMS === undefined ? null : Date.now() + durationMS,\n );\n }\n\n /** 对齐 Redis INCR/DECR */\n protected changeInteger(key: string, delta: number): number {\n return this.withImmediateTransaction(() => {\n const row = this.getRow(key, 'string');\n if (row) {\n if (!/^-?\\d+$/.test(row.value)) {\n throw new Error(i18n.t('not_integer'));\n }\n const updated = this.stmts!.incr.get(delta, key) as { value: string };\n return Number(updated.value);\n }\n this.write(key, String(delta), 'string');\n return delta;\n });\n }\n\n protected parseList(value: string): string[] {\n const parsed: unknown = JSON.parse(value);\n if (!Array.isArray(parsed) || parsed.some((item) => typeof item !== 'string')) {\n throw new Error(i18n.t('wrong_type'));\n }\n return parsed;\n }\n}\n"],"mappings":";;;;;;;;;;;;AA6CA,IAAa,mBAAb,cAAsC,aAAa;CACjD;CACA;CACA;CACA;CAEA,YAAY,SAAkC;EAC5C,MAAM;EACN,KAAK,WACH,QAAQ,aAAa,aAAa,QAAQ,WAAW,QAAQ,QAAQ,QAAQ;EAC/E,KAAK,UAAU,QAAQ,WAAW;CACpC;CAEA,MAAe,UAAyB;EACtC,KAAK,gBAAgB;CACvB;CAEA,MAAe,aAA4B;EACzC,MAAM,EAAE,OAAO;EACf,IAAI,CAAC,IAAI;EACT,IAAI,GAAG,QAAQ,GAAG,MAAM;EACxB,KAAK,KAAK,KAAA;EACV,KAAK,QAAQ,KAAA;CACf;CAEA,MAAe,UAAU,KAA+B;EACtD,OAAO,KAAK,OAAO,KAAK,KAAK,MAAM;CACrC;CAEA,MAAe,SAAS,KAAqC;EAC3D,OAAO,KAAK,OAAO,KAAK,QAAQ,CAAC,EAAE,SAAS;CAC9C;CAEA,MAAe,SACb,KACA,OACA,YACkB;EAClB,KAAK,MAAM,KAAK,OAAO,UAAU,UAAU;EAC3C,OAAO;CACT;CAEA,MAAe,iBACb,KACA,OACA,YACkB;EAClB,OAAO,KAAK,+BAA+B;GACzC,IAAI,KAAK,OAAO,KA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nD,KAAK,MAAO,OAAO,IAAI,GAAG;GAC1B,OAAO;EACT;EACA,IAAI,eAAe,SAAS,IAAI,SAAS,YACvC,MAAM,IAAI,MAAM,KAAK,EAAE,YAAY,CAAC;EAEtC,OAAO;CACT;;;;CAKA,MACE,KACA,OACA,MACA,YACA,kBAAkB,OACZ;EACN,KAAK,gBAAgB;EACrB,IAAI,iBAAiB;GACnB,KAAK,MAAO,YAAY,IAAI,OAAO,MAAM,GAAG;GAC5C;EACF;EACA,KAAK,MAAO,OAAO,IACjB,KACA,OACA,MACA,eAAe,KAAA,IAAY,OAAO,KAAK,IAAI,IAAI,UACjD;CACF;;CAGA,cAAwB,KAAa,OAAuB;EAC1D,OAAO,KAAK,+BAA+B;GACzC,MAAM,MAAM,KAAK,OAAO,KAAK,QAAQ;GACrC,IAAI,KAAK;IACP,IAAI,CAAC,UAAU,KAAK,IAAI,KAAK,GAC3B,MAAM,IAAI,MAAM,KAAK,EAAE,aAAa,CAAC;IAEvC,MAAM,UAAU,KAAK,MAAO,KAAK,IAAI,OAAO,GAAG;IAC/C,OAAO,OAAO,QAAQ,KAAK;GAC7B;GACA,KAAK,MAAM,KAAK,OAAO,KAAK,GAAG,QAAQ;GACvC,OAAO;EACT,CAAC;CACH;CAEA,UAAoB,OAAyB;EAC3C,MAAM,SAAkB,KAAK,MAAM,KAAK;EACxC,IAAI,CAAC,MAAM,QAAQ,MAAM,KAAK,OAAO,MAAM,SAAS,OAAO,SAAS,QAAQ,GAC1E,MAAM,IAAI,MAAM,KAAK,EAAE,YAAY,CAAC;EAEtC,OAAO;CACT;AACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { t as CacheAdapter } from "../cache-adapter-CVIt9DB_.js";
|
|
2
|
+
export declare class CacheMemoryAdapter extends CacheAdapter {
|
|
3
|
+
private data;
|
|
4
|
+
existsKey(key: string): Promise<boolean>;
|
|
5
|
+
getValue(key: string): Promise<string | null>;
|
|
6
|
+
setValue(key: string, value: string, duration?: number): Promise<boolean>;
|
|
7
|
+
setNotExistValue(key: string, value: string, duration?: number): Promise<boolean>;
|
|
8
|
+
leftPushValue(key: string, ...values: string[]): Promise<boolean>;
|
|
9
|
+
rightPopValue(key: string): Promise<string | null>;
|
|
10
|
+
increaseValue(key: string): Promise<number>;
|
|
11
|
+
decreaseValue(key: string): Promise<number>;
|
|
12
|
+
deleteValue(key: string): Promise<boolean>;
|
|
13
|
+
deleteAllValues(): Promise<boolean>;
|
|
14
|
+
expireKey(key: string, duration: number): Promise<boolean>;
|
|
15
|
+
ttlKey(key: string): Promise<number>;
|
|
16
|
+
protected getValueSync<T extends 'string' | 'array' | 'any'>(key: string, assertType: T): (T extends 'any' ? string | string[] : T extends 'string' ? string : Array<string>) | null;
|
|
17
|
+
protected setValueSync(key: string, value: string | string[], duration?: number): boolean;
|
|
18
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { t as CacheAdapter } from "../cache-adapter-4n2JTK4Y.js";
|
|
2
|
+
import { t as i18n } from "../i18n-BKvtLTPF.js";
|
|
3
|
+
// src/adapters/cache-memory-adapter.ts
|
|
4
|
+
var CacheMemoryAdapter = class extends CacheAdapter {
|
|
5
|
+
data = /* @__PURE__ */ new Map();
|
|
6
|
+
async existsKey(key) {
|
|
7
|
+
return this.getValueSync(key, "any") !== null;
|
|
8
|
+
}
|
|
9
|
+
async getValue(key) {
|
|
10
|
+
return this.getValueSync(key, "string");
|
|
11
|
+
}
|
|
12
|
+
async setValue(key, value, duration) {
|
|
13
|
+
return this.setValueSync(key, value, duration);
|
|
14
|
+
}
|
|
15
|
+
async setNotExistValue(key, value, duration) {
|
|
16
|
+
if (this.getValueSync(key, "string") !== null) return false;
|
|
17
|
+
return this.setValueSync(key, value, duration);
|
|
18
|
+
}
|
|
19
|
+
async leftPushValue(key, ...values) {
|
|
20
|
+
let result = this.getValueSync(key, "array");
|
|
21
|
+
if (result === null) result = [];
|
|
22
|
+
result.push(...values);
|
|
23
|
+
this.setValueSync(key, result);
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
async rightPopValue(key) {
|
|
27
|
+
let result = this.getValueSync(key, "array");
|
|
28
|
+
if (result === null || !result.length) return null;
|
|
29
|
+
const popValue = result.pop();
|
|
30
|
+
if (result.length) this.setValueSync(key, result);
|
|
31
|
+
else this.data.delete(key);
|
|
32
|
+
return popValue;
|
|
33
|
+
}
|
|
34
|
+
async increaseValue(key) {
|
|
35
|
+
const result = this.getValueSync(key, "string");
|
|
36
|
+
let value;
|
|
37
|
+
if (result === null) {
|
|
38
|
+
this.data.set(key, { value: "0" });
|
|
39
|
+
value = 0;
|
|
40
|
+
} else value = Number(result);
|
|
41
|
+
if (Number.isNaN(value) || !Number.isInteger(value)) throw new Error(i18n.t("not_integer"));
|
|
42
|
+
this.setValueSync(key, String(++value));
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
async decreaseValue(key) {
|
|
46
|
+
const result = this.getValueSync(key, "string");
|
|
47
|
+
let value;
|
|
48
|
+
if (result === null) {
|
|
49
|
+
this.data.set(key, { value: "0" });
|
|
50
|
+
value = 0;
|
|
51
|
+
} else value = Number(result);
|
|
52
|
+
if (Number.isNaN(value) || !Number.isInteger(value)) throw new Error(i18n.t("not_integer"));
|
|
53
|
+
this.setValueSync(key, String(--value));
|
|
54
|
+
return value;
|
|
55
|
+
}
|
|
56
|
+
async deleteValue(key) {
|
|
57
|
+
this.data.delete(key);
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
async deleteAllValues() {
|
|
61
|
+
this.data.clear();
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
async expireKey(key, duration) {
|
|
65
|
+
const result = this.data.get(key);
|
|
66
|
+
if (!result) return false;
|
|
67
|
+
if (result.expires && result.expires < Date.now()) return false;
|
|
68
|
+
result.expires = Date.now() + duration;
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
async ttlKey(key) {
|
|
72
|
+
const result = this.data.get(key);
|
|
73
|
+
if (!result) return -2;
|
|
74
|
+
if (!result.expires) return -1;
|
|
75
|
+
if (result.expires < Date.now()) return -2;
|
|
76
|
+
return result.expires - Date.now();
|
|
77
|
+
}
|
|
78
|
+
getValueSync(key, assertType) {
|
|
79
|
+
const result = this.data.get(key);
|
|
80
|
+
if (!result) return null;
|
|
81
|
+
if (result.expires && result.expires < Date.now()) return null;
|
|
82
|
+
const value = result.value;
|
|
83
|
+
let isValid = false;
|
|
84
|
+
switch (assertType) {
|
|
85
|
+
case "string":
|
|
86
|
+
isValid = typeof value === "string";
|
|
87
|
+
break;
|
|
88
|
+
case "array":
|
|
89
|
+
isValid = Array.isArray(value);
|
|
90
|
+
break;
|
|
91
|
+
case "any": isValid = true;
|
|
92
|
+
}
|
|
93
|
+
if (!isValid) throw new Error(i18n.t("wrong_type"));
|
|
94
|
+
return value;
|
|
95
|
+
}
|
|
96
|
+
setValueSync(key, value, duration) {
|
|
97
|
+
this.data.set(key, {
|
|
98
|
+
value,
|
|
99
|
+
expires: duration ? Date.now() + duration : void 0
|
|
100
|
+
});
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
export { CacheMemoryAdapter };
|
|
105
|
+
|
|
106
|
+
//# sourceMappingURL=cache-memory-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-memory-adapter.js","names":[],"sources":["../../src/adapters/cache-memory-adapter.ts"],"sourcesContent":["import { CacheAdapter } from '../cache-adapter';\nimport { i18n } from '../i18n';\n\nexport class CacheMemoryAdapter extends CacheAdapter {\n private data = new Map<string, { value: string | string[]; expires?: number }>();\n\n override async existsKey(key: string): Promise<boolean> {\n return this.getValueSync(key, 'any') !== null;\n }\n\n override async getValue(key: string): Promise<string | null> {\n const value = this.getValueSync(key, 'string');\n return value;\n }\n\n override async setValue(\n key: string,\n value: string,\n duration?: number,\n ): Promise<boolean> {\n return this.setValueSync(key, value, duration);\n }\n\n override async setNotExistValue(\n key: string,\n value: string,\n duration?: number,\n ): Promise<boolean> {\n const currentValue = this.getValueSync(key, 'string');\n if (currentValue !== null) return false;\n return this.setValueSync(key, value, duration);\n }\n\n override async leftPushValue(key: string, ...values: string[]): Promise<boolean> {\n let result = this.getValueSync(key, 'array');\n if (result === null) result = [];\n result.push(...values);\n this.setValueSync(key, result);\n return true;\n }\n\n override async rightPopValue(key: string): Promise<string | null> {\n let result = this.getValueSync(key, 'array');\n if (result === null || !result.length) return null;\n const popValue = result.pop()!;\n if (result.length) {\n this.setValueSync(key, result);\n } else {\n this.data.delete(key);\n }\n return popValue;\n }\n\n override async increaseValue(key: string): Promise<number> {\n const result = this.getValueSync(key, 'string');\n let value: number;\n if (result === null) {\n this.data.set(key, { value: '0' });\n value = 0;\n } else {\n value = Number(result);\n }\n\n if (Number.isNaN(value) || !Number.isInteger(value)) {\n throw new Error(i18n.t('not_integer'));\n }\n\n this.setValueSync(key, String(++value));\n return value;\n }\n\n override async decreaseValue(key: string): Promise<number> {\n const result = this.getValueSync(key, 'string');\n let value: number;\n if (result === null) {\n this.data.set(key, { value: '0' });\n value = 0;\n } else {\n value = Number(result);\n }\n\n if (Number.isNaN(value) || !Number.isInteger(value)) {\n throw new Error(i18n.t('not_integer'));\n }\n\n this.setValueSync(key, String(--value));\n return value;\n }\n\n override async deleteValue(key: string): Promise<boolean> {\n this.data.delete(key);\n return true;\n }\n\n override async deleteAllValues(): Promise<boolean> {\n this.data.clear();\n return true;\n }\n\n override async expireKey(key: string, duration: number): Promise<boolean> {\n const result = this.data.get(key);\n if (!result) return false;\n if (result.expires && result.expires < Date.now()) return false;\n result.expires = Date.now() + duration;\n return true;\n }\n\n override async ttlKey(key: string): Promise<number> {\n const result = this.data.get(key);\n if (!result) return -2;\n if (!result.expires) return -1;\n if (result.expires < Date.now()) return -2;\n return result.expires - Date.now();\n }\n\n protected getValueSync<T extends 'string' | 'array' | 'any'>(\n key: string,\n assertType: T,\n ):\n | (T extends 'any' ? string | string[] : T extends 'string' ? string : Array<string>)\n | null {\n const result = this.data.get(key);\n if (!result) return null;\n if (result.expires && result.expires < Date.now()) return null;\n const value = result.value;\n\n let isValid = false;\n switch (assertType) {\n case 'string':\n isValid = typeof value === 'string';\n break;\n case 'array':\n isValid = Array.isArray(value);\n break;\n case 'any':\n isValid = true;\n break;\n }\n\n if (!isValid) {\n throw new Error(i18n.t('wrong_type'));\n }\n\n return value as any;\n }\n\n protected setValueSync(\n key: string,\n value: string | string[],\n duration?: number,\n ): boolean {\n this.data.set(key, { value, expires: duration ? Date.now() + duration : undefined });\n return true;\n }\n}\n"],"mappings":";;;AAGA,IAAa,qBAAb,cAAwC,aAAa;CACnD,uBAAe,IAAI,IAA4D;CAE/E,MAAe,UAAU,KAA+B;EACtD,OAAO,KAAK,aAAa,KAAK,KAAK,MAAM;CAC3C;CAEA,MAAe,SAAS,KAAqC;EAE3D,OADc,KAAK,aAAa,KAAK,QAC1B;CACb;CAEA,MAAe,SACb,KACA,OACA,UACkB;EAClB,OAAO,KAAK,aAAa,KAAK,OAAO,QAAQ;CAC/C;CAEA,MAAe,iBACb,KACA,OACA,UACkB;EAElB,IADqB,KAAK,aAAa,KAAK,QAC7B,MAAM,MAAM,OAAO;EAClC,OAAO,KAAK,aAAa,KAAK,OAAO,QAAQ;CAC/C;CAEA,MAAe,cAAc,KAAa,GAAG,QAAoC;EAC/E,IAAI,SAAS,KAAK,aAAa,KAAK,OAAO;EAC3C,IAAI,WAAW,MAAM,SAAS,CAAC;EAC/B,OAAO,KAAK,GAAG,MAAM;EACrB,KAAK,aAAa,KAAK,MAAM;EAC7B,OAAO;CACT;CAEA,MAAe,cAAc,KAAqC;EAChE,IAAI,SAAS,KAAK,aAAa,KAAK,OAAO;EAC3C,IAAI,WAAW,QAAQ,CAAC,OAAO,QAAQ,OAAO;EAC9C,MAAM,WAAW,OAAO,IAAI;EAC5B,IAAI,OAAO,QACT,KAAK,aAAa,KAAK,MAAM;OAE7B,KAAK,KAAK,OAAO,GAAG;EAE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I,CAAC,OAAO,SAAS,OAAO;EAC5B,IAAI,OAAO,UAAU,KAAK,IAAI,GAAG,OAAO;EACxC,OAAO,OAAO,UAAU,KAAK,IAAI;CACnC;CAEA,aACE,KACA,YAGO;EACP,MAAM,SAAS,KAAK,KAAK,IAAI,GAAG;EAChC,IAAI,CAAC,QAAQ,OAAO;EACpB,IAAI,OAAO,WAAW,OAAO,UAAU,KAAK,IAAI,GAAG,OAAO;EAC1D,MAAM,QAAQ,OAAO;EAErB,IAAI,UAAU;EACd,QAAQ,YAAR;GACE,KAAK;IACH,UAAU,OAAO,UAAU;IAC3B;GACF,KAAK;IACH,UAAU,MAAM,QAAQ,KAAK;IAC7B;GACF,KAAK,OACH,UAAU;EAEd;EAEA,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,KAAK,EAAE,YAAY,CAAC;EAGtC,OAAO;CACT;CAEA,aACE,KACA,OACA,UACS;EACT,KAAK,KAAK,IAAI,KAAK;GAAE;GAAO,SAAS,WAAW,KAAK,IAAI,IAAI,WAAW,KAAA;EAAU,CAAC;EACnF,OAAO;CACT;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-adapter-4n2JTK4Y.js","names":[],"sources":["../src/cache-adapter.ts"],"sourcesContent":["export abstract class CacheAdapter {\n async connect() {}\n\n async disconnect() {}\n\n abstract existsKey(key: string): Promise<boolean>;\n abstract getValue(key: string): Promise<string | null>;\n abstract setValue(key: string, value: string, durationMS?: number): Promise<boolean>;\n abstract setNotExistValue(\n key: string,\n value: string,\n durationMS?: number,\n ): Promise<boolean>;\n abstract deleteValue(key: string): Promise<boolean>;\n abstract deleteAllValues(): Promise<boolean>;\n abstract increaseValue(key: string): Promise<number>;\n abstract decreaseValue(key: string): Promise<number>;\n abstract expireKey(key: string, durationMS: number): Promise<boolean>;\n abstract ttlKey(key: string): Promise<number>;\n abstract leftPushValue(key: string, ...values: string[]): Promise<boolean>;\n abstract rightPopValue(key: string): Promise<string | null>;\n}\n"],"mappings":";AAAA,IAAsB,eAAtB,MAAmC;CACjC,MAAM,UAAU,CAAC;CAEjB,MAAM,aAAa,CAAC;AAkBtB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare abstract class CacheAdapter {
|
|
2
|
+
connect(): Promise<void>;
|
|
3
|
+
disconnect(): Promise<void>;
|
|
4
|
+
abstract existsKey(key: string): Promise<boolean>;
|
|
5
|
+
abstract getValue(key: string): Promise<string | null>;
|
|
6
|
+
abstract setValue(key: string, value: string, durationMS?: number): Promise<boolean>;
|
|
7
|
+
abstract setNotExistValue(key: string, value: string, durationMS?: number): Promise<boolean>;
|
|
8
|
+
abstract deleteValue(key: string): Promise<boolean>;
|
|
9
|
+
abstract deleteAllValues(): Promise<boolean>;
|
|
10
|
+
abstract increaseValue(key: string): Promise<number>;
|
|
11
|
+
abstract decreaseValue(key: string): Promise<number>;
|
|
12
|
+
abstract expireKey(key: string, durationMS: number): Promise<boolean>;
|
|
13
|
+
abstract ttlKey(key: string): Promise<number>;
|
|
14
|
+
abstract leftPushValue(key: string, ...values: string[]): Promise<boolean>;
|
|
15
|
+
abstract rightPopValue(key: string): Promise<string | null>;
|
|
16
|
+
}
|
|
17
|
+
export { CacheAdapter as t };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { I18n, createI18n } from "@aomex/common";
|
|
2
|
+
// src/i18n/locales/zh-cn.ts
|
|
3
|
+
const zh = I18n.define({
|
|
4
|
+
wrong_type: "值的类型不正确",
|
|
5
|
+
not_integer: "值不是整数"
|
|
6
|
+
});
|
|
7
|
+
// src/i18n/locales/en-us.ts
|
|
8
|
+
const en = I18n.satisfies(zh).define({
|
|
9
|
+
wrong_type: "The value has an incorrect type",
|
|
10
|
+
not_integer: "The value is not an integer"
|
|
11
|
+
});
|
|
12
|
+
// src/i18n/index.ts
|
|
13
|
+
const i18n = createI18n({
|
|
14
|
+
zh,
|
|
15
|
+
en,
|
|
16
|
+
load: (file) => import(new URL(`./locales/${file}.js`, import.meta.url).href)
|
|
17
|
+
});
|
|
18
|
+
export { i18n as t };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=i18n-BKvtLTPF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n-BKvtLTPF.js","names":[],"sources":["../src/i18n/locales/zh-cn.ts","../src/i18n/locales/en-us.ts","../src/i18n/index.ts"],"sourcesContent":["import { I18n } from '@aomex/common';\n\nexport const zh = I18n.define({\n wrong_type: '值的类型不正确',\n not_integer: '值不是整数',\n});\n","import { I18n } from '@aomex/common';\nimport { zh } from './zh-cn';\n\nexport const en = I18n.satisfies(zh).define({\n wrong_type: 'The value has an incorrect type',\n not_integer: 'The value is not an integer',\n});\n","import { createI18n } from '@aomex/common';\nimport { zh } from './locales/zh-cn';\nimport { en } from './locales/en-us';\n\nexport const i18n = createI18n({\n zh,\n en,\n load: (file) => import(new URL(`./locales/${file}.js`, import.meta.url).href),\n});\n"],"mappings":";;AAEA,MAAa,KAAK,KAAK,OAAO;CAC5B,YAAY;CACZ,aAAa;AACf,CAAC;;ACFD,MAAa,KAAK,KAAK,UAAU,EAAE,CAAC,CAAC,OAAO;CAC1C,YAAY;CACZ,aAAa;AACf,CAAC;;ACFD,MAAa,OAAO,WAAW;CAC7B;CACA;CACA,OAAO,SAAS,OAAO,IAAI,IAAI,aAAa,KAAK,MAAM,YAAY,GAAG,CAAC,CAAC;AAC1E,CAAC"}
|