@povio/openapi-codegen-cli 2.0.8-rc.4 → 2.0.8-rc.41
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/generator.js +41 -41
- package/dist/generators/utils/generate/generate.endpoints.utils.d.ts +2 -0
- package/dist/lib/rest/error-handling.d.ts +3 -3
- package/dist/sh.js +155 -155
- package/package.json +9 -10
- package/src/assets/useMutationEffects.ts +30 -25
- package/src/generators/templates/partials/query-use-infinite-query.hbs +3 -2
- package/src/generators/templates/partials/query-use-query.hbs +4 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@povio/openapi-codegen-cli",
|
|
3
|
-
"version": "2.0.8-rc.
|
|
3
|
+
"version": "2.0.8-rc.41",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"codegen",
|
|
6
6
|
"openapi",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"dev:check": "yarn start check --config ./test/config.ts"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"i18next": "^25.8.
|
|
66
|
+
"i18next": "^25.8.11",
|
|
67
67
|
"import-fresh": "^3.3.1"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
@@ -71,29 +71,28 @@
|
|
|
71
71
|
"@casl/ability": "^6.8.0",
|
|
72
72
|
"@casl/react": "^5.0.1",
|
|
73
73
|
"@tanstack/react-query": "~5.90.21",
|
|
74
|
-
"@types/node": "^
|
|
74
|
+
"@types/node": "^25.3.0",
|
|
75
75
|
"@types/prompt-sync": "^4.2.3",
|
|
76
76
|
"@types/react": "^19.2.14",
|
|
77
77
|
"@types/yargs": "^17.0.35",
|
|
78
78
|
"@vitejs/plugin-react": "^5.1.4",
|
|
79
79
|
"axios": "^1.13.5",
|
|
80
|
-
"esbuild": "0.
|
|
80
|
+
"esbuild": "0.27.3",
|
|
81
81
|
"handlebars": "^4.7.8",
|
|
82
82
|
"openapi-types": "^12.1.3",
|
|
83
|
-
"oxfmt": "^0.
|
|
84
|
-
"oxlint": "^1.
|
|
85
|
-
"oxlint-tsgolint": "^0.14.
|
|
83
|
+
"oxfmt": "^0.34.0",
|
|
84
|
+
"oxlint": "^1.49.0",
|
|
85
|
+
"oxlint-tsgolint": "^0.14.1",
|
|
86
86
|
"prompt-sync": "^4.2.0",
|
|
87
87
|
"react": "^19.2.4",
|
|
88
88
|
"reflect-metadata": "^0.2.2",
|
|
89
|
-
"ts-node": "^10.9.2",
|
|
90
89
|
"ts-pattern": "^5.9.0",
|
|
91
90
|
"tsx": "^4.21.0",
|
|
92
|
-
"type-fest": "^4.
|
|
91
|
+
"type-fest": "^5.4.4",
|
|
93
92
|
"typescript": "^5.9.3",
|
|
94
93
|
"vite": "^7.3.1",
|
|
95
94
|
"vite-plugin-dts": "^4.5.4",
|
|
96
|
-
"vitest": "
|
|
95
|
+
"vitest": "4.0.18",
|
|
97
96
|
"yargs": "^17.7.2",
|
|
98
97
|
"zod": "^4.3.6"
|
|
99
98
|
},
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { useCallback, useEffect } from "react";
|
|
2
2
|
|
|
3
3
|
import { QueryKey, useQueryClient } from "@tanstack/react-query";
|
|
4
|
-
|
|
5
4
|
import { OpenApiQueryConfig, QueryModule, InvalidationMap } from "../lib/config/queryConfig.context";
|
|
6
5
|
import { broadcastQueryInvalidation, setupCrossTabListener } from "./useCrossTabQueryInvalidation";
|
|
7
6
|
|
|
@@ -34,37 +33,36 @@ export function useMutationEffects({ currentModule }: UseMutationEffectsProps) {
|
|
|
34
33
|
options: MutationEffectsOptions = {},
|
|
35
34
|
updateKeys?: QueryKey[],
|
|
36
35
|
) => {
|
|
37
|
-
const {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
invalidateKeys,
|
|
41
|
-
preferUpdate,
|
|
42
|
-
invalidationMap,
|
|
43
|
-
} = options;
|
|
44
|
-
const shouldUpdate = preferUpdate || (preferUpdate === undefined && config.preferUpdate);
|
|
45
|
-
const shouldInvalidateCurrentModule =
|
|
46
|
-
invalidateCurrentModule || (invalidateCurrentModule === undefined && config.invalidateCurrentModule);
|
|
36
|
+
const { invalidateCurrentModule, invalidateModules, invalidateKeys, preferUpdate } = options;
|
|
37
|
+
const shouldUpdate = preferUpdate ?? config.preferUpdate ?? false;
|
|
38
|
+
const shouldInvalidateCurrentModule = invalidateCurrentModule ?? config.invalidateCurrentModule ?? true;
|
|
47
39
|
|
|
48
40
|
const isQueryKeyEqual = (keyA: QueryKey, keyB: QueryKey) =>
|
|
49
41
|
keyA.length === keyB.length && keyA.every((item, index) => item === keyB[index]);
|
|
42
|
+
const isQueryKeyPrefix = (queryKey: QueryKey, prefixKey: QueryKey) =>
|
|
43
|
+
prefixKey.length <= queryKey.length && prefixKey.every((item, index) => item === queryKey[index]);
|
|
44
|
+
const mappedInvalidationKeys = config.invalidationMap?.[currentModule]?.(data, variables);
|
|
50
45
|
|
|
51
|
-
const
|
|
46
|
+
const shouldInvalidateQuery = (queryKey: QueryKey) => {
|
|
47
|
+
const isUpdateKey = updateKeys?.some((key) => isQueryKeyEqual(queryKey, key));
|
|
48
|
+
if (shouldUpdate && isUpdateKey) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
52
51
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
52
|
+
const isCurrentModule = shouldInvalidateCurrentModule && queryKey[0] === currentModule;
|
|
53
|
+
const isInvalidateModule = !!invalidateModules && invalidateModules.some((module) => queryKey[0] === module);
|
|
54
|
+
const isInvalidateKey = !!invalidateKeys && invalidateKeys.some((key) => isQueryKeyPrefix(queryKey, key));
|
|
55
|
+
const isMappedKey =
|
|
56
|
+
!!mappedInvalidationKeys && mappedInvalidationKeys.some((key) => isQueryKeyPrefix(queryKey, key));
|
|
59
57
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const isInvalidateKey = !!invalidateKeys && invalidateKeys.some((key) => isQueryKeyEqual(queryKey, key));
|
|
58
|
+
return isCurrentModule || isInvalidateModule || isInvalidateKey || isMappedKey;
|
|
59
|
+
};
|
|
63
60
|
|
|
64
|
-
|
|
65
|
-
const isMappedKey = !!map && map.some((key) => isQueryKeyEqual(queryKey, key));
|
|
61
|
+
const invalidatedQueryKeys: QueryKey[] = [];
|
|
66
62
|
|
|
67
|
-
|
|
63
|
+
queryClient.invalidateQueries({
|
|
64
|
+
predicate: ({ queryKey }) => {
|
|
65
|
+
const shouldInvalidate = shouldInvalidateQuery(queryKey);
|
|
68
66
|
|
|
69
67
|
if (shouldInvalidate && config.crossTabInvalidation) {
|
|
70
68
|
invalidatedQueryKeys.push([...queryKey]);
|
|
@@ -82,7 +80,14 @@ export function useMutationEffects({ currentModule }: UseMutationEffectsProps) {
|
|
|
82
80
|
updateKeys.map((queryKey) => queryClient.setQueryData(queryKey, data));
|
|
83
81
|
}
|
|
84
82
|
},
|
|
85
|
-
[
|
|
83
|
+
[
|
|
84
|
+
queryClient,
|
|
85
|
+
currentModule,
|
|
86
|
+
config.preferUpdate,
|
|
87
|
+
config.invalidateCurrentModule,
|
|
88
|
+
config.invalidationMap,
|
|
89
|
+
config.crossTabInvalidation,
|
|
90
|
+
],
|
|
86
91
|
);
|
|
87
92
|
|
|
88
93
|
return { runMutationEffects };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{{! Js docs }}
|
|
2
2
|
{{{genQueryJsDocs endpoint infiniteQuery=true}}}
|
|
3
3
|
{{! Infinite query definition}}
|
|
4
|
-
export const {{infiniteQueryName endpoint}} = <TData>({{#if (endpointParams endpoint)}}{ {{{endpointArgs endpoint excludePageParam=true}}} }: { {{{genEndpointParams endpoint excludePageParam=true}}} }, {{/if}}options?: AppInfiniteQueryOptions<typeof {{importedEndpointName endpoint}}, TData>{{#if hasAxiosRequestConfig}}, {{axiosRequestConfigName}}?: {{axiosRequestConfigType}}{{/if}}) => {
|
|
4
|
+
export const {{infiniteQueryName endpoint}} = <TData>({{#if (endpointParams endpoint)}}{{#if (endpointParamsAllOptional endpoint excludePageParam=true)}}params: { {{{genEndpointParams endpoint excludePageParam=true}}} } = {}{{else}}{ {{{endpointArgs endpoint excludePageParam=true}}} }: { {{{genEndpointParams endpoint excludePageParam=true}}} }{{/if}}, {{/if}}options?: AppInfiniteQueryOptions<typeof {{importedEndpointName endpoint}}, TData>{{#if hasAxiosRequestConfig}}, {{axiosRequestConfigName}}?: {{axiosRequestConfigType}}{{/if}}) => {
|
|
5
5
|
{{! Use acl check }}
|
|
6
6
|
{{#if hasAclCheck}}const { checkAcl } = {{aclCheckHook}}();{{/if}}
|
|
7
|
+
{{#if (endpointParams endpoint)}}{{#if (endpointParamsAllOptional endpoint excludePageParam=true)}}const { {{{endpointArgs endpoint excludePageParam=true}}} } = params;{{/if}}{{/if}}
|
|
7
8
|
|
|
8
9
|
return {{infiniteQueryHook}}({
|
|
9
10
|
queryKey: keys.{{endpointName endpoint}}Infinite({{#if (endpointParams endpoint)}}{{{endpointArgs endpoint excludePageParam=true}}}{{/if}}),
|
|
@@ -18,4 +19,4 @@ export const {{infiniteQueryName endpoint}} = <TData>({{#if (endpointParams endp
|
|
|
18
19
|
},
|
|
19
20
|
...options,
|
|
20
21
|
});
|
|
21
|
-
};
|
|
22
|
+
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{{! Js docs }}
|
|
2
2
|
{{{genQueryJsDocs endpoint query=true}}}
|
|
3
3
|
{{! Query definition}}
|
|
4
|
-
export const {{queryName endpoint}} = <TData>({{#if (endpointParams endpoint)}}{ {{{endpointArgs endpoint}}} }: { {{{genEndpointParams endpoint}}} }, {{/if}}options?: AppQueryOptions<typeof {{importedEndpointName endpoint}}, TData>{{#if hasAxiosRequestConfig}}, {{axiosRequestConfigName}}?: {{axiosRequestConfigType}}{{/if}}) => {
|
|
4
|
+
export const {{queryName endpoint}} = <TData>({{#if (endpointParams endpoint)}}{{#if (endpointParamsAllOptional endpoint)}}params: { {{{genEndpointParams endpoint}}} } = {}{{else}}{ {{{endpointArgs endpoint}}} }: { {{{genEndpointParams endpoint}}} }{{/if}}, {{/if}}options?: AppQueryOptions<typeof {{importedEndpointName endpoint}}, TData>{{#if hasAxiosRequestConfig}}, {{axiosRequestConfigName}}?: {{axiosRequestConfigType}}{{/if}}) => {
|
|
5
5
|
{{! Use acl check }}
|
|
6
6
|
{{#if hasAclCheck}}const { checkAcl } = {{aclCheckHook}}();{{/if}}
|
|
7
|
-
|
|
7
|
+
{{#if (endpointParams endpoint)}}{{#if (endpointParamsAllOptional endpoint)}}const { {{{endpointArgs endpoint}}} } = params;{{/if}}{{/if}}
|
|
8
|
+
|
|
8
9
|
return {{queryHook}}({
|
|
9
10
|
queryKey: keys.{{endpointName endpoint}}({{#if (endpointParams endpoint)}}{{{endpointArgs endpoint}}}{{/if}}),
|
|
10
11
|
queryFn: {{#if hasQueryFn}}() => {{#if hasQueryFnBody}}{ {{/if}}
|
|
@@ -13,4 +14,4 @@ export const {{queryName endpoint}} = <TData>({{#if (endpointParams endpoint)}}{
|
|
|
13
14
|
{{#if hasQueryFnBody}} }{{/if}},
|
|
14
15
|
...options,
|
|
15
16
|
});
|
|
16
|
-
};
|
|
17
|
+
};
|