@venizia/ignis-kernel 0.4.8-4 → 0.4.8-6
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/dist/esm/base/applications/body-limit.d.ts +29 -0
- package/dist/esm/base/applications/body-limit.js +49 -0
- package/dist/esm/base/applications/body-limit.js.map +1 -0
- package/dist/esm/base/applications/common/types/application.d.ts +3 -4
- package/dist/esm/base/applications/common/types/application.js.map +1 -1
- package/dist/esm/base/applications/common/types/middlewares.d.ts +7 -1
- package/dist/esm/base/applications/common/types/middlewares.js.map +1 -1
- package/dist/esm/base/applications/index.d.ts +1 -0
- package/dist/esm/base/applications/index.js +1 -0
- package/dist/esm/base/applications/index.js.map +1 -1
- package/dist/esm/base/applications/rest.d.ts +15 -7
- package/dist/esm/base/applications/rest.js +67 -21
- package/dist/esm/base/applications/rest.js.map +1 -1
- package/dist/esm/base/applications/router-factory.d.ts +27 -0
- package/dist/esm/base/applications/router-factory.js +28 -0
- package/dist/esm/base/applications/router-factory.js.map +1 -0
- package/dist/esm/base/auth/authenticate/common/types/jwt.d.ts +59 -24
- package/dist/esm/base/auth/authenticate/common/types/jwt.js.map +1 -1
- package/dist/esm/base/auth/authenticate/common/types/service.d.ts +3 -0
- package/dist/esm/base/auth/authenticate/common/types/service.js.map +1 -1
- package/dist/esm/base/auth/authenticate/providers/authentication.provider.js +5 -0
- package/dist/esm/base/auth/authenticate/providers/authentication.provider.js.map +1 -1
- package/dist/esm/base/controllers/factory/controller.d.ts +7 -0
- package/dist/esm/base/controllers/factory/crud/abstract.d.ts +11 -0
- package/dist/esm/base/controllers/factory/crud/abstract.js +7 -0
- package/dist/esm/base/controllers/factory/crud/abstract.js.map +1 -1
- package/dist/esm/base/controllers/factory/crud/persistable.js +2 -0
- package/dist/esm/base/controllers/factory/crud/persistable.js.map +1 -1
- package/dist/esm/base/controllers/factory/crud/readable.js +6 -0
- package/dist/esm/base/controllers/factory/crud/readable.js.map +1 -1
- package/dist/esm/base/controllers/factory/definition.d.ts +16 -16
- package/dist/esm/base/controllers/rest/abstract.js +5 -0
- package/dist/esm/base/controllers/rest/abstract.js.map +1 -1
- package/dist/esm/base/datasources/abstract.d.ts +69 -2
- package/dist/esm/base/datasources/abstract.js +186 -1
- package/dist/esm/base/datasources/abstract.js.map +1 -1
- package/dist/esm/base/datasources/common/types.d.ts +60 -1
- package/dist/esm/base/datasources/common/types.js +14 -0
- package/dist/esm/base/datasources/common/types.js.map +1 -1
- package/dist/esm/base/datasources/opening-handles.d.ts +8 -0
- package/dist/esm/base/datasources/opening-handles.js +8 -0
- package/dist/esm/base/datasources/opening-handles.js.map +1 -0
- package/dist/esm/base/metadata/persistents.js +15 -1
- package/dist/esm/base/metadata/persistents.js.map +1 -1
- package/dist/esm/base/middlewares/app-error/app-error.middleware.d.ts +14 -0
- package/dist/esm/base/middlewares/app-error/app-error.middleware.js +80 -3
- package/dist/esm/base/middlewares/app-error/app-error.middleware.js.map +1 -1
- package/dist/esm/base/middlewares/app-error/common/types.d.ts +10 -8
- package/dist/esm/base/middlewares/app-error/common/types.js.map +1 -1
- package/dist/esm/base/middlewares/app-error/database.handler.js +14 -14
- package/dist/esm/base/middlewares/app-error/database.handler.js.map +1 -1
- package/dist/esm/base/middlewares/app-error/index.d.ts +2 -0
- package/dist/esm/base/middlewares/app-error/index.js +1 -0
- package/dist/esm/base/middlewares/app-error/index.js.map +1 -1
- package/dist/esm/base/middlewares/app-error/postgres-errors.d.ts +20 -0
- package/dist/esm/base/middlewares/app-error/postgres-errors.js +74 -0
- package/dist/esm/base/middlewares/app-error/postgres-errors.js.map +1 -0
- package/dist/esm/base/middlewares/app-error/zod.handler.js +4 -1
- package/dist/esm/base/middlewares/app-error/zod.handler.js.map +1 -1
- package/dist/esm/base/repositories/common/index.d.ts +1 -0
- package/dist/esm/base/repositories/common/index.js +1 -0
- package/dist/esm/base/repositories/common/index.js.map +1 -1
- package/dist/esm/base/repositories/common/request-filter-guard.d.ts +118 -0
- package/dist/esm/base/repositories/common/request-filter-guard.js +179 -0
- package/dist/esm/base/repositories/common/request-filter-guard.js.map +1 -0
- package/dist/esm/base/repositories/core/abstract.d.ts +16 -0
- package/dist/esm/base/repositories/core/abstract.js +26 -0
- package/dist/esm/base/repositories/core/abstract.js.map +1 -1
- package/dist/esm/base/repositories/query-schemas/index.d.ts +6 -6
- package/dist/esm/helpers/inversion/common/types/persistence.d.ts +3 -1
- package/dist/esm/helpers/inversion/common/types/persistence.js.map +1 -1
- package/dist/esm/repository.d.ts +2 -0
- package/dist/esm/repository.js +2 -0
- package/dist/esm/repository.js.map +1 -1
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication.provider.js","sourceRoot":"","sources":["../../../../../../src/base/auth/authenticate/providers/authentication.provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAGrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACtF,OAAO,EAAE,8BAA8B,EAAE,MAAM,iCAAiC,CAAC;AAEjF;;;;GAIG;AACH,MAAM,OAAO,sBACX,SAAQ,UAAU;IAGlB;QACE,KAAK,CAAC,EAAE,KAAK,EAAE,sBAAsB,CAAC,IAAI,EAAE,CAAC,CAAC;IAChD,CAAC;IAED,KAAK;QACH,OAAO,CAAC,IAAI,EAAE,EAAE;YACd,OAAO,IAAI,CAAC,4BAA4B,CAAC,IAAI,CAAC,CAAC;QACjD,CAAC,CAAC;IACJ,CAAC;IAEO,4BAA4B,CAAC,IAAgD;QACnF,MAAM,EAAE,UAAU,EAAE,IAAI,GAAG,mBAAmB,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;QAC5D,MAAM,QAAQ,GAAG,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AC;IAEO,KAAK,CAAC,cAAc,CAAC,IAK5B;QACC,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;QAErD,8HAA8H;QAC9H,IAAI,cAAuB,CAAC;QAE5B,KAAK,MAAM,YAAY,IAAI,UAAU,EAAE,CAAC;YACtC,IAAI,CAAC;gBACH,MAAM,QAAQ,GAAG,QAAQ,CAAC,eAAe,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC;gBAClE,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"authentication.provider.js","sourceRoot":"","sources":["../../../../../../src/base/auth/authenticate/providers/authentication.provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAGrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACtF,OAAO,EAAE,8BAA8B,EAAE,MAAM,iCAAiC,CAAC;AAEjF;;;;GAIG;AACH,MAAM,OAAO,sBACX,SAAQ,UAAU;IAGlB;QACE,KAAK,CAAC,EAAE,KAAK,EAAE,sBAAsB,CAAC,IAAI,EAAE,CAAC,CAAC;IAChD,CAAC;IAED,KAAK;QACH,OAAO,CAAC,IAAI,EAAE,EAAE;YACd,OAAO,IAAI,CAAC,4BAA4B,CAAC,IAAI,CAAC,CAAC;QACjD,CAAC,CAAC;IACJ,CAAC;IAEO,4BAA4B,CAAC,IAAgD;QACnF,MAAM,EAAE,UAAU,EAAE,IAAI,GAAG,mBAAmB,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;QAC5D,MAAM,QAAQ,GAAG,8BAA8B,CAAC,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} from '@/base/controllers/common/types';\nimport { BaseHelper, getError } from '@venizia/ignis-helpers/core';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport type { IProvider } from '@venizia/ignis-inversion';\nimport type { Env } from 'hono';\nimport { createMiddleware } from 'hono/factory';\nimport type { IAuthUser, TAuthenticateFn, TAuthMode } from '../common';\nimport { Authentication, AuthenticationErrors, AuthenticationModes } from '../common';\nimport { AuthenticationStrategyRegistry } from '../strategies/strategy-registry';\n\n/**\n * Provides the `authenticate` middleware factory. Strategies resolve from `AuthenticationStrategyRegistry`.\n *\n * The middleware skips a request flagged `Authentication.SKIP_AUTHENTICATION` or already holding a current user. On success it stores the user and its audit user id in the request context.\n */\nexport class AuthenticationProvider<RouteEnv extends Env = Env>\n extends BaseHelper\n implements IProvider<TAuthenticateFn<RouteEnv>>\n{\n constructor() {\n super({ scope: AuthenticationProvider.name });\n }\n\n value(): TAuthenticateFn<RouteEnv> {\n return (opts) => {\n return this.createAuthenticateMiddleware(opts);\n };\n }\n\n private createAuthenticateMiddleware(opts: { strategies: string[]; mode?: TAuthMode }) {\n const { strategies, mode = AuthenticationModes.ANY } = opts;\n const registry = AuthenticationStrategyRegistry.getInstance();\n\n return createMiddleware(async (context, next) => {\n const isSkipAuthenticate = context.get(Authentication.SKIP_AUTHENTICATION);\n\n if (isSkipAuthenticate) {\n this.logger\n .for(this.createAuthenticateMiddleware.name)\n .debug('SKIP checking authentication | path: %s', context.req.path);\n\n return next();\n }\n\n const isAuthenticated = context.get(Authentication.CURRENT_USER);\n\n if (isAuthenticated) {\n return next();\n }\n\n switch (mode) {\n case AuthenticationModes.ANY: {\n await this.executeAnyMode({\n context: context as TContext,\n strategies,\n registry,\n next,\n });\n\n return;\n }\n case AuthenticationModes.ALL: {\n await this.executeAllMode({\n context: context as TContext,\n strategies,\n registry,\n next,\n });\n\n return;\n }\n default: {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `Invalid authentication mode | mode: ${mode}`,\n });\n }\n }\n });\n }\n\n private async executeAnyMode(opts: {\n context: TContext;\n strategies: string[];\n registry: AuthenticationStrategyRegistry;\n next: () => Promise<void>;\n }) {\n const { context, strategies, registry, next } = opts;\n\n // The first strategy's failure is the primary one - kept so the 401 carries WHY, instead of only which strategies were tried.\n let primaryFailure: unknown;\n\n for (const strategyName of strategies) {\n try {\n const strategy = registry.resolveStrategy({ name: strategyName });\n const user = await strategy.authenticate(context);\n\n // A verified credential is not yet a user: a token signed by the same key for another purpose verifies too. Both\n // modes need an id, so a strategy that answers without one has not authenticated this request.\n if (!user?.userId) {\n throw getError({ error: AuthenticationErrors.USER_UNRESOLVED });\n }\n\n this.setCurrentUser({ context, user });\n break;\n } catch (error) {\n primaryFailure ??= error;\n this.logger\n .for(this.executeAnyMode.name)\n .debug('Strategy %s failed, trying next... | Error: %s', strategyName, error);\n }\n }\n\n const currentUser = context.get(Authentication.CURRENT_USER);\n\n if (!currentUser) {\n throw getError({\n error: AuthenticationErrors.FAILED,\n message: `Authentication failed. Tried strategies: ${strategies.join(', ')}`,\n logLevel: 'warn',\n cause: primaryFailure,\n });\n }\n\n await next();\n }\n\n private async executeAllMode(opts: {\n context: TContext;\n strategies: string[];\n registry: AuthenticationStrategyRegistry;\n next: () => Promise<void>;\n }) {\n const { context, strategies, registry, next } = opts;\n\n // Use the first strategy's user as the identity source - all must succeed but first wins for identity\n let authUser: IAuthUser | null = null;\n\n for (const strategyName of strategies) {\n const strategy = registry.resolveStrategy({ name: strategyName });\n const user = await strategy.authenticate(context);\n\n authUser ??= user;\n }\n\n if (authUser?.userId) {\n this.setCurrentUser({ context, user: authUser });\n } else {\n this.logger\n .for(this.executeAllMode.name)\n .error(\n 'Failed to identify authenticated user | user: %j | userId: %s',\n authUser,\n authUser?.userId,\n );\n throw getError({ error: AuthenticationErrors.USER_UNRESOLVED });\n }\n\n return next();\n }\n\n private setCurrentUser(opts: { context: TContext; user: IAuthUser }) {\n const { context, user } = opts;\n context.set(Authentication.CURRENT_USER, user);\n\n if (user?.userId) {\n context.set(Authentication.AUDIT_USER_ID, user.userId);\n }\n }\n}\n"]}
|
|
@@ -62,6 +62,13 @@ export declare class ControllerFactory extends BaseHelper {
|
|
|
62
62
|
context: import("../index.js").TRouteContext<RouteEnv>;
|
|
63
63
|
}): Promise<import("../index.js").TJsonResponse<unknown, 200>>;
|
|
64
64
|
repository: AbstractRepository<TDataObject, TPersistObject, import("../../repositories/index.js").IExtraOptions>;
|
|
65
|
+
assertRequestFilter(opts: {
|
|
66
|
+
filter?: {
|
|
67
|
+
where?: unknown;
|
|
68
|
+
order?: unknown;
|
|
69
|
+
include?: unknown;
|
|
70
|
+
};
|
|
71
|
+
}): void;
|
|
65
72
|
bulkWhereError(opts: {
|
|
66
73
|
context: import("../index.js").TRouteContext<RouteEnv>;
|
|
67
74
|
where?: object;
|
|
@@ -22,6 +22,17 @@ export declare abstract class AbstractCrudController<TEntity extends AbstractEnt
|
|
|
22
22
|
repository: AbstractRepository<TDataObject, TPersistObject, AnyType>;
|
|
23
23
|
definitions: AnyType;
|
|
24
24
|
});
|
|
25
|
+
/**
|
|
26
|
+
* Refuses (400) a filter the client sent when it names a field the model hides (`where`, `order`, an include scope).
|
|
27
|
+
* The repository answers it; a stand-in that does not extend `AbstractRepository` has no hidden fields to hold the filter to.
|
|
28
|
+
*/
|
|
29
|
+
assertRequestFilter(opts: {
|
|
30
|
+
filter?: {
|
|
31
|
+
where?: unknown;
|
|
32
|
+
order?: unknown;
|
|
33
|
+
include?: unknown;
|
|
34
|
+
};
|
|
35
|
+
}): void;
|
|
25
36
|
/** 400 when a bulk operation is missing its `where` filter; undefined when it is present. */
|
|
26
37
|
bulkWhereError(opts: {
|
|
27
38
|
context: TRouteContext<RouteEnv>;
|
|
@@ -7,6 +7,13 @@ export class AbstractCrudController extends BaseRestController {
|
|
|
7
7
|
this.repository = opts.repository;
|
|
8
8
|
this.definitions = opts.definitions;
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Refuses (400) a filter the client sent when it names a field the model hides (`where`, `order`, an include scope).
|
|
12
|
+
* The repository answers it; a stand-in that does not extend `AbstractRepository` has no hidden fields to hold the filter to.
|
|
13
|
+
*/
|
|
14
|
+
assertRequestFilter(opts) {
|
|
15
|
+
this.repository.assertRequestFilter?.(opts);
|
|
16
|
+
}
|
|
10
17
|
/** 400 when a bulk operation is missing its `where` filter; undefined when it is present. */
|
|
11
18
|
bulkWhereError(opts) {
|
|
12
19
|
const { context, where } = opts;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abstract.js","sourceRoot":"","sources":["../../../../../../src/base/controllers/factory/crud/abstract.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAGrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAMrD,yRAAyR;AACzR,MAAM,OAAgB,sBAQpB,SAAQ,kBAAwE;IAGhF,YAAY,IAMX;QACC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QACvE,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QAClC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;IACtC,CAAC;IAED,6FAA6F;IAC7F,cAAc,CAAC,IAA0D;QACvE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QAEhC,IAAI,CAAC,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC9C,OAAO,OAAO,CAAC,IAAI,CACjB,EAAE,OAAO,EAAE,8CAA8C,EAAE,EAC3D,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CACjC,CAAC;QACJ,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,2GAA2G;IAC3G,gBAAgB,CAA2B,IAM1C;QACC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC;QAC9C,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,YAAY,IAAI,EAAE,CAAC;QAEnD,IAAI,SAAS,KAAK,SAAS,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YACtD,OAAO;gBACL,KAAK,EAAE,OAAO,CAAC,IAAI,CACjB,EAAE,OAAO,EAAE,6DAA6D,EAAE,EAC1E,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CACjC;aACF,CAAC;QACJ,CAAC;QAED,MAAM,KAAK,GAAG,SAAS,IAAI,QAAQ,CAAC;QAEpC,IAAI,CAAC,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC9C,OAAO;gBACL,KAAK,EAAE,OAAO,CAAC,IAAI,CACjB,EAAE,OAAO,EAAE,8CAA8C,EAAE,EAC3D,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CACjC;aACF,CAAC;QACJ,CAAC;QAED,OAAO,EAAE,KAAK,EAAE,CAAC;IACnB,CAAC;CACF","sourcesContent":["import type { AbstractEntity } from '@/base/models/base';\nimport type { AbstractRepository } from '@/base/repositories';\nimport type { TAnyObjectSchema } from '@/base/controllers/common/schema-builders';\nimport type { AnyType } from '@venizia/ignis-helpers/common';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport type { Env, Schema } from 'hono';\nimport type { TEntityDataObject, TEntityPersistObject, TRouteContext } from '../../common';\nimport { BaseRestController } from '../../rest/base';\n\ntype TBulkWhereResolution<WhereType> =\n | { where: WhereType; error?: undefined }\n | { where?: undefined; error: Response };\n\n/** Base tier of a generated CRUD controller - the repository handle; the response helpers (`respond`, `setListHeaders`) live on BaseRestController so hand-written controllers share them. Read and write verbs are layered on by ReadableCrudController / PersistableCrudController. */\nexport abstract class AbstractCrudController<\n TEntity extends AbstractEntity<TAnyObjectSchema> = AbstractEntity<TAnyObjectSchema>,\n RouteEnv extends Env = Env,\n RouteSchema extends Schema = {},\n BasePath extends string = '/',\n ConfigurableOptions extends object = {},\n TDataObject extends object = TEntityDataObject<TEntity>,\n TPersistObject extends object = TEntityPersistObject<TEntity>,\n> extends BaseRestController<RouteEnv, RouteSchema, BasePath, ConfigurableOptions> {\n repository: AbstractRepository<TDataObject, TPersistObject>;\n\n constructor(opts: {\n scope: string;\n path: string;\n isStrict?: boolean;\n repository: AbstractRepository<TDataObject, TPersistObject, AnyType>;\n definitions: AnyType;\n }) {\n super({ scope: opts.scope, path: opts.path, isStrict: opts.isStrict });\n this.repository = opts.repository;\n this.definitions = opts.definitions;\n }\n\n /** 400 when a bulk operation is missing its `where` filter; undefined when it is present. */\n bulkWhereError(opts: { context: TRouteContext<RouteEnv>; where?: object }) {\n const { context, where } = opts;\n\n if (!where || Object.keys(where).length === 0) {\n return context.json(\n { message: 'where filter is required for bulk operations' },\n HTTP.ResultCodes.RS_4.BadRequest,\n );\n }\n\n return undefined;\n }\n\n /** Bulk `where` from the query or the JSON body (long id lists outgrow a URL). Both, or none, is a 400. */\n resolveBulkWhere<WhereType extends object>(opts: {\n context: TRouteContext<RouteEnv>;\n where?: {\n fromQuery?: WhereType;\n fromBody?: WhereType;\n };\n }): TBulkWhereResolution<WhereType> {\n const { context, where: whereSources } = opts;\n const { fromQuery, fromBody } = whereSources ?? {};\n\n if (fromQuery !== undefined && fromBody !== undefined) {\n return {\n error: context.json(\n { message: 'where given in both the query and the body - send it in one' },\n HTTP.ResultCodes.RS_4.BadRequest,\n ),\n };\n }\n\n const where = fromQuery ?? fromBody;\n\n if (!where || Object.keys(where).length === 0) {\n return {\n error: context.json(\n { message: 'where filter is required for bulk operations' },\n HTTP.ResultCodes.RS_4.BadRequest,\n ),\n };\n }\n\n return { where };\n }\n}\n"]}
|
|
1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,IAAI,SAAS,KAAK,SAAS,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YACtD,OAAO;gBACL,KAAK,EAAE,OAAO,CAAC,IAAI,CACjB,EAAE,OAAO,EAAE,6DAA6D,EAAE,EAC1E,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CACjC;aACF,CAAC;QACJ,CAAC;QAED,MAAM,KAAK,GAAG,SAAS,IAAI,QAAQ,CAAC;QAEpC,IAAI,CAAC,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC9C,OAAO;gBACL,KAAK,EAAE,OAAO,CAAC,IAAI,CACjB,EAAE,OAAO,EAAE,8CAA8C,EAAE,EAC3D,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CACjC;aACF,CAAC;QACJ,CAAC;QAED,OAAO,EAAE,KAAK,EAAE,CAAC;IACnB,CAAC;CACF","sourcesContent":["import type { AbstractEntity } from '@/base/models/base';\nimport type { AbstractRepository } from '@/base/repositories';\nimport type { TAnyObjectSchema } from '@/base/controllers/common/schema-builders';\nimport type { AnyType } from '@venizia/ignis-helpers/common';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport type { Env, Schema } from 'hono';\nimport type { TEntityDataObject, TEntityPersistObject, TRouteContext } from '../../common';\nimport { BaseRestController } from '../../rest/base';\n\ntype TBulkWhereResolution<WhereType> =\n | { where: WhereType; error?: undefined }\n | { where?: undefined; error: Response };\n\n/** Base tier of a generated CRUD controller - the repository handle; the response helpers (`respond`, `setListHeaders`) live on BaseRestController so hand-written controllers share them. Read and write verbs are layered on by ReadableCrudController / PersistableCrudController. */\nexport abstract class AbstractCrudController<\n TEntity extends AbstractEntity<TAnyObjectSchema> = AbstractEntity<TAnyObjectSchema>,\n RouteEnv extends Env = Env,\n RouteSchema extends Schema = {},\n BasePath extends string = '/',\n ConfigurableOptions extends object = {},\n TDataObject extends object = TEntityDataObject<TEntity>,\n TPersistObject extends object = TEntityPersistObject<TEntity>,\n> extends BaseRestController<RouteEnv, RouteSchema, BasePath, ConfigurableOptions> {\n repository: AbstractRepository<TDataObject, TPersistObject>;\n\n constructor(opts: {\n scope: string;\n path: string;\n isStrict?: boolean;\n repository: AbstractRepository<TDataObject, TPersistObject, AnyType>;\n definitions: AnyType;\n }) {\n super({ scope: opts.scope, path: opts.path, isStrict: opts.isStrict });\n this.repository = opts.repository;\n this.definitions = opts.definitions;\n }\n\n /**\n * Refuses (400) a filter the client sent when it names a field the model hides (`where`, `order`, an include scope).\n * The repository answers it; a stand-in that does not extend `AbstractRepository` has no hidden fields to hold the filter to.\n */\n assertRequestFilter(opts: {\n filter?: { where?: unknown; order?: unknown; include?: unknown };\n }): void {\n (\n this.repository as Partial<Pick<AbstractRepository<object>, 'assertRequestFilter'>>\n ).assertRequestFilter?.(opts);\n }\n\n /** 400 when a bulk operation is missing its `where` filter; undefined when it is present. */\n bulkWhereError(opts: { context: TRouteContext<RouteEnv>; where?: object }) {\n const { context, where } = opts;\n\n if (!where || Object.keys(where).length === 0) {\n return context.json(\n { message: 'where filter is required for bulk operations' },\n HTTP.ResultCodes.RS_4.BadRequest,\n );\n }\n\n return undefined;\n }\n\n /** Bulk `where` from the query or the JSON body (long id lists outgrow a URL). Both, or none, is a 400. */\n resolveBulkWhere<WhereType extends object>(opts: {\n context: TRouteContext<RouteEnv>;\n where?: {\n fromQuery?: WhereType;\n fromBody?: WhereType;\n };\n }): TBulkWhereResolution<WhereType> {\n const { context, where: whereSources } = opts;\n const { fromQuery, fromBody } = whereSources ?? {};\n\n if (fromQuery !== undefined && fromBody !== undefined) {\n return {\n error: context.json(\n { message: 'where given in both the query and the body - send it in one' },\n HTTP.ResultCodes.RS_4.BadRequest,\n ),\n };\n }\n\n const where = fromQuery ?? fromBody;\n\n if (!where || Object.keys(where).length === 0) {\n return {\n error: context.json(\n { message: 'where filter is required for bulk operations' },\n HTTP.ResultCodes.RS_4.BadRequest,\n ),\n };\n }\n\n return { where };\n }\n}\n"]}
|
|
@@ -75,6 +75,7 @@ export class PersistableCrudController extends ReadableCrudController {
|
|
|
75
75
|
return resolved.error;
|
|
76
76
|
}
|
|
77
77
|
const { where } = resolved;
|
|
78
|
+
this.assertRequestFilter({ filter: { where } });
|
|
78
79
|
const rs = await this.measure({
|
|
79
80
|
scope: 'updateBy',
|
|
80
81
|
args: { where, data },
|
|
@@ -130,6 +131,7 @@ export class PersistableCrudController extends ReadableCrudController {
|
|
|
130
131
|
return resolved.error;
|
|
131
132
|
}
|
|
132
133
|
const { where } = resolved;
|
|
134
|
+
this.assertRequestFilter({ filter: { where } });
|
|
133
135
|
const rs = await this.measure({
|
|
134
136
|
scope: 'deleteBy',
|
|
135
137
|
args: { where },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"persistable.js","sourceRoot":"","sources":["../../../../../../src/base/controllers/factory/crud/persistable.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AAGjE,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAGvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,mGAAmG;AACnG,MAAM,OAAgB,yBAQpB,SAAQ,sBAQT;IACC,aAAa;IACb,KAAK,CAAC,MAAM,CAAC,IAA0C;QACrD,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;QACzB,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAiB,MAAM,CAAC,CAAC;QAEvD,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC;YAC5B,KAAK,EAAE,QAAQ;YACf,IAAI,EAAE,IAAI;YACV,IAAI,EAAE,KAAK,IAAI,EAAE;gBACf,MAAM,OAAO,GA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EAAE,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACpD,CAAC;CACF","sourcesContent":["import type { IdType } from '@/base/models';\nimport type { AbstractEntity } from '@/base/models/base';\nimport { RequestErrors } from '@/base/middlewares/common/errors';\nimport type { TWhere } from '@venizia/ignis-filter';\nimport type { TAnyObjectSchema } from '@/base/controllers/common/schema-builders';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport type { Env, Schema } from 'hono';\nimport type { TEntityDataObject, TEntityPersistObject, TRouteContext } from '../../common';\nimport { ReadableCrudController } from './readable';\nimport { ResponseFormats } from '../../common';\n\n/** Write tier: create / updateById / updateBy / deleteById / deleteBy. Inherits the read verbs. */\nexport abstract class PersistableCrudController<\n TEntity extends AbstractEntity<TAnyObjectSchema> = AbstractEntity<TAnyObjectSchema>,\n RouteEnv extends Env = Env,\n RouteSchema extends Schema = {},\n BasePath extends string = '/',\n ConfigurableOptions extends object = {},\n TDataObject extends object = TEntityDataObject<TEntity>,\n TPersistObject extends object = TEntityPersistObject<TEntity>,\n> extends ReadableCrudController<\n TEntity,\n RouteEnv,\n RouteSchema,\n BasePath,\n ConfigurableOptions,\n TDataObject,\n TPersistObject\n> {\n /** POST / */\n async create(opts: { context: TRouteContext<RouteEnv> }) {\n const { context } = opts;\n const data = context.req.valid<TPersistObject>('json');\n\n const rs = await this.measure({\n scope: 'create',\n args: data,\n task: async () => {\n const payload = await this.repository.create({ data });\n\n return this.respond<TDataObject>({\n context,\n format: ResponseFormats.OBJECT,\n payload,\n });\n },\n });\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Created);\n }\n\n /**\n * 400 when the validated body leaves no field to write - `{}`, or only keys the body schema drops.\n * The repository would otherwise fail with a 500.\n */\n assertNonEmptyUpdate(opts: { scope: string; data: object }): void {\n const { scope, data } = opts;\n\n if (Object.keys(data).length === 0) {\n throw getError({\n error: RequestErrors.NOTHING_TO_UPDATE,\n message: `[${scope}] Nothing to update | The body has no field this route writes`,\n logLevel: 'warn',\n });\n }\n }\n\n /** PATCH /:id */\n async updateById(opts: { context: TRouteContext<RouteEnv> }) {\n const { context } = opts;\n const { id } = context.req.valid<{ id: IdType }>('param');\n const data = context.req.valid<Partial<TPersistObject>>('json');\n this.assertNonEmptyUpdate({ scope: 'updateById', data });\n\n const rs = await this.measure({\n scope: 'updateById',\n args: { id, data },\n task: async () => {\n const payload = await this.repository.updateById({ id, data });\n\n return this.respond<TDataObject>({\n context,\n format: ResponseFormats.OBJECT,\n payload,\n });\n },\n });\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Ok);\n }\n\n /** PATCH / */\n async updateBy(opts: { context: TRouteContext<RouteEnv> }) {\n const { context } = opts;\n const { where: queryWhere } = context.req.valid<{ where?: TWhere<TDataObject> }>('query');\n const { where: bodyWhere } = context.req.valid<{ where?: TWhere<TDataObject> }>('json');\n // A COPY: `where` selects rows and is never written, and hono hands the same validated object to\n // an override that calls this through `super`.\n const data: Partial<TPersistObject> = { ...context.req.valid<Partial<TPersistObject>>('json') };\n Reflect.deleteProperty(data, 'where');\n this.assertNonEmptyUpdate({ scope: 'updateBy', data });\n\n const resolved = this.resolveBulkWhere({\n context,\n where: { fromQuery: queryWhere, fromBody: bodyWhere },\n });\n\n if (resolved.error !== undefined) {\n return resolved.error;\n }\n\n const { where } = resolved;\n\n const rs = await this.measure({\n scope: 'updateBy',\n args: { where, data },\n task: async () => {\n const payload = await this.repository.updateBy({ where, data });\n\n return this.respond<Array<TDataObject>>({\n context,\n format: ResponseFormats.ARRAY,\n payload,\n });\n },\n });\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Ok);\n }\n\n /** DELETE /:id */\n async deleteById(opts: { context: TRouteContext<RouteEnv> }) {\n const { context } = opts;\n const { id } = context.req.valid<{ id: IdType }>('param');\n\n const rs = await this.measure({\n scope: 'deleteById',\n args: { id },\n task: async () => {\n const payload = await this.repository.deleteById({ id });\n\n return this.respond<TDataObject>({\n context,\n format: ResponseFormats.OBJECT,\n payload,\n });\n },\n });\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Ok);\n }\n\n /** DELETE / */\n async deleteBy(opts: { context: TRouteContext<RouteEnv> }) {\n const { context } = opts;\n const { where: queryWhere } = context.req.valid<{ where?: TWhere<TDataObject> }>('query');\n // Read, never validated: a declared body schema would gate the media type and answer 400 to a\n // client that sends a content-type and no body. A body that is not JSON is simply not a `where`.\n let body;\n\n try {\n const result = await context.req.json<{ where?: TWhere<TDataObject> }>();\n body = result;\n // eslint-disable-next-line venizia/no-silent-catch -- a body that is not JSON is not a `where`; the bulk delete then relies on the query alone and nothing else is lost\n } catch {\n body = undefined;\n }\n\n const resolved = this.resolveBulkWhere({\n context,\n where: { fromQuery: queryWhere, fromBody: body?.where },\n });\n\n if (resolved.error !== undefined) {\n return resolved.error;\n }\n\n const { where } = resolved;\n\n const rs = await this.measure({\n scope: 'deleteBy',\n args: { where },\n task: async () => {\n const payload = await this.repository.deleteBy({ where });\n\n return this.respond<Array<TDataObject>>({\n context,\n format: ResponseFormats.ARRAY,\n payload,\n });\n },\n });\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Ok);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"persistable.js","sourceRoot":"","sources":["../../../../../../src/base/controllers/factory/crud/persistable.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AAGjE,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAGvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,mGAAmG;AACnG,MAAM,OAAgB,yBAQpB,SAAQ,sBAQT;IACC,aAAa;IACb,KAAK,CAAC,MAAM,CAAC,IAA0C;QACrD,MAAM,EAAE,OAAO,EAAE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QAEhD,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC;YAC5B,KAAK,EAAE,UAAU;YACjB,IAAI,EAAE,EAAE,KAAK,EAAE;YACf,IAAI,EAAE,KAAK,IAAI,EAAE;gBACf,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;gBAE1D,OAAO,IAAI,CAAC,OAAO,CAAqB;oBACtC,OAAO;oBACP,MAAM,EAAE,eAAe,CAAC,KAAK;oBAC7B,OAAO;iBACR,CAAC,CAAC;YACL,CAAC;SACF,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACpD,CAAC;CACF","sourcesContent":["import type { IdType } from '@/base/models';\nimport type { AbstractEntity } from '@/base/models/base';\nimport { RequestErrors } from '@/base/middlewares/common/errors';\nimport type { TWhere } from '@venizia/ignis-filter';\nimport type { TAnyObjectSchema } from '@/base/controllers/common/schema-builders';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport type { Env, Schema } from 'hono';\nimport type { TEntityDataObject, TEntityPersistObject, TRouteContext } from '../../common';\nimport { ReadableCrudController } from './readable';\nimport { ResponseFormats } from '../../common';\n\n/** Write tier: create / updateById / updateBy / deleteById / deleteBy. Inherits the read verbs. */\nexport abstract class PersistableCrudController<\n TEntity extends AbstractEntity<TAnyObjectSchema> = AbstractEntity<TAnyObjectSchema>,\n RouteEnv extends Env = Env,\n RouteSchema extends Schema = {},\n BasePath extends string = '/',\n ConfigurableOptions extends object = {},\n TDataObject extends object = TEntityDataObject<TEntity>,\n TPersistObject extends object = TEntityPersistObject<TEntity>,\n> extends ReadableCrudController<\n TEntity,\n RouteEnv,\n RouteSchema,\n BasePath,\n ConfigurableOptions,\n TDataObject,\n TPersistObject\n> {\n /** POST / */\n async create(opts: { context: TRouteContext<RouteEnv> }) {\n const { context } = opts;\n const data = context.req.valid<TPersistObject>('json');\n\n const rs = await this.measure({\n scope: 'create',\n args: data,\n task: async () => {\n const payload = await this.repository.create({ data });\n\n return this.respond<TDataObject>({\n context,\n format: ResponseFormats.OBJECT,\n payload,\n });\n },\n });\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Created);\n }\n\n /**\n * 400 when the validated body leaves no field to write - `{}`, or only keys the body schema drops.\n * The repository would otherwise fail with a 500.\n */\n assertNonEmptyUpdate(opts: { scope: string; data: object }): void {\n const { scope, data } = opts;\n\n if (Object.keys(data).length === 0) {\n throw getError({\n error: RequestErrors.NOTHING_TO_UPDATE,\n message: `[${scope}] Nothing to update | The body has no field this route writes`,\n logLevel: 'warn',\n });\n }\n }\n\n /** PATCH /:id */\n async updateById(opts: { context: TRouteContext<RouteEnv> }) {\n const { context } = opts;\n const { id } = context.req.valid<{ id: IdType }>('param');\n const data = context.req.valid<Partial<TPersistObject>>('json');\n this.assertNonEmptyUpdate({ scope: 'updateById', data });\n\n const rs = await this.measure({\n scope: 'updateById',\n args: { id, data },\n task: async () => {\n const payload = await this.repository.updateById({ id, data });\n\n return this.respond<TDataObject>({\n context,\n format: ResponseFormats.OBJECT,\n payload,\n });\n },\n });\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Ok);\n }\n\n /** PATCH / */\n async updateBy(opts: { context: TRouteContext<RouteEnv> }) {\n const { context } = opts;\n const { where: queryWhere } = context.req.valid<{ where?: TWhere<TDataObject> }>('query');\n const { where: bodyWhere } = context.req.valid<{ where?: TWhere<TDataObject> }>('json');\n // A COPY: `where` selects rows and is never written, and hono hands the same validated object to\n // an override that calls this through `super`.\n const data: Partial<TPersistObject> = { ...context.req.valid<Partial<TPersistObject>>('json') };\n Reflect.deleteProperty(data, 'where');\n this.assertNonEmptyUpdate({ scope: 'updateBy', data });\n\n const resolved = this.resolveBulkWhere({\n context,\n where: { fromQuery: queryWhere, fromBody: bodyWhere },\n });\n\n if (resolved.error !== undefined) {\n return resolved.error;\n }\n\n const { where } = resolved;\n\n this.assertRequestFilter({ filter: { where } });\n\n const rs = await this.measure({\n scope: 'updateBy',\n args: { where, data },\n task: async () => {\n const payload = await this.repository.updateBy({ where, data });\n\n return this.respond<Array<TDataObject>>({\n context,\n format: ResponseFormats.ARRAY,\n payload,\n });\n },\n });\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Ok);\n }\n\n /** DELETE /:id */\n async deleteById(opts: { context: TRouteContext<RouteEnv> }) {\n const { context } = opts;\n const { id } = context.req.valid<{ id: IdType }>('param');\n\n const rs = await this.measure({\n scope: 'deleteById',\n args: { id },\n task: async () => {\n const payload = await this.repository.deleteById({ id });\n\n return this.respond<TDataObject>({\n context,\n format: ResponseFormats.OBJECT,\n payload,\n });\n },\n });\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Ok);\n }\n\n /** DELETE / */\n async deleteBy(opts: { context: TRouteContext<RouteEnv> }) {\n const { context } = opts;\n const { where: queryWhere } = context.req.valid<{ where?: TWhere<TDataObject> }>('query');\n // Read, never validated: a declared body schema would gate the media type and answer 400 to a\n // client that sends a content-type and no body. A body that is not JSON is simply not a `where`.\n let body;\n\n try {\n const result = await context.req.json<{ where?: TWhere<TDataObject> }>();\n body = result;\n // eslint-disable-next-line venizia/no-silent-catch -- a body that is not JSON is not a `where`; the bulk delete then relies on the query alone and nothing else is lost\n } catch {\n body = undefined;\n }\n\n const resolved = this.resolveBulkWhere({\n context,\n where: { fromQuery: queryWhere, fromBody: body?.where },\n });\n\n if (resolved.error !== undefined) {\n return resolved.error;\n }\n\n const { where } = resolved;\n\n this.assertRequestFilter({ filter: { where } });\n\n const rs = await this.measure({\n scope: 'deleteBy',\n args: { where },\n task: async () => {\n const payload = await this.repository.deleteBy({ where });\n\n return this.respond<Array<TDataObject>>({\n context,\n format: ResponseFormats.ARRAY,\n payload,\n });\n },\n });\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Ok);\n }\n}\n"]}
|
|
@@ -26,6 +26,8 @@ export class ReadableCrudController extends AbstractCrudController {
|
|
|
26
26
|
async count(opts) {
|
|
27
27
|
const { context } = opts;
|
|
28
28
|
const { where } = context.req.valid('query');
|
|
29
|
+
// What the client sent, before the base where joins it: a hidden field cannot be asked about.
|
|
30
|
+
this.assertRequestFilter({ filter: { where } });
|
|
29
31
|
const baseWhere = await this.getBaseWhere({ context });
|
|
30
32
|
const scopedWhere = baseWhere ? withBaseWhere({ baseWhere, where }) : where;
|
|
31
33
|
const rs = await this.measure({
|
|
@@ -39,6 +41,7 @@ export class ReadableCrudController extends AbstractCrudController {
|
|
|
39
41
|
async find(opts) {
|
|
40
42
|
const { context } = opts;
|
|
41
43
|
const { filter = {} } = context.req.valid('query');
|
|
44
|
+
this.assertRequestFilter({ filter });
|
|
42
45
|
const baseWhere = await this.getBaseWhere({ context });
|
|
43
46
|
const scopedFilter = baseWhere
|
|
44
47
|
? { ...filter, where: withBaseWhere({ baseWhere, where: filter.where }) }
|
|
@@ -66,6 +69,8 @@ export class ReadableCrudController extends AbstractCrudController {
|
|
|
66
69
|
const { context } = opts;
|
|
67
70
|
const { id } = context.req.valid('param');
|
|
68
71
|
const { filter } = context.req.valid('query');
|
|
72
|
+
// The read is by id, so a `where` the client sent is never read; the check reads only what the query reads.
|
|
73
|
+
this.assertRequestFilter({ filter: filter && { ...filter, where: undefined } });
|
|
69
74
|
const baseWhere = await this.getBaseWhere({ context });
|
|
70
75
|
// `repository.findById` takes no where, so a scoped read goes through `findOne` - the same
|
|
71
76
|
// substrate every family's findById delegates to - and answers null on an out-of-scope id.
|
|
@@ -93,6 +98,7 @@ export class ReadableCrudController extends AbstractCrudController {
|
|
|
93
98
|
async findOne(opts) {
|
|
94
99
|
const { context } = opts;
|
|
95
100
|
const { filter = {} } = context.req.valid('query');
|
|
101
|
+
this.assertRequestFilter({ filter });
|
|
96
102
|
const baseWhere = await this.getBaseWhere({ context });
|
|
97
103
|
const scopedFilter = baseWhere
|
|
98
104
|
? { ...filter, where: withBaseWhere({ baseWhere, where: filter.where }) }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readable.js","sourceRoot":"","sources":["../../../../../../src/base/controllers/factory/crud/readable.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAGrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,uHAAuH;AACvH,MAAM,aAAa,GAAG,CAA6B,IAGlD,EAAuB,EAAE;IACxB,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;IAElC,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,+GAA+G;IAC/G,MAAM,MAAM,GAAqC,EAAE,GAAG,EAAE,CAAC,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC;IAE7E,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,oIAAoI;AACpI,MAAM,SAAS,GAAG,CAA6B,IAAoB,EAAuB,EAAE;IAC1F,MAAM,KAAK,GAAW,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC;IAEtC,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,oGAAoG;AACpG,MAAM,OAAgB,sBAQpB,SAAQ,sBAQT;IACC,yMAAyM;IACzM,KAAK,CAAC,YAAY,CAAC,KAElB;QACC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,iBAAiB;IACjB,KAAK,CAAC,KAAK,CAAC,IAA0C;QACpD,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;QACzB,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAiC,OAAO,CAAC,CAAC;QAC7E,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,EAAE,OA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IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC;gBAEvE,OAAO,IAAI,CAAC,OAAO,CAAc;oBAC/B,OAAO;oBACP,MAAM,EAAE,eAAe,CAAC,MAAM;oBAC9B,OAAO,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE;iBACjD,CAAC,CAAC;YACL,CAAC;SACF,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACpD,CAAC;CACF","sourcesContent":["import type { AbstractEntity, IdType } from '@/base/models';\nimport type { TFilter, TWhere } from '@venizia/ignis-filter';\nimport type { TAnyObjectSchema } from '@/base/controllers/common/schema-builders';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport type { Env, Schema } from 'hono';\nimport type { TEntityDataObject, TEntityPersistObject, TRouteContext } from '../../common';\nimport { AbstractCrudController } from './abstract';\nimport { ResponseFormats } from '../../common';\n\n/** The one combination point of a base where and a request where; without a request side there is no `and` wrapper. */\nconst withBaseWhere = <TDataObject extends object>(opts: {\n baseWhere: TWhere<TDataObject>;\n where?: TWhere<TDataObject>;\n}): TWhere<TDataObject> => {\n const { baseWhere, where } = opts;\n\n if (!where) {\n return baseWhere;\n }\n\n // `Pick` resolves the one key: a literal cannot be checked against `TWhere` over an unresolved type parameter.\n const scoped: Pick<TWhere<TDataObject>, 'and'> = { and: [baseWhere, where] };\n\n return scoped;\n};\n\n/** `id` is the primary key every entity family reads by; built at the default `TWhere` for the same unresolved-parameter reason. */\nconst whereById = <TDataObject extends object>(opts: { id: IdType }): TWhere<TDataObject> => {\n const where: TWhere = { id: opts.id };\n\n return where;\n};\n\n/** Read tier: count / find / findById / findOne. Read-only controllers can extend this directly. */\nexport abstract class ReadableCrudController<\n TEntity extends AbstractEntity<TAnyObjectSchema> = AbstractEntity<TAnyObjectSchema>,\n RouteEnv extends Env = Env,\n RouteSchema extends Schema = {},\n BasePath extends string = '/',\n ConfigurableOptions extends object = {},\n TDataObject extends object = TEntityDataObject<TEntity>,\n TPersistObject extends object = TEntityPersistObject<TEntity>,\n> extends AbstractCrudController<\n TEntity,\n RouteEnv,\n RouteSchema,\n BasePath,\n ConfigurableOptions,\n TDataObject,\n TPersistObject\n> {\n /** Narrows EVERY read of this controller - override it to scope rows to a tenant, an owner or a status. Public because a generated controller's declaration cannot carry a protected member (TS4094). */\n async getBaseWhere(_opts: {\n context: TRouteContext<RouteEnv>;\n }): Promise<TWhere<TDataObject> | undefined> {\n return undefined;\n }\n\n /** GET /count */\n async count(opts: { context: TRouteContext<RouteEnv> }) {\n const { context } = opts;\n const { where } = context.req.valid<{ where: TWhere<TDataObject> }>('query');\n const baseWhere = await this.getBaseWhere({ context });\n const scopedWhere = baseWhere ? withBaseWhere({ baseWhere, where }) : where;\n\n const rs = await this.measure({\n scope: 'count',\n args: { where: scopedWhere },\n task: () => this.repository.count({ where: scopedWhere }),\n });\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Ok);\n }\n\n /** GET / - paginated list with a Content-Range header. */\n async find(opts: { context: TRouteContext<RouteEnv> }) {\n const { context } = opts;\n const { filter = {} } = context.req.valid<{ filter?: TFilter<TDataObject> }>('query');\n const baseWhere = await this.getBaseWhere({ context });\n const scopedFilter = baseWhere\n ? { ...filter, where: withBaseWhere({ baseWhere, where: filter.where }) }\n : filter;\n\n const rs = await this.measure({\n scope: 'find',\n args: scopedFilter,\n task: async () => {\n const { data, range } = await this.repository.find({\n filter: scopedFilter,\n options: { shouldQueryRange: true },\n });\n\n return this.respond<Array<TDataObject>>({\n context,\n format: ResponseFormats.ARRAY,\n payload: { count: data.length, data },\n range,\n });\n },\n });\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Ok);\n }\n\n /** GET /:id */\n async findById(opts: { context: TRouteContext<RouteEnv> }) {\n const { context } = opts;\n const { id } = context.req.valid<{ id: IdType }>('param');\n const { filter } = context.req.valid<{ filter?: Omit<TFilter<TDataObject>, 'where'> }>('query');\n const baseWhere = await this.getBaseWhere({ context });\n\n // `repository.findById` takes no where, so a scoped read goes through `findOne` - the same\n // substrate every family's findById delegates to - and answers null on an out-of-scope id.\n const scopedWhere = baseWhere\n ? withBaseWhere({ baseWhere, where: whereById({ id }) })\n : undefined;\n\n const rs = await this.measure({\n scope: 'findById',\n args: filter,\n task: async () => {\n const lookup = scopedWhere\n ? this.repository.findOne({ filter: { ...filter, where: scopedWhere } })\n : this.repository.findById({ id, filter });\n const record = await lookup;\n\n return this.respond<TDataObject>({\n context,\n format: ResponseFormats.OBJECT,\n payload: { count: record ? 1 : 0, data: record },\n });\n },\n });\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Ok);\n }\n\n /** GET /find-one */\n async findOne(opts: { context: TRouteContext<RouteEnv> }) {\n const { context } = opts;\n const { filter = {} } = context.req.valid<{ filter?: TFilter<TDataObject> }>('query');\n const baseWhere = await this.getBaseWhere({ context });\n const scopedFilter = baseWhere\n ? { ...filter, where: withBaseWhere({ baseWhere, where: filter.where }) }\n : filter;\n\n const rs = await this.measure({\n scope: 'findOne',\n args: scopedFilter,\n task: async () => {\n const record = await this.repository.findOne({ filter: scopedFilter });\n\n return this.respond<TDataObject>({\n context,\n format: ResponseFormats.OBJECT,\n payload: { count: record ? 1 : 0, data: record },\n });\n },\n });\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Ok);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"readable.js","sourceRoot":"","sources":["../../../../../../src/base/controllers/factory/crud/readable.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAGrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,uHA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AAE,KAAK,IAAI,EAAE;gBACf,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC;gBAEvE,OAAO,IAAI,CAAC,OAAO,CAAc;oBAC/B,OAAO;oBACP,MAAM,EAAE,eAAe,CAAC,MAAM;oBAC9B,OAAO,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE;iBACjD,CAAC,CAAC;YACL,CAAC;SACF,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACpD,CAAC;CACF","sourcesContent":["import type { AbstractEntity, IdType } from '@/base/models';\nimport type { TFilter, TWhere } from '@venizia/ignis-filter';\nimport type { TAnyObjectSchema } from '@/base/controllers/common/schema-builders';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport type { Env, Schema } from 'hono';\nimport type { TEntityDataObject, TEntityPersistObject, TRouteContext } from '../../common';\nimport { AbstractCrudController } from './abstract';\nimport { ResponseFormats } from '../../common';\n\n/** The one combination point of a base where and a request where; without a request side there is no `and` wrapper. */\nconst withBaseWhere = <TDataObject extends object>(opts: {\n baseWhere: TWhere<TDataObject>;\n where?: TWhere<TDataObject>;\n}): TWhere<TDataObject> => {\n const { baseWhere, where } = opts;\n\n if (!where) {\n return baseWhere;\n }\n\n // `Pick` resolves the one key: a literal cannot be checked against `TWhere` over an unresolved type parameter.\n const scoped: Pick<TWhere<TDataObject>, 'and'> = { and: [baseWhere, where] };\n\n return scoped;\n};\n\n/** `id` is the primary key every entity family reads by; built at the default `TWhere` for the same unresolved-parameter reason. */\nconst whereById = <TDataObject extends object>(opts: { id: IdType }): TWhere<TDataObject> => {\n const where: TWhere = { id: opts.id };\n\n return where;\n};\n\n/** Read tier: count / find / findById / findOne. Read-only controllers can extend this directly. */\nexport abstract class ReadableCrudController<\n TEntity extends AbstractEntity<TAnyObjectSchema> = AbstractEntity<TAnyObjectSchema>,\n RouteEnv extends Env = Env,\n RouteSchema extends Schema = {},\n BasePath extends string = '/',\n ConfigurableOptions extends object = {},\n TDataObject extends object = TEntityDataObject<TEntity>,\n TPersistObject extends object = TEntityPersistObject<TEntity>,\n> extends AbstractCrudController<\n TEntity,\n RouteEnv,\n RouteSchema,\n BasePath,\n ConfigurableOptions,\n TDataObject,\n TPersistObject\n> {\n /** Narrows EVERY read of this controller - override it to scope rows to a tenant, an owner or a status. Public because a generated controller's declaration cannot carry a protected member (TS4094). */\n async getBaseWhere(_opts: {\n context: TRouteContext<RouteEnv>;\n }): Promise<TWhere<TDataObject> | undefined> {\n return undefined;\n }\n\n /** GET /count */\n async count(opts: { context: TRouteContext<RouteEnv> }) {\n const { context } = opts;\n const { where } = context.req.valid<{ where: TWhere<TDataObject> }>('query');\n\n // What the client sent, before the base where joins it: a hidden field cannot be asked about.\n this.assertRequestFilter({ filter: { where } });\n\n const baseWhere = await this.getBaseWhere({ context });\n const scopedWhere = baseWhere ? withBaseWhere({ baseWhere, where }) : where;\n\n const rs = await this.measure({\n scope: 'count',\n args: { where: scopedWhere },\n task: () => this.repository.count({ where: scopedWhere }),\n });\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Ok);\n }\n\n /** GET / - paginated list with a Content-Range header. */\n async find(opts: { context: TRouteContext<RouteEnv> }) {\n const { context } = opts;\n const { filter = {} } = context.req.valid<{ filter?: TFilter<TDataObject> }>('query');\n\n this.assertRequestFilter({ filter });\n\n const baseWhere = await this.getBaseWhere({ context });\n const scopedFilter = baseWhere\n ? { ...filter, where: withBaseWhere({ baseWhere, where: filter.where }) }\n : filter;\n\n const rs = await this.measure({\n scope: 'find',\n args: scopedFilter,\n task: async () => {\n const { data, range } = await this.repository.find({\n filter: scopedFilter,\n options: { shouldQueryRange: true },\n });\n\n return this.respond<Array<TDataObject>>({\n context,\n format: ResponseFormats.ARRAY,\n payload: { count: data.length, data },\n range,\n });\n },\n });\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Ok);\n }\n\n /** GET /:id */\n async findById(opts: { context: TRouteContext<RouteEnv> }) {\n const { context } = opts;\n const { id } = context.req.valid<{ id: IdType }>('param');\n const { filter } = context.req.valid<{ filter?: Omit<TFilter<TDataObject>, 'where'> }>('query');\n\n // The read is by id, so a `where` the client sent is never read; the check reads only what the query reads.\n this.assertRequestFilter({ filter: filter && { ...filter, where: undefined } });\n\n const baseWhere = await this.getBaseWhere({ context });\n\n // `repository.findById` takes no where, so a scoped read goes through `findOne` - the same\n // substrate every family's findById delegates to - and answers null on an out-of-scope id.\n const scopedWhere = baseWhere\n ? withBaseWhere({ baseWhere, where: whereById({ id }) })\n : undefined;\n\n const rs = await this.measure({\n scope: 'findById',\n args: filter,\n task: async () => {\n const lookup = scopedWhere\n ? this.repository.findOne({ filter: { ...filter, where: scopedWhere } })\n : this.repository.findById({ id, filter });\n const record = await lookup;\n\n return this.respond<TDataObject>({\n context,\n format: ResponseFormats.OBJECT,\n payload: { count: record ? 1 : 0, data: record },\n });\n },\n });\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Ok);\n }\n\n /** GET /find-one */\n async findOne(opts: { context: TRouteContext<RouteEnv> }) {\n const { context } = opts;\n const { filter = {} } = context.req.valid<{ filter?: TFilter<TDataObject> }>('query');\n\n this.assertRequestFilter({ filter });\n\n const baseWhere = await this.getBaseWhere({ context });\n const scopedFilter = baseWhere\n ? { ...filter, where: withBaseWhere({ baseWhere, where: filter.where }) }\n : filter;\n\n const rs = await this.measure({\n scope: 'findOne',\n args: scopedFilter,\n task: async () => {\n const record = await this.repository.findOne({ filter: scopedFilter });\n\n return this.respond<TDataObject>({\n context,\n format: ResponseFormats.OBJECT,\n payload: { count: record ? 1 : 0, data: record },\n });\n },\n });\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Ok);\n }\n}\n"]}
|
|
@@ -39,7 +39,7 @@ export declare class RouteConfigResolver {
|
|
|
39
39
|
}): {
|
|
40
40
|
request: {
|
|
41
41
|
query: TAnyObjectSchema | z.ZodObject<{
|
|
42
|
-
where: z.ZodUnion<readonly [z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown
|
|
42
|
+
where: z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>>]> | z.ZodOptional<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>>]>>;
|
|
43
43
|
}, z.core.$strip>;
|
|
44
44
|
headers: TAnyObjectSchema | z.ZodObject<{
|
|
45
45
|
"x-request-id": z.ZodOptional<z.ZodString>;
|
|
@@ -62,7 +62,7 @@ export declare class RouteConfigResolver {
|
|
|
62
62
|
request: {
|
|
63
63
|
query: TAnyObjectSchema | z.ZodObject<{
|
|
64
64
|
filter: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
|
|
65
|
-
where: z.ZodOptional<z.ZodUnion<readonly [z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown
|
|
65
|
+
where: z.ZodOptional<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>>]>>;
|
|
66
66
|
fields: z.ZodOptional<z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodBoolean>, z.ZodArray<z.ZodString>]>>;
|
|
67
67
|
include: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
68
68
|
relation: z.ZodString;
|
|
@@ -73,7 +73,7 @@ export declare class RouteConfigResolver {
|
|
|
73
73
|
offset: z.ZodOptional<z.ZodNumber>;
|
|
74
74
|
skip: z.ZodOptional<z.ZodNumber>;
|
|
75
75
|
}, z.core.$strip>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, z.ZodObject<{
|
|
76
|
-
where: z.ZodOptional<z.ZodUnion<readonly [z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown
|
|
76
|
+
where: z.ZodOptional<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>>]>>;
|
|
77
77
|
fields: z.ZodOptional<z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodBoolean>, z.ZodArray<z.ZodString>]>>;
|
|
78
78
|
include: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
79
79
|
relation: z.ZodString;
|
|
@@ -114,7 +114,7 @@ export declare class RouteConfigResolver {
|
|
|
114
114
|
}, z.core.$strip>;
|
|
115
115
|
query: TAnyObjectSchema | z.ZodObject<{
|
|
116
116
|
filter: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
|
|
117
|
-
where: z.ZodOptional<z.ZodUnion<readonly [z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown
|
|
117
|
+
where: z.ZodOptional<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>>]>>;
|
|
118
118
|
fields: z.ZodOptional<z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodBoolean>, z.ZodArray<z.ZodString>]>>;
|
|
119
119
|
include: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
120
120
|
relation: z.ZodString;
|
|
@@ -125,7 +125,7 @@ export declare class RouteConfigResolver {
|
|
|
125
125
|
offset: z.ZodOptional<z.ZodNumber>;
|
|
126
126
|
skip: z.ZodOptional<z.ZodNumber>;
|
|
127
127
|
}, z.core.$strip>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, z.ZodObject<{
|
|
128
|
-
where: z.ZodOptional<z.ZodUnion<readonly [z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown
|
|
128
|
+
where: z.ZodOptional<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>>]>>;
|
|
129
129
|
fields: z.ZodOptional<z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodBoolean>, z.ZodArray<z.ZodString>]>>;
|
|
130
130
|
include: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
131
131
|
relation: z.ZodString;
|
|
@@ -160,7 +160,7 @@ export declare class RouteConfigResolver {
|
|
|
160
160
|
request: {
|
|
161
161
|
query: TAnyObjectSchema | z.ZodObject<{
|
|
162
162
|
filter: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
|
|
163
|
-
where: z.ZodOptional<z.ZodUnion<readonly [z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown
|
|
163
|
+
where: z.ZodOptional<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>>]>>;
|
|
164
164
|
fields: z.ZodOptional<z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodBoolean>, z.ZodArray<z.ZodString>]>>;
|
|
165
165
|
include: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
166
166
|
relation: z.ZodString;
|
|
@@ -171,7 +171,7 @@ export declare class RouteConfigResolver {
|
|
|
171
171
|
offset: z.ZodOptional<z.ZodNumber>;
|
|
172
172
|
skip: z.ZodOptional<z.ZodNumber>;
|
|
173
173
|
}, z.core.$strip>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, z.ZodObject<{
|
|
174
|
-
where: z.ZodOptional<z.ZodUnion<readonly [z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown
|
|
174
|
+
where: z.ZodOptional<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>>]>>;
|
|
175
175
|
fields: z.ZodOptional<z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodBoolean>, z.ZodArray<z.ZodString>]>>;
|
|
176
176
|
include: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
177
177
|
relation: z.ZodString;
|
|
@@ -259,7 +259,7 @@ export declare class RouteConfigResolver {
|
|
|
259
259
|
readonly authorize: IAuthorizationSpec<import("hono").Env, string, string> | IAuthorizationSpec<import("hono").Env, string, string>[] | undefined;
|
|
260
260
|
readonly request: {
|
|
261
261
|
query: TAnyObjectSchema | z.ZodObject<{
|
|
262
|
-
where: z.ZodUnion<readonly [z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown
|
|
262
|
+
where: z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>>]> | z.ZodOptional<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>>]>>;
|
|
263
263
|
}, z.core.$strip>;
|
|
264
264
|
headers: TAnyObjectSchema | z.ZodObject<{
|
|
265
265
|
"x-request-id": z.ZodOptional<z.ZodString>;
|
|
@@ -344,7 +344,7 @@ export declare class RouteConfigResolver {
|
|
|
344
344
|
readonly request: {
|
|
345
345
|
query: TAnyObjectSchema | z.ZodObject<{
|
|
346
346
|
filter: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
|
|
347
|
-
where: z.ZodOptional<z.ZodUnion<readonly [z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown
|
|
347
|
+
where: z.ZodOptional<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>>]>>;
|
|
348
348
|
fields: z.ZodOptional<z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodBoolean>, z.ZodArray<z.ZodString>]>>;
|
|
349
349
|
include: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
350
350
|
relation: z.ZodString;
|
|
@@ -355,7 +355,7 @@ export declare class RouteConfigResolver {
|
|
|
355
355
|
offset: z.ZodOptional<z.ZodNumber>;
|
|
356
356
|
skip: z.ZodOptional<z.ZodNumber>;
|
|
357
357
|
}, z.core.$strip>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, z.ZodObject<{
|
|
358
|
-
where: z.ZodOptional<z.ZodUnion<readonly [z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown
|
|
358
|
+
where: z.ZodOptional<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>>]>>;
|
|
359
359
|
fields: z.ZodOptional<z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodBoolean>, z.ZodArray<z.ZodString>]>>;
|
|
360
360
|
include: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
361
361
|
relation: z.ZodString;
|
|
@@ -458,7 +458,7 @@ export declare class RouteConfigResolver {
|
|
|
458
458
|
}, z.core.$strip>;
|
|
459
459
|
query: TAnyObjectSchema | z.ZodObject<{
|
|
460
460
|
filter: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
|
|
461
|
-
where: z.ZodOptional<z.ZodUnion<readonly [z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown
|
|
461
|
+
where: z.ZodOptional<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>>]>>;
|
|
462
462
|
fields: z.ZodOptional<z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodBoolean>, z.ZodArray<z.ZodString>]>>;
|
|
463
463
|
include: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
464
464
|
relation: z.ZodString;
|
|
@@ -469,7 +469,7 @@ export declare class RouteConfigResolver {
|
|
|
469
469
|
offset: z.ZodOptional<z.ZodNumber>;
|
|
470
470
|
skip: z.ZodOptional<z.ZodNumber>;
|
|
471
471
|
}, z.core.$strip>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, z.ZodObject<{
|
|
472
|
-
where: z.ZodOptional<z.ZodUnion<readonly [z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown
|
|
472
|
+
where: z.ZodOptional<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>>]>>;
|
|
473
473
|
fields: z.ZodOptional<z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodBoolean>, z.ZodArray<z.ZodString>]>>;
|
|
474
474
|
include: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
475
475
|
relation: z.ZodString;
|
|
@@ -567,7 +567,7 @@ export declare class RouteConfigResolver {
|
|
|
567
567
|
readonly request: {
|
|
568
568
|
query: TAnyObjectSchema | z.ZodObject<{
|
|
569
569
|
filter: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
|
|
570
|
-
where: z.ZodOptional<z.ZodUnion<readonly [z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown
|
|
570
|
+
where: z.ZodOptional<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>>]>>;
|
|
571
571
|
fields: z.ZodOptional<z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodBoolean>, z.ZodArray<z.ZodString>]>>;
|
|
572
572
|
include: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
573
573
|
relation: z.ZodString;
|
|
@@ -578,7 +578,7 @@ export declare class RouteConfigResolver {
|
|
|
578
578
|
offset: z.ZodOptional<z.ZodNumber>;
|
|
579
579
|
skip: z.ZodOptional<z.ZodNumber>;
|
|
580
580
|
}, z.core.$strip>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, z.ZodObject<{
|
|
581
|
-
where: z.ZodOptional<z.ZodUnion<readonly [z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown
|
|
581
|
+
where: z.ZodOptional<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>>]>>;
|
|
582
582
|
fields: z.ZodOptional<z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodBoolean>, z.ZodArray<z.ZodString>]>>;
|
|
583
583
|
include: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
584
584
|
relation: z.ZodString;
|
|
@@ -866,7 +866,7 @@ export declare class RouteConfigResolver {
|
|
|
866
866
|
readonly authorize: IAuthorizationSpec<import("hono").Env, string, string> | IAuthorizationSpec<import("hono").Env, string, string>[] | undefined;
|
|
867
867
|
readonly request: {
|
|
868
868
|
readonly query: TAnyObjectSchema | z.ZodObject<{
|
|
869
|
-
where: z.ZodOptional<z.ZodUnion<readonly [z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown
|
|
869
|
+
where: z.ZodOptional<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>>]>>;
|
|
870
870
|
}, z.core.$strip>;
|
|
871
871
|
readonly body: {
|
|
872
872
|
description: string;
|
|
@@ -1066,7 +1066,7 @@ export declare class RouteConfigResolver {
|
|
|
1066
1066
|
required: boolean | undefined;
|
|
1067
1067
|
} | undefined;
|
|
1068
1068
|
readonly query: TAnyObjectSchema | z.ZodObject<{
|
|
1069
|
-
where: z.ZodOptional<z.ZodUnion<readonly [z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown
|
|
1069
|
+
where: z.ZodOptional<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, z.ZodPipe<z.ZodPipe<z.ZodAny, z.ZodTransform<any, any>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>>]>>;
|
|
1070
1070
|
}, z.core.$strip>;
|
|
1071
1071
|
};
|
|
1072
1072
|
readonly responses: {
|
|
@@ -9,6 +9,11 @@ import { RoutePathScopes } from '../common/constants.js';
|
|
|
9
9
|
import { OpenApiResponses } from '../../models/common/index.js';
|
|
10
10
|
import { createRoute, OpenAPIHono } from '@hono/zod-openapi';
|
|
11
11
|
import { BaseHelper, getError } from '@venizia/ignis-helpers/core';
|
|
12
|
+
import { RouterFactories } from '../../applications/router-factory.js';
|
|
13
|
+
// Loading this module makes the application's routers `OpenAPIHono` (see `RouterFactories`).
|
|
14
|
+
RouterFactories.registerOpenApi({
|
|
15
|
+
factory: ({ strict }) => new OpenAPIHono({ strict }),
|
|
16
|
+
});
|
|
12
17
|
/** True for a route path carrying a path parameter, in either supported syntax: `/{id}` or `/:id`. */
|
|
13
18
|
const hasPathParam = (opts) => {
|
|
14
19
|
return /\{[^}]+\}|:[^/]+/.test(opts.path);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abstract.js","sourceRoot":"","sources":["../../../../../src/base/controllers/rest/abstract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AAChF,OAAO,EAAE,YAAY,IAAI,cAAc,EAAE,MAAM,8DAA8D,CAAC;AAE9G,OAAO,EAAE,SAAS,IAAI,WAAW,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AAE,GAAG;YACf,SAAS,EAAE,MAAM,CAAC,MAAM,CACtB,EAAE,EACF,gBAAgB,CAAC,YAAY,CAAC,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC,EAC3D,SAAS,CACV;YACD,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC;YAC3B,QAAQ;SACT,CAAQ,CACV,CAAC;IACJ,CAAC;CAeF","sourcesContent":["import { AuthenticationModes } from '@/base/auth/authenticate/common/constants';\nimport { authenticate as authenticateFn } from '@/base/auth/authenticate/middlewares/authenticate.middleware';\nimport type { IAuthorizationSpec } from '@/base/auth/authorize/common/types';\nimport { authorize as authorizeFn } from '@/base/auth/authorize/middlewares/authorize.middleware';\nimport { FormBodyMiddleware } from '@/base/middlewares/form-body/form-body.middleware';\nimport { AuthenticationStrategyRegistry } from '@/base/auth/authenticate/strategies/strategy-registry';\nimport { DroppedRouteDecorators } from '@/base/metadata/routes/common';\nimport { MetadataRegistry } from '@/helpers/inversion/registry';\nimport { RoutePathScopes, type TRoutePathScope } from '@/base/controllers/common/constants';\nimport { OpenApiResponses } from '@/base/models/common';\nimport type { Hook } from '@hono/zod-openapi';\nimport { createRoute, OpenAPIHono } from '@hono/zod-openapi';\nimport type { ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport { BaseHelper, getError } from '@venizia/ignis-helpers/core';\nimport type { Env, Schema } from 'hono';\nimport type {\n IAuthRouteConfig,\n IBindRouteOptions,\n IController,\n IControllerOptions,\n IDefineRouteOptions,\n TRouteHandler,\n} from '../common/types';\n\n/** True for a route path carrying a path parameter, in either supported syntax: `/{id}` or `/:id`. */\nconst hasPathParam = (opts: { path: string }): boolean => {\n return /\\{[^}]+\\}|:[^/]+/.test(opts.path);\n};\n\n/** Abstract base class for all REST controllers, providing route registration and auth middleware integration. */\nexport abstract class AbstractRestController<\n RouteEnv extends Env = Env,\n RouteSchema extends Schema = {},\n BasePath extends string = '/',\n ConfigurableOptions extends object = {},\n Definitions extends Record<string, IAuthRouteConfig> = Record<string, IAuthRouteConfig>,\n>\n extends BaseHelper\n implements IController<RouteEnv, RouteSchema, BasePath, ConfigurableOptions>\n{\n isConfigured = false;\n router: OpenAPIHono<RouteEnv, RouteSchema, BasePath>;\n path: string;\n definitions: Definitions;\n\n constructor(opts: IControllerOptions) {\n super(opts);\n const { isStrict = true } = opts;\n\n const decoratorMetadata = MetadataRegistry.getInstance().getControllerMetadata({\n target: new.target,\n });\n const resolvedPath = decoratorMetadata?.path ?? opts.path;\n\n if (!resolvedPath) {\n throw getError({\n message: `[${new.target.name}] Controller path is required. Provide path via @controller decorator or constructor options.`,\n });\n }\n\n this.path = resolvedPath;\n\n this.router = new OpenAPIHono<RouteEnv, RouteSchema, BasePath>({\n strict: isStrict,\n defaultHook: (result, _context) => {\n if (!result.success) {\n throw result.error;\n }\n },\n });\n }\n\n /** Returns the OpenAPIHono router instance for this controller. */\n getRouter() {\n return this.router;\n }\n\n /** Registers decorator-defined routes from the metadata registry; `paths` selects them by shape - see the two-phase call in {@link configure}. */\n registerRoutesFromRegistry(opts?: { paths?: TRoutePathScope }): void {\n const { paths = RoutePathScopes.ALL } = opts ?? {};\n\n const logger = this.logger.for(this.registerRoutesFromRegistry.name);\n DroppedRouteDecorators.report({ logger });\n\n const routes = MetadataRegistry.getInstance().getRoutes({\n target: Object.getPrototypeOf(this),\n });\n\n if (!routes?.size) {\n return;\n }\n\n const routeDefs = routes.entries();\n\n for (const [methodName, routeConfigs] of routeDefs) {\n if (\n paths !== RoutePathScopes.ALL &&\n hasPathParam({ path: routeConfigs.path }) !== (paths === RoutePathScopes.PARAM)\n ) {\n continue;\n }\n\n // Dynamic dispatch by decorator-recorded method name - the controller class has no static index signature, so this read cannot be typed narrower than `unknown`.\n const handler = (this as Record<string | symbol, unknown>)[methodName];\n\n if (typeof handler !== 'function') {\n logger.warn('Route method \"%s\" not found on controller', String(methodName));\n continue;\n }\n\n this.bindRoute({ configs: routeConfigs }).to({\n handler: (handler as TRouteHandler<unknown, RouteEnv>).bind(this),\n });\n }\n }\n\n /** Configures the controller by binding all routes and registering decorator-based routes. Idempotent. */\n async configure(\n opts?: ConfigurableOptions,\n ): Promise<OpenAPIHono<RouteEnv, RouteSchema, BasePath>> {\n if (this.isConfigured) {\n return this.router;\n }\n\n const t = performance.now();\n const logger = this.logger.for(this.configure.name);\n\n const configureOptions = opts ?? {};\n logger.info('START | Binding controller | Options: %j', configureOptions);\n\n // Hono matches in registration order, so registration runs by SHAPE not source: every static path first, then binding()'s routes, then decorator param routes last (`/{id}` early would eat `/count`).\n this.registerRoutesFromRegistry({ paths: RoutePathScopes.STATIC });\n await this.binding();\n this.registerRoutesFromRegistry({ paths: RoutePathScopes.PARAM });\n\n this.isConfigured = true;\n logger.info('DONE | Binding controller | Took: %s (ms)', performance.now() - t);\n\n return this.router;\n }\n\n /** @internal Builds auth + custom middlewares and security specs from route config. */\n buildRouteMiddlewares<RouteConfig extends IAuthRouteConfig>(opts: { configs: RouteConfig }) {\n const { authenticate = {}, authorize, ...restConfig } = opts.configs;\n const { strategies = [], mode = AuthenticationModes.ANY } = authenticate;\n\n // Boot-time and NON-fatal: names a misspelled strategy at error level instead of leaving it as\n // a 401 nobody can explain. Deliberately not a throw - `AuthControllerFactory.define` hard-codes `jwt`\n // on four routes, and ANY mode tolerates a strategy that does not resolve, so failing here would\n // stop applications booting that work today. `assertRegistered` is there for an application that\n // does want the hard failure.\n AuthenticationStrategyRegistry.getInstance().reportUnregistered({\n names: strategies,\n scope: this.constructor.name,\n });\n\n const security = strategies.map((strategy: string) => ({ [strategy]: [] }));\n const mws: ReturnType<typeof authenticateFn>[] = [];\n\n if (strategies.length > 0) {\n mws.push(authenticateFn({ strategies, mode }));\n }\n\n // Inject authorize middleware AFTER authenticate\n if (authorize) {\n const specs: IAuthorizationSpec[] = Array.isArray(authorize) ? authorize : [authorize];\n\n for (const spec of specs) {\n mws.push(authorizeFn({ spec }));\n }\n }\n\n const configuredMiddleware = restConfig.middleware;\n const extraMws = Array.isArray(configuredMiddleware)\n ? configuredMiddleware\n : [configuredMiddleware];\n\n for (const mw of extraMws) {\n if (!mw) {\n continue;\n }\n\n mws.push(mw);\n }\n\n // Last: an application middleware and any size check run before the body is read.\n if (FormBodyMiddleware.hasFormBody({ content: restConfig.request?.body?.content })) {\n mws.push(FormBodyMiddleware.read);\n }\n\n return { restConfig, security, mws };\n }\n\n /** Processes route config, injecting auth middleware and OpenAPI security specs. */\n getRouteConfigs<RouteConfig extends IAuthRouteConfig>(opts: { configs: RouteConfig }) {\n const { restConfig, security, mws } = this.buildRouteMiddlewares(opts);\n const { tags = [] } = restConfig;\n\n // `restConfig` already omitted `authenticate`/`authorize` (this library's fields, not Hono's `createRoute` ones); reassembled with the injected middleware/tags/security it no longer structurally overlaps RouteConfig enough to assert directly.\n return createRoute<string, RouteConfig>(\n Object.assign({}, restConfig, {\n middleware: mws,\n tags: [...tags, this.scope],\n security,\n }) as any,\n );\n }\n\n /** Like getRouteConfigs but adds HTML response schema for JSX rendering. */\n getJSXRouteConfigs<RouteConfig extends IAuthRouteConfig>(opts: { configs: RouteConfig }) {\n const { restConfig, security, mws } = this.buildRouteMiddlewares(opts);\n const { responses, tags = [] } = restConfig;\n\n // Same reassembled-vs-RouteConfig boundary as getRouteConfigs above.\n return createRoute<string, RouteConfig>(\n Object.assign({}, restConfig, {\n middleware: mws,\n responses: Object.assign(\n {},\n OpenApiResponses.htmlResponse({ description: 'HTML page' }),\n responses,\n ),\n tags: [...tags, this.scope],\n security,\n }) as any,\n );\n }\n /** Override to register routes using bindRoute or defineRoute. */\n abstract binding(): ValueOrPromise<void>;\n\n /** Creates a fluent binding for registering a route (call .to() to attach handler). */\n abstract bindRoute<RouteConfig extends IAuthRouteConfig>(opts: {\n configs: RouteConfig;\n }): IBindRouteOptions<RouteConfig, RouteEnv, RouteSchema, BasePath>;\n\n /** Defines and registers a route with its handler in a single call. */\n abstract defineRoute<RouteConfig extends IAuthRouteConfig, ResponseType = unknown>(opts: {\n configs: RouteConfig;\n handler: TRouteHandler<ResponseType, RouteEnv>;\n hook?: Hook<any, RouteEnv, string, ValueOrPromise<any>>;\n }): IDefineRouteOptions<RouteConfig, RouteEnv, RouteSchema, BasePath>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"abstract.js","sourceRoot":"","sources":["../../../../../src/base/controllers/rest/abstract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AAChF,OAAO,EAAE,YAAY,IAAI,cAAc,EAAE,MAAM,8DAA8D,CAAC;AAE9G,OAAO,EAAE,SAAS,IAAI,WAAW,EAAE,MAAM,wDAAwD,CAAC;AAClG,OAAO,EAAE,kBAAkB,EAAE,MAAM,mDAAmD,CAAC;AACvF,OAAO,EAAE,8BAA8B,EAAE,MAAM,uDAAuD,CAAC;AACvG,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAwB,MAAM,qCAAqC,CAAC;AAC5F,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE7D,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEnE,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAUrE,6FAA6F;AAC7F,eAAe,CAAC,eAAe,CAAC;IAC9B,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,IAAI,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACrD,CAAC,CAAC;AAEH,sGAAsG;AACtG,MAAM,YAAY,GAAG,CAAC,IAAsB,EAAW,EAAE;IACvD,OAAO,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC5C,CAAC,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C;QACvE,MAAM,EAAE,IAAI,GAAG,EAAE,EAAE,GAAG,UAAU,CAAC;QAEjC,mPAAmP;QACnP,OAAO,WAAW,CAChB,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,UAAU,EAAE;YAC5B,UAAU,EAAE,GAAG;YACf,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC;YAC3B,QAAQ;SACT,CAAQ,CACV,CAAC;IACJ,CAAC;IAED,4EAA4E;IAC5E,kBAAkB,CAAuC,IAA8B;QACrF,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC;QACvE,MAAM,EAAE,SAAS,EAAE,IAAI,GAAG,EAAE,EAAE,GAAG,UAAU,CAAC;QAE5C,qEAAqE;QACrE,OAAO,WAAW,CAChB,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,UAAU,EAAE;YAC5B,UAAU,EAAE,GAAG;YACf,SAAS,EAAE,MAAM,CAAC,MAAM,CACtB,EAAE,EACF,gBAAgB,CAAC,YAAY,CAAC,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC,EAC3D,SAAS,CACV;YACD,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC;YAC3B,QAAQ;SACT,CAAQ,CACV,CAAC;IACJ,CAAC;CAeF","sourcesContent":["import { AuthenticationModes } from '@/base/auth/authenticate/common/constants';\nimport { authenticate as authenticateFn } from '@/base/auth/authenticate/middlewares/authenticate.middleware';\nimport type { IAuthorizationSpec } from '@/base/auth/authorize/common/types';\nimport { authorize as authorizeFn } from '@/base/auth/authorize/middlewares/authorize.middleware';\nimport { FormBodyMiddleware } from '@/base/middlewares/form-body/form-body.middleware';\nimport { AuthenticationStrategyRegistry } from '@/base/auth/authenticate/strategies/strategy-registry';\nimport { DroppedRouteDecorators } from '@/base/metadata/routes/common';\nimport { MetadataRegistry } from '@/helpers/inversion/registry';\nimport { RoutePathScopes, type TRoutePathScope } from '@/base/controllers/common/constants';\nimport { OpenApiResponses } from '@/base/models/common';\nimport type { Hook } from '@hono/zod-openapi';\nimport { createRoute, OpenAPIHono } from '@hono/zod-openapi';\nimport type { ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport { BaseHelper, getError } from '@venizia/ignis-helpers/core';\nimport type { Env, Schema } from 'hono';\nimport { RouterFactories } from '@/base/applications/router-factory';\nimport type {\n IAuthRouteConfig,\n IBindRouteOptions,\n IController,\n IControllerOptions,\n IDefineRouteOptions,\n TRouteHandler,\n} from '../common/types';\n\n// Loading this module makes the application's routers `OpenAPIHono` (see `RouterFactories`).\nRouterFactories.registerOpenApi({\n factory: ({ strict }) => new OpenAPIHono({ strict }),\n});\n\n/** True for a route path carrying a path parameter, in either supported syntax: `/{id}` or `/:id`. */\nconst hasPathParam = (opts: { path: string }): boolean => {\n return /\\{[^}]+\\}|:[^/]+/.test(opts.path);\n};\n\n/** Abstract base class for all REST controllers, providing route registration and auth middleware integration. */\nexport abstract class AbstractRestController<\n RouteEnv extends Env = Env,\n RouteSchema extends Schema = {},\n BasePath extends string = '/',\n ConfigurableOptions extends object = {},\n Definitions extends Record<string, IAuthRouteConfig> = Record<string, IAuthRouteConfig>,\n>\n extends BaseHelper\n implements IController<RouteEnv, RouteSchema, BasePath, ConfigurableOptions>\n{\n isConfigured = false;\n router: OpenAPIHono<RouteEnv, RouteSchema, BasePath>;\n path: string;\n definitions: Definitions;\n\n constructor(opts: IControllerOptions) {\n super(opts);\n const { isStrict = true } = opts;\n\n const decoratorMetadata = MetadataRegistry.getInstance().getControllerMetadata({\n target: new.target,\n });\n const resolvedPath = decoratorMetadata?.path ?? opts.path;\n\n if (!resolvedPath) {\n throw getError({\n message: `[${new.target.name}] Controller path is required. Provide path via @controller decorator or constructor options.`,\n });\n }\n\n this.path = resolvedPath;\n\n this.router = new OpenAPIHono<RouteEnv, RouteSchema, BasePath>({\n strict: isStrict,\n defaultHook: (result, _context) => {\n if (!result.success) {\n throw result.error;\n }\n },\n });\n }\n\n /** Returns the OpenAPIHono router instance for this controller. */\n getRouter() {\n return this.router;\n }\n\n /** Registers decorator-defined routes from the metadata registry; `paths` selects them by shape - see the two-phase call in {@link configure}. */\n registerRoutesFromRegistry(opts?: { paths?: TRoutePathScope }): void {\n const { paths = RoutePathScopes.ALL } = opts ?? {};\n\n const logger = this.logger.for(this.registerRoutesFromRegistry.name);\n DroppedRouteDecorators.report({ logger });\n\n const routes = MetadataRegistry.getInstance().getRoutes({\n target: Object.getPrototypeOf(this),\n });\n\n if (!routes?.size) {\n return;\n }\n\n const routeDefs = routes.entries();\n\n for (const [methodName, routeConfigs] of routeDefs) {\n if (\n paths !== RoutePathScopes.ALL &&\n hasPathParam({ path: routeConfigs.path }) !== (paths === RoutePathScopes.PARAM)\n ) {\n continue;\n }\n\n // Dynamic dispatch by decorator-recorded method name - the controller class has no static index signature, so this read cannot be typed narrower than `unknown`.\n const handler = (this as Record<string | symbol, unknown>)[methodName];\n\n if (typeof handler !== 'function') {\n logger.warn('Route method \"%s\" not found on controller', String(methodName));\n continue;\n }\n\n this.bindRoute({ configs: routeConfigs }).to({\n handler: (handler as TRouteHandler<unknown, RouteEnv>).bind(this),\n });\n }\n }\n\n /** Configures the controller by binding all routes and registering decorator-based routes. Idempotent. */\n async configure(\n opts?: ConfigurableOptions,\n ): Promise<OpenAPIHono<RouteEnv, RouteSchema, BasePath>> {\n if (this.isConfigured) {\n return this.router;\n }\n\n const t = performance.now();\n const logger = this.logger.for(this.configure.name);\n\n const configureOptions = opts ?? {};\n logger.info('START | Binding controller | Options: %j', configureOptions);\n\n // Hono matches in registration order, so registration runs by SHAPE not source: every static path first, then binding()'s routes, then decorator param routes last (`/{id}` early would eat `/count`).\n this.registerRoutesFromRegistry({ paths: RoutePathScopes.STATIC });\n await this.binding();\n this.registerRoutesFromRegistry({ paths: RoutePathScopes.PARAM });\n\n this.isConfigured = true;\n logger.info('DONE | Binding controller | Took: %s (ms)', performance.now() - t);\n\n return this.router;\n }\n\n /** @internal Builds auth + custom middlewares and security specs from route config. */\n buildRouteMiddlewares<RouteConfig extends IAuthRouteConfig>(opts: { configs: RouteConfig }) {\n const { authenticate = {}, authorize, ...restConfig } = opts.configs;\n const { strategies = [], mode = AuthenticationModes.ANY } = authenticate;\n\n // Boot-time and NON-fatal: names a misspelled strategy at error level instead of leaving it as\n // a 401 nobody can explain. Deliberately not a throw - `AuthControllerFactory.define` hard-codes `jwt`\n // on four routes, and ANY mode tolerates a strategy that does not resolve, so failing here would\n // stop applications booting that work today. `assertRegistered` is there for an application that\n // does want the hard failure.\n AuthenticationStrategyRegistry.getInstance().reportUnregistered({\n names: strategies,\n scope: this.constructor.name,\n });\n\n const security = strategies.map((strategy: string) => ({ [strategy]: [] }));\n const mws: ReturnType<typeof authenticateFn>[] = [];\n\n if (strategies.length > 0) {\n mws.push(authenticateFn({ strategies, mode }));\n }\n\n // Inject authorize middleware AFTER authenticate\n if (authorize) {\n const specs: IAuthorizationSpec[] = Array.isArray(authorize) ? authorize : [authorize];\n\n for (const spec of specs) {\n mws.push(authorizeFn({ spec }));\n }\n }\n\n const configuredMiddleware = restConfig.middleware;\n const extraMws = Array.isArray(configuredMiddleware)\n ? configuredMiddleware\n : [configuredMiddleware];\n\n for (const mw of extraMws) {\n if (!mw) {\n continue;\n }\n\n mws.push(mw);\n }\n\n // Last: an application middleware and any size check run before the body is read.\n if (FormBodyMiddleware.hasFormBody({ content: restConfig.request?.body?.content })) {\n mws.push(FormBodyMiddleware.read);\n }\n\n return { restConfig, security, mws };\n }\n\n /** Processes route config, injecting auth middleware and OpenAPI security specs. */\n getRouteConfigs<RouteConfig extends IAuthRouteConfig>(opts: { configs: RouteConfig }) {\n const { restConfig, security, mws } = this.buildRouteMiddlewares(opts);\n const { tags = [] } = restConfig;\n\n // `restConfig` already omitted `authenticate`/`authorize` (this library's fields, not Hono's `createRoute` ones); reassembled with the injected middleware/tags/security it no longer structurally overlaps RouteConfig enough to assert directly.\n return createRoute<string, RouteConfig>(\n Object.assign({}, restConfig, {\n middleware: mws,\n tags: [...tags, this.scope],\n security,\n }) as any,\n );\n }\n\n /** Like getRouteConfigs but adds HTML response schema for JSX rendering. */\n getJSXRouteConfigs<RouteConfig extends IAuthRouteConfig>(opts: { configs: RouteConfig }) {\n const { restConfig, security, mws } = this.buildRouteMiddlewares(opts);\n const { responses, tags = [] } = restConfig;\n\n // Same reassembled-vs-RouteConfig boundary as getRouteConfigs above.\n return createRoute<string, RouteConfig>(\n Object.assign({}, restConfig, {\n middleware: mws,\n responses: Object.assign(\n {},\n OpenApiResponses.htmlResponse({ description: 'HTML page' }),\n responses,\n ),\n tags: [...tags, this.scope],\n security,\n }) as any,\n );\n }\n /** Override to register routes using bindRoute or defineRoute. */\n abstract binding(): ValueOrPromise<void>;\n\n /** Creates a fluent binding for registering a route (call .to() to attach handler). */\n abstract bindRoute<RouteConfig extends IAuthRouteConfig>(opts: {\n configs: RouteConfig;\n }): IBindRouteOptions<RouteConfig, RouteEnv, RouteSchema, BasePath>;\n\n /** Defines and registers a route with its handler in a single call. */\n abstract defineRoute<RouteConfig extends IAuthRouteConfig, ResponseType = unknown>(opts: {\n configs: RouteConfig;\n handler: TRouteHandler<ResponseType, RouteEnv>;\n hook?: Hook<any, RouteEnv, string, ValueOrPromise<any>>;\n }): IDefineRouteOptions<RouteConfig, RouteEnv, RouteSchema, BasePath>;\n}\n"]}
|