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,56 @@
|
|
|
1
|
+
// Customizable validation error message formatters.
|
|
2
|
+
//
|
|
3
|
+
// Usage:
|
|
4
|
+
// import { addRule } from '@fastify-api/api';
|
|
5
|
+
// addRule('required', (field) => `${field} 必填`);
|
|
6
|
+
//
|
|
7
|
+
// Built-in defaults cover all common JSON Schema keywords.
|
|
8
|
+
// Any keyword without a registered rule falls back to AJV's original English message.
|
|
9
|
+
const rules = {};
|
|
10
|
+
export function addRule(keyword, formatter) {
|
|
11
|
+
rules[keyword] = formatter;
|
|
12
|
+
}
|
|
13
|
+
/** Extract field name from an AJV ErrorObject. */
|
|
14
|
+
function resolveField(err) {
|
|
15
|
+
const pathField = err.instancePath?.replace(/^\//, '') ?? '';
|
|
16
|
+
if (pathField)
|
|
17
|
+
return pathField;
|
|
18
|
+
const missing = err.params?.missingProperty;
|
|
19
|
+
return typeof missing === 'string' ? missing : '';
|
|
20
|
+
}
|
|
21
|
+
export function formatError(errors, dataVar) {
|
|
22
|
+
if (!errors || errors.length === 0)
|
|
23
|
+
return '请求参数校验失败';
|
|
24
|
+
const first = errors[0];
|
|
25
|
+
const field = resolveField(first);
|
|
26
|
+
if (!field && first.keyword === 'type' && first.params?.type === 'object') {
|
|
27
|
+
return dataVar === 'body' ? '请求体应为JSON对象' : '请求参数类型错误';
|
|
28
|
+
}
|
|
29
|
+
const formatter = rules[first.keyword];
|
|
30
|
+
return formatter ? formatter(field) : (first.message ?? '请求参数校验失败');
|
|
31
|
+
}
|
|
32
|
+
// ---- built-in defaults ----
|
|
33
|
+
addRule('required', (f) => `${f} 必填`);
|
|
34
|
+
addRule('type', (f) => `${f} 类型错误`);
|
|
35
|
+
addRule('pattern', (f) => `${f} 格式错误`);
|
|
36
|
+
addRule('format', (f) => `${f} 格式错误`);
|
|
37
|
+
addRule('enum', (f) => `${f} 值不在允许范围内`);
|
|
38
|
+
addRule('minimum', (f) => `${f} 不能小于最小值`);
|
|
39
|
+
addRule('maximum', (f) => `${f} 不能大于最大值`);
|
|
40
|
+
addRule('exclusiveMinimum', (f) => `${f} 必须大于最小值`);
|
|
41
|
+
addRule('exclusiveMaximum', (f) => `${f} 必须小于最大值`);
|
|
42
|
+
addRule('minLength', (f) => `${f} 长度不足`);
|
|
43
|
+
addRule('maxLength', (f) => `${f} 长度超限`);
|
|
44
|
+
addRule('minItems', (f) => `${f} 元素数不足`);
|
|
45
|
+
addRule('maxItems', (f) => `${f} 元素数超限`);
|
|
46
|
+
addRule('minProperties', (f) => `${f} 属性数不足`);
|
|
47
|
+
addRule('maxProperties', (f) => `${f} 属性数超限`);
|
|
48
|
+
addRule('const', (f) => `${f} 必须等于常量`);
|
|
49
|
+
addRule('multipleOf', (f) => `${f} 必须是整数倍`);
|
|
50
|
+
addRule('uniqueItems', (f) => `${f} 存在重复项`);
|
|
51
|
+
addRule('additionalProperties', () => `不允许有额外属性`);
|
|
52
|
+
addRule('anyOf', () => `数据格式不匹配`);
|
|
53
|
+
addRule('oneOf', () => `只能匹配一个条件`);
|
|
54
|
+
addRule('if', () => `条件不满足`);
|
|
55
|
+
addRule('not', () => `不应匹配禁止的条件`);
|
|
56
|
+
//# sourceMappingURL=errorRules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorRules.js","sourceRoot":"","sources":["../../../../src/common/validation/errorRules.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,EAAE;AACF,SAAS;AACT,gDAAgD;AAChD,mDAAmD;AACnD,EAAE;AACF,2DAA2D;AAC3D,sFAAsF;AAMtF,MAAM,KAAK,GAAkC,EAAE,CAAC;AAEhD,MAAM,UAAU,OAAO,CAAC,OAAe,EAAE,SAAwB;IAC/D,KAAK,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;AAC7B,CAAC;AAED,kDAAkD;AAClD,SAAS,YAAY,CAAC,GAAgB;IACpC,MAAM,SAAS,GAAW,GAAG,CAAC,YAAY,EAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC;IACrE,IAAI,SAAS;QAAE,OAAO,SAAS,CAAC;IAChC,MAAM,OAAO,GAAI,GAAG,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AACpD,OAAO,CAAC,sBAAsB,EAAC,GAAG,EAAE,CAAC,UAAU,CAAC,CAAC;AAEjD,OAAO,CAAC,OAAO,EAAgB,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;AAChD,OAAO,CAAC,OAAO,EAAgB,GAAG,EAAE,CAAC,UAAU,CAAC,CAAC;AACjD,OAAO,CAAC,IAAI,EAAmB,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC;AAC9C,OAAO,CAAC,KAAK,EAAkB,GAAG,EAAE,CAAC,WAAW,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/common/validation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACtH,YAAY,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/common/validation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Internal marker for required fields. */
|
|
2
|
+
declare const REQUIRED: unique symbol;
|
|
3
|
+
/** JSON Schema fragment returned by type helpers. */
|
|
4
|
+
export type SchemaProp = Record<string, unknown> & {
|
|
5
|
+
[REQUIRED]?: true;
|
|
6
|
+
};
|
|
7
|
+
export declare const String: SchemaProp;
|
|
8
|
+
export declare const Number: SchemaProp;
|
|
9
|
+
export declare const Boolean: SchemaProp;
|
|
10
|
+
export declare const Email: SchemaProp;
|
|
11
|
+
export declare function Required(schema: SchemaProp): SchemaProp;
|
|
12
|
+
export declare function ArrayOf(schema: SchemaProp): SchemaProp;
|
|
13
|
+
export declare function Enum(values: string[]): SchemaProp;
|
|
14
|
+
export declare function Min(n: number): SchemaProp;
|
|
15
|
+
export declare function Max(n: number): SchemaProp;
|
|
16
|
+
export declare function MinLength(n: number): SchemaProp;
|
|
17
|
+
export declare function MaxLength(n: number): SchemaProp;
|
|
18
|
+
/** JSON Schema default value — applied by Ajv when field is missing or undefined. */
|
|
19
|
+
export declare function Default(value: unknown): SchemaProp;
|
|
20
|
+
/** Date string in yyyy-MM-dd format. */
|
|
21
|
+
export declare const Date: SchemaProp;
|
|
22
|
+
/** DateTime string in yyyy-MM-dd HH:mm:ss format. */
|
|
23
|
+
export declare const DateTime: SchemaProp;
|
|
24
|
+
/** Page number — number, ≥1, default 1. */
|
|
25
|
+
export declare const Page: SchemaProp;
|
|
26
|
+
/** Page size — number, 1~1000, default 20. */
|
|
27
|
+
export declare const PageSize: SchemaProp;
|
|
28
|
+
interface SchemaDef {
|
|
29
|
+
[key: string]: SchemaProp;
|
|
30
|
+
}
|
|
31
|
+
declare function buildObjectSchema(def: SchemaDef): Record<string, unknown>;
|
|
32
|
+
export declare function Format(name: string): SchemaProp;
|
|
33
|
+
export declare function Pattern(regex: string): SchemaProp;
|
|
34
|
+
export { buildObjectSchema };
|
|
35
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../src/common/validation/schema.ts"],"names":[],"mappings":"AAGA,2CAA2C;AAC3C,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AS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAiBlE;AAID,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAE/C;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAEjD;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Declarative validation decorators and type shorthand helpers.
|
|
2
|
+
// Compose human-readable schemas instead of raw JSON Schema objects.
|
|
3
|
+
/** Internal marker for required fields. */
|
|
4
|
+
const REQUIRED = Symbol('required');
|
|
5
|
+
// ---- type helpers ----
|
|
6
|
+
export const String = { type: 'string' };
|
|
7
|
+
export const Number = { type: 'number' };
|
|
8
|
+
export const Boolean = { type: 'boolean' };
|
|
9
|
+
export const Email = { type: 'string', format: 'email' };
|
|
10
|
+
export function Required(schema) {
|
|
11
|
+
return { ...schema, [REQUIRED]: true };
|
|
12
|
+
}
|
|
13
|
+
export function ArrayOf(schema) {
|
|
14
|
+
return { type: 'array', items: { ...schema } };
|
|
15
|
+
}
|
|
16
|
+
export function Enum(values) {
|
|
17
|
+
return { type: 'string', enum: [...values] };
|
|
18
|
+
}
|
|
19
|
+
export function Min(n) {
|
|
20
|
+
return { minimum: n };
|
|
21
|
+
}
|
|
22
|
+
export function Max(n) {
|
|
23
|
+
return { maximum: n };
|
|
24
|
+
}
|
|
25
|
+
export function MinLength(n) {
|
|
26
|
+
return { minLength: n };
|
|
27
|
+
}
|
|
28
|
+
export function MaxLength(n) {
|
|
29
|
+
return { maxLength: n };
|
|
30
|
+
}
|
|
31
|
+
/** JSON Schema default value — applied by Ajv when field is missing or undefined. */
|
|
32
|
+
export function Default(value) {
|
|
33
|
+
return { default: value };
|
|
34
|
+
}
|
|
35
|
+
/** Date string in yyyy-MM-dd format. */
|
|
36
|
+
export const Date = { type: 'string', pattern: '^\\d{4}-\\d{2}-\\d{2}$' };
|
|
37
|
+
/** DateTime string in yyyy-MM-dd HH:mm:ss format. */
|
|
38
|
+
export const DateTime = { type: 'string', pattern: '^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$' };
|
|
39
|
+
/** Page number — number, ≥1, default 1. */
|
|
40
|
+
export const Page = { type: 'number', minimum: 1, default: 1 };
|
|
41
|
+
/** Page size — number, 1~1000, default 20. */
|
|
42
|
+
export const PageSize = { type: 'number', minimum: 1, maximum: 1000, default: 20 };
|
|
43
|
+
function buildObjectSchema(def) {
|
|
44
|
+
const properties = {};
|
|
45
|
+
const required = [];
|
|
46
|
+
for (const [key, prop] of Object.entries(def)) {
|
|
47
|
+
const { [REQUIRED]: _unused, ...rest } = prop;
|
|
48
|
+
properties[key] = rest;
|
|
49
|
+
if (prop[REQUIRED]) {
|
|
50
|
+
required.push(key);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const schema = { type: 'object', properties };
|
|
54
|
+
if (required.length > 0) {
|
|
55
|
+
schema.required = required;
|
|
56
|
+
}
|
|
57
|
+
return schema;
|
|
58
|
+
}
|
|
59
|
+
// ---- decorators ----
|
|
60
|
+
export function Format(name) {
|
|
61
|
+
return { format: name };
|
|
62
|
+
}
|
|
63
|
+
export function Pattern(regex) {
|
|
64
|
+
return { pattern: regex };
|
|
65
|
+
}
|
|
66
|
+
export { buildObjectSchema };
|
|
67
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../src/common/validation/schema.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,qEAAqE;AAErE,2CAA2C;AAC3C,MAAM,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAKpC,yBAAyB;AAEzB,MAAM,CAAC,MAAM,MAAM,GAAe,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;AACrD,MAAM,CAAC,MAAM,MAAM,GAAe,EAAE,IAAI,EAAE,QAAQ,EAAE,C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AO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AAC5B,CAAC;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import type { AppConfig } from './types';
|
|
3
|
+
export { Controller, Get, Post, Put, Delete, Login, Public, Valid, Stream, Rpc, File, Multipart, } from './common/scanner/decorators';
|
|
4
|
+
export type { StreamResponse, FileResponse, RpcHandler, Handler, RpcMeta } from './common/scanner/decorators';
|
|
5
|
+
export { SignatureStrategy } from './common/auth/SignatureStrategy';
|
|
6
|
+
export { signToken } from './common/auth/signToken';
|
|
7
|
+
export type { SecretResolver, SecretResult } from './common/auth/SignatureStrategy';
|
|
8
|
+
export { createDbSecretResolver, createRedisSecretResolver } from './common/auth/SecretResolvers';
|
|
9
|
+
export type { DbSecretResolverOptions, RedisSecretResolverOptions } from './common/auth/SecretResolvers';
|
|
10
|
+
export { MemoryNonceStore, RedisNonceStore } from './common/auth/NonceStore';
|
|
11
|
+
export type { NonceStore } from './common/auth/NonceStore';
|
|
12
|
+
export { BaseException, AuthException, BusinessException, NotFoundException, ServiceException, } from './common/exceptions/index';
|
|
13
|
+
export { db } from './common/db/index';
|
|
14
|
+
export type { Transaction } from './common/db/index';
|
|
15
|
+
export { knex } from './common/db/index';
|
|
16
|
+
export { redis } from './common/redis/index';
|
|
17
|
+
export { runMigrations } from './common/migrate/index';
|
|
18
|
+
export type { PageResult, PagedRows } from './common/dto/PageResult';
|
|
19
|
+
export type { User, AppConfig, SignatureConfig, RedisConfig, SwaggerConfig, StaticConfig } from './types';
|
|
20
|
+
export { Body, Query, Params, Response } from './common/validation/decorators';
|
|
21
|
+
export type { SchemaLike } from './common/validation/decorators';
|
|
22
|
+
export { addRule } from './common/validation/errorRules';
|
|
23
|
+
export { String, Number, Boolean, Email, Required, ArrayOf, Enum, Min, Max, MinLength, MaxLength, Pattern, Format, Date, DateTime, Default, Page, PageSize } from './common/validation/schema';
|
|
24
|
+
export type { SchemaProp } from './common/validation/schema';
|
|
25
|
+
export declare function createApp(config: AppConfig): Promise<import("fastify").FastifyInstance<import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>>;
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAwB1B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAIzC,OAAO,EACL,UAAU,EACV,GAAG,EACH,IAAI,EACJ,GAAG,EACH,MAAM,EACN,KAAK,EACL,MAAM,EACN,KAAK,EACL,MAAM,EACN,GAAG,EACH,IAAI,EACJ,SAAS,GACV,MAAM,6BAA6B,CAAC;AACrC,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAG9G,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AACpF,OAAO,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAClG,YAAY,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AACzG,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC7E,YAAY,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAG3D,OAAO,EACL,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AACvC,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACrE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE,eAAe,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG1G,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAC/E,YAAY,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAC/L,YAAY,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAE7D,wBAAsB,SAAS,CAAC,MAAM,EAAE,SAAS,oUAuPhD"}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { pathToFileURL } from 'node:url';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import Fastify, { LogController } from 'fastify';
|
|
5
|
+
import knexLib from 'knex';
|
|
6
|
+
import fastifyRedis from '@fastify/redis';
|
|
7
|
+
import fastifyJwt from '@fastify/jwt';
|
|
8
|
+
import fastifyMultipart from '@fastify/multipart';
|
|
9
|
+
import fastifyStatic from '@fastify/static';
|
|
10
|
+
import fastifySwagger from '@fastify/swagger';
|
|
11
|
+
import fastifySwaggerUi from '@fastify/swagger-ui';
|
|
12
|
+
import fg from 'fast-glob';
|
|
13
|
+
import { formatError } from './common/validation/errorRules';
|
|
14
|
+
import { initDb } from './common/db/index';
|
|
15
|
+
import { initRedis } from './common/redis/index';
|
|
16
|
+
import { errorHandler } from './common/errorHandler';
|
|
17
|
+
import { scanControllers } from './common/scanner/index';
|
|
18
|
+
import { CONTROLLER_PREFIX } from './common/scanner/decorators';
|
|
19
|
+
import { JwtStrategy } from './common/auth/JwtStrategy';
|
|
20
|
+
import { initSignToken } from './common/auth/signToken';
|
|
21
|
+
import { SignatureStrategy } from './common/auth/SignatureStrategy';
|
|
22
|
+
import { RedisNonceStore } from './common/auth/NonceStore';
|
|
23
|
+
import { container } from './common/container/index';
|
|
24
|
+
import { runMigrations } from './common/migrate/index';
|
|
25
|
+
// Public API — decorators
|
|
26
|
+
export { Controller, Get, Post, Put, Delete, Login, Public, Valid, Stream, Rpc, File, Multipart, } from './common/scanner/decorators';
|
|
27
|
+
// Public API — auth strategies
|
|
28
|
+
export { SignatureStrategy } from './common/auth/SignatureStrategy';
|
|
29
|
+
export { signToken } from './common/auth/signToken';
|
|
30
|
+
export { createDbSecretResolver, createRedisSecretResolver } from './common/auth/SecretResolvers';
|
|
31
|
+
export { MemoryNonceStore, RedisNonceStore } from './common/auth/NonceStore';
|
|
32
|
+
// Public API — exceptions
|
|
33
|
+
export { BaseException, AuthException, BusinessException, NotFoundException, ServiceException, } from './common/exceptions/index';
|
|
34
|
+
// Public API — utilities
|
|
35
|
+
export { db } from './common/db/index';
|
|
36
|
+
export { knex } from './common/db/index';
|
|
37
|
+
export { redis } from './common/redis/index';
|
|
38
|
+
export { runMigrations } from './common/migrate/index';
|
|
39
|
+
// Public API — validation
|
|
40
|
+
export { Body, Query, Params, Response } from './common/validation/decorators';
|
|
41
|
+
export { addRule } from './common/validation/errorRules';
|
|
42
|
+
export { String, Number, Boolean, Email, Required, ArrayOf, Enum, Min, Max, MinLength, MaxLength, Pattern, Format, Date, DateTime, Default, Page, PageSize } from './common/validation/schema';
|
|
43
|
+
export async function createApp(config) {
|
|
44
|
+
const fastify = Fastify({
|
|
45
|
+
bodyLimit: 10 * 1024 * 1024, // 10MB for file uploads
|
|
46
|
+
logController: new LogController({ disableRequestLogging: true }),
|
|
47
|
+
logger: {
|
|
48
|
+
level: 'info',
|
|
49
|
+
transport: {
|
|
50
|
+
target: 'pino-pretty',
|
|
51
|
+
options: { colorize: true },
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
ajv: {
|
|
55
|
+
customOptions: {
|
|
56
|
+
useDefaults: true,
|
|
57
|
+
coerceTypes: true,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
// MySQL
|
|
62
|
+
const knexInstance = knexLib({
|
|
63
|
+
client: 'mysql2',
|
|
64
|
+
connection: {
|
|
65
|
+
host: config.db.host,
|
|
66
|
+
port: config.db.port,
|
|
67
|
+
user: config.db.user,
|
|
68
|
+
password: config.db.password,
|
|
69
|
+
database: config.db.database,
|
|
70
|
+
},
|
|
71
|
+
pool: { min: 0, max: config.db.connectionLimit ?? 10 },
|
|
72
|
+
});
|
|
73
|
+
initDb(knexInstance);
|
|
74
|
+
// DB migrations
|
|
75
|
+
if (config.migrate) {
|
|
76
|
+
await runMigrations();
|
|
77
|
+
}
|
|
78
|
+
// Redis
|
|
79
|
+
if (config.redis) {
|
|
80
|
+
await fastify.register(fastifyRedis, {
|
|
81
|
+
host: config.redis.host,
|
|
82
|
+
port: config.redis.port,
|
|
83
|
+
password: config.redis.password,
|
|
84
|
+
db: config.redis.db,
|
|
85
|
+
});
|
|
86
|
+
initRedis(fastify);
|
|
87
|
+
fastify.redis.on('error', (err) => {
|
|
88
|
+
fastify.log.error({ err }, 'Redis connection error');
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
// Multipart form support — attach fields to request.body for signature verification
|
|
92
|
+
await fastify.register(fastifyMultipart, { attachFieldsToBody: true });
|
|
93
|
+
// JWT
|
|
94
|
+
let loginStrategy;
|
|
95
|
+
if (config.auth.jwtSecret) {
|
|
96
|
+
const jwtOpts = { secret: config.auth.jwtSecret };
|
|
97
|
+
if (config.auth.expiresIn) {
|
|
98
|
+
jwtOpts.sign = { expiresIn: config.auth.expiresIn };
|
|
99
|
+
}
|
|
100
|
+
await fastify.register(fastifyJwt, jwtOpts);
|
|
101
|
+
loginStrategy = new JwtStrategy(fastify);
|
|
102
|
+
initSignToken(fastify);
|
|
103
|
+
}
|
|
104
|
+
// HMAC signature — default auth layer for all non-@Public routes
|
|
105
|
+
let signStrategy;
|
|
106
|
+
const nonceStoreType = config.redis ? 'Redis' : 'Memory';
|
|
107
|
+
if (config.signature) {
|
|
108
|
+
signStrategy = new SignatureStrategy({
|
|
109
|
+
resolveSecret: config.signature.resolveSecret,
|
|
110
|
+
timestampWindowMs: config.signature.timestampWindowMs,
|
|
111
|
+
nonceStore: config.redis ? new RedisNonceStore() : undefined,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
// Auto-register all services found in modules/*\/service/
|
|
115
|
+
await autoRegisterServices();
|
|
116
|
+
const projectRoot = process.cwd();
|
|
117
|
+
// --- startup environment info ---
|
|
118
|
+
{
|
|
119
|
+
const authParts = [];
|
|
120
|
+
if (config.signature) {
|
|
121
|
+
authParts.push(`HMAC(${nonceStoreType}NonceStore)`);
|
|
122
|
+
}
|
|
123
|
+
if (config.auth.jwtSecret) {
|
|
124
|
+
authParts.push('JWT');
|
|
125
|
+
}
|
|
126
|
+
const authLine = authParts.length > 0 ? authParts.join(' + ') : 'none';
|
|
127
|
+
const nodeVersion = process.version;
|
|
128
|
+
const env = process.env.NODE_ENV ?? 'development';
|
|
129
|
+
fastify.log.info({ nodeVersion, env }, '--- Environment ---');
|
|
130
|
+
fastify.log.info({ db: `${config.db.host}:${config.db.port}/${config.db.database}`, connectionLimit: config.db.connectionLimit ?? 10 }, 'Database');
|
|
131
|
+
if (config.redis) {
|
|
132
|
+
fastify.log.info({ redis: `${config.redis.host}:${config.redis.port}`, db: config.redis.db ?? 0 }, 'Redis');
|
|
133
|
+
}
|
|
134
|
+
fastify.log.info({ auth: authLine }, 'Auth');
|
|
135
|
+
if (config.contextPath) {
|
|
136
|
+
fastify.log.info({ contextPath: config.contextPath }, 'Context');
|
|
137
|
+
}
|
|
138
|
+
if (config.swagger) {
|
|
139
|
+
fastify.log.info({ swagger: `enabled (${config.swagger.uiPrefix ?? '/docs'})` }, 'Swagger');
|
|
140
|
+
}
|
|
141
|
+
if (config.migrate) {
|
|
142
|
+
fastify.log.info({ migrate: 'enabled' }, 'Migrations');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// Swagger / OpenAPI — swagger must be on root to discover all routes
|
|
146
|
+
if (config.swagger) {
|
|
147
|
+
const pkg = {};
|
|
148
|
+
try {
|
|
149
|
+
const pkgJson = await import(pathToFileURL(projectRoot + '/package.json').href);
|
|
150
|
+
pkg.name = pkgJson.default.name;
|
|
151
|
+
pkg.version = pkgJson.default.version;
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
// no package.json found — use defaults
|
|
155
|
+
}
|
|
156
|
+
await fastify.register(fastifySwagger, {
|
|
157
|
+
openapi: {
|
|
158
|
+
info: {
|
|
159
|
+
title: config.swagger.title ?? pkg.name ?? 'API',
|
|
160
|
+
description: config.swagger.description ?? '',
|
|
161
|
+
version: config.swagger.version ?? pkg.version ?? '0.0.0',
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
// Schema validation error formatter
|
|
167
|
+
fastify.setSchemaErrorFormatter((errors, dataVar) => new Error(formatError(errors, dataVar)));
|
|
168
|
+
// Global error handler
|
|
169
|
+
fastify.setErrorHandler(errorHandler);
|
|
170
|
+
// Not found handler
|
|
171
|
+
fastify.setNotFoundHandler((_request, reply) => {
|
|
172
|
+
reply.status(404).send({ error: '接口不存在' });
|
|
173
|
+
});
|
|
174
|
+
// Route scanning
|
|
175
|
+
if (config.contextPath) {
|
|
176
|
+
await fastify.register(async (instance) => {
|
|
177
|
+
await scanControllers(instance, { cwd: projectRoot, signStrategy, loginStrategy });
|
|
178
|
+
if (config.static) {
|
|
179
|
+
const staticRoot = path.join(projectRoot, config.static.root);
|
|
180
|
+
const staticPrefix = config.static.prefix;
|
|
181
|
+
await instance.register(fastifyStatic, {
|
|
182
|
+
root: staticRoot,
|
|
183
|
+
prefix: staticPrefix,
|
|
184
|
+
wildcard: false,
|
|
185
|
+
});
|
|
186
|
+
// SPA fallback: unmatched paths under static prefix → index.html
|
|
187
|
+
instance.route({
|
|
188
|
+
method: ['GET', 'HEAD'],
|
|
189
|
+
url: `${staticPrefix}/*`,
|
|
190
|
+
handler: (_request, reply) => {
|
|
191
|
+
return reply.sendFile('index.html', staticRoot);
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
if (config.swagger) {
|
|
196
|
+
await instance.register(fastifySwaggerUi, {
|
|
197
|
+
routePrefix: config.swagger.uiPrefix ?? '/docs',
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}, { prefix: config.contextPath });
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
await scanControllers(fastify, { cwd: projectRoot, signStrategy, loginStrategy });
|
|
204
|
+
if (config.swagger) {
|
|
205
|
+
await fastify.register(fastifySwaggerUi, {
|
|
206
|
+
routePrefix: config.swagger.uiPrefix ?? '/docs',
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
// --- custom request logging (single line, runs before AJV validation) ---
|
|
211
|
+
fastify.addHook('preValidation', async (request) => {
|
|
212
|
+
const method = request.method;
|
|
213
|
+
const url = request.url;
|
|
214
|
+
const ct = request.headers['content-type'] || '';
|
|
215
|
+
const isMultipart = ct.includes('multipart/form-data');
|
|
216
|
+
const body = !isMultipart && request.body && Object.keys(request.body).length > 0
|
|
217
|
+
? JSON.stringify(request.body)
|
|
218
|
+
: (isMultipart ? '[multipart]' : '');
|
|
219
|
+
fastify.log.info(`request ${method} ${url} ${body}`);
|
|
220
|
+
});
|
|
221
|
+
// --- custom response logging (single line) ---
|
|
222
|
+
fastify.addHook('onSend', async (request, reply, payload) => {
|
|
223
|
+
const method = request.method;
|
|
224
|
+
const url = request.url;
|
|
225
|
+
const statusCode = reply.statusCode;
|
|
226
|
+
if (statusCode === 200) {
|
|
227
|
+
const body = typeof payload === 'string' ? payload : '[binary]';
|
|
228
|
+
fastify.log.info(`response ${method} ${url} 200 ${body}`);
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
let message = '';
|
|
232
|
+
if (typeof payload === 'string') {
|
|
233
|
+
try {
|
|
234
|
+
const parsed = JSON.parse(payload);
|
|
235
|
+
message = parsed.error ?? parsed.message ?? '';
|
|
236
|
+
}
|
|
237
|
+
catch {
|
|
238
|
+
message = payload;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
fastify.log.info(`response ${method} ${url} ${statusCode} ${message}`);
|
|
242
|
+
}
|
|
243
|
+
return payload;
|
|
244
|
+
});
|
|
245
|
+
// Graceful shutdown — SIGTERM (Docker stop) / SIGINT (Ctrl+C)
|
|
246
|
+
let shuttingDown = false;
|
|
247
|
+
const shutdown = async (signal) => {
|
|
248
|
+
if (shuttingDown)
|
|
249
|
+
return;
|
|
250
|
+
shuttingDown = true;
|
|
251
|
+
fastify.log.info(`Received ${signal}, shutting down gracefully...`);
|
|
252
|
+
const forceExit = setTimeout(() => {
|
|
253
|
+
fastify.log.warn('Graceful shutdown timed out, forcing exit.');
|
|
254
|
+
process.exit(1);
|
|
255
|
+
}, 10_000);
|
|
256
|
+
try {
|
|
257
|
+
await fastify.close();
|
|
258
|
+
await knexInstance.destroy();
|
|
259
|
+
clearTimeout(forceExit);
|
|
260
|
+
fastify.log.info('Server closed.');
|
|
261
|
+
process.exit(0);
|
|
262
|
+
}
|
|
263
|
+
catch (err) {
|
|
264
|
+
clearTimeout(forceExit);
|
|
265
|
+
fastify.log.error(err, 'Error during shutdown');
|
|
266
|
+
process.exit(1);
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
|
270
|
+
process.on('SIGINT', () => shutdown('SIGINT'));
|
|
271
|
+
return fastify;
|
|
272
|
+
}
|
|
273
|
+
async function autoRegisterServices() {
|
|
274
|
+
const files = await fg('src/modules/**/service/*.{ts,js}', {
|
|
275
|
+
cwd: process.cwd(),
|
|
276
|
+
absolute: true,
|
|
277
|
+
});
|
|
278
|
+
for (const file of files) {
|
|
279
|
+
const mod = await import(pathToFileURL(file).href);
|
|
280
|
+
for (const key of Object.keys(mod)) {
|
|
281
|
+
const exported = mod[key];
|
|
282
|
+
if (typeof exported !== 'function' || !exported.prototype) {
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
// Skip classes that are controllers (have @Controller decorator)
|
|
286
|
+
if (Reflect.getMetadata(CONTROLLER_PREFIX, exported) !== undefined) {
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
container.register(exported, new exported());
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,OAAO,EAAE,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,OAAO,MAAM,MAAM,CAAC;AAC3B,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAC1C,OAAO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AAkC,EAAE;QACzD,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;QAClB,QAAQ,EAAE,IAAI;KACf,CAAC,CAAC;IAEH,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;QACnD,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YACnC,MAAM,QAAQ,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;YAC1B,IAAI,OAAO,QAAQ,KAAK,UAAU,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC;gBAC1D,SAAS;YACX,CAAC;YACD,iEAAiE;YACjE,IAAI,OAAO,CAAC,WAAW,CAAC,iBAAiB,EAAE,QAAQ,CAAC,KAAK,SAAS,EAAE,CAAC;gBACnE,SAAS;YACX,CAAC;YACD,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,QAAQ,EAAE,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/main.ts"],"names":[],"mappings":""}
|
package/dist/src/main.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createApp } from './index';
|
|
2
|
+
const app = await createApp({
|
|
3
|
+
db: {
|
|
4
|
+
host: process.env.DB_HOST || '127.0.0.1',
|
|
5
|
+
port: Number(process.env.DB_PORT) || 3306,
|
|
6
|
+
user: process.env.DB_USER || 'root',
|
|
7
|
+
password: process.env.DB_PASSWORD || 'root',
|
|
8
|
+
database: process.env.DB_NAME || 'template',
|
|
9
|
+
connectionLimit: 10,
|
|
10
|
+
},
|
|
11
|
+
auth: {
|
|
12
|
+
jwtSecret: process.env.JWT_SECRET || 'dev-secret-change-me',
|
|
13
|
+
},
|
|
14
|
+
port: Number(process.env.PORT) || 3000,
|
|
15
|
+
host: process.env.HOST || '0.0.0.0',
|
|
16
|
+
});
|
|
17
|
+
try {
|
|
18
|
+
await app.listen({
|
|
19
|
+
port: Number(process.env.PORT) || 3000,
|
|
20
|
+
host: process.env.HOST || '0.0.0.0',
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
app.log.error(err);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC;IAC1B,EAAE,EAAE;QACF,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,WAAW;QACxC,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI;QACzC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,MAAM;QACnC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,MAAM;QAC3C,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,UAAU;QAC3C,eAAe,EAAE,EAAE;KACpB;IACD,IAAI,EAAE;QACJ,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,UAAU,IAAI,sBAAsB;KAC5D;IACD,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI;IACtC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,SAAS;CACpC,CAAC,CAAC;AAEH,IAAI,CAAC;IACH,MAAM,GAAG,CAAC,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI;QACtC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,SAAS;KACpC,CAAC,CAAC;AACL,CAAC;AAAC,OAAO,GAAG,EAAE,CAAC;IACb,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { FastifyRequest } from 'fastify';
|
|
2
|
+
interface HealthResponse {
|
|
3
|
+
status: string;
|
|
4
|
+
uptime: number;
|
|
5
|
+
timestamp: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class HealthController {
|
|
8
|
+
check(_request: FastifyRequest): HealthResponse;
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=HealthController.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HealthController.d.ts","sourceRoot":"","sources":["../../../../../src/modules/health/controller/HealthController.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,UAAU,cAAc;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,qBACa,gBAAgB;IAG3B,KAAK,CAAC,QAAQ,EAAE,cAAc,GAAG,cAAc;CAOhD"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { Controller, Get, Public } from '../../../common/scanner/decorators';
|
|
11
|
+
let HealthController = class HealthController {
|
|
12
|
+
check(_request) {
|
|
13
|
+
return {
|
|
14
|
+
status: 'ok',
|
|
15
|
+
uptime: process.uptime(),
|
|
16
|
+
timestamp: new Date().toISOString(),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
__decorate([
|
|
21
|
+
Get('/'),
|
|
22
|
+
Public(),
|
|
23
|
+
__metadata("design:type", Function),
|
|
24
|
+
__metadata("design:paramtypes", [Object]),
|
|
25
|
+
__metadata("design:returntype", Object)
|
|
26
|
+
], HealthController.prototype, "check", null);
|
|
27
|
+
HealthController = __decorate([
|
|
28
|
+
Controller('/api/health')
|
|
29
|
+
], HealthController);
|
|
30
|
+
export { HealthController };
|
|
31
|
+
//# sourceMappingURL=HealthController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HealthController.js","sourceRoot":"","sources":["../../../../../src/modules/health/controller/HealthController.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AAUtE,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAG3B,KAAK,CAAC,QAAwB;QAC5B,OAAO;YACL,MAAM,EAAE,IAAI;YACZ,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE;YACxB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACpC,CAAC;IACJ,CAAC;CACF,CAAA;AAPC;IAFC,GAAG,CAAC,GAAG,CAAC;IACR,MAAM,EAAE;;;;6CAOR;AATU,gBAAgB;IAD5B,UAAU,CAAC,aAAa,CAAC;GACb,gBAAgB,CAU5B"}
|