@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
@@ -3,24 +3,138 @@ import type { OasSchema } from '../schema/Schema.js';
3
3
  import type { OasRef } from '../ref/Ref.js';
4
4
  import type { ToJsonSchemaOptions } from '../schema/Schema.js';
5
5
  import type { OpenAPIV3 } from 'openapi-types';
6
+ /**
7
+ * Constructor fields for {@link OasUnion}.
8
+ */
6
9
  export type UnionFields = {
10
+ /** A short summary of the union type */
7
11
  title?: string;
12
+ /** A description of the union type */
8
13
  description?: string;
14
+ /** Whether the union value can be null */
9
15
  nullable?: boolean;
16
+ /** Discriminator object for creating tagged unions */
10
17
  discriminator?: OasDiscriminator;
18
+ /** Example value for the union */
11
19
  example?: unknown;
20
+ /** Default value for the union */
12
21
  default?: unknown;
22
+ /** Array of schemas that make up the union members */
13
23
  members: (OasSchema | OasRef<'schema'>)[];
24
+ /** Custom extension fields (x-* properties) */
14
25
  extensionFields?: Record<string, unknown>;
15
26
  };
16
27
  /**
17
- * Object representing a 'oneOf' or 'anyOf' in the OpenAPI Specification.
28
+ * Represents a union type schema in the OpenAPI Specification.
29
+ *
30
+ * `OasUnion` handles both OpenAPI `oneOf` and `anyOf` constructs by mapping them
31
+ * to TypeScript union types. While OpenAPI distinguishes between these concepts,
32
+ * in TypeScript they both represent union types (A | B | C), making the distinction
33
+ * less meaningful for code generation.
34
+ *
35
+ * This class supports both simple unions and discriminated (tagged) unions through
36
+ * the discriminator property, which enables more precise type narrowing in generated code.
37
+ *
38
+ * ## Key Features
39
+ *
40
+ * - **Union Types**: Represents multiple possible schema types as a single union
41
+ * - **Tagged Unions**: Supports discriminator properties for type narrowing
42
+ * - **Reference Resolution**: Handles references to other schemas within union members
43
+ * - **Nullable Support**: Can represent nullable union types (A | B | null)
44
+ * - **JSON Schema**: Converts to standard JSON Schema format for validation
45
+ *
46
+ * @example Basic union type
47
+ * ```typescript
48
+ * import { OasUnion, OasString, OasInteger } from '@skmtc/core';
49
+ *
50
+ * const stringOrNumber = new OasUnion({
51
+ * title: 'StringOrNumber',
52
+ * description: 'A value that can be either a string or number',
53
+ * members: [
54
+ * new OasString({ title: 'String Value' }),
55
+ * new OasInteger({ title: 'Integer Value' })
56
+ * ]
57
+ * });
58
+ *
59
+ * // This represents: string | number
60
+ * ```
61
+ *
62
+ * @example Discriminated union (tagged union)
63
+ * ```typescript
64
+ * const shape = new OasUnion({
65
+ * title: 'Shape',
66
+ * description: 'Different types of geometric shapes',
67
+ * discriminator: new OasDiscriminator({
68
+ * propertyName: 'type',
69
+ * mapping: {
70
+ * 'circle': '#/components/schemas/Circle',
71
+ * 'square': '#/components/schemas/Square'
72
+ * }
73
+ * }),
74
+ * members: [
75
+ * new OasRef({ $ref: '#/components/schemas/Circle' }),
76
+ * new OasRef({ $ref: '#/components/schemas/Square' })
77
+ * ]
78
+ * });
79
+ *
80
+ * // This creates a tagged union that can be narrowed by the 'type' property
81
+ * ```
82
+ *
83
+ * @example Nullable union
84
+ * ```typescript
85
+ * const nullableStatus = new OasUnion({
86
+ * title: 'NullableStatus',
87
+ * nullable: true,
88
+ * members: [
89
+ * new OasString({ enum: ['active', 'inactive'] }),
90
+ * new OasString({ enum: ['pending', 'suspended'] })
91
+ * ],
92
+ * default: null
93
+ * });
94
+ *
95
+ * // This represents: ('active' | 'inactive' | 'pending' | 'suspended') | null
96
+ * ```
97
+ *
98
+ * @example Complex nested union
99
+ * ```typescript
100
+ * const apiResponse = new OasUnion({
101
+ * title: 'ApiResponse',
102
+ * description: 'Response from API endpoint',
103
+ * members: [
104
+ * new OasObject({
105
+ * title: 'SuccessResponse',
106
+ * properties: {
107
+ * success: new OasBoolean({ default: true }),
108
+ * data: new OasObject({ additionalProperties: true })
109
+ * }
110
+ * }),
111
+ * new OasObject({
112
+ * title: 'ErrorResponse',
113
+ * properties: {
114
+ * error: new OasString(),
115
+ * code: new OasInteger()
116
+ * }
117
+ * })
118
+ * ]
119
+ * });
120
+ *
121
+ * // This represents: { success: boolean; data: Record<string, any> } | { error: string; code: number }
122
+ * ```
18
123
  *
19
- * In the context of TypeScript 'anyOf' is not helpful since it implies
20
- * a union that consists of all possible combinations of member types.
124
+ * @example Using with references
125
+ * ```typescript
126
+ * const userOrAdmin = new OasUnion({
127
+ * title: 'UserOrAdmin',
128
+ * description: 'Either a regular user or an admin user',
129
+ * members: [
130
+ * new OasRef({ $ref: '#/components/schemas/User' }),
131
+ * new OasRef({ $ref: '#/components/schemas/Admin' })
132
+ * ]
133
+ * });
21
134
  *
22
- * Generating such combination types would not be useful and we map both
23
- * 'oneOf' and 'anyOf' to a TypeScript union type.
135
+ * // References will be resolved during processing
136
+ * // This represents: User | Admin
137
+ * ```
24
138
  */
25
139
  export declare class OasUnion {
26
140
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"Union.d.ts","sourceRoot":"","sources":["../../../src/oas/union/Union.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAA;AACzE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAE9C,MAAM,MAAM,WAAW,GAAG;IAC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CAAA;IAC/B;;OAEG;IACH,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAA;IAC7B;;OAEG;IACH,aAAa,EAAE,gBAAgB,GAAG,SAAS,CAAA;IAC3C;;OAEG;IACH,OAAO,EAAE,CAAC,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAA;IAEzC,qCAAqC;IACrC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAA;IACpD;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;gBAEL,MAAM,EAAE,WAAW;IAW/B,KAAK,IAAI,IAAI,IAAI,MAAM,CAAC,QAAQ,CAAC;IAIjC,OAAO,IAAI,QAAQ;IAInB,WAAW,IAAI,QAAQ;IAIvB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,SAAS,CAAC,oBAAoB;CAU3E"}
@@ -1,11 +1,114 @@
1
1
  /**
2
- * Object representing a 'oneOf' or 'anyOf' in the OpenAPI Specification.
2
+ * Represents a union type schema in the OpenAPI Specification.
3
3
  *
4
- * In the context of TypeScript 'anyOf' is not helpful since it implies
5
- * a union that consists of all possible combinations of member types.
4
+ * `OasUnion` handles both OpenAPI `oneOf` and `anyOf` constructs by mapping them
5
+ * to TypeScript union types. While OpenAPI distinguishes between these concepts,
6
+ * in TypeScript they both represent union types (A | B | C), making the distinction
7
+ * less meaningful for code generation.
6
8
  *
7
- * Generating such combination types would not be useful and we map both
8
- * 'oneOf' and 'anyOf' to a TypeScript union type.
9
+ * This class supports both simple unions and discriminated (tagged) unions through
10
+ * the discriminator property, which enables more precise type narrowing in generated code.
11
+ *
12
+ * ## Key Features
13
+ *
14
+ * - **Union Types**: Represents multiple possible schema types as a single union
15
+ * - **Tagged Unions**: Supports discriminator properties for type narrowing
16
+ * - **Reference Resolution**: Handles references to other schemas within union members
17
+ * - **Nullable Support**: Can represent nullable union types (A | B | null)
18
+ * - **JSON Schema**: Converts to standard JSON Schema format for validation
19
+ *
20
+ * @example Basic union type
21
+ * ```typescript
22
+ * import { OasUnion, OasString, OasInteger } from '@skmtc/core';
23
+ *
24
+ * const stringOrNumber = new OasUnion({
25
+ * title: 'StringOrNumber',
26
+ * description: 'A value that can be either a string or number',
27
+ * members: [
28
+ * new OasString({ title: 'String Value' }),
29
+ * new OasInteger({ title: 'Integer Value' })
30
+ * ]
31
+ * });
32
+ *
33
+ * // This represents: string | number
34
+ * ```
35
+ *
36
+ * @example Discriminated union (tagged union)
37
+ * ```typescript
38
+ * const shape = new OasUnion({
39
+ * title: 'Shape',
40
+ * description: 'Different types of geometric shapes',
41
+ * discriminator: new OasDiscriminator({
42
+ * propertyName: 'type',
43
+ * mapping: {
44
+ * 'circle': '#/components/schemas/Circle',
45
+ * 'square': '#/components/schemas/Square'
46
+ * }
47
+ * }),
48
+ * members: [
49
+ * new OasRef({ $ref: '#/components/schemas/Circle' }),
50
+ * new OasRef({ $ref: '#/components/schemas/Square' })
51
+ * ]
52
+ * });
53
+ *
54
+ * // This creates a tagged union that can be narrowed by the 'type' property
55
+ * ```
56
+ *
57
+ * @example Nullable union
58
+ * ```typescript
59
+ * const nullableStatus = new OasUnion({
60
+ * title: 'NullableStatus',
61
+ * nullable: true,
62
+ * members: [
63
+ * new OasString({ enum: ['active', 'inactive'] }),
64
+ * new OasString({ enum: ['pending', 'suspended'] })
65
+ * ],
66
+ * default: null
67
+ * });
68
+ *
69
+ * // This represents: ('active' | 'inactive' | 'pending' | 'suspended') | null
70
+ * ```
71
+ *
72
+ * @example Complex nested union
73
+ * ```typescript
74
+ * const apiResponse = new OasUnion({
75
+ * title: 'ApiResponse',
76
+ * description: 'Response from API endpoint',
77
+ * members: [
78
+ * new OasObject({
79
+ * title: 'SuccessResponse',
80
+ * properties: {
81
+ * success: new OasBoolean({ default: true }),
82
+ * data: new OasObject({ additionalProperties: true })
83
+ * }
84
+ * }),
85
+ * new OasObject({
86
+ * title: 'ErrorResponse',
87
+ * properties: {
88
+ * error: new OasString(),
89
+ * code: new OasInteger()
90
+ * }
91
+ * })
92
+ * ]
93
+ * });
94
+ *
95
+ * // This represents: { success: boolean; data: Record<string, any> } | { error: string; code: number }
96
+ * ```
97
+ *
98
+ * @example Using with references
99
+ * ```typescript
100
+ * const userOrAdmin = new OasUnion({
101
+ * title: 'UserOrAdmin',
102
+ * description: 'Either a regular user or an admin user',
103
+ * members: [
104
+ * new OasRef({ $ref: '#/components/schemas/User' }),
105
+ * new OasRef({ $ref: '#/components/schemas/Admin' })
106
+ * ]
107
+ * });
108
+ *
109
+ * // References will be resolved during processing
110
+ * // This represents: User | Admin
111
+ * ```
9
112
  */
10
113
  export class OasUnion {
11
114
  constructor(fields) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skmtc/core",
3
- "version": "0.0.788",
3
+ "version": "0.0.790",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/skmtc/skmtc.git"
@@ -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":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAG9C,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,KAAK,KAAK,GAAG,MAAM,yCAAyC,CAAA;AACnE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAC5B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAE3C,KAAK,eAAe,GAAG;IACrB,cAAc,EAAE,SAAS,CAAC,QAAQ,CAAA;IAClC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAA;IAClB,UAAU,EAAE,UAAU,CAAA;IACtB,MAAM,EAAE,OAAO,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,WAAW,EAAE,WAAW,CAAA;IACxB,MAAM,EAAE,UAAU,EAAE,CAAA;CACrB,CAAA;AAED,KAAK,gBAAgB,GAAG;IACtB,KAAK,EAAE,SAAS,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,KAAK,cAAc,GAAG;IACpB,KAAK,EAAE,OAAO,CAAA;IACd,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAED,KAAK,cAAc,GAAG,cAAc,GAAG,gBAAgB,CAAA;AAEvD,MAAM,MAAM,YAAY,GAAG,cAAc,GAAG;IAC1C,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,OAAO,CAAA;IACf,IAAI,EAAE,SAAS,CAAA;CAChB,CAAA;AAED,M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js_1 = require("../oas/document/Document.js");
53
53
  const tracer_js_1 = require("../helpers/tracer.js");
54
54
  const v = __importStar(require("valibot"));
55
+ /**
56
+ * The parsing context for the first phase of the SKMTC transformation pipeline.
57
+ *
58
+ * `ParseContext` is responsible for converting OpenAPI v3 JSON documents into
59
+ * the internal OAS (OpenAPI Schema) object representation used by SKMTC. It
60
+ * provides comprehensive error handling, validation, and issue tracking during
61
+ * the parsing process.
62
+ *
63
+ * This context handles the complex task of transforming external OpenAPI
64
+ * specifications into type-safe internal representations while maintaining
65
+ * detailed information about any parsing issues or inconsistencies found.
66
+ *
67
+ * ## Key Features
68
+ *
69
+ * - **JSON to OAS Conversion**: Transforms OpenAPI JSON into typed OAS objects
70
+ * - **Validation & Error Handling**: Comprehensive validation with detailed error reporting
71
+ * - **Issue Tracking**: Collects warnings and errors with precise location information
72
+ * - **Reference Management**: Handles complex reference resolution and tracking
73
+ * - **Logging Integration**: Provides detailed logging and tracing capabilities
74
+ * - **Silent Mode**: Can suppress console output while maintaining error collection
75
+ *
76
+ * @example Basic parsing usage
77
+ * ```typescript
78
+ * import { ParseContext } from '@skmtc/core';
79
+ *
80
+ * const parseContext = new ParseContext({
81
+ * documentObject: openApiJsonDocument,
82
+ * logger: myLogger,
83
+ * stackTrail: traceStack,
84
+ * silent: false
85
+ * });
86
+ *
87
+ * const oasDocument = parseContext.parse();
88
+ *
89
+ * // Check for parsing issues
90
+ * if (parseContext.issues.length > 0) {
91
+ * console.log('Parsing issues found:');
92
+ * parseContext.issues.forEach(issue => {
93
+ * console.log(`${issue.level}: ${issue.location} - ${issue.message || issue.error?.message}`);
94
+ * });
95
+ * }
96
+ *
97
+ * // Use the parsed document
98
+ * console.log('Parsed schemas:', Object.keys(oasDocument.components?.schemas || {}));
99
+ * ```
100
+ *
101
+ * @example Error handling during parsing
102
+ * ```typescript
103
+ * const parseContext = new ParseContext({
104
+ * documentObject: malformedOpenApiDoc,
105
+ * logger: logger,
106
+ * stackTrail: stack,
107
+ * silent: true
108
+ * });
109
+ *
110
+ * try {
111
+ * const parsed = parseContext.parse();
112
+ *
113
+ * // Separate errors from warnings
114
+ * const errors = parseContext.issues.filter(issue => issue.level === 'error');
115
+ * const warnings = parseContext.issues.filter(issue => issue.level === 'warning');
116
+ *
117
+ * if (errors.length > 0) {
118
+ * console.error(`${errors.length} parsing errors found`);
119
+ * errors.forEach(error => {
120
+ * console.error(`Error at ${error.location}: ${error.error.message}`);
121
+ * });
122
+ * }
123
+ *
124
+ * if (warnings.length > 0) {
125
+ * console.warn(`${warnings.length} parsing warnings found`);
126
+ * warnings.forEach(warning => {
127
+ * console.warn(`Warning at ${warning.location}: ${warning.message}`);
128
+ * });
129
+ * }
130
+ * } catch (error) {
131
+ * console.error('Critical parsing failure:', error);
132
+ * }
133
+ * ```
134
+ *
135
+ * @example Integration with CoreContext
136
+ * ```typescript
137
+ * // Typically used within CoreContext.parse()
138
+ * class CustomCoreContext extends CoreContext {
139
+ * parseWithCustomValidation(document: OpenAPIV3.Document) {
140
+ * const parseContext = new ParseContext({
141
+ * documentObject: document,
142
+ * logger: this.logger,
143
+ * stackTrail: this.stackTrail,
144
+ * silent: this.silent
145
+ * });
146
+ *
147
+ * const parsed = parseContext.parse();
148
+ *
149
+ * // Custom post-processing based on issues
150
+ * const criticalErrors = parseContext.issues.filter(issue =>
151
+ * issue.level === 'error' && issue.type === 'schema-validation'
152
+ * );
153
+ *
154
+ * if (criticalErrors.length > 0) {
155
+ * throw new Error(`Schema validation failed: ${criticalErrors.length} critical errors`);
156
+ * }
157
+ *
158
+ * return parsed;
159
+ * }
160
+ * }
161
+ * ```
162
+ */
55
163
  class ParseContext {
56
164
  constructor({ documentObject, logger, stackTrail, silent = true }) {
57
165
  Object.defineProperty(this, "documentObject", {