@scpxl/nodejs-framework 1.0.22 → 1.0.25
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 +264 -26
- package/dist/api-requester/api-requester.d.ts +32 -0
- package/dist/api-requester/api-requester.d.ts.map +1 -0
- package/dist/api-requester/api-requester.js +2 -1
- package/dist/api-requester/api-requester.js.map +2 -2
- package/dist/api-requester/index.d.ts +3 -0
- package/dist/api-requester/index.d.ts.map +1 -0
- package/dist/application/base-application.d.ts +106 -0
- package/dist/application/base-application.d.ts.map +1 -0
- package/dist/application/base-application.interface.d.ts +162 -0
- package/dist/application/base-application.interface.d.ts.map +1 -0
- package/dist/application/base-application.js +7 -3
- package/dist/application/base-application.js.map +2 -2
- package/dist/application/command-application.d.ts +18 -0
- package/dist/application/command-application.d.ts.map +1 -0
- package/dist/application/command-application.interface.d.ts +26 -0
- package/dist/application/command-application.interface.d.ts.map +1 -0
- package/dist/application/index.d.ts +5 -0
- package/dist/application/index.d.ts.map +1 -0
- package/dist/application/web-application.d.ts +43 -0
- package/dist/application/web-application.d.ts.map +1 -0
- package/dist/application/web-application.interface.d.ts +21 -0
- package/dist/application/web-application.interface.d.ts.map +1 -0
- package/dist/application/web-application.js +1 -0
- package/dist/application/web-application.js.map +2 -2
- package/dist/auth/index.d.ts +2 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/jwt.d.ts +25 -0
- package/dist/auth/jwt.d.ts.map +1 -0
- package/dist/cache/index.d.ts +2 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/manager.d.ts +107 -0
- package/dist/cache/manager.d.ts.map +1 -0
- package/dist/cache/manager.js +2 -1
- package/dist/cache/manager.js.map +2 -2
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +12591 -0
- package/dist/cli/index.js.map +7 -0
- package/dist/cluster/cluster-manager.d.ts +18 -0
- package/dist/cluster/cluster-manager.d.ts.map +1 -0
- package/dist/cluster/cluster-manager.interface.d.ts +23 -0
- package/dist/cluster/cluster-manager.interface.d.ts.map +1 -0
- package/dist/cluster/cluster-manager.js +45 -8
- package/dist/cluster/cluster-manager.js.map +2 -2
- package/dist/cluster/index.d.ts +2 -0
- package/dist/cluster/index.d.ts.map +1 -0
- package/dist/command/command-manager.d.ts +19 -0
- package/dist/command/command-manager.d.ts.map +1 -0
- package/dist/command/command.d.ts +27 -0
- package/dist/command/command.d.ts.map +1 -0
- package/dist/command/command.interface.d.ts +11 -0
- package/dist/command/command.interface.d.ts.map +1 -0
- package/dist/command/index.d.ts +3 -0
- package/dist/command/index.d.ts.map +1 -0
- package/dist/config/env.d.ts +11 -0
- package/dist/config/env.d.ts.map +1 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/schema.d.ts +432 -0
- package/dist/config/schema.d.ts.map +1 -0
- package/dist/database/dynamic-entity-form-decorators.d.ts +31 -0
- package/dist/database/dynamic-entity-form-decorators.d.ts.map +1 -0
- package/dist/database/dynamic-entity-form-decorators.js.map +1 -1
- package/dist/database/dynamic-entity.d.ts +18 -0
- package/dist/database/dynamic-entity.d.ts.map +1 -0
- package/dist/database/dynamic-entity.js +11 -1
- package/dist/database/dynamic-entity.js.map +2 -2
- package/dist/database/index.d.ts +5 -0
- package/dist/database/index.d.ts.map +1 -0
- package/dist/database/instance.d.ts +36 -0
- package/dist/database/instance.d.ts.map +1 -0
- package/dist/database/instance.interface.d.ts +5 -0
- package/dist/database/instance.interface.d.ts.map +1 -0
- package/dist/database/manager.d.ts +27 -0
- package/dist/database/manager.d.ts.map +1 -0
- package/dist/database/manager.interface.d.ts +18 -0
- package/dist/database/manager.interface.d.ts.map +1 -0
- package/dist/database/manager.js +3 -2
- package/dist/database/manager.js.map +2 -2
- package/dist/error/error-reporter.d.ts +109 -0
- package/dist/error/error-reporter.d.ts.map +1 -0
- package/dist/error/error-reporter.js +32 -29
- package/dist/error/error-reporter.js.map +2 -2
- package/dist/error/error.interface.d.ts +126 -0
- package/dist/error/error.interface.d.ts.map +1 -0
- package/dist/error/framework-errors.d.ts +113 -0
- package/dist/error/framework-errors.d.ts.map +1 -0
- package/dist/error/index.d.ts +6 -0
- package/dist/error/index.d.ts.map +1 -0
- package/dist/error/index.js +3 -2
- package/dist/error/index.js.map +2 -2
- package/dist/event/controller/base.d.ts +23 -0
- package/dist/event/controller/base.d.ts.map +1 -0
- package/dist/event/controller/base.interface.d.ts +11 -0
- package/dist/event/controller/base.interface.d.ts.map +1 -0
- package/dist/event/controller/base.js +2 -1
- package/dist/event/controller/base.js.map +2 -2
- package/dist/event/index.d.ts +5 -0
- package/dist/event/index.d.ts.map +1 -0
- package/dist/event/manager.d.ts +21 -0
- package/dist/event/manager.d.ts.map +1 -0
- package/dist/event/manager.interface.d.ts +137 -0
- package/dist/event/manager.interface.d.ts.map +1 -0
- package/dist/event/manager.js +5 -4
- package/dist/event/manager.js.map +2 -2
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/lifecycle/exit.d.ts +11 -0
- package/dist/lifecycle/exit.d.ts.map +1 -0
- package/dist/lifecycle/exit.js.map +2 -2
- package/dist/lifecycle/index.d.ts +7 -0
- package/dist/lifecycle/index.d.ts.map +1 -0
- package/dist/lifecycle/lifecycle-manager.d.ts +66 -0
- package/dist/lifecycle/lifecycle-manager.d.ts.map +1 -0
- package/dist/lifecycle/lifecycle-manager.js +6 -11
- package/dist/lifecycle/lifecycle-manager.js.map +2 -2
- package/dist/lifecycle/shutdown-controller.d.ts +15 -0
- package/dist/lifecycle/shutdown-controller.d.ts.map +1 -0
- package/dist/lifecycle/types.d.ts +28 -0
- package/dist/lifecycle/types.d.ts.map +1 -0
- package/dist/logger/index.d.ts +2 -0
- package/dist/logger/index.d.ts.map +1 -0
- package/dist/logger/logger.d.ts +59 -0
- package/dist/logger/logger.d.ts.map +1 -0
- package/dist/logger/logger.interface.d.ts +2 -0
- package/dist/logger/logger.interface.d.ts.map +1 -0
- package/dist/logger/logger.js +11 -3
- package/dist/logger/logger.js.map +2 -2
- package/dist/performance/cache-performance.d.ts +64 -0
- package/dist/performance/cache-performance.d.ts.map +1 -0
- package/dist/performance/database-performance.d.ts +40 -0
- package/dist/performance/database-performance.d.ts.map +1 -0
- package/dist/performance/index.d.ts +8 -0
- package/dist/performance/index.d.ts.map +1 -0
- package/dist/performance/performance-monitor.d.ts +68 -0
- package/dist/performance/performance-monitor.d.ts.map +1 -0
- package/dist/performance/performance-monitor.js +10 -3
- package/dist/performance/performance-monitor.js.map +2 -2
- package/dist/performance/performance-monitor.plugin.d.ts +24 -0
- package/dist/performance/performance-monitor.plugin.d.ts.map +1 -0
- package/dist/performance/queue-performance.d.ts +46 -0
- package/dist/performance/queue-performance.d.ts.map +1 -0
- package/dist/performance/webserver-performance.d.ts +69 -0
- package/dist/performance/webserver-performance.d.ts.map +1 -0
- package/dist/performance/websocket-performance.d.ts +44 -0
- package/dist/performance/websocket-performance.d.ts.map +1 -0
- package/dist/queue/index.d.ts +6 -0
- package/dist/queue/index.d.ts.map +1 -0
- package/dist/queue/index.interface.d.ts +10 -0
- package/dist/queue/index.interface.d.ts.map +1 -0
- package/dist/queue/job.interface.d.ts +43 -0
- package/dist/queue/job.interface.d.ts.map +1 -0
- package/dist/queue/manager.d.ts +44 -0
- package/dist/queue/manager.d.ts.map +1 -0
- package/dist/queue/manager.interface.d.ts +18 -0
- package/dist/queue/manager.interface.d.ts.map +1 -0
- package/dist/queue/processor/base.d.ts +29 -0
- package/dist/queue/processor/base.d.ts.map +1 -0
- package/dist/queue/processor/base.js +2 -1
- package/dist/queue/processor/base.js.map +2 -2
- package/dist/queue/processor/processor.interface.d.ts +16 -0
- package/dist/queue/processor/processor.interface.d.ts.map +1 -0
- package/dist/queue/worker.d.ts +14 -0
- package/dist/queue/worker.d.ts.map +1 -0
- package/dist/queue/worker.interface.d.ts +13 -0
- package/dist/queue/worker.interface.d.ts.map +1 -0
- package/dist/redis/index.d.ts +3 -0
- package/dist/redis/index.d.ts.map +1 -0
- package/dist/redis/instance.d.ts +32 -0
- package/dist/redis/instance.d.ts.map +1 -0
- package/dist/redis/instance.interface.d.ts +9 -0
- package/dist/redis/instance.interface.d.ts.map +1 -0
- package/dist/redis/manager.d.ts +15 -0
- package/dist/redis/manager.d.ts.map +1 -0
- package/dist/redis/manager.interface.d.ts +8 -0
- package/dist/redis/manager.interface.d.ts.map +1 -0
- package/dist/redis/manager.js +16 -16
- package/dist/redis/manager.js.map +2 -2
- package/dist/request-context/index.d.ts +3 -0
- package/dist/request-context/index.d.ts.map +1 -0
- package/dist/request-context/request-context.d.ts +108 -0
- package/dist/request-context/request-context.d.ts.map +1 -0
- package/dist/request-context/request-context.interface.d.ts +46 -0
- package/dist/request-context/request-context.interface.d.ts.map +1 -0
- package/dist/schemas/common.d.ts +197 -0
- package/dist/schemas/common.d.ts.map +1 -0
- package/dist/schemas/common.js +108 -0
- package/dist/schemas/common.js.map +7 -0
- package/dist/schemas/index.d.ts +6 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +2 -0
- package/dist/schemas/index.js.map +7 -0
- package/dist/services/aws/index.d.ts +2 -0
- package/dist/services/aws/index.d.ts.map +1 -0
- package/dist/services/aws/s3.d.ts +54 -0
- package/dist/services/aws/s3.d.ts.map +1 -0
- package/dist/services/aws/s3.interface.d.ts +14 -0
- package/dist/services/aws/s3.interface.d.ts.map +1 -0
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/util/file.d.ts +58 -0
- package/dist/util/file.d.ts.map +1 -0
- package/dist/util/helper.d.ts +51 -0
- package/dist/util/helper.d.ts.map +1 -0
- package/dist/util/helper.js +72 -10
- package/dist/util/helper.js.map +2 -2
- package/dist/util/image.d.ts +12 -0
- package/dist/util/image.d.ts.map +1 -0
- package/dist/util/index.d.ts +11 -0
- package/dist/util/index.d.ts.map +1 -0
- package/dist/util/loader.d.ts +21 -0
- package/dist/util/loader.d.ts.map +1 -0
- package/dist/util/loader.js +5 -2
- package/dist/util/loader.js.map +2 -2
- package/dist/util/num.d.ts +13 -0
- package/dist/util/num.d.ts.map +1 -0
- package/dist/util/os.d.ts +6 -0
- package/dist/util/os.d.ts.map +1 -0
- package/dist/util/str.d.ts +39 -0
- package/dist/util/str.d.ts.map +1 -0
- package/dist/util/time.d.ts +19 -0
- package/dist/util/time.d.ts.map +1 -0
- package/dist/util/time.interface.d.ts +12 -0
- package/dist/util/time.interface.d.ts.map +1 -0
- package/dist/util/timing.d.ts +36 -0
- package/dist/util/timing.d.ts.map +1 -0
- package/dist/util/timing.interface.d.ts +47 -0
- package/dist/util/timing.interface.d.ts.map +1 -0
- package/dist/util/url.d.ts +7 -0
- package/dist/util/url.d.ts.map +1 -0
- package/dist/webserver/controller/auth-middleware.d.ts +21 -0
- package/dist/webserver/controller/auth-middleware.d.ts.map +1 -0
- package/dist/webserver/controller/base.d.ts +41 -0
- package/dist/webserver/controller/base.d.ts.map +1 -0
- package/dist/webserver/controller/base.interface.d.ts +50 -0
- package/dist/webserver/controller/base.interface.d.ts.map +1 -0
- package/dist/webserver/controller/base.js +4 -4
- package/dist/webserver/controller/base.js.map +2 -2
- package/dist/webserver/controller/entity.d.ts +94 -0
- package/dist/webserver/controller/entity.d.ts.map +1 -0
- package/dist/webserver/controller/entity.js.map +2 -2
- package/dist/webserver/controller/example-auth.d.ts +12 -0
- package/dist/webserver/controller/example-auth.d.ts.map +1 -0
- package/dist/webserver/controller/health.d.ts +13 -0
- package/dist/webserver/controller/health.d.ts.map +1 -0
- package/dist/webserver/controller/health.js +0 -14
- package/dist/webserver/controller/health.js.map +2 -2
- package/dist/webserver/define-action.d.ts +26 -0
- package/dist/webserver/define-action.d.ts.map +1 -0
- package/dist/webserver/define-action.js +16 -0
- package/dist/webserver/define-action.js.map +7 -0
- package/dist/webserver/define-route.d.ts +53 -0
- package/dist/webserver/define-route.d.ts.map +1 -0
- package/dist/webserver/define-route.js +11 -6
- package/dist/webserver/define-route.js.map +2 -2
- package/dist/webserver/index.d.ts +14 -0
- package/dist/webserver/index.d.ts.map +1 -0
- package/dist/webserver/index.js +2 -0
- package/dist/webserver/index.js.map +2 -2
- package/dist/webserver/util.d.ts +10 -0
- package/dist/webserver/util.d.ts.map +1 -0
- package/dist/webserver/util.js +5 -2
- package/dist/webserver/util.js.map +2 -2
- package/dist/webserver/webserver.d.ts +93 -0
- package/dist/webserver/webserver.d.ts.map +1 -0
- package/dist/webserver/webserver.interface.d.ts +181 -0
- package/dist/webserver/webserver.interface.d.ts.map +1 -0
- package/dist/webserver/webserver.interface.js.map +1 -1
- package/dist/webserver/webserver.js +30 -33
- package/dist/webserver/webserver.js.map +2 -2
- package/dist/websocket/controller/client/base.d.ts +12 -0
- package/dist/websocket/controller/client/base.d.ts.map +1 -0
- package/dist/websocket/controller/client/base.interface.d.ts +12 -0
- package/dist/websocket/controller/client/base.interface.d.ts.map +1 -0
- package/dist/websocket/controller/server/base.d.ts +13 -0
- package/dist/websocket/controller/server/base.d.ts.map +1 -0
- package/dist/websocket/controller/server/base.interface.d.ts +13 -0
- package/dist/websocket/controller/server/base.interface.d.ts.map +1 -0
- package/dist/websocket/controllers/client/system.d.ts +6 -0
- package/dist/websocket/controllers/client/system.d.ts.map +1 -0
- package/dist/websocket/controllers/server/system.d.ts +7 -0
- package/dist/websocket/controllers/server/system.d.ts.map +1 -0
- package/dist/websocket/index.d.ts +9 -0
- package/dist/websocket/index.d.ts.map +1 -0
- package/dist/websocket/index.js +2 -0
- package/dist/websocket/index.js.map +2 -2
- package/dist/websocket/routes/client/system.d.ts +3 -0
- package/dist/websocket/routes/client/system.d.ts.map +1 -0
- package/dist/websocket/routes/server/system.d.ts +3 -0
- package/dist/websocket/routes/server/system.d.ts.map +1 -0
- package/dist/websocket/utils.d.ts +9 -0
- package/dist/websocket/utils.d.ts.map +1 -0
- package/dist/websocket/websocket-auth.d.ts +17 -0
- package/dist/websocket/websocket-auth.d.ts.map +1 -0
- package/dist/websocket/websocket-auth.js +46 -0
- package/dist/websocket/websocket-auth.js.map +7 -0
- package/dist/websocket/websocket-base.d.ts +19 -0
- package/dist/websocket/websocket-base.d.ts.map +1 -0
- package/dist/websocket/websocket-client-manager.d.ts +53 -0
- package/dist/websocket/websocket-client-manager.d.ts.map +1 -0
- package/dist/websocket/websocket-client-manager.interface.d.ts +8 -0
- package/dist/websocket/websocket-client-manager.interface.d.ts.map +1 -0
- package/dist/websocket/websocket-client-manager.js +6 -5
- package/dist/websocket/websocket-client-manager.js.map +2 -2
- package/dist/websocket/websocket-client.d.ts +64 -0
- package/dist/websocket/websocket-client.d.ts.map +1 -0
- package/dist/websocket/websocket-client.interface.d.ts +14 -0
- package/dist/websocket/websocket-client.interface.d.ts.map +1 -0
- package/dist/websocket/websocket-client.js +97 -3
- package/dist/websocket/websocket-client.js.map +2 -2
- package/dist/websocket/websocket-room-manager.d.ts +32 -0
- package/dist/websocket/websocket-room-manager.d.ts.map +1 -0
- package/dist/websocket/websocket-server.d.ts +102 -0
- package/dist/websocket/websocket-server.d.ts.map +1 -0
- package/dist/websocket/websocket-server.interface.d.ts +16 -0
- package/dist/websocket/websocket-server.interface.d.ts.map +1 -0
- package/dist/websocket/websocket-server.js +62 -50
- package/dist/websocket/websocket-server.js.map +2 -2
- package/dist/websocket/websocket-service.d.ts +44 -0
- package/dist/websocket/websocket-service.d.ts.map +1 -0
- package/dist/websocket/websocket.interface.d.ts +137 -0
- package/dist/websocket/websocket.interface.d.ts.map +1 -0
- package/dist/websocket/websocket.interface.js.map +2 -2
- package/package.json +21 -24
- package/pxl.js +0 -4
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
getRandomNumber: ({ min, max }: {
|
|
3
|
+
min: number;
|
|
4
|
+
max: number;
|
|
5
|
+
}) => number;
|
|
6
|
+
clamp: ({ value, min, max }: {
|
|
7
|
+
value: number;
|
|
8
|
+
min: number;
|
|
9
|
+
max: number;
|
|
10
|
+
}) => number;
|
|
11
|
+
};
|
|
12
|
+
export default _default;
|
|
13
|
+
//# sourceMappingURL=num.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"num.d.ts","sourceRoot":"","sources":["../../src/util/num.ts"],"names":[],"mappings":";oCAAuC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,KAAG,MAAM;iCAIxC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,KAAG,MAAM;;AAIxF,wBAGE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"os.d.ts","sourceRoot":"","sources":["../../src/util/os.ts"],"names":[],"mappings":"AAGA,iBAAS,mBAAmB,IAAI,MAAM,CAarC;;;;AAED,wBAEE"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate a unique id.
|
|
3
|
+
*/
|
|
4
|
+
declare function generateUniqueId(): string;
|
|
5
|
+
/**
|
|
6
|
+
* Slugify string.
|
|
7
|
+
*/
|
|
8
|
+
declare function slugify({ text }: {
|
|
9
|
+
text: string;
|
|
10
|
+
}): string;
|
|
11
|
+
/**
|
|
12
|
+
* Make text title case.
|
|
13
|
+
*/
|
|
14
|
+
declare function titleCase({ text }: {
|
|
15
|
+
text: string;
|
|
16
|
+
}): string;
|
|
17
|
+
/**
|
|
18
|
+
* Remove file extension from filename.
|
|
19
|
+
*/
|
|
20
|
+
declare function removeFileExtension({ filename }: {
|
|
21
|
+
filename: string;
|
|
22
|
+
}): string;
|
|
23
|
+
/**
|
|
24
|
+
* Get file extension from filename.
|
|
25
|
+
* @param filename
|
|
26
|
+
* @returns File extension
|
|
27
|
+
*/
|
|
28
|
+
declare function getFileExtension({ filename }: {
|
|
29
|
+
filename: string;
|
|
30
|
+
}): string;
|
|
31
|
+
declare const _default: {
|
|
32
|
+
generateUniqueId: typeof generateUniqueId;
|
|
33
|
+
slugify: typeof slugify;
|
|
34
|
+
titleCase: typeof titleCase;
|
|
35
|
+
removeFileExtension: typeof removeFileExtension;
|
|
36
|
+
getFileExtension: typeof getFileExtension;
|
|
37
|
+
};
|
|
38
|
+
export default _default;
|
|
39
|
+
//# sourceMappingURL=str.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"str.d.ts","sourceRoot":"","sources":["../../src/util/str.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,iBAAS,gBAAgB,IAAI,MAAM,CAElC;AAED;;GAEG;AACH,iBAAS,OAAO,CAAC,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAQnD;AAED;;GAEG;AACH,iBAAS,SAAS,CAAC,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAMrD;AAED;;GAEG;AACH,iBAAS,mBAAmB,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAEvE;AAED;;;;GAIG;AACH,iBAAS,gBAAgB,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAEpE;;;;;;;;AAED,wBAME"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { FormatRelativeTimeOptions, FormatTimeOptions } from './time.interface.js';
|
|
2
|
+
import Timing from './timing.js';
|
|
3
|
+
declare const _default: {
|
|
4
|
+
calculateElapsedTimeMs: ({ startTime }: {
|
|
5
|
+
startTime: number;
|
|
6
|
+
}) => number;
|
|
7
|
+
formatTime: ({ time, format, numDecimals, showUnit }: FormatTimeOptions) => string;
|
|
8
|
+
formatRelativeTime: ({ date, baseDate, includeSeconds, }: FormatRelativeTimeOptions) => string;
|
|
9
|
+
sleep: ({ seconds }: {
|
|
10
|
+
seconds: number;
|
|
11
|
+
}) => Promise<void>;
|
|
12
|
+
now: typeof Timing.now;
|
|
13
|
+
start: typeof Timing.start;
|
|
14
|
+
measure: typeof Timing.measure;
|
|
15
|
+
measureSync: typeof Timing.measureSync;
|
|
16
|
+
duration: typeof Timing.duration;
|
|
17
|
+
};
|
|
18
|
+
export default _default;
|
|
19
|
+
//# sourceMappingURL=time.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../src/util/time.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxF,OAAO,MAAM,MAAM,aAAa,CAAC;;4CAMc;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,KAAG,MAAM;0DAOI,iBAAiB,KAAG,MAAM;8DA4CxG,yBAAyB,KAAG,MAAM;yBAbT;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,KAAG,OAAO,CAAC,IAAI,CAAC;;;;;;;AA6D/D,wBAWE"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface FormatTimeOptions {
|
|
2
|
+
time: number;
|
|
3
|
+
format?: 'ms' | 's' | 'auto' | 'hh:mm:ss';
|
|
4
|
+
numDecimals?: number;
|
|
5
|
+
showUnit?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface FormatRelativeTimeOptions {
|
|
8
|
+
date: Date;
|
|
9
|
+
baseDate?: Date;
|
|
10
|
+
includeSeconds?: boolean;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=time.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time.interface.d.ts","sourceRoot":"","sources":["../../src/util/time.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,IAAI,GAAG,GAAG,GAAG,MAAM,GAAG,UAAU,CAAC;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,IAAI,CAAC;IACX,QAAQ,CAAC,EAAE,IAAI,CAAC;IAChB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { MeasureOptions, Timer, TimingResult } from './timing.interface.js';
|
|
2
|
+
/**
|
|
3
|
+
* Modern high-resolution timing utility using performance.now()
|
|
4
|
+
*
|
|
5
|
+
* Provides simple APIs for measuring function execution time and manual timing.
|
|
6
|
+
* All durations are returned in milliseconds with decimal precision.
|
|
7
|
+
*/
|
|
8
|
+
declare class Timing {
|
|
9
|
+
/**
|
|
10
|
+
* Get current high-resolution timestamp in milliseconds.
|
|
11
|
+
* Uses performance.now() which provides sub-millisecond precision.
|
|
12
|
+
*/
|
|
13
|
+
static now(): number;
|
|
14
|
+
/**
|
|
15
|
+
* Start a timer and return a Timer instance.
|
|
16
|
+
* Call timer.stop() to get elapsed time in milliseconds.
|
|
17
|
+
*/
|
|
18
|
+
static start(): Timer;
|
|
19
|
+
/**
|
|
20
|
+
* Measure the execution time of a function (async or sync).
|
|
21
|
+
* Returns both the function result and timing information.
|
|
22
|
+
*/
|
|
23
|
+
static measure<T>(fn: () => T | Promise<T>, options?: MeasureOptions): Promise<TimingResult<T>>;
|
|
24
|
+
/**
|
|
25
|
+
* Measure the execution time of a synchronous function.
|
|
26
|
+
* Returns both the function result and timing information.
|
|
27
|
+
*/
|
|
28
|
+
static measureSync<T>(fn: () => T, options?: MeasureOptions): TimingResult<T>;
|
|
29
|
+
/**
|
|
30
|
+
* Calculate duration between two timestamps in milliseconds.
|
|
31
|
+
* Both timestamps should be from performance.now().
|
|
32
|
+
*/
|
|
33
|
+
static duration(startTime: number, endTime: number): number;
|
|
34
|
+
}
|
|
35
|
+
export default Timing;
|
|
36
|
+
//# sourceMappingURL=timing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timing.d.ts","sourceRoot":"","sources":["../../src/util/timing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAqBjF;;;;;GAKG;AACH,cAAM,MAAM;IACV;;;OAGG;IACH,MAAM,CAAC,GAAG,IAAI,MAAM;IAIpB;;;OAGG;IACH,MAAM,CAAC,KAAK,IAAI,KAAK;IAIrB;;;OAGG;WACU,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAwBzG;;;OAGG;IACH,MAAM,CAAC,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,OAAO,GAAE,cAAmB,GAAG,YAAY,CAAC,CAAC,CAAC;IAwBjF;;;OAGG;IACH,MAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM;CAG5D;AAED,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export interface Timer {
|
|
2
|
+
/**
|
|
3
|
+
* Stop the timer and return elapsed time in milliseconds with decimal precision.
|
|
4
|
+
*/
|
|
5
|
+
stop(): number;
|
|
6
|
+
/**
|
|
7
|
+
* Get elapsed time since timer start without stopping the timer.
|
|
8
|
+
*/
|
|
9
|
+
elapsed(): number;
|
|
10
|
+
/**
|
|
11
|
+
* The start timestamp in milliseconds (performance.now() format).
|
|
12
|
+
*/
|
|
13
|
+
readonly startTime: number;
|
|
14
|
+
}
|
|
15
|
+
export interface TimingResult<T = unknown> {
|
|
16
|
+
/**
|
|
17
|
+
* Duration in milliseconds with decimal precision.
|
|
18
|
+
*/
|
|
19
|
+
duration: number;
|
|
20
|
+
/**
|
|
21
|
+
* The result returned by the measured function.
|
|
22
|
+
*/
|
|
23
|
+
result: T;
|
|
24
|
+
/**
|
|
25
|
+
* Start timestamp in milliseconds (performance.now() format).
|
|
26
|
+
*/
|
|
27
|
+
startTime: number;
|
|
28
|
+
/**
|
|
29
|
+
* End timestamp in milliseconds (performance.now() format).
|
|
30
|
+
*/
|
|
31
|
+
endTime: number;
|
|
32
|
+
}
|
|
33
|
+
export interface MeasureOptions {
|
|
34
|
+
/**
|
|
35
|
+
* Optional name for the measurement (useful for logging/debugging).
|
|
36
|
+
*/
|
|
37
|
+
name?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Whether to log the timing result automatically.
|
|
40
|
+
*/
|
|
41
|
+
log?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Custom logger function to use if log is true.
|
|
44
|
+
*/
|
|
45
|
+
logger?: (message: string, duration: number) => void;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=timing.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timing.interface.d.ts","sourceRoot":"","sources":["../../src/util/timing.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,KAAK;IACpB;;OAEG;IACH,IAAI,IAAI,MAAM,CAAC;IAEf;;OAEG;IACH,OAAO,IAAI,MAAM,CAAC;IAElB;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,OAAO;IACvC;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,MAAM,EAAE,CAAC,CAAC;IAEV;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC;IAEd;;OAEG;IACH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;CACtD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../src/util/url.ts"],"names":[],"mappings":";+BAAkC;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;KAAE,KAAG,MAAM;;AAOvF,wBAEE"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { FastifyReply, FastifyRequest } from 'fastify';
|
|
2
|
+
import type { AuthenticatedUser } from './base.js';
|
|
3
|
+
export type { AuthenticatedUser } from './base.js';
|
|
4
|
+
export interface AuthenticatedRequest extends FastifyRequest {
|
|
5
|
+
user: AuthenticatedUser;
|
|
6
|
+
}
|
|
7
|
+
export type AuthenticatedRouteHandler = (request: AuthenticatedRequest, reply: FastifyReply) => Promise<void>;
|
|
8
|
+
export type RouteHandler = (request: FastifyRequest, reply: FastifyReply) => Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* Higher-order function that wraps a route handler with authentication
|
|
11
|
+
* @param handler The route handler that requires authentication
|
|
12
|
+
* @param authenticateRequest The authentication method from the controller
|
|
13
|
+
* @returns A new route handler with authentication built-in
|
|
14
|
+
*/
|
|
15
|
+
export declare function withAuth(handler: AuthenticatedRouteHandler, authenticateRequest: (request: FastifyRequest, reply: FastifyReply) => Promise<AuthenticatedUser | null>): RouteHandler;
|
|
16
|
+
/**
|
|
17
|
+
* Method decorator for class-based controllers
|
|
18
|
+
* Usage: @requiresAuth()
|
|
19
|
+
*/
|
|
20
|
+
export declare function requiresAuth(): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
21
|
+
//# sourceMappingURL=auth-middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-middleware.d.ts","sourceRoot":"","sources":["../../../src/webserver/controller/auth-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAEnD,YAAY,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAEnD,MAAM,WAAW,oBAAqB,SAAQ,cAAc;IAC1D,IAAI,EAAE,iBAAiB,CAAC;CACzB;AAED,MAAM,MAAM,yBAAyB,GAAG,CAAC,OAAO,EAAE,oBAAoB,EAAE,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAC9G,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAE3F;;;;;GAKG;AACH,wBAAgB,QAAQ,CACtB,OAAO,EAAE,yBAAyB,EAClC,mBAAmB,EAAE,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,GACvG,YAAY,CAed;AAED;;;GAGG;AACH,wBAAgB,YAAY,KACT,QAAQ,GAAG,EAAE,aAAa,MAAM,EAAE,YAAY,kBAAkB,wBAoBlF"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { StatusCodes } from 'http-status-codes';
|
|
2
|
+
import type { FastifyReply, FastifyRequest } from 'fastify';
|
|
3
|
+
import type { DatabaseInstance } from '../../database/index.js';
|
|
4
|
+
import type { RedisInstance } from '../../redis/index.js';
|
|
5
|
+
import type { QueueManager } from '../../queue/index.js';
|
|
6
|
+
import type { ApiError, ApiResponse, WebServerBaseControllerConstructorParams } from './base.interface.js';
|
|
7
|
+
import type { ApplicationConfig } from '../../application/base-application.interface.js';
|
|
8
|
+
import type EventManager from '../../event/manager.js';
|
|
9
|
+
import type { WebServerOptions } from '../webserver.interface.js';
|
|
10
|
+
import type { LifecycleManager } from '../../lifecycle/lifecycle-manager.js';
|
|
11
|
+
export interface AuthenticatedUser<TPayload = Record<string, unknown>> {
|
|
12
|
+
userId: number;
|
|
13
|
+
payload: TPayload;
|
|
14
|
+
}
|
|
15
|
+
export default abstract class BaseController<TQueueManager extends QueueManager = QueueManager, TRedisInstance extends RedisInstance = RedisInstance, TEventManager extends EventManager = EventManager, TDatabaseInstance extends DatabaseInstance = DatabaseInstance> {
|
|
16
|
+
protected workerId: number | undefined;
|
|
17
|
+
protected applicationConfig: ApplicationConfig;
|
|
18
|
+
protected webServerOptions: WebServerOptions;
|
|
19
|
+
protected redisInstance: TRedisInstance;
|
|
20
|
+
protected queueManager: TQueueManager;
|
|
21
|
+
protected eventManager: TEventManager;
|
|
22
|
+
protected databaseInstance: TDatabaseInstance;
|
|
23
|
+
protected lifecycleManager: LifecycleManager;
|
|
24
|
+
constructor({ applicationConfig, webServerOptions, redisInstance, queueManager, eventManager, databaseInstance, lifecycleManager, }: WebServerBaseControllerConstructorParams<TQueueManager, TRedisInstance, TEventManager, TDatabaseInstance>);
|
|
25
|
+
protected sendSuccessResponse<T = unknown>({ reply, data, statusCode, meta, }: {
|
|
26
|
+
reply: FastifyReply;
|
|
27
|
+
data: T;
|
|
28
|
+
statusCode?: StatusCodes;
|
|
29
|
+
meta?: ApiResponse<T>['meta'];
|
|
30
|
+
}): void;
|
|
31
|
+
protected sendNotFoundResponse(reply: FastifyReply, message?: string): void;
|
|
32
|
+
protected sendErrorResponse({ reply, error, statusCode, errorType, }: {
|
|
33
|
+
reply: FastifyReply;
|
|
34
|
+
error: unknown;
|
|
35
|
+
statusCode?: StatusCodes;
|
|
36
|
+
errorType?: ApiError['type'];
|
|
37
|
+
}): void;
|
|
38
|
+
private getErrorType;
|
|
39
|
+
protected authenticateRequest(request: FastifyRequest, reply: FastifyReply): Promise<AuthenticatedUser | null>;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/webserver/controller/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,wCAAwC,EAAE,MAAM,qBAAqB,CAAC;AAE3G,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iDAAiD,CAAC;AACzF,OAAO,KAAK,YAAY,MAAM,wBAAwB,CAAC;AAEvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAI7E,MAAM,WAAW,iBAAiB,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACnE,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,QAAQ,CAAC;CACnB;AAED,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,cAAc,CAC1C,aAAa,SAAS,YAAY,GAAG,YAAY,EACjD,cAAc,SAAS,aAAa,GAAG,aAAa,EACpD,aAAa,SAAS,YAAY,GAAG,YAAY,EACjD,iBAAiB,SAAS,gBAAgB,GAAG,gBAAgB;IAE7D,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAEvC,SAAS,CAAC,iBAAiB,EAAE,iBAAiB,CAAC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
|
|
|
1
|
+
import type { FastifyRequest } from 'fastify';
|
|
2
|
+
import type { ApplicationConfig } from '../../application/base-application.interface.js';
|
|
3
|
+
import type { DatabaseInstance } from '../../database/index.js';
|
|
4
|
+
import type EventManager from '../../event/manager.js';
|
|
5
|
+
import type { QueueManager } from '../../queue/index.js';
|
|
6
|
+
import type { RedisInstance } from '../../redis/index.js';
|
|
7
|
+
import type { RouteHandler, RouteHandlerContext, RouteSchemaDefinition, WebServerOptions } from '../webserver.interface.js';
|
|
8
|
+
import type WebServerBaseController from './base.js';
|
|
9
|
+
import type { LifecycleManager } from '../../lifecycle/lifecycle-manager.js';
|
|
10
|
+
export interface WebServerBaseControllerConstructorParams<TQueueManager extends QueueManager = QueueManager, TRedisInstance extends RedisInstance = RedisInstance, TEventManager extends EventManager = EventManager, TDatabaseInstance extends DatabaseInstance = DatabaseInstance> {
|
|
11
|
+
applicationConfig: ApplicationConfig;
|
|
12
|
+
webServerOptions: WebServerOptions;
|
|
13
|
+
redisInstance: TRedisInstance;
|
|
14
|
+
queueManager: TQueueManager;
|
|
15
|
+
eventManager: TEventManager;
|
|
16
|
+
databaseInstance: TDatabaseInstance;
|
|
17
|
+
lifecycleManager: LifecycleManager;
|
|
18
|
+
}
|
|
19
|
+
export type WebServerBaseControllerType<TQueueManager extends QueueManager = QueueManager, TRedisInstance extends RedisInstance = RedisInstance, TEventManager extends EventManager = EventManager, TDatabaseInstance extends DatabaseInstance = DatabaseInstance> = new (params: WebServerBaseControllerConstructorParams<TQueueManager, TRedisInstance, TEventManager, TDatabaseInstance>) => WebServerBaseController<TQueueManager, TRedisInstance, TEventManager, TDatabaseInstance>;
|
|
20
|
+
export type ControllerAction<Schema extends RouteSchemaDefinition | undefined = undefined> = RouteHandler<Schema>;
|
|
21
|
+
export type ControllerRequest<Schema extends RouteSchemaDefinition | undefined = undefined> = FastifyRequest<RouteHandlerContext<Schema>>;
|
|
22
|
+
export interface ApiResponse<T = unknown> {
|
|
23
|
+
data?: T;
|
|
24
|
+
meta?: {
|
|
25
|
+
pagination?: {
|
|
26
|
+
page: number;
|
|
27
|
+
limit: number;
|
|
28
|
+
total: number;
|
|
29
|
+
totalPages: number;
|
|
30
|
+
};
|
|
31
|
+
timestamp: string;
|
|
32
|
+
requestId: string;
|
|
33
|
+
};
|
|
34
|
+
error?: ApiError;
|
|
35
|
+
}
|
|
36
|
+
export interface ApiError {
|
|
37
|
+
message: string;
|
|
38
|
+
code?: string;
|
|
39
|
+
type: 'validation' | 'authentication' | 'authorization' | 'not_found' | 'server_error' | 'client_error';
|
|
40
|
+
details?: Record<string, unknown>;
|
|
41
|
+
timestamp: string;
|
|
42
|
+
requestId: string;
|
|
43
|
+
}
|
|
44
|
+
export interface PaginationParams {
|
|
45
|
+
page?: number;
|
|
46
|
+
limit?: number;
|
|
47
|
+
sortBy?: string;
|
|
48
|
+
sortOrder?: 'asc' | 'desc';
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=base.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.interface.d.ts","sourceRoot":"","sources":["../../../src/webserver/controller/base.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iDAAiD,CAAC;AACzF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,YAAY,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EACV,YAAY,EACZ,mBAAmB,EACnB,qBAAqB,EACrB,gBAAgB,EACjB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,uBAAuB,MAAM,WAAW,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EA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KAAK,EAAE,MAAM,CAAC;YACd,UAAU,EAAE,MAAM,CAAC;SACpB,CAAC;QACF,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,KAAK,CAAC,EAAE,QAAQ,CAAC;CAClB;AAED,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,YAAY,GAAG,gBAAgB,GAAG,eAAe,GAAG,WAAW,GAAG,cAAc,GAAG,cAAc,CAAC;IACxG,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;CAC5B"}
|
|
@@ -4,6 +4,7 @@ import { StatusCodes } from "http-status-codes";
|
|
|
4
4
|
import { Logger } from "../../logger/index.js";
|
|
5
5
|
import cluster from "cluster";
|
|
6
6
|
import Jwt from "../../auth/jwt.js";
|
|
7
|
+
import { safeSerializeError } from "../../error/error-reporter.js";
|
|
7
8
|
class BaseController {
|
|
8
9
|
static {
|
|
9
10
|
__name(this, "BaseController");
|
|
@@ -73,7 +74,7 @@ class BaseController {
|
|
|
73
74
|
publicErrorMessage = error.stack ?? error.message;
|
|
74
75
|
errorDetails = { stack: error.stack, name: error.name };
|
|
75
76
|
} else {
|
|
76
|
-
publicErrorMessage =
|
|
77
|
+
publicErrorMessage = safeSerializeError(error);
|
|
77
78
|
}
|
|
78
79
|
} else {
|
|
79
80
|
if (process.env.NODE_ENV === "production") {
|
|
@@ -89,12 +90,11 @@ class BaseController {
|
|
|
89
90
|
publicErrorMessage = error.stack ?? error.message;
|
|
90
91
|
errorDetails = { stack: error.stack, name: error.name };
|
|
91
92
|
} else {
|
|
92
|
-
publicErrorMessage =
|
|
93
|
+
publicErrorMessage = safeSerializeError(error);
|
|
93
94
|
}
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
|
-
Logger.
|
|
97
|
-
console.error(error);
|
|
97
|
+
Logger.error({ error });
|
|
98
98
|
const apiError = {
|
|
99
99
|
message: publicErrorMessage,
|
|
100
100
|
type: errorType ?? this.getErrorType(statusCode),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/webserver/controller/base.ts"],
|
|
4
|
-
"sourcesContent": ["import { StatusCodes } from 'http-status-codes';\nimport type { FastifyReply, FastifyRequest } from 'fastify';\nimport type { DatabaseInstance } from '../../database/index.js';\nimport type { RedisInstance } from '../../redis/index.js';\nimport type { QueueManager } from '../../queue/index.js';\nimport type { ApiError, ApiResponse, WebServerBaseControllerConstructorParams } from './base.interface.js';\nimport { Logger } from '../../logger/index.js';\nimport type { ApplicationConfig } from '../../application/base-application.interface.js';\nimport type EventManager from '../../event/manager.js';\nimport cluster from 'cluster';\nimport type { WebServerOptions } from '../webserver.interface.js';\nimport type { LifecycleManager } from '../../lifecycle/lifecycle-manager.js';\nimport Jwt from '../../auth/jwt.js';\n\nexport interface AuthenticatedUser<TPayload = Record<string, unknown>> {\n userId: number;\n payload: TPayload;\n}\n\nexport default abstract class BaseController<\n TQueueManager extends QueueManager = QueueManager,\n TRedisInstance extends RedisInstance = RedisInstance,\n TEventManager extends EventManager = EventManager,\n TDatabaseInstance extends DatabaseInstance = DatabaseInstance,\n> {\n protected workerId: number | undefined;\n\n protected applicationConfig: ApplicationConfig;\n protected webServerOptions: WebServerOptions;\n\n protected redisInstance: TRedisInstance;\n protected queueManager: TQueueManager;\n protected eventManager: TEventManager;\n protected databaseInstance: TDatabaseInstance;\n protected lifecycleManager: LifecycleManager;\n\n constructor({\n applicationConfig,\n webServerOptions,\n redisInstance,\n queueManager,\n eventManager,\n databaseInstance,\n lifecycleManager,\n }: WebServerBaseControllerConstructorParams<TQueueManager, TRedisInstance, TEventManager, TDatabaseInstance>) {\n this.workerId = cluster.worker?.id;\n\n this.applicationConfig = applicationConfig;\n this.webServerOptions = webServerOptions;\n\n this.redisInstance = redisInstance;\n this.queueManager = queueManager;\n this.eventManager = eventManager;\n this.databaseInstance = databaseInstance;\n this.lifecycleManager = lifecycleManager;\n }\n\n protected sendSuccessResponse<T = unknown>({\n reply,\n data,\n statusCode = StatusCodes.OK,\n meta,\n }: {\n reply: FastifyReply;\n data: T;\n statusCode?: StatusCodes;\n meta?: ApiResponse<T>['meta'];\n }) {\n const response: ApiResponse<T> = {\n data,\n meta: {\n timestamp: new Date().toISOString(),\n requestId: reply.request.id || 'unknown',\n ...meta,\n },\n };\n reply.status(statusCode).send(response);\n }\n\n protected sendNotFoundResponse(reply: FastifyReply, message: string = 'Resource not found') {\n const error: ApiError = {\n message,\n type: 'not_found',\n timestamp: new Date().toISOString(),\n requestId: reply.request.id || 'unknown',\n };\n const response: ApiResponse = { error };\n reply.status(StatusCodes.NOT_FOUND).send(response);\n }\n\n protected sendErrorResponse({\n reply,\n error,\n statusCode = StatusCodes.BAD_REQUEST,\n errorType,\n }: {\n reply: FastifyReply;\n error: unknown;\n statusCode?: StatusCodes;\n errorType?: ApiError['type'];\n }) {\n let publicErrorMessage: string;\n let errorDetails: Record<string, unknown> | undefined = undefined;\n\n if (this.webServerOptions.errors?.verbose === true) {\n if (error instanceof Error) {\n publicErrorMessage = error.stack ?? error.message;\n errorDetails = { stack: error.stack, name: error.name };\n } else {\n publicErrorMessage =
|
|
5
|
-
"mappings": ";;AAAA,SAAS,mBAAmB;AAM5B,SAAS,cAAc;AAGvB,OAAO,aAAa;AAGpB,OAAO,SAAS;
|
|
4
|
+
"sourcesContent": ["import { StatusCodes } from 'http-status-codes';\nimport type { FastifyReply, FastifyRequest } from 'fastify';\nimport type { DatabaseInstance } from '../../database/index.js';\nimport type { RedisInstance } from '../../redis/index.js';\nimport type { QueueManager } from '../../queue/index.js';\nimport type { ApiError, ApiResponse, WebServerBaseControllerConstructorParams } from './base.interface.js';\nimport { Logger } from '../../logger/index.js';\nimport type { ApplicationConfig } from '../../application/base-application.interface.js';\nimport type EventManager from '../../event/manager.js';\nimport cluster from 'cluster';\nimport type { WebServerOptions } from '../webserver.interface.js';\nimport type { LifecycleManager } from '../../lifecycle/lifecycle-manager.js';\nimport Jwt from '../../auth/jwt.js';\nimport { safeSerializeError } from '../../error/error-reporter.js';\n\nexport interface AuthenticatedUser<TPayload = Record<string, unknown>> {\n userId: number;\n payload: TPayload;\n}\n\nexport default abstract class BaseController<\n TQueueManager extends QueueManager = QueueManager,\n TRedisInstance extends RedisInstance = RedisInstance,\n TEventManager extends EventManager = EventManager,\n TDatabaseInstance extends DatabaseInstance = DatabaseInstance,\n> {\n protected workerId: number | undefined;\n\n protected applicationConfig: ApplicationConfig;\n protected webServerOptions: WebServerOptions;\n\n protected redisInstance: TRedisInstance;\n protected queueManager: TQueueManager;\n protected eventManager: TEventManager;\n protected databaseInstance: TDatabaseInstance;\n protected lifecycleManager: LifecycleManager;\n\n constructor({\n applicationConfig,\n webServerOptions,\n redisInstance,\n queueManager,\n eventManager,\n databaseInstance,\n lifecycleManager,\n }: WebServerBaseControllerConstructorParams<TQueueManager, TRedisInstance, TEventManager, TDatabaseInstance>) {\n this.workerId = cluster.worker?.id;\n\n this.applicationConfig = applicationConfig;\n this.webServerOptions = webServerOptions;\n\n this.redisInstance = redisInstance;\n this.queueManager = queueManager;\n this.eventManager = eventManager;\n this.databaseInstance = databaseInstance;\n this.lifecycleManager = lifecycleManager;\n }\n\n protected sendSuccessResponse<T = unknown>({\n reply,\n data,\n statusCode = StatusCodes.OK,\n meta,\n }: {\n reply: FastifyReply;\n data: T;\n statusCode?: StatusCodes;\n meta?: ApiResponse<T>['meta'];\n }) {\n const response: ApiResponse<T> = {\n data,\n meta: {\n timestamp: new Date().toISOString(),\n requestId: reply.request.id || 'unknown',\n ...meta,\n },\n };\n reply.status(statusCode).send(response);\n }\n\n protected sendNotFoundResponse(reply: FastifyReply, message: string = 'Resource not found') {\n const error: ApiError = {\n message,\n type: 'not_found',\n timestamp: new Date().toISOString(),\n requestId: reply.request.id || 'unknown',\n };\n const response: ApiResponse = { error };\n reply.status(StatusCodes.NOT_FOUND).send(response);\n }\n\n protected sendErrorResponse({\n reply,\n error,\n statusCode = StatusCodes.BAD_REQUEST,\n errorType,\n }: {\n reply: FastifyReply;\n error: unknown;\n statusCode?: StatusCodes;\n errorType?: ApiError['type'];\n }) {\n let publicErrorMessage: string;\n let errorDetails: Record<string, unknown> | undefined = undefined;\n\n if (this.webServerOptions.errors?.verbose === true) {\n if (error instanceof Error) {\n publicErrorMessage = error.stack ?? error.message;\n errorDetails = { stack: error.stack, name: error.name };\n } else {\n publicErrorMessage = safeSerializeError(error);\n }\n } else {\n if (process.env.NODE_ENV === 'production') {\n if (error instanceof Error) {\n publicErrorMessage = 'Something went wrong';\n } else if (typeof error === 'string') {\n publicErrorMessage = error;\n } else {\n publicErrorMessage = 'An unknown error occurred';\n }\n } else {\n if (error instanceof Error) {\n publicErrorMessage = error.stack ?? error.message;\n errorDetails = { stack: error.stack, name: error.name };\n } else {\n publicErrorMessage = safeSerializeError(error);\n }\n }\n }\n\n Logger.error({ error });\n\n const apiError: ApiError = {\n message: publicErrorMessage,\n type: errorType ?? this.getErrorType(statusCode),\n timestamp: new Date().toISOString(),\n requestId: reply.request.id || 'unknown',\n ...(errorDetails && { details: errorDetails }),\n };\n\n const response: ApiResponse = { error: apiError };\n reply.status(statusCode).send(response);\n }\n\n private getErrorType(statusCode: StatusCodes): ApiError['type'] {\n switch (statusCode) {\n case StatusCodes.UNAUTHORIZED:\n return 'authentication';\n case StatusCodes.FORBIDDEN:\n return 'authorization';\n case StatusCodes.NOT_FOUND:\n return 'not_found';\n case StatusCodes.BAD_REQUEST:\n case StatusCodes.UNPROCESSABLE_ENTITY:\n return 'validation';\n case StatusCodes.INTERNAL_SERVER_ERROR:\n case StatusCodes.BAD_GATEWAY:\n case StatusCodes.SERVICE_UNAVAILABLE:\n return 'server_error';\n default:\n return 'client_error';\n }\n }\n\n protected async authenticateRequest(request: FastifyRequest, reply: FastifyReply): Promise<AuthenticatedUser | null> {\n // Get JWT secret key from application config\n const jwtSecretKey = this.applicationConfig.auth?.jwtSecretKey;\n\n if (!jwtSecretKey) {\n this.sendErrorResponse({\n reply,\n error: 'Authentication not configured.',\n statusCode: StatusCodes.INTERNAL_SERVER_ERROR,\n errorType: 'server_error',\n });\n return null;\n }\n\n const authHeader = request.headers.authorization;\n\n if (!authHeader) {\n this.sendErrorResponse({\n reply,\n error: 'No token provided.',\n statusCode: StatusCodes.UNAUTHORIZED,\n errorType: 'authentication',\n });\n return null;\n }\n\n if (!authHeader.startsWith('Bearer ')) {\n this.sendErrorResponse({\n reply,\n error: 'Invalid token.',\n statusCode: StatusCodes.UNAUTHORIZED,\n errorType: 'authentication',\n });\n return null;\n }\n\n try {\n const importedJwtSecretKey = await Jwt.importJwtSecretKey({\n jwtSecretKey,\n });\n\n // Remove \"Bearer \" from token\n const jwtAccessToken = authHeader.substring(7);\n\n const { payload } = await Jwt.jwtVerify(jwtAccessToken, importedJwtSecretKey);\n\n if (!payload.sub) {\n this.sendErrorResponse({\n reply,\n error: 'Invalid token payload.',\n statusCode: StatusCodes.UNAUTHORIZED,\n errorType: 'authentication',\n });\n return null;\n }\n\n const userId = parseInt(payload.sub);\n\n return {\n userId,\n payload,\n };\n } catch {\n this.sendErrorResponse({\n reply,\n error: 'Invalid or expired token.',\n statusCode: StatusCodes.UNAUTHORIZED,\n errorType: 'authentication',\n });\n return null;\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;AAAA,SAAS,mBAAmB;AAM5B,SAAS,cAAc;AAGvB,OAAO,aAAa;AAGpB,OAAO,SAAS;AAChB,SAAS,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@ -0,0 +1,94 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import type { EntityManager } from '@mikro-orm/core';
|
|
3
|
+
import type { FastifyReply, FastifyRequest } from 'fastify';
|
|
4
|
+
import BaseController from './base.js';
|
|
5
|
+
import type { DynamicEntity } from '../../database/dynamic-entity.js';
|
|
6
|
+
import type { WebServerBaseControllerConstructorParams } from './base.interface.js';
|
|
7
|
+
export default abstract class EntityController extends BaseController {
|
|
8
|
+
protected abstract entityName: string;
|
|
9
|
+
protected entityManager: EntityManager;
|
|
10
|
+
private static entityCache;
|
|
11
|
+
constructor(props: WebServerBaseControllerConstructorParams);
|
|
12
|
+
protected getEntity: () => Promise<typeof DynamicEntity | undefined>;
|
|
13
|
+
private getEntityProperties;
|
|
14
|
+
options: (request: FastifyRequest, reply: FastifyReply) => Promise<void>;
|
|
15
|
+
metadata: (request: FastifyRequest, reply: FastifyReply) => Promise<void>;
|
|
16
|
+
protected preGetMany(_: {
|
|
17
|
+
entityManager: EntityManager;
|
|
18
|
+
request: FastifyRequest;
|
|
19
|
+
reply: FastifyReply;
|
|
20
|
+
}): Promise<void>;
|
|
21
|
+
protected postGetMany(_: {
|
|
22
|
+
entityManager: EntityManager;
|
|
23
|
+
request: FastifyRequest;
|
|
24
|
+
reply: FastifyReply;
|
|
25
|
+
data: {
|
|
26
|
+
items: any[];
|
|
27
|
+
total: number;
|
|
28
|
+
page: number;
|
|
29
|
+
totalPages: number;
|
|
30
|
+
limit: number;
|
|
31
|
+
};
|
|
32
|
+
}): Promise<void>;
|
|
33
|
+
getMany: (request: FastifyRequest<{
|
|
34
|
+
Querystring: {
|
|
35
|
+
page: string;
|
|
36
|
+
limit: string;
|
|
37
|
+
filters: string;
|
|
38
|
+
sort: string;
|
|
39
|
+
"sort-order": string;
|
|
40
|
+
search: string;
|
|
41
|
+
[key: string]: any;
|
|
42
|
+
};
|
|
43
|
+
}>, reply: FastifyReply) => Promise<void>;
|
|
44
|
+
protected preGetOne(_: {
|
|
45
|
+
entityManager: EntityManager;
|
|
46
|
+
request: FastifyRequest;
|
|
47
|
+
reply: FastifyReply;
|
|
48
|
+
}): Promise<void>;
|
|
49
|
+
protected postGetOne(_: {
|
|
50
|
+
entityManager: EntityManager;
|
|
51
|
+
request: FastifyRequest;
|
|
52
|
+
reply: FastifyReply;
|
|
53
|
+
item: any;
|
|
54
|
+
}): Promise<void>;
|
|
55
|
+
getOne: (request: FastifyRequest<{
|
|
56
|
+
Params: {
|
|
57
|
+
id: number;
|
|
58
|
+
};
|
|
59
|
+
Querystring: {
|
|
60
|
+
populate: string;
|
|
61
|
+
};
|
|
62
|
+
}>, reply: FastifyReply) => Promise<void>;
|
|
63
|
+
protected preCreateOne: ({ request, reply, }: {
|
|
64
|
+
request: FastifyRequest;
|
|
65
|
+
reply: FastifyReply;
|
|
66
|
+
}) => {
|
|
67
|
+
request: FastifyRequest;
|
|
68
|
+
reply: FastifyReply;
|
|
69
|
+
};
|
|
70
|
+
protected postCreateOne(_: {
|
|
71
|
+
entityManager: EntityManager;
|
|
72
|
+
request: FastifyRequest;
|
|
73
|
+
reply: FastifyReply;
|
|
74
|
+
item: any;
|
|
75
|
+
}): Promise<void>;
|
|
76
|
+
createOne: (request: FastifyRequest, reply: FastifyReply) => Promise<void>;
|
|
77
|
+
protected postUpdateOne(_: {
|
|
78
|
+
entityManager: EntityManager;
|
|
79
|
+
request: FastifyRequest;
|
|
80
|
+
reply: FastifyReply;
|
|
81
|
+
item: any;
|
|
82
|
+
}): Promise<void>;
|
|
83
|
+
updateOne: (request: FastifyRequest<{
|
|
84
|
+
Params: {
|
|
85
|
+
id: number;
|
|
86
|
+
};
|
|
87
|
+
}>, reply: FastifyReply) => Promise<void>;
|
|
88
|
+
deleteOne: (request: FastifyRequest<{
|
|
89
|
+
Params: {
|
|
90
|
+
id: number;
|
|
91
|
+
};
|
|
92
|
+
}>, reply: FastifyReply) => Promise<void>;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=entity.d.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