@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.d.cts CHANGED
@@ -153,6 +153,7 @@ declare const APP_CONFIG: unique symbol;
153
153
  declare const RUNTIME_APP: unique symbol;
154
154
 
155
155
  type ResolvedHandler = {
156
+ id?: string;
156
157
  path?: string;
157
158
  method?: string;
158
159
  protectedBy: string[];
@@ -200,6 +201,7 @@ declare function registerModuleGraph(graph: ModuleGraph, container: Container):
200
201
  declare class HandlerRegistry {
201
202
  private handlers;
202
203
  getHandler(path: string, method: string): ResolvedHandler | undefined;
204
+ getHandlerById(id: string): ResolvedHandler | undefined;
203
205
  getAllHandlers(): ResolvedHandler[];
204
206
  populateFromGraph(graph: ModuleGraph, container: Container): Promise<void>;
205
207
  scanModule(moduleClass: Type, container: Container): Promise<void>;
@@ -408,11 +410,14 @@ declare function mapRuntimeRequest(request: Request): HttpRequest;
408
410
  /** Convert SDK HttpResponse → NAPI runtime Response. */
409
411
  declare function mapToRuntimeResponse(response: HttpResponse): Response;
410
412
 
413
+ type RuntimeCallback = (err: Error | null, request: Request) => Promise<Response>;
411
414
  type RuntimeBootstrapResult = {
412
415
  registry: HandlerRegistry;
413
416
  container: Container;
414
417
  /** Create a runtime-compatible handler callback for a specific route. */
415
- createRouteCallback(path: string, method: string): ((err: Error | null, request: Request) => Promise<Response>) | null;
418
+ createRouteCallback(path: string, method: string): RuntimeCallback | null;
419
+ /** Create a runtime-compatible handler callback by handler ID (blueprint handler field). */
420
+ createRouteCallbackById(handlerId: string): RuntimeCallback | null;
416
421
  };
417
422
  /**
418
423
  * Bootstrap the user's module and return an object with per-route callback creation.
package/dist/index.d.ts CHANGED
@@ -153,6 +153,7 @@ declare const APP_CONFIG: unique symbol;
153
153
  declare const RUNTIME_APP: unique symbol;
154
154
 
155
155
  type ResolvedHandler = {
156
+ id?: string;
156
157
  path?: string;
157
158
  method?: string;
158
159
  protectedBy: string[];
@@ -200,6 +201,7 @@ declare function registerModuleGraph(graph: ModuleGraph, container: Container):
200
201
  declare class HandlerRegistry {
201
202
  private handlers;
202
203
  getHandler(path: string, method: string): ResolvedHandler | undefined;
204
+ getHandlerById(id: string): ResolvedHandler | undefined;
203
205
  getAllHandlers(): ResolvedHandler[];
204
206
  populateFromGraph(graph: ModuleGraph, container: Container): Promise<void>;
205
207
  scanModule(moduleClass: Type, container: Container): Promise<void>;
@@ -408,11 +410,14 @@ declare function mapRuntimeRequest(request: Request): HttpRequest;
408
410
  /** Convert SDK HttpResponse → NAPI runtime Response. */
409
411
  declare function mapToRuntimeResponse(response: HttpResponse): Response;
410
412
 
413
+ type RuntimeCallback = (err: Error | null, request: Request) => Promise<Response>;
411
414
  type RuntimeBootstrapResult = {
412
415
  registry: HandlerRegistry;
413
416
  container: Container;
414
417
  /** Create a runtime-compatible handler callback for a specific route. */
415
- createRouteCallback(path: string, method: string): ((err: Error | null, request: Request) => Promise<Response>) | null;
418
+ createRouteCallback(path: string, method: string): RuntimeCallback | null;
419
+ /** Create a runtime-compatible handler callback by handler ID (blueprint handler field). */
420
+ createRouteCallbackById(handlerId: string): RuntimeCallback | null;
416
421
  };
417
422
  /**
418
423
  * Bootstrap the user's module and return an object with per-route callback creation.
package/dist/index.js CHANGED
@@ -1055,6 +1055,11 @@ var HandlerRegistry = class {
1055
1055
  debug4("getHandler %s %s \u2192 %s", method, path, found ? "matched" : "not found");
1056
1056
  return found;
1057
1057
  }
1058
+ getHandlerById(id) {
1059
+ const found = this.handlers.find((h) => h.id !== void 0 && h.id === id);
1060
+ debug4("getHandlerById %s \u2192 %s", id, found ? "matched" : "not found");
1061
+ return found;
1062
+ }
1058
1063
  getAllHandlers() {
1059
1064
  return [
1060
1065
  ...this.handlers
@@ -1140,8 +1145,9 @@ var HandlerRegistry = class {
1140
1145
  layers.unshift(validate(schemas));
1141
1146
  }
1142
1147
  }
1143
- debug4("registerFunctionHandler: %s", meta.method && meta.path ? `${meta.method} ${meta.path}` : "(no route)");
1148
+ debug4("registerFunctionHandler: %s", definition.id ?? (meta.method && meta.path ? `${meta.method} ${meta.path}` : "(no route)"));
1144
1149
  this.handlers.push({
1150
+ id: definition.id,
1145
1151
  path: meta.path,
1146
1152
  method: meta.method,
1147
1153
  protectedBy: [],
@@ -1759,20 +1765,26 @@ async function bootstrapForRuntime(modulePath, systemLayers) {
1759
1765
  const layers = systemLayers ?? await createDefaultSystemLayers();
1760
1766
  const rootModule = await discoverModule(modulePath);
1761
1767
  const { container, registry } = await bootstrap(rootModule);
1768
+ function buildCallback(handler) {
1769
+ if (!handler) return null;
1770
+ return async (_err, request) => {
1771
+ const httpRequest = mapRuntimeRequest(request);
1772
+ const httpResponse = await executeHandlerPipeline(handler, httpRequest, {
1773
+ container,
1774
+ systemLayers: layers
1775
+ });
1776
+ return mapToRuntimeResponse(httpResponse);
1777
+ };
1778
+ }
1779
+ __name(buildCallback, "buildCallback");
1762
1780
  return {
1763
1781
  registry,
1764
1782
  container,
1765
1783
  createRouteCallback(path, method) {
1766
- const handler = registry.getHandler(path, method);
1767
- if (!handler) return null;
1768
- return async (_err, request) => {
1769
- const httpRequest = mapRuntimeRequest(request);
1770
- const httpResponse = await executeHandlerPipeline(handler, httpRequest, {
1771
- container,
1772
- systemLayers: layers
1773
- });
1774
- return mapToRuntimeResponse(httpResponse);
1775
- };
1784
+ return buildCallback(registry.getHandler(path, method));
1785
+ },
1786
+ createRouteCallbackById(handlerId) {
1787
+ return buildCallback(registry.getHandlerById(handlerId));
1776
1788
  }
1777
1789
  };
1778
1790
  }
@@ -1787,7 +1799,7 @@ async function startRuntime(options) {
1787
1799
  const appConfig = app.setup();
1788
1800
  const result = await bootstrapForRuntime();
1789
1801
  for (const def of appConfig.api?.http?.handlers ?? []) {
1790
- const callback = result.createRouteCallback(def.path, def.method);
1802
+ const callback = result.createRouteCallback(def.path, def.method) ?? result.createRouteCallbackById(def.handler);
1791
1803
  if (callback) {
1792
1804
  app.registerHttpHandler(def.path, def.method, def.timeout, callback);
1793
1805
  }