@dudousxd/nestjs-codegen 0.25.2 → 0.27.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 +56 -0
- package/README.md +2 -2
- package/dist/cli/main.cjs +991 -270
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.js +997 -274
- package/dist/cli/main.js.map +1 -1
- package/dist/extension/index.cjs.map +1 -1
- package/dist/extension/index.d.cts +1 -1
- package/dist/extension/index.d.ts +1 -1
- package/dist/extension/index.js.map +1 -1
- package/dist/{index-Ce3YnfwS.d.cts → index-Dc4s883u.d.cts} +49 -5
- package/dist/{index-Ce3YnfwS.d.ts → index-Dc4s883u.d.ts} +49 -5
- package/dist/index.cjs +994 -273
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1000 -277
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +1037 -318
- package/dist/nest/index.cjs.map +1 -1
- package/dist/nest/index.d.cts +1 -1
- package/dist/nest/index.d.ts +1 -1
- package/dist/nest/index.js +1040 -319
- package/dist/nest/index.js.map +1 -1
- package/package.json +11 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,61 @@
|
|
|
1
1
|
# @dudousxd/nestjs-codegen
|
|
2
2
|
|
|
3
|
+
## 0.27.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#101](https://github.com/DavideCarvalho/nestjs-codegen/pull/101) [`eb98ec8`](https://github.com/DavideCarvalho/nestjs-codegen/commit/eb98ec87be042b56a068bff9d4d71c35b6e67283) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Several page globs and several Inertia apps (scopes).
|
|
8
|
+
|
|
9
|
+
- `pages.glob` takes one glob or an array. Each page is named relative to the static base of
|
|
10
|
+
the glob that matched it (brace globs included: the base stops at the first segment with
|
|
11
|
+
glob syntax), and two files resolving to the same page name are an error.
|
|
12
|
+
- `pages.scopes` declares more Inertia apps, one per `InertiaModule.forFeature({ scope })`:
|
|
13
|
+
`{ glob, prefix?, componentNameStrategy? }`. A scope's page names get the prefix
|
|
14
|
+
`'<scope>/'` by default (`minimal/pages/Home.tsx` → `minimal/Home`). Every page lands in
|
|
15
|
+
`InertiaPages`/`InertiaPageName`; `pages.d.ts` also exports `InertiaScopePages` and
|
|
16
|
+
`InertiaScopePageName<S>`, `components.json` records each page's `scope`, and the watcher and
|
|
17
|
+
the skip-if-unchanged hash cover every scope's pages.
|
|
18
|
+
- The top-level `scopes` option never had an effect; it is deprecated and now warns.
|
|
19
|
+
|
|
20
|
+
- [#100](https://github.com/DavideCarvalho/nestjs-codegen/pull/100) [`1cc8944`](https://github.com/DavideCarvalho/nestjs-codegen/commit/1cc8944126b794cdd5748e2417f448cd1e157395) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Request handles are real Promises, and `api.ts` compiles under strict compiler flags.
|
|
21
|
+
|
|
22
|
+
- A generated leaf call (`api.users.create({ body })`) now returns a `RequestHandle<R>`: a
|
|
23
|
+
lazy, memoized `Promise<R>` that also carries `fetch()` and the extension members
|
|
24
|
+
(`queryKey`, `queryOptions`, `mutationOptions`, …). It can be returned from a TanStack
|
|
25
|
+
`mutationFn`/`queryFn`, passed to `Promise.all` or assigned to `Promise<T>` without calling
|
|
26
|
+
`.fetch()` first. Nothing is sent until it is awaited, so building `queryOptions()` or
|
|
27
|
+
reading `queryKey()` never fires a request. `.fetch()` keeps working.
|
|
28
|
+
- `api.ts` imports from `routes.ts` only the names it uses (no unused `ROUTES`/`RouteName`/…),
|
|
29
|
+
a leaf with no input to read takes no parameter, and `infiniteQueryOptions()` no longer
|
|
30
|
+
passes `getPreviousPageParam: undefined`. The output is clean under `noUnusedLocals`,
|
|
31
|
+
`noUnusedParameters`, `exactOptionalPropertyTypes`, `noImplicitOverride`,
|
|
32
|
+
`noUncheckedIndexedAccess` and `noPropertyAccessFromIndexSignature`; a fixture test compiles
|
|
33
|
+
it with all of them.
|
|
34
|
+
|
|
35
|
+
## 0.26.0
|
|
36
|
+
|
|
37
|
+
### Minor Changes
|
|
38
|
+
|
|
39
|
+
- [#98](https://github.com/DavideCarvalho/nestjs-codegen/pull/98) [`12a698e`](https://github.com/DavideCarvalho/nestjs-codegen/commit/12a698ee345f26365f6146cbd3065b2c72c8b26a) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Make the generated client type-check for controllers with `@Head()`, `@Options()` and `@All()` routes.
|
|
40
|
+
|
|
41
|
+
Discovery recognized all three decorators, and `api.ts` called `fetcher.head`, `fetcher.options` and `fetcher.all` for them — none of which the `Fetcher` had, so one such route anywhere in the app broke the generated file's type-check. Apps worked around it by augmenting `Fetcher` with stubs that throw.
|
|
42
|
+
|
|
43
|
+
- **`@dudousxd/nestjs-client`**: the `Fetcher` gains `head()` and `options()`. `head()` resolves to `undefined` on a 2xx (a HEAD response has no body) and still rejects a non-2xx with `ApiHttpError`; `options()` parses its body like any verb. A response with an empty body labelled `application/json` now resolves to `undefined` instead of throwing in `JSON.parse`.
|
|
44
|
+
- **`@dudousxd/nestjs-codegen`**: an `@All()` route gets no client method. It answers every verb, so there is no single request a typed method could issue, and in practice it is a protocol endpoint (an MCP transport, a proxy, a webhook sink) driven by a dedicated client rather than by the app's UI. Mapping it onto one verb would type a request the handler may not mean, and a method-parameterized call would be an untyped escape hatch the fetcher already has (`fetchRaw`). It keeps its `routes.ts` entry, so `route('mcp.handle')` still builds its URL, and it is left out of `openapi.json`, where "any method" is not a valid operation. `RequestModel['method']` (read by client-layer extensions) now includes `'head'` and `'options'`.
|
|
45
|
+
- **`@dudousxd/nestjs-codegen-tanstack`**: import decisions ignore `@All()` routes, matching the leaves core emits.
|
|
46
|
+
|
|
47
|
+
A `@Head()`/`@Options()` route now needs `@dudousxd/nestjs-client` 0.9 or later, or a custom fetcher (`fetcherImportPath`) that has both methods.
|
|
48
|
+
|
|
49
|
+
- [#98](https://github.com/DavideCarvalho/nestjs-codegen/pull/98) [`12a698e`](https://github.com/DavideCarvalho/nestjs-codegen/commit/12a698ee345f26365f6146cbd3065b2c72c8b26a) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Type requests from validation-pipe schemas, and resolve refined schemas instead of degrading them to `unknown`.
|
|
50
|
+
|
|
51
|
+
**Schema pipes.** Request types were read from `@ApplyContract(defineContract(...))` or from a DTO class, so a route validating with a schema pipe — `@Body(new ZodPipe(schema)) body: z.infer<typeof schema>`, the pattern many zod codebases use everywhere — reached the client with no body at all. The pipe's argument is now read as the schema for a whole `@Body(pipe)`, a whole or named `@Query(pipe)` / `@Query('name', pipe)`, and path params through `@Param('name', pipe)` or a whole `@Param(pipe)` object (path params were always `string`; a schema can now narrow one, e.g. to an enum's literals). Any pipe counts — `new X(schema)` or `x(schema)`, whatever it is called — as long as its argument is a schema, and the schema may be declared locally, imported, written inline or returned by a helper. `ParseIntPipe`, `new DefaultValuePipe(1)` and `new ValidationPipe({ … })` are left alone: their parameter keeps being typed by its annotation.
|
|
52
|
+
|
|
53
|
+
**Refinements.** Schemas were typed by walking the method chain, which knew a fixed list of zod calls: `.email()`, `.url()`, `.uuid()`, `.regex()`, `.trim()`, `.min()`/`.max()`, `.default()`, `.refine()`, `.superRefine()`, `.transform()`, `.brand()` and zod 4's `z.email()` all turned the field into `unknown`. Types now come from the TypeScript checker's own inference, through the schema's [Standard Schema](https://standardschema.dev) types, so they resolve fully — for `defineContract` schemas as well — and are not tied to zod: valibot (>= 1) and arktype (>= 2) schemas are read the same way. Older zod without Standard Schema is read through its `_input`/`_output` types, and when the schema library cannot be resolved at all the syntactic reader still answers as before.
|
|
54
|
+
|
|
55
|
+
Request positions (body, query, params) use the schema's **input** type — what the client may send: a `.default()` field is optional, and a `.transform()` is typed by what it reads, since sending what it produces would fail validation. Where the input is `unknown` (zod 4's `z.coerce.*`), the output type stands in, so a coerced query param is a `number`. A `defineContract` `response`/`error` uses the **output** type.
|
|
56
|
+
|
|
57
|
+
The checker runs in a second, lib-loading program, built only when a route carries a schema candidate, so a codebase without schemas does not pay for it. That program holds only what the schemas can reach: every project file enters it with the imports no schema depends on blanked out, so a controller's services, database layer and SDKs stay out. Measured on a 755-route app that validates ~300 request bodies with a schema pipe: every one of those bodies now reaches the client typed, with `unknown` left only where the schema itself says so (`z.unknown()`, `z.record(z.unknown())`); discovery takes ~3 s instead of ~0.5 s (a naive program of everything the controllers import took ~8 s).
|
|
58
|
+
|
|
3
59
|
## 0.25.2
|
|
4
60
|
|
|
5
61
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -53,8 +53,8 @@ export class AppModule {}
|
|
|
53
53
|
```
|
|
54
54
|
|
|
55
55
|
The generated `api.ts` exports a `createApi(fetcher)` factory — create the client once,
|
|
56
|
-
injecting your fetcher. Each endpoint is a **unified awaitable handle**:
|
|
57
|
-
the request.
|
|
56
|
+
injecting your fetcher. Each endpoint is a **unified awaitable handle**: a lazy, memoized
|
|
57
|
+
`Promise` — `await` it (or return it from a TanStack `mutationFn`) to run the request.
|
|
58
58
|
|
|
59
59
|
```ts title="src/lib/api.ts"
|
|
60
60
|
import { createApi } from '../generated/api';
|