@dudousxd/nestjs-codegen 0.2.0 → 0.3.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.
@@ -20,16 +20,26 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/extension/index.ts
21
21
  var extension_exports = {};
22
22
  __export(extension_exports, {
23
- defineExtension: () => defineExtension
23
+ defineExtension: () => defineExtension,
24
+ requestShape: () => requestShape
24
25
  });
25
26
  module.exports = __toCommonJS(extension_exports);
26
27
 
27
28
  // src/extension/types.ts
29
+ function requestShape(route) {
30
+ const cs = route.contract?.contractSource;
31
+ const isGet = route.method.toUpperCase() === "GET";
32
+ const isQuery = isGet || !!cs?.filterFields?.length;
33
+ const hasBody = !!cs?.bodyRef || cs?.body != null && cs.body !== "never";
34
+ const hasQuery = isGet || !!cs?.queryRef || cs?.query != null && cs.query !== "never";
35
+ return { isGet, isQuery, hasBody, hasQuery };
36
+ }
28
37
  function defineExtension(ext) {
29
38
  return ext;
30
39
  }
31
40
  // Annotate the CommonJS export names for ESM import in node:
32
41
  0 && (module.exports = {
33
- defineExtension
42
+ defineExtension,
43
+ requestShape
34
44
  });
35
45
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/extension/index.ts","../../src/extension/types.ts"],"sourcesContent":["export { defineExtension } from './types.js';\nexport type {\n ApiClientLayer,\n ApiHeaderContribution,\n ApiModuleDeps,\n ApiTransport,\n CodegenExtension,\n EmittedFile,\n ExtensionContext,\n LeafModel,\n RequestModel,\n} from './types.js';\n","import type { Project } from 'ts-morph';\nimport type { ResolvedConfig } from '../config/types.js';\nimport type { RouteDescriptor } from '../discovery/types.js';\n\n/**\n * The published, versioned extension contract for `@dudousxd/nestjs-codegen`.\n *\n * Extensions are **build-time** objects (usually returned by a factory so they can take\n * options) registered explicitly via `forRoot({ extensions: [...] })`. The host runs them\n * around the core discovery → IR → emit pipeline.\n *\n * Hooks split into **multi** (every extension runs; results accumulate or chain) and\n * **single-slot** (at most one extension may claim it — two claimers is a hard error).\n *\n * @remarks Semver 0.x — the shape may change until 1.0. Out-of-repo extensions should pin\n * a compatible `@dudousxd/nestjs-codegen` peer range.\n */\nexport interface CodegenExtension {\n /** Unique id. Used in conflict/collision errors and for deterministic ordering. */\n name: string;\n\n // ── multi hooks (every extension runs) ────────────────────────────────────\n\n /**\n * Mutate/augment the route IR before emit. Runs in registration order, chained\n * (each extension sees the previous one's output). Return the new array, or mutate\n * in place and return void. Example: the filter extension attaches `filterFields` to\n * matching routes here.\n */\n transformRoutes?(\n routes: RouteDescriptor[],\n ctx: ExtensionContext,\n ): RouteDescriptor[] | undefined | Promise<RouteDescriptor[] | undefined>;\n\n /**\n * Contribute extra output files (additive). Paths are relative to `outDir`; a path\n * claimed by two extensions is a hard error. Example: the Inertia extension does its\n * own page discovery via `ctx.project()` and emits `pages.d.ts` + `components.json`.\n */\n emitFiles?(ctx: ExtensionContext): EmittedFile[] | Promise<EmittedFile[]>;\n\n /**\n * Contribute top-level code to `api.ts` (imports + statements). Runs in registration\n * order; imports are deduped by the host. Example: the Inertia extension adds\n * `import { router } from '@inertiajs/react'` and the `navigate()` helper.\n */\n apiHeader?(ctx: ExtensionContext): ApiHeaderContribution | undefined;\n\n /**\n * Add named members to a **handle** leaf. Only runs when a client layer is active\n * (i.e. the leaf is a handle, not a bare callable). Member-name collisions across\n * extensions are a hard error. Example: the filter extension adds `filterQuery` to\n * leaves whose route carries `filterFields`.\n */\n apiMembers?(leaf: LeafModel, ctx: ExtensionContext): Record<string, string> | undefined;\n\n // ── single-slot hooks (at most one extension) ─────────────────────────────\n\n /**\n * Claims **how** a single endpoint issues its request. When unset by every extension,\n * the host falls back to the neutral fetcher transport. Example: the Inertia extension\n * routes mutations through the Inertia router while GETs stay fetcher-typed.\n */\n apiTransport?: ApiTransport;\n\n /**\n * Claims **what** a leaf returns. When unset, a leaf is a bare callable returning a\n * `Promise`. Example: the TanStack extension wraps each leaf into a handle exposing\n * `{ fetch, queryKey, queryOptions | mutationOptions }`.\n */\n apiClientLayer?: ApiClientLayer;\n}\n\n/** Shared, read-only context handed to every extension hook. */\nexport interface ExtensionContext {\n cwd: string;\n outDir: string;\n routes: readonly RouteDescriptor[];\n config: ResolvedConfig;\n /** Lazily-created shared ts-morph Project for AST work (pages, custom decorators). */\n project(): Project;\n}\n\n/** A file contributed by an extension's `emitFiles` hook. */\nexport interface EmittedFile {\n /** Path relative to `outDir`. A collision across extensions throws. */\n path: string;\n contents: string;\n}\n\n/** Top-level `api.ts` contributions from an extension's `apiHeader` hook. */\nexport interface ApiHeaderContribution {\n /** Raw import lines (e.g. `import { router } from '@inertiajs/react';`), deduped by the host. */\n imports?: string[];\n /** Top-level statements appended after the api factory (e.g. the `navigate()` helper). */\n statements?: string[];\n}\n\n/**\n * The neutral, per-endpoint request model the host builds for each leaf before any\n * transport/layer runs. Extensions read this to render their output.\n */\nexport interface RequestModel {\n /** Dot-path route name, e.g. `users.show`. */\n routeName: string;\n method: 'get' | 'post' | 'put' | 'patch' | 'delete';\n isGet: boolean;\n /** True for reads: a GET, or a filter-search route (has `filterFields`) even when POST.\n * Client layers use this (not `isGet`) to decide query vs mutation helpers. */\n isQuery: boolean;\n hasParams: boolean;\n hasBody: boolean;\n /** Type of the leaf's `input` arg, e.g. `{ params: ...; query?: ... }` or `Record<string, never>`. */\n inputType: string;\n /** URL expression, e.g. `route('users.show', input?.params) || '/api/users/:id'`. */\n urlExpr: string;\n /** Request-options expression, e.g. `{ query: ... }` or `{ body: input?.body }`. */\n optsExpr: string;\n /** Response type access, e.g. `ApiRouter['users']['show']['response']`. */\n responseType: string;\n /** Body type access, e.g. `ApiRouter['users']['create']['body']` (for mutation layers). */\n bodyType: string;\n /** Stable query-key expression, e.g. `[\"users.show\", input] as const`. */\n queryKeyExpr: string;\n}\n\n/**\n * Per-leaf model passed through the api.ts pipeline: transport → layer → member\n * contributors → render. `requestExpr` is set by the transport; `members`, when present,\n * flips the leaf from a bare callable to a handle.\n */\nexport interface LeafModel {\n route: RouteDescriptor;\n request: RequestModel;\n /** The expression that issues the request (set by the transport, default = fetcher). */\n requestExpr: string;\n /** When present, the leaf renders as a handle exposing these members (ordered). */\n members?: Record<string, string>;\n}\n\n/**\n * Top-level `api.ts` imports + helpers a transport or layer depends on. Functions of the\n * context so they can be route-aware (e.g. only import `mutationOptions` when a mutation\n * exists). Imports are deduped by the host across all extensions.\n */\nexport interface ApiModuleDeps {\n /** Raw import lines (e.g. `import { queryOptions as _q } from '@tanstack/react-query';`). */\n imports?(ctx: ExtensionContext): string[];\n /** Module-level helper declarations the rendered expressions depend on. */\n helpers?(ctx: ExtensionContext): string[];\n}\n\n/** Single-slot: decides how an endpoint issues its request. */\nexport interface ApiTransport extends ApiModuleDeps {\n name: string;\n /** Render the expression that issues this endpoint's request (e.g. `fetcher.get<Res>(url, opts)`). */\n renderRequest(leaf: LeafModel, ctx: ExtensionContext): string;\n}\n\n/** Single-slot: decides what a leaf returns (the handle members). */\nexport interface ApiClientLayer extends ApiModuleDeps {\n name: string;\n /**\n * Given the request expression (from the transport) and the leaf, return the handle's\n * members as an ordered `name → value` map (value is the expression after `name: `).\n * Returning members flips the leaf from a bare callable to a handle.\n */\n buildMembers(requestExpr: string, leaf: LeafModel, ctx: ExtensionContext): Record<string, string>;\n}\n\n/** Identity helper for authoring extensions with full type inference. */\nexport function defineExtension(ext: CodegenExtension): CodegenExtension {\n return ext;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC2KO,SAAS,gBAAgB,KAAyC;AACvE,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/extension/index.ts","../../src/extension/types.ts"],"sourcesContent":["export { defineExtension, requestShape } from './types.js';\nexport type {\n ApiClientLayer,\n ApiHeaderContribution,\n ApiModuleDeps,\n CodegenExtension,\n EmittedFile,\n ExtensionContext,\n LeafModel,\n RequestModel,\n RequestShape,\n} from './types.js';\n","import type { Project } from 'ts-morph';\nimport type { ResolvedConfig } from '../config/types.js';\nimport type { RouteDescriptor } from '../discovery/types.js';\n\n/**\n * The published, versioned extension contract for `@dudousxd/nestjs-codegen`.\n *\n * Extensions are **build-time** objects (usually returned by a factory so they can take\n * options) registered explicitly via `forRoot({ extensions: [...] })`. The host runs them\n * around the core discovery → IR → emit pipeline.\n *\n * Hooks split into **multi** (every extension runs; results accumulate or chain) and\n * **single-slot** (at most one extension may claim it — two claimers is a hard error).\n *\n * @remarks Semver 0.x — the shape may change until 1.0. Out-of-repo extensions should pin\n * a compatible `@dudousxd/nestjs-codegen` peer range.\n */\nexport interface CodegenExtension {\n /** Unique id. Used in conflict/collision errors and for deterministic ordering. */\n name: string;\n\n // ── multi hooks (every extension runs) ────────────────────────────────────\n\n /**\n * Mutate/augment the route IR before emit. Runs in registration order, chained\n * (each extension sees the previous one's output). Return the new array, or mutate\n * in place and return void. Example: the filter extension attaches `filterFields` to\n * matching routes here.\n */\n transformRoutes?(\n routes: RouteDescriptor[],\n ctx: ExtensionContext,\n ): RouteDescriptor[] | undefined | Promise<RouteDescriptor[] | undefined>;\n\n /**\n * Contribute extra output files (additive). Paths are relative to `outDir`; a path\n * claimed by two extensions is a hard error. Example: the Inertia extension does its\n * own page discovery via `ctx.project()` and emits `pages.d.ts` + `components.json`.\n */\n emitFiles?(ctx: ExtensionContext): EmittedFile[] | Promise<EmittedFile[]>;\n\n /**\n * Contribute top-level code to `api.ts` (imports + statements). Runs in registration\n * order; imports are deduped by the host. Example: the Inertia extension adds\n * `import { router } from '@inertiajs/react'` and the `navigate()` helper.\n */\n apiHeader?(ctx: ExtensionContext): ApiHeaderContribution | undefined;\n\n /**\n * Add named members to a **handle** leaf. Only runs when a client layer is active\n * (i.e. the leaf is a handle, not a bare callable). Member-name collisions across\n * extensions are a hard error. Example: the filter extension adds `filterQuery` to\n * leaves whose route carries `filterFields`.\n */\n apiMembers?(leaf: LeafModel, ctx: ExtensionContext): Record<string, string> | undefined;\n\n // ── single-slot hooks (at most one extension) ─────────────────────────────\n\n /**\n * Claims **what** a leaf returns and **how** it issues its request. At most one extension\n * may claim it. When unset, a leaf is a bare awaitable callable backed by the neutral\n * fetcher. Example: the TanStack extension wraps each leaf into a handle exposing\n * `{ fetch, queryKey, queryOptions | mutationOptions }`, composing with the fetcher\n * request the host passes in.\n */\n apiClientLayer?: ApiClientLayer;\n}\n\n/** Shared, read-only context handed to every extension hook. */\nexport interface ExtensionContext {\n cwd: string;\n outDir: string;\n routes: readonly RouteDescriptor[];\n config: ResolvedConfig;\n /** Lazily-created shared ts-morph Project for AST work (pages, custom decorators). */\n project(): Project;\n}\n\n/** A file contributed by an extension's `emitFiles` hook. */\nexport interface EmittedFile {\n /** Path relative to `outDir`. A collision across extensions throws. */\n path: string;\n contents: string;\n}\n\n/** Top-level `api.ts` contributions from an extension's `apiHeader` hook. */\nexport interface ApiHeaderContribution {\n /** Raw import lines (e.g. `import { router } from '@inertiajs/react';`), deduped by the host. */\n imports?: string[];\n /** Top-level statements appended after the api factory (e.g. the `navigate()` helper). */\n statements?: string[];\n}\n\n/**\n * The neutral, per-endpoint request model the host builds for each leaf before any\n * transport/layer runs. Extensions read this to render their output.\n */\nexport interface RequestModel {\n /** Dot-path route name, e.g. `users.show`. */\n routeName: string;\n method: 'get' | 'post' | 'put' | 'patch' | 'delete';\n isGet: boolean;\n /** True for reads: a GET, or a filter-search route (has `filterFields`) even when POST.\n * Client layers use this (not `isGet`) to decide query vs mutation helpers. */\n isQuery: boolean;\n hasParams: boolean;\n hasBody: boolean;\n /** Type of the leaf's `input` arg, e.g. `{ params: ...; query?: ... }` or `Record<string, never>`. */\n inputType: string;\n /** URL expression, e.g. `route('users.show', input?.params) || '/api/users/:id'`. */\n urlExpr: string;\n /** Request-options expression, e.g. `{ query: ... }` or `{ body: input?.body }`. */\n optsExpr: string;\n /** Response type access, e.g. `ApiRouter['users']['show']['response']`. */\n responseType: string;\n /** Stable query-key expression, e.g. `[\"users.show\", input] as const`. */\n queryKeyExpr: string;\n}\n\n/**\n * Per-leaf model passed through the api.ts pipeline: layer → member contributors → render.\n * `requestExpr` is the host's neutral fetcher request; `members`, when present, flips the\n * leaf from a bare callable to a handle.\n */\nexport interface LeafModel {\n route: RouteDescriptor;\n request: RequestModel;\n /** The expression that issues the request (the host's neutral fetcher call). */\n requestExpr: string;\n /** When present, the leaf renders as a handle exposing these members (ordered). */\n members?: Record<string, string>;\n}\n\n/**\n * Top-level `api.ts` imports a client layer depends on. A function of the context so it can\n * be route-aware (e.g. only import `mutationOptions` when a mutation exists). Imports are\n * deduped by the host across all extensions.\n */\nexport interface ApiModuleDeps {\n /** Raw import lines (e.g. `import { queryOptions as _q } from '@tanstack/react-query';`). */\n imports?(ctx: ExtensionContext): string[];\n}\n\n/** Single-slot: decides what a leaf returns (the handle members). */\nexport interface ApiClientLayer extends ApiModuleDeps {\n name: string;\n /**\n * Given the request expression (from the transport) and the leaf, return the handle's\n * members as an ordered `name → value` map (value is the expression after `name: `).\n * Returning members flips the leaf from a bare callable to a handle.\n */\n buildMembers(requestExpr: string, leaf: LeafModel, ctx: ExtensionContext): Record<string, string>;\n}\n\n/**\n * The four request-shape flags derived from a route's method + contract. Computed in ONE\n * place ({@link requestShape}) and read by both the host emitter and client-layer\n * extensions, so the \"filter-search POST counts as a read\" rule is encoded exactly once.\n */\nexport interface RequestShape {\n /** The route is a `GET`. */\n isGet: boolean;\n /** True for reads: a GET, or a filter-search route (carries `filterFields`) even when POST.\n * Client layers use this (not `isGet`) to decide query vs mutation helpers. */\n isQuery: boolean;\n /** The route carries a body contract (a mutation payload). */\n hasBody: boolean;\n /** The route can take a query string — always for GET; a mutation may too (query + body). */\n hasQuery: boolean;\n}\n\n/**\n * Compute the {@link RequestShape} flags for a route from its method and contract. This is\n * the SINGLE source of truth for these flags — `buildRequestModel`, the TanStack layer's\n * `imports()`, and any other reader must call this rather than re-deriving. The\n * \"filter-search POST counts as a read\" rule lives here and nowhere else.\n */\nexport function requestShape(route: RouteDescriptor): RequestShape {\n const cs = route.contract?.contractSource;\n const isGet = route.method.toUpperCase() === 'GET';\n const isQuery = isGet || !!cs?.filterFields?.length;\n const hasBody = !!cs?.bodyRef || (cs?.body != null && cs.body !== 'never');\n const hasQuery = isGet || !!cs?.queryRef || (cs?.query != null && cs.query !== 'never');\n return { isGet, isQuery, hasBody, hasQuery };\n}\n\n/** Identity helper for authoring extensions with full type inference. */\nexport function defineExtension(ext: CodegenExtension): CodegenExtension {\n return ext;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACiLO,SAAS,aAAa,OAAsC;AACjE,QAAM,KAAK,MAAM,UAAU;AAC3B,QAAM,QAAQ,MAAM,OAAO,YAAY,MAAM;AAC7C,QAAM,UAAU,SAAS,CAAC,CAAC,IAAI,cAAc;AAC7C,QAAM,UAAU,CAAC,CAAC,IAAI,WAAY,IAAI,QAAQ,QAAQ,GAAG,SAAS;AAClE,QAAM,WAAW,SAAS,CAAC,CAAC,IAAI,YAAa,IAAI,SAAS,QAAQ,GAAG,UAAU;AAC/E,SAAO,EAAE,OAAO,SAAS,SAAS,SAAS;AAC7C;AAGO,SAAS,gBAAgB,KAAyC;AACvE,SAAO;AACT;","names":[]}
@@ -1,2 +1,2 @@
1
- export { l as ApiClientLayer, m as ApiHeaderContribution, n as ApiModuleDeps, o as ApiTransport, C as CodegenExtension, p as EmittedFile, E as ExtensionContext, L as LeafModel, q as RequestModel, s as defineExtension } from '../index-BwIRjOQA.cjs';
1
+ export { l as ApiClientLayer, m as ApiHeaderContribution, n as ApiModuleDeps, C as CodegenExtension, o as EmittedFile, E as ExtensionContext, L as LeafModel, p as RequestModel, q as RequestShape, s as defineExtension, t as requestShape } from '../index-oH5t7x4G.cjs';
2
2
  import 'ts-morph';
@@ -1,2 +1,2 @@
1
- export { l as ApiClientLayer, m as ApiHeaderContribution, n as ApiModuleDeps, o as ApiTransport, C as CodegenExtension, p as EmittedFile, E as ExtensionContext, L as LeafModel, q as RequestModel, s as defineExtension } from '../index-BwIRjOQA.js';
1
+ export { l as ApiClientLayer, m as ApiHeaderContribution, n as ApiModuleDeps, C as CodegenExtension, o as EmittedFile, E as ExtensionContext, L as LeafModel, p as RequestModel, q as RequestShape, s as defineExtension, t as requestShape } from '../index-oH5t7x4G.js';
2
2
  import 'ts-morph';
@@ -1,8 +1,17 @@
1
1
  // src/extension/types.ts
2
+ function requestShape(route) {
3
+ const cs = route.contract?.contractSource;
4
+ const isGet = route.method.toUpperCase() === "GET";
5
+ const isQuery = isGet || !!cs?.filterFields?.length;
6
+ const hasBody = !!cs?.bodyRef || cs?.body != null && cs.body !== "never";
7
+ const hasQuery = isGet || !!cs?.queryRef || cs?.query != null && cs.query !== "never";
8
+ return { isGet, isQuery, hasBody, hasQuery };
9
+ }
2
10
  function defineExtension(ext) {
3
11
  return ext;
4
12
  }
5
13
  export {
6
- defineExtension
14
+ defineExtension,
15
+ requestShape
7
16
  };
8
17
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/extension/types.ts"],"sourcesContent":["import type { Project } from 'ts-morph';\nimport type { ResolvedConfig } from '../config/types.js';\nimport type { RouteDescriptor } from '../discovery/types.js';\n\n/**\n * The published, versioned extension contract for `@dudousxd/nestjs-codegen`.\n *\n * Extensions are **build-time** objects (usually returned by a factory so they can take\n * options) registered explicitly via `forRoot({ extensions: [...] })`. The host runs them\n * around the core discovery → IR → emit pipeline.\n *\n * Hooks split into **multi** (every extension runs; results accumulate or chain) and\n * **single-slot** (at most one extension may claim it — two claimers is a hard error).\n *\n * @remarks Semver 0.x — the shape may change until 1.0. Out-of-repo extensions should pin\n * a compatible `@dudousxd/nestjs-codegen` peer range.\n */\nexport interface CodegenExtension {\n /** Unique id. Used in conflict/collision errors and for deterministic ordering. */\n name: string;\n\n // ── multi hooks (every extension runs) ────────────────────────────────────\n\n /**\n * Mutate/augment the route IR before emit. Runs in registration order, chained\n * (each extension sees the previous one's output). Return the new array, or mutate\n * in place and return void. Example: the filter extension attaches `filterFields` to\n * matching routes here.\n */\n transformRoutes?(\n routes: RouteDescriptor[],\n ctx: ExtensionContext,\n ): RouteDescriptor[] | undefined | Promise<RouteDescriptor[] | undefined>;\n\n /**\n * Contribute extra output files (additive). Paths are relative to `outDir`; a path\n * claimed by two extensions is a hard error. Example: the Inertia extension does its\n * own page discovery via `ctx.project()` and emits `pages.d.ts` + `components.json`.\n */\n emitFiles?(ctx: ExtensionContext): EmittedFile[] | Promise<EmittedFile[]>;\n\n /**\n * Contribute top-level code to `api.ts` (imports + statements). Runs in registration\n * order; imports are deduped by the host. Example: the Inertia extension adds\n * `import { router } from '@inertiajs/react'` and the `navigate()` helper.\n */\n apiHeader?(ctx: ExtensionContext): ApiHeaderContribution | undefined;\n\n /**\n * Add named members to a **handle** leaf. Only runs when a client layer is active\n * (i.e. the leaf is a handle, not a bare callable). Member-name collisions across\n * extensions are a hard error. Example: the filter extension adds `filterQuery` to\n * leaves whose route carries `filterFields`.\n */\n apiMembers?(leaf: LeafModel, ctx: ExtensionContext): Record<string, string> | undefined;\n\n // ── single-slot hooks (at most one extension) ─────────────────────────────\n\n /**\n * Claims **how** a single endpoint issues its request. When unset by every extension,\n * the host falls back to the neutral fetcher transport. Example: the Inertia extension\n * routes mutations through the Inertia router while GETs stay fetcher-typed.\n */\n apiTransport?: ApiTransport;\n\n /**\n * Claims **what** a leaf returns. When unset, a leaf is a bare callable returning a\n * `Promise`. Example: the TanStack extension wraps each leaf into a handle exposing\n * `{ fetch, queryKey, queryOptions | mutationOptions }`.\n */\n apiClientLayer?: ApiClientLayer;\n}\n\n/** Shared, read-only context handed to every extension hook. */\nexport interface ExtensionContext {\n cwd: string;\n outDir: string;\n routes: readonly RouteDescriptor[];\n config: ResolvedConfig;\n /** Lazily-created shared ts-morph Project for AST work (pages, custom decorators). */\n project(): Project;\n}\n\n/** A file contributed by an extension's `emitFiles` hook. */\nexport interface EmittedFile {\n /** Path relative to `outDir`. A collision across extensions throws. */\n path: string;\n contents: string;\n}\n\n/** Top-level `api.ts` contributions from an extension's `apiHeader` hook. */\nexport interface ApiHeaderContribution {\n /** Raw import lines (e.g. `import { router } from '@inertiajs/react';`), deduped by the host. */\n imports?: string[];\n /** Top-level statements appended after the api factory (e.g. the `navigate()` helper). */\n statements?: string[];\n}\n\n/**\n * The neutral, per-endpoint request model the host builds for each leaf before any\n * transport/layer runs. Extensions read this to render their output.\n */\nexport interface RequestModel {\n /** Dot-path route name, e.g. `users.show`. */\n routeName: string;\n method: 'get' | 'post' | 'put' | 'patch' | 'delete';\n isGet: boolean;\n /** True for reads: a GET, or a filter-search route (has `filterFields`) even when POST.\n * Client layers use this (not `isGet`) to decide query vs mutation helpers. */\n isQuery: boolean;\n hasParams: boolean;\n hasBody: boolean;\n /** Type of the leaf's `input` arg, e.g. `{ params: ...; query?: ... }` or `Record<string, never>`. */\n inputType: string;\n /** URL expression, e.g. `route('users.show', input?.params) || '/api/users/:id'`. */\n urlExpr: string;\n /** Request-options expression, e.g. `{ query: ... }` or `{ body: input?.body }`. */\n optsExpr: string;\n /** Response type access, e.g. `ApiRouter['users']['show']['response']`. */\n responseType: string;\n /** Body type access, e.g. `ApiRouter['users']['create']['body']` (for mutation layers). */\n bodyType: string;\n /** Stable query-key expression, e.g. `[\"users.show\", input] as const`. */\n queryKeyExpr: string;\n}\n\n/**\n * Per-leaf model passed through the api.ts pipeline: transport → layer → member\n * contributors → render. `requestExpr` is set by the transport; `members`, when present,\n * flips the leaf from a bare callable to a handle.\n */\nexport interface LeafModel {\n route: RouteDescriptor;\n request: RequestModel;\n /** The expression that issues the request (set by the transport, default = fetcher). */\n requestExpr: string;\n /** When present, the leaf renders as a handle exposing these members (ordered). */\n members?: Record<string, string>;\n}\n\n/**\n * Top-level `api.ts` imports + helpers a transport or layer depends on. Functions of the\n * context so they can be route-aware (e.g. only import `mutationOptions` when a mutation\n * exists). Imports are deduped by the host across all extensions.\n */\nexport interface ApiModuleDeps {\n /** Raw import lines (e.g. `import { queryOptions as _q } from '@tanstack/react-query';`). */\n imports?(ctx: ExtensionContext): string[];\n /** Module-level helper declarations the rendered expressions depend on. */\n helpers?(ctx: ExtensionContext): string[];\n}\n\n/** Single-slot: decides how an endpoint issues its request. */\nexport interface ApiTransport extends ApiModuleDeps {\n name: string;\n /** Render the expression that issues this endpoint's request (e.g. `fetcher.get<Res>(url, opts)`). */\n renderRequest(leaf: LeafModel, ctx: ExtensionContext): string;\n}\n\n/** Single-slot: decides what a leaf returns (the handle members). */\nexport interface ApiClientLayer extends ApiModuleDeps {\n name: string;\n /**\n * Given the request expression (from the transport) and the leaf, return the handle's\n * members as an ordered `name → value` map (value is the expression after `name: `).\n * Returning members flips the leaf from a bare callable to a handle.\n */\n buildMembers(requestExpr: string, leaf: LeafModel, ctx: ExtensionContext): Record<string, string>;\n}\n\n/** Identity helper for authoring extensions with full type inference. */\nexport function defineExtension(ext: CodegenExtension): CodegenExtension {\n return ext;\n}\n"],"mappings":";AA2KO,SAAS,gBAAgB,KAAyC;AACvE,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/extension/types.ts"],"sourcesContent":["import type { Project } from 'ts-morph';\nimport type { ResolvedConfig } from '../config/types.js';\nimport type { RouteDescriptor } from '../discovery/types.js';\n\n/**\n * The published, versioned extension contract for `@dudousxd/nestjs-codegen`.\n *\n * Extensions are **build-time** objects (usually returned by a factory so they can take\n * options) registered explicitly via `forRoot({ extensions: [...] })`. The host runs them\n * around the core discovery → IR → emit pipeline.\n *\n * Hooks split into **multi** (every extension runs; results accumulate or chain) and\n * **single-slot** (at most one extension may claim it — two claimers is a hard error).\n *\n * @remarks Semver 0.x — the shape may change until 1.0. Out-of-repo extensions should pin\n * a compatible `@dudousxd/nestjs-codegen` peer range.\n */\nexport interface CodegenExtension {\n /** Unique id. Used in conflict/collision errors and for deterministic ordering. */\n name: string;\n\n // ── multi hooks (every extension runs) ────────────────────────────────────\n\n /**\n * Mutate/augment the route IR before emit. Runs in registration order, chained\n * (each extension sees the previous one's output). Return the new array, or mutate\n * in place and return void. Example: the filter extension attaches `filterFields` to\n * matching routes here.\n */\n transformRoutes?(\n routes: RouteDescriptor[],\n ctx: ExtensionContext,\n ): RouteDescriptor[] | undefined | Promise<RouteDescriptor[] | undefined>;\n\n /**\n * Contribute extra output files (additive). Paths are relative to `outDir`; a path\n * claimed by two extensions is a hard error. Example: the Inertia extension does its\n * own page discovery via `ctx.project()` and emits `pages.d.ts` + `components.json`.\n */\n emitFiles?(ctx: ExtensionContext): EmittedFile[] | Promise<EmittedFile[]>;\n\n /**\n * Contribute top-level code to `api.ts` (imports + statements). Runs in registration\n * order; imports are deduped by the host. Example: the Inertia extension adds\n * `import { router } from '@inertiajs/react'` and the `navigate()` helper.\n */\n apiHeader?(ctx: ExtensionContext): ApiHeaderContribution | undefined;\n\n /**\n * Add named members to a **handle** leaf. Only runs when a client layer is active\n * (i.e. the leaf is a handle, not a bare callable). Member-name collisions across\n * extensions are a hard error. Example: the filter extension adds `filterQuery` to\n * leaves whose route carries `filterFields`.\n */\n apiMembers?(leaf: LeafModel, ctx: ExtensionContext): Record<string, string> | undefined;\n\n // ── single-slot hooks (at most one extension) ─────────────────────────────\n\n /**\n * Claims **what** a leaf returns and **how** it issues its request. At most one extension\n * may claim it. When unset, a leaf is a bare awaitable callable backed by the neutral\n * fetcher. Example: the TanStack extension wraps each leaf into a handle exposing\n * `{ fetch, queryKey, queryOptions | mutationOptions }`, composing with the fetcher\n * request the host passes in.\n */\n apiClientLayer?: ApiClientLayer;\n}\n\n/** Shared, read-only context handed to every extension hook. */\nexport interface ExtensionContext {\n cwd: string;\n outDir: string;\n routes: readonly RouteDescriptor[];\n config: ResolvedConfig;\n /** Lazily-created shared ts-morph Project for AST work (pages, custom decorators). */\n project(): Project;\n}\n\n/** A file contributed by an extension's `emitFiles` hook. */\nexport interface EmittedFile {\n /** Path relative to `outDir`. A collision across extensions throws. */\n path: string;\n contents: string;\n}\n\n/** Top-level `api.ts` contributions from an extension's `apiHeader` hook. */\nexport interface ApiHeaderContribution {\n /** Raw import lines (e.g. `import { router } from '@inertiajs/react';`), deduped by the host. */\n imports?: string[];\n /** Top-level statements appended after the api factory (e.g. the `navigate()` helper). */\n statements?: string[];\n}\n\n/**\n * The neutral, per-endpoint request model the host builds for each leaf before any\n * transport/layer runs. Extensions read this to render their output.\n */\nexport interface RequestModel {\n /** Dot-path route name, e.g. `users.show`. */\n routeName: string;\n method: 'get' | 'post' | 'put' | 'patch' | 'delete';\n isGet: boolean;\n /** True for reads: a GET, or a filter-search route (has `filterFields`) even when POST.\n * Client layers use this (not `isGet`) to decide query vs mutation helpers. */\n isQuery: boolean;\n hasParams: boolean;\n hasBody: boolean;\n /** Type of the leaf's `input` arg, e.g. `{ params: ...; query?: ... }` or `Record<string, never>`. */\n inputType: string;\n /** URL expression, e.g. `route('users.show', input?.params) || '/api/users/:id'`. */\n urlExpr: string;\n /** Request-options expression, e.g. `{ query: ... }` or `{ body: input?.body }`. */\n optsExpr: string;\n /** Response type access, e.g. `ApiRouter['users']['show']['response']`. */\n responseType: string;\n /** Stable query-key expression, e.g. `[\"users.show\", input] as const`. */\n queryKeyExpr: string;\n}\n\n/**\n * Per-leaf model passed through the api.ts pipeline: layer → member contributors → render.\n * `requestExpr` is the host's neutral fetcher request; `members`, when present, flips the\n * leaf from a bare callable to a handle.\n */\nexport interface LeafModel {\n route: RouteDescriptor;\n request: RequestModel;\n /** The expression that issues the request (the host's neutral fetcher call). */\n requestExpr: string;\n /** When present, the leaf renders as a handle exposing these members (ordered). */\n members?: Record<string, string>;\n}\n\n/**\n * Top-level `api.ts` imports a client layer depends on. A function of the context so it can\n * be route-aware (e.g. only import `mutationOptions` when a mutation exists). Imports are\n * deduped by the host across all extensions.\n */\nexport interface ApiModuleDeps {\n /** Raw import lines (e.g. `import { queryOptions as _q } from '@tanstack/react-query';`). */\n imports?(ctx: ExtensionContext): string[];\n}\n\n/** Single-slot: decides what a leaf returns (the handle members). */\nexport interface ApiClientLayer extends ApiModuleDeps {\n name: string;\n /**\n * Given the request expression (from the transport) and the leaf, return the handle's\n * members as an ordered `name → value` map (value is the expression after `name: `).\n * Returning members flips the leaf from a bare callable to a handle.\n */\n buildMembers(requestExpr: string, leaf: LeafModel, ctx: ExtensionContext): Record<string, string>;\n}\n\n/**\n * The four request-shape flags derived from a route's method + contract. Computed in ONE\n * place ({@link requestShape}) and read by both the host emitter and client-layer\n * extensions, so the \"filter-search POST counts as a read\" rule is encoded exactly once.\n */\nexport interface RequestShape {\n /** The route is a `GET`. */\n isGet: boolean;\n /** True for reads: a GET, or a filter-search route (carries `filterFields`) even when POST.\n * Client layers use this (not `isGet`) to decide query vs mutation helpers. */\n isQuery: boolean;\n /** The route carries a body contract (a mutation payload). */\n hasBody: boolean;\n /** The route can take a query string — always for GET; a mutation may too (query + body). */\n hasQuery: boolean;\n}\n\n/**\n * Compute the {@link RequestShape} flags for a route from its method and contract. This is\n * the SINGLE source of truth for these flags — `buildRequestModel`, the TanStack layer's\n * `imports()`, and any other reader must call this rather than re-deriving. The\n * \"filter-search POST counts as a read\" rule lives here and nowhere else.\n */\nexport function requestShape(route: RouteDescriptor): RequestShape {\n const cs = route.contract?.contractSource;\n const isGet = route.method.toUpperCase() === 'GET';\n const isQuery = isGet || !!cs?.filterFields?.length;\n const hasBody = !!cs?.bodyRef || (cs?.body != null && cs.body !== 'never');\n const hasQuery = isGet || !!cs?.queryRef || (cs?.query != null && cs.query !== 'never');\n return { isGet, isQuery, hasBody, hasQuery };\n}\n\n/** Identity helper for authoring extensions with full type inference. */\nexport function defineExtension(ext: CodegenExtension): CodegenExtension {\n return ext;\n}\n"],"mappings":";AAiLO,SAAS,aAAa,OAAsC;AACjE,QAAM,KAAK,MAAM,UAAU;AAC3B,QAAM,QAAQ,MAAM,OAAO,YAAY,MAAM;AAC7C,QAAM,UAAU,SAAS,CAAC,CAAC,IAAI,cAAc;AAC7C,QAAM,UAAU,CAAC,CAAC,IAAI,WAAY,IAAI,QAAQ,QAAQ,GAAG,SAAS;AAClE,QAAM,WAAW,SAAS,CAAC,CAAC,IAAI,YAAa,IAAI,SAAS,QAAQ,GAAG,UAAU;AAC/E,SAAO,EAAE,OAAO,SAAS,SAAS,SAAS;AAC7C;AAGO,SAAS,gBAAgB,KAAyC;AACvE,SAAO;AACT;","names":[]}
@@ -137,6 +137,12 @@ interface RenderedModule {
137
137
  interface ValidationAdapter {
138
138
  /** 'zod' | 'valibot' | 'arktype'. */
139
139
  name: string;
140
+ /**
141
+ * When `true`, the emitter may pass raw zod source from `defineContract`
142
+ * (`bodyZodText`/`bodyZodRef`) through verbatim and emit a `z` import. Only the
143
+ * zod adapter sets this; any other adapter skips raw-zod sources with a warning.
144
+ */
145
+ acceptsRawZodSource?: boolean;
140
146
  /** Import lines required for any rendered text (e.g. `import { z } from 'zod'`). */
141
147
  importStatements(usage: AdapterUsage): string[];
142
148
  /** Render a single node to this lib's source text. */
@@ -150,14 +156,14 @@ interface ValidationAdapter {
150
156
  /** A built-in adapter name or a custom adapter instance. */
151
157
  type ValidationOption = 'zod' | 'valibot' | 'arktype' | ValidationAdapter;
152
158
  /**
153
- * Resolve a `validation` config value to a {@link ValidationAdapter}. `'zod'` is
154
- * bundled in core; the valibot/arktype adapters ship as their own packages — import
155
- * the adapter instance and pass it directly (it passes through here). A custom
156
- * adapter object also passes through.
159
+ * Resolve a `validation` config value to a {@link ValidationAdapter}. No adapter is
160
+ * bundled in core the zod/valibot/arktype adapters ship as their own packages.
161
+ * Import the adapter instance and pass it directly (it passes through here). A
162
+ * custom adapter object also passes through.
157
163
  *
158
164
  * @example
159
- * import { valibotAdapter } from '@dudousxd/nestjs-codegen-valibot';
160
- * defineConfig({ validation: valibotAdapter });
165
+ * import { zodAdapter } from '@dudousxd/nestjs-codegen-zod';
166
+ * defineConfig({ validation: zodAdapter });
161
167
  */
162
168
  declare function resolveAdapter(option: ValidationOption): ValidationAdapter;
163
169
 
@@ -166,15 +172,15 @@ interface UserConfig {
166
172
  * Codegen extensions, applied in order. Each may augment the route IR
167
173
  * (`transformRoutes`), contribute extra output files (`emitFiles`), and — once a
168
174
  * client layer is active — shape `api.ts`. Registered explicitly, e.g.
169
- * `extensions: [nestjsInertiaCodegen(), tanstackQuery()]`.
175
+ * `extensions: [clientCodegen(), tanstackQuery()]`.
170
176
  */
171
177
  extensions?: CodegenExtension[];
172
178
  /**
173
- * Validation library for emitted `forms.ts` schemas. `'zod'` (bundled, default)
174
- * or an imported adapter instance (`valibotAdapter`/`arktypeAdapter`).
175
- * @default 'zod'
179
+ * Validation library for emitted `forms.ts` schemas. Required pass an imported
180
+ * adapter instance, e.g. `zodAdapter` from `@dudousxd/nestjs-codegen-zod`, or
181
+ * `valibotAdapter`/`arktypeAdapter` from their packages.
176
182
  */
177
- validation?: ValidationOption;
183
+ validation: ValidationOption;
178
184
  /** Inertia page discovery. Omit when you don't use Inertia. */
179
185
  pages?: {
180
186
  glob: string;
@@ -202,11 +208,11 @@ interface UserConfig {
202
208
  * This lets users configure baseUrl, headers, plugins (e.g. superjson).
203
209
  *
204
210
  * @example
205
- * // nestjs-inertia.config.ts
211
+ * // nestjs-codegen.config.ts
206
212
  * fetcher: { importPath: '~/lib/api' }
207
213
  *
208
- * // inertia/lib/api.ts
209
- * import { createFetcher } from '@dudousxd/nestjs-inertia-client';
214
+ * // src/lib/api.ts
215
+ * import { createFetcher } from '@dudousxd/nestjs-client';
210
216
  * export const fetcher = createFetcher({ baseUrl: '/api' });
211
217
  */
212
218
  fetcher?: {
@@ -402,15 +408,11 @@ interface CodegenExtension {
402
408
  */
403
409
  apiMembers?(leaf: LeafModel, ctx: ExtensionContext): Record<string, string> | undefined;
404
410
  /**
405
- * Claims **how** a single endpoint issues its request. When unset by every extension,
406
- * the host falls back to the neutral fetcher transport. Example: the Inertia extension
407
- * routes mutations through the Inertia router while GETs stay fetcher-typed.
408
- */
409
- apiTransport?: ApiTransport;
410
- /**
411
- * Claims **what** a leaf returns. When unset, a leaf is a bare callable returning a
412
- * `Promise`. Example: the TanStack extension wraps each leaf into a handle exposing
413
- * `{ fetch, queryKey, queryOptions | mutationOptions }`.
411
+ * Claims **what** a leaf returns and **how** it issues its request. At most one extension
412
+ * may claim it. When unset, a leaf is a bare awaitable callable backed by the neutral
413
+ * fetcher. Example: the TanStack extension wraps each leaf into a handle exposing
414
+ * `{ fetch, queryKey, queryOptions | mutationOptions }`, composing with the fetcher
415
+ * request the host passes in.
414
416
  */
415
417
  apiClientLayer?: ApiClientLayer;
416
418
  }
@@ -458,40 +460,30 @@ interface RequestModel {
458
460
  optsExpr: string;
459
461
  /** Response type access, e.g. `ApiRouter['users']['show']['response']`. */
460
462
  responseType: string;
461
- /** Body type access, e.g. `ApiRouter['users']['create']['body']` (for mutation layers). */
462
- bodyType: string;
463
463
  /** Stable query-key expression, e.g. `["users.show", input] as const`. */
464
464
  queryKeyExpr: string;
465
465
  }
466
466
  /**
467
- * Per-leaf model passed through the api.ts pipeline: transportlayermember
468
- * contributors → render. `requestExpr` is set by the transport; `members`, when present,
469
- * flips the leaf from a bare callable to a handle.
467
+ * Per-leaf model passed through the api.ts pipeline: layermember contributors render.
468
+ * `requestExpr` is the host's neutral fetcher request; `members`, when present, flips the
469
+ * leaf from a bare callable to a handle.
470
470
  */
471
471
  interface LeafModel {
472
472
  route: RouteDescriptor;
473
473
  request: RequestModel;
474
- /** The expression that issues the request (set by the transport, default = fetcher). */
474
+ /** The expression that issues the request (the host's neutral fetcher call). */
475
475
  requestExpr: string;
476
476
  /** When present, the leaf renders as a handle exposing these members (ordered). */
477
477
  members?: Record<string, string>;
478
478
  }
479
479
  /**
480
- * Top-level `api.ts` imports + helpers a transport or layer depends on. Functions of the
481
- * context so they can be route-aware (e.g. only import `mutationOptions` when a mutation
482
- * exists). Imports are deduped by the host across all extensions.
480
+ * Top-level `api.ts` imports a client layer depends on. A function of the context so it can
481
+ * be route-aware (e.g. only import `mutationOptions` when a mutation exists). Imports are
482
+ * deduped by the host across all extensions.
483
483
  */
484
484
  interface ApiModuleDeps {
485
485
  /** Raw import lines (e.g. `import { queryOptions as _q } from '@tanstack/react-query';`). */
486
486
  imports?(ctx: ExtensionContext): string[];
487
- /** Module-level helper declarations the rendered expressions depend on. */
488
- helpers?(ctx: ExtensionContext): string[];
489
- }
490
- /** Single-slot: decides how an endpoint issues its request. */
491
- interface ApiTransport extends ApiModuleDeps {
492
- name: string;
493
- /** Render the expression that issues this endpoint's request (e.g. `fetcher.get<Res>(url, opts)`). */
494
- renderRequest(leaf: LeafModel, ctx: ExtensionContext): string;
495
487
  }
496
488
  /** Single-slot: decides what a leaf returns (the handle members). */
497
489
  interface ApiClientLayer extends ApiModuleDeps {
@@ -503,7 +495,30 @@ interface ApiClientLayer extends ApiModuleDeps {
503
495
  */
504
496
  buildMembers(requestExpr: string, leaf: LeafModel, ctx: ExtensionContext): Record<string, string>;
505
497
  }
498
+ /**
499
+ * The four request-shape flags derived from a route's method + contract. Computed in ONE
500
+ * place ({@link requestShape}) and read by both the host emitter and client-layer
501
+ * extensions, so the "filter-search POST counts as a read" rule is encoded exactly once.
502
+ */
503
+ interface RequestShape {
504
+ /** The route is a `GET`. */
505
+ isGet: boolean;
506
+ /** True for reads: a GET, or a filter-search route (carries `filterFields`) even when POST.
507
+ * Client layers use this (not `isGet`) to decide query vs mutation helpers. */
508
+ isQuery: boolean;
509
+ /** The route carries a body contract (a mutation payload). */
510
+ hasBody: boolean;
511
+ /** The route can take a query string — always for GET; a mutation may too (query + body). */
512
+ hasQuery: boolean;
513
+ }
514
+ /**
515
+ * Compute the {@link RequestShape} flags for a route from its method and contract. This is
516
+ * the SINGLE source of truth for these flags — `buildRequestModel`, the TanStack layer's
517
+ * `imports()`, and any other reader must call this rather than re-deriving. The
518
+ * "filter-search POST counts as a read" rule lives here and nowhere else.
519
+ */
520
+ declare function requestShape(route: RouteDescriptor): RequestShape;
506
521
  /** Identity helper for authoring extensions with full type inference. */
507
522
  declare function defineExtension(ext: CodegenExtension): CodegenExtension;
508
523
 
509
- export { type AdapterUsage as A, type CodegenExtension as C, type ExtensionContext as E, type LeafModel as L, type NumberCheck as N, type ResolvedConfig as R, type SchemaModule as S, type TypeRef as T, type UserConfig as U, type ValidationAdapter as V, type RouteDescriptor as a, type ResolvedFormsConfig as b, type ContractDescriptor as c, type ContractSource as d, type ControllerRef as e, type RenderContext as f, type RenderedModule as g, type SchemaNode as h, type ScopeConfig as i, type StringCheck as j, type ValidationOption as k, type ApiClientLayer as l, type ApiHeaderContribution as m, type ApiModuleDeps as n, type ApiTransport as o, type EmittedFile as p, type RequestModel as q, resolveAdapter as r, defineExtension as s };
524
+ export { type AdapterUsage as A, type CodegenExtension as C, type ExtensionContext as E, type LeafModel as L, type NumberCheck as N, type ResolvedConfig as R, type SchemaModule as S, type TypeRef as T, type UserConfig as U, type ValidationAdapter as V, type RouteDescriptor as a, type ResolvedFormsConfig as b, type ContractDescriptor as c, type ContractSource as d, type ControllerRef as e, type RenderContext as f, type RenderedModule as g, type SchemaNode as h, type ScopeConfig as i, type StringCheck as j, type ValidationOption as k, type ApiClientLayer as l, type ApiHeaderContribution as m, type ApiModuleDeps as n, type EmittedFile as o, type RequestModel as p, type RequestShape as q, resolveAdapter as r, defineExtension as s, requestShape as t };
@@ -137,6 +137,12 @@ interface RenderedModule {
137
137
  interface ValidationAdapter {
138
138
  /** 'zod' | 'valibot' | 'arktype'. */
139
139
  name: string;
140
+ /**
141
+ * When `true`, the emitter may pass raw zod source from `defineContract`
142
+ * (`bodyZodText`/`bodyZodRef`) through verbatim and emit a `z` import. Only the
143
+ * zod adapter sets this; any other adapter skips raw-zod sources with a warning.
144
+ */
145
+ acceptsRawZodSource?: boolean;
140
146
  /** Import lines required for any rendered text (e.g. `import { z } from 'zod'`). */
141
147
  importStatements(usage: AdapterUsage): string[];
142
148
  /** Render a single node to this lib's source text. */
@@ -150,14 +156,14 @@ interface ValidationAdapter {
150
156
  /** A built-in adapter name or a custom adapter instance. */
151
157
  type ValidationOption = 'zod' | 'valibot' | 'arktype' | ValidationAdapter;
152
158
  /**
153
- * Resolve a `validation` config value to a {@link ValidationAdapter}. `'zod'` is
154
- * bundled in core; the valibot/arktype adapters ship as their own packages — import
155
- * the adapter instance and pass it directly (it passes through here). A custom
156
- * adapter object also passes through.
159
+ * Resolve a `validation` config value to a {@link ValidationAdapter}. No adapter is
160
+ * bundled in core the zod/valibot/arktype adapters ship as their own packages.
161
+ * Import the adapter instance and pass it directly (it passes through here). A
162
+ * custom adapter object also passes through.
157
163
  *
158
164
  * @example
159
- * import { valibotAdapter } from '@dudousxd/nestjs-codegen-valibot';
160
- * defineConfig({ validation: valibotAdapter });
165
+ * import { zodAdapter } from '@dudousxd/nestjs-codegen-zod';
166
+ * defineConfig({ validation: zodAdapter });
161
167
  */
162
168
  declare function resolveAdapter(option: ValidationOption): ValidationAdapter;
163
169
 
@@ -166,15 +172,15 @@ interface UserConfig {
166
172
  * Codegen extensions, applied in order. Each may augment the route IR
167
173
  * (`transformRoutes`), contribute extra output files (`emitFiles`), and — once a
168
174
  * client layer is active — shape `api.ts`. Registered explicitly, e.g.
169
- * `extensions: [nestjsInertiaCodegen(), tanstackQuery()]`.
175
+ * `extensions: [clientCodegen(), tanstackQuery()]`.
170
176
  */
171
177
  extensions?: CodegenExtension[];
172
178
  /**
173
- * Validation library for emitted `forms.ts` schemas. `'zod'` (bundled, default)
174
- * or an imported adapter instance (`valibotAdapter`/`arktypeAdapter`).
175
- * @default 'zod'
179
+ * Validation library for emitted `forms.ts` schemas. Required pass an imported
180
+ * adapter instance, e.g. `zodAdapter` from `@dudousxd/nestjs-codegen-zod`, or
181
+ * `valibotAdapter`/`arktypeAdapter` from their packages.
176
182
  */
177
- validation?: ValidationOption;
183
+ validation: ValidationOption;
178
184
  /** Inertia page discovery. Omit when you don't use Inertia. */
179
185
  pages?: {
180
186
  glob: string;
@@ -202,11 +208,11 @@ interface UserConfig {
202
208
  * This lets users configure baseUrl, headers, plugins (e.g. superjson).
203
209
  *
204
210
  * @example
205
- * // nestjs-inertia.config.ts
211
+ * // nestjs-codegen.config.ts
206
212
  * fetcher: { importPath: '~/lib/api' }
207
213
  *
208
- * // inertia/lib/api.ts
209
- * import { createFetcher } from '@dudousxd/nestjs-inertia-client';
214
+ * // src/lib/api.ts
215
+ * import { createFetcher } from '@dudousxd/nestjs-client';
210
216
  * export const fetcher = createFetcher({ baseUrl: '/api' });
211
217
  */
212
218
  fetcher?: {
@@ -402,15 +408,11 @@ interface CodegenExtension {
402
408
  */
403
409
  apiMembers?(leaf: LeafModel, ctx: ExtensionContext): Record<string, string> | undefined;
404
410
  /**
405
- * Claims **how** a single endpoint issues its request. When unset by every extension,
406
- * the host falls back to the neutral fetcher transport. Example: the Inertia extension
407
- * routes mutations through the Inertia router while GETs stay fetcher-typed.
408
- */
409
- apiTransport?: ApiTransport;
410
- /**
411
- * Claims **what** a leaf returns. When unset, a leaf is a bare callable returning a
412
- * `Promise`. Example: the TanStack extension wraps each leaf into a handle exposing
413
- * `{ fetch, queryKey, queryOptions | mutationOptions }`.
411
+ * Claims **what** a leaf returns and **how** it issues its request. At most one extension
412
+ * may claim it. When unset, a leaf is a bare awaitable callable backed by the neutral
413
+ * fetcher. Example: the TanStack extension wraps each leaf into a handle exposing
414
+ * `{ fetch, queryKey, queryOptions | mutationOptions }`, composing with the fetcher
415
+ * request the host passes in.
414
416
  */
415
417
  apiClientLayer?: ApiClientLayer;
416
418
  }
@@ -458,40 +460,30 @@ interface RequestModel {
458
460
  optsExpr: string;
459
461
  /** Response type access, e.g. `ApiRouter['users']['show']['response']`. */
460
462
  responseType: string;
461
- /** Body type access, e.g. `ApiRouter['users']['create']['body']` (for mutation layers). */
462
- bodyType: string;
463
463
  /** Stable query-key expression, e.g. `["users.show", input] as const`. */
464
464
  queryKeyExpr: string;
465
465
  }
466
466
  /**
467
- * Per-leaf model passed through the api.ts pipeline: transportlayermember
468
- * contributors → render. `requestExpr` is set by the transport; `members`, when present,
469
- * flips the leaf from a bare callable to a handle.
467
+ * Per-leaf model passed through the api.ts pipeline: layermember contributors render.
468
+ * `requestExpr` is the host's neutral fetcher request; `members`, when present, flips the
469
+ * leaf from a bare callable to a handle.
470
470
  */
471
471
  interface LeafModel {
472
472
  route: RouteDescriptor;
473
473
  request: RequestModel;
474
- /** The expression that issues the request (set by the transport, default = fetcher). */
474
+ /** The expression that issues the request (the host's neutral fetcher call). */
475
475
  requestExpr: string;
476
476
  /** When present, the leaf renders as a handle exposing these members (ordered). */
477
477
  members?: Record<string, string>;
478
478
  }
479
479
  /**
480
- * Top-level `api.ts` imports + helpers a transport or layer depends on. Functions of the
481
- * context so they can be route-aware (e.g. only import `mutationOptions` when a mutation
482
- * exists). Imports are deduped by the host across all extensions.
480
+ * Top-level `api.ts` imports a client layer depends on. A function of the context so it can
481
+ * be route-aware (e.g. only import `mutationOptions` when a mutation exists). Imports are
482
+ * deduped by the host across all extensions.
483
483
  */
484
484
  interface ApiModuleDeps {
485
485
  /** Raw import lines (e.g. `import { queryOptions as _q } from '@tanstack/react-query';`). */
486
486
  imports?(ctx: ExtensionContext): string[];
487
- /** Module-level helper declarations the rendered expressions depend on. */
488
- helpers?(ctx: ExtensionContext): string[];
489
- }
490
- /** Single-slot: decides how an endpoint issues its request. */
491
- interface ApiTransport extends ApiModuleDeps {
492
- name: string;
493
- /** Render the expression that issues this endpoint's request (e.g. `fetcher.get<Res>(url, opts)`). */
494
- renderRequest(leaf: LeafModel, ctx: ExtensionContext): string;
495
487
  }
496
488
  /** Single-slot: decides what a leaf returns (the handle members). */
497
489
  interface ApiClientLayer extends ApiModuleDeps {
@@ -503,7 +495,30 @@ interface ApiClientLayer extends ApiModuleDeps {
503
495
  */
504
496
  buildMembers(requestExpr: string, leaf: LeafModel, ctx: ExtensionContext): Record<string, string>;
505
497
  }
498
+ /**
499
+ * The four request-shape flags derived from a route's method + contract. Computed in ONE
500
+ * place ({@link requestShape}) and read by both the host emitter and client-layer
501
+ * extensions, so the "filter-search POST counts as a read" rule is encoded exactly once.
502
+ */
503
+ interface RequestShape {
504
+ /** The route is a `GET`. */
505
+ isGet: boolean;
506
+ /** True for reads: a GET, or a filter-search route (carries `filterFields`) even when POST.
507
+ * Client layers use this (not `isGet`) to decide query vs mutation helpers. */
508
+ isQuery: boolean;
509
+ /** The route carries a body contract (a mutation payload). */
510
+ hasBody: boolean;
511
+ /** The route can take a query string — always for GET; a mutation may too (query + body). */
512
+ hasQuery: boolean;
513
+ }
514
+ /**
515
+ * Compute the {@link RequestShape} flags for a route from its method and contract. This is
516
+ * the SINGLE source of truth for these flags — `buildRequestModel`, the TanStack layer's
517
+ * `imports()`, and any other reader must call this rather than re-deriving. The
518
+ * "filter-search POST counts as a read" rule lives here and nowhere else.
519
+ */
520
+ declare function requestShape(route: RouteDescriptor): RequestShape;
506
521
  /** Identity helper for authoring extensions with full type inference. */
507
522
  declare function defineExtension(ext: CodegenExtension): CodegenExtension;
508
523
 
509
- export { type AdapterUsage as A, type CodegenExtension as C, type ExtensionContext as E, type LeafModel as L, type NumberCheck as N, type ResolvedConfig as R, type SchemaModule as S, type TypeRef as T, type UserConfig as U, type ValidationAdapter as V, type RouteDescriptor as a, type ResolvedFormsConfig as b, type ContractDescriptor as c, type ContractSource as d, type ControllerRef as e, type RenderContext as f, type RenderedModule as g, type SchemaNode as h, type ScopeConfig as i, type StringCheck as j, type ValidationOption as k, type ApiClientLayer as l, type ApiHeaderContribution as m, type ApiModuleDeps as n, type ApiTransport as o, type EmittedFile as p, type RequestModel as q, resolveAdapter as r, defineExtension as s };
524
+ export { type AdapterUsage as A, type CodegenExtension as C, type ExtensionContext as E, type LeafModel as L, type NumberCheck as N, type ResolvedConfig as R, type SchemaModule as S, type TypeRef as T, type UserConfig as U, type ValidationAdapter as V, type RouteDescriptor as a, type ResolvedFormsConfig as b, type ContractDescriptor as c, type ContractSource as d, type ControllerRef as e, type RenderContext as f, type RenderedModule as g, type SchemaNode as h, type ScopeConfig as i, type StringCheck as j, type ValidationOption as k, type ApiClientLayer as l, type ApiHeaderContribution as m, type ApiModuleDeps as n, type EmittedFile as o, type RequestModel as p, type RequestShape as q, resolveAdapter as r, defineExtension as s, requestShape as t };