@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.js
CHANGED
|
@@ -378,10 +378,10 @@ __name(EventType, "EventType");
|
|
|
378
378
|
|
|
379
379
|
// src/decorators/consumer.ts
|
|
380
380
|
import "reflect-metadata";
|
|
381
|
-
function Consumer(
|
|
381
|
+
function Consumer(source) {
|
|
382
382
|
return (target) => {
|
|
383
383
|
const meta = {};
|
|
384
|
-
if (
|
|
384
|
+
if (source !== void 0) meta.source = source;
|
|
385
385
|
Reflect.defineMetadata(CONSUMER_METADATA, meta, target);
|
|
386
386
|
Reflect.defineMetadata(INJECTABLE_METADATA, true, target);
|
|
387
387
|
};
|
|
@@ -440,11 +440,11 @@ function parseScheduleArg(arg) {
|
|
|
440
440
|
return isScheduleExpression(arg) ? {
|
|
441
441
|
schedule: arg
|
|
442
442
|
} : {
|
|
443
|
-
|
|
443
|
+
source: arg
|
|
444
444
|
};
|
|
445
445
|
}
|
|
446
446
|
const meta = {};
|
|
447
|
-
if (arg.
|
|
447
|
+
if (arg.source !== void 0) meta.source = arg.source;
|
|
448
448
|
if (arg.schedule !== void 0) meta.schedule = arg.schedule;
|
|
449
449
|
return meta;
|
|
450
450
|
}
|
|
@@ -835,6 +835,10 @@ __name(runLayerPipeline, "runLayerPipeline");
|
|
|
835
835
|
// src/layers/system.ts
|
|
836
836
|
import { ConfigLayer, captureResourceLinks, getResourceTypes } from "@celerity-sdk/config";
|
|
837
837
|
var RESOURCE_LAYER_MAP = {
|
|
838
|
+
datastore: {
|
|
839
|
+
pkg: "@celerity-sdk/datastore",
|
|
840
|
+
className: "DatastoreLayer"
|
|
841
|
+
},
|
|
838
842
|
bucket: {
|
|
839
843
|
pkg: "@celerity-sdk/bucket",
|
|
840
844
|
className: "ObjectStorageLayer"
|
|
@@ -843,9 +847,17 @@ var RESOURCE_LAYER_MAP = {
|
|
|
843
847
|
pkg: "@celerity-sdk/queue",
|
|
844
848
|
className: "QueueLayer"
|
|
845
849
|
},
|
|
850
|
+
topic: {
|
|
851
|
+
pkg: "@celerity-sdk/topic",
|
|
852
|
+
className: "TopicLayer"
|
|
853
|
+
},
|
|
846
854
|
cache: {
|
|
847
855
|
pkg: "@celerity-sdk/cache",
|
|
848
856
|
className: "CacheLayer"
|
|
857
|
+
},
|
|
858
|
+
sqlDatabase: {
|
|
859
|
+
pkg: "@celerity-sdk/sql-database",
|
|
860
|
+
className: "SqlDatabaseLayer"
|
|
849
861
|
}
|
|
850
862
|
};
|
|
851
863
|
async function createDefaultSystemLayers() {
|
|
@@ -1323,6 +1335,7 @@ __name(matchRoute, "matchRoute");
|
|
|
1323
1335
|
// src/bootstrap/module-graph.ts
|
|
1324
1336
|
import "reflect-metadata";
|
|
1325
1337
|
import createDebug4 from "debug";
|
|
1338
|
+
import { isResourceLayerToken } from "@celerity-sdk/common";
|
|
1326
1339
|
var debug4 = createDebug4("celerity:core:bootstrap");
|
|
1327
1340
|
function buildModuleGraph(rootModule) {
|
|
1328
1341
|
const graph = /* @__PURE__ */ new Map();
|
|
@@ -1511,6 +1524,7 @@ function checkDependencies(consumer, depTokens, visibleTokens, moduleClass, grap
|
|
|
1511
1524
|
checkDependencies(dep, adoptedDeps, visibleTokens, moduleClass, graph, container, diagnostics);
|
|
1512
1525
|
continue;
|
|
1513
1526
|
}
|
|
1527
|
+
if (isResourceLayerToken(dep)) continue;
|
|
1514
1528
|
diagnostics.push({
|
|
1515
1529
|
type: "missing_dependency",
|
|
1516
1530
|
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.`
|
|
@@ -1566,8 +1580,7 @@ __name(scanModule, "scanModule");
|
|
|
1566
1580
|
async function scanClassHandler(controllerClass, container, registry) {
|
|
1567
1581
|
const controllerMeta = Reflect.getOwnMetadata(CONTROLLER_METADATA, controllerClass);
|
|
1568
1582
|
if (!controllerMeta) return;
|
|
1569
|
-
const
|
|
1570
|
-
const prototype = Object.getPrototypeOf(instance);
|
|
1583
|
+
const prototype = controllerClass.prototype;
|
|
1571
1584
|
const methods = Object.getOwnPropertyNames(prototype).filter((name) => name !== "constructor");
|
|
1572
1585
|
const classProtectedBy = Reflect.getOwnMetadata(GUARD_PROTECTEDBY_METADATA, controllerClass) ?? [];
|
|
1573
1586
|
const classLayers = Reflect.getOwnMetadata(LAYER_METADATA, controllerClass) ?? [];
|
|
@@ -1609,7 +1622,7 @@ async function scanClassHandler(controllerClass, container, registry) {
|
|
|
1609
1622
|
...methodCustomMetadata
|
|
1610
1623
|
},
|
|
1611
1624
|
handlerFn: descriptor.value,
|
|
1612
|
-
|
|
1625
|
+
controllerClass
|
|
1613
1626
|
});
|
|
1614
1627
|
}
|
|
1615
1628
|
}
|
|
@@ -1650,8 +1663,7 @@ __name(scanFunctionHandler, "scanFunctionHandler");
|
|
|
1650
1663
|
async function scanClassGuard(guardClass, container, registry) {
|
|
1651
1664
|
const guardName = Reflect.getOwnMetadata(GUARD_CUSTOM_METADATA, guardClass);
|
|
1652
1665
|
if (!guardName) return;
|
|
1653
|
-
const
|
|
1654
|
-
const prototype = Object.getPrototypeOf(instance);
|
|
1666
|
+
const prototype = guardClass.prototype;
|
|
1655
1667
|
const descriptor = Object.getOwnPropertyDescriptor(prototype, "check");
|
|
1656
1668
|
if (!descriptor?.value || typeof descriptor.value !== "function") {
|
|
1657
1669
|
debug5("scanClassGuard: %s has no check() method, skipping", guardClass.name);
|
|
@@ -1663,7 +1675,7 @@ async function scanClassGuard(guardClass, container, registry) {
|
|
|
1663
1675
|
registry.registerGuard({
|
|
1664
1676
|
name: guardName,
|
|
1665
1677
|
handlerFn: descriptor.value,
|
|
1666
|
-
|
|
1678
|
+
guardClass,
|
|
1667
1679
|
paramMetadata,
|
|
1668
1680
|
customMetadata
|
|
1669
1681
|
});
|
|
@@ -1766,8 +1778,7 @@ __name(scanWebSocketHandlers, "scanWebSocketHandlers");
|
|
|
1766
1778
|
async function scanClassHandler2(controllerClass, container, registry) {
|
|
1767
1779
|
const isWsController = Reflect.getOwnMetadata(WEBSOCKET_CONTROLLER_METADATA, controllerClass);
|
|
1768
1780
|
if (!isWsController) return;
|
|
1769
|
-
const
|
|
1770
|
-
const prototype = Object.getPrototypeOf(instance);
|
|
1781
|
+
const prototype = controllerClass.prototype;
|
|
1771
1782
|
const methods = Object.getOwnPropertyNames(prototype).filter((name) => name !== "constructor");
|
|
1772
1783
|
const classProtectedBy = Reflect.getOwnMetadata(GUARD_PROTECTEDBY_METADATA, controllerClass) ?? [];
|
|
1773
1784
|
const classLayers = Reflect.getOwnMetadata(LAYER_METADATA, controllerClass) ?? [];
|
|
@@ -1804,7 +1815,7 @@ async function scanClassHandler2(controllerClass, container, registry) {
|
|
|
1804
1815
|
...methodCustomMetadata
|
|
1805
1816
|
},
|
|
1806
1817
|
handlerFn: descriptor.value,
|
|
1807
|
-
|
|
1818
|
+
controllerClass
|
|
1808
1819
|
});
|
|
1809
1820
|
}
|
|
1810
1821
|
}
|
|
@@ -1855,8 +1866,7 @@ __name(scanConsumerHandlers, "scanConsumerHandlers");
|
|
|
1855
1866
|
async function scanClassHandler3(controllerClass, container, registry) {
|
|
1856
1867
|
const consumerMeta = Reflect.getOwnMetadata(CONSUMER_METADATA, controllerClass);
|
|
1857
1868
|
if (!consumerMeta) return;
|
|
1858
|
-
const
|
|
1859
|
-
const prototype = Object.getPrototypeOf(instance);
|
|
1869
|
+
const prototype = controllerClass.prototype;
|
|
1860
1870
|
const methods = Object.getOwnPropertyNames(prototype).filter((name) => name !== "constructor");
|
|
1861
1871
|
const classLayers = Reflect.getOwnMetadata(LAYER_METADATA, controllerClass) ?? [];
|
|
1862
1872
|
const classCustomMetadata = Reflect.getOwnMetadata(CUSTOM_METADATA, controllerClass) ?? {};
|
|
@@ -1868,7 +1878,7 @@ async function scanClassHandler3(controllerClass, container, registry) {
|
|
|
1868
1878
|
const methodCustomMetadata = Reflect.getOwnMetadata(CUSTOM_METADATA, prototype, methodName) ?? {};
|
|
1869
1879
|
const descriptor = Object.getOwnPropertyDescriptor(prototype, methodName);
|
|
1870
1880
|
if (!descriptor?.value || typeof descriptor.value !== "function") continue;
|
|
1871
|
-
const handlerTag =
|
|
1881
|
+
const handlerTag = consumerMeta.source ? `${consumerMeta.source}::${methodName}` : methodName;
|
|
1872
1882
|
const layers = [
|
|
1873
1883
|
...classLayers,
|
|
1874
1884
|
...methodLayers
|
|
@@ -1890,7 +1900,7 @@ async function scanClassHandler3(controllerClass, container, registry) {
|
|
|
1890
1900
|
...methodCustomMetadata
|
|
1891
1901
|
},
|
|
1892
1902
|
handlerFn: descriptor.value,
|
|
1893
|
-
|
|
1903
|
+
controllerClass
|
|
1894
1904
|
});
|
|
1895
1905
|
}
|
|
1896
1906
|
}
|
|
@@ -1898,7 +1908,7 @@ __name(scanClassHandler3, "scanClassHandler");
|
|
|
1898
1908
|
function scanFunctionHandler3(definition, registry) {
|
|
1899
1909
|
if (definition.type !== "consumer") return;
|
|
1900
1910
|
const meta = definition.metadata;
|
|
1901
|
-
const handlerTag =
|
|
1911
|
+
const handlerTag = definition.id ?? "default";
|
|
1902
1912
|
const layers = [
|
|
1903
1913
|
...meta.layers ?? []
|
|
1904
1914
|
];
|
|
@@ -1938,8 +1948,7 @@ async function scanScheduleHandlers(graph, container, registry) {
|
|
|
1938
1948
|
}
|
|
1939
1949
|
__name(scanScheduleHandlers, "scanScheduleHandlers");
|
|
1940
1950
|
async function scanClassHandler4(controllerClass, container, registry) {
|
|
1941
|
-
const
|
|
1942
|
-
const prototype = Object.getPrototypeOf(instance);
|
|
1951
|
+
const prototype = controllerClass.prototype;
|
|
1943
1952
|
const methods = Object.getOwnPropertyNames(prototype).filter((name) => name !== "constructor");
|
|
1944
1953
|
const classLayers = Reflect.getOwnMetadata(LAYER_METADATA, controllerClass) ?? [];
|
|
1945
1954
|
const classCustomMetadata = Reflect.getOwnMetadata(CUSTOM_METADATA, controllerClass) ?? {};
|
|
@@ -1951,7 +1960,7 @@ async function scanClassHandler4(controllerClass, container, registry) {
|
|
|
1951
1960
|
const methodCustomMetadata = Reflect.getOwnMetadata(CUSTOM_METADATA, prototype, methodName) ?? {};
|
|
1952
1961
|
const descriptor = Object.getOwnPropertyDescriptor(prototype, methodName);
|
|
1953
1962
|
if (!descriptor?.value || typeof descriptor.value !== "function") continue;
|
|
1954
|
-
const handlerTag = handlerMeta.
|
|
1963
|
+
const handlerTag = handlerMeta.source ? `${handlerMeta.source}::${methodName}` : methodName;
|
|
1955
1964
|
const layers = [
|
|
1956
1965
|
...classLayers,
|
|
1957
1966
|
...methodLayers
|
|
@@ -1974,12 +1983,12 @@ async function scanClassHandler4(controllerClass, container, registry) {
|
|
|
1974
1983
|
...handlerMeta.schedule ? {
|
|
1975
1984
|
schedule: handlerMeta.schedule
|
|
1976
1985
|
} : {},
|
|
1977
|
-
...handlerMeta.
|
|
1978
|
-
|
|
1986
|
+
...handlerMeta.source ? {
|
|
1987
|
+
source: handlerMeta.source
|
|
1979
1988
|
} : {}
|
|
1980
1989
|
},
|
|
1981
1990
|
handlerFn: descriptor.value,
|
|
1982
|
-
|
|
1991
|
+
controllerClass
|
|
1983
1992
|
});
|
|
1984
1993
|
}
|
|
1985
1994
|
}
|
|
@@ -1987,7 +1996,7 @@ __name(scanClassHandler4, "scanClassHandler");
|
|
|
1987
1996
|
function scanFunctionHandler4(definition, registry) {
|
|
1988
1997
|
if (definition.type !== "schedule") return;
|
|
1989
1998
|
const meta = definition.metadata;
|
|
1990
|
-
const handlerTag = meta.
|
|
1999
|
+
const handlerTag = meta.source ?? definition.id ?? "default";
|
|
1991
2000
|
const layers = [
|
|
1992
2001
|
...meta.layers ?? []
|
|
1993
2002
|
];
|
|
@@ -2000,7 +2009,7 @@ function scanFunctionHandler4(definition, registry) {
|
|
|
2000
2009
|
...meta.customMetadata ?? {}
|
|
2001
2010
|
};
|
|
2002
2011
|
if (meta.schedule) customMetadata.schedule = meta.schedule;
|
|
2003
|
-
if (meta.
|
|
2012
|
+
if (meta.source) customMetadata.source = meta.source;
|
|
2004
2013
|
debug8("scanFunctionHandler: tag=%s", handlerTag);
|
|
2005
2014
|
registry.register({
|
|
2006
2015
|
type: "schedule",
|
|
@@ -2032,8 +2041,7 @@ async function scanCustomHandlers(graph, container, registry) {
|
|
|
2032
2041
|
}
|
|
2033
2042
|
__name(scanCustomHandlers, "scanCustomHandlers");
|
|
2034
2043
|
async function scanClassHandler5(controllerClass, container, registry) {
|
|
2035
|
-
const
|
|
2036
|
-
const prototype = Object.getPrototypeOf(instance);
|
|
2044
|
+
const prototype = controllerClass.prototype;
|
|
2037
2045
|
const methods = Object.getOwnPropertyNames(prototype).filter((name) => name !== "constructor");
|
|
2038
2046
|
const classLayers = Reflect.getOwnMetadata(LAYER_METADATA, controllerClass) ?? [];
|
|
2039
2047
|
const classCustomMetadata = Reflect.getOwnMetadata(CUSTOM_METADATA, controllerClass) ?? {};
|
|
@@ -2066,7 +2074,7 @@ async function scanClassHandler5(controllerClass, container, registry) {
|
|
|
2066
2074
|
...methodCustomMetadata
|
|
2067
2075
|
},
|
|
2068
2076
|
handlerFn: descriptor.value,
|
|
2069
|
-
|
|
2077
|
+
controllerClass
|
|
2070
2078
|
});
|
|
2071
2079
|
}
|
|
2072
2080
|
}
|
|
@@ -2272,6 +2280,28 @@ function buildHttpContext(request, metadata, container, logger) {
|
|
|
2272
2280
|
}
|
|
2273
2281
|
__name(buildHttpContext, "buildHttpContext");
|
|
2274
2282
|
|
|
2283
|
+
// src/handlers/types.ts
|
|
2284
|
+
async function resolveHandlerInstance(handler, container) {
|
|
2285
|
+
if (handler.handlerInstance) return handler.handlerInstance;
|
|
2286
|
+
if (!handler.controllerClass) {
|
|
2287
|
+
throw new Error("Handler has no controllerClass for deferred resolution");
|
|
2288
|
+
}
|
|
2289
|
+
const instance = await container.resolve(handler.controllerClass);
|
|
2290
|
+
handler.handlerInstance = instance;
|
|
2291
|
+
return instance;
|
|
2292
|
+
}
|
|
2293
|
+
__name(resolveHandlerInstance, "resolveHandlerInstance");
|
|
2294
|
+
async function resolveGuardInstance(guard, container) {
|
|
2295
|
+
if (guard.handlerInstance) return guard.handlerInstance;
|
|
2296
|
+
if (!guard.guardClass) {
|
|
2297
|
+
throw new Error("Guard has no guardClass for deferred resolution");
|
|
2298
|
+
}
|
|
2299
|
+
const instance = await container.resolve(guard.guardClass);
|
|
2300
|
+
guard.handlerInstance = instance;
|
|
2301
|
+
return instance;
|
|
2302
|
+
}
|
|
2303
|
+
__name(resolveGuardInstance, "resolveGuardInstance");
|
|
2304
|
+
|
|
2275
2305
|
// src/handlers/http-pipeline.ts
|
|
2276
2306
|
var debug12 = createDebug12("celerity:core:pipeline");
|
|
2277
2307
|
async function executeHttpPipeline(handler, request, options) {
|
|
@@ -2322,6 +2352,9 @@ async function executeHttpPipeline(handler, request, options) {
|
|
|
2322
2352
|
error: message,
|
|
2323
2353
|
...error instanceof Error && error.stack ? {
|
|
2324
2354
|
stack: error.stack
|
|
2355
|
+
} : {},
|
|
2356
|
+
...error instanceof Error && error.cause ? {
|
|
2357
|
+
cause: String(error.cause)
|
|
2325
2358
|
} : {}
|
|
2326
2359
|
});
|
|
2327
2360
|
} else {
|
|
@@ -2347,7 +2380,8 @@ async function invokeClassHandler(handler, context) {
|
|
|
2347
2380
|
for (const meta of sorted) {
|
|
2348
2381
|
args[meta.index] = extractValidatedParam(meta.type, meta.key, context.request, context.metadata);
|
|
2349
2382
|
}
|
|
2350
|
-
|
|
2383
|
+
const instance = await resolveHandlerInstance(handler, context.container);
|
|
2384
|
+
return handler.handlerFn.apply(instance, args);
|
|
2351
2385
|
}
|
|
2352
2386
|
__name(invokeClassHandler, "invokeClassHandler");
|
|
2353
2387
|
var VALIDATED_METADATA_KEYS = {
|
|
@@ -2446,6 +2480,9 @@ async function executeWebSocketPipeline(handler, message, options) {
|
|
|
2446
2480
|
eventType: message.eventType,
|
|
2447
2481
|
...error instanceof Error && error.stack ? {
|
|
2448
2482
|
stack: error.stack
|
|
2483
|
+
} : {},
|
|
2484
|
+
...error instanceof Error && error.cause ? {
|
|
2485
|
+
cause: String(error.cause)
|
|
2449
2486
|
} : {}
|
|
2450
2487
|
});
|
|
2451
2488
|
} else {
|
|
@@ -2462,7 +2499,8 @@ async function invokeClassHandler2(handler, context) {
|
|
|
2462
2499
|
for (const meta of sorted) {
|
|
2463
2500
|
args[meta.index] = extractWebSocketParam(meta, context);
|
|
2464
2501
|
}
|
|
2465
|
-
await
|
|
2502
|
+
const instance = await resolveHandlerInstance(handler, context.container);
|
|
2503
|
+
await handler.handlerFn.apply(instance, args);
|
|
2466
2504
|
}
|
|
2467
2505
|
__name(invokeClassHandler2, "invokeClassHandler");
|
|
2468
2506
|
async function invokeFunctionHandler2(handler, context) {
|
|
@@ -2560,6 +2598,9 @@ async function executeConsumerPipeline(handler, event, options) {
|
|
|
2560
2598
|
messageCount: event.messages.length,
|
|
2561
2599
|
...error instanceof Error && error.stack ? {
|
|
2562
2600
|
stack: error.stack
|
|
2601
|
+
} : {},
|
|
2602
|
+
...error instanceof Error && error.cause ? {
|
|
2603
|
+
cause: String(error.cause)
|
|
2563
2604
|
} : {}
|
|
2564
2605
|
});
|
|
2565
2606
|
} else {
|
|
@@ -2581,7 +2622,8 @@ async function invokeClassHandler3(handler, context, validatedMessages, rawMessa
|
|
|
2581
2622
|
for (const meta of sorted) {
|
|
2582
2623
|
args[meta.index] = extractConsumerParam(meta, context, validatedMessages, rawMessages);
|
|
2583
2624
|
}
|
|
2584
|
-
|
|
2625
|
+
const instance = await resolveHandlerInstance(handler, context.container);
|
|
2626
|
+
return await handler.handlerFn.apply(instance, args);
|
|
2585
2627
|
}
|
|
2586
2628
|
__name(invokeClassHandler3, "invokeClassHandler");
|
|
2587
2629
|
async function invokeFunctionHandler3(handler, context, validatedMessages, _rawMessages) {
|
|
@@ -2654,6 +2696,9 @@ async function executeSchedulePipeline(handler, event, options) {
|
|
|
2654
2696
|
scheduleId: event.scheduleId,
|
|
2655
2697
|
...error instanceof Error && error.stack ? {
|
|
2656
2698
|
stack: error.stack
|
|
2699
|
+
} : {},
|
|
2700
|
+
...error instanceof Error && error.cause ? {
|
|
2701
|
+
cause: String(error.cause)
|
|
2657
2702
|
} : {}
|
|
2658
2703
|
});
|
|
2659
2704
|
} else {
|
|
@@ -2675,7 +2720,8 @@ async function invokeClassHandler4(handler, context, validatedInput) {
|
|
|
2675
2720
|
for (const meta of sorted) {
|
|
2676
2721
|
args[meta.index] = extractScheduleParam(meta, context, validatedInput);
|
|
2677
2722
|
}
|
|
2678
|
-
|
|
2723
|
+
const instance = await resolveHandlerInstance(handler, context.container);
|
|
2724
|
+
return await handler.handlerFn.apply(instance, args);
|
|
2679
2725
|
}
|
|
2680
2726
|
__name(invokeClassHandler4, "invokeClassHandler");
|
|
2681
2727
|
async function invokeFunctionHandler4(handler, context, _validatedInput) {
|
|
@@ -2746,7 +2792,8 @@ async function invokeClassHandler5(handler, context, validatedPayload) {
|
|
|
2746
2792
|
for (const meta of sorted) {
|
|
2747
2793
|
args[meta.index] = extractCustomParam(meta, context, validatedPayload);
|
|
2748
2794
|
}
|
|
2749
|
-
|
|
2795
|
+
const instance = await resolveHandlerInstance(handler, context.container);
|
|
2796
|
+
return handler.handlerFn.apply(instance, args);
|
|
2750
2797
|
}
|
|
2751
2798
|
__name(invokeClassHandler5, "invokeClassHandler");
|
|
2752
2799
|
async function invokeFunctionHandler5(handler, context, validatedPayload) {
|
|
@@ -3103,7 +3150,7 @@ function createScheduleHandler(configOrString, configOrHandler, maybeHandler) {
|
|
|
3103
3150
|
if (isScheduleExpression2(configOrString)) {
|
|
3104
3151
|
config.schedule = configOrString;
|
|
3105
3152
|
} else {
|
|
3106
|
-
config.
|
|
3153
|
+
config.source = configOrString;
|
|
3107
3154
|
}
|
|
3108
3155
|
} else {
|
|
3109
3156
|
config = configOrString;
|
|
@@ -3114,7 +3161,7 @@ function createScheduleHandler(configOrString, configOrHandler, maybeHandler) {
|
|
|
3114
3161
|
inject: config.inject ?? [],
|
|
3115
3162
|
customMetadata: config.metadata ?? {}
|
|
3116
3163
|
};
|
|
3117
|
-
if (config.
|
|
3164
|
+
if (config.source !== void 0) metadata.source = config.source;
|
|
3118
3165
|
if (config.schedule !== void 0) metadata.schedule = config.schedule;
|
|
3119
3166
|
if (config.schema !== void 0) metadata.schema = config.schema;
|
|
3120
3167
|
return {
|
|
@@ -3237,7 +3284,7 @@ function buildResolvedFromExport(handlerId, handlerType, handlerFn, fnDef) {
|
|
|
3237
3284
|
return {
|
|
3238
3285
|
...base,
|
|
3239
3286
|
type: "schedule",
|
|
3240
|
-
handlerTag: meta?.
|
|
3287
|
+
handlerTag: meta?.source ?? handlerId
|
|
3241
3288
|
};
|
|
3242
3289
|
case "custom":
|
|
3243
3290
|
return {
|
|
@@ -3356,7 +3403,8 @@ async function invokeClassGuard(guard, input, metadata, options, logger) {
|
|
|
3356
3403
|
args[i] = guardContext;
|
|
3357
3404
|
}
|
|
3358
3405
|
}
|
|
3359
|
-
|
|
3406
|
+
const instance = await resolveGuardInstance(guard, options.container);
|
|
3407
|
+
return guard.handlerFn.apply(instance, args);
|
|
3360
3408
|
}
|
|
3361
3409
|
__name(invokeClassGuard, "invokeClassGuard");
|
|
3362
3410
|
async function invokeFunctionGuard(guard, input, metadata, options, logger) {
|
|
@@ -3748,22 +3796,37 @@ __name(registerWebSocketHandlers, "registerWebSocketHandlers");
|
|
|
3748
3796
|
async function registerConsumerHandlers(app, consumers, result) {
|
|
3749
3797
|
for (const consumer of consumers?.consumers ?? []) {
|
|
3750
3798
|
for (const def of consumer.handlers) {
|
|
3751
|
-
const
|
|
3752
|
-
const
|
|
3799
|
+
const methodName = def.handler.split(".").pop() ?? def.name;
|
|
3800
|
+
const lookupKey = `${consumer.consumerName}::${methodName}`;
|
|
3801
|
+
const callback = result.createConsumerCallback(lookupKey, def.name) ?? await result.createConsumerCallbackById(def.handler, def.location, def.name);
|
|
3753
3802
|
if (callback) {
|
|
3754
|
-
app.registerConsumerHandler(
|
|
3803
|
+
app.registerConsumerHandler(def.name, def.timeout, callback);
|
|
3755
3804
|
}
|
|
3756
3805
|
}
|
|
3757
3806
|
}
|
|
3758
3807
|
}
|
|
3759
3808
|
__name(registerConsumerHandlers, "registerConsumerHandlers");
|
|
3809
|
+
async function registerEventHandlers(app, events, result) {
|
|
3810
|
+
for (const event of events?.events ?? []) {
|
|
3811
|
+
for (const def of event.handlers) {
|
|
3812
|
+
const methodName = def.handler.split(".").pop() ?? def.name;
|
|
3813
|
+
const lookupKey = `${event.consumerName}::${methodName}`;
|
|
3814
|
+
const callback = result.createConsumerCallback(lookupKey, def.name) ?? await result.createConsumerCallbackById(def.handler, def.location, def.name);
|
|
3815
|
+
if (callback) {
|
|
3816
|
+
app.registerConsumerHandler(def.name, def.timeout, callback);
|
|
3817
|
+
}
|
|
3818
|
+
}
|
|
3819
|
+
}
|
|
3820
|
+
}
|
|
3821
|
+
__name(registerEventHandlers, "registerEventHandlers");
|
|
3760
3822
|
async function registerScheduleHandlers(app, schedules, result) {
|
|
3761
3823
|
for (const schedule of schedules?.schedules ?? []) {
|
|
3762
3824
|
for (const def of schedule.handlers) {
|
|
3763
|
-
const
|
|
3764
|
-
const
|
|
3825
|
+
const methodName = def.handler.split(".").pop() ?? def.name;
|
|
3826
|
+
const lookupKey = `${schedule.scheduleId}::${methodName}`;
|
|
3827
|
+
const callback = result.createScheduleCallback(lookupKey, def.name) ?? await result.createScheduleCallbackById(def.handler, def.location, def.name);
|
|
3765
3828
|
if (callback) {
|
|
3766
|
-
app.registerScheduleHandler(
|
|
3829
|
+
app.registerScheduleHandler(def.name, def.timeout, callback);
|
|
3767
3830
|
}
|
|
3768
3831
|
}
|
|
3769
3832
|
}
|
|
@@ -3785,6 +3848,7 @@ async function startRuntime(options) {
|
|
|
3785
3848
|
await registerGuardHandlers(app, appConfig.api?.guards, result);
|
|
3786
3849
|
await registerWebSocketHandlers(app, appConfig.api?.websocket, result);
|
|
3787
3850
|
await registerConsumerHandlers(app, appConfig.consumers, result);
|
|
3851
|
+
await registerEventHandlers(app, appConfig.events, result);
|
|
3788
3852
|
await registerScheduleHandlers(app, appConfig.schedules, result);
|
|
3789
3853
|
await registerCustomHandlers(app, appConfig.customHandlers, result);
|
|
3790
3854
|
if (appConfig.api?.websocket) {
|