@venizia/ignis-kernel 0.4.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/base/applications/abstract.js +2 -2
- package/dist/cjs/base/applications/abstract.js.map +1 -1
- package/dist/cjs/base/applications/artifact-group.js +1 -1
- package/dist/cjs/base/applications/artifact-group.js.map +1 -1
- package/dist/cjs/base/applications/artifact-index.js +11 -11
- package/dist/cjs/base/applications/artifact-index.js.map +1 -1
- package/dist/cjs/base/applications/boot-sequence.js +1 -1
- package/dist/cjs/base/applications/boot-sequence.js.map +1 -1
- package/dist/cjs/base/applications/cors.d.ts +13 -0
- package/dist/cjs/base/applications/cors.d.ts.map +1 -0
- package/dist/cjs/base/applications/cors.js +43 -0
- package/dist/cjs/base/applications/cors.js.map +1 -0
- package/dist/cjs/base/applications/deprecations.d.ts +10 -0
- package/dist/cjs/base/applications/deprecations.d.ts.map +1 -0
- package/dist/cjs/base/applications/deprecations.js +23 -0
- package/dist/cjs/base/applications/deprecations.js.map +1 -0
- package/dist/cjs/base/applications/rest.d.ts.map +1 -1
- package/dist/cjs/base/applications/rest.js +11 -5
- package/dist/cjs/base/applications/rest.js.map +1 -1
- package/dist/cjs/base/auth/authenticate/common/codecs.js +2 -2
- package/dist/cjs/base/auth/authenticate/common/codecs.js.map +1 -1
- package/dist/cjs/base/auth/authenticate/providers/authentication.provider.js +1 -1
- package/dist/cjs/base/auth/authenticate/providers/authentication.provider.js.map +1 -1
- package/dist/cjs/base/auth/authenticate/strategies/strategy-registry.js +1 -1
- package/dist/cjs/base/auth/authenticate/strategies/strategy-registry.js.map +1 -1
- package/dist/cjs/base/auth/authorize/builders/grant.builder.js +12 -12
- package/dist/cjs/base/auth/authorize/builders/grant.builder.js.map +1 -1
- package/dist/cjs/base/auth/authorize/builders/permission.builder.js +1 -1
- package/dist/cjs/base/auth/authorize/builders/permission.builder.js.map +1 -1
- package/dist/cjs/base/auth/authorize/builders/policy.builder.js +1 -1
- package/dist/cjs/base/auth/authorize/builders/policy.builder.js.map +1 -1
- package/dist/cjs/base/auth/authorize/common/constants/authorization.d.ts.map +1 -1
- package/dist/cjs/base/auth/authorize/common/constants/authorization.js +2 -2
- package/dist/cjs/base/auth/authorize/common/constants/authorization.js.map +1 -1
- package/dist/cjs/base/auth/authorize/enforcers/enforcer-registry.js +1 -1
- package/dist/cjs/base/auth/authorize/enforcers/enforcer-registry.js.map +1 -1
- package/dist/cjs/base/auth/authorize/providers/authorization.provider.js +3 -3
- package/dist/cjs/base/auth/authorize/providers/authorization.provider.js.map +1 -1
- package/dist/cjs/base/controllers/factory/authorize-guard.d.ts +19 -0
- package/dist/cjs/base/controllers/factory/authorize-guard.d.ts.map +1 -0
- package/dist/cjs/base/controllers/factory/authorize-guard.js +60 -0
- package/dist/cjs/base/controllers/factory/authorize-guard.js.map +1 -0
- package/dist/cjs/base/controllers/factory/controller.d.ts +2 -2
- package/dist/cjs/base/controllers/factory/controller.d.ts.map +1 -1
- package/dist/cjs/base/controllers/factory/controller.js +9 -0
- package/dist/cjs/base/controllers/factory/controller.js.map +1 -1
- package/dist/cjs/base/controllers/factory/crud/abstract.d.ts +1 -1
- package/dist/cjs/base/controllers/factory/crud/abstract.d.ts.map +1 -1
- package/dist/cjs/base/controllers/factory/crud/abstract.js.map +1 -1
- package/dist/cjs/base/controllers/factory/definition.js +1 -1
- package/dist/cjs/base/controllers/factory/definition.js.map +1 -1
- package/dist/cjs/base/controllers/rest/extras.js +5 -5
- package/dist/cjs/base/controllers/rest/extras.js.map +1 -1
- package/dist/cjs/base/metadata/injectable.js +1 -1
- package/dist/cjs/base/metadata/injectable.js.map +1 -1
- package/dist/cjs/base/metadata/model-settings.d.ts +21 -0
- package/dist/cjs/base/metadata/model-settings.d.ts.map +1 -0
- package/dist/cjs/base/metadata/model-settings.js +77 -0
- package/dist/cjs/base/metadata/model-settings.js.map +1 -0
- package/dist/cjs/base/metadata/persistents.d.ts +1 -1
- package/dist/cjs/base/metadata/persistents.d.ts.map +1 -1
- package/dist/cjs/base/metadata/persistents.js +24 -12
- package/dist/cjs/base/metadata/persistents.js.map +1 -1
- package/dist/cjs/base/metadata/routes/controller.js +1 -1
- package/dist/cjs/base/metadata/routes/controller.js.map +1 -1
- package/dist/cjs/base/middlewares/app-error/app-error.middleware.js +3 -3
- package/dist/cjs/base/middlewares/app-error/app-error.middleware.js.map +1 -1
- package/dist/cjs/base/middlewares/app-error/zod.handler.js +2 -2
- package/dist/cjs/base/middlewares/app-error/zod.handler.js.map +1 -1
- package/dist/cjs/base/middlewares/form-body/form-body.middleware.js +2 -2
- package/dist/cjs/base/middlewares/form-body/form-body.middleware.js.map +1 -1
- package/dist/cjs/base/middlewares/not-found/not-found.middleware.js.map +1 -1
- package/dist/cjs/base/models/common/utilities.js +1 -1
- package/dist/cjs/base/models/common/utilities.js.map +1 -1
- package/dist/cjs/base/repositories/common/constants.d.ts +18 -1
- package/dist/cjs/base/repositories/common/constants.d.ts.map +1 -1
- package/dist/cjs/base/repositories/common/constants.js +22 -2
- package/dist/cjs/base/repositories/common/constants.js.map +1 -1
- package/dist/cjs/base/repositories/common/types/contracts.d.ts +17 -17
- package/dist/cjs/base/repositories/common/types/contracts.d.ts.map +1 -1
- package/dist/cjs/base/repositories/common/types/contracts.js.map +1 -1
- package/dist/cjs/base/repositories/core/abstract.d.ts +18 -18
- package/dist/cjs/base/repositories/core/abstract.d.ts.map +1 -1
- package/dist/cjs/base/repositories/core/abstract.js +8 -7
- package/dist/cjs/base/repositories/core/abstract.js.map +1 -1
- package/dist/cjs/helpers/inversion/common/types/model.d.ts +94 -22
- package/dist/cjs/helpers/inversion/common/types/model.d.ts.map +1 -1
- package/dist/cjs/helpers/inversion/common/types/model.js.map +1 -1
- package/dist/cjs/helpers/inversion/mixins/model.mixin.js +1 -1
- package/dist/cjs/helpers/inversion/mixins/model.mixin.js.map +1 -1
- package/dist/cjs/helpers/inversion/mixins/repository.mixin.js +1 -1
- package/dist/cjs/helpers/inversion/mixins/repository.mixin.js.map +1 -1
- package/dist/cjs/repository.d.ts +1 -1
- package/dist/cjs/repository.d.ts.map +1 -1
- package/dist/cjs/repository.js.map +1 -1
- package/dist/esm/base/applications/abstract.js +2 -2
- package/dist/esm/base/applications/abstract.js.map +1 -1
- package/dist/esm/base/applications/artifact-group.js +1 -1
- package/dist/esm/base/applications/artifact-group.js.map +1 -1
- package/dist/esm/base/applications/artifact-index.js +11 -11
- package/dist/esm/base/applications/artifact-index.js.map +1 -1
- package/dist/esm/base/applications/boot-sequence.js +1 -1
- package/dist/esm/base/applications/boot-sequence.js.map +1 -1
- package/dist/esm/base/applications/cors.d.ts +13 -0
- package/dist/esm/base/applications/cors.d.ts.map +1 -0
- package/dist/esm/base/applications/cors.js +39 -0
- package/dist/esm/base/applications/cors.js.map +1 -0
- package/dist/esm/base/applications/deprecations.d.ts +10 -0
- package/dist/esm/base/applications/deprecations.d.ts.map +1 -0
- package/dist/esm/base/applications/deprecations.js +19 -0
- package/dist/esm/base/applications/deprecations.js.map +1 -0
- package/dist/esm/base/applications/rest.d.ts.map +1 -1
- package/dist/esm/base/applications/rest.js +11 -5
- package/dist/esm/base/applications/rest.js.map +1 -1
- package/dist/esm/base/auth/authenticate/common/codecs.js +2 -2
- package/dist/esm/base/auth/authenticate/common/codecs.js.map +1 -1
- package/dist/esm/base/auth/authenticate/providers/authentication.provider.js +1 -1
- package/dist/esm/base/auth/authenticate/providers/authentication.provider.js.map +1 -1
- package/dist/esm/base/auth/authenticate/strategies/strategy-registry.js +1 -1
- package/dist/esm/base/auth/authenticate/strategies/strategy-registry.js.map +1 -1
- package/dist/esm/base/auth/authorize/builders/grant.builder.js +12 -12
- package/dist/esm/base/auth/authorize/builders/grant.builder.js.map +1 -1
- package/dist/esm/base/auth/authorize/builders/permission.builder.js +1 -1
- package/dist/esm/base/auth/authorize/builders/permission.builder.js.map +1 -1
- package/dist/esm/base/auth/authorize/builders/policy.builder.js +1 -1
- package/dist/esm/base/auth/authorize/builders/policy.builder.js.map +1 -1
- package/dist/esm/base/auth/authorize/common/constants/authorization.d.ts.map +1 -1
- package/dist/esm/base/auth/authorize/common/constants/authorization.js +2 -2
- package/dist/esm/base/auth/authorize/common/constants/authorization.js.map +1 -1
- package/dist/esm/base/auth/authorize/enforcers/enforcer-registry.js +1 -1
- package/dist/esm/base/auth/authorize/enforcers/enforcer-registry.js.map +1 -1
- package/dist/esm/base/auth/authorize/providers/authorization.provider.js +3 -3
- package/dist/esm/base/auth/authorize/providers/authorization.provider.js.map +1 -1
- package/dist/esm/base/controllers/factory/authorize-guard.d.ts +19 -0
- package/dist/esm/base/controllers/factory/authorize-guard.d.ts.map +1 -0
- package/dist/esm/base/controllers/factory/authorize-guard.js +56 -0
- package/dist/esm/base/controllers/factory/authorize-guard.js.map +1 -0
- package/dist/esm/base/controllers/factory/controller.d.ts +2 -2
- package/dist/esm/base/controllers/factory/controller.d.ts.map +1 -1
- package/dist/esm/base/controllers/factory/controller.js +9 -0
- package/dist/esm/base/controllers/factory/controller.js.map +1 -1
- package/dist/esm/base/controllers/factory/crud/abstract.d.ts +1 -1
- package/dist/esm/base/controllers/factory/crud/abstract.d.ts.map +1 -1
- package/dist/esm/base/controllers/factory/crud/abstract.js.map +1 -1
- package/dist/esm/base/controllers/factory/definition.js +1 -1
- package/dist/esm/base/controllers/factory/definition.js.map +1 -1
- package/dist/esm/base/controllers/rest/extras.js +5 -5
- package/dist/esm/base/controllers/rest/extras.js.map +1 -1
- package/dist/esm/base/metadata/injectable.js +1 -1
- package/dist/esm/base/metadata/injectable.js.map +1 -1
- package/dist/esm/base/metadata/model-settings.d.ts +21 -0
- package/dist/esm/base/metadata/model-settings.d.ts.map +1 -0
- package/dist/esm/base/metadata/model-settings.js +73 -0
- package/dist/esm/base/metadata/model-settings.js.map +1 -0
- package/dist/esm/base/metadata/persistents.d.ts +1 -1
- package/dist/esm/base/metadata/persistents.d.ts.map +1 -1
- package/dist/esm/base/metadata/persistents.js +24 -12
- package/dist/esm/base/metadata/persistents.js.map +1 -1
- package/dist/esm/base/metadata/routes/controller.js +1 -1
- package/dist/esm/base/metadata/routes/controller.js.map +1 -1
- package/dist/esm/base/middlewares/app-error/app-error.middleware.js +3 -3
- package/dist/esm/base/middlewares/app-error/app-error.middleware.js.map +1 -1
- package/dist/esm/base/middlewares/app-error/zod.handler.js +2 -2
- package/dist/esm/base/middlewares/app-error/zod.handler.js.map +1 -1
- package/dist/esm/base/middlewares/form-body/form-body.middleware.js +2 -2
- package/dist/esm/base/middlewares/form-body/form-body.middleware.js.map +1 -1
- package/dist/esm/base/middlewares/not-found/not-found.middleware.js.map +1 -1
- package/dist/esm/base/models/common/utilities.js +1 -1
- package/dist/esm/base/models/common/utilities.js.map +1 -1
- package/dist/esm/base/repositories/common/constants.d.ts +18 -1
- package/dist/esm/base/repositories/common/constants.d.ts.map +1 -1
- package/dist/esm/base/repositories/common/constants.js +20 -1
- package/dist/esm/base/repositories/common/constants.js.map +1 -1
- package/dist/esm/base/repositories/common/types/contracts.d.ts +17 -17
- package/dist/esm/base/repositories/common/types/contracts.d.ts.map +1 -1
- package/dist/esm/base/repositories/common/types/contracts.js.map +1 -1
- package/dist/esm/base/repositories/core/abstract.d.ts +18 -18
- package/dist/esm/base/repositories/core/abstract.d.ts.map +1 -1
- package/dist/esm/base/repositories/core/abstract.js +8 -7
- package/dist/esm/base/repositories/core/abstract.js.map +1 -1
- package/dist/esm/helpers/inversion/common/types/model.d.ts +94 -22
- package/dist/esm/helpers/inversion/common/types/model.d.ts.map +1 -1
- package/dist/esm/helpers/inversion/common/types/model.js.map +1 -1
- package/dist/esm/helpers/inversion/mixins/model.mixin.js +1 -1
- package/dist/esm/helpers/inversion/mixins/model.mixin.js.map +1 -1
- package/dist/esm/helpers/inversion/mixins/repository.mixin.js +1 -1
- package/dist/esm/helpers/inversion/mixins/repository.mixin.js.map +1 -1
- package/dist/esm/repository.d.ts +1 -1
- package/dist/esm/repository.d.ts.map +1 -1
- package/dist/esm/repository.js.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"persistents.js","sourceRoot":"","sources":["../../../../src/base/metadata/persistents.ts"],"names":[],"mappings":";;;AAAA,gDAAsD;AAStD,mDAM6B;AAC7B,0DAA2E;AAC3E,sDAAuD;AAEvD,gDAAmD;AAEnD,gEAAmE;AACnE,6CAAmE;AAEnE,oEAAoE;AAC7D,MAAM,KAAK,GAAG,CAAC,QAAwB,EAAkB,EAAE;IAChE,OAAO,MAAM,CAAC,EAAE;QACd,IAAA,uBAAU,EAAC,EAAE,IAAI,EAAE,yBAAa,CAAC,KAAK,EAAE,GAAG,IAAA,oCAAuB,EAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;QAE5F,MAAM,YAAY,GAAG,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;QACrD,IAAI,YAAY,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,YAAY,CAAC,IAAI,YAAY,IAAI,CAAC,CAAC,EAAE,CAAC;YACzF,MAAM,IAAA,eAAQ,EAAC;gBACb,OAAO,EAAE,WAAW,MAAM,CAAC,IAAI,iEAAiE,YAAY,EAAE;aAC/G,CAAC,CAAC;QACL,CAAC;QAED,0FAA0F;QAC1F,4FAA4F;QAC5F,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;QAC7C,IAAI,QAAQ,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,QAAQ,IAAI,CAAC,CAAC,EAAE,CAAC;YAC7E,MAAM,IAAA,eAAQ,EAAC;gBACb,OAAO,EAAE,WAAW,MAAM,CAAC,IAAI,6DAA6D,QAAQ,EAAE;aACvG,CAAC,CAAC;QACL,CAAC;QAED,kFAAkF;QAClF,MAAM,SAAS,GAAG,QAAQ,CAAC,QAAQ,EAAE,SAAS,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AC,CAAC,MAAM,CAAC,CAAC;IAEX,MAAM,QAAQ,GAAG,yBAAyB,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;IAE3E,QAAQ,CAAC,qBAAqB,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,GAAG,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;AAC7F,CAAC,CAAC;AAEK,MAAM,UAAU,GAAG,CAIxB,QAAiD,EACjC,EAAE;IAClB,OAAO,MAAM,CAAC,EAAE;QACd,MAAM,QAAQ,GAAG,4BAAgB,CAAC,WAAW,EAAE,CAAC;QAChD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,uBAAuB,CAAC;gBACtB,QAAQ,EAAE,yBAAyB,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;gBACzD,YAAY,EAAE,EAAE;gBAChB,MAAM;gBACN,QAAQ;aACT,CAAC,CAAC;YACH,OAAO;QACT,CAAC;QAED,uBAAuB,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;IAClF,CAAC,CAAC;AACJ,CAAC,CAAC;AApBW,QAAA,UAAU,cAoBrB","sourcesContent":["import { BindingNamespaces } from '@/common/bindings';\nimport type {\n IArtifactRegistrationOptions,\n IDataSourceMetadata,\n IInjectMetadata,\n IModelMetadata,\n IResolvedRepositoryMetadata,\n TRepositoryMetadata,\n} from '@/helpers/inversion';\nimport {\n ArtifactTypes,\n BindingKeys,\n MetadataKeys,\n MetadataRegistry,\n resolveInjectTarget,\n} from '@/helpers/inversion';\nimport { resolveClass, resolveValue } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport type { IDataSource } from '../datasources';\nimport { isDataSourceClass } from '../datasources';\nimport type { AbstractEntity } from '../models';\nimport { RepositoryTypes } from '../repositories/common/constants';\nimport { injectable, pickRegistrationOptions } from './injectable';\n\n/** Registers a model class with its static schema and relations. */\nexport const model = (metadata: IModelMetadata): ClassDecorator => {\n return target => {\n injectable({ type: ArtifactTypes.MODEL, ...pickRegistrationOptions({ metadata }) })(target);\n\n const defaultLimit = metadata.settings?.defaultLimit;\n if (defaultLimit !== undefined && (!Number.isInteger(defaultLimit) || defaultLimit <= 0)) {\n throw getError({\n message: `[model][${target.name}] Invalid 'defaultLimit' | Expected a positive integer | Got: ${defaultLimit}`,\n });\n }\n\n // Validated at DECORATION time, like defaultLimit: a bad ceiling is a wiring mistake, and\n // catching it at boot beats catching it on the one request that happens to reach the limit.\n const maxLimit = metadata.settings?.maxLimit;\n if (maxLimit !== undefined && (!Number.isInteger(maxLimit) || maxLimit <= 0)) {\n throw getError({\n message: `[model][${target.name}] Invalid 'maxLimit' | Expected a positive integer | Got: ${maxLimit}`,\n });\n }\n\n // Auto-populate AUTHORIZATION_SUBJECT from authorize.principal if not already set\n const principal = metadata.settings?.authorize?.principal;\n if (principal && !Object.hasOwn(target, 'AUTHORIZATION_SUBJECT')) {\n (target as Record<string, unknown>).AUTHORIZATION_SUBJECT = principal;\n }\n\n MetadataRegistry.getInstance().registerModel({ target, metadata });\n };\n};\n\n/** Registers a datasource with driver and auto-discovery settings. */\nexport const datasource = (metadata?: IDataSourceMetadata): ClassDecorator => {\n return target => {\n injectable({\n type: ArtifactTypes.DATASOURCE,\n ...pickRegistrationOptions({ metadata: metadata ?? {} }),\n })(target);\n MetadataRegistry.getInstance().setDataSourceMetadata({ target, metadata });\n };\n};\n\n/** Mirrors the `TRepositoryMetadata` union for JavaScript callers: a known type, a dataSource always, a model exactly when the type is RepositoryTypes.MODEL. */\nconst validateRepositoryMetadata = <\n Model extends AbstractEntity = AbstractEntity,\n DataSource extends IDataSource = IDataSource,\n>(opts: {\n metadata: TRepositoryMetadata<Model, DataSource>;\n target: Function;\n}): void => {\n const { metadata, target } = opts;\n const type = metadata.type ?? RepositoryTypes.MODEL;\n\n if (!RepositoryTypes.isValid(type)) {\n throw getError({\n message: `[validateRepositoryMetadata][@repository][${target.name}] Invalid metadata | Unknown 'type': ${type} | Expected one of: ${[...RepositoryTypes.SCHEME_SET].join(', ')}`,\n });\n }\n\n if (type === RepositoryTypes.MODEL && !metadata.model) {\n throw getError({\n message: `[validateRepositoryMetadata][@repository][${target.name}] Invalid metadata | Missing 'model'`,\n });\n }\n\n if (type === RepositoryTypes.REMOTE && metadata.model) {\n throw getError({\n message: `[validateRepositoryMetadata][@repository][${target.name}] Invalid metadata | A '${RepositoryTypes.REMOTE}' repository takes no 'model'`,\n });\n }\n\n if (!metadata.dataSource) {\n throw getError({\n message: `[validateRepositoryMetadata][@repository][${target.name}] Invalid metadata | Missing 'dataSource'`,\n });\n }\n};\n\n/** Asserts the constructor's first parameter is an AbstractDataSource compatible with what @repository declared. */\nconst validateFirstConstructorParameter = (opts: {\n target: Function;\n firstParamType: Function;\n resolvedDataSource: string | Function;\n}): void => {\n const { target, firstParamType, resolvedDataSource } = opts;\n\n // NOT `instanceof`: two copies of this package give two `AbstractDataSource` classes and the\n // check would be false across them, rejecting a perfectly valid repository at import time.\n const isDataSourceType = isDataSourceClass(firstParamType);\n\n if (!isDataSourceType) {\n throw getError({\n message: `[@repository][${target.name}] Invalid constructor | First parameter must extend AbstractDataSource | Received: '${firstParamType.name}'`,\n });\n }\n\n if (typeof resolvedDataSource !== 'function') {\n return;\n }\n\n const isCompatible =\n firstParamType === resolvedDataSource || resolvedDataSource.prototype instanceof firstParamType;\n\n if (!isCompatible) {\n throw getError({\n message: `[@repository][${target.name}] Invalid constructor | Type mismatch | Constructor expects '${firstParamType.name}' but @repository specifies '${resolvedDataSource.name}'`,\n });\n }\n};\n\n/**\n * Auto-injects dataSource at constructor param[0] unless explicit @inject exists. A class is injected\n * by the class itself, so the container reads the key its registration recorded: a pinned\n * `binding` and a minified class name both resolve. Only a string reference is a key.\n */\nconst registerDataSourceInjection = (opts: {\n target: Function;\n registry: MetadataRegistry;\n dataSourceRef: TRepositoryMetadata['dataSource'];\n resolvedDataSource: string | Function;\n}): void => {\n const { target, registry, dataSourceRef, resolvedDataSource } = opts;\n\n // Own metadata only: `getInjectMetadata` walks the prototype chain, so a repository extending another @repository class would see the BASE's injection at param[0] and silently resolve the base's dataSource.\n const ownInjects: IInjectMetadata[] | undefined = Reflect.getOwnMetadata(\n MetadataKeys.INJECT,\n target,\n );\n const injectAtIndex0 = ownInjects?.find(entry => entry?.index === 0);\n\n if (injectAtIndex0) {\n // `@inject({ target })` carries no key; read the one recorded on the class. The function form\n // resolves through the same helper the container uses, so both paths read one class.\n const injectedTarget = injectAtIndex0.target\n ? resolveInjectTarget({ target: injectAtIndex0.target })\n : undefined;\n const injectKey =\n injectAtIndex0.key ??\n (injectedTarget ? registry.getBindingKey({ target: injectedTarget }) : undefined);\n\n // A class is judged by its brand: its key may sit under any namespace a `binding` pinned, and\n // a provisional key may still change at registration. Only a bare key is judged by its prefix.\n const isDataSourceTarget = injectedTarget\n ? isDataSourceClass(injectedTarget)\n : typeof injectKey === 'string' && injectKey.startsWith(`${BindingNamespaces.DATASOURCE}.`);\n\n if (!isDataSourceTarget) {\n throw getError({\n message: `[@repository][${target.name}] Invalid constructor | First parameter must be a DataSource | Found @inject with key: '${String(injectKey)}' | Expected a key starting with '${BindingNamespaces.DATASOURCE}.' or a DataSource class`,\n });\n }\n\n return;\n }\n\n // Checked only when this decorator writes the injection: an explicit @inject decides for itself.\n // An interface emits `Object` and a type-only class import emits `Function` under tsc (`Object`\n // under bun); neither names the class, so neither is judged.\n const firstParamType = Reflect.getMetadata('design:paramtypes', target)?.[0];\n if (firstParamType && firstParamType !== Object && firstParamType !== Function) {\n validateFirstConstructorParameter({ target, firstParamType, resolvedDataSource });\n }\n\n // The inherited list is the base repository's own, and setInjectMetadata may write straight into it.\n if (!ownInjects) {\n Reflect.defineMetadata(\n MetadataKeys.INJECT,\n [...(registry.getInjectMetadata({ target }) ?? [])],\n target,\n );\n }\n\n const derivedKey = BindingKeys.build({\n namespace: BindingNamespaces.DATASOURCE,\n key: typeof resolvedDataSource === 'string' ? resolvedDataSource : resolvedDataSource.name,\n });\n\n // The class first, decided when the repository is resolved: by then any registration - decorated,\n // `bindingList()`, or `dataSource(X, { binding })` - has recorded its key on the class. The derived\n // key is the fallback for a class nothing recorded, bound by hand under exactly that key.\n registry.setInjectMetadata({\n target,\n index: 0,\n metadata:\n typeof dataSourceRef === 'string'\n ? { key: derivedKey, index: 0, isOptional: false }\n : { target: dataSourceRef, key: derivedKey, index: 0, isOptional: false },\n });\n};\n\n/** Resolves repository metadata and registers bindings for schema auto-discovery. */\nconst resolveRepositoryMetadata = <\n Model extends AbstractEntity = AbstractEntity,\n DataSource extends IDataSource = IDataSource,\n>(opts: {\n metadata: TRepositoryMetadata<Model, DataSource>;\n target: Function;\n registry: MetadataRegistry;\n}): IResolvedRepositoryMetadata<Model, DataSource> => {\n const { metadata, target, registry } = opts;\n\n validateRepositoryMetadata({ metadata, target });\n\n const resolvedDataSource = resolveClass({ ref: metadata.dataSource });\n if (!resolvedDataSource) {\n throw getError({\n message: `[@repository][${target.name}] The dataSource resolver returned nothing at decoration time | An import cycle leaves the datasource class undefined here; import it without the cycle, or name it as a string`,\n });\n }\n\n // No model, so no binding: the datasource owns no schema through this repository.\n if (metadata.type === RepositoryTypes.REMOTE) {\n registerDataSourceInjection({\n target,\n registry,\n dataSourceRef: metadata.dataSource,\n resolvedDataSource,\n });\n return {\n type: RepositoryTypes.REMOTE,\n dataSource: resolvedDataSource,\n operationScope: metadata.operationScope,\n };\n }\n\n const resolvedModel = resolveValue({ value: metadata.model });\n\n registry.registerRepositoryBinding({\n repository: target,\n model: resolvedModel,\n dataSource: resolvedDataSource,\n });\n\n registerDataSourceInjection({\n target,\n registry,\n dataSourceRef: metadata.dataSource,\n resolvedDataSource,\n });\n\n return {\n type: RepositoryTypes.MODEL,\n model: resolvedModel,\n dataSource: resolvedDataSource,\n operationScope: metadata.operationScope,\n };\n};\n\n/** A bare `@repository()` on a subclass reuses the type, model and datasource its nearest decorated parent declared; the registration options (`binding`, `when`, ...) are never inherited, so the subclass registers under its own name. */\nconst inheritRepositoryMetadata = (opts: {\n target: Function;\n registry: MetadataRegistry;\n}): TRepositoryMetadata => {\n // Own metadata does not exist yet at decoration time, so this read walks the prototype chain.\n const inherited = opts.registry.getRepositoryMetadata({ target: opts.target });\n if (!inherited) {\n throw getError({\n message: `[@repository][${opts.target.name}] No metadata given and no decorated repository above it in the prototype chain | pass { model, dataSource } or decorate the parent`,\n });\n }\n\n if (inherited.type === RepositoryTypes.REMOTE) {\n const { type, dataSource, operationScope } = inherited;\n return { type, dataSource, operationScope };\n }\n\n const { type, model: parentModel, dataSource, operationScope } = inherited;\n return { type, model: parentModel, dataSource, operationScope };\n};\n\nconst applyRepositoryMetadata = <\n Model extends AbstractEntity = AbstractEntity,\n DataSource extends IDataSource = IDataSource,\n>(opts: {\n metadata: TRepositoryMetadata<Model, DataSource>;\n registration: IArtifactRegistrationOptions;\n target: Function;\n registry: MetadataRegistry;\n}): void => {\n const { metadata, registration, target, registry } = opts;\n injectable({\n type: ArtifactTypes.REPOSITORY,\n ...pickRegistrationOptions({ metadata: registration }),\n })(target);\n\n const resolved = resolveRepositoryMetadata({ metadata, target, registry });\n\n registry.setRepositoryMetadata({ target, metadata: { ...metadata, _resolved: resolved } });\n};\n\nexport const repository = <\n Model extends AbstractEntity = AbstractEntity,\n DataSource extends IDataSource = IDataSource,\n>(\n metadata?: TRepositoryMetadata<Model, DataSource>,\n): ClassDecorator => {\n return target => {\n const registry = MetadataRegistry.getInstance();\n if (!metadata) {\n applyRepositoryMetadata({\n metadata: inheritRepositoryMetadata({ target, registry }),\n registration: {},\n target,\n registry,\n });\n return;\n }\n\n applyRepositoryMetadata({ metadata, registration: metadata, target, registry });\n };\n};\n"]}
|
|
1
|
+
{"version":3,"file":"persistents.js","sourceRoot":"","sources":["../../../../src/base/metadata/persistents.ts"],"names":[],"mappings":";;;AAAA,gDAAsD;AAStD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AAC;AAEF,MAAM,uBAAuB,GAAG,CAG9B,IAKD,EAAQ,EAAE;IACT,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;IAC1D,IAAA,uBAAU,EAAC;QACT,IAAI,EAAE,yBAAa,CAAC,UAAU;QAC9B,GAAG,IAAA,oCAAuB,EAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC;KACvD,CAAC,CAAC,MAAM,CAAC,CAAC;IAEX,MAAM,QAAQ,GAAG,yBAAyB,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;IAE3E,QAAQ,CAAC,qBAAqB,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,GAAG,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;AAC7F,CAAC,CAAC;AAEK,MAAM,UAAU,GAAG,CAIxB,QAAiD,EACjC,EAAE;IAClB,OAAO,CAAC,MAAM,EAAE,EAAE;QAChB,MAAM,QAAQ,GAAG,4BAAgB,CAAC,WAAW,EAAE,CAAC;QAChD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,uBAAuB,CAAC;gBACtB,QAAQ,EAAE,yBAAyB,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;gBACzD,YAAY,EAAE,EAAE;gBAChB,MAAM;gBACN,QAAQ;aACT,CAAC,CAAC;YACH,OAAO;QACT,CAAC;QAED,uBAAuB,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;IAClF,CAAC,CAAC;AACJ,CAAC,CAAC;AApBW,QAAA,UAAU,cAoBrB","sourcesContent":["import { BindingNamespaces } from '@/common/bindings';\nimport type {\n IArtifactRegistrationOptions,\n IDataSourceMetadata,\n IInjectMetadata,\n IModelMetadata,\n IResolvedRepositoryMetadata,\n TRepositoryMetadata,\n} from '@/helpers/inversion';\nimport {\n ArtifactTypes,\n BindingKeys,\n MetadataKeys,\n MetadataRegistry,\n resolveInjectTarget,\n} from '@/helpers/inversion';\nimport { resolveClass, resolveValue } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport type { IDataSource } from '../datasources';\nimport { isDataSourceClass } from '../datasources';\nimport type { AbstractEntity } from '../models';\nimport { RepositoryTypes } from '../repositories/common/constants';\nimport { injectable, pickRegistrationOptions } from './injectable';\nimport { normalizeModelSettings } from './model-settings';\n\n/** Registers a model class with its static schema and relations. */\nexport const model = (input: IModelMetadata): ClassDecorator => {\n return (target) => {\n injectable({ type: ArtifactTypes.MODEL, ...pickRegistrationOptions({ metadata: input }) })(\n target,\n );\n\n // The one place the deprecated flat keys become the grouped ones; the registry, and so every\n // reader, only ever sees the grouped shape.\n const { settings, deprecated } = normalizeModelSettings({\n model: target.name,\n settings: input.settings,\n });\n const metadata: IModelMetadata = {\n ...input,\n settings,\n ...(deprecated.length > 0 ? { deprecatedSettings: deprecated } : {}),\n };\n\n const defaultLimit = settings?.query?.limit?.default;\n if (defaultLimit !== undefined && (!Number.isInteger(defaultLimit) || defaultLimit <= 0)) {\n throw getError({\n message: `[model][${target.name}] Invalid 'query.limit.default' | Expected a positive integer | Got: ${defaultLimit}`,\n });\n }\n\n // Validated at DECORATION time, like the default limit: a bad ceiling is a wiring mistake, and\n // catching it at boot beats catching it on the one request that happens to reach the limit.\n const maxLimit = settings?.query?.limit?.max;\n if (maxLimit !== undefined && (!Number.isInteger(maxLimit) || maxLimit <= 0)) {\n throw getError({\n message: `[model][${target.name}] Invalid 'query.limit.max' | Expected a positive integer | Got: ${maxLimit}`,\n });\n }\n\n // Auto-populate AUTHORIZATION_SUBJECT from authorize.principal if not already set\n const principal = settings?.authorize?.principal;\n if (principal && !Object.hasOwn(target, 'AUTHORIZATION_SUBJECT')) {\n (target as Record<string, unknown>).AUTHORIZATION_SUBJECT = principal;\n }\n\n MetadataRegistry.getInstance().registerModel({ target, metadata });\n };\n};\n\n/** Registers a datasource with driver and auto-discovery settings. */\nexport const datasource = (metadata?: IDataSourceMetadata): ClassDecorator => {\n return (target) => {\n injectable({\n type: ArtifactTypes.DATASOURCE,\n ...pickRegistrationOptions({ metadata: metadata ?? {} }),\n })(target);\n MetadataRegistry.getInstance().setDataSourceMetadata({ target, metadata });\n };\n};\n\n/** Mirrors the `TRepositoryMetadata` union for JavaScript callers: a known type, a dataSource always, a model exactly when the type is RepositoryTypes.MODEL. */\nconst validateRepositoryMetadata = <\n Model extends AbstractEntity = AbstractEntity,\n DataSource extends IDataSource = IDataSource,\n>(opts: {\n metadata: TRepositoryMetadata<Model, DataSource>;\n target: Function;\n}): void => {\n const { metadata, target } = opts;\n const type = metadata.type ?? RepositoryTypes.MODEL;\n\n if (!RepositoryTypes.isValid(type)) {\n throw getError({\n message: `[validateRepositoryMetadata][@repository][${target.name}] Invalid metadata | Unknown 'type': ${type} | Expected one of: ${[...RepositoryTypes.SCHEME_SET].join(', ')}`,\n });\n }\n\n if (type === RepositoryTypes.MODEL && !metadata.model) {\n throw getError({\n message: `[validateRepositoryMetadata][@repository][${target.name}] Invalid metadata | Missing 'model'`,\n });\n }\n\n if (type === RepositoryTypes.REMOTE && metadata.model) {\n throw getError({\n message: `[validateRepositoryMetadata][@repository][${target.name}] Invalid metadata | A '${RepositoryTypes.REMOTE}' repository takes no 'model'`,\n });\n }\n\n if (!metadata.dataSource) {\n throw getError({\n message: `[validateRepositoryMetadata][@repository][${target.name}] Invalid metadata | Missing 'dataSource'`,\n });\n }\n};\n\n/** Asserts the constructor's first parameter is an AbstractDataSource compatible with what @repository declared. */\nconst validateFirstConstructorParameter = (opts: {\n target: Function;\n firstParamType: Function;\n resolvedDataSource: string | Function;\n}): void => {\n const { target, firstParamType, resolvedDataSource } = opts;\n\n // NOT `instanceof`: two copies of this package give two `AbstractDataSource` classes and the\n // check would be false across them, rejecting a perfectly valid repository at import time.\n const isDataSourceType = isDataSourceClass(firstParamType);\n\n if (!isDataSourceType) {\n throw getError({\n message: `[@repository][${target.name}] Invalid constructor | First parameter must extend AbstractDataSource | Received: '${firstParamType.name}'`,\n });\n }\n\n if (typeof resolvedDataSource !== 'function') {\n return;\n }\n\n const isCompatible =\n firstParamType === resolvedDataSource || resolvedDataSource.prototype instanceof firstParamType;\n\n if (!isCompatible) {\n throw getError({\n message: `[@repository][${target.name}] Invalid constructor | Type mismatch | Constructor expects '${firstParamType.name}' but @repository specifies '${resolvedDataSource.name}'`,\n });\n }\n};\n\n/**\n * Auto-injects dataSource at constructor param[0] unless explicit @inject exists. A class is injected\n * by the class itself, so the container reads the key its registration recorded: a pinned\n * `binding` and a minified class name both resolve. Only a string reference is a key.\n */\nconst registerDataSourceInjection = (opts: {\n target: Function;\n registry: MetadataRegistry;\n dataSourceRef: TRepositoryMetadata['dataSource'];\n resolvedDataSource: string | Function;\n}): void => {\n const { target, registry, dataSourceRef, resolvedDataSource } = opts;\n\n // Own metadata only: `getInjectMetadata` walks the prototype chain, so a repository extending another @repository class would see the BASE's injection at param[0] and silently resolve the base's dataSource.\n const ownInjects: IInjectMetadata[] | undefined = Reflect.getOwnMetadata(\n MetadataKeys.INJECT,\n target,\n );\n const injectAtIndex0 = ownInjects?.find((entry) => entry?.index === 0);\n\n if (injectAtIndex0) {\n // `@inject({ target })` carries no key; read the one recorded on the class. The function form\n // resolves through the same helper the container uses, so both paths read one class.\n const injectedTarget = injectAtIndex0.target\n ? resolveInjectTarget({ target: injectAtIndex0.target })\n : undefined;\n const injectKey =\n injectAtIndex0.key ??\n (injectedTarget ? registry.getBindingKey({ target: injectedTarget }) : undefined);\n\n // A class is judged by its brand: its key may sit under any namespace a `binding` pinned, and\n // a provisional key may still change at registration. Only a bare key is judged by its prefix.\n const isDataSourceTarget = injectedTarget\n ? isDataSourceClass(injectedTarget)\n : typeof injectKey === 'string' && injectKey.startsWith(`${BindingNamespaces.DATASOURCE}.`);\n\n if (!isDataSourceTarget) {\n throw getError({\n message: `[@repository][${target.name}] Invalid constructor | First parameter must be a DataSource | Found @inject with key: '${String(injectKey)}' | Expected a key starting with '${BindingNamespaces.DATASOURCE}.' or a DataSource class`,\n });\n }\n\n return;\n }\n\n // Checked only when this decorator writes the injection: an explicit @inject decides for itself.\n // An interface emits `Object` and a type-only class import emits `Function` under tsc (`Object`\n // under bun); neither names the class, so neither is judged.\n const firstParamType = Reflect.getMetadata('design:paramtypes', target)?.[0];\n if (firstParamType && firstParamType !== Object && firstParamType !== Function) {\n validateFirstConstructorParameter({ target, firstParamType, resolvedDataSource });\n }\n\n // The inherited list is the base repository's own, and setInjectMetadata may write straight into it.\n if (!ownInjects) {\n Reflect.defineMetadata(\n MetadataKeys.INJECT,\n [...(registry.getInjectMetadata({ target }) ?? [])],\n target,\n );\n }\n\n const derivedKey = BindingKeys.build({\n namespace: BindingNamespaces.DATASOURCE,\n key: typeof resolvedDataSource === 'string' ? resolvedDataSource : resolvedDataSource.name,\n });\n\n // The class first, decided when the repository is resolved: by then any registration - decorated,\n // `bindingList()`, or `dataSource(X, { binding })` - has recorded its key on the class. The derived\n // key is the fallback for a class nothing recorded, bound by hand under exactly that key.\n registry.setInjectMetadata({\n target,\n index: 0,\n metadata:\n typeof dataSourceRef === 'string'\n ? { key: derivedKey, index: 0, isOptional: false }\n : { target: dataSourceRef, key: derivedKey, index: 0, isOptional: false },\n });\n};\n\n/** Resolves repository metadata and registers bindings for schema auto-discovery. */\nconst resolveRepositoryMetadata = <\n Model extends AbstractEntity = AbstractEntity,\n DataSource extends IDataSource = IDataSource,\n>(opts: {\n metadata: TRepositoryMetadata<Model, DataSource>;\n target: Function;\n registry: MetadataRegistry;\n}): IResolvedRepositoryMetadata<Model, DataSource> => {\n const { metadata, target, registry } = opts;\n\n validateRepositoryMetadata({ metadata, target });\n\n const resolvedDataSource = resolveClass({ ref: metadata.dataSource });\n if (!resolvedDataSource) {\n throw getError({\n message: `[@repository][${target.name}] The dataSource resolver returned nothing at decoration time | An import cycle leaves the datasource class undefined here; import it without the cycle, or name it as a string`,\n });\n }\n\n // No model, so no binding: the datasource owns no schema through this repository.\n if (metadata.type === RepositoryTypes.REMOTE) {\n registerDataSourceInjection({\n target,\n registry,\n dataSourceRef: metadata.dataSource,\n resolvedDataSource,\n });\n return {\n type: RepositoryTypes.REMOTE,\n dataSource: resolvedDataSource,\n operationScope: metadata.operationScope,\n };\n }\n\n const resolvedModel = resolveValue({ value: metadata.model });\n\n registry.registerRepositoryBinding({\n repository: target,\n model: resolvedModel,\n dataSource: resolvedDataSource,\n });\n\n registerDataSourceInjection({\n target,\n registry,\n dataSourceRef: metadata.dataSource,\n resolvedDataSource,\n });\n\n return {\n type: RepositoryTypes.MODEL,\n model: resolvedModel,\n dataSource: resolvedDataSource,\n operationScope: metadata.operationScope,\n };\n};\n\n/** A bare `@repository()` on a subclass reuses the type, model and datasource its nearest decorated parent declared; the registration options (`binding`, `when`, ...) are never inherited, so the subclass registers under its own name. */\nconst inheritRepositoryMetadata = (opts: {\n target: Function;\n registry: MetadataRegistry;\n}): TRepositoryMetadata => {\n // Own metadata does not exist yet at decoration time, so this read walks the prototype chain.\n const inherited = opts.registry.getRepositoryMetadata({ target: opts.target });\n if (!inherited) {\n throw getError({\n message: `[@repository][${opts.target.name}] No metadata given and no decorated repository above it in the prototype chain | pass { model, dataSource } or decorate the parent`,\n });\n }\n\n if (inherited.type === RepositoryTypes.REMOTE) {\n const { type, dataSource, operationScope } = inherited;\n return { type, dataSource, operationScope };\n }\n\n const { type, model: parentModel, dataSource, operationScope } = inherited;\n return { type, model: parentModel, dataSource, operationScope };\n};\n\nconst applyRepositoryMetadata = <\n Model extends AbstractEntity = AbstractEntity,\n DataSource extends IDataSource = IDataSource,\n>(opts: {\n metadata: TRepositoryMetadata<Model, DataSource>;\n registration: IArtifactRegistrationOptions;\n target: Function;\n registry: MetadataRegistry;\n}): void => {\n const { metadata, registration, target, registry } = opts;\n injectable({\n type: ArtifactTypes.REPOSITORY,\n ...pickRegistrationOptions({ metadata: registration }),\n })(target);\n\n const resolved = resolveRepositoryMetadata({ metadata, target, registry });\n\n registry.setRepositoryMetadata({ target, metadata: { ...metadata, _resolved: resolved } });\n};\n\nexport const repository = <\n Model extends AbstractEntity = AbstractEntity,\n DataSource extends IDataSource = IDataSource,\n>(\n metadata?: TRepositoryMetadata<Model, DataSource>,\n): ClassDecorator => {\n return (target) => {\n const registry = MetadataRegistry.getInstance();\n if (!metadata) {\n applyRepositoryMetadata({\n metadata: inheritRepositoryMetadata({ target, registry }),\n registration: {},\n target,\n registry,\n });\n return;\n }\n\n applyRepositoryMetadata({ metadata, registration: metadata, target, registry });\n };\n};\n"]}
|
|
@@ -4,7 +4,7 @@ exports.controller = void 0;
|
|
|
4
4
|
const inversion_1 = require("../../../helpers/inversion");
|
|
5
5
|
const injectable_1 = require("../injectable");
|
|
6
6
|
const controller = (metadata) => {
|
|
7
|
-
return target => {
|
|
7
|
+
return (target) => {
|
|
8
8
|
(0, injectable_1.injectable)({ type: inversion_1.ArtifactTypes.CONTROLLER, ...(0, injectable_1.pickRegistrationOptions)({ metadata }) })(target);
|
|
9
9
|
inversion_1.MetadataRegistry.getInstance().setControllerMetadata({ target, metadata });
|
|
10
10
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../../../src/base/metadata/routes/controller.ts"],"names":[],"mappings":";;;AACA,mDAAsE;AACtE,8CAAoE;AAE7D,MAAM,UAAU,GAAG,CAAC,QAA6B,EAAkB,EAAE;IAC1E,OAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../../../src/base/metadata/routes/controller.ts"],"names":[],"mappings":";;;AACA,mDAAsE;AACtE,8CAAoE;AAE7D,MAAM,UAAU,GAAG,CAAC,QAA6B,EAAkB,EAAE;IAC1E,OAAO,CAAC,MAAM,EAAE,EAAE;QAChB,IAAA,uBAAU,EAAC,EAAE,IAAI,EAAE,yBAAa,CAAC,UAAU,EAAE,GAAG,IAAA,oCAAuB,EAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,CACtF,MAAM,CACP,CAAC;QACF,4BAAgB,CAAC,WAAW,EAAE,CAAC,qBAAqB,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC7E,CAAC,CAAC;AACJ,CAAC,CAAC;AAPW,QAAA,UAAU,cAOrB","sourcesContent":["import type { TControllerMetadata } from '@/helpers/inversion';\nimport { ArtifactTypes, MetadataRegistry } from '@/helpers/inversion';\nimport { injectable, pickRegistrationOptions } from '../injectable';\n\nexport const controller = (metadata: TControllerMetadata): ClassDecorator => {\n return (target) => {\n injectable({ type: ArtifactTypes.CONTROLLER, ...pickRegistrationOptions({ metadata }) })(\n target,\n );\n MetadataRegistry.getInstance().setControllerMetadata({ target, metadata });\n };\n};\n"]}
|
|
@@ -73,7 +73,7 @@ class BaseAppErrorMiddleware extends core_1.BaseHelper {
|
|
|
73
73
|
}
|
|
74
74
|
/** Renders a thrown error for the log, through the `formatError` option when one was given. */
|
|
75
75
|
formatError(opts) {
|
|
76
|
-
return (this.formatErrorOverride ?? (o => this.renderErrorForLog(o)))(opts);
|
|
76
|
+
return (this.formatErrorOverride ?? ((o) => this.renderErrorForLog(o)))(opts);
|
|
77
77
|
}
|
|
78
78
|
/**
|
|
79
79
|
* The default log rendering: pure and deliberately small, so the whole middleware stays
|
|
@@ -97,13 +97,13 @@ class BaseAppErrorMiddleware extends core_1.BaseHelper {
|
|
|
97
97
|
lines.push(`extra: ${renderValue({ value: extra })}`);
|
|
98
98
|
}
|
|
99
99
|
if (includeStack && typeof thrown?.stack === 'string') {
|
|
100
|
-
const frames = thrown.stack.split('\n').filter(line => line.trimStart().startsWith('at '));
|
|
100
|
+
const frames = thrown.stack.split('\n').filter((line) => line.trimStart().startsWith('at '));
|
|
101
101
|
const capped = maxStackFrames === undefined ? frames : frames.slice(0, maxStackFrames);
|
|
102
102
|
if (capped.length > 0) {
|
|
103
103
|
lines.push(`stack:\n${capped.join('\n')}`);
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
-
return lines.map(line => `- ${line}`).join('\n');
|
|
106
|
+
return lines.map((line) => `- ${line}`).join('\n');
|
|
107
107
|
}
|
|
108
108
|
withRootKey(payload) {
|
|
109
109
|
return this.rootKey ? { [this.rootKey]: payload } : payload;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-error.middleware.js","sourceRoot":"","sources":["../../../../../src/base/middlewares/app-error/app-error.middleware.ts"],"names":[],"mappings":";;;AAEA,sDAMqC;AACrC,0DAAiE;AAIjE,sCAA2C;AAC3C,yDAAqF;AACrF,6CAIsB;AAEtB,+CAA+C;AAE/C,MAAM,8BAA8B,GAAG,uBAAuB,CAAC;AAE/D,2JAA2J;AAC3J,MAAM,gCAAgC,GAAG,CAAC,CAAC;AAC3C,MAAM,+BAA+B,GAAG,EAAE,CAAC;AAc3C;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,GAAG,CAAC,IAAwB,EAAU,EAAE;IACvD,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;IAEvB,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,IAAI,GAAG,IAAA,mBAAU,EAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IAEnC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;IAC/C,CAAC;IAAC,MAAM,CAAC;QACP,6FAA6F;QAC7F,8EAA8E;QAC9E,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,KAAc,EAAE,EAAE,CAC7D,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,K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E,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;YAE7F,MAAM,EAAE,GAAG;gBACT,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,CAAC;gBAClE,UAAU;gBACV,UAAU;gBACV,SAAS;gBACT,KAAK,EAAE,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,SAAS;gBAClD,OAAO,EAAE;oBACP,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG;oBACpB,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI;oBACtB,KAAK,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;oBAC9C,KAAK,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;iBAC/C;aACF,CAAC;YAEF,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,EAAE,UAAgD,CAAC,CAAC;QAC9F,CAAC,CAAC;IACJ,CAAC;CACF;AAtXD,wDAsXC","sourcesContent":["import type { ILogger, TLogLevel } from '@venizia/ignis-helpers/core';\nimport type { TNullable } from '@venizia/ignis-helpers/common';\nimport {\n BaseHelper,\n EnvironmentNames,\n LogLevels,\n MessageCode,\n MessageTemplate,\n} from '@venizia/ignis-helpers/core';\nimport { HTTP, toJsonSafe } from '@venizia/ignis-helpers/common';\nimport type { IProvider } from '@venizia/ignis-inversion';\nimport type { Context } from 'hono';\nimport type { ErrorHandler, HTTPResponseError } from 'hono/types';\nimport { REQUEST_ID_KEY } from '../common';\nimport { isDatabaseClientError, isRetryableDatabaseError } from './database.handler';\nimport {\n ApplicationErrorTypes,\n DATABASE_RETRYABLE_ERROR_CODE,\n DATABASE_RETRYABLE_ERROR_MESSAGE,\n} from './definition';\nimport type { IResolvedApplicationError, TApplicationErrorType } from './common';\nimport { formatZodError } from './zod.handler';\n\nconst DEFAULT_INTERNAL_ERROR_MESSAGE = 'Internal Server Error';\n\n/** An intentional error's throw site is still worth naming; its caller chain is framework plumbing, so it gets a smaller budget than an unexpected one. */\nconst DEFAULT_INTENTIONAL_STACK_FRAMES = 5;\nconst DEFAULT_UNEXPECTED_STACK_FRAMES = 10;\n\n/** How a thrown error is rendered into the log line. Must never throw - a throw inside the error handler turns a handled failure into an unhandled one. */\nexport type TErrorLogFormatter = (opts: {\n error: unknown;\n messageCode?: string;\n extra?: Record<string, unknown>;\n includeStack?: boolean;\n maxStackFrames?: number;\n}) => string;\n\ntype TThrown = Error | HTTPResponseError;\ntype TDatabaseClientError = ReturnType<typeof isDatabaseClientError>;\n\n/**\n * Renders a value into one log-safe fragment.\n *\n * Redaction is not optional here. This runs on `extra`, which is whatever a throw site chose to\n * attach - `getError({ extra: { apiKey } })` is a shape applications write - and in a Worker this\n * fragment lands in the browser console. `toJsonSafe` masks secret-shaped keys; a hand-rolled\n * `JSON.stringify` does not, and the server path has always redacted.\n *\n * The BigInt replacer stays: `toJsonSafe` leaves BigInt intact and `JSON.stringify` refuses it, so\n * without this a single BigInt would collapse the whole fragment to the marker below. Anything else\n * it refuses yields that marker rather than a throw - this is the last-resort error handler, where a\n * throw turns a handled failure into an unhandled one.\n */\nconst renderValue = (opts: { value: unknown }): string => {\n const { value } = opts;\n\n if (typeof value === 'string') {\n return value;\n }\n\n const safe = toJsonSafe({ value });\n\n try {\n return JSON.stringify(safe) ?? String(value);\n } catch {\n // A replacer is 6x the cost of plain stringify and deopts every key, so it is installed only\n // once BigInt has actually thrown - the case it exists for, and the rare one.\n try {\n const rendered = JSON.stringify(safe, (_key, entry: unknown) =>\n typeof entry === 'bigint' ? entry.toString() : entry,\n );\n\n return rendered ?? String(value);\n } catch {\n // Not a swallowed failure: this marker IS the report, and it lands in the log line the caller\n // is building.\n return '[unrenderable]';\n }\n }\n};\n\n/**\n * Hono `onError`: ZodError -> 422, DB client error -> 400, retryable conflict -> 409, `getError` ->\n * its own status, else 500. Browser-pure: the two reads that need a host - the ambient environment\n * name and the error formatter - are constructor OPTIONS, not methods to subclass.\n *\n * They were hooks once, and three subclasses existed to answer them and nothing else. A class seam\n * is also unreachable from application code, so the browser example had to fake the environment with\n * a Hono middleware assigning `context.env`. `@venizia/ignis`'s `AppErrorMiddleware` now just\n * supplies `process.env.NODE_ENV` and `ErrorPrettier` as options.\n */\nexport class BaseAppErrorMiddleware extends BaseHelper implements IProvider<ErrorHandler> {\n private rootKey: TNullable<string>;\n private intentionalStackFrames: number;\n private unexpectedStackFrames: number;\n\n /**\n * How this host reads its ambient environment name, and the ONE option that says whether it has\n * one at all: absent means it does not (a browser), so an unresolved name is by design; present\n * but returning `undefined` means a host that should have one is misconfigured. Either way\n * {@link isProduction} fails closed.\n *\n * A function, not a string: `process.env.NODE_ENV` has to be read per request, since a test - and\n * a `--env-file` reload - can change it after the middleware is built.\n */\n private readonly environment?: () => string | undefined;\n\n /** Replaces {@link renderErrorForLog} - `@venizia/ignis` passes `ErrorPrettier`, which reaches `node:util` and so cannot live here. */\n private readonly formatErrorOverride?: TErrorLogFormatter;\n\n constructor(opts?: {\n logger?: ILogger;\n rootKey?: string;\n intentionalStackFrames?: number;\n unexpectedStackFrames?: number;\n environment?: () => string | undefined;\n formatError?: TErrorLogFormatter;\n }) {\n // `new.target`, not a literal: a subclass logs under its own name, so `@venizia/ignis`'s\n // `AppErrorMiddleware` keeps the scope it has always logged under.\n super({ scope: new.target.name });\n\n this.rootKey = opts?.rootKey;\n this.intentionalStackFrames = opts?.intentionalStackFrames ?? DEFAULT_INTENTIONAL_STACK_FRAMES;\n this.unexpectedStackFrames = opts?.unexpectedStackFrames ?? DEFAULT_UNEXPECTED_STACK_FRAMES;\n this.environment = opts?.environment;\n this.formatErrorOverride = opts?.formatError;\n\n if (opts?.logger) {\n this.logger = opts.logger;\n }\n }\n\n /** Renders a thrown error for the log, through the `formatError` option when one was given. */\n protected formatError(opts: {\n error: unknown;\n messageCode?: string;\n extra?: Record<string, unknown>;\n includeStack?: boolean;\n maxStackFrames?: number;\n }): string {\n return (this.formatErrorOverride ?? (o => this.renderErrorForLog(o)))(opts);\n }\n\n /**\n * The default log rendering: pure and deliberately small, so the whole middleware stays\n * browser-pure.\n *\n * Must never throw, cycles included: a throw inside the error handler turns a handled failure\n * into an unhandled one.\n */\n private renderErrorForLog(opts: {\n error: unknown;\n messageCode?: string;\n extra?: Record<string, unknown>;\n includeStack?: boolean;\n maxStackFrames?: number;\n }): string {\n const { error, messageCode, extra, includeStack = true, maxStackFrames } = opts;\n const thrown = error as Partial<Error> | null | undefined;\n const lines: Array<string> = [];\n\n if (typeof thrown?.name === 'string') {\n lines.push(`name: ${thrown.name}`);\n }\n\n lines.push(\n `message: ${typeof thrown?.message === 'string' ? thrown.message : renderValue({ value: error })}`,\n );\n\n if (messageCode) {\n lines.push(`code: ${messageCode}`);\n }\n\n if (extra && Object.keys(extra).length > 0) {\n lines.push(`extra: ${renderValue({ value: extra })}`);\n }\n\n if (includeStack && typeof thrown?.stack === 'string') {\n const frames = thrown.stack.split('\\n').filter(line => line.trimStart().startsWith('at '));\n const capped = maxStackFrames === undefined ? frames : frames.slice(0, maxStackFrames);\n\n if (capped.length > 0) {\n lines.push(`stack:\\n${capped.join('\\n')}`);\n }\n }\n\n return lines.map(line => `- ${line}`).join('\\n');\n }\n\n private withRootKey(payload: object) {\n return this.rootKey ? { [this.rootKey]: payload } : payload;\n }\n\n /** Fail-closed: an unset or unrecognized env is production. */\n private isProduction(opts: { context: Context; error: TThrown; requestId: string }): boolean {\n const { context, error, requestId } = opts;\n const env = [context.env?.NODE_ENV, this.environment?.()].find(Boolean);\n\n if (!env) {\n // Only a host that HAS an ambient environment can be misconfigured about it. In a browser the\n // absence is by design, and shouting it at error level on every request buries the error the\n // reader is actually looking at. Both paths still sanitize.\n if (this.environment) {\n this.logger.error(\n '[%s] INVALID ENV IDENTIFIER | env: %s | path: %s | method: %s | url: %s\\n%s',\n requestId,\n env,\n context.req.path,\n context.req.method,\n context.req.url,\n this.formatError({ error }),\n );\n } else {\n this.logger.debug(\n '[%s] No ambient environment - sanitizing as production | path: %s | set NODE_ENV on the Hono env binding to opt out',\n requestId,\n context.req.path,\n );\n }\n\n return true;\n }\n\n return !EnvironmentNames.DEVELOPMENT_ENVS.has(env.toLowerCase());\n }\n\n private classify(opts: { error: TThrown; dbError: TDatabaseClientError }): TApplicationErrorType {\n const { error, dbError } = opts;\n\n if (dbError.isClientError) {\n return ApplicationErrorTypes.DATABASE_CLIENT;\n }\n\n if (isRetryableDatabaseError({ error })) {\n return ApplicationErrorTypes.DATABASE_RETRYABLE;\n }\n\n if ('statusCode' in error || this.readClientErrorStatus({ error }) !== undefined) {\n return ApplicationErrorTypes.INTENTIONAL;\n }\n\n return ApplicationErrorTypes.UNEXPECTED;\n }\n\n /** Hono's `HTTPException` carries `status`, not `statusCode`. Only a 4xx is the caller's fault; a 5xx stays unexpected, so its message is sanitized. */\n private readClientErrorStatus(opts: { error: TThrown }): number | undefined {\n const { error } = opts;\n\n if (!('getResponse' in error) || !('status' in error) || typeof error.status !== 'number') {\n return undefined;\n }\n\n const isClientError =\n error.status >= HTTP.ResultCodes.RS_4.BadRequest &&\n error.status < HTTP.ResultCodes.RS_5.InternalServerError;\n\n return isClientError ? error.status : undefined;\n }\n\n /** `getError` sets `statusCode`, and it wins when a foreign error carries both. Neither usable is a 500. */\n private readIntentionalStatus(opts: { error: TThrown }): number {\n const { error } = opts;\n\n if ('statusCode' in error && typeof error.statusCode === 'number') {\n return error.statusCode;\n }\n\n return this.readClientErrorStatus({ error }) ?? HTTP.ResultCodes.RS_5.InternalServerError;\n }\n\n /** An ApplicationError's `normalized` is authoritative - a `transform` may have reworded `text`. */\n private build(opts: {\n error: TThrown;\n statusCode: number;\n message: string;\n type: TApplicationErrorType;\n messageCode?: string;\n }): IResolvedApplicationError {\n const { error, statusCode, message, type, messageCode } = opts;\n\n // Fallback for a FOREIGN error that sets its own code; an ApplicationError reports via `normalized`.\n const code =\n messageCode ??\n MessageCode.resolve('messageCode' in error ? (error.messageCode as string) : undefined);\n\n const normalized =\n 'normalized' in error\n ? (error.normalized as IResolvedApplicationError['normalized'])\n : { text: message, code, args: {} };\n\n return { statusCode, message, normalized, type };\n }\n\n private resolve(opts: { error: TThrown; isProduction: boolean }): IResolvedApplicationError {\n const { error, isProduction } = opts;\n const dbError = isDatabaseClientError({ error, isProduction });\n const type = this.classify({ error, dbError });\n\n switch (type) {\n case ApplicationErrorTypes.DATABASE_CLIENT: {\n return this.build({\n error,\n type,\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n // The fallback is unreachable today; it keeps the driver's raw text from ever surfacing.\n message: dbError.message ?? DEFAULT_INTERNAL_ERROR_MESSAGE,\n });\n }\n\n case ApplicationErrorTypes.DATABASE_RETRYABLE: {\n return this.build({\n error,\n type,\n statusCode: HTTP.ResultCodes.RS_4.Conflict,\n message: DATABASE_RETRYABLE_ERROR_MESSAGE,\n messageCode: DATABASE_RETRYABLE_ERROR_CODE,\n });\n }\n\n case ApplicationErrorTypes.INTENTIONAL: {\n return this.build({\n error,\n type,\n statusCode: this.readIntentionalStatus({ error }),\n message: error.message,\n });\n }\n\n default: {\n return this.build({\n error,\n type: ApplicationErrorTypes.UNEXPECTED,\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n // Never leak a raw message - it may carry SQL, schema names or connection details.\n message: isProduction ? DEFAULT_INTERNAL_ERROR_MESSAGE : error.message,\n });\n }\n }\n }\n\n /** A throw site may set `logLevel` via `getError`; anything unset or malformed logs at `error`. */\n private resolveLogLevel(opts: { error: TThrown }): TLogLevel {\n const candidate = (opts.error as { logLevel?: unknown }).logLevel;\n\n if (typeof candidate === 'string' && LogLevels.isValid(candidate)) {\n return candidate as TLogLevel;\n }\n\n return LogLevels.ERROR;\n }\n\n /** The one place a thrown error reaches the log - called once the status is known, so it carries it. */\n private logError(opts: {\n error: TThrown;\n context: Context;\n requestId: string;\n statusCode: number;\n messageCode: string;\n type?: TApplicationErrorType;\n }) {\n const { error, context, requestId, statusCode, messageCode, type } = opts;\n\n this.logger.log(\n this.resolveLogLevel({ error }),\n '[%s] REQUEST ERROR | %s | %s %s\\n%s',\n requestId,\n statusCode,\n context.req.method,\n context.req.url,\n this.formatError({\n error,\n // The default code means \"no code\" - logging it on every error would be a noise line.\n messageCode: messageCode === MessageCode.DEFAULT ? undefined : messageCode,\n extra: 'extra' in error ? (error.extra as Record<string, unknown>) : undefined,\n includeStack: true,\n // An intentional error still needs its throw site; it just does not need the caller chain behind it.\n maxStackFrames:\n type === ApplicationErrorTypes.UNEXPECTED\n ? this.unexpectedStackFrames\n : this.intentionalStackFrames,\n }),\n );\n }\n\n /** Only an intentional error's message is a catalog template; every other branch writes its own text, so it passes through as is. */\n private renderMessage(opts: {\n resolved: IResolvedApplicationError;\n isProduction: boolean;\n requestId: string;\n }): string {\n const { resolved, isProduction, requestId } = opts;\n\n if (resolved.type !== ApplicationErrorTypes.INTENTIONAL) {\n return resolved.message;\n }\n\n const { text, missing } = MessageTemplate.render({\n text: resolved.message,\n args: resolved.normalized.args,\n });\n\n // Production stays silent and renders what it can; anywhere else a missing arg is a throw site to fix.\n if (missing.length > 0 && !isProduction) {\n this.logger.warn(\n '[%s] MESSAGE PLACEHOLDER WITHOUT ARG | code: %s | keys: %s',\n requestId,\n resolved.normalized.code,\n missing.join(', '),\n );\n }\n\n return text;\n }\n\n value(): ErrorHandler {\n return async (error, context) => {\n const requestId = context.get(REQUEST_ID_KEY);\n const isProduction = this.isProduction({ context, error, requestId });\n\n if (error.name === 'ZodError') {\n const rs = formatZodError({\n isProduction,\n requestId,\n url: context.req.url,\n path: context.req.path,\n error,\n });\n\n this.logError({\n error,\n context,\n requestId,\n statusCode: rs.statusCode,\n messageCode: rs.response.normalized.code,\n });\n\n return context.json(\n this.withRootKey(rs.response),\n rs.statusCode as Parameters<typeof context.json>[1],\n );\n }\n\n const resolved = this.resolve({ error, isProduction });\n const { statusCode, normalized, type } = resolved;\n\n this.logError({ error, context, requestId, statusCode, messageCode: normalized.code, type });\n\n const rs = {\n message: this.renderMessage({ resolved, isProduction, requestId }),\n statusCode,\n normalized,\n requestId,\n extra: 'extra' in error ? error?.extra : undefined,\n details: {\n url: context.req.url,\n path: context.req.path,\n stack: !isProduction ? error.stack : undefined,\n cause: !isProduction ? error.cause : undefined,\n },\n };\n\n return context.json(this.withRootKey(rs), statusCode as Parameters<typeof context.json>[1]);\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"app-error.middleware.js","sourceRoot":"","sources":["../../../../../src/base/middlewares/app-error/app-error.middleware.ts"],"names":[],"mappings":";;;AAEA,sDAMqC;AACrC,0DAAiE;AAIjE,sCAA2C;AAC3C,yDAAqF;AACrF,6CAIsB;AAEtB,+CAA+C;AAE/C,MAAM,8BAA8B,GAAG,uBAAuB,CAAC;AAE/D,2JAA2J;AAC3J,MAAM,gCAAgC,GAAG,CAAC,CAAC;AAC3C,MAAM,+BAA+B,GAAG,EAAE,CAAC;AAc3C;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,GAAG,CAAC,IAAwB,EAAU,EAAE;IACvD,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;IAEvB,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,IAAI,GAAG,IAAA,mBAAU,EAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IAEnC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;IAC/C,CAAC;IAAC,MAAM,CAAC;QACP,6FAA6F;QAC7F,8EAA8E;QAC9E,IAAI,CAAC;YACH,MAAM,QAAQ,G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,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,CAAC;YACvD,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC;YAElD,IAAI,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;YAE7F,MAAM,EAAE,GAAG;gBACT,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,CAAC;gBAClE,UAAU;gBACV,UAAU;gBACV,SAAS;gBACT,KAAK,EAAE,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,SAAS;gBAClD,OAAO,EAAE;oBACP,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG;oBACpB,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI;oBACtB,KAAK,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;oBAC9C,KAAK,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;iBAC/C;aACF,CAAC;YAEF,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,EAAE,UAAgD,CAAC,CAAC;QAC9F,CAAC,CAAC;IACJ,CAAC;CACF;AAtXD,wDAsXC","sourcesContent":["import type { ILogger, TLogLevel } from '@venizia/ignis-helpers/core';\nimport type { TNullable } from '@venizia/ignis-helpers/common';\nimport {\n BaseHelper,\n EnvironmentNames,\n LogLevels,\n MessageCode,\n MessageTemplate,\n} from '@venizia/ignis-helpers/core';\nimport { HTTP, toJsonSafe } from '@venizia/ignis-helpers/common';\nimport type { IProvider } from '@venizia/ignis-inversion';\nimport type { Context } from 'hono';\nimport type { ErrorHandler, HTTPResponseError } from 'hono/types';\nimport { REQUEST_ID_KEY } from '../common';\nimport { isDatabaseClientError, isRetryableDatabaseError } from './database.handler';\nimport {\n ApplicationErrorTypes,\n DATABASE_RETRYABLE_ERROR_CODE,\n DATABASE_RETRYABLE_ERROR_MESSAGE,\n} from './definition';\nimport type { IResolvedApplicationError, TApplicationErrorType } from './common';\nimport { formatZodError } from './zod.handler';\n\nconst DEFAULT_INTERNAL_ERROR_MESSAGE = 'Internal Server Error';\n\n/** An intentional error's throw site is still worth naming; its caller chain is framework plumbing, so it gets a smaller budget than an unexpected one. */\nconst DEFAULT_INTENTIONAL_STACK_FRAMES = 5;\nconst DEFAULT_UNEXPECTED_STACK_FRAMES = 10;\n\n/** How a thrown error is rendered into the log line. Must never throw - a throw inside the error handler turns a handled failure into an unhandled one. */\nexport type TErrorLogFormatter = (opts: {\n error: unknown;\n messageCode?: string;\n extra?: Record<string, unknown>;\n includeStack?: boolean;\n maxStackFrames?: number;\n}) => string;\n\ntype TThrown = Error | HTTPResponseError;\ntype TDatabaseClientError = ReturnType<typeof isDatabaseClientError>;\n\n/**\n * Renders a value into one log-safe fragment.\n *\n * Redaction is not optional here. This runs on `extra`, which is whatever a throw site chose to\n * attach - `getError({ extra: { apiKey } })` is a shape applications write - and in a Worker this\n * fragment lands in the browser console. `toJsonSafe` masks secret-shaped keys; a hand-rolled\n * `JSON.stringify` does not, and the server path has always redacted.\n *\n * The BigInt replacer stays: `toJsonSafe` leaves BigInt intact and `JSON.stringify` refuses it, so\n * without this a single BigInt would collapse the whole fragment to the marker below. Anything else\n * it refuses yields that marker rather than a throw - this is the last-resort error handler, where a\n * throw turns a handled failure into an unhandled one.\n */\nconst renderValue = (opts: { value: unknown }): string => {\n const { value } = opts;\n\n if (typeof value === 'string') {\n return value;\n }\n\n const safe = toJsonSafe({ value });\n\n try {\n return JSON.stringify(safe) ?? String(value);\n } catch {\n // A replacer is 6x the cost of plain stringify and deopts every key, so it is installed only\n // once BigInt has actually thrown - the case it exists for, and the rare one.\n try {\n const rendered = JSON.stringify(safe, (_key, entry: unknown) =>\n typeof entry === 'bigint' ? entry.toString() : entry,\n );\n\n return rendered ?? String(value);\n } catch {\n // Not a swallowed failure: this marker IS the report, and it lands in the log line the caller\n // is building.\n return '[unrenderable]';\n }\n }\n};\n\n/**\n * Hono `onError`: ZodError -> 422, DB client error -> 400, retryable conflict -> 409, `getError` ->\n * its own status, else 500. Browser-pure: the two reads that need a host - the ambient environment\n * name and the error formatter - are constructor OPTIONS, not methods to subclass.\n *\n * They were hooks once, and three subclasses existed to answer them and nothing else. A class seam\n * is also unreachable from application code, so the browser example had to fake the environment with\n * a Hono middleware assigning `context.env`. `@venizia/ignis`'s `AppErrorMiddleware` now just\n * supplies `process.env.NODE_ENV` and `ErrorPrettier` as options.\n */\nexport class BaseAppErrorMiddleware extends BaseHelper implements IProvider<ErrorHandler> {\n private rootKey: TNullable<string>;\n private intentionalStackFrames: number;\n private unexpectedStackFrames: number;\n\n /**\n * How this host reads its ambient environment name, and the ONE option that says whether it has\n * one at all: absent means it does not (a browser), so an unresolved name is by design; present\n * but returning `undefined` means a host that should have one is misconfigured. Either way\n * {@link isProduction} fails closed.\n *\n * A function, not a string: `process.env.NODE_ENV` has to be read per request, since a test - and\n * a `--env-file` reload - can change it after the middleware is built.\n */\n private readonly environment?: () => string | undefined;\n\n /** Replaces {@link renderErrorForLog} - `@venizia/ignis` passes `ErrorPrettier`, which reaches `node:util` and so cannot live here. */\n private readonly formatErrorOverride?: TErrorLogFormatter;\n\n constructor(opts?: {\n logger?: ILogger;\n rootKey?: string;\n intentionalStackFrames?: number;\n unexpectedStackFrames?: number;\n environment?: () => string | undefined;\n formatError?: TErrorLogFormatter;\n }) {\n // `new.target`, not a literal: a subclass logs under its own name, so `@venizia/ignis`'s\n // `AppErrorMiddleware` keeps the scope it has always logged under.\n super({ scope: new.target.name });\n\n this.rootKey = opts?.rootKey;\n this.intentionalStackFrames = opts?.intentionalStackFrames ?? DEFAULT_INTENTIONAL_STACK_FRAMES;\n this.unexpectedStackFrames = opts?.unexpectedStackFrames ?? DEFAULT_UNEXPECTED_STACK_FRAMES;\n this.environment = opts?.environment;\n this.formatErrorOverride = opts?.formatError;\n\n if (opts?.logger) {\n this.logger = opts.logger;\n }\n }\n\n /** Renders a thrown error for the log, through the `formatError` option when one was given. */\n protected formatError(opts: {\n error: unknown;\n messageCode?: string;\n extra?: Record<string, unknown>;\n includeStack?: boolean;\n maxStackFrames?: number;\n }): string {\n return (this.formatErrorOverride ?? ((o) => this.renderErrorForLog(o)))(opts);\n }\n\n /**\n * The default log rendering: pure and deliberately small, so the whole middleware stays\n * browser-pure.\n *\n * Must never throw, cycles included: a throw inside the error handler turns a handled failure\n * into an unhandled one.\n */\n private renderErrorForLog(opts: {\n error: unknown;\n messageCode?: string;\n extra?: Record<string, unknown>;\n includeStack?: boolean;\n maxStackFrames?: number;\n }): string {\n const { error, messageCode, extra, includeStack = true, maxStackFrames } = opts;\n const thrown = error as Partial<Error> | null | undefined;\n const lines: Array<string> = [];\n\n if (typeof thrown?.name === 'string') {\n lines.push(`name: ${thrown.name}`);\n }\n\n lines.push(\n `message: ${typeof thrown?.message === 'string' ? thrown.message : renderValue({ value: error })}`,\n );\n\n if (messageCode) {\n lines.push(`code: ${messageCode}`);\n }\n\n if (extra && Object.keys(extra).length > 0) {\n lines.push(`extra: ${renderValue({ value: extra })}`);\n }\n\n if (includeStack && typeof thrown?.stack === 'string') {\n const frames = thrown.stack.split('\\n').filter((line) => line.trimStart().startsWith('at '));\n const capped = maxStackFrames === undefined ? frames : frames.slice(0, maxStackFrames);\n\n if (capped.length > 0) {\n lines.push(`stack:\\n${capped.join('\\n')}`);\n }\n }\n\n return lines.map((line) => `- ${line}`).join('\\n');\n }\n\n private withRootKey(payload: object) {\n return this.rootKey ? { [this.rootKey]: payload } : payload;\n }\n\n /** Fail-closed: an unset or unrecognized env is production. */\n private isProduction(opts: { context: Context; error: TThrown; requestId: string }): boolean {\n const { context, error, requestId } = opts;\n const env = [context.env?.NODE_ENV, this.environment?.()].find(Boolean);\n\n if (!env) {\n // Only a host that HAS an ambient environment can be misconfigured about it. In a browser the\n // absence is by design, and shouting it at error level on every request buries the error the\n // reader is actually looking at. Both paths still sanitize.\n if (this.environment) {\n this.logger.error(\n '[%s] INVALID ENV IDENTIFIER | env: %s | path: %s | method: %s | url: %s\\n%s',\n requestId,\n env,\n context.req.path,\n context.req.method,\n context.req.url,\n this.formatError({ error }),\n );\n } else {\n this.logger.debug(\n '[%s] No ambient environment - sanitizing as production | path: %s | set NODE_ENV on the Hono env binding to opt out',\n requestId,\n context.req.path,\n );\n }\n\n return true;\n }\n\n return !EnvironmentNames.DEVELOPMENT_ENVS.has(env.toLowerCase());\n }\n\n private classify(opts: { error: TThrown; dbError: TDatabaseClientError }): TApplicationErrorType {\n const { error, dbError } = opts;\n\n if (dbError.isClientError) {\n return ApplicationErrorTypes.DATABASE_CLIENT;\n }\n\n if (isRetryableDatabaseError({ error })) {\n return ApplicationErrorTypes.DATABASE_RETRYABLE;\n }\n\n if ('statusCode' in error || this.readClientErrorStatus({ error }) !== undefined) {\n return ApplicationErrorTypes.INTENTIONAL;\n }\n\n return ApplicationErrorTypes.UNEXPECTED;\n }\n\n /** Hono's `HTTPException` carries `status`, not `statusCode`. Only a 4xx is the caller's fault; a 5xx stays unexpected, so its message is sanitized. */\n private readClientErrorStatus(opts: { error: TThrown }): number | undefined {\n const { error } = opts;\n\n if (!('getResponse' in error) || !('status' in error) || typeof error.status !== 'number') {\n return undefined;\n }\n\n const isClientError =\n error.status >= HTTP.ResultCodes.RS_4.BadRequest &&\n error.status < HTTP.ResultCodes.RS_5.InternalServerError;\n\n return isClientError ? error.status : undefined;\n }\n\n /** `getError` sets `statusCode`, and it wins when a foreign error carries both. Neither usable is a 500. */\n private readIntentionalStatus(opts: { error: TThrown }): number {\n const { error } = opts;\n\n if ('statusCode' in error && typeof error.statusCode === 'number') {\n return error.statusCode;\n }\n\n return this.readClientErrorStatus({ error }) ?? HTTP.ResultCodes.RS_5.InternalServerError;\n }\n\n /** An ApplicationError's `normalized` is authoritative - a `transform` may have reworded `text`. */\n private build(opts: {\n error: TThrown;\n statusCode: number;\n message: string;\n type: TApplicationErrorType;\n messageCode?: string;\n }): IResolvedApplicationError {\n const { error, statusCode, message, type, messageCode } = opts;\n\n // Fallback for a FOREIGN error that sets its own code; an ApplicationError reports via `normalized`.\n const code =\n messageCode ??\n MessageCode.resolve('messageCode' in error ? (error.messageCode as string) : undefined);\n\n const normalized =\n 'normalized' in error\n ? (error.normalized as IResolvedApplicationError['normalized'])\n : { text: message, code, args: {} };\n\n return { statusCode, message, normalized, type };\n }\n\n private resolve(opts: { error: TThrown; isProduction: boolean }): IResolvedApplicationError {\n const { error, isProduction } = opts;\n const dbError = isDatabaseClientError({ error, isProduction });\n const type = this.classify({ error, dbError });\n\n switch (type) {\n case ApplicationErrorTypes.DATABASE_CLIENT: {\n return this.build({\n error,\n type,\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n // The fallback is unreachable today; it keeps the driver's raw text from ever surfacing.\n message: dbError.message ?? DEFAULT_INTERNAL_ERROR_MESSAGE,\n });\n }\n\n case ApplicationErrorTypes.DATABASE_RETRYABLE: {\n return this.build({\n error,\n type,\n statusCode: HTTP.ResultCodes.RS_4.Conflict,\n message: DATABASE_RETRYABLE_ERROR_MESSAGE,\n messageCode: DATABASE_RETRYABLE_ERROR_CODE,\n });\n }\n\n case ApplicationErrorTypes.INTENTIONAL: {\n return this.build({\n error,\n type,\n statusCode: this.readIntentionalStatus({ error }),\n message: error.message,\n });\n }\n\n default: {\n return this.build({\n error,\n type: ApplicationErrorTypes.UNEXPECTED,\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n // Never leak a raw message - it may carry SQL, schema names or connection details.\n message: isProduction ? DEFAULT_INTERNAL_ERROR_MESSAGE : error.message,\n });\n }\n }\n }\n\n /** A throw site may set `logLevel` via `getError`; anything unset or malformed logs at `error`. */\n private resolveLogLevel(opts: { error: TThrown }): TLogLevel {\n const candidate = (opts.error as { logLevel?: unknown }).logLevel;\n\n if (typeof candidate === 'string' && LogLevels.isValid(candidate)) {\n return candidate as TLogLevel;\n }\n\n return LogLevels.ERROR;\n }\n\n /** The one place a thrown error reaches the log - called once the status is known, so it carries it. */\n private logError(opts: {\n error: TThrown;\n context: Context;\n requestId: string;\n statusCode: number;\n messageCode: string;\n type?: TApplicationErrorType;\n }) {\n const { error, context, requestId, statusCode, messageCode, type } = opts;\n\n this.logger.log(\n this.resolveLogLevel({ error }),\n '[%s] REQUEST ERROR | %s | %s %s\\n%s',\n requestId,\n statusCode,\n context.req.method,\n context.req.url,\n this.formatError({\n error,\n // The default code means \"no code\" - logging it on every error would be a noise line.\n messageCode: messageCode === MessageCode.DEFAULT ? undefined : messageCode,\n extra: 'extra' in error ? (error.extra as Record<string, unknown>) : undefined,\n includeStack: true,\n // An intentional error still needs its throw site; it just does not need the caller chain behind it.\n maxStackFrames:\n type === ApplicationErrorTypes.UNEXPECTED\n ? this.unexpectedStackFrames\n : this.intentionalStackFrames,\n }),\n );\n }\n\n /** Only an intentional error's message is a catalog template; every other branch writes its own text, so it passes through as is. */\n private renderMessage(opts: {\n resolved: IResolvedApplicationError;\n isProduction: boolean;\n requestId: string;\n }): string {\n const { resolved, isProduction, requestId } = opts;\n\n if (resolved.type !== ApplicationErrorTypes.INTENTIONAL) {\n return resolved.message;\n }\n\n const { text, missing } = MessageTemplate.render({\n text: resolved.message,\n args: resolved.normalized.args,\n });\n\n // Production stays silent and renders what it can; anywhere else a missing arg is a throw site to fix.\n if (missing.length > 0 && !isProduction) {\n this.logger.warn(\n '[%s] MESSAGE PLACEHOLDER WITHOUT ARG | code: %s | keys: %s',\n requestId,\n resolved.normalized.code,\n missing.join(', '),\n );\n }\n\n return text;\n }\n\n value(): ErrorHandler {\n return async (error, context) => {\n const requestId = context.get(REQUEST_ID_KEY);\n const isProduction = this.isProduction({ context, error, requestId });\n\n if (error.name === 'ZodError') {\n const rs = formatZodError({\n isProduction,\n requestId,\n url: context.req.url,\n path: context.req.path,\n error,\n });\n\n this.logError({\n error,\n context,\n requestId,\n statusCode: rs.statusCode,\n messageCode: rs.response.normalized.code,\n });\n\n return context.json(\n this.withRootKey(rs.response),\n rs.statusCode as Parameters<typeof context.json>[1],\n );\n }\n\n const resolved = this.resolve({ error, isProduction });\n const { statusCode, normalized, type } = resolved;\n\n this.logError({ error, context, requestId, statusCode, messageCode: normalized.code, type });\n\n const rs = {\n message: this.renderMessage({ resolved, isProduction, requestId }),\n statusCode,\n normalized,\n requestId,\n extra: 'extra' in error ? error?.extra : undefined,\n details: {\n url: context.req.url,\n path: context.req.path,\n stack: !isProduction ? error.stack : undefined,\n cause: !isProduction ? error.cause : undefined,\n },\n };\n\n return context.json(this.withRootKey(rs), statusCode as Parameters<typeof context.json>[1]);\n };\n }\n}\n"]}
|
|
@@ -28,7 +28,7 @@ const formatZodError = (opts) => {
|
|
|
28
28
|
let messageCode;
|
|
29
29
|
let message = DEFAULT_VALIDATION_MESSAGE;
|
|
30
30
|
if (issues && issues.length > 0) {
|
|
31
|
-
const primaryIssue = issues.find(issue => extractIssueCode({ issue }) !== undefined) ?? issues[0];
|
|
31
|
+
const primaryIssue = issues.find((issue) => extractIssueCode({ issue }) !== undefined) ?? issues[0];
|
|
32
32
|
messageCode = extractIssueCode({ issue: primaryIssue }) ?? primaryIssue.code;
|
|
33
33
|
message = primaryIssue.message;
|
|
34
34
|
}
|
|
@@ -47,7 +47,7 @@ const formatZodError = (opts) => {
|
|
|
47
47
|
path,
|
|
48
48
|
stack: !isProduction ? error.stack : undefined,
|
|
49
49
|
cause: issues
|
|
50
|
-
? issues.map(el => ({
|
|
50
|
+
? issues.map((el) => ({
|
|
51
51
|
path: el.path.join('.') || 'root',
|
|
52
52
|
message: el.message,
|
|
53
53
|
code: el.code,
|
|
@@ -1 +1 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,EAAE,EAAE,CAAC,gBAAgB,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,SAAS,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC;QACjF,WAAW,GAAG,gBAAgB,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,IAAI,YAAY,CAAC,IAAI,CAAC;QAC7E,OAAO,GAAG,YAAY,CAAC,OAAO,CAAC;IACjC,CAAC;IAED,4KAA4K;IAC5K,MAAM,mBAAmB,GAAG,kBAAW,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAE7D,OAAO;QACL,UAAU;QACV,QAAQ,EAAE;YACR,OAAO;YACP,UAAU;YACV,yGAAyG;YACzG,UAAU,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,EAAE,EAAE;YAClE,SAAS;YACT,OAAO,EAAE;gBACP,GAAG;gBACH,IAAI;gBACJ,KAAK,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;gBAC9C,KAAK,EAAE,MAAM;oBACX,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;wBAClB,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,MAAM;wBACjC,OAAO,EAAE,EAAE,CAAC,OAAO;wBACnB,IAAI,EAAE,EAAE,CAAC,IAAI;wBACb,QAAQ,EAAE,EAAE,CAAC,QAAQ;wBACrB,QAAQ,EAAE,EAAE,CAAC,QAAQ;qBACtB,CAAC,CAAC;oBACL,CAAC,CAAC,gBAAgB;aACrB;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AAzDW,QAAA,cAAc,kBAyDzB","sourcesContent":["import { MessageCode } from '@venizia/ignis-helpers/core';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport type { HTTPResponseError } from 'hono/types';\nimport type { IZodIssueLike } from './common';\n\nconst DEFAULT_VALIDATION_MESSAGE = 'ValidationError';\n\n/** Returns a schema-author-supplied code (`issue.params.code`) when it is a non-empty string. */\nconst extractIssueCode = (opts: { issue: IZodIssueLike }) => {\n const paramsCode = opts.issue?.params?.code;\n\n if (typeof paramsCode === 'string' && paramsCode.length > 0) {\n return paramsCode;\n }\n\n return undefined;\n};\n\n/** Formats a ZodError into the 422 validation response. */\nexport const formatZodError = (opts: {\n isProduction: boolean;\n requestId: string;\n url: string;\n path: string;\n error: Error | HTTPResponseError;\n}) => {\n const { isProduction, requestId, url, path, error } = opts;\n const statusCode = HTTP.ResultCodes.RS_4.UnprocessableEntity;\n\n let validationErrors: unknown;\n try {\n validationErrors = JSON.parse(error.message);\n } catch {\n validationErrors = error;\n }\n\n const issues = Array.isArray(validationErrors) ? (validationErrors as IZodIssueLike[]) : null;\n\n // Prefer the first issue with a custom `params.code`, else its raw Zod code.\n let messageCode: string | undefined;\n let message = DEFAULT_VALIDATION_MESSAGE;\n\n if (issues && issues.length > 0) {\n const primaryIssue =\n issues.find((issue) => extractIssueCode({ issue }) !== undefined) ?? issues[0];\n messageCode = extractIssueCode({ issue: primaryIssue }) ?? primaryIssue.code;\n message = primaryIssue.message;\n }\n\n // A ZodError we could not parse into issues yields no code of its own; the response still carries one, so no error response is ever missing the field a client branches on.\n const resolvedMessageCode = MessageCode.resolve(messageCode);\n\n return {\n statusCode,\n response: {\n message,\n statusCode,\n // `args` is empty: a Zod issue carries no interpolation values - per-field detail is in `details.cause`.\n normalized: { text: message, code: resolvedMessageCode, args: {} },\n requestId,\n details: {\n url,\n path,\n stack: !isProduction ? error.stack : undefined,\n cause: issues\n ? issues.map((el) => ({\n path: el.path.join('.') || 'root',\n message: el.message,\n code: el.code,\n expected: el.expected,\n received: el.received,\n }))\n : validationErrors,\n },\n },\n };\n};\n"]}
|
|
@@ -10,7 +10,7 @@ const FORM_CONTENT_TYPES = [
|
|
|
10
10
|
/** Whether a route declares a form body, so its validator will parse one. */
|
|
11
11
|
const hasFormBody = (opts) => {
|
|
12
12
|
const { content } = opts;
|
|
13
|
-
return content !== undefined && FORM_CONTENT_TYPES.some(contentType => contentType in content);
|
|
13
|
+
return content !== undefined && FORM_CONTENT_TYPES.some((contentType) => contentType in content);
|
|
14
14
|
};
|
|
15
15
|
exports.hasFormBody = hasFormBody;
|
|
16
16
|
/**
|
|
@@ -20,7 +20,7 @@ exports.hasFormBody = hasFormBody;
|
|
|
20
20
|
*/
|
|
21
21
|
const formBodyReader = async (context, next) => {
|
|
22
22
|
const contentType = context.req.header(common_1.HTTP.Headers.CONTENT_TYPE) ?? '';
|
|
23
|
-
if (FORM_CONTENT_TYPES.some(formType => contentType.includes(formType))) {
|
|
23
|
+
if (FORM_CONTENT_TYPES.some((formType) => contentType.includes(formType))) {
|
|
24
24
|
await (0, core_1.readFormBody)({ req: context.req });
|
|
25
25
|
}
|
|
26
26
|
await next();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form-body.middleware.js","sourceRoot":"","sources":["../../../../../src/base/middlewares/form-body/form-body.middleware.ts"],"names":[],"mappings":";;;AAAA,0DAAqD;AACrD,sDAA2D;AAG3D,MAAM,kBAAkB,GAAG;IACzB,aAAI,CAAC,YAAY,CAAC,mBAAmB;IACrC,aAAI,CAAC,YAAY,CAAC,2BAA2B;CAC9C,CAAC;AAEF,6EAA6E;AACtE,MAAM,WAAW,GAAG,CAAC,IAA2C,EAAW,EAAE;IAClF,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACzB,OAAO,OAAO,KAAK,SAAS,IAAI,kBAAkB,CAAC,IAAI,CAAC,WAAW,
|
|
1
|
+
{"version":3,"file":"form-body.middleware.js","sourceRoot":"","sources":["../../../../../src/base/middlewares/form-body/form-body.middleware.ts"],"names":[],"mappings":";;;AAAA,0DAAqD;AACrD,sDAA2D;AAG3D,MAAM,kBAAkB,GAAG;IACzB,aAAI,CAAC,YAAY,CAAC,mBAAmB;IACrC,aAAI,CAAC,YAAY,CAAC,2BAA2B;CAC9C,CAAC;AAEF,6EAA6E;AACtE,MAAM,WAAW,GAAG,CAAC,IAA2C,EAAW,EAAE;IAClF,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACzB,OAAO,OAAO,KAAK,SAAS,IAAI,kBAAkB,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,IAAI,OAAO,CAAC,CAAC;AACnG,CAAC,CAAC;AAHW,QAAA,WAAW,eAGtB;AAEF;;;;GAIG;AACI,MAAM,cAAc,GAAsB,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;IACvE,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,aAAI,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;IAExE,IAAI,kBAAkB,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;QAC1E,MAAM,IAAA,mBAAY,EAAC,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAC3C,CAAC;IAED,MAAM,IAAI,EAAE,CAAC;AACf,CAAC,CAAC;AARW,QAAA,cAAc,kBAQzB","sourcesContent":["import { HTTP } from '@venizia/ignis-helpers/common';\nimport { readFormBody } from '@venizia/ignis-helpers/core';\nimport type { MiddlewareHandler } from 'hono/types';\n\nconst FORM_CONTENT_TYPES = [\n HTTP.HeaderValues.MULTIPART_FORM_DATA,\n HTTP.HeaderValues.APPLICATION_FORM_URLENCODED,\n];\n\n/** Whether a route declares a form body, so its validator will parse one. */\nexport const hasFormBody = (opts: { content?: Record<string, unknown> }): boolean => {\n const { content } = opts;\n return content !== undefined && FORM_CONTENT_TYPES.some((contentType) => contentType in content);\n};\n\n/**\n * Parses a declared form body just ahead of the route's validator, which reads the cached result.\n * Left to the validator, a malformed body is a bare `HTTPException(400)` carrying the parser's own\n * text and no code; read here, it is `core.request.body_malformed`.\n */\nexport const formBodyReader: MiddlewareHandler = async (context, next) => {\n const contentType = context.req.header(HTTP.Headers.CONTENT_TYPE) ?? '';\n\n if (FORM_CONTENT_TYPES.some((formType) => contentType.includes(formType))) {\n await readFormBody({ req: context.req });\n }\n\n await next();\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"not-found.middleware.js","sourceRoot":"","sources":["../../../../../src/base/middlewares/not-found/not-found.middleware.ts"],"names":[],"mappings":";;;AACA,0DAAqD;AAErD,sCAA2C;AAEpC,MAAM,eAAe,GAAG,CAAC,IAA0B,EAAE,EAAE;IAC5D,MAAM,EAAE,MAAM,GAAG,OAAO,EAAE,GAAG,IAAI,CAAC;IAElC,MAAM,EAAE,GAAoB,KAAK,
|
|
1
|
+
{"version":3,"file":"not-found.middleware.js","sourceRoot":"","sources":["../../../../../src/base/middlewares/not-found/not-found.middleware.ts"],"names":[],"mappings":";;;AACA,0DAAqD;AAErD,sCAA2C;AAEpC,MAAM,eAAe,GAAG,CAAC,IAA0B,EAAE,EAAE;IAC5D,MAAM,EAAE,MAAM,GAAG,OAAO,EAAE,GAAG,IAAI,CAAC;IAElC,MAAM,EAAE,GAAoB,KAAK,EAAE,OAAO,EAAE,EAAE;QAC5C,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,uBAAc,CAAC,CAAC;QAE9C,6FAA6F;QAC7F,+FAA+F;QAC/F,6FAA6F;QAC7F,MAAM,CAAC,IAAI,CACT,yCAAyC,EACzC,SAAS,EACT,OAAO,CAAC,GAAG,CAAC,IAAI,EAChB,OAAO,CAAC,GAAG,CAAC,GAAG,CAChB,CAAC;QAEF,OAAO,OAAO,CAAC,IAAI,CACjB;YACE,OAAO,EAAE,eAAe;YACxB,UAAU,EAAE,aAAI,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ;YAC1C,SAAS;YACT,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI;YACtB,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG;SACrB,EACD,aAAI,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAC/B,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AA7BW,QAAA,eAAe,mBA6B1B","sourcesContent":["import type { ILogger } from '@venizia/ignis-helpers/core';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport type { NotFoundHandler } from 'hono/types';\nimport { REQUEST_ID_KEY } from '../common';\n\nexport const notFoundHandler = (opts: { logger?: ILogger }) => {\n const { logger = console } = opts;\n\n const mw: NotFoundHandler = async (context) => {\n const requestId = context.get(REQUEST_ID_KEY);\n\n // WARN, not ERROR: an unrouted path is the callers mistake, and this middleware is installed\n // unconditionally - so scanner traffic filled the dedicated error log and tripped error-volume\n // alerting. The same reasoning is already applied to an expired token elsewhere in the tree.\n logger.warn(\n '[%s] URL NOT FOUND | path: %s | url: %s',\n requestId,\n context.req.path,\n context.req.url,\n );\n\n return context.json(\n {\n message: 'URL NOT FOUND',\n statusCode: HTTP.ResultCodes.RS_4.NotFound,\n requestId,\n path: context.req.path,\n url: context.req.url,\n },\n HTTP.ResultCodes.RS_4.NotFound,\n );\n };\n\n return mw;\n};\n"]}
|
|
@@ -17,7 +17,7 @@ const snakeToCamel = (shape) => {
|
|
|
17
17
|
}));
|
|
18
18
|
return zod_openapi_1.z
|
|
19
19
|
.object(shape)
|
|
20
|
-
.transform(data => (0, core_1.keysToCamel)(data))
|
|
20
|
+
.transform((data) => (0, core_1.keysToCamel)(data))
|
|
21
21
|
.pipe(zod_openapi_1.z.object(camelShape));
|
|
22
22
|
};
|
|
23
23
|
exports.snakeToCamel = snakeToCamel;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utilities.js","sourceRoot":"","sources":["../../../../../src/base/models/common/utilities.ts"],"names":[],"mappings":";;;AAAA,mDAAsC;AACtC,sDAA6E;A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GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QACzC,OAAO,CAAC,IAAA,cAAO,EAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;IAC/B,CAAC,CAAC,CACkB,CAAC;IAEvB,OAAO,eAAC;SACL,MAAM,CAAC,KAAK,CAAC;SACb,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAA,kBAAW,EAAC,IAAI,CAAC,CAAC;SACtC,IAAI,CAAC,eAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;AAChC,CAAC,CAAC;AAXW,QAAA,YAAY,gBAWvB","sourcesContent":["import { z } from '@hono/zod-openapi';\nimport { getError, keysToCamel, toCamel } from '@venizia/ignis-helpers/core';\nimport type { TEntityId } from './types';\n\n/** The only way into `TEntityId`. Rejects an empty string - an id that is `''` collapses a `where` to no condition. */\nexport const toEntityId = (opts: { value: string }): TEntityId => {\n if (opts.value.length === 0) {\n throw getError({ message: '[toEntityId] Refusing an empty string as an entity id' });\n }\n\n return opts.value as TEntityId;\n};\n\ntype TSnakeToCamelCase<S extends string> = S extends `${infer T}_${infer U}`\n ? `${T}${Capitalize<TSnakeToCamelCase<U>>}`\n : S;\n\ntype TCamelCaseKeys<T extends z.ZodRawShape> = {\n [K in keyof T as K extends string ? TSnakeToCamelCase<K> : K]: T[K] extends z.ZodType<infer U>\n ? z.ZodType<U>\n : T[K];\n};\n\nexport const snakeToCamel = <T extends z.ZodRawShape>(shape: T) => {\n const camelShape = Object.fromEntries(\n Object.entries(shape).map(([key, value]) => {\n return [toCamel(key), value];\n }),\n ) as TCamelCaseKeys<T>;\n\n return z\n .object(shape)\n .transform((data) => keysToCamel(data))\n .pipe(z.object(camelShape));\n};\n"]}
|
|
@@ -32,7 +32,7 @@ export declare class RepositoryTypes {
|
|
|
32
32
|
}
|
|
33
33
|
/** Valid repository type values. */
|
|
34
34
|
export type TRepositoryType = TConstValue<typeof RepositoryTypes>;
|
|
35
|
-
/** What a row-scope filter (`@model` settings.
|
|
35
|
+
/** What a row-scope filter (`@model` settings.access) does when `resolve()` returns null/undefined. */
|
|
36
36
|
export declare class ScopeFilterMissingBehaviors {
|
|
37
37
|
/** An unresolved scope matches ZERO rows - the safe reading of "caller's scope is unknown". */
|
|
38
38
|
static readonly DENY = "deny";
|
|
@@ -43,6 +43,21 @@ export declare class ScopeFilterMissingBehaviors {
|
|
|
43
43
|
}
|
|
44
44
|
/** Valid scope-filter missing-behavior values. */
|
|
45
45
|
export type TScopeFilterMissingBehavior = TConstValue<typeof ScopeFilterMissingBehaviors>;
|
|
46
|
+
/**
|
|
47
|
+
* What a scoped write does with a row whose scope column disagrees with the resolved scope
|
|
48
|
+
* (`@model` settings.access.write.mode). A scope that returns `ScopeFilters.UNRESTRICTED`
|
|
49
|
+
* passes either way.
|
|
50
|
+
*/
|
|
51
|
+
export declare class ScopeWriteGuards {
|
|
52
|
+
/** Default. A row whose scope column disagrees, or is absent on create, is refused and nothing is written. */
|
|
53
|
+
static readonly REJECT = "reject";
|
|
54
|
+
/** An ABSENT scope column is filled from an equality scope; a value that disagrees is still refused. */
|
|
55
|
+
static readonly ASSIGN = "assign";
|
|
56
|
+
static readonly SCHEME_SET: Set<string>;
|
|
57
|
+
static isValid(guard: string): boolean;
|
|
58
|
+
}
|
|
59
|
+
/** Valid scope write-guard values. */
|
|
60
|
+
export type TScopeWriteGuard = TConstValue<typeof ScopeWriteGuards>;
|
|
46
61
|
/**
|
|
47
62
|
* The third `resolve()` state, beside a `where` and `deny`-by-default null/undefined: unrestricted
|
|
48
63
|
* for THIS call. `onMissing: 'allow'` cannot express it - `onMissing` lives on the model's static
|
|
@@ -62,6 +77,8 @@ export declare class ScopeFilters {
|
|
|
62
77
|
export declare class RepositoryErrorCodes {
|
|
63
78
|
/** A verb the repository's `operationScope` does not permit (e.g. `create()` on a READ_ONLY one). */
|
|
64
79
|
static readonly OPERATION_NOT_ALLOWED: string;
|
|
80
|
+
/** A write whose scope column disagrees with the resolved scope, or whose scope cannot be verified (`access` write guard). */
|
|
81
|
+
static readonly SCOPE_WRITE_DENIED: string;
|
|
65
82
|
}
|
|
66
83
|
/** Valid repository error code values. */
|
|
67
84
|
export type TRepositoryErrorCode = TConstValue<typeof RepositoryErrorCodes>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../../src/base/repositories/common/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAGjE,uDAAuD;AACvD,eAAO,MAAM,aAAa,KAAK,CAAC;AAEhC;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,OAAO,CAAC;AAEtC,gGAAgG;AAChG,qBAAa,yBAAyB;IACpC,MAAM,CAAC,QAAQ,CAAC,SAAS,eAAe;IACxC,MAAM,CAAC,QAAQ,CAAC,UAAU,gBAAgB;IAC1C,MAAM,CAAC,QAAQ,CAAC,UAAU,gBAAgB;IAC1C,MAAM,CAAC,QAAQ,CAAC,UAAU,cAA+D;IAEzF,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;CAGzC;AAED,+CAA+C;AAC/C,MAAM,MAAM,yBAAyB,GAAG,WAAW,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAEtF,kJAAkJ;AAClJ,qBAAa,eAAe;IAC1B,MAAM,CAAC,QAAQ,CAAC,KAAK,WAAW;IAChC,MAAM,CAAC,QAAQ,CAAC,MAAM,YAAY;IAClC,MAAM,CAAC,QAAQ,CAAC,UAAU,cAAsC;IAEhE,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;CAGvC;AAED,oCAAoC;AACpC,MAAM,MAAM,eAAe,GAAG,WAAW,CAAC,OAAO,eAAe,CAAC,CAAC;AAElE,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../../src/base/repositories/common/constants.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;IACxC,MAAM,CAAC,QAAQ,CAAC,UAAU,cAKvB;IAEH,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;CAG1C;AAED,kCAAkC;AAClC,MAAM,MAAM,aAAa,GAAG,WAAW,CAAC,OAAO,aAAa,CAAC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LockStrengths = exports.RelationTypes = exports.RepositoryErrorCodes = exports.ScopeFilters = exports.ScopeFilterMissingBehaviors = exports.RepositoryTypes = exports.RepositoryOperationScopes = exports.DEFAULT_MAX_LIMIT = exports.DEFAULT_LIMIT = void 0;
|
|
3
|
+
exports.LockStrengths = exports.RelationTypes = exports.RepositoryErrorCodes = exports.ScopeFilters = exports.ScopeWriteGuards = exports.ScopeFilterMissingBehaviors = exports.RepositoryTypes = exports.RepositoryOperationScopes = exports.DEFAULT_MAX_LIMIT = exports.DEFAULT_LIMIT = void 0;
|
|
4
4
|
const core_1 = require("@venizia/ignis-helpers/core");
|
|
5
5
|
/** Default pagination limit for repository queries. */
|
|
6
6
|
exports.DEFAULT_LIMIT = 10;
|
|
@@ -37,7 +37,7 @@ class RepositoryTypes {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
exports.RepositoryTypes = RepositoryTypes;
|
|
40
|
-
/** What a row-scope filter (`@model` settings.
|
|
40
|
+
/** What a row-scope filter (`@model` settings.access) does when `resolve()` returns null/undefined. */
|
|
41
41
|
class ScopeFilterMissingBehaviors {
|
|
42
42
|
/** An unresolved scope matches ZERO rows - the safe reading of "caller's scope is unknown". */
|
|
43
43
|
static { this.DENY = 'deny'; }
|
|
@@ -49,6 +49,22 @@ class ScopeFilterMissingBehaviors {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
exports.ScopeFilterMissingBehaviors = ScopeFilterMissingBehaviors;
|
|
52
|
+
/**
|
|
53
|
+
* What a scoped write does with a row whose scope column disagrees with the resolved scope
|
|
54
|
+
* (`@model` settings.access.write.mode). A scope that returns `ScopeFilters.UNRESTRICTED`
|
|
55
|
+
* passes either way.
|
|
56
|
+
*/
|
|
57
|
+
class ScopeWriteGuards {
|
|
58
|
+
/** Default. A row whose scope column disagrees, or is absent on create, is refused and nothing is written. */
|
|
59
|
+
static { this.REJECT = 'reject'; }
|
|
60
|
+
/** An ABSENT scope column is filled from an equality scope; a value that disagrees is still refused. */
|
|
61
|
+
static { this.ASSIGN = 'assign'; }
|
|
62
|
+
static { this.SCHEME_SET = new Set([this.REJECT, this.ASSIGN]); }
|
|
63
|
+
static isValid(guard) {
|
|
64
|
+
return this.SCHEME_SET.has(guard);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.ScopeWriteGuards = ScopeWriteGuards;
|
|
52
68
|
/**
|
|
53
69
|
* The third `resolve()` state, beside a `where` and `deny`-by-default null/undefined: unrestricted
|
|
54
70
|
* for THIS call. `onMissing: 'allow'` cannot express it - `onMissing` lives on the model's static
|
|
@@ -71,6 +87,10 @@ class RepositoryErrorCodes {
|
|
|
71
87
|
static { this.OPERATION_NOT_ALLOWED = core_1.MessageCode.build({
|
|
72
88
|
parts: ['core', 'repository', 'operation_not_allowed'],
|
|
73
89
|
}); }
|
|
90
|
+
/** A write whose scope column disagrees with the resolved scope, or whose scope cannot be verified (`access` write guard). */
|
|
91
|
+
static { this.SCOPE_WRITE_DENIED = core_1.MessageCode.build({
|
|
92
|
+
parts: ['core', 'repository', 'scope_write_denied'],
|
|
93
|
+
}); }
|
|
74
94
|
}
|
|
75
95
|
exports.RepositoryErrorCodes = RepositoryErrorCodes;
|
|
76
96
|
/** Entity relation types (one-to-one/many-to-one, one-to-many). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/base/repositories/common/constants.ts"],"names":[],"mappings":";;;AACA,sDAA0D;AAE1D,uDAAuD;AA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ConstValue } from '@venizia/ignis-helpers/common';\nimport { MessageCode } from '@venizia/ignis-helpers/core';\n\n/** Default pagination limit for repository queries. */\nexport const DEFAULT_LIMIT = 10;\n\n/**\n * Largest `limit` a caller may ask for when a model declares no `maxLimit`.\n *\n * POLICY, not capacity - it sits far below what an engine can physically serve. It exists because\n * removing an accidental guardrail without replacing it would leave the framework less safe than\n * before: a search engine refused a page over 250 hits, so `limit: 5000` failed fast and cheap.\n * Once that page is served, something has to decide when a page is unreasonable.\n *\n * 1000 sits above any list screen and well below the physical ceiling, so reaching it means the\n * caller is doing something unusual - and a model raises it by saying so explicitly.\n */\nexport const DEFAULT_MAX_LIMIT = 1000;\n\n/** Defines the operation scope for repository instances (READ_ONLY, WRITE_ONLY, READ_WRITE). */\nexport class RepositoryOperationScopes {\n static readonly READ_ONLY = 'READ_ONLY';\n static readonly WRITE_ONLY = 'WRITE_ONLY';\n static readonly READ_WRITE = 'READ_WRITE';\n static readonly SCHEME_SET = new Set([this.READ_ONLY, this.WRITE_ONLY, this.READ_WRITE]);\n\n static isValid(orgType: string): boolean {\n return this.SCHEME_SET.has(orgType);\n }\n}\n\n/** Valid repository operation scope values. */\nexport type TRepositoryOperationScope = TConstValue<typeof RepositoryOperationScopes>;\n\n/** What `@repository` binds: MODEL, a model this application declares (the default); REMOTE, data behind another service's API, with no model. */\nexport class RepositoryTypes {\n static readonly MODEL = 'model';\n static readonly REMOTE = 'remote';\n static readonly SCHEME_SET = new Set([this.MODEL, this.REMOTE]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** Valid repository type values. */\nexport type TRepositoryType = TConstValue<typeof RepositoryTypes>;\n\n/** What a row-scope filter (`@model` settings.access) does when `resolve()` returns null/undefined. */\nexport class ScopeFilterMissingBehaviors {\n /** An unresolved scope matches ZERO rows - the safe reading of \"caller's scope is unknown\". */\n static readonly DENY = 'deny';\n /** Explicit opt-out: no scope is applied. For migrations and background jobs, never inferred from a request. */\n static readonly ALLOW = 'allow';\n static readonly SCHEME_SET = new Set([this.DENY, this.ALLOW]);\n\n static isValid(behavior: string): boolean {\n return this.SCHEME_SET.has(behavior);\n }\n}\n\n/** Valid scope-filter missing-behavior values. */\nexport type TScopeFilterMissingBehavior = TConstValue<typeof ScopeFilterMissingBehaviors>;\n\n/**\n * What a scoped write does with a row whose scope column disagrees with the resolved scope\n * (`@model` settings.access.write.mode). A scope that returns `ScopeFilters.UNRESTRICTED`\n * passes either way.\n */\nexport class ScopeWriteGuards {\n /** Default. A row whose scope column disagrees, or is absent on create, is refused and nothing is written. */\n static readonly REJECT = 'reject';\n /** An ABSENT scope column is filled from an equality scope; a value that disagrees is still refused. */\n static readonly ASSIGN = 'assign';\n static readonly SCHEME_SET = new Set([this.REJECT, this.ASSIGN]);\n\n static isValid(guard: string): boolean {\n return this.SCHEME_SET.has(guard);\n }\n}\n\n/** Valid scope write-guard values. */\nexport type TScopeWriteGuard = TConstValue<typeof ScopeWriteGuards>;\n\n/**\n * The third `resolve()` state, beside a `where` and `deny`-by-default null/undefined: unrestricted\n * for THIS call. `onMissing: 'allow'` cannot express it - `onMissing` lives on the model's static\n * settings, so using it for a per-user bypass (an internal operator) would also unscope every\n * ordinary user whose `resolve()` happens to return nothing.\n */\nexport class ScopeFilters {\n /**\n * Return from `resolve()` to apply NO scope for this request - a caller the application has\n * decided sees everything. Deliberately a symbol: forgetting to return must land in deny, and no\n * JSON body, query string, or header can ever produce this value. `Symbol.for` so two installed\n * copies of this package agree on identity, same as `DATA_SOURCE_BRAND`.\n */\n static readonly UNRESTRICTED = Symbol.for('@venizia/ignis-kernel:scope-filter-unrestricted');\n}\n\n/** Machine-readable codes for repository-level failures, in the dotted namespace core already uses (`core.not_supported`, `core.search_engine.*`) - a client maps the code, never the message. */\nexport class RepositoryErrorCodes {\n /** A verb the repository's `operationScope` does not permit (e.g. `create()` on a READ_ONLY one). */\n static readonly OPERATION_NOT_ALLOWED = MessageCode.build({\n parts: ['core', 'repository', 'operation_not_allowed'],\n });\n\n /** A write whose scope column disagrees with the resolved scope, or whose scope cannot be verified (`access` write guard). */\n static readonly SCOPE_WRITE_DENIED = MessageCode.build({\n parts: ['core', 'repository', 'scope_write_denied'],\n });\n}\n\n/** Valid repository error code values. */\nexport type TRepositoryErrorCode = TConstValue<typeof RepositoryErrorCodes>;\n\n/** Entity relation types (one-to-one/many-to-one, one-to-many). */\nexport class RelationTypes {\n static readonly ONE = 'one';\n static readonly MANY = 'many';\n static readonly SCHEME_SET = new Set([this.ONE, this.MANY]);\n\n static isValid(orgType: string): boolean {\n return this.SCHEME_SET.has(orgType);\n }\n}\n\n/** Valid relation type values. */\nexport type TRelationType = TConstValue<typeof RelationTypes>;\n\n/** PostgreSQL row-level lock strengths for SELECT ... FOR <strength>. */\nexport class LockStrengths {\n static readonly UPDATE = 'update';\n static readonly NO_KEY_UPDATE = 'no key update';\n static readonly SHARE = 'share';\n static readonly KEY_SHARE = 'key share';\n static readonly SCHEME_SET = new Set([\n this.UPDATE,\n this.NO_KEY_UPDATE,\n this.SHARE,\n this.KEY_SHARE,\n ]);\n\n static isValid(strength: string): boolean {\n return this.SCHEME_SET.has(strength);\n }\n}\n\n/** Valid lock strength values. */\nexport type TLockStrength = TConstValue<typeof LockStrengths>;\n"]}
|