@povio/openapi-codegen-cli 2.0.8-rc.13 → 2.0.8-rc.15

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.
Files changed (32) hide show
  1. package/dist/{generate.runner-DZC8Pd8t.mjs → generate.runner-tAVdp_fl.mjs} +1 -1
  2. package/dist/{generateCodeFromOpenAPIDoc-BvUyx8CZ.mjs → generateCodeFromOpenAPIDoc-CxXf-IaZ.mjs} +6 -2
  3. package/dist/generator.mjs +1 -1
  4. package/dist/sh.mjs +3 -3
  5. package/dist/vite.mjs +2 -2
  6. package/package.json +2 -4
  7. package/src/generators/templates/acl-check.hbs +0 -29
  8. package/src/generators/templates/acl.hbs +0 -19
  9. package/src/generators/templates/app-acl.hbs +0 -17
  10. package/src/generators/templates/app-rest-client.hbs +0 -7
  11. package/src/generators/templates/configs.hbs +0 -80
  12. package/src/generators/templates/endpoints.hbs +0 -43
  13. package/src/generators/templates/models.hbs +0 -23
  14. package/src/generators/templates/partials/acl-check-call.hbs +0 -1
  15. package/src/generators/templates/partials/casl-ability-function.hbs +0 -12
  16. package/src/generators/templates/partials/casl-ability-query.hbs +0 -1
  17. package/src/generators/templates/partials/casl-ability-type.hbs +0 -1
  18. package/src/generators/templates/partials/columns-config.hbs +0 -11
  19. package/src/generators/templates/partials/endpoint-config.hbs +0 -31
  20. package/src/generators/templates/partials/endpoint-param-parse.hbs +0 -1
  21. package/src/generators/templates/partials/endpoint-params.hbs +0 -1
  22. package/src/generators/templates/partials/import.hbs +0 -1
  23. package/src/generators/templates/partials/inputs-config.hbs +0 -10
  24. package/src/generators/templates/partials/model-js-docs.hbs +0 -6
  25. package/src/generators/templates/partials/query-js-docs.hbs +0 -31
  26. package/src/generators/templates/partials/query-keys.hbs +0 -11
  27. package/src/generators/templates/partials/query-use-infinite-query.hbs +0 -21
  28. package/src/generators/templates/partials/query-use-mutation.hbs +0 -54
  29. package/src/generators/templates/partials/query-use-query.hbs +0 -16
  30. package/src/generators/templates/queries.hbs +0 -54
  31. package/src/generators/templates/query-modules.hbs +0 -5
  32. package/src/generators/templates/zod-extended.hbs +0 -49
@@ -1,4 +1,4 @@
1
- import { a as deepMerge, p as DEFAULT_GENERATE_OPTIONS, r as writeGenerateFileData, t as generateCodeFromOpenAPIDoc, x as Profiler } from "./generateCodeFromOpenAPIDoc-BvUyx8CZ.mjs";
1
+ import { a as deepMerge, p as DEFAULT_GENERATE_OPTIONS, r as writeGenerateFileData, t as generateCodeFromOpenAPIDoc, x as Profiler } from "./generateCodeFromOpenAPIDoc-CxXf-IaZ.mjs";
2
2
  import fs from "fs";
3
3
  import path from "path";
4
4
  import SwaggerParser from "@apidevtools/swagger-parser";
@@ -3773,8 +3773,11 @@ function generateQueries(params) {
3773
3773
  const queryImport = {
3774
3774
  bindings: [
3775
3775
  ...queryEndpoints.length > 0 ? [QUERY_HOOKS.query] : [],
3776
+ ...queryEndpoints.length > 0 ? ["UseQueryResult"] : [],
3776
3777
  ...resolver.options.infiniteQueries && infiniteQueryEndpoints.length > 0 ? [QUERY_HOOKS.infiniteQuery] : [],
3777
- ...mutationEndpoints.length > 0 ? [QUERY_HOOKS.mutation] : []
3778
+ ...resolver.options.infiniteQueries && infiniteQueryEndpoints.length > 0 ? ["UseInfiniteQueryResult"] : [],
3779
+ ...mutationEndpoints.length > 0 ? [QUERY_HOOKS.mutation] : [],
3780
+ ...mutationEndpoints.length > 0 ? ["UseMutationResult"] : []
3778
3781
  ],
3779
3782
  from: QUERY_IMPORT.from
3780
3783
  };
@@ -4092,7 +4095,6 @@ function renderQuery({ resolver, endpoint, inlineEndpoints }) {
4092
4095
  mode: "query"
4093
4096
  }));
4094
4097
  lines.push(`export const ${getQueryName(endpoint)} = <TData>(${endpointParams ? `{ ${endpointArgs} }: { ${endpointParams} }, ` : ""}options?: AppQueryOptions<typeof ${importedEndpoint}, TData>${hasAxiosRequestConfig ? `, ${AXIOS_REQUEST_CONFIG_NAME}?: ${AXIOS_REQUEST_CONFIG_TYPE}` : ""}) => {`);
4095
- lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
4096
4098
  if (hasAclCheck) lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
4097
4099
  lines.push(...renderWorkspaceParamResolutions({
4098
4100
  replacements: workspaceParamReplacements,
@@ -4175,6 +4177,7 @@ function renderMutation({ resolver, endpoint, inlineEndpoints, precomputed }) {
4175
4177
  if (hasMutationFnBody) lines.push(" },");
4176
4178
  else lines.push(",");
4177
4179
  lines.push(" ...options,");
4180
+ lines.push(" onError: options?.onError ?? queryConfig.onError,");
4178
4181
  if (hasMutationEffects) {
4179
4182
  lines.push(" onSuccess: async (resData, variables, onMutateResult, context) => {");
4180
4183
  if (updateQueryEndpoints.length > 0) {
@@ -4266,6 +4269,7 @@ function renderInfiniteQuery({ resolver, endpoint, inlineEndpoints }) {
4266
4269
  lines.push(` return pageParam * limitParam < ${resolver.options.infiniteQueryResponseParamNames.totalItems} ? pageParam + 1 : null;`);
4267
4270
  lines.push(" },");
4268
4271
  lines.push(" ...options,");
4272
+ lines.push(" onError: options?.onError ?? queryConfig.onError,");
4269
4273
  lines.push(" });");
4270
4274
  lines.push("};");
4271
4275
  return lines.join("\n");
@@ -1,4 +1,4 @@
1
- import { _ as isMediaTypeAllowed, b as formatTag, c as getSchemaTsMetaType, d as getTagImportPath, f as getQueryName, h as GenerateType, i as getDataFromOpenAPIDoc, l as getTsTypeBase, m as getNamespaceName, o as isMutation, p as DEFAULT_GENERATE_OPTIONS, s as isQuery, t as generateCodeFromOpenAPIDoc, v as isParamMediaTypeAllowed, y as invalidVariableNameCharactersToCamel } from "./generateCodeFromOpenAPIDoc-BvUyx8CZ.mjs";
1
+ import { _ as isMediaTypeAllowed, b as formatTag, c as getSchemaTsMetaType, d as getTagImportPath, f as getQueryName, h as GenerateType, i as getDataFromOpenAPIDoc, l as getTsTypeBase, m as getNamespaceName, o as isMutation, p as DEFAULT_GENERATE_OPTIONS, s as isQuery, t as generateCodeFromOpenAPIDoc, v as isParamMediaTypeAllowed, y as invalidVariableNameCharactersToCamel } from "./generateCodeFromOpenAPIDoc-CxXf-IaZ.mjs";
2
2
  import SwaggerParser from "@apidevtools/swagger-parser";
3
3
 
4
4
  //#region src/generators/core/getMetadataFromOpenAPIDoc.ts
package/dist/sh.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { S as VALIDATION_ERROR_TYPE_TITLE, g as groupByType, h as GenerateType, i as getDataFromOpenAPIDoc, n as getOutputFileName, u as getTagFileName, x as Profiler } from "./generateCodeFromOpenAPIDoc-BvUyx8CZ.mjs";
3
- import { n as resolveConfig, t as runGenerate } from "./generate.runner-DZC8Pd8t.mjs";
2
+ import { S as VALIDATION_ERROR_TYPE_TITLE, g as groupByType, h as GenerateType, i as getDataFromOpenAPIDoc, n as getOutputFileName, u as getTagFileName, x as Profiler } from "./generateCodeFromOpenAPIDoc-CxXf-IaZ.mjs";
3
+ import { n as resolveConfig, t as runGenerate } from "./generate.runner-tAVdp_fl.mjs";
4
4
  import { createRequire } from "node:module";
5
5
  import yargs from "yargs";
6
6
  import { hideBin } from "yargs/helpers";
@@ -39,7 +39,7 @@ function logBanner(message) {
39
39
  * Fetch the version from package.json
40
40
  */
41
41
  function getVersion() {
42
- return "2.0.8-rc.13";
42
+ return "2.0.8-rc.15";
43
43
  }
44
44
 
45
45
  //#endregion
package/dist/vite.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { x as Profiler } from "./generateCodeFromOpenAPIDoc-BvUyx8CZ.mjs";
2
- import { t as runGenerate } from "./generate.runner-DZC8Pd8t.mjs";
1
+ import { x as Profiler } from "./generateCodeFromOpenAPIDoc-CxXf-IaZ.mjs";
2
+ import { t as runGenerate } from "./generate.runner-tAVdp_fl.mjs";
3
3
  import path from "path";
4
4
 
5
5
  //#region src/vite/openapi-codegen.plugin.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@povio/openapi-codegen-cli",
3
- "version": "2.0.8-rc.13",
3
+ "version": "2.0.8-rc.15",
4
4
  "keywords": [
5
5
  "codegen",
6
6
  "openapi",
@@ -21,8 +21,7 @@
21
21
  "files": [
22
22
  "README.md",
23
23
  "dist/*",
24
- "src/assets/**",
25
- "src/generators/templates/**"
24
+ "src/assets/**"
26
25
  ],
27
26
  "type": "module",
28
27
  "main": "./dist/index.mjs",
@@ -69,7 +68,6 @@
69
68
  },
70
69
  "dependencies": {
71
70
  "@apidevtools/swagger-parser": "^10.1.0",
72
- "handlebars": "^4.7.8",
73
71
  "i18next": "^25.8.13",
74
72
  "import-fresh": "^3.3.1",
75
73
  "prompt-sync": "^4.2.0",
@@ -1,29 +0,0 @@
1
- {{! CASL ability import }}
2
- {{{genImport abilityTupleImport}}}
3
- {{! Error handling import }}
4
- {{{genImport errorHandlingImport}}}
5
- {{! Ability context import }}
6
- {{{genImport abilityContextImport}}}
7
- import { useCallback } from "react";
8
-
9
- {{! App abilities import }}
10
- {{{genImport appAbilitiesImport}}}
11
-
12
- interface UseAclCheckProps {
13
- errorHandler?: {{errorHandler}}<never>;
14
- }
15
-
16
- export function {{aclCheckHook}}({ errorHandler }: UseAclCheckProps = {}) {
17
- const ability = {{abilityContext}}.useAbility{{#if hasGenericAppAbilities}}<{{appAbilities}}>{{/if}}();
18
-
19
- const checkAcl = useCallback(
20
- (appAbility: {{appAbilities}}) => {
21
- if (!ability.can(...(appAbility as {{abilityTuple}}))) {
22
- (errorHandler ?? {{sharedErrorHandler}}).rethrowError(new Error("ACL check failed"));
23
- }
24
- },
25
- [ability, errorHandler],
26
- );
27
-
28
- return { checkAcl };
29
- }
@@ -1,19 +0,0 @@
1
- {{! Casl AbilityTuple import}}
2
- {{{genImport caslAbilityTupleImport}}}
3
- {{! Models import }}
4
- {{#each modelsImports as | modelsImport |}}
5
- {{{genImport modelsImport}}}
6
- {{/each}}
7
-
8
- {{#if includeNamespace}}
9
- export namespace {{namespace}} {
10
- {{/if}}
11
-
12
- {{! Ability functions }}
13
- {{#each endpoints as | endpoint |}}
14
- {{{genCaslAbilityFunction endpoint}}}
15
-
16
- {{/each}}
17
- {{#if includeNamespace}}
18
- }
19
- {{/if}}
@@ -1,17 +0,0 @@
1
- {{! Casl AbilityTuple import}}
2
- {{{genImport caslAbilityTupleImport}}}
3
- {{! Models import }}
4
- {{#each modelsImports as | modelsImport |}}
5
- {{{genImport modelsImport}}}
6
- {{/each}}
7
-
8
- {{! AppAbilities union type }}
9
- export type {{appAbilities}} = {{#if appAbilitiesType}}
10
- {{#each appAbilitiesType as | appAbilityType |}}
11
- | {{../abilityTuple}}<"{{@key}}", {{{union appAbilityType}}}>
12
- {{/each}}
13
- {{else}}
14
- {{abilityTuple}}<string, {{subjectType}}>;
15
- {{/if}}
16
-
17
- export type AppAbility = PureAbility<{{appAbilities}}>;
@@ -1,7 +0,0 @@
1
- import { RestClient } from "{{restClientImportPath}}";
2
-
3
- export const {{appRestClientName}} = new RestClient({
4
- config: {
5
- baseURL: "{{baseUrl}}"
6
- },
7
- });
@@ -1,80 +0,0 @@
1
- {{! Zod import }}
2
- {{#if hasZodImport}}
3
- {{{genImport zodImport}}}
4
- {{/if}}
5
- {{! Dynamic inputs import }}
6
- {{#if hasDynamicInputsImport}}
7
- {{{genImport dynamicInputsImport}}}
8
- {{/if}}
9
- {{! Dynamic columns import }}
10
- {{#if hasDynamicColumnsImport}}
11
- {{{genImport dynamicColumnsImport}}}
12
- {{/if}}
13
- {{! Models import }}
14
- {{#each modelsImports as | modelsImport |}}
15
- {{{genImport modelsImport}}}
16
- {{/each}}
17
- {{! Queries import }}
18
- {{#each queriesImports as | queriesImport |}}
19
- {{{genImport queriesImport}}}
20
- {{/each}}
21
- {{! Acl import }}
22
- {{#each aclImports as | aclImport |}}
23
- {{{genImport aclImport}}}
24
- {{/each}}
25
-
26
- {{#if includeNamespace}}
27
- export namespace {{namespace}} {
28
- {{/if}}
29
- {{! Configs export }}
30
- {{#each configs as |config|}}
31
- export const {{config.name}} = {
32
- meta: {
33
- title: "{{{config.title}}}",
34
- },
35
- readAll: {
36
- {{#if config.readAll.acl}} acl: {{{config.readAll.acl}}},
37
- {{/if}} schema: {{{config.readAll.columns.schema}}},
38
- paginated: {{{config.readAll.paginated}}}, {{#if config.readAll.infinite}}
39
- infinite: {{{config.readAll.infinite}}},
40
- {{/if}} {{#if config.readAll.filters}} filters: {
41
- schema: {{{config.readAll.filters.schema}}},
42
- filterDefs: {{../dynamicInputs}}({{{genInputsConfig config.readAll.filters}}})
43
- },
44
- {{/if}} columns: {{../dynamicColumns}}({{{genColumnsConfig config.readAll.columns}}}),
45
- }, {{#if config.read}}
46
- read: {
47
- {{#if config.read.acl}} acl: {{{config.read.acl}}},
48
- {{/if}} schema: {{{config.read.schema}}},
49
- query: {{{config.read.query}}},
50
- },{{/if}} {{#if config.create}}
51
- create: {
52
- {{#if config.create.acl}} acl: {{{config.create.acl}}},
53
- {{/if}} {{#if config.create.inputDefs}} schema: {{{config.create.inputDefs.schema}}},
54
- {{/if}} mutation: {{{config.create.mutation}}},
55
- {{#if config.create.inputDefs}} inputDefs: {{../dynamicInputs}}({{{genInputsConfig config.create.inputDefs}}})
56
- {{/if}}
57
- },{{/if}} {{#if config.update}}
58
- update: {
59
- {{#if config.update.acl}} acl: {{{config.update.acl}}},
60
- {{/if}} {{#if config.update.inputDefs}} schema: {{{config.update.inputDefs.schema}}},
61
- {{/if}} mutation: {{{config.update.mutation}}},
62
- {{#if config.update.inputDefs}} inputDefs: {{../dynamicInputs}}({{{genInputsConfig config.update.inputDefs}}})
63
- {{/if}}
64
- },{{/if}} {{#if config.delete}}
65
- delete: {
66
- {{#if config.delete.acl}} acl: {{{config.delete.acl}}},
67
- {{/if}} mutation: {{{config.delete.mutation}}},
68
- },{{/if}} {{!-- {{#if config.bulkDelete}}
69
- bulkDelete: {
70
- {{#if config.bulkDelete.acl}} acl: {{{config.bulkDelete.acl}}},
71
- {{/if}} mutation: {{{config.bulkDelete.mutation}}},
72
- {{#if config.bulkDelete.inputDefs}} inputDefs: {{../dynamicInputs}}({{{genInputsConfig config.bulkDelete.inputDefs}}})
73
- {{/if}}
74
- },{{/if}} --}}
75
- };
76
-
77
- {{/each}}
78
- {{#if includeNamespace}}
79
- }
80
- {{/if}}
@@ -1,43 +0,0 @@
1
- {{! App rest client import}}
2
- {{{genImport appRestClientImport}}}
3
- {{! Axios import }}
4
- {{#if hasAxiosImport}}
5
- {{{genImport axiosImport}}}
6
- {{/if}}
7
- {{! Zod import }}
8
- {{#if hasZodImport}}
9
- {{{genImport zodImport}}}
10
- {{/if}}
11
- {{! Zod extended import }}
12
- {{#if hasZodExtendedImport}}
13
- {{{genImport zodExtendedImport}}}
14
- {{/if}}
15
- {{! Models import }}
16
- {{#each modelsImports as | modelsImport |}}
17
- {{{genImport modelsImport}}}
18
- {{/each}}
19
-
20
- {{#if includeNamespace}}
21
- export namespace {{namespace}} {
22
- {{/if}}
23
- {{! Endpoints export }}
24
- {{#each endpoints as | endpoint |}}
25
- export const {{endpointName endpoint}} = ({{{genEndpointParams endpoint}}}{{#if ../hasAxiosRequestConfig}}{{../axiosRequestConfigName}}?: {{../axiosRequestConfigType}}{{/if}}) => {
26
- return {{../restClientName}}.{{endpoint.method}}(
27
- {{! Response }}
28
- { resSchema: {{importedZodSchemaName endpoint.response}} },
29
- {{! Path }}
30
- `{{endpointPath endpoint}}`,
31
- {{! Body }}
32
- {{#with (endpointBody endpoint) as | endpointBody |}}
33
- {{#if endpointBody}}{{#if ../../generateParse}}{{{genEndpointParamParse endpointBody endpointBody.name}}}{{else}}{{endpointBody.name}}{{/if}}, {{/if}}
34
- {{/with}}
35
- {{#if (hasUndefinedEndpointBody endpoint)}} undefined,
36
- {{! Config }}
37
- {{/if}}{{{genEndpointConfig endpoint}}}
38
- )
39
- };
40
- {{/each}}
41
- {{#if includeNamespace}}
42
- }
43
- {{/if}}
@@ -1,23 +0,0 @@
1
- {{! Zod import}}
2
- {{{genImport zodImport}}}
3
- {{! Models import }}
4
- {{#each modelsImports as | modelsImport |}}
5
- {{{genImport modelsImport}}}
6
- {{/each}}
7
-
8
- {{#if includeNamespace}}
9
- export namespace {{namespace}} {
10
- {{/if}}
11
- {{#each zodSchemasData as | zodSchema |}}
12
- {{! Js docs }}
13
- {{{genModelJsDocs @key zodSchema ../tag}}}
14
- {{! Zod schema export }}
15
- export const {{@key}} = {{{zodSchema.code}}};
16
- {{! Zod schema infered type export }}
17
- export type {{zodInferedType @key}} = z.infer<typeof {{@key}}>;
18
- {{#if zodSchema.isEnum}}export const {{zodInferedType @key}} = {{@key}}.enum;{{/if}}
19
-
20
- {{/each}}
21
- {{#if includeNamespace}}
22
- }
23
- {{/if}}
@@ -1 +0,0 @@
1
- checkAcl({{importedAbilityFunctionName endpoint}}({{#if generateAclCheckParams}}{ {{#each (abilityConditionsTypes endpoint) as | propertyType |}}{{propertyType.name}}, {{/each}} } {{/if}}));
@@ -1,12 +0,0 @@
1
- /**
2
- * Use for {{{genCaslAbilityQuery endpoint}}} ability. {{#if (hasAbilityConditions endpoint)}}For global ability, omit the object parameter.{{/if}}{{#if (abilityDescription endpoint)}}
3
- * @description {{abilityDescription endpoint}}{{/if}}
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 { AbilityTuple } An ability tuple indicating the user's ability to use {{{genCaslAbilityQuery endpoint}}}
6
- */
7
- export const {{abilityFunctionName endpoint}} = (
8
- {{#if (hasAbilityConditions endpoint)}}object?: { {{#each (abilityConditionsTypes endpoint) as | propertyType |}}{{propertyType.name}}{{#unless propertyType.required}}?{{/unless}}: {{propertyType.type}}{{propertyType.zodSchemaName}}, {{/each}} } {{/if}}
9
- ) => [
10
- "{{ablityAction endpoint}}",
11
- {{#if (hasAbilityConditions endpoint)}}object ? subject("{{ablitySubject endpoint}}", object) : "{{ablitySubject endpoint}}"{{else}}"{{ablitySubject endpoint}}"{{/if}}
12
- ] as {{{genCaslAbilityType endpoint}}};
@@ -1 +0,0 @@
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}}
@@ -1 +0,0 @@
1
- {{abilityTuple}}<"{{ablityAction endpoint}}", {{{union (abilitySubjectTypes endpoint)}}}>
@@ -1,11 +0,0 @@
1
- {
2
- schema: {{columnsConfig.schema}},
3
- options: {
4
- columns: {
5
- {{#each columnsConfig.options.columns}}
6
- {{@key}}: true,
7
- {{/each}}
8
- }, {{#if columnsConfig.options.sortable}}
9
- sortable: {{columnsConfig.options.sortable}}, {{/if}}
10
- }
11
- }
@@ -1,31 +0,0 @@
1
- {
2
- {{! Query params}}
3
- {{#if hasAxiosRequestConfig}}
4
- ...{{axiosRequestConfigName}},
5
- {{/if}}
6
- {{#if endpointConfig.params}}
7
- params: {
8
- {{#each endpointConfig.params as | param |}}
9
- {{#if (isEqual param.name param.value) }}
10
- {{{param.name}}}{{#if ../generateParse}}: {{{genEndpointParamParse param param.name}}}{{/if}},
11
- {{else}}
12
- {{{param.name}}}: {{#if ../generateParse}}{{{genEndpointParamParse param param.value}}}{{else}}{{param.value}}{{/if}},
13
- {{/if}}
14
- {{/each}}
15
- },
16
- {{/if}}
17
- {{! Headers}}
18
- {{#if endpointConfig.headers}}
19
- headers: {
20
- {{#each endpointConfig.headers as | header |}}
21
- '{{@key}}': {{{header}}},
22
- {{/each}}
23
- },
24
- {{/if}}
25
- {{#if hasBlobResponse}}
26
- responseType: "blob",
27
- {{/if}}
28
- {{#if hasFileDownload}}
29
- rawResponse: true,
30
- {{/if}}
31
- }
@@ -1 +0,0 @@
1
- {{zodExtendedNamespace}}.{{parse}}({{#if param.parameterSortingEnumSchemaName}}{{zodExtendedNamespace}}.{{sortExp}}({{{importedZodSchemaName param.parameterSortingEnumSchemaName}}}){{#if addOptional}}.optional(){{/if}}{{else}}{{{importedZodSchemaName param.zodSchema}}}{{#if addOptional}}.optional(){{/if}}{{/if}}, {{paramName}}{{#if isQuery}}, { type: "query", name: "{{paramName}}" }{{/if}})
@@ -1 +0,0 @@
1
- {{#each (endpointParams endpoint options) as | endpointParam |}}{{endpointParam.name}}{{#unless endpointParam.required}}?{{/unless}}: {{endpointParam.type}}, {{/each}}
@@ -1 +0,0 @@
1
- import {{importNames import.bindings import.defaultImport}} from "{{import.from}}";
@@ -1,10 +0,0 @@
1
- {
2
- schema: {{inputsConfig.schema}},
3
- options: {
4
- inputs: {
5
- {{#each inputsConfig.options.inputs}}
6
- {{@key}}: true,
7
- {{/each}}
8
- }
9
- }
10
- }
@@ -1,6 +0,0 @@
1
- /**
2
- * {{name}}
3
- * @type { {{zodSchemaType zodSchema}} }{{#if (zodSchemaDescription zodSchema)}}
4
- * @description {{{zodSchemaDescription zodSchema}}}{{/if}}
5
- {{#if (zodSchemaPropertyDescriptions zodSchema tag)}}{{#each (zodSchemaPropertyDescriptions zodSchema tag) as | property |}} * @property { {{property.type}} } {{@key}} {{{addAsteriskAfterNewLine property.description}}}
6
- {{/each}}{{/if}} */
@@ -1,31 +0,0 @@
1
- {{#if infiniteQuery}}
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 excludePageParam=true) 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
- */{{else if query}}
12
- /**
13
- * Query `{{queryName endpoint}}`{{#if endpoint.summary}}{{#if endpoint.mediaDownload}} - recommended when file should be cached{{/if}}
14
- * @summary {{addAsteriskAfterNewLine endpoint.summary}}{{/if}}{{#if endpoint.description}}
15
- * @description {{addAsteriskAfterNewLine endpoint.description}}{{/if}}{{#if endpoint.acl}}
16
- * @permission Requires `{{abilityFunctionName endpoint}}` ability {{/if}}
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.mediaDownload}}AxiosResponse<{{/if}}{{{importedZodSchemaInferedType endpoint.response}}}{{#if endpoint.mediaDownload}}>{{/if}}> } {{endpoint.responseDescription}}
20
- * @statusCodes [{{commaSeparated endpoint.responseStatusCodes}}]
21
- */{{else if mutation}}
22
- /**
23
- * Mutation `{{queryName endpoint mutation=true}}`{{#if endpoint.summary}}{{#if endpoint.mediaDownload}} - 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 hasMutationEffects}} & {{mutationEffectsType}}{{/if}} } options Mutation options
29
- * @returns { UseMutationResult<{{#if endpoint.mediaDownload}}AxiosResponse<{{/if}}{{{importedZodSchemaInferedType endpoint.response}}}{{#if endpoint.mediaDownload}}>{{/if}}> } {{endpoint.responseDescription}}
30
- * @statusCodes [{{commaSeparated endpoint.responseStatusCodes}}]
31
- */{{/if}}
@@ -1,11 +0,0 @@
1
- export const keys = {
2
- all: [{{queriesModuleName}}] as const,
3
- {{#each queryEndpoints as | endpoint |}}
4
- {{endpointName endpoint}}: ({{{genEndpointParams endpoint pathParamsRequiredOnly=true}}}) => [...keys.all, "{{endpoint.path}}", {{{endpointArgs endpoint}}}] as const,
5
- {{#if ../generateInfiniteQueries}}
6
- {{#if (isInfiniteQuery endpoint)}}
7
- {{endpointName endpoint}}Infinite: ({{{genEndpointParams endpoint excludePageParam=true pathParamsRequiredOnly=true}}}) => [...keys.all, "{{endpoint.path}}", "infinite", {{{endpointArgs endpoint excludePageParam=true}}}] as const,
8
- {{/if}}
9
- {{/if}}
10
- {{/each}}
11
- };
@@ -1,21 +0,0 @@
1
- {{! Js docs }}
2
- {{{genQueryJsDocs endpoint infiniteQuery=true}}}
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}}) => {
5
- {{! Use acl check }}
6
- {{#if hasAclCheck}}const { checkAcl } = {{aclCheckHook}}();{{/if}}
7
-
8
- return {{infiniteQueryHook}}({
9
- queryKey: keys.{{endpointName endpoint}}Infinite({{#if (endpointParams endpoint)}}{{{endpointArgs endpoint excludePageParam=true}}}{{/if}}),
10
- queryFn: ({ pageParam }) => {{#if hasQueryFnBody}}{ {{/if}}
11
- {{#if hasAclCheck}}{{{genAclCheckCall endpoint}}}{{/if}}
12
- {{#if hasQueryFnBody}}return {{/if}}{{importedEndpointName endpoint}}({{{endpointArgs endpoint replacePageParam=true}}}{{#if hasAxiosRequestConfig}}, {{axiosRequestConfigName}}{{/if}})
13
- {{#if hasQueryFnBody}} }{{/if}},
14
- initialPageParam: 1,
15
- getNextPageParam: ({ {{pageParamName}}, {{totalItemsName}}, {{limitParamName}}: limitParam }) => {
16
- const pageParam = {{pageParamName}} ?? 1;
17
- return pageParam * limitParam < {{totalItemsName}} ? pageParam + 1 : null;
18
- },
19
- ...options,
20
- });
21
- };
@@ -1,54 +0,0 @@
1
- {{! Js docs }}
2
- {{{genQueryJsDocs endpoint mutation=true}}}
3
- {{! Mutation definition}}
4
- export const {{queryName endpoint mutation=true}} = (options?: AppMutationOptions<typeof {{importedEndpointName endpoint}}, { {{{genEndpointParams endpoint includeFileParam=true}}}{{#if endpoint.mediaUpload}} abortController?: AbortController, onUploadProgress?: (progress: { loaded: number; total: number }) => void{{/if}} }>{{#if hasMutationEffects}} & {{mutationEffectsType}}{{/if}}{{#if hasAxiosRequestConfig}}, {{axiosRequestConfigName}}?: {{axiosRequestConfigType}}{{/if}}) => {
5
- {{! Use acl check }}
6
- {{#if hasAclCheck}}const { checkAcl } = {{aclCheckHook}}();{{/if}}
7
- {{! Use mutation effects }}
8
- {{#if hasMutationEffects}}const { runMutationEffects } = useMutationEffects({ currentModule: {{queriesModuleName}} });{{/if}}
9
-
10
- return {{queryHook}}({
11
- mutationFn: {{#if endpoint.mediaUpload}}async {{/if}}({{#if (endpointParams endpoint includeFileParam=true)}} { {{{endpointArgs endpoint includeFileParam=true}}}{{#if endpoint.mediaUpload}}, abortController, onUploadProgress{{/if}} } {{/if}}) => {{#if hasMutationFnBody}} { {{/if}}
12
- {{#if hasAclCheck}}{{{genAclCheckCall endpoint}}}{{/if}}
13
- {{#if endpoint.mediaUpload}}const uploadInstructions = await {{importedEndpointName endpoint}}({{{endpointArgs endpoint}}}{{#if hasAxiosRequestConfig}}{{#if (endpointArgs endpoint)}}, {{/if}}{{axiosRequestConfigName}}{{/if}});
14
-
15
- if (file && uploadInstructions.url) {
16
- const method = (data?.method?.toLowerCase() ?? "put") as 'put' | 'post';
17
- let dataToSend: File | FormData = file;
18
- if (method === "post") {
19
- dataToSend = new FormData();
20
- if (uploadInstructions.fields) {
21
- for (const [key, value] of uploadInstructions.fields) {
22
- dataToSend.append(key, value);
23
- }
24
- }
25
- dataToSend.append('file', file);
26
- }
27
- await axios[method](uploadInstructions.url, dataToSend, {
28
- headers: {
29
- "Content-Type": file.type,
30
- },
31
- signal: abortController?.signal,
32
- onUploadProgress: onUploadProgress
33
- ? (progressEvent) => onUploadProgress({ loaded: progressEvent.loaded, total: progressEvent.total ?? 0 })
34
- : undefined,
35
- });
36
- }
37
-
38
- return uploadInstructions;
39
- {{else}}
40
- {{#if hasMutationFnBody}}return {{/if}}{{importedEndpointName endpoint}}({{{endpointArgs endpoint}}}{{#if hasAxiosRequestConfig}}{{#if (endpointArgs endpoint)}}, {{/if}}{{axiosRequestConfigName}}{{/if}})
41
- {{/if}}
42
- {{#if hasMutationFnBody}} }{{/if}},
43
- ...options, {{#if hasMutationEffects}}
44
- onSuccess: async (resData, variables, onMutateResult, context) => {
45
- {{! Mutation effects }}
46
- {{#if updateQueryEndpoints}}
47
- {{#if destructuredVariables}}const { {{commaSeparated destructuredVariables }} } = variables;{{/if}}
48
- const updateKeys = [{{#each updateQueryEndpoints as | endpoint |}}keys.{{endpointName endpoint}}({{{endpointArgs endpoint includeOnlyRequiredParams=true}}}), {{/each}}];
49
- {{/if}}
50
- await runMutationEffects(resData, variables, options{{#if updateQueryEndpoints}}, updateKeys{{/if}});
51
- options?.onSuccess?.(resData, variables, onMutateResult, context);
52
- },{{/if}}
53
- });
54
- };
@@ -1,16 +0,0 @@
1
- {{! Js docs }}
2
- {{{genQueryJsDocs endpoint query=true}}}
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}}) => {
5
- {{! Use acl check }}
6
- {{#if hasAclCheck}}const { checkAcl } = {{aclCheckHook}}();{{/if}}
7
-
8
- return {{queryHook}}({
9
- queryKey: keys.{{endpointName endpoint}}({{#if (endpointParams endpoint)}}{{{endpointArgs endpoint}}}{{/if}}),
10
- queryFn: {{#if hasQueryFn}}() => {{#if hasQueryFnBody}}{ {{/if}}
11
- {{#if hasAclCheck}}{{{genAclCheckCall endpoint}}}{{/if}}
12
- {{#if hasQueryFnBody}}return {{/if}}{{importedEndpointName endpoint}}({{{endpointArgs endpoint}}}{{#if hasAxiosRequestConfig}}{{#if (endpointArgs endpoint)}}, {{/if}}{{axiosRequestConfigName}}{{/if}}){{else}}{{importedEndpointName endpoint}}{{/if}}
13
- {{#if hasQueryFnBody}} }{{/if}},
14
- ...options,
15
- });
16
- };
@@ -1,54 +0,0 @@
1
- {{! Axios import }}
2
- {{#if hasAxiosImport}}
3
- {{{genImport axiosImport}}}
4
- {{/if}}
5
- {{! React query import }}
6
- {{{genImport queryImport}}}
7
- {{! Query modules import }}
8
- {{#if hasMutationEffects}}
9
- {{{genImport queryModulesImport}}}
10
- {{/if}}
11
- {{! Mutation effects import }}
12
- {{#if hasMutationEffectsImport}}
13
- {{{genImport mutationEffectsImport}}}
14
- {{/if}}
15
- {{! Acl check import }}
16
- {{#if hasAclCheck}}
17
- {{{genImport aclCheckImport}}}
18
- {{#each aclImports as | aclImport |}}
19
- {{{genImport aclImport}}}
20
- {{/each}}
21
- {{/if}}
22
- {{! React query types import }}
23
- {{{genImport queryTypesImport}}}
24
- {{! Models import }}
25
- {{#each modelsImports as | modelsImport |}}
26
- {{{genImport modelsImport}}}
27
- {{/each}}
28
- {{! Endpoints import }}
29
- {{#each endpointsImports as | endpointsImport |}}
30
- {{{genImport endpointsImport}}}
31
- {{/each}}
32
-
33
- {{#if includeNamespace}}
34
- export namespace {{namespace}} {
35
- {{/if}}
36
-
37
- export const {{queriesModuleName}} = {{#if hasMutationEffects}}{{queryModuleEnum}}.{{tag}}{{else}}"{{namespace}}"{{/if}};
38
-
39
- {{! Query keys export}}
40
- {{{genQueryKeys queryEndpoints}}}
41
-
42
- {{! Query export }}
43
- {{#each endpoints as | endpoint |}}
44
- {{{genQuery endpoint}}}
45
-
46
- {{{genMutation endpoint ../queryEndpoints}}}
47
-
48
- {{{genInfiniteQuery endpoint}}}
49
-
50
- {{/each}}
51
-
52
- {{#if includeNamespace}}
53
- }
54
- {{/if}}
@@ -1,5 +0,0 @@
1
- export const enum QueryModule {
2
- {{#each modules as | module |}}
3
- {{module.tag}} = "{{module.namespace}}",
4
- {{/each}}
5
- }
@@ -1,49 +0,0 @@
1
- {{! Zod import }}
2
- {{{genImport zodImport}}}
3
- {{! Error handling import }}
4
- {{{genImport errorHandlingImport}}}
5
-
6
- export namespace ZodExtended {
7
- interface ParseOptions {
8
- type: "body" | "query";
9
- name?: string;
10
- errorHandler?: ErrorHandler<never>;
11
- }
12
-
13
- export function {{parse}}<ZOutput, ZInput>(
14
- schema: z.ZodType<ZOutput, ZInput>,
15
- data: unknown,
16
- { type, name, errorHandler }: ParseOptions = { type: "body" },
17
- ) {
18
- try {
19
- return schema.parse(data);
20
- } catch (e) {
21
- if (e instanceof z.ZodError) {
22
- e.name = `FE Request ${type === "body" ? "body" : "query param"}${name ? ` ("${name}")` : ""} schema mismatch - ZodError`;
23
- }
24
- (errorHandler ?? {{sharedErrorHandler}}).rethrowError(e);
25
- throw e;
26
- }
27
- }
28
-
29
- function is{{capitalize sortExp}}Valid(enumSchema: z.ZodEnum, data?: string) {
30
- if (data === undefined || data === "" || enumSchema.options.length === 0) {
31
- return true;
32
- }
33
-
34
- const prefixedEnumOptions = `([+-]?(${enumSchema.options.join("|")}))`;
35
- const commaSeparatedOptions = `(${prefixedEnumOptions})(\s*,\s*${prefixedEnumOptions})*`;
36
- return new RegExp(`^${commaSeparatedOptions}$`).test(data);
37
- }
38
-
39
- export const {{sortExp}} = (enumSchema: z.ZodEnum) =>
40
- z.string().superRefine((arg, ctx) => {
41
- if (!is{{capitalize sortExp}}Valid(enumSchema, arg)) {
42
- ctx.addIssue({
43
- code: "invalid_value",
44
- message: "Invalid sorting string.",
45
- values: [],
46
- });
47
- }
48
- });
49
- }