@celerity-sdk/cli 0.2.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 ADDED
@@ -0,0 +1,307 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/extract/metadata-app.ts
5
+ import "reflect-metadata";
6
+ import createDebug from "debug";
7
+ import { buildModuleGraph, getClassDependencyTokens, getProviderDependencyTokens } from "@celerity-sdk/core";
8
+ var debug = createDebug("celerity:cli");
9
+ function scanProvider(provider, seenTokens) {
10
+ if (typeof provider === "function") {
11
+ if (seenTokens.has(provider)) return null;
12
+ seenTokens.add(provider);
13
+ return {
14
+ token: provider,
15
+ providerType: "class",
16
+ dependencies: getClassDependencyTokens(provider)
17
+ };
18
+ }
19
+ const typed = provider;
20
+ if (seenTokens.has(typed.provide)) return null;
21
+ seenTokens.add(typed.provide);
22
+ return {
23
+ token: typed.provide,
24
+ providerType: "useFactory" in typed ? "factory" : "useClass" in typed ? "class" : "value",
25
+ dependencies: getProviderDependencyTokens(typed)
26
+ };
27
+ }
28
+ __name(scanProvider, "scanProvider");
29
+ function buildScannedModule(rootModule) {
30
+ const graph = buildModuleGraph(rootModule);
31
+ const controllerClasses = [];
32
+ const functionHandlers = [];
33
+ const providers = [];
34
+ const seenTokens = /* @__PURE__ */ new Set();
35
+ for (const [moduleClass, node] of graph) {
36
+ debug("scan: module %s \u2014 %d providers, %d controllers", moduleClass.name, node.providers.length, node.controllers.length);
37
+ for (const provider of node.providers) {
38
+ const scanned = scanProvider(provider, seenTokens);
39
+ if (scanned) providers.push(scanned);
40
+ }
41
+ for (const controller of node.controllers) {
42
+ controllerClasses.push(controller);
43
+ if (!seenTokens.has(controller)) {
44
+ seenTokens.add(controller);
45
+ providers.push({
46
+ token: controller,
47
+ providerType: "class",
48
+ dependencies: getClassDependencyTokens(controller)
49
+ });
50
+ }
51
+ }
52
+ functionHandlers.push(...node.functionHandlers);
53
+ }
54
+ return {
55
+ controllerClasses,
56
+ functionHandlers,
57
+ providers
58
+ };
59
+ }
60
+ __name(buildScannedModule, "buildScannedModule");
61
+ function validateScannedDependencies(scanned) {
62
+ const registeredTokens = new Set(scanned.providers.map((p) => p.token));
63
+ const diagnostics = [];
64
+ const visited = /* @__PURE__ */ new Set();
65
+ function walk(token, deps) {
66
+ if (visited.has(token)) return;
67
+ visited.add(token);
68
+ for (const dep of deps) {
69
+ if (registeredTokens.has(dep)) {
70
+ const provider = scanned.providers.find((p) => p.token === dep);
71
+ if (provider) {
72
+ walk(dep, provider.dependencies);
73
+ }
74
+ } else if (typeof dep === "function") {
75
+ walk(dep, getClassDependencyTokens(dep));
76
+ } else {
77
+ diagnostics.push({
78
+ consumer: serializeToken(token),
79
+ dependency: serializeToken(dep)
80
+ });
81
+ }
82
+ }
83
+ }
84
+ __name(walk, "walk");
85
+ for (const provider of scanned.providers) {
86
+ walk(provider.token, provider.dependencies);
87
+ }
88
+ return diagnostics;
89
+ }
90
+ __name(validateScannedDependencies, "validateScannedDependencies");
91
+ function serializeToken(token) {
92
+ if (typeof token === "function") return token.name;
93
+ if (typeof token === "symbol") return token.description ?? "Symbol()";
94
+ return String(token);
95
+ }
96
+ __name(serializeToken, "serializeToken");
97
+
98
+ // src/extract/serializer.ts
99
+ 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";
101
+
102
+ // src/extract/path-utils.ts
103
+ import { joinHandlerPath } from "@celerity-sdk/common";
104
+
105
+ // src/extract/identity.ts
106
+ import { basename, dirname, relative } from "path";
107
+ function deriveClassResourceName(className, methodName) {
108
+ const camelClass = className.charAt(0).toLowerCase() + className.slice(1);
109
+ return `${camelClass}_${methodName}`;
110
+ }
111
+ __name(deriveClassResourceName, "deriveClassResourceName");
112
+ function deriveClassHandlerName(className, methodName) {
113
+ return `${className}-${methodName}`;
114
+ }
115
+ __name(deriveClassHandlerName, "deriveClassHandlerName");
116
+ function deriveClassHandlerFunction(sourceFile, className, methodName) {
117
+ const base = basename(sourceFile).replace(/\.[^.]+$/, "");
118
+ return `${base}.${className}.${methodName}`;
119
+ }
120
+ __name(deriveClassHandlerFunction, "deriveClassHandlerFunction");
121
+ function deriveFunctionResourceName(exportName) {
122
+ return exportName;
123
+ }
124
+ __name(deriveFunctionResourceName, "deriveFunctionResourceName");
125
+ function deriveFunctionHandlerFunction(sourceFile, exportName) {
126
+ const base = basename(sourceFile).replace(/\.[^.]+$/, "");
127
+ return `${base}.${exportName}`;
128
+ }
129
+ __name(deriveFunctionHandlerFunction, "deriveFunctionHandlerFunction");
130
+ function deriveCodeLocation(sourceFile, projectRoot) {
131
+ const rel = relative(projectRoot, sourceFile);
132
+ const dir = dirname(rel);
133
+ return dir === "." ? "./" : `./${dir}`;
134
+ }
135
+ __name(deriveCodeLocation, "deriveCodeLocation");
136
+
137
+ // src/extract/serializer.ts
138
+ function serializeManifest(scanned, sourceFile, options) {
139
+ const handlers = [];
140
+ const functionHandlers = [];
141
+ for (const controllerClass of scanned.controllerClasses) {
142
+ const entries = serializeClassHandler(controllerClass, sourceFile, options);
143
+ handlers.push(...entries);
144
+ }
145
+ for (const fnHandler of scanned.functionHandlers) {
146
+ const entry = serializeFunctionHandler(fnHandler, sourceFile, options);
147
+ if (entry) {
148
+ functionHandlers.push(entry);
149
+ }
150
+ }
151
+ return {
152
+ version: "1.0.0",
153
+ handlers,
154
+ functionHandlers,
155
+ dependencyGraph: serializeDependencyGraph(scanned)
156
+ };
157
+ }
158
+ __name(serializeManifest, "serializeManifest");
159
+ function extractClassMeta(controllerClass) {
160
+ const controllerMeta = Reflect.getOwnMetadata(CONTROLLER_METADATA, controllerClass);
161
+ if (!controllerMeta) return null;
162
+ return {
163
+ prefix: controllerMeta.prefix ?? "",
164
+ protectedBy: Reflect.getOwnMetadata(GUARD_PROTECTEDBY_METADATA, controllerClass) ?? [],
165
+ customGuardName: Reflect.getOwnMetadata(GUARD_CUSTOM_METADATA, controllerClass),
166
+ customMetadata: Reflect.getOwnMetadata(CUSTOM_METADATA, controllerClass) ?? {}
167
+ };
168
+ }
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;
175
+ const methodProtectedBy = Reflect.getOwnMetadata(GUARD_PROTECTEDBY_METADATA, prototype, methodName) ?? [];
176
+ const allProtectedBy = [
177
+ ...classMeta.protectedBy,
178
+ ...methodProtectedBy
179
+ ];
180
+ if (allProtectedBy.length > 0) {
181
+ annotations["celerity.handler.guard.protectedBy"] = allProtectedBy;
182
+ }
183
+ if (classMeta.customGuardName) {
184
+ annotations["celerity.handler.guard.custom"] = classMeta.customGuardName;
185
+ }
186
+ const isPublic = Reflect.getOwnMetadata(PUBLIC_METADATA, prototype, methodName) === true;
187
+ if (isPublic) {
188
+ annotations["celerity.handler.public"] = true;
189
+ }
190
+ const methodCustomMetadata = Reflect.getOwnMetadata(CUSTOM_METADATA, prototype, methodName) ?? {};
191
+ const customMetadata = {
192
+ ...classMeta.customMetadata,
193
+ ...methodCustomMetadata
194
+ };
195
+ for (const [key, value] of Object.entries(customMetadata)) {
196
+ if (value === void 0) continue;
197
+ annotations[`celerity.handler.metadata.${key}`] = serializeAnnotationValue(value);
198
+ }
199
+ return annotations;
200
+ }
201
+ __name(buildMethodAnnotations, "buildMethodAnnotations");
202
+ function serializeClassHandler(controllerClass, sourceFile, options) {
203
+ const classMeta = extractClassMeta(controllerClass);
204
+ if (!classMeta) return [];
205
+ const className = controllerClass.name;
206
+ const prototype = controllerClass.prototype;
207
+ const methods = Object.getOwnPropertyNames(prototype).filter((n) => n !== "constructor");
208
+ const entries = [];
209
+ 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
+ });
228
+ }
229
+ return entries;
230
+ }
231
+ __name(serializeClassHandler, "serializeClassHandler");
232
+ function serializeFunctionHandler(definition, sourceFile, options) {
233
+ const exportName = definition.metadata.handlerName ?? "handler";
234
+ const customMetadata = definition.metadata.customMetadata ?? {};
235
+ 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
+ }
243
+ for (const [key, value] of Object.entries(customMetadata)) {
244
+ if (value === void 0) continue;
245
+ annotations[`celerity.handler.metadata.${key}`] = serializeAnnotationValue(value);
246
+ }
247
+ return {
248
+ resourceName: deriveFunctionResourceName(exportName),
249
+ exportName,
250
+ sourceFile,
251
+ ...Object.keys(annotations).length > 0 ? {
252
+ annotations
253
+ } : {},
254
+ spec: {
255
+ handlerName: exportName,
256
+ codeLocation: deriveCodeLocation(sourceFile, options.projectRoot),
257
+ handler: deriveFunctionHandlerFunction(sourceFile, exportName)
258
+ }
259
+ };
260
+ }
261
+ __name(serializeFunctionHandler, "serializeFunctionHandler");
262
+ function serializeAnnotationValue(value) {
263
+ if (typeof value === "boolean") return value;
264
+ if (typeof value === "string") return value;
265
+ if (Array.isArray(value) && value.every((v) => typeof v === "string")) {
266
+ return value;
267
+ }
268
+ return JSON.stringify(value);
269
+ }
270
+ __name(serializeAnnotationValue, "serializeAnnotationValue");
271
+ function serializeToken2(token) {
272
+ if (typeof token === "function") return token.name;
273
+ if (typeof token === "symbol") return token.description ?? "Symbol()";
274
+ return token;
275
+ }
276
+ __name(serializeToken2, "serializeToken");
277
+ function tokenType(token) {
278
+ if (typeof token === "function") return "class";
279
+ if (typeof token === "symbol") return "symbol";
280
+ return "string";
281
+ }
282
+ __name(tokenType, "tokenType");
283
+ function serializeDependencyGraph(scanned) {
284
+ const nodes = scanned.providers.map((provider) => ({
285
+ token: serializeToken2(provider.token),
286
+ tokenType: tokenType(provider.token),
287
+ providerType: provider.providerType,
288
+ dependencies: provider.dependencies.map(serializeToken2)
289
+ }));
290
+ return {
291
+ nodes
292
+ };
293
+ }
294
+ __name(serializeDependencyGraph, "serializeDependencyGraph");
295
+ export {
296
+ buildScannedModule,
297
+ deriveClassHandlerFunction,
298
+ deriveClassHandlerName,
299
+ deriveClassResourceName,
300
+ deriveCodeLocation,
301
+ deriveFunctionHandlerFunction,
302
+ deriveFunctionResourceName,
303
+ joinHandlerPath,
304
+ serializeManifest,
305
+ validateScannedDependencies
306
+ };
307
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/extract/metadata-app.ts","../src/extract/serializer.ts","../src/extract/path-utils.ts","../src/extract/identity.ts"],"sourcesContent":["import \"reflect-metadata\";\nimport createDebug from \"debug\";\nimport type {\n Type,\n InjectionToken,\n Provider,\n FunctionHandlerDefinition,\n} from \"@celerity-sdk/types\";\nimport {\n buildModuleGraph,\n getClassDependencyTokens,\n getProviderDependencyTokens,\n} from \"@celerity-sdk/core\";\nimport type { ModuleGraph } from \"@celerity-sdk/core\";\n\nconst debug = createDebug(\"celerity:cli\");\n\nexport type ScannedProvider = {\n token: InjectionToken;\n providerType: \"class\" | \"factory\" | \"value\";\n dependencies: InjectionToken[];\n};\n\nexport type ScannedModule = {\n controllerClasses: Type[];\n functionHandlers: FunctionHandlerDefinition[];\n providers: ScannedProvider[];\n};\n\nfunction scanProvider(\n provider: Type | (Provider & { provide: InjectionToken }),\n seenTokens: Set<InjectionToken>,\n): ScannedProvider | null {\n if (typeof provider === \"function\") {\n if (seenTokens.has(provider)) return null;\n seenTokens.add(provider);\n return {\n token: provider,\n providerType: \"class\",\n dependencies: getClassDependencyTokens(provider),\n };\n }\n\n const typed = provider as Provider & { provide: InjectionToken };\n if (seenTokens.has(typed.provide)) return null;\n seenTokens.add(typed.provide);\n\n return {\n token: typed.provide,\n providerType: \"useFactory\" in typed ? \"factory\" : \"useClass\" in typed ? \"class\" : \"value\",\n dependencies: getProviderDependencyTokens(typed),\n };\n}\n\n/**\n * Builds a scanned module from the root module class using the shared\n * `buildModuleGraph` from core. Collects all handler classes, function\n * handler definitions, and provider dependency information without\n * instantiating anything.\n *\n * Inherits circular import detection from the shared graph builder.\n */\nexport function buildScannedModule(rootModule: Type): ScannedModule {\n const graph: ModuleGraph = buildModuleGraph(rootModule);\n const controllerClasses: Type[] = [];\n const functionHandlers: FunctionHandlerDefinition[] = [];\n const providers: ScannedProvider[] = [];\n const seenTokens = new Set<InjectionToken>();\n\n for (const [moduleClass, node] of graph) {\n debug(\n \"scan: module %s — %d providers, %d controllers\",\n moduleClass.name,\n node.providers.length,\n node.controllers.length,\n );\n for (const provider of node.providers) {\n const scanned = scanProvider(provider, seenTokens);\n if (scanned) providers.push(scanned);\n }\n\n for (const controller of node.controllers) {\n controllerClasses.push(controller);\n if (!seenTokens.has(controller)) {\n seenTokens.add(controller);\n providers.push({\n token: controller,\n providerType: \"class\",\n dependencies: getClassDependencyTokens(controller),\n });\n }\n }\n\n functionHandlers.push(...node.functionHandlers);\n }\n\n return { controllerClasses, functionHandlers, providers };\n}\n\nexport type DependencyDiagnostic = {\n consumer: string;\n dependency: string;\n};\n\n/**\n * Validates that all scanned providers have resolvable dependencies.\n * Returns an array of diagnostics for each unresolvable dependency.\n * A token is resolvable if it's registered or is a class (implicitly constructable).\n */\nexport function validateScannedDependencies(scanned: ScannedModule): DependencyDiagnostic[] {\n const registeredTokens = new Set<InjectionToken>(scanned.providers.map((p) => p.token));\n const diagnostics: DependencyDiagnostic[] = [];\n const visited = new Set<InjectionToken>();\n\n function walk(token: InjectionToken, deps: InjectionToken[]): void {\n if (visited.has(token)) return;\n visited.add(token);\n\n for (const dep of deps) {\n if (registeredTokens.has(dep)) {\n const provider = scanned.providers.find((p) => p.token === dep);\n if (provider) {\n walk(dep, provider.dependencies);\n }\n } else if (typeof dep === \"function\") {\n walk(dep, getClassDependencyTokens(dep as Type));\n } else {\n diagnostics.push({\n consumer: serializeToken(token),\n dependency: serializeToken(dep),\n });\n }\n }\n }\n\n for (const provider of scanned.providers) {\n walk(provider.token, provider.dependencies);\n }\n\n return diagnostics;\n}\n\nfunction serializeToken(token: InjectionToken): string {\n if (typeof token === \"function\") return token.name;\n if (typeof token === \"symbol\") return token.description ?? \"Symbol()\";\n return String(token);\n}\n","import \"reflect-metadata\";\nimport type { Type, HttpMethod, InjectionToken } from \"@celerity-sdk/types\";\nimport {\n CONTROLLER_METADATA,\n HTTP_METHOD_METADATA,\n ROUTE_PATH_METADATA,\n GUARD_PROTECTEDBY_METADATA,\n GUARD_CUSTOM_METADATA,\n PUBLIC_METADATA,\n CUSTOM_METADATA,\n} from \"@celerity-sdk/core\";\nimport type { ControllerMetadata } from \"@celerity-sdk/core\";\nimport type { ScannedModule } from \"./metadata-app\";\nimport type {\n HandlerManifest,\n ClassHandlerEntry,\n FunctionHandlerEntry,\n DependencyGraph,\n DependencyNode,\n} from \"./types\";\nimport { joinHandlerPath } from \"./path-utils\";\nimport {\n deriveClassResourceName,\n deriveClassHandlerName,\n deriveClassHandlerFunction,\n deriveCodeLocation,\n deriveFunctionResourceName,\n deriveFunctionHandlerFunction,\n} from \"./identity\";\n\nexport type SerializeOptions = {\n projectRoot: string;\n};\n\nexport function serializeManifest(\n scanned: ScannedModule,\n sourceFile: string,\n options: SerializeOptions,\n): HandlerManifest {\n const handlers: ClassHandlerEntry[] = [];\n const functionHandlers: FunctionHandlerEntry[] = [];\n\n for (const controllerClass of scanned.controllerClasses) {\n const entries = serializeClassHandler(controllerClass, sourceFile, options);\n handlers.push(...entries);\n }\n\n for (const fnHandler of scanned.functionHandlers) {\n const entry = serializeFunctionHandler(fnHandler, sourceFile, options);\n if (entry) {\n functionHandlers.push(entry);\n }\n }\n\n return {\n version: \"1.0.0\",\n handlers,\n functionHandlers,\n dependencyGraph: serializeDependencyGraph(scanned),\n };\n}\n\ntype ClassMeta = {\n prefix: string;\n protectedBy: string[];\n customGuardName: string | undefined;\n customMetadata: Record<string, unknown>;\n};\n\nfunction extractClassMeta(controllerClass: Type): ClassMeta | null {\n const controllerMeta: ControllerMetadata | undefined = Reflect.getOwnMetadata(\n CONTROLLER_METADATA,\n controllerClass,\n );\n if (!controllerMeta) return null;\n\n return {\n prefix: controllerMeta.prefix ?? \"\",\n protectedBy: Reflect.getOwnMetadata(GUARD_PROTECTEDBY_METADATA, controllerClass) ?? [],\n customGuardName: Reflect.getOwnMetadata(GUARD_CUSTOM_METADATA, controllerClass),\n customMetadata: Reflect.getOwnMetadata(CUSTOM_METADATA, controllerClass) ?? {},\n };\n}\n\nfunction buildMethodAnnotations(\n classMeta: ClassMeta,\n prototype: object,\n methodName: string,\n httpMethod: HttpMethod,\n fullPath: string,\n): Record<string, string | string[] | boolean> {\n const annotations: Record<string, string | string[] | boolean> = {};\n\n annotations[\"celerity.handler.http\"] = true;\n annotations[\"celerity.handler.http.method\"] = httpMethod;\n annotations[\"celerity.handler.http.path\"] = fullPath;\n\n const methodProtectedBy: string[] =\n Reflect.getOwnMetadata(GUARD_PROTECTEDBY_METADATA, prototype, methodName) ?? [];\n const allProtectedBy = [...classMeta.protectedBy, ...methodProtectedBy];\n if (allProtectedBy.length > 0) {\n annotations[\"celerity.handler.guard.protectedBy\"] = allProtectedBy;\n }\n if (classMeta.customGuardName) {\n annotations[\"celerity.handler.guard.custom\"] = classMeta.customGuardName;\n }\n\n const isPublic: boolean = Reflect.getOwnMetadata(PUBLIC_METADATA, prototype, methodName) === true;\n if (isPublic) {\n annotations[\"celerity.handler.public\"] = true;\n }\n\n const methodCustomMetadata: Record<string, unknown> =\n Reflect.getOwnMetadata(CUSTOM_METADATA, prototype, methodName) ?? {};\n const customMetadata = { ...classMeta.customMetadata, ...methodCustomMetadata };\n for (const [key, value] of Object.entries(customMetadata)) {\n if (value === undefined) continue;\n annotations[`celerity.handler.metadata.${key}`] = serializeAnnotationValue(value);\n }\n\n return annotations;\n}\n\nfunction serializeClassHandler(\n controllerClass: Type,\n sourceFile: string,\n options: SerializeOptions,\n): ClassHandlerEntry[] {\n const classMeta = extractClassMeta(controllerClass);\n if (!classMeta) return [];\n\n const className = controllerClass.name;\n const prototype = controllerClass.prototype as object;\n const methods = Object.getOwnPropertyNames(prototype).filter((n) => n !== \"constructor\");\n const entries: ClassHandlerEntry[] = [];\n\n for (const methodName of methods) {\n const httpMethod: HttpMethod | undefined = Reflect.getOwnMetadata(\n HTTP_METHOD_METADATA,\n prototype,\n methodName,\n );\n if (!httpMethod) continue;\n\n const routePath: string =\n Reflect.getOwnMetadata(ROUTE_PATH_METADATA, prototype, methodName) ?? \"/\";\n const fullPath = joinHandlerPath(classMeta.prefix, routePath);\n const annotations = buildMethodAnnotations(\n classMeta,\n prototype,\n methodName,\n httpMethod,\n fullPath,\n );\n\n entries.push({\n resourceName: deriveClassResourceName(className, methodName),\n className,\n methodName,\n sourceFile,\n handlerType: \"http\",\n annotations,\n spec: {\n handlerName: deriveClassHandlerName(className, methodName),\n codeLocation: deriveCodeLocation(sourceFile, options.projectRoot),\n handler: deriveClassHandlerFunction(sourceFile, className, methodName),\n },\n });\n }\n\n return entries;\n}\n\nfunction serializeFunctionHandler(\n definition: { metadata: Record<string, unknown>; handler: (...args: unknown[]) => unknown },\n sourceFile: string,\n options: SerializeOptions,\n): FunctionHandlerEntry | null {\n // Function handlers don't have a reliable export name from the definition alone.\n // The CLI entry point will need to derive this from the module's named exports.\n // For now, use \"handler\" as a placeholder — the CLI enriches this.\n const exportName = (definition.metadata.handlerName as string) ?? \"handler\";\n const customMetadata = (definition.metadata.customMetadata as Record<string, unknown>) ?? {};\n\n const annotations: Record<string, string | string[] | boolean> = {};\n\n const path = definition.metadata.path as string | undefined;\n const method = definition.metadata.method as string | undefined;\n if (path !== undefined && method !== undefined) {\n annotations[\"celerity.handler.http\"] = true;\n annotations[\"celerity.handler.http.method\"] = method;\n annotations[\"celerity.handler.http.path\"] = path;\n }\n\n for (const [key, value] of Object.entries(customMetadata)) {\n if (value === undefined) continue;\n annotations[`celerity.handler.metadata.${key}`] = serializeAnnotationValue(value);\n }\n\n return {\n resourceName: deriveFunctionResourceName(exportName),\n exportName,\n sourceFile,\n ...(Object.keys(annotations).length > 0 ? { annotations } : {}),\n spec: {\n handlerName: exportName,\n codeLocation: deriveCodeLocation(sourceFile, options.projectRoot),\n handler: deriveFunctionHandlerFunction(sourceFile, exportName),\n },\n };\n}\n\nfunction serializeAnnotationValue(value: unknown): string | string[] | boolean {\n if (typeof value === \"boolean\") return value;\n if (typeof value === \"string\") return value;\n if (Array.isArray(value) && value.every((v) => typeof v === \"string\")) {\n return value as string[];\n }\n return JSON.stringify(value);\n}\n\nexport function serializeToken(token: InjectionToken): string {\n if (typeof token === \"function\") return token.name;\n if (typeof token === \"symbol\") return token.description ?? \"Symbol()\";\n return token;\n}\n\nexport function tokenType(token: InjectionToken): \"class\" | \"string\" | \"symbol\" {\n if (typeof token === \"function\") return \"class\";\n if (typeof token === \"symbol\") return \"symbol\";\n return \"string\";\n}\n\nfunction serializeDependencyGraph(scanned: ScannedModule): DependencyGraph {\n const nodes: DependencyNode[] = scanned.providers.map((provider) => ({\n token: serializeToken(provider.token),\n tokenType: tokenType(provider.token),\n providerType: provider.providerType,\n dependencies: provider.dependencies.map(serializeToken),\n }));\n\n return { nodes };\n}\n","export { joinHandlerPath } from \"@celerity-sdk/common\";\n","import { basename, dirname, relative } from \"node:path\";\n\n/**\n * Derives a resource name for a class-based handler method.\n * Format: camelCase(className) + \"_\" + methodName\n *\n * @example deriveClassResourceName(\"OrdersHandler\", \"getOrder\") => \"ordersHandler_getOrder\"\n */\nexport function deriveClassResourceName(className: string, methodName: string): string {\n const camelClass = className.charAt(0).toLowerCase() + className.slice(1);\n return `${camelClass}_${methodName}`;\n}\n\n/**\n * Derives a handler name for a class-based handler method.\n * Format: className + \"-\" + methodName\n *\n * @example deriveClassHandlerName(\"OrdersHandler\", \"getOrder\") => \"OrdersHandler-getOrder\"\n */\nexport function deriveClassHandlerName(className: string, methodName: string): string {\n return `${className}-${methodName}`;\n}\n\n/**\n * Derives the handler function reference for a class-based handler.\n * Format: moduleBaseName + \".\" + className + \".\" + methodName\n *\n * @example deriveClassHandlerFunction(\"src/handlers/orders.ts\", \"OrdersHandler\", \"getOrder\")\n * => \"orders.OrdersHandler.getOrder\"\n */\nexport function deriveClassHandlerFunction(\n sourceFile: string,\n className: string,\n methodName: string,\n): string {\n const base = basename(sourceFile).replace(/\\.[^.]+$/, \"\");\n return `${base}.${className}.${methodName}`;\n}\n\n/**\n * Derives a resource name for a function-based handler.\n * Uses the export name directly.\n *\n * @example deriveFunctionResourceName(\"getOrder\") => \"getOrder\"\n */\nexport function deriveFunctionResourceName(exportName: string): string {\n return exportName;\n}\n\n/**\n * Derives the handler function reference for a function-based handler.\n * Format: moduleBaseName + \".\" + exportName\n *\n * @example deriveFunctionHandlerFunction(\"src/handlers/orders.ts\", \"getOrder\")\n * => \"orders.getOrder\"\n */\nexport function deriveFunctionHandlerFunction(sourceFile: string, exportName: string): string {\n const base = basename(sourceFile).replace(/\\.[^.]+$/, \"\");\n return `${base}.${exportName}`;\n}\n\n/**\n * Derives the code location from a source file path relative to the project root.\n * Returns the directory prefixed with \"./\"\n *\n * @example deriveCodeLocation(\"src/handlers/orders.ts\", \"/project\") => \"./src/handlers\"\n */\nexport function deriveCodeLocation(sourceFile: string, projectRoot: string): string {\n const rel = relative(projectRoot, sourceFile);\n const dir = dirname(rel);\n return dir === \".\" ? \"./\" : `./${dir}`;\n}\n"],"mappings":";;;;AAAA,OAAO;AACP,OAAOA,iBAAiB;AAOxB,SACEC,kBACAC,0BACAC,mCACK;AAGP,IAAMC,QAAQC,YAAY,cAAA;AAc1B,SAASC,aACPC,UACAC,YAA+B;AAE/B,MAAI,OAAOD,aAAa,YAAY;AAClC,QAAIC,WAAWC,IAAIF,QAAAA,EAAW,QAAO;AACrCC,eAAWE,IAAIH,QAAAA;AACf,WAAO;MACLI,OAAOJ;MACPK,cAAc;MACdC,cAAcC,yBAAyBP,QAAAA;IACzC;EACF;AAEA,QAAMQ,QAAQR;AACd,MAAIC,WAAWC,IAAIM,MAAMC,OAAO,EAAG,QAAO;AAC1CR,aAAWE,IAAIK,MAAMC,OAAO;AAE5B,SAAO;IACLL,OAAOI,MAAMC;IACbJ,cAAc,gBAAgBG,QAAQ,YAAY,cAAcA,QAAQ,UAAU;IAClFF,cAAcI,4BAA4BF,KAAAA;EAC5C;AACF;AAvBST;AAiCF,SAASY,mBAAmBC,YAAgB;AACjD,QAAMC,QAAqBC,iBAAiBF,UAAAA;AAC5C,QAAMG,oBAA4B,CAAA;AAClC,QAAMC,mBAAgD,CAAA;AACtD,QAAMC,YAA+B,CAAA;AACrC,QAAMhB,aAAa,oBAAIiB,IAAAA;AAEvB,aAAW,CAACC,aAAaC,IAAAA,KAASP,OAAO;AACvChB,UACE,uDACAsB,YAAYE,MACZD,KAAKH,UAAUK,QACfF,KAAKG,YAAYD,MAAM;AAEzB,eAAWtB,YAAYoB,KAAKH,WAAW;AACrC,YAAMO,UAAUzB,aAAaC,UAAUC,UAAAA;AACvC,UAAIuB,QAASP,WAAUQ,KAAKD,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AI,OAAOmC,UAAU,SAAU,QAAOA,MAAMC,eAAe;AAC3D,SAAOD;AACT;AAJgBD,OAAAA,iBAAAA;AAMT,SAASG,UAAUF,OAAqB;AAC7C,MAAI,OAAOA,UAAU,WAAY,QAAO;AACxC,MAAI,OAAOA,UAAU,SAAU,QAAO;AACtC,SAAO;AACT;AAJgBE;AAMhB,SAASrE,yBAAyBf,SAAsB;AACtD,QAAMqF,QAA0BrF,QAAQsF,UAAUC,IAAI,CAACC,cAAc;IACnEN,OAAOD,gBAAeO,SAASN,KAAK;IACpCE,WAAWA,UAAUI,SAASN,KAAK;IACnCO,cAAcD,SAASC;IACvBC,cAAcF,SAASE,aAAaH,IAAIN,eAAAA;EAC1C,EAAA;AAEA,SAAO;IAAEI;EAAM;AACjB;AATStE;","names":["createDebug","buildModuleGraph","getClassDependencyTokens","getProviderDependencyTokens","debug","createDebug","scanProvider","provider","seenTokens","has","add","token","providerType","dependencies","getClassDependencyTokens","typed","provide","getProviderDependencyTokens","buildScannedModule","rootModule","graph","buildModuleGraph","controllerClasses","functionHandlers","providers","Set","moduleClass","node","name","length","controllers","scanned","push","controller","validateScannedDependencies","registeredTokens","map","p","diagnostics","visited","walk","deps","dep","find","consumer","serializeToken","dependency","description","String","CONTROLLER_METADATA","HTTP_METHOD_METADATA","ROUTE_PATH_METADATA","GUARD_PROTECTEDBY_METADATA","GUARD_CUSTOM_METADATA","PUBLIC_METADATA","CUSTOM_METADATA","joinHandlerPath","basename","dirname","relative","deriveClassResourceName","className","methodName","camelClass","charAt","toLowerCase","slice","deriveClassHandlerName","deriveClassHandlerFunction","sourceFile","base","basename","replace","deriveFunctionResourceName","exportName","deriveFunctionHandlerFunction","deriveCodeLocation","projectRoot","rel","relative","dir","dirname","serializeManifest","scanned","sourceFile","options","handlers","functionHandlers","controllerClass","controllerClasses","entries","serializeClassHandler","push","fnHandler","entry","serializeFunctionHandler","version","dependencyGraph","serializeDependencyGraph","extractClassMeta","controllerMeta","Reflect","getOwnMetadata","CONTROLLER_METADATA","prefix","protectedBy","GUARD_PROTECTEDBY_METADATA","customGuardName","GUARD_CUSTOM_METADATA","customMetadata","CUSTOM_METADATA","buildMethodAnnotations","classMeta","prototype","methodName","httpMethod","fullPath","annotations","methodProtectedBy","allProtectedBy","length","isPublic","PUBLIC_METADATA","methodCustomMetadata","key","value","Object","undefined","serializeAnnotationValue","className","name","methods","getOwnPropertyNames","filter","n","HTTP_METHOD_METADATA","routePath","ROUTE_PATH_METADATA","joinHandlerPath","resourceName","deriveClassResourceName","handlerType","spec","handlerName","deriveClassHandlerName","codeLocation","deriveCodeLocation","projectRoot","handler","deriveClassHandlerFunction","definition","exportName","metadata","path","method","deriveFunctionResourceName","keys","deriveFunctionHandlerFunction","Array","isArray","every","v","JSON","stringify","serializeToken","token","description","tokenType","nodes","providers","map","provider","providerType","dependencies"]}
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@celerity-sdk/cli",
3
+ "version": "0.2.0",
4
+ "description": "Build-time extraction tool for Celerity decorator metadata",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/newstack-cloud/celerity-node-sdk.git",
9
+ "directory": "packages/cli"
10
+ },
11
+ "type": "module",
12
+ "bin": {
13
+ "celerity-extract": "./dist/extract/cli.js"
14
+ },
15
+ "exports": {
16
+ ".": {
17
+ "import": {
18
+ "types": "./dist/index.d.ts",
19
+ "default": "./dist/index.js"
20
+ },
21
+ "require": {
22
+ "types": "./dist/index.d.cts",
23
+ "default": "./dist/index.cjs"
24
+ }
25
+ },
26
+ "./schemas/handler-manifest.v1.schema.json": "./schemas/handler-manifest.v1.schema.json"
27
+ },
28
+ "main": "./dist/index.cjs",
29
+ "module": "./dist/index.js",
30
+ "types": "./dist/index.d.ts",
31
+ "files": [
32
+ "dist",
33
+ "schemas"
34
+ ],
35
+ "engines": {
36
+ "node": ">=22.0.0"
37
+ },
38
+ "dependencies": {
39
+ "debug": "^4.4.0",
40
+ "reflect-metadata": "^0.2.0",
41
+ "@celerity-sdk/common": "^0.2.0",
42
+ "@celerity-sdk/types": "^0.2.0",
43
+ "@celerity-sdk/core": "^0.2.0"
44
+ },
45
+ "devDependencies": {
46
+ "ajv": "^8.17.0"
47
+ },
48
+ "publishConfig": {
49
+ "access": "public"
50
+ },
51
+ "scripts": {
52
+ "build": "tsup",
53
+ "dev": "tsup --watch",
54
+ "typecheck": "tsc --noEmit",
55
+ "clean": "rm -rf dist",
56
+ "test": "vitest run"
57
+ }
58
+ }
@@ -0,0 +1,181 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://celerityframework.com/schemas/handler-manifest.v1.schema.json",
4
+ "title": "Celerity Handler Manifest",
5
+ "description": "Output schema for the celerity-extract CLI tool. Describes all handlers discovered in a Celerity application module via decorator/metadata scanning. Consumed by the Celerity CLI to merge with blueprint infrastructure configuration.",
6
+ "type": "object",
7
+ "required": ["version", "handlers", "functionHandlers", "dependencyGraph"],
8
+ "additionalProperties": false,
9
+ "properties": {
10
+ "version": {
11
+ "const": "1.0.0",
12
+ "description": "Schema version. Consumers should check this field to ensure compatibility."
13
+ },
14
+ "handlers": {
15
+ "type": "array",
16
+ "description": "Class-based handlers discovered from @Controller-decorated classes.",
17
+ "items": { "$ref": "#/$defs/ClassHandlerEntry" }
18
+ },
19
+ "functionHandlers": {
20
+ "type": "array",
21
+ "description": "Function-based handlers registered via createHttpHandler / httpGet / httpPost / etc.",
22
+ "items": { "$ref": "#/$defs/FunctionHandlerEntry" }
23
+ },
24
+ "dependencyGraph": { "$ref": "#/$defs/DependencyGraph" }
25
+ },
26
+ "$defs": {
27
+ "AnnotationValue": {
28
+ "description": "Annotation values are serialized as strings, string arrays, or booleans. Complex objects are JSON-stringified into a string.",
29
+ "oneOf": [
30
+ { "type": "string" },
31
+ {
32
+ "type": "array",
33
+ "items": { "type": "string" }
34
+ },
35
+ { "type": "boolean" }
36
+ ]
37
+ },
38
+ "Annotations": {
39
+ "type": "object",
40
+ "description": "Key-value annotations using the 'celerity.handler.*' namespace. Well-known keys:\n- celerity.handler.http (boolean) — true if this is an HTTP handler\n- celerity.handler.http.method (string) — HTTP method (GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS)\n- celerity.handler.http.path (string) — full route path using {param} format\n- celerity.handler.guard.protectedBy (string[]) — guard names protecting this handler\n- celerity.handler.guard.custom (string) — custom guard name from @Guard decorator\n- celerity.handler.public (boolean) — true if handler opts out of guards via @Public\n- celerity.handler.metadata.* (any annotation value) — user-defined metadata from @SetMetadata / @Action",
41
+ "additionalProperties": { "$ref": "#/$defs/AnnotationValue" }
42
+ },
43
+ "ClassHandlerSpec": {
44
+ "type": "object",
45
+ "description": "Deployment specification for a class-based handler.",
46
+ "required": ["handlerName", "codeLocation", "handler"],
47
+ "additionalProperties": false,
48
+ "properties": {
49
+ "handlerName": {
50
+ "type": "string",
51
+ "description": "Unique handler identifier. Format: ClassName-methodName (e.g. 'OrdersHandler-getOrder')."
52
+ },
53
+ "codeLocation": {
54
+ "type": "string",
55
+ "description": "Relative directory path from project root, prefixed with './' (e.g. './src/handlers')."
56
+ },
57
+ "handler": {
58
+ "type": "string",
59
+ "description": "Fully qualified handler function reference. Format: moduleBaseName.ClassName.methodName (e.g. 'app.module.OrdersHandler.getOrder')."
60
+ },
61
+ "timeout": {
62
+ "type": "integer",
63
+ "minimum": 0,
64
+ "description": "Handler timeout in seconds. Optional — omitted when not explicitly configured."
65
+ }
66
+ }
67
+ },
68
+ "FunctionHandlerSpec": {
69
+ "type": "object",
70
+ "description": "Deployment specification for a function-based handler.",
71
+ "required": ["handlerName", "codeLocation", "handler"],
72
+ "additionalProperties": false,
73
+ "properties": {
74
+ "handlerName": {
75
+ "type": "string",
76
+ "description": "Handler identifier derived from the export name."
77
+ },
78
+ "codeLocation": {
79
+ "type": "string",
80
+ "description": "Relative directory path from project root, prefixed with './' (e.g. './src')."
81
+ },
82
+ "handler": {
83
+ "type": "string",
84
+ "description": "Fully qualified handler function reference. Format: moduleBaseName.exportName (e.g. 'app.module.getOrder')."
85
+ }
86
+ }
87
+ },
88
+ "ClassHandlerEntry": {
89
+ "type": "object",
90
+ "description": "A single handler method discovered from a @Controller-decorated class.",
91
+ "required": ["resourceName", "className", "methodName", "sourceFile", "handlerType", "annotations", "spec"],
92
+ "additionalProperties": false,
93
+ "properties": {
94
+ "resourceName": {
95
+ "type": "string",
96
+ "description": "Blueprint resource name. Format: camelCase(className)_methodName (e.g. 'ordersHandler_getOrder')."
97
+ },
98
+ "className": {
99
+ "type": "string",
100
+ "description": "Name of the controller class (e.g. 'OrdersHandler')."
101
+ },
102
+ "methodName": {
103
+ "type": "string",
104
+ "description": "Name of the handler method (e.g. 'getOrder')."
105
+ },
106
+ "sourceFile": {
107
+ "type": "string",
108
+ "description": "Absolute path to the source file containing the handler."
109
+ },
110
+ "handlerType": {
111
+ "type": "string",
112
+ "enum": ["http", "websocket", "consumer", "schedule"],
113
+ "description": "The type of handler, derived from the method decorators."
114
+ },
115
+ "annotations": { "$ref": "#/$defs/Annotations" },
116
+ "spec": { "$ref": "#/$defs/ClassHandlerSpec" }
117
+ }
118
+ },
119
+ "FunctionHandlerEntry": {
120
+ "type": "object",
121
+ "description": "A function-based handler registered via createHttpHandler or shorthand helpers. Function handlers provide identity only — routing configuration comes from the blueprint.",
122
+ "required": ["resourceName", "exportName", "sourceFile", "spec"],
123
+ "additionalProperties": false,
124
+ "properties": {
125
+ "resourceName": {
126
+ "type": "string",
127
+ "description": "Blueprint resource name derived from the export name."
128
+ },
129
+ "exportName": {
130
+ "type": "string",
131
+ "description": "The named export used to register this handler."
132
+ },
133
+ "sourceFile": {
134
+ "type": "string",
135
+ "description": "Absolute path to the source file containing the handler."
136
+ },
137
+ "annotations": { "$ref": "#/$defs/Annotations" },
138
+ "spec": { "$ref": "#/$defs/FunctionHandlerSpec" }
139
+ }
140
+ },
141
+ "DependencyNode": {
142
+ "type": "object",
143
+ "description": "A provider or controller in the DI dependency graph.",
144
+ "required": ["token", "tokenType", "providerType", "dependencies"],
145
+ "additionalProperties": false,
146
+ "properties": {
147
+ "token": {
148
+ "type": "string",
149
+ "description": "Serialized DI token. Class name for class tokens, raw string for string tokens, description for symbol tokens."
150
+ },
151
+ "tokenType": {
152
+ "type": "string",
153
+ "enum": ["class", "string", "symbol"],
154
+ "description": "The kind of DI token."
155
+ },
156
+ "providerType": {
157
+ "type": "string",
158
+ "enum": ["class", "factory", "value"],
159
+ "description": "How this provider is registered (useClass, useFactory, or useValue)."
160
+ },
161
+ "dependencies": {
162
+ "type": "array",
163
+ "items": { "type": "string" },
164
+ "description": "Serialized tokens of direct dependencies. Derived from constructor params (class) or inject array (factory)."
165
+ }
166
+ }
167
+ },
168
+ "DependencyGraph": {
169
+ "type": "object",
170
+ "description": "Full service dependency graph extracted from module metadata. Includes all providers and controllers with their DI dependencies.",
171
+ "required": ["nodes"],
172
+ "additionalProperties": false,
173
+ "properties": {
174
+ "nodes": {
175
+ "type": "array",
176
+ "items": { "$ref": "#/$defs/DependencyNode" }
177
+ }
178
+ }
179
+ }
180
+ }
181
+ }