@povio/openapi-codegen-cli 3.0.0-rc.1 → 3.0.0-rc.2

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 CHANGED
@@ -92,7 +92,10 @@ yarn openapi-codegen generate --config my-config.ts
92
92
  --axiosRequestConfig Include Axios request config parameters in query hooks (default: false)
93
93
  --infiniteQueries Generate infinite queries for paginated API endpoints (default: false)
94
94
  --mutationEffects Add mutation effects options to mutation hooks (default: true)
95
- --mutationScope Serialize mutations for the same path-param resource via TanStack scope.id (default: false)
95
+ --mutationScope Serialize mutations for the same path-param resource via TanStack scope.id (default: false).
96
+ In config files also accepts { include: string[] } or { exclude: string[] } to opt specific
97
+ operations in/out of scoping. Use "Tag/operationId" format for precision (e.g. "EmployeeSettings/update")
98
+ or just "operationId" to match across all tags. Cannot specify both include and exclude.
96
99
  --mutationDefaultOnError Use OpenApiQueryConfig.onError as the default onError for mutation hooks (default: false)
97
100
  --workspaceContext Comma-separated list of path/ACL params that generated hooks may resolve from OpenApiWorkspaceContext
98
101
  --inlineEndpoints Inline endpoint implementations into generated query files (default: false)
@@ -1,4 +1,4 @@
1
- import { t as GenerateOptions } from "./options-C6CNQ6tq.mjs";
1
+ import { t as GenerateOptions } from "./options-BPAjzilp.mjs";
2
2
 
3
3
  //#region src/generators/types/config.d.ts
4
4
  type OpenAPICodegenConfig = Partial<GenerateOptions>;
@@ -1,4 +1,4 @@
1
- import { S as Profiler, h as deepMerge, i as writeGenerateFileData, p as DEFAULT_GENERATE_OPTIONS, r as removeStaleGeneratedFiles, t as generateCodeFromOpenAPIDoc } from "./generateCodeFromOpenAPIDoc-BKIXvJIW.mjs";
1
+ import { S as Profiler, h as deepMerge, i as writeGenerateFileData, p as DEFAULT_GENERATE_OPTIONS, r as removeStaleGeneratedFiles, t as generateCodeFromOpenAPIDoc } from "./generateCodeFromOpenAPIDoc-CbBWYEZG.mjs";
2
2
  import path from "path";
3
3
  import SwaggerParser from "@apidevtools/swagger-parser";
4
4
 
@@ -4034,6 +4034,10 @@ function renderModelJsDocs({ name, zodSchema, tag, resolver }) {
4034
4034
  const endpointParamMappingCache = /* @__PURE__ */ new WeakMap();
4035
4035
  function generateQueries(params) {
4036
4036
  const { resolver, data, tag } = params;
4037
+ const mutationScopeOption = resolver.options.mutationScope;
4038
+ if (mutationScopeOption && typeof mutationScopeOption === "object") {
4039
+ if ("include" in mutationScopeOption && "exclude" in mutationScopeOption) throw new Error("mutationScope cannot specify both 'include' and 'exclude'");
4040
+ }
4037
4041
  const inlineEndpoints = shouldInlineEndpointsForTag(tag, resolver.options);
4038
4042
  const endpoints = data.get(tag)?.endpoints;
4039
4043
  if (!endpoints || endpoints.length === 0) return;
@@ -4541,6 +4545,27 @@ function renderMutation({ resolver, endpoint, inlineEndpoints, precomputed }) {
4541
4545
  const destructuredVariables = precomputed?.destructuredVariables ?? getDestructuredVariables(resolver, endpoint, updateQueryEndpoints);
4542
4546
  const hasMutationFnBody = endpoint.mediaUpload || hasAclCheck || Object.keys(workspaceParamReplacements).length > 0;
4543
4547
  const mutationVariablesType = endpoint.mediaUpload ? `${endpointParams}${endpointParams ? "; " : ""}abortController?: AbortController; onUploadProgress?: (progress: { loaded: number; total: number }) => void` : endpointParams;
4548
+ const isPost = endpoint.method === "post";
4549
+ const mutationScopeOption = resolver.options.mutationScope;
4550
+ const operationId = getEndpointName(endpoint);
4551
+ const scopeMatchKey = `${tag}/${operationId}`;
4552
+ let scopeEnabled = false;
4553
+ if (!isPost && mutationScopeOption) {
4554
+ if (mutationScopeOption === true) scopeEnabled = true;
4555
+ else if (typeof mutationScopeOption === "object" && "include" in mutationScopeOption) scopeEnabled = mutationScopeOption.include.some((id) => id === operationId || id === scopeMatchKey);
4556
+ else if (typeof mutationScopeOption === "object" && "exclude" in mutationScopeOption) scopeEnabled = !mutationScopeOption.exclude.some((id) => id === operationId || id === scopeMatchKey);
4557
+ }
4558
+ const scopePathParams = scopeEnabled ? mapEndpointParamsToFunctionParams(resolver, endpoint, {}).filter((p) => p.paramType === "Path") : [];
4559
+ const isScoped = scopePathParams.length > 0;
4560
+ const nonPathEndpointParams = isScoped ? renderEndpointParams(resolver, endpoint, {
4561
+ includeFileParam: true,
4562
+ optionalPathParams: resolver.options.workspaceContext,
4563
+ modelNamespaceTag: tag,
4564
+ excludePathParams: true
4565
+ }) : endpointParams;
4566
+ const nonPathMutationVariablesType = isScoped ? endpoint.mediaUpload ? `${nonPathEndpointParams}${nonPathEndpointParams ? "; " : ""}abortController?: AbortController; onUploadProgress?: (progress: { loaded: number; total: number }) => void` : nonPathEndpointParams : mutationVariablesType;
4567
+ const pathParamFirstArg = isScoped ? `{ ${scopePathParams.map((p) => p.name).join(", ")} }: { ${scopePathParams.map((p) => `${p.name}: ${p.type}`).join("; ")} }, ` : "";
4568
+ const mutationOptionsTypeArg = isScoped ? nonPathMutationVariablesType ? `, { ${nonPathMutationVariablesType} }` : "" : `, { ${mutationVariablesType} }`;
4544
4569
  const lines = [];
4545
4570
  lines.push(renderQueryJsDocs({
4546
4571
  resolver,
@@ -4548,7 +4573,7 @@ function renderMutation({ resolver, endpoint, inlineEndpoints, precomputed }) {
4548
4573
  mode: "mutation",
4549
4574
  tag
4550
4575
  }));
4551
- lines.push(`export const ${getQueryName(endpoint, true)} = (options?: AppMutationOptions<typeof ${endpointFunction}, { ${mutationVariablesType} }>${hasMutationEffects ? ` & ${MUTATION_EFFECTS.optionsType}` : ""}${hasAxiosRequestConfig ? `, ${AXIOS_REQUEST_CONFIG_NAME}?: ${AXIOS_REQUEST_CONFIG_TYPE}` : ""}) => {`);
4576
+ lines.push(`export const ${getQueryName(endpoint, true)} = (${pathParamFirstArg}options?: AppMutationOptions<typeof ${endpointFunction}${mutationOptionsTypeArg}>${hasMutationEffects ? ` & ${MUTATION_EFFECTS.optionsType}` : ""}${hasAxiosRequestConfig ? `, ${AXIOS_REQUEST_CONFIG_NAME}?: ${AXIOS_REQUEST_CONFIG_TYPE}` : ""}) => {`);
4552
4577
  if (hasMutationDefaultOnError) lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
4553
4578
  if (hasAclCheck) lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
4554
4579
  lines.push(...renderWorkspaceContextDestructure({
@@ -4559,7 +4584,13 @@ function renderMutation({ resolver, endpoint, inlineEndpoints, precomputed }) {
4559
4584
  if (hasMutationEffects) lines.push(` const { runMutationEffects } = useMutationEffects<typeof ${QUERY_MODULE_ENUM}.${tag}>({ currentModule: ${QUERIES_MODULE_NAME} });`);
4560
4585
  lines.push("");
4561
4586
  lines.push(` return ${QUERY_HOOKS.mutation}({`);
4562
- const mutationFnArg = endpointParams ? `{ ${destructuredMutationArgs}${endpoint.mediaUpload ? `${destructuredMutationArgs ? ", " : ""}abortController, onUploadProgress` : ""} }` : "";
4587
+ const nonPathDestructuredArgs = isScoped ? renderEndpointArgs(resolver, endpoint, {
4588
+ includeFileParam: true,
4589
+ excludePathParams: true
4590
+ }) : destructuredMutationArgs;
4591
+ const effectiveParams = isScoped ? nonPathEndpointParams : endpointParams;
4592
+ const effectiveArgs = isScoped ? nonPathDestructuredArgs : destructuredMutationArgs;
4593
+ const mutationFnArg = effectiveParams || endpoint.mediaUpload ? `{ ${effectiveArgs}${endpoint.mediaUpload ? `${effectiveArgs ? ", " : ""}abortController, onUploadProgress` : ""} }` : "";
4563
4594
  lines.push(` mutationFn: ${endpoint.mediaUpload ? "async " : ""}(${mutationFnArg}) => ${hasMutationFnBody ? "{ " : ""}`);
4564
4595
  lines.push(...renderWorkspaceParamCoalescing({
4565
4596
  replacements: workspaceParamReplacements,
@@ -4596,12 +4627,18 @@ function renderMutation({ resolver, endpoint, inlineEndpoints, precomputed }) {
4596
4627
  } else lines.push(` ${hasMutationFnBody ? "return " : ""}${endpointFunction}(${resolvedEndpointArgs}${hasAxiosRequestConfig ? `${resolvedEndpointArgs ? ", " : ""}${AXIOS_REQUEST_CONFIG_NAME}` : ""})`);
4597
4628
  if (hasMutationFnBody) lines.push(" },");
4598
4629
  else lines.push(",");
4630
+ if (isScoped) {
4631
+ const scopePathParamInterpolations = scopePathParams.map((p) => `:\${${p.name}}`).join("");
4632
+ lines.push(` scope: { id: \`${getEndpointName(endpoint)}${scopePathParamInterpolations}\` },`);
4633
+ }
4599
4634
  lines.push(" ...options,");
4600
4635
  if (hasMutationDefaultOnError) lines.push(" onError: options?.onError ?? queryConfig.onError,");
4601
4636
  if (hasMutationEffects) {
4602
4637
  lines.push(" onSuccess: async (resData, variables, onMutateResult, context) => {");
4603
4638
  if (updateQueryEndpoints.length > 0) {
4604
- if (destructuredVariables.length > 0) lines.push(` const { ${destructuredVariables.join(", ")} } = variables;`);
4639
+ const scopedPathParamNames = new Set(scopePathParams.map((p) => p.name));
4640
+ const variablesDestructure = destructuredVariables.filter((v) => !scopedPathParamNames.has(v));
4641
+ if (variablesDestructure.length > 0) lines.push(` const { ${variablesDestructure.join(", ")} } = variables;`);
4605
4642
  lines.push(...renderWorkspaceParamCoalescing({
4606
4643
  replacements: workspaceParamReplacements,
4607
4644
  indent: " "
@@ -1,4 +1,4 @@
1
- import { n as GenerateFileData, t as GenerateOptions } from "./options-C6CNQ6tq.mjs";
1
+ import { n as GenerateFileData, t as GenerateOptions } from "./options-BPAjzilp.mjs";
2
2
  import { OpenAPIV3 } from "openapi-types";
3
3
 
4
4
  //#region src/generators/types/metadata.d.ts
@@ -1,4 +1,4 @@
1
- import { _ as getNamespaceName, a as getDataFromOpenAPIDoc, b as isParamMediaTypeAllowed, c as getSchemaTsMetaType, d as getTagImportPath, f as getQueryName, g as invalidVariableNameCharactersToCamel, l as getTsTypeBase, o as isMutation, p as DEFAULT_GENERATE_OPTIONS, s as isQuery, t as generateCodeFromOpenAPIDoc, v as GenerateType, x as formatTag, y as isMediaTypeAllowed } from "./generateCodeFromOpenAPIDoc-BKIXvJIW.mjs";
1
+ import { _ as getNamespaceName, a as getDataFromOpenAPIDoc, b as isParamMediaTypeAllowed, c as getSchemaTsMetaType, d as getTagImportPath, f as getQueryName, g as invalidVariableNameCharactersToCamel, l as getTsTypeBase, o as isMutation, p as DEFAULT_GENERATE_OPTIONS, s as isQuery, t as generateCodeFromOpenAPIDoc, v as GenerateType, x as formatTag, y as isMediaTypeAllowed } from "./generateCodeFromOpenAPIDoc-CbBWYEZG.mjs";
2
2
  import SwaggerParser from "@apidevtools/swagger-parser";
3
3
 
4
4
  //#region src/generators/core/getMetadataFromOpenAPIDoc.ts
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { a as GeneralErrorCodes, i as ErrorHandlerOptions, n as ErrorEntry, o as SharedErrorHandler, r as ErrorHandler, t as ApplicationException } from "./error-handling-CvW_FecB.mjs";
2
- import "./options-C6CNQ6tq.mjs";
3
- import { t as OpenAPICodegenConfig } from "./config-CKmoJbQB.mjs";
2
+ import "./options-BPAjzilp.mjs";
3
+ import { t as OpenAPICodegenConfig } from "./config-C1ME3Ay4.mjs";
4
4
  import { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosResponseHeaders, CreateAxiosDefaults } from "axios";
5
5
  import { z } from "zod";
6
6
  import "i18next";
@@ -42,7 +42,11 @@ interface QueriesGenerateOptions {
42
42
  mutationDefaultOnError?: boolean;
43
43
  workspaceContext?: string[];
44
44
  prefetchQueries?: boolean;
45
- mutationScope?: boolean;
45
+ mutationScope?: boolean | {
46
+ include: string[];
47
+ } | {
48
+ exclude: string[];
49
+ };
46
50
  }
47
51
  interface InfiniteQueriesGenerateOptions {
48
52
  infiniteQueries?: boolean;
package/dist/sh.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { C as VALIDATION_ERROR_TYPE_TITLE, S as Profiler, a as getDataFromOpenAPIDoc, m as groupByType, n as getOutputFileName, u as getTagFileName, v as GenerateType } from "./generateCodeFromOpenAPIDoc-BKIXvJIW.mjs";
3
- import { n as resolveConfig, t as runGenerate } from "./generate.runner-B0iop_CE.mjs";
2
+ import { C as VALIDATION_ERROR_TYPE_TITLE, S as Profiler, a as getDataFromOpenAPIDoc, m as groupByType, n as getOutputFileName, u as getTagFileName, v as GenerateType } from "./generateCodeFromOpenAPIDoc-CbBWYEZG.mjs";
3
+ import { n as resolveConfig, t as runGenerate } from "./generate.runner-BsNMtOTd.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 "3.0.0-rc.1";
42
+ return "3.0.0-rc.2";
43
43
  }
44
44
 
45
45
  //#endregion
package/dist/vite.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { r as GenerateFileFormatter } from "./options-C6CNQ6tq.mjs";
2
- import { t as OpenAPICodegenConfig } from "./config-CKmoJbQB.mjs";
1
+ import { r as GenerateFileFormatter } from "./options-BPAjzilp.mjs";
2
+ import { t as OpenAPICodegenConfig } from "./config-C1ME3Ay4.mjs";
3
3
  import { Plugin } from "vite";
4
4
 
5
5
  //#region src/vite/openapi-codegen.plugin.d.ts
package/dist/vite.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { S as Profiler } from "./generateCodeFromOpenAPIDoc-BKIXvJIW.mjs";
2
- import { t as runGenerate } from "./generate.runner-B0iop_CE.mjs";
1
+ import { S as Profiler } from "./generateCodeFromOpenAPIDoc-CbBWYEZG.mjs";
2
+ import { t as runGenerate } from "./generate.runner-BsNMtOTd.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": "3.0.0-rc.1",
3
+ "version": "3.0.0-rc.2",
4
4
  "keywords": [
5
5
  "codegen",
6
6
  "openapi",