@celerity-sdk/core 0.4.0 → 0.5.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/README.md +281 -47
- package/dist/index.cjs +118 -54
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -17
- package/dist/index.d.ts +21 -17
- package/dist/index.js +108 -44
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
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: () =>
|
|
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: () =>
|
|
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: () =>
|
|
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: () =>
|
|
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(
|
|
561
|
+
function Consumer(source) {
|
|
562
562
|
return (target) => {
|
|
563
563
|
const meta = {};
|
|
564
|
-
if (
|
|
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
|
-
|
|
623
|
+
source: arg
|
|
624
624
|
};
|
|
625
625
|
}
|
|
626
626
|
const meta = {};
|
|
627
|
-
if (arg.
|
|
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();
|
|
@@ -1691,6 +1704,7 @@ function checkDependencies(consumer, depTokens, visibleTokens, moduleClass, grap
|
|
|
1691
1704
|
checkDependencies(dep, adoptedDeps, visibleTokens, moduleClass, graph, container, diagnostics);
|
|
1692
1705
|
continue;
|
|
1693
1706
|
}
|
|
1707
|
+
if ((0, import_common2.isResourceLayerToken)(dep)) continue;
|
|
1694
1708
|
diagnostics.push({
|
|
1695
1709
|
type: "missing_dependency",
|
|
1696
1710
|
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,7 +1725,7 @@ __name(findTokenOwner, "findTokenOwner");
|
|
|
1711
1725
|
// src/handlers/scanners/http.ts
|
|
1712
1726
|
var import_reflect_metadata21 = require("reflect-metadata");
|
|
1713
1727
|
var import_debug5 = __toESM(require("debug"), 1);
|
|
1714
|
-
var
|
|
1728
|
+
var import_common3 = require("@celerity-sdk/common");
|
|
1715
1729
|
var debug5 = (0, import_debug5.default)("celerity:core:scanner:http");
|
|
1716
1730
|
async function scanHttpHandlers(graph, container, registry) {
|
|
1717
1731
|
for (const [, node] of graph) {
|
|
@@ -1746,8 +1760,7 @@ __name(scanModule, "scanModule");
|
|
|
1746
1760
|
async function scanClassHandler(controllerClass, container, registry) {
|
|
1747
1761
|
const controllerMeta = Reflect.getOwnMetadata(CONTROLLER_METADATA, controllerClass);
|
|
1748
1762
|
if (!controllerMeta) return;
|
|
1749
|
-
const
|
|
1750
|
-
const prototype = Object.getPrototypeOf(instance);
|
|
1763
|
+
const prototype = controllerClass.prototype;
|
|
1751
1764
|
const methods = Object.getOwnPropertyNames(prototype).filter((name) => name !== "constructor");
|
|
1752
1765
|
const classProtectedBy = Reflect.getOwnMetadata(GUARD_PROTECTEDBY_METADATA, controllerClass) ?? [];
|
|
1753
1766
|
const classLayers = Reflect.getOwnMetadata(LAYER_METADATA, controllerClass) ?? [];
|
|
@@ -1756,7 +1769,7 @@ async function scanClassHandler(controllerClass, container, registry) {
|
|
|
1756
1769
|
const method = Reflect.getOwnMetadata(HTTP_METHOD_METADATA, prototype, methodName);
|
|
1757
1770
|
if (!method) continue;
|
|
1758
1771
|
const routePath = Reflect.getOwnMetadata(ROUTE_PATH_METADATA, prototype, methodName) ?? "/";
|
|
1759
|
-
const fullPath = (0,
|
|
1772
|
+
const fullPath = (0, import_common3.joinHandlerPath)(controllerMeta.prefix ?? "", routePath);
|
|
1760
1773
|
const methodProtectedBy = Reflect.getOwnMetadata(GUARD_PROTECTEDBY_METADATA, prototype, methodName) ?? [];
|
|
1761
1774
|
const methodLayers = Reflect.getOwnMetadata(LAYER_METADATA, prototype, methodName) ?? [];
|
|
1762
1775
|
const paramMetadata = Reflect.getOwnMetadata(PARAM_METADATA, prototype, methodName) ?? [];
|
|
@@ -1789,7 +1802,7 @@ async function scanClassHandler(controllerClass, container, registry) {
|
|
|
1789
1802
|
...methodCustomMetadata
|
|
1790
1803
|
},
|
|
1791
1804
|
handlerFn: descriptor.value,
|
|
1792
|
-
|
|
1805
|
+
controllerClass
|
|
1793
1806
|
});
|
|
1794
1807
|
}
|
|
1795
1808
|
}
|
|
@@ -1830,8 +1843,7 @@ __name(scanFunctionHandler, "scanFunctionHandler");
|
|
|
1830
1843
|
async function scanClassGuard(guardClass, container, registry) {
|
|
1831
1844
|
const guardName = Reflect.getOwnMetadata(GUARD_CUSTOM_METADATA, guardClass);
|
|
1832
1845
|
if (!guardName) return;
|
|
1833
|
-
const
|
|
1834
|
-
const prototype = Object.getPrototypeOf(instance);
|
|
1846
|
+
const prototype = guardClass.prototype;
|
|
1835
1847
|
const descriptor = Object.getOwnPropertyDescriptor(prototype, "check");
|
|
1836
1848
|
if (!descriptor?.value || typeof descriptor.value !== "function") {
|
|
1837
1849
|
debug5("scanClassGuard: %s has no check() method, skipping", guardClass.name);
|
|
@@ -1843,7 +1855,7 @@ async function scanClassGuard(guardClass, container, registry) {
|
|
|
1843
1855
|
registry.registerGuard({
|
|
1844
1856
|
name: guardName,
|
|
1845
1857
|
handlerFn: descriptor.value,
|
|
1846
|
-
|
|
1858
|
+
guardClass,
|
|
1847
1859
|
paramMetadata,
|
|
1848
1860
|
customMetadata
|
|
1849
1861
|
});
|
|
@@ -1946,8 +1958,7 @@ __name(scanWebSocketHandlers, "scanWebSocketHandlers");
|
|
|
1946
1958
|
async function scanClassHandler2(controllerClass, container, registry) {
|
|
1947
1959
|
const isWsController = Reflect.getOwnMetadata(WEBSOCKET_CONTROLLER_METADATA, controllerClass);
|
|
1948
1960
|
if (!isWsController) return;
|
|
1949
|
-
const
|
|
1950
|
-
const prototype = Object.getPrototypeOf(instance);
|
|
1961
|
+
const prototype = controllerClass.prototype;
|
|
1951
1962
|
const methods = Object.getOwnPropertyNames(prototype).filter((name) => name !== "constructor");
|
|
1952
1963
|
const classProtectedBy = Reflect.getOwnMetadata(GUARD_PROTECTEDBY_METADATA, controllerClass) ?? [];
|
|
1953
1964
|
const classLayers = Reflect.getOwnMetadata(LAYER_METADATA, controllerClass) ?? [];
|
|
@@ -1984,7 +1995,7 @@ async function scanClassHandler2(controllerClass, container, registry) {
|
|
|
1984
1995
|
...methodCustomMetadata
|
|
1985
1996
|
},
|
|
1986
1997
|
handlerFn: descriptor.value,
|
|
1987
|
-
|
|
1998
|
+
controllerClass
|
|
1988
1999
|
});
|
|
1989
2000
|
}
|
|
1990
2001
|
}
|
|
@@ -2035,8 +2046,7 @@ __name(scanConsumerHandlers, "scanConsumerHandlers");
|
|
|
2035
2046
|
async function scanClassHandler3(controllerClass, container, registry) {
|
|
2036
2047
|
const consumerMeta = Reflect.getOwnMetadata(CONSUMER_METADATA, controllerClass);
|
|
2037
2048
|
if (!consumerMeta) return;
|
|
2038
|
-
const
|
|
2039
|
-
const prototype = Object.getPrototypeOf(instance);
|
|
2049
|
+
const prototype = controllerClass.prototype;
|
|
2040
2050
|
const methods = Object.getOwnPropertyNames(prototype).filter((name) => name !== "constructor");
|
|
2041
2051
|
const classLayers = Reflect.getOwnMetadata(LAYER_METADATA, controllerClass) ?? [];
|
|
2042
2052
|
const classCustomMetadata = Reflect.getOwnMetadata(CUSTOM_METADATA, controllerClass) ?? {};
|
|
@@ -2048,7 +2058,7 @@ async function scanClassHandler3(controllerClass, container, registry) {
|
|
|
2048
2058
|
const methodCustomMetadata = Reflect.getOwnMetadata(CUSTOM_METADATA, prototype, methodName) ?? {};
|
|
2049
2059
|
const descriptor = Object.getOwnPropertyDescriptor(prototype, methodName);
|
|
2050
2060
|
if (!descriptor?.value || typeof descriptor.value !== "function") continue;
|
|
2051
|
-
const handlerTag =
|
|
2061
|
+
const handlerTag = consumerMeta.source ? `${consumerMeta.source}::${methodName}` : methodName;
|
|
2052
2062
|
const layers = [
|
|
2053
2063
|
...classLayers,
|
|
2054
2064
|
...methodLayers
|
|
@@ -2070,7 +2080,7 @@ async function scanClassHandler3(controllerClass, container, registry) {
|
|
|
2070
2080
|
...methodCustomMetadata
|
|
2071
2081
|
},
|
|
2072
2082
|
handlerFn: descriptor.value,
|
|
2073
|
-
|
|
2083
|
+
controllerClass
|
|
2074
2084
|
});
|
|
2075
2085
|
}
|
|
2076
2086
|
}
|
|
@@ -2078,7 +2088,7 @@ __name(scanClassHandler3, "scanClassHandler");
|
|
|
2078
2088
|
function scanFunctionHandler3(definition, registry) {
|
|
2079
2089
|
if (definition.type !== "consumer") return;
|
|
2080
2090
|
const meta = definition.metadata;
|
|
2081
|
-
const handlerTag =
|
|
2091
|
+
const handlerTag = definition.id ?? "default";
|
|
2082
2092
|
const layers = [
|
|
2083
2093
|
...meta.layers ?? []
|
|
2084
2094
|
];
|
|
@@ -2118,8 +2128,7 @@ async function scanScheduleHandlers(graph, container, registry) {
|
|
|
2118
2128
|
}
|
|
2119
2129
|
__name(scanScheduleHandlers, "scanScheduleHandlers");
|
|
2120
2130
|
async function scanClassHandler4(controllerClass, container, registry) {
|
|
2121
|
-
const
|
|
2122
|
-
const prototype = Object.getPrototypeOf(instance);
|
|
2131
|
+
const prototype = controllerClass.prototype;
|
|
2123
2132
|
const methods = Object.getOwnPropertyNames(prototype).filter((name) => name !== "constructor");
|
|
2124
2133
|
const classLayers = Reflect.getOwnMetadata(LAYER_METADATA, controllerClass) ?? [];
|
|
2125
2134
|
const classCustomMetadata = Reflect.getOwnMetadata(CUSTOM_METADATA, controllerClass) ?? {};
|
|
@@ -2131,7 +2140,7 @@ async function scanClassHandler4(controllerClass, container, registry) {
|
|
|
2131
2140
|
const methodCustomMetadata = Reflect.getOwnMetadata(CUSTOM_METADATA, prototype, methodName) ?? {};
|
|
2132
2141
|
const descriptor = Object.getOwnPropertyDescriptor(prototype, methodName);
|
|
2133
2142
|
if (!descriptor?.value || typeof descriptor.value !== "function") continue;
|
|
2134
|
-
const handlerTag = handlerMeta.
|
|
2143
|
+
const handlerTag = handlerMeta.source ? `${handlerMeta.source}::${methodName}` : methodName;
|
|
2135
2144
|
const layers = [
|
|
2136
2145
|
...classLayers,
|
|
2137
2146
|
...methodLayers
|
|
@@ -2154,12 +2163,12 @@ async function scanClassHandler4(controllerClass, container, registry) {
|
|
|
2154
2163
|
...handlerMeta.schedule ? {
|
|
2155
2164
|
schedule: handlerMeta.schedule
|
|
2156
2165
|
} : {},
|
|
2157
|
-
...handlerMeta.
|
|
2158
|
-
|
|
2166
|
+
...handlerMeta.source ? {
|
|
2167
|
+
source: handlerMeta.source
|
|
2159
2168
|
} : {}
|
|
2160
2169
|
},
|
|
2161
2170
|
handlerFn: descriptor.value,
|
|
2162
|
-
|
|
2171
|
+
controllerClass
|
|
2163
2172
|
});
|
|
2164
2173
|
}
|
|
2165
2174
|
}
|
|
@@ -2167,7 +2176,7 @@ __name(scanClassHandler4, "scanClassHandler");
|
|
|
2167
2176
|
function scanFunctionHandler4(definition, registry) {
|
|
2168
2177
|
if (definition.type !== "schedule") return;
|
|
2169
2178
|
const meta = definition.metadata;
|
|
2170
|
-
const handlerTag = meta.
|
|
2179
|
+
const handlerTag = meta.source ?? definition.id ?? "default";
|
|
2171
2180
|
const layers = [
|
|
2172
2181
|
...meta.layers ?? []
|
|
2173
2182
|
];
|
|
@@ -2180,7 +2189,7 @@ function scanFunctionHandler4(definition, registry) {
|
|
|
2180
2189
|
...meta.customMetadata ?? {}
|
|
2181
2190
|
};
|
|
2182
2191
|
if (meta.schedule) customMetadata.schedule = meta.schedule;
|
|
2183
|
-
if (meta.
|
|
2192
|
+
if (meta.source) customMetadata.source = meta.source;
|
|
2184
2193
|
debug8("scanFunctionHandler: tag=%s", handlerTag);
|
|
2185
2194
|
registry.register({
|
|
2186
2195
|
type: "schedule",
|
|
@@ -2212,8 +2221,7 @@ async function scanCustomHandlers(graph, container, registry) {
|
|
|
2212
2221
|
}
|
|
2213
2222
|
__name(scanCustomHandlers, "scanCustomHandlers");
|
|
2214
2223
|
async function scanClassHandler5(controllerClass, container, registry) {
|
|
2215
|
-
const
|
|
2216
|
-
const prototype = Object.getPrototypeOf(instance);
|
|
2224
|
+
const prototype = controllerClass.prototype;
|
|
2217
2225
|
const methods = Object.getOwnPropertyNames(prototype).filter((name) => name !== "constructor");
|
|
2218
2226
|
const classLayers = Reflect.getOwnMetadata(LAYER_METADATA, controllerClass) ?? [];
|
|
2219
2227
|
const classCustomMetadata = Reflect.getOwnMetadata(CUSTOM_METADATA, controllerClass) ?? {};
|
|
@@ -2246,7 +2254,7 @@ async function scanClassHandler5(controllerClass, container, registry) {
|
|
|
2246
2254
|
...methodCustomMetadata
|
|
2247
2255
|
},
|
|
2248
2256
|
handlerFn: descriptor.value,
|
|
2249
|
-
|
|
2257
|
+
controllerClass
|
|
2250
2258
|
});
|
|
2251
2259
|
}
|
|
2252
2260
|
}
|
|
@@ -2452,6 +2460,28 @@ function buildHttpContext(request, metadata, container, logger) {
|
|
|
2452
2460
|
}
|
|
2453
2461
|
__name(buildHttpContext, "buildHttpContext");
|
|
2454
2462
|
|
|
2463
|
+
// src/handlers/types.ts
|
|
2464
|
+
async function resolveHandlerInstance(handler, container) {
|
|
2465
|
+
if (handler.handlerInstance) return handler.handlerInstance;
|
|
2466
|
+
if (!handler.controllerClass) {
|
|
2467
|
+
throw new Error("Handler has no controllerClass for deferred resolution");
|
|
2468
|
+
}
|
|
2469
|
+
const instance = await container.resolve(handler.controllerClass);
|
|
2470
|
+
handler.handlerInstance = instance;
|
|
2471
|
+
return instance;
|
|
2472
|
+
}
|
|
2473
|
+
__name(resolveHandlerInstance, "resolveHandlerInstance");
|
|
2474
|
+
async function resolveGuardInstance(guard, container) {
|
|
2475
|
+
if (guard.handlerInstance) return guard.handlerInstance;
|
|
2476
|
+
if (!guard.guardClass) {
|
|
2477
|
+
throw new Error("Guard has no guardClass for deferred resolution");
|
|
2478
|
+
}
|
|
2479
|
+
const instance = await container.resolve(guard.guardClass);
|
|
2480
|
+
guard.handlerInstance = instance;
|
|
2481
|
+
return instance;
|
|
2482
|
+
}
|
|
2483
|
+
__name(resolveGuardInstance, "resolveGuardInstance");
|
|
2484
|
+
|
|
2455
2485
|
// src/handlers/http-pipeline.ts
|
|
2456
2486
|
var debug12 = (0, import_debug12.default)("celerity:core:pipeline");
|
|
2457
2487
|
async function executeHttpPipeline(handler, request, options) {
|
|
@@ -2502,6 +2532,9 @@ async function executeHttpPipeline(handler, request, options) {
|
|
|
2502
2532
|
error: message,
|
|
2503
2533
|
...error instanceof Error && error.stack ? {
|
|
2504
2534
|
stack: error.stack
|
|
2535
|
+
} : {},
|
|
2536
|
+
...error instanceof Error && error.cause ? {
|
|
2537
|
+
cause: String(error.cause)
|
|
2505
2538
|
} : {}
|
|
2506
2539
|
});
|
|
2507
2540
|
} else {
|
|
@@ -2527,7 +2560,8 @@ async function invokeClassHandler(handler, context) {
|
|
|
2527
2560
|
for (const meta of sorted) {
|
|
2528
2561
|
args[meta.index] = extractValidatedParam(meta.type, meta.key, context.request, context.metadata);
|
|
2529
2562
|
}
|
|
2530
|
-
|
|
2563
|
+
const instance = await resolveHandlerInstance(handler, context.container);
|
|
2564
|
+
return handler.handlerFn.apply(instance, args);
|
|
2531
2565
|
}
|
|
2532
2566
|
__name(invokeClassHandler, "invokeClassHandler");
|
|
2533
2567
|
var VALIDATED_METADATA_KEYS = {
|
|
@@ -2626,6 +2660,9 @@ async function executeWebSocketPipeline(handler, message, options) {
|
|
|
2626
2660
|
eventType: message.eventType,
|
|
2627
2661
|
...error instanceof Error && error.stack ? {
|
|
2628
2662
|
stack: error.stack
|
|
2663
|
+
} : {},
|
|
2664
|
+
...error instanceof Error && error.cause ? {
|
|
2665
|
+
cause: String(error.cause)
|
|
2629
2666
|
} : {}
|
|
2630
2667
|
});
|
|
2631
2668
|
} else {
|
|
@@ -2642,7 +2679,8 @@ async function invokeClassHandler2(handler, context) {
|
|
|
2642
2679
|
for (const meta of sorted) {
|
|
2643
2680
|
args[meta.index] = extractWebSocketParam(meta, context);
|
|
2644
2681
|
}
|
|
2645
|
-
await
|
|
2682
|
+
const instance = await resolveHandlerInstance(handler, context.container);
|
|
2683
|
+
await handler.handlerFn.apply(instance, args);
|
|
2646
2684
|
}
|
|
2647
2685
|
__name(invokeClassHandler2, "invokeClassHandler");
|
|
2648
2686
|
async function invokeFunctionHandler2(handler, context) {
|
|
@@ -2740,6 +2778,9 @@ async function executeConsumerPipeline(handler, event, options) {
|
|
|
2740
2778
|
messageCount: event.messages.length,
|
|
2741
2779
|
...error instanceof Error && error.stack ? {
|
|
2742
2780
|
stack: error.stack
|
|
2781
|
+
} : {},
|
|
2782
|
+
...error instanceof Error && error.cause ? {
|
|
2783
|
+
cause: String(error.cause)
|
|
2743
2784
|
} : {}
|
|
2744
2785
|
});
|
|
2745
2786
|
} else {
|
|
@@ -2761,7 +2802,8 @@ async function invokeClassHandler3(handler, context, validatedMessages, rawMessa
|
|
|
2761
2802
|
for (const meta of sorted) {
|
|
2762
2803
|
args[meta.index] = extractConsumerParam(meta, context, validatedMessages, rawMessages);
|
|
2763
2804
|
}
|
|
2764
|
-
|
|
2805
|
+
const instance = await resolveHandlerInstance(handler, context.container);
|
|
2806
|
+
return await handler.handlerFn.apply(instance, args);
|
|
2765
2807
|
}
|
|
2766
2808
|
__name(invokeClassHandler3, "invokeClassHandler");
|
|
2767
2809
|
async function invokeFunctionHandler3(handler, context, validatedMessages, _rawMessages) {
|
|
@@ -2834,6 +2876,9 @@ async function executeSchedulePipeline(handler, event, options) {
|
|
|
2834
2876
|
scheduleId: event.scheduleId,
|
|
2835
2877
|
...error instanceof Error && error.stack ? {
|
|
2836
2878
|
stack: error.stack
|
|
2879
|
+
} : {},
|
|
2880
|
+
...error instanceof Error && error.cause ? {
|
|
2881
|
+
cause: String(error.cause)
|
|
2837
2882
|
} : {}
|
|
2838
2883
|
});
|
|
2839
2884
|
} else {
|
|
@@ -2855,7 +2900,8 @@ async function invokeClassHandler4(handler, context, validatedInput) {
|
|
|
2855
2900
|
for (const meta of sorted) {
|
|
2856
2901
|
args[meta.index] = extractScheduleParam(meta, context, validatedInput);
|
|
2857
2902
|
}
|
|
2858
|
-
|
|
2903
|
+
const instance = await resolveHandlerInstance(handler, context.container);
|
|
2904
|
+
return await handler.handlerFn.apply(instance, args);
|
|
2859
2905
|
}
|
|
2860
2906
|
__name(invokeClassHandler4, "invokeClassHandler");
|
|
2861
2907
|
async function invokeFunctionHandler4(handler, context, _validatedInput) {
|
|
@@ -2926,7 +2972,8 @@ async function invokeClassHandler5(handler, context, validatedPayload) {
|
|
|
2926
2972
|
for (const meta of sorted) {
|
|
2927
2973
|
args[meta.index] = extractCustomParam(meta, context, validatedPayload);
|
|
2928
2974
|
}
|
|
2929
|
-
|
|
2975
|
+
const instance = await resolveHandlerInstance(handler, context.container);
|
|
2976
|
+
return handler.handlerFn.apply(instance, args);
|
|
2930
2977
|
}
|
|
2931
2978
|
__name(invokeClassHandler5, "invokeClassHandler");
|
|
2932
2979
|
async function invokeFunctionHandler5(handler, context, validatedPayload) {
|
|
@@ -3283,7 +3330,7 @@ function createScheduleHandler(configOrString, configOrHandler, maybeHandler) {
|
|
|
3283
3330
|
if (isScheduleExpression2(configOrString)) {
|
|
3284
3331
|
config.schedule = configOrString;
|
|
3285
3332
|
} else {
|
|
3286
|
-
config.
|
|
3333
|
+
config.source = configOrString;
|
|
3287
3334
|
}
|
|
3288
3335
|
} else {
|
|
3289
3336
|
config = configOrString;
|
|
@@ -3294,7 +3341,7 @@ function createScheduleHandler(configOrString, configOrHandler, maybeHandler) {
|
|
|
3294
3341
|
inject: config.inject ?? [],
|
|
3295
3342
|
customMetadata: config.metadata ?? {}
|
|
3296
3343
|
};
|
|
3297
|
-
if (config.
|
|
3344
|
+
if (config.source !== void 0) metadata.source = config.source;
|
|
3298
3345
|
if (config.schedule !== void 0) metadata.schedule = config.schedule;
|
|
3299
3346
|
if (config.schema !== void 0) metadata.schema = config.schema;
|
|
3300
3347
|
return {
|
|
@@ -3417,7 +3464,7 @@ function buildResolvedFromExport(handlerId, handlerType, handlerFn, fnDef) {
|
|
|
3417
3464
|
return {
|
|
3418
3465
|
...base,
|
|
3419
3466
|
type: "schedule",
|
|
3420
|
-
handlerTag: meta?.
|
|
3467
|
+
handlerTag: meta?.source ?? handlerId
|
|
3421
3468
|
};
|
|
3422
3469
|
case "custom":
|
|
3423
3470
|
return {
|
|
@@ -3536,7 +3583,8 @@ async function invokeClassGuard(guard, input, metadata, options, logger) {
|
|
|
3536
3583
|
args[i] = guardContext;
|
|
3537
3584
|
}
|
|
3538
3585
|
}
|
|
3539
|
-
|
|
3586
|
+
const instance = await resolveGuardInstance(guard, options.container);
|
|
3587
|
+
return guard.handlerFn.apply(instance, args);
|
|
3540
3588
|
}
|
|
3541
3589
|
__name(invokeClassGuard, "invokeClassGuard");
|
|
3542
3590
|
async function invokeFunctionGuard(guard, input, metadata, options, logger) {
|
|
@@ -3856,7 +3904,7 @@ async function bootstrapForRuntime(modulePath, systemLayers) {
|
|
|
3856
3904
|
__name(bootstrapForRuntime, "bootstrapForRuntime");
|
|
3857
3905
|
|
|
3858
3906
|
// src/bootstrap/runtime-orchestrator.ts
|
|
3859
|
-
var
|
|
3907
|
+
var import_types7 = require("@celerity-sdk/types");
|
|
3860
3908
|
async function loadRuntime() {
|
|
3861
3909
|
const pkg = "@celerity-sdk/runtime";
|
|
3862
3910
|
const runtimeModule = await import(pkg);
|
|
@@ -3928,22 +3976,37 @@ __name(registerWebSocketHandlers, "registerWebSocketHandlers");
|
|
|
3928
3976
|
async function registerConsumerHandlers(app, consumers, result) {
|
|
3929
3977
|
for (const consumer of consumers?.consumers ?? []) {
|
|
3930
3978
|
for (const def of consumer.handlers) {
|
|
3931
|
-
const
|
|
3932
|
-
const
|
|
3979
|
+
const methodName = def.handler.split(".").pop() ?? def.name;
|
|
3980
|
+
const lookupKey = `${consumer.consumerName}::${methodName}`;
|
|
3981
|
+
const callback = result.createConsumerCallback(lookupKey, def.name) ?? await result.createConsumerCallbackById(def.handler, def.location, def.name);
|
|
3933
3982
|
if (callback) {
|
|
3934
|
-
app.registerConsumerHandler(
|
|
3983
|
+
app.registerConsumerHandler(def.name, def.timeout, callback);
|
|
3935
3984
|
}
|
|
3936
3985
|
}
|
|
3937
3986
|
}
|
|
3938
3987
|
}
|
|
3939
3988
|
__name(registerConsumerHandlers, "registerConsumerHandlers");
|
|
3989
|
+
async function registerEventHandlers(app, events, result) {
|
|
3990
|
+
for (const event of events?.events ?? []) {
|
|
3991
|
+
for (const def of event.handlers) {
|
|
3992
|
+
const methodName = def.handler.split(".").pop() ?? def.name;
|
|
3993
|
+
const lookupKey = `${event.consumerName}::${methodName}`;
|
|
3994
|
+
const callback = result.createConsumerCallback(lookupKey, def.name) ?? await result.createConsumerCallbackById(def.handler, def.location, def.name);
|
|
3995
|
+
if (callback) {
|
|
3996
|
+
app.registerConsumerHandler(def.name, def.timeout, callback);
|
|
3997
|
+
}
|
|
3998
|
+
}
|
|
3999
|
+
}
|
|
4000
|
+
}
|
|
4001
|
+
__name(registerEventHandlers, "registerEventHandlers");
|
|
3940
4002
|
async function registerScheduleHandlers(app, schedules, result) {
|
|
3941
4003
|
for (const schedule of schedules?.schedules ?? []) {
|
|
3942
4004
|
for (const def of schedule.handlers) {
|
|
3943
|
-
const
|
|
3944
|
-
const
|
|
4005
|
+
const methodName = def.handler.split(".").pop() ?? def.name;
|
|
4006
|
+
const lookupKey = `${schedule.scheduleId}::${methodName}`;
|
|
4007
|
+
const callback = result.createScheduleCallback(lookupKey, def.name) ?? await result.createScheduleCallbackById(def.handler, def.location, def.name);
|
|
3945
4008
|
if (callback) {
|
|
3946
|
-
app.registerScheduleHandler(
|
|
4009
|
+
app.registerScheduleHandler(def.name, def.timeout, callback);
|
|
3947
4010
|
}
|
|
3948
4011
|
}
|
|
3949
4012
|
}
|
|
@@ -3965,11 +4028,12 @@ async function startRuntime(options) {
|
|
|
3965
4028
|
await registerGuardHandlers(app, appConfig.api?.guards, result);
|
|
3966
4029
|
await registerWebSocketHandlers(app, appConfig.api?.websocket, result);
|
|
3967
4030
|
await registerConsumerHandlers(app, appConfig.consumers, result);
|
|
4031
|
+
await registerEventHandlers(app, appConfig.events, result);
|
|
3968
4032
|
await registerScheduleHandlers(app, appConfig.schedules, result);
|
|
3969
4033
|
await registerCustomHandlers(app, appConfig.customHandlers, result);
|
|
3970
4034
|
if (appConfig.api?.websocket) {
|
|
3971
4035
|
const sender = new RuntimeWebSocketSender(app.websocketRegistry());
|
|
3972
|
-
result.container.register(
|
|
4036
|
+
result.container.register(import_types7.WebSocketSender, {
|
|
3973
4037
|
useValue: sender
|
|
3974
4038
|
});
|
|
3975
4039
|
}
|
|
@@ -3978,8 +4042,8 @@ async function startRuntime(options) {
|
|
|
3978
4042
|
__name(startRuntime, "startRuntime");
|
|
3979
4043
|
|
|
3980
4044
|
// src/index.ts
|
|
3981
|
-
var
|
|
3982
|
-
var
|
|
4045
|
+
var import_types8 = require("@celerity-sdk/types");
|
|
4046
|
+
var import_types9 = require("@celerity-sdk/types");
|
|
3983
4047
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3984
4048
|
0 && (module.exports = {
|
|
3985
4049
|
APP_CONFIG,
|