@povio/openapi-codegen-cli 0.5.8 → 0.6.0
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/README.md +16 -10
- package/dist/commands/generate.d.ts +1 -1
- package/dist/generators/const/deps.const.d.ts +1 -0
- package/dist/generators/const/query.const.d.ts +9 -0
- package/dist/generators/utils/generate/generate.endpoints.utils.d.ts +1 -1
- package/dist/generators/utils/generate/generate.query.utils.d.ts +1 -0
- package/dist/generators/utils/hbs/hbs.partials.utils.d.ts +2 -1
- package/dist/generators/utils/{queries.utils.d.ts → query.utils.d.ts} +1 -0
- package/dist/index.js +43 -43
- package/dist/sh.js +59 -59
- package/package.json +1 -1
- package/src/assets/react-query.types.ts +21 -3
- package/src/generators/templates/partials/endpoint-params.hbs +1 -1
- package/src/generators/templates/partials/query-js-docs.hbs +13 -1
- package/src/generators/templates/partials/query-keys.hbs +5 -0
- package/src/generators/templates/partials/query-use-infinite-query.hbs +15 -0
- package/src/generators/templates/queries.hbs +6 -0
package/package.json
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
InfiniteData,
|
|
3
|
+
QueryKey,
|
|
4
|
+
UseInfiniteQueryOptions,
|
|
5
|
+
UseMutationOptions,
|
|
6
|
+
UseQueryOptions,
|
|
7
|
+
} from "@tanstack/react-query";
|
|
2
8
|
|
|
3
9
|
type Function = (...args: any) => any;
|
|
4
10
|
type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N;
|
|
@@ -18,7 +24,19 @@ export type AppMutationOptions<
|
|
|
18
24
|
enableInvalidateAll?: boolean;
|
|
19
25
|
};
|
|
20
26
|
|
|
21
|
-
export type AppInfiniteQueryOptions<
|
|
22
|
-
|
|
27
|
+
export type AppInfiniteQueryOptions<
|
|
28
|
+
TFunction extends Function,
|
|
29
|
+
TData = InfiniteData<Awaited<ReturnType<TFunction>>>,
|
|
30
|
+
TQueryKey extends QueryKey = QueryKey,
|
|
31
|
+
TPageParam = number,
|
|
32
|
+
> = Omit<
|
|
33
|
+
UseInfiniteQueryOptions<
|
|
34
|
+
Awaited<ReturnType<TFunction>>,
|
|
35
|
+
Error,
|
|
36
|
+
IsUnknown<TData, InfiniteData<Awaited<ReturnType<TFunction>>>>,
|
|
37
|
+
Awaited<ReturnType<TFunction>>,
|
|
38
|
+
TQueryKey,
|
|
39
|
+
TPageParam
|
|
40
|
+
>,
|
|
23
41
|
"queryKey" | "queryFn" | "initialPageParam" | "getNextPageParam"
|
|
24
42
|
>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{{#each (endpointParams endpoint) as | endpointParam |}}{{endpointParam.name}}{{#unless endpointParam.required}}?{{/unless}}: {{endpointParam.type}}, {{/each}}
|
|
1
|
+
{{#each (endpointParams endpoint extra) as | endpointParam |}}{{endpointParam.name}}{{#unless endpointParam.required}}?{{/unless}}: {{endpointParam.type}}, {{/each}}
|
|
@@ -1,4 +1,16 @@
|
|
|
1
|
+
{{#if infiniteQuery}}
|
|
1
2
|
/**
|
|
3
|
+
* Infinite query `{{infiniteQueryName endpoint}}{{#if endpoint.summary}}
|
|
4
|
+
* @summary {{addAsteriskAfterNewLine endpoint.summary}}{{/if}}{{#if endpoint.description}}
|
|
5
|
+
* @description {{addAsteriskAfterNewLine endpoint.description}}{{/if}}{{#if endpoint.acl}}
|
|
6
|
+
* @permission Requires `{{abilityFunctionName endpoint}}` ability {{/if}}
|
|
7
|
+
{{#if (endpointParams endpoint)}}{{#each (endpointParams endpoint infiniteQuery "removePageParam") as | endpointParam |}} * @param { {{endpointParam.type}} } object.{{endpointParam.name}} {{{endpointParamDescription endpointParam}}}
|
|
8
|
+
{{/each}}{{/if}} * @param { AppInfiniteQueryOptions } options Infinite query options
|
|
9
|
+
* @returns { UseInfiniteQueryResult<{{{importedZodSchemaInferedType endpoint.response}}}> } {{endpoint.responseDescription}}
|
|
10
|
+
* @statusCodes [{{commaSeparated endpoint.responseStatusCodes}}]
|
|
11
|
+
*/
|
|
12
|
+
{{else}}
|
|
13
|
+
/**
|
|
2
14
|
* {{#if (isQuery endpoint)}}Query{{else}}Mutation{{/if}} `{{queryName endpoint}}`{{#if endpoint.summary}}
|
|
3
15
|
* @summary {{addAsteriskAfterNewLine endpoint.summary}}{{/if}}{{#if endpoint.description}}
|
|
4
16
|
* @description {{addAsteriskAfterNewLine endpoint.description}}{{/if}}{{#if endpoint.acl}}
|
|
@@ -7,4 +19,4 @@
|
|
|
7
19
|
{{/each}}{{/if}} * @param {{#if (isQuery endpoint)}}{ AppQueryOptions } options Query options{{else}}{ AppMutationOptions } options Mutation options{{/if}}
|
|
8
20
|
* @returns { {{#if (isQuery endpoint)}}UseQueryResult{{else}}UseMutationResult{{/if}}<{{{importedZodSchemaInferedType endpoint.response}}}> } {{endpoint.responseDescription}}
|
|
9
21
|
* @statusCodes [{{commaSeparated endpoint.responseStatusCodes}}]
|
|
10
|
-
*/
|
|
22
|
+
*/{{/if}}
|
|
@@ -2,5 +2,10 @@ export const keys = {
|
|
|
2
2
|
all: ["{{namespace}}"] as const,
|
|
3
3
|
{{#each queryEndpoints as | endpoint |}}
|
|
4
4
|
{{endpointName endpoint}}: ({{{genEndpointParams endpoint}}}) => [...keys.all, "{{endpoint.path}}", {{{endpointArgs endpoint}}}] as const,
|
|
5
|
+
{{#if ../generateInfiniteQueries}}
|
|
6
|
+
{{#if (isInfiniteQuery endpoint)}}
|
|
7
|
+
{{endpointName endpoint}}Infinite: ({{{genEndpointParams endpoint "removePageParam"}}}) => [...keys.all, "{{endpoint.path}}", "infinite", {{{endpointArgs endpoint "removePageParam"}}}] as const,
|
|
8
|
+
{{/if}}
|
|
9
|
+
{{/if}}
|
|
5
10
|
{{/each}}
|
|
6
11
|
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{{! Js docs }}
|
|
2
|
+
{{{genQueryJsDocs endpoint "infiniteQuery" }}}
|
|
3
|
+
{{! Infinite query definition}}
|
|
4
|
+
export const {{infiniteQueryName endpoint}} = <TData>({{#if (endpointParams endpoint)}}{ {{{endpointArgs endpoint "removePageParam"}}} }: { {{{genEndpointParams endpoint "removePageParam"}}} }, {{/if}}options?: AppInfiniteQueryOptions<typeof {{importedEndpointName endpoint}}, TData>) => {
|
|
5
|
+
return {{infiniteQueryHook}}({
|
|
6
|
+
queryKey: keys.{{endpointName endpoint}}Infinite({{#if (endpointParams endpoint)}}{{{endpointArgs endpoint "removePageParam"}}}{{/if}}),
|
|
7
|
+
queryFn: ({ pageParam }) => {{importedEndpointName endpoint}}({{{endpointArgs endpoint "replacePageParam"}}}),
|
|
8
|
+
initialPageParam: 1,
|
|
9
|
+
getNextPageParam: ({ {{pageParamName}}, {{totalItemsName}}, {{limitParamName}}: limitParam }) => {
|
|
10
|
+
const pageParam = {{pageParamName}} ?? 1;
|
|
11
|
+
return pageParam * limitParam < {{totalItemsName}} ? pageParam + 1 : null;
|
|
12
|
+
},
|
|
13
|
+
...options,
|
|
14
|
+
});
|
|
15
|
+
};
|
|
@@ -21,6 +21,12 @@ export namespace {{namespace}} {
|
|
|
21
21
|
{{#each endpoints as | endpoint |}}
|
|
22
22
|
{{{genQuery endpoint ../queryEndpoints}}}
|
|
23
23
|
|
|
24
|
+
{{#if ../generateInfiniteQueries}}
|
|
25
|
+
{{#if (isInfiniteQuery endpoint)}}
|
|
26
|
+
{{{genInfiniteQuery endpoint ../queryEndpoints}}}
|
|
27
|
+
{{/if}}
|
|
28
|
+
{{/if}}
|
|
29
|
+
|
|
24
30
|
{{/each}}
|
|
25
31
|
|
|
26
32
|
{{#if includeNamespace}}
|