import type { merge, show } from "@ark/util"; import type { UnknownErrorConfigs } from "../config.ts"; import type { nodeOfKind, reducibleKindOf } from "../kinds.ts"; import type { Disjoint } from "./disjoint.ts"; import type { ArkErrors } from "./errors.ts"; import type { NarrowedAttachments, NodeKind } from "./implement.ts"; import type { JsonSchema } from "./jsonSchema.ts"; type withMetaPrefixedKeys = { [k in keyof o as k extends string ? `meta.${k}` : never]: o[k]; }; export interface DefaultArkEnv { meta(): {}; onFail(errors: ArkErrors): ArkErrors; } interface NodeMeta extends JsonSchema.UniversalMeta, UnknownErrorConfigs { alias?: string; onFail?: ArkErrors.Handler; } declare global { export interface ArkEnv extends DefaultArkEnv { } export namespace ArkEnv { type meta = show>; type onFail = ReturnType; } } export type TypeMeta = Omit; export declare namespace TypeMeta { type Collapsible = meta | string; type Mapper = (existing: Readonly) => meta; type MappableInput = Collapsible | Mapper; namespace MappableInput { type Internal = MappableInput; } } export interface BaseNormalizedSchema extends withMetaPrefixedKeys { readonly meta?: ArkEnv.meta | string; } interface DeclarationInput { kind: NodeKind; schema: unknown; normalizedSchema: BaseNormalizedSchema; inner: object; errorContext?: BaseErrorContext; reducibleTo?: NodeKind; intersectionIsOpen?: true; prerequisite?: unknown; childKind?: NodeKind; } export interface BaseErrorContext { readonly description?: string; readonly code: kind; readonly meta: ArkEnv.meta; } export type defaultErrorContext = show & d["inner"]>; export type declareNode = merge<{ intersectionIsOpen: false; prerequisite: prerequisiteOf; childKind: never; reducibleTo: d["kind"]; errorContext: null; }, d>; type prerequisiteOf = "prerequisite" extends keyof d ? d["prerequisite"] : unknown; export type attachmentsOf = NarrowedAttachments & attachedInner; type attachedInner = "intersection" & d["kind"] extends never ? d["inner"] : {}; export interface BaseNodeDeclaration { kind: NodeKind; schema: unknown; normalizedSchema: BaseNormalizedSchema; inner: {}; reducibleTo: NodeKind; prerequisite: any; intersectionIsOpen: boolean; childKind: NodeKind; errorContext: BaseErrorContext | null; } export type ownIntersectionResult = nodeOfKind> | Disjoint; export {};