@povio/openapi-codegen-cli 3.3.0-rc.2 → 4.0.0-rc.2

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.
Files changed (68) hide show
  1. package/README.md +114 -9
  2. package/dist/AuthGuard-GbtTDXs0.d.mts +32 -0
  3. package/dist/AuthGuard-qpAtHaBz.mjs +24 -0
  4. package/dist/acl.d.mts +6 -19
  5. package/dist/acl.mjs +7 -7
  6. package/dist/{auth.context-BAz8frX9.mjs → auth.context-COWO6ssl.mjs} +1 -18
  7. package/dist/auth.d.mts +2 -0
  8. package/dist/auth.mjs +3 -0
  9. package/dist/axios.d.mts +2 -0
  10. package/dist/axios.mjs +2 -0
  11. package/dist/{config-BQqze8rU.d.mts → config-CiLFKLAY.d.mts} +1 -2
  12. package/dist/config.d.mts +4 -0
  13. package/dist/config.mjs +5 -0
  14. package/dist/{error-handling-D6ZYITQ3.d.mts → error-handling-BpAQHWrU.d.mts} +5 -42
  15. package/dist/{error-handling-CsnufAil.mjs → error-handling-uS0DgYUR.mjs} +23 -47
  16. package/dist/errors.d.mts +3 -0
  17. package/dist/errors.mjs +2 -0
  18. package/dist/generate.runner-BuSwqeff.mjs +1667 -0
  19. package/dist/generate.utils-BJxdEik8.cjs +2269 -0
  20. package/dist/generateCodeFromOpenAPIDoc-B68pSpWW.mjs +2122 -0
  21. package/dist/{generateCodeFromOpenAPIDoc-SYuVswEJ.mjs → generateCodeFromOpenAPIDoc-Cc34c6zl.cjs} +1380 -2262
  22. package/dist/generator.d.mts +3 -10
  23. package/dist/generator.mjs +6 -4
  24. package/dist/getDataFromOpenAPIDoc-B_URkLm6.mjs +2016 -0
  25. package/dist/i18n-B_brQh4X.d.mts +38 -0
  26. package/dist/i18n-D-FesqFb.mjs +36 -0
  27. package/dist/index.d.mts +12 -198
  28. package/dist/index.mjs +12 -256
  29. package/dist/metro.cjs +117 -4862
  30. package/dist/metro.d.mts +3 -4
  31. package/dist/metro.mjs +3 -3
  32. package/dist/native-rest-interceptor-DZxdDcpz.d.mts +49 -0
  33. package/dist/native-rest-interceptor-Np4Ov54n.mjs +215 -0
  34. package/dist/native.d.mts +3 -0
  35. package/dist/native.mjs +3 -0
  36. package/dist/openapi-codegen-native-darwin-arm64.node +0 -0
  37. package/dist/openapi-codegen-native-linux-x64.node +0 -0
  38. package/dist/openapi-codegen-native-win32-x64.node +0 -0
  39. package/dist/{openapi-codegen.runner-CCXQsUum.mjs → openapi-codegen.runner-G25v_q9z.mjs} +2 -2
  40. package/dist/{openapi-source.runner-B6KKrXw7.d.mts → openapi-source.runner-DIOvAX_R.d.mts} +2 -8
  41. package/dist/{openapi-source.runner-8kCe-g9S.mjs → openapi-source.runner-DPUNTduQ.mjs} +25 -11
  42. package/dist/{options-DdQJ9BSc.d.mts → options-X0zju7gw.d.mts} +8 -1
  43. package/dist/query.d.mts +3 -0
  44. package/dist/query.mjs +3 -0
  45. package/dist/queryConfig.context-CldQ5YL9.mjs +34 -0
  46. package/dist/queryConfig.context-yl7x_NdW.d.mts +48 -0
  47. package/dist/rest-client-CbS77dei.d.mts +55 -0
  48. package/dist/rest-interceptor-Dm9DFErh.mjs +115 -0
  49. package/dist/rest-transport.types-DM5-qyOJ.d.mts +66 -0
  50. package/dist/rest-transport.types-DxitRtsB.mjs +11 -0
  51. package/dist/rest.d.mts +2 -0
  52. package/dist/rest.mjs +2 -0
  53. package/dist/rest.utils-DpiFIdhF.d.mts +9 -0
  54. package/dist/router.context-EPlMBk3G.mjs +21 -0
  55. package/dist/sh.d.mts +1 -1
  56. package/dist/sh.mjs +52 -59
  57. package/dist/tiny.d.mts +1 -1
  58. package/dist/tiny.mjs +1 -1
  59. package/dist/useMutationEffects-CjGlHDg_.d.mts +29 -0
  60. package/dist/useMutationEffects-PB1fvKWM.mjs +68 -0
  61. package/dist/vite.d.mts +3 -4
  62. package/dist/vite.mjs +5 -4
  63. package/dist/workspace.context-XWvQ_7Hg.mjs +26 -0
  64. package/dist/workspace.context-isVY9ves.d.mts +23 -0
  65. package/dist/zod.d.mts +2 -7
  66. package/dist/zod.mjs +1 -1
  67. package/package.json +70 -22
  68. package/dist/generate.runner-B0Zm3pIl.mjs +0 -87
package/dist/metro.d.mts CHANGED
@@ -1,8 +1,7 @@
1
- import { r as GenerateFileFormatter } from "./options-DdQJ9BSc.mjs";
2
- import { t as OpenAPICodegenConfig } from "./config-BQqze8rU.mjs";
3
- import { d as GenerateOpenApiFile, m as GenerateOpenApiSpec, n as TinyOpenApiSpecModuleConfig } from "./openapi-source.runner-B6KKrXw7.mjs";
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 { IncomingMessage, ServerResponse } from "http";
5
-
6
5
  //#region src/metro/openapi-codegen.plugin.d.ts
7
6
  type OpenApiCodegenMetroConfig = OpenAPICodegenConfig & {
8
7
  formatGeneratedFile?: GenerateFileFormatter;
package/dist/metro.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { t as createOpenApiCodegenRunner } from "./openapi-codegen.runner-CCXQsUum.mjs";
2
- import { i as normalizeWatchFolders, r as isTinyOpenApiFakeMode, t as createTinyOpenApiSourceRunner } from "./openapi-source.runner-8kCe-g9S.mjs";
1
+ import { t as createOpenApiCodegenRunner } from "./openapi-codegen.runner-G25v_q9z.mjs";
2
+ import { i as normalizeWatchFolders, r as isTinyOpenApiFakeMode, t as createTinyOpenApiSourceRunner } from "./openapi-source.runner-DPUNTduQ.mjs";
3
3
  import fs from "fs";
4
4
  import path from "path";
5
5
  //#region src/metro/openapi-codegen.plugin.ts
@@ -83,7 +83,7 @@ function reportWatcherError$1(error) {
83
83
  }
84
84
  //#endregion
85
85
  //#region src/metro/tiny-openapi-codegen.plugin.ts
86
- const watchedEvents = new Set(["change", "rename"]);
86
+ const watchedEvents = /* @__PURE__ */ new Set(["change", "rename"]);
87
87
  function tinyOpenApiCodegenMetro(metroConfig, codegenConfig, options) {
88
88
  if (isPromiseLike(metroConfig)) return metroConfig.then((resolvedConfig) => withResolvedTinyOpenApiCodegen(resolvedConfig, codegenConfig, options));
89
89
  return withResolvedTinyOpenApiCodegen(metroConfig, codegenConfig, options);
@@ -0,0 +1,49 @@
1
+ import { s as ErrorRethrower } from "./error-handling-BpAQHWrU.mjs";
2
+ import { a as RestTransport, c as TransportFetch, d as TransportResponse, l as TransportRequest, o as RestTransportInterceptor, r as RestRequestInfo, s as TransportErrorContext, t as GeneralTransportErrorCode, u as TransportRequestConfig } from "./rest-transport.types-DM5-qyOJ.mjs";
3
+ //#region src/lib/rest/native-rest-client.d.ts
4
+ type NativeResult<T, IsRawRes extends boolean> = IsRawRes extends true ? TransportResponse<T> : T;
5
+ declare class NativeRestClient implements RestTransport {
6
+ private readonly interceptors;
7
+ private readonly errorHandler?;
8
+ constructor({ config, interceptors, errorHandler }?: {
9
+ config?: {
10
+ baseURL?: string;
11
+ headers?: HeadersInit;
12
+ credentials?: RequestCredentials;
13
+ fetch?: TransportFetch;
14
+ };
15
+ interceptors?: RestTransportInterceptor[];
16
+ errorHandler?: ErrorRethrower;
17
+ });
18
+ private readonly baseURL;
19
+ private readonly headers?;
20
+ private readonly credentials?;
21
+ private readonly fetch;
22
+ attachInterceptor(interceptor: RestTransportInterceptor): void;
23
+ ejectInterceptor(interceptor: RestTransportInterceptor): void;
24
+ get<T, E extends string = GeneralTransportErrorCode, R extends boolean = false>(info: RestRequestInfo<T, E>, url: string, config?: TransportRequestConfig<R>): Promise<NativeResult<T, R>>;
25
+ post<T, E extends string = GeneralTransportErrorCode, R extends boolean = false>(info: RestRequestInfo<T, E>, url: string, data?: unknown, config?: TransportRequestConfig<R>): Promise<NativeResult<T, R>>;
26
+ patch<T, E extends string = GeneralTransportErrorCode, R extends boolean = false>(info: RestRequestInfo<T, E>, url: string, data?: unknown, config?: TransportRequestConfig<R>): Promise<NativeResult<T, R>>;
27
+ put<T, E extends string = GeneralTransportErrorCode, R extends boolean = false>(info: RestRequestInfo<T, E>, url: string, data?: unknown, config?: TransportRequestConfig<R>): Promise<NativeResult<T, R>>;
28
+ delete<T, E extends string = GeneralTransportErrorCode, R extends boolean = false>(info: RestRequestInfo<T, E>, url: string, data?: unknown, config?: TransportRequestConfig<R>): Promise<NativeResult<T, R>>;
29
+ upload(url: string, data: BodyInit, config?: TransportRequestConfig, method?: "put" | "post"): Promise<void>;
30
+ private request;
31
+ private execute;
32
+ private readResponse;
33
+ private resolveUrl;
34
+ private runErrorInterceptors;
35
+ private isTransportResponse;
36
+ private uploadWithXhr;
37
+ }
38
+ //#endregion
39
+ //#region src/lib/rest/native-rest-interceptor.d.ts
40
+ type NativeInterceptor = RestTransportInterceptor;
41
+ declare class NativeRestInterceptor implements RestTransportInterceptor {
42
+ private readonly interceptor;
43
+ constructor(interceptor: RestTransportInterceptor);
44
+ onRequest(request: TransportRequest): Promise<TransportRequest> | TransportRequest;
45
+ onResponse<T>(response: TransportResponse<T>): Promise<TransportResponse<T>> | TransportResponse<T>;
46
+ onError(error: unknown, context: TransportErrorContext): unknown;
47
+ }
48
+ //#endregion
49
+ export { NativeRestInterceptor as n, NativeRestClient as r, NativeInterceptor as t };
@@ -0,0 +1,215 @@
1
+ import { t as HttpError } from "./rest-transport.types-DxitRtsB.mjs";
2
+ import { z } from "zod";
3
+ //#region src/lib/rest/native-rest-client.ts
4
+ var NativeRestClient = class {
5
+ interceptors;
6
+ errorHandler;
7
+ constructor({ config, interceptors = [], errorHandler } = {}) {
8
+ this.baseURL = config?.baseURL ?? "";
9
+ this.headers = config?.headers;
10
+ this.credentials = config?.credentials;
11
+ this.fetch = config?.fetch ?? globalThis.fetch.bind(globalThis);
12
+ this.interceptors = [...interceptors];
13
+ this.errorHandler = errorHandler;
14
+ }
15
+ baseURL;
16
+ headers;
17
+ credentials;
18
+ fetch;
19
+ attachInterceptor(interceptor) {
20
+ this.interceptors.push(interceptor);
21
+ }
22
+ ejectInterceptor(interceptor) {
23
+ const index = this.interceptors.indexOf(interceptor);
24
+ if (index >= 0) this.interceptors.splice(index, 1);
25
+ }
26
+ get(info, url, config) {
27
+ return this.request(info, "GET", url, void 0, config);
28
+ }
29
+ post(info, url, data, config) {
30
+ return this.request(info, "POST", url, data, config);
31
+ }
32
+ patch(info, url, data, config) {
33
+ return this.request(info, "PATCH", url, data, config);
34
+ }
35
+ put(info, url, data, config) {
36
+ return this.request(info, "PUT", url, data, config);
37
+ }
38
+ delete(info, url, data, config) {
39
+ return this.request(info, "DELETE", url, data, config);
40
+ }
41
+ async upload(url, data, config = {}, method = "put") {
42
+ if (config.onUploadProgress && typeof XMLHttpRequest !== "undefined") {
43
+ await this.uploadWithXhr(url, data, config, method);
44
+ return;
45
+ }
46
+ await this.execute({
47
+ url,
48
+ method: method.toUpperCase(),
49
+ body: data,
50
+ headers: new Headers(config.headers),
51
+ signal: config.signal
52
+ }, config, false);
53
+ }
54
+ async request(info, method, path, data, config = {}) {
55
+ const errorStack = (/* @__PURE__ */ new Error()).stack;
56
+ try {
57
+ const headers = new Headers(this.headers);
58
+ new Headers(config.headers).forEach((value, key) => headers.set(key, value));
59
+ let body;
60
+ if (data != null) {
61
+ if (data instanceof FormData || data instanceof Blob || typeof data === "string") body = data;
62
+ else {
63
+ body = JSON.stringify(data);
64
+ if (!headers.has("content-type")) headers.set("content-type", "application/json");
65
+ }
66
+ }
67
+ const request = {
68
+ url: this.resolveUrl(path, config.params),
69
+ method,
70
+ headers,
71
+ body,
72
+ signal: config.signal,
73
+ credentials: config.credentials ?? this.credentials
74
+ };
75
+ const response = await this.execute(request, config);
76
+ const parseResult = info.resSchema.safeParse(response.data);
77
+ let dataResult;
78
+ if (parseResult.success) dataResult = parseResult.data;
79
+ else if (config.allowInvalidResponseData && method === "GET") {
80
+ parseResult.error.name = "BE Response schema mismatch - ZodError";
81
+ parseResult.error.stack = [parseResult.error.stack, ...errorStack?.split("\n").slice(2) ?? []].join("\n");
82
+ console.error(parseResult.error);
83
+ dataResult = response.data;
84
+ } else throw parseResult.error;
85
+ return config.rawResponse ? {
86
+ ...response,
87
+ data: dataResult
88
+ } : dataResult;
89
+ } catch (error) {
90
+ if (error instanceof z.ZodError) error.name = "BE Response schema mismatch - ZodError";
91
+ const transformed = await this.runErrorInterceptors(error);
92
+ throw this.errorHandler ? this.errorHandler.rethrowError(transformed) : transformed;
93
+ }
94
+ }
95
+ async execute(request, config = {}, applyInterceptors = true) {
96
+ let next = request;
97
+ if (applyInterceptors) for (const interceptor of this.interceptors) next = await interceptor.onRequest?.(next) ?? next;
98
+ const timeoutController = config.timeout ? new AbortController() : void 0;
99
+ const timer = timeoutController ? setTimeout(() => timeoutController.abort(), config.timeout) : void 0;
100
+ if (timeoutController && next.signal) {
101
+ if (next.signal.aborted) timeoutController.abort(next.signal.reason);
102
+ else next.signal.addEventListener("abort", () => timeoutController.abort(next.signal?.reason), { once: true });
103
+ }
104
+ const signal = timeoutController?.signal ?? next.signal;
105
+ try {
106
+ const res = await this.fetch(next.url, {
107
+ method: next.method,
108
+ headers: next.headers,
109
+ body: next.body,
110
+ signal,
111
+ credentials: next.credentials
112
+ });
113
+ let response = {
114
+ data: await this.readResponse(res, config.responseType),
115
+ status: res.status,
116
+ statusText: res.statusText,
117
+ headers: res.headers,
118
+ url: res.url
119
+ };
120
+ if (!res.ok) throw new HttpError(`Request failed with status ${res.status}`, response);
121
+ if (applyInterceptors) for (const interceptor of this.interceptors) response = await interceptor.onResponse?.(response) ?? response;
122
+ return response;
123
+ } catch (error) {
124
+ if (!applyInterceptors) throw error;
125
+ const context = {
126
+ request: next,
127
+ response: error instanceof HttpError ? error.response : void 0,
128
+ retry: (request = next) => this.execute({
129
+ ...request,
130
+ retryCount: (next.retryCount ?? 0) + 1
131
+ }, config, true)
132
+ };
133
+ const transformed = await this.runErrorInterceptors(error, context);
134
+ if (this.isTransportResponse(transformed)) return transformed;
135
+ throw transformed;
136
+ } finally {
137
+ if (timer) clearTimeout(timer);
138
+ }
139
+ }
140
+ async readResponse(response, type) {
141
+ if (response.status === 204) return void 0;
142
+ if (type === "blob") return response.blob();
143
+ if (type === "arrayBuffer") return response.arrayBuffer();
144
+ if (type === "text") return response.text();
145
+ const text = await response.text();
146
+ if (text === "") return void 0;
147
+ if (!response.headers.get("content-type")?.includes("json")) try {
148
+ return JSON.parse(text);
149
+ } catch {
150
+ return text;
151
+ }
152
+ return JSON.parse(text);
153
+ }
154
+ resolveUrl(path, params) {
155
+ const baseURL = this.baseURL && !this.baseURL.endsWith("/") ? `${this.baseURL}/` : this.baseURL;
156
+ const url = /^https?:\/\//.test(path) ? new URL(path) : new URL(path.replace(/^\//, ""), baseURL || globalThis.location?.origin);
157
+ for (const [key, value] of Object.entries(params ?? {})) {
158
+ if (value == null) continue;
159
+ if (Array.isArray(value)) value.forEach((item) => url.searchParams.append(key, String(item)));
160
+ else url.searchParams.append(key, String(value));
161
+ }
162
+ return url.toString();
163
+ }
164
+ async runErrorInterceptors(error, context) {
165
+ let next = error;
166
+ if (!context) return next;
167
+ for (const interceptor of [...this.interceptors].reverse()) if (interceptor.onError) try {
168
+ next = await interceptor.onError(next, context);
169
+ } catch (transformed) {
170
+ next = transformed;
171
+ }
172
+ return next;
173
+ }
174
+ isTransportResponse(value) {
175
+ return !!value && typeof value === "object" && "status" in value && "headers" in value && "data" in value;
176
+ }
177
+ uploadWithXhr(url, data, config, method) {
178
+ return new Promise((resolve, reject) => {
179
+ const xhr = new XMLHttpRequest();
180
+ xhr.open(method.toUpperCase(), url);
181
+ new Headers(config.headers).forEach((value, key) => xhr.setRequestHeader(key, value));
182
+ if (config.timeout) xhr.timeout = config.timeout;
183
+ xhr.upload.onprogress = ({ loaded, total }) => config.onUploadProgress?.({
184
+ loaded,
185
+ total
186
+ });
187
+ xhr.onload = () => xhr.status >= 200 && xhr.status < 300 ? resolve() : reject(/* @__PURE__ */ new Error(`Upload failed with status ${xhr.status}`));
188
+ xhr.onerror = () => reject(/* @__PURE__ */ new TypeError("Network request failed"));
189
+ xhr.ontimeout = () => reject(new DOMException("Request timed out", "TimeoutError"));
190
+ config.signal?.addEventListener("abort", () => xhr.abort(), { once: true });
191
+ xhr.onabort = () => reject(config.signal?.reason ?? new DOMException("Request aborted", "AbortError"));
192
+ xhr.send(data);
193
+ });
194
+ }
195
+ };
196
+ //#endregion
197
+ //#region src/lib/rest/native-rest-interceptor.ts
198
+ var NativeRestInterceptor = class {
199
+ interceptor;
200
+ constructor(interceptor) {
201
+ this.interceptor = interceptor;
202
+ }
203
+ onRequest(request) {
204
+ return this.interceptor.onRequest?.(request) ?? request;
205
+ }
206
+ onResponse(response) {
207
+ return this.interceptor.onResponse?.(response) ?? response;
208
+ }
209
+ onError(error, context) {
210
+ if (!this.interceptor.onError) throw error;
211
+ return this.interceptor.onError(error, context);
212
+ }
213
+ };
214
+ //#endregion
215
+ export { NativeRestClient as n, NativeRestInterceptor as t };
@@ -0,0 +1,3 @@
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
+ import { n as NativeRestInterceptor, r as NativeRestClient, t as NativeInterceptor } from "./native-rest-interceptor-DZxdDcpz.mjs";
3
+ export { type GeneralTransportErrorCode, HttpError, HttpError as NativeHttpError, type NativeInterceptor, type TransportRequest as NativeRequest, type TransportRequest, type TransportRequestConfig as NativeRequestConfig, type TransportRequestConfig, type TransportResponse as NativeResponse, type TransportResponse, NativeRestClient, NativeRestInterceptor, type UploadProgress as NativeUploadProgress, type UploadProgress, type RestRequestInfo, type RestResponseType, type RestTransport, type RestTransportInterceptor, type TransportResult };
@@ -0,0 +1,3 @@
1
+ import { t as HttpError } from "./rest-transport.types-DxitRtsB.mjs";
2
+ import { n as NativeRestClient, t as NativeRestInterceptor } from "./native-rest-interceptor-Np4Ov54n.mjs";
3
+ export { HttpError, HttpError as NativeHttpError, NativeRestClient, NativeRestInterceptor };
@@ -1,5 +1,4 @@
1
- import { x as Profiler } from "./generateCodeFromOpenAPIDoc-SYuVswEJ.mjs";
2
- import { t as runGenerate } from "./generate.runner-B0Zm3pIl.mjs";
1
+ import { Wn as Profiler, n as runGenerate } from "./generate.runner-BuSwqeff.mjs";
3
2
  import path from "path";
4
3
  //#region src/plugins/openapi-codegen.runner.ts
5
4
  function createOpenApiCodegenRunner(config, options = {}) {
@@ -13,6 +12,7 @@ function createOpenApiCodegenRunner(config, options = {}) {
13
12
  formatGeneratedFile,
14
13
  profiler
15
14
  });
15
+ for (const line of profiler.formatLines()) console.info(`[openapi-codegen] ${line}`);
16
16
  options.onGenerated?.();
17
17
  });
18
18
  queue = run.then(() => void 0, () => void 0);
@@ -1,5 +1,4 @@
1
- import { t as OpenAPICodegenConfig } from "./config-BQqze8rU.mjs";
2
-
1
+ import { t as OpenAPICodegenConfig } from "./config-CiLFKLAY.mjs";
3
2
  //#region src/tiny/openapi.d.ts
4
3
  interface GenerateOpenApiFileOptions {
5
4
  argv?: readonly string[];
@@ -79,12 +78,7 @@ interface OrpcContractProcedureData {
79
78
  successStatus?: number;
80
79
  };
81
80
  }
82
- declare function resolveOpenApiOutputPath({
83
- argv,
84
- cwd,
85
- defaultOutput,
86
- env
87
- }: GenerateOpenApiFileOptions): string;
81
+ declare function resolveOpenApiOutputPath({ argv, cwd, defaultOutput, env }: GenerateOpenApiFileOptions): string;
88
82
  declare function generateOpenApiFile(options: GenerateTinyOpenApiFileOptions): Promise<GenerateOpenApiFileResult>;
89
83
  declare function defineOpenApiSchemas<const TSchemas extends OpenApiSchemaRegistry>(schemas: TSchemas): TSchemas;
90
84
  declare function collectExtraSchemas<TModules extends Record<string, {
@@ -19,7 +19,7 @@ const PAGINATION_PROPERTY_NAMES = [
19
19
  "limit",
20
20
  "totalItems"
21
21
  ];
22
- const OPENAPI_31_ONLY_KEYS = new Set([
22
+ const OPENAPI_31_ONLY_KEYS = /* @__PURE__ */ new Set([
23
23
  "$schema",
24
24
  "$id",
25
25
  "$vocabulary",
@@ -314,11 +314,13 @@ function collectContractSchemas(router, routerPath = [], schemas = {}, getSchema
314
314
  if (procedure) {
315
315
  const procedureName = routerPath.map(toPascalCase).join("");
316
316
  const { inputSchema, outputSchema, route } = procedure;
317
- if (inputSchema) if (route.inputStructure === "detailed") {
318
- addContractSchema(schemas, getObjectPropertySchema(inputSchema, "params"), procedureSchemaName(procedureName, "Params"), getSchemaName);
319
- addContractSchema(schemas, getObjectPropertySchema(inputSchema, "query"), procedureSchemaName(procedureName, "Query"), getSchemaName);
320
- addContractSchema(schemas, getObjectPropertySchema(inputSchema, "body") ?? inputSchema, procedureSchemaName(procedureName, "Request"), getSchemaName);
321
- } else addContractSchema(schemas, inputSchema, procedureSchemaName(procedureName, getProcedureInputSchemaRole(route)), getSchemaName);
317
+ if (inputSchema) {
318
+ if (route.inputStructure === "detailed") {
319
+ addContractSchema(schemas, getObjectPropertySchema(inputSchema, "params"), procedureSchemaName(procedureName, "Params"), getSchemaName);
320
+ addContractSchema(schemas, getObjectPropertySchema(inputSchema, "query"), procedureSchemaName(procedureName, "Query"), getSchemaName);
321
+ addContractSchema(schemas, getObjectPropertySchema(inputSchema, "body") ?? inputSchema, procedureSchemaName(procedureName, "Request"), getSchemaName);
322
+ } else addContractSchema(schemas, inputSchema, procedureSchemaName(procedureName, getProcedureInputSchemaRole(route)), getSchemaName);
323
+ }
322
324
  if (outputSchema && route.successStatus !== 204) addContractSchema(schemas, outputSchema, procedureSchemaName(procedureName, "Response"), getSchemaName, "output");
323
325
  return schemas;
324
326
  }
@@ -585,13 +587,18 @@ function toOpenAPI30Document(spec) {
585
587
  return converted;
586
588
  }
587
589
  async function generateORPCOpenAPISpec(options) {
588
- const [{ OpenAPIGenerator }, { ZodToJsonSchemaConverter }] = await Promise.all([importRuntimeModule("@orpc/openapi"), importRuntimeModule("@orpc/zod/zod4")]);
589
- const generator = new OpenAPIGenerator({ schemaConverters: [new ZodToJsonSchemaConverter()] });
590
- const explicitSchemaName = options.getOpenApiSchemaName ?? getOpenApiSchemaName;
591
- const modelSchemas = await collectModelSchemaExports({
590
+ const profile = process.env.TINY_OPENAPI_PROFILE === "1";
591
+ const started = performance.now();
592
+ const runtimePromise = Promise.all([importRuntimeModule("@orpc/openapi"), importRuntimeModule("@orpc/zod/zod4")]);
593
+ const modelSchemasPromise = collectModelSchemaExports({
592
594
  apiRoot: options.apiRoot,
593
595
  dbTablesRoot: options.dbTablesRoot
594
596
  });
597
+ const [[{ OpenAPIGenerator }, { ZodToJsonSchemaConverter }], modelSchemas] = await Promise.all([runtimePromise, modelSchemasPromise]);
598
+ const generator = new OpenAPIGenerator({ schemaConverters: [new ZodToJsonSchemaConverter()] });
599
+ const afterRuntime = performance.now();
600
+ const explicitSchemaName = options.getOpenApiSchemaName ?? getOpenApiSchemaName;
601
+ const afterModels = performance.now();
595
602
  const getSchemaName = createModelSchemaNameGetter(modelSchemas, explicitSchemaName);
596
603
  const operationMeta = collectOperationMeta(options.contract);
597
604
  const extraSchemas = collectExtraSchemas(options.apiModules);
@@ -607,6 +614,7 @@ async function generateORPCOpenAPISpec(options) {
607
614
  ...extraSchemas,
608
615
  ...reachableModelSchemas
609
616
  };
617
+ const afterCollection = performance.now();
610
618
  const spec = await generator.generate(options.contract, {
611
619
  info: options.info ?? {
612
620
  title: "Tiny Template Fake API",
@@ -620,6 +628,7 @@ async function generateORPCOpenAPISpec(options) {
620
628
  ...Object.keys(commonSchemas).length > 0 ? { commonSchemas } : {}
621
629
  });
622
630
  const jsonSpec = spec;
631
+ const afterGeneration = performance.now();
623
632
  const sortableSchemaNames = options.realBackendSortableSchemaNames instanceof Map ? options.realBackendSortableSchemaNames : new Map(Object.entries(options.realBackendSortableSchemaNames ?? {}));
624
633
  applyOperationMeta(jsonSpec, operationMeta, options.apiModules);
625
634
  applyEnumExtensions(spec);
@@ -642,7 +651,12 @@ async function generateORPCOpenAPISpec(options) {
642
651
  }
643
652
  applyRobodevModuleExtensions(jsonSpec, robodevModuleExtensions, options.apiModules);
644
653
  applyRobodevUserRolesExtension(jsonSpec, userRoles);
645
- return toOpenAPI30Document(jsonSpec);
654
+ const output = toOpenAPI30Document(jsonSpec);
655
+ if (profile) {
656
+ const finished = performance.now();
657
+ console.error(`tiny openapi profile runtime=${(afterRuntime - started).toFixed(1)}ms models=${(afterModels - afterRuntime).toFixed(1)}ms collection=${(afterCollection - afterModels).toFixed(1)}ms orpc=${(afterGeneration - afterCollection).toFixed(1)}ms post=${(finished - afterGeneration).toFixed(1)}ms total=${(finished - started).toFixed(1)}ms`);
658
+ }
659
+ return output;
646
660
  }
647
661
  //#endregion
648
662
  //#region src/tiny/openapi-source.runner.ts
@@ -1,5 +1,4 @@
1
1
  import { OpenAPIV3 } from "openapi-types";
2
-
3
2
  //#region src/generators/types/generate.d.ts
4
3
  declare enum GenerateType {
5
4
  Models = "models",
@@ -16,9 +15,12 @@ type GenerateFileFormatter = (file: GenerateFileData) => string | Promise<string
16
15
  //#endregion
17
16
  //#region src/generators/types/options.d.ts
18
17
  interface ZodGenerateOptions {
18
+ /** Eagerly compile non-recursive schemas. Defaults to false to avoid startup work. */
19
+ compileSchemas?: boolean;
19
20
  schemaSuffix: string;
20
21
  enumSuffix: string;
21
22
  modelsInCommon?: boolean;
23
+ modelsInModules?: boolean;
22
24
  withImplicitRequiredProps?: boolean;
23
25
  withDefaultValues?: boolean;
24
26
  withDescription?: boolean;
@@ -27,7 +29,9 @@ interface ZodGenerateOptions {
27
29
  replaceOptionalWithNullish?: boolean;
28
30
  }
29
31
  interface EndpointsGenerateOptions {
32
+ restClient: "axios" | "native";
30
33
  restClientImportPath: string;
34
+ zodImportPath: string;
31
35
  errorHandlingImportPath?: string;
32
36
  withDeprecatedEndpoints?: boolean;
33
37
  removeOperationPrefixEndingWith?: string;
@@ -37,6 +41,7 @@ interface EndpointsGenerateOptions {
37
41
  }
38
42
  interface QueriesGenerateOptions {
39
43
  queryTypesImportPath: string;
44
+ mutationEffectsImportPath: string;
40
45
  axiosRequestConfig?: boolean;
41
46
  mutationEffects?: boolean;
42
47
  mutationDefaultOnError?: boolean;
@@ -64,6 +69,7 @@ interface ACLGenerateOptions {
64
69
  checkAcl?: boolean;
65
70
  abilityContextGenericAppAbilities: boolean;
66
71
  abilityContextImportPath?: string;
72
+ aclCheckImportPath: string;
67
73
  }
68
74
  interface BuilderConfigsGenerateOptions {
69
75
  builderConfigs?: boolean;
@@ -88,6 +94,7 @@ interface BaseGenerateOptions {
88
94
  excludePathRegex: string;
89
95
  excludeRedundantZodSchemas: boolean;
90
96
  tsNamespaces: boolean;
97
+ treeShakeableNamespaces?: boolean;
91
98
  tsPath: string;
92
99
  importPath: "ts" | "relative" | "absolute";
93
100
  configs: Record<GenerateType, GenerateConfig>;
@@ -0,0 +1,3 @@
1
+ import { a as MutationEffectsTypes, i as MutationEffectsOf, n as InvalidationMapFunc, o as OpenApiQueryConfig, r as MergedMutationVariables, s as QueryModule, t as InvalidationMap } from "./queryConfig.context-yl7x_NdW.mjs";
2
+ import { a as AppQueryOptions, i as AppMutationOptions, n as useMutationEffects, r as AppInfiniteQueryOptions, t as MutationEffectsOptions } from "./useMutationEffects-CjGlHDg_.mjs";
3
+ export { type AppInfiniteQueryOptions, type AppMutationOptions, type AppQueryOptions, type InvalidationMap, type InvalidationMapFunc, type MergedMutationVariables, type MutationEffectsOf, type MutationEffectsOptions, type MutationEffectsTypes, OpenApiQueryConfig, type QueryModule, useMutationEffects };
package/dist/query.mjs ADDED
@@ -0,0 +1,3 @@
1
+ import { t as OpenApiQueryConfig } from "./queryConfig.context-CldQ5YL9.mjs";
2
+ import { t as useMutationEffects } from "./useMutationEffects-PB1fvKWM.mjs";
3
+ export { OpenApiQueryConfig, useMutationEffects };
@@ -0,0 +1,34 @@
1
+ import { createContext, use, useMemo } from "react";
2
+ import { jsx } from "react/jsx-runtime";
3
+ //#region src/lib/config/queryConfig.context.tsx
4
+ let OpenApiQueryConfig;
5
+ (function(_OpenApiQueryConfig) {
6
+ const Context = createContext({});
7
+ function Provider({ preferUpdate, invalidateCurrentModule, invalidationMap, crossTabInvalidation, allowInvalidResponseData, onError, children }) {
8
+ const value = useMemo(() => ({
9
+ preferUpdate,
10
+ invalidateCurrentModule,
11
+ invalidationMap,
12
+ crossTabInvalidation,
13
+ allowInvalidResponseData,
14
+ onError
15
+ }), [
16
+ preferUpdate,
17
+ invalidateCurrentModule,
18
+ invalidationMap,
19
+ crossTabInvalidation,
20
+ allowInvalidResponseData,
21
+ onError
22
+ ]);
23
+ return /* @__PURE__ */ jsx(Context.Provider, {
24
+ value,
25
+ children
26
+ });
27
+ }
28
+ _OpenApiQueryConfig.Provider = Provider;
29
+ _OpenApiQueryConfig.useConfig = () => {
30
+ return use(Context) ?? {};
31
+ };
32
+ })(OpenApiQueryConfig || (OpenApiQueryConfig = {}));
33
+ //#endregion
34
+ export { OpenApiQueryConfig as t };
@@ -0,0 +1,48 @@
1
+ import { PropsWithChildren } from "react";
2
+ import { QueryKey, UseMutationResult } from "@tanstack/react-query";
3
+ //#region src/lib/config/queryConfig.context.d.ts
4
+ type QueryModule = string | number | symbol;
5
+ type InvalidationMapFunc<TData = unknown, TVariables = unknown> = {
6
+ invalidate(data: TData, variables: TVariables): QueryKey[];
7
+ }["invalidate"];
8
+ /** The `data` and `variables` one mutation passes to its module's invalidation callback. */
9
+ interface MutationEffectsTypes {
10
+ data: unknown;
11
+ variables: unknown;
12
+ }
13
+ /** `data` and `variables` of mutation hooks, e.g. `MutationEffectsOf<typeof useCreate | typeof useUpdate>`. */
14
+ type MutationEffectsOf<THook> = THook extends ((...args: never) => UseMutationResult<infer TData, infer _TError, infer TVariables, infer _TOnMutateResult>) ? {
15
+ data: TData;
16
+ variables: TVariables;
17
+ } : never;
18
+ type ObjectMembers<T> = T extends object ? T : never;
19
+ type KeysOfUnion<T> = T extends unknown ? keyof T : never;
20
+ type ValueOfUnion<T, K extends PropertyKey> = T extends unknown ? (K extends keyof T ? T[K] : undefined) : never;
21
+ type MergedObjects<T> = { [K in keyof T]: ValueOfUnion<T, K>; } & { [K in Exclude<KeysOfUnion<T>, keyof T>]?: ValueOfUnion<T, K>; };
22
+ /**
23
+ * The variables of a module's mutations as one object: keys some mutations lack become optional.
24
+ * Mutations without variables (`void`) stay in the union, as their callbacks receive `undefined`.
25
+ */
26
+ type MergedMutationVariables<T> = [ObjectMembers<T>] extends [never] ? T : MergedObjects<ObjectMembers<T>> | Exclude<T, object>;
27
+ type InvalidationMapFuncFor<T> = InvalidationMapFunc<T extends MutationEffectsTypes ? T["data"] : never, MergedMutationVariables<T extends MutationEffectsTypes ? T["variables"] : never>>;
28
+ /**
29
+ * Query keys to invalidate after a module's mutations. Pass the generated `QueryModuleMutations` as
30
+ * `TMutations` to type each module's callback with its mutations' `data` and `variables`.
31
+ */
32
+ type InvalidationMap<TQueryModule extends QueryModule = QueryModule, TMutations extends { [K in TQueryModule]?: MutationEffectsTypes; } = {}> = { [K in TQueryModule]?: K extends keyof TMutations ? InvalidationMapFuncFor<TMutations[K]> : InvalidationMapFunc; };
33
+ declare namespace OpenApiQueryConfig {
34
+ export interface Type<TQueryModule extends QueryModule = QueryModule> {
35
+ preferUpdate?: boolean;
36
+ invalidateCurrentModule?: boolean;
37
+ invalidationMap?: InvalidationMap<TQueryModule>;
38
+ crossTabInvalidation?: boolean;
39
+ allowInvalidResponseData?: boolean;
40
+ onError?: (error: unknown) => void;
41
+ }
42
+ type ProviderProps<TQueryModule extends QueryModule = QueryModule> = Type<TQueryModule>;
43
+ export function Provider<TQueryModule extends QueryModule = QueryModule>({ preferUpdate, invalidateCurrentModule, invalidationMap, crossTabInvalidation, allowInvalidResponseData, onError, children }: PropsWithChildren<ProviderProps<TQueryModule>>): import("react").JSX.Element;
44
+ export const useConfig: <TQueryModule extends QueryModule = QueryModule>() => Type<TQueryModule>;
45
+ export {};
46
+ }
47
+ //#endregion
48
+ export { MutationEffectsTypes as a, MutationEffectsOf as i, InvalidationMapFunc as n, OpenApiQueryConfig as o, MergedMutationVariables as r, QueryModule as s, InvalidationMap as t };
@@ -0,0 +1,55 @@
1
+ import { a as ErrorHandler, c as GeneralErrorCodes$1, s as ErrorRethrower } from "./error-handling-BpAQHWrU.mjs";
2
+ import { AxiosInstance, AxiosRequestConfig, AxiosResponse, CreateAxiosDefaults } from "axios";
3
+ import { z } from "zod";
4
+ //#region src/lib/rest/rest-interceptor.d.ts
5
+ declare class RestInterceptor<T extends unknown[]> {
6
+ private applyInterceptor;
7
+ private interceptorIdMap;
8
+ constructor(applyInterceptor: (client: AxiosInstance, ...args: T) => number);
9
+ addInterceptor(client: AxiosInstance, ...args: T): void;
10
+ removeInterceptor(client: AxiosInstance): void;
11
+ }
12
+ //#endregion
13
+ //#region src/lib/rest/rest-client.types.d.ts
14
+ type GeneralErrorCodes = string;
15
+ interface RequestInfo<ZOutput, ECodes extends string> {
16
+ resSchema: z.ZodType<ZOutput>;
17
+ errorHandler?: ErrorHandler<ECodes>;
18
+ }
19
+ interface RequestConfig<IsRawRes extends boolean = false> {
20
+ rawResponse?: IsRawRes;
21
+ allowInvalidResponseData?: boolean;
22
+ }
23
+ type Response<ZOutput, IsRawRes extends boolean = false> = IsRawRes extends true ? AxiosResponse<ZOutput> : ZOutput;
24
+ interface RestClient$1 {
25
+ attachInterceptors<T extends unknown[]>(interceptors?: RestInterceptor<T>[], ...args: T): void;
26
+ attachInterceptor<T extends unknown[]>(interceptor: RestInterceptor<T>, ...args: T): void;
27
+ ejectInterceptor<T extends unknown[]>(interceptor: RestInterceptor<T>): void;
28
+ get<ZOutput, ECodes extends string = GeneralErrorCodes, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
29
+ post<ZOutput, ECodes extends string = GeneralErrorCodes, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, data?: unknown, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
30
+ patch<ZOutput, ECodes extends string = GeneralErrorCodes, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, data?: unknown, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
31
+ put<ZOutput, ECodes extends string = GeneralErrorCodes, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, data?: unknown, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
32
+ delete<ZOutput, ECodes extends string = GeneralErrorCodes, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, data?: unknown, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
33
+ }
34
+ //#endregion
35
+ //#region src/lib/rest/rest-client.d.ts
36
+ declare class RestClient implements RestClient$1 {
37
+ private readonly client;
38
+ private readonly errorHandler;
39
+ constructor({ config, interceptors, errorHandler }?: {
40
+ config?: CreateAxiosDefaults;
41
+ interceptors?: RestInterceptor<[]>[];
42
+ errorHandler?: ErrorRethrower;
43
+ });
44
+ attachInterceptors<T extends unknown[]>(interceptors?: RestInterceptor<T>[], ...args: T): void;
45
+ attachInterceptor<T extends unknown[]>(interceptor: RestInterceptor<T>, ...args: T): void;
46
+ ejectInterceptor<T extends unknown[]>(interceptor: RestInterceptor<T>): void;
47
+ get<ZOutput, ECodes extends string = GeneralErrorCodes$1, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
48
+ post<ZOutput, ECodes extends string = GeneralErrorCodes$1, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, data?: unknown, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
49
+ patch<ZOutput, ECodes extends string = GeneralErrorCodes$1, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, data?: unknown, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
50
+ put<ZOutput, ECodes extends string = GeneralErrorCodes$1, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, data?: unknown, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
51
+ delete<ZOutput, ECodes extends string = GeneralErrorCodes$1, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, data?: unknown, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
52
+ private makeRequest;
53
+ }
54
+ //#endregion
55
+ export { RestClient$1 as a, Response as i, RequestConfig as n, RestInterceptor as o, RequestInfo as r, RestClient as t };