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

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-CFbiHxB7.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-CeqvxYG3.mjs";
2
2
  import path from "path";
3
3
  import SwaggerParser from "@apidevtools/swagger-parser";
4
4
 
@@ -3134,13 +3134,19 @@ function generateAcl({ resolver, data, tag }) {
3134
3134
  });
3135
3135
  if (!aclData) return;
3136
3136
  const { hasAdditionalAbilityImports, modelsImports, endpoints } = aclData;
3137
+ const hasWorkspaceContext = endpoints.some((endpoint) => getWorkspaceConditionNames(resolver, endpoint).length > 0);
3137
3138
  const caslAbilityTupleImport = {
3138
3139
  bindings: [...hasAdditionalAbilityImports ? [CASL_ABILITY_BINDING.forcedSubject, CASL_ABILITY_BINDING.subject] : []],
3139
3140
  typeBindings: [CASL_ABILITY_BINDING.abilityTuple],
3140
3141
  from: CASL_ABILITY_IMPORT.from
3141
3142
  };
3143
+ const workspaceContextImport = {
3144
+ bindings: ["useWorkspaceContext"],
3145
+ from: PACKAGE_IMPORT_PATH
3146
+ };
3142
3147
  const lines = [];
3143
3148
  lines.push(renderImport$4(caslAbilityTupleImport));
3149
+ if (hasWorkspaceContext) lines.push(renderImport$4(workspaceContextImport));
3144
3150
  for (const modelsImport of modelsImports) lines.push(renderImport$4(modelsImport));
3145
3151
  lines.push("");
3146
3152
  if (resolver.options.tsNamespaces) lines.push(`export namespace ${getNamespaceName({
@@ -3149,7 +3155,10 @@ function generateAcl({ resolver, data, tag }) {
3149
3155
  options: resolver.options
3150
3156
  })} {`);
3151
3157
  for (const endpoint of endpoints) {
3152
- lines.push(renderAbilityFunction(endpoint));
3158
+ lines.push(renderAbilityFunction({
3159
+ resolver,
3160
+ endpoint
3161
+ }));
3153
3162
  lines.push("");
3154
3163
  }
3155
3164
  if (resolver.options.tsNamespaces) lines.push("}");
@@ -3188,7 +3197,42 @@ function renderImport$4(importData) {
3188
3197
  const names = [...importData.defaultImport ? [importData.defaultImport] : [], ...namedImports.length > 0 ? [`{ ${namedImports.join(", ")} }`] : []].join(", ");
3189
3198
  return `import${importData.typeOnly ? " type" : ""} ${names} from "${importData.from}";`;
3190
3199
  }
3191
- function renderAbilityFunction(endpoint) {
3200
+ function getWorkspaceContextAllowList$1(workspaceContext) {
3201
+ return new Set(workspaceContext);
3202
+ }
3203
+ function getWorkspaceConditionNames(resolver, endpoint) {
3204
+ const allowList = getWorkspaceContextAllowList$1(resolver.options.workspaceContext);
3205
+ return (getAbilityConditionsTypes(endpoint) ?? []).map((condition) => condition.name).filter((name) => allowList.has(name));
3206
+ }
3207
+ function renderWorkspaceAclHook({ resolver, endpoint }) {
3208
+ const abilityConditionsTypes = getAbilityConditionsTypes(endpoint) ?? [];
3209
+ const workspaceConditionNames = getWorkspaceConditionNames(resolver, endpoint);
3210
+ if (workspaceConditionNames.length === 0) return;
3211
+ const workspaceConditionNameSet = new Set(workspaceConditionNames);
3212
+ const objectRequired = abilityConditionsTypes.some((propertyType) => propertyType.required && !workspaceConditionNameSet.has(propertyType.name));
3213
+ const objectParams = abilityConditionsTypes.map((propertyType) => {
3214
+ const isWorkspaceCondition = workspaceConditionNameSet.has(propertyType.name);
3215
+ return `${propertyType.name}${propertyType.required && !isWorkspaceCondition ? "" : "?"}: ${(propertyType.type ?? "") + (propertyType.zodSchemaName ?? "")}, `;
3216
+ }).join("");
3217
+ const contextType = abilityConditionsTypes.filter((propertyType) => workspaceConditionNameSet.has(propertyType.name)).map((propertyType) => `${propertyType.name}?: ${(propertyType.type ?? "") + (propertyType.zodSchemaName ?? "")}`).join("; ");
3218
+ const contextBindings = workspaceConditionNames.map((name) => `${name}: ${name}Workspace`).join(", ");
3219
+ const lines = [];
3220
+ lines.push(`export const use${capitalize(getAbilityFunctionName(endpoint))} = (`);
3221
+ lines.push(` object${objectRequired ? "" : "?"}: { ${objectParams} } `);
3222
+ lines.push(") => {");
3223
+ lines.push(` const { ${contextBindings} } = useWorkspaceContext<{ ${contextType} }>();`);
3224
+ for (const conditionName of workspaceConditionNames) {
3225
+ const resolvedName = `normalize${capitalize(conditionName)}`;
3226
+ lines.push(` const ${resolvedName} = object?.${conditionName} ?? ${conditionName}Workspace;`);
3227
+ lines.push(` if (!${resolvedName}) {`);
3228
+ lines.push(` throw Error(\`${capitalize(conditionName)} not provided\`);`);
3229
+ lines.push(" }");
3230
+ }
3231
+ lines.push(` return ${getAbilityFunctionName(endpoint)}({ ...object, ${workspaceConditionNames.map((conditionName) => `${conditionName}: normalize${capitalize(conditionName)}`).join(", ")} });`);
3232
+ lines.push("};");
3233
+ return lines.join("\n");
3234
+ }
3235
+ function renderAbilityFunction({ resolver, endpoint }) {
3192
3236
  const abilityConditionsTypes = getAbilityConditionsTypes(endpoint) ?? [];
3193
3237
  const hasConditions = hasAbilityConditions(endpoint);
3194
3238
  const lines = [];
@@ -3205,6 +3249,14 @@ function renderAbilityFunction(endpoint) {
3205
3249
  lines.push(` "${getAbilityAction(endpoint)}",`);
3206
3250
  lines.push(` ${hasConditions ? `object ? subject("${getAbilitySubject(endpoint)}", object) : "${getAbilitySubject(endpoint)}"` : `"${getAbilitySubject(endpoint)}"`}`);
3207
3251
  lines.push(`] as ${CASL_ABILITY_BINDING.abilityTuple}<"${getAbilityAction(endpoint)}", ${getAbilitySubjectTypes(endpoint).join(" | ")}>;`);
3252
+ const workspaceAclHook = renderWorkspaceAclHook({
3253
+ resolver,
3254
+ endpoint
3255
+ });
3256
+ if (workspaceAclHook) {
3257
+ lines.push("");
3258
+ lines.push(workspaceAclHook);
3259
+ }
3208
3260
  return lines.join("\n");
3209
3261
  }
3210
3262
 
@@ -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-CFbiHxB7.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-CeqvxYG3.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 { 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";
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-CeqvxYG3.mjs";
3
+ import { n as resolveConfig, t as runGenerate } from "./generate.runner-BNSPwk_e.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.37";
42
+ return "2.0.8-rc.38";
43
43
  }
44
44
 
45
45
  //#endregion
package/dist/vite.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { S as Profiler } from "./generateCodeFromOpenAPIDoc-CFbiHxB7.mjs";
2
- import { t as runGenerate } from "./generate.runner-DLLGYMVB.mjs";
1
+ import { S as Profiler } from "./generateCodeFromOpenAPIDoc-CeqvxYG3.mjs";
2
+ import { t as runGenerate } from "./generate.runner-BNSPwk_e.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.37",
3
+ "version": "2.0.8-rc.38",
4
4
  "keywords": [
5
5
  "codegen",
6
6
  "openapi",