Skip to content

Commit f4d3492

Browse files
committed
Fixes
1 parent 7924ce9 commit f4d3492

416 files changed

Lines changed: 55786 additions & 23 deletions

File tree

Some content is hidden

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

src/generators/const/endpoints.const.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const AXIOS_REQUEST_CONFIG_NAME = "config";
1313
export const AXIOS_REQUEST_CONFIG_TYPE = "AxiosRequestConfig";
1414
export const AXIOS_IMPORT: Import = {
1515
defaultImport: AXIOS_DEFAULT_IMPORT_NAME,
16-
bindings: [AXIOS_REQUEST_CONFIG_TYPE],
16+
bindings: [],
17+
typeBindings: [AXIOS_REQUEST_CONFIG_TYPE],
1718
from: "axios",
1819
};

src/generators/generate/generateAcl.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@ export function generateAcl({ resolver, data, tag }: GenerateTypeParams) {
2424
const { hasAdditionalAbilityImports, modelsImports, endpoints } = aclData;
2525

2626
const caslAbilityTupleImport: Import = {
27-
bindings: [
28-
CASL_ABILITY_BINDING.abilityTuple,
29-
...(hasAdditionalAbilityImports ? [CASL_ABILITY_BINDING.forcedSubject, CASL_ABILITY_BINDING.subject] : []),
30-
],
27+
bindings: [...(hasAdditionalAbilityImports ? [CASL_ABILITY_BINDING.forcedSubject, CASL_ABILITY_BINDING.subject] : [])],
28+
typeBindings: [CASL_ABILITY_BINDING.abilityTuple],
3129
from: CASL_ABILITY_IMPORT.from,
3230
};
3331

@@ -58,13 +56,15 @@ export function generateAppAcl({ resolver, data }: Omit<GenerateTypeParams, "tag
5856
const { appAbilitiesType, hasAdditionalAbilityImports, modelsImports } = getAppAbilitiesType({ resolver, data });
5957

6058
const caslAbilityTupleImport: Import = {
61-
bindings: [
59+
bindings: [],
60+
typeBindings: [
6261
CASL_ABILITY_BINDING.pureAbility,
6362
CASL_ABILITY_BINDING.abilityTuple,
6463
...(!appAbilitiesType ? [CASL_ABILITY_BINDING.subjectType] : []),
6564
...(hasAdditionalAbilityImports ? [CASL_ABILITY_BINDING.forcedSubject] : []),
6665
],
6766
from: CASL_ABILITY_IMPORT.from,
67+
typeOnly: true,
6868
};
6969

7070
const lines: string[] = [];
@@ -90,11 +90,15 @@ export function generateAppAcl({ resolver, data }: Omit<GenerateTypeParams, "tag
9090
}
9191

9292
function renderImport(importData: Import) {
93+
const namedImports = [
94+
...importData.bindings,
95+
...((importData.typeBindings ?? []).map((binding) => (importData.typeOnly ? binding : `type ${binding}`))),
96+
];
9397
const names = [
9498
...(importData.defaultImport ? [importData.defaultImport] : []),
95-
...(importData.bindings ? [`{ ${importData.bindings.join(", ")} }`] : []),
99+
...(namedImports.length > 0 ? [`{ ${namedImports.join(", ")} }`] : []),
96100
].join(", ");
97-
return `import ${names} from "${importData.from}";`;
101+
return `import${importData.typeOnly ? " type" : ""} ${names} from "${importData.from}";`;
98102
}
99103

100104
function renderAbilityFunction(endpoint: Endpoint) {

src/generators/generate/generateConfigs.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,15 @@ export function generateConfigs(generateTypeParams: GenerateTypeParams) {
6767
}
6868

6969
function renderImport(importData: Import) {
70+
const namedImports = [
71+
...importData.bindings,
72+
...((importData.typeBindings ?? []).map((binding) => (importData.typeOnly ? binding : `type ${binding}`))),
73+
];
7074
const names = [
7175
...(importData.defaultImport ? [importData.defaultImport] : []),
72-
...(importData.bindings ? [`{ ${importData.bindings.join(", ")} }`] : []),
76+
...(namedImports.length > 0 ? [`{ ${namedImports.join(", ")} }`] : []),
7377
].join(", ");
74-
return `import ${names} from "${importData.from}";`;
78+
return `import${importData.typeOnly ? " type" : ""} ${names} from "${importData.from}";`;
7579
}
7680

7781
function renderInputsConfig(inputsConfig: DynamicInputsConfig) {

src/generators/generate/generateEndpoints.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ export function generateEndpoints({ resolver, data, tag }: GenerateTypeParams) {
3939
const hasAxiosRequestConfig = resolver.options.axiosRequestConfig;
4040
const hasAxiosImport = hasAxiosRequestConfig;
4141
const axiosImport: Import = {
42-
bindings: hasAxiosRequestConfig ? [AXIOS_REQUEST_CONFIG_TYPE] : [],
42+
bindings: [],
43+
typeBindings: hasAxiosRequestConfig ? [AXIOS_REQUEST_CONFIG_TYPE] : [],
4344
from: AXIOS_IMPORT.from,
4445
};
4546

@@ -125,11 +126,15 @@ export function generateEndpoints({ resolver, data, tag }: GenerateTypeParams) {
125126
}
126127

127128
function renderImport(importData: Import) {
129+
const namedImports = [
130+
...importData.bindings,
131+
...((importData.typeBindings ?? []).map((binding) => (importData.typeOnly ? binding : `type ${binding}`))),
132+
];
128133
const names = [
129134
...(importData.defaultImport ? [importData.defaultImport] : []),
130-
...(importData.bindings ? [`{ ${importData.bindings.join(", ")} }`] : []),
135+
...(namedImports.length > 0 ? [`{ ${namedImports.join(", ")} }`] : []),
131136
].join(", ");
132-
return `import ${names} from "${importData.from}";`;
137+
return `import${importData.typeOnly ? " type" : ""} ${names} from "${importData.from}";`;
133138
}
134139

135140
function renderEndpointParams(

src/generators/generate/generateModels.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,15 @@ function getUsedSchemaNames({
182182
}
183183

184184
function renderImport(importData: Import) {
185+
const namedImports = [
186+
...importData.bindings,
187+
...((importData.typeBindings ?? []).map((binding) => (importData.typeOnly ? binding : `type ${binding}`))),
188+
];
185189
const names = [
186190
...(importData.defaultImport ? [importData.defaultImport] : []),
187-
...(importData.bindings ? [`{ ${importData.bindings.join(", ")} }`] : []),
191+
...(namedImports.length > 0 ? [`{ ${namedImports.join(", ")} }`] : []),
188192
].join(", ");
189-
return `import ${names} from "${importData.from}";`;
193+
return `import${importData.typeOnly ? " type" : ""} ${names} from "${importData.from}";`;
190194
}
191195

192196
function renderModelJsDocs({

src/generators/generate/generateQueries.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ export function generateQueries(params: GenerateTypeParams) {
8585
const hasAxiosImport = hasAxiosRequestConfig || hasAxiosDefaultImport;
8686
const axiosImport: Import = {
8787
defaultImport: hasAxiosDefaultImport ? AXIOS_DEFAULT_IMPORT_NAME : undefined,
88-
bindings: hasAxiosRequestConfig ? [AXIOS_REQUEST_CONFIG_TYPE] : [],
88+
bindings: [],
89+
typeBindings: hasAxiosRequestConfig ? [AXIOS_REQUEST_CONFIG_TYPE] : [],
8990
from: AXIOS_IMPORT.from,
9091
};
9192

@@ -109,7 +110,8 @@ export function generateQueries(params: GenerateTypeParams) {
109110

110111
const hasMutationEffectsImport = hasMutationEffects && mutationEndpoints.length > 0;
111112
const mutationEffectsImport: Import = {
112-
bindings: [...(mutationEndpoints.length > 0 ? [MUTATION_EFFECTS.optionsType, MUTATION_EFFECTS.hookName] : [])],
113+
bindings: [...(mutationEndpoints.length > 0 ? [MUTATION_EFFECTS.hookName] : [])],
114+
typeBindings: [...(mutationEndpoints.length > 0 ? [MUTATION_EFFECTS.optionsType] : [])],
113115
from: PACKAGE_IMPORT_PATH,
114116
};
115117

@@ -122,6 +124,8 @@ export function generateQueries(params: GenerateTypeParams) {
122124
const queryTypesImport: Import = {
123125
bindings: [
124126
"OpenApiQueryConfig",
127+
],
128+
typeBindings: [
125129
...(queryEndpoints.length > 0 ? [QUERY_OPTIONS_TYPES.query] : []),
126130
...(resolver.options.infiniteQueries && infiniteQueryEndpoints.length > 0
127131
? [QUERY_OPTIONS_TYPES.infiniteQuery]
@@ -313,11 +317,15 @@ function getEndpointParamMapping(
313317
}
314318

315319
function renderImport(importData: Import) {
320+
const namedImports = [
321+
...importData.bindings,
322+
...((importData.typeBindings ?? []).map((binding) => (importData.typeOnly ? binding : `type ${binding}`))),
323+
];
316324
const names = [
317325
...(importData.defaultImport ? [importData.defaultImport] : []),
318-
...(importData.bindings ? [`{ ${importData.bindings.join(", ")} }`] : []),
326+
...(namedImports.length > 0 ? [`{ ${namedImports.join(", ")} }`] : []),
319327
].join(", ");
320-
return `import ${names} from "${importData.from}";`;
328+
return `import${importData.typeOnly ? " type" : ""} ${names} from "${importData.from}";`;
321329
}
322330

323331
function renderEndpointParams(

src/generators/types/generate.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Endpoint } from "./endpoint";
77
export interface Import {
88
defaultImport?: string;
99
bindings: string[];
10+
typeBindings?: string[];
1011
from: string;
1112
typeOnly?: boolean;
1213
}

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ export function getModelsImports({
4343
getTag,
4444
getEntityName: (zodSchema) => getZodSchemaInferedTypeName(zodSchema, resolver.options),
4545
options: resolver.options,
46-
});
46+
}).map((importData) => ({
47+
...importData,
48+
...(resolver.options.tsNamespaces ? {} : { typeOnly: true }),
49+
}));
4750

4851
return mergeImports(resolver.options, zodSchemaImports, zodSchemaTypeImports);
4952
}
@@ -201,14 +204,29 @@ export function mergeImports(options: GenerateOptions, ...importArrs: Import[][]
201204
importArrs.forEach((imports) => {
202205
imports.forEach((importItem) => {
203206
if (!merged.has(importItem.from)) {
204-
merged.set(importItem.from, importItem);
205-
} else if (!options.tsNamespaces) {
206-
merged.get(importItem.from)!.bindings.push(...importItem.bindings);
207+
merged.set(importItem.from, {
208+
...importItem,
209+
bindings: importItem.typeOnly ? [] : [...importItem.bindings],
210+
typeBindings: [...(importItem.typeBindings ?? []), ...(importItem.typeOnly ? importItem.bindings : [])],
211+
});
212+
} else {
213+
const existing = merged.get(importItem.from)!;
214+
if (!options.tsNamespaces && !importItem.typeOnly) {
215+
existing.bindings.push(...importItem.bindings);
216+
}
217+
existing.typeBindings = [
218+
...(existing.typeBindings ?? []),
219+
...(importItem.typeBindings ?? []),
220+
...(importItem.typeOnly ? importItem.bindings : []),
221+
];
222+
existing.typeOnly = false;
207223
}
208224
});
209225
});
210226
return Array.from(merged.values()).map((importItem) => ({
211227
...importItem,
212228
bindings: getUniqueArray(importItem.bindings),
229+
typeBindings: getUniqueArray(importItem.typeBindings ?? []).filter((binding) => !importItem.bindings.includes(binding)),
230+
typeOnly: Boolean(importItem.typeOnly && importItem.bindings.length === 0 && (importItem.typeBindings?.length ?? 0) > 0),
213231
}));
214232
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"openApiHash":"8a5456ab","optionsHash":"41c56198"}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import { ForcedSubject, subject, type AbilityTuple } 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)