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