@adaptivestone/framework 5.0.0-beta.5 → 5.0.0-beta.50
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 +1210 -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 +39 -0
- package/dist/codegen/collectMetadata.js +59 -0
- package/dist/codegen/collectMetadata.js.map +1 -0
- package/dist/codegen/emit.d.ts +29 -0
- package/dist/codegen/emit.js +325 -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 +74 -0
- package/dist/controllers/Auth.js +191 -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 +416 -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 +13 -0
- package/{helpers → dist/helpers}/yup.js +9 -9
- 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/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 +74 -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/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 +28 -0
- package/dist/services/http/middleware/Pagination.js +49 -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 +101 -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/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/package.json +63 -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/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,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,G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AAC,GAAG,CAAC,SAAS,CAAC,MAAM,CAAsB,CAAC;gBAEnE,MAAM,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC;oBAChC,OAAO,EAAE;wBACP,QAAQ,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,OAAO,sBAAsB;wBACjE,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,OAAO,8BAA8B;qBACzE;oBACD,WAAW,EAAE,UAAU,CAAC,WAAW;oBACnC,OAAO,EAAE,UAAU,CAAC,OAAO;oBAC3B,WAAW,EAAE,UAAU,CAAC,WAAW;oBACnC,KAAK,EAAE,UAAU,CAAC,KAAK;iBACxB,CAAC,CAAC;gBACH,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC;gBACzB,OAAO,IAAI,CAAC,SAAS,CAAC;YACxB,CAAC,CAAC,EAAE,CAAC;QACP,CAAC;QACD,OAAO,IAAI,CAAC,gBAAgB,CAAC;IAC/B,CAAC;IAED,MAAM,KAAK,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,121 @@
|
|
|
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
|
+
// Setup Sentry scope with tags, user, and extras
|
|
74
|
+
const scope = this.#sentry.getCurrentScope();
|
|
75
|
+
scope.clear();
|
|
76
|
+
if (tags !== undefined && isObject(tags)) {
|
|
77
|
+
scope.setTags(tags);
|
|
78
|
+
}
|
|
79
|
+
if (user !== undefined && isObject(user)) {
|
|
80
|
+
scope.setUser(user);
|
|
81
|
+
}
|
|
82
|
+
// Filter out undefined values and set extras
|
|
83
|
+
const extras = Object.fromEntries(Object.entries(attributes).filter(([_, value]) => value !== undefined));
|
|
84
|
+
scope.setExtras(extras);
|
|
85
|
+
const error = Object.values(info).find((value) => value instanceof Error) ??
|
|
86
|
+
new ExtendedError(info);
|
|
87
|
+
this.#sentry.captureException(error, {
|
|
88
|
+
tags: tags,
|
|
89
|
+
level: logSeverityLevel,
|
|
90
|
+
});
|
|
91
|
+
return callback();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const WINSTON_LEVEL_TO_LOG_SEVERITY_LEVEL_MAP = {
|
|
95
|
+
// npm
|
|
96
|
+
silly: 'trace',
|
|
97
|
+
// npm and syslog
|
|
98
|
+
debug: 'debug',
|
|
99
|
+
// npm
|
|
100
|
+
verbose: 'debug',
|
|
101
|
+
// npm
|
|
102
|
+
http: 'debug',
|
|
103
|
+
// npm and syslog
|
|
104
|
+
info: 'info',
|
|
105
|
+
// syslog
|
|
106
|
+
notice: 'info',
|
|
107
|
+
// npm
|
|
108
|
+
warn: 'warn',
|
|
109
|
+
// syslog
|
|
110
|
+
warning: 'warn',
|
|
111
|
+
// npm and syslog
|
|
112
|
+
error: 'error',
|
|
113
|
+
// syslog
|
|
114
|
+
emerg: 'fatal',
|
|
115
|
+
// syslog
|
|
116
|
+
alert: 'fatal',
|
|
117
|
+
// syslog
|
|
118
|
+
crit: 'fatal',
|
|
119
|
+
};
|
|
120
|
+
export default SentryTransport;
|
|
121
|
+
//# 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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AAM,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC,CACvE,CAAC;QACF,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAExB,MAAM,KAAK,GACT,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,YAAY,KAAK,CAAC;YAC3D,IAAI,aAAa,CAAC,IAA+B,CAAC,CAAC;QAErD,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,KAAK,EAAE;YACnC,IAAI,EAAE,IAA8B;YACpC,KAAK,EAAE,gBAAiC;SACzC,CAAC,CAAC;QAEH,OAAO,QAAQ,EAAE,CAAC;IACpB,CAAC;CACF;AAED,MAAM,uCAAuC,GAGzC;IACF,MAAM;IACN,KAAK,EAAE,OAAO;IACd,iBAAiB;IACjB,KAAK,EAAE,OAAO;IACd,MAAM;IACN,OAAO,EAAE,OAAO;IAChB,MAAM;IACN,IAAI,EAAE,OAAO;IACb,iBAAiB;IACjB,IAAI,EAAE,MAAM;IACZ,SAAS;IACT,MAAM,EAAE,MAAM;IACd,MAAM;IACN,IAAI,EAAE,MAAM;IACZ,SAAS;IACT,OAAO,EAAE,MAAM;IACf,iBAAiB;IACjB,KAAK,EAAE,OAAO;IACd,SAAS;IACT,KAAK,EAAE,OAAO;IACd,SAAS;IACT,KAAK,EAAE,OAAO;IACd,SAAS;IACT,IAAI,EAAE,OAAO;CACd,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +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,122 @@
|
|
|
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
|
+
function translateInPlace(err, t) {
|
|
90
|
+
err.issues = err.issues.map((issue) => ({
|
|
91
|
+
...issue,
|
|
92
|
+
message: t(issue.message, issue.message, issue.params),
|
|
93
|
+
}));
|
|
94
|
+
err.message = issuesToPayload(err.issues);
|
|
95
|
+
}
|
|
96
|
+
function buildNoDriverMessage(schema) {
|
|
97
|
+
const looksLegacy = typeof schema === 'object' &&
|
|
98
|
+
schema !== null &&
|
|
99
|
+
typeof schema.validate === 'function' &&
|
|
100
|
+
typeof schema.cast === 'function';
|
|
101
|
+
if (looksLegacy) {
|
|
102
|
+
return ('Schema appears to be a legacy `{validate, cast}` plain object. ' +
|
|
103
|
+
'This pattern was removed in @adaptivestone/framework@5.0. Wrap as ' +
|
|
104
|
+
'Standard Schema (https://standardschema.dev/) — ~10 lines:\n\n' +
|
|
105
|
+
' const schema: StandardSchemaV1<Input, Output> = {\n' +
|
|
106
|
+
" '~standard': {\n" +
|
|
107
|
+
' version: 1,\n' +
|
|
108
|
+
" vendor: 'mycustom',\n" +
|
|
109
|
+
' validate(value) {\n' +
|
|
110
|
+
' // your validation logic; return {value} on success or {issues} on failure\n' +
|
|
111
|
+
' },\n' +
|
|
112
|
+
' },\n' +
|
|
113
|
+
' };');
|
|
114
|
+
}
|
|
115
|
+
return ('No ValidatorDriver matches this schema. Schemas must implement ' +
|
|
116
|
+
'Standard Schema (`~standard`). Yup ≥1.7, Zod ≥3.24, Valibot, and ArkType ' +
|
|
117
|
+
'all conform — see https://standardschema.dev/. ' +
|
|
118
|
+
'Custom validators: implement the `~standard` interface, or register ' +
|
|
119
|
+
'a custom driver via `ValidateService.register(driver)`.');
|
|
120
|
+
}
|
|
121
|
+
export default ValidateService;
|
|
122
|
+
//# sourceMappingURL=ValidateService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValidateService.js","sourceRoot":"","sources":["../../../src/services/validate/ValidateService.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,uBAAuB,CAAC;AAEzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAExE;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,eAAgB,SAAQ,IAAI;IAChC,MAAM,CAAU;IAChB,MAAM,CAAyB;IAE/B,MAAM,CAAC,OAAO,GAAsB,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC;IAEtE,YAAY,GAAS,EAAE,MAAsB;QAC3C,KAAK,CAAC,GAAG,CAAC,CAAC;QACX,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,MAAM,EAAE,CAAC;YACX,MAAM,MAAM,GAAG,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAC/C,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC;YAChD,CAAC;YACD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACvB,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACrB,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,MAAe;QAC5B,OAAO,CACL,eAAe,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,IAAI,IAAI,CAC3E,CAA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C;AAED,SAAS,oBAAoB,CAAC,MAAe;IAC3C,MAAM,WAAW,GACf,OAAO,MAAM,KAAK,QAAQ;QAC1B,MAAM,KAAK,IAAI;QACf,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 `AbstractController.ts:222` 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;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework-owned validation error. Replaces yup's `ValidationError` at the
|
|
3
|
+
* framework layer.
|
|
4
|
+
*
|
|
5
|
+
* Wire compatibility note — `.message` is the path-keyed payload object,
|
|
6
|
+
* NOT a string. This mirrors yup's hack: `res.json({ errors: err.message })`
|
|
7
|
+
* in `AbstractController.ts:222` serializes the object directly to produce
|
|
8
|
+
* `{ "errors": { "fieldName": [...] | "...", ... } }`. Existing user
|
|
9
|
+
* catch-blocks that read `err.message` keep working unchanged.
|
|
10
|
+
*
|
|
11
|
+
* `.issues` is the canonical list (one entry per field/message pair) that
|
|
12
|
+
* non-wire consumers (logging, observability) should iterate.
|
|
13
|
+
*/
|
|
14
|
+
export class ValidationError extends Error {
|
|
15
|
+
issues;
|
|
16
|
+
constructor(payload) {
|
|
17
|
+
super();
|
|
18
|
+
this.name = 'ValidationError';
|
|
19
|
+
if (Array.isArray(payload)) {
|
|
20
|
+
const issues = [...payload];
|
|
21
|
+
this.issues = issues;
|
|
22
|
+
this.message = issuesToPayload(issues);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
const obj = { ...payload };
|
|
26
|
+
this.issues = payloadToIssues(obj);
|
|
27
|
+
// Normalize: even when constructed from a string-valued payload,
|
|
28
|
+
// canonical .message is always-array.
|
|
29
|
+
this.message = issuesToPayload(this.issues);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Cross-realm-safe duck check. Mirrors `yup.ValidationError.isError`.
|
|
34
|
+
* Use this in framework code instead of `instanceof` when the error
|
|
35
|
+
* may have crossed a module-graph boundary.
|
|
36
|
+
*/
|
|
37
|
+
static isValidationError(err) {
|
|
38
|
+
return (err instanceof Error &&
|
|
39
|
+
err.name === 'ValidationError');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function payloadToIssues(payload) {
|
|
43
|
+
const issues = [];
|
|
44
|
+
for (const [path, value] of Object.entries(payload)) {
|
|
45
|
+
const messages = Array.isArray(value) ? value : [value];
|
|
46
|
+
for (const message of messages) {
|
|
47
|
+
issues.push({ message, path: path === '' ? undefined : [path] });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return issues;
|
|
51
|
+
}
|
|
52
|
+
export function issuesToPayload(issues) {
|
|
53
|
+
// Always emit arrays per path, matching the existing yup-pipeline wire
|
|
54
|
+
// shape: `{path: ["msg"]}` even for a single error. Single-string form
|
|
55
|
+
// is still accepted as constructor input, but the canonical output is
|
|
56
|
+
// always an array.
|
|
57
|
+
const out = {};
|
|
58
|
+
for (const issue of issues) {
|
|
59
|
+
const path = pathToString(issue.path);
|
|
60
|
+
if (!out[path]) {
|
|
61
|
+
out[path] = [];
|
|
62
|
+
}
|
|
63
|
+
out[path].push(issue.message);
|
|
64
|
+
}
|
|
65
|
+
return out;
|
|
66
|
+
}
|
|
67
|
+
function pathToString(path) {
|
|
68
|
+
if (!path || path.length === 0) {
|
|
69
|
+
return '';
|
|
70
|
+
}
|
|
71
|
+
return path
|
|
72
|
+
.map((segment) => typeof segment === 'object' && segment !== null && 'key' in segment
|
|
73
|
+
? String(segment.key)
|
|
74
|
+
: String(segment))
|
|
75
|
+
.join('.');
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=ValidationError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValidationError.js","sourceRoot":"","sources":["../../../src/services/validate/ValidationError.ts"],"names":[],"mappings":"AAYA;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACxC,MAAM,CAAoB;IAQ1B,YACE,OAAgE;QAEhE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAE9B,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;YAC3B,MAAM,MAAM,GAAG,CAAC,GAAI,OAA0C,CAAC,CAAC;YAChE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;YACrB,IAAI,CAAC,OAAO,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;QACzC,CAAC;aAAM,CAAC;YACN,MAAM,GAAG,GAAG,EAAE,GAAI,OAAkC,EAAE,CAAC;YACvD,IAAI,CAAC,MAAM,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;YACnC,iEAAiE;YACjE,sCAAsC;YACtC,IAAI,CAAC,OAAO,GAAG,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,iBAAiB,CAAC,GAAY;QACnC,OAAO,CACL,GAAG,YAAY,KAAK;YACnB,GAA0B,CAAC,IAAI,KAAK,iBAAiB,CACvD,CAAC;IACJ,CAAC;CACF;AAED,SAAS,eAAe,CAAC,OAA+B;IACtD,MAAM,MAAM,GAAsB,EAAE,CAAC;IACrC,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACpD,MAAM,QAAQ,GAAG,KAAK,CAAC,O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C,GAAG,CAAC,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ValidatorDriver } from '../types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Generic Standard Schema driver. Handles any validator that implements
|
|
4
|
+
* the `~standard` interface (zod ≥3.24, valibot, arktype, custom user
|
|
5
|
+
* Standard-Schema-conformant shapes — and yup, when no more-specific
|
|
6
|
+
* driver is registered).
|
|
7
|
+
*
|
|
8
|
+
* Most popular libs strip unknown fields by default in their Standard
|
|
9
|
+
* Schema validate (zod, valibot, arktype). Yup is the outlier — see
|
|
10
|
+
* `YupDriver.ts` for the strip-preserving fast path.
|
|
11
|
+
*
|
|
12
|
+
* `toJsonSchema` returns null here; per-vendor drivers can override
|
|
13
|
+
* with their own native exporters when OpenAPI export is needed.
|
|
14
|
+
*/
|
|
15
|
+
export declare const standardSchemaDriver: ValidatorDriver;
|