@cerios/openapi-to-zod 0.6.0 → 1.0.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,200 @@
1
+ import { E as ExecutionMode, d as OperationFilters } from './types-BjoP91vk.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
+ * @shared Convert enum value to PascalCase and sanitize for TypeScript enum keys
121
+ * @since 1.0.0
122
+ * Utility used by core and playwright packages
123
+ */
124
+ declare function toPascalCase(str: string | number): string;
125
+
126
+ /**
127
+ * Filter statistics to track which operations were included/excluded
128
+ */
129
+ interface FilterStatistics {
130
+ totalOperations: number;
131
+ includedOperations: number;
132
+ filteredByTags: number;
133
+ filteredByPaths: number;
134
+ filteredByMethods: number;
135
+ filteredByOperationIds: number;
136
+ filteredByDeprecated: number;
137
+ }
138
+ /**
139
+ * Create a new filter statistics object with all counters initialized to zero
140
+ */
141
+ declare function createFilterStatistics(): FilterStatistics;
142
+ /**
143
+ * Determine if an operation should be included based on filter criteria
144
+ *
145
+ * Filter logic:
146
+ * 1. If no filters specified, include all operations
147
+ * 2. Empty arrays are treated as "no constraint" (not as "exclude all")
148
+ * 3. Include filters are applied first (allowlist)
149
+ * 4. Exclude filters are applied second (blocklist)
150
+ * 5. Exclude rules always win over include rules
151
+ *
152
+ * @param operation - The OpenAPI operation object
153
+ * @param path - The operation path (e.g., "/users/{id}")
154
+ * @param method - The HTTP method (e.g., "get", "post")
155
+ * @param filters - Optional filter configuration
156
+ * @param stats - Optional statistics object to track filtering reasons
157
+ * @returns true if the operation should be included, false otherwise
158
+ */
159
+ declare function shouldIncludeOperation(operation: any, path: string, method: string, filters?: OperationFilters, stats?: FilterStatistics): boolean;
160
+ /**
161
+ * Validate filter statistics and emit warnings for filters that matched nothing
162
+ * Helps users debug filter configurations that might be too restrictive or contain typos
163
+ *
164
+ * @param stats - Filter statistics object
165
+ * @param filters - The filter configuration to validate
166
+ */
167
+ declare function validateFilters(stats: FilterStatistics, filters?: OperationFilters): void;
168
+ /**
169
+ * Format filter statistics for display in generated output
170
+ * Returns a formatted string suitable for inclusion in comments
171
+ *
172
+ * @param stats - Filter statistics object
173
+ * @returns Formatted statistics string
174
+ */
175
+ declare function formatFilterStatistics(stats: FilterStatistics): string;
176
+
177
+ /**
178
+ * String utility functions for escaping and formatting
179
+ */
180
+
181
+ /**
182
+ * @shared Escape JSDoc comment content to prevent injection
183
+ * @since 1.0.0
184
+ * Utility used by core and playwright packages
185
+ */
186
+ declare function escapeJSDoc(str: string): string;
187
+
188
+ /**
189
+ * @shared Create a TypeScript loader for cosmiconfig using esbuild
190
+ * @since 1.0.0
191
+ * Utility used by core and playwright packages
192
+ *
193
+ * Creates a loader that transpiles TypeScript config files to JavaScript
194
+ * using esbuild, then executes them to load the configuration.
195
+ *
196
+ * @returns A cosmiconfig Loader function
197
+ */
198
+ declare function createTypeScriptLoader(): Loader;
199
+
200
+ export { type BaseOperationFilters, type FilterStatistics, type Generator, LRUCache, OperationFiltersSchema, type RequestResponseOptions, RequestResponseOptionsSchema, createFilterStatistics, createTypeScriptLoader, escapeJSDoc, executeBatch, formatConfigValidationError, formatFilterStatistics, getBatchExitCode, shouldIncludeOperation, toPascalCase, validateFilters };
@@ -0,0 +1,200 @@
1
+ import { E as ExecutionMode, d as OperationFilters } from './types-BjoP91vk.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
+ * @shared Convert enum value to PascalCase and sanitize for TypeScript enum keys
121
+ * @since 1.0.0
122
+ * Utility used by core and playwright packages
123
+ */
124
+ declare function toPascalCase(str: string | number): string;
125
+
126
+ /**
127
+ * Filter statistics to track which operations were included/excluded
128
+ */
129
+ interface FilterStatistics {
130
+ totalOperations: number;
131
+ includedOperations: number;
132
+ filteredByTags: number;
133
+ filteredByPaths: number;
134
+ filteredByMethods: number;
135
+ filteredByOperationIds: number;
136
+ filteredByDeprecated: number;
137
+ }
138
+ /**
139
+ * Create a new filter statistics object with all counters initialized to zero
140
+ */
141
+ declare function createFilterStatistics(): FilterStatistics;
142
+ /**
143
+ * Determine if an operation should be included based on filter criteria
144
+ *
145
+ * Filter logic:
146
+ * 1. If no filters specified, include all operations
147
+ * 2. Empty arrays are treated as "no constraint" (not as "exclude all")
148
+ * 3. Include filters are applied first (allowlist)
149
+ * 4. Exclude filters are applied second (blocklist)
150
+ * 5. Exclude rules always win over include rules
151
+ *
152
+ * @param operation - The OpenAPI operation object
153
+ * @param path - The operation path (e.g., "/users/{id}")
154
+ * @param method - The HTTP method (e.g., "get", "post")
155
+ * @param filters - Optional filter configuration
156
+ * @param stats - Optional statistics object to track filtering reasons
157
+ * @returns true if the operation should be included, false otherwise
158
+ */
159
+ declare function shouldIncludeOperation(operation: any, path: string, method: string, filters?: OperationFilters, stats?: FilterStatistics): boolean;
160
+ /**
161
+ * Validate filter statistics and emit warnings for filters that matched nothing
162
+ * Helps users debug filter configurations that might be too restrictive or contain typos
163
+ *
164
+ * @param stats - Filter statistics object
165
+ * @param filters - The filter configuration to validate
166
+ */
167
+ declare function validateFilters(stats: FilterStatistics, filters?: OperationFilters): void;
168
+ /**
169
+ * Format filter statistics for display in generated output
170
+ * Returns a formatted string suitable for inclusion in comments
171
+ *
172
+ * @param stats - Filter statistics object
173
+ * @returns Formatted statistics string
174
+ */
175
+ declare function formatFilterStatistics(stats: FilterStatistics): string;
176
+
177
+ /**
178
+ * String utility functions for escaping and formatting
179
+ */
180
+
181
+ /**
182
+ * @shared Escape JSDoc comment content to prevent injection
183
+ * @since 1.0.0
184
+ * Utility used by core and playwright packages
185
+ */
186
+ declare function escapeJSDoc(str: string): string;
187
+
188
+ /**
189
+ * @shared Create a TypeScript loader for cosmiconfig using esbuild
190
+ * @since 1.0.0
191
+ * Utility used by core and playwright packages
192
+ *
193
+ * Creates a loader that transpiles TypeScript config files to JavaScript
194
+ * using esbuild, then executes them to load the configuration.
195
+ *
196
+ * @returns A cosmiconfig Loader function
197
+ */
198
+ declare function createTypeScriptLoader(): Loader;
199
+
200
+ export { type BaseOperationFilters, type FilterStatistics, type Generator, LRUCache, OperationFiltersSchema, type RequestResponseOptions, RequestResponseOptionsSchema, createFilterStatistics, createTypeScriptLoader, escapeJSDoc, executeBatch, formatConfigValidationError, formatFilterStatistics, getBatchExitCode, shouldIncludeOperation, toPascalCase, validateFilters };