@skmtc/core 0.0.788 → 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.
Files changed (49) hide show
  1. package/esm/context/ParseContext.d.ts +178 -0
  2. package/esm/context/ParseContext.d.ts.map +1 -1
  3. package/esm/context/ParseContext.js +108 -0
  4. package/esm/context/RenderContext.d.ts +190 -0
  5. package/esm/context/RenderContext.d.ts.map +1 -1
  6. package/esm/context/RenderContext.js +179 -0
  7. package/esm/dsl/Inserted.d.ts +240 -0
  8. package/esm/dsl/Inserted.d.ts.map +1 -1
  9. package/esm/dsl/Inserted.js +231 -0
  10. package/esm/helpers/refFns.d.ts +160 -0
  11. package/esm/helpers/refFns.d.ts.map +1 -1
  12. package/esm/helpers/refFns.js +156 -0
  13. package/esm/oas/boolean/Boolean.d.ts +142 -1
  14. package/esm/oas/boolean/Boolean.d.ts.map +1 -1
  15. package/esm/oas/boolean/Boolean.js +130 -1
  16. package/esm/oas/components/Components.d.ts +252 -2
  17. package/esm/oas/components/Components.d.ts.map +1 -1
  18. package/esm/oas/components/Components.js +241 -2
  19. package/esm/oas/parameter/Parameter.d.ts +160 -0
  20. package/esm/oas/parameter/Parameter.d.ts.map +1 -1
  21. package/esm/oas/parameter/Parameter.js +144 -0
  22. package/esm/oas/union/Union.d.ts +119 -5
  23. package/esm/oas/union/Union.d.ts.map +1 -1
  24. package/esm/oas/union/Union.js +108 -5
  25. package/package.json +1 -1
  26. package/script/context/ParseContext.d.ts +178 -0
  27. package/script/context/ParseContext.d.ts.map +1 -1
  28. package/script/context/ParseContext.js +108 -0
  29. package/script/context/RenderContext.d.ts +190 -0
  30. package/script/context/RenderContext.d.ts.map +1 -1
  31. package/script/context/RenderContext.js +179 -0
  32. package/script/dsl/Inserted.d.ts +240 -0
  33. package/script/dsl/Inserted.d.ts.map +1 -1
  34. package/script/dsl/Inserted.js +231 -0
  35. package/script/helpers/refFns.d.ts +160 -0
  36. package/script/helpers/refFns.d.ts.map +1 -1
  37. package/script/helpers/refFns.js +156 -0
  38. package/script/oas/boolean/Boolean.d.ts +142 -1
  39. package/script/oas/boolean/Boolean.d.ts.map +1 -1
  40. package/script/oas/boolean/Boolean.js +130 -1
  41. package/script/oas/components/Components.d.ts +252 -2
  42. package/script/oas/components/Components.d.ts.map +1 -1
  43. package/script/oas/components/Components.js +241 -2
  44. package/script/oas/parameter/Parameter.d.ts +160 -0
  45. package/script/oas/parameter/Parameter.d.ts.map +1 -1
  46. package/script/oas/parameter/Parameter.js +144 -0
  47. package/script/oas/union/Union.d.ts +119 -5
  48. package/script/oas/union/Union.d.ts.map +1 -1
  49. package/script/oas/union/Union.js +108 -5
@@ -5,62 +5,240 @@ import type * as log from '../deps/jsr.io/@std/log/0.224.14/mod.js';
5
5
  import type { StackTrail } from './StackTrail.js';
6
6
  import * as v from 'valibot';
7
7
  import type { IssueType } from './types.js';
8
+ /**
9
+ * Constructor arguments for {@link ParseContext}.
10
+ */
8
11
  type ConstructorArgs = {
12
+ /** The OpenAPI v3 document to parse */
9
13
  documentObject: OpenAPIV3.Document;
14
+ /** Logger instance for debug information */
10
15
  logger: log.Logger;
16
+ /** Stack trail for distributed tracing */
11
17
  stackTrail: StackTrail;
18
+ /** Whether to suppress console output */
12
19
  silent: boolean;
13
20
  };
21
+ /**
22
+ * Return type for the parse operation.
23
+ */
14
24
  export type ParseReturn = {
25
+ /** The parsed OAS document */
15
26
  oasDocument: OasDocument;
27
+ /** Array of parsing issues encountered */
16
28
  issues: ParseIssue[];
17
29
  };
30
+ /**
31
+ * Base type for parse warning messages.
32
+ */
18
33
  type ParseWarningBase = {
34
+ /** Issue severity level */
19
35
  level: 'warning';
36
+ /** Warning message */
20
37
  message: string;
21
38
  };
39
+ /**
40
+ * Base type for parse error messages.
41
+ */
22
42
  type ParseErrorBase = {
43
+ /** Issue severity level */
23
44
  level: 'error';
45
+ /** The error that occurred */
24
46
  error: Error;
25
47
  };
48
+ /**
49
+ * Base union type for parse issues.
50
+ */
26
51
  type ParseIssueBase = ParseErrorBase | ParseWarningBase;
52
+ /**
53
+ * Arguments for logging issues with a specific key.
54
+ */
27
55
  export type LogIssueArgs = ParseIssueBase & {
56
+ /** The key where the issue occurred */
28
57
  key: string;
58
+ /** The parent object containing the issue */
29
59
  parent: unknown;
60
+ /** The type of issue for categorization */
30
61
  type: IssueType;
31
62
  };
63
+ /**
64
+ * Arguments for logging issues without a specific key.
65
+ */
32
66
  export type LogIssueNoKeyArgs = ParseIssueBase & {
67
+ /** The parent object containing the issue */
33
68
  parent: unknown;
69
+ /** The type of issue for categorization */
34
70
  type: IssueType;
35
71
  };
72
+ /**
73
+ * Arguments for provisional parsing with validation.
74
+ */
36
75
  export type ProvisionalParseArgs<T> = {
76
+ /** The key being parsed */
37
77
  key: string;
78
+ /** The value to validate */
38
79
  value: unknown;
80
+ /** The parent object context */
39
81
  parent: unknown;
82
+ /** Valibot schema for validation */
40
83
  schema: v.GenericSchema<T>;
84
+ /** Function to generate error messages */
41
85
  toMessage: (value: unknown) => string;
86
+ /** The type of issue for categorization */
42
87
  type: IssueType;
43
88
  };
89
+ /**
90
+ * Arguments for logging skipped values during parsing.
91
+ */
44
92
  export type LogSkippedValuesArgs = {
93
+ /** Record of skipped key-value pairs */
45
94
  skipped: Record<string, unknown>;
95
+ /** The parent object context */
46
96
  parent: unknown;
97
+ /** String description of the parent type */
47
98
  parentType: string;
48
99
  };
100
+ /**
101
+ * Represents a parsing error with location context.
102
+ */
49
103
  export type ParseError = {
104
+ /** Error severity level */
50
105
  level: 'error';
106
+ /** The error that occurred */
51
107
  error: Error;
108
+ /** Location string where the error occurred */
52
109
  location: string;
110
+ /** The parent object context */
53
111
  parent: unknown;
112
+ /** The type of issue for categorization */
54
113
  type: IssueType;
55
114
  };
115
+ /**
116
+ * Represents a parsing warning with location context.
117
+ */
56
118
  export type ParseWarning = {
119
+ /** Warning severity level */
57
120
  level: 'warning';
121
+ /** Warning message */
58
122
  message: string;
123
+ /** Location string where the warning occurred */
59
124
  location: string;
125
+ /** The parent object context */
60
126
  parent: unknown;
127
+ /** The type of issue for categorization */
61
128
  type: IssueType;
62
129
  };
130
+ /**
131
+ * Union type for all parsing issues.
132
+ */
63
133
  export type ParseIssue = ParseError | ParseWarning;
134
+ /**
135
+ * The parsing context for the first phase of the SKMTC transformation pipeline.
136
+ *
137
+ * `ParseContext` is responsible for converting OpenAPI v3 JSON documents into
138
+ * the internal OAS (OpenAPI Schema) object representation used by SKMTC. It
139
+ * provides comprehensive error handling, validation, and issue tracking during
140
+ * the parsing process.
141
+ *
142
+ * This context handles the complex task of transforming external OpenAPI
143
+ * specifications into type-safe internal representations while maintaining
144
+ * detailed information about any parsing issues or inconsistencies found.
145
+ *
146
+ * ## Key Features
147
+ *
148
+ * - **JSON to OAS Conversion**: Transforms OpenAPI JSON into typed OAS objects
149
+ * - **Validation & Error Handling**: Comprehensive validation with detailed error reporting
150
+ * - **Issue Tracking**: Collects warnings and errors with precise location information
151
+ * - **Reference Management**: Handles complex reference resolution and tracking
152
+ * - **Logging Integration**: Provides detailed logging and tracing capabilities
153
+ * - **Silent Mode**: Can suppress console output while maintaining error collection
154
+ *
155
+ * @example Basic parsing usage
156
+ * ```typescript
157
+ * import { ParseContext } from '@skmtc/core';
158
+ *
159
+ * const parseContext = new ParseContext({
160
+ * documentObject: openApiJsonDocument,
161
+ * logger: myLogger,
162
+ * stackTrail: traceStack,
163
+ * silent: false
164
+ * });
165
+ *
166
+ * const oasDocument = parseContext.parse();
167
+ *
168
+ * // Check for parsing issues
169
+ * if (parseContext.issues.length > 0) {
170
+ * console.log('Parsing issues found:');
171
+ * parseContext.issues.forEach(issue => {
172
+ * console.log(`${issue.level}: ${issue.location} - ${issue.message || issue.error?.message}`);
173
+ * });
174
+ * }
175
+ *
176
+ * // Use the parsed document
177
+ * console.log('Parsed schemas:', Object.keys(oasDocument.components?.schemas || {}));
178
+ * ```
179
+ *
180
+ * @example Error handling during parsing
181
+ * ```typescript
182
+ * const parseContext = new ParseContext({
183
+ * documentObject: malformedOpenApiDoc,
184
+ * logger: logger,
185
+ * stackTrail: stack,
186
+ * silent: true
187
+ * });
188
+ *
189
+ * try {
190
+ * const parsed = parseContext.parse();
191
+ *
192
+ * // Separate errors from warnings
193
+ * const errors = parseContext.issues.filter(issue => issue.level === 'error');
194
+ * const warnings = parseContext.issues.filter(issue => issue.level === 'warning');
195
+ *
196
+ * if (errors.length > 0) {
197
+ * console.error(`${errors.length} parsing errors found`);
198
+ * errors.forEach(error => {
199
+ * console.error(`Error at ${error.location}: ${error.error.message}`);
200
+ * });
201
+ * }
202
+ *
203
+ * if (warnings.length > 0) {
204
+ * console.warn(`${warnings.length} parsing warnings found`);
205
+ * warnings.forEach(warning => {
206
+ * console.warn(`Warning at ${warning.location}: ${warning.message}`);
207
+ * });
208
+ * }
209
+ * } catch (error) {
210
+ * console.error('Critical parsing failure:', error);
211
+ * }
212
+ * ```
213
+ *
214
+ * @example Integration with CoreContext
215
+ * ```typescript
216
+ * // Typically used within CoreContext.parse()
217
+ * class CustomCoreContext extends CoreContext {
218
+ * parseWithCustomValidation(document: OpenAPIV3.Document) {
219
+ * const parseContext = new ParseContext({
220
+ * documentObject: document,
221
+ * logger: this.logger,
222
+ * stackTrail: this.stackTrail,
223
+ * silent: this.silent
224
+ * });
225
+ *
226
+ * const parsed = parseContext.parse();
227
+ *
228
+ * // Custom post-processing based on issues
229
+ * const criticalErrors = parseContext.issues.filter(issue =>
230
+ * issue.level === 'error' && issue.type === 'schema-validation'
231
+ * );
232
+ *
233
+ * if (criticalErrors.length > 0) {
234
+ * throw new Error(`Schema validation failed: ${criticalErrors.length} critical errors`);
235
+ * }
236
+ *
237
+ * return parsed;
238
+ * }
239
+ * }
240
+ * ```
241
+ */
64
242
  export declare class ParseContext {
65
243
  #private;
66
244
  documentObject: OpenAPIV3.Document;
@@ -1 +1 @@
1
- {"version":3,"file":"ParseContext.d.ts","sourceRoot":"","sources":["../../src/context/ParseContext.ts"],"names":[],"mappings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AE,UAAU,CAAA;IACtB,MAAM,EAAE,UAAU,EAAE,CAAA;IACpB,MAAM,EAAE,OAAO,CAAA;gBAGH,EAAE,cAAc,EAAE,MAAM,EAAE,UAAU,EAAE,MAAa,EAAE,EAAE,eAAe;IAWlF,KAAK,IAAI,WAAW;IAWpB,kBAAkB;IAoBlB,WAAW,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM;IAMhD,gBAAgB,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS;IAQvD,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC;IAIlD,gBAAgB,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,oBAAoB;IAYtE,gBAAgB,CAAC,CAAC,EAAE,EAClB,GAAG,EACH,KAAK,EACL,MAAM,EACN,MAAM,EACN,SAAS,EACT,IAAI,EACL,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS;IAgB1C,QAAQ,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,EAAE,EAAE,YAAY;IAItD,aAAa,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,EAAE,EAAE,iBAAiB;CAqB5D;AAED,eAAO,MAAM,WAAW,GAAI,QAAQ,MAAM,KAAG,SAAS,CAAC,QAMtD,CAAA"}
@@ -16,6 +16,114 @@ import { toDocumentFieldsV3 } from '../oas/document/toDocumentFieldsV3.js';
16
16
  import { OasDocument } from '../oas/document/Document.js';
17
17
  import { tracer } from '../helpers/tracer.js';
18
18
  import * as v from 'valibot';
19
+ /**
20
+ * The parsing context for the first phase of the SKMTC transformation pipeline.
21
+ *
22
+ * `ParseContext` is responsible for converting OpenAPI v3 JSON documents into
23
+ * the internal OAS (OpenAPI Schema) object representation used by SKMTC. It
24
+ * provides comprehensive error handling, validation, and issue tracking during
25
+ * the parsing process.
26
+ *
27
+ * This context handles the complex task of transforming external OpenAPI
28
+ * specifications into type-safe internal representations while maintaining
29
+ * detailed information about any parsing issues or inconsistencies found.
30
+ *
31
+ * ## Key Features
32
+ *
33
+ * - **JSON to OAS Conversion**: Transforms OpenAPI JSON into typed OAS objects
34
+ * - **Validation & Error Handling**: Comprehensive validation with detailed error reporting
35
+ * - **Issue Tracking**: Collects warnings and errors with precise location information
36
+ * - **Reference Management**: Handles complex reference resolution and tracking
37
+ * - **Logging Integration**: Provides detailed logging and tracing capabilities
38
+ * - **Silent Mode**: Can suppress console output while maintaining error collection
39
+ *
40
+ * @example Basic parsing usage
41
+ * ```typescript
42
+ * import { ParseContext } from '@skmtc/core';
43
+ *
44
+ * const parseContext = new ParseContext({
45
+ * documentObject: openApiJsonDocument,
46
+ * logger: myLogger,
47
+ * stackTrail: traceStack,
48
+ * silent: false
49
+ * });
50
+ *
51
+ * const oasDocument = parseContext.parse();
52
+ *
53
+ * // Check for parsing issues
54
+ * if (parseContext.issues.length > 0) {
55
+ * console.log('Parsing issues found:');
56
+ * parseContext.issues.forEach(issue => {
57
+ * console.log(`${issue.level}: ${issue.location} - ${issue.message || issue.error?.message}`);
58
+ * });
59
+ * }
60
+ *
61
+ * // Use the parsed document
62
+ * console.log('Parsed schemas:', Object.keys(oasDocument.components?.schemas || {}));
63
+ * ```
64
+ *
65
+ * @example Error handling during parsing
66
+ * ```typescript
67
+ * const parseContext = new ParseContext({
68
+ * documentObject: malformedOpenApiDoc,
69
+ * logger: logger,
70
+ * stackTrail: stack,
71
+ * silent: true
72
+ * });
73
+ *
74
+ * try {
75
+ * const parsed = parseContext.parse();
76
+ *
77
+ * // Separate errors from warnings
78
+ * const errors = parseContext.issues.filter(issue => issue.level === 'error');
79
+ * const warnings = parseContext.issues.filter(issue => issue.level === 'warning');
80
+ *
81
+ * if (errors.length > 0) {
82
+ * console.error(`${errors.length} parsing errors found`);
83
+ * errors.forEach(error => {
84
+ * console.error(`Error at ${error.location}: ${error.error.message}`);
85
+ * });
86
+ * }
87
+ *
88
+ * if (warnings.length > 0) {
89
+ * console.warn(`${warnings.length} parsing warnings found`);
90
+ * warnings.forEach(warning => {
91
+ * console.warn(`Warning at ${warning.location}: ${warning.message}`);
92
+ * });
93
+ * }
94
+ * } catch (error) {
95
+ * console.error('Critical parsing failure:', error);
96
+ * }
97
+ * ```
98
+ *
99
+ * @example Integration with CoreContext
100
+ * ```typescript
101
+ * // Typically used within CoreContext.parse()
102
+ * class CustomCoreContext extends CoreContext {
103
+ * parseWithCustomValidation(document: OpenAPIV3.Document) {
104
+ * const parseContext = new ParseContext({
105
+ * documentObject: document,
106
+ * logger: this.logger,
107
+ * stackTrail: this.stackTrail,
108
+ * silent: this.silent
109
+ * });
110
+ *
111
+ * const parsed = parseContext.parse();
112
+ *
113
+ * // Custom post-processing based on issues
114
+ * const criticalErrors = parseContext.issues.filter(issue =>
115
+ * issue.level === 'error' && issue.type === 'schema-validation'
116
+ * );
117
+ *
118
+ * if (criticalErrors.length > 0) {
119
+ * throw new Error(`Schema validation failed: ${criticalErrors.length} critical errors`);
120
+ * }
121
+ *
122
+ * return parsed;
123
+ * }
124
+ * }
125
+ * ```
126
+ */
19
127
  export class ParseContext {
20
128
  constructor({ documentObject, logger, stackTrail, silent = true }) {
21
129
  Object.defineProperty(this, "documentObject", {
@@ -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,EAAE,GAAG,CAAC,MAAM,CAAA;IAClB,oBAAoB,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,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