@skmtc/core 0.0.789 → 0.0.790
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/esm/context/RenderContext.d.ts +190 -0
- package/esm/context/RenderContext.d.ts.map +1 -1
- package/esm/context/RenderContext.js +179 -0
- package/esm/oas/boolean/Boolean.d.ts +142 -1
- package/esm/oas/boolean/Boolean.d.ts.map +1 -1
- package/esm/oas/boolean/Boolean.js +130 -1
- package/esm/oas/parameter/Parameter.d.ts +160 -0
- package/esm/oas/parameter/Parameter.d.ts.map +1 -1
- package/esm/oas/parameter/Parameter.js +144 -0
- package/package.json +1 -1
- package/script/context/RenderContext.d.ts +190 -0
- package/script/context/RenderContext.d.ts.map +1 -1
- package/script/context/RenderContext.js +179 -0
- package/script/oas/boolean/Boolean.d.ts +142 -1
- package/script/oas/boolean/Boolean.d.ts.map +1 -1
- package/script/oas/boolean/Boolean.js +130 -1
- package/script/oas/parameter/Parameter.d.ts +160 -0
- package/script/oas/parameter/Parameter.d.ts.map +1 -1
- package/script/oas/parameter/Parameter.js +144 -0
|
@@ -8,16 +8,206 @@ import type * as log from '../deps/jsr.io/@std/log/0.224.14/mod.js';
|
|
|
8
8
|
import { File } from '../dsl/File.js';
|
|
9
9
|
import type { Preview, Mapping } from '../types/Preview.js';
|
|
10
10
|
import type { JsonFile } from '../dsl/JsonFile.js';
|
|
11
|
+
/**
|
|
12
|
+
* Constructor arguments for {@link RenderContext}.
|
|
13
|
+
*/
|
|
11
14
|
type ConstructorArgs = {
|
|
15
|
+
/** Map of generated files to render */
|
|
12
16
|
files: Map<string, File | JsonFile>;
|
|
17
|
+
/** Preview data for generated content */
|
|
13
18
|
previews: Record<string, Record<string, Preview>>;
|
|
19
|
+
/** Mapping data for file relationships */
|
|
14
20
|
mappings: Record<string, Record<string, Mapping>>;
|
|
21
|
+
/** Optional Prettier configuration for code formatting */
|
|
15
22
|
prettierConfig?: PrettierConfigType;
|
|
23
|
+
/** Base path for resolving file paths */
|
|
16
24
|
basePath: string | undefined;
|
|
25
|
+
/** Stack trail for distributed tracing */
|
|
17
26
|
stackTrail: StackTrail;
|
|
27
|
+
/** Logger instance for debug information */
|
|
18
28
|
logger: log.Logger;
|
|
29
|
+
/** Function to capture result status */
|
|
19
30
|
captureCurrentResult: (result: ResultType) => void;
|
|
20
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* The rendering context for the final phase of the SKMTC transformation pipeline.
|
|
34
|
+
*
|
|
35
|
+
* `RenderContext` is responsible for taking the generated artifacts from the generation
|
|
36
|
+
* phase and rendering them into their final form with proper formatting, path resolution,
|
|
37
|
+
* and file preparation. It handles code formatting via Prettier, path normalization,
|
|
38
|
+
* and produces the final artifacts ready for writing to the filesystem.
|
|
39
|
+
*
|
|
40
|
+
* This context represents the culmination of the three-phase SKMTC pipeline, transforming
|
|
41
|
+
* generator outputs into production-ready code files with proper formatting and structure.
|
|
42
|
+
*
|
|
43
|
+
* ## Key Features
|
|
44
|
+
*
|
|
45
|
+
* - **Code Formatting**: Automatic Prettier formatting for generated TypeScript/JavaScript code
|
|
46
|
+
* - **Path Resolution**: Intelligent path resolution with base path support
|
|
47
|
+
* - **Content Collation**: Combines all generated content into organized file structures
|
|
48
|
+
* - **Metadata Generation**: Tracks file statistics (lines, characters) and relationships
|
|
49
|
+
* - **Error Tracking**: Comprehensive error handling with Sentry integration
|
|
50
|
+
* - **Performance Monitoring**: Built-in tracing and performance measurement
|
|
51
|
+
*
|
|
52
|
+
* @example Basic rendering usage
|
|
53
|
+
* ```typescript
|
|
54
|
+
* import { RenderContext } from '@skmtc/core';
|
|
55
|
+
*
|
|
56
|
+
* const renderContext = new RenderContext({
|
|
57
|
+
* files: generatedFiles,
|
|
58
|
+
* previews: previewData,
|
|
59
|
+
* mappings: mappingData,
|
|
60
|
+
* prettierConfig: {
|
|
61
|
+
* semi: false,
|
|
62
|
+
* singleQuote: true,
|
|
63
|
+
* trailingComma: 'all'
|
|
64
|
+
* },
|
|
65
|
+
* basePath: './src/generated',
|
|
66
|
+
* stackTrail: traceStack,
|
|
67
|
+
* logger: myLogger,
|
|
68
|
+
* captureCurrentResult: (result) => console.log(result)
|
|
69
|
+
* });
|
|
70
|
+
*
|
|
71
|
+
* const rendered = await renderContext.render();
|
|
72
|
+
*
|
|
73
|
+
* // Access rendered files
|
|
74
|
+
* Object.entries(rendered.artifacts).forEach(([path, content]) => {
|
|
75
|
+
* console.log(`Rendered ${path}: ${rendered.files[path].lines} lines`);
|
|
76
|
+
* // Write to filesystem
|
|
77
|
+
* await Deno.writeTextFile(path, content);
|
|
78
|
+
* });
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @example With custom Prettier configuration
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const renderContext = new RenderContext({
|
|
84
|
+
* files: generatedFiles,
|
|
85
|
+
* previews: {},
|
|
86
|
+
* mappings: {},
|
|
87
|
+
* prettierConfig: {
|
|
88
|
+
* parser: 'typescript',
|
|
89
|
+
* printWidth: 120,
|
|
90
|
+
* tabWidth: 2,
|
|
91
|
+
* semi: true,
|
|
92
|
+
* singleQuote: true,
|
|
93
|
+
* trailingComma: 'es5',
|
|
94
|
+
* bracketSpacing: true,
|
|
95
|
+
* arrowParens: 'avoid'
|
|
96
|
+
* },
|
|
97
|
+
* basePath: './packages/api-client/src',
|
|
98
|
+
* stackTrail: stack,
|
|
99
|
+
* logger: logger,
|
|
100
|
+
* captureCurrentResult: resultHandler
|
|
101
|
+
* });
|
|
102
|
+
*
|
|
103
|
+
* const result = await renderContext.render();
|
|
104
|
+
*
|
|
105
|
+
* // All TypeScript files are automatically formatted
|
|
106
|
+
* console.log('Formatted files:', Object.keys(result.artifacts).length);
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* @example Processing render results
|
|
110
|
+
* ```typescript
|
|
111
|
+
* const rendered = await renderContext.render();
|
|
112
|
+
*
|
|
113
|
+
* // Analyze file statistics
|
|
114
|
+
* const totalLines = Object.values(rendered.files)
|
|
115
|
+
* .reduce((sum, file) => sum + file.lines, 0);
|
|
116
|
+
* const totalChars = Object.values(rendered.files)
|
|
117
|
+
* .reduce((sum, file) => sum + file.characters, 0);
|
|
118
|
+
*
|
|
119
|
+
* console.log(`Generated ${Object.keys(rendered.artifacts).length} files`);
|
|
120
|
+
* console.log(`Total lines: ${totalLines}`);
|
|
121
|
+
* console.log(`Total characters: ${totalChars}`);
|
|
122
|
+
*
|
|
123
|
+
* // Check for large files
|
|
124
|
+
* const largeFiles = Object.entries(rendered.files)
|
|
125
|
+
* .filter(([_, metadata]) => metadata.lines > 1000)
|
|
126
|
+
* .map(([path, metadata]) => ({ path, lines: metadata.lines }));
|
|
127
|
+
*
|
|
128
|
+
* if (largeFiles.length > 0) {
|
|
129
|
+
* console.log('Large files detected:', largeFiles);
|
|
130
|
+
* }
|
|
131
|
+
*
|
|
132
|
+
* // Access preview and mapping data
|
|
133
|
+
* console.log('Previews available:', Object.keys(rendered.previews));
|
|
134
|
+
* console.log('Mappings available:', Object.keys(rendered.mappings));
|
|
135
|
+
* ```
|
|
136
|
+
*
|
|
137
|
+
* @example Integration with CoreContext
|
|
138
|
+
* ```typescript
|
|
139
|
+
* // Typically used within CoreContext.toArtifacts()
|
|
140
|
+
* class CustomCoreContext extends CoreContext {
|
|
141
|
+
* async renderWithPostProcessing(
|
|
142
|
+
* files: Map<string, File | JsonFile>,
|
|
143
|
+
* previews: Record<string, Record<string, Preview>>,
|
|
144
|
+
* mappings: Record<string, Record<string, Mapping>>
|
|
145
|
+
* ) {
|
|
146
|
+
* const renderContext = new RenderContext({
|
|
147
|
+
* files,
|
|
148
|
+
* previews,
|
|
149
|
+
* mappings,
|
|
150
|
+
* prettierConfig: this.prettierConfig,
|
|
151
|
+
* basePath: this.settings?.basePath,
|
|
152
|
+
* stackTrail: this.stackTrail,
|
|
153
|
+
* logger: this.logger,
|
|
154
|
+
* captureCurrentResult: this.captureCurrentResult.bind(this)
|
|
155
|
+
* });
|
|
156
|
+
*
|
|
157
|
+
* const rendered = await renderContext.render();
|
|
158
|
+
*
|
|
159
|
+
* // Post-process rendered files
|
|
160
|
+
* const processedArtifacts: Record<string, string> = {};
|
|
161
|
+
*
|
|
162
|
+
* for (const [path, content] of Object.entries(rendered.artifacts)) {
|
|
163
|
+
* // Add file headers, license notices, etc.
|
|
164
|
+
* const processedContent = this.addFileHeader(content, path);
|
|
165
|
+
* processedArtifacts[path] = processedContent;
|
|
166
|
+
* }
|
|
167
|
+
*
|
|
168
|
+
* return {
|
|
169
|
+
* ...rendered,
|
|
170
|
+
* artifacts: processedArtifacts
|
|
171
|
+
* };
|
|
172
|
+
* }
|
|
173
|
+
* }
|
|
174
|
+
* ```
|
|
175
|
+
*
|
|
176
|
+
* @example Error handling during rendering
|
|
177
|
+
* ```typescript
|
|
178
|
+
* try {
|
|
179
|
+
* const renderContext = new RenderContext({
|
|
180
|
+
* files: generatedFiles,
|
|
181
|
+
* previews: {},
|
|
182
|
+
* mappings: {},
|
|
183
|
+
* prettierConfig: prettierConfig,
|
|
184
|
+
* basePath: './invalid-path', // This might cause issues
|
|
185
|
+
* stackTrail: stack,
|
|
186
|
+
* logger: logger,
|
|
187
|
+
* captureCurrentResult: (result) => {
|
|
188
|
+
* if (result === 'error') {
|
|
189
|
+
* console.error('Render error detected');
|
|
190
|
+
* }
|
|
191
|
+
* }
|
|
192
|
+
* });
|
|
193
|
+
*
|
|
194
|
+
* const result = await renderContext.render();
|
|
195
|
+
*
|
|
196
|
+
* // Check if any files failed to render
|
|
197
|
+
* const failedFiles = Object.entries(result.files)
|
|
198
|
+
* .filter(([path, metadata]) => metadata.lines === 0)
|
|
199
|
+
* .map(([path]) => path);
|
|
200
|
+
*
|
|
201
|
+
* if (failedFiles.length > 0) {
|
|
202
|
+
* console.warn('Files with no content:', failedFiles);
|
|
203
|
+
* }
|
|
204
|
+
*
|
|
205
|
+
* } catch (error) {
|
|
206
|
+
* console.error('Render operation failed:', error);
|
|
207
|
+
* // Sentry automatically captures the error
|
|
208
|
+
* }
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
21
211
|
export declare class RenderContext {
|
|
22
212
|
#private;
|
|
23
213
|
files: Map<string, File | JsonFile>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RenderContext.d.ts","sourceRoot":"","sources":["../../src/context/RenderContext.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAEpE,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAEjE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAGrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,KAAK,KAAK,GAAG,MAAM,yCAAyC,CAAA;AACnE,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AACrC,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAE3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAElD,KAAK,eAAe,GAAG;IACrB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,GAAG,QAAQ,CAAC,CAAA;IACnC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;IACjD,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;IACjD,cAAc,CAAC,EAAE,kBAAkB,CAAA;IACnC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B,UAAU,EAAE,UAAU,CAAA;IACtB,MAAM,EA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IAAI,GAAG,QAAQ;IAU1C,IAAI,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,QAAQ,GAAG,UAAU,GAAG,SAAS;CAO7D"}
|
|
@@ -17,6 +17,185 @@ import { toResolvedArtifactPath } from '../helpers/toResolvedArtifactPath.js';
|
|
|
17
17
|
import { tracer } from '../helpers/tracer.js';
|
|
18
18
|
import { File } from '../dsl/File.js';
|
|
19
19
|
import * as prettier from 'prettier';
|
|
20
|
+
/**
|
|
21
|
+
* The rendering context for the final phase of the SKMTC transformation pipeline.
|
|
22
|
+
*
|
|
23
|
+
* `RenderContext` is responsible for taking the generated artifacts from the generation
|
|
24
|
+
* phase and rendering them into their final form with proper formatting, path resolution,
|
|
25
|
+
* and file preparation. It handles code formatting via Prettier, path normalization,
|
|
26
|
+
* and produces the final artifacts ready for writing to the filesystem.
|
|
27
|
+
*
|
|
28
|
+
* This context represents the culmination of the three-phase SKMTC pipeline, transforming
|
|
29
|
+
* generator outputs into production-ready code files with proper formatting and structure.
|
|
30
|
+
*
|
|
31
|
+
* ## Key Features
|
|
32
|
+
*
|
|
33
|
+
* - **Code Formatting**: Automatic Prettier formatting for generated TypeScript/JavaScript code
|
|
34
|
+
* - **Path Resolution**: Intelligent path resolution with base path support
|
|
35
|
+
* - **Content Collation**: Combines all generated content into organized file structures
|
|
36
|
+
* - **Metadata Generation**: Tracks file statistics (lines, characters) and relationships
|
|
37
|
+
* - **Error Tracking**: Comprehensive error handling with Sentry integration
|
|
38
|
+
* - **Performance Monitoring**: Built-in tracing and performance measurement
|
|
39
|
+
*
|
|
40
|
+
* @example Basic rendering usage
|
|
41
|
+
* ```typescript
|
|
42
|
+
* import { RenderContext } from '@skmtc/core';
|
|
43
|
+
*
|
|
44
|
+
* const renderContext = new RenderContext({
|
|
45
|
+
* files: generatedFiles,
|
|
46
|
+
* previews: previewData,
|
|
47
|
+
* mappings: mappingData,
|
|
48
|
+
* prettierConfig: {
|
|
49
|
+
* semi: false,
|
|
50
|
+
* singleQuote: true,
|
|
51
|
+
* trailingComma: 'all'
|
|
52
|
+
* },
|
|
53
|
+
* basePath: './src/generated',
|
|
54
|
+
* stackTrail: traceStack,
|
|
55
|
+
* logger: myLogger,
|
|
56
|
+
* captureCurrentResult: (result) => console.log(result)
|
|
57
|
+
* });
|
|
58
|
+
*
|
|
59
|
+
* const rendered = await renderContext.render();
|
|
60
|
+
*
|
|
61
|
+
* // Access rendered files
|
|
62
|
+
* Object.entries(rendered.artifacts).forEach(([path, content]) => {
|
|
63
|
+
* console.log(`Rendered ${path}: ${rendered.files[path].lines} lines`);
|
|
64
|
+
* // Write to filesystem
|
|
65
|
+
* await Deno.writeTextFile(path, content);
|
|
66
|
+
* });
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @example With custom Prettier configuration
|
|
70
|
+
* ```typescript
|
|
71
|
+
* const renderContext = new RenderContext({
|
|
72
|
+
* files: generatedFiles,
|
|
73
|
+
* previews: {},
|
|
74
|
+
* mappings: {},
|
|
75
|
+
* prettierConfig: {
|
|
76
|
+
* parser: 'typescript',
|
|
77
|
+
* printWidth: 120,
|
|
78
|
+
* tabWidth: 2,
|
|
79
|
+
* semi: true,
|
|
80
|
+
* singleQuote: true,
|
|
81
|
+
* trailingComma: 'es5',
|
|
82
|
+
* bracketSpacing: true,
|
|
83
|
+
* arrowParens: 'avoid'
|
|
84
|
+
* },
|
|
85
|
+
* basePath: './packages/api-client/src',
|
|
86
|
+
* stackTrail: stack,
|
|
87
|
+
* logger: logger,
|
|
88
|
+
* captureCurrentResult: resultHandler
|
|
89
|
+
* });
|
|
90
|
+
*
|
|
91
|
+
* const result = await renderContext.render();
|
|
92
|
+
*
|
|
93
|
+
* // All TypeScript files are automatically formatted
|
|
94
|
+
* console.log('Formatted files:', Object.keys(result.artifacts).length);
|
|
95
|
+
* ```
|
|
96
|
+
*
|
|
97
|
+
* @example Processing render results
|
|
98
|
+
* ```typescript
|
|
99
|
+
* const rendered = await renderContext.render();
|
|
100
|
+
*
|
|
101
|
+
* // Analyze file statistics
|
|
102
|
+
* const totalLines = Object.values(rendered.files)
|
|
103
|
+
* .reduce((sum, file) => sum + file.lines, 0);
|
|
104
|
+
* const totalChars = Object.values(rendered.files)
|
|
105
|
+
* .reduce((sum, file) => sum + file.characters, 0);
|
|
106
|
+
*
|
|
107
|
+
* console.log(`Generated ${Object.keys(rendered.artifacts).length} files`);
|
|
108
|
+
* console.log(`Total lines: ${totalLines}`);
|
|
109
|
+
* console.log(`Total characters: ${totalChars}`);
|
|
110
|
+
*
|
|
111
|
+
* // Check for large files
|
|
112
|
+
* const largeFiles = Object.entries(rendered.files)
|
|
113
|
+
* .filter(([_, metadata]) => metadata.lines > 1000)
|
|
114
|
+
* .map(([path, metadata]) => ({ path, lines: metadata.lines }));
|
|
115
|
+
*
|
|
116
|
+
* if (largeFiles.length > 0) {
|
|
117
|
+
* console.log('Large files detected:', largeFiles);
|
|
118
|
+
* }
|
|
119
|
+
*
|
|
120
|
+
* // Access preview and mapping data
|
|
121
|
+
* console.log('Previews available:', Object.keys(rendered.previews));
|
|
122
|
+
* console.log('Mappings available:', Object.keys(rendered.mappings));
|
|
123
|
+
* ```
|
|
124
|
+
*
|
|
125
|
+
* @example Integration with CoreContext
|
|
126
|
+
* ```typescript
|
|
127
|
+
* // Typically used within CoreContext.toArtifacts()
|
|
128
|
+
* class CustomCoreContext extends CoreContext {
|
|
129
|
+
* async renderWithPostProcessing(
|
|
130
|
+
* files: Map<string, File | JsonFile>,
|
|
131
|
+
* previews: Record<string, Record<string, Preview>>,
|
|
132
|
+
* mappings: Record<string, Record<string, Mapping>>
|
|
133
|
+
* ) {
|
|
134
|
+
* const renderContext = new RenderContext({
|
|
135
|
+
* files,
|
|
136
|
+
* previews,
|
|
137
|
+
* mappings,
|
|
138
|
+
* prettierConfig: this.prettierConfig,
|
|
139
|
+
* basePath: this.settings?.basePath,
|
|
140
|
+
* stackTrail: this.stackTrail,
|
|
141
|
+
* logger: this.logger,
|
|
142
|
+
* captureCurrentResult: this.captureCurrentResult.bind(this)
|
|
143
|
+
* });
|
|
144
|
+
*
|
|
145
|
+
* const rendered = await renderContext.render();
|
|
146
|
+
*
|
|
147
|
+
* // Post-process rendered files
|
|
148
|
+
* const processedArtifacts: Record<string, string> = {};
|
|
149
|
+
*
|
|
150
|
+
* for (const [path, content] of Object.entries(rendered.artifacts)) {
|
|
151
|
+
* // Add file headers, license notices, etc.
|
|
152
|
+
* const processedContent = this.addFileHeader(content, path);
|
|
153
|
+
* processedArtifacts[path] = processedContent;
|
|
154
|
+
* }
|
|
155
|
+
*
|
|
156
|
+
* return {
|
|
157
|
+
* ...rendered,
|
|
158
|
+
* artifacts: processedArtifacts
|
|
159
|
+
* };
|
|
160
|
+
* }
|
|
161
|
+
* }
|
|
162
|
+
* ```
|
|
163
|
+
*
|
|
164
|
+
* @example Error handling during rendering
|
|
165
|
+
* ```typescript
|
|
166
|
+
* try {
|
|
167
|
+
* const renderContext = new RenderContext({
|
|
168
|
+
* files: generatedFiles,
|
|
169
|
+
* previews: {},
|
|
170
|
+
* mappings: {},
|
|
171
|
+
* prettierConfig: prettierConfig,
|
|
172
|
+
* basePath: './invalid-path', // This might cause issues
|
|
173
|
+
* stackTrail: stack,
|
|
174
|
+
* logger: logger,
|
|
175
|
+
* captureCurrentResult: (result) => {
|
|
176
|
+
* if (result === 'error') {
|
|
177
|
+
* console.error('Render error detected');
|
|
178
|
+
* }
|
|
179
|
+
* }
|
|
180
|
+
* });
|
|
181
|
+
*
|
|
182
|
+
* const result = await renderContext.render();
|
|
183
|
+
*
|
|
184
|
+
* // Check if any files failed to render
|
|
185
|
+
* const failedFiles = Object.entries(result.files)
|
|
186
|
+
* .filter(([path, metadata]) => metadata.lines === 0)
|
|
187
|
+
* .map(([path]) => path);
|
|
188
|
+
*
|
|
189
|
+
* if (failedFiles.length > 0) {
|
|
190
|
+
* console.warn('Files with no content:', failedFiles);
|
|
191
|
+
* }
|
|
192
|
+
*
|
|
193
|
+
* } catch (error) {
|
|
194
|
+
* console.error('Render operation failed:', error);
|
|
195
|
+
* // Sentry automatically captures the error
|
|
196
|
+
* }
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
20
199
|
export class RenderContext {
|
|
21
200
|
constructor({ files, previews, mappings, prettierConfig, basePath, logger, stackTrail, captureCurrentResult }) {
|
|
22
201
|
Object.defineProperty(this, "files", {
|
|
@@ -2,17 +2,158 @@ import "../../_dnt.polyfills.js";
|
|
|
2
2
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
3
3
|
import type { OasRef } from '../ref/Ref.js';
|
|
4
4
|
import type { ToJsonSchemaOptions } from '../schema/Schema.js';
|
|
5
|
+
/**
|
|
6
|
+
* Constructor fields for {@link OasBoolean}.
|
|
7
|
+
*
|
|
8
|
+
* @template Nullable - Whether the boolean can be null (affects type unions)
|
|
9
|
+
*/
|
|
5
10
|
export type BooleanFields<Nullable extends boolean | undefined> = {
|
|
11
|
+
/** A short summary of the boolean schema */
|
|
6
12
|
title?: string;
|
|
13
|
+
/** A description of the boolean schema */
|
|
7
14
|
description?: string;
|
|
15
|
+
/** Whether the boolean value can be null */
|
|
8
16
|
nullable?: Nullable;
|
|
17
|
+
/** Custom extension fields (x-* properties) */
|
|
9
18
|
extensionFields?: Record<string, unknown>;
|
|
19
|
+
/** Example value for the boolean (null allowed if Nullable is true) */
|
|
10
20
|
example?: Nullable extends true ? boolean | null | undefined : boolean | undefined;
|
|
21
|
+
/** Array of valid enum values for the boolean (null allowed if Nullable is true) */
|
|
11
22
|
enums?: Nullable extends true ? (boolean | null)[] | undefined : boolean[] | undefined;
|
|
23
|
+
/** Default value for the boolean (null allowed if Nullable is true) */
|
|
12
24
|
default?: Nullable extends true ? boolean | null | undefined : boolean | undefined;
|
|
13
25
|
};
|
|
14
26
|
/**
|
|
15
|
-
*
|
|
27
|
+
* Represents a boolean schema in the OpenAPI Specification.
|
|
28
|
+
*
|
|
29
|
+
* The `OasBoolean` class handles boolean data types in OpenAPI schemas, supporting
|
|
30
|
+
* both simple true/false values and more complex boolean schemas with constraints,
|
|
31
|
+
* enumerations, and nullable types. This class provides type-safe boolean handling
|
|
32
|
+
* with optional null value support through generic typing.
|
|
33
|
+
*
|
|
34
|
+
* ## Key Features
|
|
35
|
+
*
|
|
36
|
+
* - **Type Safety**: Generic nullable type support with proper TypeScript inference
|
|
37
|
+
* - **Enum Support**: Constrain boolean values to specific true/false combinations
|
|
38
|
+
* - **Null Handling**: Optional null value support for nullable boolean types
|
|
39
|
+
* - **Validation**: Default values and example validation
|
|
40
|
+
* - **JSON Schema**: Converts to standard JSON Schema format for validation
|
|
41
|
+
* - **Documentation**: Rich metadata support for API documentation
|
|
42
|
+
*
|
|
43
|
+
* @template Nullable - Whether the boolean value itself can be null
|
|
44
|
+
*
|
|
45
|
+
* @example Basic boolean schema
|
|
46
|
+
* ```typescript
|
|
47
|
+
* import { OasBoolean } from '@skmtc/core';
|
|
48
|
+
*
|
|
49
|
+
* const isActiveSchema = new OasBoolean({
|
|
50
|
+
* title: 'Active Status',
|
|
51
|
+
* description: 'Whether the user account is active',
|
|
52
|
+
* default: true,
|
|
53
|
+
* example: true
|
|
54
|
+
* });
|
|
55
|
+
*
|
|
56
|
+
* // This represents: boolean with default true
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @example Nullable boolean schema
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const nullableFlag = new OasBoolean<true>({
|
|
62
|
+
* title: 'Optional Flag',
|
|
63
|
+
* description: 'An optional boolean flag that can be null',
|
|
64
|
+
* nullable: true,
|
|
65
|
+
* default: null,
|
|
66
|
+
* example: true
|
|
67
|
+
* });
|
|
68
|
+
*
|
|
69
|
+
* // This represents: boolean | null
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @example Boolean with enum constraints
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const strictBoolean = new OasBoolean({
|
|
75
|
+
* title: 'Confirmation',
|
|
76
|
+
* description: 'Must explicitly be true to confirm action',
|
|
77
|
+
* enums: [true], // Only true is allowed
|
|
78
|
+
* example: true
|
|
79
|
+
* });
|
|
80
|
+
*
|
|
81
|
+
* // This only accepts true, effectively making it required
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* @example Boolean with null in enum
|
|
85
|
+
* ```typescript
|
|
86
|
+
* const triStateBoolean = new OasBoolean<true>({
|
|
87
|
+
* title: 'Approval Status',
|
|
88
|
+
* description: 'Approval can be true (approved), false (denied), or null (pending)',
|
|
89
|
+
* nullable: true,
|
|
90
|
+
* enums: [true, false, null],
|
|
91
|
+
* default: null,
|
|
92
|
+
* example: null
|
|
93
|
+
* });
|
|
94
|
+
*
|
|
95
|
+
* // This represents: true | false | null (tri-state logic)
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* @example Feature flag schema
|
|
99
|
+
* ```typescript
|
|
100
|
+
* const featureFlag = new OasBoolean({
|
|
101
|
+
* title: 'Feature Enabled',
|
|
102
|
+
* description: 'Whether the new feature is enabled for this user',
|
|
103
|
+
* default: false,
|
|
104
|
+
* example: false
|
|
105
|
+
* });
|
|
106
|
+
*
|
|
107
|
+
* // Used in configuration objects
|
|
108
|
+
* const userConfig = new OasObject({
|
|
109
|
+
* properties: {
|
|
110
|
+
* darkMode: featureFlag,
|
|
111
|
+
* notifications: featureFlag,
|
|
112
|
+
* betaFeatures: featureFlag
|
|
113
|
+
* }
|
|
114
|
+
* });
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* @example Consent and agreement booleans
|
|
118
|
+
* ```typescript
|
|
119
|
+
* const consentSchema = new OasBoolean({
|
|
120
|
+
* title: 'Terms Accepted',
|
|
121
|
+
* description: 'User has accepted the terms and conditions',
|
|
122
|
+
* enums: [true], // Must be true to be valid
|
|
123
|
+
* example: true
|
|
124
|
+
* });
|
|
125
|
+
*
|
|
126
|
+
* const privacyConsent = new OasBoolean({
|
|
127
|
+
* title: 'Privacy Policy Accepted',
|
|
128
|
+
* description: 'User has accepted the privacy policy',
|
|
129
|
+
* default: false,
|
|
130
|
+
* example: true
|
|
131
|
+
* });
|
|
132
|
+
*
|
|
133
|
+
* // Used in registration forms where consent is required
|
|
134
|
+
* ```
|
|
135
|
+
*
|
|
136
|
+
* @example Optional settings with nullable booleans
|
|
137
|
+
* ```typescript
|
|
138
|
+
* const userPreferences = new OasObject({
|
|
139
|
+
* properties: {
|
|
140
|
+
* emailNotifications: new OasBoolean<true>({
|
|
141
|
+
* title: 'Email Notifications',
|
|
142
|
+
* description: 'Enable email notifications (null means use default)',
|
|
143
|
+
* nullable: true,
|
|
144
|
+
* default: null
|
|
145
|
+
* }),
|
|
146
|
+
* smsNotifications: new OasBoolean<true>({
|
|
147
|
+
* title: 'SMS Notifications',
|
|
148
|
+
* description: 'Enable SMS notifications (null means not set)',
|
|
149
|
+
* nullable: true,
|
|
150
|
+
* default: null
|
|
151
|
+
* })
|
|
152
|
+
* }
|
|
153
|
+
* });
|
|
154
|
+
*
|
|
155
|
+
* // Allows: { emailNotifications: true, smsNotifications: null }
|
|
156
|
+
* ```
|
|
16
157
|
*/
|
|
17
158
|
export declare class OasBoolean<Nullable extends boolean | undefined = boolean | undefined> {
|
|
18
159
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Boolean.d.ts","sourceRoot":"","sources":["../../../src/oas/boolean/Boolean.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"Boolean.d.ts","sourceRoot":"","sources":["../../../src/oas/boolean/Boolean.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;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