@povio/openapi-codegen-cli 0.8.1 → 0.8.3
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/generators/const/deps.const.d.ts +2 -2
- package/dist/generators/generate/generateInvalidateQueries.d.ts +2 -0
- package/dist/generators/utils/file.utils.d.ts +0 -4
- package/dist/generators/utils/generate/generate.query.utils.d.ts +0 -2
- package/dist/index.js +46 -46
- package/dist/sh.js +63 -63
- package/package.json +1 -1
- package/src/generators/templates/invalidate-queries.hbs +34 -0
- package/src/generators/templates/partials/query-js-docs.hbs +4 -4
- package/src/generators/templates/partials/query-use-mutation.hbs +2 -2
- package/src/generators/templates/queries.hbs +2 -2
- package/dist/generators/generate/generateQueryModules.d.ts +0 -2
- package/src/assets/invalidateQueries.ts +0 -31
- package/src/generators/templates/query-modules.hbs +0 -18
package/package.json
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { QueryClient, QueryKey } from "@tanstack/react-query";
|
|
2
|
+
|
|
3
|
+
export const enum QueryModule {
|
|
4
|
+
{{#each modules as | module |}}
|
|
5
|
+
{{module.tag}} = "{{module.namespace}}",
|
|
6
|
+
{{/each}}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface InvalidateQueryOptions {
|
|
10
|
+
invalidateCurrentModule?: boolean;
|
|
11
|
+
invalidateModules?: QueryModule[];
|
|
12
|
+
invalidateKeys?: QueryKey[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function invalidateQueries(
|
|
16
|
+
queryClient: QueryClient,
|
|
17
|
+
currentModule: QueryModule,
|
|
18
|
+
options: InvalidateQueryOptions = {},
|
|
19
|
+
) {
|
|
20
|
+
const { invalidateCurrentModule, invalidateModules, invalidateKeys } = options;
|
|
21
|
+
|
|
22
|
+
if (invalidateCurrentModule) {
|
|
23
|
+
await queryClient.invalidateQueries({ queryKey: [currentModule] });
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (invalidateModules) {
|
|
27
|
+
await Promise.all([...invalidateModules.map((module) => queryClient.invalidateQueries({ queryKey: [module] }))]);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (invalidateKeys) {
|
|
31
|
+
await Promise.all([...invalidateKeys.map((queryKey) => queryClient.invalidateQueries({ queryKey }))]);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
@@ -10,22 +10,22 @@
|
|
|
10
10
|
* @statusCodes [{{commaSeparated endpoint.responseStatusCodes}}]
|
|
11
11
|
*/{{else if query}}
|
|
12
12
|
/**
|
|
13
|
-
* Query `{{queryName endpoint}}`{{#if endpoint.summary}}{{#if endpoint.
|
|
13
|
+
* Query `{{queryName endpoint}}`{{#if endpoint.summary}}{{#if endpoint.mediaDownload}} - recommended when file should be cached{{/if}}
|
|
14
14
|
* @summary {{addAsteriskAfterNewLine endpoint.summary}}{{/if}}{{#if endpoint.description}}
|
|
15
15
|
* @description {{addAsteriskAfterNewLine endpoint.description}}{{/if}}{{#if endpoint.acl}}
|
|
16
16
|
* @permission Requires `{{abilityFunctionName endpoint}}` ability {{/if}}
|
|
17
17
|
{{#if (endpointParams endpoint includeFileParam=true)}}{{#each (endpointParams endpoint includeFileParam=true) as | endpointParam |}} * @param { {{endpointParam.type}} } object.{{endpointParam.name}} {{{endpointParamDescription endpointParam}}}
|
|
18
18
|
{{/each}}{{/if}} * @param { AppQueryOptions } options Query options
|
|
19
|
-
* @returns { UseQueryResult<{{#if endpoint.
|
|
19
|
+
* @returns { UseQueryResult<{{#if endpoint.mediaDownload}}AxiosResponse<{{/if}}{{{importedZodSchemaInferedType endpoint.response}}}{{#if endpoint.mediaDownload}}>{{/if}}> } {{endpoint.responseDescription}}
|
|
20
20
|
* @statusCodes [{{commaSeparated endpoint.responseStatusCodes}}]
|
|
21
21
|
*/{{else if mutation}}
|
|
22
22
|
/**
|
|
23
|
-
* Mutation `{{queryName endpoint mutation=true}}`{{#if endpoint.summary}}{{#if endpoint.
|
|
23
|
+
* Mutation `{{queryName endpoint mutation=true}}`{{#if endpoint.summary}}{{#if endpoint.mediaDownload}} - recommended when file should not be cached{{/if}}
|
|
24
24
|
* @summary {{addAsteriskAfterNewLine endpoint.summary}}{{/if}}{{#if endpoint.description}}
|
|
25
25
|
* @description {{addAsteriskAfterNewLine endpoint.description}}{{/if}}{{#if endpoint.acl}}
|
|
26
26
|
* @permission Requires `{{abilityFunctionName endpoint}}` ability {{/if}}
|
|
27
27
|
{{#if (endpointParams endpoint includeFileParam=true)}}{{#each (endpointParams endpoint includeFileParam=true) as | endpointParam |}} * @param { {{endpointParam.type}} } mutation.{{endpointParam.name}} {{{endpointParamDescription endpointParam}}}
|
|
28
28
|
{{/each}}{{/if}} * @param { AppMutationOptions{{#if hasInvalidateQueryOptions}} & {{invalidateQueryOptionsType}}{{/if}} } options Mutation options
|
|
29
|
-
* @returns { UseMutationResult<{{#if endpoint.
|
|
29
|
+
* @returns { UseMutationResult<{{#if endpoint.mediaDownload}}AxiosResponse<{{/if}}{{{importedZodSchemaInferedType endpoint.response}}}{{#if endpoint.mediaDownload}}>{{/if}}> } {{endpoint.responseDescription}}
|
|
30
30
|
* @statusCodes [{{commaSeparated endpoint.responseStatusCodes}}]
|
|
31
31
|
*/{{/if}}
|
|
@@ -5,8 +5,8 @@ export const {{queryName endpoint mutation=true}} = (options?: AppMutationOption
|
|
|
5
5
|
{{#if hasInvalidateQueryOptions}} const queryClient = useQueryClient();{{/if}}
|
|
6
6
|
|
|
7
7
|
return {{queryHook}}({
|
|
8
|
-
mutationFn: {{#if endpoint.
|
|
9
|
-
const uploadInstructions = await{{/if}} {{importedEndpointName endpoint}}({{{endpointArgs endpoint}}}{{#if hasAxiosRequestConfig}}{{#if (endpointArgs endpoint)}}, {{/if}}{{axiosRequestConfigName}}{{/if}}){{#if endpoint.
|
|
8
|
+
mutationFn: {{#if endpoint.mediaUpload}}async {{/if}}({{#if (endpointParams endpoint includeFileParam=true)}} { {{{endpointArgs endpoint includeFileParam=true}}} } {{/if}}) => {{#if endpoint.mediaUpload}} {
|
|
9
|
+
const uploadInstructions = await{{/if}} {{importedEndpointName endpoint}}({{{endpointArgs endpoint}}}{{#if hasAxiosRequestConfig}}{{#if (endpointArgs endpoint)}}, {{/if}}{{axiosRequestConfigName}}{{/if}}){{#if endpoint.mediaUpload}};
|
|
10
10
|
|
|
11
11
|
if (file && uploadInstructions.url) {
|
|
12
12
|
await axios.put(uploadInstructions.url, file, {
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
{{! React query import }}
|
|
6
6
|
{{{genImport queryImport}}}
|
|
7
7
|
{{! Invalidate queries import }}
|
|
8
|
-
{{#if
|
|
8
|
+
{{#if hasInvalidateQueryOptions}}
|
|
9
9
|
{{{genImport invalidateQueriesImport}}}
|
|
10
10
|
{{/if}}
|
|
11
11
|
{{! React query types import }}
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
export namespace {{namespace}} {
|
|
24
24
|
{{/if}}
|
|
25
25
|
|
|
26
|
-
export const {{queriesModuleName}} = "{{namespace}}";
|
|
26
|
+
export const {{queriesModuleName}} = {{#if hasInvalidateQueryOptions}}{{queryModuleEnum}}.{{tag}}{{else}}"{{namespace}}"{{/if}};
|
|
27
27
|
|
|
28
28
|
{{! Query keys export}}
|
|
29
29
|
{{{genQueryKeys queryEndpoints}}}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { QueryClient } from "@tanstack/react-query";
|
|
2
|
-
|
|
3
|
-
import { QueriesModuleType, QueriesModuleKeysAll } from "./queryModules";
|
|
4
|
-
|
|
5
|
-
export interface InvalidateQueryOptions {
|
|
6
|
-
invalidateCurrentModule?: boolean;
|
|
7
|
-
invalidateModules?: QueriesModuleType[];
|
|
8
|
-
invalidateKeys?: readonly unknown[][];
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export async function invalidateQueries(
|
|
12
|
-
queryClient: QueryClient,
|
|
13
|
-
currentModule: QueriesModuleType,
|
|
14
|
-
options: InvalidateQueryOptions = {},
|
|
15
|
-
) {
|
|
16
|
-
const { invalidateCurrentModule, invalidateModules, invalidateKeys } = options;
|
|
17
|
-
|
|
18
|
-
if (invalidateCurrentModule && QueriesModuleKeysAll[currentModule]) {
|
|
19
|
-
await queryClient.invalidateQueries({ queryKey: QueriesModuleKeysAll[currentModule] });
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (invalidateModules) {
|
|
23
|
-
await Promise.all([
|
|
24
|
-
...invalidateModules.map((module) => queryClient.invalidateQueries({ queryKey: QueriesModuleKeysAll[module] })),
|
|
25
|
-
]);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (invalidateKeys) {
|
|
29
|
-
await Promise.all([...invalidateKeys.map((queryKey) => queryClient.invalidateQueries({ queryKey }))]);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{{! Module name and keys imports }}
|
|
2
|
-
{{#each imports as | import |}}
|
|
3
|
-
{{{genImport import}}}
|
|
4
|
-
{{/each}}
|
|
5
|
-
|
|
6
|
-
{{! Queries module name and keys object }}
|
|
7
|
-
export const QueriesModuleKeysAll = {
|
|
8
|
-
{{#if includeNamespace}}{{#each modules as | module |}} [{{module.namespace}}.{{../queriesModuleName}}]: {{#if module.hasKeys}}{{module.namespace}}.keys.all{{else}}undefined{{/if}}, {{/each}}
|
|
9
|
-
{{else}}{{#each modules as | module |}} [{{tagModuleName module.tag}}]:{{#if module.hasKeys}}{{tagKeys module.tag}}.all{{else}}undefined{{/if}}, {{/each}}{{/if}}
|
|
10
|
-
} as const;
|
|
11
|
-
|
|
12
|
-
export type QueriesModuleType = keyof typeof QueriesModuleKeysAll;
|
|
13
|
-
|
|
14
|
-
{{! Queries modules record }}
|
|
15
|
-
export const QueriesModule = {
|
|
16
|
-
{{#if includeNamespace}}{{#each modules as | module |}} {{module.tag}}: {{module.namespace}}.{{../queriesModuleName}}, {{/each}}
|
|
17
|
-
{{else}}{{#each modules as | module |}} {{module.tag}}: {{tagModuleName module.tag}}, {{/each}}{{/if}}
|
|
18
|
-
} satisfies Record<string, QueriesModuleType>;
|