@celerity-sdk/cli 0.3.1 → 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/dist/index.js CHANGED
@@ -4,6 +4,7 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
4
4
  // src/extract/metadata-app.ts
5
5
  import "reflect-metadata";
6
6
  import createDebug from "debug";
7
+ import { isResourceLayerToken } from "@celerity-sdk/common";
7
8
  import { buildModuleGraph, getClassDependencyTokens, getProviderDependencyTokens } from "@celerity-sdk/core";
8
9
  var debug = createDebug("celerity:cli");
9
10
  function scanProvider(provider, seenTokens) {
@@ -30,10 +31,12 @@ function buildScannedModule(rootModule) {
30
31
  const graph = buildModuleGraph(rootModule);
31
32
  const controllerClasses = [];
32
33
  const functionHandlers = [];
34
+ const guardClasses = [];
35
+ const functionGuards = [];
33
36
  const providers = [];
34
37
  const seenTokens = /* @__PURE__ */ new Set();
35
38
  for (const [moduleClass, node] of graph) {
36
- debug("scan: module %s \u2014 %d providers, %d controllers", moduleClass.name, node.providers.length, node.controllers.length);
39
+ debug("scan: module %s \u2014 %d providers, %d controllers, %d guards", moduleClass.name, node.providers.length, node.controllers.length, node.guards.length);
37
40
  for (const provider of node.providers) {
38
41
  const scanned = scanProvider(provider, seenTokens);
39
42
  if (scanned) providers.push(scanned);
@@ -49,11 +52,28 @@ function buildScannedModule(rootModule) {
49
52
  });
50
53
  }
51
54
  }
55
+ for (const guard of node.guards) {
56
+ if (typeof guard === "function") {
57
+ guardClasses.push(guard);
58
+ if (!seenTokens.has(guard)) {
59
+ seenTokens.add(guard);
60
+ providers.push({
61
+ token: guard,
62
+ providerType: "class",
63
+ dependencies: getClassDependencyTokens(guard)
64
+ });
65
+ }
66
+ } else {
67
+ functionGuards.push(guard);
68
+ }
69
+ }
52
70
  functionHandlers.push(...node.functionHandlers);
53
71
  }
54
72
  return {
55
73
  controllerClasses,
56
74
  functionHandlers,
75
+ guardClasses,
76
+ functionGuards,
57
77
  providers
58
78
  };
59
79
  }
@@ -73,7 +93,7 @@ function validateScannedDependencies(scanned) {
73
93
  }
74
94
  } else if (typeof dep === "function") {
75
95
  walk(dep, getClassDependencyTokens(dep));
76
- } else {
96
+ } else if (!isResourceLayerToken(dep)) {
77
97
  diagnostics.push({
78
98
  consumer: serializeToken(token),
79
99
  dependency: serializeToken(dep)
@@ -97,7 +117,7 @@ __name(serializeToken, "serializeToken");
97
117
 
98
118
  // src/extract/serializer.ts
99
119
  import "reflect-metadata";
100
- import { CONTROLLER_METADATA, HTTP_METHOD_METADATA, ROUTE_PATH_METADATA, GUARD_PROTECTEDBY_METADATA, GUARD_CUSTOM_METADATA, PUBLIC_METADATA, CUSTOM_METADATA } from "@celerity-sdk/core";
120
+ import { CONTROLLER_METADATA, HTTP_METHOD_METADATA, ROUTE_PATH_METADATA, WEBSOCKET_CONTROLLER_METADATA, WEBSOCKET_EVENT_METADATA, CONSUMER_METADATA, CONSUMER_HANDLER_METADATA, SCHEDULE_HANDLER_METADATA, INVOKE_METADATA, GUARD_PROTECTEDBY_METADATA, GUARD_CUSTOM_METADATA, PUBLIC_METADATA, CUSTOM_METADATA, USE_RESOURCE_METADATA } from "@celerity-sdk/core";
101
121
 
102
122
  // src/extract/path-utils.ts
103
123
  import { joinHandlerPath } from "@celerity-sdk/common";
@@ -138,8 +158,9 @@ __name(deriveCodeLocation, "deriveCodeLocation");
138
158
  function serializeManifest(scanned, sourceFile, options) {
139
159
  const handlers = [];
140
160
  const functionHandlers = [];
161
+ const guardHandlers = [];
141
162
  for (const controllerClass of scanned.controllerClasses) {
142
- const entries = serializeClassHandler(controllerClass, sourceFile, options);
163
+ const entries = serializeClassHandlers(controllerClass, sourceFile, options);
143
164
  handlers.push(...entries);
144
165
  }
145
166
  for (const fnHandler of scanned.functionHandlers) {
@@ -148,40 +169,76 @@ function serializeManifest(scanned, sourceFile, options) {
148
169
  functionHandlers.push(entry);
149
170
  }
150
171
  }
172
+ for (const guardClass of scanned.guardClasses) {
173
+ const entry = serializeClassGuard(guardClass, sourceFile, options);
174
+ if (entry) {
175
+ guardHandlers.push(entry);
176
+ }
177
+ }
178
+ for (const fnGuard of scanned.functionGuards) {
179
+ const entry = serializeFunctionGuard(fnGuard, sourceFile, options);
180
+ if (entry) {
181
+ guardHandlers.push(entry);
182
+ }
183
+ }
151
184
  return {
152
185
  version: "1.0.0",
153
186
  handlers,
154
187
  functionHandlers,
188
+ guardHandlers,
155
189
  dependencyGraph: serializeDependencyGraph(scanned)
156
190
  };
157
191
  }
158
192
  __name(serializeManifest, "serializeManifest");
159
- function extractClassMeta(controllerClass) {
160
- const controllerMeta = Reflect.getOwnMetadata(CONTROLLER_METADATA, controllerClass);
161
- if (!controllerMeta) return null;
193
+ function extractControllerMeta(controllerClass) {
194
+ const httpMeta = Reflect.getOwnMetadata(CONTROLLER_METADATA, controllerClass);
195
+ if (httpMeta) {
196
+ return {
197
+ controllerType: "http",
198
+ prefix: httpMeta.prefix ?? "",
199
+ ...extractSharedClassMeta(controllerClass)
200
+ };
201
+ }
202
+ const isWebSocket = Reflect.getOwnMetadata(WEBSOCKET_CONTROLLER_METADATA, controllerClass);
203
+ if (isWebSocket) {
204
+ return {
205
+ controllerType: "websocket",
206
+ prefix: "",
207
+ ...extractSharedClassMeta(controllerClass)
208
+ };
209
+ }
210
+ const consumerMeta = Reflect.getOwnMetadata(CONSUMER_METADATA, controllerClass);
211
+ if (consumerMeta) {
212
+ return {
213
+ controllerType: "consumer",
214
+ prefix: "",
215
+ source: consumerMeta.source,
216
+ ...extractSharedClassMeta(controllerClass)
217
+ };
218
+ }
219
+ return null;
220
+ }
221
+ __name(extractControllerMeta, "extractControllerMeta");
222
+ function extractSharedClassMeta(controllerClass) {
162
223
  return {
163
- prefix: controllerMeta.prefix ?? "",
164
224
  protectedBy: Reflect.getOwnMetadata(GUARD_PROTECTEDBY_METADATA, controllerClass) ?? [],
165
225
  customGuardName: Reflect.getOwnMetadata(GUARD_CUSTOM_METADATA, controllerClass),
166
- customMetadata: Reflect.getOwnMetadata(CUSTOM_METADATA, controllerClass) ?? {}
226
+ customMetadata: Reflect.getOwnMetadata(CUSTOM_METADATA, controllerClass) ?? {},
227
+ resourceRefs: Reflect.getOwnMetadata(USE_RESOURCE_METADATA, controllerClass) ?? []
167
228
  };
168
229
  }
169
- __name(extractClassMeta, "extractClassMeta");
170
- function buildMethodAnnotations(classMeta, prototype, methodName, httpMethod, fullPath) {
171
- const annotations = {};
172
- annotations["celerity.handler.http"] = true;
173
- annotations["celerity.handler.http.method"] = httpMethod;
174
- annotations["celerity.handler.http.path"] = fullPath;
230
+ __name(extractSharedClassMeta, "extractSharedClassMeta");
231
+ function appendSharedAnnotations(annotations, meta, prototype, methodName) {
175
232
  const methodProtectedBy = Reflect.getOwnMetadata(GUARD_PROTECTEDBY_METADATA, prototype, methodName) ?? [];
176
233
  const allProtectedBy = [
177
- ...classMeta.protectedBy,
234
+ ...meta.protectedBy,
178
235
  ...methodProtectedBy
179
236
  ];
180
237
  if (allProtectedBy.length > 0) {
181
238
  annotations["celerity.handler.guard.protectedBy"] = allProtectedBy;
182
239
  }
183
- if (classMeta.customGuardName) {
184
- annotations["celerity.handler.guard.custom"] = classMeta.customGuardName;
240
+ if (meta.customGuardName) {
241
+ annotations["celerity.handler.guard.custom"] = meta.customGuardName;
185
242
  }
186
243
  const isPublic = Reflect.getOwnMetadata(PUBLIC_METADATA, prototype, methodName) === true;
187
244
  if (isPublic) {
@@ -189,57 +246,206 @@ function buildMethodAnnotations(classMeta, prototype, methodName, httpMethod, fu
189
246
  }
190
247
  const methodCustomMetadata = Reflect.getOwnMetadata(CUSTOM_METADATA, prototype, methodName) ?? {};
191
248
  const customMetadata = {
192
- ...classMeta.customMetadata,
249
+ ...meta.customMetadata,
193
250
  ...methodCustomMetadata
194
251
  };
195
252
  for (const [key, value] of Object.entries(customMetadata)) {
196
253
  if (value === void 0) continue;
197
254
  annotations[`celerity.handler.metadata.${key}`] = serializeAnnotationValue(value);
198
255
  }
256
+ const methodResourceRefs = Reflect.getOwnMetadata(USE_RESOURCE_METADATA, prototype, methodName) ?? [];
257
+ const allResourceRefs = [
258
+ .../* @__PURE__ */ new Set([
259
+ ...meta.resourceRefs,
260
+ ...methodResourceRefs
261
+ ])
262
+ ];
263
+ if (allResourceRefs.length > 0) {
264
+ annotations["celerity.handler.resource.ref"] = allResourceRefs;
265
+ }
266
+ }
267
+ __name(appendSharedAnnotations, "appendSharedAnnotations");
268
+ function buildHttpAnnotations(meta, prototype, methodName, httpMethod, fullPath) {
269
+ const annotations = {};
270
+ annotations["celerity.handler.http"] = true;
271
+ annotations["celerity.handler.http.method"] = httpMethod;
272
+ annotations["celerity.handler.http.path"] = fullPath;
273
+ appendSharedAnnotations(annotations, meta, prototype, methodName);
274
+ return annotations;
275
+ }
276
+ __name(buildHttpAnnotations, "buildHttpAnnotations");
277
+ function buildWebSocketAnnotations(meta, prototype, methodName, wsEvent) {
278
+ const annotations = {};
279
+ annotations["celerity.handler.websocket"] = true;
280
+ annotations["celerity.handler.websocket.route"] = wsEvent.route;
281
+ annotations["celerity.handler.websocket.eventType"] = wsEvent.eventType;
282
+ appendSharedAnnotations(annotations, meta, prototype, methodName);
283
+ return annotations;
284
+ }
285
+ __name(buildWebSocketAnnotations, "buildWebSocketAnnotations");
286
+ function buildConsumerAnnotations(meta, prototype, methodName, consumerHandler) {
287
+ const annotations = {};
288
+ annotations["celerity.handler.consumer"] = true;
289
+ if (meta.source) {
290
+ annotations["celerity.handler.consumer.source"] = meta.source;
291
+ }
292
+ if (consumerHandler.route) {
293
+ annotations["celerity.handler.consumer.route"] = consumerHandler.route;
294
+ }
295
+ appendSharedAnnotations(annotations, meta, prototype, methodName);
296
+ return annotations;
297
+ }
298
+ __name(buildConsumerAnnotations, "buildConsumerAnnotations");
299
+ function buildScheduleAnnotations(meta, prototype, methodName, scheduleMeta) {
300
+ const annotations = {};
301
+ annotations["celerity.handler.schedule"] = true;
302
+ if (scheduleMeta.source) {
303
+ annotations["celerity.handler.schedule.source"] = scheduleMeta.source;
304
+ }
305
+ if (scheduleMeta.schedule) {
306
+ annotations["celerity.handler.schedule.expression"] = scheduleMeta.schedule;
307
+ }
308
+ appendSharedAnnotations(annotations, meta, prototype, methodName);
309
+ return annotations;
310
+ }
311
+ __name(buildScheduleAnnotations, "buildScheduleAnnotations");
312
+ function buildCustomAnnotations(meta, prototype, methodName, invokeMeta) {
313
+ const annotations = {};
314
+ annotations["celerity.handler.custom"] = true;
315
+ annotations["celerity.handler.custom.name"] = invokeMeta.name;
316
+ appendSharedAnnotations(annotations, meta, prototype, methodName);
199
317
  return annotations;
200
318
  }
201
- __name(buildMethodAnnotations, "buildMethodAnnotations");
202
- function serializeClassHandler(controllerClass, sourceFile, options) {
203
- const classMeta = extractClassMeta(controllerClass);
204
- if (!classMeta) return [];
319
+ __name(buildCustomAnnotations, "buildCustomAnnotations");
320
+ function serializeClassHandlers(controllerClass, sourceFile, options) {
321
+ const meta = extractControllerMeta(controllerClass);
322
+ if (!meta) return [];
205
323
  const className = controllerClass.name;
206
324
  const prototype = controllerClass.prototype;
207
325
  const methods = Object.getOwnPropertyNames(prototype).filter((n) => n !== "constructor");
208
326
  const entries = [];
209
327
  for (const methodName of methods) {
210
- const httpMethod = Reflect.getOwnMetadata(HTTP_METHOD_METADATA, prototype, methodName);
211
- if (!httpMethod) continue;
212
- const routePath = Reflect.getOwnMetadata(ROUTE_PATH_METADATA, prototype, methodName) ?? "/";
213
- const fullPath = joinHandlerPath(classMeta.prefix, routePath);
214
- const annotations = buildMethodAnnotations(classMeta, prototype, methodName, httpMethod, fullPath);
215
- entries.push({
216
- resourceName: deriveClassResourceName(className, methodName),
217
- className,
218
- methodName,
219
- sourceFile,
220
- handlerType: "http",
221
- annotations,
222
- spec: {
223
- handlerName: deriveClassHandlerName(className, methodName),
224
- codeLocation: deriveCodeLocation(sourceFile, options.projectRoot),
225
- handler: deriveClassHandlerFunction(sourceFile, className, methodName)
226
- }
227
- });
328
+ const typeEntry = serializeControllerTypeMethod(meta, className, prototype, methodName, sourceFile, options);
329
+ if (typeEntry) entries.push(typeEntry);
330
+ const scheduleMeta = Reflect.getOwnMetadata(SCHEDULE_HANDLER_METADATA, prototype, methodName);
331
+ if (scheduleMeta) {
332
+ entries.push({
333
+ resourceName: deriveClassResourceName(className, methodName),
334
+ className,
335
+ methodName,
336
+ sourceFile,
337
+ handlerType: "schedule",
338
+ annotations: buildScheduleAnnotations(meta, prototype, methodName, scheduleMeta),
339
+ spec: {
340
+ handlerName: deriveClassHandlerName(className, methodName),
341
+ codeLocation: deriveCodeLocation(sourceFile, options.projectRoot),
342
+ handler: deriveClassHandlerFunction(sourceFile, className, methodName)
343
+ }
344
+ });
345
+ }
346
+ const invokeMeta = Reflect.getOwnMetadata(INVOKE_METADATA, prototype, methodName);
347
+ if (invokeMeta) {
348
+ entries.push({
349
+ resourceName: deriveClassResourceName(className, methodName),
350
+ className,
351
+ methodName,
352
+ sourceFile,
353
+ handlerType: "custom",
354
+ annotations: buildCustomAnnotations(meta, prototype, methodName, invokeMeta),
355
+ spec: {
356
+ handlerName: deriveClassHandlerName(className, methodName),
357
+ codeLocation: deriveCodeLocation(sourceFile, options.projectRoot),
358
+ handler: deriveClassHandlerFunction(sourceFile, className, methodName)
359
+ }
360
+ });
361
+ }
228
362
  }
229
363
  return entries;
230
364
  }
231
- __name(serializeClassHandler, "serializeClassHandler");
365
+ __name(serializeClassHandlers, "serializeClassHandlers");
366
+ function serializeControllerTypeMethod(meta, className, prototype, methodName, sourceFile, options) {
367
+ switch (meta.controllerType) {
368
+ case "http":
369
+ return serializeHttpMethod(meta, className, prototype, methodName, sourceFile, options);
370
+ case "websocket":
371
+ return serializeWebSocketMethod(meta, className, prototype, methodName, sourceFile, options);
372
+ case "consumer":
373
+ return serializeConsumerMethod(meta, className, prototype, methodName, sourceFile, options);
374
+ default:
375
+ return null;
376
+ }
377
+ }
378
+ __name(serializeControllerTypeMethod, "serializeControllerTypeMethod");
379
+ function serializeHttpMethod(meta, className, prototype, methodName, sourceFile, options) {
380
+ const httpMethod = Reflect.getOwnMetadata(HTTP_METHOD_METADATA, prototype, methodName);
381
+ if (!httpMethod) return null;
382
+ const routePath = Reflect.getOwnMetadata(ROUTE_PATH_METADATA, prototype, methodName) ?? "/";
383
+ const fullPath = joinHandlerPath(meta.prefix, routePath);
384
+ return {
385
+ resourceName: deriveClassResourceName(className, methodName),
386
+ className,
387
+ methodName,
388
+ sourceFile,
389
+ handlerType: "http",
390
+ annotations: buildHttpAnnotations(meta, prototype, methodName, httpMethod, fullPath),
391
+ spec: {
392
+ handlerName: deriveClassHandlerName(className, methodName),
393
+ codeLocation: deriveCodeLocation(sourceFile, options.projectRoot),
394
+ handler: deriveClassHandlerFunction(sourceFile, className, methodName)
395
+ }
396
+ };
397
+ }
398
+ __name(serializeHttpMethod, "serializeHttpMethod");
399
+ function serializeWebSocketMethod(meta, className, prototype, methodName, sourceFile, options) {
400
+ const wsEvent = Reflect.getOwnMetadata(WEBSOCKET_EVENT_METADATA, prototype, methodName);
401
+ if (!wsEvent) return null;
402
+ return {
403
+ resourceName: deriveClassResourceName(className, methodName),
404
+ className,
405
+ methodName,
406
+ sourceFile,
407
+ handlerType: "websocket",
408
+ annotations: buildWebSocketAnnotations(meta, prototype, methodName, wsEvent),
409
+ spec: {
410
+ handlerName: deriveClassHandlerName(className, methodName),
411
+ codeLocation: deriveCodeLocation(sourceFile, options.projectRoot),
412
+ handler: deriveClassHandlerFunction(sourceFile, className, methodName)
413
+ }
414
+ };
415
+ }
416
+ __name(serializeWebSocketMethod, "serializeWebSocketMethod");
417
+ function serializeConsumerMethod(meta, className, prototype, methodName, sourceFile, options) {
418
+ const consumerHandler = Reflect.getOwnMetadata(CONSUMER_HANDLER_METADATA, prototype, methodName);
419
+ if (!consumerHandler) return null;
420
+ return {
421
+ resourceName: deriveClassResourceName(className, methodName),
422
+ className,
423
+ methodName,
424
+ sourceFile,
425
+ handlerType: "consumer",
426
+ annotations: buildConsumerAnnotations(meta, prototype, methodName, consumerHandler),
427
+ spec: {
428
+ handlerName: deriveClassHandlerName(className, methodName),
429
+ codeLocation: deriveCodeLocation(sourceFile, options.projectRoot),
430
+ handler: deriveClassHandlerFunction(sourceFile, className, methodName)
431
+ }
432
+ };
433
+ }
434
+ __name(serializeConsumerMethod, "serializeConsumerMethod");
232
435
  function serializeFunctionHandler(definition, sourceFile, options) {
436
+ const supported = [
437
+ "http",
438
+ "websocket",
439
+ "consumer",
440
+ "schedule",
441
+ "custom"
442
+ ];
443
+ if (!supported.includes(definition.type)) return null;
233
444
  const exportName = definition.metadata.handlerName ?? "handler";
234
445
  const customMetadata = definition.metadata.customMetadata ?? {};
446
+ const handlerType = definition.type;
235
447
  const annotations = {};
236
- const path = definition.metadata.path;
237
- const method = definition.metadata.method;
238
- if (path !== void 0 && method !== void 0) {
239
- annotations["celerity.handler.http"] = true;
240
- annotations["celerity.handler.http.method"] = method;
241
- annotations["celerity.handler.http.path"] = path;
242
- }
448
+ buildFunctionTypeAnnotations(annotations, definition);
243
449
  for (const [key, value] of Object.entries(customMetadata)) {
244
450
  if (value === void 0) continue;
245
451
  annotations[`celerity.handler.metadata.${key}`] = serializeAnnotationValue(value);
@@ -248,6 +454,7 @@ function serializeFunctionHandler(definition, sourceFile, options) {
248
454
  resourceName: deriveFunctionResourceName(exportName),
249
455
  exportName,
250
456
  sourceFile,
457
+ handlerType,
251
458
  ...Object.keys(annotations).length > 0 ? {
252
459
  annotations
253
460
  } : {},
@@ -259,6 +466,122 @@ function serializeFunctionHandler(definition, sourceFile, options) {
259
466
  };
260
467
  }
261
468
  __name(serializeFunctionHandler, "serializeFunctionHandler");
469
+ function buildFunctionTypeAnnotations(annotations, definition) {
470
+ const meta = definition.metadata;
471
+ switch (definition.type) {
472
+ case "http": {
473
+ const path = meta.path;
474
+ const method = meta.method;
475
+ if (path !== void 0 && method !== void 0) {
476
+ annotations["celerity.handler.http"] = true;
477
+ annotations["celerity.handler.http.method"] = method;
478
+ annotations["celerity.handler.http.path"] = path;
479
+ }
480
+ break;
481
+ }
482
+ case "websocket": {
483
+ annotations["celerity.handler.websocket"] = true;
484
+ const route = meta.route;
485
+ if (route) {
486
+ annotations["celerity.handler.websocket.route"] = route;
487
+ }
488
+ break;
489
+ }
490
+ case "consumer": {
491
+ annotations["celerity.handler.consumer"] = true;
492
+ const route = meta.route;
493
+ if (route) {
494
+ annotations["celerity.handler.consumer.route"] = route;
495
+ }
496
+ break;
497
+ }
498
+ case "schedule": {
499
+ annotations["celerity.handler.schedule"] = true;
500
+ const source = meta.source;
501
+ if (source) {
502
+ annotations["celerity.handler.schedule.source"] = source;
503
+ }
504
+ const schedule = meta.schedule;
505
+ if (schedule) {
506
+ annotations["celerity.handler.schedule.expression"] = schedule;
507
+ }
508
+ break;
509
+ }
510
+ case "custom": {
511
+ annotations["celerity.handler.custom"] = true;
512
+ const name = meta.name;
513
+ if (name) {
514
+ annotations["celerity.handler.custom.name"] = name;
515
+ }
516
+ break;
517
+ }
518
+ }
519
+ }
520
+ __name(buildFunctionTypeAnnotations, "buildFunctionTypeAnnotations");
521
+ function extractGuardMeta(guardClass) {
522
+ const guardName = Reflect.getOwnMetadata(GUARD_CUSTOM_METADATA, guardClass);
523
+ if (!guardName) return null;
524
+ return {
525
+ guardName,
526
+ customMetadata: Reflect.getOwnMetadata(CUSTOM_METADATA, guardClass) ?? {}
527
+ };
528
+ }
529
+ __name(extractGuardMeta, "extractGuardMeta");
530
+ function serializeClassGuard(guardClass, sourceFile, options) {
531
+ const meta = extractGuardMeta(guardClass);
532
+ if (!meta) return null;
533
+ const className = guardClass.name;
534
+ const methodName = "check";
535
+ const annotations = {
536
+ "celerity.handler.guard.custom": meta.guardName
537
+ };
538
+ for (const [key, value] of Object.entries(meta.customMetadata)) {
539
+ if (value === void 0) continue;
540
+ annotations[`celerity.handler.metadata.${key}`] = serializeAnnotationValue(value);
541
+ }
542
+ return {
543
+ resourceName: deriveClassResourceName(className, methodName),
544
+ guardName: meta.guardName,
545
+ sourceFile,
546
+ guardType: "class",
547
+ className,
548
+ annotations,
549
+ spec: {
550
+ handlerName: deriveClassHandlerName(className, methodName),
551
+ codeLocation: deriveCodeLocation(sourceFile, options.projectRoot),
552
+ handler: deriveClassHandlerFunction(sourceFile, className, methodName)
553
+ }
554
+ };
555
+ }
556
+ __name(serializeClassGuard, "serializeClassGuard");
557
+ function serializeFunctionGuard(definition, sourceFile, options) {
558
+ const guardName = definition.name;
559
+ if (!guardName) return null;
560
+ const meta = definition.metadata ?? {};
561
+ const customMetadata = meta.customMetadata ?? {};
562
+ const annotations = {
563
+ "celerity.handler.guard.custom": guardName
564
+ };
565
+ for (const [key, value] of Object.entries(customMetadata)) {
566
+ if (value === void 0) continue;
567
+ annotations[`celerity.handler.metadata.${key}`] = serializeAnnotationValue(value);
568
+ }
569
+ const exportName = guardName;
570
+ return {
571
+ resourceName: deriveFunctionResourceName(exportName),
572
+ guardName,
573
+ sourceFile,
574
+ guardType: "function",
575
+ exportName,
576
+ annotations,
577
+ spec: {
578
+ handlerName: exportName,
579
+ codeLocation: deriveCodeLocation(sourceFile, options.projectRoot),
580
+ handler: deriveFunctionHandlerFunction(sourceFile, exportName)
581
+ }
582
+ };
583
+ }
584
+ __name(serializeFunctionGuard, "serializeFunctionGuard");
262
585
  function serializeAnnotationValue(value) {
263
586
  if (typeof value === "boolean") return value;
264
587
  if (typeof value === "string") return value;