@povio/openapi-codegen-cli 2.0.8-rc.23 → 2.0.8-rc.24

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.
@@ -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-vrPucfhY.mjs";
1
+ import { a as deepMerge, p as DEFAULT_GENERATE_OPTIONS, r as writeGenerateFileData, t as generateCodeFromOpenAPIDoc, x as Profiler } from "./generateCodeFromOpenAPIDoc-DYOqSvuQ.mjs";
2
2
  import fs from "fs";
3
3
  import path from "path";
4
4
  import SwaggerParser from "@apidevtools/swagger-parser";
@@ -3206,42 +3206,55 @@ function getBuilderConfigs({ data, tag, resolver }) {
3206
3206
  if (createEndpoint) {
3207
3207
  importedEndpoints.push(createEndpoint);
3208
3208
  const body = getEndpointBody$1(createEndpoint);
3209
- if (body) importedZodSchemas.push(body.zodSchema);
3210
- config.create = {
3211
- acl: getAclConfig(createEndpoint, resolver.options),
3212
- mutation: getImportedQueryName(createEndpoint, resolver.options),
3213
- inputDefs: getInputsConfig(resolver, body)
3214
- };
3209
+ if (body) {
3210
+ importedZodSchemas.push(body.zodSchema);
3211
+ config.create = {
3212
+ acl: getAclConfig(createEndpoint, resolver.options),
3213
+ schema: getImportedZodSchemaName(resolver, body.zodSchema),
3214
+ mutation: createEndpoint,
3215
+ inputDefs: getInputsConfig(resolver, body)
3216
+ };
3217
+ }
3215
3218
  }
3216
3219
  const updateEndpoint = extendedEndpoints.find((endpoint) => isUpdateEndpoint(endpoint, readAllEndpoint));
3217
3220
  if (updateEndpoint) {
3218
3221
  importedEndpoints.push(updateEndpoint);
3219
3222
  const body = getEndpointBody$1(updateEndpoint);
3220
- if (body) importedZodSchemas.push(body.zodSchema);
3221
- config.update = {
3222
- acl: getAclConfig(updateEndpoint, resolver.options),
3223
- mutation: getImportedQueryName(updateEndpoint, resolver.options),
3224
- inputDefs: getInputsConfig(resolver, body)
3225
- };
3223
+ if (body) {
3224
+ importedZodSchemas.push(body.zodSchema);
3225
+ config.update = {
3226
+ acl: getAclConfig(updateEndpoint, resolver.options),
3227
+ schema: getImportedZodSchemaName(resolver, body.zodSchema),
3228
+ mutation: updateEndpoint,
3229
+ inputDefs: getInputsConfig(resolver, body)
3230
+ };
3231
+ }
3226
3232
  }
3227
3233
  const deleteEndpoint = extendedEndpoints.find((endpoint) => isDeleteEndpoint(endpoint, readAllEndpoint));
3228
3234
  if (deleteEndpoint) {
3229
3235
  importedEndpoints.push(deleteEndpoint);
3230
- config.delete = {
3231
- acl: getAclConfig(deleteEndpoint, resolver.options),
3232
- mutation: getImportedQueryName(deleteEndpoint, resolver.options)
3233
- };
3236
+ const body = getEndpointBody$1(deleteEndpoint);
3237
+ if (body) {
3238
+ importedZodSchemas.push(body.zodSchema);
3239
+ config.delete = {
3240
+ acl: getAclConfig(deleteEndpoint, resolver.options),
3241
+ mutation: deleteEndpoint
3242
+ };
3243
+ }
3234
3244
  }
3235
3245
  const bulkDeleteEndpoint = extendedEndpoints.find((endpoint) => isBulkDeleteEndpoint(endpoint, readAllEndpoint));
3236
3246
  if (bulkDeleteEndpoint) {
3237
3247
  importedEndpoints.push(bulkDeleteEndpoint);
3238
3248
  const body = getEndpointBody$1(bulkDeleteEndpoint);
3239
- if (body) importedZodSchemas.push(body.zodSchema);
3240
- config.bulkDelete = {
3241
- acl: getAclConfig(bulkDeleteEndpoint, resolver.options),
3242
- mutation: getImportedQueryName(bulkDeleteEndpoint, resolver.options),
3243
- inputDefs: getInputsConfig(resolver, body)
3244
- };
3249
+ if (body) {
3250
+ importedZodSchemas.push(body.zodSchema);
3251
+ config.bulkDelete = {
3252
+ acl: getAclConfig(bulkDeleteEndpoint, resolver.options),
3253
+ schema: getImportedZodSchemaName(resolver, body.zodSchema),
3254
+ mutation: bulkDeleteEndpoint,
3255
+ inputDefs: getInputsConfig(resolver, body)
3256
+ };
3257
+ }
3245
3258
  }
3246
3259
  return config;
3247
3260
  });
@@ -3359,12 +3372,70 @@ function getSchemaProperties(resolver, schema) {
3359
3372
  return {};
3360
3373
  }
3361
3374
 
3375
+ //#endregion
3376
+ //#region src/generators/const/queries.const.ts
3377
+ const QUERY_HOOKS = {
3378
+ query: "useQuery",
3379
+ infiniteQuery: "useInfiniteQuery",
3380
+ mutation: "useMutation"
3381
+ };
3382
+ const QUERY_IMPORT = {
3383
+ bindings: [
3384
+ QUERY_HOOKS.query,
3385
+ QUERY_HOOKS.infiniteQuery,
3386
+ QUERY_HOOKS.mutation
3387
+ ],
3388
+ from: "@tanstack/react-query"
3389
+ };
3390
+ const QUERIES_MODULE_NAME = "moduleName";
3391
+
3362
3392
  //#endregion
3363
3393
  //#region src/generators/generate/generateConfigs.ts
3364
3394
  function generateConfigs(generateTypeParams) {
3365
- const { configs, hasZodImport, modelsImports, queriesImports, aclImports } = getBuilderConfigs(generateTypeParams);
3395
+ const { configs, hasZodImport, modelsImports, aclImports } = getBuilderConfigs(generateTypeParams);
3366
3396
  if (configs.length === 0) return;
3367
3397
  const { resolver, tag } = generateTypeParams;
3398
+ const endpoints = configs.flatMap((config) => [
3399
+ config.create?.mutation,
3400
+ config.update?.mutation,
3401
+ config.delete?.mutation,
3402
+ config.bulkDelete?.mutation
3403
+ ]).filter((m) => typeof m !== "string" && m !== void 0);
3404
+ const hasMutation = endpoints.length > 0;
3405
+ resolver.options.checkAcl && endpoints.some((e) => e.acl);
3406
+ const hasMutationEffects = resolver.options.mutationEffects && hasMutation;
3407
+ const hasWorkspaceContext = resolver.options.workspaceContext && endpoints.some((e) => resolver.options.workspaceContext);
3408
+ const endpointsImports = getEndpointsImports({
3409
+ tag,
3410
+ endpoints,
3411
+ options: resolver.options
3412
+ });
3413
+ const queryImport = {
3414
+ bindings: [QUERY_HOOKS.mutation],
3415
+ from: "@tanstack/react-query"
3416
+ };
3417
+ const queryTypesImport = {
3418
+ bindings: ["OpenApiQueryConfig"],
3419
+ typeBindings: [QUERY_OPTIONS_TYPES.mutation],
3420
+ from: getQueryTypesImportPath(resolver.options)
3421
+ };
3422
+ const mutationEffectsImport = {
3423
+ bindings: [MUTATION_EFFECTS.hookName],
3424
+ typeBindings: [MUTATION_EFFECTS.optionsType],
3425
+ from: PACKAGE_IMPORT_PATH
3426
+ };
3427
+ const queryModulesImport = {
3428
+ bindings: [QUERY_MODULE_ENUM],
3429
+ from: getQueryModulesImportPath(resolver.options)
3430
+ };
3431
+ const aclCheckImport = {
3432
+ bindings: [ACL_CHECK_HOOK],
3433
+ from: ACL_PACKAGE_IMPORT_PATH
3434
+ };
3435
+ const workspaceContextImport = {
3436
+ bindings: ["OpenApiWorkspaceContext"],
3437
+ from: PACKAGE_IMPORT_PATH
3438
+ };
3368
3439
  const hasDynamicInputsImport = configs.some((config) => config.readAll.filters || config.create?.inputDefs || config.update?.inputDefs);
3369
3440
  const dynamicInputsImport = {
3370
3441
  bindings: [BUILDERS_UTILS.dynamicInputs],
@@ -3380,7 +3451,17 @@ function generateConfigs(generateTypeParams) {
3380
3451
  if (hasDynamicInputsImport) lines.push(renderImport$3(dynamicInputsImport));
3381
3452
  if (hasDynamicColumnsImport) lines.push(renderImport$3(dynamicColumnsImport));
3382
3453
  for (const modelsImport of modelsImports) lines.push(renderImport$3(modelsImport));
3383
- for (const queriesImport of queriesImports) lines.push(renderImport$3(queriesImport));
3454
+ for (const endpointsImport of endpointsImports) lines.push(renderImport$3(endpointsImport));
3455
+ if (hasMutation) {
3456
+ lines.push(renderImport$3(queryImport));
3457
+ lines.push(renderImport$3(queryTypesImport));
3458
+ if (hasMutationEffects) {
3459
+ lines.push(renderImport$3(queryModulesImport));
3460
+ lines.push(renderImport$3(mutationEffectsImport));
3461
+ }
3462
+ lines.push(renderImport$3(aclCheckImport));
3463
+ if (hasWorkspaceContext) lines.push(renderImport$3(workspaceContextImport));
3464
+ }
3384
3465
  for (const aclImport of aclImports) lines.push(renderImport$3(aclImport));
3385
3466
  lines.push("");
3386
3467
  if (resolver.options.tsNamespaces) lines.push(`export namespace ${getNamespaceName({
@@ -3389,7 +3470,7 @@ function generateConfigs(generateTypeParams) {
3389
3470
  options: resolver.options
3390
3471
  })} {`);
3391
3472
  for (const config of configs) {
3392
- lines.push(renderBuilderConfig(config));
3473
+ lines.push(renderBuilderConfig(config, generateTypeParams));
3393
3474
  lines.push("");
3394
3475
  }
3395
3476
  if (resolver.options.tsNamespaces) lines.push("}");
@@ -3425,7 +3506,48 @@ function renderColumnsConfig(columnsConfig) {
3425
3506
  lines.push("}");
3426
3507
  return lines.join("\n");
3427
3508
  }
3428
- function renderBuilderConfig(config) {
3509
+ function renderMutationContent(resolver, endpoint, tag) {
3510
+ const hasAclCheck = resolver.options.checkAcl && endpoint.acl;
3511
+ const hasMutationEffects = resolver.options.mutationEffects;
3512
+ const hasAxiosRequestConfig = resolver.options.axiosRequestConfig;
3513
+ const endpointTag = getEndpointTag(endpoint, resolver.options);
3514
+ const endpointParams = mapEndpointParamsToFunctionParams(resolver, endpoint, {
3515
+ includeFileParam: true,
3516
+ modelNamespaceTag: endpointTag
3517
+ });
3518
+ const endpointParamsStr = endpointParams.map((p) => `${p.name}${p.required ? "" : "?"}: ${p.type}`).join("; ");
3519
+ const destructuredMutationArgs = endpointParams.map((p) => p.name).join(", ");
3520
+ const endpointFunction = getImportedEndpointName(endpoint, resolver.options);
3521
+ const mutationVariablesType = endpoint.mediaUpload ? `{ ${endpointParamsStr}${endpointParamsStr ? "; " : ""}abortController?: AbortController; onUploadProgress?: (progress: { loaded: number; total: number }) => void }` : `{ ${endpointParamsStr} }`;
3522
+ const lines = [];
3523
+ lines.push(`(options?: AppMutationOptions<typeof ${endpointFunction}, ${mutationVariablesType}>${hasAxiosRequestConfig ? `, config?: AxiosRequestConfig` : ""}) => {`);
3524
+ lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
3525
+ if (hasMutationEffects) lines.push(` const { runMutationEffects } = useMutationEffects<typeof ${QUERY_MODULE_ENUM}.${endpointTag}>({ currentModule: ${QUERY_MODULE_ENUM}.${tag} });`);
3526
+ lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
3527
+ lines.push("");
3528
+ lines.push(` return ${QUERY_HOOKS.mutation}({`);
3529
+ const mutationFnArg = destructuredMutationArgs ? `{ ${destructuredMutationArgs}${endpoint.mediaUpload ? `${destructuredMutationArgs ? ", " : ""}abortController, onUploadProgress` : ""} }` : "";
3530
+ lines.push(` mutationFn: (${mutationFnArg}) => {`);
3531
+ if (hasAclCheck) lines.push(` checkAcl(${getNamespaceName({
3532
+ type: GenerateType.Acl,
3533
+ tag: endpointTag,
3534
+ options: resolver.options
3535
+ })}.canUse${capitalize(snakeToCamel(endpoint.operationName))}({ ${destructuredMutationArgs} }));`);
3536
+ lines.push(` return ${endpointFunction}(${destructuredMutationArgs}${hasAxiosRequestConfig ? `${destructuredMutationArgs ? ", " : ""}config` : ""});`);
3537
+ lines.push(" },");
3538
+ if (hasMutationEffects) {
3539
+ lines.push(" onSuccess: async (...args) => {");
3540
+ lines.push(" await runMutationEffects();");
3541
+ lines.push(" await options?.onSuccess?.(...args);");
3542
+ lines.push(" },");
3543
+ }
3544
+ lines.push(" ...options,");
3545
+ lines.push(" });");
3546
+ lines.push("}");
3547
+ return lines.map((line) => " " + line).join("\n").trimStart();
3548
+ }
3549
+ function renderBuilderConfig(config, params) {
3550
+ const { resolver, tag } = params;
3429
3551
  const lines = [];
3430
3552
  lines.push(`export const ${config.name} = {`);
3431
3553
  lines.push(" meta: {");
@@ -3454,23 +3576,31 @@ function renderBuilderConfig(config) {
3454
3576
  if (config.create) {
3455
3577
  lines.push(" create: {");
3456
3578
  if (config.create.acl) lines.push(` acl: ${config.create.acl},`);
3457
- if (config.create.inputDefs) lines.push(` schema: ${config.create.inputDefs.schema},`);
3458
- lines.push(` mutation: ${config.create.mutation},`);
3579
+ if (config.create.schema) lines.push(` schema: ${config.create.schema},`);
3580
+ lines.push(` mutation: ${typeof config.create.mutation === "string" ? config.create.mutation : renderMutationContent(resolver, config.create.mutation, tag)},`);
3459
3581
  if (config.create.inputDefs) lines.push(` inputDefs: ${BUILDERS_UTILS.dynamicInputs}(${renderInputsConfig(config.create.inputDefs)})`);
3460
3582
  lines.push(" },");
3461
3583
  }
3462
3584
  if (config.update) {
3463
3585
  lines.push(" update: {");
3464
3586
  if (config.update.acl) lines.push(` acl: ${config.update.acl},`);
3465
- if (config.update.inputDefs) lines.push(` schema: ${config.update.inputDefs.schema},`);
3466
- lines.push(` mutation: ${config.update.mutation},`);
3587
+ if (config.update.schema) lines.push(` schema: ${config.update.schema},`);
3588
+ lines.push(` mutation: ${typeof config.update.mutation === "string" ? config.update.mutation : renderMutationContent(resolver, config.update.mutation, tag)},`);
3467
3589
  if (config.update.inputDefs) lines.push(` inputDefs: ${BUILDERS_UTILS.dynamicInputs}(${renderInputsConfig(config.update.inputDefs)})`);
3468
3590
  lines.push(" },");
3469
3591
  }
3470
3592
  if (config.delete) {
3471
3593
  lines.push(" delete: {");
3472
3594
  if (config.delete.acl) lines.push(` acl: ${config.delete.acl},`);
3473
- lines.push(` mutation: ${config.delete.mutation},`);
3595
+ lines.push(` mutation: ${typeof config.delete.mutation === "string" ? config.delete.mutation : renderMutationContent(resolver, config.delete.mutation, tag)},`);
3596
+ lines.push(" },");
3597
+ }
3598
+ if (config.bulkDelete) {
3599
+ lines.push(" bulkDelete: {");
3600
+ if (config.bulkDelete.acl) lines.push(` acl: ${config.bulkDelete.acl},`);
3601
+ if (config.bulkDelete.schema) lines.push(` schema: ${config.bulkDelete.schema},`);
3602
+ lines.push(` mutation: ${typeof config.bulkDelete.mutation === "string" ? config.bulkDelete.mutation : renderMutationContent(resolver, config.bulkDelete.mutation, tag)},`);
3603
+ if (config.bulkDelete.inputDefs) lines.push(` inputDefs: ${BUILDERS_UTILS.dynamicInputs}(${renderInputsConfig(config.bulkDelete.inputDefs)})`);
3474
3604
  lines.push(" },");
3475
3605
  }
3476
3606
  lines.push("};");
@@ -3725,23 +3855,6 @@ function renderModelJsDocs({ name, zodSchema, tag, resolver }) {
3725
3855
  return lines.join("\n");
3726
3856
  }
3727
3857
 
3728
- //#endregion
3729
- //#region src/generators/const/queries.const.ts
3730
- const QUERY_HOOKS = {
3731
- query: "useQuery",
3732
- infiniteQuery: "useInfiniteQuery",
3733
- mutation: "useMutation"
3734
- };
3735
- const QUERY_IMPORT = {
3736
- bindings: [
3737
- QUERY_HOOKS.query,
3738
- QUERY_HOOKS.infiniteQuery,
3739
- QUERY_HOOKS.mutation
3740
- ],
3741
- from: "@tanstack/react-query"
3742
- };
3743
- const QUERIES_MODULE_NAME = "moduleName";
3744
-
3745
3858
  //#endregion
3746
3859
  //#region src/generators/generate/generateQueries.ts
3747
3860
  const endpointParamMappingCache = /* @__PURE__ */ new WeakMap();
@@ -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-vrPucfhY.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-DYOqSvuQ.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-vrPucfhY.mjs";
3
- import { n as resolveConfig, t as runGenerate } from "./generate.runner-DKpRoYsX.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-DYOqSvuQ.mjs";
3
+ import { n as resolveConfig, t as runGenerate } from "./generate.runner-DRRxZ7ZJ.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.23";
42
+ return "2.0.8-rc.24";
43
43
  }
44
44
 
45
45
  //#endregion
package/dist/vite.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { x as Profiler } from "./generateCodeFromOpenAPIDoc-vrPucfhY.mjs";
2
- import { t as runGenerate } from "./generate.runner-DKpRoYsX.mjs";
1
+ import { x as Profiler } from "./generateCodeFromOpenAPIDoc-DYOqSvuQ.mjs";
2
+ import { t as runGenerate } from "./generate.runner-DRRxZ7ZJ.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.23",
3
+ "version": "2.0.8-rc.24",
4
4
  "keywords": [
5
5
  "codegen",
6
6
  "openapi",