Skip to main content

Class: SpecPath

Defined in: packages/core/src/domain/value-objects/spec-path.ts:13

An immutable, validated path identifying a spec within the repository.

Paths are slash-separated sequences of segments (e.g. "auth/oauth"). Leading/trailing slashes and empty segments are normalized away. Segments must not be ., .., or contain reserved filesystem characters.

Use SpecPath.parse(string) or SpecPath.fromSegments(string[]) to construct.

Extends

Properties

_segments

protected readonly _segments: readonly string[]

Defined in: packages/core/src/domain/value-objects/domain-path.ts:35

The validated, non-empty sequence of path segments.

Inherited from

DomainPath._segments

Accessors

leaf

Get Signature

get leaf(): string

Defined in: packages/core/src/domain/value-objects/domain-path.ts:77

The last segment of the path (e.g. "oauth" for "auth/oauth").

Safe to call without null-check — subclasses guarantee non-empty segments.

Returns

string

Inherited from

DomainPath.leaf


parent

Get Signature

get parent(): this | null

Defined in: packages/core/src/domain/value-objects/domain-path.ts:89

The parent path, or null if this is a top-level (single-segment) path.

Returns the same concrete type as the receiver.

Example
`SpecPath.parse("auth/oauth").parent``SpecPath("auth")`
Returns

this | null

Inherited from

DomainPath.parent

Methods

_withSegments()

protected _withSegments(segments): this

Defined in: packages/core/src/domain/value-objects/spec-path.ts:31

Creates a new SpecPath from pre-validated segments without re-running validation.

Used by _withSegments to satisfy the DomainPath contract.

Parameters

segments

readonly string[]

Pre-validated, non-empty array of path segments

Returns

this

A new SpecPath wrapping the segments

Overrides

DomainPath._withSegments


child()

child(segment): this

Defined in: packages/core/src/domain/value-objects/spec-path.ts:93

Returns a new SpecPath with segment appended, running full validation on the resulting path.

Parameters

segment

string

The child segment to append

Returns

this

A new SpecPath one level deeper

Throws

If the segment is invalid

Overrides

DomainPath.child


equals()

equals(other): boolean

Defined in: packages/core/src/domain/value-objects/domain-path.ts:130

Returns whether this path is structurally equal to other.

Equality is determined by string representation.

Parameters

other

DomainPath

The path to compare against

Returns

boolean

true if both paths have the same string representation

Inherited from

DomainPath.equals


isAncestorOf()

isAncestorOf(other): boolean

Defined in: packages/core/src/domain/value-objects/domain-path.ts:117

Returns whether this path is a strict ancestor of other.

A path is an ancestor of other if other starts with all of this path's segments and has at least one additional segment.

Parameters

other

DomainPath

The path to test against

Returns

boolean

true if other starts with this path and has more segments

Inherited from

DomainPath.isAncestorOf


toFsPath()

toFsPath(sep): string

Defined in: packages/core/src/domain/value-objects/domain-path.ts:168

Returns a native filesystem path suitable for disk operations.

The caller provides the platform separator so the domain layer stays free of Node.js dependencies. Pass path.sep from node:path in infrastructure adapters — '/' on POSIX, '\\' on Windows.

Parameters

sep

string

The platform path separator to use between segments

Returns

string

The OS-native path string

Example

// In an infrastructure adapter:
import { sep, resolve } from 'node:path'
const fullPath = resolve(root, specPath.toFsPath(sep))
await fs.readFile(fullPath, 'utf8')

Inherited from

DomainPath.toFsPath


toString()

toString(): string

Defined in: packages/core/src/domain/value-objects/domain-path.ts:146

Returns the canonical slash-separated representation (e.g. "auth/oauth").

This is the domain identity of the path — always '/'-separated regardless of the host operating system. It is suitable for serialisation, display, and use as a map key, but NOT for filesystem operations on Windows.

Infrastructure adapters that need a native filesystem path must use toFsPath instead of this method.

Returns

string

The canonical path string

Inherited from

DomainPath.toString


fromSegments()

static fromSegments(segments): SpecPath

Defined in: packages/core/src/domain/value-objects/spec-path.ts:62

Creates a SpecPath directly from a pre-validated array of segments.

Parameters

segments

readonly string[]

Non-empty array of path segments

Returns

SpecPath

A SpecPath instance wrapping the given segments

Throws

If the segments array is empty or any segment is invalid


parse()

static parse(path): SpecPath

Defined in: packages/core/src/domain/value-objects/spec-path.ts:43

Parses and validates a slash-separated path string into a SpecPath.

Parameters

path

string

The path string to parse (e.g. "auth/oauth")

Returns

SpecPath

A validated SpecPath instance

Throws

If the path is empty, contains . or .. segments, or contains reserved characters (\, :, *, ?, ", <, >, |)