@dudousxd/nestjs-codegen 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,77 @@
1
+ # @dudousxd/nestjs-codegen
2
+
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 0fe7439: Unified, awaitable leaf handles (Tuyau-style) + `infiniteQueryOptions`.
8
+
9
+ Every generated `api.ts` leaf is now an **awaitable handle**: `await api.users.show({ params })`
10
+ performs the request and resolves to the typed response (memoized, so repeated awaits hit the
11
+ network once), exposing `.fetch()`/`.then`/`.catch`/`.finally` via a small `__req` runtime helper.
12
+ When the TanStack extension is registered, the **same** handle additionally carries
13
+ `.queryKey()`, `.queryOptions()` / `.mutationOptions()`, and now `.infiniteQueryOptions()`
14
+ (GET routes, cursor/page pagination). No more "plain fetch OR handle" split — one call shape
15
+ supports both `await` and the TanStack helpers.
16
+
17
+ ```ts
18
+ const user = await api.users.show({ params: { id } }); // request
19
+ useQuery(api.users.show({ params: { id } }).queryOptions()); // tanstack
20
+ useInfiniteQuery(api.users.list().infiniteQueryOptions()); // pagination
21
+ ```
22
+
23
+ - ad80b18: Filter-search routes are treated as queries. `RequestModel.isQuery` is `true` for GET **or**
24
+ any route carrying `filterFields` (a filtered search is a read even when POST). The TanStack
25
+ layer now emits `.queryOptions()` for `isQuery` routes and `.mutationOptions()` for any non-GET
26
+ — so a filter-search POST gets **both** `.queryOptions()`/`.filterQuery()` and
27
+ `.mutationOptions()`. `.infiniteQueryOptions()` stays GET-only (page goes in the query string).
28
+ - 9c86e57: Move the runtime `filterQuery()` helper out of core into the new
29
+ `@dudousxd/nestjs-filter-codegen` extension. Core no longer emits the `filterQuery`
30
+ member or the `@dudousxd/nestjs-filter-client` value import in `api.ts` — register
31
+ `nestjsFilterCodegen()` to get it. Core still discovers `filterFields`/`filterFieldTypes`
32
+ and renders the type-level `TypedFilterQuery<…>` (query-source filters). Also decouples the
33
+ TanStack layer from filter (it no longer imports `queryOptions` for filter-only routes).
34
+ - 5f52ecf: Move the Inertia `navigate()` helper + `@inertiajs/react` router import out of core into the
35
+ new `@dudousxd/nestjs-inertia-codegen-extension`. The `mutationClient` config option is
36
+ removed — register `nestjsInertiaCodegen()` instead to get `navigate()` in `api.ts`. Core's
37
+ generated `api.ts` is now Inertia-agnostic (Inertia page discovery / `pages.d.ts` is still
38
+ driven by the `pages` config). Same model as `query` → `tanstackQuery()` and
39
+ `filterQuery` → `nestjsFilterCodegen()`.
40
+ - 3ff3199: Initial release: typed-client codegen for NestJS.
41
+
42
+ - `@dudousxd/nestjs-codegen` — discovery (controllers, `defineContract`, DTOs, pages,
43
+ shared props, filters), emitters (`routes.ts`/`api.ts`/`forms.ts`/`pages.d.ts`),
44
+ config loader, watch mode, and the `codegen`/`init`/`doctor` CLI. Bundles the neutral
45
+ validation IR + zod adapter.
46
+ - `@dudousxd/nestjs-codegen-valibot`, `@dudousxd/nestjs-codegen-arktype` — validation
47
+ adapters rendering the shared IR.
48
+ - `@dudousxd/nestjs-client` — framework-neutral runtime: typed fetcher with a pluggable
49
+ transport (axios via `axiosTransport`) and a superjson transformer hook.
50
+
51
+ Highlights: pluggable validation, Tuyau-style `createApi(fetcher)` factory, optional
52
+ TanStack Query (configurable adapter import), and nestjs-inertia + nestjs-filter
53
+ integrations.
54
+
55
+ - 5a9b90e: Add `NestjsCodegenModule.forRoot()` — a NestJS module (exported from
56
+ `@dudousxd/nestjs-codegen/nest`) that auto-starts the codegen watcher on app boot, the
57
+ recommended way to wire the codegen in dev. Import it into your `AppModule` and the typed
58
+ client regenerates as you edit controllers — no config file, no separate process. Skips the
59
+ watcher in production by default (`enabled`/`cwd` options to override); `@nestjs/common` is an
60
+ optional peer dependency. The one-shot CLI remains for CI/pre-deploy runs.
61
+
62
+ Also exposes `resolveConfig(userConfig, cwd?)` for resolving config in memory, and fixes the
63
+ watcher's incremental contracts pass to honor the full emit options (`query` /
64
+ `mutationClient` / `queryImport` / validation adapter) instead of silently dropping them on
65
+ each edit.
66
+
67
+ - fd032c4: TanStack Query is now an extension, not a core flag (extension system Phase 3).
68
+
69
+ - New package `@dudousxd/nestjs-codegen-tanstack` exporting `tanstackQuery({ import? })`,
70
+ a `CodegenExtension` whose `apiClientLayer` turns `api.ts` leaves into handles with
71
+ `fetch`/`queryKey`/`queryOptions`|`mutationOptions`. Register it via
72
+ `forRoot({ extensions: [tanstackQuery()] })`.
73
+ - **Breaking (core):** the `query` and `queryImport` config options are removed. Replace
74
+ `query: true` with `extensions: [tanstackQuery()]`, and `queryImport: '@tanstack/vue-query'`
75
+ with `tanstackQuery({ import: '@tanstack/vue-query' })`. The default client is unchanged
76
+ (plain typed fetch). `emitApi` now resolves the api.ts transport/layer/members from the
77
+ registered extensions; output is byte-identical to the old flag (verified by a golden snapshot).
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Davide Carvalho
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ import { run } from '../dist/cli/main.js';
3
+ run(process.argv.slice(2))
4
+ .then((code) => process.exit(code ?? 0))
5
+ .catch((err) => {
6
+ console.error(`[nestjs-codegen] ${err?.message ?? err}`);
7
+ process.exit(1);
8
+ });