@povio/openapi-codegen-cli 3.0.0 → 3.1.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.
- package/README.md +88 -0
- package/dist/acl.d.mts +1 -1
- package/dist/{config-CrZa_Jbm.d.mts → config-BU7wVf7U.d.mts} +1 -1
- package/dist/generator.d.mts +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/metro.d.mts +16 -3
- package/dist/metro.mjs +106 -7
- package/dist/openapi-D9apjIRy.d.mts +172 -0
- package/dist/openapi-source.runner-D19XnvMe.mjs +39 -0
- package/dist/sh.mjs +1 -1
- package/dist/tiny.d.mts +21 -0
- package/dist/tiny.mjs +635 -0
- package/dist/vite.d.mts +16 -4
- package/dist/vite.mjs +72 -1
- package/dist/zod.d.mts +1 -1
- package/package.json +8 -1
- /package/dist/{error-handling-oM5YJYYH.d.mts → error-handling-CDeKUFHF.d.mts} +0 -0
- /package/dist/{options-BZOw7Hx4.d.mts → options-CE4Koxof.d.mts} +0 -0
package/README.md
CHANGED
|
@@ -287,6 +287,51 @@ export default defineConfig({
|
|
|
287
287
|
The plugin runs on both `vite serve` and `vite build`, and watches local OpenAPI files in dev mode.
|
|
288
288
|
If you provide `formatGeneratedFile`, the plugin formats each generated file in memory before comparing and writing it, which helps avoid unnecessary HMR when the formatted output is unchanged.
|
|
289
289
|
|
|
290
|
+
For Tiny projects that generate the OpenAPI JSON from ORPC before client codegen, use the wrapper plugin:
|
|
291
|
+
|
|
292
|
+
```ts
|
|
293
|
+
import { defineConfig } from "vite";
|
|
294
|
+
import { generateOpenApiFile as writeOpenApiFile, generateORPCOpenAPISpec } from "@povio/openapi-codegen-cli/tiny";
|
|
295
|
+
import { tinyOpenApiCodegen } from "@povio/openapi-codegen-cli/vite";
|
|
296
|
+
import { apiModules } from "../packages/fake-be/src/orpc/api/modules";
|
|
297
|
+
import { contract } from "../packages/fake-be/src/orpc/api/contract";
|
|
298
|
+
import { getOpenApiSchemaName } from "../packages/fake-be/src/orpc/spec";
|
|
299
|
+
import { userRoles } from "../packages/fake-be/src/roles";
|
|
300
|
+
|
|
301
|
+
const generateOpenApiFile = (options) =>
|
|
302
|
+
writeOpenApiFile({
|
|
303
|
+
...options,
|
|
304
|
+
generateOpenApiSpec: () =>
|
|
305
|
+
generateORPCOpenAPISpec({
|
|
306
|
+
contract,
|
|
307
|
+
apiModules,
|
|
308
|
+
userRoles,
|
|
309
|
+
apiRoot: "../packages/fake-be/src/orpc/api",
|
|
310
|
+
dbTablesRoot: "../packages/fake-be/src/db/tables",
|
|
311
|
+
getOpenApiSchemaName,
|
|
312
|
+
}),
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
export default defineConfig({
|
|
316
|
+
plugins: [
|
|
317
|
+
tinyOpenApiCodegen(
|
|
318
|
+
{
|
|
319
|
+
input: "./openapi.generated.json",
|
|
320
|
+
output: "./src/data",
|
|
321
|
+
inlineEndpoints: true,
|
|
322
|
+
incremental: true,
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
generateOpenApiFile,
|
|
326
|
+
watchFolders: ["../packages/fake-be/src/orpc", "../packages/fake-be/src/db"],
|
|
327
|
+
},
|
|
328
|
+
),
|
|
329
|
+
],
|
|
330
|
+
});
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
When `VITE_PUBLIC_API_MODE` or `EXPO_PUBLIC_API_MODE` is `real`, the Tiny wrapper skips ORPC OpenAPI generation and behaves like `openApiCodegen`.
|
|
334
|
+
|
|
290
335
|
### Metro Plugin
|
|
291
336
|
|
|
292
337
|
You can run codegen directly from React Native Metro config:
|
|
@@ -318,6 +363,49 @@ export default withOpenApiCodegen(
|
|
|
318
363
|
The Metro wrapper runs generation when the config is loaded, waits for it before Metro transforms or serves the first request, and watches local OpenAPI files while the dev server is running.
|
|
319
364
|
If you provide `formatGeneratedFile`, it behaves the same way as the Vite plugin.
|
|
320
365
|
|
|
366
|
+
For Tiny projects, use the Metro wrapper:
|
|
367
|
+
|
|
368
|
+
```ts
|
|
369
|
+
import { getDefaultConfig } from "@react-native/metro-config";
|
|
370
|
+
import { generateOpenApiFile as writeOpenApiFile, generateORPCOpenAPISpec } from "@povio/openapi-codegen-cli/tiny";
|
|
371
|
+
import { tinyOpenApiCodegenMetro } from "@povio/openapi-codegen-cli/metro";
|
|
372
|
+
import { apiModules } from "../../packages/fake-be/src/orpc/api/modules";
|
|
373
|
+
import { contract } from "../../packages/fake-be/src/orpc/api/contract";
|
|
374
|
+
import { getOpenApiSchemaName } from "../../packages/fake-be/src/orpc/spec";
|
|
375
|
+
import { userRoles } from "../../packages/fake-be/src/roles";
|
|
376
|
+
|
|
377
|
+
const root = __dirname;
|
|
378
|
+
const config = getDefaultConfig(root);
|
|
379
|
+
const generateOpenApiFile = (options) =>
|
|
380
|
+
writeOpenApiFile({
|
|
381
|
+
...options,
|
|
382
|
+
generateOpenApiSpec: () =>
|
|
383
|
+
generateORPCOpenAPISpec({
|
|
384
|
+
contract,
|
|
385
|
+
apiModules,
|
|
386
|
+
userRoles,
|
|
387
|
+
apiRoot: "../../packages/fake-be/src/orpc/api",
|
|
388
|
+
dbTablesRoot: "../../packages/fake-be/src/db/tables",
|
|
389
|
+
getOpenApiSchemaName,
|
|
390
|
+
}),
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
export default tinyOpenApiCodegenMetro(
|
|
394
|
+
config,
|
|
395
|
+
{
|
|
396
|
+
input: "./assets/openapi/main.json",
|
|
397
|
+
output: "./utils/rest/openapi",
|
|
398
|
+
inlineEndpoints: true,
|
|
399
|
+
incremental: true,
|
|
400
|
+
},
|
|
401
|
+
{
|
|
402
|
+
root,
|
|
403
|
+
generateOpenApiFile,
|
|
404
|
+
watchFolders: ["../../packages/fake-be/src/orpc", "../../packages/fake-be/src/db"],
|
|
405
|
+
},
|
|
406
|
+
);
|
|
407
|
+
```
|
|
408
|
+
|
|
321
409
|
### Enums
|
|
322
410
|
|
|
323
411
|
If you're using Enums in your backend DTOs with `@Expose()` and `@IsEnum`, they may still not appear correctly in the OpenAPI schema unless you also provide both `enum` **and** `enumName` to `@ApiProperty`.
|
package/dist/acl.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as ErrorHandler } from "./error-handling-
|
|
1
|
+
import { a as ErrorHandler } from "./error-handling-CDeKUFHF.mjs";
|
|
2
2
|
import * as react from "react";
|
|
3
3
|
import { PropsWithChildren } from "react";
|
|
4
4
|
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
package/dist/generator.d.mts
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as ErrorHandler, c as SharedErrorHandler, i as ErrorEntry, n as DomainErrorEntry, o as ErrorHandlerOptions, r as DomainErrorRegistry, s as GeneralErrorCodes, t as ApplicationException } from "./error-handling-
|
|
2
|
-
import "./options-
|
|
3
|
-
import { t as OpenAPICodegenConfig } from "./config-
|
|
1
|
+
import { a as ErrorHandler, c as SharedErrorHandler, i as ErrorEntry, n as DomainErrorEntry, o as ErrorHandlerOptions, r as DomainErrorRegistry, s as GeneralErrorCodes, t as ApplicationException } from "./error-handling-CDeKUFHF.mjs";
|
|
2
|
+
import "./options-CE4Koxof.mjs";
|
|
3
|
+
import { t as OpenAPICodegenConfig } from "./config-BU7wVf7U.mjs";
|
|
4
4
|
import { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosResponseHeaders, CreateAxiosDefaults } from "axios";
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
import "i18next";
|
package/dist/metro.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { r as GenerateFileFormatter } from "./options-
|
|
2
|
-
import { t as OpenAPICodegenConfig } from "./config-
|
|
1
|
+
import { r as GenerateFileFormatter } from "./options-CE4Koxof.mjs";
|
|
2
|
+
import { t as OpenAPICodegenConfig } from "./config-BU7wVf7U.mjs";
|
|
3
|
+
import { a as GenerateOpenApiFile } from "./openapi-D9apjIRy.mjs";
|
|
3
4
|
import { IncomingMessage, ServerResponse } from "http";
|
|
4
5
|
|
|
5
6
|
//#region src/metro/openapi-codegen.plugin.d.ts
|
|
@@ -29,4 +30,16 @@ type MetroConfig = {
|
|
|
29
30
|
declare function withOpenApiCodegen<TMetroConfig extends MetroConfig>(metroConfig: Promise<TMetroConfig>, codegenConfig: OpenApiCodegenMetroConfig, options?: OpenApiCodegenMetroOptions): Promise<TMetroConfig>;
|
|
30
31
|
declare function withOpenApiCodegen<TMetroConfig extends MetroConfig>(metroConfig: TMetroConfig, codegenConfig: OpenApiCodegenMetroConfig, options?: OpenApiCodegenMetroOptions): TMetroConfig;
|
|
31
32
|
//#endregion
|
|
32
|
-
|
|
33
|
+
//#region src/metro/tiny-openapi-codegen.plugin.d.ts
|
|
34
|
+
interface TinyOpenApiCodegenMetroOptions extends OpenApiCodegenMetroOptions {
|
|
35
|
+
apiMode?: string;
|
|
36
|
+
cwd?: string;
|
|
37
|
+
env?: NodeJS.ProcessEnv;
|
|
38
|
+
generateOpenApiFile: GenerateOpenApiFile;
|
|
39
|
+
watchFolders: readonly string[];
|
|
40
|
+
watchTinyOpenApiInput?: boolean;
|
|
41
|
+
}
|
|
42
|
+
declare function tinyOpenApiCodegenMetro<TMetroConfig extends MetroConfig>(metroConfig: Promise<TMetroConfig>, codegenConfig: OpenApiCodegenMetroConfig, options: TinyOpenApiCodegenMetroOptions): Promise<TMetroConfig>;
|
|
43
|
+
declare function tinyOpenApiCodegenMetro<TMetroConfig extends MetroConfig>(metroConfig: TMetroConfig, codegenConfig: OpenApiCodegenMetroConfig, options: TinyOpenApiCodegenMetroOptions): TMetroConfig;
|
|
44
|
+
//#endregion
|
|
45
|
+
export { type MetroConfig, type MetroMiddleware, type OpenAPICodegenConfig, type OpenApiCodegenMetroConfig, type OpenApiCodegenMetroOptions, type TinyOpenApiCodegenMetroOptions, tinyOpenApiCodegenMetro, withOpenApiCodegen };
|
package/dist/metro.mjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import "./generateCodeFromOpenAPIDoc-C-n0Knj8.mjs";
|
|
2
2
|
import "./generate.runner-BXTc97I0.mjs";
|
|
3
3
|
import { t as createOpenApiCodegenRunner } from "./openapi-codegen.runner-QGd35-a3.mjs";
|
|
4
|
+
import { i as normalizeWatchFolders, r as isTinyOpenApiFakeMode, t as createTinyOpenApiSourceRunner } from "./openapi-source.runner-D19XnvMe.mjs";
|
|
4
5
|
import fs from "fs";
|
|
5
6
|
import path from "path";
|
|
6
7
|
|
|
7
8
|
//#region src/metro/openapi-codegen.plugin.ts
|
|
8
9
|
function withOpenApiCodegen(metroConfig, codegenConfig, options = {}) {
|
|
9
|
-
if (isPromiseLike(metroConfig)) return metroConfig.then((resolvedConfig) => withResolvedOpenApiCodegen(resolvedConfig, codegenConfig, options));
|
|
10
|
+
if (isPromiseLike$1(metroConfig)) return metroConfig.then((resolvedConfig) => withResolvedOpenApiCodegen(resolvedConfig, codegenConfig, options));
|
|
10
11
|
return withResolvedOpenApiCodegen(metroConfig, codegenConfig, options);
|
|
11
12
|
}
|
|
12
13
|
function withResolvedOpenApiCodegen(metroConfig, codegenConfig, options) {
|
|
@@ -37,11 +38,11 @@ function withResolvedOpenApiCodegen(metroConfig, codegenConfig, options) {
|
|
|
37
38
|
try {
|
|
38
39
|
inputWatcher = fs.watch(inputPath, { persistent: false }, () => {
|
|
39
40
|
startupSucceeded = false;
|
|
40
|
-
requestStartupGenerate().catch(reportGenerateError);
|
|
41
|
+
requestStartupGenerate().catch(reportGenerateError$1);
|
|
41
42
|
});
|
|
42
|
-
inputWatcher.on("error", reportWatcherError);
|
|
43
|
+
inputWatcher.on("error", reportWatcherError$1);
|
|
43
44
|
} catch (error) {
|
|
44
|
-
reportWatcherError(error);
|
|
45
|
+
reportWatcherError$1(error);
|
|
45
46
|
}
|
|
46
47
|
};
|
|
47
48
|
const wrappedConfig = {
|
|
@@ -72,15 +73,113 @@ function withResolvedOpenApiCodegen(metroConfig, codegenConfig, options) {
|
|
|
72
73
|
if (options.root || metroConfig.projectRoot) wrappedConfig.projectRoot = root;
|
|
73
74
|
return wrappedConfig;
|
|
74
75
|
}
|
|
76
|
+
function isPromiseLike$1(value) {
|
|
77
|
+
return typeof value.then === "function";
|
|
78
|
+
}
|
|
79
|
+
function reportGenerateError$1(error) {
|
|
80
|
+
console.error("[openapi-codegen] Failed to generate OpenAPI client from Metro config.", error);
|
|
81
|
+
}
|
|
82
|
+
function reportWatcherError$1(error) {
|
|
83
|
+
console.error("[openapi-codegen] Failed to watch OpenAPI input from Metro config.", error);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/metro/tiny-openapi-codegen.plugin.ts
|
|
88
|
+
const watchedEvents = new Set(["change", "rename"]);
|
|
89
|
+
function tinyOpenApiCodegenMetro(metroConfig, codegenConfig, options) {
|
|
90
|
+
if (isPromiseLike(metroConfig)) return metroConfig.then((resolvedConfig) => withResolvedTinyOpenApiCodegen(resolvedConfig, codegenConfig, options));
|
|
91
|
+
return withResolvedTinyOpenApiCodegen(metroConfig, codegenConfig, options);
|
|
92
|
+
}
|
|
93
|
+
function withResolvedTinyOpenApiCodegen(metroConfig, codegenConfig, options) {
|
|
94
|
+
if (!isTinyOpenApiFakeMode(options.apiMode)) return withOpenApiCodegen(metroConfig, codegenConfig, options);
|
|
95
|
+
const root = path.resolve(options.root ?? metroConfig.projectRoot ?? process.cwd());
|
|
96
|
+
const sourceRunner = createTinyOpenApiSourceRunner({
|
|
97
|
+
cwd: options.cwd,
|
|
98
|
+
env: options.env,
|
|
99
|
+
generateOpenApiFile: options.generateOpenApiFile,
|
|
100
|
+
input: codegenConfig.input,
|
|
101
|
+
root
|
|
102
|
+
});
|
|
103
|
+
const codegenRunner = createOpenApiCodegenRunner(codegenConfig);
|
|
104
|
+
const originalEnhanceMiddleware = metroConfig.server?.enhanceMiddleware;
|
|
105
|
+
const originalGetTransformOptions = metroConfig.transformer?.getTransformOptions;
|
|
106
|
+
let startupSucceeded = false;
|
|
107
|
+
let inflightGenerate;
|
|
108
|
+
let watcherReady = false;
|
|
109
|
+
const requestGenerateAll = () => {
|
|
110
|
+
if (startupSucceeded) return Promise.resolve();
|
|
111
|
+
if (inflightGenerate) return inflightGenerate;
|
|
112
|
+
const attempt = sourceRunner.enqueueGenerate().then(() => codegenRunner.enqueueGenerate(root)).then(() => {
|
|
113
|
+
startupSucceeded = true;
|
|
114
|
+
inflightGenerate = void 0;
|
|
115
|
+
}, (error) => {
|
|
116
|
+
inflightGenerate = void 0;
|
|
117
|
+
throw error;
|
|
118
|
+
});
|
|
119
|
+
inflightGenerate = attempt;
|
|
120
|
+
return attempt;
|
|
121
|
+
};
|
|
122
|
+
const requestSourceChangeGenerate = () => {
|
|
123
|
+
startupSucceeded = false;
|
|
124
|
+
return requestGenerateAll();
|
|
125
|
+
};
|
|
126
|
+
const ensureWatcher = () => {
|
|
127
|
+
if (watcherReady || options.watchTinyOpenApiInput === false) return;
|
|
128
|
+
watcherReady = true;
|
|
129
|
+
normalizeWatchFolders(root, options.watchFolders).flatMap(watchPath);
|
|
130
|
+
};
|
|
131
|
+
const enhancedConfig = {
|
|
132
|
+
...metroConfig,
|
|
133
|
+
server: {
|
|
134
|
+
...metroConfig.server,
|
|
135
|
+
enhanceMiddleware(middleware, server) {
|
|
136
|
+
ensureWatcher();
|
|
137
|
+
const enhancedMiddleware = originalEnhanceMiddleware ? originalEnhanceMiddleware(middleware, server) : middleware;
|
|
138
|
+
return async (request, response, next) => {
|
|
139
|
+
try {
|
|
140
|
+
await requestGenerateAll();
|
|
141
|
+
return await enhancedMiddleware(request, response, next);
|
|
142
|
+
} catch (error) {
|
|
143
|
+
next(error);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
transformer: {
|
|
149
|
+
...metroConfig.transformer,
|
|
150
|
+
async getTransformOptions(...args) {
|
|
151
|
+
await requestGenerateAll();
|
|
152
|
+
return originalGetTransformOptions ? originalGetTransformOptions(...args) : void 0;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
if (options.root || metroConfig.projectRoot) enhancedConfig.projectRoot = root;
|
|
157
|
+
return enhancedConfig;
|
|
158
|
+
function watchPath(target) {
|
|
159
|
+
try {
|
|
160
|
+
const watcher = fs.watch(target, {
|
|
161
|
+
persistent: false,
|
|
162
|
+
recursive: fs.existsSync(target) && fs.statSync(target).isDirectory()
|
|
163
|
+
}, (event) => {
|
|
164
|
+
if (watchedEvents.has(event)) requestSourceChangeGenerate().catch(reportGenerateError);
|
|
165
|
+
});
|
|
166
|
+
watcher.on("error", reportWatcherError);
|
|
167
|
+
return [watcher];
|
|
168
|
+
} catch (error) {
|
|
169
|
+
reportWatcherError(error);
|
|
170
|
+
return [];
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
75
174
|
function isPromiseLike(value) {
|
|
76
175
|
return typeof value.then === "function";
|
|
77
176
|
}
|
|
78
177
|
function reportGenerateError(error) {
|
|
79
|
-
console.error("[openapi
|
|
178
|
+
console.error("[tiny-openapi] Failed to generate OpenAPI spec from Metro config.", error);
|
|
80
179
|
}
|
|
81
180
|
function reportWatcherError(error) {
|
|
82
|
-
console.error("[openapi
|
|
181
|
+
console.error("[tiny-openapi] Failed to watch OpenAPI inputs from Metro config.", error);
|
|
83
182
|
}
|
|
84
183
|
|
|
85
184
|
//#endregion
|
|
86
|
-
export { withOpenApiCodegen };
|
|
185
|
+
export { tinyOpenApiCodegenMetro, withOpenApiCodegen };
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
//#region src/tiny/openapi.d.ts
|
|
2
|
+
interface GenerateOpenApiFileOptions {
|
|
3
|
+
argv?: readonly string[];
|
|
4
|
+
cwd?: string;
|
|
5
|
+
defaultOutput: string;
|
|
6
|
+
env?: NodeJS.ProcessEnv;
|
|
7
|
+
}
|
|
8
|
+
interface GenerateTinyOpenApiFileOptions extends GenerateOpenApiFileOptions {
|
|
9
|
+
generateOpenApiSpec: () => Promise<unknown> | unknown;
|
|
10
|
+
}
|
|
11
|
+
interface GenerateOpenApiFileResult {
|
|
12
|
+
changed: boolean;
|
|
13
|
+
outputPath: string;
|
|
14
|
+
}
|
|
15
|
+
type GenerateOpenApiFile = (options: GenerateOpenApiFileOptions) => Promise<unknown> | unknown;
|
|
16
|
+
type JsonObject = Record<string, unknown>;
|
|
17
|
+
type AnySchema = unknown;
|
|
18
|
+
type AnyContractRouter = unknown;
|
|
19
|
+
type OpenApiSchemaRegistry = Record<string, {
|
|
20
|
+
schema?: AnySchema;
|
|
21
|
+
strategy?: "input" | "output";
|
|
22
|
+
}>;
|
|
23
|
+
type AclRule = `${string}:${string}`;
|
|
24
|
+
type ZodSchema = AnySchema & {
|
|
25
|
+
_zod: {
|
|
26
|
+
def: JsonObject;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
interface ProcedureMeta {
|
|
30
|
+
bl: string;
|
|
31
|
+
acl?: AclRule[];
|
|
32
|
+
}
|
|
33
|
+
interface TinyOpenApiUserRole {
|
|
34
|
+
description?: string;
|
|
35
|
+
isDefault?: boolean;
|
|
36
|
+
name: string;
|
|
37
|
+
}
|
|
38
|
+
interface TinyOpenApiModule {
|
|
39
|
+
extraSchemas?: OpenApiSchemaRegistry;
|
|
40
|
+
openApiController?: string;
|
|
41
|
+
openApiTag?: string;
|
|
42
|
+
robodevHidden?: boolean;
|
|
43
|
+
robodevOwnedTables?: readonly string[];
|
|
44
|
+
robodevRoles?: readonly string[];
|
|
45
|
+
}
|
|
46
|
+
interface GenerateORPCOpenAPISpecOptions {
|
|
47
|
+
apiModules: Record<string, TinyOpenApiModule>;
|
|
48
|
+
apiRoot?: string;
|
|
49
|
+
contract: AnyContractRouter;
|
|
50
|
+
dbTablesRoot?: string;
|
|
51
|
+
getOpenApiSchemaName?: (schema: unknown) => string | undefined;
|
|
52
|
+
info?: JsonObject;
|
|
53
|
+
realBackendSortableSchemaNames?: ReadonlyMap<string, string> | Record<string, string>;
|
|
54
|
+
servers?: JsonObject[];
|
|
55
|
+
userRoles?: readonly TinyOpenApiUserRole[];
|
|
56
|
+
}
|
|
57
|
+
interface ModelSchemaExport {
|
|
58
|
+
moduleName: string;
|
|
59
|
+
name: string;
|
|
60
|
+
schema: ZodSchema;
|
|
61
|
+
}
|
|
62
|
+
interface OperationContractInfo {
|
|
63
|
+
meta: ProcedureMeta;
|
|
64
|
+
path: string[];
|
|
65
|
+
routeOperationId?: string;
|
|
66
|
+
}
|
|
67
|
+
interface OrpcContractProcedureData {
|
|
68
|
+
inputSchema?: AnySchema;
|
|
69
|
+
meta?: unknown;
|
|
70
|
+
outputSchema?: AnySchema;
|
|
71
|
+
route: {
|
|
72
|
+
inputStructure?: string;
|
|
73
|
+
method?: string;
|
|
74
|
+
operationId?: string;
|
|
75
|
+
path?: string;
|
|
76
|
+
successStatus?: number;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
declare function resolveOpenApiOutputPath({
|
|
80
|
+
argv,
|
|
81
|
+
cwd,
|
|
82
|
+
defaultOutput,
|
|
83
|
+
env
|
|
84
|
+
}: GenerateOpenApiFileOptions): string;
|
|
85
|
+
declare function generateOpenApiFile(options: GenerateTinyOpenApiFileOptions): Promise<GenerateOpenApiFileResult>;
|
|
86
|
+
declare function defineOpenApiSchemas<const TSchemas extends OpenApiSchemaRegistry>(schemas: TSchemas): TSchemas;
|
|
87
|
+
declare function collectExtraSchemas<TModules extends Record<string, {
|
|
88
|
+
extraSchemas?: OpenApiSchemaRegistry;
|
|
89
|
+
}>>(modules: TModules): OpenApiSchemaRegistry;
|
|
90
|
+
declare function namedOpenApiSchema<TSchema extends object>(schema: TSchema, name: string): TSchema;
|
|
91
|
+
declare function namedOpenApiRequestSchema<TSchema extends object>(schema: TSchema, name: string): TSchema;
|
|
92
|
+
declare function namedOpenApiResponseSchema<TSchema extends object>(schema: TSchema, name: string): TSchema;
|
|
93
|
+
declare function namedOpenApiOutputSchema<TSchema extends object>(schema: TSchema, name: string): TSchema;
|
|
94
|
+
declare function namedControllerActionSchema<TSchema extends object>(schema: TSchema, controller: string, action: string, suffix: string): TSchema;
|
|
95
|
+
declare function namedControllerActionInputDtoSchema<TSchema extends object>(schema: TSchema, controller: string, action: string): TSchema;
|
|
96
|
+
declare function getOpenApiSchemaName(schema: unknown): string | undefined;
|
|
97
|
+
declare function isObject(value: unknown): value is JsonObject;
|
|
98
|
+
declare function getContractProcedureData(router: AnyContractRouter): OrpcContractProcedureData | undefined;
|
|
99
|
+
declare function isContractProcedure(router: AnyContractRouter): boolean;
|
|
100
|
+
declare function asStringArray(value: unknown): string[];
|
|
101
|
+
declare function isNullSchema(value: unknown): boolean;
|
|
102
|
+
declare function isNullableOnlySchema(value: unknown): boolean;
|
|
103
|
+
declare function toOpenAPI30Schema(value: unknown): unknown;
|
|
104
|
+
declare function stripNoContentResponseBodies(spec: JsonObject): void;
|
|
105
|
+
declare function isProcedureMeta(meta: unknown): meta is ProcedureMeta;
|
|
106
|
+
declare function operationKey(method: string, routePath: string): string;
|
|
107
|
+
declare function toPascalCase(value: string): string;
|
|
108
|
+
declare function isZodSchema(value: unknown): value is ZodSchema;
|
|
109
|
+
declare function schemaExportName(moduleName: string, exportName: string, schema: ZodSchema, getSchemaName?: typeof getOpenApiSchemaName): string;
|
|
110
|
+
declare function sharedSchemaExportName(exportName: string): string;
|
|
111
|
+
declare function collectModelSchemaExports(options: {
|
|
112
|
+
apiRoot?: string;
|
|
113
|
+
dbTablesRoot?: string;
|
|
114
|
+
getOpenApiSchemaName?: (schema: unknown) => string | undefined;
|
|
115
|
+
}): Promise<ModelSchemaExport[]>;
|
|
116
|
+
declare function collectApiModelSchemaExports(apiRoot: string, options?: {
|
|
117
|
+
getOpenApiSchemaName?: (schema: unknown) => string | undefined;
|
|
118
|
+
}): Promise<ModelSchemaExport[]>;
|
|
119
|
+
declare function collectModuleModelSchemaExports(apiRoot: string, moduleName: string, options?: {
|
|
120
|
+
getOpenApiSchemaName?: (schema: unknown) => string | undefined;
|
|
121
|
+
}): Promise<ModelSchemaExport[]>;
|
|
122
|
+
declare function collectDbTableModelSchemaExports(tablesRoot: string): Promise<ModelSchemaExport[]>;
|
|
123
|
+
declare function collectDbTableModelSchemaExport(tablesRoot: string, tableName: string): Promise<ModelSchemaExport[]>;
|
|
124
|
+
declare function toOpenAPIAclRule(rule: string): JsonObject;
|
|
125
|
+
declare function collectOperationMeta(router: AnyContractRouter, routerPath?: string[], operationMeta?: Map<string, OperationContractInfo>): Map<string, OperationContractInfo>;
|
|
126
|
+
declare function getObjectPropertySchema(schema: AnySchema, property: string): AnySchema | undefined;
|
|
127
|
+
declare function routeHasPathParameters(routePath?: string): boolean;
|
|
128
|
+
declare function getProcedureInputSchemaRole(route: OrpcContractProcedureData["route"]): "Params" | "Query" | "Request";
|
|
129
|
+
declare function procedureSchemaName(procedureName: string, role: "Params" | "Query" | "Request" | "Response"): string;
|
|
130
|
+
declare function addContractSchema(schemas: OpenApiSchemaRegistry, schema: AnySchema | undefined, name: string, getSchemaName: (schema: unknown) => string | undefined, strategy?: "input" | "output"): void;
|
|
131
|
+
declare function collectContractSchemas(router: AnyContractRouter, routerPath?: string[], schemas?: OpenApiSchemaRegistry, getSchemaName?: typeof getOpenApiSchemaName): OpenApiSchemaRegistry;
|
|
132
|
+
declare function collectContractSchemaRoots(router: AnyContractRouter, roots?: Set<unknown>): Set<AnySchema>;
|
|
133
|
+
declare function visitZodSchema(schema: ZodSchema, visit: (schema: ZodSchema) => void, seen?: Set<{
|
|
134
|
+
_zod: {
|
|
135
|
+
def: JsonObject;
|
|
136
|
+
};
|
|
137
|
+
}>): void;
|
|
138
|
+
declare function collectSchemaRegistryRoots(registry: OpenApiSchemaRegistry): Set<AnySchema>;
|
|
139
|
+
declare function collectReachableModelSchemas(router: AnyContractRouter, options?: {
|
|
140
|
+
apiRoot?: string;
|
|
141
|
+
dbTablesRoot?: string;
|
|
142
|
+
excludedSchemas?: Set<AnySchema>;
|
|
143
|
+
getOpenApiSchemaName?: (schema: unknown) => string | undefined;
|
|
144
|
+
}): Promise<OpenApiSchemaRegistry>;
|
|
145
|
+
declare function compactTagName(value: string): string;
|
|
146
|
+
declare function getModuleOpenApiController(apiModules: Record<string, TinyOpenApiModule>, moduleName: string): string;
|
|
147
|
+
declare function getOperationController(apiModules: Record<string, TinyOpenApiModule>, operationPath: string[]): string | undefined;
|
|
148
|
+
declare function getOperationAction(operationPath: string[]): string | undefined;
|
|
149
|
+
declare function getDerivedOperationId(apiModules: Record<string, TinyOpenApiModule>, info: OperationContractInfo): string | undefined;
|
|
150
|
+
declare function applyOperationMeta(spec: JsonObject, operationMeta: Map<string, OperationContractInfo>, apiModules: Record<string, TinyOpenApiModule>): void;
|
|
151
|
+
declare function findEnumNames(value: unknown): string[] | undefined;
|
|
152
|
+
declare function getStringEnumValues(schema: JsonObject): string[] | undefined;
|
|
153
|
+
declare function applyEnumExtensions(value: unknown): void;
|
|
154
|
+
declare function findComponentEnumNames(spec: JsonObject, name: string): string[] | undefined;
|
|
155
|
+
declare function applyParameterExtensions(spec: JsonObject, realBackendSortableSchemaNames?: ReadonlyMap<string, string>): void;
|
|
156
|
+
declare function getModuleOpenApiTag(apiModules: Record<string, TinyOpenApiModule>, moduleName: string): string;
|
|
157
|
+
declare function applyRobodevModuleExtensions(spec: JsonObject, moduleExtensions: Map<string, {
|
|
158
|
+
hidden: boolean;
|
|
159
|
+
tables: string[];
|
|
160
|
+
roles: string[];
|
|
161
|
+
}>, apiModules: Record<string, TinyOpenApiModule>): void;
|
|
162
|
+
declare function applyRobodevUserRolesExtension(spec: JsonObject, userRoles?: readonly TinyOpenApiUserRole[]): void;
|
|
163
|
+
declare function collectOperationTags(spec: JsonObject): Set<string>;
|
|
164
|
+
declare function getRobodevModuleRoles(hidden: boolean, explicitRoles: readonly string[] | null, moduleHasOperations: boolean, defaultRoles: readonly string[]): string[];
|
|
165
|
+
declare function schemaComponentRef(name: string): JsonObject;
|
|
166
|
+
declare function getComponentSchemas(spec: JsonObject): JsonObject | null;
|
|
167
|
+
declare function getPaginatedItemSchema(schema: JsonObject): unknown;
|
|
168
|
+
declare function applyPaginatedItemSchemas(spec: JsonObject): void;
|
|
169
|
+
declare function toOpenAPI30Document(spec: JsonObject): JsonObject;
|
|
170
|
+
declare function generateORPCOpenAPISpec(options: GenerateORPCOpenAPISpecOptions): Promise<JsonObject>;
|
|
171
|
+
//#endregion
|
|
172
|
+
export { getStringEnumValues as $, collectModuleModelSchemaExports as A, generateOpenApiFile as B, collectApiModelSchemaExports as C, toPascalCase as Ct, collectDbTableModelSchemaExports as D, collectDbTableModelSchemaExport as E, compactTagName as F, getModuleOpenApiTag as G, getContractProcedureData as H, defineOpenApiSchemas as I, getOperationAction as J, getObjectPropertySchema as K, findComponentEnumNames as L, collectOperationTags as M, collectReachableModelSchemas as N, collectExtraSchemas as O, collectSchemaRegistryRoots as P, getRobodevModuleRoles as Q, findEnumNames as R, asStringArray as S, toOpenAPIAclRule as St, collectContractSchemas as T, getDerivedOperationId as U, getComponentSchemas as V, getModuleOpenApiController as W, getPaginatedItemSchema as X, getOperationController as Y, getProcedureInputSchemaRole as Z, applyOperationMeta as _, schemaExportName as _t, GenerateOpenApiFile as a, isZodSchema as at, applyRobodevModuleExtensions as b, toOpenAPI30Document as bt, GenerateTinyOpenApiFileOptions as c, namedOpenApiOutputSchema as ct, ProcedureMeta as d, namedOpenApiSchema as dt, isContractProcedure as et, TinyOpenApiModule as f, operationKey as ft, applyEnumExtensions as g, schemaComponentRef as gt, addContractSchema as h, routeHasPathParameters as ht, GenerateORPCOpenAPISpecOptions as i, isProcedureMeta as it, collectOperationMeta as j, collectModelSchemaExports as k, JsonObject as l, namedOpenApiRequestSchema as lt, ZodSchema as m, resolveOpenApiOutputPath as mt, AnyContractRouter as n, isNullableOnlySchema as nt, GenerateOpenApiFileOptions as o, namedControllerActionInputDtoSchema as ot, TinyOpenApiUserRole as p, procedureSchemaName as pt, getOpenApiSchemaName as q, AnySchema as r, isObject as rt, GenerateOpenApiFileResult as s, namedControllerActionSchema as st, AclRule as t, isNullSchema as tt, OpenApiSchemaRegistry as u, namedOpenApiResponseSchema as ut, applyPaginatedItemSchemas as v, sharedSchemaExportName as vt, collectContractSchemaRoots as w, visitZodSchema as wt, applyRobodevUserRolesExtension as x, toOpenAPI30Schema as xt, applyParameterExtensions as y, stripNoContentResponseBodies as yt, generateORPCOpenAPISpec as z };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
|
|
3
|
+
//#region src/tiny/openapi-source.runner.ts
|
|
4
|
+
function createTinyOpenApiSourceRunner(config) {
|
|
5
|
+
let queue = Promise.resolve();
|
|
6
|
+
const getOutputPath = () => getLocalInputPath(config.input, config.root);
|
|
7
|
+
const runGenerate = async () => {
|
|
8
|
+
const outputPath = getOutputPath();
|
|
9
|
+
if (!outputPath) return;
|
|
10
|
+
await config.generateOpenApiFile({
|
|
11
|
+
argv: ["--output", outputPath],
|
|
12
|
+
cwd: config.cwd ?? config.root,
|
|
13
|
+
defaultOutput: outputPath,
|
|
14
|
+
env: config.env ?? process.env
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
const enqueueGenerate = () => {
|
|
18
|
+
const run = queue.catch(() => void 0).then(runGenerate);
|
|
19
|
+
queue = run.then(() => void 0, () => void 0);
|
|
20
|
+
return run;
|
|
21
|
+
};
|
|
22
|
+
return {
|
|
23
|
+
enqueueGenerate,
|
|
24
|
+
getOutputPath
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function isTinyOpenApiFakeMode(apiMode = process.env.VITE_PUBLIC_API_MODE ?? process.env.EXPO_PUBLIC_API_MODE) {
|
|
28
|
+
return apiMode !== "real";
|
|
29
|
+
}
|
|
30
|
+
function getLocalInputPath(input, root) {
|
|
31
|
+
if (typeof input !== "string" || /^https?:\/\//i.test(input)) return;
|
|
32
|
+
return path.resolve(root, input);
|
|
33
|
+
}
|
|
34
|
+
function normalizeWatchFolders(root, watchFolders = []) {
|
|
35
|
+
return watchFolders.map((folder) => path.isAbsolute(folder) ? folder : path.resolve(root, folder));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { normalizeWatchFolders as i, getLocalInputPath as n, isTinyOpenApiFakeMode as r, createTinyOpenApiSourceRunner as t };
|
package/dist/sh.mjs
CHANGED
package/dist/tiny.d.mts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import "./options-CE4Koxof.mjs";
|
|
2
|
+
import { t as OpenAPICodegenConfig } from "./config-BU7wVf7U.mjs";
|
|
3
|
+
import { $ as getStringEnumValues, A as collectModuleModelSchemaExports, B as generateOpenApiFile, C as collectApiModelSchemaExports, Ct as toPascalCase, D as collectDbTableModelSchemaExports, E as collectDbTableModelSchemaExport, F as compactTagName, G as getModuleOpenApiTag, H as getContractProcedureData, I as defineOpenApiSchemas, J as getOperationAction, K as getObjectPropertySchema, L as findComponentEnumNames, M as collectOperationTags, N as collectReachableModelSchemas, O as collectExtraSchemas, P as collectSchemaRegistryRoots, Q as getRobodevModuleRoles, R as findEnumNames, S as asStringArray, St as toOpenAPIAclRule, T as collectContractSchemas, U as getDerivedOperationId, V as getComponentSchemas, W as getModuleOpenApiController, X as getPaginatedItemSchema, Y as getOperationController, Z as getProcedureInputSchemaRole, _ as applyOperationMeta, _t as schemaExportName, a as GenerateOpenApiFile, at as isZodSchema, b as applyRobodevModuleExtensions, bt as toOpenAPI30Document, c as GenerateTinyOpenApiFileOptions, ct as namedOpenApiOutputSchema, d as ProcedureMeta, dt as namedOpenApiSchema, et as isContractProcedure, f as TinyOpenApiModule, ft as operationKey, g as applyEnumExtensions, gt as schemaComponentRef, h as addContractSchema, ht as routeHasPathParameters, i as GenerateORPCOpenAPISpecOptions, it as isProcedureMeta, j as collectOperationMeta, k as collectModelSchemaExports, l as JsonObject, lt as namedOpenApiRequestSchema, m as ZodSchema, mt as resolveOpenApiOutputPath, n as AnyContractRouter, nt as isNullableOnlySchema, o as GenerateOpenApiFileOptions, ot as namedControllerActionInputDtoSchema, p as TinyOpenApiUserRole, pt as procedureSchemaName, q as getOpenApiSchemaName, r as AnySchema, rt as isObject, s as GenerateOpenApiFileResult, st as namedControllerActionSchema, t as AclRule, tt as isNullSchema, u as OpenApiSchemaRegistry, ut as namedOpenApiResponseSchema, v as applyPaginatedItemSchemas, vt as sharedSchemaExportName, w as collectContractSchemaRoots, wt as visitZodSchema, x as applyRobodevUserRolesExtension, xt as toOpenAPI30Schema, y as applyParameterExtensions, yt as stripNoContentResponseBodies, z as generateORPCOpenAPISpec } from "./openapi-D9apjIRy.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/tiny/openapi-source.runner.d.ts
|
|
6
|
+
interface TinyOpenApiSourceRunnerConfig {
|
|
7
|
+
cwd?: string;
|
|
8
|
+
env?: NodeJS.ProcessEnv;
|
|
9
|
+
generateOpenApiFile: GenerateOpenApiFile;
|
|
10
|
+
input: OpenAPICodegenConfig["input"];
|
|
11
|
+
root: string;
|
|
12
|
+
}
|
|
13
|
+
declare function createTinyOpenApiSourceRunner(config: TinyOpenApiSourceRunnerConfig): {
|
|
14
|
+
enqueueGenerate: () => Promise<void>;
|
|
15
|
+
getOutputPath: () => string | undefined;
|
|
16
|
+
};
|
|
17
|
+
declare function isTinyOpenApiFakeMode(apiMode?: string | undefined): boolean;
|
|
18
|
+
declare function getLocalInputPath(input: OpenAPICodegenConfig["input"], root: string): string | undefined;
|
|
19
|
+
declare function normalizeWatchFolders(root: string, watchFolders?: readonly string[]): string[];
|
|
20
|
+
//#endregion
|
|
21
|
+
export { AclRule, AnyContractRouter, AnySchema, GenerateORPCOpenAPISpecOptions, GenerateOpenApiFile, GenerateOpenApiFileOptions, GenerateOpenApiFileResult, 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, 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, namedControllerActionInputDtoSchema, namedControllerActionSchema, namedOpenApiOutputSchema, namedOpenApiRequestSchema, namedOpenApiResponseSchema, namedOpenApiSchema, normalizeWatchFolders as normalizeTinyOpenApiWatchFolders, operationKey, procedureSchemaName, resolveOpenApiOutputPath, routeHasPathParameters, schemaComponentRef, schemaExportName, sharedSchemaExportName, stripNoContentResponseBodies, toOpenAPI30Document, toOpenAPI30Schema, toOpenAPIAclRule, toPascalCase, visitZodSchema };
|