@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.
Files changed (75) 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/application.d.ts +3 -4
  5. package/dist/esm/base/applications/common/types/application.js.map +1 -1
  6. package/dist/esm/base/applications/common/types/middlewares.d.ts +7 -1
  7. package/dist/esm/base/applications/common/types/middlewares.js.map +1 -1
  8. package/dist/esm/base/applications/index.d.ts +1 -0
  9. package/dist/esm/base/applications/index.js +1 -0
  10. package/dist/esm/base/applications/index.js.map +1 -1
  11. package/dist/esm/base/applications/rest.d.ts +15 -7
  12. package/dist/esm/base/applications/rest.js +67 -21
  13. package/dist/esm/base/applications/rest.js.map +1 -1
  14. package/dist/esm/base/applications/router-factory.d.ts +27 -0
  15. package/dist/esm/base/applications/router-factory.js +28 -0
  16. package/dist/esm/base/applications/router-factory.js.map +1 -0
  17. package/dist/esm/base/auth/authenticate/common/types/jwt.d.ts +59 -24
  18. package/dist/esm/base/auth/authenticate/common/types/jwt.js.map +1 -1
  19. package/dist/esm/base/auth/authenticate/common/types/service.d.ts +3 -0
  20. package/dist/esm/base/auth/authenticate/common/types/service.js.map +1 -1
  21. package/dist/esm/base/auth/authenticate/providers/authentication.provider.js +5 -0
  22. package/dist/esm/base/auth/authenticate/providers/authentication.provider.js.map +1 -1
  23. package/dist/esm/base/controllers/factory/controller.d.ts +7 -0
  24. package/dist/esm/base/controllers/factory/crud/abstract.d.ts +11 -0
  25. package/dist/esm/base/controllers/factory/crud/abstract.js +7 -0
  26. package/dist/esm/base/controllers/factory/crud/abstract.js.map +1 -1
  27. package/dist/esm/base/controllers/factory/crud/persistable.js +2 -0
  28. package/dist/esm/base/controllers/factory/crud/persistable.js.map +1 -1
  29. package/dist/esm/base/controllers/factory/crud/readable.js +6 -0
  30. package/dist/esm/base/controllers/factory/crud/readable.js.map +1 -1
  31. package/dist/esm/base/controllers/factory/definition.d.ts +16 -16
  32. package/dist/esm/base/controllers/rest/abstract.js +5 -0
  33. package/dist/esm/base/controllers/rest/abstract.js.map +1 -1
  34. package/dist/esm/base/datasources/abstract.d.ts +69 -2
  35. package/dist/esm/base/datasources/abstract.js +186 -1
  36. package/dist/esm/base/datasources/abstract.js.map +1 -1
  37. package/dist/esm/base/datasources/common/types.d.ts +60 -1
  38. package/dist/esm/base/datasources/common/types.js +14 -0
  39. package/dist/esm/base/datasources/common/types.js.map +1 -1
  40. package/dist/esm/base/datasources/opening-handles.d.ts +8 -0
  41. package/dist/esm/base/datasources/opening-handles.js +8 -0
  42. package/dist/esm/base/datasources/opening-handles.js.map +1 -0
  43. package/dist/esm/base/metadata/persistents.js +15 -1
  44. package/dist/esm/base/metadata/persistents.js.map +1 -1
  45. package/dist/esm/base/middlewares/app-error/app-error.middleware.d.ts +14 -0
  46. package/dist/esm/base/middlewares/app-error/app-error.middleware.js +80 -3
  47. package/dist/esm/base/middlewares/app-error/app-error.middleware.js.map +1 -1
  48. package/dist/esm/base/middlewares/app-error/common/types.d.ts +10 -8
  49. package/dist/esm/base/middlewares/app-error/common/types.js.map +1 -1
  50. package/dist/esm/base/middlewares/app-error/database.handler.js +14 -14
  51. package/dist/esm/base/middlewares/app-error/database.handler.js.map +1 -1
  52. package/dist/esm/base/middlewares/app-error/index.d.ts +2 -0
  53. package/dist/esm/base/middlewares/app-error/index.js +1 -0
  54. package/dist/esm/base/middlewares/app-error/index.js.map +1 -1
  55. package/dist/esm/base/middlewares/app-error/postgres-errors.d.ts +20 -0
  56. package/dist/esm/base/middlewares/app-error/postgres-errors.js +74 -0
  57. package/dist/esm/base/middlewares/app-error/postgres-errors.js.map +1 -0
  58. package/dist/esm/base/middlewares/app-error/zod.handler.js +4 -1
  59. package/dist/esm/base/middlewares/app-error/zod.handler.js.map +1 -1
  60. package/dist/esm/base/repositories/common/index.d.ts +1 -0
  61. package/dist/esm/base/repositories/common/index.js +1 -0
  62. package/dist/esm/base/repositories/common/index.js.map +1 -1
  63. package/dist/esm/base/repositories/common/request-filter-guard.d.ts +118 -0
  64. package/dist/esm/base/repositories/common/request-filter-guard.js +179 -0
  65. package/dist/esm/base/repositories/common/request-filter-guard.js.map +1 -0
  66. package/dist/esm/base/repositories/core/abstract.d.ts +16 -0
  67. package/dist/esm/base/repositories/core/abstract.js +26 -0
  68. package/dist/esm/base/repositories/core/abstract.js.map +1 -1
  69. package/dist/esm/base/repositories/query-schemas/index.d.ts +6 -6
  70. package/dist/esm/helpers/inversion/common/types/persistence.d.ts +3 -1
  71. package/dist/esm/helpers/inversion/common/types/persistence.js.map +1 -1
  72. package/dist/esm/repository.d.ts +2 -0
  73. package/dist/esm/repository.js +2 -0
  74. package/dist/esm/repository.js.map +1 -1
  75. package/package.json +5 -5
@@ -0,0 +1,29 @@
1
+ import type { Context, MiddlewareHandler } from 'hono';
2
+ /**
3
+ * The request body limit: the default every route gets, and the limit one route sets for itself.
4
+ *
5
+ * The application installs the default (`DEFAULT_MAX_SIZE`) ahead of every other middleware, so no route reads
6
+ * a body over it. A route that takes larger bodies (an upload, an import) puts `BodyLimits.route({ maxSize })`
7
+ * in its `middleware`: the default steps aside for that route and this limit answers instead. The limit counts
8
+ * the bytes that arrive, so a chunked body with no `Content-Length` is held to it too.
9
+ */
10
+ export declare class BodyLimits {
11
+ /** The default of every route: 5 MiB. */
12
+ static readonly DEFAULT_MAX_SIZE: number;
13
+ /** The limiter itself: a body over `maxSize` bytes is the framework's 413, or the `onError` answer. */
14
+ static limiter(opts: {
15
+ maxSize: number;
16
+ onError?: (context: Context) => Response | Promise<Response>;
17
+ }): MiddlewareHandler;
18
+ /**
19
+ * The limit of one route, to put in the route's `middleware`. It replaces the default for this route, larger or smaller.
20
+ * A body larger than the host accepts at all (`configs.server.maxRequestBodySize`, Bun's own cap) is still refused there.
21
+ */
22
+ static route(opts: {
23
+ maxSize: number;
24
+ onError?: (context: Context) => Response | Promise<Response>;
25
+ }): MiddlewareHandler;
26
+ /** Whether the route this request matched carries its own limit, so the default stands aside. */
27
+ static hasRouteLimit(context: Context): boolean;
28
+ }
29
+ //# sourceMappingURL=body-limit.d.ts.map
@@ -0,0 +1,49 @@
1
+ import { getError } from '@venizia/ignis-helpers/core';
2
+ import { bodyLimit } from 'hono/body-limit';
3
+ import { RequestErrors } from '../middlewares/common/errors.js';
4
+ /** Marks a middleware as the body limit of ONE route. A registry symbol, so two installed copies of this package still read each other's marks. */
5
+ const ROUTE_BODY_LIMIT = Symbol.for('@venizia/ignis-kernel/route-body-limit');
6
+ /**
7
+ * The request body limit: the default every route gets, and the limit one route sets for itself.
8
+ *
9
+ * The application installs the default (`DEFAULT_MAX_SIZE`) ahead of every other middleware, so no route reads
10
+ * a body over it. A route that takes larger bodies (an upload, an import) puts `BodyLimits.route({ maxSize })`
11
+ * in its `middleware`: the default steps aside for that route and this limit answers instead. The limit counts
12
+ * the bytes that arrive, so a chunked body with no `Content-Length` is held to it too.
13
+ */
14
+ export class BodyLimits {
15
+ /** The default of every route: 5 MiB. */
16
+ static { this.DEFAULT_MAX_SIZE = 5 * 1024 * 1024; }
17
+ /** The limiter itself: a body over `maxSize` bytes is the framework's 413, or the `onError` answer. */
18
+ static limiter(opts) {
19
+ const { maxSize, onError } = opts;
20
+ return bodyLimit({
21
+ maxSize,
22
+ onError: onError ??
23
+ (() => {
24
+ throw getError({
25
+ error: RequestErrors.BODY_TOO_LARGE,
26
+ message: `Request body exceeds the maximum of ${maxSize} bytes`,
27
+ });
28
+ }),
29
+ });
30
+ }
31
+ /**
32
+ * The limit of one route, to put in the route's `middleware`. It replaces the default for this route, larger or smaller.
33
+ * A body larger than the host accepts at all (`configs.server.maxRequestBodySize`, Bun's own cap) is still refused there.
34
+ */
35
+ static route(opts) {
36
+ const { maxSize } = opts;
37
+ if (typeof maxSize !== 'number' || !Number.isFinite(maxSize) || maxSize < 0) {
38
+ throw getError({
39
+ message: `[BodyLimits.route] maxSize must be a non-negative number of bytes | value: ${String(maxSize)}`,
40
+ });
41
+ }
42
+ return Object.assign(BodyLimits.limiter(opts), { [ROUTE_BODY_LIMIT]: maxSize });
43
+ }
44
+ /** Whether the route this request matched carries its own limit, so the default stands aside. */
45
+ static hasRouteLimit(context) {
46
+ return context.req.matchedRoutes.some((matched) => matched.handler[ROUTE_BODY_LIMIT] !== undefined);
47
+ }
48
+ }
49
+ //# sourceMappingURL=body-limit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"body-limit.js","sourceRoot":"","sources":["../../../../src/base/applications/body-limit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEvD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAE7D,mJAAmJ;AACnJ,MAAM,gBAAgB,GAAkB,MAAM,CAAC,GAAG,CAChD,wCAAwC,CAChC,CAAC;AAEX;;;;;;;GAOG;AACH,MAAM,OAAO,UAAU;IACrB,yCAAyC;aACzB,qBAAgB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;IAEnD,uGAAuG;IACvG,MAAM,CAAC,OAAO,CAAC,IAGd;QACC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;QAElC,OAAO,SAAS,CAAC;YACf,OAAO;YACP,OAAO,EACL,OAAO;gBACP,CAAC,GAAG,EAAE;oBACJ,MAAM,QAAQ,CAAC;wBACb,KAAK,EAAE,aAAa,CAAC,cAAc;wBACnC,OAAO,EAAE,uCAAuC,OAAO,QAAQ;qBAChE,CAAC,CAAC;gBACL,CAAC,CAAC;SACL,CAAC,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,KAAK,CAAC,IAGZ;QACC,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;QAEzB,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;YAC5E,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,8EAA8E,MAAM,CAAC,OAAO,CAAC,EAAE;aACzG,CAAC,CAAC;QACL,CAAC;QAED,OAAO,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,gBAAgB,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;IAClF,CAAC;IAED,iGAAiG;IACjG,MAAM,CAAC,aAAa,CAAC,OAAgB;QACnC,OAAO,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,CACnC,CAAC,OAAO,EAAE,EAAE,CACT,OAAO,CAAC,OAA8C,CAAC,gBAAgB,CAAC,KAAK,SAAS,CAC1F,CAAC;IACJ,CAAC","sourcesContent":["import { getError } from '@venizia/ignis-helpers/core';\nimport type { Context, MiddlewareHandler } from 'hono';\nimport { bodyLimit } from 'hono/body-limit';\nimport { RequestErrors } from '../middlewares/common/errors';\n\n/** Marks a middleware as the body limit of ONE route. A registry symbol, so two installed copies of this package still read each other's marks. */\nconst ROUTE_BODY_LIMIT: unique symbol = Symbol.for(\n '@venizia/ignis-kernel/route-body-limit',\n) as never;\n\n/**\n * The request body limit: the default every route gets, and the limit one route sets for itself.\n *\n * The application installs the default (`DEFAULT_MAX_SIZE`) ahead of every other middleware, so no route reads\n * a body over it. A route that takes larger bodies (an upload, an import) puts `BodyLimits.route({ maxSize })`\n * in its `middleware`: the default steps aside for that route and this limit answers instead. The limit counts\n * the bytes that arrive, so a chunked body with no `Content-Length` is held to it too.\n */\nexport class BodyLimits {\n /** The default of every route: 5 MiB. */\n static readonly DEFAULT_MAX_SIZE = 5 * 1024 * 1024;\n\n /** The limiter itself: a body over `maxSize` bytes is the framework's 413, or the `onError` answer. */\n static limiter(opts: {\n maxSize: number;\n onError?: (context: Context) => Response | Promise<Response>;\n }): MiddlewareHandler {\n const { maxSize, onError } = opts;\n\n return bodyLimit({\n maxSize,\n onError:\n onError ??\n (() => {\n throw getError({\n error: RequestErrors.BODY_TOO_LARGE,\n message: `Request body exceeds the maximum of ${maxSize} bytes`,\n });\n }),\n });\n }\n\n /**\n * The limit of one route, to put in the route's `middleware`. It replaces the default for this route, larger or smaller.\n * A body larger than the host accepts at all (`configs.server.maxRequestBodySize`, Bun's own cap) is still refused there.\n */\n static route(opts: {\n maxSize: number;\n onError?: (context: Context) => Response | Promise<Response>;\n }): MiddlewareHandler {\n const { maxSize } = opts;\n\n if (typeof maxSize !== 'number' || !Number.isFinite(maxSize) || maxSize < 0) {\n throw getError({\n message: `[BodyLimits.route] maxSize must be a non-negative number of bytes | value: ${String(maxSize)}`,\n });\n }\n\n return Object.assign(BodyLimits.limiter(opts), { [ROUTE_BODY_LIMIT]: maxSize });\n }\n\n /** Whether the route this request matched carries its own limit, so the default stands aside. */\n static hasRouteLimit(context: Context): boolean {\n return context.req.matchedRoutes.some(\n (matched) =>\n (matched.handler as unknown as Record<symbol, unknown>)[ROUTE_BODY_LIMIT] !== undefined,\n );\n }\n}\n"]}
@@ -1,6 +1,5 @@
1
- import type { OpenAPIHono } from '@hono/zod-openapi';
2
1
  import type { ValueOrPromise } from '@venizia/ignis-helpers/common';
3
- import type { Env, Schema } from 'hono';
2
+ import type { Env, Hono, Schema } from 'hono';
4
3
  import type { TControllerTransport } from '../../../controllers/common/constants.js';
5
4
  import type { IComponentMixin, IControllerMixin, IRepositoryMixin, IServiceMixin, IStaticServeMixin } from '../../../mixins/common/index.js';
6
5
  import type { TArtifactIndexInput } from './artifacts.js';
@@ -94,8 +93,8 @@ export interface IApplicationInfo {
94
93
  export interface IApplication<AppEnv extends Env = Env, AppSchema extends Schema = Schema, BasePath extends string = '/'> {
95
94
  getProjectRoot(): string;
96
95
  getProjectConfigs(): IApplicationConfigs;
97
- getServer(): OpenAPIHono<AppEnv, AppSchema, BasePath>;
98
- getRootRouter(): OpenAPIHono<AppEnv, AppSchema, BasePath>;
96
+ getServer(): Hono<AppEnv, AppSchema, BasePath>;
97
+ getRootRouter(): Hono<AppEnv, AppSchema, BasePath>;
99
98
  setupMiddlewares(): ValueOrPromise<void>;
100
99
  initialize(): ValueOrPromise<void>;
101
100
  }
@@ -1 +1 @@
1
- {"version":3,"file":"application.js","sourceRoot":"","sources":["../../../../../../src/base/applications/common/types/application.ts"],"names":[],"mappings":"","sourcesContent":["import type { OpenAPIHono } from '@hono/zod-openapi';\nimport type { ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport type { Env, Schema } from 'hono';\nimport type { TControllerTransport } from '../../../controllers/common/constants';\nimport type {\n IComponentMixin,\n IControllerMixin,\n IRepositoryMixin,\n IServiceMixin,\n IStaticServeMixin,\n} from '../../../mixins/common';\nimport type { TArtifactIndexInput } from './artifacts';\nimport type { IMiddlewareConfigs } from './middlewares';\n\n/** No `host`/`port`: a browser Worker has neither, and carrying them here made one silently configured with `localhost:3000`. `@venizia/ignis` widens this shape with both - see its `IServerApplicationConfigs`. */\nexport interface IApplicationConfigs {\n path: {\n base: string;\n\n /**\n * Whether `/users` and `/users/` are different routes; `false` answers both. Under `false`,\n * declare routes without a trailing slash: a route declared as `/users/` answers neither\n * `/users` nor `/users/`. The type requires it; omitting it at run time means `true`.\n *\n * @default true\n */\n isStrict: boolean;\n };\n requestId?: { isStrict: boolean };\n favicon?: string;\n\n /** `environment` is the host's ambient environment name. Set it where there is none to read - a browser Worker - so the error middleware can tell \"no ambient environment\" from \"misconfigured\". Absent on a server, which reads `process.env.NODE_ENV`. */\n error?: { rootKey?: string; environment?: string };\n\n /** Generated indexes to register before `preConfigure` - one, or an array composed from several packages. */\n artifacts?: TArtifactIndexInput;\n\n /**\n * Registers every class a stereotype decorated, so an application lists none of its own. An absent\n * `artifacts` keeps meaning \"register nothing\", never \"register everything\". Both together\n * register the union, de-duplicated - which is how an application discovers its own classes and\n * still composes a library index.\n *\n * @default false\n */\n discoverArtifacts?: boolean;\n\n /** Boot-time checks. Without `binding`, nothing is verified, and hand registration and same-key override stay allowed. */\n bootChecks?: {\n binding?: {\n doVerify: boolean;\n allowManual: boolean;\n\n /** @default true */\n allowOverride: boolean;\n };\n\n /**\n * Two different classes deriving one binding key from their class name fail registration: in a\n * minified build the second would silently replace the first. A development setup that\n * re-registers after a hot reload re-evaluates modules, which looks the same; `true` there turns\n * the failure into a warning.\n */\n allowDerivedKeyCollision?: boolean;\n };\n\n /**\n * Controller transports to enable.\n *\n * @default ['rest']\n */\n transports?: TControllerTransport[];\n\n asyncContext?: { enable: boolean };\n debug?: {\n /** @default false */\n shouldShowRoutes?: boolean;\n };\n\n /** The framework installs `cors` (first) and `bodyLimit` (right after the request id). Every other key is typed only: wire it in `setupMiddlewares()`. */\n middlewares?: IMiddlewareConfigs;\n\n /**\n * How long `stop()` waits, in ms, for one datasource's `close()` before it logs and moves on; `0`\n * waits without limit.\n *\n * @default 10_000\n */\n dataSourceCloseTimeoutMs?: number;\n [key: string]: any;\n}\n\n/** Identity of an application, returned by `getAppInfo()`. Extra keys are allowed. */\nexport interface IApplicationInfo {\n name: string;\n version: string;\n description: string;\n author?: { name: string; email: string; url?: string };\n [extra: string | symbol]: any;\n}\n\n/** Exactly what EVERY host implements. `getServerHost`/`getServerPort`/`getServerAddress`/`start`/`stop` are not here on purpose - a browser Worker can implement none of them; they live on `@venizia/ignis`'s `IServerApplication`. */\nexport interface IApplication<\n AppEnv extends Env = Env,\n AppSchema extends Schema = Schema,\n BasePath extends string = '/',\n> {\n getProjectRoot(): string;\n getProjectConfigs(): IApplicationConfigs;\n getServer(): OpenAPIHono<AppEnv, AppSchema, BasePath>;\n getRootRouter(): OpenAPIHono<AppEnv, AppSchema, BasePath>;\n\n setupMiddlewares(): ValueOrPromise<void>;\n\n initialize(): ValueOrPromise<void>;\n}\n\n/** The REST application contract: `IApplication` plus the component, controller, repository, service and static-serve registration mixins. */\nexport interface IRestApplication\n extends\n IApplication,\n IComponentMixin,\n IControllerMixin,\n IRepositoryMixin,\n IServiceMixin,\n IStaticServeMixin {}\n"]}
1
+ {"version":3,"file":"application.js","sourceRoot":"","sources":["../../../../../../src/base/applications/common/types/application.ts"],"names":[],"mappings":"","sourcesContent":["import type { ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport type { Env, Hono, Schema } from 'hono';\nimport type { TControllerTransport } from '../../../controllers/common/constants';\nimport type {\n IComponentMixin,\n IControllerMixin,\n IRepositoryMixin,\n IServiceMixin,\n IStaticServeMixin,\n} from '../../../mixins/common';\nimport type { TArtifactIndexInput } from './artifacts';\nimport type { IMiddlewareConfigs } from './middlewares';\n\n/** No `host`/`port`: a browser Worker has neither, and carrying them here made one silently configured with `localhost:3000`. `@venizia/ignis` widens this shape with both - see its `IServerApplicationConfigs`. */\nexport interface IApplicationConfigs {\n path: {\n base: string;\n\n /**\n * Whether `/users` and `/users/` are different routes; `false` answers both. Under `false`,\n * declare routes without a trailing slash: a route declared as `/users/` answers neither\n * `/users` nor `/users/`. The type requires it; omitting it at run time means `true`.\n *\n * @default true\n */\n isStrict: boolean;\n };\n requestId?: { isStrict: boolean };\n favicon?: string;\n\n /** `environment` is the host's ambient environment name. Set it where there is none to read - a browser Worker - so the error middleware can tell \"no ambient environment\" from \"misconfigured\". Absent on a server, which reads `process.env.NODE_ENV`. */\n error?: { rootKey?: string; environment?: string };\n\n /** Generated indexes to register before `preConfigure` - one, or an array composed from several packages. */\n artifacts?: TArtifactIndexInput;\n\n /**\n * Registers every class a stereotype decorated, so an application lists none of its own. An absent\n * `artifacts` keeps meaning \"register nothing\", never \"register everything\". Both together\n * register the union, de-duplicated - which is how an application discovers its own classes and\n * still composes a library index.\n *\n * @default false\n */\n discoverArtifacts?: boolean;\n\n /** Boot-time checks. Without `binding`, nothing is verified, and hand registration and same-key override stay allowed. */\n bootChecks?: {\n binding?: {\n doVerify: boolean;\n allowManual: boolean;\n\n /** @default true */\n allowOverride: boolean;\n };\n\n /**\n * Two different classes deriving one binding key from their class name fail registration: in a\n * minified build the second would silently replace the first. A development setup that\n * re-registers after a hot reload re-evaluates modules, which looks the same; `true` there turns\n * the failure into a warning.\n */\n allowDerivedKeyCollision?: boolean;\n };\n\n /**\n * Controller transports to enable.\n *\n * @default ['rest']\n */\n transports?: TControllerTransport[];\n\n asyncContext?: { enable: boolean };\n debug?: {\n /** @default false */\n shouldShowRoutes?: boolean;\n };\n\n /** The framework installs `cors` (first) and `bodyLimit` (right after the request id). Every other key is typed only: wire it in `setupMiddlewares()`. */\n middlewares?: IMiddlewareConfigs;\n\n /**\n * How long `stop()` waits, in ms, for one datasource's `close()` before it logs and moves on; `0`\n * waits without limit.\n *\n * @default 10_000\n */\n dataSourceCloseTimeoutMs?: number;\n [key: string]: any;\n}\n\n/** Identity of an application, returned by `getAppInfo()`. Extra keys are allowed. */\nexport interface IApplicationInfo {\n name: string;\n version: string;\n description: string;\n author?: { name: string; email: string; url?: string };\n [extra: string | symbol]: any;\n}\n\n/** Exactly what EVERY host implements. `getServerHost`/`getServerPort`/`getServerAddress`/`start`/`stop` are not here on purpose - a browser Worker can implement none of them; they live on `@venizia/ignis`'s `IServerApplication`. */\nexport interface IApplication<\n AppEnv extends Env = Env,\n AppSchema extends Schema = Schema,\n BasePath extends string = '/',\n> {\n getProjectRoot(): string;\n getProjectConfigs(): IApplicationConfigs;\n getServer(): Hono<AppEnv, AppSchema, BasePath>;\n getRootRouter(): Hono<AppEnv, AppSchema, BasePath>;\n\n setupMiddlewares(): ValueOrPromise<void>;\n\n initialize(): ValueOrPromise<void>;\n}\n\n/** The REST application contract: `IApplication` plus the component, controller, repository, service and static-serve registration mixins. */\nexport interface IRestApplication\n extends\n IApplication,\n IComponentMixin,\n IControllerMixin,\n IRepositoryMixin,\n IServiceMixin,\n IStaticServeMixin {}\n"]}
@@ -39,7 +39,13 @@ export interface ICSRFOptions extends IBaseMiddlewareOptions {
39
39
  origin?: string | string[] | TIsAllowedOriginHandler;
40
40
  secFetchSite?: TSecFetchSite | TSecFetchSite[] | TIsAllowedSecFetchSiteHandler;
41
41
  }
42
- /** Options of the body limit middleware the framework installs right after the request id. `maxSize` is in bytes. */
42
+ /**
43
+ * Options of the body limit middleware the framework installs right after the request id. `maxSize` is in bytes.
44
+ *
45
+ * Unset (no `bodyLimit` key), every route gets `BodyLimits.DEFAULT_MAX_SIZE`, 5 MiB. Configured, it replaces
46
+ * the default (with a `path`, only the routes under it are limited). `enable: false` removes the limit. A route
47
+ * that takes larger bodies puts `BodyLimits.route({ maxSize })` in its `middleware`.
48
+ */
43
49
  export interface IBodyLimitOptions extends IBaseMiddlewareOptions {
44
50
  maxSize: number;
45
51
  onError?: (c: Context) => Response | Promise<Response>;
@@ -1 +1 @@
1
- {"version":3,"file":"middlewares.js","sourceRoot":"","sources":["../../../../../../src/base/applications/common/types/middlewares.ts"],"names":[],"mappings":"","sourcesContent":["import type { Context } from 'hono';\nimport type { IPRestrictionRules as IIPRestrictionRules } from 'hono/ip-restriction';\nimport { type SecFetchSiteValues, type TCompressEncoding } from '../constants';\n\n/** Options shared by every configurable middleware. Extra keys are allowed. */\nexport interface IBaseMiddlewareOptions {\n /**\n * Only `false` switches the middleware off.\n *\n * @default true\n */\n enable?: boolean;\n path?: string;\n [extra: string | symbol]: any;\n}\n\n/** Options of the compress middleware. Typed only: the framework does not install it. */\nexport interface ICompressOptions extends IBaseMiddlewareOptions {\n encoding: TCompressEncoding;\n threshold?: number;\n}\n\n/** Allowed origin for CORS: one origin, a list of origins, or a function that returns the origin to echo (or nothing to reject). A string or a list entry may be a subdomain wildcard such as `https://*.example.com`, or a pattern with `:*` for any port such as `http://localhost:*` or `https://*.example.com:*`: the scheme is matched exactly, so is the port unless it is `*`, the apex domain is not included by a subdomain wildcard, and the bare `'*'` still means any origin. */\nexport type TOrigin =\n | string\n | string[]\n | ((\n origin: string,\n c: Context,\n ) => Promise<string | undefined | null> | string | undefined | null);\n/** Options of the CORS middleware the framework installs first. `origin` is required. */\nexport interface ICORSOptions extends IBaseMiddlewareOptions {\n origin: TOrigin;\n allowMethods?: string[] | ((origin: string, c: Context) => Promise<string[]> | string[]);\n allowHeaders?: string[];\n maxAge?: number;\n credentials?: boolean;\n exposeHeaders?: string[];\n}\n\n/** Decides whether the request `Origin` is allowed for the CSRF check. */\nexport type TIsAllowedOriginHandler = (origin: string, context: Context) => boolean;\n/** One value of the `Sec-Fetch-Site` header, taken from `SecFetchSiteValues`. */\nexport type TSecFetchSite = (typeof SecFetchSiteValues)[number];\n/** Decides whether the request `Sec-Fetch-Site` value is allowed for the CSRF check. */\nexport type TIsAllowedSecFetchSiteHandler = (\n secFetchSite: TSecFetchSite,\n context: Context,\n) => boolean;\n\n/** Options of the CSRF middleware. Typed only: the framework does not install it. */\nexport interface ICSRFOptions extends IBaseMiddlewareOptions {\n origin?: string | string[] | TIsAllowedOriginHandler;\n secFetchSite?: TSecFetchSite | TSecFetchSite[] | TIsAllowedSecFetchSiteHandler;\n}\n\n/** Options of the body limit middleware the framework installs right after the request id. `maxSize` is in bytes. */\nexport interface IBodyLimitOptions extends IBaseMiddlewareOptions {\n maxSize: number;\n onError?: (c: Context) => Response | Promise<Response>;\n}\n\n/** Options of the request id middleware. Only the shared options apply. */\nexport interface IRequestIdOptions extends IBaseMiddlewareOptions {}\n\n/** The `configs.middlewares` shape: which framework middleware to switch off or configure. Extra keys are allowed. */\nexport interface IMiddlewareConfigs {\n requestId?: IRequestIdOptions;\n /** Typed only: the framework installs no compress middleware. Wire it in `setupMiddlewares()`. */\n compress?: ICompressOptions;\n /** Installed first, before the request id and the body limit, so early framework responses carry its headers. */\n cors?: ICORSOptions;\n /** Typed only: the framework installs no csrf middleware. Wire it in `setupMiddlewares()`. */\n csrf?: ICSRFOptions;\n /** Installed right after the request id, ahead of every other middleware, so none of them reads a body over it. */\n bodyLimit?: IBodyLimitOptions;\n /** Typed only: the framework installs no ip restriction. Wire it in `setupMiddlewares()`. */\n ipRestriction?: IBaseMiddlewareOptions & IIPRestrictionRules;\n [extra: string | symbol]: any;\n}\n"]}
1
+ {"version":3,"file":"middlewares.js","sourceRoot":"","sources":["../../../../../../src/base/applications/common/types/middlewares.ts"],"names":[],"mappings":"","sourcesContent":["import type { Context } from 'hono';\nimport type { IPRestrictionRules as IIPRestrictionRules } from 'hono/ip-restriction';\nimport { type SecFetchSiteValues, type TCompressEncoding } from '../constants';\n\n/** Options shared by every configurable middleware. Extra keys are allowed. */\nexport interface IBaseMiddlewareOptions {\n /**\n * Only `false` switches the middleware off.\n *\n * @default true\n */\n enable?: boolean;\n path?: string;\n [extra: string | symbol]: any;\n}\n\n/** Options of the compress middleware. Typed only: the framework does not install it. */\nexport interface ICompressOptions extends IBaseMiddlewareOptions {\n encoding: TCompressEncoding;\n threshold?: number;\n}\n\n/** Allowed origin for CORS: one origin, a list of origins, or a function that returns the origin to echo (or nothing to reject). A string or a list entry may be a subdomain wildcard such as `https://*.example.com`, or a pattern with `:*` for any port such as `http://localhost:*` or `https://*.example.com:*`: the scheme is matched exactly, so is the port unless it is `*`, the apex domain is not included by a subdomain wildcard, and the bare `'*'` still means any origin. */\nexport type TOrigin =\n | string\n | string[]\n | ((\n origin: string,\n c: Context,\n ) => Promise<string | undefined | null> | string | undefined | null);\n/** Options of the CORS middleware the framework installs first. `origin` is required. */\nexport interface ICORSOptions extends IBaseMiddlewareOptions {\n origin: TOrigin;\n allowMethods?: string[] | ((origin: string, c: Context) => Promise<string[]> | string[]);\n allowHeaders?: string[];\n maxAge?: number;\n credentials?: boolean;\n exposeHeaders?: string[];\n}\n\n/** Decides whether the request `Origin` is allowed for the CSRF check. */\nexport type TIsAllowedOriginHandler = (origin: string, context: Context) => boolean;\n/** One value of the `Sec-Fetch-Site` header, taken from `SecFetchSiteValues`. */\nexport type TSecFetchSite = (typeof SecFetchSiteValues)[number];\n/** Decides whether the request `Sec-Fetch-Site` value is allowed for the CSRF check. */\nexport type TIsAllowedSecFetchSiteHandler = (\n secFetchSite: TSecFetchSite,\n context: Context,\n) => boolean;\n\n/** Options of the CSRF middleware. Typed only: the framework does not install it. */\nexport interface ICSRFOptions extends IBaseMiddlewareOptions {\n origin?: string | string[] | TIsAllowedOriginHandler;\n secFetchSite?: TSecFetchSite | TSecFetchSite[] | TIsAllowedSecFetchSiteHandler;\n}\n\n/**\n * Options of the body limit middleware the framework installs right after the request id. `maxSize` is in bytes.\n *\n * Unset (no `bodyLimit` key), every route gets `BodyLimits.DEFAULT_MAX_SIZE`, 5 MiB. Configured, it replaces\n * the default (with a `path`, only the routes under it are limited). `enable: false` removes the limit. A route\n * that takes larger bodies puts `BodyLimits.route({ maxSize })` in its `middleware`.\n */\nexport interface IBodyLimitOptions extends IBaseMiddlewareOptions {\n maxSize: number;\n onError?: (c: Context) => Response | Promise<Response>;\n}\n\n/** Options of the request id middleware. Only the shared options apply. */\nexport interface IRequestIdOptions extends IBaseMiddlewareOptions {}\n\n/** The `configs.middlewares` shape: which framework middleware to switch off or configure. Extra keys are allowed. */\nexport interface IMiddlewareConfigs {\n requestId?: IRequestIdOptions;\n /** Typed only: the framework installs no compress middleware. Wire it in `setupMiddlewares()`. */\n compress?: ICompressOptions;\n /** Installed first, before the request id and the body limit, so early framework responses carry its headers. */\n cors?: ICORSOptions;\n /** Typed only: the framework installs no csrf middleware. Wire it in `setupMiddlewares()`. */\n csrf?: ICSRFOptions;\n /** Installed right after the request id, ahead of every other middleware, so none of them reads a body over it. */\n bodyLimit?: IBodyLimitOptions;\n /** Typed only: the framework installs no ip restriction. Wire it in `setupMiddlewares()`. */\n ipRestriction?: IBaseMiddlewareOptions & IIPRestrictionRules;\n [extra: string | symbol]: any;\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  export * from './abstract.js';
2
2
  export * from './artifact-group.js';
3
+ export * from './body-limit.js';
3
4
  export * from './boot-sequence.js';
4
5
  export * from './common/index.js';
5
6
  export * from './rest.js';
@@ -1,5 +1,6 @@
1
1
  export * from './abstract.js';
2
2
  export * from './artifact-group.js';
3
+ export * from './body-limit.js';
3
4
  export * from './boot-sequence.js';
4
5
  export * from './common/index.js';
5
6
  export * from './rest.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/base/applications/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC","sourcesContent":["export * from './abstract';\nexport * from './artifact-group';\nexport * from './boot-sequence';\nexport * from './common';\nexport * from './rest';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/base/applications/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC","sourcesContent":["export * from './abstract';\nexport * from './artifact-group';\nexport * from './body-limit';\nexport * from './boot-sequence';\nexport * from './common';\nexport * from './rest';\n"]}
@@ -1,9 +1,8 @@
1
1
  import type { TBindingNamespace } from '../../common/bindings.js';
2
2
  import type { Binding } from '../../helpers/inversion/index.js';
3
- import { OpenAPIHono } from '@hono/zod-openapi';
4
3
  import type { IConfigurable, TClass, ValueOrPromise } from '@venizia/ignis-helpers/common';
5
4
  import { RequestIdGenerator } from '@venizia/ignis-helpers/core';
6
- import type { Env, Schema } from 'hono';
5
+ import type { Env, Hono, Schema } from 'hono';
7
6
  import type { BaseComponent } from '../components/index.js';
8
7
  import type { BaseConfiguration } from '../configurations/index.js';
9
8
  import type { IDataSource } from '../datasources/index.js';
@@ -24,15 +23,15 @@ interface IRegisterDynamicBindingsOptions<T extends IConfigurable = IConfigurabl
24
23
  instance: T;
25
24
  }) => Promise<void>;
26
25
  }
27
- /** Adds the `OpenAPIHono` router surface on top of `AbstractApplication` - no listening server, so this is the layer a browser Worker or gRPC-only host can extend without pulling in `Bun.serve`. */
26
+ /** Adds the Hono router surface on top of `AbstractApplication` - no listening server, so this is the layer a browser Worker or gRPC-only host can extend without pulling in `Bun.serve`. */
28
27
  export declare abstract class RestApplication<AppEnv extends Env = Env, AppSchema extends Schema = {}, BasePath extends string = '/'> extends AbstractApplication {
29
28
  private registeredBindings;
30
29
  private artifactOptions;
31
30
  /** The router, and nothing else. What runtime is underneath and what socket is bound are `ServerApplication`'s to know - a browser Worker has neither, and carrying the union here made `RuntimeModules.detect()` answer `'node'` inside a Worker. */
32
31
  protected server: {
33
- hono: OpenAPIHono<AppEnv, AppSchema, BasePath>;
32
+ hono: Hono<AppEnv, AppSchema, BasePath>;
34
33
  };
35
- protected rootRouter: OpenAPIHono<AppEnv, AppSchema, BasePath>;
34
+ protected rootRouter: Hono<AppEnv, AppSchema, BasePath>;
36
35
  protected readonly requestIdGenerator: RequestIdGenerator;
37
36
  /** A copy of the `bodyLimit` the default stack installed, absent until `registerDefaultMiddlewares()` ran. */
38
37
  private installedBodyLimit?;
@@ -40,8 +39,15 @@ export declare abstract class RestApplication<AppEnv extends Env = Env, AppSchem
40
39
  scope: string;
41
40
  config: IApplicationConfigs;
42
41
  });
43
- getRootRouter(): OpenAPIHono<AppEnv, AppSchema, BasePath>;
44
- getServer(): OpenAPIHono<AppEnv, AppSchema, BasePath>;
42
+ /**
43
+ * Builds one of the two routers: a plain `Hono`, or an `OpenAPIHono` once the REST controller layer is
44
+ * loaded. Called from the constructor, so an override must not read its own instance fields.
45
+ */
46
+ protected createRouter(opts: {
47
+ strict: boolean;
48
+ }): Hono<AppEnv, AppSchema, BasePath>;
49
+ getRootRouter(): Hono<AppEnv, AppSchema, BasePath>;
50
+ getServer(): Hono<AppEnv, AppSchema, BasePath>;
45
51
  protected registerCoreBindings(): void;
46
52
  /** The correlation id every host stamps - see {@link RequestIdGenerator} for why `crypto.randomUUID` is refused. */
47
53
  protected generateRequestId(): string;
@@ -53,6 +59,8 @@ export declare abstract class RestApplication<AppEnv extends Env = Env, AppSchem
53
59
  * Registered before `initialize()`, so an application's own handlers still win.
54
60
  */
55
61
  protected registerDefaultMiddlewares(): ValueOrPromise<void>;
62
+ /** The configured `bodyLimit`, or the default one when none is configured. */
63
+ private resolveBodyLimit;
56
64
  /** What a `bodyLimit` config installs: nothing when absent or disabled, else a copy, so a later in-place edit shows. */
57
65
  private toInstalledBodyLimit;
58
66
  private isSameBodyLimit;
@@ -1,22 +1,49 @@
1
1
  import { ArtifactNamespaces, BindingNamespaces, CoreBindings } from '../../common/bindings.js';
2
2
  import { BindingScopes, MetadataRegistry } from '../../helpers/inversion/index.js';
3
3
  import { BindingVerifier } from '@venizia/ignis-inversion';
4
- import { OpenAPIHono } from '@hono/zod-openapi';
5
4
  import { PerformanceUtility, getError, RequestIdGenerator, RetryHelper, } from '@venizia/ignis-helpers/core';
6
5
  import { showRoutes as showApplicationRoutes } from 'hono/dev';
7
- import { bodyLimit } from 'hono/body-limit';
8
6
  import { requestId } from 'hono/request-id';
9
7
  import { ArtifactBindingKeys } from '../metadata/artifact-keys.js';
10
8
  import { RestComponent } from '../components/controller/rest/rest.component.js';
11
9
  import { ControllerTransports } from '../controllers/common/constants.js';
10
+ import { OPENING_HANDLES } from '../datasources/opening-handles.js';
12
11
  import { BaseAppErrorMiddleware } from '../middlewares/app-error/app-error.middleware.js';
13
- import { RequestErrors } from '../middlewares/common/errors.js';
14
12
  import { notFoundHandler } from '../middlewares/not-found/not-found.middleware.js';
15
13
  import { AbstractApplication } from './abstract.js';
14
+ import { BodyLimits } from './body-limit.js';
15
+ import { RouterFactories } from './router-factory.js';
16
16
  import { CorsUtility } from './cors.js';
17
17
  import { ArtifactIndexHelper } from './artifact-index.js';
18
18
  import { BootSteps } from './boot-sequence.js';
19
- /** Adds the `OpenAPIHono` router surface on top of `AbstractApplication` - no listening server, so this is the layer a browser Worker or gRPC-only host can extend without pulling in `Bun.serve`. */
19
+ /**
20
+ * Runtime checks that narrow a bound instance to the members the boot calls on it. Positional: a type predicate narrows
21
+ * its own parameter.
22
+ */
23
+ class BootTargets {
24
+ static isObjectLike(value) {
25
+ return (typeof value === 'object' && value !== null) || typeof value === 'function';
26
+ }
27
+ /** Has `isOpenDeferred()`, so the boot can ask whether its open waits for the first use. */
28
+ static canDeferOpen(value) {
29
+ return (BootTargets.isObjectLike(value) &&
30
+ 'isOpenDeferred' in value &&
31
+ typeof value.isOpenDeferred === 'function');
32
+ }
33
+ /** Has `configure()`; a datasource's takes the opening handles in its second argument. */
34
+ static isConfigurable(value) {
35
+ return (BootTargets.isObjectLike(value) &&
36
+ 'configure' in value &&
37
+ typeof value.configure === 'function');
38
+ }
39
+ /** Carries the opening handles every datasource root defines. */
40
+ static hasOpeningHandles(value) {
41
+ return (BootTargets.isObjectLike(value) &&
42
+ OPENING_HANDLES in value &&
43
+ typeof value[OPENING_HANDLES] === 'function');
44
+ }
45
+ }
46
+ /** Adds the Hono router surface on top of `AbstractApplication` - no listening server, so this is the layer a browser Worker or gRPC-only host can extend without pulling in `Bun.serve`. */
20
47
  export class RestApplication extends AbstractApplication {
21
48
  constructor(opts) {
22
49
  super(opts);
@@ -36,9 +63,15 @@ export class RestApplication extends AbstractApplication {
36
63
  }
37
64
  this.requestIdGenerator = new RequestIdGenerator({ scope: opts.scope });
38
65
  const strict = this.configs.path.isStrict ?? true;
39
- const honoServer = new OpenAPIHono({ strict });
40
- this.rootRouter = new OpenAPIHono({ strict });
41
- this.server = { hono: honoServer };
66
+ this.server = { hono: this.createRouter({ strict }) };
67
+ this.rootRouter = this.createRouter({ strict });
68
+ }
69
+ /**
70
+ * Builds one of the two routers: a plain `Hono`, or an `OpenAPIHono` once the REST controller layer is
71
+ * loaded. Called from the constructor, so an override must not read its own instance fields.
72
+ */
73
+ createRouter(opts) {
74
+ return RouterFactories.create({ strict: opts.strict });
42
75
  }
43
76
  getRootRouter() {
44
77
  return this.rootRouter;
@@ -82,7 +115,10 @@ export class RestApplication extends AbstractApplication {
82
115
  CorsUtility.registerCors({ server, options: this.configs.middlewares?.cors });
83
116
  server.use(requestId({ generator: () => this.generateRequestId() }));
84
117
  // Ahead of every middleware a host adds after this one, so none of them buffers a body over it.
85
- const bodyLimitOptions = this.configs.middlewares?.bodyLimit;
118
+ // Unset, every route gets BodyLimits.DEFAULT_MAX_SIZE; a configured bodyLimit replaces it, and `enable: false` removes it.
119
+ const bodyLimitOptions = this.resolveBodyLimit({
120
+ options: this.configs.middlewares?.bodyLimit,
121
+ });
86
122
  this.installedBodyLimit = { options: this.toInstalledBodyLimit({ options: bodyLimitOptions }) };
87
123
  if (bodyLimitOptions && bodyLimitOptions.enable !== false) {
88
124
  const { maxSize, path, onError } = bodyLimitOptions;
@@ -91,16 +127,9 @@ export class RestApplication extends AbstractApplication {
91
127
  message: `[registerDefaultMiddlewares] configs.middlewares.bodyLimit.maxSize must be a non-negative number of bytes | value: ${String(maxSize)}`,
92
128
  });
93
129
  }
94
- const limiter = bodyLimit({
95
- maxSize,
96
- onError: onError ??
97
- (() => {
98
- throw getError({
99
- error: RequestErrors.BODY_TOO_LARGE,
100
- message: `Request body exceeds the maximum of ${maxSize} bytes`,
101
- });
102
- }),
103
- });
130
+ const defaultLimiter = BodyLimits.limiter({ maxSize, onError });
131
+ // A route with its own limit (BodyLimits.route) is held to that one, not to this.
132
+ const limiter = (context, next) => BodyLimits.hasRouteLimit(context) ? next() : defaultLimiter(context, next);
104
133
  if (path) {
105
134
  server.use(path, limiter);
106
135
  }
@@ -111,6 +140,10 @@ export class RestApplication extends AbstractApplication {
111
140
  server.onError(this.buildErrorMiddleware().value());
112
141
  server.notFound(notFoundHandler({ logger: this.logger }));
113
142
  }
143
+ /** The configured `bodyLimit`, or the default one when none is configured. */
144
+ resolveBodyLimit(opts) {
145
+ return opts.options ?? { maxSize: BodyLimits.DEFAULT_MAX_SIZE };
146
+ }
114
147
  /** What a `bodyLimit` config installs: nothing when absent or disabled, else a copy, so a later in-place edit shows. */
115
148
  toInstalledBodyLimit(opts) {
116
149
  const { options } = opts;
@@ -141,7 +174,9 @@ export class RestApplication extends AbstractApplication {
141
174
  return;
142
175
  }
143
176
  const installed = this.installedBodyLimit.options;
144
- const current = this.toInstalledBodyLimit({ options: this.configs.middlewares?.bodyLimit });
177
+ const current = this.toInstalledBodyLimit({
178
+ options: this.resolveBodyLimit({ options: this.configs.middlewares?.bodyLimit }),
179
+ });
145
180
  if (this.isSameBodyLimit({ left: installed, right: current })) {
146
181
  return;
147
182
  }
@@ -326,9 +361,20 @@ export class RestApplication extends AbstractApplication {
326
361
  logger.debug('No binding instance | namespace: %s | key: %s', namespace, binding.key);
327
362
  return;
328
363
  }
329
- if (typeof instance?.configure === 'function') {
364
+ if (namespace === BindingNamespaces.DATASOURCE &&
365
+ BootTargets.canDeferOpen(instance) &&
366
+ instance.isOpenDeferred() === true) {
367
+ // Opens at the first call that needs it; the application starts, and listens, without it.
368
+ instance.deferOpen?.({ options: this.artifactOptions.get(binding.key) });
369
+ logger.info('Datasource opens on first use | key: %s', binding.key);
370
+ }
371
+ else if (BootTargets.isConfigurable(instance)) {
330
372
  const options = this.artifactOptions.get(binding.key);
331
- await instance.configure(options);
373
+ // A datasource also gets the handles of its open (the same body works at start and on first use).
374
+ const opening = namespace === BindingNamespaces.DATASOURCE && BootTargets.hasOpeningHandles(instance)
375
+ ? instance[OPENING_HANDLES]()
376
+ : undefined;
377
+ await instance.configure(options, opening);
332
378
  }
333
379
  // Marked before the after-hook runs, so the hook sees its own binding as configured.
334
380
  configured.add(binding.key);