import { Callable, type GuardablePredicate, type JsonStructure, type Key, type array, type conform, type listable, type mutable, type requireKeys } from "@ark/util"; import type { BaseConstraint } from "./constraint.ts"; import type { Inner, NormalizedSchema, childKindOf, nodeOfKind, reducibleKindOf } from "./kinds.ts"; import type { BaseParseOptions } from "./parse.ts"; import type { Intersection } from "./roots/intersection.ts"; import type { Morph } from "./roots/morph.ts"; import type { BaseRoot } from "./roots/root.ts"; import type { Unit } from "./roots/unit.ts"; import type { BaseScope } from "./scope.ts"; import type { NodeCompiler } from "./shared/compile.ts"; import type { BaseNodeDeclaration, TypeMeta, attachmentsOf } from "./shared/declare.ts"; import type { ArkErrors } from "./shared/errors.ts"; import { type BasisKind, type NodeKind, type OpenNodeKind, type RefinementKind, type StructuralKind, type UnknownAttachments } from "./shared/implement.ts"; import { Traversal, type TraverseAllows, type TraverseApply } from "./shared/traversal.ts"; import type { UndeclaredKeyHandling } from "./structure/structure.ts"; export declare abstract class BaseNode< /** @ts-ignore allow instantiation assignment to the base type */ out d extends BaseNodeDeclaration = BaseNodeDeclaration> extends Callable<(data: d["prerequisite"], ctx?: Traversal, onFail?: ArkErrors.Handler | null) => unknown, attachmentsOf> { attachments: UnknownAttachments; $: BaseScope; onFail: ArkErrors.Handler | null; includesTransform: boolean; includesContextualPredicate: boolean; isCyclic: boolean; allowsRequiresContext: boolean; rootApplyStrategy: "allows" | "contextual" | "optimistic" | "branchedOptimistic"; contextFreeMorph: ((data: unknown) => unknown) | undefined; rootApply: (data: unknown, onFail: ArkErrors.Handler | null) => unknown; referencesById: Record; shallowReferences: BaseNode[]; flatRefs: FlatRef[]; flatMorphs: FlatRef[]; allows: (data: d["prerequisite"]) => boolean; get shallowMorphs(): array; constructor(attachments: UnknownAttachments, $: BaseScope); protected createRootApply(): this["rootApply"]; abstract traverseAllows: TraverseAllows; abstract traverseApply: TraverseApply; abstract expression: string; abstract compile(js: NodeCompiler): void; readonly compiledMeta: string; protected cacheGetter(name: name, value: this[name]): this[name]; get description(): string; get references(): BaseNode[]; readonly precedence: number; precompilation: string | undefined; assert: (data: d["prerequisite"], pipedFromCtx?: Traversal) => unknown; traverse(data: d["prerequisite"], pipedFromCtx?: Traversal): ArkErrors | {} | null | undefined; /** rawIn should be used internally instead */ get in(): unknown; get rawIn(): BaseNode; /** rawOut should be used internally instead */ get out(): unknown; get rawOut(): BaseNode; getIo(ioKind: "in" | "out"): BaseNode; toJSON(): JsonStructure; toString(): string; equals(r: unknown): boolean; ifEquals(r: unknown): BaseNode | undefined; hasKind(kind: kind): this is nodeOfKind; assertHasKind(kind: kind): nodeOfKind; hasKindIn(...kinds: kinds): this is nodeOfKind; assertHasKindIn(...kinds: kinds): nodeOfKind; isBasis(): this is nodeOfKind; isConstraint(): this is BaseConstraint; isStructural(): this is nodeOfKind; isRefinement(): this is nodeOfKind; isRoot(): this is BaseRoot; isUnknown(): boolean; isNever(): boolean; hasUnit(value: unknown): this is Unit.Node & { unit: value; }; hasOpenIntersection(): this is nodeOfKind; get nestableExpression(): string; select>>(selector: NodeSelector.validateComposite): NodeSelector.infer; select(selector: selector): NodeSelector.infer; private _select; transform(mapper: mapper, opts?: DeepNodeTransformOptions): nodeOfKind> | Extract, null>; protected _createTransformContext(opts: DeepNodeTransformOptions | undefined): DeepNodeTransformContext; protected _transform(mapper: DeepNodeTransformation, ctx: DeepNodeTransformContext): BaseNode | null; configureReferences(meta: TypeMeta.MappableInput.Internal, selector?: NodeSelector): this; } /** a literal key (named property) or a node (index signatures) representing part of a type structure */ export type KeyOrKeyNode = Key | BaseRoot; export type GettableKeyOrNode = KeyOrKeyNode | number; export type FlatRef = { path: array; node: root; propString: string; }; export type NodeSelector = NodeSelector.Single | NodeSelector.Composite; export declare namespace NodeSelector { type SelectableFn = { >>(input: input, selector?: NodeSelector.validateComposite): returns; (input: input, selector?: selector): returns; }; type Single = NodeSelector.Boundary | NodeSelector.Kind | GuardablePredicate; type Boundary = "self" | "child" | "shallow" | "references"; type Kind = NodeKind; type Method = "filter" | "assertFilter" | "find" | "assertFind"; interface Composite { method?: Method; boundary?: Boundary; kind?: Kind; where?: GuardablePredicate; } type Normalized = requireKeys; type CompositeInput = Omit; type BaseResult = BaseNode | BaseNode[] | undefined; type validateComposite = { [k in keyof selector]: k extends "where" ? predicate : conform; }; type infer = applyMethod ? narrowed : NodeSelector.inferSelectKind, selector>; type BoundaryInput = b | { boundary: b; }; type KindInput = k | { kind: k; }; type WhereCastInput = ((In: kindNode) => In is narrowed) | { where: (In: kindNode) => In is narrowed; }; type inferSelectKind = selectKind extends infer kind extends NodeKind ? NodeKind extends kind ? BaseNode : nodeOfKind : never; type selectKind = selector extends BoundaryInput<"self"> ? selfKind : selector extends KindInput ? kind : selector extends BoundaryInput<"child"> ? selfKind | childKindOf : NodeKind; type applyMethod = selector extends { method: infer method extends Method; } ? method extends "filter" ? t[] : method extends "assertFilter" ? [t, ...t[]] : method extends "find" ? t | undefined : method extends "assertFind" ? t : never : t[]; } export declare const typePathToPropString: (path: array) => string; export declare const flatRef: (path: array, node: node) => FlatRef; export declare const flatRefsAreEqual: (l: FlatRef, r: FlatRef) => boolean; export declare const appendUniqueFlatRefs: (existing: FlatRef[] | undefined, refs: listable>) => FlatRef[]; export declare const appendUniqueNodes: (existing: node[] | undefined, refs: listable) => node[]; export type DeepNodeTransformOptions = { shouldTransform?: ShouldTransformFn; bindScope?: BaseScope; prereduced?: boolean; selected?: readonly BaseNode[] | undefined; }; export type ShouldTransformFn = (node: BaseNode, ctx: DeepNodeTransformContext) => boolean; export interface DeepNodeTransformContext extends DeepNodeTransformOptions { root: BaseNode; selected: readonly BaseNode[] | undefined; path: mutable>; seen: { [originalId: string]: (() => BaseNode | undefined) | undefined; }; parseOptions: BaseParseOptions; undeclaredKeyHandling: UndeclaredKeyHandling | undefined; } export type DeepNodeTransformation = (kind: kind, innerWithMeta: Inner & { meta: ArkEnv.meta; }, ctx: DeepNodeTransformContext) => NormalizedSchema | null;