@povio/openapi-codegen-cli 2.0.8-rc.36 → 2.0.8-rc.37

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 { S as Profiler, i as writeGenerateFileData, m as DEFAULT_GENERATE_OPTIONS, o as deepMerge, r as removeStaleGeneratedFiles, t as generateCodeFromOpenAPIDoc } from "./generateCodeFromOpenAPIDoc-WP1lRhb0.mjs";
1
+ import { S as Profiler, i as writeGenerateFileData, m as DEFAULT_GENERATE_OPTIONS, o as deepMerge, r as removeStaleGeneratedFiles, t as generateCodeFromOpenAPIDoc } from "./generateCodeFromOpenAPIDoc-CFbiHxB7.mjs";
2
2
  import path from "path";
3
3
  import SwaggerParser from "@apidevtools/swagger-parser";
4
4
 
@@ -3979,7 +3979,7 @@ function generateQueries(params) {
3979
3979
  };
3980
3980
  const hasWorkspaceContext = resolver.options.workspaceContext && endpoints.some((endpoint) => getWorkspaceParamNames(resolver, endpoint).length > 0);
3981
3981
  const workspaceContextImport = {
3982
- bindings: ["OpenApiWorkspaceContext"],
3982
+ bindings: ["useWorkspaceContext"],
3983
3983
  from: PACKAGE_IMPORT_PATH
3984
3984
  };
3985
3985
  const endpointParams = endpoints.flatMap((endpoint) => endpoint.parameters);
@@ -4174,15 +4174,40 @@ function getWorkspaceParamNames(resolver, endpoint) {
4174
4174
  return getUniqueArray([...workspaceParamNames, ...aclParamNames]).filter((name) => allowList.has(name));
4175
4175
  }
4176
4176
  function getWorkspaceParamReplacements(resolver, endpoint) {
4177
- return Object.fromEntries(getWorkspaceParamNames(resolver, endpoint).map((name) => [name, `${name}FromWorkspace`]));
4177
+ return Object.fromEntries(getWorkspaceParamNames(resolver, endpoint).map((name) => [name, `normalize${capitalize(name)}`]));
4178
+ }
4179
+ function getWorkspaceParamTypes(resolver, endpoint, modelNamespaceTag) {
4180
+ const workspaceParamNames = new Set(getWorkspaceParamNames(resolver, endpoint));
4181
+ return Object.fromEntries(getEndpointParamMapping(resolver, endpoint, { modelNamespaceTag }).filter((param) => workspaceParamNames.has(param.name)).map((param) => [param.name, param.type]));
4178
4182
  }
4179
- function renderWorkspaceParamResolutions({ replacements, indent }) {
4183
+ function renderWorkspaceContextDestructure({ replacements, paramTypes, indent }) {
4180
4184
  const workspaceParamNames = Object.keys(replacements);
4181
4185
  if (workspaceParamNames.length === 0) return [];
4182
- const lines = [`${indent}const workspaceContext = OpenApiWorkspaceContext.useContext();`];
4183
- for (const paramName of workspaceParamNames) lines.push(`${indent}const ${replacements[paramName]} = OpenApiWorkspaceContext.resolveParam(workspaceContext, "${paramName}", ${paramName});`);
4186
+ const workspaceParamBindings = workspaceParamNames.map((paramName) => `${paramName}: ${paramName}Workspace`);
4187
+ const workspaceContextType = workspaceParamNames.map((paramName) => `${paramName}?: ${paramTypes[paramName] ?? "unknown"}`).join("; ");
4188
+ return [`${indent}const { ${workspaceParamBindings.join(", ")} } = useWorkspaceContext<{ ${workspaceContextType} }>();`];
4189
+ }
4190
+ function renderWorkspaceParamCoalescing({ replacements, indent }) {
4191
+ const workspaceParamNames = Object.keys(replacements);
4192
+ const lines = [];
4193
+ for (const paramName of workspaceParamNames) {
4194
+ lines.push(`${indent}const ${replacements[paramName]} = ${paramName} ?? ${paramName}Workspace;`);
4195
+ lines.push(`${indent}if (!${replacements[paramName]}) {`);
4196
+ lines.push(`${indent} throw Error(\`${capitalize(paramName)} not provided\`);`);
4197
+ lines.push(`${indent}}`);
4198
+ }
4184
4199
  return lines;
4185
4200
  }
4201
+ function renderWorkspaceParamResolutions({ replacements, paramTypes, indent }) {
4202
+ return [...renderWorkspaceContextDestructure({
4203
+ replacements,
4204
+ paramTypes,
4205
+ indent
4206
+ }), ...renderWorkspaceParamCoalescing({
4207
+ replacements,
4208
+ indent
4209
+ })];
4210
+ }
4186
4211
  function renderAclCheckCall(resolver, endpoint, replacements, indent = "") {
4187
4212
  const checkParams = getAbilityConditionsTypes(endpoint)?.map((condition) => invalidVariableNameCharactersToCamel(condition.name));
4188
4213
  const paramNames = new Set(endpoint.parameters.map((param) => invalidVariableNameCharactersToCamel(param.name)));
@@ -4352,6 +4377,7 @@ function renderQuery({ resolver, endpoint, inlineEndpoints }) {
4352
4377
  const hasAclCheck = resolver.options.checkAcl && endpoint.acl;
4353
4378
  const tag = getEndpointTag(endpoint, resolver.options);
4354
4379
  const workspaceParamReplacements = resolver.options.workspaceContext ? getWorkspaceParamReplacements(resolver, endpoint) : {};
4380
+ const workspaceParamTypes = getWorkspaceParamTypes(resolver, endpoint, tag);
4355
4381
  const endpointArgs = renderEndpointArgs(resolver, endpoint, {});
4356
4382
  const resolvedEndpointArgs = renderEndpointObjectArgs(resolver, endpoint, {}, workspaceParamReplacements);
4357
4383
  const endpointParams = renderEndpointParams(resolver, endpoint, {
@@ -4372,6 +4398,7 @@ function renderQuery({ resolver, endpoint, inlineEndpoints }) {
4372
4398
  if (hasAclCheck) lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
4373
4399
  lines.push(...renderWorkspaceParamResolutions({
4374
4400
  replacements: workspaceParamReplacements,
4401
+ paramTypes: workspaceParamTypes,
4375
4402
  indent: " "
4376
4403
  }));
4377
4404
  lines.push(" ");
@@ -4395,6 +4422,7 @@ function renderMutation({ resolver, endpoint, inlineEndpoints, precomputed }) {
4395
4422
  const hasAxiosRequestConfig = resolver.options.axiosRequestConfig;
4396
4423
  const tag = getEndpointTag(endpoint, resolver.options);
4397
4424
  const workspaceParamReplacements = resolver.options.workspaceContext ? getWorkspaceParamReplacements(resolver, endpoint) : {};
4425
+ const workspaceParamTypes = getWorkspaceParamTypes(resolver, endpoint, tag);
4398
4426
  const endpointParams = renderEndpointParams(resolver, endpoint, {
4399
4427
  includeFileParam: true,
4400
4428
  optionalPathParams: resolver.options.workspaceContext,
@@ -4417,13 +4445,20 @@ function renderMutation({ resolver, endpoint, inlineEndpoints, precomputed }) {
4417
4445
  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}` : ""}) => {`);
4418
4446
  if (hasMutationDefaultOnError) lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
4419
4447
  if (hasAclCheck) lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
4420
- if (Object.keys(workspaceParamReplacements).length > 0) lines.push(" const workspaceContext = OpenApiWorkspaceContext.useContext();");
4448
+ lines.push(...renderWorkspaceContextDestructure({
4449
+ replacements: workspaceParamReplacements,
4450
+ paramTypes: workspaceParamTypes,
4451
+ indent: " "
4452
+ }));
4421
4453
  if (hasMutationEffects) lines.push(` const { runMutationEffects } = useMutationEffects<typeof ${QUERY_MODULE_ENUM}.${tag}>({ currentModule: ${QUERIES_MODULE_NAME} });`);
4422
4454
  lines.push("");
4423
4455
  lines.push(` return ${QUERY_HOOKS.mutation}({`);
4424
4456
  const mutationFnArg = endpointParams ? `{ ${destructuredMutationArgs}${endpoint.mediaUpload ? `${destructuredMutationArgs ? ", " : ""}abortController, onUploadProgress` : ""} }` : "";
4425
4457
  lines.push(` mutationFn: ${endpoint.mediaUpload ? "async " : ""}(${mutationFnArg}) => ${hasMutationFnBody ? "{ " : ""}`);
4426
- for (const [paramName, resolvedParamName] of Object.entries(workspaceParamReplacements)) lines.push(` const ${resolvedParamName} = OpenApiWorkspaceContext.resolveParam(workspaceContext, "${paramName}", ${paramName});`);
4458
+ lines.push(...renderWorkspaceParamCoalescing({
4459
+ replacements: workspaceParamReplacements,
4460
+ indent: " "
4461
+ }));
4427
4462
  if (hasAclCheck) lines.push(renderAclCheckCall(resolver, endpoint, workspaceParamReplacements, " "));
4428
4463
  if (endpoint.mediaUpload) {
4429
4464
  lines.push(` const uploadInstructions = await ${endpointFunction}(${resolvedEndpointArgs}${hasAxiosRequestConfig ? `${resolvedEndpointArgs ? ", " : ""}${AXIOS_REQUEST_CONFIG_NAME}` : ""});`);
@@ -4461,7 +4496,10 @@ function renderMutation({ resolver, endpoint, inlineEndpoints, precomputed }) {
4461
4496
  lines.push(" onSuccess: async (resData, variables, onMutateResult, context) => {");
4462
4497
  if (updateQueryEndpoints.length > 0) {
4463
4498
  if (destructuredVariables.length > 0) lines.push(` const { ${destructuredVariables.join(", ")} } = variables;`);
4464
- for (const [paramName, resolvedParamName] of Object.entries(workspaceParamReplacements)) lines.push(` const ${resolvedParamName} = OpenApiWorkspaceContext.resolveParam(workspaceContext, "${paramName}", ${paramName});`);
4499
+ lines.push(...renderWorkspaceParamCoalescing({
4500
+ replacements: workspaceParamReplacements,
4501
+ indent: " "
4502
+ }));
4465
4503
  lines.push(` const updateKeys = [${updateQueryEndpoints.map((e) => `keys.${getEndpointName(e)}(${renderEndpointArgs(resolver, e, { includeOnlyRequiredParams: true }, workspaceParamReplacements)})`).join(", ")}];`);
4466
4504
  lines.push(` await runMutationEffects(resData, variables, options, updateKeys);`);
4467
4505
  } else lines.push(" await runMutationEffects(resData, variables, options);");
@@ -4514,6 +4552,7 @@ function renderInfiniteQuery({ resolver, endpoint, inlineEndpoints }) {
4514
4552
  const hasAxiosRequestConfig = resolver.options.axiosRequestConfig;
4515
4553
  const tag = getEndpointTag(endpoint, resolver.options);
4516
4554
  const workspaceParamReplacements = resolver.options.workspaceContext ? getWorkspaceParamReplacements(resolver, endpoint) : {};
4555
+ const workspaceParamTypes = getWorkspaceParamTypes(resolver, endpoint, tag);
4517
4556
  const endpointParams = renderEndpointParams(resolver, endpoint, {
4518
4557
  excludePageParam: true,
4519
4558
  optionalPathParams: resolver.options.workspaceContext,
@@ -4535,6 +4574,7 @@ function renderInfiniteQuery({ resolver, endpoint, inlineEndpoints }) {
4535
4574
  if (hasAclCheck) lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
4536
4575
  lines.push(...renderWorkspaceParamResolutions({
4537
4576
  replacements: workspaceParamReplacements,
4577
+ paramTypes: workspaceParamTypes,
4538
4578
  indent: " "
4539
4579
  }));
4540
4580
  lines.push("");
@@ -1,4 +1,4 @@
1
- import { a as getDataFromOpenAPIDoc, b as invalidVariableNameCharactersToCamel, c as isQuery, f as getTagImportPath, g as GenerateType, h as getNamespaceName, l as getSchemaTsMetaType, m as DEFAULT_GENERATE_OPTIONS, p as getQueryName, s as isMutation, t as generateCodeFromOpenAPIDoc, u as getTsTypeBase, v as isMediaTypeAllowed, x as formatTag, y as isParamMediaTypeAllowed } from "./generateCodeFromOpenAPIDoc-WP1lRhb0.mjs";
1
+ import { a as getDataFromOpenAPIDoc, b as invalidVariableNameCharactersToCamel, c as isQuery, f as getTagImportPath, g as GenerateType, h as getNamespaceName, l as getSchemaTsMetaType, m as DEFAULT_GENERATE_OPTIONS, p as getQueryName, s as isMutation, t as generateCodeFromOpenAPIDoc, u as getTsTypeBase, v as isMediaTypeAllowed, x as formatTag, y as isParamMediaTypeAllowed } from "./generateCodeFromOpenAPIDoc-CFbiHxB7.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
@@ -145,9 +145,10 @@ declare namespace OpenApiWorkspaceContext {
145
145
  values,
146
146
  children
147
147
  }: PropsWithChildren<WorkspaceProviderProps>) => react_jsx_runtime0.JSX.Element;
148
- const useContext: () => WorkspaceValues;
148
+ const useContext: <TValues extends WorkspaceValues = WorkspaceValues>() => TValues;
149
149
  const resolveParam: <T>(context: WorkspaceValues, name: string, value: T | null | undefined) => T;
150
150
  }
151
+ declare const useWorkspaceContext: <TValues extends WorkspaceValues = WorkspaceValues>() => TValues;
151
152
  //#endregion
152
153
  //#region src/lib/config/i18n.d.ts
153
154
  declare const ns = "openapi";
@@ -227,4 +228,4 @@ declare const AuthGuard: ({
227
228
  children
228
229
  }: PropsWithChildren<AuthGuardProps>) => react.ReactNode;
229
230
  //#endregion
230
- export { type AppInfiniteQueryOptions, type AppMutationOptions, type AppQueryOptions, ApplicationException, AuthContext, AuthGuard, type AuthGuardProps, type ErrorEntry, ErrorHandler, type ErrorHandlerOptions, type GeneralErrorCodes, type RestClient as IRestClient, type InvalidationMap, type InvalidationMapFunc, type MutationEffectsOptions, OpenAPICodegenConfig, OpenApiQueryConfig, OpenApiRouter, OpenApiWorkspaceContext, type QueryModule, type RequestConfig, type RequestInfo, type Response, RestClient$1 as RestClient, RestInterceptor, RestUtils, SharedErrorHandler, ns, resources, useMutationEffects };
231
+ export { type AppInfiniteQueryOptions, type AppMutationOptions, type AppQueryOptions, ApplicationException, AuthContext, AuthGuard, type AuthGuardProps, type ErrorEntry, ErrorHandler, type ErrorHandlerOptions, type GeneralErrorCodes, type RestClient as IRestClient, type InvalidationMap, type InvalidationMapFunc, type MutationEffectsOptions, OpenAPICodegenConfig, OpenApiQueryConfig, OpenApiRouter, OpenApiWorkspaceContext, type QueryModule, type RequestConfig, type RequestInfo, type Response, RestClient$1 as RestClient, RestInterceptor, RestUtils, SharedErrorHandler, ns, resources, useMutationEffects, useWorkspaceContext };
package/dist/index.mjs CHANGED
@@ -226,6 +226,7 @@ let OpenApiWorkspaceContext;
226
226
  return workspaceValue;
227
227
  };
228
228
  })(OpenApiWorkspaceContext || (OpenApiWorkspaceContext = {}));
229
+ const useWorkspaceContext = () => OpenApiWorkspaceContext.useContext();
229
230
 
230
231
  //#endregion
231
232
  //#region src/lib/auth/AuthGuard.tsx
@@ -249,4 +250,4 @@ const AuthGuard = ({ type, redirectTo, children }) => {
249
250
  };
250
251
 
251
252
  //#endregion
252
- export { ApplicationException, AuthContext, AuthGuard, ErrorHandler, OpenApiQueryConfig, OpenApiRouter, OpenApiWorkspaceContext, RestClient, RestInterceptor, RestUtils, SharedErrorHandler, ns, resources, useMutationEffects };
253
+ export { ApplicationException, AuthContext, AuthGuard, ErrorHandler, OpenApiQueryConfig, OpenApiRouter, OpenApiWorkspaceContext, RestClient, RestInterceptor, RestUtils, SharedErrorHandler, ns, resources, useMutationEffects, useWorkspaceContext };
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, _ as groupByType, a as getDataFromOpenAPIDoc, d as getTagFileName, g as GenerateType, n as getOutputFileName } from "./generateCodeFromOpenAPIDoc-WP1lRhb0.mjs";
3
- import { n as resolveConfig, t as runGenerate } from "./generate.runner-52viWKLA.mjs";
2
+ import { C as VALIDATION_ERROR_TYPE_TITLE, S as Profiler, _ as groupByType, a as getDataFromOpenAPIDoc, d as getTagFileName, g as GenerateType, n as getOutputFileName } from "./generateCodeFromOpenAPIDoc-CFbiHxB7.mjs";
3
+ import { n as resolveConfig, t as runGenerate } from "./generate.runner-DLLGYMVB.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.36";
42
+ return "2.0.8-rc.37";
43
43
  }
44
44
 
45
45
  //#endregion
package/dist/vite.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { S as Profiler } from "./generateCodeFromOpenAPIDoc-WP1lRhb0.mjs";
2
- import { t as runGenerate } from "./generate.runner-52viWKLA.mjs";
1
+ import { S as Profiler } from "./generateCodeFromOpenAPIDoc-CFbiHxB7.mjs";
2
+ import { t as runGenerate } from "./generate.runner-DLLGYMVB.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.36",
3
+ "version": "2.0.8-rc.37",
4
4
  "keywords": [
5
5
  "codegen",
6
6
  "openapi",