@cosmneo/onion-lasagna 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-36IO4BM7.js +113 -0
- package/dist/chunk-36IO4BM7.js.map +1 -0
- package/dist/chunk-4BVOLXDJ.js +54 -0
- package/dist/chunk-4BVOLXDJ.js.map +1 -0
- package/dist/{chunk-GGSAAZPM.js → chunk-AUMHMWDD.js} +19 -20
- package/dist/chunk-AUMHMWDD.js.map +1 -0
- package/dist/chunk-CBTICRSM.js +34 -0
- package/dist/chunk-CBTICRSM.js.map +1 -0
- package/dist/chunk-H5TNDC5U.js +138 -0
- package/dist/chunk-H5TNDC5U.js.map +1 -0
- package/dist/chunk-KJ4JGZOE.js +96 -0
- package/dist/chunk-KJ4JGZOE.js.map +1 -0
- package/dist/chunk-MF2JDREK.js +168 -0
- package/dist/chunk-MF2JDREK.js.map +1 -0
- package/dist/chunk-RVSBIYY4.js +1 -0
- package/dist/chunk-RVSBIYY4.js.map +1 -0
- package/dist/{chunk-PUVAB3JX.js → chunk-XIRJ73IO.js} +38 -36
- package/dist/chunk-XIRJ73IO.js.map +1 -0
- package/dist/{chunk-DS7TE6KZ.js → chunk-XP6PLTV2.js} +11 -3
- package/dist/chunk-XP6PLTV2.js.map +1 -0
- package/dist/chunk-XWKHOLIP.js +191 -0
- package/dist/chunk-XWKHOLIP.js.map +1 -0
- package/dist/event-router-definition.type-CP9uTlux.d.cts +150 -0
- package/dist/event-router-definition.type-D8CG-kjZ.d.ts +150 -0
- package/dist/events/asyncapi/index.cjs +143 -0
- package/dist/events/asyncapi/index.cjs.map +1 -0
- package/dist/events/asyncapi/index.d.cts +184 -0
- package/dist/events/asyncapi/index.d.ts +184 -0
- package/dist/events/asyncapi/index.js +8 -0
- package/dist/events/asyncapi/index.js.map +1 -0
- package/dist/events/handler/index.cjs +171 -0
- package/dist/events/handler/index.cjs.map +1 -0
- package/dist/events/handler/index.d.cts +153 -0
- package/dist/events/handler/index.d.ts +153 -0
- package/dist/events/handler/index.js +21 -0
- package/dist/events/handler/index.js.map +1 -0
- package/dist/events/index.cjs +497 -0
- package/dist/events/index.cjs.map +1 -0
- package/dist/events/index.d.cts +9 -0
- package/dist/events/index.d.ts +9 -0
- package/dist/events/index.js +41 -0
- package/dist/events/index.js.map +1 -0
- package/dist/events/server/index.cjs +291 -0
- package/dist/events/server/index.cjs.map +1 -0
- package/dist/events/server/index.d.cts +281 -0
- package/dist/events/server/index.d.ts +281 -0
- package/dist/events/server/index.js +16 -0
- package/dist/events/server/index.js.map +1 -0
- package/dist/events/shared/index.cjs +85 -0
- package/dist/events/shared/index.cjs.map +1 -0
- package/dist/events/shared/index.d.cts +35 -0
- package/dist/events/shared/index.d.ts +35 -0
- package/dist/events/shared/index.js +13 -0
- package/dist/events/shared/index.js.map +1 -0
- package/dist/global.js +3 -3
- package/dist/http/index.cjs +563 -93
- package/dist/http/index.cjs.map +1 -1
- package/dist/http/index.d.cts +5 -3
- package/dist/http/index.d.ts +5 -3
- package/dist/http/index.js +30 -12
- package/dist/http/openapi/index.cjs +43 -35
- package/dist/http/openapi/index.cjs.map +1 -1
- package/dist/http/openapi/index.d.cts +8 -34
- package/dist/http/openapi/index.d.ts +8 -34
- package/dist/http/openapi/index.js +2 -2
- package/dist/http/route/index.cjs +106 -9
- package/dist/http/route/index.cjs.map +1 -1
- package/dist/http/route/index.d.cts +133 -227
- package/dist/http/route/index.d.ts +133 -227
- package/dist/http/route/index.js +5 -2
- package/dist/http/server/index.cjs +24 -19
- package/dist/http/server/index.cjs.map +1 -1
- package/dist/http/server/index.d.cts +4 -261
- package/dist/http/server/index.d.ts +4 -261
- package/dist/http/server/index.js +2 -2
- package/dist/http/shared/index.cjs.map +1 -1
- package/dist/http/shared/index.d.cts +10 -14
- package/dist/http/shared/index.d.ts +10 -14
- package/dist/http/shared/index.js +11 -127
- package/dist/http/shared/index.js.map +1 -1
- package/dist/index.js +6 -6
- package/dist/{router-definition.type-ynBhT16T.d.cts → router-definition.type-BElX-Pl4.d.cts} +169 -256
- package/dist/{router-definition.type-DORVlLNk.d.ts → router-definition.type-DxG8ncJZ.d.ts} +169 -256
- package/dist/types-B6Q1iCgf.d.ts +262 -0
- package/dist/types-afYpL7Ap.d.cts +262 -0
- package/dist/types-cke61juH.d.cts +42 -0
- package/dist/types-cke61juH.d.ts +42 -0
- package/package.json +35 -2
- package/dist/chunk-BZULBF4N.js +0 -82
- package/dist/chunk-BZULBF4N.js.map +0 -1
- package/dist/chunk-DS7TE6KZ.js.map +0 -1
- package/dist/chunk-GGSAAZPM.js.map +0 -1
- package/dist/chunk-PUVAB3JX.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/presentation/events/index.ts","../../src/presentation/events/handler/define-event-handler.ts","../../src/presentation/events/handler/types/event-router-definition.type.ts","../../src/presentation/events/handler/define-event-router.ts","../../src/presentation/events/handler/utils.ts","../../src/presentation/http/shared/error-mapping.ts","../../src/presentation/events/shared/error-mapping.ts","../../src/presentation/events/server/types.ts","../../src/presentation/events/server/create-event-routes.ts","../../src/presentation/events/server/event-routes-builder.ts","../../src/presentation/events/asyncapi/generate.ts"],"sourcesContent":["// Handler layer: defineEventHandler, defineEventRouter, mergeEventRouters\nexport {\n defineEventHandler,\n defineEventRouter,\n mergeEventRouters,\n generateHandlerId,\n} from './handler';\nexport type {\n DefineEventRouterOptions,\n EventHandlerDefinition,\n EventHandlerDocumentation,\n EventRouterEntry,\n EventRouterConfig,\n EventRouterDefaults,\n EventRouterDefinition,\n FlattenEventRouter,\n EventRouterKeys,\n GetEventHandler,\n InferEventType,\n InferEventPayload,\n InferEventContext,\n} from './handler';\nexport { isEventHandlerDefinition, isEventRouterDefinition, collectEventHandlers } from './handler';\n\n// Server layer: eventRoutes builder\nexport { eventRoutes } from './server';\nexport type {\n EventRoutesBuilder,\n MissingHandlersError,\n BuilderEventHandlerConfig,\n RawEvent,\n EventMetadata,\n ValidatedEvent,\n TypedEventContext,\n EventHandlerConfig,\n SimpleEventHandlerFn,\n SimpleEventHandlerConfig,\n EventMiddlewareFunction,\n CreateEventRoutesOptions,\n UnifiedEventInput,\n UseCasePort,\n} from './server';\nexport { isSimpleEventHandlerConfig } from './server';\n\n// Shared layer: EventResult, error mapping\nexport type { EventResult } from './shared';\nexport { mapErrorToEventResult } from './shared';\n\n// AsyncAPI layer: spec generation\nexport { generateAsyncAPI } from './asyncapi';\nexport type {\n AsyncAPIConfig,\n AsyncAPIInfo,\n AsyncAPIServer,\n AsyncAPITag,\n AsyncAPIExternalDocs,\n AsyncAPISpec,\n AsyncAPIChannel,\n AsyncAPIMessage,\n AsyncAPIOperation,\n AsyncAPIComponents,\n} from './asyncapi';\n","/**\n * @fileoverview Factory function for creating event handler definitions.\n *\n * The `defineEventHandler` function is the main entry point for defining\n * event handlers. It mirrors `defineRoute` from the HTTP layer but is\n * tailored for asynchronous event processing.\n *\n * @module events/handler/define-event-handler\n */\n\nimport type { SchemaAdapter, InferOutput } from '../../http/schema/types';\nimport type { EventHandlerDefinition } from './types';\n\n// ============================================================================\n// Input Types\n// ============================================================================\n\n/**\n * Input for defineEventHandler.\n *\n * @example Basic handler with payload schema\n * ```typescript\n * defineEventHandler({\n * eventType: 'ticket.created',\n * payload: zodSchema(z.object({ ticketId: z.string() })),\n * docs: { summary: 'Handle ticket creation', tags: ['ticket'] },\n * })\n * ```\n *\n * @example With context schema\n * ```typescript\n * defineEventHandler({\n * eventType: 'order.shipped',\n * payload: zodSchema(orderShippedSchema),\n * context: zodSchema(eventMetadataSchema),\n * })\n * ```\n */\ninterface DefineEventHandlerInput<\n TEventType extends string,\n TPayload extends SchemaAdapter | undefined = undefined,\n TContext extends SchemaAdapter | undefined = undefined,\n> {\n /** Event type string used for routing (e.g., 'ticket.created'). */\n readonly eventType: TEventType;\n\n /** Payload validation schema. */\n readonly payload?: TPayload;\n\n /** Context validation schema (validates event metadata). */\n readonly context?: TContext;\n\n /** Handler documentation. */\n readonly docs?: {\n readonly summary?: string;\n readonly description?: string;\n readonly tags?: readonly string[];\n readonly deprecated?: boolean;\n };\n}\n\n// ============================================================================\n// Return type helpers\n// ============================================================================\n\ntype ResolvePayload<T> = T extends SchemaAdapter ? InferOutput<T> : undefined;\ntype ResolveContext<T> = T extends SchemaAdapter ? InferOutput<T> : undefined;\n\n// ============================================================================\n// Factory Function\n// ============================================================================\n\n/**\n * Creates an event handler definition from the provided configuration.\n *\n * This is the main entry point for defining event handlers. The resulting\n * definition can be used for type-safe handler registration, payload\n * validation, and documentation generation.\n *\n * @param input - Event handler configuration with optional schemas\n * @returns A frozen EventHandlerDefinition object with full type information\n */\nexport function defineEventHandler<\n TEventType extends string,\n TPayload extends SchemaAdapter | undefined = undefined,\n TContext extends SchemaAdapter | undefined = undefined,\n>(\n input: DefineEventHandlerInput<TEventType, TPayload, TContext>,\n): EventHandlerDefinition<TEventType, ResolvePayload<TPayload>, ResolveContext<TContext>> {\n const definition = {\n eventType: input.eventType,\n payload: input.payload ?? undefined,\n context: input.context ?? undefined,\n docs: {\n summary: input.docs?.summary,\n description: input.docs?.description,\n tags: input.docs?.tags,\n deprecated: input.docs?.deprecated ?? false,\n },\n _types: undefined as unknown,\n };\n\n return Object.freeze(definition) as EventHandlerDefinition<\n TEventType,\n ResolvePayload<TPayload>,\n ResolveContext<TContext>\n >;\n}\n","/**\n * @fileoverview Event router definition types for grouping event handlers.\n *\n * Mirrors the HTTP router definition pattern with hierarchical grouping,\n * dotted-key access, and deep merge support.\n *\n * @module events/handler/types/event-router-definition\n */\n\nimport type { EventHandlerDefinition } from './event-handler-definition.type';\nimport type { SchemaAdapter } from '../../../http/schema/types';\n\n// ============================================================================\n// Router Types\n// ============================================================================\n\n/**\n * A router entry can be an event handler definition, a nested config, or a router definition.\n */\nexport type EventRouterEntry =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n EventHandlerDefinition<string, any, any> | EventRouterConfig | EventRouterDefinition;\n\n/**\n * Configuration for an event router (group of event handlers).\n */\nexport interface EventRouterConfig {\n readonly [key: string]: EventRouterEntry;\n}\n\n/**\n * Router-level defaults applied to all child event handlers.\n */\nexport interface EventRouterDefaults {\n /** Default tags for all handlers. Merged with handler-specific tags. */\n readonly tags?: readonly string[];\n\n /** Default context schema. Applied to handlers that don't define their own. */\n readonly context?: SchemaAdapter;\n}\n\n/**\n * A fully defined event router.\n */\nexport interface EventRouterDefinition<T extends EventRouterConfig = EventRouterConfig> {\n /** The handlers and nested routers in this router. */\n readonly handlers: T;\n\n /** Default values applied to all child handlers. */\n readonly defaults?: EventRouterDefaults;\n\n /**\n * Marker to identify this as an event router.\n * @internal\n */\n readonly _isEventRouter: true;\n}\n\n// ============================================================================\n// Type Guards\n// ============================================================================\n\n/**\n * Checks if a value is an EventHandlerDefinition.\n */\nexport function isEventHandlerDefinition(value: unknown): value is EventHandlerDefinition {\n return typeof value === 'object' && value !== null && 'eventType' in value && '_types' in value;\n}\n\n/**\n * Checks if a value is an EventRouterDefinition.\n */\nexport function isEventRouterDefinition(value: unknown): value is EventRouterDefinition {\n return (\n typeof value === 'object' &&\n value !== null &&\n '_isEventRouter' in value &&\n (value as EventRouterDefinition)._isEventRouter === true\n );\n}\n\n// ============================================================================\n// Utility Types\n// ============================================================================\n\n/**\n * Flattens an event router into a map of dotted keys to handler definitions.\n */\nexport type FlattenEventRouter<\n T extends EventRouterConfig,\n Prefix extends string = '',\n> = T extends EventRouterConfig\n ? {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [K in keyof T]: T[K] extends EventHandlerDefinition<any, any, any>\n ? { [P in `${Prefix}${K & string}`]: T[K] }\n : T[K] extends EventRouterConfig\n ? FlattenEventRouter<T[K], `${Prefix}${K & string}.`>\n : never;\n }[keyof T] extends infer U\n ? // eslint-disable-next-line @typescript-eslint/no-explicit-any\n U extends Record<string, EventHandlerDefinition<any, any, any>>\n ? U\n : never\n : never\n : never;\n\n/**\n * Gets all handler keys from an event router.\n */\nexport type EventRouterKeys<\n T extends EventRouterConfig,\n Prefix extends string = '',\n> = T extends EventRouterConfig\n ? {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [K in keyof T]: T[K] extends EventHandlerDefinition<any, any, any>\n ? `${Prefix}${K & string}`\n : T[K] extends EventRouterConfig\n ? EventRouterKeys<T[K], `${Prefix}${K & string}.`>\n : never;\n }[keyof T]\n : never;\n\n/**\n * Gets an event handler by its dotted key path.\n */\nexport type GetEventHandler<\n T extends EventRouterConfig,\n K extends string,\n> = K extends `${infer Head}.${infer Tail}`\n ? Head extends keyof T\n ? T[Head] extends EventRouterConfig\n ? GetEventHandler<T[Head], Tail>\n : never\n : never\n : K extends keyof T\n ? // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T[K] extends EventHandlerDefinition<any, any, any>\n ? T[K]\n : never\n : never;\n\n// ============================================================================\n// Deep Merge Types\n// ============================================================================\n\n/**\n * Deep-merges two event router configs at the type level.\n */\nexport type DeepMergeTwo<A extends EventRouterConfig, B extends EventRouterConfig> = {\n readonly [K in keyof A | keyof B]: K extends keyof A\n ? K extends keyof B\n ? A[K] extends EventRouterConfig\n ? B[K] extends EventRouterConfig\n ? DeepMergeTwo<A[K], B[K]>\n : B[K]\n : B[K]\n : A[K]\n : K extends keyof B\n ? B[K]\n : never;\n};\n\n/**\n * Recursively deep-merges N event router configs left-to-right.\n */\nexport type DeepMergeAll<T extends readonly EventRouterConfig[]> = T extends readonly [\n infer Only extends EventRouterConfig,\n]\n ? Only\n : T extends readonly [\n infer First extends EventRouterConfig,\n infer Second extends EventRouterConfig,\n ...infer Rest extends readonly EventRouterConfig[],\n ]\n ? DeepMergeAll<[DeepMergeTwo<First, Second>, ...Rest]>\n : EventRouterConfig;\n\n// ============================================================================\n// Runtime Utilities\n// ============================================================================\n\n/**\n * Collects all event handlers from a router into a flat array.\n */\nexport function collectEventHandlers(\n config: EventRouterConfig,\n basePath = '',\n): { key: string; handler: EventHandlerDefinition }[] {\n const handlers: { key: string; handler: EventHandlerDefinition }[] = [];\n\n for (const [key, value] of Object.entries(config)) {\n const fullKey = basePath ? `${basePath}.${key}` : key;\n\n if (isEventHandlerDefinition(value)) {\n handlers.push({ key: fullKey, handler: value });\n } else if (isEventRouterDefinition(value)) {\n handlers.push(...collectEventHandlers(value.handlers, fullKey));\n } else if (typeof value === 'object' && value !== null) {\n handlers.push(...collectEventHandlers(value as EventRouterConfig, fullKey));\n }\n }\n\n return handlers;\n}\n","/**\n * @fileoverview Factory function for creating event router definitions.\n *\n * The `defineEventRouter` function groups event handlers into a hierarchical\n * structure with optional router-level defaults for context and tags.\n *\n * @module events/handler/define-event-router\n */\n\nimport type {\n EventRouterConfig,\n EventRouterDefaults,\n EventRouterDefinition,\n EventHandlerDefinition,\n DeepMergeTwo,\n DeepMergeAll,\n} from './types';\nimport { isEventHandlerDefinition, isEventRouterDefinition } from './types';\n\n/**\n * Options for event router definition.\n */\nexport interface DefineEventRouterOptions {\n /**\n * Default values applied to all child handlers.\n *\n * @example\n * ```typescript\n * defineEventRouter({\n * created: onTicketCreated,\n * assigned: onTicketAssigned,\n * }, {\n * defaults: {\n * context: zodSchema(eventMetadataSchema),\n * tags: ['ticket'],\n * },\n * })\n * ```\n */\n readonly defaults?: EventRouterDefaults;\n}\n\n/**\n * Creates an event router definition from a configuration object.\n *\n * @param handlers - Object containing event handlers and nested routers\n * @param options - Optional router configuration\n * @returns A frozen EventRouterDefinition object\n *\n * @example Basic router\n * ```typescript\n * const ticketEvents = defineEventRouter({\n * created: onTicketCreated,\n * assigned: onTicketAssigned,\n * transferred: onTicketTransferred,\n * });\n * ```\n *\n * @example Nested router\n * ```typescript\n * const events = defineEventRouter({\n * ticket: {\n * created: onTicketCreated,\n * assigned: onTicketAssigned,\n * },\n * ecosystem: {\n * memberAdded: onMemberAdded,\n * },\n * });\n * ```\n */\nexport function defineEventRouter<T extends EventRouterConfig>(\n handlers: T,\n options?: DefineEventRouterOptions,\n): EventRouterDefinition<T> {\n const defaults = options?.defaults;\n\n const processedHandlers =\n defaults?.context || defaults?.tags\n ? (applyEventRouterDefaults(handlers, defaults) as T)\n : handlers;\n\n const definition: EventRouterDefinition<T> = {\n handlers: processedHandlers,\n defaults,\n _isEventRouter: true,\n };\n\n return deepFreeze(definition);\n}\n\n/**\n * Recursively applies router-level defaults to all handlers in the tree.\n */\nfunction applyEventRouterDefaults(\n handlers: EventRouterConfig,\n defaults: EventRouterDefaults,\n): EventRouterConfig {\n const result: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(handlers)) {\n if (isEventHandlerDefinition(value)) {\n result[key] = applyDefaultsToEventHandler(value, defaults);\n } else if (isEventRouterDefinition(value)) {\n result[key] = {\n ...value,\n handlers: applyEventRouterDefaults(value.handlers, defaults),\n };\n } else if (typeof value === 'object' && value !== null) {\n result[key] = applyEventRouterDefaults(value as EventRouterConfig, defaults);\n }\n }\n\n return result as EventRouterConfig;\n}\n\n/**\n * Applies router-level defaults to a single event handler definition.\n */\nfunction applyDefaultsToEventHandler(\n handler: EventHandlerDefinition,\n defaults: EventRouterDefaults,\n): EventHandlerDefinition {\n const needsContext = defaults.context && !handler.context;\n const needsTags = defaults.tags && defaults.tags.length > 0;\n\n if (!needsContext && !needsTags) return handler;\n\n return Object.freeze({\n ...handler,\n context: handler.context ?? defaults.context ?? undefined,\n docs: {\n ...handler.docs,\n tags: mergeTags(defaults.tags, handler.docs.tags),\n },\n }) as EventHandlerDefinition;\n}\n\n/**\n * Merges router-level tags with handler-level tags, avoiding duplicates.\n */\nfunction mergeTags(\n routerTags?: readonly string[],\n handlerTags?: readonly string[],\n): readonly string[] | undefined {\n if (!routerTags || routerTags.length === 0) return handlerTags;\n if (!handlerTags || handlerTags.length === 0) return routerTags;\n\n const merged = [...routerTags];\n for (const tag of handlerTags) {\n if (!merged.includes(tag)) {\n merged.push(tag);\n }\n }\n return merged;\n}\n\n/**\n * Deep freezes an object and all its nested objects.\n */\nfunction deepFreeze<T extends object>(obj: T): T {\n const propNames = Object.getOwnPropertyNames(obj) as (keyof T)[];\n\n for (const name of propNames) {\n const value = obj[name];\n if (value && typeof value === 'object' && !Object.isFrozen(value)) {\n deepFreeze(value);\n }\n }\n\n return Object.freeze(obj);\n}\n\n// ============================================================================\n// mergeEventRouters — variadic deep merge\n// ============================================================================\n\ntype EventRouterInput<T extends EventRouterConfig> = T | EventRouterDefinition<T>;\n\n/** Extracts the raw EventRouterConfig from either a plain config or an EventRouterDefinition. */\nfunction extractHandlers<T extends EventRouterConfig>(input: EventRouterInput<T>): T {\n return isEventRouterDefinition(input) ? input.handlers : input;\n}\n\n/** Returns true if `value` is a plain sub-router object. */\nfunction isSubRouter(value: unknown): value is EventRouterConfig {\n return (\n typeof value === 'object' &&\n value !== null &&\n !isEventHandlerDefinition(value) &&\n !isEventRouterDefinition(value)\n );\n}\n\n/** Recursively deep-merges two router configs. Sub-routers are merged; leaves are overwritten. */\nfunction deepMergeConfigs(a: EventRouterConfig, b: EventRouterConfig): EventRouterConfig {\n const result: Record<string, unknown> = { ...a };\n\n for (const key of Object.keys(b)) {\n const aVal = result[key];\n const bVal = b[key];\n\n if (isSubRouter(aVal) && isSubRouter(bVal)) {\n result[key] = deepMergeConfigs(aVal, bVal);\n } else {\n result[key] = bVal;\n }\n }\n\n return result as EventRouterConfig;\n}\n\n// Overloads for 2–8 routers\nexport function mergeEventRouters<T1 extends EventRouterConfig, T2 extends EventRouterConfig>(\n r1: EventRouterInput<T1>,\n r2: EventRouterInput<T2>,\n): EventRouterDefinition<DeepMergeTwo<T1, T2>>;\nexport function mergeEventRouters<\n T1 extends EventRouterConfig,\n T2 extends EventRouterConfig,\n T3 extends EventRouterConfig,\n>(\n r1: EventRouterInput<T1>,\n r2: EventRouterInput<T2>,\n r3: EventRouterInput<T3>,\n): EventRouterDefinition<DeepMergeAll<[T1, T2, T3]>>;\nexport function mergeEventRouters<\n T1 extends EventRouterConfig,\n T2 extends EventRouterConfig,\n T3 extends EventRouterConfig,\n T4 extends EventRouterConfig,\n>(\n r1: EventRouterInput<T1>,\n r2: EventRouterInput<T2>,\n r3: EventRouterInput<T3>,\n r4: EventRouterInput<T4>,\n): EventRouterDefinition<DeepMergeAll<[T1, T2, T3, T4]>>;\nexport function mergeEventRouters<\n T1 extends EventRouterConfig,\n T2 extends EventRouterConfig,\n T3 extends EventRouterConfig,\n T4 extends EventRouterConfig,\n T5 extends EventRouterConfig,\n>(\n r1: EventRouterInput<T1>,\n r2: EventRouterInput<T2>,\n r3: EventRouterInput<T3>,\n r4: EventRouterInput<T4>,\n r5: EventRouterInput<T5>,\n): EventRouterDefinition<DeepMergeAll<[T1, T2, T3, T4, T5]>>;\nexport function mergeEventRouters<\n T1 extends EventRouterConfig,\n T2 extends EventRouterConfig,\n T3 extends EventRouterConfig,\n T4 extends EventRouterConfig,\n T5 extends EventRouterConfig,\n T6 extends EventRouterConfig,\n>(\n r1: EventRouterInput<T1>,\n r2: EventRouterInput<T2>,\n r3: EventRouterInput<T3>,\n r4: EventRouterInput<T4>,\n r5: EventRouterInput<T5>,\n r6: EventRouterInput<T6>,\n): EventRouterDefinition<DeepMergeAll<[T1, T2, T3, T4, T5, T6]>>;\nexport function mergeEventRouters<\n T1 extends EventRouterConfig,\n T2 extends EventRouterConfig,\n T3 extends EventRouterConfig,\n T4 extends EventRouterConfig,\n T5 extends EventRouterConfig,\n T6 extends EventRouterConfig,\n T7 extends EventRouterConfig,\n>(\n r1: EventRouterInput<T1>,\n r2: EventRouterInput<T2>,\n r3: EventRouterInput<T3>,\n r4: EventRouterInput<T4>,\n r5: EventRouterInput<T5>,\n r6: EventRouterInput<T6>,\n r7: EventRouterInput<T7>,\n): EventRouterDefinition<DeepMergeAll<[T1, T2, T3, T4, T5, T6, T7]>>;\nexport function mergeEventRouters<\n T1 extends EventRouterConfig,\n T2 extends EventRouterConfig,\n T3 extends EventRouterConfig,\n T4 extends EventRouterConfig,\n T5 extends EventRouterConfig,\n T6 extends EventRouterConfig,\n T7 extends EventRouterConfig,\n T8 extends EventRouterConfig,\n>(\n r1: EventRouterInput<T1>,\n r2: EventRouterInput<T2>,\n r3: EventRouterInput<T3>,\n r4: EventRouterInput<T4>,\n r5: EventRouterInput<T5>,\n r6: EventRouterInput<T6>,\n r7: EventRouterInput<T7>,\n r8: EventRouterInput<T8>,\n): EventRouterDefinition<DeepMergeAll<[T1, T2, T3, T4, T5, T6, T7, T8]>>;\n\n// Variadic fallback for 9+\nexport function mergeEventRouters(\n ...routers: EventRouterInput<EventRouterConfig>[]\n): EventRouterDefinition<EventRouterConfig>;\n\n// Implementation\nexport function mergeEventRouters(\n ...routers: EventRouterInput<EventRouterConfig>[]\n): EventRouterDefinition<EventRouterConfig> {\n const merged = routers.map(extractHandlers).reduce(deepMergeConfigs);\n return defineEventRouter(merged);\n}\n","/**\n * @fileoverview Utility functions for event handler routing.\n *\n * @module events/handler/utils\n */\n\n/**\n * Generates a handler ID from a dotted key path.\n *\n * Converts dot-separated keys to camelCase:\n * - `\"ticket.created\"` → `\"ticketCreated\"`\n * - `\"ecosystem.member.added\"` → `\"ecosystemMemberAdded\"`\n *\n * @param key - The dotted key path\n * @returns A camelCase handler ID\n */\nexport function generateHandlerId(key: string): string {\n return key.replace(/\\.(\\w)/g, (_, char: string) => char.toUpperCase());\n}\n","/**\n * @fileoverview Centralized error mapping for HTTP frameworks.\n *\n * Provides a single source of truth for mapping onion-lasagna errors\n * to HTTP status codes and response bodies.\n *\n * @module http/shared/error-mapping\n */\n\nimport { CodedError } from '../../../global/exceptions/coded-error.error';\nimport { ObjectValidationError } from '../../../global/exceptions/object-validation.error';\nimport { DomainError } from '../../../domain/exceptions/domain.error';\nimport { UseCaseError } from '../../../app/exceptions/use-case.error';\nimport { NotFoundError } from '../../../app/exceptions/not-found.error';\nimport { ConflictError } from '../../../app/exceptions/conflict.error';\nimport { UnprocessableError } from '../../../app/exceptions/unprocessable.error';\nimport { ForbiddenError } from '../../../app/exceptions/forbidden.error';\nimport { UnauthorizedError } from '../../../app/exceptions/unauthorized.error';\nimport { InfraError } from '../../../infra/exceptions/infra.error';\nimport { ControllerError } from '../../exceptions/controller.error';\nimport { AccessDeniedError } from '../../exceptions/access-denied.error';\nimport { InvalidRequestError } from '../../exceptions/invalid-request.error';\nimport type { ErrorResponseBody, MappedErrorResponse } from './types';\n\n// ============================================================================\n// Constants and Interfaces\n// ============================================================================\n\n/**\n * Default masked error response for internal errors.\n */\nconst MASKED_ERROR_BODY: ErrorResponseBody = {\n message: 'An unexpected error occurred',\n errorCode: 'INTERNAL_ERROR',\n};\n\n/**\n * Known internal error type names that should be masked.\n */\nconst INTERNAL_ERROR_TYPES = [\n 'DomainError',\n 'InfraError',\n 'ControllerError',\n 'NetworkError',\n 'PersistenceError',\n 'ExternalServiceError',\n 'InvariantViolationError',\n];\n\n/**\n * Validation error item structure.\n */\ninterface ValidationErrorInput {\n field: string;\n message: string;\n}\n\n/**\n * Validation error structure for string-based checking.\n */\ninterface ValidationErrorItem {\n field: string;\n message: string;\n}\n\n/**\n * Interface for errors with validation items.\n */\ninterface ErrorWithValidation {\n message: string;\n code: string;\n validationErrors: ValidationErrorItem[];\n}\n\n/**\n * Interface for coded errors.\n */\ninterface CodedErrorLike {\n message: string;\n code: string;\n}\n\n// ============================================================================\n// String-based type checking helpers (for bundled code compatibility)\n// ============================================================================\n\n/**\n * Checks if error matches a specific error type by checking its constructor name.\n * This approach avoids issues with multiple class instances in bundled code.\n * Handles both original names and tsup's mangled names (prefixed with _).\n *\n * @param error - The error to check\n * @param typeName - The error type name to match\n * @returns True if error matches the type name\n */\nexport function isErrorType(error: unknown, typeName: string): error is CodedErrorLike {\n if (!error || typeof error !== 'object') return false;\n // Guard against objects without constructor (e.g., Object.create(null))\n const constructor = Object.prototype.hasOwnProperty.call(error, 'constructor')\n ? (error as { constructor?: { name?: string } }).constructor\n : Object.getPrototypeOf(error)?.constructor;\n if (!constructor) return false;\n const name = constructor.name;\n // Check both the original name and the mangled name (tsup prefixes with _)\n return name === typeName || name === `_${typeName}`;\n}\n\n/**\n * Checks if error has validation errors array.\n *\n * @param error - The error to check\n * @returns True if error has validationErrors property\n */\nexport function hasValidationErrors(error: unknown): error is ErrorWithValidation {\n if (!error || typeof error !== 'object') return false;\n return (\n 'validationErrors' in error && Array.isArray((error as ErrorWithValidation).validationErrors)\n );\n}\n\n// ============================================================================\n// Response body builders\n// ============================================================================\n\n/**\n * Builds a validation error response body from error details.\n *\n * @param message - The error message\n * @param code - The error code\n * @param validationErrors - Array of field validation errors\n * @returns Error response body with errorItems\n */\nfunction buildValidationErrorBody(\n message: string,\n code: string,\n validationErrors: readonly ValidationErrorInput[],\n): ErrorResponseBody {\n return {\n message,\n errorCode: code,\n errorItems: validationErrors.map((e) => ({\n item: e.field,\n message: e.message,\n })),\n };\n}\n\n/**\n * Builds a simple error response body from error details.\n *\n * @param message - The error message\n * @param code - The error code\n * @returns Error response body\n */\nfunction buildSimpleErrorBody(message: string, code: string): ErrorResponseBody {\n return {\n message,\n errorCode: code,\n };\n}\n\n// ============================================================================\n// Primary error mapping functions (with bundled code fallback)\n// ============================================================================\n\n/**\n * Maps an error to the appropriate HTTP status code.\n * Uses instanceof first, then falls back to name-based checking for bundled code.\n *\n * @param error - The error to map\n * @returns HTTP status code\n */\nexport function getHttpStatusCode(error: unknown): number {\n // Try instanceof first (faster)\n if (error instanceof ObjectValidationError) return 400;\n if (error instanceof InvalidRequestError) return 400;\n if (error instanceof UnauthorizedError) return 401;\n if (error instanceof ForbiddenError) return 403;\n if (error instanceof AccessDeniedError) return 403;\n if (error instanceof NotFoundError) return 404;\n if (error instanceof ConflictError) return 409;\n if (error instanceof UnprocessableError) return 422;\n if (error instanceof UseCaseError) return 400;\n\n // Fall back to name-based checking for bundled code (e.g., _NotFoundError)\n if (isErrorType(error, 'ObjectValidationError')) return 400;\n if (isErrorType(error, 'InvalidRequestError')) return 400;\n if (isErrorType(error, 'UnauthorizedError')) return 401;\n if (isErrorType(error, 'ForbiddenError')) return 403;\n if (isErrorType(error, 'AccessDeniedError')) return 403;\n if (isErrorType(error, 'NotFoundError')) return 404;\n if (isErrorType(error, 'ConflictError')) return 409;\n if (isErrorType(error, 'UnprocessableError')) return 422;\n if (isErrorType(error, 'UseCaseError')) return 400;\n\n return 500;\n}\n\n/**\n * Checks if an error should have its details masked in the response.\n *\n * Security-sensitive errors (domain, infrastructure, controller) are masked\n * to prevent leaking implementation details.\n * Uses instanceof first, then falls back to name-based checking for bundled code.\n *\n * @param error - The error to check\n * @returns True if error details should be hidden\n */\nexport function shouldMaskError(error: unknown): boolean {\n // Try instanceof first (faster)\n if (\n error instanceof DomainError ||\n error instanceof InfraError ||\n error instanceof ControllerError\n ) {\n return true;\n }\n\n // Fall back to name-based checking for bundled code\n for (const errorType of INTERNAL_ERROR_TYPES) {\n if (isErrorType(error, errorType)) {\n return true;\n }\n }\n\n return false;\n}\n\n/**\n * Creates the response body for an error.\n * Uses instanceof first, then falls back to name-based checking for bundled code.\n *\n * @param error - The error to create body for\n * @returns Error response body\n */\nexport function createErrorResponseBody(error: unknown): ErrorResponseBody {\n // Masked errors - hide internal details\n if (shouldMaskError(error)) {\n return MASKED_ERROR_BODY;\n }\n\n // Validation errors - include field details (try instanceof first)\n if (error instanceof ObjectValidationError) {\n return buildValidationErrorBody(error.message, error.code, error.validationErrors);\n }\n if (error instanceof InvalidRequestError) {\n return buildValidationErrorBody(error.message, error.code, error.validationErrors);\n }\n\n // Validation errors - fall back to name-based checking for bundled code\n if (isErrorType(error, 'ObjectValidationError') && hasValidationErrors(error)) {\n return buildValidationErrorBody(error.message, error.code, error.validationErrors);\n }\n if (isErrorType(error, 'InvalidRequestError') && hasValidationErrors(error)) {\n return buildValidationErrorBody(error.message, error.code, error.validationErrors);\n }\n\n // Other coded errors - expose message and code (try instanceof first)\n if (error instanceof CodedError) {\n return buildSimpleErrorBody(error.message, error.code);\n }\n\n // Other coded errors - fall back to name-based checking\n if (isErrorType(error, 'CodedError')) {\n return buildSimpleErrorBody(error.message, error.code);\n }\n\n // Check for any error with message and code properties\n if (\n error &&\n typeof error === 'object' &&\n 'message' in error &&\n 'code' in error &&\n typeof (error as CodedErrorLike).message === 'string' &&\n typeof (error as CodedErrorLike).code === 'string'\n ) {\n return buildSimpleErrorBody((error as CodedErrorLike).message, (error as CodedErrorLike).code);\n }\n\n // Unknown errors - mask\n return MASKED_ERROR_BODY;\n}\n\n/**\n * Maps an error to a complete HTTP response structure.\n *\n * Mapping strategy (checked in order):\n * 1. `ObjectValidationError` / `InvalidRequestError` → 400 Bad Request (with field errors)\n * 2. `UseCaseError` → 400 Bad Request\n * 3. `UnauthorizedError` → 401 Unauthorized\n * 4. `ForbiddenError` / `AccessDeniedError` → 403 Forbidden\n * 5. `NotFoundError` → 404 Not Found\n * 6. `ConflictError` → 409 Conflict\n * 7. `UnprocessableError` → 422 Unprocessable Entity\n * 8. `DomainError` / `InfraError` / `ControllerError` → 500 Internal Server Error (masked)\n * 9. Unknown → 500 Internal Server Error (masked)\n *\n * @param error - The error to map\n * @returns Mapped error response with status and body\n */\nexport function mapErrorToHttpResponse(error: unknown): MappedErrorResponse {\n return {\n status: getHttpStatusCode(error),\n body: createErrorResponseBody(error),\n };\n}\n","/**\n * @fileoverview Error-to-EventResult mapping for event handlers.\n *\n * Maps caught errors to event processing outcomes (ack/retry/dlq).\n * Uses the same name-based type checking as the HTTP error mapper\n * for compatibility with bundled/minified code.\n *\n * @module events/shared/error-mapping\n */\n\nimport { isErrorType } from '../../http/shared/error-mapping';\nimport type { EventResult } from './types';\n\n// ============================================================================\n// Error Type Classifications\n// ============================================================================\n\n/**\n * Error types that indicate permanent failures (send to DLQ).\n * These errors will not resolve on retry.\n */\nconst DLQ_ERROR_TYPES = [\n 'ObjectValidationError',\n 'InvalidRequestError',\n 'UseCaseError',\n 'DomainError',\n 'UnprocessableError',\n 'AccessDeniedError',\n 'ForbiddenError',\n 'UnauthorizedError',\n 'InvariantViolationError',\n];\n\n/**\n * Error types that indicate transient failures (retry).\n * These errors may resolve on subsequent attempts.\n */\nconst RETRY_ERROR_TYPES = [\n 'NotFoundError',\n 'ConflictError',\n 'InfraError',\n 'DbError',\n 'NetworkError',\n 'TimeoutError',\n 'ExternalServiceError',\n 'PersistenceError',\n];\n\n// ============================================================================\n// Mapping Function\n// ============================================================================\n\n/**\n * Maps a caught error to an EventResult.\n *\n * Default mapping strategy:\n *\n * | Error Type | Outcome | Rationale |\n * |------------------------------------------------|---------|----------------------------------------|\n * | ObjectValidationError, InvalidRequestError | dlq | Bad payload — retrying won't help |\n * | UseCaseError | dlq | Business rule rejection — permanent |\n * | DomainError, InvariantViolationError | dlq | Domain invariant — permanent |\n * | UnprocessableError | dlq | Valid but not processable — permanent |\n * | AccessDeniedError, ForbiddenError, Unauthorized | dlq | Permission — permanent |\n * | NotFoundError | retry | Entity might not exist yet |\n * | ConflictError | retry | Concurrent write — may resolve |\n * | InfraError, DbError, NetworkError, TimeoutError | retry | Infrastructure/transient |\n * | Unknown | retry | Conservative — don't lose messages |\n *\n * @param error - The caught error\n * @returns An EventResult indicating how the message should be handled\n */\nexport function mapErrorToEventResult(error: unknown): EventResult {\n // Check DLQ errors first (permanent failures)\n for (const typeName of DLQ_ERROR_TYPES) {\n if (isErrorType(error, typeName)) {\n return {\n outcome: 'dlq',\n reason: (error as { message: string }).message,\n };\n }\n }\n\n // Check retry errors (transient failures)\n for (const typeName of RETRY_ERROR_TYPES) {\n if (isErrorType(error, typeName)) {\n return {\n outcome: 'retry',\n reason: (error as { message: string }).message,\n };\n }\n }\n\n // Unknown errors — retry conservatively to avoid losing messages\n const message =\n error instanceof Error ? error.message : 'Unknown error occurred during event processing';\n\n return {\n outcome: 'retry',\n reason: message,\n };\n}\n","/**\n * @fileoverview Server types for the event handler system.\n *\n * @module events/server/types\n */\n\nimport type { EventHandlerDefinition, EventRouterConfig, EventRouterKeys } from '../handler/types';\nimport type { EventResult } from '../shared/types';\n\n// Re-export UseCasePort from HTTP — same interface, no duplication\nexport type { UseCasePort } from '../../http/server/types';\n\n// ============================================================================\n// Raw Event (from messaging system)\n// ============================================================================\n\n/**\n * Event metadata provided by the messaging system.\n */\nexport interface EventMetadata {\n /** Unique event identifier for idempotency checks. */\n readonly eventId: string;\n\n /** ISO 8601 timestamp of when the event occurred. */\n readonly timestamp: string;\n\n /** Correlation ID for distributed tracing. */\n readonly correlationId?: string;\n\n /** Source system or bounded context that emitted the event. */\n readonly source?: string;\n\n /** Number of delivery attempts (1-based). */\n readonly attemptCount?: number;\n\n /** Additional metadata from the messaging system. */\n readonly [key: string]: unknown;\n}\n\n/**\n * Raw event from the messaging system.\n * This is the input to event handlers before validation.\n */\nexport interface RawEvent {\n /** Event type string for routing. */\n readonly type: string;\n\n /** Event payload (unvalidated). */\n readonly payload: unknown;\n\n /** Event metadata from the messaging system. */\n readonly metadata: EventMetadata;\n}\n\n// ============================================================================\n// Validated Event\n// ============================================================================\n\n/**\n * A validated event with typed payload.\n * This is what handlers receive after validation passes.\n */\nexport interface ValidatedEvent<THandler extends EventHandlerDefinition> {\n /** Validated event payload. */\n readonly payload: THandler['_types']['payload'];\n\n /** Raw event object for advanced use cases. */\n readonly raw: RawEvent;\n}\n\n/**\n * Typed event context based on handler definition.\n * If the handler defines a context schema, this will be the validated type.\n * Otherwise, it falls back to the generic EventMetadata.\n */\nexport type TypedEventContext<THandler extends EventHandlerDefinition> =\n THandler['_types']['context'] extends undefined ? EventMetadata : THandler['_types']['context'];\n\n// ============================================================================\n// Handler Types\n// ============================================================================\n\n/**\n * Handler configuration using the use case pattern.\n *\n * @typeParam THandler - The event handler definition type\n * @typeParam TInput - Use case input type\n * @typeParam TOutput - Use case output type\n */\nexport interface EventHandlerConfig<\n THandler extends EventHandlerDefinition,\n TInput = void,\n TOutput = void,\n> {\n /**\n * Maps the validated event payload to use case input.\n * Both `event` and `ctx` are fully typed based on handler schemas.\n */\n readonly payloadMapper: (\n event: ValidatedEvent<THandler>,\n ctx: TypedEventContext<THandler>,\n ) => TInput;\n\n /** The use case to execute. */\n readonly useCase: { execute(input?: TInput): Promise<TOutput> };\n\n /**\n * Maps the use case output to an EventResult.\n * If omitted, defaults to `{ outcome: 'ack' }`.\n */\n readonly resultMapper?: (output: TOutput) => EventResult;\n\n /** Middleware to run before the handler. */\n readonly middleware?: readonly EventMiddlewareFunction[];\n}\n\n/**\n * Simple handler function that directly returns an EventResult.\n */\nexport type SimpleEventHandlerFn<THandler extends EventHandlerDefinition> = (\n event: ValidatedEvent<THandler>,\n ctx: TypedEventContext<THandler>,\n) => Promise<EventResult> | EventResult;\n\n/**\n * Configuration for a simple handler (no use case).\n */\nexport interface SimpleEventHandlerConfig<THandler extends EventHandlerDefinition> {\n readonly handler: SimpleEventHandlerFn<THandler>;\n readonly middleware?: readonly EventMiddlewareFunction[];\n}\n\n/**\n * Union of all event handler config types.\n * Used internally to store handlers in the builder.\n */\nexport type AnyEventHandlerConfig<\n THandler extends EventHandlerDefinition,\n TInput = unknown,\n TOutput = unknown,\n> = EventHandlerConfig<THandler, TInput, TOutput> | SimpleEventHandlerConfig<THandler>;\n\n/**\n * Type guard to check if config is a simple event handler.\n */\nexport function isSimpleEventHandlerConfig(\n config: AnyEventHandlerConfig<EventHandlerDefinition, unknown, unknown>,\n): config is SimpleEventHandlerConfig<EventHandlerDefinition> {\n return 'handler' in config && typeof config.handler === 'function';\n}\n\n/**\n * Event middleware function type.\n */\nexport type EventMiddlewareFunction = (\n event: RawEvent,\n next: () => Promise<EventResult>,\n) => Promise<EventResult>;\n\n// ============================================================================\n// Server Configuration\n// ============================================================================\n\n/**\n * Configuration mapping handler keys to handler configs.\n */\n// TInput/TOutput are user-defined per handler - any is required for heterogeneous configs\nexport type EventRoutesConfig<T extends EventRouterConfig> = Record<\n EventRouterKeys<T>,\n EventHandlerConfig<any, any, any>\n>;\n\n/**\n * Options for creating event routes.\n */\nexport interface CreateEventRoutesOptions {\n /** Global middleware to run before all handlers. */\n readonly middleware?: readonly EventMiddlewareFunction[];\n\n /**\n * Whether to validate incoming event payloads against handler schemas.\n * When enabled, invalid payloads result in a `dlq` outcome.\n * @default true\n */\n readonly validatePayload?: boolean;\n\n /**\n * Custom error mapper to override default error-to-EventResult mapping.\n * If not provided, uses the built-in `mapErrorToEventResult`.\n */\n readonly errorMapper?: (error: unknown) => EventResult;\n\n /**\n * Allow partial handler configuration (not all handlers need to be wired).\n * @default false\n * @internal Used by builder pattern's buildPartial()\n */\n readonly allowPartial?: boolean;\n}\n\n// ============================================================================\n// Unified Event Input (for messaging adapters)\n// ============================================================================\n\n/**\n * Event input compatible with messaging adapters.\n * This is the output of eventRoutes().build().\n */\nexport interface UnifiedEventInput {\n /** Event type string for routing. */\n readonly eventType: string;\n\n /** Handler function. */\n readonly handler: (rawEvent: RawEvent) => Promise<EventResult>;\n\n /** Handler metadata for documentation. */\n readonly metadata: {\n readonly handlerId?: string;\n readonly summary?: string;\n readonly description?: string;\n readonly tags?: readonly string[];\n readonly deprecated?: boolean;\n };\n}\n","/**\n * @fileoverview Internal implementation for creating event routes with auto-validation.\n *\n * Generates event handlers from an event router definition.\n * Each handler automatically validates incoming event payloads and context\n * against the handler's schemas.\n *\n * @module events/server/create-event-routes\n * @internal\n */\n\nimport type { SchemaAdapter, ValidationIssue } from '../../http/schema/types';\nimport type {\n EventRouterConfig,\n EventRouterDefinition,\n EventHandlerDefinition,\n} from '../handler/types';\nimport { isEventRouterDefinition, collectEventHandlers } from '../handler/types';\nimport { generateHandlerId } from '../handler/utils';\nimport { mapErrorToEventResult } from '../shared/error-mapping';\nimport type { EventResult } from '../shared/types';\nimport type {\n AnyEventHandlerConfig,\n CreateEventRoutesOptions,\n EventMetadata,\n RawEvent,\n UnifiedEventInput,\n ValidatedEvent,\n} from './types';\nimport { isSimpleEventHandlerConfig } from './types';\n\n/**\n * Internal implementation for creating event routes.\n * Used by the builder pattern (eventRoutes).\n *\n * @internal\n */\nexport function createEventRoutesInternal<T extends EventRouterConfig>(\n router: T | EventRouterDefinition<T>,\n handlers: Record<string, AnyEventHandlerConfig<EventHandlerDefinition, unknown, unknown>>,\n options?: CreateEventRoutesOptions,\n): UnifiedEventInput[] {\n const config = isEventRouterDefinition(router) ? router.handlers : router;\n const collectedHandlers = collectEventHandlers(config);\n\n const result: UnifiedEventInput[] = [];\n\n const resolvedOptions: CreateEventRoutesOptions = {\n ...options,\n validatePayload: options?.validatePayload ?? true,\n allowPartial: options?.allowPartial ?? false,\n };\n\n for (const { key, handler: handlerDef } of collectedHandlers) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const handlerConfig = handlers[key] as\n | AnyEventHandlerConfig<EventHandlerDefinition, any, any>\n | undefined;\n\n if (!handlerConfig) {\n if (resolvedOptions.allowPartial) {\n continue;\n }\n throw new Error(\n `Missing handler for event \"${key}\". All event handlers must have a handler configuration.`,\n );\n }\n\n result.push(createEventHandler(key, handlerDef, handlerConfig, resolvedOptions));\n }\n\n return result;\n}\n\n/**\n * Creates a single event handler with validation and error mapping.\n */\nfunction createEventHandler(\n key: string,\n handlerDef: EventHandlerDefinition,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n config: AnyEventHandlerConfig<EventHandlerDefinition, any, any>,\n options: CreateEventRoutesOptions,\n): UnifiedEventInput {\n const middleware = config.middleware ?? [];\n const globalMiddleware = options?.middleware ?? [];\n const allMiddleware = [...globalMiddleware, ...middleware];\n const shouldValidatePayload = options.validatePayload ?? true;\n const errorMapper = options.errorMapper ?? mapErrorToEventResult;\n\n return {\n eventType: handlerDef.eventType,\n metadata: {\n handlerId: generateHandlerId(key),\n summary: handlerDef.docs.summary,\n description: handlerDef.docs.description,\n tags: handlerDef.docs.tags as string[],\n deprecated: handlerDef.docs.deprecated,\n },\n handler: async (rawEvent: RawEvent): Promise<EventResult> => {\n try {\n // Validate context (if schema defined)\n let validatedContext: unknown = rawEvent.metadata;\n if (handlerDef.context) {\n const contextResult = validateContextData(handlerDef, rawEvent.metadata);\n if (!contextResult.success) {\n const errors = contextResult.errors ?? [];\n return {\n outcome: 'dlq',\n reason: `Context validation failed: ${errors.map((e) => `${e.path.join('.')}: ${e.message}`).join('; ')}`,\n };\n }\n validatedContext = contextResult.data;\n }\n\n // Validate payload (if enabled and schema defined)\n let validatedPayload: unknown = rawEvent.payload;\n if (shouldValidatePayload && handlerDef.payload) {\n const payloadResult = validatePayloadData(handlerDef, rawEvent.payload);\n if (!payloadResult.success) {\n const errors = payloadResult.errors ?? [];\n return {\n outcome: 'dlq',\n reason: `Payload validation failed: ${errors.map((e) => `${e.path.join('.')}: ${e.message}`).join('; ')}`,\n };\n }\n validatedPayload = payloadResult.data;\n }\n\n const validatedEvent: ValidatedEventInternal = {\n payload: validatedPayload,\n raw: rawEvent,\n };\n\n // Execute the pipeline\n const executePipeline = async (): Promise<EventResult> => {\n if (isSimpleEventHandlerConfig(config)) {\n return config.handler(\n validatedEvent as unknown as ValidatedEvent<EventHandlerDefinition>,\n validatedContext as EventMetadata,\n );\n } else {\n const { payloadMapper, useCase, resultMapper } = config;\n\n const input = payloadMapper(\n validatedEvent as unknown as ValidatedEvent<EventHandlerDefinition>,\n validatedContext as EventMetadata,\n );\n\n const output = await useCase.execute(input);\n\n return resultMapper ? resultMapper(output) : { outcome: 'ack' };\n }\n };\n\n if (allMiddleware.length === 0) {\n return await executePipeline();\n }\n\n // Build middleware chain\n let index = 0;\n const next = async (): Promise<EventResult> => {\n if (index >= allMiddleware.length) {\n return executePipeline();\n }\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- index bounds checked above\n const mw = allMiddleware[index++]!;\n return mw(rawEvent, next);\n };\n\n return await next();\n } catch (error) {\n return errorMapper(error);\n }\n },\n };\n}\n\n// ============================================================================\n// Validation Helpers\n// ============================================================================\n\ninterface ValidationResultInternal {\n success: boolean;\n errors?: ValidationIssue[];\n data?: unknown;\n}\n\n/**\n * Validates event payload against the handler's payload schema.\n */\nfunction validatePayloadData(\n handler: EventHandlerDefinition,\n payload: unknown,\n): ValidationResultInternal {\n const schema = handler.payload as SchemaAdapter | undefined;\n if (!schema) return { success: true, data: payload };\n\n const result = schema.validate(payload);\n if (result.success) {\n return { success: true, data: result.data };\n }\n\n const errors = result.issues.map((issue) => ({\n ...issue,\n path: ['payload', ...issue.path],\n }));\n\n return { success: false, errors };\n}\n\n/**\n * Validates event metadata against the handler's context schema.\n */\nfunction validateContextData(\n handler: EventHandlerDefinition,\n metadata: EventMetadata,\n): ValidationResultInternal {\n const schema = handler.context as SchemaAdapter | undefined;\n if (!schema) return { success: true, data: metadata };\n\n const result = schema.validate(metadata);\n if (result.success) {\n return { success: true, data: result.data };\n }\n\n const errors = result.issues.map((issue) => ({\n ...issue,\n path: ['context', ...issue.path],\n }));\n\n return { success: false, errors };\n}\n\n/**\n * Internal validated event type with unknown fields.\n * Used inside createEventHandler where specific types are erased.\n */\ninterface ValidatedEventInternal {\n readonly payload: unknown;\n readonly raw: RawEvent;\n}\n","/**\n * @fileoverview Builder pattern for creating type-safe event routes.\n *\n * The `eventRoutes` function returns a builder that provides 100% type inference\n * for all handler parameters — no manual type annotations required.\n *\n * @module events/server/event-routes-builder\n */\n\nimport type {\n EventRouterConfig,\n EventRouterDefinition,\n GetEventHandler,\n EventRouterKeys,\n EventHandlerDefinition,\n} from '../handler/types';\nimport type { EventResult } from '../shared/types';\nimport type {\n AnyEventHandlerConfig,\n CreateEventRoutesOptions,\n EventHandlerConfig,\n EventMiddlewareFunction,\n SimpleEventHandlerConfig,\n SimpleEventHandlerFn,\n TypedEventContext,\n UnifiedEventInput,\n ValidatedEvent,\n} from './types';\nimport { createEventRoutesInternal } from './create-event-routes';\n\n// ============================================================================\n// Builder Types\n// ============================================================================\n\n/**\n * Error type displayed when attempting to build() with missing handlers.\n * The `___missingHandlers` property shows which handlers are missing.\n */\nexport interface MissingHandlersError<TMissing extends string> {\n /**\n * This error indicates that not all event handlers have been wired.\n * Use buildPartial() to build with only the defined handlers,\n * or add handlers for the missing events.\n */\n (options?: never): never;\n /** Event handlers that are missing. */\n readonly ___missingHandlers: TMissing;\n}\n\n/**\n * Handler configuration for the builder pattern.\n */\nexport interface BuilderEventHandlerConfig<\n THandler extends EventHandlerDefinition,\n TInput,\n TOutput,\n> {\n /**\n * Maps the validated event payload to use case input.\n * Both `event` and `ctx` are fully typed based on handler schemas.\n */\n readonly payloadMapper: (\n event: ValidatedEvent<THandler>,\n ctx: TypedEventContext<THandler>,\n ) => TInput;\n\n /** The use case to execute. */\n readonly useCase: { execute(input?: TInput): Promise<TOutput> };\n\n /**\n * Maps the use case output to an EventResult.\n * If omitted, defaults to `{ outcome: 'ack' }`.\n */\n readonly resultMapper?: (output: TOutput) => EventResult;\n\n /** Middleware to run before the handler. */\n readonly middleware?: readonly EventMiddlewareFunction[];\n}\n\n/**\n * Builder interface for creating type-safe event routes.\n *\n * Each `.handle()` call captures the specific handler type and provides\n * full type inference for payloadMapper and useCase.\n *\n * @typeParam T - The event router configuration type\n * @typeParam THandled - Union of handler keys that have been wired (accumulates)\n *\n * @example\n * ```typescript\n * const routes = eventRoutes(ticketEvents)\n * .handleWithUseCase('created', {\n * payloadMapper: (event, ctx) => ({\n * ticketId: event.payload.ticketId, // Fully typed!\n * correlationId: ctx.correlationId, // Fully typed!\n * }),\n * useCase: sendNotificationUseCase,\n * })\n * .handle('assigned', async (event) => {\n * await notifyAssignee(event.payload);\n * return { outcome: 'ack' as const };\n * })\n * .build();\n * ```\n */\nexport interface EventRoutesBuilder<T extends EventRouterConfig, THandled extends string = never> {\n /**\n * Register a simple handler for an event.\n * The handler receives validated event and context, returns EventResult directly.\n */\n handle<K extends Exclude<EventRouterKeys<T>, THandled>>(\n key: K,\n handlerOrConfig:\n | SimpleEventHandlerFn<GetEventHandler<T, K>>\n | SimpleEventHandlerConfig<GetEventHandler<T, K>>,\n ): EventRoutesBuilder<T, THandled | K>;\n\n /**\n * Register a handler using the use case pattern.\n * Follows: payloadMapper → useCase.execute() → resultMapper (or ack)\n */\n handleWithUseCase<K extends Exclude<EventRouterKeys<T>, THandled>, TInput, TOutput>(\n key: K,\n config: BuilderEventHandlerConfig<GetEventHandler<T, K>, TInput, TOutput>,\n ): EventRoutesBuilder<T, THandled | K>;\n\n /**\n * Build the event routes array for messaging adapter registration.\n *\n * This method is only available when ALL handlers have been wired.\n * If some handlers are missing, use `buildPartial()` instead.\n */\n build: [Exclude<EventRouterKeys<T>, THandled>] extends [never]\n ? (options?: CreateEventRoutesOptions) => UnifiedEventInput[]\n : MissingHandlersError<Exclude<EventRouterKeys<T>, THandled>>;\n\n /**\n * Build event routes for only the defined handlers.\n * No compile-time enforcement of completeness.\n */\n buildPartial(options?: CreateEventRoutesOptions): UnifiedEventInput[];\n}\n\n// ============================================================================\n// Builder Implementation\n// ============================================================================\n\n/**\n * Internal builder implementation.\n *\n * Uses an immutable pattern where each handle() call returns a new\n * builder instance with the updated handlers map.\n */\nclass EventRoutesBuilderImpl<T extends EventRouterConfig, THandled extends string = never> {\n private readonly router: T | EventRouterDefinition<T>;\n private readonly handlers: Map<\n string,\n AnyEventHandlerConfig<EventHandlerDefinition, unknown, unknown>\n >;\n\n constructor(\n router: T | EventRouterDefinition<T>,\n handlers?: Map<string, AnyEventHandlerConfig<EventHandlerDefinition, unknown, unknown>>,\n ) {\n this.router = router;\n this.handlers = handlers ?? new Map();\n }\n\n handle<K extends Exclude<EventRouterKeys<T>, THandled>>(\n key: K,\n handlerOrConfig:\n | SimpleEventHandlerFn<GetEventHandler<T, K>>\n | SimpleEventHandlerConfig<GetEventHandler<T, K>>,\n ): EventRoutesBuilder<T, THandled | K> {\n const config: SimpleEventHandlerConfig<EventHandlerDefinition> =\n typeof handlerOrConfig === 'function'\n ? { handler: handlerOrConfig as SimpleEventHandlerFn<EventHandlerDefinition> }\n : (handlerOrConfig as SimpleEventHandlerConfig<EventHandlerDefinition>);\n\n const newHandlers = new Map(this.handlers);\n newHandlers.set(key as string, config);\n\n return new EventRoutesBuilderImpl<T, THandled | K>(\n this.router,\n newHandlers,\n ) as unknown as EventRoutesBuilder<T, THandled | K>;\n }\n\n handleWithUseCase<K extends Exclude<EventRouterKeys<T>, THandled>, TInput, TOutput>(\n key: K,\n config: BuilderEventHandlerConfig<GetEventHandler<T, K>, TInput, TOutput>,\n ): EventRoutesBuilder<T, THandled | K> {\n const newHandlers = new Map(this.handlers);\n newHandlers.set(\n key as string,\n config as EventHandlerConfig<EventHandlerDefinition, unknown, unknown>,\n );\n\n return new EventRoutesBuilderImpl<T, THandled | K>(\n this.router,\n newHandlers,\n ) as unknown as EventRoutesBuilder<T, THandled | K>;\n }\n\n build(options?: CreateEventRoutesOptions): UnifiedEventInput[] {\n return createEventRoutesInternal(this.router, Object.fromEntries(this.handlers), options);\n }\n\n buildPartial(options?: CreateEventRoutesOptions): UnifiedEventInput[] {\n return createEventRoutesInternal(this.router, Object.fromEntries(this.handlers), {\n ...options,\n allowPartial: true,\n });\n }\n}\n\n// ============================================================================\n// Public API\n// ============================================================================\n\n/**\n * Creates a type-safe event routes builder for an event router.\n *\n * The builder pattern provides 100% type inference for all handler parameters:\n * - `event.payload` is typed from the handler's payload schema\n * - `ctx` is typed from the handler's context schema (or EventMetadata)\n * - `output` in resultMapper is typed from the use case\n *\n * @param router - Event router definition or event router config\n * @returns Builder for registering handlers\n *\n * @example Basic usage\n * ```typescript\n * import { eventRoutes } from '@cosmneo/onion-lasagna/events/server';\n * import { ticketEvents } from './router';\n *\n * const routes = eventRoutes(ticketEvents)\n * .handleWithUseCase('created', {\n * payloadMapper: (event, ctx) => ({\n * ticketId: event.payload.ticketId,\n * correlationId: ctx.correlationId,\n * }),\n * useCase: sendNotificationUseCase,\n * })\n * .handle('assigned', async (event) => {\n * await notifyAssignee(event.payload);\n * return { outcome: 'ack' as const };\n * })\n * .build();\n * ```\n */\nexport function eventRoutes<T extends EventRouterConfig>(\n router: T | EventRouterDefinition<T>,\n): EventRoutesBuilder<T, never> {\n return new EventRoutesBuilderImpl(router) as unknown as EventRoutesBuilder<T, never>;\n}\n","/**\n * @fileoverview AsyncAPI specification generation from event router definitions.\n *\n * The `generateAsyncAPI` function creates a complete AsyncAPI 3.0 specification\n * from an event router definition. All handler payload schemas are converted to\n * JSON Schema and included in the specification.\n *\n * @module events/asyncapi/generate\n */\n\nimport type { SchemaAdapter } from '../../http/schema/types';\nimport type { EventRouterConfig, EventRouterDefinition } from '../handler/types';\nimport { isEventRouterDefinition, collectEventHandlers } from '../handler/types';\nimport { generateHandlerId } from '../handler/utils';\nimport type {\n AsyncAPIConfig,\n AsyncAPISpec,\n AsyncAPIChannel,\n AsyncAPIOperation,\n AsyncAPIMessage,\n AsyncAPITag,\n} from './types';\n\n/**\n * Generates an AsyncAPI 3.0 specification from an event router definition.\n *\n * This function walks the event router structure, extracts JSON schemas from\n * all handler payload definitions, and builds a complete AsyncAPI 3.0 specification.\n *\n * @param router - Event router definition or raw config\n * @param config - AsyncAPI configuration (info, servers, tags, etc.)\n * @returns Complete AsyncAPI specification\n *\n * @example\n * ```typescript\n * import { generateAsyncAPI } from '@cosmneo/onion-lasagna/events/asyncapi';\n * import { notificationEventRouter } from './events/router';\n *\n * const spec = generateAsyncAPI(notificationEventRouter, {\n * info: {\n * title: 'My Event API',\n * version: '1.0.0',\n * description: 'Domain events for the application',\n * },\n * });\n *\n * app.get('/asyncapi.json', (c) => c.json(spec));\n * ```\n */\nexport function generateAsyncAPI<T extends EventRouterConfig>(\n router: T | EventRouterDefinition<T>,\n config: AsyncAPIConfig,\n): AsyncAPISpec {\n const routerConfig = isEventRouterDefinition(router) ? router.handlers : router;\n const handlers = collectEventHandlers(routerConfig);\n\n const channels: Record<string, AsyncAPIChannel> = {};\n const operations: Record<string, AsyncAPIOperation> = {};\n const allTags = new Set<string>();\n\n for (const { key, handler } of handlers) {\n const handlerId = generateHandlerId(key);\n const channelId = handler.eventType;\n\n // Build message\n const message = buildMessage(handler.eventType, handler.payload, handler.docs);\n\n // Build channel (group by eventType — multiple handlers may share a channel)\n if (!channels[channelId]) {\n channels[channelId] = {\n address: handler.eventType,\n messages: {},\n };\n }\n const channelMessages = { ...(channels[channelId]!.messages ?? {}) };\n channelMessages[handlerId] = message;\n channels[channelId] = { ...channels[channelId]!, messages: channelMessages };\n\n // Build operation (one per handler)\n const operation: AsyncAPIOperation = {\n action: 'receive',\n channel: { $ref: `#/channels/${channelId}` },\n messages: [{ $ref: `#/channels/${channelId}/messages/${handlerId}` }],\n };\n\n if (handler.docs.summary) {\n (operation as { summary: string }).summary = handler.docs.summary;\n }\n if (handler.docs.description) {\n (operation as { description: string }).description = handler.docs.description;\n }\n if (handler.docs.deprecated) {\n (operation as { deprecated: boolean }).deprecated = true;\n }\n if (handler.docs.tags && handler.docs.tags.length > 0) {\n (operation as { tags: readonly AsyncAPITag[] }).tags = handler.docs.tags.map((t) => ({\n name: t,\n }));\n for (const tag of handler.docs.tags) {\n allTags.add(tag);\n }\n }\n\n operations[handlerId] = operation;\n }\n\n // Merge custom tags with collected tags (AsyncAPI 3.0: tags live inside info)\n const tags: AsyncAPITag[] = config.tags ? [...config.tags] : [];\n for (const tagName of allTags) {\n if (!tags.some((t) => t.name === tagName)) {\n tags.push({ name: tagName });\n }\n }\n\n const info = tags.length > 0 ? { ...config.info, tags } : config.info;\n\n // Build the specification\n const spec: AsyncAPISpec = {\n asyncapi: config.asyncapi ?? '3.0.0',\n info,\n defaultContentType: config.defaultContentType ?? 'application/json',\n channels,\n operations,\n };\n\n if (config.servers && Object.keys(config.servers).length > 0) {\n (spec as { servers: typeof config.servers }).servers = config.servers;\n }\n\n if (config.externalDocs) {\n (spec as { externalDocs: typeof config.externalDocs }).externalDocs = config.externalDocs;\n }\n\n return spec;\n}\n\n/**\n * Builds an AsyncAPI message from a handler definition.\n */\nfunction buildMessage(\n eventType: string,\n payload: unknown,\n docs: {\n readonly summary?: string;\n readonly description?: string;\n readonly tags?: readonly string[];\n readonly deprecated?: boolean;\n },\n): AsyncAPIMessage {\n const message: AsyncAPIMessage = {\n name: eventType,\n };\n\n if (docs.summary) {\n (message as { summary: string }).summary = docs.summary;\n }\n if (docs.description) {\n (message as { description: string }).description = docs.description;\n }\n if (docs.deprecated) {\n (message as { deprecated: boolean }).deprecated = true;\n }\n\n if (payload) {\n const schema = (payload as SchemaAdapter).toJsonSchema();\n (message as { payload: typeof schema }).payload = schema;\n }\n\n return message;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACkFO,SAAS,mBAKd,OACwF;AACxF,QAAM,aAAa;AAAA,IACjB,WAAW,MAAM;AAAA,IACjB,SAAS,MAAM,WAAW;AAAA,IAC1B,SAAS,MAAM,WAAW;AAAA,IAC1B,MAAM;AAAA,MACJ,SAAS,MAAM,MAAM;AAAA,MACrB,aAAa,MAAM,MAAM;AAAA,MACzB,MAAM,MAAM,MAAM;AAAA,MAClB,YAAY,MAAM,MAAM,cAAc;AAAA,IACxC;AAAA,IACA,QAAQ;AAAA,EACV;AAEA,SAAO,OAAO,OAAO,UAAU;AAKjC;;;AC1CO,SAAS,yBAAyB,OAAiD;AACxF,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,eAAe,SAAS,YAAY;AAC5F;AAKO,SAAS,wBAAwB,OAAgD;AACtF,SACE,OAAO,UAAU,YACjB,UAAU,QACV,oBAAoB,SACnB,MAAgC,mBAAmB;AAExD;AA2GO,SAAS,qBACd,QACA,WAAW,IACyC;AACpD,QAAM,WAA+D,CAAC;AAEtE,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,MAAM,GAAG;AACjD,UAAM,UAAU,WAAW,GAAG,QAAQ,IAAI,GAAG,KAAK;AAElD,QAAI,yBAAyB,KAAK,GAAG;AACnC,eAAS,KAAK,EAAE,KAAK,SAAS,SAAS,MAAM,CAAC;AAAA,IAChD,WAAW,wBAAwB,KAAK,GAAG;AACzC,eAAS,KAAK,GAAG,qBAAqB,MAAM,UAAU,OAAO,CAAC;AAAA,IAChE,WAAW,OAAO,UAAU,YAAY,UAAU,MAAM;AACtD,eAAS,KAAK,GAAG,qBAAqB,OAA4B,OAA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AAe,OAAO;AAAA,EAC/E;AAEA,SAAO;AACT;AAKA,SAAS,aACP,WACA,SACA,MAMiB;AACjB,QAAM,UAA2B;AAAA,IAC/B,MAAM;AAAA,EACR;AAEA,MAAI,KAAK,SAAS;AAChB,IAAC,QAAgC,UAAU,KAAK;AAAA,EAClD;AACA,MAAI,KAAK,aAAa;AACpB,IAAC,QAAoC,cAAc,KAAK;AAAA,EAC1D;AACA,MAAI,KAAK,YAAY;AACnB,IAAC,QAAoC,aAAa;AAAA,EACpD;AAEA,MAAI,SAAS;AACX,UAAM,SAAU,QAA0B,aAAa;AACvD,IAAC,QAAuC,UAAU;AAAA,EACpD;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { DefineEventRouterOptions, defineEventHandler, defineEventRouter, generateHandlerId, mergeEventRouters } from './handler/index.cjs';
|
|
2
|
+
export { E as EventHandlerDefinition, a as EventHandlerDocumentation, c as EventRouterConfig, d as EventRouterDefaults, e as EventRouterDefinition, b as EventRouterEntry, f as EventRouterKeys, F as FlattenEventRouter, G as GetEventHandler, h as InferEventContext, g as InferEventPayload, I as InferEventType, k as collectEventHandlers, i as isEventHandlerDefinition, j as isEventRouterDefinition } from '../event-router-definition.type-CP9uTlux.cjs';
|
|
3
|
+
export { BuilderEventHandlerConfig, CreateEventRoutesOptions, EventHandlerConfig, EventMetadata, EventMiddlewareFunction, EventRoutesBuilder, MissingHandlersError, RawEvent, SimpleEventHandlerConfig, SimpleEventHandlerFn, TypedEventContext, UnifiedEventInput, ValidatedEvent, eventRoutes, isSimpleEventHandlerConfig } from './server/index.cjs';
|
|
4
|
+
export { E as EventResult } from '../types-cke61juH.cjs';
|
|
5
|
+
export { mapErrorToEventResult } from './shared/index.cjs';
|
|
6
|
+
export { AsyncAPIChannel, AsyncAPIComponents, AsyncAPIConfig, AsyncAPIExternalDocs, AsyncAPIInfo, AsyncAPIMessage, AsyncAPIOperation, AsyncAPIServer, AsyncAPISpec, AsyncAPITag, generateAsyncAPI } from './asyncapi/index.cjs';
|
|
7
|
+
export { U as UseCasePort } from '../types-afYpL7Ap.cjs';
|
|
8
|
+
import '../http/schema/types.cjs';
|
|
9
|
+
import '../router-definition.type-BElX-Pl4.cjs';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { DefineEventRouterOptions, defineEventHandler, defineEventRouter, generateHandlerId, mergeEventRouters } from './handler/index.js';
|
|
2
|
+
export { E as EventHandlerDefinition, a as EventHandlerDocumentation, c as EventRouterConfig, d as EventRouterDefaults, e as EventRouterDefinition, b as EventRouterEntry, f as EventRouterKeys, F as FlattenEventRouter, G as GetEventHandler, h as InferEventContext, g as InferEventPayload, I as InferEventType, k as collectEventHandlers, i as isEventHandlerDefinition, j as isEventRouterDefinition } from '../event-router-definition.type-D8CG-kjZ.js';
|
|
3
|
+
export { BuilderEventHandlerConfig, CreateEventRoutesOptions, EventHandlerConfig, EventMetadata, EventMiddlewareFunction, EventRoutesBuilder, MissingHandlersError, RawEvent, SimpleEventHandlerConfig, SimpleEventHandlerFn, TypedEventContext, UnifiedEventInput, ValidatedEvent, eventRoutes, isSimpleEventHandlerConfig } from './server/index.js';
|
|
4
|
+
export { E as EventResult } from '../types-cke61juH.js';
|
|
5
|
+
export { mapErrorToEventResult } from './shared/index.js';
|
|
6
|
+
export { AsyncAPIChannel, AsyncAPIComponents, AsyncAPIConfig, AsyncAPIExternalDocs, AsyncAPIInfo, AsyncAPIMessage, AsyncAPIOperation, AsyncAPIServer, AsyncAPISpec, AsyncAPITag, generateAsyncAPI } from './asyncapi/index.js';
|
|
7
|
+
export { U as UseCasePort } from '../types-B6Q1iCgf.js';
|
|
8
|
+
import '../http/schema/types.js';
|
|
9
|
+
import '../router-definition.type-DxG8ncJZ.js';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineEventHandler,
|
|
3
|
+
defineEventRouter,
|
|
4
|
+
mergeEventRouters
|
|
5
|
+
} from "../chunk-36IO4BM7.js";
|
|
6
|
+
import {
|
|
7
|
+
eventRoutes,
|
|
8
|
+
isSimpleEventHandlerConfig
|
|
9
|
+
} from "../chunk-XWKHOLIP.js";
|
|
10
|
+
import "../chunk-RVSBIYY4.js";
|
|
11
|
+
import {
|
|
12
|
+
mapErrorToEventResult
|
|
13
|
+
} from "../chunk-4BVOLXDJ.js";
|
|
14
|
+
import {
|
|
15
|
+
generateAsyncAPI
|
|
16
|
+
} from "../chunk-KJ4JGZOE.js";
|
|
17
|
+
import {
|
|
18
|
+
collectEventHandlers,
|
|
19
|
+
generateHandlerId,
|
|
20
|
+
isEventHandlerDefinition,
|
|
21
|
+
isEventRouterDefinition
|
|
22
|
+
} from "../chunk-CBTICRSM.js";
|
|
23
|
+
import "../chunk-H5TNDC5U.js";
|
|
24
|
+
import "../chunk-2BVCU32G.js";
|
|
25
|
+
import "../chunk-T7S574XQ.js";
|
|
26
|
+
import "../chunk-3BY5RBF2.js";
|
|
27
|
+
import "../chunk-A4JUAZK4.js";
|
|
28
|
+
export {
|
|
29
|
+
collectEventHandlers,
|
|
30
|
+
defineEventHandler,
|
|
31
|
+
defineEventRouter,
|
|
32
|
+
eventRoutes,
|
|
33
|
+
generateAsyncAPI,
|
|
34
|
+
generateHandlerId,
|
|
35
|
+
isEventHandlerDefinition,
|
|
36
|
+
isEventRouterDefinition,
|
|
37
|
+
isSimpleEventHandlerConfig,
|
|
38
|
+
mapErrorToEventResult,
|
|
39
|
+
mergeEventRouters
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/presentation/events/server/index.ts
|
|
21
|
+
var server_exports = {};
|
|
22
|
+
__export(server_exports, {
|
|
23
|
+
eventRoutes: () => eventRoutes,
|
|
24
|
+
isSimpleEventHandlerConfig: () => isSimpleEventHandlerConfig
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(server_exports);
|
|
27
|
+
|
|
28
|
+
// src/presentation/events/handler/types/event-router-definition.type.ts
|
|
29
|
+
function isEventHandlerDefinition(value) {
|
|
30
|
+
return typeof value === "object" && value !== null && "eventType" in value && "_types" in value;
|
|
31
|
+
}
|
|
32
|
+
function isEventRouterDefinition(value) {
|
|
33
|
+
return typeof value === "object" && value !== null && "_isEventRouter" in value && value._isEventRouter === true;
|
|
34
|
+
}
|
|
35
|
+
function collectEventHandlers(config, basePath = "") {
|
|
36
|
+
const handlers = [];
|
|
37
|
+
for (const [key, value] of Object.entries(config)) {
|
|
38
|
+
const fullKey = basePath ? `${basePath}.${key}` : key;
|
|
39
|
+
if (isEventHandlerDefinition(value)) {
|
|
40
|
+
handlers.push({ key: fullKey, handler: value });
|
|
41
|
+
} else if (isEventRouterDefinition(value)) {
|
|
42
|
+
handlers.push(...collectEventHandlers(value.handlers, fullKey));
|
|
43
|
+
} else if (typeof value === "object" && value !== null) {
|
|
44
|
+
handlers.push(...collectEventHandlers(value, fullKey));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return handlers;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// src/presentation/events/handler/utils.ts
|
|
51
|
+
function generateHandlerId(key) {
|
|
52
|
+
return key.replace(/\.(\w)/g, (_, char) => char.toUpperCase());
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/presentation/http/shared/error-mapping.ts
|
|
56
|
+
function isErrorType(error, typeName) {
|
|
57
|
+
if (!error || typeof error !== "object") return false;
|
|
58
|
+
const constructor = Object.prototype.hasOwnProperty.call(error, "constructor") ? error.constructor : Object.getPrototypeOf(error)?.constructor;
|
|
59
|
+
if (!constructor) return false;
|
|
60
|
+
const name = constructor.name;
|
|
61
|
+
return name === typeName || name === `_${typeName}`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/presentation/events/shared/error-mapping.ts
|
|
65
|
+
var DLQ_ERROR_TYPES = [
|
|
66
|
+
"ObjectValidationError",
|
|
67
|
+
"InvalidRequestError",
|
|
68
|
+
"UseCaseError",
|
|
69
|
+
"DomainError",
|
|
70
|
+
"UnprocessableError",
|
|
71
|
+
"AccessDeniedError",
|
|
72
|
+
"ForbiddenError",
|
|
73
|
+
"UnauthorizedError",
|
|
74
|
+
"InvariantViolationError"
|
|
75
|
+
];
|
|
76
|
+
var RETRY_ERROR_TYPES = [
|
|
77
|
+
"NotFoundError",
|
|
78
|
+
"ConflictError",
|
|
79
|
+
"InfraError",
|
|
80
|
+
"DbError",
|
|
81
|
+
"NetworkError",
|
|
82
|
+
"TimeoutError",
|
|
83
|
+
"ExternalServiceError",
|
|
84
|
+
"PersistenceError"
|
|
85
|
+
];
|
|
86
|
+
function mapErrorToEventResult(error) {
|
|
87
|
+
for (const typeName of DLQ_ERROR_TYPES) {
|
|
88
|
+
if (isErrorType(error, typeName)) {
|
|
89
|
+
return {
|
|
90
|
+
outcome: "dlq",
|
|
91
|
+
reason: error.message
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
for (const typeName of RETRY_ERROR_TYPES) {
|
|
96
|
+
if (isErrorType(error, typeName)) {
|
|
97
|
+
return {
|
|
98
|
+
outcome: "retry",
|
|
99
|
+
reason: error.message
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const message = error instanceof Error ? error.message : "Unknown error occurred during event processing";
|
|
104
|
+
return {
|
|
105
|
+
outcome: "retry",
|
|
106
|
+
reason: message
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// src/presentation/events/server/types.ts
|
|
111
|
+
function isSimpleEventHandlerConfig(config) {
|
|
112
|
+
return "handler" in config && typeof config.handler === "function";
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// src/presentation/events/server/create-event-routes.ts
|
|
116
|
+
function createEventRoutesInternal(router, handlers, options) {
|
|
117
|
+
const config = isEventRouterDefinition(router) ? router.handlers : router;
|
|
118
|
+
const collectedHandlers = collectEventHandlers(config);
|
|
119
|
+
const result = [];
|
|
120
|
+
const resolvedOptions = {
|
|
121
|
+
...options,
|
|
122
|
+
validatePayload: options?.validatePayload ?? true,
|
|
123
|
+
allowPartial: options?.allowPartial ?? false
|
|
124
|
+
};
|
|
125
|
+
for (const { key, handler: handlerDef } of collectedHandlers) {
|
|
126
|
+
const handlerConfig = handlers[key];
|
|
127
|
+
if (!handlerConfig) {
|
|
128
|
+
if (resolvedOptions.allowPartial) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
throw new Error(
|
|
132
|
+
`Missing handler for event "${key}". All event handlers must have a handler configuration.`
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
result.push(createEventHandler(key, handlerDef, handlerConfig, resolvedOptions));
|
|
136
|
+
}
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
139
|
+
function createEventHandler(key, handlerDef, config, options) {
|
|
140
|
+
const middleware = config.middleware ?? [];
|
|
141
|
+
const globalMiddleware = options?.middleware ?? [];
|
|
142
|
+
const allMiddleware = [...globalMiddleware, ...middleware];
|
|
143
|
+
const shouldValidatePayload = options.validatePayload ?? true;
|
|
144
|
+
const errorMapper = options.errorMapper ?? mapErrorToEventResult;
|
|
145
|
+
return {
|
|
146
|
+
eventType: handlerDef.eventType,
|
|
147
|
+
metadata: {
|
|
148
|
+
handlerId: generateHandlerId(key),
|
|
149
|
+
summary: handlerDef.docs.summary,
|
|
150
|
+
description: handlerDef.docs.description,
|
|
151
|
+
tags: handlerDef.docs.tags,
|
|
152
|
+
deprecated: handlerDef.docs.deprecated
|
|
153
|
+
},
|
|
154
|
+
handler: async (rawEvent) => {
|
|
155
|
+
try {
|
|
156
|
+
let validatedContext = rawEvent.metadata;
|
|
157
|
+
if (handlerDef.context) {
|
|
158
|
+
const contextResult = validateContextData(handlerDef, rawEvent.metadata);
|
|
159
|
+
if (!contextResult.success) {
|
|
160
|
+
const errors = contextResult.errors ?? [];
|
|
161
|
+
return {
|
|
162
|
+
outcome: "dlq",
|
|
163
|
+
reason: `Context validation failed: ${errors.map((e) => `${e.path.join(".")}: ${e.message}`).join("; ")}`
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
validatedContext = contextResult.data;
|
|
167
|
+
}
|
|
168
|
+
let validatedPayload = rawEvent.payload;
|
|
169
|
+
if (shouldValidatePayload && handlerDef.payload) {
|
|
170
|
+
const payloadResult = validatePayloadData(handlerDef, rawEvent.payload);
|
|
171
|
+
if (!payloadResult.success) {
|
|
172
|
+
const errors = payloadResult.errors ?? [];
|
|
173
|
+
return {
|
|
174
|
+
outcome: "dlq",
|
|
175
|
+
reason: `Payload validation failed: ${errors.map((e) => `${e.path.join(".")}: ${e.message}`).join("; ")}`
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
validatedPayload = payloadResult.data;
|
|
179
|
+
}
|
|
180
|
+
const validatedEvent = {
|
|
181
|
+
payload: validatedPayload,
|
|
182
|
+
raw: rawEvent
|
|
183
|
+
};
|
|
184
|
+
const executePipeline = async () => {
|
|
185
|
+
if (isSimpleEventHandlerConfig(config)) {
|
|
186
|
+
return config.handler(
|
|
187
|
+
validatedEvent,
|
|
188
|
+
validatedContext
|
|
189
|
+
);
|
|
190
|
+
} else {
|
|
191
|
+
const { payloadMapper, useCase, resultMapper } = config;
|
|
192
|
+
const input = payloadMapper(
|
|
193
|
+
validatedEvent,
|
|
194
|
+
validatedContext
|
|
195
|
+
);
|
|
196
|
+
const output = await useCase.execute(input);
|
|
197
|
+
return resultMapper ? resultMapper(output) : { outcome: "ack" };
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
if (allMiddleware.length === 0) {
|
|
201
|
+
return await executePipeline();
|
|
202
|
+
}
|
|
203
|
+
let index = 0;
|
|
204
|
+
const next = async () => {
|
|
205
|
+
if (index >= allMiddleware.length) {
|
|
206
|
+
return executePipeline();
|
|
207
|
+
}
|
|
208
|
+
const mw = allMiddleware[index++];
|
|
209
|
+
return mw(rawEvent, next);
|
|
210
|
+
};
|
|
211
|
+
return await next();
|
|
212
|
+
} catch (error) {
|
|
213
|
+
return errorMapper(error);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
function validatePayloadData(handler, payload) {
|
|
219
|
+
const schema = handler.payload;
|
|
220
|
+
if (!schema) return { success: true, data: payload };
|
|
221
|
+
const result = schema.validate(payload);
|
|
222
|
+
if (result.success) {
|
|
223
|
+
return { success: true, data: result.data };
|
|
224
|
+
}
|
|
225
|
+
const errors = result.issues.map((issue) => ({
|
|
226
|
+
...issue,
|
|
227
|
+
path: ["payload", ...issue.path]
|
|
228
|
+
}));
|
|
229
|
+
return { success: false, errors };
|
|
230
|
+
}
|
|
231
|
+
function validateContextData(handler, metadata) {
|
|
232
|
+
const schema = handler.context;
|
|
233
|
+
if (!schema) return { success: true, data: metadata };
|
|
234
|
+
const result = schema.validate(metadata);
|
|
235
|
+
if (result.success) {
|
|
236
|
+
return { success: true, data: result.data };
|
|
237
|
+
}
|
|
238
|
+
const errors = result.issues.map((issue) => ({
|
|
239
|
+
...issue,
|
|
240
|
+
path: ["context", ...issue.path]
|
|
241
|
+
}));
|
|
242
|
+
return { success: false, errors };
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// src/presentation/events/server/event-routes-builder.ts
|
|
246
|
+
var EventRoutesBuilderImpl = class _EventRoutesBuilderImpl {
|
|
247
|
+
router;
|
|
248
|
+
handlers;
|
|
249
|
+
constructor(router, handlers) {
|
|
250
|
+
this.router = router;
|
|
251
|
+
this.handlers = handlers ?? /* @__PURE__ */ new Map();
|
|
252
|
+
}
|
|
253
|
+
handle(key, handlerOrConfig) {
|
|
254
|
+
const config = typeof handlerOrConfig === "function" ? { handler: handlerOrConfig } : handlerOrConfig;
|
|
255
|
+
const newHandlers = new Map(this.handlers);
|
|
256
|
+
newHandlers.set(key, config);
|
|
257
|
+
return new _EventRoutesBuilderImpl(
|
|
258
|
+
this.router,
|
|
259
|
+
newHandlers
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
handleWithUseCase(key, config) {
|
|
263
|
+
const newHandlers = new Map(this.handlers);
|
|
264
|
+
newHandlers.set(
|
|
265
|
+
key,
|
|
266
|
+
config
|
|
267
|
+
);
|
|
268
|
+
return new _EventRoutesBuilderImpl(
|
|
269
|
+
this.router,
|
|
270
|
+
newHandlers
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
build(options) {
|
|
274
|
+
return createEventRoutesInternal(this.router, Object.fromEntries(this.handlers), options);
|
|
275
|
+
}
|
|
276
|
+
buildPartial(options) {
|
|
277
|
+
return createEventRoutesInternal(this.router, Object.fromEntries(this.handlers), {
|
|
278
|
+
...options,
|
|
279
|
+
allowPartial: true
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
function eventRoutes(router) {
|
|
284
|
+
return new EventRoutesBuilderImpl(router);
|
|
285
|
+
}
|
|
286
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
287
|
+
0 && (module.exports = {
|
|
288
|
+
eventRoutes,
|
|
289
|
+
isSimpleEventHandlerConfig
|
|
290
|
+
});
|
|
291
|
+
//# sourceMappingURL=index.cjs.map
|