Docs@skmtc/core

OpenAPI document

CLASS

StackTrail

@skmtc/core 0.63.4

A position in a run, as a list of frames from the outermost to the innermost. While the parser reads a schema, they can be components, schemas and User. toString joins them: components:schemas:User.

append and remove change the trail. To keep a position, use clone. To add frames only while a function runs, use trace, which gives the function its own trail.

Signature

import { StackTrail } from '@skmtc/core'

class StackTrail

Constructor

constructor

constructor(stack?: readonly string[])

Properties

stackTrail, readonly string[]

The frames of the trail as a new read-only array, built on each read. Change the trail with append, remove or trace, not through this array. The trail itself is live: trace removes its frame after fn returns, so read the frames inside fn to keep them.

Methods

StackTrail.empty

StackTrail.empty(): StackTrail

The canonical empty trail - used for nodes that were synthesized programmatically rather than parsed from a source document (they have no position). Distinct from any parsed position: no parsed OasBase node ever sits at the empty trail.

isEmpty

isEmpty(): boolean

True when the trail holds no frames (a synthetic / positionless node).

clone

clone(): StackTrail

Creates an independent trail with the same frames. The frames are shared, not copied.

Returns

A new StackTrail instance with the same frames

append

append(frame: string | string[]): StackTrail

Appends frame(s) to the end of the trail.

frame

Single frame string or array of frames to append

Returns

This StackTrail instance for chaining

Throws
Error

When frame is not a string or string array

trace

trace<T>(key: string | string[], fn: (st: StackTrail) => T): T

Runs fn on a copy of the trail with key appended: one frame for a string, one frame per element for an array.

When fn returns, key is removed and must be the last frame. When fn throws, the copy goes back to the frames it started with and the error from fn is rethrown: a frame check there would replace it.

traceAsync

traceAsync<T>(
  key: string | string[],
  fn: (st: StackTrail) => Promise<T>
): Promise<T>

Async form of trace.

toJsonPointer

toJsonPointer(): JsonPointer

Converts the trail to an RFC 6901 JSON Pointer (URI fragment form).

Unlike toStackRef, this works for any visitor path - not just components-rooted references. Used by the gen-maps system to attach a location field to every parsed OAS schema, recording exactly where in the document the schema lives.

Special characters in stack frames (/, ~) are escaped per RFC 6901.

Returns

A JSON Pointer string starting with #/

toSchemaPointer

toSchemaPointer(): JsonPointer

The document-relative JSON Pointer for a parsed node, with the run's operational prefix stripped - the resolvable form used as a schema pointer in gen-maps.

A parsed node's trail is seeded with operational frames before any document traversal: the worker pushes [traceId, spanId] and CoreContext.toArtifacts wraps each phase in .trace('parse', …) / .trace('generate', …) etc. The document path (components/schemas/Pet/properties/name) is appended on top. Unlike toJsonPointer - which serializes the whole trail and so does NOT resolve against the input document - this drops everything up to and including the phase frame, leaving only the document-relative path.

The remaining frames are the input document's own keys (components, paths, …), never an oas: scheme.

Falls back to the full trail when no phase frame is present (a trail seeded empty - e.g. in tests - is already document-relative). Returns #/ (document root) for the empty trail.

toStackRef

toStackRef(): string | undefined

remove

remove(frame: string | string[]): StackTrail

Removes frame(s) from the end of the trail.

frame

Single frame string or array of frames to remove

Returns

This StackTrail instance for chaining

Throws
Error

When trying to remove a frame that doesn't match the last frame

Throws
Error

When frame is not a string or string array

toJSON

toJSON(): string

Converts the trail to JSON representation.

Used for serialization in JSON contexts. Returns the same as toString() method.

Returns

String representation of the trail

toString

toString(): string

Converts the trail to a colon-separated string.

Inside a frame, % is escaped as %25 and : as %3A, so StackTrail.fromString reads the same frames back.

StackTrail.fromString

StackTrail.fromString(value: string): StackTrail

Reads a string written by StackTrail.toString back into a trail.

Splits on : and decodes %25 and %3A in each frame. The empty string gives the empty trail, so a trail of one empty frame is the one trail that does not round-trip.