@adaptivestone/framework 5.0.0-beta.45 → 5.0.0-beta.47

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.
Files changed (109) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/codegen/appTypes.d.ts +19 -0
  3. package/dist/codegen/appTypes.js +49 -0
  4. package/dist/codegen/appTypes.js.map +1 -0
  5. package/dist/codegen/collectMetadata.d.ts +37 -0
  6. package/dist/codegen/collectMetadata.js +51 -0
  7. package/dist/codegen/collectMetadata.js.map +1 -0
  8. package/dist/codegen/emit.d.ts +29 -0
  9. package/dist/codegen/emit.js +214 -0
  10. package/dist/codegen/emit.js.map +1 -0
  11. package/dist/codegen/index.d.ts +16 -0
  12. package/dist/codegen/index.js +18 -0
  13. package/dist/codegen/index.js.map +1 -0
  14. package/dist/codegen/routeTypes.d.ts +13 -0
  15. package/dist/codegen/routeTypes.js +126 -0
  16. package/dist/codegen/routeTypes.js.map +1 -0
  17. package/dist/commands/GenerateTypes.d.ts +0 -4
  18. package/dist/commands/GenerateTypes.js +4 -42
  19. package/dist/commands/GenerateTypes.js.map +1 -1
  20. package/dist/controllers/Auth.d.ts +15 -124
  21. package/dist/controllers/Auth.js.map +1 -1
  22. package/dist/controllers/Auth.routes.gen.d.ts +57 -0
  23. package/dist/controllers/Auth.routes.gen.js +10 -0
  24. package/dist/controllers/Auth.routes.gen.js.map +1 -0
  25. package/dist/controllers/Home.routes.gen.d.ts +14 -0
  26. package/dist/controllers/Home.routes.gen.js +10 -0
  27. package/dist/controllers/Home.routes.gen.js.map +1 -0
  28. package/dist/controllers/index.d.ts +23 -3
  29. package/dist/controllers/index.js +355 -8
  30. package/dist/controllers/index.js.map +1 -1
  31. package/dist/helpers/files.js +2 -0
  32. package/dist/helpers/files.js.map +1 -1
  33. package/dist/models/Sequence.js +1 -1
  34. package/dist/models/Sequence.js.map +1 -1
  35. package/dist/models/User.d.ts +28 -28
  36. package/dist/models/UserOld.d.ts +16 -6
  37. package/dist/modules/AbstractController.d.ts +7 -29
  38. package/dist/modules/AbstractController.js +1 -253
  39. package/dist/modules/AbstractController.js.map +1 -1
  40. package/dist/server.d.ts +0 -1
  41. package/dist/server.js +11 -1
  42. package/dist/server.js.map +1 -1
  43. package/dist/services/http/HttpServer.d.ts +9 -0
  44. package/dist/services/http/HttpServer.js +20 -9
  45. package/dist/services/http/HttpServer.js.map +1 -1
  46. package/dist/services/http/middleware/AbstractMiddleware.d.ts +19 -4
  47. package/dist/services/http/middleware/AbstractMiddleware.js +16 -5
  48. package/dist/services/http/middleware/AbstractMiddleware.js.map +1 -1
  49. package/dist/services/http/middleware/GetUserByToken.d.ts +9 -0
  50. package/dist/services/http/middleware/GetUserByToken.js +9 -0
  51. package/dist/services/http/middleware/GetUserByToken.js.map +1 -1
  52. package/dist/services/http/routing/ExpressAdapter.d.ts +12 -0
  53. package/dist/services/http/routing/ExpressAdapter.js +93 -0
  54. package/dist/services/http/routing/ExpressAdapter.js.map +1 -0
  55. package/dist/services/http/routing/RouteNode.d.ts +99 -0
  56. package/dist/services/http/routing/RouteNode.js +21 -0
  57. package/dist/services/http/routing/RouteNode.js.map +1 -0
  58. package/dist/services/http/routing/RouteRegistry.d.ts +37 -0
  59. package/dist/services/http/routing/RouteRegistry.js +207 -0
  60. package/dist/services/http/routing/RouteRegistry.js.map +1 -0
  61. package/dist/services/http/routing/formatTree.d.ts +23 -0
  62. package/dist/services/http/routing/formatTree.js +158 -0
  63. package/dist/services/http/routing/formatTree.js.map +1 -0
  64. package/dist/services/http/routing/match.d.ts +30 -0
  65. package/dist/services/http/routing/match.js +128 -0
  66. package/dist/services/http/routing/match.js.map +1 -0
  67. package/dist/services/http/routing/middlewareNormalization.d.ts +16 -0
  68. package/dist/services/http/routing/middlewareNormalization.js +28 -0
  69. package/dist/services/http/routing/middlewareNormalization.js.map +1 -0
  70. package/dist/services/http/types.d.ts +74 -0
  71. package/dist/services/http/types.js +8 -0
  72. package/dist/services/http/types.js.map +1 -0
  73. package/dist/services/validate/ValidateService.d.ts +46 -23
  74. package/dist/services/validate/ValidateService.js +101 -74
  75. package/dist/services/validate/ValidateService.js.map +1 -1
  76. package/dist/services/validate/ValidationError.d.ts +35 -0
  77. package/dist/services/validate/ValidationError.js +77 -0
  78. package/dist/services/validate/ValidationError.js.map +1 -0
  79. package/dist/services/validate/drivers/StandardSchemaDriver.d.ts +15 -0
  80. package/dist/services/validate/drivers/StandardSchemaDriver.js +34 -0
  81. package/dist/services/validate/drivers/StandardSchemaDriver.js.map +1 -0
  82. package/dist/services/validate/drivers/YupDriver.d.ts +21 -0
  83. package/dist/services/validate/drivers/YupDriver.js +66 -0
  84. package/dist/services/validate/drivers/YupDriver.js.map +1 -0
  85. package/dist/services/validate/types.d.ts +104 -0
  86. package/dist/services/validate/types.js +11 -0
  87. package/dist/services/validate/types.js.map +1 -0
  88. package/dist/tests/setupVitest.js +4 -1
  89. package/dist/tests/setupVitest.js.map +1 -1
  90. package/dist/tests/testHelpers.d.ts +18 -16
  91. package/package.json +17 -8
  92. package/dist/commands/Documentation.d.ts +0 -5
  93. package/dist/commands/Documentation.js +0 -15
  94. package/dist/commands/Documentation.js.map +0 -1
  95. package/dist/commands/GetOpenApiJson.d.ts +0 -17
  96. package/dist/commands/GetOpenApiJson.js +0 -272
  97. package/dist/commands/GetOpenApiJson.js.map +0 -1
  98. package/dist/services/documentation/DocumentationGenerator.d.ts +0 -11
  99. package/dist/services/documentation/DocumentationGenerator.js +0 -130
  100. package/dist/services/documentation/DocumentationGenerator.js.map +0 -1
  101. package/dist/services/validate/drivers/AbstractValidator.d.ts +0 -14
  102. package/dist/services/validate/drivers/AbstractValidator.js +0 -29
  103. package/dist/services/validate/drivers/AbstractValidator.js.map +0 -1
  104. package/dist/services/validate/drivers/CustomValidator.d.ts +0 -14
  105. package/dist/services/validate/drivers/CustomValidator.js +0 -48
  106. package/dist/services/validate/drivers/CustomValidator.js.map +0 -1
  107. package/dist/services/validate/drivers/YupValidator.d.ts +0 -13
  108. package/dist/services/validate/drivers/YupValidator.js +0 -86
  109. package/dist/services/validate/drivers/YupValidator.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -27,6 +27,18 @@ Main feature of that release is full TypeScript support insluding mongoose model
27
27
  - **[NEW]** Rate limiter middleware - add consumeResult function to allow user middleware as a regular rate limiter
28
28
  - **[NEW]** Ip detector middleware - add getIpAdressFromIncomingMessage function to allow user middleware as a detector of id adresses without middleware
29
29
  - **[NEW]** Introduce i18nService (ability to user i18n not only inside middleware)
30
+ - **[NEW]** [Standard Schema](https://standardschema.dev/) validation. Yup ≥1.7, Zod, Valibot, ArkType supported.
31
+ - **[NEW]** Pluggable `ValidatorDriver` + `ValidateService.register(driver)` for custom validators.
32
+ - **[NEW]** `StandardSchemaV1.InferOutput<typeof schema>` for compile-time handler types.
33
+ - **[NEW]** Framework-owned `ValidationError` with structured `.issues`. Wire-compatible.
34
+ - **[NEW]** Tree-based `RouteRegistry` replaces Express's hidden router internally. Lives on `app.httpServer.routeRegistry`. One global tree, walkable by codegen / OpenAPI / MCP emitters. The Express adapter mounts once (`app.express.use(adapter)`); path matching, parameter extraction, method dispatch, and middleware ordering all live in framework code now. 405 with `Allow` header, 400 on malformed paths, HEAD → GET fallback. Per-segment URL decoding (Spring's `PathPatternParser` model).
35
+ - **[NEW]** `app.controllerManager.registerController(ControllerClass, prefix?)` for explicit/programmatic controller registration. Auto-loading uses the same entry point internally. Register late via `Server.startServer`'s `callbackBefore404` hook so routes mount before the 404 handler.
36
+ - **[NEW]** Per-controller route type generation: `npm run gen` (alias for `npm run cli generatetypes`) emits `<File>.routes.gen.ts` next to each controller plus `genTypes.d.ts` at the project root. Handler signatures use `import type { PostLoginRequest } from './Auth.routes.gen.ts'` instead of hand-written `req: FrameworkRequest & { appInfo: { request: { ... } } }` intersections. Codegen walks `RouteRegistry.flatten()` so resolved middleware chains exactly match what the runtime executes (no parallel matcher). Gen files are gitignored — recommend `**/*.routes.gen.ts` in your `.gitignore` and `npm run gen && tsc --noEmit` in your `check:types` script.
37
+ - **[NEW]** Type contracts in `services/http/types`: `BaseRequestContext`, `BaseAppInfo`, `AppInfoExtensions` (module-augmentation point for app-wide globals), `ProvidesOf<T>`, `UnionAppInfoProvides<MWs>`. Codegen output composes these into per-handler `<MethodName>Request` aliases.
38
+ - **[NEW]** `static get provides()` convention on middlewares — declares what the middleware adds to `req.appInfo` (e.g., `GetUserByToken.provides` returns `{ user?: InstanceType<TUser> }`). Codegen reads this; runtime ignores it. Type-only phantom.
39
+ - **[NEW]** Boot-time route tree log at `verbose` log level. After all controllers register, the framework prints the full route registry: path structure, per-node attached middlewares (with inherited chain marked separately as `pmw:`), per-method handlers with their absolute path, schema flags (`[body]` / `[query]`), and route-level middleware (`[mw: ...]`). HTTP verbs are color-coded (blue GET, green POST, yellow PUT/PATCH, red DELETE, gray OPTIONS); `:param` and `*splat` segments stand out in magenta. ANSI codes are emitted unconditionally — looks right in TTY consoles, raw codes appear in file/Sentry transports for the one-time boot output.
40
+ - **[NEW]** `Server#getLogger()` registers a `shutdown` listener that drains the winston logger (`logger.close()`). Fixes 5s exit stall in CLI commands (`generatetypes`, etc.) caused by winston transport sockets keeping the event loop alive past the shutdown signal. The 5-second force-shutdown safety timer remains as zombie-prevention in production.
41
+ - **[NEW]** Boot-time warnings on misconfigured routes / middleware Maps. Framework now logs at `warn` level when it sees: unknown verb in the `routes` getter (anything other than `get/post/put/patch/delete/head/options`), a route object missing a callable `handler` field, a non-string key in the middleware `Map`, or an unknown method prefix on a `Map` key (e.g., a typo like `'PATC/login'`). Previously these silently produced 404s at request time.
30
42
 
31
43
  ### Breaking changes (please read carefully)
32
44
 
@@ -50,6 +62,16 @@ Main feature of that release is full TypeScript support insluding mongoose model
50
62
  - **[BREAKING]** Mongoose v8. <https://mongoosejs.com/docs/migrating_to_8.html>.
51
63
  - **[BREAKING]** Mongoose v9. <https://mongoosejs.com/docs/migrating_to_9.html>.
52
64
  - **[BREAKING]** Vitest v4 <https://vitest.dev/guide/migration.html#vitest-4>
65
+ - **[BREAKING]** Yup ≥1.7 required (was ≥1.0). Stays as a direct dep — used by built-in `Auth` controller. Schemas must implement Standard Schema (`~standard`); yup ≥1.7 does this natively.
66
+ - **[BREAKING]** Legacy `{validate, cast}` plain-object validators removed. Wrap as Standard Schema (~10 lines).
67
+ - **[BREAKING]** Yup `req:` context inside `.test()` / `.when()` removed. Use `this.parent` or move logic to handler.
68
+ - **[BREAKING]** Internal driver classes (`AbstractValidator`, `YupValidator`, `CustomValidator`) removed.
69
+ - **[BREAKING]** `ValidateService` surface trimmed to `{constructor, validate, resolve, register}`. Helpers like `validateReqData` removed.
70
+ - **[BREAKING]** `AbstractMiddleware.relatedQueryParameters` / `relatedRequestParameters` defaults changed from `yup.object().shape({})` to `null`. Override with any Standard Schema-conformant schema.
71
+ - **[BREAKING]** `BaseAppInfo.i18n` is now required (was optional in `FrameworkRequest`). Reflects runtime reality: `I18nMiddleware` is part of `HttpServer`'s default chain. If you removed I18n from your global chain, augment `BaseAppInfo` to relax the field.
72
+ - **[BREAKING]** OpenAPI / documentation generation removed: `framework documentation` and `framework getOpenApiJson` CLI commands, `DocumentationGenerator`, and `app.documentation` field deleted. Output was already partial after Standard Schema migration. Will return in later with per-vendor `toJsonSchema` support.
73
+ - **[BREAKING]** Path-pattern syntax narrowed. The new tree-based router supports literal segments, `:name` params (exactly one segment), and `{*name}` splats (zero or more segments to end of path). **Express 5's optional-param `{:name}` and inline regex are NOT supported.** If you had routes like `/fullpath/:paramOne/{:paramTwo}`, split into two explicit routes (`/fullpath/:paramOne` + `/fullpath/:paramOne/:paramTwo`) or restructure. Specificity is structural (static > param > splat); URL decoding is per-segment.
74
+ - **[BREAKING]** `AbstractController` constructor third argument `isExpressMergeParams` removed. The old default Express-router behavior of stripping parent params is gone — all matched params (across the full path, including the controller prefix) are available on `req.params`. If you relied on the merge-params toggle, no action needed in most cases; if you specifically depended on the strip behavior, restructure your handler to filter `req.params` keys.
53
75
 
54
76
  ---
55
77
  ## [5.0.0-beta.45]
@@ -0,0 +1,19 @@
1
+ /**
2
+ * App-level type generation. Emits a single `genTypes.d.ts` at
3
+ * `process.cwd()` that augments `IApp` so `getConfig('foo')` and
4
+ * `getModel('Bar')` are typed against the project's actual config /
5
+ * model files.
6
+ */
7
+ import type { IApp } from '../server.ts';
8
+ /** Subset of the framework logger we use here. */
9
+ export interface CodegenLogger {
10
+ info?(msg: string): void;
11
+ warn?(msg: string): void;
12
+ }
13
+ /** Generate the app-level `genTypes.d.ts` file. */
14
+ export declare function generateAppTypes(app: IApp, logger?: CodegenLogger | null): Promise<void>;
15
+ /** Render the `genTypes.d.ts` template text from configs + model paths. */
16
+ export declare function getTemplate(configs: Map<string, unknown>, modelPaths: {
17
+ file: string;
18
+ path: string;
19
+ }[]): Promise<string>;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * App-level type generation. Emits a single `genTypes.d.ts` at
3
+ * `process.cwd()` that augments `IApp` so `getConfig('foo')` and
4
+ * `getModel('Bar')` are typed against the project's actual config /
5
+ * model files.
6
+ */
7
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
8
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
9
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
10
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
11
+ });
12
+ }
13
+ return path;
14
+ };
15
+ import fs from 'node:fs/promises';
16
+ import { BaseModel } from "../modules/BaseModel.js";
17
+ /** Generate the app-level `genTypes.d.ts` file. */
18
+ export async function generateAppTypes(app, logger) {
19
+ const template = await getTemplate(app.internalFilesCache.configs, app.internalFilesCache.modelPaths);
20
+ await fs.writeFile(`${process.cwd()}/genTypes.d.ts`, template);
21
+ logger?.info?.('TypeScript types generated successfully at genTypes.d.ts');
22
+ }
23
+ /** Render the `genTypes.d.ts` template text from configs + model paths. */
24
+ export async function getTemplate(configs, modelPaths) {
25
+ const dir = process.cwd();
26
+ const configTypes = Array.from(configs)
27
+ .map((config) => ` getConfig(configName: '${config[0]}'): ${JSON.stringify(config[1], null, 6)};`)
28
+ .join('\n');
29
+ const modelTypes = (await Promise.all(modelPaths.map(async (modelPath) => {
30
+ const modelModule = await import(__rewriteRelativeImportExtension(modelPath.path));
31
+ const relPath = modelPath.path.replace(dir, '.');
32
+ if (modelModule.default.prototype instanceof BaseModel) {
33
+ return ` getModel(modelName: '${modelPath.file}'): GetModelTypeFromClass<typeof import('${relPath}').default>`;
34
+ }
35
+ return ` getModel(modelName: '${modelPath.file}'): import('${relPath}').default['mongooseModel']`;
36
+ }))).join('\n');
37
+ return `
38
+ import type {} from '@adaptivestone/framework/server.js';
39
+ import type { GetModelTypeFromClass } from '@adaptivestone/framework/modules/BaseModel.js';
40
+
41
+ declare module '@adaptivestone/framework/server.js' {
42
+ export interface IApp {
43
+ ${configTypes}
44
+ ${modelTypes}
45
+ }
46
+ }
47
+ `;
48
+ }
49
+ //# sourceMappingURL=appTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"appTypes.js","sourceRoot":"","sources":["../../src/codegen/appTypes.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;;;;;;;;;AAEH,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AASpD,mDAAmD;AACnD,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,GAAS,EACT,MAA6B;IAE7B,MAAM,QAAQ,GAAG,MAAM,WAAW,CAChC,GAAG,CAAC,kBAAkB,CAAC,OAAO,EAC9B,GAAG,CAAC,kBAAkB,CAAC,UAAU,CAClC,CAAC;IACF,MAAM,EAAE,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,GAAG,EAAE,gBAAgB,EAAE,QAAQ,CAAC,CAAC;IAC/D,MAAM,EAAE,IAAI,EAAE,CAAC,0DAA0D,CAAC,CAAC;AAC7E,CAAC;AAED,2EAA2E;AAC3E,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,OAA6B,EAC7B,UAA4C;IAE5C,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAC1B,MAAM,WAAW,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC;SACpC,GAAG,CACF,CAAC,MAAM,EAAE,EAAE,CACT,8BAA8B,MAAM,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,CACtF;SACA,IAAI,CAAC,IAAI,CAAC,CAAC;IAEd,MAAM,UAAU,GAAG,CACjB,MAAM,OAAO,CAAC,GAAG,CACf,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE;QACjC,MAAM,WAAW,GAAG,MAAM,MAAM,kCAAC,SAAS,CAAC,IAAI,EAAC,CAAC;QACjD,MAAM,OAAO,GAAG,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACjD,IAAI,WAAW,CAAC,OAAO,CAAC,SAAS,YAAY,SAAS,EAAE,CAAC;YACvD,OAAO,4BAA4B,SAAS,CAAC,IAAI,4CAA4C,OAAO,aAAa,CAAC;QACpH,CAAC;QACD,OAAO,4BAA4B,SAAS,CAAC,IAAI,eAAe,OAAO,6BAA6B,CAAC;IACvG,CAAC,CAAC,CACH,CACF,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEb,OAAO;;;;;;QAMD,WAAW;QACX,UAAU;;;CAGjB,CAAC;AACF,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Pure controller-shape extraction. Given an instantiated controller,
3
+ * walks the `routes` getter and returns a structural manifest with
4
+ * one entry per (method, path).
5
+ *
6
+ * Middleware chains are NOT computed here — that's the registry's job
7
+ * (`RouteRegistry.flatten()`). Codegen pairs this metadata with the
8
+ * registry output to render per-handler `<MethodName>Request` aliases.
9
+ */
10
+ import type AbstractController from '../modules/AbstractController.ts';
11
+ /** One middleware reference, with its parameters if it was declared as a tuple. */
12
+ export interface MiddlewareRef {
13
+ className: string;
14
+ /** Present when the middleware was declared as `[Class, params]` in a Map or route-level array. */
15
+ params?: Record<string, unknown>;
16
+ }
17
+ /** One route registered by a controller. */
18
+ export interface RouteMeta {
19
+ method: string;
20
+ path: string;
21
+ /** Method name on the controller (e.g., `'postLogin'`). `null` if the route's handler couldn't be identified. */
22
+ handlerName: string | null;
23
+ /** True when the route entry is `{ handler, request }` and `request` is set. */
24
+ hasSchema: boolean;
25
+ }
26
+ /** Aggregate metadata for one controller. */
27
+ export interface ControllerMeta {
28
+ /** Class name (e.g., `'Auth'`). */
29
+ className: string;
30
+ /** Folder prefix from auto-loader (`''` for top-level, `'test'` for `controllers/test/Foo.ts`). */
31
+ prefix: string;
32
+ /** URL prefix the controller mounts at (e.g., `/auth`). */
33
+ urlPrefix: string;
34
+ routes: RouteMeta[];
35
+ }
36
+ /** Extract metadata from one already-instantiated controller. */
37
+ export declare function extractControllerMeta(controller: AbstractController): ControllerMeta;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Pure controller-shape extraction. Given an instantiated controller,
3
+ * walks the `routes` getter and returns a structural manifest with
4
+ * one entry per (method, path).
5
+ *
6
+ * Middleware chains are NOT computed here — that's the registry's job
7
+ * (`RouteRegistry.flatten()`). Codegen pairs this metadata with the
8
+ * registry output to render per-handler `<MethodName>Request` aliases.
9
+ */
10
+ /** Extract metadata from one already-instantiated controller. */
11
+ export function extractControllerMeta(controller) {
12
+ const className = controller.constructor.name;
13
+ const prefix = controller.prefix;
14
+ const urlPrefix = controller.getHttpPath();
15
+ const routes = [];
16
+ for (const [verb, methodRoutes] of Object.entries(controller.routes)) {
17
+ for (const [path, entry] of Object.entries(methodRoutes)) {
18
+ routes.push(extractRouteMeta(verb, path, entry));
19
+ }
20
+ }
21
+ return { className, prefix, urlPrefix, routes };
22
+ }
23
+ function extractRouteMeta(verb, path, entry) {
24
+ // Bare method ref: `'/logout': this.postLogout`
25
+ if (typeof entry === 'function') {
26
+ return {
27
+ method: verb,
28
+ path,
29
+ handlerName: nameOf(entry),
30
+ hasSchema: false,
31
+ };
32
+ }
33
+ if (entry && typeof entry === 'object') {
34
+ const obj = entry;
35
+ return {
36
+ method: verb,
37
+ path,
38
+ handlerName: typeof obj.handler === 'function' ? nameOf(obj.handler) : null,
39
+ hasSchema: obj.request != null,
40
+ };
41
+ }
42
+ return { method: verb, path, handlerName: null, hasSchema: false };
43
+ }
44
+ function nameOf(value) {
45
+ if (typeof value === 'function') {
46
+ const fn = value;
47
+ return fn.name && fn.name.length > 0 ? fn.name : null;
48
+ }
49
+ return null;
50
+ }
51
+ //# sourceMappingURL=collectMetadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collectMetadata.js","sourceRoot":"","sources":["../../src/codegen/collectMetadata.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAgCH,iEAAiE;AACjE,MAAM,UAAU,qBAAqB,CACnC,UAA8B;IAE9B,MAAM,SAAS,GAAG,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC;IAC9C,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;IACjC,MAAM,SAAS,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC;IAE3C,MAAM,MAAM,GAAgB,EAAE,CAAC;IAC/B,KAAK,MAAM,CAAC,IAAI,EAAE,YAAY,CAAC,IAAI,MAAM,CAAC,OAAO,CAC/C,UAAU,CAAC,MAAiD,CAC7D,EAAE,CAAC;QACF,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;YACzD,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK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gen.ts` text. The output matches the hand-written format
4
+ * shipped in step 1.5 — same import shape, same per-handler `<Method>Request`
5
+ * aliases, same `InstanceType<typeof Controller>['routes']` navigation pattern.
6
+ *
7
+ * Import paths for middleware classes are reused verbatim from the controller's
8
+ * own source file. The gen file lives in the same directory as the controller,
9
+ * so relative paths to siblings (other middleware files, etc.) work without
10
+ * recomputation. Framework types (`BaseRequestContext`, `StandardSchemaV1`)
11
+ * are computed relative to the controller's location.
12
+ */
13
+ import type { ControllerMeta, MiddlewareRef } from './collectMetadata.ts';
14
+ /**
15
+ * Inputs the emit step needs that aren't in the metadata itself.
16
+ *
17
+ * `chains` is parallel to `controller.routes`: chains[i] is the resolved
18
+ * middleware list for routes[i], pre-computed by the caller via
19
+ * `RouteRegistry.flatten()` (single source of truth shared with runtime).
20
+ */
21
+ export interface EmitInput {
22
+ controller: ControllerMeta;
23
+ /** Absolute path to the controller's source `.ts` file. */
24
+ srcPath: string;
25
+ /** Resolved middleware chains, parallel to `controller.routes`. */
26
+ chains: MiddlewareRef[][];
27
+ }
28
+ /** Emit the gen.ts text for one controller. */
29
+ export declare function emitGenFile(input: EmitInput): Promise<string>;
@@ -0,0 +1,214 @@
1
+ /**
2
+ * Render one controller's metadata + resolved middleware chains into
3
+ * `<File>.routes.gen.ts` text. The output matches the hand-written format
4
+ * shipped in step 1.5 — same import shape, same per-handler `<Method>Request`
5
+ * aliases, same `InstanceType<typeof Controller>['routes']` navigation pattern.
6
+ *
7
+ * Import paths for middleware classes are reused verbatim from the controller's
8
+ * own source file. The gen file lives in the same directory as the controller,
9
+ * so relative paths to siblings (other middleware files, etc.) work without
10
+ * recomputation. Framework types (`BaseRequestContext`, `StandardSchemaV1`)
11
+ * are computed relative to the controller's location.
12
+ */
13
+ import { promises as fs } from 'node:fs';
14
+ import path from 'node:path';
15
+ import { fileURLToPath } from 'node:url';
16
+ /** Emit the gen.ts text for one controller. */
17
+ export async function emitGenFile(input) {
18
+ const { controller, srcPath, chains } = input;
19
+ const source = await fs.readFile(srcPath, 'utf8');
20
+ const importMap = parseImports(source);
21
+ // Drop chain entries whose middleware isn't imported by the controller
22
+ // file. Cross-controller propagation (e.g., a `/`-mounted controller
23
+ // pushing its `'/{*splat}'` middleware onto every other controller's
24
+ // chain) is the common case — the receiving controller doesn't import
25
+ // the propagating middleware. The runtime still runs them; the gen
26
+ // file just can't type them. v5.1 will thread `MiddlewareEntry.source`
27
+ // through so codegen can synthesize the import path itself.
28
+ const filteredChains = chains.map((chain) => chain.filter((mw) => importMap.has(mw.className)));
29
+ const uniqueMiddlewares = collectUniqueMiddlewares(filteredChains);
30
+ const frameworkRoot = findFrameworkSrcRoot(srcPath);
31
+ const ctrlDir = path.dirname(srcPath);
32
+ const isFrameworkOwnController = srcPath.startsWith(`${frameworkRoot}${path.sep}`);
33
+ const relFromCtrl = (target) => relativeImport(ctrlDir, target);
34
+ // Framework's own controllers (during framework dev / build) use
35
+ // relative imports because the framework references itself by relative
36
+ // path. External consumers' controllers use bare package specifiers
37
+ // so the gen file resolves through node_modules (or npm-linked
38
+ // framework) regardless of where in the consumer's tree it lives.
39
+ const typesPath = isFrameworkOwnController
40
+ ? relFromCtrl(path.join(frameworkRoot, 'services/http/types.ts'))
41
+ : '@adaptivestone/framework/services/http/types.js';
42
+ const validateTypesPath = isFrameworkOwnController
43
+ ? relFromCtrl(path.join(frameworkRoot, 'services/validate/types.ts'))
44
+ : '@adaptivestone/framework/services/validate/types.js';
45
+ const ctrlBaseName = path.basename(srcPath, '.ts');
46
+ const ctrlImportPath = `./${ctrlBaseName}.ts`;
47
+ const middlewareImports = uniqueMiddlewares
48
+ .map((mw) => `import type ${mw} from '${importMap.get(mw)}';`)
49
+ .sort();
50
+ const routesAlias = `${controller.className}Routes`;
51
+ const anyRouteHasSchema = controller.routes.some((r) => r.hasSchema);
52
+ // Group routes by handler name so a method serving multiple routes
53
+ // (e.g., both POST and GET wired to the same `getContainers`) emits
54
+ // a single union alias instead of duplicate identifiers.
55
+ const groupedByHandler = new Map();
56
+ for (let i = 0; i < controller.routes.length; i++) {
57
+ const route = controller.routes[i];
58
+ if (!route?.handlerName) {
59
+ continue;
60
+ }
61
+ const existing = groupedByHandler.get(route.handlerName);
62
+ const entry = { route, chain: filteredChains[i] ?? [] };
63
+ if (existing) {
64
+ existing.push(entry);
65
+ }
66
+ else {
67
+ groupedByHandler.set(route.handlerName, [entry]);
68
+ }
69
+ }
70
+ const handlerBlocks = [];
71
+ for (const [, group] of groupedByHandler) {
72
+ const block = renderHandlerGroup(group, routesAlias);
73
+ if (block !== null) {
74
+ handlerBlocks.push(block);
75
+ }
76
+ }
77
+ const importLines = [];
78
+ importLines.push(...middlewareImports);
79
+ importLines.push(`import type {`, ` BaseRequestContext,`, ` UnionAppInfoProvides,`, `} from '${typesPath}';`);
80
+ if (anyRouteHasSchema) {
81
+ importLines.push(`import type { StandardSchemaV1 } from '${validateTypesPath}';`);
82
+ importLines.push(`import type ${controller.className} from '${ctrlImportPath}';`);
83
+ }
84
+ const importBlock = importLines.join('\n');
85
+ const routesAliasBlock = anyRouteHasSchema
86
+ ? `\n/**\n * Type-level navigation into the controller's \`routes\` getter. Schema\n * references for inline schemas resolve through this alias.\n */\ntype ${routesAlias} = InstanceType<typeof ${controller.className}>['routes'];\n`
87
+ : '';
88
+ const header = `/**
89
+ * AUTOGENERATED — do not edit by hand.
90
+ *
91
+ * Regenerate with: \`npm run gen\`
92
+ *
93
+ * Source of truth: \`${ctrlBaseName}.ts\`'s \`routes\` getter and
94
+ * \`static get middleware()\` Map.
95
+ */
96
+ `;
97
+ return `${header}\n${importBlock}\n${routesAliasBlock}\n${handlerBlocks.join('\n\n')}\n`;
98
+ }
99
+ /**
100
+ * Build the `<MethodName>Request` alias for a group of routes sharing
101
+ * the same handler method. When the group has one route, emits a single
102
+ * shape. When the group has 2+ routes (one method, multiple verbs/paths),
103
+ * emits a union — narrow with `req.method` inside the handler.
104
+ *
105
+ * Output is intentionally single-line for the union/schema generics —
106
+ * gen files are gitignored, so biome skips them (`vcs.useIgnoreFile`),
107
+ * and TS doesn't care about line length. No formatter post-step needed.
108
+ */
109
+ function renderHandlerGroup(group, routesAlias) {
110
+ if (group.length === 0 || !group[0]?.route.handlerName) {
111
+ return null;
112
+ }
113
+ const handlerName = group[0].route.handlerName;
114
+ const typeName = `${pascalCase(handlerName)}Request`;
115
+ const docComment = group
116
+ .map(({ route }) => `\`${route.method.toUpperCase()} ${route.path}\``)
117
+ .join(', ');
118
+ const shapes = group.map(({ route, chain }) => renderShape(route, chain, routesAlias));
119
+ if (shapes.length === 1) {
120
+ return `/** Request type for ${docComment} (handler: \`${handlerName}\`). */
121
+ export type ${typeName} = ${shapes[0]};`;
122
+ }
123
+ return `/** Request type for ${docComment} (handler: \`${handlerName}\`). */
124
+ export type ${typeName} =
125
+ | ${shapes.join('\n | ')};`;
126
+ }
127
+ /** Render the BaseRequestContext intersection for one route. */
128
+ function renderShape(route, chain, routesAlias) {
129
+ const tupleInner = chain.length === 0
130
+ ? 'readonly []'
131
+ : `readonly [${chain.map((m) => `typeof ${m.className}`).join(', ')}]`;
132
+ const requestOverride = route.hasSchema
133
+ ? ` & { request: StandardSchemaV1.InferOutput<${routesAlias}['${route.method}']['${route.path}']['request']> }`
134
+ : '';
135
+ return `BaseRequestContext & { appInfo: UnionAppInfoProvides<${tupleInner}>${requestOverride} }`;
136
+ }
137
+ function collectUniqueMiddlewares(chains) {
138
+ const set = new Set();
139
+ for (const chain of chains) {
140
+ for (const mw of chain) {
141
+ set.add(mw.className);
142
+ }
143
+ }
144
+ return Array.from(set);
145
+ }
146
+ function pascalCase(name) {
147
+ if (name.length === 0) {
148
+ return name;
149
+ }
150
+ return name.charAt(0).toUpperCase() + name.slice(1);
151
+ }
152
+ /**
153
+ * Parse top-of-file `import` declarations into a binding-name → path map.
154
+ * Handles default imports (`import X from '…'`), namespace-style default
155
+ * (`import * as X from '…'`), and named imports (`import { A, B as C }
156
+ * from '…'`). Strips `import type` and `as Alias` rebinding.
157
+ */
158
+ function parseImports(source) {
159
+ const map = new Map();
160
+ const re = /import\s+(?:type\s+)?(?:(\w+)\s*,?\s*)?(?:\*\s+as\s+(\w+)\s+)?(?:\{([^}]+)\}\s+)?from\s+['"]([^'"]+)['"]/g;
161
+ let m;
162
+ while (true) {
163
+ m = re.exec(source);
164
+ if (m === null) {
165
+ break;
166
+ }
167
+ const [, defaultName, starName, namedBlock, importPath] = m;
168
+ if (defaultName) {
169
+ map.set(defaultName, importPath ?? '');
170
+ }
171
+ if (starName) {
172
+ map.set(starName, importPath ?? '');
173
+ }
174
+ if (namedBlock) {
175
+ for (const piece of namedBlock.split(',')) {
176
+ const trimmed = piece.trim();
177
+ if (!trimmed) {
178
+ continue;
179
+ }
180
+ // `OrigName as LocalName` → bind LocalName
181
+ const asMatch = trimmed.match(/(\w+)\s+as\s+(\w+)/);
182
+ const localName = asMatch
183
+ ? asMatch[2]
184
+ : trimmed.replace(/^type\s+/, '').trim();
185
+ if (localName) {
186
+ map.set(localName, importPath ?? '');
187
+ }
188
+ }
189
+ }
190
+ }
191
+ return map;
192
+ }
193
+ /**
194
+ * Find the framework's `src/` root by walking up from `srcPath` until we hit
195
+ * a directory whose name is `src`. Used to compute import paths to framework
196
+ * type modules. Falls back to walking up from this file's location.
197
+ */
198
+ function findFrameworkSrcRoot(_srcPath) {
199
+ // Use this module's own location to find src/, since we ship inside the
200
+ // framework. `import.meta.url` resolves to .../src/codegen/emit.ts.
201
+ const here = fileURLToPath(new URL('.', import.meta.url));
202
+ // here = .../src/codegen/
203
+ return path.resolve(here, '..');
204
+ }
205
+ /** Compute a TS-style relative import specifier from `fromDir` to `toFile`. */
206
+ function relativeImport(fromDir, toFile) {
207
+ let rel = path.relative(fromDir, toFile);
208
+ if (!rel.startsWith('.')) {
209
+ rel = `./${rel}`;
210
+ }
211
+ // Ensure forward slashes (cross-platform)
212
+ return rel.split(path.sep).join('/');
213
+ }
214
+ //# sourceMappingURL=emit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file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MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1D,0BAA0B;IAC1B,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AAClC,CAAC;AAED,+EAA+E;AAC/E,SAAS,cAAc,CAAC,OAAe,EAAE,MAAc;IACrD,IAAI,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACzC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACzB,GAAG,GAAG,KAAK,GAAG,EAAE,CAAC;IACnB,CAAC;IACD,0CAA0C;IAC1C,OAAO,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACvC,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Codegen public entry. Used by:
3
+ * - the `generatetypes` CLI command (`src/commands/GenerateTypes.ts`)
4
+ * - any programmatic caller (build plugin, watch mode, etc.)
5
+ *
6
+ * Splits into two outputs:
7
+ * - `genTypes.d.ts` at the project root (config + model maps)
8
+ * - `<File>.routes.gen.ts` next to each controller (handler request shapes)
9
+ */
10
+ import type { IApp } from '../server.ts';
11
+ import { type CodegenLogger, generateAppTypes } from './appTypes.ts';
12
+ import { generateRouteTypes } from './routeTypes.ts';
13
+ export type { CodegenLogger };
14
+ export { generateAppTypes, generateRouteTypes };
15
+ /** Generate both app-level and per-controller route types. */
16
+ export declare function generateAll(app: IApp, logger?: CodegenLogger | null): Promise<void>;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Codegen public entry. Used by:
3
+ * - the `generatetypes` CLI command (`src/commands/GenerateTypes.ts`)
4
+ * - any programmatic caller (build plugin, watch mode, etc.)
5
+ *
6
+ * Splits into two outputs:
7
+ * - `genTypes.d.ts` at the project root (config + model maps)
8
+ * - `<File>.routes.gen.ts` next to each controller (handler request shapes)
9
+ */
10
+ import { generateAppTypes } from "./appTypes.js";
11
+ import { generateRouteTypes } from "./routeTypes.js";
12
+ export { generateAppTypes, generateRouteTypes };
13
+ /** Generate both app-level and per-controller route types. */
14
+ export async function generateAll(app, logger) {
15
+ await generateAppTypes(app, logger);
16
+ await generateRouteTypes(app, logger);
17
+ }
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/codegen/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAsB,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAGrD,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,CAAC;AAEhD,8DAA8D;AAC9D,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,GAAS,EACT,MAA6B;IAE7B,MAAM,gBAAgB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IACpC,MAAM,kBAAkB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AACxC,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Per-controller route type generation. Boots the framework into an
3
+ * inspectable state, registers controllers with a fresh `RouteRegistry`,
4
+ * then walks `registry.flatten()` so the resolved middleware chain
5
+ * matches what the runtime actually executes (no parallel matcher).
6
+ *
7
+ * Emits `<File>.routes.gen.ts` next to each controller. Output is piped
8
+ * through biome at the end so re-runs don't churn whitespace.
9
+ */
10
+ import type { IApp } from '../server.ts';
11
+ import type { CodegenLogger } from './appTypes.ts';
12
+ /** Generate per-controller `.routes.gen.ts` files. */
13
+ export declare function generateRouteTypes(app: IApp, logger?: CodegenLogger | null): Promise<void>;