@cerios/openapi-to-zod 0.6.0 → 1.1.0

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.
@@ -0,0 +1,257 @@
1
+ import { E as ExecutionMode, d as OperationFilters } from './types-B7ePTDjr.mjs';
2
+ import { z } from 'zod';
3
+ import { Loader } from 'cosmiconfig';
4
+
5
+ /**
6
+ * @shared Generator interface for batch execution
7
+ * @since 1.0.0
8
+ * Interface that both OpenApiGenerator and OpenApiPlaywrightGenerator must implement
9
+ */
10
+ interface Generator {
11
+ generate(): void;
12
+ }
13
+ /**
14
+ * Result of processing a single spec
15
+ */
16
+ interface SpecResult<T> {
17
+ spec: T;
18
+ success: boolean;
19
+ error?: string;
20
+ }
21
+ /**
22
+ * Summary of batch execution results
23
+ */
24
+ interface BatchExecutionSummary<T> {
25
+ total: number;
26
+ successful: number;
27
+ failed: number;
28
+ results: SpecResult<T>[];
29
+ }
30
+ /**
31
+ * @shared Execute batch processing of multiple specs with custom generator
32
+ * @since 1.0.0
33
+ * Utility used by core and playwright packages
34
+ *
35
+ * @param specs - Array of spec configurations to process
36
+ * @param executionMode - Execution mode: "parallel" (default) or "sequential"
37
+ * @param createGenerator - Factory function to create generator from spec
38
+ * @param batchSize - Number of specifications to process concurrently in parallel mode
39
+ * @returns BatchExecutionSummary with results
40
+ * @throws Never throws - collects all errors and reports them
41
+ */
42
+ declare function executeBatch<T>(specs: T[], executionMode: ExecutionMode | undefined, createGenerator: (spec: T) => Generator, batchSize: number): Promise<BatchExecutionSummary<T>>;
43
+ /**
44
+ * Determine exit code based on batch execution results
45
+ * Returns 1 if any spec failed, 0 if all succeeded
46
+ */
47
+ declare function getBatchExitCode<T>(summary: BatchExecutionSummary<T>): number;
48
+
49
+ /**
50
+ * @shared Zod schema for request/response options validation
51
+ * @since 1.0.0
52
+ * Utility used by core and playwright packages
53
+ */
54
+ declare const RequestResponseOptionsSchema: z.ZodObject<{
55
+ mode: z.ZodOptional<z.ZodEnum<{
56
+ strict: "strict";
57
+ normal: "normal";
58
+ loose: "loose";
59
+ }>>;
60
+ useDescribe: z.ZodOptional<z.ZodBoolean>;
61
+ includeDescriptions: z.ZodOptional<z.ZodBoolean>;
62
+ }, z.core.$strict>;
63
+ /**
64
+ * @shared Base Zod schema for operation filters (without status codes)
65
+ * @since 1.0.0
66
+ * Utility used by core and playwright packages
67
+ */
68
+ declare const OperationFiltersSchema: z.ZodObject<{
69
+ includeTags: z.ZodOptional<z.ZodArray<z.ZodString>>;
70
+ excludeTags: z.ZodOptional<z.ZodArray<z.ZodString>>;
71
+ includePaths: z.ZodOptional<z.ZodArray<z.ZodString>>;
72
+ excludePaths: z.ZodOptional<z.ZodArray<z.ZodString>>;
73
+ includeMethods: z.ZodOptional<z.ZodArray<z.ZodString>>;
74
+ excludeMethods: z.ZodOptional<z.ZodArray<z.ZodString>>;
75
+ includeOperationIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
76
+ excludeOperationIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
77
+ excludeDeprecated: z.ZodOptional<z.ZodBoolean>;
78
+ }, z.core.$strict>;
79
+ /**
80
+ * Inferred TypeScript type for request/response options
81
+ */
82
+ type RequestResponseOptions = z.infer<typeof RequestResponseOptionsSchema>;
83
+ /**
84
+ * Inferred TypeScript type for base operation filters
85
+ */
86
+ type BaseOperationFilters = z.infer<typeof OperationFiltersSchema>;
87
+
88
+ /**
89
+ * @shared Format Zod validation errors into user-friendly error messages
90
+ * @since 1.0.0
91
+ * Utility used by core and playwright packages
92
+ *
93
+ * @param error - The Zod validation error
94
+ * @param filepath - Path to the config file that was being validated
95
+ * @param configPath - Optional explicit config path provided by user
96
+ * @param additionalNotes - Optional array of additional notes to append to the error message
97
+ * @returns Formatted error message string
98
+ */
99
+ declare function formatConfigValidationError(error: z.ZodError, filepath: string | undefined, configPath: string | undefined, additionalNotes?: string[]): string;
100
+
101
+ /**
102
+ * @shared Simple LRU Cache implementation for performance optimization
103
+ * @since 1.0.0
104
+ * Utility used by core and playwright packages
105
+ * Prevents memory leaks from unbounded cache growth
106
+ */
107
+ declare class LRUCache<K, V> {
108
+ private cache;
109
+ private maxSize;
110
+ constructor(maxSize: number);
111
+ get capacity(): number;
112
+ get(key: K): V | undefined;
113
+ set(key: K, value: V): void;
114
+ has(key: K): boolean;
115
+ clear(): void;
116
+ size(): number;
117
+ }
118
+
119
+ /**
120
+ * Name conversion utilities
121
+ */
122
+ interface NamingOptions {
123
+ prefix?: string;
124
+ suffix?: string;
125
+ }
126
+ /**
127
+ * Convert schema name to camelCase with optional prefix/suffix
128
+ * Handles dotted names like "Company.Models.User" -> "companyModelsUser"
129
+ */
130
+ declare function toCamelCase(str: string, options?: NamingOptions): string;
131
+ /**
132
+ * @shared Convert enum value to PascalCase and sanitize for TypeScript enum keys
133
+ * @since 1.0.0
134
+ * Utility used by core and playwright packages
135
+ * Handles dotted names like "Company.Models.User" -> "CompanyModelsUser"
136
+ */
137
+ declare function toPascalCase(str: string | number): string;
138
+
139
+ /**
140
+ * Filter statistics to track which operations were included/excluded
141
+ */
142
+ interface FilterStatistics {
143
+ totalOperations: number;
144
+ includedOperations: number;
145
+ filteredByTags: number;
146
+ filteredByPaths: number;
147
+ filteredByMethods: number;
148
+ filteredByOperationIds: number;
149
+ filteredByDeprecated: number;
150
+ }
151
+ /**
152
+ * Create a new filter statistics object with all counters initialized to zero
153
+ */
154
+ declare function createFilterStatistics(): FilterStatistics;
155
+ /**
156
+ * Determine if an operation should be included based on filter criteria
157
+ *
158
+ * Filter logic:
159
+ * 1. If no filters specified, include all operations
160
+ * 2. Empty arrays are treated as "no constraint" (not as "exclude all")
161
+ * 3. Include filters are applied first (allowlist)
162
+ * 4. Exclude filters are applied second (blocklist)
163
+ * 5. Exclude rules always win over include rules
164
+ *
165
+ * @param operation - The OpenAPI operation object
166
+ * @param path - The operation path (e.g., "/users/{id}")
167
+ * @param method - The HTTP method (e.g., "get", "post")
168
+ * @param filters - Optional filter configuration
169
+ * @param stats - Optional statistics object to track filtering reasons
170
+ * @returns true if the operation should be included, false otherwise
171
+ */
172
+ declare function shouldIncludeOperation(operation: any, path: string, method: string, filters?: OperationFilters, stats?: FilterStatistics): boolean;
173
+ /**
174
+ * Validate filter statistics and emit warnings for filters that matched nothing
175
+ * Helps users debug filter configurations that might be too restrictive or contain typos
176
+ *
177
+ * @param stats - Filter statistics object
178
+ * @param filters - The filter configuration to validate
179
+ */
180
+ declare function validateFilters(stats: FilterStatistics, filters?: OperationFilters): void;
181
+ /**
182
+ * Format filter statistics for display in generated output
183
+ * Returns a formatted string suitable for inclusion in comments
184
+ *
185
+ * @param stats - Filter statistics object
186
+ * @returns Formatted statistics string
187
+ */
188
+ declare function formatFilterStatistics(stats: FilterStatistics): string;
189
+
190
+ /**
191
+ * Pattern matching utilities for prefix stripping
192
+ *
193
+ * Shared utility used by core and playwright packages
194
+ *
195
+ * Supports both literal string matching and regex patterns for stripping
196
+ * prefixes from strings (paths, schema names, etc.)
197
+ */
198
+ /**
199
+ * @shared Strips a prefix from a string using either literal string matching or regex
200
+ * @since 1.1.0
201
+ * Shared utility used by core and playwright packages
202
+ *
203
+ * @param input - The full string to strip from
204
+ * @param pattern - The pattern to strip (string or RegExp)
205
+ * @param ensureLeadingChar - Optional character to ensure at start (e.g., "/" for paths)
206
+ * @returns The string with prefix removed, or original string if no match
207
+ *
208
+ * @example
209
+ * // Literal string matching
210
+ * stripPrefix("/api/v1/users", "/api/v1") // => "/users"
211
+ * stripPrefix("Company.Models.User", "Company.Models.") // => "User"
212
+ *
213
+ * @example
214
+ * // Regex pattern matching
215
+ * stripPrefix("/api/v1.0/users", "^/api/v\\d+\\.\\d+") // => "/users"
216
+ * stripPrefix("api_v2_UserSchema", "^api_v\\d+_") // => "UserSchema"
217
+ */
218
+ declare function stripPrefix(input: string, pattern: string | RegExp | undefined, ensureLeadingChar?: string): string;
219
+ /**
220
+ * @shared Strips a prefix from a path (ensures leading slash)
221
+ * @since 1.1.0
222
+ * Shared utility used by playwright package for path manipulation
223
+ *
224
+ * @param path - The full path to strip from
225
+ * @param pattern - The pattern to strip (string or RegExp)
226
+ * @returns The path with prefix removed, or original path if no match
227
+ *
228
+ * @example
229
+ * stripPathPrefix("/api/v1/users", "/api/v1") // => "/users"
230
+ * stripPathPrefix("/api/v2/posts", "^/api/v\\d+") // => "/posts"
231
+ */
232
+ declare function stripPathPrefix(path: string, pattern: string | RegExp | undefined): string;
233
+
234
+ /**
235
+ * String utility functions for escaping and formatting
236
+ */
237
+
238
+ /**
239
+ * @shared Escape JSDoc comment content to prevent injection
240
+ * @since 1.0.0
241
+ * Utility used by core and playwright packages
242
+ */
243
+ declare function escapeJSDoc(str: string): string;
244
+
245
+ /**
246
+ * @shared Create a TypeScript loader for cosmiconfig using esbuild
247
+ * @since 1.0.0
248
+ * Utility used by core and playwright packages
249
+ *
250
+ * Creates a loader that transpiles TypeScript config files to JavaScript
251
+ * using esbuild, then executes them to load the configuration.
252
+ *
253
+ * @returns A cosmiconfig Loader function
254
+ */
255
+ declare function createTypeScriptLoader(): Loader;
256
+
257
+ export { type BaseOperationFilters, type FilterStatistics, type Generator, LRUCache, OperationFiltersSchema, type RequestResponseOptions, RequestResponseOptionsSchema, createFilterStatistics, createTypeScriptLoader, escapeJSDoc, executeBatch, formatConfigValidationError, formatFilterStatistics, getBatchExitCode, shouldIncludeOperation, stripPathPrefix, stripPrefix, toCamelCase, toPascalCase, validateFilters };
@@ -0,0 +1,257 @@
1
+ import { E as ExecutionMode, d as OperationFilters } from './types-B7ePTDjr.js';
2
+ import { z } from 'zod';
3
+ import { Loader } from 'cosmiconfig';
4
+
5
+ /**
6
+ * @shared Generator interface for batch execution
7
+ * @since 1.0.0
8
+ * Interface that both OpenApiGenerator and OpenApiPlaywrightGenerator must implement
9
+ */
10
+ interface Generator {
11
+ generate(): void;
12
+ }
13
+ /**
14
+ * Result of processing a single spec
15
+ */
16
+ interface SpecResult<T> {
17
+ spec: T;
18
+ success: boolean;
19
+ error?: string;
20
+ }
21
+ /**
22
+ * Summary of batch execution results
23
+ */
24
+ interface BatchExecutionSummary<T> {
25
+ total: number;
26
+ successful: number;
27
+ failed: number;
28
+ results: SpecResult<T>[];
29
+ }
30
+ /**
31
+ * @shared Execute batch processing of multiple specs with custom generator
32
+ * @since 1.0.0
33
+ * Utility used by core and playwright packages
34
+ *
35
+ * @param specs - Array of spec configurations to process
36
+ * @param executionMode - Execution mode: "parallel" (default) or "sequential"
37
+ * @param createGenerator - Factory function to create generator from spec
38
+ * @param batchSize - Number of specifications to process concurrently in parallel mode
39
+ * @returns BatchExecutionSummary with results
40
+ * @throws Never throws - collects all errors and reports them
41
+ */
42
+ declare function executeBatch<T>(specs: T[], executionMode: ExecutionMode | undefined, createGenerator: (spec: T) => Generator, batchSize: number): Promise<BatchExecutionSummary<T>>;
43
+ /**
44
+ * Determine exit code based on batch execution results
45
+ * Returns 1 if any spec failed, 0 if all succeeded
46
+ */
47
+ declare function getBatchExitCode<T>(summary: BatchExecutionSummary<T>): number;
48
+
49
+ /**
50
+ * @shared Zod schema for request/response options validation
51
+ * @since 1.0.0
52
+ * Utility used by core and playwright packages
53
+ */
54
+ declare const RequestResponseOptionsSchema: z.ZodObject<{
55
+ mode: z.ZodOptional<z.ZodEnum<{
56
+ strict: "strict";
57
+ normal: "normal";
58
+ loose: "loose";
59
+ }>>;
60
+ useDescribe: z.ZodOptional<z.ZodBoolean>;
61
+ includeDescriptions: z.ZodOptional<z.ZodBoolean>;
62
+ }, z.core.$strict>;
63
+ /**
64
+ * @shared Base Zod schema for operation filters (without status codes)
65
+ * @since 1.0.0
66
+ * Utility used by core and playwright packages
67
+ */
68
+ declare const OperationFiltersSchema: z.ZodObject<{
69
+ includeTags: z.ZodOptional<z.ZodArray<z.ZodString>>;
70
+ excludeTags: z.ZodOptional<z.ZodArray<z.ZodString>>;
71
+ includePaths: z.ZodOptional<z.ZodArray<z.ZodString>>;
72
+ excludePaths: z.ZodOptional<z.ZodArray<z.ZodString>>;
73
+ includeMethods: z.ZodOptional<z.ZodArray<z.ZodString>>;
74
+ excludeMethods: z.ZodOptional<z.ZodArray<z.ZodString>>;
75
+ includeOperationIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
76
+ excludeOperationIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
77
+ excludeDeprecated: z.ZodOptional<z.ZodBoolean>;
78
+ }, z.core.$strict>;
79
+ /**
80
+ * Inferred TypeScript type for request/response options
81
+ */
82
+ type RequestResponseOptions = z.infer<typeof RequestResponseOptionsSchema>;
83
+ /**
84
+ * Inferred TypeScript type for base operation filters
85
+ */
86
+ type BaseOperationFilters = z.infer<typeof OperationFiltersSchema>;
87
+
88
+ /**
89
+ * @shared Format Zod validation errors into user-friendly error messages
90
+ * @since 1.0.0
91
+ * Utility used by core and playwright packages
92
+ *
93
+ * @param error - The Zod validation error
94
+ * @param filepath - Path to the config file that was being validated
95
+ * @param configPath - Optional explicit config path provided by user
96
+ * @param additionalNotes - Optional array of additional notes to append to the error message
97
+ * @returns Formatted error message string
98
+ */
99
+ declare function formatConfigValidationError(error: z.ZodError, filepath: string | undefined, configPath: string | undefined, additionalNotes?: string[]): string;
100
+
101
+ /**
102
+ * @shared Simple LRU Cache implementation for performance optimization
103
+ * @since 1.0.0
104
+ * Utility used by core and playwright packages
105
+ * Prevents memory leaks from unbounded cache growth
106
+ */
107
+ declare class LRUCache<K, V> {
108
+ private cache;
109
+ private maxSize;
110
+ constructor(maxSize: number);
111
+ get capacity(): number;
112
+ get(key: K): V | undefined;
113
+ set(key: K, value: V): void;
114
+ has(key: K): boolean;
115
+ clear(): void;
116
+ size(): number;
117
+ }
118
+
119
+ /**
120
+ * Name conversion utilities
121
+ */
122
+ interface NamingOptions {
123
+ prefix?: string;
124
+ suffix?: string;
125
+ }
126
+ /**
127
+ * Convert schema name to camelCase with optional prefix/suffix
128
+ * Handles dotted names like "Company.Models.User" -> "companyModelsUser"
129
+ */
130
+ declare function toCamelCase(str: string, options?: NamingOptions): string;
131
+ /**
132
+ * @shared Convert enum value to PascalCase and sanitize for TypeScript enum keys
133
+ * @since 1.0.0
134
+ * Utility used by core and playwright packages
135
+ * Handles dotted names like "Company.Models.User" -> "CompanyModelsUser"
136
+ */
137
+ declare function toPascalCase(str: string | number): string;
138
+
139
+ /**
140
+ * Filter statistics to track which operations were included/excluded
141
+ */
142
+ interface FilterStatistics {
143
+ totalOperations: number;
144
+ includedOperations: number;
145
+ filteredByTags: number;
146
+ filteredByPaths: number;
147
+ filteredByMethods: number;
148
+ filteredByOperationIds: number;
149
+ filteredByDeprecated: number;
150
+ }
151
+ /**
152
+ * Create a new filter statistics object with all counters initialized to zero
153
+ */
154
+ declare function createFilterStatistics(): FilterStatistics;
155
+ /**
156
+ * Determine if an operation should be included based on filter criteria
157
+ *
158
+ * Filter logic:
159
+ * 1. If no filters specified, include all operations
160
+ * 2. Empty arrays are treated as "no constraint" (not as "exclude all")
161
+ * 3. Include filters are applied first (allowlist)
162
+ * 4. Exclude filters are applied second (blocklist)
163
+ * 5. Exclude rules always win over include rules
164
+ *
165
+ * @param operation - The OpenAPI operation object
166
+ * @param path - The operation path (e.g., "/users/{id}")
167
+ * @param method - The HTTP method (e.g., "get", "post")
168
+ * @param filters - Optional filter configuration
169
+ * @param stats - Optional statistics object to track filtering reasons
170
+ * @returns true if the operation should be included, false otherwise
171
+ */
172
+ declare function shouldIncludeOperation(operation: any, path: string, method: string, filters?: OperationFilters, stats?: FilterStatistics): boolean;
173
+ /**
174
+ * Validate filter statistics and emit warnings for filters that matched nothing
175
+ * Helps users debug filter configurations that might be too restrictive or contain typos
176
+ *
177
+ * @param stats - Filter statistics object
178
+ * @param filters - The filter configuration to validate
179
+ */
180
+ declare function validateFilters(stats: FilterStatistics, filters?: OperationFilters): void;
181
+ /**
182
+ * Format filter statistics for display in generated output
183
+ * Returns a formatted string suitable for inclusion in comments
184
+ *
185
+ * @param stats - Filter statistics object
186
+ * @returns Formatted statistics string
187
+ */
188
+ declare function formatFilterStatistics(stats: FilterStatistics): string;
189
+
190
+ /**
191
+ * Pattern matching utilities for prefix stripping
192
+ *
193
+ * Shared utility used by core and playwright packages
194
+ *
195
+ * Supports both literal string matching and regex patterns for stripping
196
+ * prefixes from strings (paths, schema names, etc.)
197
+ */
198
+ /**
199
+ * @shared Strips a prefix from a string using either literal string matching or regex
200
+ * @since 1.1.0
201
+ * Shared utility used by core and playwright packages
202
+ *
203
+ * @param input - The full string to strip from
204
+ * @param pattern - The pattern to strip (string or RegExp)
205
+ * @param ensureLeadingChar - Optional character to ensure at start (e.g., "/" for paths)
206
+ * @returns The string with prefix removed, or original string if no match
207
+ *
208
+ * @example
209
+ * // Literal string matching
210
+ * stripPrefix("/api/v1/users", "/api/v1") // => "/users"
211
+ * stripPrefix("Company.Models.User", "Company.Models.") // => "User"
212
+ *
213
+ * @example
214
+ * // Regex pattern matching
215
+ * stripPrefix("/api/v1.0/users", "^/api/v\\d+\\.\\d+") // => "/users"
216
+ * stripPrefix("api_v2_UserSchema", "^api_v\\d+_") // => "UserSchema"
217
+ */
218
+ declare function stripPrefix(input: string, pattern: string | RegExp | undefined, ensureLeadingChar?: string): string;
219
+ /**
220
+ * @shared Strips a prefix from a path (ensures leading slash)
221
+ * @since 1.1.0
222
+ * Shared utility used by playwright package for path manipulation
223
+ *
224
+ * @param path - The full path to strip from
225
+ * @param pattern - The pattern to strip (string or RegExp)
226
+ * @returns The path with prefix removed, or original path if no match
227
+ *
228
+ * @example
229
+ * stripPathPrefix("/api/v1/users", "/api/v1") // => "/users"
230
+ * stripPathPrefix("/api/v2/posts", "^/api/v\\d+") // => "/posts"
231
+ */
232
+ declare function stripPathPrefix(path: string, pattern: string | RegExp | undefined): string;
233
+
234
+ /**
235
+ * String utility functions for escaping and formatting
236
+ */
237
+
238
+ /**
239
+ * @shared Escape JSDoc comment content to prevent injection
240
+ * @since 1.0.0
241
+ * Utility used by core and playwright packages
242
+ */
243
+ declare function escapeJSDoc(str: string): string;
244
+
245
+ /**
246
+ * @shared Create a TypeScript loader for cosmiconfig using esbuild
247
+ * @since 1.0.0
248
+ * Utility used by core and playwright packages
249
+ *
250
+ * Creates a loader that transpiles TypeScript config files to JavaScript
251
+ * using esbuild, then executes them to load the configuration.
252
+ *
253
+ * @returns A cosmiconfig Loader function
254
+ */
255
+ declare function createTypeScriptLoader(): Loader;
256
+
257
+ export { type BaseOperationFilters, type FilterStatistics, type Generator, LRUCache, OperationFiltersSchema, type RequestResponseOptions, RequestResponseOptionsSchema, createFilterStatistics, createTypeScriptLoader, escapeJSDoc, executeBatch, formatConfigValidationError, formatFilterStatistics, getBatchExitCode, shouldIncludeOperation, stripPathPrefix, stripPrefix, toCamelCase, toPascalCase, validateFilters };