@venizia/ignis-kernel 0.4.8-3 → 0.4.8-5

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.
Files changed (45) hide show
  1. package/dist/esm/base/applications/body-limit.d.ts +29 -0
  2. package/dist/esm/base/applications/body-limit.js +49 -0
  3. package/dist/esm/base/applications/body-limit.js.map +1 -0
  4. package/dist/esm/base/applications/common/types/middlewares.d.ts +8 -2
  5. package/dist/esm/base/applications/common/types/middlewares.js.map +1 -1
  6. package/dist/esm/base/applications/cors.d.ts +19 -10
  7. package/dist/esm/base/applications/cors.js +51 -21
  8. package/dist/esm/base/applications/cors.js.map +1 -1
  9. package/dist/esm/base/applications/index.d.ts +1 -0
  10. package/dist/esm/base/applications/index.js +1 -0
  11. package/dist/esm/base/applications/index.js.map +1 -1
  12. package/dist/esm/base/applications/rest.d.ts +2 -0
  13. package/dist/esm/base/applications/rest.js +15 -14
  14. package/dist/esm/base/applications/rest.js.map +1 -1
  15. package/dist/esm/base/auth/authenticate/common/types/jwt.d.ts +57 -24
  16. package/dist/esm/base/auth/authenticate/common/types/jwt.js.map +1 -1
  17. package/dist/esm/base/auth/authenticate/common/types/service.d.ts +3 -0
  18. package/dist/esm/base/auth/authenticate/common/types/service.js.map +1 -1
  19. package/dist/esm/base/auth/authenticate/providers/authentication.provider.js +5 -0
  20. package/dist/esm/base/auth/authenticate/providers/authentication.provider.js.map +1 -1
  21. package/dist/esm/base/controllers/factory/controller.d.ts +7 -0
  22. package/dist/esm/base/controllers/factory/crud/abstract.d.ts +11 -0
  23. package/dist/esm/base/controllers/factory/crud/abstract.js +7 -0
  24. package/dist/esm/base/controllers/factory/crud/abstract.js.map +1 -1
  25. package/dist/esm/base/controllers/factory/crud/persistable.js +2 -0
  26. package/dist/esm/base/controllers/factory/crud/persistable.js.map +1 -1
  27. package/dist/esm/base/controllers/factory/crud/readable.js +5 -0
  28. package/dist/esm/base/controllers/factory/crud/readable.js.map +1 -1
  29. package/dist/esm/base/controllers/factory/definition.d.ts +16 -16
  30. package/dist/esm/base/middlewares/app-error/app-error.middleware.d.ts +14 -0
  31. package/dist/esm/base/middlewares/app-error/app-error.middleware.js +68 -2
  32. package/dist/esm/base/middlewares/app-error/app-error.middleware.js.map +1 -1
  33. package/dist/esm/base/middlewares/app-error/zod.handler.js +4 -1
  34. package/dist/esm/base/middlewares/app-error/zod.handler.js.map +1 -1
  35. package/dist/esm/base/repositories/common/index.d.ts +1 -0
  36. package/dist/esm/base/repositories/common/index.js +1 -0
  37. package/dist/esm/base/repositories/common/index.js.map +1 -1
  38. package/dist/esm/base/repositories/common/request-filter-guard.d.ts +68 -0
  39. package/dist/esm/base/repositories/common/request-filter-guard.js +94 -0
  40. package/dist/esm/base/repositories/common/request-filter-guard.js.map +1 -0
  41. package/dist/esm/base/repositories/core/abstract.d.ts +16 -0
  42. package/dist/esm/base/repositories/core/abstract.js +26 -0
  43. package/dist/esm/base/repositories/core/abstract.js.map +1 -1
  44. package/dist/esm/base/repositories/query-schemas/index.d.ts +6 -6
  45. package/package.json +3 -3
@@ -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,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,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
+ {"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;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F,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;AAGj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AC;QAEH,IAAI,QAAQ,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YACjC,OAAO,QAAQ,CAAC,KAAK,CAAC;QACxB,CAAC;QAED,MAAM,EAAE,KAAK,EAAE,GAAG,QAAQ,CAAC;QAE3B,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 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,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,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;gBAEvD,OAAO,IAAI,CAAC,OAAO,CAAc;oBAC/B,OAAO;oBACP,MAAM,EAAE,eAAe,CAAC,MAAM;oBAC9B,OAAO;iBACR,CAAC,CAAC;YACL,CAAC;SACF,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACzD,CAAC;IAED;;;OAGG;IACH,oBAAoB,CAAC,IAAqC;QACxD,MAAM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,MAAM,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,EAAmC,CAAC;YACzE,IAAI,GAAG,MAAM,CAAC;YACd,wKAAwK;QAC1K,CAAC;QAAC,MAAM,CAAC;YACP,IAAI,GAAG,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,CAAC,gBAAgB,CAAC;YACrC,OAAO;YACP,KAAK,EAAE,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE;SACxD,CAAC,CAAC;QAEH,IAAI,QAAQ,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YACjC,OAAO,QAAQ,CAAC,KAAK,CAAC;QACxB,CAAC;QAED,MAAM,EAAE,KAAK,EAAE,GAAG,QAAQ,CAAC;QAE3B,IAAI,CAAC,mBAAmB,CAAC,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;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,7 @@ 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
+ this.assertRequestFilter({ filter });
69
73
  const baseWhere = await this.getBaseWhere({ context });
70
74
  // `repository.findById` takes no where, so a scoped read goes through `findOne` - the same
71
75
  // substrate every family's findById delegates to - and answers null on an out-of-scope id.
@@ -93,6 +97,7 @@ export class ReadableCrudController extends AbstractCrudController {
93
97
  async findOne(opts) {
94
98
  const { context } = opts;
95
99
  const { filter = {} } = context.req.valid('query');
100
+ this.assertRequestFilter({ filter });
96
101
  const baseWhere = await this.getBaseWhere({ context });
97
102
  const scopedFilter = baseWhere
98
103
  ? { ...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,KAEl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,KAAK,EAAE,aAAa,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE;YACzE,CAAC,CAAC,MAAM,CAAC;QAEX,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC;YAC5B,KAAK,EAAE,SAAS;YAChB,IAAI,EAAE,YAAY;YAClB,IAAI,EAAE,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 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,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;QAE7E,8FAA8F;QAC9F,IAAI,CAAC,mBAAmB,CAAC,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;Q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EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE;YACzE,CAAC,CAAC,MAAM,CAAC;QAEX,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC;YAC5B,KAAK,EAAE,SAAS;YAChB,IAAI,EAAE,YAAY;YAClB,IAAI,EAAE,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 this.assertRequestFilter({ filter });\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>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>]> | z.ZodOptional<z.ZodUnion<readonly [z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, 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>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, 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>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, 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>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, 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>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, 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>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, 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>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, 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>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>]> | z.ZodOptional<z.ZodUnion<readonly [z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, 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>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, 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>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, 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>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, 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>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, 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>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, 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>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, 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>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, 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>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, 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: {
@@ -77,6 +77,20 @@ export declare class BaseAppErrorMiddleware extends BaseHelper implements IProvi
77
77
  private logError;
78
78
  /** Only an intentional error's message is a catalog template; every other branch writes its own text, so it passes through as is. */
79
79
  private renderMessage;
80
+ /**
81
+ * The `extra` a response carries. It is whatever a throw site attached, so it goes through the same redaction the log
82
+ * line uses (always masking in production, whatever the logger switch says), and a server error (5xx) in production
83
+ * carries none: the log has it, a client has no use for it.
84
+ */
85
+ private renderExtra;
86
+ /**
87
+ * What a production server error still carries from `extra`: the correlation ids support needs, `requestId` and
88
+ * `upstreamRequestIds`, and nothing else. Only short strings count (a list of them for the chain), so the allowance
89
+ * cannot carry anything but an id.
90
+ */
91
+ private pickCorrelationIds;
92
+ /** The `args` a throw site passes to its message template are data the client may see; secret-shaped keys in them are masked in production, whatever the logger switch says. */
93
+ private renderNormalized;
80
94
  value(): ErrorHandler;
81
95
  }
82
96
  //# sourceMappingURL=app-error.middleware.d.ts.map
@@ -247,6 +247,72 @@ export class BaseAppErrorMiddleware extends BaseHelper {
247
247
  }
248
248
  return text;
249
249
  }
250
+ /**
251
+ * The `extra` a response carries. It is whatever a throw site attached, so it goes through the same redaction the log
252
+ * line uses (always masking in production, whatever the logger switch says), and a server error (5xx) in production
253
+ * carries none: the log has it, a client has no use for it.
254
+ */
255
+ renderExtra(opts) {
256
+ const { error, statusCode, isProduction } = opts;
257
+ if (!('extra' in error) || error.extra === undefined) {
258
+ return undefined;
259
+ }
260
+ if (isProduction && statusCode >= 500) {
261
+ return this.pickCorrelationIds({ extra: error.extra });
262
+ }
263
+ const safe = RedactUtility.toJsonSafe({ value: error.extra, force: isProduction });
264
+ // A value `context.json` would refuse (a BigInt) becomes text here, so the authored status survives it.
265
+ try {
266
+ // A nested Error keeps its `stack` through the redaction (the log wants it); a client in production does not get one.
267
+ const text = JSON.stringify(safe, (key, entry) => {
268
+ if (isProduction && key === 'stack') {
269
+ return undefined;
270
+ }
271
+ return typeof entry === 'bigint' ? entry.toString() : entry;
272
+ });
273
+ return text === undefined ? undefined : JSON.parse(text);
274
+ // eslint-disable-next-line venizia/no-silent-catch -- the marker returned below is the report: the response carries it where the value would have been
275
+ }
276
+ catch {
277
+ return '[unrenderable]';
278
+ }
279
+ }
280
+ /**
281
+ * What a production server error still carries from `extra`: the correlation ids support needs, `requestId` and
282
+ * `upstreamRequestIds`, and nothing else. Only short strings count (a list of them for the chain), so the allowance
283
+ * cannot carry anything but an id.
284
+ */
285
+ pickCorrelationIds(opts) {
286
+ const { extra } = opts;
287
+ if (typeof extra !== 'object' || extra === null) {
288
+ return undefined;
289
+ }
290
+ const source = extra;
291
+ const isId = (value) => typeof value === 'string' && value.length <= 128;
292
+ const picked = {};
293
+ if (isId(source.requestId)) {
294
+ picked.requestId = source.requestId;
295
+ }
296
+ const chain = source.upstreamRequestIds;
297
+ if (Array.isArray(chain) && chain.length <= 32 && chain.every(isId)) {
298
+ picked.upstreamRequestIds = chain;
299
+ }
300
+ return Object.keys(picked).length > 0 ? picked : undefined;
301
+ }
302
+ /** The `args` a throw site passes to its message template are data the client may see; secret-shaped keys in them are masked in production, whatever the logger switch says. */
303
+ renderNormalized(opts) {
304
+ const { normalized, isProduction } = opts;
305
+ if (!isProduction || !normalized.args || Object.keys(normalized.args).length === 0) {
306
+ return normalized;
307
+ }
308
+ return {
309
+ ...normalized,
310
+ args: RedactUtility.redactSecrets({
311
+ value: normalized.args,
312
+ force: true,
313
+ }),
314
+ };
315
+ }
250
316
  value() {
251
317
  return async (error, context) => {
252
318
  const requestId = context.get(REQUEST_ID_KEY);
@@ -274,9 +340,9 @@ export class BaseAppErrorMiddleware extends BaseHelper {
274
340
  const rs = {
275
341
  message: this.renderMessage({ resolved, isProduction, requestId }),
276
342
  statusCode,
277
- normalized,
343
+ normalized: this.renderNormalized({ normalized, isProduction }),
278
344
  requestId,
279
- extra: 'extra' in error ? error?.extra : undefined,
345
+ extra: this.renderExtra({ error, statusCode, isProduction }),
280
346
  details: {
281
347
  url: context.req.url,
282
348
  path: context.req.path,