@povio/openapi-codegen-cli 0.8.0 → 0.8.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@povio/openapi-codegen-cli",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "main": "./dist/index.js",
5
5
  "bin": {
6
6
  "openapi-codegen": "./dist/sh.js"
@@ -1,8 +1,8 @@
1
1
  /**
2
- * Use for `{{queryName endpoint}}` {{#if (isQuery endpoint)}}query{{else}}mutation{{/if}} ability. {{#if (hasAbilityConditions endpoint)}}For global ability, omit the object parameter.{{/if}}{{#if (abilityDescription endpoint)}}
2
+ * Use for {{{genCaslAbilityQuery endpoint}}} ability. {{#if (hasAbilityConditions endpoint)}}For global ability, omit the object parameter.{{/if}}{{#if (abilityDescription endpoint)}}
3
3
  * @description {{abilityDescription endpoint}}{{/if}}
4
4
  {{#if (hasAbilityConditions endpoint)}}{{#each (abilityConditionsTypes endpoint) as | propertyType |}} * @param { {{propertyType.type}}{{propertyType.zodSchemaName}} } object.{{propertyType.name}} {{propertyType.name}} from {{propertyType.info}}
5
- {{/each}}{{/if}} * @returns { {{abilityTypeName endpoint}} } An ability tuple indicating the user's ability to use `{{queryName endpoint}}` {{#if (isQuery endpoint)}}query{{else}}mutation{{/if}}
5
+ {{/each}}{{/if}} * @returns { {{abilityTypeName endpoint}} } An ability tuple indicating the user's ability to use {{{genCaslAbilityQuery endpoint}}}
6
6
  */
7
7
  export const {{abilityFunctionName endpoint}} = (
8
8
  {{#if (hasAbilityConditions endpoint)}}object?: { {{#each (abilityConditionsTypes endpoint) as | propertyType |}}{{propertyType.name}}{{#unless propertyType.required}}?{{/unless}}: {{propertyType.type}}{{propertyType.zodSchemaName}}, {{/each}} } {{/if}}
@@ -0,0 +1 @@
1
+ {{#if (isQuery endpoint)}}{{#if (isMutation endpoint)}}`{{queryName endpoint}}` query or `{{queryName endpoint mutation=true}}` mutation{{else}}`{{queryName endpoint}}` query{{/if}}{{else}}`{{queryName endpoint}}` mutation{{/if}}
@@ -8,14 +8,24 @@
8
8
  {{/each}}{{/if}} * @param { AppInfiniteQueryOptions } options Infinite query options
9
9
  * @returns { UseInfiniteQueryResult<{{{importedZodSchemaInferedType endpoint.response}}}> } {{endpoint.responseDescription}}
10
10
  * @statusCodes [{{commaSeparated endpoint.responseStatusCodes}}]
11
- */{{else}}
11
+ */{{else if query}}
12
12
  /**
13
- * {{#if (isQuery endpoint)}}Query{{else}}Mutation{{/if}} `{{queryName endpoint}}`{{#if endpoint.summary}}
13
+ * Query `{{queryName endpoint}}`{{#if endpoint.summary}}{{#if endpoint.fileDownload}} - 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
- {{#if (endpointParams endpoint includeFileParam=true)}}{{#each (endpointParams endpoint includeFileParam=true) as | endpointParam |}} * @param { {{endpointParam.type}} } {{#if (isQuery ../endpoint)}}object{{else}}mutation{{/if}}.{{endpointParam.name}} {{{endpointParamDescription endpointParam}}}
18
- {{/each}}{{/if}} * @param {{#if (isQuery endpoint)}}{ AppQueryOptions{{#if hasFileActionQueryOptions}} & {{fileActionQueryOptionsType}}{{/if}} } options Query options{{else}}{ AppMutationOptions{{#if hasInvalidateQueryOptions}} & {{invalidateQueryOptionsType}}{{/if}} } options Mutation options{{/if}}
19
- * @returns { {{#if (isQuery endpoint)}}UseQueryResult{{else}}UseMutationResult{{/if}}<{{{importedZodSchemaInferedType endpoint.response}}}> } {{endpoint.responseDescription}}
17
+ {{#if (endpointParams endpoint includeFileParam=true)}}{{#each (endpointParams endpoint includeFileParam=true) as | endpointParam |}} * @param { {{endpointParam.type}} } object.{{endpointParam.name}} {{{endpointParamDescription endpointParam}}}
18
+ {{/each}}{{/if}} * @param { AppQueryOptions } options Query options
19
+ * @returns { UseQueryResult<{{#if endpoint.fileDownload}}AxiosResponse<{{/if}}{{{importedZodSchemaInferedType endpoint.response}}}{{#if endpoint.fileDownload}}>{{/if}}> } {{endpoint.responseDescription}}
20
+ * @statusCodes [{{commaSeparated endpoint.responseStatusCodes}}]
21
+ */{{else if mutation}}
22
+ /**
23
+ * Mutation `{{queryName endpoint mutation=true}}`{{#if endpoint.summary}}{{#if endpoint.fileDownload}} - recommended when file should not be cached{{/if}}
24
+ * @summary {{addAsteriskAfterNewLine endpoint.summary}}{{/if}}{{#if endpoint.description}}
25
+ * @description {{addAsteriskAfterNewLine endpoint.description}}{{/if}}{{#if endpoint.acl}}
26
+ * @permission Requires `{{abilityFunctionName endpoint}}` ability {{/if}}
27
+ {{#if (endpointParams endpoint includeFileParam=true)}}{{#each (endpointParams endpoint includeFileParam=true) as | endpointParam |}} * @param { {{endpointParam.type}} } mutation.{{endpointParam.name}} {{{endpointParamDescription endpointParam}}}
28
+ {{/each}}{{/if}} * @param { AppMutationOptions{{#if hasInvalidateQueryOptions}} & {{invalidateQueryOptionsType}}{{/if}} } options Mutation options
29
+ * @returns { UseMutationResult<{{#if endpoint.fileDownload}}AxiosResponse<{{/if}}{{{importedZodSchemaInferedType endpoint.response}}}{{#if endpoint.fileDownload}}>{{/if}}> } {{endpoint.responseDescription}}
20
30
  * @statusCodes [{{commaSeparated endpoint.responseStatusCodes}}]
21
31
  */{{/if}}
@@ -1,12 +1,12 @@
1
1
  {{! Js docs }}
2
- {{{genQueryJsDocs endpoint}}}
2
+ {{{genQueryJsDocs endpoint mutation=true}}}
3
3
  {{! Mutation definition}}
4
- export const {{queryName endpoint}} = (options?: AppMutationOptions<typeof {{importedEndpointName endpoint}}, { {{{genEndpointParams endpoint includeFileParam=true}}} }>{{#if hasInvalidateQueryOptions}} & {{invalidateQueryOptionsType}}{{/if}}{{#if hasAxiosRequestConfig}}, {{axiosRequestConfigName}}?: {{axiosRequestConfigType}}{{/if}}) => {
4
+ export const {{queryName endpoint mutation=true}} = (options?: AppMutationOptions<typeof {{importedEndpointName endpoint}}, { {{{genEndpointParams endpoint includeFileParam=true}}} }>{{#if hasInvalidateQueryOptions}} & {{invalidateQueryOptionsType}}{{/if}}{{#if hasAxiosRequestConfig}}, {{axiosRequestConfigName}}?: {{axiosRequestConfigType}}{{/if}}) => {
5
5
  {{#if hasInvalidateQueryOptions}} const queryClient = useQueryClient();{{/if}}
6
6
 
7
7
  return {{queryHook}}({
8
- mutationFn: {{#if hasFileUpload}}async {{/if}}({{#if (endpointParams endpoint includeFileParam=true)}} { {{{endpointArgs endpoint includeFileParam=true}}} } {{/if}}) => {{#if hasFileUpload}} {
9
- const uploadInstructions = await{{/if}} {{importedEndpointName endpoint}}({{{endpointArgs endpoint}}}{{#if hasAxiosRequestConfig}}{{#if (endpointArgs endpoint)}}, {{/if}}{{axiosRequestConfigName}}{{/if}}){{#if hasFileUpload}};
8
+ mutationFn: {{#if endpoint.fileUpload}}async {{/if}}({{#if (endpointParams endpoint includeFileParam=true)}} { {{{endpointArgs endpoint includeFileParam=true}}} } {{/if}}) => {{#if endpoint.fileUpload}} {
9
+ const uploadInstructions = await{{/if}} {{importedEndpointName endpoint}}({{{endpointArgs endpoint}}}{{#if hasAxiosRequestConfig}}{{#if (endpointArgs endpoint)}}, {{/if}}{{axiosRequestConfigName}}{{/if}}){{#if endpoint.fileUpload}};
10
10
 
11
11
  if (file && uploadInstructions.url) {
12
12
  await axios.put(uploadInstructions.url, file, {
@@ -1,14 +1,10 @@
1
1
  {{! Js docs }}
2
- {{{genQueryJsDocs endpoint}}}
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 hasFileActionQueryOptions}} & {{fileActionQueryOptionsType}}{{/if}}{{#if hasAxiosRequestConfig}}, {{axiosRequestConfigName}}?: {{axiosRequestConfigType}}{{/if}}) => {
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}}) => {
5
5
  return {{queryHook}}({
6
6
  queryKey: keys.{{endpointName endpoint}}({{#if (endpointParams endpoint)}}{{{endpointArgs endpoint}}}{{/if}}),
7
- queryFn: {{#if hasFileDownload}}async {{/if}}{{#if hasQueryFn}}() => {{#if hasFileDownload}} {
8
- const res = await{{/if}} {{importedEndpointName endpoint}}({{{endpointArgs endpoint}}}{{#if hasAxiosRequestConfig}}{{#if (endpointArgs endpoint)}}, {{/if}}{{axiosRequestConfigName}}{{/if}}){{else}}{{importedEndpointName endpoint}}{{/if}}{{#if hasFileDownload}};
9
- responseFileAction(res, options);
10
- return res;
11
- }{{/if}},
7
+ queryFn: {{#if hasQueryFn}}() => {{importedEndpointName endpoint}}({{{endpointArgs endpoint}}}{{#if hasAxiosRequestConfig}}{{#if (endpointArgs endpoint)}}, {{/if}}{{axiosRequestConfigName}}{{/if}}){{else}}{{importedEndpointName endpoint}}{{/if}},
12
8
  ...options,
13
9
  });
14
10
  };
@@ -8,10 +8,6 @@
8
8
  {{#if hasInvalidateQueriesImport}}
9
9
  {{{genImport invalidateQueriesImport}}}
10
10
  {{/if}}
11
- {{! File action import }}
12
- {{#if hasFileActionImport}}
13
- {{{genImport fileActionImport}}}
14
- {{/if}}
15
11
  {{! React query types import }}
16
12
  {{{genImport queryTypesImport}}}
17
13
  {{! Models import }}
@@ -36,11 +32,9 @@ export const {{queriesModuleName}} = "{{namespace}}";
36
32
  {{#each endpoints as | endpoint |}}
37
33
  {{{genQuery endpoint}}}
38
34
 
39
- {{#if ../generateInfiniteQueries}}
40
- {{#if (isInfiniteQuery endpoint)}}
35
+ {{{genMutation endpoint}}}
36
+
41
37
  {{{genInfiniteQuery endpoint}}}
42
- {{/if}}
43
- {{/if}}
44
38
 
45
39
  {{/each}}
46
40
 
@@ -1,47 +0,0 @@
1
- import { AxiosResponse, AxiosResponseHeaders } from "axios";
2
-
3
- export interface FileActionQueryOptions {
4
- fileName?: string;
5
- downloadFile?: boolean;
6
- previewFile?: boolean;
7
- }
8
-
9
- export function responseFileAction(res: AxiosResponse<Blob>, options?: FileActionQueryOptions) {
10
- const fileName = extractFilename(res.headers as AxiosResponseHeaders);
11
-
12
- fileAction(res.data, { ...options, fileName: options?.fileName ?? fileName });
13
- }
14
-
15
- export function fileAction(blob: Blob, options?: FileActionQueryOptions) {
16
- const url = URL.createObjectURL(blob);
17
- const a = document.createElement("a");
18
- a.download = options?.fileName ?? "download";
19
- a.rel = "noopener";
20
- a.href = url;
21
-
22
- if (options?.downloadFile) {
23
- setTimeout(() => a.dispatchEvent(new MouseEvent("click")), 0);
24
- }
25
-
26
- if (options?.previewFile) {
27
- window.open(url, "_blank");
28
- }
29
-
30
- setTimeout(() => URL.revokeObjectURL(url), 40000); // Cleanup after 40s
31
- }
32
-
33
- function extractFilename(headers: AxiosResponseHeaders): string | undefined {
34
- const contentDisposition = Object.keys(headers).find((key) => key.toLowerCase() === "content-disposition");
35
-
36
- if (!contentDisposition) {
37
- return undefined;
38
- }
39
-
40
- const contentDispositionValue = headers[contentDisposition] as string | undefined;
41
- if (!contentDispositionValue) {
42
- return undefined;
43
- }
44
-
45
- const filenameMatch = /filename=["']?([^"';]+)/i.exec(contentDispositionValue);
46
- return filenameMatch ? filenameMatch[1] : undefined;
47
- }