@skmtc/core 0.0.794 → 0.0.796

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.
@@ -15,23 +15,190 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.StackTrail = void 0;
16
16
  require("../_dnt.polyfills.js");
17
17
  const Components_js_1 = require("../oas/components/Components.js");
18
+ /**
19
+ * Represents a stack-based trail for tracking document traversal in OpenAPI processing.
20
+ *
21
+ * The `StackTrail` class maintains a stack of string frames that represent the current
22
+ * path through an OpenAPI document structure. It's used throughout the SKMTC pipeline
23
+ * for tracking context during parsing, generating, and debugging schema processing.
24
+ *
25
+ * This class is essential for error reporting, debugging, and maintaining context
26
+ * when processing nested OpenAPI structures like schemas, operations, and components.
27
+ *
28
+ * ## Key Features
29
+ *
30
+ * - **Path Tracking**: Maintains a trail of traversed document elements
31
+ * - **Context Preservation**: Preserves parsing context for error reporting
32
+ * - **Stack Operations**: Supports push, pop, clone, and manipulation operations
33
+ * - **Reference Resolution**: Can generate OpenAPI reference strings from trails
34
+ * - **Serialization**: Supports string serialization and parsing for persistence
35
+ *
36
+ * @example Basic usage
37
+ * ```typescript
38
+ * import { StackTrail } from '@skmtc/core';
39
+ *
40
+ * // Start with empty trail
41
+ * const trail = new StackTrail();
42
+ *
43
+ * // Build a path through document structure
44
+ * trail.append('components')
45
+ * .append('schemas')
46
+ * .append('User')
47
+ * .append('properties')
48
+ * .append('name');
49
+ *
50
+ * console.log(trail.toString()); // 'components:schemas:User:properties:name'
51
+ * ```
52
+ *
53
+ * @example Schema reference generation
54
+ * ```typescript
55
+ * const schemaTrail = new StackTrail(['components', 'schemas', 'User']);
56
+ * const ref = schemaTrail.toStackRef();
57
+ * console.log(ref); // '#/components/schemas/User'
58
+ * ```
59
+ *
60
+ * @example Error context tracking
61
+ * ```typescript
62
+ * class SchemaProcessor {
63
+ * processSchema(schema: OasSchema, trail: StackTrail) {
64
+ * try {
65
+ * // Process schema logic
66
+ * return this.transformSchema(schema);
67
+ * } catch (error) {
68
+ * throw new Error(`Error at ${trail.toString()}: ${error.message}`);
69
+ * // Error at components:schemas:User:properties:email: Invalid format
70
+ * }
71
+ * }
72
+ * }
73
+ * ```
74
+ *
75
+ * @example Cloning and manipulation
76
+ * ```typescript
77
+ * const baseTrail = new StackTrail(['components', 'schemas']);
78
+ *
79
+ * // Clone for processing different schemas
80
+ * const userTrail = baseTrail.clone().append('User');
81
+ * const productTrail = baseTrail.clone().append('Product');
82
+ *
83
+ * console.log(userTrail.toString()); // 'components:schemas:User'
84
+ * console.log(productTrail.toString()); // 'components:schemas:Product'
85
+ * console.log(baseTrail.toString()); // 'components:schemas' (unchanged)
86
+ * ```
87
+ */
18
88
  class StackTrail {
89
+ /**
90
+ * Creates a new StackTrail instance.
91
+ *
92
+ * @param stack - Initial stack frames (defaults to empty array)
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * // Empty trail
97
+ * const trail1 = new StackTrail();
98
+ *
99
+ * // Pre-populated trail
100
+ * const trail2 = new StackTrail(['components', 'schemas', 'User']);
101
+ * ```
102
+ */
19
103
  constructor(stack = []) {
104
+ /** Internal stack of traversal frames */
20
105
  _StackTrail_stack.set(this, void 0);
21
106
  __classPrivateFieldSet(this, _StackTrail_stack, stack, "f");
22
107
  }
108
+ /**
109
+ * Creates a shallow copy of the stack trail.
110
+ *
111
+ * @returns A new StackTrail instance with copied frames
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * const original = new StackTrail(['components', 'schemas']);
116
+ * const copy = original.clone();
117
+ *
118
+ * copy.append('User');
119
+ * console.log(original.toString()); // 'components:schemas'
120
+ * console.log(copy.toString()); // 'components:schemas:User'
121
+ * ```
122
+ */
23
123
  clone() {
24
124
  return new StackTrail([...__classPrivateFieldGet(this, _StackTrail_stack, "f")]);
25
125
  }
126
+ /**
127
+ * Creates a new trail from a slice of the current trail.
128
+ *
129
+ * @param start - Starting index (inclusive)
130
+ * @param end - Ending index (exclusive, optional)
131
+ * @returns A new StackTrail with sliced frames
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * const trail = new StackTrail(['a', 'b', 'c', 'd', 'e']);
136
+ *
137
+ * const slice1 = trail.slice(1, 3);
138
+ * console.log(slice1.toString()); // 'b:c'
139
+ *
140
+ * const slice2 = trail.slice(2);
141
+ * console.log(slice2.toString()); // 'c:d:e'
142
+ * ```
143
+ */
26
144
  slice(start, end) {
27
145
  return new StackTrail(__classPrivateFieldGet(this, _StackTrail_stack, "f").slice(start, end));
28
146
  }
147
+ /**
148
+ * Checks if all specified frames exist in the trail.
149
+ *
150
+ * @param frames - Array of frames to check for
151
+ * @returns True if all frames are present in the trail
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * const trail = new StackTrail(['components', 'schemas', 'User', 'properties']);
156
+ *
157
+ * console.log(trail.includes(['schemas', 'User'])); // true
158
+ * console.log(trail.includes(['schemas', 'Product'])); // false
159
+ * console.log(trail.includes(['components'])); // true
160
+ * ```
161
+ */
29
162
  includes(frames) {
30
163
  return frames.every(frame => __classPrivateFieldGet(this, _StackTrail_stack, "f").includes(frame));
31
164
  }
165
+ /**
166
+ * Gets a copy of the current stack frames.
167
+ *
168
+ * @returns Array of stack frames in order
169
+ *
170
+ * @example
171
+ * ```typescript
172
+ * const trail = new StackTrail(['components', 'schemas', 'User']);
173
+ * const frames = trail.stackTrail;
174
+ * console.log(frames); // ['components', 'schemas', 'User']
175
+ * ```
176
+ */
32
177
  get stackTrail() {
33
178
  return __classPrivateFieldGet(this, _StackTrail_stack, "f");
34
179
  }
180
+ /**
181
+ * Appends frame(s) to the end of the trail.
182
+ *
183
+ * @param frame - Single frame string or array of frames to append
184
+ * @returns This StackTrail instance for chaining
185
+ *
186
+ * @throws {Error} When frame is not a string or string array
187
+ *
188
+ * @example Single frame
189
+ * ```typescript
190
+ * const trail = new StackTrail(['components']);
191
+ * trail.append('schemas').append('User');
192
+ * console.log(trail.toString()); // 'components:schemas:User'
193
+ * ```
194
+ *
195
+ * @example Multiple frames
196
+ * ```typescript
197
+ * const trail = new StackTrail();
198
+ * trail.append(['components', 'schemas', 'User']);
199
+ * console.log(trail.toString()); // 'components:schemas:User'
200
+ * ```
201
+ */
35
202
  append(frame) {
36
203
  if (typeof frame === 'string') {
37
204
  __classPrivateFieldGet(this, _StackTrail_stack, "f").push(frame);
@@ -43,6 +210,22 @@ class StackTrail {
43
210
  }
44
211
  throw new Error(`Unexpected stack frame: ${frame}`);
45
212
  }
213
+ /**
214
+ * Gets the parent name of a property frame.
215
+ *
216
+ * This method is specifically designed to find parent object names
217
+ * for property trails in schema processing.
218
+ *
219
+ * @param frame - The frame name to find the parent of
220
+ * @returns Parent name if found, undefined otherwise
221
+ *
222
+ * @example
223
+ * ```typescript
224
+ * const trail = new StackTrail(['components', 'schemas', 'User', 'properties', 'email']);
225
+ * const parent = trail.getParentOf('email');
226
+ * console.log(parent); // 'User'
227
+ * ```
228
+ */
46
229
  getParentOf(frame) {
47
230
  const lastItemIndex = this.stackTrail.length - 1;
48
231
  if (this.stackTrail?.[lastItemIndex] === frame &&
@@ -51,6 +234,28 @@ class StackTrail {
51
234
  return typeof parentName === 'string' ? parentName : undefined;
52
235
  }
53
236
  }
237
+ /**
238
+ * Converts the trail to an OpenAPI reference string if applicable.
239
+ *
240
+ * Only trails that represent valid OpenAPI component references
241
+ * (starting with 'components') can be converted to reference strings.
242
+ *
243
+ * @returns OpenAPI reference string or undefined if not a valid reference trail
244
+ *
245
+ * @example Valid reference trail
246
+ * ```typescript
247
+ * const trail = new StackTrail(['components', 'schemas', 'User']);
248
+ * const ref = trail.toStackRef();
249
+ * console.log(ref); // '#/components/schemas/User'
250
+ * ```
251
+ *
252
+ * @example Invalid trail
253
+ * ```typescript
254
+ * const trail = new StackTrail(['paths', '/users', 'get']);
255
+ * const ref = trail.toStackRef();
256
+ * console.log(ref); // undefined
257
+ * ```
258
+ */
54
259
  toStackRef() {
55
260
  const [first, second, third] = this.stackTrail;
56
261
  if (first !== 'components') {
@@ -64,6 +269,29 @@ class StackTrail {
64
269
  }
65
270
  return `#/${first}/${second}/${third}`;
66
271
  }
272
+ /**
273
+ * Removes frame(s) from the end of the trail.
274
+ *
275
+ * @param frame - Single frame string or array of frames to remove
276
+ * @returns This StackTrail instance for chaining
277
+ *
278
+ * @throws {Error} When trying to remove a frame that doesn't match the last frame
279
+ * @throws {Error} When frame is not a string or string array
280
+ *
281
+ * @example Single frame removal
282
+ * ```typescript
283
+ * const trail = new StackTrail(['components', 'schemas', 'User', 'properties']);
284
+ * trail.remove('properties');
285
+ * console.log(trail.toString()); // 'components:schemas:User'
286
+ * ```
287
+ *
288
+ * @example Multiple frame removal
289
+ * ```typescript
290
+ * const trail = new StackTrail(['components', 'schemas', 'User', 'properties', 'name']);
291
+ * trail.remove(['name', 'properties']);
292
+ * console.log(trail.toString()); // 'components:schemas:User'
293
+ * ```
294
+ */
67
295
  remove(frame) {
68
296
  if (typeof frame === 'string') {
69
297
  const lastItem = __classPrivateFieldGet(this, _StackTrail_stack, "f")[__classPrivateFieldGet(this, _StackTrail_stack, "f").length - 1];
@@ -79,9 +307,42 @@ class StackTrail {
79
307
  }
80
308
  throw new Error(`Unexpected stack frame: ${frame}`);
81
309
  }
310
+ /**
311
+ * Joins multiple stacks or strings into a single colon-separated string.
312
+ *
313
+ * @param stacks - Array of StackTrail instances or strings to join
314
+ * @returns Joined string with colon separators
315
+ *
316
+ * @example
317
+ * ```typescript
318
+ * const trail1 = new StackTrail(['components', 'schemas']);
319
+ * const trail2 = new StackTrail(['User', 'properties']);
320
+ *
321
+ * const joined = StackTrail.join(trail1, 'separator', trail2);
322
+ * console.log(joined); // 'components:schemas:separator:User:properties'
323
+ * ```
324
+ */
82
325
  static join(...stacks) {
83
326
  return stacks.map(stack => stack.toString()).join(':');
84
327
  }
328
+ /**
329
+ * Parses a colon-separated string into a StackTrail instance.
330
+ *
331
+ * @param value - Colon-separated string to parse
332
+ * @returns New StackTrail instance
333
+ *
334
+ * @throws {Error} When the string contains empty tokens
335
+ *
336
+ * @example
337
+ * ```typescript
338
+ * const trail = StackTrail.parse('components:schemas:User:properties:name');
339
+ * console.log(trail.stackTrail); // ['components', 'schemas', 'User', 'properties', 'name']
340
+ *
341
+ * // Handles escaped colons
342
+ * const escapedTrail = StackTrail.parse('components:schemas:User%3AType');
343
+ * console.log(escapedTrail.stackTrail); // ['components', 'schemas', 'User:Type']
344
+ * ```
345
+ */
85
346
  static parse(value) {
86
347
  const stack = value.split(':').map(item => {
87
348
  if (!item) {
@@ -91,9 +352,42 @@ class StackTrail {
91
352
  });
92
353
  return new StackTrail(stack);
93
354
  }
355
+ /**
356
+ * Converts the trail to JSON representation.
357
+ *
358
+ * Used for serialization in JSON contexts. Returns the same
359
+ * as toString() method.
360
+ *
361
+ * @returns String representation of the trail
362
+ *
363
+ * @example
364
+ * ```typescript
365
+ * const trail = new StackTrail(['components', 'schemas', 'User']);
366
+ * const json = JSON.stringify({ path: trail });
367
+ * console.log(json); // '{"path":"components:schemas:User"}'
368
+ * ```
369
+ */
94
370
  toJSON() {
95
371
  return this.toString();
96
372
  }
373
+ /**
374
+ * Converts the trail to a colon-separated string representation.
375
+ *
376
+ * Colons within frame names are escaped as '%3A' to avoid conflicts
377
+ * with the separator character.
378
+ *
379
+ * @returns String representation of the trail
380
+ *
381
+ * @example
382
+ * ```typescript
383
+ * const trail = new StackTrail(['components', 'schemas', 'User']);
384
+ * console.log(trail.toString()); // 'components:schemas:User'
385
+ *
386
+ * // With colon in frame name
387
+ * const trailWithColon = new StackTrail(['components', 'schemas', 'User:Type']);
388
+ * console.log(trailWithColon.toString()); // 'components:schemas:User%3AType'
389
+ * ```
390
+ */
97
391
  toString() {
98
392
  return __classPrivateFieldGet(this, _StackTrail_stack, "f")
99
393
  .map(item => {
@@ -1,6 +1,74 @@
1
+ /**
2
+ * Type modifiers used throughout the SKMTC type system.
3
+ *
4
+ * `Modifiers` represent additional metadata and constraints that can be
5
+ * applied to type system values. These modifiers affect how types are
6
+ * generated and used in the target language output.
7
+ *
8
+ * @example Basic usage
9
+ * ```typescript
10
+ * import { Modifiers } from '@skmtc/core';
11
+ *
12
+ * const stringModifiers: Modifiers = {
13
+ * required: true,
14
+ * nullable: false,
15
+ * description: 'User email address'
16
+ * };
17
+ *
18
+ * const optionalModifiers: Modifiers = {
19
+ * required: false,
20
+ * nullable: true,
21
+ * description: 'Optional user profile image URL'
22
+ * };
23
+ * ```
24
+ *
25
+ * @example In type system values
26
+ * ```typescript
27
+ * const emailField: TypeSystemString = {
28
+ * type: 'string',
29
+ * format: 'email',
30
+ * enums: undefined,
31
+ * modifiers: {
32
+ * required: true,
33
+ * nullable: false,
34
+ * description: 'Valid email address for account registration'
35
+ * }
36
+ * };
37
+ *
38
+ * const optionalNote: TypeSystemString = {
39
+ * type: 'string',
40
+ * format: undefined,
41
+ * enums: undefined,
42
+ * modifiers: {
43
+ * required: false,
44
+ * nullable: true,
45
+ * description: 'Optional user note or comment'
46
+ * }
47
+ * };
48
+ * ```
49
+ *
50
+ * @example TypeScript generation
51
+ * ```typescript
52
+ * function generateTypeScript(type: TypeSystemValue): string {
53
+ * const baseType = generateBaseType(type);
54
+ * const optional = !type.modifiers.required ? '?' : '';
55
+ * const nullable = type.modifiers.nullable ? ' | null' : '';
56
+ *
57
+ * return `${baseType}${nullable}${optional}`;
58
+ * }
59
+ *
60
+ * // Required non-null string: 'string'
61
+ * // Optional non-null string: 'string?'
62
+ * // Required nullable string: 'string | null'
63
+ * // Optional nullable string: 'string | null?'
64
+ * ```
65
+ */
1
66
  export type Modifiers = {
67
+ /** Whether the field is required (affects optional markers in generated types) */
2
68
  required?: boolean;
69
+ /** Human-readable description of the field (used in documentation) */
3
70
  description?: string;
71
+ /** Whether the field can be null (affects null union types) */
4
72
  nullable?: boolean;
5
73
  };
6
74
  //# sourceMappingURL=Modifiers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Modifiers.d.ts","sourceRoot":"","sources":["../../src/types/Modifiers.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA"}
1
+ {"version":3,"file":"Modifiers.d.ts","sourceRoot":"","sources":["../../src/types/Modifiers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgEG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,kFAAkF;IAClF,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,sEAAsE;IACtE,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA"}