import { type Entry, type Json, type JsonStructure, type KeySet, type arrayIndexOf, type keySetOf, type listable, type requireKeys, type show } from "@ark/util"; import type { NodeConfig, ResolvedUnknownNodeConfig } from "../config.ts"; import type { Declaration, Inner, errorContext, nodeOfKind } from "../kinds.ts"; import type { BaseNode } from "../node.ts"; import type { NodeId, NodeParseContext } from "../parse.ts"; import type { BaseRoot, schemaKindOrRightOf, schemaKindRightOf } from "../roots/root.ts"; import type { BaseScope, ResolvedScopeConfig } from "../scope.ts"; import type { Structure } from "../structure/structure.ts"; import type { BaseErrorContext, BaseNodeDeclaration, BaseNormalizedSchema } from "./declare.ts"; import type { Disjoint } from "./disjoint.ts"; import { type makeRootAndArrayPropertiesMutable } from "./utils.ts"; export declare const basisKinds: readonly ["unit", "proto", "domain"]; export type BasisKind = (typeof basisKinds)[number]; export declare const structuralKinds: readonly ["required", "optional", "index", "sequence"]; export type StructuralKind = (typeof structuralKinds)[number]; export declare const prestructuralKinds: readonly ["pattern", "divisor", "exactLength", "max", "min", "maxLength", "minLength", "before", "after"]; export type PrestructuralKind = (typeof prestructuralKinds)[number]; export declare const refinementKinds: readonly ["pattern", "divisor", "exactLength", "max", "min", "maxLength", "minLength", "before", "after", "structure", "predicate"]; export type RefinementKind = (typeof refinementKinds)[number]; export declare const constraintKinds: readonly ["pattern", "divisor", "exactLength", "max", "min", "maxLength", "minLength", "before", "after", "structure", "predicate", "required", "optional", "index", "sequence"]; export type ConstraintKind = (typeof constraintKinds)[number]; export declare const rootKinds: readonly ["alias", "union", "morph", "unit", "intersection", "proto", "domain"]; export type RootKind = (typeof rootKinds)[number]; export type NodeKind = RootKind | ConstraintKind; type orderedNodeKinds = [...typeof rootKinds, ...typeof constraintKinds]; export declare const nodeKinds: orderedNodeKinds; export type OpenNodeKind = { [k in NodeKind]: Declaration["intersectionIsOpen"] extends true ? k : never; }[NodeKind]; export type ClosedNodeKind = Exclude; export type PrimitiveKind = Exclude; export type CompositeKind = Exclude; export type OrderedNodeKinds = typeof nodeKinds; export declare const constraintKeys: KeySet; export declare const structureKeys: keySetOf; type RightsByKind = accumulateRightKinds; export type kindOrRightOf = kind | kindRightOf; export type kindLeftOf = Exclude>; export type kindOrLeftOf = kind | kindLeftOf; type accumulateRightKinds = remaining extends (readonly [infer head extends NodeKind, ...infer tail extends NodeKind[]]) ? accumulateRightKinds : result; export interface InternalIntersectionOptions { pipe: boolean; } export interface IntersectionContext extends InternalIntersectionOptions { $: BaseScope; invert: boolean; } export type ConstraintIntersection> = (l: nodeOfKind, r: nodeOfKind, ctx: IntersectionContext) => BaseNode | Disjoint | null; export type ConstraintIntersectionMap = show<{ [_ in kind]: ConstraintIntersection; } & { [rKind in kindRightOf]?: ConstraintIntersection; }>; export type RootIntersection> = (l: nodeOfKind, r: nodeOfKind, ctx: IntersectionContext) => BaseRoot | Disjoint; export type TypeIntersectionMap = { [rKind in schemaKindOrRightOf]: RootIntersection; }; export type IntersectionMap = kind extends RootKind ? TypeIntersectionMap : ConstraintIntersectionMap; export type UnknownIntersectionMap = { [k in NodeKind]?: (l: BaseNode, r: BaseNode, ctx: IntersectionContext) => UnknownIntersectionResult; }; export type UnknownIntersectionResult = BaseNode | Disjoint | null; type PrecedenceByKind = { [i in arrayIndexOf as OrderedNodeKinds[i]]: i; }; export declare const precedenceByKind: PrecedenceByKind; export declare const isNodeKind: (value: unknown) => value is NodeKind; export declare function assertNodeKind(value: BaseNode, kind: kind): asserts value is nodeOfKind; export type precedenceOfKind = PrecedenceByKind[kind]; export declare const precedenceOfKind: (kind: kind) => precedenceOfKind; export type kindRightOf = RightsByKind[kind]; export declare const schemaKindsRightOf: (kind: kind) => schemaKindRightOf[]; export declare const unionChildKinds: readonly [...("intersection" | "morph" | "unit" | "proto" | "domain")[], "alias"]; export type UnionChildKind = (typeof unionChildKinds)[number]; export declare const morphChildKinds: readonly [...("intersection" | "unit" | "proto" | "domain")[], "alias"]; export type MorphChildKind = (typeof morphChildKinds)[number]; export type keySchemaDefinitions = { [k in keyRequiringSchemaDefinition]: NodeKeyImplementation; }; type keyRequiringSchemaDefinition = Exclude; export declare const defaultValueSerializer: (v: unknown) => Json; export type NodeKeyImplementation : never> = requireKeys<{ preserveUndefined?: true; child?: boolean | ((value: instantiated) => BaseNode[]); serialize?: (schema: instantiated) => Json; reduceIo?: (ioKind: "in" | "out", inner: makeRootAndArrayPropertiesMutable, value: d["inner"][k]) => void; parse?: (schema: Exclude, ctx: NodeParseContext) => instantiated | undefined; }, (d["normalizedSchema"][k] extends instantiated | undefined ? never : "parse") | ([instantiated] extends [listable] ? "child" : never)>; interface CommonNodeImplementationInput { kind: d["kind"]; keys: keySchemaDefinitions; normalize: (schema: d["schema"], $: BaseScope) => d["normalizedSchema"]; applyConfig?: (schema: d["normalizedSchema"], config: ResolvedScopeConfig) => d["normalizedSchema"]; hasAssociatedError: d["errorContext"] extends null ? false : true; finalizeInnerJson?: (json: { [k in keyof d["inner"]]: Json; }) => JsonStructure; collapsibleKey?: keyof d["inner"]; reduce?: (inner: d["inner"], $: BaseScope) => nodeOfKind | Disjoint | undefined; obviatesBasisDescription?: d["kind"] extends RefinementKind ? true : never; obviatesBasisExpression?: d["kind"] extends RefinementKind ? true : never; } export interface UnknownNodeImplementation extends CommonNodeImplementationInput { defaults: ResolvedUnknownNodeConfig; intersectionIsOpen: boolean; intersections: UnknownIntersectionMap; keys: Record>; } export declare const compileObjectLiteral: (ctx: object) => string; export type nodeImplementationOf = nodeImplementationInputOf & { intersections: IntersectionMap; intersectionIsOpen: d["intersectionIsOpen"]; defaults: Required>; }; export type nodeImplementationInputOf = CommonNodeImplementationInput & { intersections: IntersectionMap; defaults: nodeSchemaaultsImplementationInputFor; } & (d["intersectionIsOpen"] extends true ? { intersectionIsOpen: true; } : {}) & (d["reducibleTo"] extends d["kind"] ? {} : { reduce: {}; }); type nodeSchemaaultsImplementationInputFor = requireKeys, "description" | (Inner extends (Omit, keyof BaseErrorContext | "description">) ? never : "expected" & keyof NodeConfig)>; export type DescriptionWriter = (node: nodeOfKind) => string; export interface UnknownAttachments { readonly kind: NodeKind; readonly impl: UnknownNodeImplementation; readonly id: NodeId; readonly inner: Record; readonly innerEntries: readonly Entry[]; readonly innerJson: object; readonly innerHash: string; readonly meta: ArkEnv.meta; readonly metaJson: object; readonly json: object; readonly hash: string; readonly collapsibleJson: Json; readonly children: BaseNode[]; } export interface NarrowedAttachments extends UnknownAttachments { kind: d["kind"]; inner: d["inner"]; json: JsonStructure; innerJson: JsonStructure; collapsibleJson: Json; children: nodeOfKind[]; } export declare const implementNode: (_: nodeImplementationInputOf) => nodeImplementationOf; export {};