@povio/openapi-codegen-cli 3.3.0-rc.1 → 4.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/README.md +97 -9
- package/dist/AuthGuard-GbtTDXs0.d.mts +32 -0
- package/dist/AuthGuard-qpAtHaBz.mjs +24 -0
- package/dist/acl.d.mts +6 -19
- package/dist/acl.mjs +7 -7
- package/dist/{auth.context-BAz8frX9.mjs → auth.context-COWO6ssl.mjs} +1 -18
- package/dist/auth.d.mts +2 -0
- package/dist/auth.mjs +3 -0
- package/dist/axios.d.mts +2 -0
- package/dist/axios.mjs +2 -0
- package/dist/{config-BQqze8rU.d.mts → config-CiLFKLAY.d.mts} +1 -2
- package/dist/config.d.mts +4 -0
- package/dist/config.mjs +5 -0
- package/dist/{error-handling-D6ZYITQ3.d.mts → error-handling-LPEPQV1V.d.mts} +3 -42
- package/dist/{error-handling-CsnufAil.mjs → error-handling-uS0DgYUR.mjs} +23 -47
- package/dist/errors.d.mts +3 -0
- package/dist/errors.mjs +2 -0
- package/dist/generate.runner-BtPpBVj9.mjs +1667 -0
- package/dist/generate.utils-BJxdEik8.cjs +2269 -0
- package/dist/{generateCodeFromOpenAPIDoc-KQT4kYxY.mjs → generateCodeFromOpenAPIDoc-CGoR73wh.cjs} +1335 -2237
- package/dist/generateCodeFromOpenAPIDoc-D1H6MZiS.mjs +2101 -0
- package/dist/generator.d.mts +3 -10
- package/dist/generator.mjs +6 -4
- package/dist/getDataFromOpenAPIDoc-fJCwtr-2.mjs +2016 -0
- package/dist/i18n-B_brQh4X.d.mts +38 -0
- package/dist/i18n-D-FesqFb.mjs +36 -0
- package/dist/index.d.mts +12 -198
- package/dist/index.mjs +12 -256
- package/dist/metro.cjs +117 -4861
- package/dist/metro.d.mts +3 -4
- package/dist/metro.mjs +3 -3
- package/dist/native-rest-interceptor-BX45GDWd.d.mts +49 -0
- package/dist/native-rest-interceptor-Np4Ov54n.mjs +215 -0
- package/dist/native.d.mts +3 -0
- package/dist/native.mjs +3 -0
- package/dist/openapi-codegen-native-darwin-arm64.node +0 -0
- package/dist/openapi-codegen-native-linux-x64.node +0 -0
- package/dist/openapi-codegen-native-win32-x64.node +0 -0
- package/dist/{openapi-codegen.runner-nPBssrBL.mjs → openapi-codegen.runner-BpykceyD.mjs} +2 -2
- package/dist/{openapi-source.runner-B6KKrXw7.d.mts → openapi-source.runner-DIOvAX_R.d.mts} +2 -8
- package/dist/{openapi-source.runner-8kCe-g9S.mjs → openapi-source.runner-DPUNTduQ.mjs} +25 -11
- package/dist/{options-DdQJ9BSc.d.mts → options-X0zju7gw.d.mts} +8 -1
- package/dist/query.d.mts +3 -0
- package/dist/query.mjs +3 -0
- package/dist/queryConfig.context-CldQ5YL9.mjs +34 -0
- package/dist/queryConfig.context-aO4QOLru.d.mts +24 -0
- package/dist/rest-client-BSXsrOff.d.mts +55 -0
- package/dist/rest-interceptor-Dm9DFErh.mjs +115 -0
- package/dist/rest-transport.types-DM5-qyOJ.d.mts +66 -0
- package/dist/rest-transport.types-DxitRtsB.mjs +11 -0
- package/dist/rest.d.mts +2 -0
- package/dist/rest.mjs +2 -0
- package/dist/rest.utils-DpiFIdhF.d.mts +9 -0
- package/dist/router.context-EPlMBk3G.mjs +21 -0
- package/dist/sh.d.mts +1 -1
- package/dist/sh.mjs +52 -59
- package/dist/tiny.d.mts +1 -1
- package/dist/tiny.mjs +1 -1
- package/dist/useMutationEffects-D_wEEF6-.d.mts +29 -0
- package/dist/useMutationEffects-PB1fvKWM.mjs +68 -0
- package/dist/vite.d.mts +3 -4
- package/dist/vite.mjs +5 -4
- package/dist/workspace.context-XWvQ_7Hg.mjs +26 -0
- package/dist/workspace.context-isVY9ves.d.mts +23 -0
- package/dist/zod.d.mts +2 -7
- package/dist/zod.mjs +1 -1
- package/package.json +70 -22
- package/dist/generate.runner-BeCGJ1ar.mjs +0 -87
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { i as SharedErrorHandler } from "./error-handling-uS0DgYUR.mjs";
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
//#region src/lib/rest/rest-client.ts
|
|
5
|
+
var RestClient = class {
|
|
6
|
+
client;
|
|
7
|
+
errorHandler;
|
|
8
|
+
constructor({ config, interceptors, errorHandler } = {}) {
|
|
9
|
+
this.client = axios.create(config);
|
|
10
|
+
this.errorHandler = errorHandler ?? SharedErrorHandler;
|
|
11
|
+
this.attachInterceptors(interceptors);
|
|
12
|
+
}
|
|
13
|
+
attachInterceptors(interceptors, ...args) {
|
|
14
|
+
if (interceptors != null) interceptors.forEach((interceptor) => this.attachInterceptor(interceptor, ...args));
|
|
15
|
+
}
|
|
16
|
+
attachInterceptor(interceptor, ...args) {
|
|
17
|
+
interceptor.addInterceptor(this.client, ...args);
|
|
18
|
+
}
|
|
19
|
+
ejectInterceptor(interceptor) {
|
|
20
|
+
interceptor.removeInterceptor(this.client);
|
|
21
|
+
}
|
|
22
|
+
async get(requestInfo, url, requestConfig) {
|
|
23
|
+
return this.makeRequest(requestInfo, {
|
|
24
|
+
...requestConfig,
|
|
25
|
+
method: "get",
|
|
26
|
+
url
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
async post(requestInfo, url, data, requestConfig) {
|
|
30
|
+
return this.makeRequest(requestInfo, {
|
|
31
|
+
...requestConfig,
|
|
32
|
+
method: "post",
|
|
33
|
+
url,
|
|
34
|
+
data
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
async patch(requestInfo, url, data, requestConfig) {
|
|
38
|
+
return this.makeRequest(requestInfo, {
|
|
39
|
+
...requestConfig,
|
|
40
|
+
method: "patch",
|
|
41
|
+
url,
|
|
42
|
+
data
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
async put(requestInfo, url, data, requestConfig) {
|
|
46
|
+
return this.makeRequest(requestInfo, {
|
|
47
|
+
...requestConfig,
|
|
48
|
+
method: "put",
|
|
49
|
+
url,
|
|
50
|
+
data
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
async delete(requestInfo, url, data, requestConfig) {
|
|
54
|
+
return this.makeRequest(requestInfo, {
|
|
55
|
+
...requestConfig,
|
|
56
|
+
method: "delete",
|
|
57
|
+
url,
|
|
58
|
+
data
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
async makeRequest(requestInfo, requestConfig) {
|
|
62
|
+
const errorStack = (/* @__PURE__ */ new Error()).stack;
|
|
63
|
+
try {
|
|
64
|
+
const { rawResponse, allowInvalidResponseData, ...config } = requestConfig;
|
|
65
|
+
const res = await this.client(config);
|
|
66
|
+
const responseData = res.status === 204 && res.data === "" ? void 0 : res.data;
|
|
67
|
+
const parseResult = requestInfo.resSchema.safeParse(responseData);
|
|
68
|
+
let resData;
|
|
69
|
+
if (parseResult.success) resData = parseResult.data;
|
|
70
|
+
else if (allowInvalidResponseData && config.method === "get") {
|
|
71
|
+
parseResult.error.name = "BE Response schema mismatch - ZodError";
|
|
72
|
+
parseResult.error.stack = [parseResult.error.stack, ...errorStack?.split("\n").slice(2) ?? []].join("\n");
|
|
73
|
+
console.error(parseResult.error);
|
|
74
|
+
resData = res.data;
|
|
75
|
+
} else throw parseResult.error;
|
|
76
|
+
return rawResponse ? {
|
|
77
|
+
...res,
|
|
78
|
+
data: resData
|
|
79
|
+
} : resData;
|
|
80
|
+
} catch (error) {
|
|
81
|
+
if (error instanceof z.ZodError) {
|
|
82
|
+
error.name = "BE Response schema mismatch - ZodError";
|
|
83
|
+
error.stack = [error.stack, ...errorStack?.split("\n").slice(2) ?? []].join("\n");
|
|
84
|
+
}
|
|
85
|
+
(requestInfo.errorHandler ?? this.errorHandler).rethrowError(error);
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/lib/rest/rest-interceptor.ts
|
|
92
|
+
var RestInterceptor = class {
|
|
93
|
+
applyInterceptor;
|
|
94
|
+
interceptorIdMap = [];
|
|
95
|
+
constructor(applyInterceptor) {
|
|
96
|
+
this.applyInterceptor = applyInterceptor;
|
|
97
|
+
}
|
|
98
|
+
addInterceptor(client, ...args) {
|
|
99
|
+
this.removeInterceptor(client);
|
|
100
|
+
const interceptorId = this.applyInterceptor(client, ...args);
|
|
101
|
+
this.interceptorIdMap.push({
|
|
102
|
+
client,
|
|
103
|
+
interceptorId
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
removeInterceptor(client) {
|
|
107
|
+
const interceptorId = this.interceptorIdMap.find((i) => i.client === client)?.interceptorId;
|
|
108
|
+
if (interceptorId != null) {
|
|
109
|
+
client.interceptors.request.eject(interceptorId);
|
|
110
|
+
this.interceptorIdMap = this.interceptorIdMap.filter((i) => i.client !== client);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
//#endregion
|
|
115
|
+
export { RestClient as n, RestInterceptor as t };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
//#region src/lib/rest/rest-transport.types.d.ts
|
|
3
|
+
type GeneralTransportErrorCode = "DATA_VALIDATION_ERROR" | "NETWORK_ERROR" | "CANCELED_ERROR" | "INTERNAL_ERROR" | "UNKNOWN_ERROR";
|
|
4
|
+
type RestResponseType = "json" | "text" | "blob" | "arrayBuffer";
|
|
5
|
+
type TransportFetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
6
|
+
interface UploadProgress {
|
|
7
|
+
loaded: number;
|
|
8
|
+
total: number;
|
|
9
|
+
}
|
|
10
|
+
interface TransportRequestConfig<IsRawRes extends boolean = false> {
|
|
11
|
+
headers?: HeadersInit;
|
|
12
|
+
params?: Record<string, unknown>;
|
|
13
|
+
signal?: AbortSignal;
|
|
14
|
+
timeout?: number;
|
|
15
|
+
credentials?: RequestCredentials;
|
|
16
|
+
responseType?: RestResponseType;
|
|
17
|
+
rawResponse?: IsRawRes;
|
|
18
|
+
allowInvalidResponseData?: boolean;
|
|
19
|
+
onUploadProgress?: (progress: UploadProgress) => void;
|
|
20
|
+
}
|
|
21
|
+
interface TransportResponse<T> {
|
|
22
|
+
data: T;
|
|
23
|
+
status: number;
|
|
24
|
+
statusText: string;
|
|
25
|
+
headers: Headers;
|
|
26
|
+
url: string;
|
|
27
|
+
}
|
|
28
|
+
interface RestRequestInfo<ZOutput, ECodes extends string> {
|
|
29
|
+
resSchema: z.ZodType<ZOutput>;
|
|
30
|
+
}
|
|
31
|
+
interface TransportRequest {
|
|
32
|
+
url: string;
|
|
33
|
+
method: string;
|
|
34
|
+
headers: Headers;
|
|
35
|
+
body?: BodyInit | null;
|
|
36
|
+
signal?: AbortSignal;
|
|
37
|
+
credentials?: RequestCredentials;
|
|
38
|
+
retryCount?: number;
|
|
39
|
+
}
|
|
40
|
+
interface TransportErrorContext {
|
|
41
|
+
request: TransportRequest;
|
|
42
|
+
response?: TransportResponse<unknown>;
|
|
43
|
+
retry(request?: TransportRequest): Promise<TransportResponse<unknown>>;
|
|
44
|
+
}
|
|
45
|
+
interface RestTransportInterceptor {
|
|
46
|
+
onRequest?(request: TransportRequest): TransportRequest | Promise<TransportRequest>;
|
|
47
|
+
onResponse?<T>(response: TransportResponse<T>): TransportResponse<T> | Promise<TransportResponse<T>>;
|
|
48
|
+
onError?(error: unknown, context: TransportErrorContext): unknown | Promise<unknown>;
|
|
49
|
+
}
|
|
50
|
+
type TransportResult<T, IsRawRes extends boolean> = IsRawRes extends true ? TransportResponse<T> : T;
|
|
51
|
+
interface RestTransport {
|
|
52
|
+
attachInterceptor(interceptor: RestTransportInterceptor): void;
|
|
53
|
+
ejectInterceptor(interceptor: RestTransportInterceptor): void;
|
|
54
|
+
get<T, E extends string, R extends boolean = false>(info: RestRequestInfo<T, E>, url: string, config?: TransportRequestConfig<R>): Promise<TransportResult<T, R>>;
|
|
55
|
+
post<T, E extends string, R extends boolean = false>(info: RestRequestInfo<T, E>, url: string, data?: unknown, config?: TransportRequestConfig<R>): Promise<TransportResult<T, R>>;
|
|
56
|
+
patch<T, E extends string, R extends boolean = false>(info: RestRequestInfo<T, E>, url: string, data?: unknown, config?: TransportRequestConfig<R>): Promise<TransportResult<T, R>>;
|
|
57
|
+
put<T, E extends string, R extends boolean = false>(info: RestRequestInfo<T, E>, url: string, data?: unknown, config?: TransportRequestConfig<R>): Promise<TransportResult<T, R>>;
|
|
58
|
+
delete<T, E extends string, R extends boolean = false>(info: RestRequestInfo<T, E>, url: string, data?: unknown, config?: TransportRequestConfig<R>): Promise<TransportResult<T, R>>;
|
|
59
|
+
upload(url: string, data: BodyInit, config?: TransportRequestConfig, method?: "put" | "post"): Promise<void>;
|
|
60
|
+
}
|
|
61
|
+
declare class HttpError<T = unknown> extends Error {
|
|
62
|
+
readonly response: TransportResponse<T>;
|
|
63
|
+
constructor(message: string, response: TransportResponse<T>);
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
export { RestTransport as a, TransportFetch as c, TransportResponse as d, TransportResult as f, RestResponseType as i, TransportRequest as l, HttpError as n, RestTransportInterceptor as o, UploadProgress as p, RestRequestInfo as r, TransportErrorContext as s, GeneralTransportErrorCode as t, TransportRequestConfig as u };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/lib/rest/rest-transport.types.ts
|
|
2
|
+
var HttpError = class extends Error {
|
|
3
|
+
response;
|
|
4
|
+
constructor(message, response) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.response = response;
|
|
7
|
+
this.name = "HttpError";
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
11
|
+
export { HttpError as t };
|
package/dist/rest.d.mts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as RestTransport, d as TransportResponse, f as TransportResult, i as RestResponseType, l as TransportRequest, n as HttpError, o as RestTransportInterceptor, p as UploadProgress, r as RestRequestInfo, t as GeneralTransportErrorCode, u as TransportRequestConfig } from "./rest-transport.types-DM5-qyOJ.mjs";
|
|
2
|
+
export { type GeneralTransportErrorCode, HttpError, type RestRequestInfo, type RestResponseType, type RestTransport, type RestTransportInterceptor, type TransportRequest, type TransportRequestConfig, type TransportResponse, type TransportResult, type UploadProgress };
|
package/dist/rest.mjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/lib/rest/rest.utils.d.ts
|
|
2
|
+
declare namespace RestUtils {
|
|
3
|
+
const extractServerResponseCode: (e: unknown) => string | number | null;
|
|
4
|
+
const doesServerErrorMessageContain: (e: unknown, text: string) => boolean;
|
|
5
|
+
const extractServerErrorMessage: (e: unknown) => string | null;
|
|
6
|
+
const extractContentDispositionFilename: (headers: Headers | Record<string, unknown>) => string | undefined;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { RestUtils as t };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createContext, use, useMemo } from "react";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
//#region src/lib/config/router.context.tsx
|
|
4
|
+
let OpenApiRouter;
|
|
5
|
+
(function(_OpenApiRouter) {
|
|
6
|
+
const Context = createContext(null);
|
|
7
|
+
_OpenApiRouter.Provider = ({ children, replace }) => {
|
|
8
|
+
const value = useMemo(() => ({ replace }), [replace]);
|
|
9
|
+
return /* @__PURE__ */ jsx(Context, {
|
|
10
|
+
value,
|
|
11
|
+
children
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
_OpenApiRouter.useRouter = () => {
|
|
15
|
+
const context = use(Context);
|
|
16
|
+
if (!context) throw new Error("useRouter must be used within an OpenApiRouter.Provider");
|
|
17
|
+
return context;
|
|
18
|
+
};
|
|
19
|
+
})(OpenApiRouter || (OpenApiRouter = {}));
|
|
20
|
+
//#endregion
|
|
21
|
+
export { OpenApiRouter as t };
|
package/dist/sh.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {}
|
package/dist/sh.mjs
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { createRequire } from "node:module";
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { i as VALIDATION_ERROR_TYPE_TITLE, n as groupByType, t as getDataFromOpenAPIDoc } from "./getDataFromOpenAPIDoc-fJCwtr-2.mjs";
|
|
3
|
+
import { D as getTagFileName, Wn as Profiler, a as resolveConfig, n as runGenerate, o as getOutputFileName, t as getOpenApiDoc } from "./generate.runner-BtPpBVj9.mjs";
|
|
5
4
|
import yargs from "yargs";
|
|
6
5
|
import { hideBin } from "yargs/helpers";
|
|
7
6
|
import { styleText } from "node:util";
|
|
8
|
-
import fs
|
|
7
|
+
import fs from "fs";
|
|
9
8
|
import "reflect-metadata";
|
|
10
9
|
import path from "path";
|
|
11
|
-
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
12
10
|
import { exec } from "child_process";
|
|
13
|
-
//#region \0rolldown/runtime.js
|
|
14
|
-
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
15
|
-
//#endregion
|
|
16
11
|
//#region src/helpers/cli.helper.ts
|
|
17
12
|
function log(message) {
|
|
18
13
|
console.log(message);
|
|
@@ -36,7 +31,7 @@ function logBanner(message) {
|
|
|
36
31
|
* Fetch the version from package.json
|
|
37
32
|
*/
|
|
38
33
|
function getVersion() {
|
|
39
|
-
return "
|
|
34
|
+
return "4.0.0-rc.1";
|
|
40
35
|
}
|
|
41
36
|
//#endregion
|
|
42
37
|
//#region src/helpers/yargs.helper.ts
|
|
@@ -63,20 +58,23 @@ function getYargsOption(target) {
|
|
|
63
58
|
}
|
|
64
59
|
function getBuilder(options) {
|
|
65
60
|
return async (y) => {
|
|
66
|
-
return y.options(getYargsOptions(options)).middleware(async (
|
|
67
|
-
|
|
61
|
+
return y.options(getYargsOptions(options)).middleware(async (argv) => {
|
|
62
|
+
Object.assign(argv, await loadYargsConfig(options, argv));
|
|
68
63
|
}, true);
|
|
69
64
|
};
|
|
70
65
|
}
|
|
66
|
+
function getYargsOptionEntries(target) {
|
|
67
|
+
return Object.entries(getYargsOption(target));
|
|
68
|
+
}
|
|
71
69
|
function getYargsOptions(target) {
|
|
72
|
-
return
|
|
70
|
+
return getYargsOptionEntries(target).reduce((a, [property, options]) => {
|
|
73
71
|
a[property] = Object.fromEntries(Object.entries(options).filter(([optionName]) => !["envAlias", "default"].includes(optionName)));
|
|
74
72
|
return a;
|
|
75
73
|
}, {});
|
|
76
74
|
}
|
|
77
75
|
async function loadYargsConfig(cls, _argv) {
|
|
78
76
|
const argv = new cls();
|
|
79
|
-
for (const [name, o] of
|
|
77
|
+
for (const [name, o] of getYargsOptionEntries(cls)) argv[name] = _argv[name] ?? o.default;
|
|
80
78
|
return argv;
|
|
81
79
|
}
|
|
82
80
|
//#endregion
|
|
@@ -130,50 +128,16 @@ async function loadConfigFromPath(filePath) {
|
|
|
130
128
|
const ext = path.extname(absolutePath).toLowerCase();
|
|
131
129
|
if (ext === ".mjs") return loadMjsConfig(absolutePath);
|
|
132
130
|
if (ext !== ".ts") throw new Error(`Only ESM (.mjs) and TypeScript (.ts) configuration files are supported. Found: ${ext}`);
|
|
133
|
-
return
|
|
131
|
+
return loadModuleConfig(absolutePath, "TypeScript");
|
|
134
132
|
}
|
|
135
133
|
async function loadMjsConfig(filePath) {
|
|
134
|
+
return loadModuleConfig(filePath, "ESM");
|
|
135
|
+
}
|
|
136
|
+
async function loadModuleConfig(filePath, format) {
|
|
136
137
|
const imported = await import(`${pathToFileURL(filePath).href}?t=${Date.now()}`);
|
|
137
|
-
if (!imported.default) throw new Error(
|
|
138
|
+
if (!imported.default) throw new Error(`${format} config must have a default export: ${filePath}`);
|
|
138
139
|
return imported.default;
|
|
139
140
|
}
|
|
140
|
-
let importFresh;
|
|
141
|
-
const loadJsSync = function loadJsSync(filepath) {
|
|
142
|
-
if (importFresh === void 0) importFresh = __require("import-fresh");
|
|
143
|
-
return importFresh(filepath);
|
|
144
|
-
};
|
|
145
|
-
let typescript;
|
|
146
|
-
async function loadTsConfig(filePath) {
|
|
147
|
-
if (typescript === void 0) typescript = __require("typescript");
|
|
148
|
-
const transpiledFilepath = `${filePath.slice(0, -2)}cjs`;
|
|
149
|
-
try {
|
|
150
|
-
const tsConfig = resolveTsConfig(path.dirname(filePath)) ?? {};
|
|
151
|
-
tsConfig.compilerOptions = Object.assign({}, tsConfig.compilerOptions, {
|
|
152
|
-
module: typescript.ModuleKind.NodeNext,
|
|
153
|
-
moduleResolution: typescript.ModuleResolutionKind.NodeNext,
|
|
154
|
-
target: typescript.ScriptTarget.ES2022,
|
|
155
|
-
noEmit: false
|
|
156
|
-
});
|
|
157
|
-
const fileContent = fs.readFileSync(filePath, "utf-8");
|
|
158
|
-
const transpiledFileContent = typescript.transpileModule(fileContent, tsConfig).outputText;
|
|
159
|
-
writeFileSync(transpiledFilepath, transpiledFileContent);
|
|
160
|
-
return loadJsSync(transpiledFilepath).default;
|
|
161
|
-
} catch (error) {
|
|
162
|
-
error.message = `TypeScript Error in ${filePath}:\n${error.message}`;
|
|
163
|
-
throw error;
|
|
164
|
-
} finally {
|
|
165
|
-
if (existsSync(transpiledFilepath)) rmSync(transpiledFilepath);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
function resolveTsConfig(directory) {
|
|
169
|
-
const filePath = typescript.findConfigFile(directory, (fileName) => {
|
|
170
|
-
return typescript.sys.fileExists(fileName);
|
|
171
|
-
});
|
|
172
|
-
if (filePath === void 0) return;
|
|
173
|
-
const { config, error } = typescript.readConfigFile(filePath, (path) => typescript.sys.readFile(path));
|
|
174
|
-
if (error) throw new Error(`Error in ${filePath}: ${error.messageText.toString()}`);
|
|
175
|
-
return config;
|
|
176
|
-
}
|
|
177
141
|
function pathToFileURL(filePath) {
|
|
178
142
|
const normalizedPath = path.resolve(filePath).replace(/\\/g, "/");
|
|
179
143
|
return { href: normalizedPath.startsWith("/") ? `file://${normalizedPath}` : `file:///${normalizedPath}` };
|
|
@@ -183,24 +147,25 @@ function pathToFileURL(filePath) {
|
|
|
183
147
|
async function check({ verbose, config: configParam, includeTags: _includeTagsParam, excludeTags: _excludeTagsParam, ...params }) {
|
|
184
148
|
const start = Date.now();
|
|
185
149
|
if (verbose) logInfo("Resolving config...");
|
|
150
|
+
const fileConfig = await loadConfig(configParam);
|
|
186
151
|
const config = resolveConfig({
|
|
187
|
-
fileConfig
|
|
152
|
+
fileConfig,
|
|
188
153
|
params
|
|
189
154
|
});
|
|
190
155
|
if (verbose) logInfo("Parsing OpenAPI spec...");
|
|
191
|
-
const openApiDoc = await
|
|
156
|
+
const openApiDoc = await getOpenApiDoc(config.input);
|
|
192
157
|
if (verbose) logInfo("Running check...");
|
|
193
158
|
const errorMessages = checkOpenAPIDoc(openApiDoc, config);
|
|
194
159
|
if (errorMessages.length === 0) logSuccess(`Time: ${Date.now() - start}ms`);
|
|
195
160
|
else throw new Error(`Found ${errorMessages.length} issues. Time: ${Date.now() - start}ms`);
|
|
196
161
|
}
|
|
197
162
|
//#endregion
|
|
198
|
-
//#region \0@oxc-project+runtime@0.
|
|
163
|
+
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/decorateMetadata.js
|
|
199
164
|
function __decorateMetadata(k, v) {
|
|
200
165
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
201
166
|
}
|
|
202
167
|
//#endregion
|
|
203
|
-
//#region \0@oxc-project+runtime@0.
|
|
168
|
+
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/decorate.js
|
|
204
169
|
function __decorate(decorators, target, key, desc) {
|
|
205
170
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
206
171
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -278,8 +243,10 @@ async function generate({ prettier, verbose, config: configParam, ...params }) {
|
|
|
278
243
|
function execPrettier({ output, verbose }) {
|
|
279
244
|
if (verbose) logInfo("Running Prettier...");
|
|
280
245
|
exec(`prettier --write ${output} `, (error) => {
|
|
281
|
-
if (verbose)
|
|
282
|
-
|
|
246
|
+
if (verbose) {
|
|
247
|
+
if (error) logError(error, "Prettier error");
|
|
248
|
+
else logSuccess("Prettier finished.");
|
|
249
|
+
}
|
|
283
250
|
});
|
|
284
251
|
}
|
|
285
252
|
//#endregion
|
|
@@ -291,6 +258,7 @@ var GenerateOptions = class {
|
|
|
291
258
|
clearOutput;
|
|
292
259
|
incremental;
|
|
293
260
|
tsNamespaces;
|
|
261
|
+
treeShakeableNamespaces;
|
|
294
262
|
tsPath;
|
|
295
263
|
splitByTags;
|
|
296
264
|
defaultTag;
|
|
@@ -299,8 +267,14 @@ var GenerateOptions = class {
|
|
|
299
267
|
excludePathRegex;
|
|
300
268
|
excludeRedundantZodSchemas;
|
|
301
269
|
importPath;
|
|
270
|
+
compileSchemas;
|
|
302
271
|
extractEnums;
|
|
303
272
|
modelsInCommon;
|
|
273
|
+
modelsInModules;
|
|
274
|
+
zodImportPath;
|
|
275
|
+
restClient;
|
|
276
|
+
mutationEffectsImportPath;
|
|
277
|
+
aclCheckImportPath;
|
|
304
278
|
removeOperationPrefixEndingWith;
|
|
305
279
|
acl;
|
|
306
280
|
checkAcl;
|
|
@@ -335,6 +309,10 @@ __decorate([YargOption({
|
|
|
335
309
|
envAlias: "tsNamespaces",
|
|
336
310
|
type: "boolean"
|
|
337
311
|
}), __decorateMetadata("design:type", Boolean)], GenerateOptions.prototype, "tsNamespaces", void 0);
|
|
312
|
+
__decorate([YargOption({
|
|
313
|
+
envAlias: "treeShakeableNamespaces",
|
|
314
|
+
type: "boolean"
|
|
315
|
+
}), __decorateMetadata("design:type", Boolean)], GenerateOptions.prototype, "treeShakeableNamespaces", void 0);
|
|
338
316
|
__decorate([YargOption({ envAlias: "tsPath" }), __decorateMetadata("design:type", String)], GenerateOptions.prototype, "tsPath", void 0);
|
|
339
317
|
__decorate([YargOption({
|
|
340
318
|
envAlias: "splitByTags",
|
|
@@ -349,6 +327,10 @@ __decorate([YargOption({
|
|
|
349
327
|
type: "boolean"
|
|
350
328
|
}), __decorateMetadata("design:type", Boolean)], GenerateOptions.prototype, "excludeRedundantZodSchemas", void 0);
|
|
351
329
|
__decorate([YargOption({ envAlias: "importPath" }), __decorateMetadata("design:type", String)], GenerateOptions.prototype, "importPath", void 0);
|
|
330
|
+
__decorate([YargOption({
|
|
331
|
+
envAlias: "compileSchemas",
|
|
332
|
+
type: "boolean"
|
|
333
|
+
}), __decorateMetadata("design:type", Boolean)], GenerateOptions.prototype, "compileSchemas", void 0);
|
|
352
334
|
__decorate([YargOption({
|
|
353
335
|
envAlias: "extractEnums",
|
|
354
336
|
type: "boolean"
|
|
@@ -357,6 +339,17 @@ __decorate([YargOption({
|
|
|
357
339
|
envAlias: "modelsInCommon",
|
|
358
340
|
type: "boolean"
|
|
359
341
|
}), __decorateMetadata("design:type", Boolean)], GenerateOptions.prototype, "modelsInCommon", void 0);
|
|
342
|
+
__decorate([YargOption({
|
|
343
|
+
envAlias: "modelsInModules",
|
|
344
|
+
type: "boolean"
|
|
345
|
+
}), __decorateMetadata("design:type", Boolean)], GenerateOptions.prototype, "modelsInModules", void 0);
|
|
346
|
+
__decorate([YargOption({ envAlias: "zodImportPath" }), __decorateMetadata("design:type", String)], GenerateOptions.prototype, "zodImportPath", void 0);
|
|
347
|
+
__decorate([YargOption({
|
|
348
|
+
envAlias: "restClient",
|
|
349
|
+
choices: ["axios", "native"]
|
|
350
|
+
}), __decorateMetadata("design:type", String)], GenerateOptions.prototype, "restClient", void 0);
|
|
351
|
+
__decorate([YargOption({ envAlias: "mutationEffectsImportPath" }), __decorateMetadata("design:type", String)], GenerateOptions.prototype, "mutationEffectsImportPath", void 0);
|
|
352
|
+
__decorate([YargOption({ envAlias: "aclCheckImportPath" }), __decorateMetadata("design:type", String)], GenerateOptions.prototype, "aclCheckImportPath", void 0);
|
|
360
353
|
__decorate([YargOption({ envAlias: "removeOperationPrefixEndingWith" }), __decorateMetadata("design:type", String)], GenerateOptions.prototype, "removeOperationPrefixEndingWith", void 0);
|
|
361
354
|
__decorate([YargOption({
|
|
362
355
|
envAlias: "acl",
|
package/dist/tiny.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $ as getModuleOpenApiTag, A as collectApiModelSchemaExports, At as toOpenAPI30Document, B as collectReachableModelSchemas, C as applyEnumExtensions, Ct as procedureSchemaName, D as applyRobodevModuleExtensions, Dt as schemaExportName, E as applyParameterExtensions, Et as schemaComponentRef, F as collectExtraSchemas, G as findComponentEnumNames, H as compactTagName, I as collectModelSchemaExports, J as generateOpenApiFile, K as findEnumNames, L as collectModuleModelSchemaExports, M as collectContractSchemas, Mt as toOpenAPIAclRule, N as collectDbTableModelSchemaExport, Nt as toPascalCase, O as applyRobodevUserRolesExtension, Ot as sharedSchemaExportName, P as collectDbTableModelSchemaExports, Pt as visitZodSchema, Q as getModuleOpenApiController, R as collectOperationMeta, S as addContractSchema, St as operationKey, T as applyPaginatedItemSchemas, Tt as routeHasPathParameters, U as createModelSchemaNameGetter, V as collectSchemaRegistryRoots, W as defineOpenApiSchemas, X as getContractProcedureData, Y as getComponentSchemas, Z as getDerivedOperationId, _ as OpenApiSchemaRegistry, _t as namedControllerActionSchema, a as isTinyOpenApiFakeMode, at as getProcedureInputSchemaRole, b as TinyOpenApiUserRole, bt as namedOpenApiResponseSchema, c as AnyContractRouter, ct as isContractProcedure, d as GenerateOpenApiFile, dt as isObject, et as getObjectPropertySchema, f as GenerateOpenApiFileOptions, ft as isProcedureMeta, g as JsonObject, gt as namedControllerActionInputDtoSchema, h as GenerateTinyOpenApiFileOptions, ht as modelSchemaNameEntries, i as getLocalInputPath, it as getPaginatedItemSchema, j as collectContractSchemaRoots, jt as toOpenAPI30Schema, k as asStringArray, kt as stripNoContentResponseBodies, l as AnySchema, lt as isNullSchema, m as GenerateOpenApiSpec, mt as modelSchemaExportName, nt as getOperationAction, o as normalizeWatchFolders, ot as getRobodevModuleRoles, p as GenerateOpenApiFileResult, pt as isZodSchema, q as generateORPCOpenAPISpec, r as createTinyOpenApiSourceRunner, rt as getOperationController, s as AclRule, st as getStringEnumValues, t as TinyOpenApiSourceRunnerConfig, tt as getOpenApiSchemaName, u as GenerateORPCOpenAPISpecOptions, ut as isNullableOnlySchema, v as ProcedureMeta, vt as namedOpenApiOutputSchema, w as applyOperationMeta, wt as resolveOpenApiOutputPath, x as ZodSchema, xt as namedOpenApiSchema, y as TinyOpenApiModule, yt as namedOpenApiRequestSchema, z as collectOperationTags } from "./openapi-source.runner-
|
|
1
|
+
import { $ as getModuleOpenApiTag, A as collectApiModelSchemaExports, At as toOpenAPI30Document, B as collectReachableModelSchemas, C as applyEnumExtensions, Ct as procedureSchemaName, D as applyRobodevModuleExtensions, Dt as schemaExportName, E as applyParameterExtensions, Et as schemaComponentRef, F as collectExtraSchemas, G as findComponentEnumNames, H as compactTagName, I as collectModelSchemaExports, J as generateOpenApiFile, K as findEnumNames, L as collectModuleModelSchemaExports, M as collectContractSchemas, Mt as toOpenAPIAclRule, N as collectDbTableModelSchemaExport, Nt as toPascalCase, O as applyRobodevUserRolesExtension, Ot as sharedSchemaExportName, P as collectDbTableModelSchemaExports, Pt as visitZodSchema, Q as getModuleOpenApiController, R as collectOperationMeta, S as addContractSchema, St as operationKey, T as applyPaginatedItemSchemas, Tt as routeHasPathParameters, U as createModelSchemaNameGetter, V as collectSchemaRegistryRoots, W as defineOpenApiSchemas, X as getContractProcedureData, Y as getComponentSchemas, Z as getDerivedOperationId, _ as OpenApiSchemaRegistry, _t as namedControllerActionSchema, a as isTinyOpenApiFakeMode, at as getProcedureInputSchemaRole, b as TinyOpenApiUserRole, bt as namedOpenApiResponseSchema, c as AnyContractRouter, ct as isContractProcedure, d as GenerateOpenApiFile, dt as isObject, et as getObjectPropertySchema, f as GenerateOpenApiFileOptions, ft as isProcedureMeta, g as JsonObject, gt as namedControllerActionInputDtoSchema, h as GenerateTinyOpenApiFileOptions, ht as modelSchemaNameEntries, i as getLocalInputPath, it as getPaginatedItemSchema, j as collectContractSchemaRoots, jt as toOpenAPI30Schema, k as asStringArray, kt as stripNoContentResponseBodies, l as AnySchema, lt as isNullSchema, m as GenerateOpenApiSpec, mt as modelSchemaExportName, nt as getOperationAction, o as normalizeWatchFolders, ot as getRobodevModuleRoles, p as GenerateOpenApiFileResult, pt as isZodSchema, q as generateORPCOpenAPISpec, r as createTinyOpenApiSourceRunner, rt as getOperationController, s as AclRule, st as getStringEnumValues, t as TinyOpenApiSourceRunnerConfig, tt as getOpenApiSchemaName, u as GenerateORPCOpenAPISpecOptions, ut as isNullableOnlySchema, v as ProcedureMeta, vt as namedOpenApiOutputSchema, w as applyOperationMeta, wt as resolveOpenApiOutputPath, x as ZodSchema, xt as namedOpenApiSchema, y as TinyOpenApiModule, yt as namedOpenApiRequestSchema, z as collectOperationTags } from "./openapi-source.runner-DIOvAX_R.mjs";
|
|
2
2
|
export { AclRule, AnyContractRouter, AnySchema, GenerateORPCOpenAPISpecOptions, GenerateOpenApiFile, GenerateOpenApiFileOptions, GenerateOpenApiFileResult, GenerateOpenApiSpec, GenerateTinyOpenApiFileOptions, JsonObject, OpenApiSchemaRegistry, ProcedureMeta, TinyOpenApiModule, type TinyOpenApiSourceRunnerConfig, TinyOpenApiUserRole, ZodSchema, addContractSchema, applyEnumExtensions, applyOperationMeta, applyPaginatedItemSchemas, applyParameterExtensions, applyRobodevModuleExtensions, applyRobodevUserRolesExtension, asStringArray, collectApiModelSchemaExports, collectContractSchemaRoots, collectContractSchemas, collectDbTableModelSchemaExport, collectDbTableModelSchemaExports, collectExtraSchemas, collectModelSchemaExports, collectModuleModelSchemaExports, collectOperationMeta, collectOperationTags, collectReachableModelSchemas, collectSchemaRegistryRoots, compactTagName, createModelSchemaNameGetter, createTinyOpenApiSourceRunner, defineOpenApiSchemas, findComponentEnumNames, findEnumNames, generateORPCOpenAPISpec, generateOpenApiFile, getComponentSchemas, getContractProcedureData, getDerivedOperationId, getModuleOpenApiController, getModuleOpenApiTag, getObjectPropertySchema, getOpenApiSchemaName, getOperationAction, getOperationController, getPaginatedItemSchema, getProcedureInputSchemaRole, getRobodevModuleRoles, getStringEnumValues, getLocalInputPath as getTinyOpenApiLocalInputPath, isContractProcedure, isNullSchema, isNullableOnlySchema, isObject, isProcedureMeta, isTinyOpenApiFakeMode, isZodSchema, modelSchemaExportName, modelSchemaNameEntries, namedControllerActionInputDtoSchema, namedControllerActionSchema, namedOpenApiOutputSchema, namedOpenApiRequestSchema, namedOpenApiResponseSchema, namedOpenApiSchema, normalizeWatchFolders as normalizeTinyOpenApiWatchFolders, operationKey, procedureSchemaName, resolveOpenApiOutputPath, routeHasPathParameters, schemaComponentRef, schemaExportName, sharedSchemaExportName, stripNoContentResponseBodies, toOpenAPI30Document, toOpenAPI30Schema, toOpenAPIAclRule, toPascalCase, visitZodSchema };
|
package/dist/tiny.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $ as namedControllerActionInputDtoSchema, A as generateORPCOpenAPISpec, B as getOperationController, C as collectReachableModelSchemas, D as defineOpenApiSchemas, E as createModelSchemaNameGetter, F as getModuleOpenApiController, G as isContractProcedure, H as getProcedureInputSchemaRole, I as getModuleOpenApiTag, J as isObject, K as isNullSchema, L as getObjectPropertySchema, M as getComponentSchemas, N as getContractProcedureData, O as findComponentEnumNames, P as getDerivedOperationId, Q as modelSchemaNameEntries, R as getOpenApiSchemaName, S as collectOperationTags, T as compactTagName, U as getRobodevModuleRoles, V as getPaginatedItemSchema, W as getStringEnumValues, X as isZodSchema, Y as isProcedureMeta, Z as modelSchemaExportName, _ as collectDbTableModelSchemaExports, _t as visitZodSchema, a as addContractSchema, at as operationKey, b as collectModuleModelSchemaExports, c as applyPaginatedItemSchemas, ct as routeHasPathParameters, d as applyRobodevUserRolesExtension, dt as sharedSchemaExportName, et as namedControllerActionSchema, f as asStringArray, ft as stripNoContentResponseBodies, g as collectDbTableModelSchemaExport, gt as toPascalCase, h as collectContractSchemas, ht as toOpenAPIAclRule, i as normalizeWatchFolders, it as namedOpenApiSchema, j as generateOpenApiFile, k as findEnumNames, l as applyParameterExtensions, lt as schemaComponentRef, m as collectContractSchemaRoots, mt as toOpenAPI30Schema, n as getLocalInputPath, nt as namedOpenApiRequestSchema, o as applyEnumExtensions, ot as procedureSchemaName, p as collectApiModelSchemaExports, pt as toOpenAPI30Document, q as isNullableOnlySchema, r as isTinyOpenApiFakeMode, rt as namedOpenApiResponseSchema, s as applyOperationMeta, st as resolveOpenApiOutputPath, t as createTinyOpenApiSourceRunner, tt as namedOpenApiOutputSchema, u as applyRobodevModuleExtensions, ut as schemaExportName, v as collectExtraSchemas, w as collectSchemaRegistryRoots, x as collectOperationMeta, y as collectModelSchemaExports, z as getOperationAction } from "./openapi-source.runner-
|
|
1
|
+
import { $ as namedControllerActionInputDtoSchema, A as generateORPCOpenAPISpec, B as getOperationController, C as collectReachableModelSchemas, D as defineOpenApiSchemas, E as createModelSchemaNameGetter, F as getModuleOpenApiController, G as isContractProcedure, H as getProcedureInputSchemaRole, I as getModuleOpenApiTag, J as isObject, K as isNullSchema, L as getObjectPropertySchema, M as getComponentSchemas, N as getContractProcedureData, O as findComponentEnumNames, P as getDerivedOperationId, Q as modelSchemaNameEntries, R as getOpenApiSchemaName, S as collectOperationTags, T as compactTagName, U as getRobodevModuleRoles, V as getPaginatedItemSchema, W as getStringEnumValues, X as isZodSchema, Y as isProcedureMeta, Z as modelSchemaExportName, _ as collectDbTableModelSchemaExports, _t as visitZodSchema, a as addContractSchema, at as operationKey, b as collectModuleModelSchemaExports, c as applyPaginatedItemSchemas, ct as routeHasPathParameters, d as applyRobodevUserRolesExtension, dt as sharedSchemaExportName, et as namedControllerActionSchema, f as asStringArray, ft as stripNoContentResponseBodies, g as collectDbTableModelSchemaExport, gt as toPascalCase, h as collectContractSchemas, ht as toOpenAPIAclRule, i as normalizeWatchFolders, it as namedOpenApiSchema, j as generateOpenApiFile, k as findEnumNames, l as applyParameterExtensions, lt as schemaComponentRef, m as collectContractSchemaRoots, mt as toOpenAPI30Schema, n as getLocalInputPath, nt as namedOpenApiRequestSchema, o as applyEnumExtensions, ot as procedureSchemaName, p as collectApiModelSchemaExports, pt as toOpenAPI30Document, q as isNullableOnlySchema, r as isTinyOpenApiFakeMode, rt as namedOpenApiResponseSchema, s as applyOperationMeta, st as resolveOpenApiOutputPath, t as createTinyOpenApiSourceRunner, tt as namedOpenApiOutputSchema, u as applyRobodevModuleExtensions, ut as schemaExportName, v as collectExtraSchemas, w as collectSchemaRegistryRoots, x as collectOperationMeta, y as collectModelSchemaExports, z as getOperationAction } from "./openapi-source.runner-DPUNTduQ.mjs";
|
|
2
2
|
export { addContractSchema, applyEnumExtensions, applyOperationMeta, applyPaginatedItemSchemas, applyParameterExtensions, applyRobodevModuleExtensions, applyRobodevUserRolesExtension, asStringArray, collectApiModelSchemaExports, collectContractSchemaRoots, collectContractSchemas, collectDbTableModelSchemaExport, collectDbTableModelSchemaExports, collectExtraSchemas, collectModelSchemaExports, collectModuleModelSchemaExports, collectOperationMeta, collectOperationTags, collectReachableModelSchemas, collectSchemaRegistryRoots, compactTagName, createModelSchemaNameGetter, createTinyOpenApiSourceRunner, defineOpenApiSchemas, findComponentEnumNames, findEnumNames, generateORPCOpenAPISpec, generateOpenApiFile, getComponentSchemas, getContractProcedureData, getDerivedOperationId, getModuleOpenApiController, getModuleOpenApiTag, getObjectPropertySchema, getOpenApiSchemaName, getOperationAction, getOperationController, getPaginatedItemSchema, getProcedureInputSchemaRole, getRobodevModuleRoles, getStringEnumValues, getLocalInputPath as getTinyOpenApiLocalInputPath, isContractProcedure, isNullSchema, isNullableOnlySchema, isObject, isProcedureMeta, isTinyOpenApiFakeMode, isZodSchema, modelSchemaExportName, modelSchemaNameEntries, namedControllerActionInputDtoSchema, namedControllerActionSchema, namedOpenApiOutputSchema, namedOpenApiRequestSchema, namedOpenApiResponseSchema, namedOpenApiSchema, normalizeWatchFolders as normalizeTinyOpenApiWatchFolders, operationKey, procedureSchemaName, resolveOpenApiOutputPath, routeHasPathParameters, schemaComponentRef, schemaExportName, sharedSchemaExportName, stripNoContentResponseBodies, toOpenAPI30Document, toOpenAPI30Schema, toOpenAPIAclRule, toPascalCase, visitZodSchema };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { s as GeneralErrorCodes, t as ApplicationException } from "./error-handling-LPEPQV1V.mjs";
|
|
2
|
+
import { i as QueryModule, t as InvalidationMap } from "./queryConfig.context-aO4QOLru.mjs";
|
|
3
|
+
import { InfiniteData, QueryKey, UseInfiniteQueryOptions, UseMutationOptions, UseQueryOptions } from "@tanstack/react-query";
|
|
4
|
+
//#region src/lib/react-query.types.d.ts
|
|
5
|
+
type Function = (...args: never) => unknown;
|
|
6
|
+
type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N;
|
|
7
|
+
type IsAny<T> = IfAny<T, true, never>;
|
|
8
|
+
type IsUnknown<T, Y, N = T> = IsAny<T> extends never ? (unknown extends T ? Y : N) : N;
|
|
9
|
+
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">;
|
|
10
|
+
type AppMutationOptions<TFunction extends Function, TVariables = void, TData = Awaited<ReturnType<TFunction>>, TErrorCodes = GeneralErrorCodes> = Omit<UseMutationOptions<TData, ApplicationException<TErrorCodes>, TVariables>, "mutationKey" | "mutationFn">;
|
|
11
|
+
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">;
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/lib/react-query/useMutationEffects.d.ts
|
|
14
|
+
interface MutationEffectsOptions<TQueryModule extends QueryModule = QueryModule> {
|
|
15
|
+
invalidateCurrentModule?: boolean;
|
|
16
|
+
crossTabInvalidation?: boolean;
|
|
17
|
+
invalidationMap?: InvalidationMap<TQueryModule>;
|
|
18
|
+
invalidateModules?: QueryModule[];
|
|
19
|
+
invalidateKeys?: QueryKey[];
|
|
20
|
+
preferUpdate?: boolean;
|
|
21
|
+
}
|
|
22
|
+
interface UseMutationEffectsProps<TQueryModule extends QueryModule = QueryModule> {
|
|
23
|
+
currentModule: TQueryModule;
|
|
24
|
+
}
|
|
25
|
+
declare function useMutationEffects<TQueryModule extends QueryModule = QueryModule>({ currentModule }: UseMutationEffectsProps<TQueryModule>): {
|
|
26
|
+
runMutationEffects: <TData, TVariables>(data: TData, variables: TVariables, options?: MutationEffectsOptions<TQueryModule>, updateKeys?: QueryKey[]) => Promise<void>;
|
|
27
|
+
};
|
|
28
|
+
//#endregion
|
|
29
|
+
export { AppQueryOptions as a, AppMutationOptions as i, useMutationEffects as n, AppInfiniteQueryOptions as r, MutationEffectsOptions as t };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { t as OpenApiQueryConfig } from "./queryConfig.context-CldQ5YL9.mjs";
|
|
2
|
+
import { useCallback, useEffect } from "react";
|
|
3
|
+
import { useQueryClient } from "@tanstack/react-query";
|
|
4
|
+
//#region src/lib/react-query/cross-tab-invalidation.ts
|
|
5
|
+
const CROSS_TAB_INVALIDATE_KEY = "__rq_invalidate__";
|
|
6
|
+
const broadcastQueryInvalidation = (queryKeys) => {
|
|
7
|
+
localStorage.setItem(CROSS_TAB_INVALIDATE_KEY, JSON.stringify({
|
|
8
|
+
keys: queryKeys,
|
|
9
|
+
timestamp: Date.now()
|
|
10
|
+
}));
|
|
11
|
+
};
|
|
12
|
+
let isListenerSetUp = false;
|
|
13
|
+
const setupCrossTabListener = (queryClient) => {
|
|
14
|
+
if (isListenerSetUp) return;
|
|
15
|
+
isListenerSetUp = true;
|
|
16
|
+
window.addEventListener("storage", (e) => {
|
|
17
|
+
if (e.key !== CROSS_TAB_INVALIDATE_KEY || !e.newValue) return;
|
|
18
|
+
try {
|
|
19
|
+
const { keys } = JSON.parse(e.newValue);
|
|
20
|
+
for (const queryKey of keys) queryClient.invalidateQueries({ queryKey });
|
|
21
|
+
} catch {}
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/lib/react-query/useMutationEffects.ts
|
|
26
|
+
function useMutationEffects({ currentModule }) {
|
|
27
|
+
const queryClient = useQueryClient();
|
|
28
|
+
const config = OpenApiQueryConfig.useConfig();
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (!config.crossTabInvalidation) return;
|
|
31
|
+
setupCrossTabListener(queryClient);
|
|
32
|
+
}, [queryClient, config.crossTabInvalidation]);
|
|
33
|
+
return { runMutationEffects: useCallback(async (data, variables, options = {}, updateKeys) => {
|
|
34
|
+
const { invalidateCurrentModule, invalidationMap, invalidateModules, invalidateKeys, preferUpdate } = options;
|
|
35
|
+
const shouldUpdate = preferUpdate ?? config.preferUpdate ?? false;
|
|
36
|
+
const shouldInvalidateCurrentModule = invalidateCurrentModule ?? config.invalidateCurrentModule ?? true;
|
|
37
|
+
const isQueryKeyEqual = (keyA, keyB) => keyA.length === keyB.length && keyA.every((item, index) => item === keyB[index]);
|
|
38
|
+
const isQueryKeyPrefix = (queryKey, prefixKey) => prefixKey.length <= queryKey.length && prefixKey.every((item, index) => item === queryKey[index]);
|
|
39
|
+
const mappedInvalidationKeys = invalidationMap?.[currentModule]?.(data, variables) ?? config.invalidationMap?.[currentModule]?.(data, variables);
|
|
40
|
+
const shouldInvalidateQuery = (queryKey) => {
|
|
41
|
+
const isUpdateKey = updateKeys?.some((key) => isQueryKeyEqual(queryKey, key));
|
|
42
|
+
if (shouldUpdate && isUpdateKey) return false;
|
|
43
|
+
const isCurrentModule = shouldInvalidateCurrentModule && queryKey[0] === currentModule;
|
|
44
|
+
const isInvalidateModule = !!invalidateModules && invalidateModules.some((module) => queryKey[0] === module);
|
|
45
|
+
const isInvalidateKey = !!invalidateKeys && invalidateKeys.some((key) => isQueryKeyPrefix(queryKey, key));
|
|
46
|
+
const isMappedKey = !!mappedInvalidationKeys && mappedInvalidationKeys.some((key) => isQueryKeyPrefix(queryKey, key));
|
|
47
|
+
return isCurrentModule || isInvalidateModule || isInvalidateKey || isMappedKey;
|
|
48
|
+
};
|
|
49
|
+
const invalidatedQueryKeys = [];
|
|
50
|
+
const shouldBroadcast = options.crossTabInvalidation ?? config.crossTabInvalidation;
|
|
51
|
+
queryClient.invalidateQueries({ predicate: ({ queryKey }) => {
|
|
52
|
+
const shouldInvalidate = shouldInvalidateQuery(queryKey);
|
|
53
|
+
if (shouldInvalidate && shouldBroadcast) invalidatedQueryKeys.push([...queryKey]);
|
|
54
|
+
return shouldInvalidate;
|
|
55
|
+
} });
|
|
56
|
+
if (shouldBroadcast && invalidatedQueryKeys.length > 0) broadcastQueryInvalidation(invalidatedQueryKeys);
|
|
57
|
+
if (shouldUpdate && updateKeys) updateKeys.map((queryKey) => queryClient.setQueryData(queryKey, data));
|
|
58
|
+
}, [
|
|
59
|
+
queryClient,
|
|
60
|
+
currentModule,
|
|
61
|
+
config.preferUpdate,
|
|
62
|
+
config.invalidateCurrentModule,
|
|
63
|
+
config.invalidationMap,
|
|
64
|
+
config.crossTabInvalidation
|
|
65
|
+
]) };
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
export { useMutationEffects as t };
|
package/dist/vite.d.mts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { r as GenerateFileFormatter } from "./options-
|
|
2
|
-
import { t as OpenAPICodegenConfig } from "./config-
|
|
3
|
-
import { d as GenerateOpenApiFile, m as GenerateOpenApiSpec, n as TinyOpenApiSpecModuleConfig } from "./openapi-source.runner-
|
|
1
|
+
import { r as GenerateFileFormatter } from "./options-X0zju7gw.mjs";
|
|
2
|
+
import { t as OpenAPICodegenConfig } from "./config-CiLFKLAY.mjs";
|
|
3
|
+
import { d as GenerateOpenApiFile, m as GenerateOpenApiSpec, n as TinyOpenApiSpecModuleConfig } from "./openapi-source.runner-DIOvAX_R.mjs";
|
|
4
4
|
import { Plugin, PluginOption } from "vite";
|
|
5
|
-
|
|
6
5
|
//#region src/plugins/openapi-codegen.runner.d.ts
|
|
7
6
|
type OpenApiCodegenPluginConfig = OpenAPICodegenConfig & {
|
|
8
7
|
formatGeneratedFile?: GenerateFileFormatter;
|
package/dist/vite.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as createOpenApiCodegenRunner } from "./openapi-codegen.runner-
|
|
2
|
-
import { i as normalizeWatchFolders, r as isTinyOpenApiFakeMode, t as createTinyOpenApiSourceRunner } from "./openapi-source.runner-
|
|
1
|
+
import { t as createOpenApiCodegenRunner } from "./openapi-codegen.runner-BpykceyD.mjs";
|
|
2
|
+
import { i as normalizeWatchFolders, r as isTinyOpenApiFakeMode, t as createTinyOpenApiSourceRunner } from "./openapi-source.runner-DPUNTduQ.mjs";
|
|
3
3
|
import path from "path";
|
|
4
4
|
//#region src/vite/openapi-codegen.plugin.ts
|
|
5
5
|
function openApiCodegen(config) {
|
|
@@ -36,7 +36,7 @@ function openApiCodegen(config) {
|
|
|
36
36
|
}
|
|
37
37
|
//#endregion
|
|
38
38
|
//#region src/vite/tiny-openapi-codegen.plugin.ts
|
|
39
|
-
const watchedEvents = new Set([
|
|
39
|
+
const watchedEvents = /* @__PURE__ */ new Set([
|
|
40
40
|
"add",
|
|
41
41
|
"change",
|
|
42
42
|
"unlink"
|
|
@@ -75,7 +75,8 @@ function tinyOpenApiCodegenPlugin(codegenConfig, options) {
|
|
|
75
75
|
}, debounceMs);
|
|
76
76
|
};
|
|
77
77
|
const setupWatcher = (server) => {
|
|
78
|
-
const
|
|
78
|
+
const root = resolvedConfig?.root ?? server.config.root;
|
|
79
|
+
const watchFolders = normalizeWatchFolders(root, options.watchFolders);
|
|
79
80
|
server.watcher.add(watchFolders);
|
|
80
81
|
server.watcher.on("all", (event, changedPath) => {
|
|
81
82
|
if (watchedEvents.has(event) && isPathInWatchFolders(changedPath, watchFolders)) scheduleGenerate(server);
|