@7nohe/openapi-react-query-codegen 1.4.0 → 1.4.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.
@@ -1,6 +1,6 @@
1
1
  import ts from "typescript";
2
2
  import { BuildCommonTypeName, extractPropertiesFromObjectParam, getNameFromMethod, } from "./common.mjs";
3
- import { createQueryKeyFromMethod, getRequestParamFromMethod, hookNameFromMethod, } from "./createUseQuery.mjs";
3
+ import { createQueryKeyFromMethod, getQueryKeyFnName, getRequestParamFromMethod, hookNameFromMethod, } from "./createUseQuery.mjs";
4
4
  import { addJSDocToNode } from "./util.mjs";
5
5
  /**
6
6
  * Creates a prefetch function for a query
@@ -19,16 +19,13 @@ function createPrefetchHook({ requestParams, method, className, }) {
19
19
  ...requestParams,
20
20
  ], undefined, ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), ts.factory.createCallExpression(ts.factory.createIdentifier("queryClient.prefetchQuery"), undefined, [
21
21
  ts.factory.createObjectLiteralExpression([
22
- ts.factory.createPropertyAssignment(ts.factory.createIdentifier("queryKey"), ts.factory.createArrayLiteralExpression([
23
- BuildCommonTypeName(queryKey),
24
- method.getParameters().length
25
- ? ts.factory.createArrayLiteralExpression([
26
- ts.factory.createObjectLiteralExpression(method
27
- .getParameters()
28
- .flatMap((param) => extractPropertiesFromObjectParam(param).map((p) => ts.factory.createShorthandPropertyAssignment(ts.factory.createIdentifier(p.name))))),
29
- ])
30
- : ts.factory.createArrayLiteralExpression([]),
31
- ], false)),
22
+ ts.factory.createPropertyAssignment(ts.factory.createIdentifier("queryKey"), ts.factory.createCallExpression(BuildCommonTypeName(getQueryKeyFnName(queryKey)), undefined, method.getParameters().length
23
+ ? [
24
+ ts.factory.createObjectLiteralExpression(method
25
+ .getParameters()
26
+ .flatMap((param) => extractPropertiesFromObjectParam(param).map((p) => ts.factory.createShorthandPropertyAssignment(ts.factory.createIdentifier(p.name))))),
27
+ ]
28
+ : [])),
32
29
  ts.factory.createPropertyAssignment(ts.factory.createIdentifier("queryFn"), ts.factory.createArrowFunction(undefined, undefined, [], undefined, ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier(className), ts.factory.createIdentifier(methodName)), undefined, method.getParameters().length
33
30
  ? [
34
31
  ts.factory.createObjectLiteralExpression(method
@@ -183,7 +183,7 @@ export const createUseQuery = ({ className, method, jsDoc, }) => {
183
183
  queryKeyFn,
184
184
  };
185
185
  };
186
- function getQueryKeyFnName(queryKey) {
186
+ export function getQueryKeyFnName(queryKey) {
187
187
  return `${capitalizeFirstLetter(queryKey)}Fn`;
188
188
  }
189
189
  function createQueryKeyFnExport(queryKey, method) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@7nohe/openapi-react-query-codegen",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "OpenAPI React Query Codegen",
5
5
  "bin": {
6
6
  "openapi-rq": "dist/cli.mjs"