@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.
Files changed (93) hide show
  1. package/dist/chunk-36IO4BM7.js +113 -0
  2. package/dist/chunk-36IO4BM7.js.map +1 -0
  3. package/dist/chunk-4BVOLXDJ.js +54 -0
  4. package/dist/chunk-4BVOLXDJ.js.map +1 -0
  5. package/dist/{chunk-GGSAAZPM.js → chunk-AUMHMWDD.js} +19 -20
  6. package/dist/chunk-AUMHMWDD.js.map +1 -0
  7. package/dist/chunk-CBTICRSM.js +34 -0
  8. package/dist/chunk-CBTICRSM.js.map +1 -0
  9. package/dist/chunk-H5TNDC5U.js +138 -0
  10. package/dist/chunk-H5TNDC5U.js.map +1 -0
  11. package/dist/chunk-KJ4JGZOE.js +96 -0
  12. package/dist/chunk-KJ4JGZOE.js.map +1 -0
  13. package/dist/chunk-MF2JDREK.js +168 -0
  14. package/dist/chunk-MF2JDREK.js.map +1 -0
  15. package/dist/chunk-RVSBIYY4.js +1 -0
  16. package/dist/chunk-RVSBIYY4.js.map +1 -0
  17. package/dist/{chunk-PUVAB3JX.js → chunk-XIRJ73IO.js} +38 -36
  18. package/dist/chunk-XIRJ73IO.js.map +1 -0
  19. package/dist/{chunk-DS7TE6KZ.js → chunk-XP6PLTV2.js} +11 -3
  20. package/dist/chunk-XP6PLTV2.js.map +1 -0
  21. package/dist/chunk-XWKHOLIP.js +191 -0
  22. package/dist/chunk-XWKHOLIP.js.map +1 -0
  23. package/dist/event-router-definition.type-CP9uTlux.d.cts +150 -0
  24. package/dist/event-router-definition.type-D8CG-kjZ.d.ts +150 -0
  25. package/dist/events/asyncapi/index.cjs +143 -0
  26. package/dist/events/asyncapi/index.cjs.map +1 -0
  27. package/dist/events/asyncapi/index.d.cts +184 -0
  28. package/dist/events/asyncapi/index.d.ts +184 -0
  29. package/dist/events/asyncapi/index.js +8 -0
  30. package/dist/events/asyncapi/index.js.map +1 -0
  31. package/dist/events/handler/index.cjs +171 -0
  32. package/dist/events/handler/index.cjs.map +1 -0
  33. package/dist/events/handler/index.d.cts +153 -0
  34. package/dist/events/handler/index.d.ts +153 -0
  35. package/dist/events/handler/index.js +21 -0
  36. package/dist/events/handler/index.js.map +1 -0
  37. package/dist/events/index.cjs +497 -0
  38. package/dist/events/index.cjs.map +1 -0
  39. package/dist/events/index.d.cts +9 -0
  40. package/dist/events/index.d.ts +9 -0
  41. package/dist/events/index.js +41 -0
  42. package/dist/events/index.js.map +1 -0
  43. package/dist/events/server/index.cjs +291 -0
  44. package/dist/events/server/index.cjs.map +1 -0
  45. package/dist/events/server/index.d.cts +281 -0
  46. package/dist/events/server/index.d.ts +281 -0
  47. package/dist/events/server/index.js +16 -0
  48. package/dist/events/server/index.js.map +1 -0
  49. package/dist/events/shared/index.cjs +85 -0
  50. package/dist/events/shared/index.cjs.map +1 -0
  51. package/dist/events/shared/index.d.cts +35 -0
  52. package/dist/events/shared/index.d.ts +35 -0
  53. package/dist/events/shared/index.js +13 -0
  54. package/dist/events/shared/index.js.map +1 -0
  55. package/dist/global.js +3 -3
  56. package/dist/http/index.cjs +563 -93
  57. package/dist/http/index.cjs.map +1 -1
  58. package/dist/http/index.d.cts +5 -3
  59. package/dist/http/index.d.ts +5 -3
  60. package/dist/http/index.js +30 -12
  61. package/dist/http/openapi/index.cjs +43 -35
  62. package/dist/http/openapi/index.cjs.map +1 -1
  63. package/dist/http/openapi/index.d.cts +8 -34
  64. package/dist/http/openapi/index.d.ts +8 -34
  65. package/dist/http/openapi/index.js +2 -2
  66. package/dist/http/route/index.cjs +106 -9
  67. package/dist/http/route/index.cjs.map +1 -1
  68. package/dist/http/route/index.d.cts +133 -227
  69. package/dist/http/route/index.d.ts +133 -227
  70. package/dist/http/route/index.js +5 -2
  71. package/dist/http/server/index.cjs +24 -19
  72. package/dist/http/server/index.cjs.map +1 -1
  73. package/dist/http/server/index.d.cts +4 -261
  74. package/dist/http/server/index.d.ts +4 -261
  75. package/dist/http/server/index.js +2 -2
  76. package/dist/http/shared/index.cjs.map +1 -1
  77. package/dist/http/shared/index.d.cts +10 -14
  78. package/dist/http/shared/index.d.ts +10 -14
  79. package/dist/http/shared/index.js +11 -127
  80. package/dist/http/shared/index.js.map +1 -1
  81. package/dist/index.js +6 -6
  82. package/dist/{router-definition.type-ynBhT16T.d.cts → router-definition.type-BElX-Pl4.d.cts} +169 -256
  83. package/dist/{router-definition.type-DORVlLNk.d.ts → router-definition.type-DxG8ncJZ.d.ts} +169 -256
  84. package/dist/types-B6Q1iCgf.d.ts +262 -0
  85. package/dist/types-afYpL7Ap.d.cts +262 -0
  86. package/dist/types-cke61juH.d.cts +42 -0
  87. package/dist/types-cke61juH.d.ts +42 -0
  88. package/package.json +35 -2
  89. package/dist/chunk-BZULBF4N.js +0 -82
  90. package/dist/chunk-BZULBF4N.js.map +0 -1
  91. package/dist/chunk-DS7TE6KZ.js.map +0 -1
  92. package/dist/chunk-GGSAAZPM.js.map +0 -1
  93. package/dist/chunk-PUVAB3JX.js.map +0 -1
@@ -0,0 +1,184 @@
1
+ import { c as EventRouterConfig, e as EventRouterDefinition } from '../../event-router-definition.type-D8CG-kjZ.js';
2
+ import { JsonSchema } from '../../http/schema/types.js';
3
+
4
+ /**
5
+ * @fileoverview AsyncAPI types for specification generation.
6
+ *
7
+ * @module events/asyncapi/types
8
+ */
9
+
10
+ /**
11
+ * AsyncAPI specification configuration.
12
+ */
13
+ interface AsyncAPIConfig {
14
+ /**
15
+ * AsyncAPI specification version.
16
+ * @default '3.0.0'
17
+ */
18
+ readonly asyncapi?: '3.0.0';
19
+ /**
20
+ * API information.
21
+ */
22
+ readonly info: AsyncAPIInfo;
23
+ /**
24
+ * Server configurations (e.g., message broker details).
25
+ */
26
+ readonly servers?: Record<string, AsyncAPIServer>;
27
+ /**
28
+ * Default content type for messages.
29
+ * @default 'application/json'
30
+ */
31
+ readonly defaultContentType?: string;
32
+ /**
33
+ * Custom tags with descriptions.
34
+ */
35
+ readonly tags?: readonly AsyncAPITag[];
36
+ /**
37
+ * External documentation.
38
+ */
39
+ readonly externalDocs?: AsyncAPIExternalDocs;
40
+ }
41
+ /**
42
+ * API information.
43
+ */
44
+ interface AsyncAPIInfo {
45
+ readonly title: string;
46
+ readonly version: string;
47
+ readonly description?: string;
48
+ readonly termsOfService?: string;
49
+ readonly contact?: {
50
+ readonly name?: string;
51
+ readonly url?: string;
52
+ readonly email?: string;
53
+ };
54
+ readonly license?: {
55
+ readonly name: string;
56
+ readonly url?: string;
57
+ };
58
+ readonly tags?: readonly AsyncAPITag[];
59
+ }
60
+ /**
61
+ * Server configuration (message broker).
62
+ */
63
+ interface AsyncAPIServer {
64
+ readonly host: string;
65
+ readonly protocol: string;
66
+ readonly protocolVersion?: string;
67
+ readonly pathname?: string;
68
+ readonly description?: string;
69
+ readonly tags?: readonly AsyncAPITag[];
70
+ }
71
+ /**
72
+ * Tag definition.
73
+ */
74
+ interface AsyncAPITag {
75
+ readonly name: string;
76
+ readonly description?: string;
77
+ readonly externalDocs?: AsyncAPIExternalDocs;
78
+ }
79
+ /**
80
+ * External documentation.
81
+ */
82
+ interface AsyncAPIExternalDocs {
83
+ readonly url: string;
84
+ readonly description?: string;
85
+ }
86
+ /**
87
+ * Complete AsyncAPI 3.0 specification.
88
+ */
89
+ interface AsyncAPISpec {
90
+ readonly asyncapi: string;
91
+ readonly info: AsyncAPIInfo;
92
+ readonly servers?: Record<string, AsyncAPIServer>;
93
+ readonly defaultContentType?: string;
94
+ readonly channels?: Record<string, AsyncAPIChannel>;
95
+ readonly operations?: Record<string, AsyncAPIOperation>;
96
+ readonly components?: AsyncAPIComponents;
97
+ readonly externalDocs?: AsyncAPIExternalDocs;
98
+ }
99
+ /**
100
+ * Channel definition (represents an event type).
101
+ */
102
+ interface AsyncAPIChannel {
103
+ readonly address?: string;
104
+ readonly messages?: Record<string, AsyncAPIMessage>;
105
+ readonly description?: string;
106
+ readonly tags?: readonly AsyncAPITag[];
107
+ }
108
+ /**
109
+ * Message definition (event payload).
110
+ */
111
+ interface AsyncAPIMessage {
112
+ readonly name?: string;
113
+ readonly title?: string;
114
+ readonly summary?: string;
115
+ readonly description?: string;
116
+ readonly contentType?: string;
117
+ readonly payload?: JsonSchema;
118
+ readonly tags?: readonly AsyncAPITag[];
119
+ readonly deprecated?: boolean;
120
+ }
121
+ /**
122
+ * Operation definition (subscribe action).
123
+ */
124
+ interface AsyncAPIOperation {
125
+ readonly action: 'send' | 'receive';
126
+ readonly channel: {
127
+ readonly $ref: string;
128
+ };
129
+ readonly summary?: string;
130
+ readonly description?: string;
131
+ readonly tags?: readonly AsyncAPITag[];
132
+ readonly deprecated?: boolean;
133
+ readonly messages?: readonly {
134
+ readonly $ref: string;
135
+ }[];
136
+ }
137
+ /**
138
+ * Components object for reusable definitions.
139
+ */
140
+ interface AsyncAPIComponents {
141
+ readonly schemas?: Record<string, JsonSchema>;
142
+ readonly messages?: Record<string, AsyncAPIMessage>;
143
+ readonly channels?: Record<string, AsyncAPIChannel>;
144
+ }
145
+
146
+ /**
147
+ * @fileoverview AsyncAPI specification generation from event router definitions.
148
+ *
149
+ * The `generateAsyncAPI` function creates a complete AsyncAPI 3.0 specification
150
+ * from an event router definition. All handler payload schemas are converted to
151
+ * JSON Schema and included in the specification.
152
+ *
153
+ * @module events/asyncapi/generate
154
+ */
155
+
156
+ /**
157
+ * Generates an AsyncAPI 3.0 specification from an event router definition.
158
+ *
159
+ * This function walks the event router structure, extracts JSON schemas from
160
+ * all handler payload definitions, and builds a complete AsyncAPI 3.0 specification.
161
+ *
162
+ * @param router - Event router definition or raw config
163
+ * @param config - AsyncAPI configuration (info, servers, tags, etc.)
164
+ * @returns Complete AsyncAPI specification
165
+ *
166
+ * @example
167
+ * ```typescript
168
+ * import { generateAsyncAPI } from '@cosmneo/onion-lasagna/events/asyncapi';
169
+ * import { notificationEventRouter } from './events/router';
170
+ *
171
+ * const spec = generateAsyncAPI(notificationEventRouter, {
172
+ * info: {
173
+ * title: 'My Event API',
174
+ * version: '1.0.0',
175
+ * description: 'Domain events for the application',
176
+ * },
177
+ * });
178
+ *
179
+ * app.get('/asyncapi.json', (c) => c.json(spec));
180
+ * ```
181
+ */
182
+ declare function generateAsyncAPI<T extends EventRouterConfig>(router: T | EventRouterDefinition<T>, config: AsyncAPIConfig): AsyncAPISpec;
183
+
184
+ export { type AsyncAPIChannel, type AsyncAPIComponents, type AsyncAPIConfig, type AsyncAPIExternalDocs, type AsyncAPIInfo, type AsyncAPIMessage, type AsyncAPIOperation, type AsyncAPIServer, type AsyncAPISpec, type AsyncAPITag, generateAsyncAPI };
@@ -0,0 +1,8 @@
1
+ import {
2
+ generateAsyncAPI
3
+ } from "../../chunk-KJ4JGZOE.js";
4
+ import "../../chunk-CBTICRSM.js";
5
+ export {
6
+ generateAsyncAPI
7
+ };
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,171 @@
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/handler/index.ts
21
+ var handler_exports = {};
22
+ __export(handler_exports, {
23
+ collectEventHandlers: () => collectEventHandlers,
24
+ defineEventHandler: () => defineEventHandler,
25
+ defineEventRouter: () => defineEventRouter,
26
+ generateHandlerId: () => generateHandlerId,
27
+ isEventHandlerDefinition: () => isEventHandlerDefinition,
28
+ isEventRouterDefinition: () => isEventRouterDefinition,
29
+ mergeEventRouters: () => mergeEventRouters
30
+ });
31
+ module.exports = __toCommonJS(handler_exports);
32
+
33
+ // src/presentation/events/handler/define-event-handler.ts
34
+ function defineEventHandler(input) {
35
+ const definition = {
36
+ eventType: input.eventType,
37
+ payload: input.payload ?? void 0,
38
+ context: input.context ?? void 0,
39
+ docs: {
40
+ summary: input.docs?.summary,
41
+ description: input.docs?.description,
42
+ tags: input.docs?.tags,
43
+ deprecated: input.docs?.deprecated ?? false
44
+ },
45
+ _types: void 0
46
+ };
47
+ return Object.freeze(definition);
48
+ }
49
+
50
+ // src/presentation/events/handler/types/event-router-definition.type.ts
51
+ function isEventHandlerDefinition(value) {
52
+ return typeof value === "object" && value !== null && "eventType" in value && "_types" in value;
53
+ }
54
+ function isEventRouterDefinition(value) {
55
+ return typeof value === "object" && value !== null && "_isEventRouter" in value && value._isEventRouter === true;
56
+ }
57
+ function collectEventHandlers(config, basePath = "") {
58
+ const handlers = [];
59
+ for (const [key, value] of Object.entries(config)) {
60
+ const fullKey = basePath ? `${basePath}.${key}` : key;
61
+ if (isEventHandlerDefinition(value)) {
62
+ handlers.push({ key: fullKey, handler: value });
63
+ } else if (isEventRouterDefinition(value)) {
64
+ handlers.push(...collectEventHandlers(value.handlers, fullKey));
65
+ } else if (typeof value === "object" && value !== null) {
66
+ handlers.push(...collectEventHandlers(value, fullKey));
67
+ }
68
+ }
69
+ return handlers;
70
+ }
71
+
72
+ // src/presentation/events/handler/define-event-router.ts
73
+ function defineEventRouter(handlers, options) {
74
+ const defaults = options?.defaults;
75
+ const processedHandlers = defaults?.context || defaults?.tags ? applyEventRouterDefaults(handlers, defaults) : handlers;
76
+ const definition = {
77
+ handlers: processedHandlers,
78
+ defaults,
79
+ _isEventRouter: true
80
+ };
81
+ return deepFreeze(definition);
82
+ }
83
+ function applyEventRouterDefaults(handlers, defaults) {
84
+ const result = {};
85
+ for (const [key, value] of Object.entries(handlers)) {
86
+ if (isEventHandlerDefinition(value)) {
87
+ result[key] = applyDefaultsToEventHandler(value, defaults);
88
+ } else if (isEventRouterDefinition(value)) {
89
+ result[key] = {
90
+ ...value,
91
+ handlers: applyEventRouterDefaults(value.handlers, defaults)
92
+ };
93
+ } else if (typeof value === "object" && value !== null) {
94
+ result[key] = applyEventRouterDefaults(value, defaults);
95
+ }
96
+ }
97
+ return result;
98
+ }
99
+ function applyDefaultsToEventHandler(handler, defaults) {
100
+ const needsContext = defaults.context && !handler.context;
101
+ const needsTags = defaults.tags && defaults.tags.length > 0;
102
+ if (!needsContext && !needsTags) return handler;
103
+ return Object.freeze({
104
+ ...handler,
105
+ context: handler.context ?? defaults.context ?? void 0,
106
+ docs: {
107
+ ...handler.docs,
108
+ tags: mergeTags(defaults.tags, handler.docs.tags)
109
+ }
110
+ });
111
+ }
112
+ function mergeTags(routerTags, handlerTags) {
113
+ if (!routerTags || routerTags.length === 0) return handlerTags;
114
+ if (!handlerTags || handlerTags.length === 0) return routerTags;
115
+ const merged = [...routerTags];
116
+ for (const tag of handlerTags) {
117
+ if (!merged.includes(tag)) {
118
+ merged.push(tag);
119
+ }
120
+ }
121
+ return merged;
122
+ }
123
+ function deepFreeze(obj) {
124
+ const propNames = Object.getOwnPropertyNames(obj);
125
+ for (const name of propNames) {
126
+ const value = obj[name];
127
+ if (value && typeof value === "object" && !Object.isFrozen(value)) {
128
+ deepFreeze(value);
129
+ }
130
+ }
131
+ return Object.freeze(obj);
132
+ }
133
+ function extractHandlers(input) {
134
+ return isEventRouterDefinition(input) ? input.handlers : input;
135
+ }
136
+ function isSubRouter(value) {
137
+ return typeof value === "object" && value !== null && !isEventHandlerDefinition(value) && !isEventRouterDefinition(value);
138
+ }
139
+ function deepMergeConfigs(a, b) {
140
+ const result = { ...a };
141
+ for (const key of Object.keys(b)) {
142
+ const aVal = result[key];
143
+ const bVal = b[key];
144
+ if (isSubRouter(aVal) && isSubRouter(bVal)) {
145
+ result[key] = deepMergeConfigs(aVal, bVal);
146
+ } else {
147
+ result[key] = bVal;
148
+ }
149
+ }
150
+ return result;
151
+ }
152
+ function mergeEventRouters(...routers) {
153
+ const merged = routers.map(extractHandlers).reduce(deepMergeConfigs);
154
+ return defineEventRouter(merged);
155
+ }
156
+
157
+ // src/presentation/events/handler/utils.ts
158
+ function generateHandlerId(key) {
159
+ return key.replace(/\.(\w)/g, (_, char) => char.toUpperCase());
160
+ }
161
+ // Annotate the CommonJS export names for ESM import in node:
162
+ 0 && (module.exports = {
163
+ collectEventHandlers,
164
+ defineEventHandler,
165
+ defineEventRouter,
166
+ generateHandlerId,
167
+ isEventHandlerDefinition,
168
+ isEventRouterDefinition,
169
+ mergeEventRouters
170
+ });
171
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/presentation/events/handler/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"],"sourcesContent":["export { defineEventHandler } from './define-event-handler';\nexport { defineEventRouter, mergeEventRouters } from './define-event-router';\nexport type { DefineEventRouterOptions } from './define-event-router';\nexport { generateHandlerId } from './utils';\nexport * from './types';\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"],"mappings":"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","names":[]}
@@ -0,0 +1,153 @@
1
+ import { SchemaAdapter, InferOutput } from '../../http/schema/types.cjs';
2
+ import { E as EventHandlerDefinition, c as EventRouterConfig, d as EventRouterDefaults, e as EventRouterDefinition, D as DeepMergeTwo, l as DeepMergeAll } from '../../event-router-definition.type-CP9uTlux.cjs';
3
+ export { a as EventHandlerDocumentation, 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';
4
+
5
+ /**
6
+ * @fileoverview Factory function for creating event handler definitions.
7
+ *
8
+ * The `defineEventHandler` function is the main entry point for defining
9
+ * event handlers. It mirrors `defineRoute` from the HTTP layer but is
10
+ * tailored for asynchronous event processing.
11
+ *
12
+ * @module events/handler/define-event-handler
13
+ */
14
+
15
+ /**
16
+ * Input for defineEventHandler.
17
+ *
18
+ * @example Basic handler with payload schema
19
+ * ```typescript
20
+ * defineEventHandler({
21
+ * eventType: 'ticket.created',
22
+ * payload: zodSchema(z.object({ ticketId: z.string() })),
23
+ * docs: { summary: 'Handle ticket creation', tags: ['ticket'] },
24
+ * })
25
+ * ```
26
+ *
27
+ * @example With context schema
28
+ * ```typescript
29
+ * defineEventHandler({
30
+ * eventType: 'order.shipped',
31
+ * payload: zodSchema(orderShippedSchema),
32
+ * context: zodSchema(eventMetadataSchema),
33
+ * })
34
+ * ```
35
+ */
36
+ interface DefineEventHandlerInput<TEventType extends string, TPayload extends SchemaAdapter | undefined = undefined, TContext extends SchemaAdapter | undefined = undefined> {
37
+ /** Event type string used for routing (e.g., 'ticket.created'). */
38
+ readonly eventType: TEventType;
39
+ /** Payload validation schema. */
40
+ readonly payload?: TPayload;
41
+ /** Context validation schema (validates event metadata). */
42
+ readonly context?: TContext;
43
+ /** Handler documentation. */
44
+ readonly docs?: {
45
+ readonly summary?: string;
46
+ readonly description?: string;
47
+ readonly tags?: readonly string[];
48
+ readonly deprecated?: boolean;
49
+ };
50
+ }
51
+ type ResolvePayload<T> = T extends SchemaAdapter ? InferOutput<T> : undefined;
52
+ type ResolveContext<T> = T extends SchemaAdapter ? InferOutput<T> : undefined;
53
+ /**
54
+ * Creates an event handler definition from the provided configuration.
55
+ *
56
+ * This is the main entry point for defining event handlers. The resulting
57
+ * definition can be used for type-safe handler registration, payload
58
+ * validation, and documentation generation.
59
+ *
60
+ * @param input - Event handler configuration with optional schemas
61
+ * @returns A frozen EventHandlerDefinition object with full type information
62
+ */
63
+ declare function defineEventHandler<TEventType extends string, TPayload extends SchemaAdapter | undefined = undefined, TContext extends SchemaAdapter | undefined = undefined>(input: DefineEventHandlerInput<TEventType, TPayload, TContext>): EventHandlerDefinition<TEventType, ResolvePayload<TPayload>, ResolveContext<TContext>>;
64
+
65
+ /**
66
+ * @fileoverview Factory function for creating event router definitions.
67
+ *
68
+ * The `defineEventRouter` function groups event handlers into a hierarchical
69
+ * structure with optional router-level defaults for context and tags.
70
+ *
71
+ * @module events/handler/define-event-router
72
+ */
73
+
74
+ /**
75
+ * Options for event router definition.
76
+ */
77
+ interface DefineEventRouterOptions {
78
+ /**
79
+ * Default values applied to all child handlers.
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * defineEventRouter({
84
+ * created: onTicketCreated,
85
+ * assigned: onTicketAssigned,
86
+ * }, {
87
+ * defaults: {
88
+ * context: zodSchema(eventMetadataSchema),
89
+ * tags: ['ticket'],
90
+ * },
91
+ * })
92
+ * ```
93
+ */
94
+ readonly defaults?: EventRouterDefaults;
95
+ }
96
+ /**
97
+ * Creates an event router definition from a configuration object.
98
+ *
99
+ * @param handlers - Object containing event handlers and nested routers
100
+ * @param options - Optional router configuration
101
+ * @returns A frozen EventRouterDefinition object
102
+ *
103
+ * @example Basic router
104
+ * ```typescript
105
+ * const ticketEvents = defineEventRouter({
106
+ * created: onTicketCreated,
107
+ * assigned: onTicketAssigned,
108
+ * transferred: onTicketTransferred,
109
+ * });
110
+ * ```
111
+ *
112
+ * @example Nested router
113
+ * ```typescript
114
+ * const events = defineEventRouter({
115
+ * ticket: {
116
+ * created: onTicketCreated,
117
+ * assigned: onTicketAssigned,
118
+ * },
119
+ * ecosystem: {
120
+ * memberAdded: onMemberAdded,
121
+ * },
122
+ * });
123
+ * ```
124
+ */
125
+ declare function defineEventRouter<T extends EventRouterConfig>(handlers: T, options?: DefineEventRouterOptions): EventRouterDefinition<T>;
126
+ type EventRouterInput<T extends EventRouterConfig> = T | EventRouterDefinition<T>;
127
+ declare function mergeEventRouters<T1 extends EventRouterConfig, T2 extends EventRouterConfig>(r1: EventRouterInput<T1>, r2: EventRouterInput<T2>): EventRouterDefinition<DeepMergeTwo<T1, T2>>;
128
+ declare function mergeEventRouters<T1 extends EventRouterConfig, T2 extends EventRouterConfig, T3 extends EventRouterConfig>(r1: EventRouterInput<T1>, r2: EventRouterInput<T2>, r3: EventRouterInput<T3>): EventRouterDefinition<DeepMergeAll<[T1, T2, T3]>>;
129
+ declare function mergeEventRouters<T1 extends EventRouterConfig, T2 extends EventRouterConfig, T3 extends EventRouterConfig, T4 extends EventRouterConfig>(r1: EventRouterInput<T1>, r2: EventRouterInput<T2>, r3: EventRouterInput<T3>, r4: EventRouterInput<T4>): EventRouterDefinition<DeepMergeAll<[T1, T2, T3, T4]>>;
130
+ declare function mergeEventRouters<T1 extends EventRouterConfig, T2 extends EventRouterConfig, T3 extends EventRouterConfig, T4 extends EventRouterConfig, T5 extends EventRouterConfig>(r1: EventRouterInput<T1>, r2: EventRouterInput<T2>, r3: EventRouterInput<T3>, r4: EventRouterInput<T4>, r5: EventRouterInput<T5>): EventRouterDefinition<DeepMergeAll<[T1, T2, T3, T4, T5]>>;
131
+ declare function mergeEventRouters<T1 extends EventRouterConfig, T2 extends EventRouterConfig, T3 extends EventRouterConfig, T4 extends EventRouterConfig, T5 extends EventRouterConfig, T6 extends EventRouterConfig>(r1: EventRouterInput<T1>, r2: EventRouterInput<T2>, r3: EventRouterInput<T3>, r4: EventRouterInput<T4>, r5: EventRouterInput<T5>, r6: EventRouterInput<T6>): EventRouterDefinition<DeepMergeAll<[T1, T2, T3, T4, T5, T6]>>;
132
+ declare function mergeEventRouters<T1 extends EventRouterConfig, T2 extends EventRouterConfig, T3 extends EventRouterConfig, T4 extends EventRouterConfig, T5 extends EventRouterConfig, T6 extends EventRouterConfig, T7 extends EventRouterConfig>(r1: EventRouterInput<T1>, r2: EventRouterInput<T2>, r3: EventRouterInput<T3>, r4: EventRouterInput<T4>, r5: EventRouterInput<T5>, r6: EventRouterInput<T6>, r7: EventRouterInput<T7>): EventRouterDefinition<DeepMergeAll<[T1, T2, T3, T4, T5, T6, T7]>>;
133
+ declare function mergeEventRouters<T1 extends EventRouterConfig, T2 extends EventRouterConfig, T3 extends EventRouterConfig, T4 extends EventRouterConfig, T5 extends EventRouterConfig, T6 extends EventRouterConfig, T7 extends EventRouterConfig, T8 extends EventRouterConfig>(r1: EventRouterInput<T1>, r2: EventRouterInput<T2>, r3: EventRouterInput<T3>, r4: EventRouterInput<T4>, r5: EventRouterInput<T5>, r6: EventRouterInput<T6>, r7: EventRouterInput<T7>, r8: EventRouterInput<T8>): EventRouterDefinition<DeepMergeAll<[T1, T2, T3, T4, T5, T6, T7, T8]>>;
134
+ declare function mergeEventRouters(...routers: EventRouterInput<EventRouterConfig>[]): EventRouterDefinition<EventRouterConfig>;
135
+
136
+ /**
137
+ * @fileoverview Utility functions for event handler routing.
138
+ *
139
+ * @module events/handler/utils
140
+ */
141
+ /**
142
+ * Generates a handler ID from a dotted key path.
143
+ *
144
+ * Converts dot-separated keys to camelCase:
145
+ * - `"ticket.created"` → `"ticketCreated"`
146
+ * - `"ecosystem.member.added"` → `"ecosystemMemberAdded"`
147
+ *
148
+ * @param key - The dotted key path
149
+ * @returns A camelCase handler ID
150
+ */
151
+ declare function generateHandlerId(key: string): string;
152
+
153
+ export { DeepMergeAll, DeepMergeTwo, type DefineEventRouterOptions, EventHandlerDefinition, EventRouterConfig, EventRouterDefaults, EventRouterDefinition, defineEventHandler, defineEventRouter, generateHandlerId, mergeEventRouters };