@adaptivestone/framework 5.0.0-beta.5 → 5.0.0-beta.51
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/CHANGELOG.md +1223 -530
- package/LICENCE +1 -1
- package/dist/Cli.d.ts +7 -0
- package/dist/Cli.js +19 -0
- package/dist/Cli.js.map +1 -0
- package/dist/cluster.d.ts +1 -0
- package/dist/cluster.js +18 -0
- package/dist/cluster.js.map +1 -0
- package/dist/codegen/appTypes.d.ts +19 -0
- package/dist/codegen/appTypes.js +49 -0
- package/dist/codegen/appTypes.js.map +1 -0
- package/dist/codegen/collectMetadata.d.ts +45 -0
- package/dist/codegen/collectMetadata.js +63 -0
- package/dist/codegen/collectMetadata.js.map +1 -0
- package/dist/codegen/emit.d.ts +29 -0
- package/dist/codegen/emit.js +339 -0
- package/dist/codegen/emit.js.map +1 -0
- package/dist/codegen/index.d.ts +16 -0
- package/dist/codegen/index.js +18 -0
- package/dist/codegen/index.js.map +1 -0
- package/dist/codegen/routeTypes.d.ts +13 -0
- package/dist/codegen/routeTypes.js +126 -0
- package/dist/codegen/routeTypes.js.map +1 -0
- package/dist/commands/CreateUser.d.ts +32 -0
- package/dist/commands/CreateUser.js +83 -0
- package/dist/commands/CreateUser.js.map +1 -0
- package/dist/commands/DropIndex.d.ts +16 -0
- package/dist/commands/DropIndex.js +30 -0
- package/dist/commands/DropIndex.js.map +1 -0
- package/dist/commands/GenerateRandomBytes.d.ts +7 -0
- package/dist/commands/GenerateRandomBytes.js +18 -0
- package/dist/commands/GenerateRandomBytes.js.map +1 -0
- package/dist/commands/GenerateTypes.d.ts +7 -0
- package/dist/commands/GenerateTypes.js +14 -0
- package/dist/commands/GenerateTypes.js.map +1 -0
- package/dist/commands/SyncIndexes.d.ts +6 -0
- package/dist/commands/SyncIndexes.js +31 -0
- package/dist/commands/SyncIndexes.js.map +1 -0
- package/dist/commands/migration/Create.d.ts +18 -0
- package/dist/commands/migration/Create.js +57 -0
- package/dist/commands/migration/Create.js.map +1 -0
- package/dist/commands/migration/Migrate.d.ts +6 -0
- package/dist/commands/migration/Migrate.js +43 -0
- package/dist/commands/migration/Migrate.js.map +1 -0
- package/dist/config/auth.d.ts +6 -0
- package/dist/config/auth.js +7 -0
- package/dist/config/auth.js.map +1 -0
- package/dist/config/http.d.ts +8 -0
- package/dist/config/http.js +10 -0
- package/dist/config/http.js.map +1 -0
- package/dist/config/i18n.d.ts +13 -0
- package/dist/config/i18n.js +13 -0
- package/dist/config/i18n.js.map +1 -0
- package/dist/config/ipDetector.d.ts +5 -0
- package/dist/config/ipDetector.js +15 -0
- package/dist/config/ipDetector.js.map +1 -0
- package/dist/config/log.d.ts +11 -0
- package/dist/config/log.js +20 -0
- package/dist/config/log.js.map +1 -0
- package/dist/config/mongo.d.ts +4 -0
- package/dist/config/mongo.js +4 -0
- package/dist/config/mongo.js.map +1 -0
- package/dist/config/rateLimiter.d.ts +13 -0
- package/dist/config/rateLimiter.js +17 -0
- package/dist/config/rateLimiter.js.map +1 -0
- package/dist/config/redis.d.ts +5 -0
- package/dist/config/redis.js +5 -0
- package/dist/config/redis.js.map +1 -0
- package/dist/config/validate.d.ts +4 -0
- package/dist/config/validate.js +4 -0
- package/dist/config/validate.js.map +1 -0
- package/dist/controllers/Auth.d.ts +59 -0
- package/dist/controllers/Auth.js +317 -0
- package/dist/controllers/Auth.js.map +1 -0
- package/dist/controllers/Auth.routes.gen.d.ts +57 -0
- package/dist/controllers/Auth.routes.gen.js +10 -0
- package/dist/controllers/Auth.routes.gen.js.map +1 -0
- package/dist/controllers/Home.d.ts +15 -0
- package/dist/controllers/Home.js +22 -0
- package/dist/controllers/Home.js.map +1 -0
- package/dist/controllers/Home.routes.gen.d.ts +14 -0
- package/dist/controllers/Home.routes.gen.js +10 -0
- package/dist/controllers/Home.routes.gen.js.map +1 -0
- package/dist/controllers/index.d.ts +36 -0
- package/dist/controllers/index.js +454 -0
- package/dist/controllers/index.js.map +1 -0
- package/dist/folderConfig.d.ts +34 -0
- package/dist/folderConfig.js +14 -0
- package/dist/folderConfig.js.map +1 -0
- package/dist/helpers/appInstance.d.ts +3 -0
- package/dist/helpers/appInstance.js +8 -0
- package/dist/helpers/appInstance.js.map +1 -0
- package/dist/helpers/crypto.d.ts +3 -0
- package/dist/helpers/crypto.js +17 -0
- package/dist/helpers/crypto.js.map +1 -0
- package/dist/helpers/files.d.ts +16 -0
- package/dist/helpers/files.js +78 -0
- package/dist/helpers/files.js.map +1 -0
- package/dist/helpers/logger.d.ts +4 -0
- package/dist/helpers/logger.js +20 -0
- package/dist/helpers/logger.js.map +1 -0
- package/dist/helpers/redis/clearNamespace.d.ts +2 -0
- package/dist/helpers/redis/clearNamespace.js +14 -0
- package/dist/helpers/redis/clearNamespace.js.map +1 -0
- package/dist/helpers/redis/redisConnection.d.ts +6 -0
- package/dist/helpers/redis/redisConnection.js +48 -0
- package/dist/helpers/redis/redisConnection.js.map +1 -0
- package/dist/helpers/yup.d.ts +22 -0
- package/dist/helpers/yup.js +39 -0
- package/dist/helpers/yup.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/models/KeyValue.d.ts +22 -0
- package/dist/models/KeyValue.js +17 -0
- package/dist/models/KeyValue.js.map +1 -0
- package/dist/models/Lock.d.ts +90 -0
- package/dist/models/Lock.js +97 -0
- package/dist/models/Lock.js.map +1 -0
- package/dist/models/Migration.d.ts +13 -0
- package/dist/models/Migration.js +14 -0
- package/dist/models/Migration.js.map +1 -0
- package/dist/models/Sequence.d.ts +28 -0
- package/dist/models/Sequence.js +19 -0
- package/dist/models/Sequence.js.map +1 -0
- package/dist/models/User.d.ts +729 -0
- package/dist/models/User.js +294 -0
- package/dist/models/User.js.map +1 -0
- package/dist/models/UserOld.d.ts +190 -0
- package/dist/models/UserOld.js +230 -0
- package/dist/models/UserOld.js.map +1 -0
- package/dist/modules/AbstractCommand.d.ts +51 -0
- package/dist/modules/AbstractCommand.js +60 -0
- package/dist/modules/AbstractCommand.js.map +1 -0
- package/dist/modules/AbstractConnector.d.ts +5 -0
- package/dist/modules/AbstractConnector.js +8 -0
- package/dist/modules/AbstractConnector.js.map +1 -0
- package/dist/modules/AbstractController.d.ts +85 -0
- package/dist/modules/AbstractController.js +71 -0
- package/dist/modules/AbstractController.js.map +1 -0
- package/dist/modules/AbstractModel.d.ts +29 -0
- package/dist/modules/AbstractModel.js +42 -0
- package/dist/modules/AbstractModel.js.map +1 -0
- package/dist/modules/Base.d.ts +29 -0
- package/dist/modules/Base.js +58 -0
- package/dist/modules/Base.js.map +1 -0
- package/dist/modules/BaseCli.d.ts +25 -0
- package/dist/modules/BaseCli.js +148 -0
- package/dist/modules/BaseCli.js.map +1 -0
- package/dist/modules/BaseModel.d.ts +57 -0
- package/dist/modules/BaseModel.js +37 -0
- package/dist/modules/BaseModel.js.map +1 -0
- package/dist/server.d.ts +122 -0
- package/dist/server.js +478 -0
- package/dist/server.js.map +1 -0
- package/dist/services/cache/Cache.d.ts +31 -0
- package/dist/services/cache/Cache.js +103 -0
- package/dist/services/cache/Cache.js.map +1 -0
- package/dist/services/http/HttpServer.d.ts +44 -0
- package/dist/services/http/HttpServer.js +81 -0
- package/dist/services/http/HttpServer.js.map +1 -0
- package/dist/services/http/files.d.ts +18 -0
- package/dist/services/http/files.js +19 -0
- package/dist/services/http/files.js.map +1 -0
- package/dist/services/http/middleware/AbstractMiddleware.d.ts +41 -0
- package/dist/services/http/middleware/AbstractMiddleware.js +52 -0
- package/dist/services/http/middleware/AbstractMiddleware.js.map +1 -0
- package/dist/services/http/middleware/Auth.d.ts +9 -0
- package/dist/services/http/middleware/Auth.js +18 -0
- package/dist/services/http/middleware/Auth.js.map +1 -0
- package/dist/services/http/middleware/Cors.d.ts +12 -0
- package/dist/services/http/middleware/Cors.js +36 -0
- package/dist/services/http/middleware/Cors.js.map +1 -0
- package/dist/services/http/middleware/GetUserByToken.d.ts +36 -0
- package/dist/services/http/middleware/GetUserByToken.js +56 -0
- package/dist/services/http/middleware/GetUserByToken.js.map +1 -0
- package/dist/services/http/middleware/I18n.d.ts +23 -0
- package/dist/services/http/middleware/I18n.js +61 -0
- package/dist/services/http/middleware/I18n.js.map +1 -0
- package/dist/services/http/middleware/IpDetector.d.ts +14 -0
- package/dist/services/http/middleware/IpDetector.js +55 -0
- package/dist/services/http/middleware/IpDetector.js.map +1 -0
- package/dist/services/http/middleware/Pagination.d.ts +26 -0
- package/dist/services/http/middleware/Pagination.js +66 -0
- package/dist/services/http/middleware/Pagination.js.map +1 -0
- package/dist/services/http/middleware/PrepareAppInfo.d.ts +8 -0
- package/dist/services/http/middleware/PrepareAppInfo.js +17 -0
- package/dist/services/http/middleware/PrepareAppInfo.js.map +1 -0
- package/dist/services/http/middleware/RateLimiter.d.ts +26 -0
- package/dist/services/http/middleware/RateLimiter.js +102 -0
- package/dist/services/http/middleware/RateLimiter.js.map +1 -0
- package/dist/services/http/middleware/RequestLogger.d.ts +8 -0
- package/dist/services/http/middleware/RequestLogger.js +18 -0
- package/dist/services/http/middleware/RequestLogger.js.map +1 -0
- package/dist/services/http/middleware/RequestParser.d.ts +8 -0
- package/dist/services/http/middleware/RequestParser.js +35 -0
- package/dist/services/http/middleware/RequestParser.js.map +1 -0
- package/dist/services/http/middleware/Role.d.ts +12 -0
- package/dist/services/http/middleware/Role.js +24 -0
- package/dist/services/http/middleware/Role.js.map +1 -0
- package/dist/services/http/routing/ExpressAdapter.d.ts +12 -0
- package/dist/services/http/routing/ExpressAdapter.js +93 -0
- package/dist/services/http/routing/ExpressAdapter.js.map +1 -0
- package/dist/services/http/routing/RouteNode.d.ts +102 -0
- package/dist/services/http/routing/RouteNode.js +21 -0
- package/dist/services/http/routing/RouteNode.js.map +1 -0
- package/dist/services/http/routing/RouteRegistry.d.ts +37 -0
- package/dist/services/http/routing/RouteRegistry.js +201 -0
- package/dist/services/http/routing/RouteRegistry.js.map +1 -0
- package/dist/services/http/routing/formatTree.d.ts +23 -0
- package/dist/services/http/routing/formatTree.js +158 -0
- package/dist/services/http/routing/formatTree.js.map +1 -0
- package/dist/services/http/routing/match.d.ts +30 -0
- package/dist/services/http/routing/match.js +136 -0
- package/dist/services/http/routing/match.js.map +1 -0
- package/dist/services/http/routing/middlewareNormalization.d.ts +16 -0
- package/dist/services/http/routing/middlewareNormalization.js +28 -0
- package/dist/services/http/routing/middlewareNormalization.js.map +1 -0
- package/dist/services/http/types.d.ts +74 -0
- package/dist/services/http/types.js +8 -0
- package/dist/services/http/types.js.map +1 -0
- package/dist/services/i18n/I18n.d.ts +15 -0
- package/dist/services/i18n/I18n.js +58 -0
- package/dist/services/i18n/I18n.js.map +1 -0
- package/dist/services/logging/SentryTransport.d.ts +13 -0
- package/dist/services/logging/SentryTransport.js +121 -0
- package/dist/services/logging/SentryTransport.js.map +1 -0
- package/dist/services/validate/ValidateService.d.ts +54 -0
- package/dist/services/validate/ValidateService.js +122 -0
- package/dist/services/validate/ValidateService.js.map +1 -0
- package/dist/services/validate/ValidationError.d.ts +35 -0
- package/dist/services/validate/ValidationError.js +77 -0
- package/dist/services/validate/ValidationError.js.map +1 -0
- package/dist/services/validate/contentType.d.ts +18 -0
- package/dist/services/validate/contentType.js +30 -0
- package/dist/services/validate/contentType.js.map +1 -0
- package/dist/services/validate/defineSchema.d.ts +23 -0
- package/dist/services/validate/defineSchema.js +25 -0
- package/dist/services/validate/defineSchema.js.map +1 -0
- package/dist/services/validate/drivers/StandardSchemaDriver.d.ts +15 -0
- package/dist/services/validate/drivers/StandardSchemaDriver.js +34 -0
- package/dist/services/validate/drivers/StandardSchemaDriver.js.map +1 -0
- package/dist/services/validate/drivers/YupDriver.d.ts +21 -0
- package/dist/services/validate/drivers/YupDriver.js +66 -0
- package/dist/services/validate/drivers/YupDriver.js.map +1 -0
- package/dist/services/validate/types.d.ts +104 -0
- package/dist/services/validate/types.js +11 -0
- package/dist/services/validate/types.js.map +1 -0
- package/dist/tests/frameworkVitestSetup.d.ts +1 -0
- package/dist/tests/frameworkVitestSetup.js +9 -0
- package/dist/tests/frameworkVitestSetup.js.map +1 -0
- package/dist/tests/globalSetupVitest.d.ts +3 -0
- package/dist/tests/globalSetupVitest.js +29 -0
- package/dist/tests/globalSetupVitest.js.map +1 -0
- package/dist/tests/setupVitest.d.ts +1 -0
- package/dist/tests/setupVitest.js +91 -0
- package/dist/tests/setupVitest.js.map +1 -0
- package/dist/tests/testHelpers.d.ts +361 -0
- package/dist/tests/testHelpers.js +48 -0
- package/dist/tests/testHelpers.js.map +1 -0
- package/dist/types.d.ts +4 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/package.json +67 -43
- package/Cli.js +0 -22
- package/cluster.js +0 -25
- package/commands/CreateUser.js +0 -75
- package/commands/Documentation.js +0 -17
- package/commands/DropIndex.js +0 -29
- package/commands/GenerateRandomBytes.js +0 -21
- package/commands/GetOpenApiJson.js +0 -324
- package/commands/SyncIndexes.js +0 -39
- package/commands/migration/Create.js +0 -61
- package/commands/migration/Migrate.js +0 -55
- package/config/auth.js +0 -9
- package/config/http.js +0 -9
- package/config/i18n.js +0 -12
- package/config/ipDetector.js +0 -14
- package/config/log.js +0 -22
- package/config/mail.js +0 -29
- package/config/mongo.js +0 -3
- package/config/rateLimiter.js +0 -16
- package/config/redis.js +0 -4
- package/config/validate.js +0 -3
- package/controllers/Auth.js +0 -204
- package/controllers/Home.js +0 -28
- package/controllers/index.js +0 -60
- package/eslint.config.js +0 -44
- package/folderConfig.js +0 -14
- package/helpers/files.js +0 -76
- package/helpers/logger.js +0 -16
- package/helpers/redis/clearNamespace.js +0 -14
- package/helpers/yup.js +0 -21
- package/index.js +0 -8
- package/jsconfig.json +0 -9
- package/locales/en/translation.json +0 -27
- package/locales/ru/translation.json +0 -27
- package/migrations/.gitkeep +0 -0
- package/models/Migration.js +0 -15
- package/models/Sequence.js +0 -22
- package/models/User.js +0 -261
- package/modules/AbstractCommand.js +0 -43
- package/modules/AbstractConnector.js +0 -9
- package/modules/AbstractController.js +0 -406
- package/modules/AbstractModel.d.ts +0 -48
- package/modules/AbstractModel.js +0 -92
- package/modules/Base.d.ts +0 -37
- package/modules/Base.js +0 -63
- package/modules/BaseCli.js +0 -94
- package/server.d.ts +0 -98
- package/server.js +0 -437
- package/services/cache/Cache.d.ts +0 -35
- package/services/cache/Cache.js +0 -124
- package/services/documentation/DocumentationGenerator.js +0 -169
- package/services/http/HttpServer.js +0 -95
- package/services/http/middleware/AbstractMiddleware.js +0 -51
- package/services/http/middleware/Auth.js +0 -20
- package/services/http/middleware/Cors.js +0 -46
- package/services/http/middleware/GetUserByToken.js +0 -47
- package/services/http/middleware/I18n.js +0 -117
- package/services/http/middleware/IpDetector.js +0 -59
- package/services/http/middleware/Pagination.js +0 -57
- package/services/http/middleware/PrepareAppInfo.js +0 -18
- package/services/http/middleware/RateLimiter.js +0 -134
- package/services/http/middleware/RequestLogger.js +0 -22
- package/services/http/middleware/RequestParser.js +0 -40
- package/services/http/middleware/Role.js +0 -29
- package/services/messaging/email/index.js +0 -217
- package/services/messaging/email/resources/.gitkeep +0 -1
- package/services/messaging/email/templates/emptyTemplate/html.pug +0 -9
- package/services/messaging/email/templates/emptyTemplate/subject.pug +0 -1
- package/services/messaging/email/templates/emptyTemplate/text.pug +0 -1
- package/services/messaging/email/templates/recovery/html.pug +0 -8
- package/services/messaging/email/templates/recovery/subject.pug +0 -2
- package/services/messaging/email/templates/recovery/text.pug +0 -3
- package/services/messaging/email/templates/verification/html.pug +0 -10
- package/services/messaging/email/templates/verification/subject.pug +0 -1
- package/services/messaging/email/templates/verification/text.pug +0 -1
- package/services/messaging/index.js +0 -3
- package/services/validate/ValidateService.js +0 -157
- package/services/validate/drivers/AbstractValidator.js +0 -37
- package/services/validate/drivers/CustomValidator.js +0 -51
- package/services/validate/drivers/YupValidator.js +0 -103
- package/tests/globalSetupVitest.js +0 -35
- package/tests/setup.js +0 -116
- package/tests/setupVitest.js +0 -107
- package/types/Expand.d.ts +0 -11
- package/types/TFoldersConfig.d.ts +0 -17
- package/views/404.pug +0 -3
- package/views/home.pug +0 -3
- package/views/layouts/base.pug +0 -39
- package/vitest.config.js +0 -16
- /package/{commands → dist/migrations}/.gitkeep +0 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AUTOGENERATED — do not edit by hand.
|
|
3
|
+
*
|
|
4
|
+
* Regenerate with: `npm run gen`
|
|
5
|
+
*
|
|
6
|
+
* Source of truth: `Auth.ts`'s `routes` getter and
|
|
7
|
+
* `static get middleware()` Map.
|
|
8
|
+
*/
|
|
9
|
+
import type GetUserByToken from '../services/http/middleware/GetUserByToken.ts';
|
|
10
|
+
import type RateLimiter from '../services/http/middleware/RateLimiter.ts';
|
|
11
|
+
import type { BaseRequestContext, UnionAppInfoProvides } from '../services/http/types.ts';
|
|
12
|
+
import type { StandardSchemaV1 } from '../services/validate/types.ts';
|
|
13
|
+
import type Auth from './Auth.ts';
|
|
14
|
+
/**
|
|
15
|
+
* Type-level navigation into the controller's `routes` getter. Schema
|
|
16
|
+
* references for inline schemas resolve through this alias.
|
|
17
|
+
*/
|
|
18
|
+
type AuthRoutes = InstanceType<typeof Auth>['routes'];
|
|
19
|
+
/** Request type for `POST /login` (handler: `postLogin`). */
|
|
20
|
+
export type PostLoginRequest = BaseRequestContext & {
|
|
21
|
+
appInfo: UnionAppInfoProvides<readonly [typeof GetUserByToken, typeof RateLimiter]> & {
|
|
22
|
+
request: StandardSchemaV1.InferOutput<AuthRoutes['post']['/login']['request']>;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
/** Request type for `POST /register` (handler: `postRegister`). */
|
|
26
|
+
export type PostRegisterRequest = BaseRequestContext & {
|
|
27
|
+
appInfo: UnionAppInfoProvides<readonly [typeof GetUserByToken, typeof RateLimiter]> & {
|
|
28
|
+
request: StandardSchemaV1.InferOutput<AuthRoutes['post']['/register']['request']>;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
/** Request type for `POST /logout` (handler: `postLogout`). */
|
|
32
|
+
export type PostLogoutRequest = BaseRequestContext & {
|
|
33
|
+
appInfo: UnionAppInfoProvides<readonly [typeof GetUserByToken, typeof RateLimiter]>;
|
|
34
|
+
};
|
|
35
|
+
/** Request type for `POST /verify` (handler: `verifyUser`). */
|
|
36
|
+
export type VerifyUserRequest = BaseRequestContext & {
|
|
37
|
+
appInfo: UnionAppInfoProvides<readonly [typeof GetUserByToken, typeof RateLimiter]>;
|
|
38
|
+
};
|
|
39
|
+
/** Request type for `POST /send-recovery-email` (handler: `sendPasswordRecoveryEmail`). */
|
|
40
|
+
export type SendPasswordRecoveryEmailRequest = BaseRequestContext & {
|
|
41
|
+
appInfo: UnionAppInfoProvides<readonly [typeof GetUserByToken, typeof RateLimiter]> & {
|
|
42
|
+
request: StandardSchemaV1.InferOutput<AuthRoutes['post']['/send-recovery-email']['request']>;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
/** Request type for `POST /recover-password` (handler: `recoverPassword`). */
|
|
46
|
+
export type RecoverPasswordRequest = BaseRequestContext & {
|
|
47
|
+
appInfo: UnionAppInfoProvides<readonly [typeof GetUserByToken, typeof RateLimiter]> & {
|
|
48
|
+
request: StandardSchemaV1.InferOutput<AuthRoutes['post']['/recover-password']['request']>;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
/** Request type for `POST /send-verification` (handler: `sendVerification`). */
|
|
52
|
+
export type SendVerificationRequest = BaseRequestContext & {
|
|
53
|
+
appInfo: UnionAppInfoProvides<readonly [typeof GetUserByToken, typeof RateLimiter]> & {
|
|
54
|
+
request: StandardSchemaV1.InferOutput<AuthRoutes['post']['/send-verification']['request']>;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Auth.routes.gen.js","sourceRoot":"","sources":["../../src/controllers/Auth.routes.gen.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Response } from 'express';
|
|
2
|
+
import AbstractController from '../modules/AbstractController.ts';
|
|
3
|
+
import type { FrameworkRequest } from '../services/http/HttpServer.ts';
|
|
4
|
+
import GetUserByToken from '../services/http/middleware/GetUserByToken.ts';
|
|
5
|
+
declare class Home extends AbstractController {
|
|
6
|
+
get routes(): {
|
|
7
|
+
get: {
|
|
8
|
+
'/': (_req: FrameworkRequest, res: Response) => Promise<Response<any, Record<string, any>>>;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
home(_req: FrameworkRequest, res: Response): Promise<Response<any, Record<string, any>>>;
|
|
12
|
+
getHttpPath(): string;
|
|
13
|
+
static get middleware(): Map<string, (typeof GetUserByToken)[]>;
|
|
14
|
+
}
|
|
15
|
+
export default Home;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import AbstractController from "../modules/AbstractController.js";
|
|
2
|
+
import GetUserByToken from "../services/http/middleware/GetUserByToken.js";
|
|
3
|
+
class Home extends AbstractController {
|
|
4
|
+
get routes() {
|
|
5
|
+
return {
|
|
6
|
+
get: {
|
|
7
|
+
'/': this.home,
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
async home(_req, res) {
|
|
12
|
+
return res.json({ message: 'Home' });
|
|
13
|
+
}
|
|
14
|
+
getHttpPath() {
|
|
15
|
+
return '/';
|
|
16
|
+
}
|
|
17
|
+
static get middleware() {
|
|
18
|
+
return new Map([['/{*splat}', [GetUserByToken]]]);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export default Home;
|
|
22
|
+
//# sourceMappingURL=Home.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Home.js","sourceRoot":"","sources":["../../src/controllers/Home.ts"],"names":[],"mappings":"AACA,OAAO,kBAAkB,MAAM,kCAAkC,CAAC;AAElE,OAAO,cAAc,MAAM,+CAA+C,CAAC;AAE3E,MAAM,IAAK,SAAQ,kBAAkB;IACnC,IAAI,MAAM;QACR,OAAO;YACL,GAAG,EAAE;gBACH,GAAG,EAAE,IAAI,CAAC,IAAI;aACf;SACF,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,IAAsB,EAAE,GAAa;QAC9C,OAAO,GAAG,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;IACvC,CAAC;IAED,WAAW;QACT,OAAO,GAAG,CAAC;IACb,CAAC;IAED,MAAM,KAAK,UAAU;QACnB,OAAO,IAAI,GAAG,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;IACpD,CAAC;CACF;AAED,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AUTOGENERATED — do not edit by hand.
|
|
3
|
+
*
|
|
4
|
+
* Regenerate with: `npm run gen`
|
|
5
|
+
*
|
|
6
|
+
* Source of truth: `Home.ts`'s `routes` getter and
|
|
7
|
+
* `static get middleware()` Map.
|
|
8
|
+
*/
|
|
9
|
+
import type GetUserByToken from '../services/http/middleware/GetUserByToken.ts';
|
|
10
|
+
import type { BaseRequestContext, UnionAppInfoProvides } from '../services/http/types.ts';
|
|
11
|
+
/** Request type for `GET /` (handler: `home`). */
|
|
12
|
+
export type HomeRequest = BaseRequestContext & {
|
|
13
|
+
appInfo: UnionAppInfoProvides<readonly [typeof GetUserByToken]>;
|
|
14
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Home.routes.gen.js","sourceRoot":"","sources":["../../src/controllers/Home.routes.gen.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type AbstractController from '../modules/AbstractController.ts';
|
|
2
|
+
import Base from '../modules/Base.ts';
|
|
3
|
+
import type { IApp } from '../server.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Class does autoloading a http controllers
|
|
6
|
+
*/
|
|
7
|
+
declare class ControllerManager extends Base {
|
|
8
|
+
#private;
|
|
9
|
+
controllers: Record<string, AbstractController>;
|
|
10
|
+
constructor(app: IApp);
|
|
11
|
+
/**
|
|
12
|
+
* Register a controller explicitly. Returns the constructed instance.
|
|
13
|
+
* Builds a `RouteNode` subtree from the controller's `routes` getter and
|
|
14
|
+
* `static middleware` Map, wraps handlers with validation, and registers
|
|
15
|
+
* with the `RouteRegistry`. For late registration (after `startServer`
|
|
16
|
+
* finishes) use `Server.startServer`'s `callbackBefore404` hook.
|
|
17
|
+
*/
|
|
18
|
+
registerController<T extends typeof AbstractController>(ControllerClass: T, prefix?: string, options?: {
|
|
19
|
+
skipWrap?: boolean;
|
|
20
|
+
}): InstanceType<T>;
|
|
21
|
+
/**
|
|
22
|
+
* Auto-load controllers from the framework's internal folder and the user's
|
|
23
|
+
* external folder, then register each one. User overrides win when filenames
|
|
24
|
+
* collide (handled by `getFilesPathWithInheritance`).
|
|
25
|
+
*
|
|
26
|
+
* `options.skipWrap` (codegen-only): build the registry tree without
|
|
27
|
+
* wrapping handlers with validation. Skips middleware instantiation —
|
|
28
|
+
* which avoids side effects (Redis clients, timers) in introspection
|
|
29
|
+
* commands like `generatetypes`.
|
|
30
|
+
*/
|
|
31
|
+
initControllers(options?: {
|
|
32
|
+
skipWrap?: boolean;
|
|
33
|
+
}): Promise<void>;
|
|
34
|
+
static get loggerGroup(): string;
|
|
35
|
+
}
|
|
36
|
+
export default ControllerManager;
|
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import * as url from 'node:url';
|
|
11
|
+
import Base from "../modules/Base.js";
|
|
12
|
+
import { normalizeMiddlewares, } from "../services/http/routing/middlewareNormalization.js";
|
|
13
|
+
import { HTTP_METHODS } from "../services/http/routing/RouteNode.js";
|
|
14
|
+
import { createNode } from "../services/http/routing/RouteRegistry.js";
|
|
15
|
+
import { isContentTypeRequestMap, normalizeContentType, } from "../services/validate/contentType.js";
|
|
16
|
+
import ValidateService from "../services/validate/ValidateService.js";
|
|
17
|
+
/** HTTP methods valid in a controller's `routes` getter (no `'ALL'`). */
|
|
18
|
+
const ROUTE_HTTP_METHODS = new Set(HTTP_METHODS);
|
|
19
|
+
/** HTTP methods plus the `'ALL'` pseudo-verb for middleware-Map scope keys. */
|
|
20
|
+
const MAP_KEY_METHODS = new Set([...HTTP_METHODS, 'ALL']);
|
|
21
|
+
/**
|
|
22
|
+
* Class does autoloading a http controllers
|
|
23
|
+
*/
|
|
24
|
+
class ControllerManager extends Base {
|
|
25
|
+
controllers;
|
|
26
|
+
constructor(app) {
|
|
27
|
+
super(app);
|
|
28
|
+
this.controllers = {};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Register a controller explicitly. Returns the constructed instance.
|
|
32
|
+
* Builds a `RouteNode` subtree from the controller's `routes` getter and
|
|
33
|
+
* `static middleware` Map, wraps handlers with validation, and registers
|
|
34
|
+
* with the `RouteRegistry`. For late registration (after `startServer`
|
|
35
|
+
* finishes) use `Server.startServer`'s `callbackBefore404` hook.
|
|
36
|
+
*/
|
|
37
|
+
registerController(ControllerClass, prefix = '', options = {}) {
|
|
38
|
+
const name = ControllerClass.name.toLowerCase();
|
|
39
|
+
const key = prefix ? `${prefix}/${name}` : name;
|
|
40
|
+
const instance = new ControllerClass(this.app, prefix);
|
|
41
|
+
this.controllers[key] = instance;
|
|
42
|
+
const registry = this.app.httpServer?.routeRegistry;
|
|
43
|
+
if (!registry) {
|
|
44
|
+
this.logger?.warn(`RouteRegistry not available; controller ${key} not registered with the new routing.`);
|
|
45
|
+
return instance;
|
|
46
|
+
}
|
|
47
|
+
const source = {
|
|
48
|
+
kind: 'package',
|
|
49
|
+
spec: `<${ControllerClass.name}>`,
|
|
50
|
+
};
|
|
51
|
+
const subtree = this.#buildSubtree(instance, source);
|
|
52
|
+
// `skipWrap` is the codegen escape hatch — we only need the tree
|
|
53
|
+
// structure to emit types, not the runtime validation wrappers.
|
|
54
|
+
// Wrapping instantiates every middleware in every handler's chain
|
|
55
|
+
// to read schemas, which side-effects (Redis clients, timers, etc.)
|
|
56
|
+
// and keeps the event loop open for codegen-only runs.
|
|
57
|
+
if (!options.skipWrap) {
|
|
58
|
+
this.#wrapHandlersInSubtree(subtree, []);
|
|
59
|
+
}
|
|
60
|
+
registry.registerSubtree(instance.getHttpPath(), subtree);
|
|
61
|
+
return instance;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Auto-load controllers from the framework's internal folder and the user's
|
|
65
|
+
* external folder, then register each one. User overrides win when filenames
|
|
66
|
+
* collide (handled by `getFilesPathWithInheritance`).
|
|
67
|
+
*
|
|
68
|
+
* `options.skipWrap` (codegen-only): build the registry tree without
|
|
69
|
+
* wrapping handlers with validation. Skips middleware instantiation —
|
|
70
|
+
* which avoids side effects (Redis clients, timers) in introspection
|
|
71
|
+
* commands like `generatetypes`.
|
|
72
|
+
*/
|
|
73
|
+
async initControllers(options = {}) {
|
|
74
|
+
const dirname = url.fileURLToPath(new URL('.', import.meta.url));
|
|
75
|
+
const controllersToLoad = await this.getFilesPathWithInheritance(dirname, this.app.foldersConfig.controllers);
|
|
76
|
+
controllersToLoad.sort((a, b) => {
|
|
77
|
+
if (a.file.toLowerCase().endsWith('index.js') ||
|
|
78
|
+
a.file.toLowerCase().endsWith('index.ts')) {
|
|
79
|
+
if (b.file.toLowerCase().endsWith('index.js') ||
|
|
80
|
+
b.file.toLowerCase().endsWith('index.ts')) {
|
|
81
|
+
return 0;
|
|
82
|
+
}
|
|
83
|
+
return -1;
|
|
84
|
+
}
|
|
85
|
+
return 0;
|
|
86
|
+
});
|
|
87
|
+
const controllers = [];
|
|
88
|
+
for (const controller of controllersToLoad) {
|
|
89
|
+
controllers.push(import(__rewriteRelativeImportExtension(controller.path)).then(({ default: ControllerModule }) => {
|
|
90
|
+
let prefix = path.dirname(controller.file);
|
|
91
|
+
if (prefix === '.') {
|
|
92
|
+
prefix = '';
|
|
93
|
+
}
|
|
94
|
+
this.registerController(ControllerModule, prefix, options);
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
await Promise.all(controllers);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Build a `RouteNode` subtree for one controller — walks `routes` getter,
|
|
101
|
+
* places handlers in the tree, then attaches the `static middleware` Map
|
|
102
|
+
* entries to the right tree positions. Path syntax conversion: user-facing
|
|
103
|
+
* `{*splat}` → internal `*splat`. Map scope keys: `'METHOD/path'`,
|
|
104
|
+
* `'ALL/path'`, `'/path'`.
|
|
105
|
+
*/
|
|
106
|
+
#buildSubtree(controller, source) {
|
|
107
|
+
const subtree = createNode('');
|
|
108
|
+
const ctrlName = controller.constructor.name;
|
|
109
|
+
// 1. Routes first — handlers placed in the tree before middleware
|
|
110
|
+
// attachments look for them.
|
|
111
|
+
const routes = controller.routes;
|
|
112
|
+
if (routes && typeof routes === 'object') {
|
|
113
|
+
for (const [verb, routeMap] of Object.entries(routes)) {
|
|
114
|
+
if (!routeMap || typeof routeMap !== 'object') {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const upperVerb = verb.toUpperCase();
|
|
118
|
+
if (!ROUTE_HTTP_METHODS.has(upperVerb)) {
|
|
119
|
+
this.logger?.warn(`Controller ${ctrlName}: unknown verb '${verb}' in routes getter (expected one of: ${[...ROUTE_HTTP_METHODS].join(', ').toLowerCase()}). Routes under this verb will never match.`);
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
for (const [pathKey, routeSpec] of Object.entries(routeMap)) {
|
|
123
|
+
const entry = buildHandlerEntry(routeSpec, controller, source);
|
|
124
|
+
if (!entry) {
|
|
125
|
+
// Object spec but no callable `handler` field — a common
|
|
126
|
+
// misconfiguration (e.g., `{ request: schema }` without a
|
|
127
|
+
// handler). Warn and skip; the old framework also rejected
|
|
128
|
+
// these with a 500 at request time.
|
|
129
|
+
if (routeSpec !== null &&
|
|
130
|
+
typeof routeSpec === 'object' &&
|
|
131
|
+
typeof routeSpec.handler !== 'function') {
|
|
132
|
+
this.logger?.warn(`Controller ${ctrlName}: route ${upperVerb} ${pathKey} has no \`handler\` function. Skipping.`);
|
|
133
|
+
}
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
attachHandler(subtree, upperVerb, convertPathSyntax(pathKey), entry);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// 2. Middleware Map — attach to nodes / per-handler.
|
|
141
|
+
// `static get middleware()` lives on the class; instance.constructor
|
|
142
|
+
// types as `Function`, so cast to read the static member.
|
|
143
|
+
const ControllerClass = controller.constructor;
|
|
144
|
+
const mwMap = ControllerClass.middleware;
|
|
145
|
+
if (mwMap instanceof Map) {
|
|
146
|
+
for (const [scopeKey, mwList] of mwMap) {
|
|
147
|
+
if (typeof scopeKey !== 'string') {
|
|
148
|
+
this.logger?.warn(`Controller ${ctrlName}: middleware Map key is not a string (got ${typeof scopeKey}). Skipping.`);
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
if (!Array.isArray(mwList) || mwList.length === 0) {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
const parsed = parseScopeKey(scopeKey);
|
|
155
|
+
if (parsed.unknownMethod) {
|
|
156
|
+
this.logger?.warn(`Controller ${ctrlName}: middleware Map key '${scopeKey}' has unknown method prefix '${parsed.unknownMethod}'. Treating the whole key as a path. Expected method prefix is one of: ${[...MAP_KEY_METHODS].join(', ')}.`);
|
|
157
|
+
}
|
|
158
|
+
const entries = normalizeMiddlewares(mwList, source);
|
|
159
|
+
attachMiddlewares(subtree, parsed.method, convertPathSyntax(parsed.path), entries);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return subtree;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Walk the subtree depth-first, accumulating middleware as we descend.
|
|
166
|
+
* For each handler, wrap with validation that merges route schemas +
|
|
167
|
+
* schemas declared by middlewares in the chain (`relatedRequestParameters`
|
|
168
|
+
* / `relatedQueryParameters`).
|
|
169
|
+
*/
|
|
170
|
+
#wrapHandlersInSubtree(node, accumulated) {
|
|
171
|
+
const chain = [...accumulated, ...node.middlewares];
|
|
172
|
+
if (node.methods) {
|
|
173
|
+
for (const method of Object.keys(node.methods)) {
|
|
174
|
+
const entry = node.methods[method];
|
|
175
|
+
if (entry) {
|
|
176
|
+
const fullChain = [...chain, ...(entry.middlewares ?? [])];
|
|
177
|
+
this.#wrapHandlerEntry(entry, fullChain);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
for (const child of node.children.values()) {
|
|
182
|
+
this.#wrapHandlersInSubtree(child, chain);
|
|
183
|
+
}
|
|
184
|
+
if (node.paramChild) {
|
|
185
|
+
this.#wrapHandlersInSubtree(node.paramChild, chain);
|
|
186
|
+
}
|
|
187
|
+
if (node.splatChild) {
|
|
188
|
+
this.#wrapHandlersInSubtree(node.splatChild, chain);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
#wrapHandlerEntry(entry, chain) {
|
|
192
|
+
const original = entry.handler;
|
|
193
|
+
const app = this.app;
|
|
194
|
+
const logger = this.logger;
|
|
195
|
+
// Collect middleware-declared schemas at translation time.
|
|
196
|
+
const middlewareRequestSchemas = [];
|
|
197
|
+
const middlewareQuerySchemas = [];
|
|
198
|
+
for (const mw of chain) {
|
|
199
|
+
const inst = new mw.Class(app, mw.params ?? {});
|
|
200
|
+
const r = inst.relatedReqParameters?.request;
|
|
201
|
+
const q = inst.relatedReqParameters?.query;
|
|
202
|
+
if (r) {
|
|
203
|
+
middlewareRequestSchemas.push(r);
|
|
204
|
+
}
|
|
205
|
+
if (q) {
|
|
206
|
+
middlewareQuerySchemas.push(q);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
// Route-entry request schema: a single Standard Schema, or a content-type
|
|
210
|
+
// map resolved per-request by `Content-Type`. The map is resolved inside
|
|
211
|
+
// the request handler (it depends on the incoming header); middleware
|
|
212
|
+
// schemas are content-type-agnostic and resolved once here.
|
|
213
|
+
//
|
|
214
|
+
// The lookup table is a null-prototype object with lower-cased keys: this
|
|
215
|
+
// makes matching case-insensitive AND prevents a header like `__proto__`
|
|
216
|
+
// or `constructor` from resolving to an inherited `Object.prototype`
|
|
217
|
+
// member (which would otherwise be truthy and bypass the 415).
|
|
218
|
+
const entryRequest = entry.request;
|
|
219
|
+
let entryRequestMapLookup = null;
|
|
220
|
+
let entryRequestMapKeys = [];
|
|
221
|
+
if (isContentTypeRequestMap(entryRequest)) {
|
|
222
|
+
entryRequestMapLookup = Object.create(null);
|
|
223
|
+
entryRequestMapKeys = Object.keys(entryRequest);
|
|
224
|
+
for (const key of entryRequestMapKeys) {
|
|
225
|
+
entryRequestMapLookup[key.toLowerCase()] = entryRequest[key];
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
const querySchemas = [];
|
|
229
|
+
if (entry.query) {
|
|
230
|
+
querySchemas.push(entry.query);
|
|
231
|
+
}
|
|
232
|
+
querySchemas.push(...middlewareQuerySchemas);
|
|
233
|
+
const wrapped = async (req, res, next) => {
|
|
234
|
+
try {
|
|
235
|
+
const requestSchemas = [];
|
|
236
|
+
let resolvedContentType = null;
|
|
237
|
+
if (entryRequestMapLookup) {
|
|
238
|
+
const contentType = normalizeContentType(req.headers['content-type']);
|
|
239
|
+
const matched = contentType && Object.hasOwn(entryRequestMapLookup, contentType)
|
|
240
|
+
? entryRequestMapLookup[contentType]
|
|
241
|
+
: undefined;
|
|
242
|
+
if (!matched) {
|
|
243
|
+
return res.status(415).json({
|
|
244
|
+
message: `Unsupported Content-Type. Expected one of: ${entryRequestMapKeys.join(', ')}`,
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
requestSchemas.push(matched);
|
|
248
|
+
resolvedContentType = contentType;
|
|
249
|
+
}
|
|
250
|
+
else if (entryRequest) {
|
|
251
|
+
requestSchemas.push(entryRequest);
|
|
252
|
+
}
|
|
253
|
+
requestSchemas.push(...middlewareRequestSchemas);
|
|
254
|
+
if (requestSchemas.length > 0) {
|
|
255
|
+
const parts = await Promise.all(requestSchemas.map((s) => new ValidateService(app, s).validate(req.body, req.appInfo.i18n)));
|
|
256
|
+
req.appInfo.request = Object.assign({}, ...parts);
|
|
257
|
+
if (resolvedContentType) {
|
|
258
|
+
req.appInfo.request.contentType =
|
|
259
|
+
resolvedContentType;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
if (querySchemas.length > 0) {
|
|
263
|
+
const parts = await Promise.all(querySchemas.map((s) => new ValidateService(app, s).validate(req.query, req.appInfo.i18n)));
|
|
264
|
+
req.appInfo.query = Object.assign({}, ...parts);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
catch (err) {
|
|
268
|
+
return res.status(400).json({
|
|
269
|
+
errors: err instanceof Error ? err.message : String(err),
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
try {
|
|
273
|
+
return await Promise.resolve(original(req, res, next));
|
|
274
|
+
}
|
|
275
|
+
catch (err) {
|
|
276
|
+
logger?.error(err);
|
|
277
|
+
return res.status(500).json({
|
|
278
|
+
message: 'Platform error. Please check later or contact support',
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
entry.handler = wrapped;
|
|
283
|
+
}
|
|
284
|
+
static get loggerGroup() {
|
|
285
|
+
return 'controller';
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
// ─── translation helpers (file-local) ────────────────────────────────
|
|
289
|
+
/**
|
|
290
|
+
* `'POST/login'` → method=POST,path=/login · `'/login'` → method=ALL,path=/login
|
|
291
|
+
*
|
|
292
|
+
* When the key looks like `METHOD/path` but the method isn't recognized
|
|
293
|
+
* (likely a typo, e.g., `'PATC/login'`), returns `unknownMethod` so the
|
|
294
|
+
* caller can warn instead of silently treating the whole key as a path.
|
|
295
|
+
*/
|
|
296
|
+
function parseScopeKey(key) {
|
|
297
|
+
if (key.startsWith('/')) {
|
|
298
|
+
return { method: 'ALL', path: key };
|
|
299
|
+
}
|
|
300
|
+
const slashIdx = key.indexOf('/');
|
|
301
|
+
if (slashIdx === -1) {
|
|
302
|
+
return { method: 'ALL', path: `/${key}` };
|
|
303
|
+
}
|
|
304
|
+
const candidate = key.slice(0, slashIdx).toUpperCase();
|
|
305
|
+
if (MAP_KEY_METHODS.has(candidate)) {
|
|
306
|
+
return {
|
|
307
|
+
method: candidate,
|
|
308
|
+
path: key.slice(slashIdx),
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
return { method: 'ALL', path: `/${key}`, unknownMethod: candidate };
|
|
312
|
+
}
|
|
313
|
+
/** `{*splat}` → `*splat`. Other syntax stays as-is. */
|
|
314
|
+
function convertPathSyntax(p) {
|
|
315
|
+
return p.replace(/\{\*([a-zA-Z_][a-zA-Z0-9_]*)\}/g, '*$1');
|
|
316
|
+
}
|
|
317
|
+
function buildHandlerEntry(spec, controller, source) {
|
|
318
|
+
if (typeof spec === 'function') {
|
|
319
|
+
return {
|
|
320
|
+
handler: spec.bind(controller),
|
|
321
|
+
meta: { methodName: spec.name || undefined },
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
if (typeof spec !== 'object' || spec === null) {
|
|
325
|
+
return null;
|
|
326
|
+
}
|
|
327
|
+
const obj = spec;
|
|
328
|
+
if (typeof obj.handler !== 'function') {
|
|
329
|
+
return null;
|
|
330
|
+
}
|
|
331
|
+
const handlerName = obj.handler.name;
|
|
332
|
+
const entry = {
|
|
333
|
+
// biome-ignore lint/complexity/noBannedTypes: handler is a user-provided callable
|
|
334
|
+
handler: obj.handler.bind(controller),
|
|
335
|
+
meta: { methodName: handlerName || undefined },
|
|
336
|
+
};
|
|
337
|
+
if (obj.request != null) {
|
|
338
|
+
// biome-ignore lint/suspicious/noExplicitAny: Standard Schema validator passthrough
|
|
339
|
+
entry.request = obj.request;
|
|
340
|
+
}
|
|
341
|
+
if (obj.query != null) {
|
|
342
|
+
// biome-ignore lint/suspicious/noExplicitAny: Standard Schema validator passthrough
|
|
343
|
+
entry.query = obj.query;
|
|
344
|
+
}
|
|
345
|
+
if (obj.bodyParsing) {
|
|
346
|
+
entry.bodyParsing = obj.bodyParsing;
|
|
347
|
+
}
|
|
348
|
+
if (Array.isArray(obj.middleware) && obj.middleware.length > 0) {
|
|
349
|
+
entry.middlewares = normalizeMiddlewares(obj.middleware, source);
|
|
350
|
+
}
|
|
351
|
+
return entry;
|
|
352
|
+
}
|
|
353
|
+
function attachHandler(subtree, method, pathStr, entry) {
|
|
354
|
+
const target = walkToNode(subtree, pathStr);
|
|
355
|
+
if (!target.methods) {
|
|
356
|
+
target.methods = {};
|
|
357
|
+
}
|
|
358
|
+
if (target.methods[method]) {
|
|
359
|
+
throw new Error(`ControllerManager: duplicate handler for ${method} ${pathStr}`);
|
|
360
|
+
}
|
|
361
|
+
const segments = pathStr.split('/').filter((s) => s.length > 0);
|
|
362
|
+
const paramNames = [];
|
|
363
|
+
for (const seg of segments) {
|
|
364
|
+
if (seg.startsWith(':') || seg.startsWith('*')) {
|
|
365
|
+
paramNames.push(seg.slice(1));
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
if (paramNames.length > 0) {
|
|
369
|
+
entry.paramNames = paramNames;
|
|
370
|
+
}
|
|
371
|
+
target.methods[method] = entry;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Attach middlewares to the right tree position.
|
|
375
|
+
*
|
|
376
|
+
* - `ALL` + path → node-level middlewares (apply to all methods at the
|
|
377
|
+
* path + descendants via walk).
|
|
378
|
+
* - `METHOD` + specific path → prepend to the handler's middleware list
|
|
379
|
+
* so they run before any route-level middlewares.
|
|
380
|
+
* - `METHOD` + splat (e.g. `'PUT/{*splat}'`) → walk the subtree at the
|
|
381
|
+
* splat's parent and attach to every handler that matches the method.
|
|
382
|
+
*/
|
|
383
|
+
function attachMiddlewares(subtree, method, pathStr, entries) {
|
|
384
|
+
const segments = pathStr.split('/').filter((s) => s.length > 0);
|
|
385
|
+
const hasSplat = segments.length > 0 && segments[segments.length - 1]?.startsWith('*');
|
|
386
|
+
if (hasSplat) {
|
|
387
|
+
segments.pop();
|
|
388
|
+
}
|
|
389
|
+
let target = subtree;
|
|
390
|
+
for (const seg of segments) {
|
|
391
|
+
target = ensureChildSegment(target, seg);
|
|
392
|
+
}
|
|
393
|
+
if (method === 'ALL') {
|
|
394
|
+
target.middlewares.push(...entries);
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
if (hasSplat) {
|
|
398
|
+
attachToMethodHandlers(target, method, entries);
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
const existingHandler = target.methods?.[method];
|
|
402
|
+
if (existingHandler) {
|
|
403
|
+
existingHandler.middlewares = [
|
|
404
|
+
...entries,
|
|
405
|
+
...(existingHandler.middlewares ?? []),
|
|
406
|
+
];
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
/** Walk a subtree, attaching mws to every handler that matches `method`. */
|
|
410
|
+
function attachToMethodHandlers(node, method, entries) {
|
|
411
|
+
const handler = node.methods?.[method];
|
|
412
|
+
if (handler) {
|
|
413
|
+
handler.middlewares = [...entries, ...(handler.middlewares ?? [])];
|
|
414
|
+
}
|
|
415
|
+
for (const child of node.children.values()) {
|
|
416
|
+
attachToMethodHandlers(child, method, entries);
|
|
417
|
+
}
|
|
418
|
+
if (node.paramChild) {
|
|
419
|
+
attachToMethodHandlers(node.paramChild, method, entries);
|
|
420
|
+
}
|
|
421
|
+
if (node.splatChild) {
|
|
422
|
+
attachToMethodHandlers(node.splatChild, method, entries);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
function walkToNode(subtree, pathStr) {
|
|
426
|
+
const segments = pathStr.split('/').filter((s) => s.length > 0);
|
|
427
|
+
let target = subtree;
|
|
428
|
+
for (const seg of segments) {
|
|
429
|
+
target = ensureChildSegment(target, seg);
|
|
430
|
+
}
|
|
431
|
+
return target;
|
|
432
|
+
}
|
|
433
|
+
function ensureChildSegment(node, segment) {
|
|
434
|
+
if (segment.startsWith(':')) {
|
|
435
|
+
if (!node.paramChild) {
|
|
436
|
+
node.paramChild = createNode(segment);
|
|
437
|
+
}
|
|
438
|
+
return node.paramChild;
|
|
439
|
+
}
|
|
440
|
+
if (segment.startsWith('*')) {
|
|
441
|
+
if (!node.splatChild) {
|
|
442
|
+
node.splatChild = createNode(segment);
|
|
443
|
+
}
|
|
444
|
+
return node.splatChild;
|
|
445
|
+
}
|
|
446
|
+
let child = node.children.get(segment);
|
|
447
|
+
if (!child) {
|
|
448
|
+
child = createNode(segment);
|
|
449
|
+
node.children.set(segment, child);
|
|
450
|
+
}
|
|
451
|
+
return child;
|
|
452
|
+
}
|
|
453
|
+
export default ControllerManager;
|
|
454
|
+
//# sourceMappingURL=index.js.map
|