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