@7nohe/openapi-react-query-codegen 1.3.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
@@ -122,7 +122,7 @@ export function createQueryHook({ queryString, suffix, responseDataType, request
122
122
  .flatMap((param) => extractPropertiesFromObjectParam(param).map((p) => ts.factory.createShorthandPropertyAssignment(ts.factory.createIdentifier(p.name))))),
123
123
  ts.factory.createIdentifier("queryKey"),
124
124
  ]
125
- : [])),
125
+ : [ts.factory.createIdentifier("queryKey")])),
126
126
  ts.factory.createPropertyAssignment(ts.factory.createIdentifier("queryFn"), ts.factory.createArrowFunction(undefined, undefined, [], undefined, EqualsOrGreaterThanToken, ts.factory.createAsExpression(ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier(className), ts.factory.createIdentifier(methodName)), undefined, method.getParameters().length
127
127
  ? [
128
128
  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) {
@@ -191,16 +191,10 @@ function createQueryKeyFnExport(queryKey, method) {
191
191
  // override key is used to allow the user to override the the queryKey values
192
192
  const overrideKey = ts.factory.createParameterDeclaration(undefined, undefined, ts.factory.createIdentifier("queryKey"), QuestionToken, ts.factory.createTypeReferenceNode("Array<unknown>", []));
193
193
  return ts.factory.createVariableStatement([ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)], ts.factory.createVariableDeclarationList([
194
- ts.factory.createVariableDeclaration(ts.factory.createIdentifier(getQueryKeyFnName(queryKey)), undefined, undefined, ts.factory.createArrowFunction(undefined, undefined, params ? [params, overrideKey] : [], undefined, EqualsOrGreaterThanToken, queryKeyFn(queryKey, method))),
194
+ ts.factory.createVariableDeclaration(ts.factory.createIdentifier(getQueryKeyFnName(queryKey)), undefined, undefined, ts.factory.createArrowFunction(undefined, undefined, params ? [params, overrideKey] : [overrideKey], undefined, EqualsOrGreaterThanToken, queryKeyFn(queryKey, method))),
195
195
  ], ts.NodeFlags.Const));
196
196
  }
197
197
  function queryKeyFn(queryKey, method) {
198
- const params = getRequestParamFromMethod(method);
199
- if (!params) {
200
- return ts.factory.createArrayLiteralExpression([
201
- ts.factory.createIdentifier(queryKey),
202
- ]);
203
- }
204
198
  return ts.factory.createArrayLiteralExpression([
205
199
  ts.factory.createIdentifier(queryKey),
206
200
  ts.factory.createSpreadElement(ts.factory.createParenthesizedExpression(ts.factory.createBinaryExpression(ts.factory.createIdentifier("queryKey"), ts.factory.createToken(ts.SyntaxKind.QuestionQuestionToken), method.getParameters().length
package/dist/generate.mjs CHANGED
@@ -12,10 +12,12 @@ export async function generate(options, version) {
12
12
  debug: formattedOptions.debug,
13
13
  dryRun: false,
14
14
  exportCore: true,
15
- format: formattedOptions.format,
15
+ output: {
16
+ format: formattedOptions.format,
17
+ lint: formattedOptions.lint,
18
+ path: openApiOutputPath,
19
+ },
16
20
  input: formattedOptions.input,
17
- lint: formattedOptions.lint,
18
- output: openApiOutputPath,
19
21
  request: formattedOptions.request,
20
22
  schemas: {
21
23
  export: !formattedOptions.noSchemas,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@7nohe/openapi-react-query-codegen",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
4
4
  "description": "OpenAPI React Query Codegen",
5
5
  "bin": {
6
6
  "openapi-rq": "dist/cli.mjs"
@@ -31,7 +31,7 @@
31
31
  "author": "Daiki Urata (@7nohe)",
32
32
  "license": "MIT",
33
33
  "dependencies": {
34
- "@hey-api/openapi-ts": "0.43.0"
34
+ "@hey-api/openapi-ts": "0.45.1"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@biomejs/biome": "^1.7.2",
@@ -42,6 +42,7 @@
42
42
  "lefthook": "^1.6.10",
43
43
  "rimraf": "^5.0.5",
44
44
  "ts-morph": "^22.0.0",
45
+ "ts-node": "^10.9.2",
45
46
  "typescript": "^5.3.3",
46
47
  "vitest": "^1.5.0"
47
48
  },