@povio/openapi-codegen-cli 3.1.1 → 3.2.0-rc.11
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 +63 -15
- package/dist/AuthGuard-GbtTDXs0.d.mts +32 -0
- package/dist/AuthGuard-qpAtHaBz.mjs +24 -0
- package/dist/acl.d.mts +6 -20
- package/dist/acl.mjs +8 -13
- package/dist/{auth.context-Bu5KW2sI.mjs → auth.context-COWO6ssl.mjs} +1 -21
- 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-BU7wVf7U.d.mts → config-DgrOddSC.d.mts} +1 -2
- package/dist/config.d.mts +4 -0
- package/dist/config.mjs +5 -0
- package/dist/{error-handling-DSI86D3u.mjs → error-handling-BeydPL7s.mjs} +21 -51
- package/dist/{error-handling-D-mHJ60d.d.mts → error-handling-LPEPQV1V.d.mts} +3 -42
- package/dist/errors.d.mts +3 -0
- package/dist/errors.mjs +2 -0
- package/dist/generate.runner-CD7mlcJ4.mjs +184 -0
- package/dist/generate.utils-CT-LA-gX.cjs +2267 -0
- package/dist/generateCodeFromOpenAPIDoc-D9W5BtAt.mjs +2097 -0
- package/dist/{generateCodeFromOpenAPIDoc-DseBECa-.mjs → generateCodeFromOpenAPIDoc-DhI7CHeh.cjs} +1349 -2344
- package/dist/generator.d.mts +3 -10
- package/dist/generator.mjs +9 -9
- package/dist/getDataFromOpenAPIDoc-D8w0QElH.mjs +2011 -0
- package/dist/i18n-B_brQh4X.d.mts +38 -0
- package/dist/i18n-D-FesqFb.mjs +36 -0
- package/dist/index.d.mts +12 -200
- package/dist/index.mjs +12 -264
- package/dist/metro.cjs +114 -4959
- package/dist/metro.d.mts +3 -4
- package/dist/metro.mjs +4 -9
- package/dist/native-bindings-BTQGSGhU.mjs +1480 -0
- package/dist/native-rest-interceptor-CAWR8H5Y.mjs +208 -0
- package/dist/native-rest-interceptor-Cz6saoq5.d.mts +46 -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-Co_bG00_.mjs → openapi-codegen.runner-C4TIXQNx.mjs} +4 -5
- package/dist/{openapi-source.runner-wLs5vqw6.mjs → openapi-source.runner-BZ6ZLgRO.mjs} +19 -10
- package/dist/{openapi-source.runner-BSIrB6ny.d.mts → openapi-source.runner-ykstqlPC.d.mts} +2 -8
- package/dist/{options-CE4Koxof.d.mts → options-KPf-Fti5.d.mts} +6 -1
- package/dist/query.d.mts +3 -0
- package/dist/query.mjs +3 -0
- package/dist/queryConfig.context-CRJOgf19.d.mts +22 -0
- package/dist/queryConfig.context-CldQ5YL9.mjs +34 -0
- package/dist/rest-client-CQyFvqYC.d.mts +55 -0
- package/dist/rest-interceptor-D5NCNTm1.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-rezWAIYL.d.mts +10 -0
- package/dist/router.context-EPlMBk3G.mjs +21 -0
- package/dist/sh.d.mts +1 -1
- package/dist/sh.mjs +41 -71
- package/dist/tiny.d.mts +1 -3
- package/dist/tiny.mjs +2 -3
- package/dist/useMutationEffects-DIdL8tlx.d.mts +29 -0
- package/dist/useMutationEffects-PB1fvKWM.mjs +68 -0
- package/dist/vite.d.mts +3 -4
- package/dist/vite.mjs +6 -10
- 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 +2 -4
- package/package.json +73 -26
- package/dist/generate.runner-C1HrS_9G.mjs +0 -90
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { i as SharedErrorHandler } from "./error-handling-BeydPL7s.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,10 @@
|
|
|
1
|
+
import { AxiosError, AxiosResponseHeaders } from "axios";
|
|
2
|
+
//#region src/lib/rest/rest.utils.d.ts
|
|
3
|
+
declare namespace RestUtils {
|
|
4
|
+
const extractServerResponseCode: (e: unknown) => string | number | null;
|
|
5
|
+
const doesServerErrorMessageContain: (e: AxiosError, text: string) => boolean;
|
|
6
|
+
const extractServerErrorMessage: (e: unknown) => string | null;
|
|
7
|
+
const extractContentDispositionFilename: (headers: AxiosResponseHeaders) => string | undefined;
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
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,20 +1,14 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { i as VALIDATION_ERROR_TYPE_TITLE, n as groupByType, t as getDataFromOpenAPIDoc } from "./getDataFromOpenAPIDoc-D8w0QElH.mjs";
|
|
3
|
+
import { D as getTagFileName, Wn as Profiler, r as getOutputFileName } from "./native-bindings-BTQGSGhU.mjs";
|
|
4
|
+
import { n as runGenerate, r as resolveConfig, t as getOpenApiDoc } from "./generate.runner-CD7mlcJ4.mjs";
|
|
5
5
|
import yargs from "yargs";
|
|
6
6
|
import { hideBin } from "yargs/helpers";
|
|
7
7
|
import { styleText } from "node:util";
|
|
8
|
-
import fs
|
|
8
|
+
import fs from "fs";
|
|
9
9
|
import "reflect-metadata";
|
|
10
10
|
import path from "path";
|
|
11
|
-
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
12
11
|
import { exec } from "child_process";
|
|
13
|
-
|
|
14
|
-
//#region \0rolldown/runtime.js
|
|
15
|
-
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
16
|
-
|
|
17
|
-
//#endregion
|
|
18
12
|
//#region src/helpers/cli.helper.ts
|
|
19
13
|
function log(message) {
|
|
20
14
|
console.log(message);
|
|
@@ -32,16 +26,14 @@ function logError(error, message) {
|
|
|
32
26
|
function logBanner(message) {
|
|
33
27
|
console.log(styleText("bgYellow", `==== ${message} ====`));
|
|
34
28
|
}
|
|
35
|
-
|
|
36
29
|
//#endregion
|
|
37
30
|
//#region src/helpers/version.helper.ts
|
|
38
31
|
/**
|
|
39
32
|
* Fetch the version from package.json
|
|
40
33
|
*/
|
|
41
34
|
function getVersion() {
|
|
42
|
-
return "3.
|
|
35
|
+
return "3.2.0-rc.11";
|
|
43
36
|
}
|
|
44
|
-
|
|
45
37
|
//#endregion
|
|
46
38
|
//#region src/helpers/yargs.helper.ts
|
|
47
39
|
const optionsKey = Symbol("options_key");
|
|
@@ -83,7 +75,6 @@ async function loadYargsConfig(cls, _argv) {
|
|
|
83
75
|
for (const [name, o] of Object.entries(getYargsOption(cls))) argv[name] = _argv[name] ?? o.default;
|
|
84
76
|
return argv;
|
|
85
77
|
}
|
|
86
|
-
|
|
87
78
|
//#endregion
|
|
88
79
|
//#region src/generators/checkOpenAPIDoc.ts
|
|
89
80
|
function checkOpenAPIDoc(openApiDoc, options) {
|
|
@@ -101,9 +92,9 @@ function checkOpenAPIDoc(openApiDoc, options) {
|
|
|
101
92
|
}
|
|
102
93
|
function getOutputFileNames(tag, options) {
|
|
103
94
|
return [
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
95
|
+
"models",
|
|
96
|
+
"endpoints",
|
|
97
|
+
"queries"
|
|
107
98
|
].map((type) => getOutputFileName({
|
|
108
99
|
output: options.output,
|
|
109
100
|
fileName: getTagFileName({
|
|
@@ -113,7 +104,6 @@ function getOutputFileNames(tag, options) {
|
|
|
113
104
|
})
|
|
114
105
|
}));
|
|
115
106
|
}
|
|
116
|
-
|
|
117
107
|
//#endregion
|
|
118
108
|
//#region src/helpers/config.helper.ts
|
|
119
109
|
const CONFIG_FILE_NAMES = ["openapi-codegen.config.mjs", "openapi-codegen.config.ts"];
|
|
@@ -136,87 +126,50 @@ async function loadConfigFromPath(filePath) {
|
|
|
136
126
|
const ext = path.extname(absolutePath).toLowerCase();
|
|
137
127
|
if (ext === ".mjs") return loadMjsConfig(absolutePath);
|
|
138
128
|
if (ext !== ".ts") throw new Error(`Only ESM (.mjs) and TypeScript (.ts) configuration files are supported. Found: ${ext}`);
|
|
139
|
-
return
|
|
129
|
+
return loadModuleConfig(absolutePath, "TypeScript");
|
|
140
130
|
}
|
|
141
131
|
async function loadMjsConfig(filePath) {
|
|
132
|
+
return loadModuleConfig(filePath, "ESM");
|
|
133
|
+
}
|
|
134
|
+
async function loadModuleConfig(filePath, format) {
|
|
142
135
|
const imported = await import(`${pathToFileURL(filePath).href}?t=${Date.now()}`);
|
|
143
|
-
if (!imported.default) throw new Error(
|
|
136
|
+
if (!imported.default) throw new Error(`${format} config must have a default export: ${filePath}`);
|
|
144
137
|
return imported.default;
|
|
145
138
|
}
|
|
146
|
-
let importFresh;
|
|
147
|
-
const loadJsSync = function loadJsSync(filepath) {
|
|
148
|
-
if (importFresh === void 0) importFresh = __require("import-fresh");
|
|
149
|
-
return importFresh(filepath);
|
|
150
|
-
};
|
|
151
|
-
let typescript;
|
|
152
|
-
async function loadTsConfig(filePath) {
|
|
153
|
-
if (typescript === void 0) typescript = __require("typescript");
|
|
154
|
-
const transpiledFilepath = `${filePath.slice(0, -2)}cjs`;
|
|
155
|
-
try {
|
|
156
|
-
const tsConfig = resolveTsConfig(path.dirname(filePath)) ?? {};
|
|
157
|
-
tsConfig.compilerOptions = Object.assign({}, tsConfig.compilerOptions, {
|
|
158
|
-
module: typescript.ModuleKind.NodeNext,
|
|
159
|
-
moduleResolution: typescript.ModuleResolutionKind.NodeNext,
|
|
160
|
-
target: typescript.ScriptTarget.ES2022,
|
|
161
|
-
noEmit: false
|
|
162
|
-
});
|
|
163
|
-
const fileContent = fs.readFileSync(filePath, "utf-8");
|
|
164
|
-
const transpiledFileContent = typescript.transpileModule(fileContent, tsConfig).outputText;
|
|
165
|
-
writeFileSync(transpiledFilepath, transpiledFileContent);
|
|
166
|
-
return loadJsSync(transpiledFilepath).default;
|
|
167
|
-
} catch (error) {
|
|
168
|
-
error.message = `TypeScript Error in ${filePath}:\n${error.message}`;
|
|
169
|
-
throw error;
|
|
170
|
-
} finally {
|
|
171
|
-
if (existsSync(transpiledFilepath)) rmSync(transpiledFilepath);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
function resolveTsConfig(directory) {
|
|
175
|
-
const filePath = typescript.findConfigFile(directory, (fileName) => {
|
|
176
|
-
return typescript.sys.fileExists(fileName);
|
|
177
|
-
});
|
|
178
|
-
if (filePath === void 0) return;
|
|
179
|
-
const { config, error } = typescript.readConfigFile(filePath, (path) => typescript.sys.readFile(path));
|
|
180
|
-
if (error) throw new Error(`Error in ${filePath}: ${error.messageText.toString()}`);
|
|
181
|
-
return config;
|
|
182
|
-
}
|
|
183
139
|
function pathToFileURL(filePath) {
|
|
184
140
|
const normalizedPath = path.resolve(filePath).replace(/\\/g, "/");
|
|
185
141
|
return { href: normalizedPath.startsWith("/") ? `file://${normalizedPath}` : `file:///${normalizedPath}` };
|
|
186
142
|
}
|
|
187
|
-
|
|
188
143
|
//#endregion
|
|
189
144
|
//#region src/commands/check.ts
|
|
190
145
|
async function check({ verbose, config: configParam, includeTags: _includeTagsParam, excludeTags: _excludeTagsParam, ...params }) {
|
|
191
146
|
const start = Date.now();
|
|
192
147
|
if (verbose) logInfo("Resolving config...");
|
|
148
|
+
const fileConfig = await loadConfig(configParam);
|
|
193
149
|
const config = resolveConfig({
|
|
194
|
-
fileConfig
|
|
150
|
+
fileConfig,
|
|
195
151
|
params
|
|
196
152
|
});
|
|
197
153
|
if (verbose) logInfo("Parsing OpenAPI spec...");
|
|
198
|
-
const openApiDoc = await
|
|
154
|
+
const openApiDoc = await getOpenApiDoc(config.input);
|
|
199
155
|
if (verbose) logInfo("Running check...");
|
|
200
156
|
const errorMessages = checkOpenAPIDoc(openApiDoc, config);
|
|
201
157
|
if (errorMessages.length === 0) logSuccess(`Time: ${Date.now() - start}ms`);
|
|
202
158
|
else throw new Error(`Found ${errorMessages.length} issues. Time: ${Date.now() - start}ms`);
|
|
203
159
|
}
|
|
204
|
-
|
|
205
160
|
//#endregion
|
|
206
|
-
//#region \0@oxc-project+runtime@0.
|
|
161
|
+
//#region \0@oxc-project+runtime@0.142.0/helpers/esm/decorateMetadata.js
|
|
207
162
|
function __decorateMetadata(k, v) {
|
|
208
163
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
209
164
|
}
|
|
210
|
-
|
|
211
165
|
//#endregion
|
|
212
|
-
//#region \0@oxc-project+runtime@0.
|
|
166
|
+
//#region \0@oxc-project+runtime@0.142.0/helpers/esm/decorate.js
|
|
213
167
|
function __decorate(decorators, target, key, desc) {
|
|
214
168
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
215
169
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
216
170
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
217
171
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
218
172
|
}
|
|
219
|
-
|
|
220
173
|
//#endregion
|
|
221
174
|
//#region src/commands/check.command.ts
|
|
222
175
|
var CheckOptions = class {
|
|
@@ -259,7 +212,6 @@ const command$1 = {
|
|
|
259
212
|
return check(argv);
|
|
260
213
|
}
|
|
261
214
|
};
|
|
262
|
-
|
|
263
215
|
//#endregion
|
|
264
216
|
//#region src/commands/generate.ts
|
|
265
217
|
async function generate({ prettier, verbose, config: configParam, ...params }) {
|
|
@@ -293,7 +245,6 @@ function execPrettier({ output, verbose }) {
|
|
|
293
245
|
else logSuccess("Prettier finished.");
|
|
294
246
|
});
|
|
295
247
|
}
|
|
296
|
-
|
|
297
248
|
//#endregion
|
|
298
249
|
//#region src/commands/generate.command.ts
|
|
299
250
|
var GenerateOptions = class {
|
|
@@ -303,6 +254,7 @@ var GenerateOptions = class {
|
|
|
303
254
|
clearOutput;
|
|
304
255
|
incremental;
|
|
305
256
|
tsNamespaces;
|
|
257
|
+
treeShakeableNamespaces;
|
|
306
258
|
tsPath;
|
|
307
259
|
splitByTags;
|
|
308
260
|
defaultTag;
|
|
@@ -313,6 +265,11 @@ var GenerateOptions = class {
|
|
|
313
265
|
importPath;
|
|
314
266
|
extractEnums;
|
|
315
267
|
modelsInCommon;
|
|
268
|
+
modelsInModules;
|
|
269
|
+
zodImportPath;
|
|
270
|
+
restClient;
|
|
271
|
+
mutationEffectsImportPath;
|
|
272
|
+
aclCheckImportPath;
|
|
316
273
|
removeOperationPrefixEndingWith;
|
|
317
274
|
acl;
|
|
318
275
|
checkAcl;
|
|
@@ -347,6 +304,10 @@ __decorate([YargOption({
|
|
|
347
304
|
envAlias: "tsNamespaces",
|
|
348
305
|
type: "boolean"
|
|
349
306
|
}), __decorateMetadata("design:type", Boolean)], GenerateOptions.prototype, "tsNamespaces", void 0);
|
|
307
|
+
__decorate([YargOption({
|
|
308
|
+
envAlias: "treeShakeableNamespaces",
|
|
309
|
+
type: "boolean"
|
|
310
|
+
}), __decorateMetadata("design:type", Boolean)], GenerateOptions.prototype, "treeShakeableNamespaces", void 0);
|
|
350
311
|
__decorate([YargOption({ envAlias: "tsPath" }), __decorateMetadata("design:type", String)], GenerateOptions.prototype, "tsPath", void 0);
|
|
351
312
|
__decorate([YargOption({
|
|
352
313
|
envAlias: "splitByTags",
|
|
@@ -369,6 +330,17 @@ __decorate([YargOption({
|
|
|
369
330
|
envAlias: "modelsInCommon",
|
|
370
331
|
type: "boolean"
|
|
371
332
|
}), __decorateMetadata("design:type", Boolean)], GenerateOptions.prototype, "modelsInCommon", void 0);
|
|
333
|
+
__decorate([YargOption({
|
|
334
|
+
envAlias: "modelsInModules",
|
|
335
|
+
type: "boolean"
|
|
336
|
+
}), __decorateMetadata("design:type", Boolean)], GenerateOptions.prototype, "modelsInModules", void 0);
|
|
337
|
+
__decorate([YargOption({ envAlias: "zodImportPath" }), __decorateMetadata("design:type", String)], GenerateOptions.prototype, "zodImportPath", void 0);
|
|
338
|
+
__decorate([YargOption({
|
|
339
|
+
envAlias: "restClient",
|
|
340
|
+
choices: ["axios", "native"]
|
|
341
|
+
}), __decorateMetadata("design:type", String)], GenerateOptions.prototype, "restClient", void 0);
|
|
342
|
+
__decorate([YargOption({ envAlias: "mutationEffectsImportPath" }), __decorateMetadata("design:type", String)], GenerateOptions.prototype, "mutationEffectsImportPath", void 0);
|
|
343
|
+
__decorate([YargOption({ envAlias: "aclCheckImportPath" }), __decorateMetadata("design:type", String)], GenerateOptions.prototype, "aclCheckImportPath", void 0);
|
|
372
344
|
__decorate([YargOption({ envAlias: "removeOperationPrefixEndingWith" }), __decorateMetadata("design:type", String)], GenerateOptions.prototype, "removeOperationPrefixEndingWith", void 0);
|
|
373
345
|
__decorate([YargOption({
|
|
374
346
|
envAlias: "acl",
|
|
@@ -441,7 +413,6 @@ const command = {
|
|
|
441
413
|
return generate(argv);
|
|
442
414
|
}
|
|
443
415
|
};
|
|
444
|
-
|
|
445
416
|
//#endregion
|
|
446
417
|
//#region src/sh.ts
|
|
447
418
|
yargs(hideBin(process.argv)).version(getVersion() || "unknown").scriptName("openapi-codegen").command(command).command(command$1).help().demandCommand(1).strictCommands(true).showHelpOnFail(true).fail((msg, err) => {
|
|
@@ -450,6 +421,5 @@ yargs(hideBin(process.argv)).version(getVersion() || "unknown").scriptName("open
|
|
|
450
421
|
logInfo("Use '--help' for more info");
|
|
451
422
|
process.exit(1);
|
|
452
423
|
}).parse();
|
|
453
|
-
|
|
454
424
|
//#endregion
|
|
455
|
-
export {
|
|
425
|
+
export {};
|
package/dist/tiny.d.mts
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import "./config-BU7wVf7U.mjs";
|
|
3
|
-
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-BSIrB6ny.mjs";
|
|
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-ykstqlPC.mjs";
|
|
4
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,3 +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-
|
|
2
|
-
|
|
3
|
-
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 };
|
|
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-BZ6ZLgRO.mjs";
|
|
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-CRJOgf19.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: any) => any;
|
|
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-KPf-Fti5.mjs";
|
|
2
|
+
import { t as OpenAPICodegenConfig } from "./config-DgrOddSC.mjs";
|
|
3
|
+
import { d as GenerateOpenApiFile, m as GenerateOpenApiSpec, n as TinyOpenApiSpecModuleConfig } from "./openapi-source.runner-ykstqlPC.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;
|