Skip to content

Commit 4ce6a44

Browse files
committed
Fixes
1 parent 856cf1b commit 4ce6a44

File tree

331 files changed

+56365
-62
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

331 files changed

+56365
-62
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@povio/openapi-codegen-cli",
3-
"version": "2.0.8-rc.16",
3+
"version": "2.0.8-rc.17",
44
"keywords": [
55
"codegen",
66
"openapi",

src/acl.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
export { AbilityContext } from "./lib/acl/ability.context";
33
export { createAclGuard } from "./lib/acl/AclGuard";
44
export { Can } from "./lib/acl/Can";
5+
export { useAclCheck } from "./lib/acl/useAclCheck";
56
export type { AppAbilities, AppAbility } from "./lib/acl/appAbility.types";

src/generators/const/acl.const.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { GenerateFile, Import } from "@/generators/types/generate";
33
export const ACL_APP_ABILITY_FILE: GenerateFile = { fileName: "acl/app.ability", extension: "ts" };
44
export const ACL_APP_ABILITIES = "AppAbilities";
55

6-
export const ACL_CHECK_FILE: GenerateFile = { fileName: "acl/useAclCheck", extension: "ts" };
76
export const ACL_CHECK_HOOK = "useAclCheck";
87

98
export const CASL_ABILITY_BINDING = {

src/generators/generate/generateAclCheck.ts

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/generators/generate/generateQueries.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
AXIOS_REQUEST_CONFIG_NAME,
1313
AXIOS_REQUEST_CONFIG_TYPE,
1414
} from "@/generators/const/endpoints.const";
15-
import { PACKAGE_IMPORT_PATH } from "@/generators/const/package.const";
15+
import { ACL_PACKAGE_IMPORT_PATH, PACKAGE_IMPORT_PATH } from "@/generators/const/package.const";
1616
import { QUERIES_MODULE_NAME, QUERY_HOOKS, QUERY_IMPORT } from "@/generators/const/queries.const";
1717
import { SchemaResolver } from "@/generators/core/SchemaResolver.class";
1818
import { Endpoint, EndpointParameter } from "@/generators/types/endpoint";
@@ -43,7 +43,6 @@ import {
4343
import { getInfiniteQueryName, getQueryName } from "@/generators/utils/generate/generate.query.utils";
4444
import {
4545
getAppRestClientImportPath,
46-
getAclCheckImportPath,
4746
getMutationEffectsImportPath,
4847
getQueryModulesImportPath,
4948
getQueryTypesImportPath,
@@ -111,7 +110,7 @@ export function generateQueries(params: GenerateTypeParams) {
111110
const hasAclCheck = resolver.options.checkAcl && aclEndpoints.length > 0;
112111
const aclCheckImport: Import = {
113112
bindings: [ACL_CHECK_HOOK],
114-
from: getAclCheckImportPath(resolver.options),
113+
from: ACL_PACKAGE_IMPORT_PATH,
115114
};
116115

117116
const queryTypesImport: Import = {

src/generators/utils/generate-files.utils.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ACL_APP_ABILITY_FILE, ACL_CHECK_FILE } from "@/generators/const/acl.const";
1+
import { ACL_APP_ABILITY_FILE } from "@/generators/const/acl.const";
22
import {
33
APP_REST_CLIENT_FILE,
44
CROSS_TAB_QUERY_INVALIDATION_FILE,
@@ -10,7 +10,6 @@ import { PACKAGE_IMPORT_PATH } from "@/generators/const/package.const";
1010
import { DEFAULT_GENERATE_OPTIONS } from "@/generators/const/options.const";
1111
import { SchemaResolver } from "@/generators/core/SchemaResolver.class";
1212
import { generateAppAcl } from "@/generators/generate/generateAcl";
13-
import { generateAclCheck } from "@/generators/generate/generateAclCheck";
1413
import { generateAppRestClient } from "@/generators/generate/generateAppRestClient";
1514
import { generateQueryModules } from "@/generators/generate/generateQueryModules";
1615
import { generateZodExtended } from "@/generators/generate/generateZodExtended";
@@ -32,17 +31,6 @@ export function getAclFiles(data: GenerateData, resolver: SchemaResolver): Gener
3231
}),
3332
content: generateAppAcl({ resolver, data }),
3433
},
35-
...(resolver.options.checkAcl
36-
? [
37-
{
38-
fileName: getOutputFileName({
39-
output: resolver.options.output,
40-
fileName: getFileNameWithExtension(ACL_CHECK_FILE),
41-
}),
42-
content: generateAclCheck(resolver),
43-
},
44-
]
45-
: []),
4634
];
4735
}
4836

src/generators/utils/generate/generate.utils.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ACL_APP_ABILITY_FILE, ACL_CHECK_FILE } from "@/generators/const/acl.const";
1+
import { ACL_APP_ABILITY_FILE } from "@/generators/const/acl.const";
22
import {
33
APP_REST_CLIENT_FILE,
44
MUTATION_EFFECTS_FILE,
@@ -61,10 +61,6 @@ export function getMutationEffectsImportPath(options: GenerateOptions) {
6161
return `${getImportPath(options)}${MUTATION_EFFECTS_FILE.fileName}`;
6262
}
6363

64-
export function getAclCheckImportPath(options: GenerateOptions) {
65-
return `${getImportPath(options)}${ACL_CHECK_FILE.fileName}`;
66-
}
67-
6864
export function getZodExtendedImportPath(options: GenerateOptions) {
6965
return `${getImportPath(options)}${ZOD_EXTENDED_FILE.fileName}`;
7066
}

src/lib/acl/useAclCheck.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { useCallback } from "react";
2+
3+
import { type ErrorHandler, SharedErrorHandler } from "../rest/error-handling";
4+
import { AbilityContext } from "./ability.context";
5+
import type { AppAbilities } from "./appAbility.types";
6+
7+
interface UseAclCheckProps {
8+
errorHandler?: ErrorHandler<never>;
9+
}
10+
11+
export function useAclCheck<TAppAbilities extends AppAbilities = AppAbilities>({
12+
errorHandler,
13+
}: UseAclCheckProps = {}) {
14+
const ability = AbilityContext.useAbility<TAppAbilities>();
15+
16+
const checkAcl = useCallback(
17+
(appAbility: TAppAbilities) => {
18+
const can = ability.can as unknown as (...appAbility: AppAbilities) => boolean;
19+
if (!can(...(appAbility as AppAbilities))) {
20+
(errorHandler ?? SharedErrorHandler).rethrowError(new Error("ACL check failed"));
21+
}
22+
},
23+
[ability, errorHandler],
24+
);
25+
26+
return { checkAcl };
27+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"openApiHash":"8a5456ab","optionsHash":"1eec34d8"}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import { AbilityTuple, ForcedSubject, subject } from "@casl/ability";
2+
3+
export namespace AWBStocksAcl {
4+
/**
5+
* Use for `usePaginate` query ability. For global ability, omit the object parameter.
6+
* @description List AWB stocks
7+
* @param { string } object.officeId officeId from officeId path parameter
8+
* @returns { AbilityTuple } An ability tuple indicating the user's ability to use `usePaginate` query
9+
*/
10+
export const canUsePaginate = (
11+
object?: { officeId: string, }
12+
) => [
13+
"Read",
14+
object ? subject("AWBStock", object) : "AWBStock"
15+
] as AbilityTuple<"Read", "AWBStock" | ForcedSubject<"AWBStock"> & { officeId: string, }>;
16+
17+
/**
18+
* Use for `useCreate` mutation ability. For global ability, omit the object parameter.
19+
* @description Create AWB stock
20+
* @param { string } object.officeId officeId from officeId path parameter
21+
* @returns { AbilityTuple } An ability tuple indicating the user's ability to use `useCreate` mutation
22+
*/
23+
export const canUseCreate = (
24+
object?: { officeId: string, }
25+
) => [
26+
"Create",
27+
object ? subject("AWBStock", object) : "AWBStock"
28+
] as AbilityTuple<"Create", "AWBStock" | ForcedSubject<"AWBStock"> & { officeId: string, }>;
29+
30+
/**
31+
* Use for `useFindById` query ability. For global ability, omit the object parameter.
32+
* @description Get AWB stock details
33+
* @param { string } object.officeId officeId from officeId path parameter
34+
* @returns { AbilityTuple } An ability tuple indicating the user's ability to use `useFindById` query
35+
*/
36+
export const canUseFindById = (
37+
object?: { officeId: string, }
38+
) => [
39+
"Read",
40+
object ? subject("AWBStock", object) : "AWBStock"
41+
] as AbilityTuple<"Read", "AWBStock" | ForcedSubject<"AWBStock"> & { officeId: string, }>;
42+
43+
/**
44+
* Use for `useUpdate` mutation ability. For global ability, omit the object parameter.
45+
* @description Update AWB stock
46+
* @param { string } object.officeId officeId from officeId path parameter
47+
* @returns { AbilityTuple } An ability tuple indicating the user's ability to use `useUpdate` mutation
48+
*/
49+
export const canUseUpdate = (
50+
object?: { officeId: string, }
51+
) => [
52+
"Update",
53+
object ? subject("AWBStock", object) : "AWBStock"
54+
] as AbilityTuple<"Update", "AWBStock" | ForcedSubject<"AWBStock"> & { officeId: string, }>;
55+
56+
/**
57+
* Use for `useArchive` mutation ability. For global ability, omit the object parameter.
58+
* @description Archive AWB stock
59+
* @param { string } object.officeId officeId from officeId path parameter
60+
* @returns { AbilityTuple } An ability tuple indicating the user's ability to use `useArchive` mutation
61+
*/
62+
export const canUseArchive = (
63+
object?: { officeId: string, }
64+
) => [
65+
"Update",
66+
object ? subject("AWBStock", object) : "AWBStock"
67+
] as AbilityTuple<"Update", "AWBStock" | ForcedSubject<"AWBStock"> & { officeId: string, }>;
68+
69+
/**
70+
* Use for `useUnarchive` mutation ability. For global ability, omit the object parameter.
71+
* @description Unarchive AWB stock
72+
* @param { string } object.officeId officeId from officeId path parameter
73+
* @returns { AbilityTuple } An ability tuple indicating the user's ability to use `useUnarchive` mutation
74+
*/
75+
export const canUseUnarchive = (
76+
object?: { officeId: string, }
77+
) => [
78+
"Update",
79+
object ? subject("AWBStock", object) : "AWBStock"
80+
] as AbilityTuple<"Update", "AWBStock" | ForcedSubject<"AWBStock"> & { officeId: string, }>;
81+
82+
/**
83+
* Use for `useGenerateNextNumber` mutation ability. For global ability, omit the object parameter.
84+
* @description Generate next AWB number
85+
* @param { string } object.officeId officeId from officeId path parameter
86+
* @returns { AbilityTuple } An ability tuple indicating the user's ability to use `useGenerateNextNumber` mutation
87+
*/
88+
export const canUseGenerateNextNumber = (
89+
object?: { officeId: string, }
90+
) => [
91+
"Update",
92+
object ? subject("AWBStock", object) : "AWBStock"
93+
] as AbilityTuple<"Update", "AWBStock" | ForcedSubject<"AWBStock"> & { officeId: string, }>;
94+
95+
}

0 commit comments

Comments
 (0)