@venizia/ignis-kernel 0.4.8-0 → 0.4.8-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/README.md +5 -4
- package/dist/esm/base/applications/abstract.d.ts +1 -0
- package/dist/esm/base/applications/abstract.js +1 -0
- package/dist/esm/base/applications/abstract.js.map +1 -1
- package/dist/esm/base/applications/boot-sequence.d.ts +2 -0
- package/dist/esm/base/applications/boot-sequence.js.map +1 -1
- package/dist/esm/base/applications/common/constants.d.ts +2 -0
- package/dist/esm/base/applications/common/constants.js +1 -0
- package/dist/esm/base/applications/common/constants.js.map +1 -1
- package/dist/esm/base/applications/common/types/application.d.ts +30 -8
- package/dist/esm/base/applications/common/types/application.js.map +1 -1
- package/dist/esm/base/applications/common/types/middlewares.d.ts +16 -1
- package/dist/esm/base/applications/common/types/middlewares.js.map +1 -1
- package/dist/esm/base/auth/authenticate/common/codecs.d.ts +1 -0
- package/dist/esm/base/auth/authenticate/common/codecs.js +1 -0
- package/dist/esm/base/auth/authenticate/common/codecs.js.map +1 -1
- package/dist/esm/base/auth/authenticate/common/constants/authentication.d.ts +6 -0
- package/dist/esm/base/auth/authenticate/common/constants/authentication.js +4 -0
- package/dist/esm/base/auth/authenticate/common/constants/authentication.js.map +1 -1
- package/dist/esm/base/auth/authenticate/common/constants/jose.d.ts +8 -0
- package/dist/esm/base/auth/authenticate/common/constants/jose.js +4 -0
- package/dist/esm/base/auth/authenticate/common/constants/jose.js.map +1 -1
- package/dist/esm/base/auth/authenticate/common/keys.d.ts +1 -0
- package/dist/esm/base/auth/authenticate/common/keys.js +1 -0
- package/dist/esm/base/auth/authenticate/common/keys.js.map +1 -1
- package/dist/esm/base/auth/authenticate/common/types/basic.d.ts +1 -0
- package/dist/esm/base/auth/authenticate/common/types/basic.js.map +1 -1
- package/dist/esm/base/auth/authenticate/common/types/jwt.d.ts +42 -0
- package/dist/esm/base/auth/authenticate/common/types/jwt.js.map +1 -1
- package/dist/esm/base/auth/authenticate/common/types/rest.d.ts +2 -0
- package/dist/esm/base/auth/authenticate/common/types/rest.js.map +1 -1
- package/dist/esm/base/auth/authenticate/common/types/service.d.ts +10 -1
- package/dist/esm/base/auth/authenticate/common/types/service.js.map +1 -1
- package/dist/esm/base/auth/authenticate/common/types/strategy.d.ts +5 -0
- package/dist/esm/base/auth/authenticate/common/types/strategy.js.map +1 -1
- package/dist/esm/base/auth/authenticate/middlewares/authenticate.middleware.d.ts +1 -0
- package/dist/esm/base/auth/authenticate/middlewares/authenticate.middleware.js +1 -0
- package/dist/esm/base/auth/authenticate/middlewares/authenticate.middleware.js.map +1 -1
- package/dist/esm/base/auth/authenticate/providers/authentication.provider.d.ts +5 -0
- package/dist/esm/base/auth/authenticate/providers/authentication.provider.js +5 -0
- package/dist/esm/base/auth/authenticate/providers/authentication.provider.js.map +1 -1
- package/dist/esm/base/auth/authenticate/strategies/strategy-registry.d.ts +1 -0
- package/dist/esm/base/auth/authenticate/strategies/strategy-registry.js +1 -0
- package/dist/esm/base/auth/authenticate/strategies/strategy-registry.js.map +1 -1
- package/dist/esm/base/auth/authorize/builders/grant.builder.d.ts +1 -0
- package/dist/esm/base/auth/authorize/builders/grant.builder.js +1 -0
- package/dist/esm/base/auth/authorize/builders/grant.builder.js.map +1 -1
- package/dist/esm/base/auth/authorize/builders/policy.builder.d.ts +1 -0
- package/dist/esm/base/auth/authorize/builders/policy.builder.js +1 -0
- package/dist/esm/base/auth/authorize/builders/policy.builder.js.map +1 -1
- package/dist/esm/base/auth/authorize/common/constants/authorization.d.ts +8 -0
- package/dist/esm/base/auth/authorize/common/constants/authorization.js +5 -0
- package/dist/esm/base/auth/authorize/common/constants/authorization.js.map +1 -1
- package/dist/esm/base/auth/authorize/common/constants/binding-keys.d.ts +1 -0
- package/dist/esm/base/auth/authorize/common/constants/binding-keys.js +1 -0
- package/dist/esm/base/auth/authorize/common/constants/binding-keys.js.map +1 -1
- package/dist/esm/base/auth/authorize/common/constants/enforcer.d.ts +9 -0
- package/dist/esm/base/auth/authorize/common/constants/enforcer.js +4 -0
- package/dist/esm/base/auth/authorize/common/constants/enforcer.js.map +1 -1
- package/dist/esm/base/auth/authorize/common/types/enforcer.d.ts +21 -3
- package/dist/esm/base/auth/authorize/common/types/enforcer.js.map +1 -1
- package/dist/esm/base/auth/authorize/common/types/grant.d.ts +1 -0
- package/dist/esm/base/auth/authorize/common/types/grant.js.map +1 -1
- package/dist/esm/base/auth/authorize/common/types/request.d.ts +3 -0
- package/dist/esm/base/auth/authorize/common/types/request.js.map +1 -1
- package/dist/esm/base/auth/authorize/enforcers/enforcer-registry.d.ts +1 -0
- package/dist/esm/base/auth/authorize/enforcers/enforcer-registry.js +1 -0
- package/dist/esm/base/auth/authorize/enforcers/enforcer-registry.js.map +1 -1
- package/dist/esm/base/auth/authorize/middlewares/authorize.middleware.d.ts +1 -0
- package/dist/esm/base/auth/authorize/middlewares/authorize.middleware.js +1 -0
- package/dist/esm/base/auth/authorize/middlewares/authorize.middleware.js.map +1 -1
- package/dist/esm/base/auth/authorize/models/authorization-role.model.d.ts +6 -0
- package/dist/esm/base/auth/authorize/models/authorization-role.model.js +1 -0
- package/dist/esm/base/auth/authorize/models/authorization-role.model.js.map +1 -1
- package/dist/esm/base/auth/authorize/providers/authorization.provider.d.ts +1 -0
- package/dist/esm/base/auth/authorize/providers/authorization.provider.js +1 -0
- package/dist/esm/base/auth/authorize/providers/authorization.provider.js.map +1 -1
- package/dist/esm/base/auth/base/abstract-auth-registry.d.ts +2 -0
- package/dist/esm/base/auth/base/abstract-auth-registry.js +1 -0
- package/dist/esm/base/auth/base/abstract-auth-registry.js.map +1 -1
- package/dist/esm/base/auth/models/requests/change-password.schema.d.ts +2 -0
- package/dist/esm/base/auth/models/requests/change-password.schema.js +1 -0
- package/dist/esm/base/auth/models/requests/change-password.schema.js.map +1 -1
- package/dist/esm/base/auth/models/requests/sign-in.schema.d.ts +2 -0
- package/dist/esm/base/auth/models/requests/sign-in.schema.js +1 -0
- package/dist/esm/base/auth/models/requests/sign-in.schema.js.map +1 -1
- package/dist/esm/base/auth/models/requests/sign-up.schema.d.ts +2 -0
- package/dist/esm/base/auth/models/requests/sign-up.schema.js +1 -0
- package/dist/esm/base/auth/models/requests/sign-up.schema.js.map +1 -1
- package/dist/esm/base/components/base.d.ts +1 -0
- package/dist/esm/base/components/base.js +1 -0
- package/dist/esm/base/components/base.js.map +1 -1
- package/dist/esm/base/components/controller/rest/common/types.d.ts +2 -0
- package/dist/esm/base/components/controller/rest/common/types.js +1 -0
- package/dist/esm/base/components/controller/rest/common/types.js.map +1 -1
- package/dist/esm/base/configurations/base.d.ts +1 -0
- package/dist/esm/base/configurations/base.js +1 -0
- package/dist/esm/base/configurations/base.js.map +1 -1
- package/dist/esm/base/configurations/common/types.d.ts +1 -0
- package/dist/esm/base/configurations/common/types.js.map +1 -1
- package/dist/esm/base/controllers/common/constants.d.ts +4 -0
- package/dist/esm/base/controllers/common/constants.js +2 -0
- package/dist/esm/base/controllers/common/constants.js.map +1 -1
- package/dist/esm/base/controllers/common/schema-builders.d.ts +3 -0
- package/dist/esm/base/controllers/common/schema-builders.js +1 -0
- package/dist/esm/base/controllers/common/schema-builders.js.map +1 -1
- package/dist/esm/base/controllers/common/schemas.d.ts +2 -0
- package/dist/esm/base/controllers/common/schemas.js +2 -0
- package/dist/esm/base/controllers/common/schemas.js.map +1 -1
- package/dist/esm/base/controllers/common/types/context.d.ts +2 -0
- package/dist/esm/base/controllers/common/types/context.js.map +1 -1
- package/dist/esm/base/controllers/common/types/controller.d.ts +5 -1
- package/dist/esm/base/controllers/common/types/controller.js.map +1 -1
- package/dist/esm/base/controllers/common/types/route.d.ts +7 -1
- package/dist/esm/base/controllers/common/types/route.js.map +1 -1
- package/dist/esm/base/datasources/common/types.d.ts +5 -0
- package/dist/esm/base/datasources/common/types.js +1 -0
- package/dist/esm/base/datasources/common/types.js.map +1 -1
- package/dist/esm/base/events/common/constants.d.ts +4 -0
- package/dist/esm/base/events/common/constants.js +3 -0
- package/dist/esm/base/events/common/constants.js.map +1 -1
- package/dist/esm/base/events/common/types.d.ts +10 -2
- package/dist/esm/base/events/common/types.js.map +1 -1
- package/dist/esm/base/metadata/injectable.d.ts +46 -0
- package/dist/esm/base/metadata/injectable.js +46 -0
- package/dist/esm/base/metadata/injectable.js.map +1 -1
- package/dist/esm/base/metadata/persistents.d.ts +47 -2
- package/dist/esm/base/metadata/persistents.js +47 -2
- package/dist/esm/base/metadata/persistents.js.map +1 -1
- package/dist/esm/base/metadata/routes/controller.d.ts +17 -0
- package/dist/esm/base/metadata/routes/controller.js +17 -0
- package/dist/esm/base/metadata/routes/controller.js.map +1 -1
- package/dist/esm/base/middlewares/emoji-favicon/emoji-favicon.middleware.d.ts +1 -0
- package/dist/esm/base/middlewares/emoji-favicon/emoji-favicon.middleware.js +1 -0
- package/dist/esm/base/middlewares/emoji-favicon/emoji-favicon.middleware.js.map +1 -1
- package/dist/esm/base/middlewares/not-found/not-found.middleware.d.ts +1 -0
- package/dist/esm/base/middlewares/not-found/not-found.middleware.js +1 -0
- package/dist/esm/base/middlewares/not-found/not-found.middleware.js.map +1 -1
- package/dist/esm/base/mixins/common/types.d.ts +14 -1
- package/dist/esm/base/mixins/common/types.js.map +1 -1
- package/dist/esm/base/models/common/constants.d.ts +2 -0
- package/dist/esm/base/models/common/constants.js +1 -0
- package/dist/esm/base/models/common/constants.js.map +1 -1
- package/dist/esm/base/models/common/schemas.d.ts +1 -0
- package/dist/esm/base/models/common/schemas.js.map +1 -1
- package/dist/esm/base/models/common/types/id.d.ts +4 -0
- package/dist/esm/base/models/common/types/id.js.map +1 -1
- package/dist/esm/base/providers/base.d.ts +1 -0
- package/dist/esm/base/providers/base.js +1 -0
- package/dist/esm/base/providers/base.js.map +1 -1
- package/dist/esm/base/repositories/common/constants.d.ts +2 -2
- package/dist/esm/base/repositories/common/constants.js +2 -2
- package/dist/esm/base/repositories/common/constants.js.map +1 -1
- package/dist/esm/base/repositories/common/scope-through.d.ts +18 -1
- package/dist/esm/base/repositories/common/scope-through.js +18 -1
- package/dist/esm/base/repositories/common/scope-through.js.map +1 -1
- package/dist/esm/base/repositories/common/types/options.d.ts +10 -4
- package/dist/esm/base/repositories/common/types/options.js.map +1 -1
- package/dist/esm/base/repositories/query-schemas/index.d.ts +18 -3
- package/dist/esm/base/repositories/query-schemas/index.js +17 -1
- package/dist/esm/base/repositories/query-schemas/index.js.map +1 -1
- package/dist/esm/base/request-context/registry.d.ts +1 -0
- package/dist/esm/base/request-context/registry.js +1 -0
- package/dist/esm/base/request-context/registry.js.map +1 -1
- package/dist/esm/base/services/base.d.ts +1 -0
- package/dist/esm/base/services/base.js +1 -0
- package/dist/esm/base/services/base.js.map +1 -1
- package/dist/esm/base/services/common/types.d.ts +1 -0
- package/dist/esm/base/services/common/types.js.map +1 -1
- package/dist/esm/common/bindings.d.ts +1 -0
- package/dist/esm/common/bindings.js.map +1 -1
- package/dist/esm/common/error-codes.d.ts +2 -0
- package/dist/esm/common/error-codes.js.map +1 -1
- package/dist/esm/helpers/inversion/common/keys.d.ts +1 -0
- package/dist/esm/helpers/inversion/common/keys.js +1 -0
- package/dist/esm/helpers/inversion/common/keys.js.map +1 -1
- package/dist/esm/helpers/inversion/common/relation-builder.d.ts +1 -0
- package/dist/esm/helpers/inversion/common/relation-builder.js +1 -0
- package/dist/esm/helpers/inversion/common/relation-builder.js.map +1 -1
- package/dist/esm/helpers/inversion/common/types/artifact.d.ts +9 -2
- package/dist/esm/helpers/inversion/common/types/artifact.js.map +1 -1
- package/dist/esm/helpers/inversion/common/types/controller.d.ts +4 -0
- package/dist/esm/helpers/inversion/common/types/controller.js.map +1 -1
- package/dist/esm/helpers/inversion/common/types/model.d.ts +80 -8
- package/dist/esm/helpers/inversion/common/types/model.js.map +1 -1
- package/dist/esm/helpers/inversion/common/types/persistence.d.ts +9 -1
- package/dist/esm/helpers/inversion/common/types/persistence.js.map +1 -1
- package/dist/esm/helpers/inversion/container.d.ts +1 -0
- package/dist/esm/helpers/inversion/container.js +1 -0
- package/dist/esm/helpers/inversion/container.js.map +1 -1
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../../../../src/base/controllers/common/types/controller.ts"],"names":[],"mappings":"","sourcesContent":["import type { AbstractEntity } from '@/base/models';\nimport type { TAuthMode, TAuthStrategy } from '@/base/auth/authenticate/common/constants';\nimport type { IAuthorizationSpec } from '@/base/auth/authorize/common/types';\nimport type {\n IConfigurable,\n TClass,\n TResolver,\n ValueOrPromise,\n} from '@venizia/ignis-helpers/common';\nimport type { Hook, OpenAPIHono } from '@hono/zod-openapi';\nimport type { Env, Schema } from 'hono';\nimport type { TRouteHandler } from './context';\nimport type {\n IAuthRouteConfig,\n IBindRouteOptions,\n ICustomizableRoutes,\n IDefineRouteOptions,\n} from './route';\n\n/** Base controller interface defining route registration and configuration contract. */\nexport interface IController<\n RouteEnv extends Env = Env,\n RouteSchema extends Schema = {},\n BasePath extends string = '/',\n ConfigurableOptions extends object = {},\n> extends IConfigurable<ConfigurableOptions, OpenAPIHono<RouteEnv, RouteSchema, BasePath>> {\n router: OpenAPIHono<RouteEnv, RouteSchema, BasePath>;\n\n bindRoute<RouteConfig extends IAuthRouteConfig>(opts: {\n configs: RouteConfig;\n }): IBindRouteOptions<RouteConfig, RouteEnv, RouteSchema, BasePath>;\n\n /** Defines and registers a route with its handler in a single call. */\n defineRoute<RouteConfig extends IAuthRouteConfig, ResponseType = unknown>(opts: {\n configs: RouteConfig;\n handler: TRouteHandler<ResponseType, RouteEnv>;\n hook?: Hook<any, RouteEnv, string, ValueOrPromise<any>>;\n }): IDefineRouteOptions<RouteConfig, RouteEnv, RouteSchema, BasePath>;\n}\n\n/** Configuration options for controller instantiation. */\nexport interface IControllerOptions {\n scope: string;\n /** Falls back to @controller decorator path if not provided. */\n path?: string;\n
|
|
1
|
+
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../../../../src/base/controllers/common/types/controller.ts"],"names":[],"mappings":"","sourcesContent":["import type { AbstractEntity } from '@/base/models';\nimport type { TAuthMode, TAuthStrategy } from '@/base/auth/authenticate/common/constants';\nimport type { IAuthorizationSpec } from '@/base/auth/authorize/common/types';\nimport type {\n IConfigurable,\n TClass,\n TResolver,\n ValueOrPromise,\n} from '@venizia/ignis-helpers/common';\nimport type { Hook, OpenAPIHono } from '@hono/zod-openapi';\nimport type { Env, Schema } from 'hono';\nimport type { TRouteHandler } from './context';\nimport type {\n IAuthRouteConfig,\n IBindRouteOptions,\n ICustomizableRoutes,\n IDefineRouteOptions,\n} from './route';\n\n/** Base controller interface defining route registration and configuration contract. */\nexport interface IController<\n RouteEnv extends Env = Env,\n RouteSchema extends Schema = {},\n BasePath extends string = '/',\n ConfigurableOptions extends object = {},\n> extends IConfigurable<ConfigurableOptions, OpenAPIHono<RouteEnv, RouteSchema, BasePath>> {\n router: OpenAPIHono<RouteEnv, RouteSchema, BasePath>;\n\n bindRoute<RouteConfig extends IAuthRouteConfig>(opts: {\n configs: RouteConfig;\n }): IBindRouteOptions<RouteConfig, RouteEnv, RouteSchema, BasePath>;\n\n /** Defines and registers a route with its handler in a single call. */\n defineRoute<RouteConfig extends IAuthRouteConfig, ResponseType = unknown>(opts: {\n configs: RouteConfig;\n handler: TRouteHandler<ResponseType, RouteEnv>;\n hook?: Hook<any, RouteEnv, string, ValueOrPromise<any>>;\n }): IDefineRouteOptions<RouteConfig, RouteEnv, RouteSchema, BasePath>;\n}\n\n/** Configuration options for controller instantiation. */\nexport interface IControllerOptions {\n scope: string;\n /** Falls back to @controller decorator path if not provided. */\n path?: string;\n /**\n * When true, /users and /users/ are different routes.\n *\n * @default true\n */\n isStrict?: boolean;\n}\n\n/** Read object inferred from an entity's engine-neutral `$inferData` phantom marker - each family fills it with its own type, so the base layer needs no connector import; falls back to `object`. */\nexport type TEntityDataObject<TEntity> = TEntity extends { $inferData?: infer TData }\n ? TData extends object\n ? TData\n : object\n : object;\n\n/** Persist object inferred from an entity's engine-neutral `$inferPersist` phantom marker - same contract and `object` fallback as {@link TEntityDataObject}. */\nexport type TEntityPersistObject<TEntity> = TEntity extends { $inferPersist?: infer TPersist }\n ? TPersist extends object\n ? TPersist\n : object\n : object;\n\n/** Configuration options for creating a CRUD controller via ControllerFactory.defineCrudController. */\nexport interface ICrudControllerOptions<\n TEntity extends AbstractEntity = AbstractEntity,\n Routes extends ICustomizableRoutes = ICustomizableRoutes,\n> {\n /** Entity class or resolver returning it - its schema drives the inferred DataObject/PersistObject types of the generated controller's `repository`. */\n entity: TClass<TEntity> | TResolver<TClass<TEntity>>;\n\n /** Repository binding configuration */\n repository: {\n name: string; // Repository binding name in the IoC container\n };\n\n controller: {\n name: string;\n basePath: string;\n readonly?: boolean;\n\n /** Whitelist of routes to register; overrides per-route `enabled` flags in `routes` when set. */\n enabledRoutes?: Array<keyof ICustomizableRoutes>;\n\n isStrict?: {\n path?: boolean;\n requestSchema?: boolean;\n };\n };\n\n /** Authentication config applied to all routes (unless overridden per-route). */\n authenticate?: { strategies?: TAuthStrategy[]; mode?: TAuthMode };\n\n /** Authorization config applied to all routes (unless overridden per-route). */\n authorize?: IAuthorizationSpec | IAuthorizationSpec[];\n\n /** Per-route configuration combining schema and auth overrides. */\n routes?: Routes;\n}\n"]}
|
|
@@ -53,11 +53,17 @@ export type TResponseHeaderObject = {
|
|
|
53
53
|
/** OpenAPI response headers format */
|
|
54
54
|
export type TResponseHeaders = Record<string, TResponseHeaderObject>;
|
|
55
55
|
type TInferDistributive<S> = S extends z.ZodType ? z.infer<S> : never;
|
|
56
|
+
/** The JSON response body type of a route config `R`: the union of the schemas under `application/json` across all its response codes. */
|
|
56
57
|
export type TResponseBodyOf<R extends {
|
|
57
58
|
responses: AnyType;
|
|
58
59
|
}> = TInferDistributive<R['responses'][keyof R['responses']]['content']['application/json']['schema']>;
|
|
60
|
+
/** What a CRUD route lets a caller override: auth, `enabled`, the request schemas (params, query, body, headers) and the response schema and headers. */
|
|
59
61
|
export type TCustomizableRouteConfig = TRouteAuthConfig & {
|
|
60
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* Whether this route is registered.
|
|
64
|
+
*
|
|
65
|
+
* @default true
|
|
66
|
+
*/
|
|
61
67
|
enabled?: boolean;
|
|
62
68
|
request?: {
|
|
63
69
|
params?: TAnyObjectSchema;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.js","sourceRoot":"","sources":["../../../../../../src/base/controllers/common/types/route.ts"],"names":[],"mappings":"","sourcesContent":["import type { TAuthMode, TAuthStrategy } from '@/base/auth/authenticate/common/constants';\nimport type { IAuthorizationSpec } from '@/base/auth/authorize/common/types';\nimport type { TAnyObjectSchema } from '@/base/controllers/common/schema-builders';\nimport type {\n createRoute,\n RouteConfig as HonoRouteConfig,\n OpenAPIHono,\n z,\n} from '@hono/zod-openapi';\nimport type { AnyType } from '@venizia/ignis-helpers/common';\nimport type { Env, Schema } from 'hono';\nimport type { TRouteHandler } from './context';\n\n/** Registered route with its configuration and router instance. */\nexport interface IDefineRouteOptions<\n RouteConfig extends HonoRouteConfig,\n RouteEnv extends Env = Env,\n RouteSchema extends Schema = {},\n BasePath extends string = '/',\n> {\n configs: ReturnType<typeof createRoute<string, RouteConfig>>;\n route: OpenAPIHono<RouteEnv, RouteSchema, BasePath>;\n}\n\n/** Fluent binding for two-step route registration: bindRoute({ configs }).to({ handler }). */\nexport interface IBindRouteOptions<\n RouteConfig extends HonoRouteConfig,\n RouteEnv extends Env = Env,\n RouteSchema extends Schema = {},\n BasePath extends string = '/',\n> {\n configs: RouteConfig;\n to: <ResponseType = unknown>(opts: {\n handler: TRouteHandler<ResponseType, RouteEnv>;\n }) => IDefineRouteOptions<RouteConfig, RouteEnv, RouteSchema, BasePath>;\n}\n\n/** Route configuration extended with optional authenticate and authorize fields. */\nexport interface IAuthRouteConfig extends HonoRouteConfig {\n authenticate?: { strategies?: TAuthStrategy[]; mode?: TAuthMode };\n authorize?: IAuthorizationSpec | IAuthorizationSpec[];\n}\n\n/** Per-route authentication config: { skip: true } or { strategies, mode }. */\nexport type TRouteAuthenticateConfig =\n | { skip: true }\n | { skip?: false; strategies?: TAuthStrategy[]; mode?: TAuthMode };\n\n/** Per-route authorization config: { skip: true }, single spec, or array of specs. */\nexport type TRouteAuthorizeConfig = { skip: true } | IAuthorizationSpec | IAuthorizationSpec[];\n\n/** Per-route auth config. Endpoint config takes precedence over controller-level config. */\nexport type TRouteAuthConfig = {\n authenticate?: TRouteAuthenticateConfig;\n authorize?: TRouteAuthorizeConfig;\n};\n\n/** OpenAPI response header object */\nexport type TResponseHeaderObject = {\n description?: string;\n schema: { type: 'string'; examples?: string[] };\n};\n\n/** OpenAPI response headers format */\nexport type TResponseHeaders = Record<string, TResponseHeaderObject>;\n\n// Response body types derived from route definitions; a distributive conditional applies z.infer to each schema of the union separately.\ntype TInferDistributive<S> = S extends z.ZodType ? z.infer<S> : never;\nexport type TResponseBodyOf<R extends { responses: AnyType }> = TInferDistributive<\n R['responses'][keyof R['responses']]['content']['application/json']['schema']\n>;\n\nexport type TCustomizableRouteConfig = TRouteAuthConfig & {\n
|
|
1
|
+
{"version":3,"file":"route.js","sourceRoot":"","sources":["../../../../../../src/base/controllers/common/types/route.ts"],"names":[],"mappings":"","sourcesContent":["import type { TAuthMode, TAuthStrategy } from '@/base/auth/authenticate/common/constants';\nimport type { IAuthorizationSpec } from '@/base/auth/authorize/common/types';\nimport type { TAnyObjectSchema } from '@/base/controllers/common/schema-builders';\nimport type {\n createRoute,\n RouteConfig as HonoRouteConfig,\n OpenAPIHono,\n z,\n} from '@hono/zod-openapi';\nimport type { AnyType } from '@venizia/ignis-helpers/common';\nimport type { Env, Schema } from 'hono';\nimport type { TRouteHandler } from './context';\n\n/** Registered route with its configuration and router instance. */\nexport interface IDefineRouteOptions<\n RouteConfig extends HonoRouteConfig,\n RouteEnv extends Env = Env,\n RouteSchema extends Schema = {},\n BasePath extends string = '/',\n> {\n configs: ReturnType<typeof createRoute<string, RouteConfig>>;\n route: OpenAPIHono<RouteEnv, RouteSchema, BasePath>;\n}\n\n/** Fluent binding for two-step route registration: bindRoute({ configs }).to({ handler }). */\nexport interface IBindRouteOptions<\n RouteConfig extends HonoRouteConfig,\n RouteEnv extends Env = Env,\n RouteSchema extends Schema = {},\n BasePath extends string = '/',\n> {\n configs: RouteConfig;\n to: <ResponseType = unknown>(opts: {\n handler: TRouteHandler<ResponseType, RouteEnv>;\n }) => IDefineRouteOptions<RouteConfig, RouteEnv, RouteSchema, BasePath>;\n}\n\n/** Route configuration extended with optional authenticate and authorize fields. */\nexport interface IAuthRouteConfig extends HonoRouteConfig {\n authenticate?: { strategies?: TAuthStrategy[]; mode?: TAuthMode };\n authorize?: IAuthorizationSpec | IAuthorizationSpec[];\n}\n\n/** Per-route authentication config: { skip: true } or { strategies, mode }. */\nexport type TRouteAuthenticateConfig =\n | { skip: true }\n | { skip?: false; strategies?: TAuthStrategy[]; mode?: TAuthMode };\n\n/** Per-route authorization config: { skip: true }, single spec, or array of specs. */\nexport type TRouteAuthorizeConfig = { skip: true } | IAuthorizationSpec | IAuthorizationSpec[];\n\n/** Per-route auth config. Endpoint config takes precedence over controller-level config. */\nexport type TRouteAuthConfig = {\n authenticate?: TRouteAuthenticateConfig;\n authorize?: TRouteAuthorizeConfig;\n};\n\n/** OpenAPI response header object */\nexport type TResponseHeaderObject = {\n description?: string;\n schema: { type: 'string'; examples?: string[] };\n};\n\n/** OpenAPI response headers format */\nexport type TResponseHeaders = Record<string, TResponseHeaderObject>;\n\n// Response body types derived from route definitions; a distributive conditional applies z.infer to each schema of the union separately.\ntype TInferDistributive<S> = S extends z.ZodType ? z.infer<S> : never;\n/** The JSON response body type of a route config `R`: the union of the schemas under `application/json` across all its response codes. */\nexport type TResponseBodyOf<R extends { responses: AnyType }> = TInferDistributive<\n R['responses'][keyof R['responses']]['content']['application/json']['schema']\n>;\n\n/** What a CRUD route lets a caller override: auth, `enabled`, the request schemas (params, query, body, headers) and the response schema and headers. */\nexport type TCustomizableRouteConfig = TRouteAuthConfig & {\n /**\n * Whether this route is registered.\n *\n * @default true\n */\n enabled?: boolean;\n request?: {\n params?: TAnyObjectSchema;\n query?: TAnyObjectSchema;\n body?: TAnyObjectSchema;\n headers?: TAnyObjectSchema;\n };\n response?: {\n schema?: z.ZodType;\n headers?: TResponseHeaders;\n };\n};\n\n/** Per-route configuration for CRUD controller endpoints (auth, request, response). */\nexport interface ICustomizableRoutes<\n RouteConfig extends TCustomizableRouteConfig = TCustomizableRouteConfig,\n> {\n count?: RouteConfig;\n find?: RouteConfig;\n findById?: RouteConfig;\n findOne?: RouteConfig;\n create?: RouteConfig;\n updateById?: RouteConfig;\n updateBy?: RouteConfig;\n deleteById?: RouteConfig;\n deleteBy?: RouteConfig;\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AnyType, IConfigurable, TClass, TConstValue } from '@venizia/ignis-helpers/common';
|
|
2
|
+
/** Names of the supported datasource drivers, split into relational and search sets. `isValid` checks a value against all of them. */
|
|
2
3
|
export declare class DataSourceDrivers {
|
|
3
4
|
static readonly NODE_POSTGRES = "node-postgres";
|
|
4
5
|
static readonly POSTGRES_JS = "postgres-js";
|
|
@@ -11,6 +12,7 @@ export declare class DataSourceDrivers {
|
|
|
11
12
|
static readonly SCHEME_SET: Set<string>;
|
|
12
13
|
static isValid(value: string): boolean;
|
|
13
14
|
}
|
|
15
|
+
/** A driver name: one of `DataSourceDrivers`, or any other string for an unlisted engine. */
|
|
14
16
|
export type TDataSourceDriver = TConstValue<typeof DataSourceDrivers> | (string & {});
|
|
15
17
|
/**
|
|
16
18
|
* A driver CLASS, named by `@datasource({ driver })`. The class reference is what pulls the peer
|
|
@@ -18,6 +20,7 @@ export type TDataSourceDriver = TConstValue<typeof DataSourceDrivers> | (string
|
|
|
18
20
|
* dropped. Untyped because `IRelationalDriver` lives under `connectors/`, off-limits to `base/`.
|
|
19
21
|
*/
|
|
20
22
|
export type TDataSourceDriverClass = TClass<AnyType>;
|
|
23
|
+
/** Loose schema record of a datasource; the default `Schema` type argument of `IDataSource`. */
|
|
21
24
|
export type TAnyDataSourceSchema = Record<string, any>;
|
|
22
25
|
/** Engine-neutral datasource contract - the root every connector family implements. */
|
|
23
26
|
export interface IDataSource<Settings extends object = {}, Schema extends TAnyDataSourceSchema = TAnyDataSourceSchema, ConfigurableOptions extends object = {}> extends IConfigurable<ConfigurableOptions> {
|
|
@@ -42,9 +45,11 @@ export interface ITransaction {
|
|
|
42
45
|
commit(): Promise<void>;
|
|
43
46
|
rollback(): Promise<void>;
|
|
44
47
|
}
|
|
48
|
+
/** What a datasource supports. `transactions` tells whether it can open transactions. */
|
|
45
49
|
export interface IDataSourceCapabilities {
|
|
46
50
|
transactions: boolean;
|
|
47
51
|
}
|
|
52
|
+
/** Capabilities of a search datasource. Each `search` flag tells whether the engine supports that feature. */
|
|
48
53
|
export interface ISearchableDataSourceCapabilities extends IDataSourceCapabilities {
|
|
49
54
|
search?: {
|
|
50
55
|
/** Vector / semantic / hybrid search (search engines). */
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** Names of the supported datasource drivers, split into relational and search sets. `isValid` checks a value against all of them. */
|
|
1
2
|
export class DataSourceDrivers {
|
|
2
3
|
// Relational - PGlite is a Postgres DRIVER (Postgres compiled to WASM), not a separate engine.
|
|
3
4
|
static { this.NODE_POSTGRES = 'node-postgres'; }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/base/datasources/common/types.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,iBAAiB;IAC5B,+FAA+F;aAC/E,kBAAa,GAAG,eAAe,CAAC;aAChC,gBAAW,GAAG,aAAa,CAAC;aAC5B,WAAM,GAAG,QAAQ,CAAC;aAClB,WAAM,GAAG,QAAQ,CAAC;IAElC,SAAS;aACO,cAAS,GAAG,WAAW,CAAC;aACxB,gBAAW,GAAG,aAAa,CAAC;aAE5B,0BAAqB,GAAG,IAAI,GAAG,CAAC;QAC9C,IAAI,CAAC,aAAa;QAClB,IAAI,CAAC,WAAW;QAChB,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,MAAM;KACZ,CAAC,CAAC;aAEa,sBAAiB,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;aAEhE,eAAU,GAAG,IAAI,GAAG,CAAC;QACnC,aAAa;QACb,IAAI,CAAC,aAAa;QAClB,IAAI,CAAC,WAAW;QAChB,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,MAAM;QAEX,SAAS;QACT,IAAI,CAAC,SAAS;QACd,IAAI,CAAC,WAAW;KACjB,CAAC,CAAC;IAEH,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC","sourcesContent":["import type { AnyType, IConfigurable, TClass, TConstValue } from '@venizia/ignis-helpers/common';\n\nexport class DataSourceDrivers {\n // Relational - PGlite is a Postgres DRIVER (Postgres compiled to WASM), not a separate engine.\n static readonly NODE_POSTGRES = 'node-postgres';\n static readonly POSTGRES_JS = 'postgres-js';\n static readonly PGLITE = 'pglite';\n static readonly LIBSQL = 'libsql';\n\n // Search\n static readonly TYPESENSE = 'typesense';\n static readonly MEILISEARCH = 'meilisearch';\n\n static readonly RELATIONAL_SCHEME_SET = new Set([\n this.NODE_POSTGRES,\n this.POSTGRES_JS,\n this.PGLITE,\n this.LIBSQL,\n ]);\n\n static readonly SEARCH_SCHEME_SET = new Set([this.TYPESENSE, this.MEILISEARCH]);\n\n static readonly SCHEME_SET = new Set([\n // Relational\n this.NODE_POSTGRES,\n this.POSTGRES_JS,\n this.PGLITE,\n this.LIBSQL,\n\n // Search\n this.TYPESENSE,\n this.MEILISEARCH,\n ]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n// `(string & {})` keeps autocomplete for the known values\n// while still accepting any other engine-driver string.\nexport type TDataSourceDriver = TConstValue<typeof DataSourceDrivers> | (string & {});\n\n/**\n * A driver CLASS, named by `@datasource({ driver })`. The class reference is what pulls the peer\n * package into a bundle - a name string pulls nothing, and a bare side-effect import may be\n * dropped. Untyped because `IRelationalDriver` lives under `connectors/`, off-limits to `base/`.\n */\nexport type TDataSourceDriverClass = TClass<AnyType>;\n\nexport type TAnyDataSourceSchema = Record<string, any>;\n\n/** Engine-neutral datasource contract - the root every connector family implements. */\nexport interface IDataSource<\n Settings extends object = {},\n Schema extends TAnyDataSourceSchema = TAnyDataSourceSchema,\n ConfigurableOptions extends object = {},\n> extends IConfigurable<ConfigurableOptions> {\n name: string;\n settings: Settings;\n schema: Schema;\n\n getSettings(): Settings;\n getSchema(): Schema;\n\n /** Releases what `configure()` opened. `stop()` calls it on every datasource the boot configured. */\n close?(): Promise<void>;\n}\n\n/**\n * Neutral transaction options - isolation levels are engine vocabulary, so `isolationLevel` stays\n * a loose string here and connectors narrow it in their own `ITransactionOptions` extension.\n */\nexport interface ITransactionOptions {\n isolationLevel?: string;\n}\n\n/** Neutral transaction handle - the minimum shape every connector's transaction satisfies. */\nexport interface ITransaction {\n isActive: boolean;\n commit(): Promise<void>;\n rollback(): Promise<void>;\n}\n\nexport interface IDataSourceCapabilities {\n transactions: boolean;\n}\n\nexport interface ISearchableDataSourceCapabilities extends IDataSourceCapabilities {\n search?: {\n /** Vector / semantic / hybrid search (search engines). */\n vector?: boolean;\n\n /** Batched multi-query search across collections. */\n multi?: boolean;\n\n /** Merged (union) result set across a multi-search. */\n union?: boolean;\n\n /** Synonym sets (multi-way / one-way). */\n synonyms?: boolean;\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/base/datasources/common/types.ts"],"names":[],"mappings":"AAEA,sIAAsI;AACtI,MAAM,OAAO,iBAAiB;IAC5B,+FAA+F;aAC/E,kBAAa,GAAG,eAAe,CAAC;aAChC,gBAAW,GAAG,aAAa,CAAC;aAC5B,WAAM,GAAG,QAAQ,CAAC;aAClB,WAAM,GAAG,QAAQ,CAAC;IAElC,SAAS;aACO,cAAS,GAAG,WAAW,CAAC;aACxB,gBAAW,GAAG,aAAa,CAAC;aAE5B,0BAAqB,GAAG,IAAI,GAAG,CAAC;QAC9C,IAAI,CAAC,aAAa;QAClB,IAAI,CAAC,WAAW;QAChB,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,MAAM;KACZ,CAAC,CAAC;aAEa,sBAAiB,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;aAEhE,eAAU,GAAG,IAAI,GAAG,CAAC;QACnC,aAAa;QACb,IAAI,CAAC,aAAa;QAClB,IAAI,CAAC,WAAW;QAChB,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,MAAM;QAEX,SAAS;QACT,IAAI,CAAC,SAAS;QACd,IAAI,CAAC,WAAW;KACjB,CAAC,CAAC;IAEH,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC","sourcesContent":["import type { AnyType, IConfigurable, TClass, TConstValue } from '@venizia/ignis-helpers/common';\n\n/** Names of the supported datasource drivers, split into relational and search sets. `isValid` checks a value against all of them. */\nexport class DataSourceDrivers {\n // Relational - PGlite is a Postgres DRIVER (Postgres compiled to WASM), not a separate engine.\n static readonly NODE_POSTGRES = 'node-postgres';\n static readonly POSTGRES_JS = 'postgres-js';\n static readonly PGLITE = 'pglite';\n static readonly LIBSQL = 'libsql';\n\n // Search\n static readonly TYPESENSE = 'typesense';\n static readonly MEILISEARCH = 'meilisearch';\n\n static readonly RELATIONAL_SCHEME_SET = new Set([\n this.NODE_POSTGRES,\n this.POSTGRES_JS,\n this.PGLITE,\n this.LIBSQL,\n ]);\n\n static readonly SEARCH_SCHEME_SET = new Set([this.TYPESENSE, this.MEILISEARCH]);\n\n static readonly SCHEME_SET = new Set([\n // Relational\n this.NODE_POSTGRES,\n this.POSTGRES_JS,\n this.PGLITE,\n this.LIBSQL,\n\n // Search\n this.TYPESENSE,\n this.MEILISEARCH,\n ]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n// `(string & {})` keeps autocomplete for the known values\n// while still accepting any other engine-driver string.\n/** A driver name: one of `DataSourceDrivers`, or any other string for an unlisted engine. */\nexport type TDataSourceDriver = TConstValue<typeof DataSourceDrivers> | (string & {});\n\n/**\n * A driver CLASS, named by `@datasource({ driver })`. The class reference is what pulls the peer\n * package into a bundle - a name string pulls nothing, and a bare side-effect import may be\n * dropped. Untyped because `IRelationalDriver` lives under `connectors/`, off-limits to `base/`.\n */\nexport type TDataSourceDriverClass = TClass<AnyType>;\n\n/** Loose schema record of a datasource; the default `Schema` type argument of `IDataSource`. */\nexport type TAnyDataSourceSchema = Record<string, any>;\n\n/** Engine-neutral datasource contract - the root every connector family implements. */\nexport interface IDataSource<\n Settings extends object = {},\n Schema extends TAnyDataSourceSchema = TAnyDataSourceSchema,\n ConfigurableOptions extends object = {},\n> extends IConfigurable<ConfigurableOptions> {\n name: string;\n settings: Settings;\n schema: Schema;\n\n getSettings(): Settings;\n getSchema(): Schema;\n\n /** Releases what `configure()` opened. `stop()` calls it on every datasource the boot configured. */\n close?(): Promise<void>;\n}\n\n/**\n * Neutral transaction options - isolation levels are engine vocabulary, so `isolationLevel` stays\n * a loose string here and connectors narrow it in their own `ITransactionOptions` extension.\n */\nexport interface ITransactionOptions {\n isolationLevel?: string;\n}\n\n/** Neutral transaction handle - the minimum shape every connector's transaction satisfies. */\nexport interface ITransaction {\n isActive: boolean;\n commit(): Promise<void>;\n rollback(): Promise<void>;\n}\n\n/** What a datasource supports. `transactions` tells whether it can open transactions. */\nexport interface IDataSourceCapabilities {\n transactions: boolean;\n}\n\n/** Capabilities of a search datasource. Each `search` flag tells whether the engine supports that feature. */\nexport interface ISearchableDataSourceCapabilities extends IDataSourceCapabilities {\n search?: {\n /** Vector / semantic / hybrid search (search engines). */\n vector?: boolean;\n\n /** Batched multi-query search across collections. */\n multi?: boolean;\n\n /** Merged (union) result set across a multi-search. */\n union?: boolean;\n\n /** Synonym sets (multi-way / one-way). */\n synonyms?: boolean;\n };\n}\n"]}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { TConstValue } from '@venizia/ignis-helpers/common';
|
|
2
|
+
/** Defaults and ceilings of event dispatch retry: the `*_CEILING` and `*_WINDOW_MS` values cap what `register` may ask for. */
|
|
2
3
|
export declare class EventDispatchRetry {
|
|
4
|
+
/** Attempts per dispatch when `register` gives no `retry.maxAttempts`. */
|
|
3
5
|
static readonly MAX_ATTEMPTS = 3;
|
|
6
|
+
/** First backoff delay in ms when `register` gives no `retry.baseDelayMs`. */
|
|
4
7
|
static readonly BASE_DELAY_MS = 100;
|
|
5
8
|
/**
|
|
6
9
|
* Ceiling on `register`'s `retry.maxAttempts`. Dispatch is fire-and-forget - nobody awaits it - so
|
|
@@ -33,5 +36,6 @@ export declare class EventHandlerTypes {
|
|
|
33
36
|
static readonly SCHEME_SET: Set<string>;
|
|
34
37
|
static isValid(value: string): value is TEventHandlerType;
|
|
35
38
|
}
|
|
39
|
+
/** Union of the `EventHandlerTypes` values. */
|
|
36
40
|
export type TEventHandlerType = TConstValue<typeof EventHandlerTypes>;
|
|
37
41
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
/** Defaults and ceilings of event dispatch retry: the `*_CEILING` and `*_WINDOW_MS` values cap what `register` may ask for. */
|
|
1
2
|
export class EventDispatchRetry {
|
|
3
|
+
/** Attempts per dispatch when `register` gives no `retry.maxAttempts`. */
|
|
2
4
|
static { this.MAX_ATTEMPTS = 3; }
|
|
5
|
+
/** First backoff delay in ms when `register` gives no `retry.baseDelayMs`. */
|
|
3
6
|
static { this.BASE_DELAY_MS = 100; }
|
|
4
7
|
/**
|
|
5
8
|
* Ceiling on `register`'s `retry.maxAttempts`. Dispatch is fire-and-forget - nobody awaits it - so
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/base/events/common/constants.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,kBAAkB;
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/base/events/common/constants.ts"],"names":[],"mappings":"AAEA,+HAA+H;AAC/H,MAAM,OAAO,kBAAkB;IAC7B,0EAA0E;aAC1D,iBAAY,GAAG,CAAC,CAAC;IAEjC,8EAA8E;aAC9D,kBAAa,GAAG,GAAG,CAAC;IAEpC;;;;;OAKG;aACa,yBAAoB,GAAG,EAAE,CAAC;IAE1C;;;;;;OAMG;aACa,wBAAmB,GAAG,MAAM,CAAC;;AAG/C;;;;;;GAMG;AACH,MAAM,OAAO,iBAAiB;IAC5B,2HAA2H;aAC3G,gBAAW,GAAG,aAAa,CAAC;IAE5C,wKAAwK;aACxJ,aAAQ,GAAG,UAAU,CAAC;aAEtB,eAAU,GAAG,IAAI,GAAG,CAAS,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEhF,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC","sourcesContent":["import type { TConstValue } from '@venizia/ignis-helpers/common';\n\n/** Defaults and ceilings of event dispatch retry: the `*_CEILING` and `*_WINDOW_MS` values cap what `register` may ask for. */\nexport class EventDispatchRetry {\n /** Attempts per dispatch when `register` gives no `retry.maxAttempts`. */\n static readonly MAX_ATTEMPTS = 3;\n\n /** First backoff delay in ms when `register` gives no `retry.baseDelayMs`. */\n static readonly BASE_DELAY_MS = 100;\n\n /**\n * Ceiling on `register`'s `retry.maxAttempts`. Dispatch is fire-and-forget - nobody awaits it - so\n * an attempt count high enough to matter is already high enough to hammer a struggling downstream\n * resource attempt after attempt. Twice the highest count any known consumer has asked for (5)\n * leaves room to tune without permitting an attempt storm.\n */\n static readonly MAX_ATTEMPTS_CEILING = 10;\n\n /**\n * Ceiling, in ms, on the total backoff window `register`'s `retry` can produce (the sum of every\n * inter-attempt delay, computed without jitter since jitter only shrinks it). Matches\n * `RetryHelper`'s own default cap on a SINGLE delay: a dispatch holds a handler's resources - e.g.\n * a database connection - for its entire retry window, so the sum across every attempt gets the\n * same \"unreasonable beyond this\" line the framework already draws for one attempt.\n */\n static readonly MAX_TOTAL_WINDOW_MS = 30_000;\n}\n\n/**\n * Tag for `EventBus.register`'s `handler` union (`TEventHandlerReference`). The tag makes the\n * caller's choice explicit at the call site instead of implicit in whichever field is present, so a\n * mismatched `type`/field pair (`BINDING_KEY` with `fn`, or `FUNCTION` with `key`) is a compile\n * error there rather than a runtime surprise later, inside a `queueMicrotask` where nobody is\n * watching.\n */\nexport class EventHandlerTypes {\n /** `handler.key` is resolved from the container on every retry attempt - a rebind reaches an attempt already in flight. */\n static readonly BINDING_KEY = 'binding-key';\n\n /** `handler.fn` is invoked directly as a captured closure - there is nothing to rebind, so every attempt in a retry window calls the exact function registered here. */\n static readonly FUNCTION = 'function';\n\n static readonly SCHEME_SET = new Set<string>([this.BINDING_KEY, this.FUNCTION]);\n\n static isValid(value: string): value is TEventHandlerType {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** Union of the `EventHandlerTypes` values. */\nexport type TEventHandlerType = TConstValue<typeof EventHandlerTypes>;\n"]}
|
|
@@ -13,9 +13,17 @@ export interface IDomainEvent<TPayload = unknown> {
|
|
|
13
13
|
* outside either throws at `register()`, never clamps.
|
|
14
14
|
*/
|
|
15
15
|
export interface IEventHandlerRetryOptions {
|
|
16
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Attempts per dispatch.
|
|
18
|
+
*
|
|
19
|
+
* @default 3
|
|
20
|
+
*/
|
|
17
21
|
maxAttempts?: number;
|
|
18
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* First backoff delay in ms; exponential growth is computed from it.
|
|
24
|
+
*
|
|
25
|
+
* @default 100
|
|
26
|
+
*/
|
|
19
27
|
baseDelayMs?: number;
|
|
20
28
|
}
|
|
21
29
|
/** A handler callback - synchronous or asynchronous, `EventBus` awaits either the same way. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/base/events/common/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport { type EventHandlerTypes } from './constants';\n\n/** One occurrence of a named domain event, decoupled from whatever publishes or handles it. */\nexport interface IDomainEvent<TPayload = unknown> {\n name: string;\n payload: TPayload;\n occurredAt: string;\n traceId?: string;\n}\n\n/**\n * Per-registration retry override for `EventBus.register`. Both fields must be positive integers,\n * and are bounded by `EventDispatchRetry.MAX_ATTEMPTS_CEILING` / `MAX_TOTAL_WINDOW_MS` - a value\n * outside either throws at `register()`, never clamps.\n */\nexport interface IEventHandlerRetryOptions {\n
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/base/events/common/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport { type EventHandlerTypes } from './constants';\n\n/** One occurrence of a named domain event, decoupled from whatever publishes or handles it. */\nexport interface IDomainEvent<TPayload = unknown> {\n name: string;\n payload: TPayload;\n occurredAt: string;\n traceId?: string;\n}\n\n/**\n * Per-registration retry override for `EventBus.register`. Both fields must be positive integers,\n * and are bounded by `EventDispatchRetry.MAX_ATTEMPTS_CEILING` / `MAX_TOTAL_WINDOW_MS` - a value\n * outside either throws at `register()`, never clamps.\n */\nexport interface IEventHandlerRetryOptions {\n /**\n * Attempts per dispatch.\n *\n * @default 3\n */\n maxAttempts?: number;\n\n /**\n * First backoff delay in ms; exponential growth is computed from it.\n *\n * @default 100\n */\n baseDelayMs?: number;\n}\n\n/** A handler callback - synchronous or asynchronous, `EventBus` awaits either the same way. */\nexport type TEventHandlerFunction<TPayload = unknown> = (opts: {\n event: IDomainEvent<TPayload>;\n}) => ValueOrPromise<void>;\n\n/** `register`'s binding-key handler shape: resolved from the container by `key` on every retry attempt. */\nexport interface IEventHandlerBindingKeyReference {\n type: typeof EventHandlerTypes.BINDING_KEY;\n key: string;\n}\n\n/** `register`'s function handler shape: `fn` is invoked directly, captured as a closure - see `TEventHandlerReference`. */\nexport interface IEventHandlerFunctionReference<TPayload = unknown> {\n type: typeof EventHandlerTypes.FUNCTION;\n fn: TEventHandlerFunction<TPayload>;\n}\n\n/**\n * The two shapes `EventBus.register`'s `handler` accepts, tagged by `type` so the caller states\n * which rather than the bus inferring it from whichever field is present. Only `BINDING_KEY` shares\n * `IEventHandler`'s rebind property; see its doc.\n */\nexport type TEventHandlerReference<TPayload = unknown> =\n | IEventHandlerBindingKeyReference\n | IEventHandlerFunctionReference<TPayload>;\n\n/**\n * Handles one `IDomainEvent`. Implemented by whatever is bound into the container under\n * `register`'s `{ type: EventHandlerTypes.BINDING_KEY, key }` form - see `TEventHandlerReference`\n * for the `FUNCTION` form, which does not implement this interface and does not share its rebind\n * property.\n *\n * MUST be idempotent. The bus retries a failed handler, so delivery is at-least-once: one that\n * half-succeeds then throws runs again from the top, re-applying whatever already landed. Three\n * shapes break, and only the first looks dangerous: a cumulative write (`count = count + 1`, or a\n * rolling average, which drifts toward the resampled value); several writes batched under one\n * `Promise.all`, where any failure re-runs the ones that succeeded; and a bare INSERT of a log or\n * audit row, which simply gains a duplicate - corrupting the record used to diagnose the retry.\n *\n * Resolved from the container by binding key at dispatch time, never captured as a direct reference,\n * so rebinding the key takes effect on the next attempt - including one already in flight. A\n * `FUNCTION`-form handler does NOT have this property: `fn` is a captured closure, so every attempt\n * in a long retry window calls the exact function registered at startup.\n */\nexport interface IEventHandler<TEvent extends IDomainEvent = IDomainEvent> {\n handle(opts: { event: TEvent }): ValueOrPromise<void>;\n}\n"]}
|
|
@@ -1,8 +1,54 @@
|
|
|
1
1
|
import type { IArtifactMetadata, IArtifactRegistrationOptions, TBindingScope } from '../../helpers/inversion/index.js';
|
|
2
2
|
/** The root stereotype: marks a class as an artifact the application registers, with its registration defaults. Every other stereotype calls it. */
|
|
3
3
|
export declare const injectable: <ApplicationType = unknown>(opts: IArtifactMetadata<ApplicationType>) => ClassDecorator;
|
|
4
|
+
/**
|
|
5
|
+
* Class decorator that registers the class as a service artifact; accepts the same registration options as `injectable`.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { BaseService, service } from '@venizia/ignis';
|
|
10
|
+
*
|
|
11
|
+
* export @service()
|
|
12
|
+
* class MailService extends BaseService {
|
|
13
|
+
* constructor() {
|
|
14
|
+
* super({ scope: MailService.name });
|
|
15
|
+
* }
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
4
19
|
export declare const service: <ApplicationType = unknown>(opts?: IArtifactRegistrationOptions<ApplicationType>) => ClassDecorator;
|
|
20
|
+
/**
|
|
21
|
+
* Class decorator that registers the class as a component artifact; accepts the same registration options as `injectable`.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* import { BaseComponent, component } from '@venizia/ignis';
|
|
26
|
+
*
|
|
27
|
+
* export @component()
|
|
28
|
+
* class AuditComponent extends BaseComponent {
|
|
29
|
+
* constructor() {
|
|
30
|
+
* super({ scope: AuditComponent.name });
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* override binding(): void {}
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
5
37
|
export declare const component: <ApplicationType = unknown>(opts?: IArtifactRegistrationOptions<ApplicationType>) => ClassDecorator;
|
|
38
|
+
/**
|
|
39
|
+
* Class decorator that registers the class as a configuration artifact; `after` orders it behind other configuration classes.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* import { BaseConfiguration, configuration } from '@venizia/ignis';
|
|
44
|
+
*
|
|
45
|
+
* export @configuration()
|
|
46
|
+
* class SeedConfiguration extends BaseConfiguration {}
|
|
47
|
+
*
|
|
48
|
+
* export @configuration({ after: [SeedConfiguration] })
|
|
49
|
+
* class IndexConfiguration extends BaseConfiguration {}
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
6
52
|
export declare const configuration: <ApplicationType = unknown>(opts?: IArtifactRegistrationOptions<ApplicationType>) => ClassDecorator;
|
|
7
53
|
/** Marks a component method as the provider of `key`. `registerArtifacts` binds the key to a lazy provider that resolves the component and calls the method; SINGLETON unless `scope` says otherwise. */
|
|
8
54
|
export declare const provide: (opts: {
|
|
@@ -35,12 +35,58 @@ export const injectable = (opts) => {
|
|
|
35
35
|
});
|
|
36
36
|
};
|
|
37
37
|
};
|
|
38
|
+
/**
|
|
39
|
+
* Class decorator that registers the class as a service artifact; accepts the same registration options as `injectable`.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* import { BaseService, service } from '@venizia/ignis';
|
|
44
|
+
*
|
|
45
|
+
* export @service()
|
|
46
|
+
* class MailService extends BaseService {
|
|
47
|
+
* constructor() {
|
|
48
|
+
* super({ scope: MailService.name });
|
|
49
|
+
* }
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
38
53
|
export const service = (opts) => {
|
|
39
54
|
return injectable({ type: ArtifactTypes.SERVICE, ...opts });
|
|
40
55
|
};
|
|
56
|
+
/**
|
|
57
|
+
* Class decorator that registers the class as a component artifact; accepts the same registration options as `injectable`.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* import { BaseComponent, component } from '@venizia/ignis';
|
|
62
|
+
*
|
|
63
|
+
* export @component()
|
|
64
|
+
* class AuditComponent extends BaseComponent {
|
|
65
|
+
* constructor() {
|
|
66
|
+
* super({ scope: AuditComponent.name });
|
|
67
|
+
* }
|
|
68
|
+
*
|
|
69
|
+
* override binding(): void {}
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
41
73
|
export const component = (opts) => {
|
|
42
74
|
return injectable({ type: ArtifactTypes.COMPONENT, ...opts });
|
|
43
75
|
};
|
|
76
|
+
/**
|
|
77
|
+
* Class decorator that registers the class as a configuration artifact; `after` orders it behind other configuration classes.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* import { BaseConfiguration, configuration } from '@venizia/ignis';
|
|
82
|
+
*
|
|
83
|
+
* export @configuration()
|
|
84
|
+
* class SeedConfiguration extends BaseConfiguration {}
|
|
85
|
+
*
|
|
86
|
+
* export @configuration({ after: [SeedConfiguration] })
|
|
87
|
+
* class IndexConfiguration extends BaseConfiguration {}
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
44
90
|
export const configuration = (opts) => {
|
|
45
91
|
return injectable({ type: ArtifactTypes.CONFIGURATION, ...opts });
|
|
46
92
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectable.js","sourceRoot":"","sources":["../../../../src/base/metadata/injectable.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEvD,oJAAoJ;AACpJ,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,IAAwC,EACxB,EAAE;IAClB,OAAO,CAAC,MAAM,EAAE,EAAE;QAChB,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI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,YAAY,CAAC,aAAa,GAAG,aAAa,CAAC;QAC7C,CAAC;QAED,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,YAAY,CAAC,KAAK,GAAG,KAAK,CAAC;QAC7B,CAAC;QAED,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,YAAY,CAAC,KAAK,GAAG,KAAK,CAAC;QAC7B,CAAC;QAED,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,YAAY,CAAC,IAAI,GAAG,IAAI,CAAC;QAC3B,CAAC;QAED,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,YAAY,CAAC,KAAK,GAAG,KAAK,CAAC;QAC7B,CAAC;QAED,OAAO,YAAY,CAAC;IACtB,CAAC;CACF","sourcesContent":["import type {\n IArtifactMetadata,\n IArtifactRegistrationOptions,\n TBindingScope,\n} from '@/helpers/inversion';\nimport { ArtifactNamespaces, BindingNamespaces } from '@/common/bindings';\nimport { ArtifactTypes, MetadataRegistry } from '@/helpers/inversion';\nimport { ArtifactBindingKeys } from './artifact-keys';\nimport { getError } from '@venizia/ignis-helpers/core';\n\n/** The root stereotype: marks a class as an artifact the application registers, with its registration defaults. Every other stereotype calls it. */\nexport const injectable = <ApplicationType = unknown>(\n opts: IArtifactMetadata<ApplicationType>,\n): ClassDecorator => {\n return (target) => {\n if (!ArtifactTypes.isValid(opts.type)) {\n throw getError({\n message: `[injectable][${target.name}] Invalid artifact type: '${opts.type}' | Expected one of: ${[...ArtifactTypes.SCHEME_SET].join(', ')}`,\n });\n }\n\n // At import time, so the failure lands where the binding is written, not at boot.\n if (opts.binding) {\n BindingNamespaces.assertArtifactNamespace({\n namespace: opts.binding.namespace,\n artifact: target.name,\n caller: 'injectable',\n });\n }\n\n const registry = MetadataRegistry.getInstance();\n registry.setArtifactMetadata({ target, metadata: opts });\n\n // Discovery happens HERE, at import time. A boot-time filesystem scan cannot see a compiled\n // single-file binary, and a class exists at run time only because something imported it.\n registry.addDiscoveredArtifact({ target });\n\n // The key this class WOULD get; `registerArtifact` overwrites it with the one actually bound.\n registry.setBindingKey({\n target,\n key: ArtifactBindingKeys.resolve({\n target,\n namespace: ArtifactNamespaces.resolve({ type: opts.type }),\n binding: opts.binding,\n }).key,\n isProvisional: true,\n });\n };\n};\n\nexport const service = <ApplicationType = unknown>(\n opts?: IArtifactRegistrationOptions<ApplicationType>,\n): ClassDecorator => {\n return injectable<ApplicationType>({ type: ArtifactTypes.SERVICE, ...opts });\n};\n\nexport const component = <ApplicationType = unknown>(\n opts?: IArtifactRegistrationOptions<ApplicationType>,\n): ClassDecorator => {\n return injectable<ApplicationType>({ type: ArtifactTypes.COMPONENT, ...opts });\n};\n\nexport const configuration = <ApplicationType = unknown>(\n opts?: IArtifactRegistrationOptions<ApplicationType>,\n): ClassDecorator => {\n return injectable<ApplicationType>({ type: ArtifactTypes.CONFIGURATION, ...opts });\n};\n\n/** Marks a component method as the provider of `key`. `registerArtifacts` binds the key to a lazy provider that resolves the component and calls the method; SINGLETON unless `scope` says otherwise. */\nexport const provide = (opts: { key: string; scope?: TBindingScope }): MethodDecorator => {\n return (target, propertyKey) => {\n MetadataRegistry.getInstance().addProvideMetadata({\n target: target.constructor,\n metadata: {\n methodName: propertyKey,\n key: opts.key,\n ...(opts.scope ? { scope: opts.scope } : {}),\n },\n });\n };\n};\n\n/** Helpers of the stereotype decorators; the decorators themselves stay functions. */\nexport class InjectableUtility {\n /** The registration defaults a stereotype forwards to `@injectable`, copied field by field so an absent option stays absent. */\n static pickRegistrationOptions<ApplicationType = unknown>(opts: {\n metadata: IArtifactRegistrationOptions<ApplicationType>;\n }): IArtifactRegistrationOptions<ApplicationType> {\n const { binding, allowOverride, scope, order, when, after } = opts.metadata;\n const registration: IArtifactRegistrationOptions<ApplicationType> = {};\n\n if (binding !== undefined) {\n registration.binding = binding;\n }\n\n if (allowOverride !== undefined) {\n registration.allowOverride = allowOverride;\n }\n\n if (scope !== undefined) {\n registration.scope = scope;\n }\n\n if (order !== undefined) {\n registration.order = order;\n }\n\n if (when !== undefined) {\n registration.when = when;\n }\n\n if (after !== undefined) {\n registration.after = after;\n }\n\n return registration;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"injectable.js","sourceRoot":"","sources":["../../../../src/base/metadata/injectable.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEvD,oJAAoJ;AACpJ,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,IAAwC,EACxB,EAAE;IAClB,OAAO,CAAC,MAAM,EAAE,EAAE;QAChB,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACtC,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,gBAAgB,MAAM,CAAC,IAAI,6BAA6B,IAAI,CAAC,IAAI,wBAAwB,CAAC,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;aAC7I,CAAC,CAAC;QACL,CAAC;QAED,kFAAkF;QAClF,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,iBAAiB,CAAC,uBAAuB,CAAC;gBACxC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS;gBACjC,QAAQ,EAAE,MAAM,CAAC,IAAI;gBACrB,MAAM,EAAE,YAAY;aACrB,CAAC,CAAC;QACL,CAAC;QAED,MAAM,QAAQ,GAAG,gBAAgB,CAAC,WAAW,EAAE,CAAC;QAChD,QAAQ,CAAC,mBAAmB,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;QAEzD,4FAA4F;QAC5F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ers/inversion';\nimport { ArtifactNamespaces, BindingNamespaces } from '@/common/bindings';\nimport { ArtifactTypes, MetadataRegistry } from '@/helpers/inversion';\nimport { ArtifactBindingKeys } from './artifact-keys';\nimport { getError } from '@venizia/ignis-helpers/core';\n\n/** The root stereotype: marks a class as an artifact the application registers, with its registration defaults. Every other stereotype calls it. */\nexport const injectable = <ApplicationType = unknown>(\n opts: IArtifactMetadata<ApplicationType>,\n): ClassDecorator => {\n return (target) => {\n if (!ArtifactTypes.isValid(opts.type)) {\n throw getError({\n message: `[injectable][${target.name}] Invalid artifact type: '${opts.type}' | Expected one of: ${[...ArtifactTypes.SCHEME_SET].join(', ')}`,\n });\n }\n\n // At import time, so the failure lands where the binding is written, not at boot.\n if (opts.binding) {\n BindingNamespaces.assertArtifactNamespace({\n namespace: opts.binding.namespace,\n artifact: target.name,\n caller: 'injectable',\n });\n }\n\n const registry = MetadataRegistry.getInstance();\n registry.setArtifactMetadata({ target, metadata: opts });\n\n // Discovery happens HERE, at import time. A boot-time filesystem scan cannot see a compiled\n // single-file binary, and a class exists at run time only because something imported it.\n registry.addDiscoveredArtifact({ target });\n\n // The key this class WOULD get; `registerArtifact` overwrites it with the one actually bound.\n registry.setBindingKey({\n target,\n key: ArtifactBindingKeys.resolve({\n target,\n namespace: ArtifactNamespaces.resolve({ type: opts.type }),\n binding: opts.binding,\n }).key,\n isProvisional: true,\n });\n };\n};\n\n/**\n * Class decorator that registers the class as a service artifact; accepts the same registration options as `injectable`.\n *\n * @example\n * ```typescript\n * import { BaseService, service } from '@venizia/ignis';\n *\n * export @service()\n * class MailService extends BaseService {\n * constructor() {\n * super({ scope: MailService.name });\n * }\n * }\n * ```\n */\nexport const service = <ApplicationType = unknown>(\n opts?: IArtifactRegistrationOptions<ApplicationType>,\n): ClassDecorator => {\n return injectable<ApplicationType>({ type: ArtifactTypes.SERVICE, ...opts });\n};\n\n/**\n * Class decorator that registers the class as a component artifact; accepts the same registration options as `injectable`.\n *\n * @example\n * ```typescript\n * import { BaseComponent, component } from '@venizia/ignis';\n *\n * export @component()\n * class AuditComponent extends BaseComponent {\n * constructor() {\n * super({ scope: AuditComponent.name });\n * }\n *\n * override binding(): void {}\n * }\n * ```\n */\nexport const component = <ApplicationType = unknown>(\n opts?: IArtifactRegistrationOptions<ApplicationType>,\n): ClassDecorator => {\n return injectable<ApplicationType>({ type: ArtifactTypes.COMPONENT, ...opts });\n};\n\n/**\n * Class decorator that registers the class as a configuration artifact; `after` orders it behind other configuration classes.\n *\n * @example\n * ```typescript\n * import { BaseConfiguration, configuration } from '@venizia/ignis';\n *\n * export @configuration()\n * class SeedConfiguration extends BaseConfiguration {}\n *\n * export @configuration({ after: [SeedConfiguration] })\n * class IndexConfiguration extends BaseConfiguration {}\n * ```\n */\nexport const configuration = <ApplicationType = unknown>(\n opts?: IArtifactRegistrationOptions<ApplicationType>,\n): ClassDecorator => {\n return injectable<ApplicationType>({ type: ArtifactTypes.CONFIGURATION, ...opts });\n};\n\n/** Marks a component method as the provider of `key`. `registerArtifacts` binds the key to a lazy provider that resolves the component and calls the method; SINGLETON unless `scope` says otherwise. */\nexport const provide = (opts: { key: string; scope?: TBindingScope }): MethodDecorator => {\n return (target, propertyKey) => {\n MetadataRegistry.getInstance().addProvideMetadata({\n target: target.constructor,\n metadata: {\n methodName: propertyKey,\n key: opts.key,\n ...(opts.scope ? { scope: opts.scope } : {}),\n },\n });\n };\n};\n\n/** Helpers of the stereotype decorators; the decorators themselves stay functions. */\nexport class InjectableUtility {\n /** The registration defaults a stereotype forwards to `@injectable`, copied field by field so an absent option stays absent. */\n static pickRegistrationOptions<ApplicationType = unknown>(opts: {\n metadata: IArtifactRegistrationOptions<ApplicationType>;\n }): IArtifactRegistrationOptions<ApplicationType> {\n const { binding, allowOverride, scope, order, when, after } = opts.metadata;\n const registration: IArtifactRegistrationOptions<ApplicationType> = {};\n\n if (binding !== undefined) {\n registration.binding = binding;\n }\n\n if (allowOverride !== undefined) {\n registration.allowOverride = allowOverride;\n }\n\n if (scope !== undefined) {\n registration.scope = scope;\n }\n\n if (order !== undefined) {\n registration.order = order;\n }\n\n if (when !== undefined) {\n registration.when = when;\n }\n\n if (after !== undefined) {\n registration.after = after;\n }\n\n return registration;\n }\n}\n"]}
|
|
@@ -1,9 +1,54 @@
|
|
|
1
1
|
import type { IDataSourceMetadata, IModelMetadata, TRepositoryMetadata } from '../../helpers/inversion/index.js';
|
|
2
2
|
import type { IDataSource } from '../datasources/index.js';
|
|
3
3
|
import type { AbstractEntity } from '../models/index.js';
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* Registers a model class with its static schema and relations.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { model } from '@venizia/ignis';
|
|
10
|
+
* import { ModelFactory } from '@venizia/ignis-connectors/postgres';
|
|
11
|
+
* import { pgTable, serial, text } from 'drizzle-orm/pg-core';
|
|
12
|
+
*
|
|
13
|
+
* const noteTable = pgTable('Note', { id: serial('id').primaryKey(), body: text('body') });
|
|
14
|
+
*
|
|
15
|
+
* export @model({ settings: { query: { limit: { default: 20 } } } })
|
|
16
|
+
* class Note extends ModelFactory.defineEntity({ table: noteTable }) {}
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
5
19
|
export declare const model: (input?: IModelMetadata) => ClassDecorator;
|
|
6
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* Registers a datasource with driver and auto-discovery settings.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* import { datasource } from '@venizia/ignis';
|
|
26
|
+
* import { BasePostgresDataSource } from '@venizia/ignis-connectors/postgres';
|
|
27
|
+
* import { NodePostgresDriver } from '@venizia/ignis-connectors/postgres/node-postgres';
|
|
28
|
+
* import { Pool } from 'pg';
|
|
29
|
+
*
|
|
30
|
+
* export @datasource({ driver: NodePostgresDriver })
|
|
31
|
+
* class AppDataSource extends BasePostgresDataSource<{ connectionString: string }> {
|
|
32
|
+
* constructor() { super({ name: AppDataSource.name, config: { connectionString: 'postgres://localhost/app' } }); }
|
|
33
|
+
* override configure(): void { this.client = new Pool(this.settings); }
|
|
34
|
+
* override getConnectionString(): string { return this.settings.connectionString; }
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
7
38
|
export declare const datasource: (metadata?: IDataSourceMetadata) => ClassDecorator;
|
|
39
|
+
/**
|
|
40
|
+
* Class decorator that registers a repository and binds it to a model (or, for a remote repository, only a datasource). Called without arguments on a subclass it reuses the type, model and datasource of its nearest decorated parent; registration options are not inherited.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* import { repository } from '@venizia/ignis';
|
|
45
|
+
* import { DefaultCRUDRepository } from '@venizia/ignis-connectors/postgres';
|
|
46
|
+
* import { AppDataSource } from './app.datasource';
|
|
47
|
+
* import { Note, noteTable } from './note.model';
|
|
48
|
+
*
|
|
49
|
+
* export @repository({ model: Note, dataSource: AppDataSource })
|
|
50
|
+
* class NoteRepository extends DefaultCRUDRepository<typeof noteTable> {}
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
8
53
|
export declare const repository: <Model extends AbstractEntity = AbstractEntity, DataSource extends IDataSource = IDataSource>(metadata?: TRepositoryMetadata<Model, DataSource>) => ClassDecorator;
|
|
9
54
|
//# sourceMappingURL=persistents.d.ts.map
|
|
@@ -6,7 +6,21 @@ import { isDataSourceClass } from '../datasources/index.js';
|
|
|
6
6
|
import { RepositoryTypes } from '../repositories/common/constants.js';
|
|
7
7
|
import { injectable, InjectableUtility } from './injectable.js';
|
|
8
8
|
import { ModelMetadataUtility } from './model-metadata.js';
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Registers a model class with its static schema and relations.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { model } from '@venizia/ignis';
|
|
15
|
+
* import { ModelFactory } from '@venizia/ignis-connectors/postgres';
|
|
16
|
+
* import { pgTable, serial, text } from 'drizzle-orm/pg-core';
|
|
17
|
+
*
|
|
18
|
+
* const noteTable = pgTable('Note', { id: serial('id').primaryKey(), body: text('body') });
|
|
19
|
+
*
|
|
20
|
+
* export @model({ settings: { query: { limit: { default: 20 } } } })
|
|
21
|
+
* class Note extends ModelFactory.defineEntity({ table: noteTable }) {}
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
10
24
|
export const model = (input = {}) => {
|
|
11
25
|
return (target) => {
|
|
12
26
|
injectable({
|
|
@@ -40,7 +54,24 @@ export const model = (input = {}) => {
|
|
|
40
54
|
MetadataRegistry.getInstance().registerModel({ target, metadata });
|
|
41
55
|
};
|
|
42
56
|
};
|
|
43
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* Registers a datasource with driver and auto-discovery settings.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* import { datasource } from '@venizia/ignis';
|
|
63
|
+
* import { BasePostgresDataSource } from '@venizia/ignis-connectors/postgres';
|
|
64
|
+
* import { NodePostgresDriver } from '@venizia/ignis-connectors/postgres/node-postgres';
|
|
65
|
+
* import { Pool } from 'pg';
|
|
66
|
+
*
|
|
67
|
+
* export @datasource({ driver: NodePostgresDriver })
|
|
68
|
+
* class AppDataSource extends BasePostgresDataSource<{ connectionString: string }> {
|
|
69
|
+
* constructor() { super({ name: AppDataSource.name, config: { connectionString: 'postgres://localhost/app' } }); }
|
|
70
|
+
* override configure(): void { this.client = new Pool(this.settings); }
|
|
71
|
+
* override getConnectionString(): string { return this.settings.connectionString; }
|
|
72
|
+
* }
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
44
75
|
export const datasource = (metadata) => {
|
|
45
76
|
return (target) => {
|
|
46
77
|
injectable({
|
|
@@ -220,6 +251,20 @@ const applyRepositoryMetadata = (opts) => {
|
|
|
220
251
|
const resolved = resolveRepositoryMetadata({ metadata, target, registry });
|
|
221
252
|
registry.setRepositoryMetadata({ target, metadata: { ...metadata, _resolved: resolved } });
|
|
222
253
|
};
|
|
254
|
+
/**
|
|
255
|
+
* Class decorator that registers a repository and binds it to a model (or, for a remote repository, only a datasource). Called without arguments on a subclass it reuses the type, model and datasource of its nearest decorated parent; registration options are not inherited.
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* ```typescript
|
|
259
|
+
* import { repository } from '@venizia/ignis';
|
|
260
|
+
* import { DefaultCRUDRepository } from '@venizia/ignis-connectors/postgres';
|
|
261
|
+
* import { AppDataSource } from './app.datasource';
|
|
262
|
+
* import { Note, noteTable } from './note.model';
|
|
263
|
+
*
|
|
264
|
+
* export @repository({ model: Note, dataSource: AppDataSource })
|
|
265
|
+
* class NoteRepository extends DefaultCRUDRepository<typeof noteTable> {}
|
|
266
|
+
* ```
|
|
267
|
+
*/
|
|
223
268
|
export const repository = (metadata) => {
|
|
224
269
|
return (target) => {
|
|
225
270
|
const registry = MetadataRegistry.getInstance();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"persistents.js","sourceRoot":"","sources":["../../../../src/base/metadata/persistents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAQtD,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACjG,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAE/E,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD,oEAAoE;AACpE,MAAM,CAAC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qB,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,GAAG,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;AAC7F,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,CAIxB,QAAiD,EACjC,EAAE;IAClB,OAAO,CAAC,MAAM,EAAE,EAAE;QAChB,MAAM,QAAQ,GAAG,gBAAgB,CAAC,WAAW,EAAE,CAAC;QAEhD,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;YAEH,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","sourcesContent":["import { BindingNamespaces } from '@/common/bindings';\nimport type {\n IArtifactRegistrationOptions,\n IDataSourceMetadata,\n IModelMetadata,\n IResolvedRepositoryMetadata,\n TRepositoryMetadata,\n} from '@/helpers/inversion';\nimport { ArtifactTypes, BindingKeys, MetadataKeys, MetadataRegistry } from '@/helpers/inversion';\nimport { ClassResolver, ResolverUtility } from '@venizia/ignis-helpers/common';\nimport type { IInjectMetadata } from '@venizia/ignis-inversion';\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, InjectableUtility } from './injectable';\nimport { ModelMetadataUtility } from './model-metadata';\n\n/** Registers a model class with its static schema and relations. */\nexport const model = (input: IModelMetadata = {}): ClassDecorator => {\n return (target) => {\n injectable({\n type: ArtifactTypes.MODEL,\n ...InjectableUtility.pickRegistrationOptions({ metadata: input }),\n })(target);\n\n const metadata = ModelMetadataUtility.normalizeModelMetadata({\n model: target.name,\n metadata: input,\n });\n\n const { settings } = metadata;\n\n const defaultLimit = settings?.query?.limit?.default;\n\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\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\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 ...InjectableUtility.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 ? ResolverUtility.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\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 = ClassResolver.resolveClass({ ref: metadata.dataSource });\n\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\n return {\n type: RepositoryTypes.REMOTE,\n dataSource: resolvedDataSource,\n operationScope: metadata.operationScope,\n };\n }\n\n const resolvedModel = ResolverUtility.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\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\n return { type, dataSource, operationScope };\n }\n\n const { type, model: parentModel, dataSource, operationScope } = inherited;\n\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 ...InjectableUtility.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\n if (!metadata) {\n applyRepositoryMetadata({\n metadata: inheritRepositoryMetadata({ target, registry }),\n registration: {},\n target,\n registry,\n });\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.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Content":["import { BindingNamespaces } from '@/common/bindings';\nimport type {\n IArtifactRegistrationOptions,\n IDataSourceMetadata,\n IModelMetadata,\n IResolvedRepositoryMetadata,\n TRepositoryMetadata,\n} from '@/helpers/inversion';\nimport { ArtifactTypes, BindingKeys, MetadataKeys, MetadataRegistry } from '@/helpers/inversion';\nimport { ClassResolver, ResolverUtility } from '@venizia/ignis-helpers/common';\nimport type { IInjectMetadata } from '@venizia/ignis-inversion';\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, InjectableUtility } from './injectable';\nimport { ModelMetadataUtility } from './model-metadata';\n\n/**\n * Registers a model class with its static schema and relations.\n *\n * @example\n * ```typescript\n * import { model } from '@venizia/ignis';\n * import { ModelFactory } from '@venizia/ignis-connectors/postgres';\n * import { pgTable, serial, text } from 'drizzle-orm/pg-core';\n *\n * const noteTable = pgTable('Note', { id: serial('id').primaryKey(), body: text('body') });\n *\n * export @model({ settings: { query: { limit: { default: 20 } } } })\n * class Note extends ModelFactory.defineEntity({ table: noteTable }) {}\n * ```\n */\nexport const model = (input: IModelMetadata = {}): ClassDecorator => {\n return (target) => {\n injectable({\n type: ArtifactTypes.MODEL,\n ...InjectableUtility.pickRegistrationOptions({ metadata: input }),\n })(target);\n\n const metadata = ModelMetadataUtility.normalizeModelMetadata({\n model: target.name,\n metadata: input,\n });\n\n const { settings } = metadata;\n\n const defaultLimit = settings?.query?.limit?.default;\n\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\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\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/**\n * Registers a datasource with driver and auto-discovery settings.\n *\n * @example\n * ```typescript\n * import { datasource } from '@venizia/ignis';\n * import { BasePostgresDataSource } from '@venizia/ignis-connectors/postgres';\n * import { NodePostgresDriver } from '@venizia/ignis-connectors/postgres/node-postgres';\n * import { Pool } from 'pg';\n *\n * export @datasource({ driver: NodePostgresDriver })\n * class AppDataSource extends BasePostgresDataSource<{ connectionString: string }> {\n * constructor() { super({ name: AppDataSource.name, config: { connectionString: 'postgres://localhost/app' } }); }\n * override configure(): void { this.client = new Pool(this.settings); }\n * override getConnectionString(): string { return this.settings.connectionString; }\n * }\n * ```\n */\nexport const datasource = (metadata?: IDataSourceMetadata): ClassDecorator => {\n return (target) => {\n injectable({\n type: ArtifactTypes.DATASOURCE,\n ...InjectableUtility.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 ? ResolverUtility.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\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 = ClassResolver.resolveClass({ ref: metadata.dataSource });\n\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\n return {\n type: RepositoryTypes.REMOTE,\n dataSource: resolvedDataSource,\n operationScope: metadata.operationScope,\n };\n }\n\n const resolvedModel = ResolverUtility.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\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\n return { type, dataSource, operationScope };\n }\n\n const { type, model: parentModel, dataSource, operationScope } = inherited;\n\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 ...InjectableUtility.pickRegistrationOptions({ metadata: registration }),\n })(target);\n\n const resolved = resolveRepositoryMetadata({ metadata, target, registry });\n\n registry.setRepositoryMetadata({ target, metadata: { ...metadata, _resolved: resolved } });\n};\n\n/**\n * Class decorator that registers a repository and binds it to a model (or, for a remote repository, only a datasource). Called without arguments on a subclass it reuses the type, model and datasource of its nearest decorated parent; registration options are not inherited.\n *\n * @example\n * ```typescript\n * import { repository } from '@venizia/ignis';\n * import { DefaultCRUDRepository } from '@venizia/ignis-connectors/postgres';\n * import { AppDataSource } from './app.datasource';\n * import { Note, noteTable } from './note.model';\n *\n * export @repository({ model: Note, dataSource: AppDataSource })\n * class NoteRepository extends DefaultCRUDRepository<typeof noteTable> {}\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\n if (!metadata) {\n applyRepositoryMetadata({\n metadata: inheritRepositoryMetadata({ target, registry }),\n registration: {},\n target,\n registry,\n });\n\n return;\n }\n\n applyRepositoryMetadata({ metadata, registration: metadata, target, registry });\n };\n};\n"]}
|