@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/README.md +106 -5
- package/dist/extract/cli.cjs +372 -49
- package/dist/extract/cli.cjs.map +1 -1
- package/dist/extract/cli.js +372 -49
- package/dist/extract/cli.js.map +1 -1
- package/dist/index.cjs +373 -50
- 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 +372 -49
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/schemas/handler-manifest.v1.schema.json +56 -11
package/dist/index.cjs
CHANGED
|
@@ -38,7 +38,7 @@ __export(index_exports, {
|
|
|
38
38
|
deriveCodeLocation: () => deriveCodeLocation,
|
|
39
39
|
deriveFunctionHandlerFunction: () => deriveFunctionHandlerFunction,
|
|
40
40
|
deriveFunctionResourceName: () => deriveFunctionResourceName,
|
|
41
|
-
joinHandlerPath: () =>
|
|
41
|
+
joinHandlerPath: () => import_common2.joinHandlerPath,
|
|
42
42
|
serializeManifest: () => serializeManifest,
|
|
43
43
|
validateScannedDependencies: () => validateScannedDependencies
|
|
44
44
|
});
|
|
@@ -47,6 +47,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
47
47
|
// src/extract/metadata-app.ts
|
|
48
48
|
var import_reflect_metadata = require("reflect-metadata");
|
|
49
49
|
var import_debug = __toESM(require("debug"), 1);
|
|
50
|
+
var import_common = require("@celerity-sdk/common");
|
|
50
51
|
var import_core = require("@celerity-sdk/core");
|
|
51
52
|
var debug = (0, import_debug.default)("celerity:cli");
|
|
52
53
|
function scanProvider(provider, seenTokens) {
|
|
@@ -73,10 +74,12 @@ function buildScannedModule(rootModule) {
|
|
|
73
74
|
const graph = (0, import_core.buildModuleGraph)(rootModule);
|
|
74
75
|
const controllerClasses = [];
|
|
75
76
|
const functionHandlers = [];
|
|
77
|
+
const guardClasses = [];
|
|
78
|
+
const functionGuards = [];
|
|
76
79
|
const providers = [];
|
|
77
80
|
const seenTokens = /* @__PURE__ */ new Set();
|
|
78
81
|
for (const [moduleClass, node] of graph) {
|
|
79
|
-
debug("scan: module %s \u2014 %d providers, %d controllers", moduleClass.name, node.providers.length, node.controllers.length);
|
|
82
|
+
debug("scan: module %s \u2014 %d providers, %d controllers, %d guards", moduleClass.name, node.providers.length, node.controllers.length, node.guards.length);
|
|
80
83
|
for (const provider of node.providers) {
|
|
81
84
|
const scanned = scanProvider(provider, seenTokens);
|
|
82
85
|
if (scanned) providers.push(scanned);
|
|
@@ -92,11 +95,28 @@ function buildScannedModule(rootModule) {
|
|
|
92
95
|
});
|
|
93
96
|
}
|
|
94
97
|
}
|
|
98
|
+
for (const guard of node.guards) {
|
|
99
|
+
if (typeof guard === "function") {
|
|
100
|
+
guardClasses.push(guard);
|
|
101
|
+
if (!seenTokens.has(guard)) {
|
|
102
|
+
seenTokens.add(guard);
|
|
103
|
+
providers.push({
|
|
104
|
+
token: guard,
|
|
105
|
+
providerType: "class",
|
|
106
|
+
dependencies: (0, import_core.getClassDependencyTokens)(guard)
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
110
|
+
functionGuards.push(guard);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
95
113
|
functionHandlers.push(...node.functionHandlers);
|
|
96
114
|
}
|
|
97
115
|
return {
|
|
98
116
|
controllerClasses,
|
|
99
117
|
functionHandlers,
|
|
118
|
+
guardClasses,
|
|
119
|
+
functionGuards,
|
|
100
120
|
providers
|
|
101
121
|
};
|
|
102
122
|
}
|
|
@@ -116,7 +136,7 @@ function validateScannedDependencies(scanned) {
|
|
|
116
136
|
}
|
|
117
137
|
} else if (typeof dep === "function") {
|
|
118
138
|
walk(dep, (0, import_core.getClassDependencyTokens)(dep));
|
|
119
|
-
} else {
|
|
139
|
+
} else if (!(0, import_common.isResourceLayerToken)(dep)) {
|
|
120
140
|
diagnostics.push({
|
|
121
141
|
consumer: serializeToken(token),
|
|
122
142
|
dependency: serializeToken(dep)
|
|
@@ -143,7 +163,7 @@ var import_reflect_metadata2 = require("reflect-metadata");
|
|
|
143
163
|
var import_core2 = require("@celerity-sdk/core");
|
|
144
164
|
|
|
145
165
|
// src/extract/path-utils.ts
|
|
146
|
-
var
|
|
166
|
+
var import_common2 = require("@celerity-sdk/common");
|
|
147
167
|
|
|
148
168
|
// src/extract/identity.ts
|
|
149
169
|
var import_node_path = require("path");
|
|
@@ -181,8 +201,9 @@ __name(deriveCodeLocation, "deriveCodeLocation");
|
|
|
181
201
|
function serializeManifest(scanned, sourceFile, options) {
|
|
182
202
|
const handlers = [];
|
|
183
203
|
const functionHandlers = [];
|
|
204
|
+
const guardHandlers = [];
|
|
184
205
|
for (const controllerClass of scanned.controllerClasses) {
|
|
185
|
-
const entries =
|
|
206
|
+
const entries = serializeClassHandlers(controllerClass, sourceFile, options);
|
|
186
207
|
handlers.push(...entries);
|
|
187
208
|
}
|
|
188
209
|
for (const fnHandler of scanned.functionHandlers) {
|
|
@@ -191,40 +212,76 @@ function serializeManifest(scanned, sourceFile, options) {
|
|
|
191
212
|
functionHandlers.push(entry);
|
|
192
213
|
}
|
|
193
214
|
}
|
|
215
|
+
for (const guardClass of scanned.guardClasses) {
|
|
216
|
+
const entry = serializeClassGuard(guardClass, sourceFile, options);
|
|
217
|
+
if (entry) {
|
|
218
|
+
guardHandlers.push(entry);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
for (const fnGuard of scanned.functionGuards) {
|
|
222
|
+
const entry = serializeFunctionGuard(fnGuard, sourceFile, options);
|
|
223
|
+
if (entry) {
|
|
224
|
+
guardHandlers.push(entry);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
194
227
|
return {
|
|
195
228
|
version: "1.0.0",
|
|
196
229
|
handlers,
|
|
197
230
|
functionHandlers,
|
|
231
|
+
guardHandlers,
|
|
198
232
|
dependencyGraph: serializeDependencyGraph(scanned)
|
|
199
233
|
};
|
|
200
234
|
}
|
|
201
235
|
__name(serializeManifest, "serializeManifest");
|
|
202
|
-
function
|
|
203
|
-
const
|
|
204
|
-
if (
|
|
236
|
+
function extractControllerMeta(controllerClass) {
|
|
237
|
+
const httpMeta = Reflect.getOwnMetadata(import_core2.CONTROLLER_METADATA, controllerClass);
|
|
238
|
+
if (httpMeta) {
|
|
239
|
+
return {
|
|
240
|
+
controllerType: "http",
|
|
241
|
+
prefix: httpMeta.prefix ?? "",
|
|
242
|
+
...extractSharedClassMeta(controllerClass)
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
const isWebSocket = Reflect.getOwnMetadata(import_core2.WEBSOCKET_CONTROLLER_METADATA, controllerClass);
|
|
246
|
+
if (isWebSocket) {
|
|
247
|
+
return {
|
|
248
|
+
controllerType: "websocket",
|
|
249
|
+
prefix: "",
|
|
250
|
+
...extractSharedClassMeta(controllerClass)
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
const consumerMeta = Reflect.getOwnMetadata(import_core2.CONSUMER_METADATA, controllerClass);
|
|
254
|
+
if (consumerMeta) {
|
|
255
|
+
return {
|
|
256
|
+
controllerType: "consumer",
|
|
257
|
+
prefix: "",
|
|
258
|
+
source: consumerMeta.source,
|
|
259
|
+
...extractSharedClassMeta(controllerClass)
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
return null;
|
|
263
|
+
}
|
|
264
|
+
__name(extractControllerMeta, "extractControllerMeta");
|
|
265
|
+
function extractSharedClassMeta(controllerClass) {
|
|
205
266
|
return {
|
|
206
|
-
prefix: controllerMeta.prefix ?? "",
|
|
207
267
|
protectedBy: Reflect.getOwnMetadata(import_core2.GUARD_PROTECTEDBY_METADATA, controllerClass) ?? [],
|
|
208
268
|
customGuardName: Reflect.getOwnMetadata(import_core2.GUARD_CUSTOM_METADATA, controllerClass),
|
|
209
|
-
customMetadata: Reflect.getOwnMetadata(import_core2.CUSTOM_METADATA, controllerClass) ?? {}
|
|
269
|
+
customMetadata: Reflect.getOwnMetadata(import_core2.CUSTOM_METADATA, controllerClass) ?? {},
|
|
270
|
+
resourceRefs: Reflect.getOwnMetadata(import_core2.USE_RESOURCE_METADATA, controllerClass) ?? []
|
|
210
271
|
};
|
|
211
272
|
}
|
|
212
|
-
__name(
|
|
213
|
-
function
|
|
214
|
-
const annotations = {};
|
|
215
|
-
annotations["celerity.handler.http"] = true;
|
|
216
|
-
annotations["celerity.handler.http.method"] = httpMethod;
|
|
217
|
-
annotations["celerity.handler.http.path"] = fullPath;
|
|
273
|
+
__name(extractSharedClassMeta, "extractSharedClassMeta");
|
|
274
|
+
function appendSharedAnnotations(annotations, meta, prototype, methodName) {
|
|
218
275
|
const methodProtectedBy = Reflect.getOwnMetadata(import_core2.GUARD_PROTECTEDBY_METADATA, prototype, methodName) ?? [];
|
|
219
276
|
const allProtectedBy = [
|
|
220
|
-
...
|
|
277
|
+
...meta.protectedBy,
|
|
221
278
|
...methodProtectedBy
|
|
222
279
|
];
|
|
223
280
|
if (allProtectedBy.length > 0) {
|
|
224
281
|
annotations["celerity.handler.guard.protectedBy"] = allProtectedBy;
|
|
225
282
|
}
|
|
226
|
-
if (
|
|
227
|
-
annotations["celerity.handler.guard.custom"] =
|
|
283
|
+
if (meta.customGuardName) {
|
|
284
|
+
annotations["celerity.handler.guard.custom"] = meta.customGuardName;
|
|
228
285
|
}
|
|
229
286
|
const isPublic = Reflect.getOwnMetadata(import_core2.PUBLIC_METADATA, prototype, methodName) === true;
|
|
230
287
|
if (isPublic) {
|
|
@@ -232,57 +289,206 @@ function buildMethodAnnotations(classMeta, prototype, methodName, httpMethod, fu
|
|
|
232
289
|
}
|
|
233
290
|
const methodCustomMetadata = Reflect.getOwnMetadata(import_core2.CUSTOM_METADATA, prototype, methodName) ?? {};
|
|
234
291
|
const customMetadata = {
|
|
235
|
-
...
|
|
292
|
+
...meta.customMetadata,
|
|
236
293
|
...methodCustomMetadata
|
|
237
294
|
};
|
|
238
295
|
for (const [key, value] of Object.entries(customMetadata)) {
|
|
239
296
|
if (value === void 0) continue;
|
|
240
297
|
annotations[`celerity.handler.metadata.${key}`] = serializeAnnotationValue(value);
|
|
241
298
|
}
|
|
299
|
+
const methodResourceRefs = Reflect.getOwnMetadata(import_core2.USE_RESOURCE_METADATA, prototype, methodName) ?? [];
|
|
300
|
+
const allResourceRefs = [
|
|
301
|
+
.../* @__PURE__ */ new Set([
|
|
302
|
+
...meta.resourceRefs,
|
|
303
|
+
...methodResourceRefs
|
|
304
|
+
])
|
|
305
|
+
];
|
|
306
|
+
if (allResourceRefs.length > 0) {
|
|
307
|
+
annotations["celerity.handler.resource.ref"] = allResourceRefs;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
__name(appendSharedAnnotations, "appendSharedAnnotations");
|
|
311
|
+
function buildHttpAnnotations(meta, prototype, methodName, httpMethod, fullPath) {
|
|
312
|
+
const annotations = {};
|
|
313
|
+
annotations["celerity.handler.http"] = true;
|
|
314
|
+
annotations["celerity.handler.http.method"] = httpMethod;
|
|
315
|
+
annotations["celerity.handler.http.path"] = fullPath;
|
|
316
|
+
appendSharedAnnotations(annotations, meta, prototype, methodName);
|
|
317
|
+
return annotations;
|
|
318
|
+
}
|
|
319
|
+
__name(buildHttpAnnotations, "buildHttpAnnotations");
|
|
320
|
+
function buildWebSocketAnnotations(meta, prototype, methodName, wsEvent) {
|
|
321
|
+
const annotations = {};
|
|
322
|
+
annotations["celerity.handler.websocket"] = true;
|
|
323
|
+
annotations["celerity.handler.websocket.route"] = wsEvent.route;
|
|
324
|
+
annotations["celerity.handler.websocket.eventType"] = wsEvent.eventType;
|
|
325
|
+
appendSharedAnnotations(annotations, meta, prototype, methodName);
|
|
326
|
+
return annotations;
|
|
327
|
+
}
|
|
328
|
+
__name(buildWebSocketAnnotations, "buildWebSocketAnnotations");
|
|
329
|
+
function buildConsumerAnnotations(meta, prototype, methodName, consumerHandler) {
|
|
330
|
+
const annotations = {};
|
|
331
|
+
annotations["celerity.handler.consumer"] = true;
|
|
332
|
+
if (meta.source) {
|
|
333
|
+
annotations["celerity.handler.consumer.source"] = meta.source;
|
|
334
|
+
}
|
|
335
|
+
if (consumerHandler.route) {
|
|
336
|
+
annotations["celerity.handler.consumer.route"] = consumerHandler.route;
|
|
337
|
+
}
|
|
338
|
+
appendSharedAnnotations(annotations, meta, prototype, methodName);
|
|
339
|
+
return annotations;
|
|
340
|
+
}
|
|
341
|
+
__name(buildConsumerAnnotations, "buildConsumerAnnotations");
|
|
342
|
+
function buildScheduleAnnotations(meta, prototype, methodName, scheduleMeta) {
|
|
343
|
+
const annotations = {};
|
|
344
|
+
annotations["celerity.handler.schedule"] = true;
|
|
345
|
+
if (scheduleMeta.source) {
|
|
346
|
+
annotations["celerity.handler.schedule.source"] = scheduleMeta.source;
|
|
347
|
+
}
|
|
348
|
+
if (scheduleMeta.schedule) {
|
|
349
|
+
annotations["celerity.handler.schedule.expression"] = scheduleMeta.schedule;
|
|
350
|
+
}
|
|
351
|
+
appendSharedAnnotations(annotations, meta, prototype, methodName);
|
|
242
352
|
return annotations;
|
|
243
353
|
}
|
|
244
|
-
__name(
|
|
245
|
-
function
|
|
246
|
-
const
|
|
247
|
-
|
|
354
|
+
__name(buildScheduleAnnotations, "buildScheduleAnnotations");
|
|
355
|
+
function buildCustomAnnotations(meta, prototype, methodName, invokeMeta) {
|
|
356
|
+
const annotations = {};
|
|
357
|
+
annotations["celerity.handler.custom"] = true;
|
|
358
|
+
annotations["celerity.handler.custom.name"] = invokeMeta.name;
|
|
359
|
+
appendSharedAnnotations(annotations, meta, prototype, methodName);
|
|
360
|
+
return annotations;
|
|
361
|
+
}
|
|
362
|
+
__name(buildCustomAnnotations, "buildCustomAnnotations");
|
|
363
|
+
function serializeClassHandlers(controllerClass, sourceFile, options) {
|
|
364
|
+
const meta = extractControllerMeta(controllerClass);
|
|
365
|
+
if (!meta) return [];
|
|
248
366
|
const className = controllerClass.name;
|
|
249
367
|
const prototype = controllerClass.prototype;
|
|
250
368
|
const methods = Object.getOwnPropertyNames(prototype).filter((n) => n !== "constructor");
|
|
251
369
|
const entries = [];
|
|
252
370
|
for (const methodName of methods) {
|
|
253
|
-
const
|
|
254
|
-
if (
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
270
|
-
}
|
|
371
|
+
const typeEntry = serializeControllerTypeMethod(meta, className, prototype, methodName, sourceFile, options);
|
|
372
|
+
if (typeEntry) entries.push(typeEntry);
|
|
373
|
+
const scheduleMeta = Reflect.getOwnMetadata(import_core2.SCHEDULE_HANDLER_METADATA, prototype, methodName);
|
|
374
|
+
if (scheduleMeta) {
|
|
375
|
+
entries.push({
|
|
376
|
+
resourceName: deriveClassResourceName(className, methodName),
|
|
377
|
+
className,
|
|
378
|
+
methodName,
|
|
379
|
+
sourceFile,
|
|
380
|
+
handlerType: "schedule",
|
|
381
|
+
annotations: buildScheduleAnnotations(meta, prototype, methodName, scheduleMeta),
|
|
382
|
+
spec: {
|
|
383
|
+
handlerName: deriveClassHandlerName(className, methodName),
|
|
384
|
+
codeLocation: deriveCodeLocation(sourceFile, options.projectRoot),
|
|
385
|
+
handler: deriveClassHandlerFunction(sourceFile, className, methodName)
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
const invokeMeta = Reflect.getOwnMetadata(import_core2.INVOKE_METADATA, prototype, methodName);
|
|
390
|
+
if (invokeMeta) {
|
|
391
|
+
entries.push({
|
|
392
|
+
resourceName: deriveClassResourceName(className, methodName),
|
|
393
|
+
className,
|
|
394
|
+
methodName,
|
|
395
|
+
sourceFile,
|
|
396
|
+
handlerType: "custom",
|
|
397
|
+
annotations: buildCustomAnnotations(meta, prototype, methodName, invokeMeta),
|
|
398
|
+
spec: {
|
|
399
|
+
handlerName: deriveClassHandlerName(className, methodName),
|
|
400
|
+
codeLocation: deriveCodeLocation(sourceFile, options.projectRoot),
|
|
401
|
+
handler: deriveClassHandlerFunction(sourceFile, className, methodName)
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
}
|
|
271
405
|
}
|
|
272
406
|
return entries;
|
|
273
407
|
}
|
|
274
|
-
__name(
|
|
408
|
+
__name(serializeClassHandlers, "serializeClassHandlers");
|
|
409
|
+
function serializeControllerTypeMethod(meta, className, prototype, methodName, sourceFile, options) {
|
|
410
|
+
switch (meta.controllerType) {
|
|
411
|
+
case "http":
|
|
412
|
+
return serializeHttpMethod(meta, className, prototype, methodName, sourceFile, options);
|
|
413
|
+
case "websocket":
|
|
414
|
+
return serializeWebSocketMethod(meta, className, prototype, methodName, sourceFile, options);
|
|
415
|
+
case "consumer":
|
|
416
|
+
return serializeConsumerMethod(meta, className, prototype, methodName, sourceFile, options);
|
|
417
|
+
default:
|
|
418
|
+
return null;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
__name(serializeControllerTypeMethod, "serializeControllerTypeMethod");
|
|
422
|
+
function serializeHttpMethod(meta, className, prototype, methodName, sourceFile, options) {
|
|
423
|
+
const httpMethod = Reflect.getOwnMetadata(import_core2.HTTP_METHOD_METADATA, prototype, methodName);
|
|
424
|
+
if (!httpMethod) return null;
|
|
425
|
+
const routePath = Reflect.getOwnMetadata(import_core2.ROUTE_PATH_METADATA, prototype, methodName) ?? "/";
|
|
426
|
+
const fullPath = (0, import_common2.joinHandlerPath)(meta.prefix, routePath);
|
|
427
|
+
return {
|
|
428
|
+
resourceName: deriveClassResourceName(className, methodName),
|
|
429
|
+
className,
|
|
430
|
+
methodName,
|
|
431
|
+
sourceFile,
|
|
432
|
+
handlerType: "http",
|
|
433
|
+
annotations: buildHttpAnnotations(meta, prototype, methodName, httpMethod, fullPath),
|
|
434
|
+
spec: {
|
|
435
|
+
handlerName: deriveClassHandlerName(className, methodName),
|
|
436
|
+
codeLocation: deriveCodeLocation(sourceFile, options.projectRoot),
|
|
437
|
+
handler: deriveClassHandlerFunction(sourceFile, className, methodName)
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
__name(serializeHttpMethod, "serializeHttpMethod");
|
|
442
|
+
function serializeWebSocketMethod(meta, className, prototype, methodName, sourceFile, options) {
|
|
443
|
+
const wsEvent = Reflect.getOwnMetadata(import_core2.WEBSOCKET_EVENT_METADATA, prototype, methodName);
|
|
444
|
+
if (!wsEvent) return null;
|
|
445
|
+
return {
|
|
446
|
+
resourceName: deriveClassResourceName(className, methodName),
|
|
447
|
+
className,
|
|
448
|
+
methodName,
|
|
449
|
+
sourceFile,
|
|
450
|
+
handlerType: "websocket",
|
|
451
|
+
annotations: buildWebSocketAnnotations(meta, prototype, methodName, wsEvent),
|
|
452
|
+
spec: {
|
|
453
|
+
handlerName: deriveClassHandlerName(className, methodName),
|
|
454
|
+
codeLocation: deriveCodeLocation(sourceFile, options.projectRoot),
|
|
455
|
+
handler: deriveClassHandlerFunction(sourceFile, className, methodName)
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
__name(serializeWebSocketMethod, "serializeWebSocketMethod");
|
|
460
|
+
function serializeConsumerMethod(meta, className, prototype, methodName, sourceFile, options) {
|
|
461
|
+
const consumerHandler = Reflect.getOwnMetadata(import_core2.CONSUMER_HANDLER_METADATA, prototype, methodName);
|
|
462
|
+
if (!consumerHandler) return null;
|
|
463
|
+
return {
|
|
464
|
+
resourceName: deriveClassResourceName(className, methodName),
|
|
465
|
+
className,
|
|
466
|
+
methodName,
|
|
467
|
+
sourceFile,
|
|
468
|
+
handlerType: "consumer",
|
|
469
|
+
annotations: buildConsumerAnnotations(meta, prototype, methodName, consumerHandler),
|
|
470
|
+
spec: {
|
|
471
|
+
handlerName: deriveClassHandlerName(className, methodName),
|
|
472
|
+
codeLocation: deriveCodeLocation(sourceFile, options.projectRoot),
|
|
473
|
+
handler: deriveClassHandlerFunction(sourceFile, className, methodName)
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
__name(serializeConsumerMethod, "serializeConsumerMethod");
|
|
275
478
|
function serializeFunctionHandler(definition, sourceFile, options) {
|
|
479
|
+
const supported = [
|
|
480
|
+
"http",
|
|
481
|
+
"websocket",
|
|
482
|
+
"consumer",
|
|
483
|
+
"schedule",
|
|
484
|
+
"custom"
|
|
485
|
+
];
|
|
486
|
+
if (!supported.includes(definition.type)) return null;
|
|
276
487
|
const exportName = definition.metadata.handlerName ?? "handler";
|
|
277
488
|
const customMetadata = definition.metadata.customMetadata ?? {};
|
|
489
|
+
const handlerType = definition.type;
|
|
278
490
|
const annotations = {};
|
|
279
|
-
|
|
280
|
-
const method = definition.metadata.method;
|
|
281
|
-
if (path !== void 0 && method !== void 0) {
|
|
282
|
-
annotations["celerity.handler.http"] = true;
|
|
283
|
-
annotations["celerity.handler.http.method"] = method;
|
|
284
|
-
annotations["celerity.handler.http.path"] = path;
|
|
285
|
-
}
|
|
491
|
+
buildFunctionTypeAnnotations(annotations, definition);
|
|
286
492
|
for (const [key, value] of Object.entries(customMetadata)) {
|
|
287
493
|
if (value === void 0) continue;
|
|
288
494
|
annotations[`celerity.handler.metadata.${key}`] = serializeAnnotationValue(value);
|
|
@@ -291,6 +497,7 @@ function serializeFunctionHandler(definition, sourceFile, options) {
|
|
|
291
497
|
resourceName: deriveFunctionResourceName(exportName),
|
|
292
498
|
exportName,
|
|
293
499
|
sourceFile,
|
|
500
|
+
handlerType,
|
|
294
501
|
...Object.keys(annotations).length > 0 ? {
|
|
295
502
|
annotations
|
|
296
503
|
} : {},
|
|
@@ -302,6 +509,122 @@ function serializeFunctionHandler(definition, sourceFile, options) {
|
|
|
302
509
|
};
|
|
303
510
|
}
|
|
304
511
|
__name(serializeFunctionHandler, "serializeFunctionHandler");
|
|
512
|
+
function buildFunctionTypeAnnotations(annotations, definition) {
|
|
513
|
+
const meta = definition.metadata;
|
|
514
|
+
switch (definition.type) {
|
|
515
|
+
case "http": {
|
|
516
|
+
const path = meta.path;
|
|
517
|
+
const method = meta.method;
|
|
518
|
+
if (path !== void 0 && method !== void 0) {
|
|
519
|
+
annotations["celerity.handler.http"] = true;
|
|
520
|
+
annotations["celerity.handler.http.method"] = method;
|
|
521
|
+
annotations["celerity.handler.http.path"] = path;
|
|
522
|
+
}
|
|
523
|
+
break;
|
|
524
|
+
}
|
|
525
|
+
case "websocket": {
|
|
526
|
+
annotations["celerity.handler.websocket"] = true;
|
|
527
|
+
const route = meta.route;
|
|
528
|
+
if (route) {
|
|
529
|
+
annotations["celerity.handler.websocket.route"] = route;
|
|
530
|
+
}
|
|
531
|
+
break;
|
|
532
|
+
}
|
|
533
|
+
case "consumer": {
|
|
534
|
+
annotations["celerity.handler.consumer"] = true;
|
|
535
|
+
const route = meta.route;
|
|
536
|
+
if (route) {
|
|
537
|
+
annotations["celerity.handler.consumer.route"] = route;
|
|
538
|
+
}
|
|
539
|
+
break;
|
|
540
|
+
}
|
|
541
|
+
case "schedule": {
|
|
542
|
+
annotations["celerity.handler.schedule"] = true;
|
|
543
|
+
const source = meta.source;
|
|
544
|
+
if (source) {
|
|
545
|
+
annotations["celerity.handler.schedule.source"] = source;
|
|
546
|
+
}
|
|
547
|
+
const schedule = meta.schedule;
|
|
548
|
+
if (schedule) {
|
|
549
|
+
annotations["celerity.handler.schedule.expression"] = schedule;
|
|
550
|
+
}
|
|
551
|
+
break;
|
|
552
|
+
}
|
|
553
|
+
case "custom": {
|
|
554
|
+
annotations["celerity.handler.custom"] = true;
|
|
555
|
+
const name = meta.name;
|
|
556
|
+
if (name) {
|
|
557
|
+
annotations["celerity.handler.custom.name"] = name;
|
|
558
|
+
}
|
|
559
|
+
break;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
__name(buildFunctionTypeAnnotations, "buildFunctionTypeAnnotations");
|
|
564
|
+
function extractGuardMeta(guardClass) {
|
|
565
|
+
const guardName = Reflect.getOwnMetadata(import_core2.GUARD_CUSTOM_METADATA, guardClass);
|
|
566
|
+
if (!guardName) return null;
|
|
567
|
+
return {
|
|
568
|
+
guardName,
|
|
569
|
+
customMetadata: Reflect.getOwnMetadata(import_core2.CUSTOM_METADATA, guardClass) ?? {}
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
__name(extractGuardMeta, "extractGuardMeta");
|
|
573
|
+
function serializeClassGuard(guardClass, sourceFile, options) {
|
|
574
|
+
const meta = extractGuardMeta(guardClass);
|
|
575
|
+
if (!meta) return null;
|
|
576
|
+
const className = guardClass.name;
|
|
577
|
+
const methodName = "check";
|
|
578
|
+
const annotations = {
|
|
579
|
+
"celerity.handler.guard.custom": meta.guardName
|
|
580
|
+
};
|
|
581
|
+
for (const [key, value] of Object.entries(meta.customMetadata)) {
|
|
582
|
+
if (value === void 0) continue;
|
|
583
|
+
annotations[`celerity.handler.metadata.${key}`] = serializeAnnotationValue(value);
|
|
584
|
+
}
|
|
585
|
+
return {
|
|
586
|
+
resourceName: deriveClassResourceName(className, methodName),
|
|
587
|
+
guardName: meta.guardName,
|
|
588
|
+
sourceFile,
|
|
589
|
+
guardType: "class",
|
|
590
|
+
className,
|
|
591
|
+
annotations,
|
|
592
|
+
spec: {
|
|
593
|
+
handlerName: deriveClassHandlerName(className, methodName),
|
|
594
|
+
codeLocation: deriveCodeLocation(sourceFile, options.projectRoot),
|
|
595
|
+
handler: deriveClassHandlerFunction(sourceFile, className, methodName)
|
|
596
|
+
}
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
__name(serializeClassGuard, "serializeClassGuard");
|
|
600
|
+
function serializeFunctionGuard(definition, sourceFile, options) {
|
|
601
|
+
const guardName = definition.name;
|
|
602
|
+
if (!guardName) return null;
|
|
603
|
+
const meta = definition.metadata ?? {};
|
|
604
|
+
const customMetadata = meta.customMetadata ?? {};
|
|
605
|
+
const annotations = {
|
|
606
|
+
"celerity.handler.guard.custom": guardName
|
|
607
|
+
};
|
|
608
|
+
for (const [key, value] of Object.entries(customMetadata)) {
|
|
609
|
+
if (value === void 0) continue;
|
|
610
|
+
annotations[`celerity.handler.metadata.${key}`] = serializeAnnotationValue(value);
|
|
611
|
+
}
|
|
612
|
+
const exportName = guardName;
|
|
613
|
+
return {
|
|
614
|
+
resourceName: deriveFunctionResourceName(exportName),
|
|
615
|
+
guardName,
|
|
616
|
+
sourceFile,
|
|
617
|
+
guardType: "function",
|
|
618
|
+
exportName,
|
|
619
|
+
annotations,
|
|
620
|
+
spec: {
|
|
621
|
+
handlerName: exportName,
|
|
622
|
+
codeLocation: deriveCodeLocation(sourceFile, options.projectRoot),
|
|
623
|
+
handler: deriveFunctionHandlerFunction(sourceFile, exportName)
|
|
624
|
+
}
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
__name(serializeFunctionGuard, "serializeFunctionGuard");
|
|
305
628
|
function serializeAnnotationValue(value) {
|
|
306
629
|
if (typeof value === "boolean") return value;
|
|
307
630
|
if (typeof value === "string") return value;
|