@povio/openapi-codegen-cli 3.0.0-rc.9 → 3.1.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { n as GenerateFileData, t as GenerateOptions } from "./options-BPAjzilp.mjs";
1
+ import { n as GenerateFileData, t as GenerateOptions } from "./options-CE4Koxof.mjs";
2
2
  import { OpenAPIV3 } from "openapi-types";
3
3
 
4
4
  //#region src/generators/types/metadata.d.ts
@@ -1,4 +1,4 @@
1
- import { _ as getNamespaceName, a as getDataFromOpenAPIDoc, b as isParamMediaTypeAllowed, c as getSchemaTsMetaType, d as getTagImportPath, f as getQueryName, g as invalidVariableNameCharactersToCamel, l as getTsTypeBase, o as isMutation, p as DEFAULT_GENERATE_OPTIONS, s as isQuery, t as generateCodeFromOpenAPIDoc, v as GenerateType, x as formatTag, y as isMediaTypeAllowed } from "./generateCodeFromOpenAPIDoc-NA2XZmIv.mjs";
1
+ import { _ as getNamespaceName, a as getDataFromOpenAPIDoc, b as isParamMediaTypeAllowed, c as getSchemaTsMetaType, d as getTagImportPath, f as getQueryName, g as invalidVariableNameCharactersToCamel, l as getTsTypeBase, o as isMutation, p as DEFAULT_GENERATE_OPTIONS, s as isQuery, t as generateCodeFromOpenAPIDoc, v as GenerateType, x as formatTag, y as isMediaTypeAllowed } from "./generateCodeFromOpenAPIDoc-C-n0Knj8.mjs";
2
2
  import SwaggerParser from "@apidevtools/swagger-parser";
3
3
 
4
4
  //#region src/generators/core/getMetadataFromOpenAPIDoc.ts
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-B4aYKmyL.mjs";
2
- import "./options-BPAjzilp.mjs";
3
- import { t as OpenAPICodegenConfig } from "./config-C1ME3Ay4.mjs";
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";
@@ -26,6 +26,7 @@ interface RequestInfo<ZOutput, ECodes extends string> {
26
26
  }
27
27
  interface RequestConfig<IsRawRes extends boolean = false> {
28
28
  rawResponse?: IsRawRes;
29
+ allowInvalidResponseData?: boolean;
29
30
  }
30
31
  type Response<ZOutput, IsRawRes extends boolean = false> = IsRawRes extends true ? AxiosResponse<ZOutput> : ZOutput;
31
32
  interface RestClient {
@@ -90,6 +91,7 @@ declare namespace OpenApiQueryConfig {
90
91
  invalidateCurrentModule?: boolean;
91
92
  invalidationMap?: InvalidationMap<TQueryModule>;
92
93
  crossTabInvalidation?: boolean;
94
+ allowInvalidResponseData?: boolean;
93
95
  onError?: (error: unknown) => void;
94
96
  }
95
97
  type ProviderProps<TQueryModule extends QueryModule = QueryModule> = Type<TQueryModule>;
@@ -98,6 +100,7 @@ declare namespace OpenApiQueryConfig {
98
100
  invalidateCurrentModule,
99
101
  invalidationMap,
100
102
  crossTabInvalidation,
103
+ allowInvalidResponseData,
101
104
  onError,
102
105
  children
103
106
  }: PropsWithChildren<ProviderProps<TQueryModule>>): react_jsx_runtime0.JSX.Element;
package/dist/index.mjs CHANGED
@@ -66,9 +66,18 @@ var RestClient = class {
66
66
  async makeRequest(requestInfo, requestConfig) {
67
67
  const errorStack = (/* @__PURE__ */ new Error()).stack;
68
68
  try {
69
- const { rawResponse, ...config } = requestConfig;
69
+ const { rawResponse, allowInvalidResponseData, ...config } = requestConfig;
70
70
  const res = await this.client(config);
71
- const resData = requestInfo.resSchema.parse(res.data);
71
+ const responseData = res.status === 204 && res.data === "" ? void 0 : res.data;
72
+ const parseResult = requestInfo.resSchema.safeParse(responseData);
73
+ let resData;
74
+ if (parseResult.success) resData = parseResult.data;
75
+ else if (allowInvalidResponseData && config.method === "get") {
76
+ parseResult.error.name = "BE Response schema mismatch - ZodError";
77
+ parseResult.error.stack = [parseResult.error.stack, ...errorStack?.split("\n").slice(2) ?? []].join("\n");
78
+ console.error(parseResult.error);
79
+ resData = res.data;
80
+ } else throw parseResult.error;
72
81
  return rawResponse ? {
73
82
  ...res,
74
83
  data: resData
@@ -113,18 +122,20 @@ var RestInterceptor = class {
113
122
  let OpenApiQueryConfig;
114
123
  (function(_OpenApiQueryConfig) {
115
124
  const Context = createContext({});
116
- function Provider({ preferUpdate, invalidateCurrentModule, invalidationMap, crossTabInvalidation, onError, children }) {
125
+ function Provider({ preferUpdate, invalidateCurrentModule, invalidationMap, crossTabInvalidation, allowInvalidResponseData, onError, children }) {
117
126
  const value = useMemo(() => ({
118
127
  preferUpdate,
119
128
  invalidateCurrentModule,
120
129
  invalidationMap,
121
130
  crossTabInvalidation,
131
+ allowInvalidResponseData,
122
132
  onError
123
133
  }), [
124
134
  preferUpdate,
125
135
  invalidateCurrentModule,
126
136
  invalidationMap,
127
137
  crossTabInvalidation,
138
+ allowInvalidResponseData,
128
139
  onError
129
140
  ]);
130
141
  return /* @__PURE__ */ jsx(Context.Provider, {
@@ -0,0 +1,45 @@
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-B14GzSA_.mjs";
4
+ import { IncomingMessage, ServerResponse } from "http";
5
+
6
+ //#region src/metro/openapi-codegen.plugin.d.ts
7
+ type OpenApiCodegenMetroConfig = OpenAPICodegenConfig & {
8
+ formatGeneratedFile?: GenerateFileFormatter;
9
+ };
10
+ type OpenApiCodegenMetroOptions = {
11
+ root?: string;
12
+ watchOpenApiInput?: boolean;
13
+ };
14
+ type MetroNextFunction = (error?: unknown) => void;
15
+ type MetroMiddleware = (request: IncomingMessage, response: ServerResponse, next: MetroNextFunction) => unknown;
16
+ type MetroServer = unknown;
17
+ type MetroConfig = {
18
+ projectRoot?: string;
19
+ server?: {
20
+ enhanceMiddleware?: (middleware: MetroMiddleware, server: MetroServer) => MetroMiddleware;
21
+ [key: string]: unknown;
22
+ };
23
+ transformer?: {
24
+ getTransformOptions?: (...args: unknown[]) => unknown;
25
+ [key: string]: unknown;
26
+ };
27
+ watchFolders?: readonly string[];
28
+ [key: string]: unknown;
29
+ };
30
+ declare function withOpenApiCodegen<TMetroConfig extends MetroConfig>(metroConfig: Promise<TMetroConfig>, codegenConfig: OpenApiCodegenMetroConfig, options?: OpenApiCodegenMetroOptions): Promise<TMetroConfig>;
31
+ declare function withOpenApiCodegen<TMetroConfig extends MetroConfig>(metroConfig: TMetroConfig, codegenConfig: OpenApiCodegenMetroConfig, options?: OpenApiCodegenMetroOptions): TMetroConfig;
32
+ //#endregion
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 ADDED
@@ -0,0 +1,185 @@
1
+ import "./generateCodeFromOpenAPIDoc-C-n0Knj8.mjs";
2
+ import "./generate.runner-BXTc97I0.mjs";
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";
5
+ import fs from "fs";
6
+ import path from "path";
7
+
8
+ //#region src/metro/openapi-codegen.plugin.ts
9
+ function withOpenApiCodegen(metroConfig, codegenConfig, options = {}) {
10
+ if (isPromiseLike$1(metroConfig)) return metroConfig.then((resolvedConfig) => withResolvedOpenApiCodegen(resolvedConfig, codegenConfig, options));
11
+ return withResolvedOpenApiCodegen(metroConfig, codegenConfig, options);
12
+ }
13
+ function withResolvedOpenApiCodegen(metroConfig, codegenConfig, options) {
14
+ const root = path.resolve(options.root ?? metroConfig.projectRoot ?? process.cwd());
15
+ const codegen = createOpenApiCodegenRunner(codegenConfig);
16
+ const originalEnhanceMiddleware = metroConfig.server?.enhanceMiddleware;
17
+ const originalGetTransformOptions = metroConfig.transformer?.getTransformOptions;
18
+ let startupSucceeded = false;
19
+ let inflightGenerate;
20
+ let inputWatcher;
21
+ const requestStartupGenerate = () => {
22
+ if (startupSucceeded) return Promise.resolve();
23
+ if (inflightGenerate) return inflightGenerate;
24
+ const attempt = codegen.enqueueGenerate(root).then(() => {
25
+ startupSucceeded = true;
26
+ inflightGenerate = void 0;
27
+ }, (error) => {
28
+ inflightGenerate = void 0;
29
+ throw error;
30
+ });
31
+ inflightGenerate = attempt;
32
+ return attempt;
33
+ };
34
+ const ensureInputWatcher = () => {
35
+ if (options.watchOpenApiInput === false || inputWatcher) return;
36
+ const inputPath = codegen.getLocalInputPath(root);
37
+ if (!inputPath) return;
38
+ try {
39
+ inputWatcher = fs.watch(inputPath, { persistent: false }, () => {
40
+ startupSucceeded = false;
41
+ requestStartupGenerate().catch(reportGenerateError$1);
42
+ });
43
+ inputWatcher.on("error", reportWatcherError$1);
44
+ } catch (error) {
45
+ reportWatcherError$1(error);
46
+ }
47
+ };
48
+ const wrappedConfig = {
49
+ ...metroConfig,
50
+ server: {
51
+ ...metroConfig.server,
52
+ enhanceMiddleware(middleware, server) {
53
+ ensureInputWatcher();
54
+ const enhancedMiddleware = originalEnhanceMiddleware ? originalEnhanceMiddleware(middleware, server) : middleware;
55
+ return async (request, response, next) => {
56
+ try {
57
+ await requestStartupGenerate();
58
+ return await enhancedMiddleware(request, response, next);
59
+ } catch (error) {
60
+ next(error);
61
+ }
62
+ };
63
+ }
64
+ },
65
+ transformer: {
66
+ ...metroConfig.transformer,
67
+ async getTransformOptions(...args) {
68
+ await requestStartupGenerate();
69
+ return originalGetTransformOptions ? originalGetTransformOptions(...args) : void 0;
70
+ }
71
+ }
72
+ };
73
+ if (options.root || metroConfig.projectRoot) wrappedConfig.projectRoot = root;
74
+ return wrappedConfig;
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
+ }
174
+ function isPromiseLike(value) {
175
+ return typeof value.then === "function";
176
+ }
177
+ function reportGenerateError(error) {
178
+ console.error("[tiny-openapi] Failed to generate OpenAPI spec from Metro config.", error);
179
+ }
180
+ function reportWatcherError(error) {
181
+ console.error("[tiny-openapi] Failed to watch OpenAPI inputs from Metro config.", error);
182
+ }
183
+
184
+ //#endregion
185
+ export { tinyOpenApiCodegenMetro, withOpenApiCodegen };
@@ -0,0 +1,170 @@
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 dtoSchemaName(name: string): string;
110
+ declare function shouldUseDtoSchemaName(moduleName: string, schema: ZodSchema): boolean;
111
+ declare function schemaExportName(moduleName: string, exportName: string, schema: ZodSchema, getSchemaName?: typeof getOpenApiSchemaName): string;
112
+ declare function sharedSchemaExportName(exportName: string): string;
113
+ declare function collectModelSchemaExports(options: {
114
+ apiRoot?: string;
115
+ dbTablesRoot?: string;
116
+ getOpenApiSchemaName?: (schema: unknown) => string | undefined;
117
+ }): Promise<ModelSchemaExport[]>;
118
+ declare function collectApiModelSchemaExports(apiRoot: string, options?: {
119
+ getOpenApiSchemaName?: (schema: unknown) => string | undefined;
120
+ }): Promise<ModelSchemaExport[]>;
121
+ declare function collectModuleModelSchemaExports(apiRoot: string, moduleName: string, options?: {
122
+ getOpenApiSchemaName?: (schema: unknown) => string | undefined;
123
+ }): Promise<ModelSchemaExport[]>;
124
+ declare function collectDbTableModelSchemaExports(tablesRoot: string): Promise<ModelSchemaExport[]>;
125
+ declare function collectDbTableModelSchemaExport(tablesRoot: string, tableName: string): Promise<ModelSchemaExport[]>;
126
+ declare function toOpenAPIAclRule(rule: string): JsonObject;
127
+ declare function collectOperationMeta(router: AnyContractRouter, routerPath?: string[], operationMeta?: Map<string, OperationContractInfo>): Map<string, OperationContractInfo>;
128
+ declare function getObjectPropertySchema(schema: AnySchema, property: string): AnySchema | undefined;
129
+ declare function collectContractSchemas(router: AnyContractRouter, routerPath?: string[], schemas?: OpenApiSchemaRegistry, getSchemaName?: typeof getOpenApiSchemaName): OpenApiSchemaRegistry;
130
+ declare function collectContractSchemaRoots(router: AnyContractRouter, roots?: Set<unknown>): Set<AnySchema>;
131
+ declare function visitZodSchema(schema: ZodSchema, visit: (schema: ZodSchema) => void, seen?: Set<{
132
+ _zod: {
133
+ def: JsonObject;
134
+ };
135
+ }>): void;
136
+ declare function collectSchemaRegistryRoots(registry: OpenApiSchemaRegistry): Set<AnySchema>;
137
+ declare function collectReachableModelSchemas(router: AnyContractRouter, options?: {
138
+ apiRoot?: string;
139
+ dbTablesRoot?: string;
140
+ excludedSchemas?: Set<AnySchema>;
141
+ getOpenApiSchemaName?: (schema: unknown) => string | undefined;
142
+ }): Promise<OpenApiSchemaRegistry>;
143
+ declare function compactTagName(value: string): string;
144
+ declare function getModuleOpenApiController(apiModules: Record<string, TinyOpenApiModule>, moduleName: string): string;
145
+ declare function getOperationController(apiModules: Record<string, TinyOpenApiModule>, operationPath: string[]): string | undefined;
146
+ declare function getOperationAction(operationPath: string[]): string | undefined;
147
+ declare function getDerivedOperationId(apiModules: Record<string, TinyOpenApiModule>, info: OperationContractInfo): string | undefined;
148
+ declare function applyOperationMeta(spec: JsonObject, operationMeta: Map<string, OperationContractInfo>, apiModules: Record<string, TinyOpenApiModule>): void;
149
+ declare function findEnumNames(value: unknown): string[] | undefined;
150
+ declare function getStringEnumValues(schema: JsonObject): string[] | undefined;
151
+ declare function applyEnumExtensions(value: unknown): void;
152
+ declare function findComponentEnumNames(spec: JsonObject, name: string): string[] | undefined;
153
+ declare function applyParameterExtensions(spec: JsonObject, realBackendSortableSchemaNames?: ReadonlyMap<string, string>): void;
154
+ declare function getModuleOpenApiTag(apiModules: Record<string, TinyOpenApiModule>, moduleName: string): string;
155
+ declare function applyRobodevModuleExtensions(spec: JsonObject, moduleExtensions: Map<string, {
156
+ hidden: boolean;
157
+ tables: string[];
158
+ roles: string[];
159
+ }>, apiModules: Record<string, TinyOpenApiModule>): void;
160
+ declare function applyRobodevUserRolesExtension(spec: JsonObject, userRoles?: readonly TinyOpenApiUserRole[]): void;
161
+ declare function collectOperationTags(spec: JsonObject): Set<string>;
162
+ declare function getRobodevModuleRoles(hidden: boolean, explicitRoles: readonly string[] | null, moduleHasOperations: boolean, defaultRoles: readonly string[]): string[];
163
+ declare function schemaComponentRef(name: string): JsonObject;
164
+ declare function getComponentSchemas(spec: JsonObject): JsonObject | null;
165
+ declare function getPaginatedItemSchema(schema: JsonObject): unknown;
166
+ declare function applyPaginatedItemSchemas(spec: JsonObject): void;
167
+ declare function toOpenAPI30Document(spec: JsonObject): JsonObject;
168
+ declare function generateORPCOpenAPISpec(options: GenerateORPCOpenAPISpecOptions): Promise<JsonObject>;
169
+ //#endregion
170
+ export { isContractProcedure as $, collectOperationMeta as A, generateOpenApiFile as B, collectContractSchemaRoots as C, collectExtraSchemas as D, collectDbTableModelSchemaExports as E, defineOpenApiSchemas as F, getModuleOpenApiTag as G, getContractProcedureData as H, dtoSchemaName as I, getOperationAction as J, getObjectPropertySchema as K, findComponentEnumNames as L, collectReachableModelSchemas as M, collectSchemaRegistryRoots as N, collectModelSchemaExports as O, compactTagName as P, getStringEnumValues as Q, findEnumNames as R, collectApiModelSchemaExports as S, visitZodSchema as St, collectDbTableModelSchemaExport as T, getDerivedOperationId as U, getComponentSchemas as V, getModuleOpenApiController as W, getPaginatedItemSchema as X, getOperationController as Y, getRobodevModuleRoles as Z, applyPaginatedItemSchemas as _, stripNoContentResponseBodies as _t, GenerateOpenApiFile as a, namedControllerActionInputDtoSchema as at, applyRobodevUserRolesExtension as b, toOpenAPIAclRule as bt, GenerateTinyOpenApiFileOptions as c, namedOpenApiRequestSchema as ct, ProcedureMeta as d, operationKey as dt, isNullSchema as et, TinyOpenApiModule as f, resolveOpenApiOutputPath as ft, applyOperationMeta as g, shouldUseDtoSchemaName as gt, applyEnumExtensions as h, sharedSchemaExportName as ht, GenerateORPCOpenAPISpecOptions as i, isZodSchema as it, collectOperationTags as j, collectModuleModelSchemaExports as k, JsonObject as l, namedOpenApiResponseSchema as lt, ZodSchema as m, schemaExportName as mt, AnyContractRouter as n, isObject as nt, GenerateOpenApiFileOptions as o, namedControllerActionSchema as ot, TinyOpenApiUserRole as p, schemaComponentRef as pt, getOpenApiSchemaName as q, AnySchema as r, isProcedureMeta as rt, GenerateOpenApiFileResult as s, namedOpenApiOutputSchema as st, AclRule as t, isNullableOnlySchema as tt, OpenApiSchemaRegistry as u, namedOpenApiSchema as ut, applyParameterExtensions as v, toOpenAPI30Document as vt, collectContractSchemas as w, asStringArray as x, toPascalCase as xt, applyRobodevModuleExtensions as y, toOpenAPI30Schema as yt, generateORPCOpenAPISpec as z };
@@ -0,0 +1,42 @@
1
+ import { S as Profiler } from "./generateCodeFromOpenAPIDoc-C-n0Knj8.mjs";
2
+ import { t as runGenerate } from "./generate.runner-BXTc97I0.mjs";
3
+ import path from "path";
4
+
5
+ //#region src/plugins/openapi-codegen.runner.ts
6
+ function createOpenApiCodegenRunner(config) {
7
+ let queue = Promise.resolve();
8
+ const { formatGeneratedFile, ...fileConfig } = config;
9
+ const enqueueGenerate = (root) => {
10
+ const run = queue.catch(() => void 0).then(async () => {
11
+ const profiler = new Profiler(process.env.OPENAPI_CODEGEN_PROFILE === "1");
12
+ await runGenerate({
13
+ fileConfig: normalizeOpenApiCodegenPaths(fileConfig, root),
14
+ formatGeneratedFile,
15
+ profiler
16
+ });
17
+ });
18
+ queue = run.then(() => void 0, () => void 0);
19
+ return run;
20
+ };
21
+ return {
22
+ enqueueGenerate,
23
+ getLocalInputPath: (root) => getLocalInputPath(config.input, root),
24
+ isLocalInput: isLocalOpenApiInput(config.input)
25
+ };
26
+ }
27
+ function normalizeOpenApiCodegenPaths(config, root) {
28
+ const normalized = { ...config };
29
+ if (typeof normalized.output === "string" && !path.isAbsolute(normalized.output)) normalized.output = path.resolve(root, normalized.output);
30
+ if (typeof normalized.input === "string" && !path.isAbsolute(normalized.input) && isLocalOpenApiInput(normalized.input)) normalized.input = path.resolve(root, normalized.input);
31
+ return normalized;
32
+ }
33
+ function getLocalInputPath(input, root) {
34
+ if (!isLocalOpenApiInput(input)) return;
35
+ return path.resolve(root, input);
36
+ }
37
+ function isLocalOpenApiInput(input) {
38
+ return typeof input === "string" && !/^https?:\/\//i.test(input);
39
+ }
40
+
41
+ //#endregion
42
+ export { createOpenApiCodegenRunner as t };
@@ -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
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { C as VALIDATION_ERROR_TYPE_TITLE, S as Profiler, a as getDataFromOpenAPIDoc, m as groupByType, n as getOutputFileName, u as getTagFileName, v as GenerateType } from "./generateCodeFromOpenAPIDoc-NA2XZmIv.mjs";
3
- import { n as resolveConfig, t as runGenerate } from "./generate.runner-DSZ2ivlU.mjs";
2
+ import { C as VALIDATION_ERROR_TYPE_TITLE, S as Profiler, a as getDataFromOpenAPIDoc, m as groupByType, n as getOutputFileName, u as getTagFileName, v as GenerateType } from "./generateCodeFromOpenAPIDoc-C-n0Knj8.mjs";
3
+ import { n as resolveConfig, t as runGenerate } from "./generate.runner-BXTc97I0.mjs";
4
4
  import { createRequire } from "node:module";
5
5
  import yargs from "yargs";
6
6
  import { hideBin } from "yargs/helpers";
@@ -39,7 +39,7 @@ function logBanner(message) {
39
39
  * Fetch the version from package.json
40
40
  */
41
41
  function getVersion() {
42
- return "3.0.0-rc.9";
42
+ return "3.1.0-rc.1";
43
43
  }
44
44
 
45
45
  //#endregion
@@ -0,0 +1,21 @@
1
+ import "./options-CE4Koxof.mjs";
2
+ import { t as OpenAPICodegenConfig } from "./config-BU7wVf7U.mjs";
3
+ import { $ as isContractProcedure, A as collectOperationMeta, B as generateOpenApiFile, C as collectContractSchemaRoots, D as collectExtraSchemas, E as collectDbTableModelSchemaExports, F as defineOpenApiSchemas, G as getModuleOpenApiTag, H as getContractProcedureData, I as dtoSchemaName, J as getOperationAction, K as getObjectPropertySchema, L as findComponentEnumNames, M as collectReachableModelSchemas, N as collectSchemaRegistryRoots, O as collectModelSchemaExports, P as compactTagName, Q as getStringEnumValues, R as findEnumNames, S as collectApiModelSchemaExports, St as visitZodSchema, T as collectDbTableModelSchemaExport, U as getDerivedOperationId, V as getComponentSchemas, W as getModuleOpenApiController, X as getPaginatedItemSchema, Y as getOperationController, Z as getRobodevModuleRoles, _ as applyPaginatedItemSchemas, _t as stripNoContentResponseBodies, a as GenerateOpenApiFile, at as namedControllerActionInputDtoSchema, b as applyRobodevUserRolesExtension, bt as toOpenAPIAclRule, c as GenerateTinyOpenApiFileOptions, ct as namedOpenApiRequestSchema, d as ProcedureMeta, dt as operationKey, et as isNullSchema, f as TinyOpenApiModule, ft as resolveOpenApiOutputPath, g as applyOperationMeta, gt as shouldUseDtoSchemaName, h as applyEnumExtensions, ht as sharedSchemaExportName, i as GenerateORPCOpenAPISpecOptions, it as isZodSchema, j as collectOperationTags, k as collectModuleModelSchemaExports, l as JsonObject, lt as namedOpenApiResponseSchema, m as ZodSchema, mt as schemaExportName, n as AnyContractRouter, nt as isObject, o as GenerateOpenApiFileOptions, ot as namedControllerActionSchema, p as TinyOpenApiUserRole, pt as schemaComponentRef, q as getOpenApiSchemaName, r as AnySchema, rt as isProcedureMeta, s as GenerateOpenApiFileResult, st as namedOpenApiOutputSchema, t as AclRule, tt as isNullableOnlySchema, u as OpenApiSchemaRegistry, ut as namedOpenApiSchema, v as applyParameterExtensions, vt as toOpenAPI30Document, w as collectContractSchemas, x as asStringArray, xt as toPascalCase, y as applyRobodevModuleExtensions, yt as toOpenAPI30Schema, z as generateORPCOpenAPISpec } from "./openapi-B14GzSA_.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, applyEnumExtensions, applyOperationMeta, applyPaginatedItemSchemas, applyParameterExtensions, applyRobodevModuleExtensions, applyRobodevUserRolesExtension, asStringArray, collectApiModelSchemaExports, collectContractSchemaRoots, collectContractSchemas, collectDbTableModelSchemaExport, collectDbTableModelSchemaExports, collectExtraSchemas, collectModelSchemaExports, collectModuleModelSchemaExports, collectOperationMeta, collectOperationTags, collectReachableModelSchemas, collectSchemaRegistryRoots, compactTagName, createTinyOpenApiSourceRunner, defineOpenApiSchemas, dtoSchemaName, findComponentEnumNames, findEnumNames, generateORPCOpenAPISpec, generateOpenApiFile, getComponentSchemas, getContractProcedureData, getDerivedOperationId, getModuleOpenApiController, getModuleOpenApiTag, getObjectPropertySchema, getOpenApiSchemaName, getOperationAction, getOperationController, getPaginatedItemSchema, getRobodevModuleRoles, getStringEnumValues, getLocalInputPath as getTinyOpenApiLocalInputPath, isContractProcedure, isNullSchema, isNullableOnlySchema, isObject, isProcedureMeta, isTinyOpenApiFakeMode, isZodSchema, namedControllerActionInputDtoSchema, namedControllerActionSchema, namedOpenApiOutputSchema, namedOpenApiRequestSchema, namedOpenApiResponseSchema, namedOpenApiSchema, normalizeWatchFolders as normalizeTinyOpenApiWatchFolders, operationKey, resolveOpenApiOutputPath, schemaComponentRef, schemaExportName, sharedSchemaExportName, shouldUseDtoSchemaName, stripNoContentResponseBodies, toOpenAPI30Document, toOpenAPI30Schema, toOpenAPIAclRule, toPascalCase, visitZodSchema };