@celerity-sdk/core 0.2.0 → 0.2.1

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
@@ -1171,6 +1171,11 @@ var HandlerRegistry = class {
1171
1171
  debug4("getHandler %s %s \u2192 %s", method, path, found ? "matched" : "not found");
1172
1172
  return found;
1173
1173
  }
1174
+ getHandlerById(id) {
1175
+ const found = this.handlers.find((h) => h.id !== void 0 && h.id === id);
1176
+ debug4("getHandlerById %s \u2192 %s", id, found ? "matched" : "not found");
1177
+ return found;
1178
+ }
1174
1179
  getAllHandlers() {
1175
1180
  return [
1176
1181
  ...this.handlers
@@ -1256,8 +1261,9 @@ var HandlerRegistry = class {
1256
1261
  layers.unshift(validate(schemas));
1257
1262
  }
1258
1263
  }
1259
- debug4("registerFunctionHandler: %s", meta.method && meta.path ? `${meta.method} ${meta.path}` : "(no route)");
1264
+ debug4("registerFunctionHandler: %s", definition.id ?? (meta.method && meta.path ? `${meta.method} ${meta.path}` : "(no route)"));
1260
1265
  this.handlers.push({
1266
+ id: definition.id,
1261
1267
  path: meta.path,
1262
1268
  method: meta.method,
1263
1269
  protectedBy: [],
@@ -1875,20 +1881,26 @@ async function bootstrapForRuntime(modulePath, systemLayers) {
1875
1881
  const layers = systemLayers ?? await createDefaultSystemLayers();
1876
1882
  const rootModule = await discoverModule(modulePath);
1877
1883
  const { container, registry } = await bootstrap(rootModule);
1884
+ function buildCallback(handler) {
1885
+ if (!handler) return null;
1886
+ return async (_err, request) => {
1887
+ const httpRequest = mapRuntimeRequest(request);
1888
+ const httpResponse = await executeHandlerPipeline(handler, httpRequest, {
1889
+ container,
1890
+ systemLayers: layers
1891
+ });
1892
+ return mapToRuntimeResponse(httpResponse);
1893
+ };
1894
+ }
1895
+ __name(buildCallback, "buildCallback");
1878
1896
  return {
1879
1897
  registry,
1880
1898
  container,
1881
1899
  createRouteCallback(path, method) {
1882
- const handler = registry.getHandler(path, method);
1883
- if (!handler) return null;
1884
- return async (_err, request) => {
1885
- const httpRequest = mapRuntimeRequest(request);
1886
- const httpResponse = await executeHandlerPipeline(handler, httpRequest, {
1887
- container,
1888
- systemLayers: layers
1889
- });
1890
- return mapToRuntimeResponse(httpResponse);
1891
- };
1900
+ return buildCallback(registry.getHandler(path, method));
1901
+ },
1902
+ createRouteCallbackById(handlerId) {
1903
+ return buildCallback(registry.getHandlerById(handlerId));
1892
1904
  }
1893
1905
  };
1894
1906
  }
@@ -1903,7 +1915,7 @@ async function startRuntime(options) {
1903
1915
  const appConfig = app.setup();
1904
1916
  const result = await bootstrapForRuntime();
1905
1917
  for (const def of appConfig.api?.http?.handlers ?? []) {
1906
- const callback = result.createRouteCallback(def.path, def.method);
1918
+ const callback = result.createRouteCallback(def.path, def.method) ?? result.createRouteCallbackById(def.handler);
1907
1919
  if (callback) {
1908
1920
  app.registerHttpHandler(def.path, def.method, def.timeout, callback);
1909
1921
  }