@adaptivestone/framework 5.0.0-beta.9 → 5.0.0-rc.1
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/LICENCE +1 -1
- package/README.md +66 -2
- 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 +67 -0
- package/dist/cluster.js.map +1 -0
- package/dist/codegen/appTypes.d.ts +19 -0
- package/dist/codegen/appTypes.js +126 -0
- package/dist/codegen/appTypes.js.map +1 -0
- package/dist/codegen/astEmit.d.ts +53 -0
- package/dist/codegen/astEmit.js +242 -0
- package/dist/codegen/astEmit.js.map +1 -0
- package/dist/codegen/astExtract.d.ts +78 -0
- package/dist/codegen/astExtract.js +539 -0
- package/dist/codegen/astExtract.js.map +1 -0
- package/dist/codegen/astModel.d.ts +14 -0
- package/dist/codegen/astModel.js +73 -0
- package/dist/codegen/astModel.js.map +1 -0
- package/dist/codegen/astResolve.d.ts +53 -0
- package/dist/codegen/astResolve.js +276 -0
- package/dist/codegen/astResolve.js.map +1 -0
- package/dist/codegen/astSpec.d.ts +25 -0
- package/dist/codegen/astSpec.js +63 -0
- package/dist/codegen/astSpec.js.map +1 -0
- package/dist/codegen/collectMetadata.d.ts +39 -0
- package/dist/codegen/collectMetadata.js +7 -0
- package/dist/codegen/collectMetadata.js.map +1 -0
- package/dist/codegen/emit.d.ts +30 -0
- package/dist/codegen/emit.js +213 -0
- package/dist/codegen/emit.js.map +1 -0
- package/dist/codegen/index.d.ts +30 -0
- package/dist/codegen/index.js +76 -0
- package/dist/codegen/index.js.map +1 -0
- package/dist/codegen/paths.d.ts +9 -0
- package/dist/codegen/paths.js +25 -0
- package/dist/codegen/paths.js.map +1 -0
- package/dist/commands/CreateUser.d.ts +32 -0
- package/dist/commands/CreateUser.js +85 -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 +13 -0
- package/dist/commands/GenerateTypes.js +34 -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 +73 -0
- package/dist/commands/migration/Migrate.js.map +1 -0
- package/dist/config/auth.d.ts +11 -0
- package/dist/config/auth.js +18 -0
- package/dist/config/auth.js.map +1 -0
- package/dist/config/http.d.ts +22 -0
- package/dist/config/http.js +40 -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 +21 -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/controllers/Auth.d.ts +59 -0
- package/dist/controllers/Auth.js +356 -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 +14 -0
- package/dist/controllers/Home.js +26 -0
- package/dist/controllers/Home.js.map +1 -0
- package/dist/controllers/Home.routes.gen.d.ts +13 -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 +107 -0
- package/dist/controllers/index.js +548 -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 +10 -0
- package/dist/helpers/appInstance.js +19 -0
- package/dist/helpers/appInstance.js.map +1 -0
- package/dist/helpers/crypto.d.ts +26 -0
- package/dist/helpers/crypto.js +160 -0
- package/dist/helpers/crypto.js.map +1 -0
- package/dist/helpers/deprecation.d.ts +8 -0
- package/dist/helpers/deprecation.js +19 -0
- package/dist/helpers/deprecation.js.map +1 -0
- package/dist/helpers/env.d.ts +8 -0
- package/dist/helpers/env.js +15 -0
- package/dist/helpers/env.js.map +1 -0
- package/dist/helpers/files.d.ts +16 -0
- package/dist/helpers/files.js +83 -0
- package/dist/helpers/files.js.map +1 -0
- package/dist/helpers/logger.d.ts +6 -0
- package/dist/helpers/logger.js +34 -0
- package/dist/helpers/logger.js.map +1 -0
- package/dist/helpers/redis/clearNamespace.d.ts +10 -0
- package/dist/helpers/redis/clearNamespace.js +31 -0
- package/dist/helpers/redis/clearNamespace.js.map +1 -0
- package/dist/helpers/redis/redisConnection.d.ts +8 -0
- package/dist/helpers/redis/redisConnection.js +63 -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 +8 -0
- package/dist/index.js.map +1 -0
- package/{locales → dist/locales}/en/translation.json +5 -0
- package/{locales → dist/locales}/ru/translation.json +5 -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 +99 -0
- package/dist/models/Lock.js +123 -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 +31 -0
- package/dist/models/Sequence.js.map +1 -0
- package/dist/models/User.d.ts +769 -0
- package/dist/models/User.js +336 -0
- package/dist/models/User.js.map +1 -0
- package/dist/models/UserOld.d.ts +191 -0
- package/dist/models/UserOld.js +231 -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 +99 -0
- package/dist/modules/AbstractController.js +83 -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 +62 -0
- package/dist/modules/Base.js.map +1 -0
- package/dist/modules/BaseCli.d.ts +25 -0
- package/dist/modules/BaseCli.js +159 -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 +130 -0
- package/dist/server.js +603 -0
- package/dist/server.js.map +1 -0
- package/dist/services/cache/Cache.d.ts +31 -0
- package/dist/services/cache/Cache.js +146 -0
- package/dist/services/cache/Cache.js.map +1 -0
- package/dist/services/http/HttpServer.d.ts +46 -0
- package/dist/services/http/HttpServer.js +114 -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 +58 -0
- package/dist/services/http/middleware/AbstractMiddleware.js +73 -0
- package/dist/services/http/middleware/AbstractMiddleware.js.map +1 -0
- package/dist/services/http/middleware/Auth.d.ts +22 -0
- package/dist/services/http/middleware/Auth.js +30 -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 +45 -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 +59 -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 +80 -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 +70 -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 +31 -0
- package/dist/services/http/middleware/RateLimiter.js +118 -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 +20 -0
- package/dist/services/http/middleware/RequestLogger.js.map +1 -0
- package/dist/services/http/middleware/RequestParser.d.ts +15 -0
- package/dist/services/http/middleware/RequestParser.js +112 -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 +27 -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 +95 -0
- package/dist/services/http/routing/ExpressAdapter.js.map +1 -0
- package/dist/services/http/routing/RouteNode.d.ts +105 -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 +244 -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 +159 -0
- package/dist/services/http/routing/formatTree.js.map +1 -0
- package/dist/services/http/routing/match.d.ts +31 -0
- package/dist/services/http/routing/match.js +164 -0
- package/dist/services/http/routing/match.js.map +1 -0
- package/dist/services/http/routing/middlewareNormalization.d.ts +11 -0
- package/dist/services/http/routing/middlewareNormalization.js +23 -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 +134 -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 +144 -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 +90 -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 +38 -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 +81 -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 +101 -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 +83 -39
- package/.env.example +0 -18
- package/CHANGELOG.md +0 -956
- package/Cli.js +0 -21
- package/cluster.js +0 -25
- package/commands/CreateUser.js +0 -106
- package/commands/Documentation.js +0 -17
- package/commands/DropIndex.js +0 -38
- package/commands/GenerateRandomBytes.js +0 -21
- package/commands/GetOpenApiJson.js +0 -336
- package/commands/SyncIndexes.js +0 -40
- package/commands/migration/Create.js +0 -72
- package/commands/migration/Migrate.js +0 -56
- 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/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 -201
- package/controllers/Home.js +0 -28
- package/controllers/index.js +0 -60
- package/eslint.config.js +0 -68
- package/folderConfig.js +0 -13
- package/helpers/files.js +0 -76
- package/helpers/logger.js +0 -16
- package/helpers/redis/clearNamespace.js +0 -14
- package/helpers/yup.js +0 -22
- package/index.js +0 -8
- package/jsconfig.json +0 -9
- package/models/Lock.js +0 -107
- package/models/Migration.js +0 -15
- package/models/Sequence.js +0 -22
- package/models/User.js +0 -280
- package/modules/AbstractCommand.js +0 -52
- 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 -64
- package/modules/BaseCli.js +0 -157
- package/server.d.ts +0 -100
- package/server.js +0 -439
- 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 -89
- 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/templates/.gitkeep +0 -0
- 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 -120
- package/tests/setupVitest.js +0 -111
- package/types/Expand.d.ts +0 -11
- package/types/ICommandArguments.d.ts +0 -41
- package/types/TFoldersConfig.d.ts +0 -20
- package/views/404.pug +0 -3
- package/views/home.pug +0 -3
- package/views/layouts/base.pug +0 -39
- package/vitest.config.js +0 -17
- /package/{commands → dist/migrations}/.gitkeep +0 -0
- /package/{services → dist/services}/messaging/email/resources/.gitkeep +0 -0
- /package/{migrations → dist/services/messaging/email/templates}/.gitkeep +0 -0
- /package/{services → dist/services}/messaging/email/templates/recovery/html.pug +0 -0
- /package/{services → dist/services}/messaging/email/templates/recovery/subject.pug +0 -0
- /package/{services → dist/services}/messaging/email/templates/recovery/text.pug +0 -0
- /package/{services → dist/services}/messaging/email/templates/verification/html.pug +0 -0
- /package/{services → dist/services}/messaging/email/templates/verification/subject.pug +0 -0
- /package/{services → dist/services}/messaging/email/templates/verification/text.pug +0 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert authoring shorthand (`Class` or `[Class, params]`) into
|
|
3
|
+
* canonical `MiddlewareEntry`. The registry stores only canonical form;
|
|
4
|
+
* shorthand exists at the user-authoring boundary.
|
|
5
|
+
*/
|
|
6
|
+
import type AbstractMiddleware from '../middleware/AbstractMiddleware.ts';
|
|
7
|
+
import type { MiddlewareEntry } from './RouteNode.ts';
|
|
8
|
+
export type MiddlewareSpec = typeof AbstractMiddleware | readonly [typeof AbstractMiddleware, Record<string, unknown>];
|
|
9
|
+
/** Throws `TypeError` on malformed input. */
|
|
10
|
+
export declare function normalizeMiddleware(spec: MiddlewareSpec): MiddlewareEntry;
|
|
11
|
+
export declare function normalizeMiddlewares(specs: ReadonlyArray<MiddlewareSpec>): MiddlewareEntry[];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert authoring shorthand (`Class` or `[Class, params]`) into
|
|
3
|
+
* canonical `MiddlewareEntry`. The registry stores only canonical form;
|
|
4
|
+
* shorthand exists at the user-authoring boundary.
|
|
5
|
+
*/
|
|
6
|
+
/** Throws `TypeError` on malformed input. */
|
|
7
|
+
export function normalizeMiddleware(spec) {
|
|
8
|
+
if (Array.isArray(spec)) {
|
|
9
|
+
const [Class, params] = spec;
|
|
10
|
+
if (typeof Class !== 'function') {
|
|
11
|
+
throw new TypeError(`normalizeMiddleware: tuple form expected [Class, params] but got [${typeof Class}, …]`);
|
|
12
|
+
}
|
|
13
|
+
return { Class, params };
|
|
14
|
+
}
|
|
15
|
+
if (typeof spec !== 'function') {
|
|
16
|
+
throw new TypeError(`normalizeMiddleware: expected middleware class or [Class, params] tuple, got ${typeof spec}`);
|
|
17
|
+
}
|
|
18
|
+
return { Class: spec };
|
|
19
|
+
}
|
|
20
|
+
export function normalizeMiddlewares(specs) {
|
|
21
|
+
return specs.map((spec) => normalizeMiddleware(spec));
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=middlewareNormalization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middlewareNormalization.js","sourceRoot":"","sources":["../../../../src/services/http/routing/middlewareNormalization.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AASH,6CAA6C;AAC7C,MAAM,UAAU,mBAAmB,CAAC,IAAoB;IACtD,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,IAGvB,CAAC;QACF,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;YAChC,MAAM,IAAI,SAAS,CACjB,qEAAqE,OAAO,KAAK,MAAM,CACxF,CAAC;QACJ,CAAC;QACD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAC3B,CAAC;IACD,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE,CAAC;QAC/B,MAAM,IAAI,SAAS,CACjB,gFAAgF,OAAO,IAAI,EAAE,CAC9F,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AACzB,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,KAAoC;IAEpC,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP type contracts. Pure type-only — no runtime, no behavior.
|
|
3
|
+
*
|
|
4
|
+
* Per-controller `<File>.routes.gen.ts` files (hand-written today, codegen-emitted
|
|
5
|
+
* later) compose these primitives into per-route `Request<M, P>` helpers.
|
|
6
|
+
*/
|
|
7
|
+
import type { TFunction } from 'i18next';
|
|
8
|
+
import type { IApp } from '../../server.ts';
|
|
9
|
+
import type { FrameworkRequest } from './HttpServer.ts';
|
|
10
|
+
/**
|
|
11
|
+
* Module-augmentation point for app-wide `appInfo` extensions. Users add:
|
|
12
|
+
*
|
|
13
|
+
* declare module '@adaptivestone/framework' {
|
|
14
|
+
* interface AppInfoExtensions {
|
|
15
|
+
* requestId: string;
|
|
16
|
+
* sentryTransaction?: SentryTransaction;
|
|
17
|
+
* }
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* Per-route precision (e.g. `appInfo.user` from a route's middleware stack)
|
|
21
|
+
* comes from the per-controller `Request<M, P>` helper, not from this interface.
|
|
22
|
+
*/
|
|
23
|
+
export interface AppInfoExtensions {
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* `appInfo` shape populated by the framework's built-in middlewares before any
|
|
27
|
+
* user middleware runs. Mirrors what `HttpServer`'s middleware chain sets per
|
|
28
|
+
* request (`PrepareAppInfo`, `IpDetector`, `I18n`) plus the slots that the
|
|
29
|
+
* route-level validation populates (`request`, `query`).
|
|
30
|
+
*
|
|
31
|
+
* `i18n` is required — `I18nMiddleware` is part of `HttpServer`'s default
|
|
32
|
+
* chain (`HttpServer.ts:63`) and runs on every HTTP request before any
|
|
33
|
+
* controller. If a user removes it, they should augment `BaseAppInfo` to
|
|
34
|
+
* relax the field.
|
|
35
|
+
*/
|
|
36
|
+
export interface BaseAppInfo {
|
|
37
|
+
app: IApp;
|
|
38
|
+
ip?: string | undefined;
|
|
39
|
+
i18n: {
|
|
40
|
+
t: TFunction;
|
|
41
|
+
language: string;
|
|
42
|
+
};
|
|
43
|
+
request: Record<string, unknown>;
|
|
44
|
+
query: Record<string, unknown>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Default request context handlers see when no per-route `Request<M, P>` is
|
|
48
|
+
* imported. Equivalent to today's `FrameworkRequest` plus `AppInfoExtensions`.
|
|
49
|
+
*/
|
|
50
|
+
export type BaseRequestContext = FrameworkRequest & {
|
|
51
|
+
appInfo: BaseAppInfo & AppInfoExtensions;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Extract the static `provides` shape from a middleware class. Middlewares
|
|
55
|
+
* declare what they add to `appInfo` via:
|
|
56
|
+
*
|
|
57
|
+
* class GetUserByToken extends AbstractMiddleware {
|
|
58
|
+
* static get provides() {
|
|
59
|
+
* return {} as { user?: InstanceType<TUser> };
|
|
60
|
+
* }
|
|
61
|
+
* }
|
|
62
|
+
*
|
|
63
|
+
* `ProvidesOf<typeof GetUserByToken>` resolves to `{ user?: InstanceType<TUser> }`.
|
|
64
|
+
* Returns `Record<never, never>` for middlewares without `provides`.
|
|
65
|
+
*/
|
|
66
|
+
export type ProvidesOf<T> = T extends {
|
|
67
|
+
provides: infer P;
|
|
68
|
+
} ? P : Record<never, never>;
|
|
69
|
+
/**
|
|
70
|
+
* Reduce a tuple of middleware classes (or `[Class, params]` tuples) to the
|
|
71
|
+
* intersection of their `provides` shapes. Used by per-route `Request<M, P>`
|
|
72
|
+
* to layer middleware-contributed `appInfo` fields onto the base context.
|
|
73
|
+
*/
|
|
74
|
+
export type UnionAppInfoProvides<MWs extends readonly unknown[]> = MWs extends readonly [infer Head, ...infer Tail extends readonly unknown[]] ? ProvidesOf<Head extends readonly [infer C, unknown] ? C : Head> & UnionAppInfoProvides<Tail> : Record<never, never>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP type contracts. Pure type-only — no runtime, no behavior.
|
|
3
|
+
*
|
|
4
|
+
* Per-controller `<File>.routes.gen.ts` files (hand-written today, codegen-emitted
|
|
5
|
+
* later) compose these primitives into per-route `Request<M, P>` helpers.
|
|
6
|
+
*/
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/services/http/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { i18n, TFunction } from 'i18next';
|
|
2
|
+
import Base from '../../modules/Base.ts';
|
|
3
|
+
export type TI18n = {
|
|
4
|
+
t: TFunction;
|
|
5
|
+
language: string;
|
|
6
|
+
};
|
|
7
|
+
export declare class I18n extends Base {
|
|
8
|
+
#private;
|
|
9
|
+
getI18nForLang(lang?: string): Promise<{
|
|
10
|
+
t: TFunction;
|
|
11
|
+
language: string;
|
|
12
|
+
}>;
|
|
13
|
+
getI18nBaseInstance(): Promise<i18n>;
|
|
14
|
+
static get loggerGroup(): string;
|
|
15
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import Base from "../../modules/Base.js";
|
|
2
|
+
export class I18n extends Base {
|
|
3
|
+
#cache = {};
|
|
4
|
+
#i18nBase;
|
|
5
|
+
#i18nBasePromise;
|
|
6
|
+
#i18nFallback = {
|
|
7
|
+
t: ((text) => text),
|
|
8
|
+
language: 'en',
|
|
9
|
+
};
|
|
10
|
+
async getI18nForLang(lang) {
|
|
11
|
+
const i18NConfig = this.app.getConfig('i18n');
|
|
12
|
+
if (!i18NConfig.enabled) {
|
|
13
|
+
return this.#i18nFallback;
|
|
14
|
+
}
|
|
15
|
+
if (!lang || i18NConfig.supportedLngs.indexOf(lang) === -1) {
|
|
16
|
+
this.logger?.verbose(`Language "${lang}" is not supported or not provided. Using fallback on ${i18NConfig.fallbackLng}`);
|
|
17
|
+
lang = i18NConfig.fallbackLng;
|
|
18
|
+
}
|
|
19
|
+
if (!this.#cache[lang]) {
|
|
20
|
+
this.#cache[lang] = (await this.getI18nBaseInstance()).cloneInstance({
|
|
21
|
+
initAsync: false,
|
|
22
|
+
lng: lang,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return this.#cache[lang];
|
|
26
|
+
}
|
|
27
|
+
async getI18nBaseInstance() {
|
|
28
|
+
if (this.#i18nBase) {
|
|
29
|
+
return this.#i18nBase;
|
|
30
|
+
}
|
|
31
|
+
if (!this.#i18nBasePromise) {
|
|
32
|
+
this.#i18nBasePromise = (async () => {
|
|
33
|
+
const [{ default: i18next }, { default: BackendFS }] = await Promise.all([
|
|
34
|
+
import('i18next'), // Speed optimisation
|
|
35
|
+
import('i18next-fs-backend'), // Speed optimisation
|
|
36
|
+
]);
|
|
37
|
+
const i18NConfig = this.app.getConfig('i18n');
|
|
38
|
+
await i18next.use(BackendFS).init({
|
|
39
|
+
backend: {
|
|
40
|
+
loadPath: `${this.app.foldersConfig.locales}/{{lng}}/{{ns}}.json`,
|
|
41
|
+
addPath: `${this.app.foldersConfig.locales}/{{lng}}/{{ns}}.missing.json`,
|
|
42
|
+
},
|
|
43
|
+
fallbackLng: i18NConfig.fallbackLng,
|
|
44
|
+
preload: i18NConfig.preload,
|
|
45
|
+
saveMissing: i18NConfig.saveMissing,
|
|
46
|
+
debug: i18NConfig.debug,
|
|
47
|
+
});
|
|
48
|
+
this.#i18nBase = i18next;
|
|
49
|
+
return this.#i18nBase;
|
|
50
|
+
})();
|
|
51
|
+
}
|
|
52
|
+
return this.#i18nBasePromise;
|
|
53
|
+
}
|
|
54
|
+
static get loggerGroup() {
|
|
55
|
+
return 'I18n_';
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=I18n.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"I18n.js","sourceRoot":"","sources":["../../../src/services/i18n/I18n.ts"],"names":[],"mappings":"AAEA,OAAO,IAAI,MAAM,uBAAuB,CAAC;AAIzC,MAAM,OAAO,IAAK,SAAQ,IAAI;IAC5B,MAAM,GAA4B,EAAE,CAAC;IAErC,SAAS,CAAQ;IACjB,gBAAgB,CAAiB;IAEjC,aAAa,GAAuC;QAClD,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAc;QAChC,QAAQ,EAAE,IAAI;KACf,CAAC;IAEF,KAAK,CAAC,cAAc,CAAC,IAAa;QAChC,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,CAAsB,CAAC;QACnE,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;YACxB,OAAO,IAAI,CAAC,aAAa,CAAC;QAC5B,CAAC;QAED,IAAI,CAAC,IAAI,IAAI,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;YAC3D,IAAI,CAAC,MAAM,EAAE,OAAO,CAClB,aAAa,IAAI,yDAAyD,UAAU,CAAC,WAAW,EAAE,CACnG,CAAC;YACF,IAAI,GAAG,UAAU,CAAC,WAAW,CAAC;QAChC,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YACvB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,IAAI,CAAC,mBAAmB,EAAE,CAAC,CAAC,aAAa,CAAC;gBACnE,SAAS,EAAE,KAAK;gBAChB,GAAG,EAAE,IAAI;aACV,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K,WAAW;QACpB,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import Transport from 'winston-transport';
|
|
2
|
+
/**
|
|
3
|
+
* Winston transport wrapper for Sentry that conditionally loads @sentry/node
|
|
4
|
+
* Assumes Sentry is already initialized in the consuming application
|
|
5
|
+
* Only loads the Winston transport if @sentry/node is installed
|
|
6
|
+
*/
|
|
7
|
+
declare class SentryTransport extends Transport {
|
|
8
|
+
#private;
|
|
9
|
+
constructor(opts?: Transport.TransportStreamOptions);
|
|
10
|
+
private loadSentryTransport;
|
|
11
|
+
log(info: unknown, callback: () => void): void;
|
|
12
|
+
}
|
|
13
|
+
export default SentryTransport;
|
|
@@ -0,0 +1,134 @@
|
|
|
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 Transport from 'winston-transport';
|
|
10
|
+
// See: https://github.com/winstonjs/triple-beam
|
|
11
|
+
const LEVEL_SYMBOL = Symbol.for('level');
|
|
12
|
+
const MESSAGE_SYMBOL = Symbol.for('message');
|
|
13
|
+
const SPLAT_SYMBOL = Symbol.for('splat');
|
|
14
|
+
class ExtendedError extends Error {
|
|
15
|
+
constructor(info) {
|
|
16
|
+
super(info.message || 'Unknown error');
|
|
17
|
+
this.name = info.name || 'Error';
|
|
18
|
+
if (info.stack && typeof info.stack === 'string') {
|
|
19
|
+
this.stack = info.stack;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function isObject(anything) {
|
|
24
|
+
return typeof anything === 'object' && anything != null;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Winston transport wrapper for Sentry that conditionally loads @sentry/node
|
|
28
|
+
* Assumes Sentry is already initialized in the consuming application
|
|
29
|
+
* Only loads the Winston transport if @sentry/node is installed
|
|
30
|
+
*/
|
|
31
|
+
class SentryTransport extends Transport {
|
|
32
|
+
#sentry = null;
|
|
33
|
+
#initializationAttempted = false;
|
|
34
|
+
constructor(opts = {}) {
|
|
35
|
+
super(opts);
|
|
36
|
+
// Try to load Sentry Winston transport asynchronously
|
|
37
|
+
this.loadSentryTransport(opts);
|
|
38
|
+
}
|
|
39
|
+
async loadSentryTransport(_opts) {
|
|
40
|
+
if (this.#initializationAttempted) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
this.#initializationAttempted = true;
|
|
44
|
+
try {
|
|
45
|
+
// Dynamically import @sentry/node - will fail if not installed
|
|
46
|
+
// Using dynamic import to avoid TypeScript errors when package is not installed
|
|
47
|
+
const SentryNode = await import(__rewriteRelativeImportExtension('@sentry/node'));
|
|
48
|
+
const sentry = SentryNode.default || SentryNode;
|
|
49
|
+
this.#sentry = sentry;
|
|
50
|
+
console.log('[Framework] Sentry Winston transport loaded successfully');
|
|
51
|
+
}
|
|
52
|
+
catch (_error) {
|
|
53
|
+
// Sentry is not installed - this is fine for a framework
|
|
54
|
+
console.log('[Framework] Sentry Winston transport not available (package not installed)');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
log(info, callback) {
|
|
58
|
+
setImmediate(() => {
|
|
59
|
+
this.emit('logged', info);
|
|
60
|
+
});
|
|
61
|
+
if (!this.#sentry || !isObject(info)) {
|
|
62
|
+
return callback();
|
|
63
|
+
}
|
|
64
|
+
const levelFromSymbol = info[LEVEL_SYMBOL];
|
|
65
|
+
// See: https://github.com/winstonjs/winston?tab=readme-ov-file#streams-objectmode-and-info-objects
|
|
66
|
+
const { message, tags, user, ...attributes } = info;
|
|
67
|
+
// Remove all symbols from the remaining attributes
|
|
68
|
+
attributes[LEVEL_SYMBOL] = undefined;
|
|
69
|
+
attributes[MESSAGE_SYMBOL] = undefined;
|
|
70
|
+
attributes[SPLAT_SYMBOL] = undefined;
|
|
71
|
+
const logSeverityLevel = WINSTON_LEVEL_TO_LOG_SEVERITY_LEVEL_MAP[levelFromSymbol] ??
|
|
72
|
+
'info';
|
|
73
|
+
const embeddedError = Object.values(info).find((value) => value instanceof Error);
|
|
74
|
+
// Only a real Error, or a warn/error/fatal-level record, becomes a Sentry
|
|
75
|
+
// *issue*. An ordinary info/debug log (request lines, boot output) is sent
|
|
76
|
+
// as a breadcrumb-style message instead — otherwise every log burns issue
|
|
77
|
+
// quota and pages on noise.
|
|
78
|
+
const isIssueLevel = logSeverityLevel === 'warn' ||
|
|
79
|
+
logSeverityLevel === 'error' ||
|
|
80
|
+
logSeverityLevel === 'fatal';
|
|
81
|
+
// Run inside an isolated scope so this log's tags/user/extras don't leak
|
|
82
|
+
// into — or wipe (`scope.clear()`) — the host application's Sentry scope.
|
|
83
|
+
this.#sentry.withScope((scope) => {
|
|
84
|
+
if (tags !== undefined && isObject(tags)) {
|
|
85
|
+
scope.setTags(tags);
|
|
86
|
+
}
|
|
87
|
+
if (user !== undefined && isObject(user)) {
|
|
88
|
+
scope.setUser(user);
|
|
89
|
+
}
|
|
90
|
+
// Filter out undefined values and set extras
|
|
91
|
+
const extras = Object.fromEntries(Object.entries(attributes).filter(([_, value]) => value !== undefined));
|
|
92
|
+
scope.setExtras(extras);
|
|
93
|
+
scope.setLevel(logSeverityLevel);
|
|
94
|
+
if (embeddedError) {
|
|
95
|
+
this.#sentry?.captureException(embeddedError);
|
|
96
|
+
}
|
|
97
|
+
else if (isIssueLevel) {
|
|
98
|
+
this.#sentry?.captureException(new ExtendedError(info));
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
this.#sentry?.captureMessage(message || 'log', logSeverityLevel);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
return callback();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const WINSTON_LEVEL_TO_LOG_SEVERITY_LEVEL_MAP = {
|
|
108
|
+
// npm
|
|
109
|
+
silly: 'trace',
|
|
110
|
+
// npm and syslog
|
|
111
|
+
debug: 'debug',
|
|
112
|
+
// npm
|
|
113
|
+
verbose: 'debug',
|
|
114
|
+
// npm
|
|
115
|
+
http: 'debug',
|
|
116
|
+
// npm and syslog
|
|
117
|
+
info: 'info',
|
|
118
|
+
// syslog
|
|
119
|
+
notice: 'info',
|
|
120
|
+
// npm
|
|
121
|
+
warn: 'warn',
|
|
122
|
+
// syslog
|
|
123
|
+
warning: 'warn',
|
|
124
|
+
// npm and syslog
|
|
125
|
+
error: 'error',
|
|
126
|
+
// syslog
|
|
127
|
+
emerg: 'fatal',
|
|
128
|
+
// syslog
|
|
129
|
+
alert: 'fatal',
|
|
130
|
+
// syslog
|
|
131
|
+
crit: 'fatal',
|
|
132
|
+
};
|
|
133
|
+
export default SentryTransport;
|
|
134
|
+
//# sourceMappingURL=SentryTransport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SentryTransport.js","sourceRoot":"","sources":["../../../src/services/logging/SentryTransport.ts"],"names":[],"mappings":";;;;;;;;AAEA,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAE1C,gDAAgD;AAChD,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AACzC,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;AAC7C,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AAEzC,MAAM,aAAc,SAAQ,KAAK;IAC/B,YAAY,IAA6B;QACvC,KAAK,CAAE,IAAI,CAAC,OAAkB,IAAI,eAAe,CAAC,CAAC;QAEnD,IAAI,CAAC,IAAI,G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 +1,54 @@
|
|
|
1
|
+
import type { TFunction } from 'i18next';
|
|
2
|
+
import Base from '../../modules/Base.ts';
|
|
3
|
+
import type { IApp } from '../../server.ts';
|
|
4
|
+
import type { ValidatorDriver } from './types.ts';
|
|
5
|
+
/**
|
|
6
|
+
* Per-route validator dispatcher. Resolves a `ValidatorDriver` once at
|
|
7
|
+
* construction (cheap sync property check) and delegates per-request
|
|
8
|
+
* validation to it. Drivers are vendor-aware — see `./drivers/`.
|
|
9
|
+
*
|
|
10
|
+
* User-extension API: `ValidateService.register(myDriver)` prepends
|
|
11
|
+
* a custom driver, giving it priority over the built-ins. Drivers
|
|
12
|
+
* are matched in order via `canHandle(body)`; first match wins.
|
|
13
|
+
*
|
|
14
|
+
* Built-in resolution order (most specific first):
|
|
15
|
+
* 1. yupDriver — Standard Schema with `vendor: 'yup'` (strip-unknown)
|
|
16
|
+
* 2. standardSchemaDriver — any other `~standard`-conformant lib
|
|
17
|
+
*
|
|
18
|
+
* Schemas that match no driver throw at construction with a migration
|
|
19
|
+
* message — including legacy `{validate, cast}` plain objects (removed
|
|
20
|
+
* in 5.0; wrap as Standard Schema, ~10 lines).
|
|
21
|
+
*/
|
|
22
|
+
declare class ValidateService extends Base {
|
|
23
|
+
schema: unknown;
|
|
24
|
+
driver: ValidatorDriver | null;
|
|
25
|
+
static drivers: ValidatorDriver[];
|
|
26
|
+
constructor(app: IApp, schema: unknown | null);
|
|
27
|
+
/**
|
|
28
|
+
* Find the first registered driver whose `canHandle(schema)` returns true.
|
|
29
|
+
*/
|
|
30
|
+
static resolve(schema: unknown): ValidatorDriver | null;
|
|
31
|
+
/**
|
|
32
|
+
* Register a custom driver. By default prepends so user drivers take
|
|
33
|
+
* priority over the built-ins (e.g., to override yup-strip behavior
|
|
34
|
+
* or to add a non-Standard-Schema lib like raw Joi).
|
|
35
|
+
*/
|
|
36
|
+
static register(driver: ValidatorDriver, position?: 'first' | 'last'): void;
|
|
37
|
+
/**
|
|
38
|
+
* Validate `data` against the route's schema. Returns the cast value
|
|
39
|
+
* on success; throws `ValidationError` on failure. If no schema was
|
|
40
|
+
* provided, returns `data` unchanged.
|
|
41
|
+
*
|
|
42
|
+
* If `i18n` is supplied, error messages are translated through `i18n.t`
|
|
43
|
+
* before the error is re-thrown — both `.message` (wire-shape) and
|
|
44
|
+
* `.issues` (structured). Skip the argument and consumers that don't
|
|
45
|
+
* need translation (workers, RPC, tests) get raw keys back. The HTTP
|
|
46
|
+
* controller path passes `req.appInfo.i18n` so users never have to
|
|
47
|
+
* remember a translation step.
|
|
48
|
+
*/
|
|
49
|
+
validate(data: unknown, i18n?: {
|
|
50
|
+
t: TFunction;
|
|
51
|
+
} | null): Promise<unknown>;
|
|
52
|
+
static get loggerGroup(): string;
|
|
53
|
+
}
|
|
54
|
+
export default ValidateService;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import Base from "../../modules/Base.js";
|
|
2
|
+
import { standardSchemaDriver } from "./drivers/StandardSchemaDriver.js";
|
|
3
|
+
import { yupDriver } from "./drivers/YupDriver.js";
|
|
4
|
+
import { issuesToPayload, ValidationError } from "./ValidationError.js";
|
|
5
|
+
/**
|
|
6
|
+
* Per-route validator dispatcher. Resolves a `ValidatorDriver` once at
|
|
7
|
+
* construction (cheap sync property check) and delegates per-request
|
|
8
|
+
* validation to it. Drivers are vendor-aware — see `./drivers/`.
|
|
9
|
+
*
|
|
10
|
+
* User-extension API: `ValidateService.register(myDriver)` prepends
|
|
11
|
+
* a custom driver, giving it priority over the built-ins. Drivers
|
|
12
|
+
* are matched in order via `canHandle(body)`; first match wins.
|
|
13
|
+
*
|
|
14
|
+
* Built-in resolution order (most specific first):
|
|
15
|
+
* 1. yupDriver — Standard Schema with `vendor: 'yup'` (strip-unknown)
|
|
16
|
+
* 2. standardSchemaDriver — any other `~standard`-conformant lib
|
|
17
|
+
*
|
|
18
|
+
* Schemas that match no driver throw at construction with a migration
|
|
19
|
+
* message — including legacy `{validate, cast}` plain objects (removed
|
|
20
|
+
* in 5.0; wrap as Standard Schema, ~10 lines).
|
|
21
|
+
*/
|
|
22
|
+
class ValidateService extends Base {
|
|
23
|
+
schema;
|
|
24
|
+
driver;
|
|
25
|
+
static drivers = [yupDriver, standardSchemaDriver];
|
|
26
|
+
constructor(app, schema) {
|
|
27
|
+
super(app);
|
|
28
|
+
this.schema = schema;
|
|
29
|
+
if (schema) {
|
|
30
|
+
const driver = ValidateService.resolve(schema);
|
|
31
|
+
if (!driver) {
|
|
32
|
+
throw new Error(buildNoDriverMessage(schema));
|
|
33
|
+
}
|
|
34
|
+
this.driver = driver;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
this.driver = null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Find the first registered driver whose `canHandle(schema)` returns true.
|
|
42
|
+
*/
|
|
43
|
+
static resolve(schema) {
|
|
44
|
+
return (ValidateService.drivers.find((driver) => driver.canHandle(schema)) ?? null);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Register a custom driver. By default prepends so user drivers take
|
|
48
|
+
* priority over the built-ins (e.g., to override yup-strip behavior
|
|
49
|
+
* or to add a non-Standard-Schema lib like raw Joi).
|
|
50
|
+
*/
|
|
51
|
+
static register(driver, position = 'first') {
|
|
52
|
+
if (position === 'first') {
|
|
53
|
+
ValidateService.drivers.unshift(driver);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
ValidateService.drivers.push(driver);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Validate `data` against the route's schema. Returns the cast value
|
|
61
|
+
* on success; throws `ValidationError` on failure. If no schema was
|
|
62
|
+
* provided, returns `data` unchanged.
|
|
63
|
+
*
|
|
64
|
+
* If `i18n` is supplied, error messages are translated through `i18n.t`
|
|
65
|
+
* before the error is re-thrown — both `.message` (wire-shape) and
|
|
66
|
+
* `.issues` (structured). Skip the argument and consumers that don't
|
|
67
|
+
* need translation (workers, RPC, tests) get raw keys back. The HTTP
|
|
68
|
+
* controller path passes `req.appInfo.i18n` so users never have to
|
|
69
|
+
* remember a translation step.
|
|
70
|
+
*/
|
|
71
|
+
async validate(data, i18n) {
|
|
72
|
+
if (!this.driver) {
|
|
73
|
+
return data;
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
return await this.driver.validate(this.schema, data);
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
if (i18n?.t && err instanceof ValidationError) {
|
|
80
|
+
translateInPlace(err, i18n.t);
|
|
81
|
+
}
|
|
82
|
+
throw err;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
static get loggerGroup() {
|
|
86
|
+
return 'service';
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// A framework validation message is an i18n KEY (e.g. `auth.emailValid`) — a
|
|
90
|
+
// dotted/underscored token with no whitespace or template syntax. Driver
|
|
91
|
+
// messages (yup/zod) are free-form English sentences that often embed the raw
|
|
92
|
+
// submitted value (e.g. yup's typeError: `… (cast from the value "…")`). Only
|
|
93
|
+
// keys are sent through i18next; free-form messages are passed through verbatim.
|
|
94
|
+
const I18N_KEY_RE = /^[\w.:-]+$/;
|
|
95
|
+
/**
|
|
96
|
+
* Translate validation messages that are i18n keys; pass everything else
|
|
97
|
+
* through untouched. This is deliberately a KEY allow-list, not a fallback to
|
|
98
|
+
* `t(msg, msg, …)`: i18next runs nesting (`$t(...)`) and interpolation
|
|
99
|
+
* (`{{...}}`) over its key/defaultValue, so feeding a user-influenced driver
|
|
100
|
+
* message into it turns a 400 response into a reflected injection that can
|
|
101
|
+
* resolve arbitrary keys out of the loaded translation bundle.
|
|
102
|
+
*/
|
|
103
|
+
function translateInPlace(err, t) {
|
|
104
|
+
err.issues = err.issues.map((issue) => {
|
|
105
|
+
if (typeof issue.message !== 'string' || !I18N_KEY_RE.test(issue.message)) {
|
|
106
|
+
return issue;
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
...issue,
|
|
110
|
+
// 2-arg form: the message IS the key; if it isn't loaded i18next returns
|
|
111
|
+
// the key string unchanged. `params` supplies interpolation values for the
|
|
112
|
+
// (trusted, app-authored) translation string.
|
|
113
|
+
message: t(issue.message, issue.params),
|
|
114
|
+
};
|
|
115
|
+
});
|
|
116
|
+
err.message = issuesToPayload(err.issues);
|
|
117
|
+
}
|
|
118
|
+
function buildNoDriverMessage(schema) {
|
|
119
|
+
const looksLegacy = schema !== null &&
|
|
120
|
+
typeof schema === 'object' &&
|
|
121
|
+
typeof schema.validate === 'function' &&
|
|
122
|
+
typeof schema.cast === 'function';
|
|
123
|
+
if (looksLegacy) {
|
|
124
|
+
return ('Schema appears to be a legacy `{validate, cast}` plain object. ' +
|
|
125
|
+
'This pattern was removed in @adaptivestone/framework@5.0. Wrap as ' +
|
|
126
|
+
'Standard Schema (https://standardschema.dev/) — ~10 lines:\n\n' +
|
|
127
|
+
' const schema: StandardSchemaV1<Input, Output> = {\n' +
|
|
128
|
+
" '~standard': {\n" +
|
|
129
|
+
' version: 1,\n' +
|
|
130
|
+
" vendor: 'mycustom',\n" +
|
|
131
|
+
' validate(value) {\n' +
|
|
132
|
+
' // your validation logic; return {value} on success or {issues} on failure\n' +
|
|
133
|
+
' },\n' +
|
|
134
|
+
' },\n' +
|
|
135
|
+
' };');
|
|
136
|
+
}
|
|
137
|
+
return ('No ValidatorDriver matches this schema. Schemas must implement ' +
|
|
138
|
+
'Standard Schema (`~standard`). Yup ≥1.7, Zod ≥3.24, Valibot, and ArkType ' +
|
|
139
|
+
'all conform — see https://standardschema.dev/. ' +
|
|
140
|
+
'Custom validators: implement the `~standard` interface, or register ' +
|
|
141
|
+
'a custom driver via `ValidateService.register(driver)`.');
|
|
142
|
+
}
|
|
143
|
+
export default ValidateService;
|
|
144
|
+
//# sourceMappingURL=ValidateService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValidateService.js","sourceRoot":"","sources":["../../../src/services/validate/ValidateService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MAAM,CAAsB;SAC7D,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,GAAG,CAAC,OAAO,GAAG,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AAC5C,CAAC;AAED,SAAS,oBAAoB,CAAC,MAAe;IAC3C,MAAM,WAAW,GACf,MAAM,KAAK,IAAI;QACf,OAAO,MAAM,KAAK,QAAQ;QAC1B,OAAQ,MAAiC,CAAC,QAAQ,KAAK,UAAU;QACjE,OAAQ,MAA6B,CAAC,IAAI,KAAK,UAAU,CAAC;IAE5D,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,CACL,iEAAiE;YACjE,oEAAoE;YACpE,gEAAgE;YAChE,uDAAuD;YACvD,sBAAsB;YACtB,qBAAqB;YACrB,6BAA6B;YAC7B,2BAA2B;YAC3B,sFAAsF;YACtF,YAAY;YACZ,UAAU;YACV,MAAM,CACP,CAAC;IACJ,CAAC;IAED,OAAO,CACL,iEAAiE;QACjE,2EAA2E;QAC3E,iDAAiD;QACjD,sEAAsE;QACtE,yDAAyD,CAC1D,CAAC;AACJ,CAAC;AAED,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ValidationIssue } from './types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* The wire shape that goes out via `res.json({ errors: err.message })`.
|
|
4
|
+
*
|
|
5
|
+
* Each key is a field path. Each value is either a single message string
|
|
6
|
+
* or an array of messages. Both forms are preserved as-given — no
|
|
7
|
+
* normalization — so consumers see the same response bytes regardless
|
|
8
|
+
* of which validator produced the error.
|
|
9
|
+
*/
|
|
10
|
+
export type ValidationErrorPayload = Record<string, string | string[]>;
|
|
11
|
+
/**
|
|
12
|
+
* Framework-owned validation error. Replaces yup's `ValidationError` at the
|
|
13
|
+
* framework layer.
|
|
14
|
+
*
|
|
15
|
+
* Wire compatibility note — `.message` is the path-keyed payload object,
|
|
16
|
+
* NOT a string. This mirrors yup's hack: `res.json({ errors: err.message })`
|
|
17
|
+
* in `controllers/index.ts` (the validation wrapper) serializes the object directly to produce
|
|
18
|
+
* `{ "errors": { "fieldName": [...] | "...", ... } }`. Existing user
|
|
19
|
+
* catch-blocks that read `err.message` keep working unchanged.
|
|
20
|
+
*
|
|
21
|
+
* `.issues` is the canonical list (one entry per field/message pair) that
|
|
22
|
+
* non-wire consumers (logging, observability) should iterate.
|
|
23
|
+
*/
|
|
24
|
+
export declare class ValidationError extends Error {
|
|
25
|
+
issues: ValidationIssue[];
|
|
26
|
+
message: ValidationErrorPayload;
|
|
27
|
+
constructor(payload: ValidationErrorPayload | ReadonlyArray<ValidationIssue>);
|
|
28
|
+
/**
|
|
29
|
+
* Cross-realm-safe duck check. Mirrors `yup.ValidationError.isError`.
|
|
30
|
+
* Use this in framework code instead of `instanceof` when the error
|
|
31
|
+
* may have crossed a module-graph boundary.
|
|
32
|
+
*/
|
|
33
|
+
static isValidationError(err: unknown): err is ValidationError;
|
|
34
|
+
}
|
|
35
|
+
export declare function issuesToPayload(issues: ReadonlyArray<ValidationIssue>): ValidationErrorPayload;
|