Metakit / @doeixd/metakit

Path

namespace · packages/metakit/src/path.ts:8

export * as Path from './path.js'

Typed, serializable paths into an environment (Path<Env, A>).

Every Path<Env, A> is also an Expr<Env, A> (they share the same carrier brand and node field), so paths drop straight into expressions while Transition.set requires a path from the transition's state accessor.

In the guides

Members

Path.accessor

function · packages/metakit/src/path.ts:438

function accessor<Env, A>(
  segments: ReadonlyArray<string>,
  ast: Option.Option<SchemaAST.AST>,
  element?: Element,
): PathAccessor<Env, A>

Build a PathAccessor<Env, A> rooted at segments from an Effect Schema AST so ({ row, principal }) => Num.lte(row.reserved, row.balance) yields typed Path values with their field ASTs attached. With element, every path reads that binder's element, and refuses to be used once its body has returned.

Path.AnyPath

type · packages/metakit/src/path.ts:43

type AnyPath = Path<never, unknown>

Path.compose

function · packages/metakit/src/path.ts:111

function compose<Outer, Mid, Inner>(
  outer: StatePath<Outer, Mid>,
  inner: Path<Mid, Inner>,
): StatePath<Outer, Inner>
function compose<Outer, Mid, Inner>(
  outer: Path<Outer, Mid>,
  inner: Path<Mid, Inner>,
): Path<Outer, Inner>

Compose Outer -> Mid with Mid -> Inner.

Path.declaredFields

function · packages/metakit/src/path.ts:388

function declaredFields(
  ast: Option.Option<SchemaAST.AST>,
): Option.Option<ReadonlySet<string>>

The names of the fields the Schema ast declares, where it is one struct (or an Option or nullable of one); none where it is not known to be.

Path.Element

interface · packages/metakit/src/path.ts:406

interface Element {
  readonly binder: Node.Binder
  readonly open: () => boolean
  readonly name: string
}

The element a body's accessor reads: its binder, whether the body is still being built, and who builds it.

Path.EnvOf

type · packages/metakit/src/path.ts:523

type EnvOf<Shape extends Readonly<Record<string, Schema.Top>>> = {
  readonly [K in keyof Shape]: Shape[K]['Type']
}

Map { k: Schema } to { readonly [K]: Schema['Type'] }.

Path.EVERY

const · packages/metakit/src/path.ts:219

const EVERY: '*'

The segment of a footprint that stands for every element of a list: todos.*.title.

Path.Expr

interface · packages/metakit/src/path.ts:22

interface Expr<in Env, out A> extends Pipeable.Pipeable {
  readonly [ExprTypeId]: {
    readonly env: (env: Env) => void
    readonly out: () => A
  }
  readonly node: Node.Node
}

Pure, terminating expression reading paths from Env and producing A. Env is contravariant (phantom) so an expression over { row } widens into { row, principal } without adapters.

Path.ExprTypeId

const · packages/metakit/src/path.ts:13

const ExprTypeId: unique symbol

Path.Field

interface · packages/metakit/src/path.ts:52

interface Field<E, K extends keyof E & string> extends Path<
  unknown,
  Read<E[K]>
> {
  readonly [FieldTypeId]: K
}

A path to field K of an element E, whose type holds the field's name: what a field selector such as each => each.sku returns. The name lives only in the type; at run time the path's one segment is the name.

Path.field

function · packages/metakit/src/path.ts:105

function field<Env extends object, K extends keyof Env & string>(
  key: K,
  ast?: Option.Option<SchemaAST.AST>,
): Path<Env, Env[K]>

Field path Env -> Env[K] for a direct property of Env.

Path.Fields

type · packages/metakit/src/path.ts:57

type Fields<E> = {
  readonly [
    K in Exclude<keyof E & string, keyof Path<unknown, unknown>>
  ]: Field<E, K>
}

One Field per key of E, one level deep: what a field selector is handed.

Path.forEnv

function · packages/metakit/src/path.ts:535

function forEnv<Shape extends Readonly<Record<string, Schema.Top>>>(
  shape: Shape,
): {
  readonly [K in keyof Shape & string]: PathAccessor<
    EnvOf<Shape>,
    Shape[K]['Type']
  >
}

Build the proxy record { row, principal, ... } for an Env shape.

Path.format

function · packages/metakit/src/path.ts:248

function format(segments: ReadonlyArray<string>): string

Dot-joined form of a path (e.g. "row.balance", or "$" for root), one text per path: a . or \ inside a segment is written \. or \\, and a segment that is $ alone is written \$, so the field "a.b" is a\.b and never the nested a.b. Readers that name a field by it (the solver's variables, a witness's keys) rely on that.

Path.forSchema

function · packages/metakit/src/path.ts:516

function forSchema<S extends Schema.Top>(
  schema: S,
): PathAccessor<S['Type'], S['Type']>

Build a PathAccessor for a single Schema's Type.

Path.from

function · packages/metakit/src/path.ts:516

function from<S extends Schema.Top>(
  schema: S,
): PathAccessor<S['Type'], S['Type']>

Build a PathAccessor for a single Schema's Type.

Path.get

function · packages/metakit/src/path.ts:139

function get<Env, A>(path: Path<Env, A>, env: Env): Option.Option<A>

Read the value at path from env, or Option.none() if any segment is missing. A path built from a Schema reads the logical value: through an Option to its value, or null for a none; a path made from raw segments reads storage, an Option included.

Path.isPath

function · packages/metakit/src/path.ts:547

function isPath(value: unknown): value is AnyPath

Path.isPrefix

function · packages/metakit/src/path.ts:229

function isPrefix(
  prefix: ReadonlyArray<string>,
  target: ReadonlyArray<string>,
): boolean

True when prefix is a segment prefix of target (useful for cache and surface invalidation). A * segment on either side matches any one segment, so todos.* is a prefix of todos.3.title and of todos.*.title.

Path.make

function · packages/metakit/src/path.ts:83

function make<Env, A>(
  segments: ReadonlyArray<string>,
  ast?: Option.Option<SchemaAST.AST>,
  bound?: Node.Binder,
): Path<Env, A>

Construct a Path from raw segments and an optional Schema AST; with bound, a read of that binder's element.

Path.meets

function · packages/metakit/src/path.ts:238

function meets(a: ReadonlyArray<string>, b: ReadonlyArray<string>): boolean

Whether two paths meet: one is a prefix of the other, * matching any one segment.

Path.of

function · packages/metakit/src/path.ts:513

function of<Env>(): PathAccessor<Env, Env>

Build a PathAccessor for any TypeScript type Env (e.g. Path.of<AppModel>().account).

Path.optionInner

function · packages/metakit/src/path.ts:303

function optionInner(ast: SchemaAST.AST): Option.Option<SchemaAST.AST>

The value's Schema, where ast declares an Effect Option (Schema.Option, Schema.OptionFromNullOr).

Path.Path

interface · packages/metakit/src/path.ts:33

interface Path<Env, A> extends Expr<Env, A> {
  readonly [PathTypeId]: {
    readonly env: (env: Env) => void
    readonly out: () => A
  }
  readonly node: Node.PathNode
  readonly segments: ReadonlyArray<string>
  readonly ast: Option.Option<SchemaAST.AST>
}

A typed lens into Env producing A. Subtype of Expr<Env, A>.

Path.PathAccessor

type · packages/metakit/src/path.ts:276

type PathAccessor<
  Env,
  A,
  Writable extends boolean = false,
> = (Writable extends true ? StatePath<Env, Read<A>> : Path<Env, Read<A>>) &
  AccessorFields<Env, Read<A>, Writable>

Recursive typed accessor for an environment value A: every plain object property (including TypeScript interfaces) becomes a nested PathAccessor<Env, A[K]>, and every level is itself a Path<Env, A>. An Option reads as its value or null, and a field under a value that may be null may be null too, as evaluation reads it.

A field named as a member of Path itself (node, segments, ast) is not reached by its name, which reads the member: compose it, Path.compose(parent, Path.field('segments')).

Path.PathTypeId

const · packages/metakit/src/path.ts:14

const PathTypeId: unique symbol

Path.Read

type · packages/metakit/src/path.ts:256

type Read<A> = [Exclude<A, undefined>] extends [Option.Option<infer T>]
  ? T | null
  : undefined extends A
    ? Exclude<A, undefined> | null
    : A

What a path reads: an Option reads as its value or null, and an absent/undefined field reads as null.

Path.readable

function · packages/metakit/src/path.ts:402

function readable(value: unknown): unknown

What evaluation reads of a held value: an Option's value, or null for none.

Path.reroot

function · packages/metakit/src/path.ts:418

function reroot<Env, A>(
  path: Path<Env, unknown>,
  ast: Option.Option<SchemaAST.AST>,
): PathAccessor<Env, A>

An accessor over ast at path's place, which reads the same element where path reads one, and refuses to be used when path would.

Path.root

function · packages/metakit/src/path.ts:101

function root<Env>(ast?: Option.Option<SchemaAST.AST>): Path<Env, Env>

The identity path Env -> Env.

Path.sameSegment

function · packages/metakit/src/path.ts:222

function sameSegment(a: string, b: string): boolean

Whether two segments can name one place: equal, or either stands for every element.

Path.SchemaOf

type · packages/metakit/src/path.ts:532

type SchemaOf = Schema.Top & Schema.ConstraintDecoder<unknown>

Constraint for a generic helper that both composes a Schema (Schema.Struct, Schema.Array, Expr.refine) and decodes it synchronously (Schema.decodeUnknownSync).

Path.Selector

type · packages/metakit/src/path.ts:62

type Selector<E, K extends keyof E & string> = (each: Fields<E>) => Field<E, K>

Picks field K of an element E: each => each.sku.

Path.set

function · packages/metakit/src/path.ts:168

function set<Env, A>(path: Path<Env, A>, env: Env, value: A): Env

Pure structural update at path inside env. Returns a new object along the updated spine; returns env untouched when the new value is Object.is equal to the existing one.

Path.StatePath

type · packages/metakit/src/path.ts:65

type StatePath<Env, A> = Path<Env, A> & {
  readonly [StatePathTypeId]: true
}

A path rooted in the state slice of a transition.