@povio/openapi-codegen-cli 1.2.12 → 2.0.0-rc.1
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/commands/generate.d.ts +1 -1
- package/dist/generator.d.ts +3 -0
- package/dist/generator.js +77 -0
- package/dist/generators/const/deps.const.d.ts +3 -9
- package/dist/generators/const/package.const.d.ts +1 -0
- package/dist/generators/types/options.d.ts +0 -3
- package/dist/generators/utils/generate/generate.imports.utils.d.ts +1 -1
- package/dist/generators/utils/generate/generate.utils.d.ts +0 -1
- package/dist/generators/utils/generate-files.utils.d.ts +1 -1
- package/dist/index.d.ts +16 -3
- package/dist/index.js +3 -77
- package/dist/lib/acl/AclGuard.d.ts +8 -0
- package/dist/lib/acl/Can.d.ts +9 -0
- package/dist/lib/acl/ability.context.d.ts +15 -0
- package/dist/lib/acl/appAbility.types.d.ts +3 -0
- package/dist/lib/auth/AuthGuard.d.ts +6 -0
- package/dist/lib/auth/auth.context.d.ts +22 -0
- package/dist/lib/config/queryConfig.context.d.ts +9 -0
- package/dist/lib/config/router.context.d.ts +9 -0
- package/dist/lib/react-query.types.d.ts +10 -0
- package/dist/lib/rest/error-handling.d.ts +20 -0
- package/dist/lib/rest/rest-client.d.ts +20 -0
- package/dist/lib/rest/rest-client.types.d.ts +23 -0
- package/dist/lib/rest/rest-interceptor.d.ts +8 -0
- package/dist/lib/rest/rest.utils.d.ts +7 -0
- package/dist/sh.js +139 -139
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +30 -2
- package/src/assets/useMutationEffects.ts +1 -1
- package/src/generators/templates/app-rest-client.hbs +2 -2
- package/src/assets/queryConfig.context.tsx +0 -22
- package/src/assets/react-query.types.ts +0 -39
- package/src/assets/rest-client.ts +0 -99
- package/src/assets/rest-interceptor.ts +0 -22
package/package.json
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@povio/openapi-codegen-cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-rc.1",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
|
+
"types": "./dist/index.d.ts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"require": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./generator": {
|
|
13
|
+
"types": "./dist/generator.d.ts",
|
|
14
|
+
"import": "./dist/generator.js",
|
|
15
|
+
"require": "./dist/generator.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
5
18
|
"bin": {
|
|
6
19
|
"openapi-codegen": "./dist/sh.js"
|
|
7
20
|
},
|
|
@@ -43,14 +56,27 @@
|
|
|
43
56
|
"dependencies": {
|
|
44
57
|
"import-fresh": "^3.3.1"
|
|
45
58
|
},
|
|
59
|
+
"peerDependencies": {
|
|
60
|
+
"@casl/ability": "^6.7.3",
|
|
61
|
+
"@casl/react": "^5.0.0",
|
|
62
|
+
"@tanstack/react-query": "~5.85.9",
|
|
63
|
+
"axios": "^1.13.1",
|
|
64
|
+
"react": "^19.1.0",
|
|
65
|
+
"zod": "^4.1.12"
|
|
66
|
+
},
|
|
46
67
|
"devDependencies": {
|
|
47
68
|
"@apidevtools/swagger-parser": "^10.1.0",
|
|
69
|
+
"@casl/ability": "^6.7.3",
|
|
70
|
+
"@casl/react": "^5.0.0",
|
|
71
|
+
"@tanstack/react-query": "~5.85.9",
|
|
48
72
|
"@types/node": "^20.12.12",
|
|
49
73
|
"@types/prettier": "^3.0.0",
|
|
50
74
|
"@types/prompt-sync": "^4.2.3",
|
|
75
|
+
"@types/react": "^19.1.0",
|
|
51
76
|
"@types/yargs": "^17.0.32",
|
|
52
77
|
"@typescript-eslint/eslint-plugin": "^8.40.0",
|
|
53
78
|
"@typescript-eslint/parser": "^8.40.0",
|
|
79
|
+
"axios": "^1.13.1",
|
|
54
80
|
"chalk": "^5.3.0",
|
|
55
81
|
"esbuild": "^0.21.3",
|
|
56
82
|
"eslint": "^8.57.0",
|
|
@@ -61,6 +87,7 @@
|
|
|
61
87
|
"openapi-types": "^12.1.3",
|
|
62
88
|
"prettier": "^3.2.5",
|
|
63
89
|
"prompt-sync": "^4.2.0",
|
|
90
|
+
"react": "^19.1.0",
|
|
64
91
|
"reflect-metadata": "^0.2.2",
|
|
65
92
|
"ts-node": "^10.9.2",
|
|
66
93
|
"ts-pattern": "^5.3.1",
|
|
@@ -68,7 +95,8 @@
|
|
|
68
95
|
"type-fest": "^4.26.0",
|
|
69
96
|
"typescript": "^5.4.5",
|
|
70
97
|
"vitest": "^2.0.5",
|
|
71
|
-
"yargs": "^17.7.2"
|
|
98
|
+
"yargs": "^17.7.2",
|
|
99
|
+
"zod": "^4.1.12"
|
|
72
100
|
},
|
|
73
101
|
"engines": {
|
|
74
102
|
"node": ">= 14",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { QueryKey, useQueryClient } from "@tanstack/react-query";
|
|
2
2
|
import { useCallback } from "react";
|
|
3
3
|
|
|
4
|
-
import { OpenApiQueryConfig } from "
|
|
4
|
+
import { OpenApiQueryConfig } from "@povio/openapi-codegen-cli";
|
|
5
5
|
import { QueryModule } from "./queryModules";
|
|
6
6
|
|
|
7
7
|
export interface MutationEffectsOptions {
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { createContext, use, useMemo } from "react";
|
|
2
|
-
|
|
3
|
-
export namespace OpenApiQueryConfig {
|
|
4
|
-
interface Type {
|
|
5
|
-
preferUpdate?: boolean;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const Context = createContext<Type>({});
|
|
9
|
-
|
|
10
|
-
type ProviderProps = Type;
|
|
11
|
-
|
|
12
|
-
export const Provider = ({ preferUpdate = true, children }: React.PropsWithChildren<ProviderProps>) => {
|
|
13
|
-
const value = useMemo(() => ({ preferUpdate }), [preferUpdate]);
|
|
14
|
-
|
|
15
|
-
return <Context.Provider value={value}>{children}</Context.Provider>;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export const useConfig = () => {
|
|
19
|
-
const context = use(Context);
|
|
20
|
-
return context ?? {};
|
|
21
|
-
};
|
|
22
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
InfiniteData,
|
|
3
|
-
QueryKey,
|
|
4
|
-
UseInfiniteQueryOptions,
|
|
5
|
-
UseMutationOptions,
|
|
6
|
-
UseQueryOptions,
|
|
7
|
-
} from "@tanstack/react-query";
|
|
8
|
-
|
|
9
|
-
type Function = (...args: any) => any;
|
|
10
|
-
type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N;
|
|
11
|
-
type IsAny<T> = IfAny<T, true, never>;
|
|
12
|
-
type IsUnknown<T, Y, N = T> = IsAny<T> extends never ? (unknown extends T ? Y : N) : N;
|
|
13
|
-
|
|
14
|
-
export type AppQueryOptions<TFunction extends Function, TData = Awaited<ReturnType<TFunction>>> = Omit<
|
|
15
|
-
UseQueryOptions<Awaited<ReturnType<TFunction>>, Error, IsUnknown<TData, Awaited<ReturnType<TFunction>>>>,
|
|
16
|
-
"queryKey" | "queryFn"
|
|
17
|
-
>;
|
|
18
|
-
|
|
19
|
-
export type AppMutationOptions<
|
|
20
|
-
TFunction extends Function,
|
|
21
|
-
TVariables = void,
|
|
22
|
-
TData = Awaited<ReturnType<TFunction>>,
|
|
23
|
-
> = Omit<UseMutationOptions<TData, Error, TVariables>, "mutationKey" | "mutationFn">;
|
|
24
|
-
|
|
25
|
-
export type AppInfiniteQueryOptions<
|
|
26
|
-
TFunction extends Function,
|
|
27
|
-
TData = InfiniteData<Awaited<ReturnType<TFunction>>>,
|
|
28
|
-
TQueryKey extends QueryKey = QueryKey,
|
|
29
|
-
TPageParam = number,
|
|
30
|
-
> = Omit<
|
|
31
|
-
UseInfiniteQueryOptions<
|
|
32
|
-
Awaited<ReturnType<TFunction>>,
|
|
33
|
-
Error,
|
|
34
|
-
IsUnknown<TData, InfiniteData<Awaited<ReturnType<TFunction>>>>,
|
|
35
|
-
TQueryKey,
|
|
36
|
-
TPageParam
|
|
37
|
-
>,
|
|
38
|
-
"queryKey" | "queryFn" | "initialPageParam" | "getNextPageParam"
|
|
39
|
-
>;
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse, CreateAxiosDefaults } from "axios";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import { RestInterceptor } from "./rest-interceptor";
|
|
4
|
-
|
|
5
|
-
interface RequestInfo<ZOutput> {
|
|
6
|
-
resSchema: z.ZodType<ZOutput>;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
interface RequestConfig<IsRawRes extends boolean = false> {
|
|
10
|
-
rawResponse?: IsRawRes;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
type Response<ZOutput, IsRawRes extends boolean = false> = IsRawRes extends true ? AxiosResponse<ZOutput> : ZOutput;
|
|
14
|
-
|
|
15
|
-
export class RestClient {
|
|
16
|
-
private client: AxiosInstance;
|
|
17
|
-
|
|
18
|
-
constructor({
|
|
19
|
-
config,
|
|
20
|
-
interceptors,
|
|
21
|
-
}: {
|
|
22
|
-
config?: CreateAxiosDefaults;
|
|
23
|
-
interceptors?: RestInterceptor<any[]>[];
|
|
24
|
-
} = {}) {
|
|
25
|
-
this.client = axios.create(config);
|
|
26
|
-
this.attachInterceptors(interceptors);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
public attachInterceptors<T extends any[]>(interceptors?: RestInterceptor<T>[], ...args: T) {
|
|
30
|
-
if (interceptors != null) {
|
|
31
|
-
interceptors.forEach((interceptor) => this.attachInterceptor(interceptor, ...args));
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public attachInterceptor<T extends any[]>(interceptor: RestInterceptor<T>, ...args: T) {
|
|
36
|
-
interceptor.addInterceptor(this.client, ...args);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public ejectInterceptor<T extends any[]>(interceptor: RestInterceptor<T>) {
|
|
40
|
-
interceptor.removeInterceptor(this.client);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public async get<ZOutput, IsRawRes extends boolean = false>(
|
|
44
|
-
requestInfo: RequestInfo<ZOutput>,
|
|
45
|
-
url: string,
|
|
46
|
-
requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>,
|
|
47
|
-
): Promise<Response<ZOutput, IsRawRes>> {
|
|
48
|
-
return this.makeRequest(requestInfo, { ...requestConfig, method: "get", url });
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
public async post<ZOutput, IsRawRes extends boolean = false>(
|
|
52
|
-
requestInfo: RequestInfo<ZOutput>,
|
|
53
|
-
url: string,
|
|
54
|
-
data?: any,
|
|
55
|
-
requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>,
|
|
56
|
-
): Promise<Response<ZOutput, IsRawRes>> {
|
|
57
|
-
return this.makeRequest(requestInfo, { ...requestConfig, method: "post", url, data });
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
public async patch<ZOutput, IsRawRes extends boolean = false>(
|
|
61
|
-
requestInfo: RequestInfo<ZOutput>,
|
|
62
|
-
url: string,
|
|
63
|
-
data?: any,
|
|
64
|
-
requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>,
|
|
65
|
-
): Promise<Response<ZOutput, IsRawRes>> {
|
|
66
|
-
return this.makeRequest(requestInfo, { ...requestConfig, method: "patch", url, data });
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
public async put<ZOutput, IsRawRes extends boolean = false>(
|
|
70
|
-
requestInfo: RequestInfo<ZOutput>,
|
|
71
|
-
url: string,
|
|
72
|
-
data?: any,
|
|
73
|
-
requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>,
|
|
74
|
-
): Promise<Response<ZOutput, IsRawRes>> {
|
|
75
|
-
return this.makeRequest(requestInfo, { ...requestConfig, method: "put", url, data });
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
public async delete<ZOutput, IsRawRes extends boolean = false>(
|
|
79
|
-
requestInfo: RequestInfo<ZOutput>,
|
|
80
|
-
url: string,
|
|
81
|
-
data?: any,
|
|
82
|
-
requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>,
|
|
83
|
-
): Promise<Response<ZOutput, IsRawRes>> {
|
|
84
|
-
return this.makeRequest(requestInfo, { ...requestConfig, method: "delete", url, data });
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
private async makeRequest<ZOutput, IsRawRes extends boolean = false>(
|
|
88
|
-
requestInfo: RequestInfo<ZOutput>,
|
|
89
|
-
requestConfig: AxiosRequestConfig & RequestConfig<IsRawRes>,
|
|
90
|
-
): Promise<Response<ZOutput, IsRawRes>> {
|
|
91
|
-
const { rawResponse, ...config } = requestConfig;
|
|
92
|
-
|
|
93
|
-
const res = await this.client(config);
|
|
94
|
-
|
|
95
|
-
const resData = requestInfo.resSchema.parse(res.data);
|
|
96
|
-
|
|
97
|
-
return (rawResponse ? { ...res, data: resData } : resData) as Response<ZOutput, IsRawRes>;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { AxiosInstance } from "axios";
|
|
2
|
-
|
|
3
|
-
export class RestInterceptor<T extends any[]> {
|
|
4
|
-
private interceptorIdMap: { client: AxiosInstance; interceptorId: number }[] = [];
|
|
5
|
-
|
|
6
|
-
constructor(private applyInterceptor: (client: AxiosInstance, ...args: T) => number) {}
|
|
7
|
-
|
|
8
|
-
public addInterceptor(client: AxiosInstance, ...args: T) {
|
|
9
|
-
this.removeInterceptor(client);
|
|
10
|
-
const interceptorId = this.applyInterceptor(client, ...args);
|
|
11
|
-
this.interceptorIdMap.push({ client, interceptorId });
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
public removeInterceptor(client: AxiosInstance) {
|
|
15
|
-
const interceptorId = this.interceptorIdMap.find((i) => i.client === client)?.interceptorId;
|
|
16
|
-
|
|
17
|
-
if (interceptorId != null) {
|
|
18
|
-
client.interceptors.request.eject(interceptorId);
|
|
19
|
-
this.interceptorIdMap = this.interceptorIdMap.filter((i) => i.client !== client);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|