fastify-wrap 0.1.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/README.md +980 -0
- package/dist/src/client/TestClient.d.ts +33 -0
- package/dist/src/client/TestClient.d.ts.map +1 -0
- package/dist/src/client/TestClient.js +359 -0
- package/dist/src/client/TestClient.js.map +1 -0
- package/dist/src/client/index.d.ts +4 -0
- package/dist/src/client/index.d.ts.map +1 -0
- package/dist/src/client/index.js +3 -0
- package/dist/src/client/index.js.map +1 -0
- package/dist/src/client/sign.d.ts +12 -0
- package/dist/src/client/sign.d.ts.map +1 -0
- package/dist/src/client/sign.js +44 -0
- package/dist/src/client/sign.js.map +1 -0
- package/dist/src/client/types.d.ts +41 -0
- package/dist/src/client/types.d.ts.map +1 -0
- package/dist/src/client/types.js +20 -0
- package/dist/src/client/types.js.map +1 -0
- package/dist/src/common/auth/AuthStrategy.d.ts +6 -0
- package/dist/src/common/auth/AuthStrategy.d.ts.map +1 -0
- package/dist/src/common/auth/AuthStrategy.js +2 -0
- package/dist/src/common/auth/AuthStrategy.js.map +1 -0
- package/dist/src/common/auth/JwtStrategy.d.ts +9 -0
- package/dist/src/common/auth/JwtStrategy.d.ts.map +1 -0
- package/dist/src/common/auth/JwtStrategy.js +34 -0
- package/dist/src/common/auth/JwtStrategy.js.map +1 -0
- package/dist/src/common/auth/NonceStore.d.ts +22 -0
- package/dist/src/common/auth/NonceStore.d.ts.map +1 -0
- package/dist/src/common/auth/NonceStore.js +27 -0
- package/dist/src/common/auth/NonceStore.js.map +1 -0
- package/dist/src/common/auth/SecretResolvers.d.ts +18 -0
- package/dist/src/common/auth/SecretResolvers.d.ts.map +1 -0
- package/dist/src/common/auth/SecretResolvers.js +30 -0
- package/dist/src/common/auth/SecretResolvers.js.map +1 -0
- package/dist/src/common/auth/SignatureStrategy.d.ts +23 -0
- package/dist/src/common/auth/SignatureStrategy.d.ts.map +1 -0
- package/dist/src/common/auth/SignatureStrategy.js +115 -0
- package/dist/src/common/auth/SignatureStrategy.js.map +1 -0
- package/dist/src/common/auth/index.d.ts +4 -0
- package/dist/src/common/auth/index.d.ts.map +1 -0
- package/dist/src/common/auth/index.js +3 -0
- package/dist/src/common/auth/index.js.map +1 -0
- package/dist/src/common/auth/signToken.d.ts +4 -0
- package/dist/src/common/auth/signToken.d.ts.map +1 -0
- package/dist/src/common/auth/signToken.js +11 -0
- package/dist/src/common/auth/signToken.js.map +1 -0
- package/dist/src/common/config/loader.d.ts +10 -0
- package/dist/src/common/config/loader.d.ts.map +1 -0
- package/dist/src/common/config/loader.js +20 -0
- package/dist/src/common/config/loader.js.map +1 -0
- package/dist/src/common/container/index.d.ts +7 -0
- package/dist/src/common/container/index.d.ts.map +1 -0
- package/dist/src/common/container/index.js +15 -0
- package/dist/src/common/container/index.js.map +1 -0
- package/dist/src/common/db/index.d.ts +19 -0
- package/dist/src/common/db/index.d.ts.map +1 -0
- package/dist/src/common/db/index.js +64 -0
- package/dist/src/common/db/index.js.map +1 -0
- package/dist/src/common/dto/PageResult.d.ts +12 -0
- package/dist/src/common/dto/PageResult.d.ts.map +1 -0
- package/dist/src/common/dto/PageResult.js +2 -0
- package/dist/src/common/dto/PageResult.js.map +1 -0
- package/dist/src/common/errorHandler.d.ts +3 -0
- package/dist/src/common/errorHandler.d.ts.map +1 -0
- package/dist/src/common/errorHandler.js +47 -0
- package/dist/src/common/errorHandler.js.map +1 -0
- package/dist/src/common/exceptions/AuthException.d.ts +5 -0
- package/dist/src/common/exceptions/AuthException.d.ts.map +1 -0
- package/dist/src/common/exceptions/AuthException.js +8 -0
- package/dist/src/common/exceptions/AuthException.js.map +1 -0
- package/dist/src/common/exceptions/BaseException.d.ts +4 -0
- package/dist/src/common/exceptions/BaseException.d.ts.map +1 -0
- package/dist/src/common/exceptions/BaseException.js +7 -0
- package/dist/src/common/exceptions/BaseException.js.map +1 -0
- package/dist/src/common/exceptions/BusinessException.d.ts +5 -0
- package/dist/src/common/exceptions/BusinessException.d.ts.map +1 -0
- package/dist/src/common/exceptions/BusinessException.js +8 -0
- package/dist/src/common/exceptions/BusinessException.js.map +1 -0
- package/dist/src/common/exceptions/NotFoundException.d.ts +5 -0
- package/dist/src/common/exceptions/NotFoundException.d.ts.map +1 -0
- package/dist/src/common/exceptions/NotFoundException.js +8 -0
- package/dist/src/common/exceptions/NotFoundException.js.map +1 -0
- package/dist/src/common/exceptions/ServiceException.d.ts +5 -0
- package/dist/src/common/exceptions/ServiceException.d.ts.map +1 -0
- package/dist/src/common/exceptions/ServiceException.js +8 -0
- package/dist/src/common/exceptions/ServiceException.js.map +1 -0
- package/dist/src/common/exceptions/index.d.ts +6 -0
- package/dist/src/common/exceptions/index.d.ts.map +1 -0
- package/dist/src/common/exceptions/index.js +6 -0
- package/dist/src/common/exceptions/index.js.map +1 -0
- package/dist/src/common/migrate/index.d.ts +3 -0
- package/dist/src/common/migrate/index.d.ts.map +1 -0
- package/dist/src/common/migrate/index.js +49 -0
- package/dist/src/common/migrate/index.js.map +1 -0
- package/dist/src/common/redis/index.d.ts +14 -0
- package/dist/src/common/redis/index.d.ts.map +1 -0
- package/dist/src/common/redis/index.js +41 -0
- package/dist/src/common/redis/index.js.map +1 -0
- package/dist/src/common/scanner/auth-factory.d.ts +42 -0
- package/dist/src/common/scanner/auth-factory.d.ts.map +1 -0
- package/dist/src/common/scanner/auth-factory.js +86 -0
- package/dist/src/common/scanner/auth-factory.js.map +1 -0
- package/dist/src/common/scanner/decorators.d.ts +123 -0
- package/dist/src/common/scanner/decorators.d.ts.map +1 -0
- package/dist/src/common/scanner/decorators.js +158 -0
- package/dist/src/common/scanner/decorators.js.map +1 -0
- package/dist/src/common/scanner/handler-factory.d.ts +38 -0
- package/dist/src/common/scanner/handler-factory.d.ts.map +1 -0
- package/dist/src/common/scanner/handler-factory.js +76 -0
- package/dist/src/common/scanner/handler-factory.js.map +1 -0
- package/dist/src/common/scanner/index.d.ts +16 -0
- package/dist/src/common/scanner/index.d.ts.map +1 -0
- package/dist/src/common/scanner/index.js +157 -0
- package/dist/src/common/scanner/index.js.map +1 -0
- package/dist/src/common/validation/decorators.d.ts +28 -0
- package/dist/src/common/validation/decorators.d.ts.map +1 -0
- package/dist/src/common/validation/decorators.js +70 -0
- package/dist/src/common/validation/decorators.js.map +1 -0
- package/dist/src/common/validation/errorRules.d.ts +5 -0
- package/dist/src/common/validation/errorRules.d.ts.map +1 -0
- package/dist/src/common/validation/errorRules.js +56 -0
- package/dist/src/common/validation/errorRules.js.map +1 -0
- package/dist/src/common/validation/index.d.ts +4 -0
- package/dist/src/common/validation/index.d.ts.map +1 -0
- package/dist/src/common/validation/index.js +3 -0
- package/dist/src/common/validation/index.js.map +1 -0
- package/dist/src/common/validation/schema.d.ts +35 -0
- package/dist/src/common/validation/schema.d.ts.map +1 -0
- package/dist/src/common/validation/schema.js +67 -0
- package/dist/src/common/validation/schema.js.map +1 -0
- package/dist/src/index.d.ts +26 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +293 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/main.d.ts +2 -0
- package/dist/src/main.d.ts.map +1 -0
- package/dist/src/main.js +27 -0
- package/dist/src/main.js.map +1 -0
- package/dist/src/modules/health/controller/HealthController.d.ts +11 -0
- package/dist/src/modules/health/controller/HealthController.d.ts.map +1 -0
- package/dist/src/modules/health/controller/HealthController.js +31 -0
- package/dist/src/modules/health/controller/HealthController.js.map +1 -0
- package/dist/src/modules/health/service/HealthService.d.ts +4 -0
- package/dist/src/modules/health/service/HealthService.d.ts.map +1 -0
- package/dist/src/modules/health/service/HealthService.js +6 -0
- package/dist/src/modules/health/service/HealthService.js.map +1 -0
- package/dist/src/types.d.ts +75 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/package.json +53 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseException.js","sourceRoot":"","sources":["../../../../src/common/exceptions/BaseException.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BusinessException.d.ts","sourceRoot":"","sources":["../../../../src/common/exceptions/BusinessException.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,qBAAa,iBAAkB,SAAQ,aAAa;gBACtC,OAAO,EAAE,MAAM;CAI5B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BusinessException.js","sourceRoot":"","sources":["../../../../src/common/exceptions/BusinessException.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,MAAM,OAAO,iBAAkB,SAAQ,aAAa;IAClD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NotFoundException.d.ts","sourceRoot":"","sources":["../../../../src/common/exceptions/NotFoundException.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,qBAAa,iBAAkB,SAAQ,aAAa;gBACtC,OAAO,EAAE,MAAM;CAI5B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NotFoundException.js","sourceRoot":"","sources":["../../../../src/common/exceptions/NotFoundException.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,MAAM,OAAO,iBAAkB,SAAQ,aAAa;IAClD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServiceException.d.ts","sourceRoot":"","sources":["../../../../src/common/exceptions/ServiceException.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,qBAAa,gBAAiB,SAAQ,aAAa;gBACrC,OAAO,EAAE,MAAM;CAI5B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServiceException.js","sourceRoot":"","sources":["../../../../src/common/exceptions/ServiceException.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,MAAM,OAAO,gBAAiB,SAAQ,aAAa;IACjD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { BaseException } from './BaseException';
|
|
2
|
+
export { BusinessException } from './BusinessException';
|
|
3
|
+
export { ServiceException } from './ServiceException';
|
|
4
|
+
export { NotFoundException } from './NotFoundException';
|
|
5
|
+
export { AuthException } from './AuthException';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/common/exceptions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { BaseException } from './BaseException';
|
|
2
|
+
export { BusinessException } from './BusinessException';
|
|
3
|
+
export { ServiceException } from './ServiceException';
|
|
4
|
+
export { NotFoundException } from './NotFoundException';
|
|
5
|
+
export { AuthException } from './AuthException';
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/common/exceptions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/common/migrate/index.ts"],"names":[],"mappings":"AA6BA,sEAAsE;AACtE,wBAAsB,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAoBnD"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { readdir, readFile } from 'node:fs/promises';
|
|
2
|
+
import { join, extname } from 'node:path';
|
|
3
|
+
import { db } from '../db/index';
|
|
4
|
+
/** Creates the tracking table if it doesn't exist. */
|
|
5
|
+
async function ensureTrackingTable() {
|
|
6
|
+
await db.execute(`CREATE TABLE IF NOT EXISTS migrations (
|
|
7
|
+
name VARCHAR(255) NOT NULL,
|
|
8
|
+
executed_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
9
|
+
PRIMARY KEY (name)
|
|
10
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4`);
|
|
11
|
+
}
|
|
12
|
+
/** Returns the set of file names already recorded as executed. */
|
|
13
|
+
async function executedFiles() {
|
|
14
|
+
const rows = await db.query('SELECT name FROM migrations');
|
|
15
|
+
return new Set(rows.map((r) => r.name));
|
|
16
|
+
}
|
|
17
|
+
/** Lists .sql files in alphabetical order. */
|
|
18
|
+
async function sqlFiles(dir) {
|
|
19
|
+
try {
|
|
20
|
+
const names = await readdir(dir);
|
|
21
|
+
return names.filter((n) => extname(n) === '.sql').sort();
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** Scans src/migrations/, executes unexecuted .sql files in order. */
|
|
28
|
+
export async function runMigrations() {
|
|
29
|
+
const dir = join(process.cwd(), 'src/migrations');
|
|
30
|
+
const files = await sqlFiles(dir);
|
|
31
|
+
if (files.length === 0)
|
|
32
|
+
return;
|
|
33
|
+
await ensureTrackingTable();
|
|
34
|
+
const executed = await executedFiles();
|
|
35
|
+
for (const file of files) {
|
|
36
|
+
if (executed.has(file))
|
|
37
|
+
continue;
|
|
38
|
+
const sql = await readFile(join(dir, file), 'utf-8');
|
|
39
|
+
const statements = sql
|
|
40
|
+
.split(';')
|
|
41
|
+
.map((s) => s.trim())
|
|
42
|
+
.filter((s) => s.length > 0);
|
|
43
|
+
for (const stmt of statements) {
|
|
44
|
+
await db.execute(stmt);
|
|
45
|
+
}
|
|
46
|
+
await db.execute('INSERT INTO migrations (name) VALUES (?)', [file]);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/common/migrate/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAEjC,sDAAsD;AACt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CAAC;QAC7D,MAAM,UAAU,GAAa,GAAG;aAC7B,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;aAC5B,MAAM,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACvC,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;YAC9B,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACzB,CAAC;QACD,MAAM,EAAE,CAAC,OAAO,CAAC,0CAA0C,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IACvE,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { FastifyInstance } from 'fastify';
|
|
2
|
+
export declare function initRedis(fastify: FastifyInstance): void;
|
|
3
|
+
export declare const redis: {
|
|
4
|
+
set(key: string, value: string, ttlSeconds?: number): Promise<void>;
|
|
5
|
+
get(key: string): Promise<string | null>;
|
|
6
|
+
del(key: string): Promise<void>;
|
|
7
|
+
exists(key: string): Promise<boolean>;
|
|
8
|
+
/**
|
|
9
|
+
* SET if Not eXists with TTL. Atomic.
|
|
10
|
+
* @returns true if set (key was new), false if key already existed.
|
|
11
|
+
*/
|
|
12
|
+
setnx(key: string, value: string, ttlSeconds: number): Promise<boolean>;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/common/redis/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAK/C,wBAAgB,SAAS,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI,CAGxD;AASD,eAAO,MAAM,KAAK;aACD,MAAM,SAAS,MAAM,eAAe,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;aAS1D,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;aAI/B,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;gBAInB,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAK3C;;;OAGG;eACc,MAAM,SAAS,MAAM,cAAc,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAI9E,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
let client = null;
|
|
2
|
+
export function initRedis(fastify) {
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4
|
+
client = fastify.redis;
|
|
5
|
+
}
|
|
6
|
+
function assertClient() {
|
|
7
|
+
if (!client) {
|
|
8
|
+
throw new Error('Redis not initialized. Did you call initRedis()?');
|
|
9
|
+
}
|
|
10
|
+
return client;
|
|
11
|
+
}
|
|
12
|
+
export const redis = {
|
|
13
|
+
async set(key, value, ttlSeconds) {
|
|
14
|
+
const c = assertClient();
|
|
15
|
+
if (ttlSeconds !== undefined) {
|
|
16
|
+
await c.set(key, value, 'EX', ttlSeconds);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
await c.set(key, value);
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
async get(key) {
|
|
23
|
+
return assertClient().get(key);
|
|
24
|
+
},
|
|
25
|
+
async del(key) {
|
|
26
|
+
await assertClient().del(key);
|
|
27
|
+
},
|
|
28
|
+
async exists(key) {
|
|
29
|
+
const result = await assertClient().exists(key);
|
|
30
|
+
return result === 1;
|
|
31
|
+
},
|
|
32
|
+
/**
|
|
33
|
+
* SET if Not eXists with TTL. Atomic.
|
|
34
|
+
* @returns true if set (key was new), false if key already existed.
|
|
35
|
+
*/
|
|
36
|
+
async setnx(key, value, ttlSeconds) {
|
|
37
|
+
const reply = await assertClient().set(key, value, 'EX', ttlSeconds, 'NX');
|
|
38
|
+
return reply === 'OK';
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/common/redis/index.ts"],"names":[],"mappings":"AAGA,IAAI,MAAM,GAAiB,IAAI,CAAC;AAEhC,MAAM,UAAU,SAAS,CAAC,OAAwB;IAChD,8DAA8D;IAC9D,MAAM,GAAI,OAAe,CAAC,KAAc,CAAC;AAC3C,CAAC;AAED,SAAS,YAAY;IACnB,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACtE,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,KAAa,EAAE,UAAmB;QACvD,MAAM,CAAC,GAAG,YAAY,EAAE,CAAC;QACzB,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;YAC7B,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;QAC5C,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW;QACnB,OAAO,YAAY,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW;QACnB,MAAM,YAAY,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAChC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAW;QACtB,MAAM,MAAM,GAAG,MAAM,YAAY,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAChD,OAAO,MAAM,KAAK,CAAC,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,KAAK,CAAC,GAAW,EAAE,KAAa,EAAE,UAAkB;QACxD,MAAM,KAAK,GAAG,MAAM,YAAY,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;QAC3E,OAAO,KAAK,KAAK,IAAI,CAAC;IACxB,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { FastifyRequest, FastifyReply } from 'fastify';
|
|
2
|
+
import type { AuthStrategy } from '../auth/AuthStrategy';
|
|
3
|
+
import type { LoginMeta } from './decorators';
|
|
4
|
+
export type AuthHook = (request: FastifyRequest, reply: FastifyReply) => Promise<void>;
|
|
5
|
+
export interface AuthHookMeta {
|
|
6
|
+
isPublic: boolean;
|
|
7
|
+
loginMeta?: LoginMeta;
|
|
8
|
+
}
|
|
9
|
+
export interface AuthHookFactoryOptions {
|
|
10
|
+
signStrategy?: AuthStrategy;
|
|
11
|
+
loginStrategy?: AuthStrategy;
|
|
12
|
+
}
|
|
13
|
+
export interface AuthHookFactory {
|
|
14
|
+
/** Returns true if this factory should handle the given auth metadata */
|
|
15
|
+
accept(meta: AuthHookMeta): boolean;
|
|
16
|
+
/** Creates preValidation hooks for the route */
|
|
17
|
+
create(meta: AuthHookMeta, options: AuthHookFactoryOptions): AuthHook[];
|
|
18
|
+
}
|
|
19
|
+
/** Computes auth label string for logging */
|
|
20
|
+
export declare function authLabel(meta: AuthHookMeta): string;
|
|
21
|
+
/** No auth hooks for @Public routes */
|
|
22
|
+
export declare class PublicAuthHookFactory implements AuthHookFactory {
|
|
23
|
+
accept(meta: AuthHookMeta): boolean;
|
|
24
|
+
create(): AuthHook[];
|
|
25
|
+
}
|
|
26
|
+
/** HMAC signature only — no module filtering */
|
|
27
|
+
export declare class HmacAuthHookFactory implements AuthHookFactory {
|
|
28
|
+
accept(meta: AuthHookMeta): boolean;
|
|
29
|
+
create(_meta: AuthHookMeta, options: AuthHookFactoryOptions): AuthHook[];
|
|
30
|
+
}
|
|
31
|
+
/** HMAC signature + JWT login with module filtering */
|
|
32
|
+
export declare class JwtAuthHookFactory implements AuthHookFactory {
|
|
33
|
+
accept(meta: AuthHookMeta): boolean;
|
|
34
|
+
create(meta: AuthHookMeta, options: AuthHookFactoryOptions): AuthHook[];
|
|
35
|
+
}
|
|
36
|
+
/** Registry that holds AuthHookFactory instances and delegates via first-match */
|
|
37
|
+
export declare class AuthHookFactoryRegistry {
|
|
38
|
+
private factories;
|
|
39
|
+
register(factory: AuthHookFactory): void;
|
|
40
|
+
create(meta: AuthHookMeta, options: AuthHookFactoryOptions): AuthHook[];
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=auth-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-factory.d.ts","sourceRoot":"","sources":["../../../../src/common/scanner/auth-factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAG9C,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEvF,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAED,MAAM,WAAW,sBAAsB;IACrC,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,aAAa,CAAC,EAAE,YAAY,CAAC;CAC9B;AAED,MAAM,WAAW,eAAe;IAC9B,yEAAyE;IACzE,MAAM,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC;IACpC,gDAAgD;IAChD,MAAM,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,sBAAsB,GAAG,QAAQ,EAAE,CAAC;CACzE;AAED,6CAA6C;AAC7C,wBAAgB,SAAS,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,CAQpD;AAED,uCAAuC;AACvC,qBAAa,qBAAsB,YAAW,eAAe;IAC3D,MAAM,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO;IAGnC,MAAM,IAAI,QAAQ,EAAE;CAGrB;AAED,gDAAgD;AAChD,qBAAa,mBAAoB,YAAW,eAAe;IACzD,MAAM,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO;IAGnC,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,sBAAsB,GAAG,QAAQ,EAAE;CAYzE;AAED,uDAAuD;AACvD,qBAAa,kBAAmB,YAAW,eAAe;IACxD,MAAM,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO;IAGnC,MAAM,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,sBAAsB,GAAG,QAAQ,EAAE;CA0BxE;AAED,kFAAkF;AAClF,qBAAa,uBAAuB;IAClC,OAAO,CAAC,SAAS,CAAyB;IAE1C,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI;IAIxC,MAAM,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,sBAAsB,GAAG,QAAQ,EAAE;CAQxE"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/** Computes auth label string for logging */
|
|
2
|
+
export function authLabel(meta) {
|
|
3
|
+
if (meta.isPublic)
|
|
4
|
+
return 'public';
|
|
5
|
+
if (meta.loginMeta) {
|
|
6
|
+
return meta.loginMeta.module
|
|
7
|
+
? `HMAC+JWT(${meta.loginMeta.module})`
|
|
8
|
+
: 'HMAC+JWT';
|
|
9
|
+
}
|
|
10
|
+
return 'HMAC';
|
|
11
|
+
}
|
|
12
|
+
/** No auth hooks for @Public routes */
|
|
13
|
+
export class PublicAuthHookFactory {
|
|
14
|
+
accept(meta) {
|
|
15
|
+
return meta.isPublic;
|
|
16
|
+
}
|
|
17
|
+
create() {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** HMAC signature only — no module filtering */
|
|
22
|
+
export class HmacAuthHookFactory {
|
|
23
|
+
accept(meta) {
|
|
24
|
+
return !meta.isPublic && !meta.loginMeta;
|
|
25
|
+
}
|
|
26
|
+
create(_meta, options) {
|
|
27
|
+
const signAuth = options.signStrategy;
|
|
28
|
+
if (!signAuth) {
|
|
29
|
+
throw new Error('Route requires signature auth but no signStrategy configured');
|
|
30
|
+
}
|
|
31
|
+
return [
|
|
32
|
+
async (request, reply) => {
|
|
33
|
+
const user = await signAuth.authenticate(request, reply);
|
|
34
|
+
request.user = user;
|
|
35
|
+
},
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** HMAC signature + JWT login with module filtering */
|
|
40
|
+
export class JwtAuthHookFactory {
|
|
41
|
+
accept(meta) {
|
|
42
|
+
return !meta.isPublic && !!meta.loginMeta;
|
|
43
|
+
}
|
|
44
|
+
create(meta, options) {
|
|
45
|
+
const signAuth = options.signStrategy;
|
|
46
|
+
const loginAuth = options.loginStrategy;
|
|
47
|
+
if (!signAuth) {
|
|
48
|
+
throw new Error('Route requires signature auth but no signStrategy configured');
|
|
49
|
+
}
|
|
50
|
+
if (!loginAuth) {
|
|
51
|
+
throw new Error('Route requires login but no loginStrategy configured');
|
|
52
|
+
}
|
|
53
|
+
const moduleName = meta.loginMeta?.module;
|
|
54
|
+
const hooks = [
|
|
55
|
+
async (request, reply) => {
|
|
56
|
+
const user = await signAuth.authenticate(request, reply, moduleName);
|
|
57
|
+
request.user = user;
|
|
58
|
+
},
|
|
59
|
+
async (request, reply) => {
|
|
60
|
+
const user = await loginAuth.authenticate(request, reply, moduleName);
|
|
61
|
+
const loginMeta = meta.loginMeta;
|
|
62
|
+
if (loginMeta.module && user.type !== loginMeta.module) {
|
|
63
|
+
reply.status(403).send({ error: '权限不足' });
|
|
64
|
+
}
|
|
65
|
+
request.user = user;
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
return hooks;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/** Registry that holds AuthHookFactory instances and delegates via first-match */
|
|
72
|
+
export class AuthHookFactoryRegistry {
|
|
73
|
+
factories = [];
|
|
74
|
+
register(factory) {
|
|
75
|
+
this.factories.push(factory);
|
|
76
|
+
}
|
|
77
|
+
create(meta, options) {
|
|
78
|
+
for (const factory of this.factories) {
|
|
79
|
+
if (factory.accept(meta)) {
|
|
80
|
+
return factory.create(meta, options);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
throw new Error(`No AuthHookFactory found for meta: isPublic=${meta.isPublic}, hasLogin=${!!meta.loginMeta}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=auth-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-factory.js","sourceRoot":"","sources":["../../../../src/common/scanner/auth-factory.ts"],"names":[],"mappings":"AAwBA,6CAA6C;AAC7C,MAAM,UAAU,SAAS,CAAC,IAAkB;IAC1C,IAAI,IAAI,CAAC,QAAQ;QAAE,OAAO,QAAQ,CAAC;IACnC,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;QACnB,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM;YAC1B,CAAC,CAAC,YAAY,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG;YACtC,CAAC,CAAC,UAAU,CAAC;IACjB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,uCAAuC;AACvC,MAAM,OAAO,qBAAqB;IAChC,MAAM,CAAC,IAAkB;QACvB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IACD,MAAM;QACJ,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AAED,gDAAgD;AAChD,MAAM,OAAO,mBAAmB;IAC9B,MAAM,CAAC,IAAkB;QACvB,OAAO,CAAC,IAA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AAG,IAAI,CAAC;YAC3D,CAAC;YACD,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE;gBACvB,MAAM,IAAI,GAAS,MAAM,SAAS,CAAC,YAAY,CAAC,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;gBAC5E,MAAM,SAAS,GAAG,IAAI,CAAC,SAAU,CAAC;gBAClC,IAAI,SAAS,CAAC,MAAM,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,MAAM,EAAE,CAAC;oBACvD,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;gBAC5C,CAAC;gBACA,OAA2C,CAAC,IAAI,GAAG,IAAI,CAAC;YAC3D,CAAC;SACF,CAAC;QACF,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAED,kFAAkF;AAClF,MAAM,OAAO,uBAAuB;IAC1B,SAAS,GAAsB,EAAE,CAAC;IAE1C,QAAQ,CAAC,OAAwB;QAC/B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC;IAED,MAAM,CAAC,IAAkB,EAAE,OAA+B;QACxD,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACrC,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;gBACzB,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YACvC,CAAC;QACH,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,+CAA+C,IAAI,CAAC,QAAQ,cAAc,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;IAChH,CAAC;CACF"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import type { FastifyRequest, FastifyReply } from 'fastify';
|
|
3
|
+
import type { User } from '../../types';
|
|
4
|
+
export declare const CONTROLLER_PREFIX: unique symbol;
|
|
5
|
+
export declare const ROUTES: unique symbol;
|
|
6
|
+
export declare const LOGIN_META: unique symbol;
|
|
7
|
+
export declare const PUBLIC_META: unique symbol;
|
|
8
|
+
export declare const VALID_META: unique symbol;
|
|
9
|
+
export declare const STREAM_META: unique symbol;
|
|
10
|
+
export declare const RPC_META: unique symbol;
|
|
11
|
+
export declare const FILE_META: unique symbol;
|
|
12
|
+
export declare const MULTIPART_META: unique symbol;
|
|
13
|
+
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
14
|
+
export interface RouteMeta {
|
|
15
|
+
method: HttpMethod;
|
|
16
|
+
path: string;
|
|
17
|
+
handlerName: string;
|
|
18
|
+
}
|
|
19
|
+
export interface LoginMeta {
|
|
20
|
+
/** Required module (subsystem) that the token must belong to, e.g. 'admin', 'bd'. Checks against user.type. */
|
|
21
|
+
module?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface ValidMeta {
|
|
24
|
+
schema: Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Marks a class as a controller and sets the route prefix.
|
|
28
|
+
*/
|
|
29
|
+
export declare function Controller(prefix: string): ClassDecorator;
|
|
30
|
+
export interface RpcMeta {
|
|
31
|
+
/** Controller name segment in URL path. Defaults to the exported class name. */
|
|
32
|
+
name?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Marks a controller class as RPC-style.
|
|
36
|
+
*
|
|
37
|
+
* RPC controllers differ from regular controllers:
|
|
38
|
+
* - All routes must use POST (JSON body)
|
|
39
|
+
* - URL must not contain path parameters (e.g. /user/:id)
|
|
40
|
+
* - Handler methods receive (body, user) instead of (request, reply)
|
|
41
|
+
* - Routes are auto-derived from module directory, controller name, and method name
|
|
42
|
+
*
|
|
43
|
+
* URL pattern: `/{module}/{controller}/{method}`
|
|
44
|
+
* - Module: folder name under src/modules/, overridable via route.config.ts
|
|
45
|
+
* - Controller: set via the `name` argument (defaults to class name)
|
|
46
|
+
* - Method name stays as-is in code
|
|
47
|
+
*
|
|
48
|
+
* Does not require @Controller — @Rpc() on its own is sufficient.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* @Rpc('users')
|
|
53
|
+
* class UserRpc {
|
|
54
|
+
* list(body: { page: number }, user: User) { ... }
|
|
55
|
+
* // → POST /{module}/users/list
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare function Rpc(name?: string): ClassDecorator;
|
|
60
|
+
/** RPC handler: receives parsed body and authenticated user */
|
|
61
|
+
export type RpcHandler<B = unknown, R = unknown> = (body: B, user: User) => R;
|
|
62
|
+
/** Normal controller handler: receives Fastify request and reply */
|
|
63
|
+
export type Handler = (request: FastifyRequest, reply: FastifyReply) => unknown;
|
|
64
|
+
export declare const Get: (path: string) => MethodDecorator;
|
|
65
|
+
export declare const Post: (path: string) => MethodDecorator;
|
|
66
|
+
export declare const Put: (path: string) => MethodDecorator;
|
|
67
|
+
export declare const Delete: (path: string) => MethodDecorator;
|
|
68
|
+
/**
|
|
69
|
+
* Requires login authentication for the route.
|
|
70
|
+
* Can be used as method decorator (on individual methods) or class decorator
|
|
71
|
+
* (applies to all methods in the controller, overridable by method-level @Login or @Public).
|
|
72
|
+
* @param module Required module (subsystem) e.g. 'admin', 'bd', 'merchant'. Checks against user.type in JWT.
|
|
73
|
+
*/
|
|
74
|
+
export declare function Login(module?: string): MethodDecorator & ClassDecorator;
|
|
75
|
+
/**
|
|
76
|
+
* Explicitly marks a route as public (no authentication).
|
|
77
|
+
*/
|
|
78
|
+
export declare function Public(): MethodDecorator;
|
|
79
|
+
/**
|
|
80
|
+
* Attaches a JSON Schema for Fastify validation.
|
|
81
|
+
* @param schema A Fastify route schema object (body/query/params/headers).
|
|
82
|
+
*/
|
|
83
|
+
export declare function Valid(schema: Record<string, unknown>): MethodDecorator;
|
|
84
|
+
/**
|
|
85
|
+
* Marks a route that streams content as a downloadable file.
|
|
86
|
+
* The controller method must return `StreamResponse { name, content }`.
|
|
87
|
+
*
|
|
88
|
+
* @param description Optional OpenAPI description for the response.
|
|
89
|
+
*/
|
|
90
|
+
export declare function Stream(description?: string): MethodDecorator;
|
|
91
|
+
/**
|
|
92
|
+
* Response type for stream download endpoints.
|
|
93
|
+
* @property name - The filename sent to the client (Content-Disposition)
|
|
94
|
+
* @property content - Raw content as string or Buffer, sent directly
|
|
95
|
+
*/
|
|
96
|
+
export interface StreamResponse {
|
|
97
|
+
name: string;
|
|
98
|
+
content: string | Buffer;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Marks a route that sends a file from the server filesystem as download.
|
|
102
|
+
* The controller method must return `FileResponse { name, path }`.
|
|
103
|
+
* The framework reads the file at `path` and sends it with the given filename.
|
|
104
|
+
*
|
|
105
|
+
* @param description Optional OpenAPI description for the response.
|
|
106
|
+
*/
|
|
107
|
+
export declare function File(description?: string): MethodDecorator;
|
|
108
|
+
/**
|
|
109
|
+
* Response type for file download endpoints.
|
|
110
|
+
* @property name - The filename sent to the client (Content-Disposition)
|
|
111
|
+
* @property path - Absolute path on the server filesystem
|
|
112
|
+
*/
|
|
113
|
+
export interface FileResponse {
|
|
114
|
+
name: string;
|
|
115
|
+
path: string;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Marks a route that handles multipart/form-data file upload.
|
|
119
|
+
* No @Body is required — the file cannot be validated as JSON Schema.
|
|
120
|
+
* This is a pure marker; the framework does not attach any runtime behavior.
|
|
121
|
+
*/
|
|
122
|
+
export declare function Multipart(): MethodDecorator;
|
|
123
|
+
//# sourceMappingURL=decorators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../../../src/common/scanner/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EA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