@dudousxd/nestjs-inertia-codegen 1.0.7 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli/main.js CHANGED
@@ -292,15 +292,16 @@ function emitApiObjectBlock(tree, indent) {
292
292
  if (method === "GET") {
293
293
  const typeAccess = buildRouterTypeAccess(c.name);
294
294
  lines.push(`${pad}${objKey}: {`);
295
- lines.push(`${pad} queryOptions: (query?: ${typeAccess}['query']) =>`);
296
- lines.push(`${pad} queryOptions({`);
297
- lines.push(`${pad} queryKey: [${flatName}, query],`);
298
- lines.push(`${pad} queryFn: () => fetcher.get<${typeAccess}['response']>(route(${flatName} as never) || ${safePath}, { query }),`);
299
- lines.push(`${pad} }),`);
295
+ lines.push(`${pad} queryKey: (query?: ${typeAccess}['query']) => query !== undefined ? [${flatName}, query] as const : [${flatName}] as const,`);
296
+ lines.push(`${pad} queryOptions: (query?: ${typeAccess}['query']) => ({`);
297
+ lines.push(`${pad} queryKey: query !== undefined ? [${flatName}, query] as const : [${flatName}] as const,`);
298
+ lines.push(`${pad} queryFn: () => fetcher.get<${typeAccess}['response']>(route(${flatName} as never) || ${safePath}, { query }),`);
299
+ lines.push(`${pad} }),`);
300
300
  lines.push(`${pad}},`);
301
301
  } else {
302
302
  const typeAccess = buildRouterTypeAccess(c.name);
303
303
  lines.push(`${pad}${objKey}: {`);
304
+ lines.push(`${pad} queryKey: () => [${flatName}] as const,`);
304
305
  lines.push(`${pad} mutationOptions: () => ({`);
305
306
  lines.push(`${pad} mutationFn: (body: ${typeAccess}['body']) => fetcher.${fetcherMethod}<${typeAccess}['response']>(route(${flatName} as never) || ${safePath}, { body }),`);
306
307
  lines.push(`${pad} }),`);
@@ -322,14 +323,10 @@ function buildRouterTypeAccess(name) {
322
323
  __name(buildRouterTypeAccess, "buildRouterTypeAccess");
323
324
  function buildApiFile(routes) {
324
325
  const contracted = routes.filter((r) => r.contract);
325
- const hasGetRoutes = contracted.some((r) => r.method === "GET");
326
326
  const lines = [
327
327
  "// Generated by @dudousxd/nestjs-inertia-codegen. Do not edit.",
328
328
  ""
329
329
  ];
330
- if (hasGetRoutes) {
331
- lines.push("import { queryOptions } from '@tanstack/query-core';");
332
- }
333
330
  lines.push("import { route } from './routes.js';");
334
331
  lines.push("import { createFetcher } from '@dudousxd/nestjs-inertia-client';");
335
332
  lines.push("");
@@ -1400,7 +1397,7 @@ async function watch(config, onChange) {
1400
1397
  __name(watch, "watch");
1401
1398
 
1402
1399
  // src/index.ts
1403
- var VERSION = "1.0.7";
1400
+ var VERSION = "2.0.1";
1404
1401
 
1405
1402
  // src/cli/codegen.ts
1406
1403
  async function runCodegen(opts = {}) {