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