@povio/openapi-codegen-cli 3.0.0-rc.15 → 3.0.0-rc.16
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/dist/acl.mjs +14 -6
- package/dist/{generate.runner-DmjWJwgS.mjs → generate.runner-bJnq9ZZJ.mjs} +1 -1
- package/dist/{generateCodeFromOpenAPIDoc-DjVJepG8.mjs → generateCodeFromOpenAPIDoc-x7KFQcSq.mjs} +32 -13
- package/dist/generator.mjs +1 -1
- package/dist/index.d.mts +6 -3
- package/dist/index.mjs +11 -8
- package/dist/metro.mjs +3 -3
- package/dist/{openapi-codegen.runner-CtfeBizk.mjs → openapi-codegen.runner-NNdDG0V4.mjs} +2 -2
- package/dist/sh.mjs +3 -3
- package/dist/vite.mjs +3 -3
- package/package.json +2 -2
package/dist/acl.mjs
CHANGED
|
@@ -11,14 +11,17 @@ let AbilityContext;
|
|
|
11
11
|
(function(_AbilityContext) {
|
|
12
12
|
const createAppAbilityBuilder = () => new AbilityBuilder(createMongoAbility);
|
|
13
13
|
const initialAppAbility = createAppAbilityBuilder().build();
|
|
14
|
-
const Context = createContext(
|
|
14
|
+
const Context = createContext(initialAppAbility);
|
|
15
15
|
const { Consumer } = Context;
|
|
16
16
|
_AbilityContext.Consumer = Consumer;
|
|
17
17
|
_AbilityContext.Provider = ({ children }) => {
|
|
18
18
|
const [ability, setAbility] = useState(initialAppAbility);
|
|
19
19
|
const { user } = AuthContext.useAuth();
|
|
20
20
|
useEffect(() => {
|
|
21
|
-
if (!user || !("aclRules" in user))
|
|
21
|
+
if (!user || !("aclRules" in user)) {
|
|
22
|
+
setAbility(initialAppAbility);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
22
25
|
const { can, build } = createAppAbilityBuilder();
|
|
23
26
|
const packedRules = user.aclRules;
|
|
24
27
|
unpackRules(packedRules).forEach(({ action, subject, conditions }) => {
|
|
@@ -41,10 +44,15 @@ let AbilityContext;
|
|
|
41
44
|
const createAclGuard = () => ({ canUse, redirectTo = "/", children }) => {
|
|
42
45
|
const ability = AbilityContext.useAbility();
|
|
43
46
|
const { replace } = OpenApiRouter.useRouter();
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
47
|
+
const shouldRedirect = !ability.can(canUse[0], canUse[1]);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (shouldRedirect) replace(redirectTo);
|
|
50
|
+
}, [
|
|
51
|
+
redirectTo,
|
|
52
|
+
replace,
|
|
53
|
+
shouldRedirect
|
|
54
|
+
]);
|
|
55
|
+
if (shouldRedirect) return null;
|
|
48
56
|
return children;
|
|
49
57
|
};
|
|
50
58
|
|
|
@@ -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-
|
|
1
|
+
import { S as Profiler, h as deepMerge, i as writeGenerateFileData, p as DEFAULT_GENERATE_OPTIONS, r as removeStaleGeneratedFiles, t as generateCodeFromOpenAPIDoc } from "./generateCodeFromOpenAPIDoc-x7KFQcSq.mjs";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
4
4
|
|
package/dist/{generateCodeFromOpenAPIDoc-DjVJepG8.mjs → generateCodeFromOpenAPIDoc-x7KFQcSq.mjs}
RENAMED
|
@@ -4580,7 +4580,10 @@ function renderQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
|
4580
4580
|
}));
|
|
4581
4581
|
lines.push(`export const ${getQueryName(endpoint)} = <TData>(${endpointParams ? `{ ${endpointArgs} }: { ${endpointParams} }, ` : ""}options?: AppQueryOptions<typeof ${inlineEndpoints ? getEndpointName(endpoint) : getImportedEndpointName(endpoint, resolver.options)}, TData>${hasAxiosRequestConfig ? `, ${AXIOS_REQUEST_CONFIG_NAME}?: ${AXIOS_REQUEST_CONFIG_TYPE}` : ""}) => {`);
|
|
4582
4582
|
lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
|
|
4583
|
-
if (hasAclCheck)
|
|
4583
|
+
if (hasAclCheck) {
|
|
4584
|
+
lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
|
|
4585
|
+
lines.push(" const { skipAcl, ...queryOptions } = options ?? {};");
|
|
4586
|
+
}
|
|
4584
4587
|
lines.push(...renderWorkspaceParamResolutions({
|
|
4585
4588
|
replacements: workspaceParamReplacements,
|
|
4586
4589
|
paramTypes: workspaceParamTypes,
|
|
@@ -4591,11 +4594,15 @@ function renderQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
|
4591
4594
|
lines.push(` ...${queryOptionsName}(${queryOptionsArgs}),`);
|
|
4592
4595
|
if (hasQueryFnOverride) {
|
|
4593
4596
|
lines.push(" queryFn: async () => {");
|
|
4594
|
-
if (hasAclCheck)
|
|
4597
|
+
if (hasAclCheck) {
|
|
4598
|
+
lines.push(" if (!skipAcl) {");
|
|
4599
|
+
lines.push(renderAclCheckCall(resolver, endpoint, workspaceParamReplacements, " "));
|
|
4600
|
+
lines.push(" }");
|
|
4601
|
+
}
|
|
4595
4602
|
lines.push(` return ${queryOptionsName}(${queryOptionsArgs}).queryFn();`);
|
|
4596
4603
|
lines.push(" },");
|
|
4597
4604
|
}
|
|
4598
|
-
lines.push("
|
|
4605
|
+
lines.push(` ...${hasAclCheck ? "queryOptions" : "options"},`);
|
|
4599
4606
|
lines.push(" });");
|
|
4600
4607
|
lines.push("};");
|
|
4601
4608
|
return lines.join("\n");
|
|
@@ -4650,7 +4657,10 @@ function renderMutation({ resolver, endpoint, inlineEndpoints, precomputed }) {
|
|
|
4650
4657
|
}));
|
|
4651
4658
|
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}` : ""}) => {`);
|
|
4652
4659
|
if (hasMutationDefaultOnError) lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
|
|
4653
|
-
if (hasAclCheck)
|
|
4660
|
+
if (hasAclCheck) {
|
|
4661
|
+
lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
|
|
4662
|
+
lines.push(" const { skipAcl, ...queryOptions } = options ?? {};");
|
|
4663
|
+
}
|
|
4654
4664
|
lines.push(...renderWorkspaceContextDestructure({
|
|
4655
4665
|
replacements: workspaceParamReplacements,
|
|
4656
4666
|
paramTypes: workspaceParamTypes,
|
|
@@ -4671,7 +4681,11 @@ function renderMutation({ resolver, endpoint, inlineEndpoints, precomputed }) {
|
|
|
4671
4681
|
replacements: workspaceParamReplacements,
|
|
4672
4682
|
indent: " "
|
|
4673
4683
|
}));
|
|
4674
|
-
if (hasAclCheck)
|
|
4684
|
+
if (hasAclCheck) {
|
|
4685
|
+
lines.push(" if (!skipAcl) {");
|
|
4686
|
+
lines.push(renderAclCheckCall(resolver, endpoint, workspaceParamReplacements, " "));
|
|
4687
|
+
lines.push(" }");
|
|
4688
|
+
}
|
|
4675
4689
|
if (endpoint.mediaUpload) {
|
|
4676
4690
|
lines.push(` const uploadInstructions = await ${endpointFunction}(${resolvedEndpointArgs}${hasAxiosRequestConfig ? `${resolvedEndpointArgs ? ", " : ""}${AXIOS_REQUEST_CONFIG_NAME}` : ""});`);
|
|
4677
4691
|
lines.push(" ");
|
|
@@ -4706,8 +4720,8 @@ function renderMutation({ resolver, endpoint, inlineEndpoints, precomputed }) {
|
|
|
4706
4720
|
const scopePathParamInterpolations = scopePathParams.map((p) => `:\${${p.name}}`).join("");
|
|
4707
4721
|
lines.push(` scope: { id: \`${getEndpointName(endpoint)}${scopePathParamInterpolations}\` },`);
|
|
4708
4722
|
}
|
|
4709
|
-
lines.push("
|
|
4710
|
-
if (hasMutationDefaultOnError) lines.push(
|
|
4723
|
+
lines.push(` ...${hasAclCheck ? "queryOptions" : "options"},`);
|
|
4724
|
+
if (hasMutationDefaultOnError) lines.push(` onError: ${hasAclCheck ? "queryOptions" : "options"}?.onError ?? queryConfig.onError,`);
|
|
4711
4725
|
if (hasMutationEffects) {
|
|
4712
4726
|
lines.push(" onSuccess: async (resData, variables, onMutateResult, context) => {");
|
|
4713
4727
|
if (updateQueryEndpoints.length > 0) {
|
|
@@ -4719,9 +4733,9 @@ function renderMutation({ resolver, endpoint, inlineEndpoints, precomputed }) {
|
|
|
4719
4733
|
indent: " "
|
|
4720
4734
|
}));
|
|
4721
4735
|
lines.push(` const updateKeys = [${updateQueryEndpoints.map((e) => `keys.${getEndpointName(e)}(${renderEndpointArgs(resolver, e, { includeOnlyRequiredParams: true }, workspaceParamReplacements)})`).join(", ")}];`);
|
|
4722
|
-
lines.push(` await runMutationEffects(resData, variables, options, updateKeys);`);
|
|
4723
|
-
} else lines.push(
|
|
4724
|
-
lines.push("
|
|
4736
|
+
lines.push(` await runMutationEffects(resData, variables, ${hasAclCheck ? "queryOptions" : "options"}, updateKeys);`);
|
|
4737
|
+
} else lines.push(` await runMutationEffects(resData, variables, ${hasAclCheck ? "queryOptions" : "options"});`);
|
|
4738
|
+
lines.push(` ${hasAclCheck ? "queryOptions" : "options"}?.onSuccess?.(resData, variables, onMutateResult, context);`);
|
|
4725
4739
|
lines.push(" },");
|
|
4726
4740
|
}
|
|
4727
4741
|
lines.push(" });");
|
|
@@ -4791,7 +4805,10 @@ function renderInfiniteQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
|
4791
4805
|
}));
|
|
4792
4806
|
lines.push(`export const ${getInfiniteQueryName(endpoint)} = <TData>(${endpointParams ? `{ ${endpointArgsWithoutPage} }: { ${endpointParams} }, ` : ""}options?: AppInfiniteQueryOptions<typeof ${inlineEndpoints ? getEndpointName(endpoint) : getImportedEndpointName(endpoint, resolver.options)}, TData>${hasAxiosRequestConfig ? `, ${AXIOS_REQUEST_CONFIG_NAME}?: ${AXIOS_REQUEST_CONFIG_TYPE}` : ""}) => {`);
|
|
4793
4807
|
lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
|
|
4794
|
-
if (hasAclCheck)
|
|
4808
|
+
if (hasAclCheck) {
|
|
4809
|
+
lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
|
|
4810
|
+
lines.push(" const { skipAcl, ...queryOptions } = options ?? {};");
|
|
4811
|
+
}
|
|
4795
4812
|
lines.push(...renderWorkspaceParamResolutions({
|
|
4796
4813
|
replacements: workspaceParamReplacements,
|
|
4797
4814
|
paramTypes: workspaceParamTypes,
|
|
@@ -4802,11 +4819,13 @@ function renderInfiniteQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
|
4802
4819
|
lines.push(` ...${queryOptionsName}(${queryOptionsArgs}),`);
|
|
4803
4820
|
if (hasQueryFnOverride) {
|
|
4804
4821
|
lines.push(" queryFn: async ({ pageParam }) => {");
|
|
4805
|
-
lines.push(
|
|
4822
|
+
lines.push(" if (!skipAcl) {");
|
|
4823
|
+
lines.push(renderAclCheckCall(resolver, endpoint, workspaceParamReplacements, " "));
|
|
4824
|
+
lines.push(" }");
|
|
4806
4825
|
lines.push(` return ${queryOptionsName}(${queryOptionsArgs}).queryFn({ pageParam });`);
|
|
4807
4826
|
lines.push(" },");
|
|
4808
4827
|
}
|
|
4809
|
-
lines.push("
|
|
4828
|
+
lines.push(` ...${hasAclCheck ? "queryOptions" : "options"},`);
|
|
4810
4829
|
lines.push(" });");
|
|
4811
4830
|
lines.push("};");
|
|
4812
4831
|
return lines.join("\n");
|
package/dist/generator.mjs
CHANGED
|
@@ -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-
|
|
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-x7KFQcSq.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
|
@@ -77,9 +77,12 @@ type Function = (...args: any) => any;
|
|
|
77
77
|
type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N;
|
|
78
78
|
type IsAny<T> = IfAny<T, true, never>;
|
|
79
79
|
type IsUnknown<T, Y, N = T> = IsAny<T> extends never ? (unknown extends T ? Y : N) : N;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
interface OpenApiAclCheckOptions {
|
|
81
|
+
skipAcl?: boolean;
|
|
82
|
+
}
|
|
83
|
+
type AppQueryOptions<TFunction extends Function, TData = Awaited<ReturnType<TFunction>>, TErrorCodes = GeneralErrorCodes> = Omit<UseQueryOptions<Awaited<ReturnType<TFunction>>, ApplicationException<TErrorCodes>, IsUnknown<TData, Awaited<ReturnType<TFunction>>>>, "queryKey" | "queryFn"> & OpenApiAclCheckOptions;
|
|
84
|
+
type AppMutationOptions<TFunction extends Function, TVariables = void, TData = Awaited<ReturnType<TFunction>>, TErrorCodes = GeneralErrorCodes> = Omit<UseMutationOptions<TData, ApplicationException<TErrorCodes>, TVariables>, "mutationKey" | "mutationFn"> & OpenApiAclCheckOptions;
|
|
85
|
+
type AppInfiniteQueryOptions<TFunction extends Function, TData = InfiniteData<Awaited<ReturnType<TFunction>>>, TErrorCodes = GeneralErrorCodes, TQueryKey extends QueryKey = QueryKey, TPageParam = number> = Omit<UseInfiniteQueryOptions<Awaited<ReturnType<TFunction>>, ApplicationException<TErrorCodes>, IsUnknown<TData, InfiniteData<Awaited<ReturnType<TFunction>>>>, TQueryKey, TPageParam>, "queryKey" | "queryFn" | "initialPageParam" | "getNextPageParam"> & OpenApiAclCheckOptions;
|
|
83
86
|
//#endregion
|
|
84
87
|
//#region src/lib/config/queryConfig.context.d.ts
|
|
85
88
|
type QueryModule = string | number | symbol;
|
package/dist/index.mjs
CHANGED
|
@@ -248,15 +248,18 @@ const AuthGuard = ({ type, redirectTo, children }) => {
|
|
|
248
248
|
useEffect(() => {
|
|
249
249
|
setHasMounted(true);
|
|
250
250
|
}, []);
|
|
251
|
+
const privateRedirectTo = redirectTo || routes?.unauthenticated || "/";
|
|
252
|
+
const publicRedirectTo = redirectTo || routes?.authenticated || "/";
|
|
253
|
+
const redirectTarget = type === "private" && !isAuthenticated ? privateRedirectTo : type === "public-only" && isAuthenticated ? publicRedirectTo : null;
|
|
254
|
+
useEffect(() => {
|
|
255
|
+
if (hasMounted && redirectTarget) replace(redirectTarget);
|
|
256
|
+
}, [
|
|
257
|
+
hasMounted,
|
|
258
|
+
redirectTarget,
|
|
259
|
+
replace
|
|
260
|
+
]);
|
|
251
261
|
if (!hasMounted) return loadingState;
|
|
252
|
-
if (
|
|
253
|
-
replace(redirectTo || routes?.unauthenticated || "/");
|
|
254
|
-
return null;
|
|
255
|
-
}
|
|
256
|
-
if (type === "public-only" && isAuthenticated) {
|
|
257
|
-
replace(redirectTo || routes?.authenticated || "/");
|
|
258
|
-
return null;
|
|
259
|
-
}
|
|
262
|
+
if (redirectTarget) return null;
|
|
260
263
|
return children;
|
|
261
264
|
};
|
|
262
265
|
|
package/dist/metro.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "./generateCodeFromOpenAPIDoc-
|
|
2
|
-
import "./generate.runner-
|
|
3
|
-
import { t as createOpenApiCodegenRunner } from "./openapi-codegen.runner-
|
|
1
|
+
import "./generateCodeFromOpenAPIDoc-x7KFQcSq.mjs";
|
|
2
|
+
import "./generate.runner-bJnq9ZZJ.mjs";
|
|
3
|
+
import { t as createOpenApiCodegenRunner } from "./openapi-codegen.runner-NNdDG0V4.mjs";
|
|
4
4
|
import fs from "fs";
|
|
5
5
|
import path from "path";
|
|
6
6
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as Profiler } from "./generateCodeFromOpenAPIDoc-
|
|
2
|
-
import { t as runGenerate } from "./generate.runner-
|
|
1
|
+
import { S as Profiler } from "./generateCodeFromOpenAPIDoc-x7KFQcSq.mjs";
|
|
2
|
+
import { t as runGenerate } from "./generate.runner-bJnq9ZZJ.mjs";
|
|
3
3
|
import path from "path";
|
|
4
4
|
|
|
5
5
|
//#region src/plugins/openapi-codegen.runner.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, a as getDataFromOpenAPIDoc, m as groupByType, n as getOutputFileName, u as getTagFileName, v as GenerateType } from "./generateCodeFromOpenAPIDoc-
|
|
3
|
-
import { n as resolveConfig, t as runGenerate } from "./generate.runner-
|
|
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-x7KFQcSq.mjs";
|
|
3
|
+
import { n as resolveConfig, t as runGenerate } from "./generate.runner-bJnq9ZZJ.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.
|
|
42
|
+
return "3.0.0-rc.16";
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
//#endregion
|
package/dist/vite.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "./generateCodeFromOpenAPIDoc-
|
|
2
|
-
import "./generate.runner-
|
|
3
|
-
import { t as createOpenApiCodegenRunner } from "./openapi-codegen.runner-
|
|
1
|
+
import "./generateCodeFromOpenAPIDoc-x7KFQcSq.mjs";
|
|
2
|
+
import "./generate.runner-bJnq9ZZJ.mjs";
|
|
3
|
+
import { t as createOpenApiCodegenRunner } from "./openapi-codegen.runner-NNdDG0V4.mjs";
|
|
4
4
|
import path from "path";
|
|
5
5
|
|
|
6
6
|
//#region src/vite/openapi-codegen.plugin.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@povio/openapi-codegen-cli",
|
|
3
|
-
"version": "3.0.0-rc.15",
|
|
4
3
|
"keywords": [
|
|
5
4
|
"codegen",
|
|
6
5
|
"openapi",
|
|
@@ -131,5 +130,6 @@
|
|
|
131
130
|
"node": ">= 14",
|
|
132
131
|
"pnpm": ">= 9"
|
|
133
132
|
},
|
|
134
|
-
"packageManager": "pnpm@10.4.0"
|
|
133
|
+
"packageManager": "pnpm@10.4.0",
|
|
134
|
+
"version": "3.0.0-rc.16"
|
|
135
135
|
}
|