@celerity-sdk/core 0.4.0 → 0.6.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/index.cjs CHANGED
@@ -37,7 +37,7 @@ __export(index_exports, {
37
37
  BadGatewayException: () => BadGatewayException,
38
38
  BadRequestException: () => BadRequestException,
39
39
  Body: () => Body,
40
- BucketEventType: () => import_types3.BucketEventType,
40
+ BucketEventType: () => import_types9.BucketEventType,
41
41
  CONSUMER_HANDLER_METADATA: () => CONSUMER_HANDLER_METADATA,
42
42
  CONSUMER_METADATA: () => CONSUMER_METADATA,
43
43
  CONTROLLER_METADATA: () => CONTROLLER_METADATA,
@@ -51,7 +51,7 @@ __export(index_exports, {
51
51
  Container: () => Container,
52
52
  Controller: () => Controller,
53
53
  Cookies: () => Cookies,
54
- DatastoreEventType: () => import_types3.DatastoreEventType,
54
+ DatastoreEventType: () => import_types9.DatastoreEventType,
55
55
  Delete: () => Delete,
56
56
  EventInput: () => EventInput,
57
57
  EventType: () => EventType,
@@ -114,7 +114,7 @@ __export(index_exports, {
114
114
  ServerlessApplication: () => ServerlessApplication,
115
115
  ServiceUnavailableException: () => ServiceUnavailableException,
116
116
  SetMetadata: () => SetMetadata,
117
- SourceType: () => import_types3.SourceType,
117
+ SourceType: () => import_types9.SourceType,
118
118
  TestingApplication: () => TestingApplication,
119
119
  Token: () => Token,
120
120
  TooManyRequestsException: () => TooManyRequestsException,
@@ -129,7 +129,7 @@ __export(index_exports, {
129
129
  WEBSOCKET_CONTROLLER_METADATA: () => WEBSOCKET_CONTROLLER_METADATA,
130
130
  WEBSOCKET_EVENT_METADATA: () => WEBSOCKET_EVENT_METADATA,
131
131
  WebSocketController: () => WebSocketController,
132
- WebSocketSender: () => import_types2.WebSocketSender,
132
+ WebSocketSender: () => import_types8.WebSocketSender,
133
133
  bootstrap: () => bootstrap,
134
134
  bootstrapForRuntime: () => bootstrapForRuntime,
135
135
  buildModuleGraph: () => buildModuleGraph,
@@ -558,10 +558,10 @@ __name(EventType, "EventType");
558
558
 
559
559
  // src/decorators/consumer.ts
560
560
  var import_reflect_metadata12 = require("reflect-metadata");
561
- function Consumer(sourceId) {
561
+ function Consumer(source) {
562
562
  return (target) => {
563
563
  const meta = {};
564
- if (sourceId !== void 0) meta.sourceId = sourceId;
564
+ if (source !== void 0) meta.source = source;
565
565
  Reflect.defineMetadata(CONSUMER_METADATA, meta, target);
566
566
  Reflect.defineMetadata(INJECTABLE_METADATA, true, target);
567
567
  };
@@ -620,11 +620,11 @@ function parseScheduleArg(arg) {
620
620
  return isScheduleExpression(arg) ? {
621
621
  schedule: arg
622
622
  } : {
623
- scheduleId: arg
623
+ source: arg
624
624
  };
625
625
  }
626
626
  const meta = {};
627
- if (arg.scheduleId !== void 0) meta.scheduleId = arg.scheduleId;
627
+ if (arg.source !== void 0) meta.source = arg.source;
628
628
  if (arg.schedule !== void 0) meta.schedule = arg.schedule;
629
629
  return meta;
630
630
  }
@@ -1015,6 +1015,10 @@ __name(runLayerPipeline, "runLayerPipeline");
1015
1015
  // src/layers/system.ts
1016
1016
  var import_config = require("@celerity-sdk/config");
1017
1017
  var RESOURCE_LAYER_MAP = {
1018
+ datastore: {
1019
+ pkg: "@celerity-sdk/datastore",
1020
+ className: "DatastoreLayer"
1021
+ },
1018
1022
  bucket: {
1019
1023
  pkg: "@celerity-sdk/bucket",
1020
1024
  className: "ObjectStorageLayer"
@@ -1023,9 +1027,17 @@ var RESOURCE_LAYER_MAP = {
1023
1027
  pkg: "@celerity-sdk/queue",
1024
1028
  className: "QueueLayer"
1025
1029
  },
1030
+ topic: {
1031
+ pkg: "@celerity-sdk/topic",
1032
+ className: "TopicLayer"
1033
+ },
1026
1034
  cache: {
1027
1035
  pkg: "@celerity-sdk/cache",
1028
1036
  className: "CacheLayer"
1037
+ },
1038
+ sqlDatabase: {
1039
+ pkg: "@celerity-sdk/sql-database",
1040
+ className: "SqlDatabaseLayer"
1029
1041
  }
1030
1042
  };
1031
1043
  async function createDefaultSystemLayers() {
@@ -1503,6 +1515,7 @@ __name(matchRoute, "matchRoute");
1503
1515
  // src/bootstrap/module-graph.ts
1504
1516
  var import_reflect_metadata20 = require("reflect-metadata");
1505
1517
  var import_debug4 = __toESM(require("debug"), 1);
1518
+ var import_common2 = require("@celerity-sdk/common");
1506
1519
  var debug4 = (0, import_debug4.default)("celerity:core:bootstrap");
1507
1520
  function buildModuleGraph(rootModule) {
1508
1521
  const graph = /* @__PURE__ */ new Map();
@@ -1531,7 +1544,8 @@ function buildModuleGraph(rootModule) {
1531
1544
  controllers: [],
1532
1545
  functionHandlers: [],
1533
1546
  guards: [],
1534
- providers: []
1547
+ providers: [],
1548
+ layers: []
1535
1549
  });
1536
1550
  return;
1537
1551
  }
@@ -1573,7 +1587,8 @@ function buildModuleGraph(rootModule) {
1573
1587
  controllers,
1574
1588
  functionHandlers: metadata.functionHandlers ?? [],
1575
1589
  guards,
1576
- providers
1590
+ providers,
1591
+ layers: metadata.layers ?? []
1577
1592
  });
1578
1593
  }
1579
1594
  __name(walk, "walk");
@@ -1691,6 +1706,7 @@ function checkDependencies(consumer, depTokens, visibleTokens, moduleClass, grap
1691
1706
  checkDependencies(dep, adoptedDeps, visibleTokens, moduleClass, graph, container, diagnostics);
1692
1707
  continue;
1693
1708
  }
1709
+ if ((0, import_common2.isResourceLayerToken)(dep)) continue;
1694
1710
  diagnostics.push({
1695
1711
  type: "missing_dependency",
1696
1712
  message: `${tokenToString(consumer)} in ${moduleClass.name} requires ${tokenToString(dep)} \u2014 no provider registered. Ensure the module providing it is included in your module's "imports" array, or register a provider for it directly.`
@@ -1711,15 +1727,15 @@ __name(findTokenOwner, "findTokenOwner");
1711
1727
  // src/handlers/scanners/http.ts
1712
1728
  var import_reflect_metadata21 = require("reflect-metadata");
1713
1729
  var import_debug5 = __toESM(require("debug"), 1);
1714
- var import_common2 = require("@celerity-sdk/common");
1730
+ var import_common3 = require("@celerity-sdk/common");
1715
1731
  var debug5 = (0, import_debug5.default)("celerity:core:scanner:http");
1716
1732
  async function scanHttpHandlers(graph, container, registry) {
1717
1733
  for (const [, node] of graph) {
1718
1734
  for (const controllerClass of node.controllers) {
1719
- await scanClassHandler(controllerClass, container, registry);
1735
+ await scanClassHandler(controllerClass, container, registry, node.layers);
1720
1736
  }
1721
1737
  for (const fnHandler of node.functionHandlers) {
1722
- scanFunctionHandler(fnHandler, registry);
1738
+ scanFunctionHandler(fnHandler, registry, node.layers);
1723
1739
  }
1724
1740
  }
1725
1741
  }
@@ -1743,11 +1759,10 @@ async function scanModule(moduleClass, container, registry) {
1743
1759
  await scanHttpGuards(graph, container, registry);
1744
1760
  }
1745
1761
  __name(scanModule, "scanModule");
1746
- async function scanClassHandler(controllerClass, container, registry) {
1762
+ async function scanClassHandler(controllerClass, container, registry, moduleLayers) {
1747
1763
  const controllerMeta = Reflect.getOwnMetadata(CONTROLLER_METADATA, controllerClass);
1748
1764
  if (!controllerMeta) return;
1749
- const instance = await container.resolve(controllerClass);
1750
- const prototype = Object.getPrototypeOf(instance);
1765
+ const prototype = controllerClass.prototype;
1751
1766
  const methods = Object.getOwnPropertyNames(prototype).filter((name) => name !== "constructor");
1752
1767
  const classProtectedBy = Reflect.getOwnMetadata(GUARD_PROTECTEDBY_METADATA, controllerClass) ?? [];
1753
1768
  const classLayers = Reflect.getOwnMetadata(LAYER_METADATA, controllerClass) ?? [];
@@ -1756,7 +1771,7 @@ async function scanClassHandler(controllerClass, container, registry) {
1756
1771
  const method = Reflect.getOwnMetadata(HTTP_METHOD_METADATA, prototype, methodName);
1757
1772
  if (!method) continue;
1758
1773
  const routePath = Reflect.getOwnMetadata(ROUTE_PATH_METADATA, prototype, methodName) ?? "/";
1759
- const fullPath = (0, import_common2.joinHandlerPath)(controllerMeta.prefix ?? "", routePath);
1774
+ const fullPath = (0, import_common3.joinHandlerPath)(controllerMeta.prefix ?? "", routePath);
1760
1775
  const methodProtectedBy = Reflect.getOwnMetadata(GUARD_PROTECTEDBY_METADATA, prototype, methodName) ?? [];
1761
1776
  const methodLayers = Reflect.getOwnMetadata(LAYER_METADATA, prototype, methodName) ?? [];
1762
1777
  const paramMetadata = Reflect.getOwnMetadata(PARAM_METADATA, prototype, methodName) ?? [];
@@ -1765,6 +1780,7 @@ async function scanClassHandler(controllerClass, container, registry) {
1765
1780
  const descriptor = Object.getOwnPropertyDescriptor(prototype, methodName);
1766
1781
  if (!descriptor?.value || typeof descriptor.value !== "function") continue;
1767
1782
  const layers = [
1783
+ ...moduleLayers,
1768
1784
  ...classLayers,
1769
1785
  ...methodLayers
1770
1786
  ];
@@ -1789,15 +1805,16 @@ async function scanClassHandler(controllerClass, container, registry) {
1789
1805
  ...methodCustomMetadata
1790
1806
  },
1791
1807
  handlerFn: descriptor.value,
1792
- handlerInstance: instance
1808
+ controllerClass
1793
1809
  });
1794
1810
  }
1795
1811
  }
1796
1812
  __name(scanClassHandler, "scanClassHandler");
1797
- function scanFunctionHandler(definition, registry) {
1813
+ function scanFunctionHandler(definition, registry, moduleLayers) {
1798
1814
  if (definition.type !== "http") return;
1799
1815
  const meta = definition.metadata;
1800
1816
  const layers = [
1817
+ ...moduleLayers,
1801
1818
  ...meta.layers ?? []
1802
1819
  ];
1803
1820
  if (meta.schema) {
@@ -1830,8 +1847,7 @@ __name(scanFunctionHandler, "scanFunctionHandler");
1830
1847
  async function scanClassGuard(guardClass, container, registry) {
1831
1848
  const guardName = Reflect.getOwnMetadata(GUARD_CUSTOM_METADATA, guardClass);
1832
1849
  if (!guardName) return;
1833
- const instance = await container.resolve(guardClass);
1834
- const prototype = Object.getPrototypeOf(instance);
1850
+ const prototype = guardClass.prototype;
1835
1851
  const descriptor = Object.getOwnPropertyDescriptor(prototype, "check");
1836
1852
  if (!descriptor?.value || typeof descriptor.value !== "function") {
1837
1853
  debug5("scanClassGuard: %s has no check() method, skipping", guardClass.name);
@@ -1843,7 +1859,7 @@ async function scanClassGuard(guardClass, container, registry) {
1843
1859
  registry.registerGuard({
1844
1860
  name: guardName,
1845
1861
  handlerFn: descriptor.value,
1846
- handlerInstance: instance,
1862
+ guardClass,
1847
1863
  paramMetadata,
1848
1864
  customMetadata
1849
1865
  });
@@ -1935,19 +1951,18 @@ var debug6 = (0, import_debug6.default)("celerity:core:scanner:websocket");
1935
1951
  async function scanWebSocketHandlers(graph, container, registry) {
1936
1952
  for (const [, node] of graph) {
1937
1953
  for (const controllerClass of node.controllers) {
1938
- await scanClassHandler2(controllerClass, container, registry);
1954
+ await scanClassHandler2(controllerClass, container, registry, node.layers);
1939
1955
  }
1940
1956
  for (const fnHandler of node.functionHandlers) {
1941
- scanFunctionHandler2(fnHandler, registry);
1957
+ scanFunctionHandler2(fnHandler, registry, node.layers);
1942
1958
  }
1943
1959
  }
1944
1960
  }
1945
1961
  __name(scanWebSocketHandlers, "scanWebSocketHandlers");
1946
- async function scanClassHandler2(controllerClass, container, registry) {
1962
+ async function scanClassHandler2(controllerClass, container, registry, moduleLayers) {
1947
1963
  const isWsController = Reflect.getOwnMetadata(WEBSOCKET_CONTROLLER_METADATA, controllerClass);
1948
1964
  if (!isWsController) return;
1949
- const instance = await container.resolve(controllerClass);
1950
- const prototype = Object.getPrototypeOf(instance);
1965
+ const prototype = controllerClass.prototype;
1951
1966
  const methods = Object.getOwnPropertyNames(prototype).filter((name) => name !== "constructor");
1952
1967
  const classProtectedBy = Reflect.getOwnMetadata(GUARD_PROTECTEDBY_METADATA, controllerClass) ?? [];
1953
1968
  const classLayers = Reflect.getOwnMetadata(LAYER_METADATA, controllerClass) ?? [];
@@ -1963,6 +1978,7 @@ async function scanClassHandler2(controllerClass, container, registry) {
1963
1978
  if (!descriptor?.value || typeof descriptor.value !== "function") continue;
1964
1979
  debug6("scanClassHandler: %s %s (%s.%s)", eventMeta.eventType, eventMeta.route, controllerClass.name, methodName);
1965
1980
  const layers = [
1981
+ ...moduleLayers,
1966
1982
  ...classLayers,
1967
1983
  ...methodLayers
1968
1984
  ];
@@ -1984,15 +2000,16 @@ async function scanClassHandler2(controllerClass, container, registry) {
1984
2000
  ...methodCustomMetadata
1985
2001
  },
1986
2002
  handlerFn: descriptor.value,
1987
- handlerInstance: instance
2003
+ controllerClass
1988
2004
  });
1989
2005
  }
1990
2006
  }
1991
2007
  __name(scanClassHandler2, "scanClassHandler");
1992
- function scanFunctionHandler2(definition, registry) {
2008
+ function scanFunctionHandler2(definition, registry, moduleLayers) {
1993
2009
  if (definition.type !== "websocket") return;
1994
2010
  const meta = definition.metadata;
1995
2011
  const layers = [
2012
+ ...moduleLayers,
1996
2013
  ...meta.layers ?? []
1997
2014
  ];
1998
2015
  if (meta.schema) {
@@ -2024,19 +2041,18 @@ var debug7 = (0, import_debug7.default)("celerity:core:scanner:consumer");
2024
2041
  async function scanConsumerHandlers(graph, container, registry) {
2025
2042
  for (const [, node] of graph) {
2026
2043
  for (const controllerClass of node.controllers) {
2027
- await scanClassHandler3(controllerClass, container, registry);
2044
+ await scanClassHandler3(controllerClass, container, registry, node.layers);
2028
2045
  }
2029
2046
  for (const fnHandler of node.functionHandlers) {
2030
- scanFunctionHandler3(fnHandler, registry);
2047
+ scanFunctionHandler3(fnHandler, registry, node.layers);
2031
2048
  }
2032
2049
  }
2033
2050
  }
2034
2051
  __name(scanConsumerHandlers, "scanConsumerHandlers");
2035
- async function scanClassHandler3(controllerClass, container, registry) {
2052
+ async function scanClassHandler3(controllerClass, container, registry, moduleLayers) {
2036
2053
  const consumerMeta = Reflect.getOwnMetadata(CONSUMER_METADATA, controllerClass);
2037
2054
  if (!consumerMeta) return;
2038
- const instance = await container.resolve(controllerClass);
2039
- const prototype = Object.getPrototypeOf(instance);
2055
+ const prototype = controllerClass.prototype;
2040
2056
  const methods = Object.getOwnPropertyNames(prototype).filter((name) => name !== "constructor");
2041
2057
  const classLayers = Reflect.getOwnMetadata(LAYER_METADATA, controllerClass) ?? [];
2042
2058
  const classCustomMetadata = Reflect.getOwnMetadata(CUSTOM_METADATA, controllerClass) ?? {};
@@ -2048,8 +2064,9 @@ async function scanClassHandler3(controllerClass, container, registry) {
2048
2064
  const methodCustomMetadata = Reflect.getOwnMetadata(CUSTOM_METADATA, prototype, methodName) ?? {};
2049
2065
  const descriptor = Object.getOwnPropertyDescriptor(prototype, methodName);
2050
2066
  if (!descriptor?.value || typeof descriptor.value !== "function") continue;
2051
- const handlerTag = handlerMeta.route ?? methodName;
2067
+ const handlerTag = consumerMeta.source ? `${consumerMeta.source}::${methodName}` : methodName;
2052
2068
  const layers = [
2069
+ ...moduleLayers,
2053
2070
  ...classLayers,
2054
2071
  ...methodLayers
2055
2072
  ];
@@ -2070,16 +2087,17 @@ async function scanClassHandler3(controllerClass, container, registry) {
2070
2087
  ...methodCustomMetadata
2071
2088
  },
2072
2089
  handlerFn: descriptor.value,
2073
- handlerInstance: instance
2090
+ controllerClass
2074
2091
  });
2075
2092
  }
2076
2093
  }
2077
2094
  __name(scanClassHandler3, "scanClassHandler");
2078
- function scanFunctionHandler3(definition, registry) {
2095
+ function scanFunctionHandler3(definition, registry, moduleLayers) {
2079
2096
  if (definition.type !== "consumer") return;
2080
2097
  const meta = definition.metadata;
2081
- const handlerTag = meta.route ?? definition.id ?? "default";
2098
+ const handlerTag = definition.id ?? "default";
2082
2099
  const layers = [
2100
+ ...moduleLayers,
2083
2101
  ...meta.layers ?? []
2084
2102
  ];
2085
2103
  if (meta.messageSchema) {
@@ -2109,17 +2127,16 @@ var debug8 = (0, import_debug8.default)("celerity:core:scanner:schedule");
2109
2127
  async function scanScheduleHandlers(graph, container, registry) {
2110
2128
  for (const [, node] of graph) {
2111
2129
  for (const controllerClass of node.controllers) {
2112
- await scanClassHandler4(controllerClass, container, registry);
2130
+ await scanClassHandler4(controllerClass, container, registry, node.layers);
2113
2131
  }
2114
2132
  for (const fnHandler of node.functionHandlers) {
2115
- scanFunctionHandler4(fnHandler, registry);
2133
+ scanFunctionHandler4(fnHandler, registry, node.layers);
2116
2134
  }
2117
2135
  }
2118
2136
  }
2119
2137
  __name(scanScheduleHandlers, "scanScheduleHandlers");
2120
- async function scanClassHandler4(controllerClass, container, registry) {
2121
- const instance = await container.resolve(controllerClass);
2122
- const prototype = Object.getPrototypeOf(instance);
2138
+ async function scanClassHandler4(controllerClass, container, registry, moduleLayers) {
2139
+ const prototype = controllerClass.prototype;
2123
2140
  const methods = Object.getOwnPropertyNames(prototype).filter((name) => name !== "constructor");
2124
2141
  const classLayers = Reflect.getOwnMetadata(LAYER_METADATA, controllerClass) ?? [];
2125
2142
  const classCustomMetadata = Reflect.getOwnMetadata(CUSTOM_METADATA, controllerClass) ?? {};
@@ -2131,8 +2148,9 @@ async function scanClassHandler4(controllerClass, container, registry) {
2131
2148
  const methodCustomMetadata = Reflect.getOwnMetadata(CUSTOM_METADATA, prototype, methodName) ?? {};
2132
2149
  const descriptor = Object.getOwnPropertyDescriptor(prototype, methodName);
2133
2150
  if (!descriptor?.value || typeof descriptor.value !== "function") continue;
2134
- const handlerTag = handlerMeta.scheduleId ?? methodName;
2151
+ const handlerTag = handlerMeta.source ? `${handlerMeta.source}::${methodName}` : methodName;
2135
2152
  const layers = [
2153
+ ...moduleLayers,
2136
2154
  ...classLayers,
2137
2155
  ...methodLayers
2138
2156
  ];
@@ -2154,21 +2172,22 @@ async function scanClassHandler4(controllerClass, container, registry) {
2154
2172
  ...handlerMeta.schedule ? {
2155
2173
  schedule: handlerMeta.schedule
2156
2174
  } : {},
2157
- ...handlerMeta.scheduleId ? {
2158
- scheduleId: handlerMeta.scheduleId
2175
+ ...handlerMeta.source ? {
2176
+ source: handlerMeta.source
2159
2177
  } : {}
2160
2178
  },
2161
2179
  handlerFn: descriptor.value,
2162
- handlerInstance: instance
2180
+ controllerClass
2163
2181
  });
2164
2182
  }
2165
2183
  }
2166
2184
  __name(scanClassHandler4, "scanClassHandler");
2167
- function scanFunctionHandler4(definition, registry) {
2185
+ function scanFunctionHandler4(definition, registry, moduleLayers) {
2168
2186
  if (definition.type !== "schedule") return;
2169
2187
  const meta = definition.metadata;
2170
- const handlerTag = meta.scheduleId ?? definition.id ?? "default";
2188
+ const handlerTag = meta.source ?? definition.id ?? "default";
2171
2189
  const layers = [
2190
+ ...moduleLayers,
2172
2191
  ...meta.layers ?? []
2173
2192
  ];
2174
2193
  if (meta.schema) {
@@ -2180,7 +2199,7 @@ function scanFunctionHandler4(definition, registry) {
2180
2199
  ...meta.customMetadata ?? {}
2181
2200
  };
2182
2201
  if (meta.schedule) customMetadata.schedule = meta.schedule;
2183
- if (meta.scheduleId) customMetadata.scheduleId = meta.scheduleId;
2202
+ if (meta.source) customMetadata.source = meta.source;
2184
2203
  debug8("scanFunctionHandler: tag=%s", handlerTag);
2185
2204
  registry.register({
2186
2205
  type: "schedule",
@@ -2203,17 +2222,16 @@ var debug9 = (0, import_debug9.default)("celerity:core:scanner:custom");
2203
2222
  async function scanCustomHandlers(graph, container, registry) {
2204
2223
  for (const [, node] of graph) {
2205
2224
  for (const controllerClass of node.controllers) {
2206
- await scanClassHandler5(controllerClass, container, registry);
2225
+ await scanClassHandler5(controllerClass, container, registry, node.layers);
2207
2226
  }
2208
2227
  for (const fnHandler of node.functionHandlers) {
2209
- scanFunctionHandler5(fnHandler, registry);
2228
+ scanFunctionHandler5(fnHandler, registry, node.layers);
2210
2229
  }
2211
2230
  }
2212
2231
  }
2213
2232
  __name(scanCustomHandlers, "scanCustomHandlers");
2214
- async function scanClassHandler5(controllerClass, container, registry) {
2215
- const instance = await container.resolve(controllerClass);
2216
- const prototype = Object.getPrototypeOf(instance);
2233
+ async function scanClassHandler5(controllerClass, container, registry, moduleLayers) {
2234
+ const prototype = controllerClass.prototype;
2217
2235
  const methods = Object.getOwnPropertyNames(prototype).filter((name) => name !== "constructor");
2218
2236
  const classLayers = Reflect.getOwnMetadata(LAYER_METADATA, controllerClass) ?? [];
2219
2237
  const classCustomMetadata = Reflect.getOwnMetadata(CUSTOM_METADATA, controllerClass) ?? {};
@@ -2226,6 +2244,7 @@ async function scanClassHandler5(controllerClass, container, registry) {
2226
2244
  const descriptor = Object.getOwnPropertyDescriptor(prototype, methodName);
2227
2245
  if (!descriptor?.value || typeof descriptor.value !== "function") continue;
2228
2246
  const layers = [
2247
+ ...moduleLayers,
2229
2248
  ...classLayers,
2230
2249
  ...methodLayers
2231
2250
  ];
@@ -2246,16 +2265,17 @@ async function scanClassHandler5(controllerClass, container, registry) {
2246
2265
  ...methodCustomMetadata
2247
2266
  },
2248
2267
  handlerFn: descriptor.value,
2249
- handlerInstance: instance
2268
+ controllerClass
2250
2269
  });
2251
2270
  }
2252
2271
  }
2253
2272
  __name(scanClassHandler5, "scanClassHandler");
2254
- function scanFunctionHandler5(definition, registry) {
2273
+ function scanFunctionHandler5(definition, registry, moduleLayers) {
2255
2274
  if (definition.type !== "custom") return;
2256
2275
  const meta = definition.metadata;
2257
2276
  const name = meta.name ?? definition.id ?? "default";
2258
2277
  const layers = [
2278
+ ...moduleLayers,
2259
2279
  ...meta.layers ?? []
2260
2280
  ];
2261
2281
  if (meta.schema) {
@@ -2452,6 +2472,28 @@ function buildHttpContext(request, metadata, container, logger) {
2452
2472
  }
2453
2473
  __name(buildHttpContext, "buildHttpContext");
2454
2474
 
2475
+ // src/handlers/types.ts
2476
+ async function resolveHandlerInstance(handler, container) {
2477
+ if (handler.handlerInstance) return handler.handlerInstance;
2478
+ if (!handler.controllerClass) {
2479
+ throw new Error("Handler has no controllerClass for deferred resolution");
2480
+ }
2481
+ const instance = await container.resolve(handler.controllerClass);
2482
+ handler.handlerInstance = instance;
2483
+ return instance;
2484
+ }
2485
+ __name(resolveHandlerInstance, "resolveHandlerInstance");
2486
+ async function resolveGuardInstance(guard, container) {
2487
+ if (guard.handlerInstance) return guard.handlerInstance;
2488
+ if (!guard.guardClass) {
2489
+ throw new Error("Guard has no guardClass for deferred resolution");
2490
+ }
2491
+ const instance = await container.resolve(guard.guardClass);
2492
+ guard.handlerInstance = instance;
2493
+ return instance;
2494
+ }
2495
+ __name(resolveGuardInstance, "resolveGuardInstance");
2496
+
2455
2497
  // src/handlers/http-pipeline.ts
2456
2498
  var debug12 = (0, import_debug12.default)("celerity:core:pipeline");
2457
2499
  async function executeHttpPipeline(handler, request, options) {
@@ -2502,6 +2544,9 @@ async function executeHttpPipeline(handler, request, options) {
2502
2544
  error: message,
2503
2545
  ...error instanceof Error && error.stack ? {
2504
2546
  stack: error.stack
2547
+ } : {},
2548
+ ...error instanceof Error && error.cause ? {
2549
+ cause: String(error.cause)
2505
2550
  } : {}
2506
2551
  });
2507
2552
  } else {
@@ -2527,7 +2572,8 @@ async function invokeClassHandler(handler, context) {
2527
2572
  for (const meta of sorted) {
2528
2573
  args[meta.index] = extractValidatedParam(meta.type, meta.key, context.request, context.metadata);
2529
2574
  }
2530
- return handler.handlerFn.apply(handler.handlerInstance, args);
2575
+ const instance = await resolveHandlerInstance(handler, context.container);
2576
+ return handler.handlerFn.apply(instance, args);
2531
2577
  }
2532
2578
  __name(invokeClassHandler, "invokeClassHandler");
2533
2579
  var VALIDATED_METADATA_KEYS = {
@@ -2626,6 +2672,9 @@ async function executeWebSocketPipeline(handler, message, options) {
2626
2672
  eventType: message.eventType,
2627
2673
  ...error instanceof Error && error.stack ? {
2628
2674
  stack: error.stack
2675
+ } : {},
2676
+ ...error instanceof Error && error.cause ? {
2677
+ cause: String(error.cause)
2629
2678
  } : {}
2630
2679
  });
2631
2680
  } else {
@@ -2642,7 +2691,8 @@ async function invokeClassHandler2(handler, context) {
2642
2691
  for (const meta of sorted) {
2643
2692
  args[meta.index] = extractWebSocketParam(meta, context);
2644
2693
  }
2645
- await handler.handlerFn.apply(handler.handlerInstance, args);
2694
+ const instance = await resolveHandlerInstance(handler, context.container);
2695
+ await handler.handlerFn.apply(instance, args);
2646
2696
  }
2647
2697
  __name(invokeClassHandler2, "invokeClassHandler");
2648
2698
  async function invokeFunctionHandler2(handler, context) {
@@ -2740,6 +2790,9 @@ async function executeConsumerPipeline(handler, event, options) {
2740
2790
  messageCount: event.messages.length,
2741
2791
  ...error instanceof Error && error.stack ? {
2742
2792
  stack: error.stack
2793
+ } : {},
2794
+ ...error instanceof Error && error.cause ? {
2795
+ cause: String(error.cause)
2743
2796
  } : {}
2744
2797
  });
2745
2798
  } else {
@@ -2761,7 +2814,8 @@ async function invokeClassHandler3(handler, context, validatedMessages, rawMessa
2761
2814
  for (const meta of sorted) {
2762
2815
  args[meta.index] = extractConsumerParam(meta, context, validatedMessages, rawMessages);
2763
2816
  }
2764
- return await handler.handlerFn.apply(handler.handlerInstance, args);
2817
+ const instance = await resolveHandlerInstance(handler, context.container);
2818
+ return await handler.handlerFn.apply(instance, args);
2765
2819
  }
2766
2820
  __name(invokeClassHandler3, "invokeClassHandler");
2767
2821
  async function invokeFunctionHandler3(handler, context, validatedMessages, _rawMessages) {
@@ -2834,6 +2888,9 @@ async function executeSchedulePipeline(handler, event, options) {
2834
2888
  scheduleId: event.scheduleId,
2835
2889
  ...error instanceof Error && error.stack ? {
2836
2890
  stack: error.stack
2891
+ } : {},
2892
+ ...error instanceof Error && error.cause ? {
2893
+ cause: String(error.cause)
2837
2894
  } : {}
2838
2895
  });
2839
2896
  } else {
@@ -2855,7 +2912,8 @@ async function invokeClassHandler4(handler, context, validatedInput) {
2855
2912
  for (const meta of sorted) {
2856
2913
  args[meta.index] = extractScheduleParam(meta, context, validatedInput);
2857
2914
  }
2858
- return await handler.handlerFn.apply(handler.handlerInstance, args);
2915
+ const instance = await resolveHandlerInstance(handler, context.container);
2916
+ return await handler.handlerFn.apply(instance, args);
2859
2917
  }
2860
2918
  __name(invokeClassHandler4, "invokeClassHandler");
2861
2919
  async function invokeFunctionHandler4(handler, context, _validatedInput) {
@@ -2926,7 +2984,8 @@ async function invokeClassHandler5(handler, context, validatedPayload) {
2926
2984
  for (const meta of sorted) {
2927
2985
  args[meta.index] = extractCustomParam(meta, context, validatedPayload);
2928
2986
  }
2929
- return handler.handlerFn.apply(handler.handlerInstance, args);
2987
+ const instance = await resolveHandlerInstance(handler, context.container);
2988
+ return handler.handlerFn.apply(instance, args);
2930
2989
  }
2931
2990
  __name(invokeClassHandler5, "invokeClassHandler");
2932
2991
  async function invokeFunctionHandler5(handler, context, validatedPayload) {
@@ -3283,7 +3342,7 @@ function createScheduleHandler(configOrString, configOrHandler, maybeHandler) {
3283
3342
  if (isScheduleExpression2(configOrString)) {
3284
3343
  config.schedule = configOrString;
3285
3344
  } else {
3286
- config.scheduleId = configOrString;
3345
+ config.source = configOrString;
3287
3346
  }
3288
3347
  } else {
3289
3348
  config = configOrString;
@@ -3294,7 +3353,7 @@ function createScheduleHandler(configOrString, configOrHandler, maybeHandler) {
3294
3353
  inject: config.inject ?? [],
3295
3354
  customMetadata: config.metadata ?? {}
3296
3355
  };
3297
- if (config.scheduleId !== void 0) metadata.scheduleId = config.scheduleId;
3356
+ if (config.source !== void 0) metadata.source = config.source;
3298
3357
  if (config.schedule !== void 0) metadata.schedule = config.schedule;
3299
3358
  if (config.schema !== void 0) metadata.schema = config.schema;
3300
3359
  return {
@@ -3417,7 +3476,7 @@ function buildResolvedFromExport(handlerId, handlerType, handlerFn, fnDef) {
3417
3476
  return {
3418
3477
  ...base,
3419
3478
  type: "schedule",
3420
- handlerTag: meta?.scheduleId ?? handlerId
3479
+ handlerTag: meta?.source ?? handlerId
3421
3480
  };
3422
3481
  case "custom":
3423
3482
  return {
@@ -3536,7 +3595,8 @@ async function invokeClassGuard(guard, input, metadata, options, logger) {
3536
3595
  args[i] = guardContext;
3537
3596
  }
3538
3597
  }
3539
- return guard.handlerFn.apply(guard.handlerInstance, args);
3598
+ const instance = await resolveGuardInstance(guard, options.container);
3599
+ return guard.handlerFn.apply(instance, args);
3540
3600
  }
3541
3601
  __name(invokeClassGuard, "invokeClassGuard");
3542
3602
  async function invokeFunctionGuard(guard, input, metadata, options, logger) {
@@ -3856,7 +3916,7 @@ async function bootstrapForRuntime(modulePath, systemLayers) {
3856
3916
  __name(bootstrapForRuntime, "bootstrapForRuntime");
3857
3917
 
3858
3918
  // src/bootstrap/runtime-orchestrator.ts
3859
- var import_types = require("@celerity-sdk/types");
3919
+ var import_types7 = require("@celerity-sdk/types");
3860
3920
  async function loadRuntime() {
3861
3921
  const pkg = "@celerity-sdk/runtime";
3862
3922
  const runtimeModule = await import(pkg);
@@ -3928,22 +3988,37 @@ __name(registerWebSocketHandlers, "registerWebSocketHandlers");
3928
3988
  async function registerConsumerHandlers(app, consumers, result) {
3929
3989
  for (const consumer of consumers?.consumers ?? []) {
3930
3990
  for (const def of consumer.handlers) {
3931
- const tag = `source::${consumer.sourceId}::${def.name}`;
3932
- const callback = result.createConsumerCallback(tag, def.name) ?? await result.createConsumerCallbackById(def.handler, def.location, def.name);
3991
+ const methodName = def.handler.split(".").pop() ?? def.name;
3992
+ const lookupKey = `${consumer.consumerName}::${methodName}`;
3993
+ const callback = result.createConsumerCallback(lookupKey, def.name) ?? await result.createConsumerCallbackById(def.handler, def.location, def.name);
3933
3994
  if (callback) {
3934
- app.registerConsumerHandler(tag, def.timeout, callback);
3995
+ app.registerConsumerHandler(def.name, def.timeout, callback);
3935
3996
  }
3936
3997
  }
3937
3998
  }
3938
3999
  }
3939
4000
  __name(registerConsumerHandlers, "registerConsumerHandlers");
4001
+ async function registerEventHandlers(app, events, result) {
4002
+ for (const event of events?.events ?? []) {
4003
+ for (const def of event.handlers) {
4004
+ const methodName = def.handler.split(".").pop() ?? def.name;
4005
+ const lookupKey = `${event.consumerName}::${methodName}`;
4006
+ const callback = result.createConsumerCallback(lookupKey, def.name) ?? await result.createConsumerCallbackById(def.handler, def.location, def.name);
4007
+ if (callback) {
4008
+ app.registerConsumerHandler(def.name, def.timeout, callback);
4009
+ }
4010
+ }
4011
+ }
4012
+ }
4013
+ __name(registerEventHandlers, "registerEventHandlers");
3940
4014
  async function registerScheduleHandlers(app, schedules, result) {
3941
4015
  for (const schedule of schedules?.schedules ?? []) {
3942
4016
  for (const def of schedule.handlers) {
3943
- const tag = `source::${schedule.scheduleId}::${def.name}`;
3944
- const callback = result.createScheduleCallback(tag, def.name) ?? await result.createScheduleCallbackById(def.handler, def.location, def.name);
4017
+ const methodName = def.handler.split(".").pop() ?? def.name;
4018
+ const lookupKey = `${schedule.scheduleId}::${methodName}`;
4019
+ const callback = result.createScheduleCallback(lookupKey, def.name) ?? await result.createScheduleCallbackById(def.handler, def.location, def.name);
3945
4020
  if (callback) {
3946
- app.registerScheduleHandler(tag, def.timeout, callback);
4021
+ app.registerScheduleHandler(def.name, def.timeout, callback);
3947
4022
  }
3948
4023
  }
3949
4024
  }
@@ -3965,11 +4040,12 @@ async function startRuntime(options) {
3965
4040
  await registerGuardHandlers(app, appConfig.api?.guards, result);
3966
4041
  await registerWebSocketHandlers(app, appConfig.api?.websocket, result);
3967
4042
  await registerConsumerHandlers(app, appConfig.consumers, result);
4043
+ await registerEventHandlers(app, appConfig.events, result);
3968
4044
  await registerScheduleHandlers(app, appConfig.schedules, result);
3969
4045
  await registerCustomHandlers(app, appConfig.customHandlers, result);
3970
4046
  if (appConfig.api?.websocket) {
3971
4047
  const sender = new RuntimeWebSocketSender(app.websocketRegistry());
3972
- result.container.register(import_types.WebSocketSender, {
4048
+ result.container.register(import_types7.WebSocketSender, {
3973
4049
  useValue: sender
3974
4050
  });
3975
4051
  }
@@ -3978,8 +4054,8 @@ async function startRuntime(options) {
3978
4054
  __name(startRuntime, "startRuntime");
3979
4055
 
3980
4056
  // src/index.ts
3981
- var import_types2 = require("@celerity-sdk/types");
3982
- var import_types3 = require("@celerity-sdk/types");
4057
+ var import_types8 = require("@celerity-sdk/types");
4058
+ var import_types9 = require("@celerity-sdk/types");
3983
4059
  // Annotate the CommonJS export names for ESM import in node:
3984
4060
  0 && (module.exports = {
3985
4061
  APP_CONFIG,