@ark/schema
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -1,3 +0,5 @@ | ||
import type { anyOrNever, array, BuiltinObjectKind, BuiltinObjects, conform, equals, leftIfEqual, Primitive, show } from "@ark/util"; | ||
import type { anyOrNever, array, BuiltinObjectKind, BuiltinObjects, conform, equals, leftIfEqual, Primitive, propValueOf, show } from "@ark/util"; | ||
import type { PrimitiveConstraintKind } from "./constraint.js"; | ||
import type { platformObjectExports } from "./keywords/platformObjects.js"; | ||
import type { typedArrayExports } from "./keywords/typedArray.js"; | ||
import type { NodeSchema } from "./kinds.js"; | ||
@@ -177,3 +179,3 @@ import type { constraintKindOf } from "./roots/intersection.js"; | ||
infer constraints extends Constraints | ||
]) ? distilledKind extends "base" ? _distill<base, io, distilledKind> : of<_distill<base, io, distilledKind>, constraints> : t extends TerminallyInferredObjectKind | ArkEnv.preserve | Primitive ? t : unknown extends t ? unknown : t extends MorphAst<infer i, infer o> ? io extends "in" ? _distill<i, io, distilledKind> : _distill<o, io, distilledKind> : t extends DefaultableAst<infer t> ? _distill<t, io, distilledKind> : t extends array ? distillArray<t, io, distilledKind, []> : t extends Function ? t : { | ||
]) ? distilledKind extends "base" ? _distill<base, io, distilledKind> : of<_distill<base, io, distilledKind>, constraints> : t extends TerminallyInferredObjectKind | Primitive ? t : unknown extends t ? unknown : t extends MorphAst<infer i, infer o> ? io extends "in" ? _distill<i, io, distilledKind> : _distill<o, io, distilledKind> : t extends DefaultableAst<infer t> ? _distill<t, io, distilledKind> : t extends array ? distillArray<t, io, distilledKind, []> : t extends Function ? t : { | ||
[k in keyof t]: t[k]; | ||
@@ -201,3 +203,3 @@ } extends t ? io extends "in" ? show<{ | ||
/** Objects we don't want to expand during inference like Date or Promise */ | ||
type TerminallyInferredObjectKind = ArkEnv.preserve | BuiltinObjects[Exclude<BuiltinObjectKind, "Array" | "Function">]; | ||
type TerminallyInferredObjectKind = ArkEnv.preserve | BuiltinObjects[Exclude<BuiltinObjectKind, "Array" | "Function">] | propValueOf<platformObjectExports> | propValueOf<typedArrayExports>; | ||
export {}; |
@@ -1,4 +0,4 @@ | ||
import type { mutable, requireKeys, show } from "@ark/util"; | ||
import { type mutable, type requireKeys, type show } from "@ark/util"; | ||
import type { Ark } from "./keywords/keywords.js"; | ||
import type { IntrinsicKeywords, RawRootScope } from "./scope.js"; | ||
import type { InternalBaseScope, IntrinsicKeywords } from "./scope.js"; | ||
import type { ActualWriter, ArkErrorCode, ExpectedWriter, MessageWriter, ProblemWriter } from "./shared/errors.js"; | ||
@@ -12,3 +12,3 @@ import { type DescriptionWriter, type NodeKind } from "./shared/implement.js"; | ||
registry(): { | ||
ambient: RawRootScope; | ||
ambient: InternalBaseScope; | ||
intrinsic: IntrinsicKeywords; | ||
@@ -15,0 +15,0 @@ config: ArkConfig; |
@@ -0,1 +1,2 @@ | ||
import { $ark } from "@ark/util"; | ||
import { isNodeKind } from "./shared/implement.js"; | ||
@@ -2,0 +3,0 @@ $ark.config = {}; |
@@ -6,5 +6,5 @@ import { type array, type describe, type listable, type satisfy } from "@ark/util"; | ||
import type { IntersectionInner, MutableIntersectionInner } from "./roots/intersection.js"; | ||
import type { BaseRoot, Root, UnknownRoot } from "./roots/root.js"; | ||
import type { BaseRoot, SchemaRoot, UnknownRoot } from "./roots/root.js"; | ||
import type { NodeCompiler } from "./shared/compile.js"; | ||
import type { RawNodeDeclaration } from "./shared/declare.js"; | ||
import type { BaseNodeDeclaration } from "./shared/declare.js"; | ||
import { Disjoint } from "./shared/disjoint.js"; | ||
@@ -14,3 +14,3 @@ import { type ConstraintKind, type IntersectionContext, type NodeKind, type RootKind, type StructuralKind, type kindLeftOf } from "./shared/implement.js"; | ||
import { arkKind } from "./shared/utils.js"; | ||
export interface BaseConstraintDeclaration extends RawNodeDeclaration { | ||
export interface BaseConstraintDeclaration extends BaseNodeDeclaration { | ||
kind: ConstraintKind; | ||
@@ -28,3 +28,3 @@ } | ||
export type ConstraintReductionResult = BaseRoot | Disjoint | MutableIntersectionInner; | ||
export declare abstract class RawPrimitiveConstraint<d extends BaseConstraintDeclaration> extends BaseConstraint<d> { | ||
export declare abstract class InternalPrimitiveConstraint<d extends BaseConstraintDeclaration> extends BaseConstraint<d> { | ||
abstract traverseAllows: TraverseAllows<d["prerequisite"]>; | ||
@@ -54,5 +54,5 @@ abstract readonly compiledCondition: string; | ||
export type intersectConstraintKinds<l extends ConstraintKind, r extends ConstraintKind> = Node<l | r | "unit" | "union"> | Disjoint | null; | ||
export declare const throwInvalidOperandError: (kind: "pattern" | "divisor" | "exactLength" | "max" | "min" | "maxLength" | "minLength" | "before" | "after" | "required" | "optional" | "index" | "sequence" | "structure" | "predicate", expected: Root<unknown, any>, actual: Root<unknown, any>) => never; | ||
export declare const writeInvalidOperandMessage: <kind extends ConstraintKind, expected extends Root, actual extends Root>(kind: kind, expected: expected, actual: actual) => writeInvalidOperandMessage<kind, actual>; | ||
export type writeInvalidOperandMessage<kind extends ConstraintKind, actual extends Root> = `${Capitalize<kind>} operand must be ${describe<Prerequisite<kind>>} (was ${describe<Exclude<actual["infer"], Prerequisite<kind>>>})`; | ||
export declare const throwInvalidOperandError: (kind: "pattern" | "divisor" | "exactLength" | "max" | "min" | "maxLength" | "minLength" | "before" | "after" | "required" | "optional" | "index" | "sequence" | "structure" | "predicate", expected: SchemaRoot<unknown, any>, actual: SchemaRoot<unknown, any>) => never; | ||
export declare const writeInvalidOperandMessage: <kind extends ConstraintKind, expected extends SchemaRoot, actual extends SchemaRoot>(kind: kind, expected: expected, actual: actual) => never; | ||
export type writeInvalidOperandMessage<kind extends ConstraintKind, actual extends SchemaRoot> = `${Capitalize<kind>} operand must be ${describe<Prerequisite<kind>>} (was ${describe<Exclude<actual["infer"], Prerequisite<kind>>>})`; | ||
export interface ConstraintAttachments { | ||
@@ -59,0 +59,0 @@ impliedBasis: UnknownRoot | null; |
@@ -1,2 +0,2 @@ | ||
import { append, appendUnique, capitalize, isArray, throwInternalError, throwParseError } from "@ark/util"; | ||
import { $ark, append, appendUnique, capitalize, isArray, throwInternalError, throwParseError } from "@ark/util"; | ||
import { BaseNode } from "./node.js"; | ||
@@ -14,3 +14,3 @@ import { Disjoint } from "./shared/disjoint.js"; | ||
} | ||
export class RawPrimitiveConstraint extends BaseConstraint { | ||
export class InternalPrimitiveConstraint extends BaseConstraint { | ||
traverseApply = (data, ctx) => { | ||
@@ -17,0 +17,0 @@ if (!this.traverseAllows(data, ctx)) |
@@ -1,17 +0,18 @@ | ||
import { Callable, type array, type thunkable } from "@ark/util"; | ||
import { Callable, type array, type Hkt, type Json } from "@ark/util"; | ||
import type { inferRoot } from "./inference.js"; | ||
import type { RootSchema } from "./kinds.js"; | ||
import type { Root, UnknownRoot } from "./roots/root.js"; | ||
import type { RawRootScope, RootScope } from "./scope.js"; | ||
import type { SchemaRoot, UnknownRoot } from "./roots/root.js"; | ||
import type { BaseScope, InternalBaseScope } from "./scope.js"; | ||
import { arkKind } from "./shared/utils.js"; | ||
export type GenericParamAst<name extends string = string, constraint = unknown> = readonly [name: name, constraint: constraint]; | ||
export type GenericParamAst<name extends string = string, constraint = unknown> = [name: name, constraint: constraint]; | ||
export type GenericParamDef<name extends string = string> = name | ConstrainedGenericParamDef; | ||
export type ConstrainedGenericParamDef<name extends string = string> = GenericParamAst<name>; | ||
export declare const parseGeneric: (paramDefs: array<GenericParamDef>, bodyDef: unknown, $: thunkable<RootScope>) => GenericRoot; | ||
type genericParamSchemaToAst<schema extends GenericParamDef, $> = schema extends string ? GenericParamAst<schema> : schema extends ConstrainedGenericParamDef ? GenericParamAst<schema[0], inferRoot<schema[1], $>> : never; | ||
export type genericParamSchemasToAst<schemas extends array<GenericParamDef>, $> = readonly [ | ||
...{ | ||
[i in keyof schemas]: genericParamSchemaToAst<schemas[i], $>; | ||
} | ||
]; | ||
export declare const parseGeneric: (paramDefs: array<GenericParamDef>, bodyDef: unknown, $: BaseScope) => GenericRoot; | ||
type genericParamSchemaToAst<schema extends GenericParamDef, $> = schema extends string ? GenericParamAst<schema> : schema extends ConstrainedGenericParamDef ? [ | ||
schema[0], | ||
inferRoot<schema[1], $> | ||
] : never; | ||
export type genericParamSchemasToAst<schemas extends array<GenericParamDef>, $> = [...{ | ||
[i in keyof schemas]: genericParamSchemaToAst<schemas[i], $>; | ||
}]; | ||
export type genericParamAstToDefs<asts extends array<GenericParamAst>> = { | ||
@@ -29,5 +30,5 @@ [i in keyof asts]: GenericParamDef<asts[i][0]>; | ||
}; | ||
export type GenericNodeSignature<params extends array<GenericParamAst>, def, $> = <args extends instantiateConstraintsOf<params>>(...args: args) => Root<inferRoot<def, $ & bindGenericNodeInstantiation<params, $, args>>>; | ||
export type GenericRootInstantiator<params extends array<GenericParamAst>, def, $> = <args extends instantiateConstraintsOf<params>>(...args: args) => SchemaRoot<inferRoot<def, $ & bindGenericNodeInstantiation<params, $, args>>>; | ||
type instantiateConstraintsOf<params extends array<GenericParamAst>> = { | ||
[i in keyof params]: Root<params[i][1]>; | ||
[i in keyof params]: SchemaRoot<params[i][1]>; | ||
}; | ||
@@ -40,2 +41,3 @@ export type GenericParam<name extends string = string, constraint = unknown> = readonly [name: name, constraint: UnknownRoot<constraint>]; | ||
[arkKind]: "generic"; | ||
paramsAst: params; | ||
params: instantiateParams<params>; | ||
@@ -45,30 +47,36 @@ names: genericParamNames<params>; | ||
bodyDef: bodyDef; | ||
$: RootScope<$>; | ||
$: BaseScope<$>; | ||
} | ||
export type GenericArgResolutions<params extends array<GenericParamAst> = array<GenericParamAst>> = { | ||
[i in keyof params as params[i & `${number}`][0]]: UnknownRoot<params[i & `${number}`][1]>; | ||
[i in keyof params as params[i & `${number}`][0]]: SchemaRoot<params[i & `${number}`][1]>; | ||
}; | ||
export type LazyGenericSchema<params extends array<GenericParamAst> = array<GenericParamAst>, returns extends RootSchema = RootSchema> = (args: GenericArgResolutions<params>) => returns; | ||
export declare class LazyGenericRoot<params extends array<GenericParamAst> = array<GenericParamAst>> extends Callable<LazyGenericSchema<params>> { | ||
export declare class LazyGenericBody<params extends array<GenericParamAst> = array<GenericParamAst>, returns = unknown> extends Callable<(args: GenericArgResolutions<params>) => returns> { | ||
} | ||
export declare class GenericRoot<params extends array<GenericParamAst> = array<GenericParamAst>, bodyDef = any, $ = any> extends Callable<GenericNodeSignature<params, bodyDef, $>> implements GenericProps { | ||
export declare class GenericRoot<params extends array<GenericParamAst> = array<GenericParamAst>, bodyDef = unknown, $ = {}, arg$ = $> extends Callable<GenericRootInstantiator<params, bodyDef, $>> { | ||
paramDefs: genericParamAstToDefs<params>; | ||
bodyDef: bodyDef; | ||
private _$; | ||
private _arg$; | ||
$: BaseScope<$>; | ||
arg$: BaseScope<arg$>; | ||
readonly [arkKind] = "generic"; | ||
constructor(paramDefs: genericParamAstToDefs<params>, bodyDef: bodyDef, _$: thunkable<RootScope<$>>, _arg$: thunkable<RootScope<$>>); | ||
get $(): RootScope<$>; | ||
get arg$(): RootScope<$>; | ||
bindScope($: RawRootScope): this; | ||
readonly paramsAst: params; | ||
constructor(paramDefs: genericParamAstToDefs<params>, bodyDef: bodyDef, $: BaseScope<$>, arg$: BaseScope<arg$>); | ||
defIsLazy(): this is GenericRoot<params, LazyGenericBody, $, arg$>; | ||
bindScope($: InternalBaseScope): this; | ||
get json(): Json; | ||
get params(): instantiateParams<params>; | ||
get names(): genericParamNames<params>; | ||
get constraints(): instantiateConstraintsOf<params>; | ||
get baseInstantiation(): Root; | ||
get baseInstantiation(): SchemaRoot; | ||
validateBaseInstantiation(): this; | ||
get internal(): this; | ||
get references(): import("./node.js").BaseNode<import("./index.js").RawNodeDeclaration>[]; | ||
get references(): import("./node.js").BaseNode<import("./index.js").BaseNodeDeclaration>[]; | ||
} | ||
export type GenericHktSchemaParser<$ = {}> = <const paramsDef extends array<GenericParamDef>>(...params: paramsDef) => (instantiateDef: LazyGenericBody<genericParamSchemasToAst<paramsDef, $>, RootSchema>) => GenericHktRootSubclass<genericParamSchemasToAst<paramsDef, $>, $>; | ||
export type GenericHktRootSubclass<params extends array<GenericParamAst>, $> = abstract new () => GenericHktRoot<params, $, $>; | ||
interface Hkt extends Hkt.Kind { | ||
} | ||
export interface GenericHktRoot<params extends array<GenericParamAst>, $, args$> extends GenericRoot<params, Hkt, $, args$>, Hkt.Kind { | ||
} | ||
export declare const writeUnsatisfiedParameterConstraintMessage: <name extends string, constraint extends string, arg extends string>(name: name, constraint: constraint, arg: arg) => writeUnsatisfiedParameterConstraintMessage<name, constraint, arg>; | ||
export type writeUnsatisfiedParameterConstraintMessage<name extends string, constraint extends string, arg extends string> = `${name} must be assignable to ${constraint} (was ${arg})`; | ||
export {}; |
@@ -35,6 +35,6 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) { | ||
}; | ||
import { Callable, cached, flatMorph, isThunk, throwParseError } from "@ark/util"; | ||
import { $ark, cached, Callable, flatMorph, snapshot, throwParseError } from "@ark/util"; | ||
import { arkKind } from "./shared/utils.js"; | ||
export const parseGeneric = (paramDefs, bodyDef, $) => new GenericRoot(paramDefs, bodyDef, $, $); | ||
export class LazyGenericRoot extends Callable { | ||
export class LazyGenericBody extends Callable { | ||
} | ||
@@ -44,2 +44,3 @@ let GenericRoot = (() => { | ||
let _instanceExtraInitializers = []; | ||
let _get_json_decorators; | ||
let _get_params_decorators; | ||
@@ -52,2 +53,3 @@ let _get_names_decorators; | ||
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0; | ||
_get_json_decorators = [cached]; | ||
_get_params_decorators = [cached]; | ||
@@ -57,2 +59,3 @@ _get_names_decorators = [cached]; | ||
_get_baseInstantiation_decorators = [cached]; | ||
__esDecorate(this, null, _get_json_decorators, { kind: "getter", name: "json", static: false, private: false, access: { has: obj => "json" in obj, get: obj => obj.json }, metadata: _metadata }, null, _instanceExtraInitializers); | ||
__esDecorate(this, null, _get_params_decorators, { kind: "getter", name: "params", static: false, private: false, access: { has: obj => "params" in obj, get: obj => obj.params }, metadata: _metadata }, null, _instanceExtraInitializers); | ||
@@ -66,6 +69,6 @@ __esDecorate(this, null, _get_names_decorators, { kind: "getter", name: "names", static: false, private: false, access: { has: obj => "names" in obj, get: obj => obj.names }, metadata: _metadata }, null, _instanceExtraInitializers); | ||
bodyDef; | ||
_$; | ||
_arg$; | ||
$; | ||
arg$; | ||
[arkKind] = "generic"; | ||
constructor(paramDefs, bodyDef, _$, _arg$) { | ||
constructor(paramDefs, bodyDef, $, arg$) { | ||
super((...args) => { | ||
@@ -79,4 +82,6 @@ const argNodes = flatMorph(this.names, (i, name) => { | ||
}); | ||
if (bodyDef instanceof LazyGenericRoot) | ||
return this.$.parseRoot(bodyDef(argNodes)); | ||
if (this.defIsLazy()) { | ||
const def = this.bodyDef(argNodes); | ||
return this.$.parseRoot(def); | ||
} | ||
return this.$.parseRoot(bodyDef, { args: argNodes }); | ||
@@ -86,16 +91,9 @@ }); | ||
this.bodyDef = bodyDef; | ||
this._$ = _$; | ||
this._arg$ = _arg$; | ||
// if this is a standalone generic, validate its base constraints right away | ||
if (!isThunk(this._$)) | ||
this.validateBaseInstantiation(); | ||
// if it's part of a scope, scope.export will be resposible for invoking | ||
// validateBaseInstantiation on export() once everything is resolvable | ||
this.$ = $; | ||
this.arg$ = arg$; | ||
this.validateBaseInstantiation(); | ||
} | ||
get $() { | ||
return isThunk(this._$) ? this._$() : this._$; | ||
defIsLazy() { | ||
return this.bodyDef instanceof LazyGenericBody; | ||
} | ||
get arg$() { | ||
return isThunk(this._arg$) ? this._arg$() : this._arg$; | ||
} | ||
bindScope($) { | ||
@@ -106,2 +104,8 @@ if (this.arg$ === $) | ||
} | ||
get json() { | ||
return { | ||
params: this.params.map(param => param[1].isUnknown() ? param[0] : [param[0], param[1].json]), | ||
body: snapshot(this.bodyDef) | ||
}; | ||
} | ||
get params() { | ||
@@ -108,0 +112,0 @@ return this.paramDefs.map((param) => typeof param === "string" ? |
@@ -35,2 +35,3 @@ export * from "./ast.js"; | ||
export * from "./scope.js"; | ||
export * from "./shared/compile.js"; | ||
export * from "./shared/declare.js"; | ||
@@ -41,2 +42,3 @@ export * from "./shared/disjoint.js"; | ||
export * from "./shared/intersections.js"; | ||
export * from "./shared/registry.js"; | ||
export * from "./shared/utils.js"; | ||
@@ -43,0 +45,0 @@ export * from "./structure/indexed.js"; |
@@ -35,2 +35,3 @@ export * from "./ast.js"; | ||
export * from "./scope.js"; | ||
export * from "./shared/compile.js"; | ||
export * from "./shared/declare.js"; | ||
@@ -41,2 +42,3 @@ export * from "./shared/disjoint.js"; | ||
export * from "./shared/intersections.js"; | ||
export * from "./shared/registry.js"; | ||
export * from "./shared/utils.js"; | ||
@@ -43,0 +45,0 @@ export * from "./structure/indexed.js"; |
@@ -10,12 +10,8 @@ import type { Constructor, ErrorMessage, NonEnumerableDomain, array, conform, inferDomain, instanceOf, isAny, typeToString } from "@ark/util"; | ||
import type { UnitSchema } from "./roots/unit.js"; | ||
import type { ArkErrors } from "./shared/errors.js"; | ||
import type { BasisKind, ConstraintKind } from "./shared/implement.js"; | ||
import type { inferred } from "./shared/utils.js"; | ||
export declare namespace type { | ||
type cast<t> = { | ||
[inferred]?: t; | ||
}; | ||
type errors = ArkErrors; | ||
} | ||
export type validateRoot<schema, $> = schema extends type.cast<unknown> ? schema : schema extends array ? { | ||
export type InferredRoot<t = unknown> = { | ||
[inferred]?: t; | ||
}; | ||
export type validateRoot<schema, $> = schema extends InferredRoot ? schema : schema extends array ? { | ||
[i in keyof schema]: validateRootBranch<schema[i], $>; | ||
@@ -27,5 +23,5 @@ } : schema extends NormalizedUnionSchema<infer branches> ? conform<schema, NormalizedUnionSchema & { | ||
}> : validateRootBranch<schema, $>; | ||
export type inferRoot<schema, $> = schema extends type.cast<infer to> ? to : schema extends UnionSchema<infer branches> ? branches["length"] extends 0 ? never : branches["length"] extends 1 ? inferRootBranch<branches[0], $> : inferRootBranch<branches[number], $> : inferRootBranch<schema, $>; | ||
export type inferRoot<schema, $> = schema extends InferredRoot<infer to> ? to : schema extends UnionSchema<infer branches> ? branches["length"] extends 0 ? never : branches["length"] extends 1 ? inferRootBranch<branches[0], $> : inferRootBranch<branches[number], $> : inferRootBranch<schema, $>; | ||
type validateRootBranch<schema, $> = schema extends BaseNode ? schema : "morphs" extends keyof schema ? validateMorphRoot<schema, $> : validateMorphChild<schema, $>; | ||
type inferRootBranch<schema, $> = schema extends type.cast<infer to> ? to : schema extends MorphSchema ? (In: schema["in"] extends {} ? inferMorphChild<schema["in"], $> : unknown) => schema["morphs"] extends infer morph extends Morph ? Out<inferMorphOut<morph>> : schema["morphs"] extends (readonly [...unknown[], infer morph extends Morph]) ? Out<inferMorphOut<morph>> : never : schema extends MorphChildSchema ? inferMorphChild<schema, $> : unknown; | ||
type inferRootBranch<schema, $> = schema extends InferredRoot<infer to> ? to : schema extends MorphSchema ? (In: schema["in"] extends {} ? inferMorphChild<schema["in"], $> : unknown) => schema["morphs"] extends infer morph extends Morph ? Out<inferMorphOut<morph>> : schema["morphs"] extends (readonly [...unknown[], infer morph extends Morph]) ? Out<inferMorphOut<morph>> : never : schema extends MorphChildSchema ? inferMorphChild<schema, $> : unknown; | ||
type NonIntersectableBasisRoot = NonEnumerableDomain | Constructor | UnitSchema; | ||
@@ -32,0 +28,0 @@ type validateMorphChild<schema, $> = [ |
import type { SchemaModule } from "../module.js"; | ||
export interface jsObjectExports { | ||
Array: Array<unknown>; | ||
Function: Function; | ||
Date: Date; | ||
Error: Error; | ||
Function: Function; | ||
Map: Map<unknown, unknown>; | ||
@@ -8,0 +8,0 @@ RegExp: RegExp; |
import { schemaScope } from "../scope.js"; | ||
export const jsObjects = schemaScope({ | ||
Array, | ||
Function, | ||
Date, | ||
Error, | ||
Function, | ||
Map, | ||
@@ -8,0 +8,0 @@ RegExp, |
import type { RootModule, SchemaModule } from "../module.js"; | ||
import { type RootScope } from "../scope.js"; | ||
import { type BaseScope } from "../scope.js"; | ||
import { type tsKeywordExports } from "./tsKeywords.js"; | ||
@@ -8,9 +8,12 @@ import { type formattingExports } from "./format.js"; | ||
import { type parsingExports } from "./parsing.js"; | ||
import { type platformObjectExports } from "./platformObjects.js"; | ||
import { type tsGenericsExports } from "./tsGenerics.js"; | ||
import { type typedArrayExports } from "./typedArray.js"; | ||
import { type validationExports } from "./validation.js"; | ||
export declare const ambientRootScope: RootScope<Ark>; | ||
export declare const ambientRootScope: BaseScope<Ark>; | ||
export declare const keywordNodes: SchemaModule<Ark>; | ||
export interface Ark extends tsKeywordExports, jsObjectExports, validationExports, tsGenericsExports, internalExports { | ||
export interface Ark extends tsKeywordExports, jsObjectExports, platformObjectExports, validationExports, tsGenericsExports, internalExports { | ||
TypedArray: RootModule<typedArrayExports>; | ||
parse: RootModule<parsingExports>; | ||
format: RootModule<formattingExports>; | ||
} |
@@ -5,2 +5,3 @@ import { schemaScope } from "../scope.js"; | ||
import { tsKeywords } from "./tsKeywords.js"; | ||
import { $ark } from "@ark/util"; | ||
import { formatting } from "./format.js"; | ||
@@ -10,3 +11,5 @@ import { internal } from "./internal.js"; | ||
import { parsing } from "./parsing.js"; | ||
import { platformObjects } from "./platformObjects.js"; | ||
import { tsGenerics } from "./tsGenerics.js"; | ||
import { typedArray } from "./typedArray.js"; | ||
import { validation } from "./validation.js"; | ||
@@ -16,10 +19,11 @@ export const ambientRootScope = schemaScope({ | ||
...jsObjects, | ||
...platformObjects, | ||
...validation, | ||
...internal, | ||
...tsGenerics, | ||
TypedArray: typedArray, | ||
parse: parsing, | ||
format: formatting | ||
// TODO: remove cast | ||
}); | ||
$ark.ambient = ambientRootScope.internal; | ||
export const keywordNodes = ambientRootScope.export(); |
@@ -11,2 +11,5 @@ import type { number } from "../ast.js"; | ||
}; | ||
export type FormDataValue = string | File; | ||
export type ParsedFormData = Record<string, FormDataValue | FormDataValue[]>; | ||
export declare const parse: (data: FormData) => ParsedFormData; | ||
export type parsingExports = { | ||
@@ -18,2 +21,3 @@ url: (In: string) => Out<URL>; | ||
json: (In: string) => Out<object>; | ||
formData: (In: FormData) => Out<ParsedFormData>; | ||
}; | ||
@@ -20,0 +24,0 @@ export type parsing = SchemaModule<parsingExports>; |
@@ -47,2 +47,37 @@ import { isWellFormedInteger, wellFormedIntegerMatcher, wellFormedNumberMatcher } from "@ark/util"; | ||
}); | ||
export const parse = (data) => { | ||
const result = {}; | ||
for (const [k, v] of data) { | ||
if (k in result) { | ||
const existing = result[k]; | ||
if (typeof existing === "string" || existing instanceof File) | ||
result[k] = [existing, v]; | ||
else | ||
existing.push(v); | ||
} | ||
else | ||
result[k] = v; | ||
} | ||
return result; | ||
}; | ||
// support Node18 | ||
const File = globalThis.File ?? Blob; | ||
const formData = defineRoot({ | ||
in: FormData, | ||
morphs: (data) => { | ||
const result = {}; | ||
for (const [k, v] of data) { | ||
if (k in result) { | ||
const existing = result[k]; | ||
if (typeof existing === "string" || existing instanceof File) | ||
result[k] = [existing, v]; | ||
else | ||
existing.push(v); | ||
} | ||
else | ||
result[k] = v; | ||
} | ||
return result; | ||
} | ||
}); | ||
export const parsing = schemaScope({ | ||
@@ -53,3 +88,4 @@ url, | ||
date, | ||
json | ||
json, | ||
formData | ||
}).export(); |
@@ -1,13 +0,39 @@ | ||
import type { Key } from "@ark/util"; | ||
import type { GenericRoot } from "../generic.js"; | ||
import { liftArray, type conform, type Hkt, type Key, type show } from "@ark/util"; | ||
import type { SchemaModule } from "../module.js"; | ||
export interface tsGenericsExports<$ = {}> { | ||
Record: GenericRoot<[ | ||
["K", Key], | ||
["V", unknown] | ||
], { | ||
"[K]": "V"; | ||
}, $>; | ||
import type { Out } from "../roots/morph.js"; | ||
declare const ArkRecord_base: import("../generic.js").GenericHktRootSubclass<[["K", Key], import("../generic.js").GenericParamAst<"V", unknown>], {}>; | ||
declare class ArkRecord extends ArkRecord_base { | ||
hkt: (args: conform<this[Hkt.args], [PropertyKey, unknown]>) => Record<(typeof args)[0], (typeof args)[1]>; | ||
} | ||
declare const ArkPick_base: import("../generic.js").GenericHktRootSubclass<[["T", object], ["K", Key]], {}>; | ||
declare class ArkPick extends ArkPick_base { | ||
hkt: (args: conform<this[Hkt.args], [object, Key]>) => show<Pick<(typeof args)[0], (typeof args)[1] & keyof (typeof args)[0]>>; | ||
} | ||
declare const ArkOmit_base: import("../generic.js").GenericHktRootSubclass<[["T", object], ["K", Key]], {}>; | ||
declare class ArkOmit extends ArkOmit_base { | ||
hkt: (args: conform<this[Hkt.args], [object, Key]>) => show<Omit<(typeof args)[0], (typeof args)[1] & keyof (typeof args)[0]>>; | ||
} | ||
declare const ArkExclude_base: import("../generic.js").GenericHktRootSubclass<[import("../generic.js").GenericParamAst<"T", unknown>, import("../generic.js").GenericParamAst<"U", unknown>], {}>; | ||
declare class ArkExclude extends ArkExclude_base { | ||
hkt: (args: conform<this[Hkt.args], [unknown, unknown]>) => Exclude<(typeof args)[0], (typeof args)[1]>; | ||
} | ||
declare const ArkExtract_base: import("../generic.js").GenericHktRootSubclass<[import("../generic.js").GenericParamAst<"T", unknown>, import("../generic.js").GenericParamAst<"U", unknown>], {}>; | ||
declare class ArkExtract extends ArkExtract_base { | ||
hkt: (args: conform<this[Hkt.args], [unknown, unknown]>) => Extract<(typeof args)[0], (typeof args)[1]>; | ||
} | ||
declare const ArkLiftArray_base: import("../generic.js").GenericHktRootSubclass<[import("../generic.js").GenericParamAst<"T", unknown>], {}>; | ||
declare class ArkLiftArray extends ArkLiftArray_base { | ||
hkt: (args: conform<this[Hkt.args], [unknown]>) => liftArray<(typeof args)[0]> extends infer lifted ? (In: (typeof args)[0] | lifted) => Out<lifted> : never; | ||
} | ||
declare const tsGenericsExports: { | ||
Record: ArkRecord; | ||
Pick: ArkPick; | ||
Omit: ArkOmit; | ||
Exclude: ArkExclude; | ||
Extract: ArkExtract; | ||
liftArray: ArkLiftArray; | ||
}; | ||
export type tsGenericsExports = typeof tsGenericsExports; | ||
export type tsGenerics = SchemaModule<tsGenericsExports>; | ||
export declare const tsGenerics: tsGenerics; | ||
export {}; |
@@ -0,11 +1,30 @@ | ||
import { $ark, liftArray } from "@ark/util"; | ||
import { generic, schemaScope } from "../scope.js"; | ||
const $ = schemaScope({ | ||
Record: generic([["K", $ark.intrinsic.propertyKey], "V"])(args => ({ | ||
domain: "object", | ||
index: { | ||
signature: args.K, | ||
value: args.V | ||
} | ||
})) | ||
}); | ||
class ArkRecord extends generic(["K", $ark.intrinsic.propertyKey], "V")(args => ({ | ||
domain: "object", | ||
index: { | ||
signature: args.K, | ||
value: args.V | ||
} | ||
})) { | ||
} | ||
class ArkPick extends generic(["T", $ark.intrinsic.object], ["K", $ark.intrinsic.propertyKey])(args => args.T.pick(args.K)) { | ||
} | ||
class ArkOmit extends generic(["T", $ark.intrinsic.object], ["K", $ark.intrinsic.propertyKey])(args => args.T.omit(args.K)) { | ||
} | ||
class ArkExclude extends generic("T", "U")(args => args.T.exclude(args.U)) { | ||
} | ||
class ArkExtract extends generic("T", "U")(args => args.T.extract(args.U)) { | ||
} | ||
class ArkLiftArray extends generic("T")(args => args.T.or(args.T.array()).pipe(liftArray)) { | ||
} | ||
const tsGenericsExports = { | ||
Record: new ArkRecord(), | ||
Pick: new ArkPick(), | ||
Omit: new ArkOmit(), | ||
Exclude: new ArkExclude(), | ||
Extract: new ArkExtract(), | ||
liftArray: new ArkLiftArray() | ||
}; | ||
const $ = schemaScope(tsGenericsExports); | ||
export const tsGenerics = $.export(); |
@@ -15,3 +15,2 @@ import type { SchemaModule } from "../module.js"; | ||
unknown: unknown; | ||
void: void; | ||
undefined: undefined; | ||
@@ -18,0 +17,0 @@ } |
@@ -16,4 +16,5 @@ import { schemaScope } from "../scope.js"; | ||
unknown: {}, | ||
void: { unit: undefined }, | ||
undefined: { unit: undefined } | ||
// void is not included because it doesn't have a well-defined meaning | ||
// as a standalone type | ||
}, { prereducedAliases: true, intrinsic: true }).export(); |
@@ -14,3 +14,3 @@ import { type array, type listable } from "@ark/util"; | ||
import { UnitNode, type UnitDeclaration } from "./roots/unit.js"; | ||
import type { RawRootScope } from "./scope.js"; | ||
import type { InternalBaseScope } from "./scope.js"; | ||
import type { ConstraintKind, NodeKind, OpenNodeKind, RootKind, UnknownAttachments, UnknownNodeImplementation } from "./shared/implement.js"; | ||
@@ -41,3 +41,3 @@ import type { makeRootAndArrayPropertiesMutable } from "./shared/utils.js"; | ||
export declare const nodeImplementationsByKind: Record<NodeKind, UnknownNodeImplementation>; | ||
export declare const nodeClassesByKind: Record<NodeKind, new (attachments: UnknownAttachments, $: RawRootScope) => BaseNode>; | ||
export declare const nodeClassesByKind: Record<NodeKind, new (attachments: UnknownAttachments, $: InternalBaseScope) => BaseNode>; | ||
interface NodesByKind extends BoundNodesByKind { | ||
@@ -44,0 +44,0 @@ alias: AliasNode; |
@@ -1,2 +0,2 @@ | ||
import { envHasCsp, flatMorph } from "@ark/util"; | ||
import { $ark, envHasCsp, flatMorph } from "@ark/util"; | ||
import { PredicateNode, predicateImplementation } from "./predicate.js"; | ||
@@ -3,0 +3,0 @@ import { DivisorNode, divisorImplementation } from "./refinements/divisor.js"; |
import { DynamicBase, type anyOrNever } from "@ark/util"; | ||
import type { Root } from "./roots/root.js"; | ||
import type { SchemaRoot } from "./roots/root.js"; | ||
import { arkKind } from "./shared/utils.js"; | ||
@@ -13,3 +13,3 @@ export type PreparsedNodeResolution = { | ||
$[k] | ||
] extends [anyOrNever] ? Root<$[k], $> : $[k] : Root<$[k], $>; | ||
] extends [anyOrNever] ? SchemaRoot<$[k], $> : $[k] : SchemaRoot<$[k], $>; | ||
}; | ||
@@ -16,0 +16,0 @@ export declare const SchemaModule: new <$ = {}>(types: exportSchemaScope<$>) => SchemaModule<$>; |
@@ -8,5 +8,5 @@ import { Callable, type Guardable, type Json, type Key, type array, type conform, type listable, type mutable } from "@ark/util"; | ||
import type { UnitNode } from "./roots/unit.js"; | ||
import type { RawRootScope } from "./scope.js"; | ||
import type { InternalBaseScope } from "./scope.js"; | ||
import type { NodeCompiler } from "./shared/compile.js"; | ||
import type { BaseMeta, RawNodeDeclaration, attachmentsOf } from "./shared/declare.js"; | ||
import type { BaseMeta, BaseNodeDeclaration, attachmentsOf } from "./shared/declare.js"; | ||
import { type BasisKind, type NodeKind, type OpenNodeKind, type RefinementKind, type StructuralKind, type UnknownAttachments } from "./shared/implement.js"; | ||
@@ -19,7 +19,7 @@ import { type TraverseAllows, type TraverseApply } from "./shared/traversal.js"; | ||
* @ts-ignore allow instantiation assignment to the base type */ | ||
out d extends RawNodeDeclaration = RawNodeDeclaration> extends Callable<(data: d["prerequisite"]) => unknown, attachmentsOf<d>> { | ||
out d extends BaseNodeDeclaration = BaseNodeDeclaration> extends Callable<(data: d["prerequisite"]) => unknown, attachmentsOf<d>> { | ||
attachments: UnknownAttachments; | ||
$: RawRootScope; | ||
constructor(attachments: UnknownAttachments, $: RawRootScope); | ||
bindScope($: RawRootScope): this; | ||
$: InternalBaseScope; | ||
constructor(attachments: UnknownAttachments, $: InternalBaseScope); | ||
bindScope($: InternalBaseScope): this; | ||
abstract traverseAllows: TraverseAllows<d["prerequisite"]>; | ||
@@ -73,10 +73,10 @@ abstract traverseApply: TraverseApply<d["prerequisite"]>; | ||
export type TypeKey = Key | BaseRoot; | ||
export type TypePath = array<TypeKey>; | ||
export type TypeIndexer = TypeKey | number; | ||
export type FlatRef<root extends BaseRoot = BaseRoot> = { | ||
path: TypePath; | ||
path: array<TypeKey>; | ||
node: root; | ||
propString: string; | ||
}; | ||
export declare const typePathToPropString: (path: Readonly<TypePath>) => string; | ||
export declare const flatRef: <node extends BaseRoot>(path: TypePath, node: node) => FlatRef<node>; | ||
export declare const typePathToPropString: (path: array<TypeKey>) => string; | ||
export declare const flatRef: <node extends BaseRoot>(path: array<TypeKey>, node: node) => FlatRef<node>; | ||
export declare const flatRefsAreEqual: (l: FlatRef, r: FlatRef) => boolean; | ||
@@ -87,3 +87,3 @@ export declare const appendUniqueFlatRefs: <node extends BaseRoot>(existing: FlatRef<node>[] | undefined, refs: listable<FlatRef<node>>) => FlatRef<node>[]; | ||
shouldTransform?: ShouldTransformFn; | ||
bindScope?: RawRootScope; | ||
bindScope?: InternalBaseScope; | ||
prereduced?: boolean; | ||
@@ -93,3 +93,3 @@ }; | ||
export interface DeepNodeTransformContext extends DeepNodeTransformOptions { | ||
path: mutable<TypePath>; | ||
path: mutable<array<TypeKey>>; | ||
seen: { | ||
@@ -96,0 +96,0 @@ [originalId: string]: (() => BaseNode | undefined) | undefined; |
@@ -35,3 +35,3 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) { | ||
}; | ||
import { Callable, appendUnique, cached, flatMorph, includes, isArray, isEmptyObject, throwError } from "@ark/util"; | ||
import { $ark, Callable, appendUnique, cached, flatMorph, includes, isArray, isEmptyObject, throwError } from "@ark/util"; | ||
import { basisKinds, constraintKinds, precedenceOfKind, refinementKinds, rootKinds, structuralKinds } from "./shared/implement.js"; | ||
@@ -38,0 +38,0 @@ import { TraversalContext } from "./shared/traversal.js"; |
import type { GenericArgResolutions } from "./generic.js"; | ||
import { type NormalizedSchema } from "./kinds.js"; | ||
import type { BaseNode } from "./node.js"; | ||
import type { RawRootScope } from "./scope.js"; | ||
import type { InternalBaseScope } from "./scope.js"; | ||
import { type NodeKind, type RootKind } from "./shared/implement.js"; | ||
@@ -18,3 +18,3 @@ export type NodeParseOptions<prereduced extends boolean = boolean> = { | ||
export interface NodeParseContext<kind extends NodeKind = NodeKind> extends NodeParseOptions { | ||
$: RawRootScope; | ||
$: InternalBaseScope; | ||
args: GenericArgResolutions; | ||
@@ -27,2 +27,2 @@ schema: NormalizedSchema<kind>; | ||
export declare const registerNodeId: (kind: NodeKind, opts: NodeParseOptions) => string; | ||
export declare const parseNode: <kind extends NodeKind>(id: string, kind: kind, schema: NormalizedSchema<kind>, $: RawRootScope, opts: NodeParseOptions) => BaseNode; | ||
export declare const parseNode: <kind extends NodeKind>(id: string, kind: kind, schema: NormalizedSchema<kind>, $: InternalBaseScope, opts: NodeParseOptions) => BaseNode; |
@@ -1,2 +0,1 @@ | ||
import { type RegisteredReference } from "@ark/util"; | ||
import type { constrain, of } from "./ast.js"; | ||
@@ -8,2 +7,3 @@ import { BaseConstraint } from "./constraint.js"; | ||
import { type nodeImplementationOf } from "./shared/implement.js"; | ||
import { type RegisteredReference } from "./shared/registry.js"; | ||
import type { TraversalContext, TraverseAllows, TraverseApply } from "./shared/traversal.js"; | ||
@@ -10,0 +10,0 @@ export interface PredicateInner<predicate extends Predicate = Predicate> extends BaseMeta { |
@@ -1,4 +0,4 @@ | ||
import { registeredReference } from "@ark/util"; | ||
import { BaseConstraint } from "./constraint.js"; | ||
import { compileErrorContext, implementNode } from "./shared/implement.js"; | ||
import { registeredReference } from "./shared/registry.js"; | ||
export const predicateImplementation = implementNode({ | ||
@@ -5,0 +5,0 @@ kind: "predicate", |
@@ -0,1 +1,2 @@ | ||
import { $ark } from "@ark/util"; | ||
import { implementNode } from "../shared/implement.js"; | ||
@@ -30,4 +31,4 @@ import { BaseRange, parseDateLimit, parseExclusiveKey } from "./range.js"; | ||
export class AfterNode extends BaseRange { | ||
impliedBasis = $ark.intrinsic.Date; | ||
impliedBasis = $ark.intrinsic.Date.internal; | ||
traverseAllows = this.exclusive ? data => data > this.rule : data => data >= this.rule; | ||
} |
@@ -0,1 +1,2 @@ | ||
import { $ark } from "@ark/util"; | ||
import { Disjoint } from "../shared/disjoint.js"; | ||
@@ -37,3 +38,3 @@ import { implementNode } from "../shared/implement.js"; | ||
traverseAllows = this.exclusive ? data => data < this.rule : data => data <= this.rule; | ||
impliedBasis = $ark.intrinsic.Date; | ||
impliedBasis = $ark.intrinsic.Date.internal; | ||
} |
@@ -1,3 +0,3 @@ | ||
import { RawPrimitiveConstraint, writeInvalidOperandMessage } from "../constraint.js"; | ||
import type { BaseRoot, Root } from "../roots/root.js"; | ||
import { InternalPrimitiveConstraint, writeInvalidOperandMessage } from "../constraint.js"; | ||
import type { BaseRoot, SchemaRoot } from "../roots/root.js"; | ||
import type { BaseMeta, declareNode } from "../shared/declare.js"; | ||
@@ -20,3 +20,3 @@ import { type nodeImplementationOf } from "../shared/implement.js"; | ||
export declare const divisorImplementation: nodeImplementationOf<DivisorDeclaration>; | ||
export declare class DivisorNode extends RawPrimitiveConstraint<DivisorDeclaration> { | ||
export declare class DivisorNode extends InternalPrimitiveConstraint<DivisorDeclaration> { | ||
traverseAllows: TraverseAllows<number>; | ||
@@ -28,3 +28,3 @@ readonly compiledCondition: string; | ||
} | ||
export declare const writeIndivisibleMessage: <node extends Root>(t: node) => writeIndivisibleMessage<node>; | ||
export type writeIndivisibleMessage<node extends Root> = writeInvalidOperandMessage<"divisor", node>; | ||
export declare const writeIndivisibleMessage: <node extends SchemaRoot>(t: node) => writeIndivisibleMessage<node>; | ||
export type writeIndivisibleMessage<node extends SchemaRoot> = writeInvalidOperandMessage<"divisor", node>; |
@@ -1,2 +0,3 @@ | ||
import { RawPrimitiveConstraint, writeInvalidOperandMessage } from "../constraint.js"; | ||
import { $ark } from "@ark/util"; | ||
import { InternalPrimitiveConstraint, writeInvalidOperandMessage } from "../constraint.js"; | ||
import { implementNode } from "../shared/implement.js"; | ||
@@ -20,7 +21,7 @@ export const divisorImplementation = implementNode({ | ||
}); | ||
export class DivisorNode extends RawPrimitiveConstraint { | ||
export class DivisorNode extends InternalPrimitiveConstraint { | ||
traverseAllows = data => data % this.rule === 0; | ||
compiledCondition = `data % ${this.rule} === 0`; | ||
compiledNegation = `data % ${this.rule} !== 0`; | ||
impliedBasis = $ark.intrinsic.number; | ||
impliedBasis = $ark.intrinsic.number.internal; | ||
expression = `% ${this.rule}`; | ||
@@ -27,0 +28,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { RawPrimitiveConstraint } from "../constraint.js"; | ||
import { InternalPrimitiveConstraint } from "../constraint.js"; | ||
import type { BaseRoot } from "../roots/root.js"; | ||
@@ -21,3 +21,3 @@ import type { BaseMeta, declareNode } from "../shared/declare.js"; | ||
export declare const exactLengthImplementation: nodeImplementationOf<ExactLengthDeclaration>; | ||
export declare class ExactLengthNode extends RawPrimitiveConstraint<ExactLengthDeclaration> { | ||
export declare class ExactLengthNode extends InternalPrimitiveConstraint<ExactLengthDeclaration> { | ||
traverseAllows: TraverseAllows<LengthBoundableData>; | ||
@@ -24,0 +24,0 @@ readonly compiledCondition: string; |
@@ -1,2 +0,3 @@ | ||
import { RawPrimitiveConstraint } from "../constraint.js"; | ||
import { $ark } from "@ark/util"; | ||
import { InternalPrimitiveConstraint } from "../constraint.js"; | ||
import { Disjoint } from "../shared/disjoint.js"; | ||
@@ -30,8 +31,8 @@ import { implementNode } from "../shared/implement.js"; | ||
}); | ||
export class ExactLengthNode extends RawPrimitiveConstraint { | ||
export class ExactLengthNode extends InternalPrimitiveConstraint { | ||
traverseAllows = data => data.length === this.rule; | ||
compiledCondition = `data.length === ${this.rule}`; | ||
compiledNegation = `data.length !== ${this.rule}`; | ||
impliedBasis = $ark.intrinsic.lengthBoundable; | ||
impliedBasis = $ark.intrinsic.lengthBoundable.internal; | ||
expression = `{ length: ${this.rule} }`; | ||
} |
@@ -0,1 +1,2 @@ | ||
import { $ark } from "@ark/util"; | ||
import { Disjoint } from "../shared/disjoint.js"; | ||
@@ -26,4 +27,4 @@ import { implementNode } from "../shared/implement.js"; | ||
export class MaxNode extends BaseRange { | ||
impliedBasis = $ark.intrinsic.number; | ||
impliedBasis = $ark.intrinsic.number.internal; | ||
traverseAllows = this.exclusive ? data => data < this.rule : data => data <= this.rule; | ||
} |
@@ -0,1 +1,2 @@ | ||
import { $ark } from "@ark/util"; | ||
import { Disjoint } from "../shared/disjoint.js"; | ||
@@ -29,3 +30,3 @@ import { implementNode } from "../shared/implement.js"; | ||
export class MaxLengthNode extends BaseRange { | ||
impliedBasis = $ark.intrinsic.lengthBoundable; | ||
impliedBasis = $ark.intrinsic.lengthBoundable.internal; | ||
traverseAllows = this.exclusive ? | ||
@@ -32,0 +33,0 @@ data => data.length < this.rule |
@@ -0,1 +1,2 @@ | ||
import { $ark } from "@ark/util"; | ||
import { implementNode } from "../shared/implement.js"; | ||
@@ -20,4 +21,4 @@ import { BaseRange, parseExclusiveKey } from "./range.js"; | ||
export class MinNode extends BaseRange { | ||
impliedBasis = $ark.intrinsic.number; | ||
impliedBasis = $ark.intrinsic.number.internal; | ||
traverseAllows = this.exclusive ? data => data > this.rule : data => data >= this.rule; | ||
} |
@@ -0,1 +1,2 @@ | ||
import { $ark } from "@ark/util"; | ||
import { implementNode } from "../shared/implement.js"; | ||
@@ -27,3 +28,3 @@ import { BaseRange, parseExclusiveKey } from "./range.js"; | ||
export class MinLengthNode extends BaseRange { | ||
impliedBasis = $ark.intrinsic.lengthBoundable; | ||
impliedBasis = $ark.intrinsic.lengthBoundable.internal; | ||
traverseAllows = this.exclusive ? | ||
@@ -30,0 +31,0 @@ data => data.length > this.rule |
@@ -1,2 +0,2 @@ | ||
import { RawPrimitiveConstraint } from "../constraint.js"; | ||
import { InternalPrimitiveConstraint } from "../constraint.js"; | ||
import type { BaseRoot } from "../roots/root.js"; | ||
@@ -22,3 +22,3 @@ import type { BaseMeta, declareNode } from "../shared/declare.js"; | ||
export declare const patternImplementation: nodeImplementationOf<PatternDeclaration>; | ||
export declare class PatternNode extends RawPrimitiveConstraint<PatternDeclaration> { | ||
export declare class PatternNode extends InternalPrimitiveConstraint<PatternDeclaration> { | ||
readonly instance: RegExp; | ||
@@ -25,0 +25,0 @@ readonly expression: string; |
@@ -1,2 +0,3 @@ | ||
import { RawPrimitiveConstraint } from "../constraint.js"; | ||
import { $ark } from "@ark/util"; | ||
import { InternalPrimitiveConstraint } from "../constraint.js"; | ||
import { implementNode } from "../shared/implement.js"; | ||
@@ -27,3 +28,3 @@ export const patternImplementation = implementNode({ | ||
}); | ||
export class PatternNode extends RawPrimitiveConstraint { | ||
export class PatternNode extends InternalPrimitiveConstraint { | ||
instance = new RegExp(this.rule, this.flags); | ||
@@ -34,3 +35,3 @@ expression = `${this.instance}`; | ||
compiledNegation = `!${this.compiledCondition}`; | ||
impliedBasis = $ark.intrinsic.string; | ||
impliedBasis = $ark.intrinsic.string.internal; | ||
} |
import { type array, type propValueOf, type satisfy } from "@ark/util"; | ||
import { RawPrimitiveConstraint } from "../constraint.js"; | ||
import { InternalPrimitiveConstraint } from "../constraint.js"; | ||
import type { Node } from "../kinds.js"; | ||
import type { BaseMeta, RawNodeDeclaration } from "../shared/declare.js"; | ||
import type { BaseMeta, BaseNodeDeclaration } from "../shared/declare.js"; | ||
import type { KeySchemaDefinitions, RangeKind } from "../shared/implement.js"; | ||
export interface BaseRangeDeclaration extends RawNodeDeclaration { | ||
export interface BaseRangeDeclaration extends BaseNodeDeclaration { | ||
kind: RangeKind; | ||
@@ -11,3 +11,3 @@ inner: BaseRangeInner; | ||
} | ||
export declare abstract class BaseRange<d extends BaseRangeDeclaration> extends RawPrimitiveConstraint<d> { | ||
export declare abstract class BaseRange<d extends BaseRangeDeclaration> extends InternalPrimitiveConstraint<d> { | ||
readonly boundOperandKind: OperandKindsByBoundKind[d["kind"]]; | ||
@@ -14,0 +14,0 @@ readonly compiledActual: string; |
import { isKeyOf } from "@ark/util"; | ||
import { RawPrimitiveConstraint } from "../constraint.js"; | ||
export class BaseRange extends RawPrimitiveConstraint { | ||
import { InternalPrimitiveConstraint } from "../constraint.js"; | ||
export class BaseRange extends InternalPrimitiveConstraint { | ||
boundOperandKind = operandKindsByBoundKind[this.kind]; | ||
@@ -5,0 +5,0 @@ compiledActual = this.boundOperandKind === "value" ? `data` |
@@ -5,3 +5,3 @@ import type { NodeCompiler } from "../shared/compile.js"; | ||
import type { TraverseAllows, TraverseApply } from "../shared/traversal.js"; | ||
import { BaseRoot, type RawRootDeclaration } from "./root.js"; | ||
import { BaseRoot, type InternalRootDeclaration } from "./root.js"; | ||
export interface AliasInner<alias extends string = string> extends BaseMeta { | ||
@@ -23,3 +23,3 @@ readonly alias: alias; | ||
get resolution(): BaseRoot; | ||
rawKeyOf(): BaseRoot<RawRootDeclaration>; | ||
rawKeyOf(): BaseRoot<InternalRootDeclaration>; | ||
get shortDescription(): string; | ||
@@ -26,0 +26,0 @@ traverseAllows: TraverseAllows; |
@@ -35,3 +35,3 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) { | ||
}; | ||
import { append, cached, domainDescriptions } from "@ark/util"; | ||
import { $ark, append, cached, domainDescriptions } from "@ark/util"; | ||
import { Disjoint } from "../shared/disjoint.js"; | ||
@@ -106,2 +106,2 @@ import { implementNode } from "../shared/implement.js"; | ||
}); | ||
const neverIfDisjoint = (result) => result instanceof Disjoint ? $ark.intrinsic.never : result; | ||
const neverIfDisjoint = (result) => result instanceof Disjoint ? $ark.intrinsic.never.internal : result; |
import type { array, Key } from "@ark/util"; | ||
import type { NodeCompiler } from "../shared/compile.js"; | ||
import type { TraverseApply } from "../shared/traversal.js"; | ||
import { BaseRoot, type RawRootDeclaration } from "./root.js"; | ||
export declare abstract class RawBasis<d extends RawRootDeclaration = RawRootDeclaration> extends BaseRoot<d> { | ||
import { BaseRoot, type InternalRootDeclaration } from "./root.js"; | ||
export declare abstract class InternalBasis<d extends InternalRootDeclaration = InternalRootDeclaration> extends BaseRoot<d> { | ||
abstract compiledCondition: string; | ||
@@ -7,0 +7,0 @@ abstract compiledNegation: string; |
import { compileErrorContext } from "../shared/implement.js"; | ||
import { BaseRoot } from "./root.js"; | ||
export class RawBasis extends BaseRoot { | ||
export class InternalBasis extends BaseRoot { | ||
rawKeyOf() { | ||
@@ -5,0 +5,0 @@ return this.$.units(this.literalKeys); |
@@ -5,3 +5,3 @@ import { type Key, type NonEnumerableDomain, type array } from "@ark/util"; | ||
import type { TraverseAllows } from "../shared/traversal.js"; | ||
import { RawBasis } from "./basis.js"; | ||
import { InternalBasis } from "./basis.js"; | ||
export interface DomainInner<domain extends NonEnumerableDomain = NonEnumerableDomain> extends BaseMeta { | ||
@@ -19,3 +19,3 @@ readonly domain: domain; | ||
} | ||
export declare class DomainNode extends RawBasis<DomainDeclaration> { | ||
export declare class DomainNode extends InternalBasis<DomainDeclaration> { | ||
traverseAllows: TraverseAllows; | ||
@@ -22,0 +22,0 @@ readonly compiledCondition: string; |
import { domainDescriptions, domainOf, getBaseDomainKeys } from "@ark/util"; | ||
import { Disjoint } from "../shared/disjoint.js"; | ||
import { implementNode } from "../shared/implement.js"; | ||
import { RawBasis } from "./basis.js"; | ||
export class DomainNode extends RawBasis { | ||
import { InternalBasis } from "./basis.js"; | ||
export class DomainNode extends InternalBasis { | ||
traverseAllows = data => domainOf(data) === this.domain; | ||
@@ -7,0 +7,0 @@ compiledCondition = this.domain === "object" ? |
@@ -1,2 +0,2 @@ | ||
import { flatMorph, hasDomain, isEmptyObject, isKeyOf, omit, pick, throwParseError } from "@ark/util"; | ||
import { $ark, flatMorph, hasDomain, isEmptyObject, isKeyOf, omit, pick, throwParseError } from "@ark/util"; | ||
import { constraintKeyParser, flattenConstraints, intersectConstraints } from "../constraint.js"; | ||
@@ -93,3 +93,3 @@ import { metaKeys } from "../shared/declare.js"; | ||
: this.basis.rawKeyOf() | ||
: this.structure?.keyof() ?? $ark.intrinsic.never); | ||
: this.structure?.keyof() ?? $ark.intrinsic.never.internal); | ||
} | ||
@@ -96,0 +96,0 @@ } |
import { type array, type listable } from "@ark/util"; | ||
import type { distillConstrainableIn } from "../ast.js"; | ||
import type { type } from "../inference.js"; | ||
import type { InferredRoot } from "../inference.js"; | ||
import type { Node, NodeSchema } from "../kinds.js"; | ||
@@ -53,3 +53,3 @@ import type { NodeCompiler } from "../shared/compile.js"; | ||
export declare const writeMorphIntersectionMessage: (lDescription: string, rDescription: string) => string; | ||
export type inferPipes<t, pipes extends Morph[]> = pipes extends [infer head extends Morph, ...infer tail extends Morph[]] ? inferPipes<pipes[0] extends type.cast<infer tPipe> ? inferPipe<t, tPipe> : inferMorphOut<head> extends infer out ? (In: distillConstrainableIn<t>) => Out<out> : never, tail> : t; | ||
export type inferPipes<t, pipes extends Morph[]> = pipes extends [infer head extends Morph, ...infer tail extends Morph[]] ? inferPipes<pipes[0] extends InferredRoot<infer tPipe> ? inferPipe<t, tPipe> : inferMorphOut<head> extends infer out ? (In: distillConstrainableIn<t>) => Out<out> : never, tail> : t; | ||
export type inferMorphOut<morph extends Morph> = Exclude<ReturnType<morph>, ArkError | ArkErrors>; |
@@ -1,5 +0,6 @@ | ||
import { arrayEquals, arrayFrom, registeredReference, throwParseError } from "@ark/util"; | ||
import { $ark, arrayEquals, liftArray, throwParseError } from "@ark/util"; | ||
import { Disjoint } from "../shared/disjoint.js"; | ||
import { implementNode } from "../shared/implement.js"; | ||
import { intersectNodes } from "../shared/intersections.js"; | ||
import { registeredReference } from "../shared/registry.js"; | ||
import { hasArkKind } from "../shared/utils.js"; | ||
@@ -24,3 +25,3 @@ import { BaseRoot } from "./root.js"; | ||
morphs: { | ||
parse: arrayFrom, | ||
parse: liftArray, | ||
serialize: morphs => morphs.map(m => hasArkKind(m, "root") ? m.json : registeredReference(m)) | ||
@@ -88,3 +89,3 @@ } | ||
get out() { | ||
return this.validatedOut ?? $ark.intrinsic.unknown; | ||
return this.validatedOut ?? $ark.intrinsic.unknown.internal; | ||
} | ||
@@ -91,0 +92,0 @@ /** Check if the morphs of r are equal to those of this node */ |
@@ -5,3 +5,3 @@ import { type BuiltinObjectKind, type Constructor, type Key, type array } from "@ark/util"; | ||
import type { TraverseAllows } from "../shared/traversal.js"; | ||
import { RawBasis } from "./basis.js"; | ||
import { InternalBasis } from "./basis.js"; | ||
export interface ProtoInner<proto extends Constructor = Constructor> extends BaseMeta { | ||
@@ -25,3 +25,3 @@ readonly proto: proto; | ||
export declare const protoImplementation: nodeImplementationOf<ProtoDeclaration>; | ||
export declare class ProtoNode extends RawBasis<ProtoDeclaration> { | ||
export declare class ProtoNode extends InternalBasis<ProtoDeclaration> { | ||
builtinName: BuiltinObjectKind | null; | ||
@@ -28,0 +28,0 @@ serializedConstructor: string; |
@@ -1,5 +0,5 @@ | ||
import { builtinConstructors, constructorExtends, getExactBuiltinConstructorName, objectKindDescriptions, objectKindOrDomainOf, prototypeKeysOf } from "@ark/util"; | ||
import { $ark, builtinConstructors, constructorExtends, getExactBuiltinConstructorName, objectKindDescriptions, objectKindOrDomainOf, prototypeKeysOf } from "@ark/util"; | ||
import { Disjoint } from "../shared/disjoint.js"; | ||
import { defaultValueSerializer, implementNode } from "../shared/implement.js"; | ||
import { RawBasis } from "./basis.js"; | ||
import { InternalBasis } from "./basis.js"; | ||
export const protoImplementation = implementNode({ | ||
@@ -34,3 +34,3 @@ kind: "proto", | ||
}); | ||
export class ProtoNode extends RawBasis { | ||
export class ProtoNode extends InternalBasis { | ||
builtinName = getExactBuiltinConstructorName(this.proto); | ||
@@ -37,0 +37,0 @@ serializedConstructor = this.json.proto; |
@@ -1,10 +0,10 @@ | ||
import type { DivisorSchema, ExactLengthSchema, ExclusiveDateRangeSchema, ExclusiveNumericRangeSchema, FlatRef, InclusiveDateRangeSchema, InclusiveNumericRangeSchema, LimitSchemaValue, PatternSchema, TypeKey, TypePath, UnknownRangeSchema } from "@ark/schema"; | ||
import { type Callable, type Json, type array, type conform } from "@ark/util"; | ||
import type { ConstraintKind, DivisorSchema, ExactLengthSchema, ExclusiveDateRangeSchema, ExclusiveNumericRangeSchema, FlatRef, InclusiveDateRangeSchema, InclusiveNumericRangeSchema, InferredRoot, LimitSchemaValue, PatternSchema, TypeIndexer, TypeKey, UnknownRangeSchema, writeInvalidOperandMessage } from "@ark/schema"; | ||
import { type Callable, type ErrorMessage, type Json, type anyOrNever, type array, type conform, type typeToString, type unset } from "@ark/util"; | ||
import type { constrain, distillConstrainableIn, distillConstrainableOut, distillIn, distillOut } from "../ast.js"; | ||
import { type PrimitiveConstraintKind } from "../constraint.js"; | ||
import type { Node, NodeSchema, reducibleKindOf } from "../kinds.js"; | ||
import type { Node, NodeSchema, Prerequisite, reducibleKindOf } from "../kinds.js"; | ||
import { BaseNode } from "../node.js"; | ||
import type { Predicate } from "../predicate.js"; | ||
import type { RootScope } from "../scope.js"; | ||
import type { BaseMeta, RawNodeDeclaration } from "../shared/declare.js"; | ||
import type { BaseScope } from "../scope.js"; | ||
import type { BaseMeta, BaseNodeDeclaration } from "../shared/declare.js"; | ||
import { Disjoint } from "../shared/disjoint.js"; | ||
@@ -14,19 +14,21 @@ import { ArkErrors } from "../shared/errors.js"; | ||
import { type inferIntersection } from "../shared/intersections.js"; | ||
import { arkKind, type inferred, type internalImplementationOf } from "../shared/utils.js"; | ||
import type { UndeclaredKeyBehavior } from "../structure/structure.js"; | ||
import { arkKind, inferred, type internalImplementationOf } from "../shared/utils.js"; | ||
import type { UndeclaredKeyBehavior, arkKeyOf, getArkKey } from "../structure/structure.js"; | ||
import type { constraintKindOf } from "./intersection.js"; | ||
import type { Morph, MorphNode, inferMorphOut, inferPipes } from "./morph.js"; | ||
import type { UnionChildKind } from "./union.js"; | ||
export interface RawRootDeclaration extends RawNodeDeclaration { | ||
export interface InternalRootDeclaration extends BaseNodeDeclaration { | ||
kind: RootKind; | ||
} | ||
export type UnknownRoot<t = unknown> = Root<t> | BaseRoot; | ||
export type TypeOnlyRootKey = (keyof Root & symbol) | "infer" | "inferIn" | "t" | "tIn" | "tOut"; | ||
export type UnknownRoot<t = unknown> = SchemaRoot<t> | BaseRoot; | ||
export type TypeOnlyRootKey = (keyof SchemaRoot & symbol) | "infer" | "inferIn" | "t" | "tIn" | "tOut"; | ||
export declare abstract class BaseRoot< | ||
/** uses -ignore rather than -expect-error because this is not an error in .d.ts | ||
* @ts-ignore allow instantiation assignment to the base type */ | ||
out d extends RawRootDeclaration = RawRootDeclaration> extends BaseNode<d> implements internalImplementationOf<Root, TypeOnlyRootKey | "intersect"> { | ||
out d extends InternalRootDeclaration = InternalRootDeclaration> extends BaseNode<d> implements internalImplementationOf<SchemaRoot, TypeOnlyRootKey | "intersect"> { | ||
[inferred]?: unknown; | ||
readonly branches: readonly Node<UnionChildKind>[]; | ||
readonly [arkKind] = "root"; | ||
get internal(): this; | ||
as(): this; | ||
abstract rawKeyOf(): BaseRoot; | ||
@@ -36,6 +38,11 @@ abstract get shortDescription(): string; | ||
protected intersect(r: unknown): BaseRoot | Disjoint; | ||
isUnknown(): boolean; | ||
isNever(): boolean; | ||
and(r: unknown): BaseRoot; | ||
or(r: unknown): BaseRoot; | ||
assert(data: unknown): unknown; | ||
get(...[key, ...tail]: TypePath): BaseRoot; | ||
pick(...keys: array<TypeKey>): BaseRoot; | ||
omit(...keys: array<TypeKey>): BaseRoot; | ||
private filterKeys; | ||
get(...path: array<TypeIndexer>): BaseRoot; | ||
extract(r: unknown): BaseRoot; | ||
@@ -47,3 +54,2 @@ exclude(r: UnknownRoot): BaseRoot; | ||
subsumes(r: UnknownRoot): boolean; | ||
includes(r: unknown): boolean; | ||
configure(configOrDescription: BaseMeta | string): this; | ||
@@ -86,3 +92,3 @@ describe(description: string): this; | ||
} : schema; | ||
export declare abstract class InnerRoot<t = unknown, $ = any> extends Callable<(data: unknown) => distillOut<t> | ArkErrors> { | ||
export declare abstract class Root<t = unknown, $ = any> extends Callable<(data: unknown) => distillOut<t> | ArkErrors> { | ||
t: t; | ||
@@ -98,5 +104,6 @@ tIn: distillConstrainableIn<t>; | ||
internal: BaseRoot; | ||
abstract $: RootScope<$>; | ||
abstract $: BaseScope<$>; | ||
abstract get in(): unknown; | ||
abstract get out(): unknown; | ||
abstract as(): unknown; | ||
abstract keyof(): unknown; | ||
@@ -112,4 +119,8 @@ abstract intersect(r: never): unknown | Disjoint; | ||
abstract overlaps(r: never): boolean; | ||
abstract pick(...keys: never): unknown; | ||
abstract omit(...keys: never): unknown; | ||
abstract array(): unknown; | ||
abstract pipe(morph: Morph): unknown; | ||
isUnknown(): boolean; | ||
isNever(): boolean; | ||
assert(data: unknown): this["infer"]; | ||
@@ -123,31 +134,49 @@ allows(data: unknown): data is this["inferIn"]; | ||
} | ||
declare class _Root<t = unknown, $ = any> extends InnerRoot<t, $> { | ||
$: RootScope<$>; | ||
get in(): Root<this["tIn"], $>; | ||
get out(): Root<this["tOut"], $>; | ||
keyof(): Root<keyof this["inferIn"], $>; | ||
intersect<r extends Root>(r: r): Root<inferIntersection<t, r["t"]>> | Disjoint; | ||
and<r extends Root>(r: r): Root<inferIntersection<t, r["t"]>>; | ||
or<r extends Root>(r: r): Root<t | r["t"]>; | ||
array(): Root<t[], $>; | ||
constrain<kind extends PrimitiveConstraintKind, const schema extends NodeSchema<kind>>(kind: conform<kind, constraintKindOf<this["inferIn"]>>, schema: schema): Root<constrain<t, kind, schema>, $>; | ||
equals<r>(r: Root<r>): this is Root<r>; | ||
extract<r>(r: Root<r>): Root<t, $>; | ||
exclude<r>(r: Root<r>): Root<t, $>; | ||
extends<r>(other: Root<r>): this is Root<r> & { | ||
declare class _SchemaRoot<t = unknown, $ = any> extends Root<t, $> { | ||
$: BaseScope<$>; | ||
as<t = unset>(...args: validateChainedAsArgs<t>): SchemaRoot<t, $>; | ||
get in(): SchemaRoot<this["tIn"], $>; | ||
get out(): SchemaRoot<this["tOut"], $>; | ||
keyof(): SchemaRoot<keyof this["inferIn"], $>; | ||
pick<const key extends arkKeyOf<t> = never>(this: validateStructuralOperand<"pick", this>, ...keys: array<key | InferredRoot<key>>): SchemaRoot<{ | ||
[k in key]: getArkKey<t, k>; | ||
}, $>; | ||
omit<const key extends arkKeyOf<t> = never>(this: validateStructuralOperand<"omit", this>, ...keys: array<key | InferredRoot<key>>): SchemaRoot<{ | ||
[k in key]: getArkKey<t, k>; | ||
}, $>; | ||
get<k1 extends arkKeyOf<t>>(k1: k1 | InferredRoot<k1>): SchemaRoot<getArkKey<t, k1>, $>; | ||
get<k1 extends arkKeyOf<t>, k2 extends arkKeyOf<getArkKey<t, k1>>>(k1: k1 | InferredRoot<k1>, k2: k2 | InferredRoot<k2>): SchemaRoot<getArkKey<getArkKey<t, k1>, k2>, $>; | ||
get<k1 extends arkKeyOf<t>, k2 extends arkKeyOf<getArkKey<t, k1>>, k3 extends arkKeyOf<getArkKey<getArkKey<t, k1>, k2>>>(k1: k1 | InferredRoot<k1>, k2: k2 | InferredRoot<k2>, k3: k3 | InferredRoot<k3>): SchemaRoot<getArkKey<getArkKey<getArkKey<t, k1>, k2>, k3>, $>; | ||
intersect<r extends SchemaRoot>(r: r): SchemaRoot<inferIntersection<t, r["t"]>> | Disjoint; | ||
and<r extends SchemaRoot>(r: r): SchemaRoot<inferIntersection<t, r["t"]>>; | ||
or<r extends SchemaRoot>(r: r): SchemaRoot<t | r["t"]>; | ||
array(): SchemaRoot<t[], $>; | ||
constrain<kind extends PrimitiveConstraintKind, const schema extends NodeSchema<kind>>(kind: conform<kind, constraintKindOf<this["inferIn"]>>, schema: schema): SchemaRoot<constrain<t, kind, schema>, $>; | ||
equals<r>(r: SchemaRoot<r>): this is SchemaRoot<r>; | ||
extract<r>(r: SchemaRoot<r>): SchemaRoot<t, $>; | ||
exclude<r>(r: SchemaRoot<r>): SchemaRoot<t, $>; | ||
extends<r>(other: SchemaRoot<r>): this is SchemaRoot<r> & { | ||
[inferred]?: r; | ||
}; | ||
pipe<a extends Morph<this["infer"]>>(a: a): Root<inferPipes<t, [a]>, $>; | ||
pipe<a extends Morph<this["infer"]>, b extends Morph<inferMorphOut<a>>>(a: a, b: b): Root<inferPipes<t, [a, b]>, $>; | ||
pipe<a extends Morph<this["infer"]>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>>(a: a, b: b, c: c): Root<inferPipes<t, [a, b, c]>, $>; | ||
pipe<a extends Morph<this["infer"]>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>>(a: a, b: b, c: c, d: d): Root<inferPipes<t, [a, b, c, d]>, $>; | ||
pipe<a extends Morph<this["infer"]>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>>(a: a, b: b, c: c, d: d, e: e): Root<inferPipes<t, [a, b, c, d, e]>, $>; | ||
pipe<a extends Morph<this["infer"]>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, f extends Morph<inferMorphOut<e>>>(a: a, b: b, c: c, d: d, e: e, f: f): Root<inferPipes<t, [a, b, c, d, e, f]>, $>; | ||
pipe<a extends Morph<this["infer"]>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, f extends Morph<inferMorphOut<e>>, g extends Morph<inferMorphOut<f>>>(a: a, b: b, c: c, d: d, e: e, f: f, g: g): Root<inferPipes<t, [a, b, c, d, e, f, g]>, $>; | ||
overlaps(r: Root): boolean; | ||
pipe<a extends Morph<this["infer"]>>(a: a): SchemaRoot<inferPipes<t, [a]>, $>; | ||
pipe<a extends Morph<this["infer"]>, b extends Morph<inferMorphOut<a>>>(a: a, b: b): SchemaRoot<inferPipes<t, [a, b]>, $>; | ||
pipe<a extends Morph<this["infer"]>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>>(a: a, b: b, c: c): SchemaRoot<inferPipes<t, [a, b, c]>, $>; | ||
pipe<a extends Morph<this["infer"]>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>>(a: a, b: b, c: c, d: d): SchemaRoot<inferPipes<t, [a, b, c, d]>, $>; | ||
pipe<a extends Morph<this["infer"]>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>>(a: a, b: b, c: c, d: d, e: e): SchemaRoot<inferPipes<t, [a, b, c, d, e]>, $>; | ||
pipe<a extends Morph<this["infer"]>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, f extends Morph<inferMorphOut<e>>>(a: a, b: b, c: c, d: d, e: e, f: f): SchemaRoot<inferPipes<t, [a, b, c, d, e, f]>, $>; | ||
pipe<a extends Morph<this["infer"]>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, f extends Morph<inferMorphOut<e>>, g extends Morph<inferMorphOut<f>>>(a: a, b: b, c: c, d: d, e: e, f: f, g: g): SchemaRoot<inferPipes<t, [a, b, c, d, e, f, g]>, $>; | ||
overlaps(r: SchemaRoot): boolean; | ||
} | ||
export declare const writeNonStructuralIndexAccessMessage: (key: TypeKey) => string; | ||
export interface Root< | ||
export declare const typeOrTermExtends: (t: unknown, base: unknown) => boolean; | ||
export type validateChainedAsArgs<t> = [ | ||
t | ||
] extends [unset] ? [ | ||
t | ||
] extends [anyOrNever] ? [ | ||
] : [ | ||
ErrorMessage<"as requires an explicit type parameter like myType.as<t>()"> | ||
] : []; | ||
export interface SchemaRoot< | ||
/** @ts-expect-error allow instantiation assignment to the base type */ | ||
out t = unknown, $ = any> extends _Root<t, $> { | ||
out t = unknown, $ = any> extends _SchemaRoot<t, $> { | ||
} | ||
@@ -161,2 +190,11 @@ export type intersectRoot<l extends RootKind, r extends NodeKind> = [ | ||
export type schemaKindOrRightOf<kind extends RootKind> = kind | schemaKindRightOf<kind>; | ||
export type validateStructuralOperand<name extends StructuralOperationName, t extends { | ||
inferIn: unknown; | ||
}> = t["inferIn"] extends object ? t : ErrorMessage<writeNonStructuralOperandMessage<name, typeToString<t["inferIn"]>>>; | ||
export type validateChainedConstraint<kind extends ConstraintKind, t extends { | ||
inferIn: unknown; | ||
}> = t["inferIn"] extends Prerequisite<kind> ? t : ErrorMessage<writeInvalidOperandMessage<kind, SchemaRoot<t["inferIn"]>>>; | ||
export type StructuralOperationName = "pick" | "omit" | "index access"; | ||
export type writeNonStructuralOperandMessage<operation extends StructuralOperationName, operand extends string> = `${operation} operand must be an object (was ${operand})`; | ||
export declare const writeNonStructuralOperandMessage: <operation extends StructuralOperationName, operand extends string>(operation: operation, operand: operand) => writeNonStructuralOperandMessage<operation, operand>; | ||
export {}; |
@@ -35,3 +35,3 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) { | ||
}; | ||
import { cached, includes, omit, printable, throwParseError } from "@ark/util"; | ||
import { $ark, cached, includes, omit, throwParseError } from "@ark/util"; | ||
import { throwInvalidOperandError } from "../constraint.js"; | ||
@@ -43,3 +43,3 @@ import { BaseNode, appendUniqueFlatRefs } from "../node.js"; | ||
import { intersectNodesRoot, pipeNodesRoot } from "../shared/intersections.js"; | ||
import { arkKind, hasArkKind } from "../shared/utils.js"; | ||
import { arkKind, hasArkKind, inferred } from "../shared/utils.js"; | ||
let BaseRoot = (() => { | ||
@@ -59,3 +59,4 @@ let _classSuper = BaseNode; | ||
} | ||
branches = (__runInitializers(this, _instanceExtraInitializers), this.hasKind("union") ? this.inner.branches : [this]); | ||
[inferred] = __runInitializers(this, _instanceExtraInitializers); | ||
branches = this.hasKind("union") ? this.inner.branches : [this]; | ||
[arkKind] = "root"; | ||
@@ -65,2 +66,5 @@ get internal() { | ||
} | ||
as() { | ||
return this; | ||
} | ||
keyof() { | ||
@@ -77,2 +81,8 @@ const result = this.rawKeyOf(); | ||
} | ||
isUnknown() { | ||
return this.hasKind("intersection") && this.children.length === 0; | ||
} | ||
isNever() { | ||
return this.hasKind("union") && this.children.length === 0; | ||
} | ||
and(r) { | ||
@@ -91,14 +101,41 @@ const result = this.intersect(r); | ||
} | ||
get(...[key, ...tail]) { | ||
if (key === undefined) | ||
pick(...keys) { | ||
return this.filterKeys("pick", keys); | ||
} | ||
omit(...keys) { | ||
return this.filterKeys("omit", keys); | ||
} | ||
filterKeys(operation, keys) { | ||
if (this.hasKind("union")) { | ||
return this.$.schema(this.branches.map(branch => branch[operation](...keys))); | ||
} | ||
if (this.hasKind("morph")) { | ||
return this.$.node("morph", { | ||
...this.inner, | ||
in: this.in[operation](...keys) | ||
}); | ||
} | ||
if (this.hasKind("intersection")) { | ||
if (!this.inner.structure) { | ||
throwParseError(writeNonStructuralOperandMessage(operation, this.expression)); | ||
} | ||
return this.$.node("intersection", { | ||
...this.inner, | ||
structure: this.inner.structure[operation](...keys) | ||
}); | ||
} | ||
if (this.isBasis() && this.domain === "object") | ||
// if it's an object but has no Structure node, return an empty object | ||
return $ark.intrinsic.object.internal.bindScope(this.$); | ||
return throwParseError(writeNonStructuralOperandMessage(operation, this.expression)); | ||
} | ||
get(...path) { | ||
if (path[0] === undefined) | ||
return this; | ||
if (hasArkKind(key, "root") && key.hasKind("unit")) | ||
key = key.unit; | ||
if (typeof key === "number") | ||
key = `${key}`; | ||
if (this.hasKind("union")) { | ||
return this.branches.reduce((acc, b) => acc.or(b.get(key, ...tail)), $ark.intrinsic.never); | ||
return this.branches.reduce((acc, b) => acc.or(b.get(...path)), $ark.intrinsic.never.internal); | ||
} | ||
return (this.structure?.get(key, ...tail) ?? | ||
throwParseError(writeNonStructuralIndexAccessMessage(key))); | ||
const branch = this; | ||
return (branch.structure?.get(...path) ?? | ||
throwParseError(writeNonStructuralOperandMessage("index access", this.expression))); | ||
} | ||
@@ -130,5 +167,2 @@ extract(r) { | ||
} | ||
includes(r) { | ||
return hasArkKind(r, "root") ? r.extends(this) : this.allows(r); | ||
} | ||
configure(configOrDescription) { | ||
@@ -272,2 +306,7 @@ return this.configureShallowDescendants(configOrDescription); | ||
}); | ||
export const writeNonStructuralIndexAccessMessage = (key) => `${printable(key)} cannot be accessed on ${this}, which has no structural keys`; | ||
export const typeOrTermExtends = (t, base) => hasArkKind(base, "root") ? | ||
hasArkKind(t, "root") ? t.extends(base) | ||
: base.allows(t) | ||
: hasArkKind(t, "root") ? t.hasUnit(base) | ||
: base === t; | ||
export const writeNonStructuralOperandMessage = (operation, operand) => `${operation} operand must be an object (was ${operand})`; |
import { type Domain, type Json, type Key, type SerializedPrimitive, type show } from "@ark/util"; | ||
import type { Node, NodeSchema } from "../kinds.js"; | ||
import type { NodeCompiler } from "../shared/compile.js"; | ||
import { type NodeCompiler } from "../shared/compile.js"; | ||
import type { BaseMeta, declareNode } from "../shared/declare.js"; | ||
@@ -38,3 +38,2 @@ import { Disjoint } from "../shared/disjoint.js"; | ||
export declare class UnionNode extends BaseRoot<UnionDeclaration> { | ||
isNever: boolean; | ||
isBoolean: boolean; | ||
@@ -41,0 +40,0 @@ unitBranches: (MorphNode | UnitNode)[]; |
@@ -35,7 +35,9 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) { | ||
}; | ||
import { appendUnique, arrayEquals, cached, compileLiteralPropAccess, compileSerializedValue, domainDescriptions, flatMorph, groupBy, isArray, isKeyOf, printable, registeredReference, throwInternalError, throwParseError } from "@ark/util"; | ||
import { $ark, appendUnique, arrayEquals, cached, domainDescriptions, flatMorph, groupBy, isArray, isKeyOf, printable, throwInternalError, throwParseError } from "@ark/util"; | ||
import { typePathToPropString } from "../node.js"; | ||
import { compileLiteralPropAccess, compileSerializedValue } from "../shared/compile.js"; | ||
import { Disjoint } from "../shared/disjoint.js"; | ||
import { implementNode, schemaKindsRightOf } from "../shared/implement.js"; | ||
import { intersectNodes, intersectNodesRoot } from "../shared/intersections.js"; | ||
import { registeredReference } from "../shared/registry.js"; | ||
import { pathToPropString } from "../shared/utils.js"; | ||
@@ -146,6 +148,5 @@ import { BaseRoot } from "./root.js"; | ||
} | ||
isNever = (__runInitializers(this, _instanceExtraInitializers), this.branches.length === 0); | ||
isBoolean = this.branches.length === 2 && | ||
isBoolean = (__runInitializers(this, _instanceExtraInitializers), this.branches.length === 2 && | ||
this.branches[0].hasUnit(false) && | ||
this.branches[1].hasUnit(true); | ||
this.branches[1].hasUnit(true)); | ||
unitBranches = this.branches.filter((n) => n.in.hasKind("unit")); | ||
@@ -219,3 +220,3 @@ discriminant = this.discriminate(); | ||
rawKeyOf() { | ||
return this.branches.reduce((result, branch) => result.and(branch.rawKeyOf()), $ark.intrinsic.unknown); | ||
return this.branches.reduce((result, branch) => result.and(branch.rawKeyOf()), $ark.intrinsic.unknown.internal); | ||
} | ||
@@ -222,0 +223,0 @@ get nestableExpression() { |
@@ -5,3 +5,3 @@ import { type Domain, type JsonPrimitive, type Key, type array } from "@ark/util"; | ||
import type { TraverseAllows } from "../shared/traversal.js"; | ||
import { RawBasis } from "./basis.js"; | ||
import { InternalBasis } from "./basis.js"; | ||
export type UnitSchema<value = unknown> = UnitInner<value>; | ||
@@ -20,3 +20,3 @@ export interface UnitInner<value = unknown> extends BaseMeta { | ||
export declare const unitImplementation: nodeImplementationOf<UnitDeclaration>; | ||
export declare class UnitNode extends RawBasis<UnitDeclaration> { | ||
export declare class UnitNode extends InternalBasis<UnitDeclaration> { | ||
compiledValue: JsonPrimitive; | ||
@@ -23,0 +23,0 @@ serializedValue: JsonPrimitive; |
import { domainDescriptions, domainOf, printable, prototypeKeysOf } from "@ark/util"; | ||
import { Disjoint } from "../shared/disjoint.js"; | ||
import { defaultValueSerializer, implementNode } from "../shared/implement.js"; | ||
import { RawBasis } from "./basis.js"; | ||
import { InternalBasis } from "./basis.js"; | ||
import { defineRightwardIntersections } from "./utils.js"; | ||
@@ -29,3 +29,3 @@ export const unitImplementation = implementNode({ | ||
}); | ||
export class UnitNode extends RawBasis { | ||
export class UnitNode extends InternalBasis { | ||
compiledValue = this.json.unit; | ||
@@ -32,0 +32,0 @@ serializedValue = typeof this.unit === "string" || this.unit instanceof Date ? |
@@ -1,4 +0,4 @@ | ||
import { DynamicBase, ParseError, type Json, type array, type flattenListable, type show } from "@ark/util"; | ||
import { DynamicBase, ParseError, type Json, type anyOrNever, type array, type flattenListable, type show } from "@ark/util"; | ||
import { type ArkConfig, type ResolvedArkConfig } from "./config.js"; | ||
import { type GenericParamDef, type GenericRoot, type LazyGenericSchema, type genericParamSchemasToAst } from "./generic.js"; | ||
import { GenericRoot, type GenericHktSchemaParser, type GenericParamDef } from "./generic.js"; | ||
import type { inferRoot, validateRoot } from "./inference.js"; | ||
@@ -13,3 +13,3 @@ import type { internal } from "./keywords/internal.js"; | ||
import { type AliasNode } from "./roots/alias.js"; | ||
import type { BaseRoot, Root } from "./roots/root.js"; | ||
import type { BaseRoot, SchemaRoot } from "./roots/root.js"; | ||
import type { NodeKind, RootKind } from "./shared/implement.js"; | ||
@@ -21,3 +21,3 @@ import { arkKind, type internalImplementationOf } from "./shared/utils.js"; | ||
export type BaseResolutions = Record<string, BaseRoot>; | ||
export type RawRootResolutions = Record<string, RawResolution | undefined>; | ||
export type InternalResolutions = Record<string, InternalResolution | undefined>; | ||
export type exportedNameOf<$> = Exclude<keyof $ & string, PrivateDeclaration>; | ||
@@ -27,16 +27,17 @@ export type resolvableReferenceIn<$> = keyof $ extends infer k extends string ? k extends PrivateDeclaration<infer alias> ? alias : k : never; | ||
export type PrivateDeclaration<key extends string = string> = `#${key}`; | ||
type toRawScope<$> = RawRootScope<{ | ||
type toInternalScope<$> = InternalBaseScope<{ | ||
[k in keyof $]: $[k] extends { | ||
[arkKind]: infer kind; | ||
} ? kind extends "generic" ? GenericRoot : kind extends "module" ? RawRootModule : never : BaseRoot; | ||
} ? [ | ||
$[k] | ||
] extends [anyOrNever] ? BaseRoot : kind extends "generic" ? GenericRoot : kind extends "module" ? InternalRootModule : never : BaseRoot; | ||
}>; | ||
export type IntrinsicKeywords = { | ||
[alias in keyof tsKeywords | keyof jsObjects | keyof internal]: BaseRoot; | ||
}; | ||
export type RawResolution = BaseRoot | GenericRoot | RawRootModule; | ||
type CachedResolution = string | RawResolution; | ||
export interface IntrinsicKeywords extends tsKeywords, jsObjects, internal { | ||
} | ||
export type InternalResolution = BaseRoot | GenericRoot | InternalRootModule; | ||
type CachedResolution = string | InternalResolution; | ||
export declare const writeDuplicateAliasError: <alias extends string>(alias: alias) => writeDuplicateAliasError<alias>; | ||
export type writeDuplicateAliasError<alias extends string> = `#${alias} duplicates public alias ${alias}`; | ||
export type AliasDefEntry = [name: string, defValue: unknown]; | ||
export declare class RawRootScope<$ extends RawRootResolutions = RawRootResolutions> implements internalImplementationOf<RootScope, "t"> { | ||
export declare abstract class InternalBaseScope<$ extends InternalResolutions = InternalResolutions> implements internalImplementationOf<BaseScope, "t"> { | ||
readonly config: ArkConfig; | ||
@@ -62,5 +63,6 @@ readonly resolvedConfig: ResolvedArkConfig; | ||
get internal(): this; | ||
defineSchema(def: RootSchema): RootSchema; | ||
schema(def: RootSchema, opts?: NodeParseOptions): BaseRoot; | ||
defineRoot(def: RootSchema): RootSchema; | ||
generic(params: array<GenericParamDef>, def?: unknown): GenericRoot | ((def: LazyGenericSchema) => GenericRoot); | ||
generic(...params: array<GenericParamDef>): ReturnType<GenericHktSchemaParser>; | ||
units(values: array, opts?: NodeParseOptions): BaseRoot; | ||
@@ -71,3 +73,2 @@ protected lazyResolutions: AliasNode[]; | ||
protected finalizeRootArgs(opts: NodeParseOptions, resolve: () => BaseRoot): NodeParseOptions; | ||
parseRoot(def: unknown, opts?: NodeParseOptions): BaseRoot; | ||
resolveRoot(name: string): BaseRoot; | ||
@@ -78,3 +79,3 @@ maybeResolveRoot(name: string): BaseRoot | undefined; | ||
preparseAlias(k: string, v: unknown): AliasDefEntry; | ||
maybeResolve(name: string): RawResolution | undefined; | ||
maybeResolve(name: string): InternalResolution | undefined; | ||
maybeShallowResolve(name: string): CachedResolution | undefined; | ||
@@ -88,2 +89,3 @@ /** If name is a valid reference to a submodule alias, return its resolution */ | ||
resolve<name extends exportedNameOf<$>>(name: name): destructuredExportContext<$, []>[name]; | ||
abstract parseRoot(schema: any, opts?: NodeParseOptions): BaseRoot; | ||
} | ||
@@ -96,4 +98,4 @@ export type validateAliases<aliases> = { | ||
} & unknown; | ||
export declare const schemaScope: <const aliases>(aliases: validateAliases<aliases>, config?: ArkConfig) => RootScope<instantiateAliases<aliases>>; | ||
export interface RootScope<$ = any> { | ||
export declare const schemaScope: <const aliases>(aliases: validateAliases<aliases>, config?: ArkConfig) => SchemaScope<instantiateAliases<aliases>>; | ||
export interface BaseScope<$ = any> { | ||
t: $; | ||
@@ -108,27 +110,34 @@ [arkKind]: "scope"; | ||
aliases: Record<string, unknown>; | ||
internal: toRawScope<$>; | ||
schema<const def extends RootSchema>(schema: def, opts?: NodeParseOptions): Root<inferRoot<def, $>, $>; | ||
defineRoot<const def extends RootSchema>(schema: def): def; | ||
units<const branches extends array>(values: branches, opts?: NodeParseOptions): Root<branches[number], $>; | ||
internal: toInternalScope<$>; | ||
defineSchema<const def extends RootSchema>(schema: def): def; | ||
schema<const def extends RootSchema>(schema: def, opts?: NodeParseOptions): SchemaRoot<inferRoot<def, $>, $>; | ||
units<const branches extends array>(values: branches, opts?: NodeParseOptions): SchemaRoot<branches[number], $>; | ||
node<kinds extends NodeKind | array<RootKind>>(kinds: kinds, schema: NodeSchema<flattenListable<kinds>>, opts?: NodeParseOptions): Node<reducibleKindOf<flattenListable<kinds>>>; | ||
generic<const paramsDef extends array<GenericParamDef>, bodyDef extends LazyGenericSchema<genericParamSchemasToAst<paramsDef, $>> = never>(params: paramsDef, def?: bodyDef): [bodyDef] extends [never] ? <lazyDef extends LazyGenericSchema<genericParamSchemasToAst<paramsDef, $>>>(lazyDef: lazyDef) => GenericRoot<genericParamSchemasToAst<paramsDef, $>, ReturnType<lazyDef>, $> : GenericRoot<genericParamSchemasToAst<paramsDef, $>, bodyDef, $>; | ||
parseRoot(schema: unknown, opts?: NodeParseOptions): BaseRoot; | ||
import<names extends exportedNameOf<$>[]>(...names: names): SchemaModule<show<destructuredImportContext<$, names>>>; | ||
export<names extends exportedNameOf<$>[]>(...names: names): SchemaModule<show<destructuredExportContext<$, names>>>; | ||
resolve<name extends exportedNameOf<$>>(name: name): $[name] extends PreparsedNodeResolution ? $[name] : Root<$[name], $>; | ||
resolve<name extends exportedNameOf<$>>(name: name): $[name] extends PreparsedNodeResolution ? $[name] : SchemaRoot<$[name], $>; | ||
parseRoot(def: any, opts?: NodeParseOptions): SchemaRoot; | ||
} | ||
export declare const RootScope: new <$ = any>(...args: ConstructorParameters<typeof RawRootScope>) => RootScope<$>; | ||
export declare const root: RootScope<{}>; | ||
export declare const schema: RootScope["schema"]; | ||
export declare const node: RootScope["node"]; | ||
export declare const defineRoot: RootScope["defineRoot"]; | ||
export declare const units: RootScope["units"]; | ||
export declare const generic: RootScope["generic"]; | ||
export declare const internalSchema: RawRootScope["schema"]; | ||
export declare const internalNode: RawRootScope["node"]; | ||
export declare const defineInternalRoot: RawRootScope["defineRoot"]; | ||
export declare const internalUnits: RawRootScope["units"]; | ||
export declare const internalGeneric: RawRootScope["generic"]; | ||
export declare const parseAsSchema: <castTo = unknown>(def: unknown, opts?: NodeParseOptions) => Root<castTo, {}> | ParseError; | ||
export declare class RawRootModule<resolutions extends RawRootResolutions = RawRootResolutions> extends DynamicBase<resolutions> { | ||
export declare class InternalSchemaScope<$ extends InternalResolutions = InternalResolutions> extends InternalBaseScope<$> { | ||
parseRoot(def: unknown, opts?: NodeParseOptions): BaseRoot; | ||
} | ||
export interface SchemaScope<$ = {}> extends BaseScope<$> { | ||
defineRoot: this["defineSchema"]; | ||
parseRoot: this["schema"]; | ||
generic: GenericHktSchemaParser<$>; | ||
} | ||
export declare const SchemaScope: new <$ = {}>(...args: ConstructorParameters<typeof InternalBaseScope>) => SchemaScope<$>; | ||
export declare const root: SchemaScope; | ||
export declare const schema: SchemaScope["schema"]; | ||
export declare const node: SchemaScope["node"]; | ||
export declare const defineRoot: SchemaScope["defineRoot"]; | ||
export declare const units: SchemaScope["units"]; | ||
export declare const generic: SchemaScope["generic"]; | ||
export declare const internalSchema: InternalBaseScope["schema"]; | ||
export declare const internalNode: InternalBaseScope["node"]; | ||
export declare const defineInternalRoot: InternalBaseScope["defineRoot"]; | ||
export declare const internalUnits: InternalBaseScope["units"]; | ||
export declare const internalGeneric: InternalBaseScope["generic"]; | ||
export declare const parseAsSchema: <castTo = unknown>(def: unknown, opts?: NodeParseOptions) => SchemaRoot<castTo, {}> | ParseError; | ||
export declare class InternalRootModule<resolutions extends InternalResolutions = InternalResolutions> extends DynamicBase<resolutions> { | ||
readonly [arkKind]: "module"; | ||
@@ -142,3 +151,3 @@ } | ||
}; | ||
export type RootExportCache = Record<string, BaseRoot | GenericRoot | RawRootModule | undefined>; | ||
export type RootExportCache = Record<string, BaseRoot | GenericRoot | InternalRootModule | undefined>; | ||
export declare const writeUnresolvableMessage: <token extends string>(token: token) => writeUnresolvableMessage<token>; | ||
@@ -145,0 +154,0 @@ export type writeUnresolvableMessage<token extends string> = `'${token}' is unresolvable`; |
@@ -35,5 +35,5 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) { | ||
}; | ||
import { CompiledFunction, DynamicBase, ParseError, bound, flatMorph, hasDomain, isArray, printable, throwInternalError, throwParseError } from "@ark/util"; | ||
import { $ark, DynamicBase, ParseError, bound, flatMorph, hasDomain, isArray, printable, throwInternalError, throwParseError } from "@ark/util"; | ||
import { resolveConfig } from "./config.js"; | ||
import { LazyGenericRoot, parseGeneric } from "./generic.js"; | ||
import { GenericRoot, LazyGenericBody } from "./generic.js"; | ||
import { nodeImplementationsByKind } from "./kinds.js"; | ||
@@ -43,3 +43,3 @@ import { RootModule } from "./module.js"; | ||
import { normalizeAliasSchema } from "./roots/alias.js"; | ||
import { NodeCompiler } from "./shared/compile.js"; | ||
import { CompiledFunction, NodeCompiler } from "./shared/compile.js"; | ||
import { arkKind, hasArkKind, isNode } from "./shared/utils.js"; | ||
@@ -53,4 +53,5 @@ const schemaBranchesOf = (schema) => isArray(schema) ? schema | ||
$ark.intrinsic = {}; | ||
let RawRootScope = (() => { | ||
let InternalBaseScope = (() => { | ||
let _instanceExtraInitializers = []; | ||
let _defineSchema_decorators; | ||
let _schema_decorators; | ||
@@ -61,5 +62,6 @@ let _defineRoot_decorators; | ||
let _node_decorators; | ||
return class RawRootScope { | ||
return class InternalBaseScope { | ||
static { | ||
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0; | ||
_defineSchema_decorators = [bound]; | ||
_schema_decorators = [bound]; | ||
@@ -70,2 +72,3 @@ _defineRoot_decorators = [bound]; | ||
_node_decorators = [bound]; | ||
__esDecorate(this, null, _defineSchema_decorators, { kind: "method", name: "defineSchema", static: false, private: false, access: { has: obj => "defineSchema" in obj, get: obj => obj.defineSchema }, metadata: _metadata }, null, _instanceExtraInitializers); | ||
__esDecorate(this, null, _schema_decorators, { kind: "method", name: "schema", static: false, private: false, access: { has: obj => "schema" in obj, get: obj => obj.schema }, metadata: _metadata }, null, _instanceExtraInitializers); | ||
@@ -120,2 +123,5 @@ __esDecorate(this, null, _defineRoot_decorators, { kind: "method", name: "defineRoot", static: false, private: false, access: { has: obj => "defineRoot" in obj, get: obj => obj.defineRoot }, metadata: _metadata }, null, _instanceExtraInitializers); | ||
} | ||
defineSchema(def) { | ||
return def; | ||
} | ||
schema(def, opts) { | ||
@@ -125,9 +131,11 @@ return this.node(schemaKindOf(def), def, opts); | ||
defineRoot(def) { | ||
return def; | ||
return this.defineSchema(def); | ||
} | ||
generic(params, def) { | ||
if (def === undefined) { | ||
return (def) => this.generic(params, new LazyGenericRoot(def)); | ||
} | ||
return parseGeneric(params, def, this); | ||
generic(...params) { | ||
const $ = this; | ||
return (instantiateDef) => class GenericHktSubclass extends GenericRoot { | ||
constructor() { | ||
super(params, new LazyGenericBody(instantiateDef), $, $); | ||
} | ||
}; | ||
} | ||
@@ -206,6 +214,2 @@ units(values, opts) { | ||
} | ||
parseRoot(def, opts = {}) { | ||
const node = this.schema(def, this.finalizeRootArgs(opts, () => node)); | ||
return node; | ||
} | ||
resolveRoot(name) { | ||
@@ -247,7 +251,4 @@ return (this.maybeResolveRoot(name) ?? | ||
const preparsed = this.preparseRoot(def); | ||
if (hasArkKind(preparsed, "generic")) { | ||
return (this.resolutions[name] = preparsed | ||
.validateBaseInstantiation() | ||
?.bindScope(this)); | ||
} | ||
if (hasArkKind(preparsed, "generic")) | ||
return (this.resolutions[name] = preparsed.bindScope(this)); | ||
if (hasArkKind(preparsed, "module")) { | ||
@@ -296,4 +297,3 @@ return (this.resolutions[name] = new RootModule(flatMorph(preparsed, (alias, node) => [ | ||
this._exportedResolutions = resolutionsOfModule(this, this._exports); | ||
// TODO: add generic json | ||
Object.assign(this.json, flatMorph(this._exportedResolutions, (k, v) => hasArkKind(v, "root") ? [k, v.json] : [])); | ||
Object.assign(this.json, resolutionsToJson(this._exportedResolutions)); | ||
Object.assign(this.resolutions, this._exportedResolutions); | ||
@@ -318,3 +318,9 @@ if (this.config.intrinsic) | ||
})(); | ||
export { RawRootScope }; | ||
export { InternalBaseScope }; | ||
const resolutionsToJson = (resolutions) => flatMorph(resolutions, (k, v) => [ | ||
k, | ||
hasArkKind(v, "root") || hasArkKind(v, "generic") ? | ||
v.json | ||
: resolutionsToJson(v) | ||
]); | ||
const maybeResolveSubalias = (base, name) => { | ||
@@ -342,5 +348,11 @@ const dotIndex = name.indexOf("."); | ||
}; | ||
export const schemaScope = (aliases, config) => new RootScope(aliases, config); | ||
export const RootScope = RawRootScope; | ||
export const root = new RootScope({}); | ||
export const schemaScope = (aliases, config) => new SchemaScope(aliases, config); | ||
export class InternalSchemaScope extends InternalBaseScope { | ||
parseRoot(def, opts = {}) { | ||
const node = this.schema(def, this.finalizeRootArgs(opts, () => node)); | ||
return node; | ||
} | ||
} | ||
export const SchemaScope = InternalSchemaScope; | ||
export const root = new SchemaScope({}); | ||
export const schema = root.schema; | ||
@@ -366,3 +378,3 @@ export const node = root.node; | ||
}; | ||
export class RawRootModule extends DynamicBase { | ||
export class InternalRootModule extends DynamicBase { | ||
} | ||
@@ -369,0 +381,0 @@ const resolutionsOfModule = ($, typeSet) => { |
@@ -1,5 +0,38 @@ | ||
import { CompiledFunction } from "@ark/util"; | ||
import { CastableBase } from "@ark/util"; | ||
import type { BaseNode } from "../node.js"; | ||
import type { Discriminant } from "../roots/union.js"; | ||
import type { TraversalKind } from "./traversal.js"; | ||
export type CoercibleValue = string | number | boolean | null | undefined; | ||
export declare class CompiledFunction<args extends readonly string[]> extends CastableBase<{ | ||
[k in args[number]]: k; | ||
}> { | ||
readonly argNames: args; | ||
readonly body = ""; | ||
constructor(...args: args); | ||
indentation: number; | ||
indent(): this; | ||
dedent(): this; | ||
prop(key: PropertyKey, optional?: boolean): string; | ||
index(key: string | number, optional?: boolean): string; | ||
line(statement: string): this; | ||
const(identifier: string, expression: CoercibleValue): this; | ||
let(identifier: string, expression: CoercibleValue): this; | ||
set(identifier: string, expression: CoercibleValue): this; | ||
if(condition: string, then: (self: this) => this): this; | ||
elseIf(condition: string, then: (self: this) => this): this; | ||
else(then: (self: this) => this): this; | ||
/** Current index is "i" */ | ||
for(until: string, body: (self: this) => this, initialValue?: CoercibleValue): this; | ||
/** Current key is "k" */ | ||
forIn(object: string, body: (self: this) => this): this; | ||
block(prefix: string, contents: (self: this) => this, suffix?: string): this; | ||
return(expression?: CoercibleValue): this; | ||
compile<f extends (...args: { | ||
[i in keyof args]: never; | ||
}) => unknown>(): f; | ||
} | ||
export declare const compileSerializedValue: (value: unknown) => string; | ||
export declare const compileLiteralPropAccess: (key: PropertyKey, optional?: boolean) => string; | ||
export declare const serializeLiteralKey: (key: PropertyKey) => string; | ||
export declare const indexPropAccess: (key: string, optional?: boolean) => string; | ||
export interface InvokeOptions extends ReferenceOptions { | ||
@@ -6,0 +39,0 @@ arg?: string; |
@@ -1,2 +0,88 @@ | ||
import { CompiledFunction } from "@ark/util"; | ||
import { CastableBase, DynamicFunction, hasDomain, isDotAccessible, serializePrimitive } from "@ark/util"; | ||
import { registeredReference } from "./registry.js"; | ||
export class CompiledFunction extends CastableBase { | ||
argNames; | ||
body = ""; | ||
constructor(...args) { | ||
super(); | ||
this.argNames = args; | ||
for (const arg of args) { | ||
if (arg in this) { | ||
throw new Error(`Arg name '${arg}' would overwrite an existing property on FunctionBody`); | ||
} | ||
; | ||
this[arg] = arg; | ||
} | ||
} | ||
indentation = 0; | ||
indent() { | ||
this.indentation += 4; | ||
return this; | ||
} | ||
dedent() { | ||
this.indentation -= 4; | ||
return this; | ||
} | ||
prop(key, optional = false) { | ||
return compileLiteralPropAccess(key, optional); | ||
} | ||
index(key, optional = false) { | ||
return indexPropAccess(`${key}`, optional); | ||
} | ||
line(statement) { | ||
; | ||
this.body += `${" ".repeat(this.indentation)}${statement}\n`; | ||
return this; | ||
} | ||
const(identifier, expression) { | ||
this.line(`const ${identifier} = ${expression}`); | ||
return this; | ||
} | ||
let(identifier, expression) { | ||
return this.line(`let ${identifier} = ${expression}`); | ||
} | ||
set(identifier, expression) { | ||
return this.line(`${identifier} = ${expression}`); | ||
} | ||
if(condition, then) { | ||
return this.block(`if (${condition})`, then); | ||
} | ||
elseIf(condition, then) { | ||
return this.block(`else if (${condition})`, then); | ||
} | ||
else(then) { | ||
return this.block("else", then); | ||
} | ||
/** Current index is "i" */ | ||
for(until, body, initialValue = 0) { | ||
return this.block(`for (let i = ${initialValue}; ${until}; i++)`, body); | ||
} | ||
/** Current key is "k" */ | ||
forIn(object, body) { | ||
return this.block(`for (const k in ${object})`, body); | ||
} | ||
block(prefix, contents, suffix = "") { | ||
this.line(`${prefix} {`); | ||
this.indent(); | ||
contents(this); | ||
this.dedent(); | ||
return this.line(`}${suffix}`); | ||
} | ||
return(expression = "") { | ||
return this.line(`return ${expression}`); | ||
} | ||
compile() { | ||
return new DynamicFunction(...this.argNames, this.body); | ||
} | ||
} | ||
export const compileSerializedValue = (value) => hasDomain(value, "object") || typeof value === "symbol" ? | ||
registeredReference(value) | ||
: serializePrimitive(value); | ||
export const compileLiteralPropAccess = (key, optional = false) => { | ||
if (typeof key === "string" && isDotAccessible(key)) | ||
return `${optional ? "?" : ""}.${key}`; | ||
return indexPropAccess(serializeLiteralKey(key), optional); | ||
}; | ||
export const serializeLiteralKey = (key) => typeof key === "symbol" ? registeredReference(key) : JSON.stringify(key); | ||
export const indexPropAccess = (key, optional = false) => `${optional ? "?." : ""}[${key}]`; | ||
export class NodeCompiler extends CompiledFunction { | ||
@@ -3,0 +89,0 @@ traversalKind; |
@@ -37,4 +37,4 @@ import type { merge, show } from "@ark/util"; | ||
type prerequisiteOf<d extends DeclarationInput> = "prerequisite" extends keyof d ? d["prerequisite"] : unknown; | ||
export type attachmentsOf<d extends RawNodeDeclaration> = NarrowedAttachments<d> & d["inner"]; | ||
export interface RawNodeDeclaration { | ||
export type attachmentsOf<d extends BaseNodeDeclaration> = NarrowedAttachments<d> & d["inner"]; | ||
export interface BaseNodeDeclaration { | ||
kind: NodeKind; | ||
@@ -50,3 +50,3 @@ schema: unknown; | ||
} | ||
export type ownIntersectionResult<d extends RawNodeDeclaration> = Node<reducibleKindOf<d["kind"]>> | Disjoint; | ||
export type ownIntersectionResult<d extends BaseNodeDeclaration> = Node<reducibleKindOf<d["kind"]>> | Disjoint; | ||
export {}; |
@@ -1,2 +0,2 @@ | ||
import { type Entry, type Json, type JsonData, type PartialRecord, type indexOf, type keySet, type keySetOf, type listable, type propValueOf, type requireKeys, type show } from "@ark/util"; | ||
import { type Entry, type Json, type JsonData, type PartialRecord, type arrayIndexOf, type keySet, type keySetOf, type listable, type propValueOf, type requireKeys, type show } from "@ark/util"; | ||
import type { NodeConfig, ResolvedUnknownNodeConfig } from "../config.js"; | ||
@@ -7,5 +7,5 @@ import type { Declaration, Inner, Node, errorContext } from "../kinds.js"; | ||
import type { BaseRoot, schemaKindOrRightOf, schemaKindRightOf } from "../roots/root.js"; | ||
import type { RawRootScope } from "../scope.js"; | ||
import type { InternalBaseScope } from "../scope.js"; | ||
import type { StructureInner } from "../structure/structure.js"; | ||
import type { BaseErrorContext, BaseMeta, RawNodeDeclaration } from "./declare.js"; | ||
import type { BaseErrorContext, BaseMeta, BaseNodeDeclaration } from "./declare.js"; | ||
import type { Disjoint } from "./disjoint.js"; | ||
@@ -53,3 +53,3 @@ export declare const basisKinds: readonly ["unit", "proto", "domain"]; | ||
export interface IntersectionContext extends InternalIntersectionOptions { | ||
$: RawRootScope; | ||
$: InternalBaseScope; | ||
invert: boolean; | ||
@@ -73,3 +73,3 @@ } | ||
type PrecedenceByKind = { | ||
[i in indexOf<OrderedNodeKinds> as OrderedNodeKinds[i]]: i; | ||
[i in arrayIndexOf<OrderedNodeKinds> as OrderedNodeKinds[i]]: i; | ||
}; | ||
@@ -83,8 +83,8 @@ export declare const precedenceByKind: PrecedenceByKind; | ||
export declare const schemaKindsRightOf: <kind extends RootKind>(kind: kind) => schemaKindRightOf<kind>[]; | ||
export type KeySchemaDefinitions<d extends RawNodeDeclaration> = { | ||
export type KeySchemaDefinitions<d extends BaseNodeDeclaration> = { | ||
[k in keyRequiringSchemaDefinition<d>]: NodeKeyImplementation<d, k>; | ||
}; | ||
type keyRequiringSchemaDefinition<d extends RawNodeDeclaration> = Exclude<keyof d["normalizedSchema"], keyof BaseMeta>; | ||
type keyRequiringSchemaDefinition<d extends BaseNodeDeclaration> = Exclude<keyof d["normalizedSchema"], keyof BaseMeta>; | ||
export declare const defaultValueSerializer: (v: unknown) => JsonData; | ||
export type NodeKeyImplementation<d extends RawNodeDeclaration, k extends keyof d["normalizedSchema"], instantiated = k extends keyof d["inner"] ? Exclude<d["inner"][k], undefined> : never> = requireKeys<{ | ||
export type NodeKeyImplementation<d extends BaseNodeDeclaration, k extends keyof d["normalizedSchema"], instantiated = k extends keyof d["inner"] ? Exclude<d["inner"][k], undefined> : never> = requireKeys<{ | ||
preserveUndefined?: true; | ||
@@ -96,3 +96,3 @@ meta?: true; | ||
}, (d["normalizedSchema"][k] extends instantiated | undefined ? never : "parse") | ([instantiated] extends [listable<BaseNode>] ? "child" : never)>; | ||
interface CommonNodeImplementationInput<d extends RawNodeDeclaration> { | ||
interface CommonNodeImplementationInput<d extends BaseNodeDeclaration> { | ||
kind: d["kind"]; | ||
@@ -106,5 +106,5 @@ keys: KeySchemaDefinitions<d>; | ||
collapsibleKey?: keyof d["inner"]; | ||
reduce?: (inner: d["inner"], $: RawRootScope) => Node<d["reducibleTo"]> | Disjoint | undefined; | ||
reduce?: (inner: d["inner"], $: InternalBaseScope) => Node<d["reducibleTo"]> | Disjoint | undefined; | ||
} | ||
export interface UnknownNodeImplementation extends CommonNodeImplementationInput<RawNodeDeclaration> { | ||
export interface UnknownNodeImplementation extends CommonNodeImplementationInput<BaseNodeDeclaration> { | ||
defaults: ResolvedUnknownNodeConfig; | ||
@@ -116,3 +116,3 @@ intersectionIsOpen: boolean; | ||
export declare const compileErrorContext: (ctx: object) => string; | ||
export type nodeImplementationOf<d extends RawNodeDeclaration> = nodeImplementationInputOf<d> & { | ||
export type nodeImplementationOf<d extends BaseNodeDeclaration> = nodeImplementationInputOf<d> & { | ||
intersections: IntersectionMap<d["kind"]>; | ||
@@ -122,3 +122,3 @@ intersectionIsOpen: d["intersectionIsOpen"]; | ||
}; | ||
export type nodeImplementationInputOf<d extends RawNodeDeclaration> = CommonNodeImplementationInput<d> & { | ||
export type nodeImplementationInputOf<d extends BaseNodeDeclaration> = CommonNodeImplementationInput<d> & { | ||
intersections: IntersectionMap<d["kind"]>; | ||
@@ -147,3 +147,3 @@ defaults: nodeSchemaaultsImplementationInputFor<d["kind"]>; | ||
} | ||
export interface NarrowedAttachments<d extends RawNodeDeclaration> extends UnknownAttachments { | ||
export interface NarrowedAttachments<d extends BaseNodeDeclaration> extends UnknownAttachments { | ||
kind: d["kind"]; | ||
@@ -157,3 +157,3 @@ inner: d["inner"]; | ||
export declare const baseKeys: PartialRecord<string, propValueOf<KeySchemaDefinitions<any>>>; | ||
export declare const implementNode: <d extends RawNodeDeclaration = never>(_: nodeImplementationInputOf<d>) => nodeImplementationOf<d>; | ||
export declare const implementNode: <d extends BaseNodeDeclaration = never>(_: nodeImplementationInputOf<d>) => nodeImplementationOf<d>; | ||
export {}; |
@@ -1,2 +0,3 @@ | ||
import { compileSerializedValue, flatMorph, printable, throwParseError } from "@ark/util"; | ||
import { flatMorph, printable, throwParseError } from "@ark/util"; | ||
import { compileSerializedValue } from "./compile.js"; | ||
import { isNode } from "./utils.js"; | ||
@@ -3,0 +4,0 @@ export const basisKinds = ["unit", "proto", "domain"]; |
@@ -6,3 +6,3 @@ import { Hkt, type array, type conform, type intersectArrays, type isAny, type show } from "@ark/util"; | ||
import type { BaseRoot } from "../roots/root.js"; | ||
import type { RawRootScope } from "../scope.js"; | ||
import type { InternalBaseScope } from "../scope.js"; | ||
import { Disjoint } from "./disjoint.js"; | ||
@@ -36,4 +36,4 @@ import type { IntersectionContext, RootKind } from "./implement.js"; | ||
type InternalNodeIntersection<ctx> = <l extends BaseNode, r extends BaseNode>(l: l, r: r, ctx: ctx) => l["kind"] | r["kind"] extends RootKind ? BaseRoot | Disjoint : BaseNode | Disjoint | null; | ||
export declare const intersectNodesRoot: InternalNodeIntersection<RawRootScope>; | ||
export declare const pipeNodesRoot: InternalNodeIntersection<RawRootScope>; | ||
export declare const intersectNodesRoot: InternalNodeIntersection<InternalBaseScope>; | ||
export declare const pipeNodesRoot: InternalNodeIntersection<InternalBaseScope>; | ||
export declare const intersectNodes: InternalNodeIntersection<IntersectionContext>; | ||
@@ -40,0 +40,0 @@ export declare const pipeFromMorph: (from: MorphNode, to: BaseRoot, ctx: IntersectionContext) => MorphNode | Disjoint; |
@@ -6,3 +6,3 @@ import { type array, type mutable, type requireKeys, type show } from "@ark/util"; | ||
import type { BaseRoot } from "../roots/root.js"; | ||
import type { RawRootModule, RawRootScope } from "../scope.js"; | ||
import type { InternalBaseScope, InternalRootModule } from "../scope.js"; | ||
import type { ArkError } from "./errors.js"; | ||
@@ -29,5 +29,5 @@ export declare const makeRootAndArrayPropertiesMutable: <o extends object>(o: o) => makeRootAndArrayPropertiesMutable<o>; | ||
root: BaseRoot; | ||
scope: RawRootScope; | ||
scope: InternalBaseScope; | ||
generic: GenericRoot; | ||
module: RawRootModule; | ||
module: InternalRootModule; | ||
error: ArkError; | ||
@@ -34,0 +34,0 @@ } |
@@ -34,4 +34,4 @@ import { BaseConstraint } from "../constraint.js"; | ||
traverseApply: TraverseApply<object>; | ||
protected _transform(mapper: DeepNodeTransformation, ctx: DeepNodeTransformContext): import("../node.js").BaseNode<import("../shared/declare.js").RawNodeDeclaration> | null; | ||
get flatRefs(): import("../node.js").FlatRef<BaseRoot<import("../roots/root.js").RawRootDeclaration>>[]; | ||
protected _transform(mapper: DeepNodeTransformation, ctx: DeepNodeTransformContext): import("../node.js").BaseNode<import("../shared/declare.js").BaseNodeDeclaration> | null; | ||
get flatRefs(): import("../node.js").FlatRef<BaseRoot<import("../roots/root.js").InternalRootDeclaration>>[]; | ||
compile(): void; | ||
@@ -38,0 +38,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { append, printable, stringAndSymbolicEntriesOf, throwParseError } from "@ark/util"; | ||
import { $ark, append, printable, stringAndSymbolicEntriesOf, throwParseError } from "@ark/util"; | ||
import { BaseConstraint } from "../constraint.js"; | ||
@@ -56,3 +56,3 @@ import { flatRef } from "../node.js"; | ||
export class IndexNode extends BaseConstraint { | ||
impliedBasis = $ark.intrinsic.object; | ||
impliedBasis = $ark.intrinsic.object.internal; | ||
expression = `[${this.signature.expression}]: ${this.value.expression}`; | ||
@@ -59,0 +59,0 @@ traverseAllows = (data, ctx) => stringAndSymbolicEntriesOf(data).every(entry => { |
@@ -6,3 +6,3 @@ import { type Key } from "@ark/util"; | ||
import type { BaseRoot } from "../roots/root.js"; | ||
import type { NodeCompiler } from "../shared/compile.js"; | ||
import { type NodeCompiler } from "../shared/compile.js"; | ||
import type { BaseMeta } from "../shared/declare.js"; | ||
@@ -37,3 +37,3 @@ import { Disjoint } from "../shared/disjoint.js"; | ||
get flatRefs(): FlatRef[]; | ||
protected _transform(mapper: DeepNodeTransformation, ctx: DeepNodeTransformContext): import("../node.js").BaseNode<import("../shared/declare.js").RawNodeDeclaration> | null; | ||
protected _transform(mapper: DeepNodeTransformation, ctx: DeepNodeTransformContext): import("../node.js").BaseNode<import("../shared/declare.js").BaseNodeDeclaration> | null; | ||
private defaultValueMorphs; | ||
@@ -40,0 +40,0 @@ private defaultValueMorphsReference; |
@@ -1,6 +0,8 @@ | ||
import { append, compileSerializedValue, printable, registeredReference, throwParseError, unset } from "@ark/util"; | ||
import { $ark, append, printable, throwParseError, unset } from "@ark/util"; | ||
import { BaseConstraint } from "../constraint.js"; | ||
import { flatRef } from "../node.js"; | ||
import { compileSerializedValue } from "../shared/compile.js"; | ||
import { Disjoint } from "../shared/disjoint.js"; | ||
import { intersectNodes } from "../shared/intersections.js"; | ||
import { registeredReference } from "../shared/registry.js"; | ||
export const intersectProps = (l, r, ctx) => { | ||
@@ -44,3 +46,3 @@ if (l.key !== r.key) | ||
optional = this.kind === "optional"; | ||
impliedBasis = $ark.intrinsic.object; | ||
impliedBasis = $ark.intrinsic.object.internal; | ||
serializedKey = compileSerializedValue(this.key); | ||
@@ -47,0 +49,0 @@ compiledKey = typeof this.key === "string" ? this.key : this.serializedKey; |
@@ -58,3 +58,3 @@ import { type array, type satisfy } from "@ark/util"; | ||
compile(js: NodeCompiler): void; | ||
protected _transform(mapper: DeepNodeTransformation, ctx: DeepNodeTransformContext): import("../node.js").BaseNode<import("../shared/declare.js").RawNodeDeclaration> | null; | ||
protected _transform(mapper: DeepNodeTransformation, ctx: DeepNodeTransformContext): import("../node.js").BaseNode<import("../shared/declare.js").BaseNodeDeclaration> | null; | ||
tuple: SequenceTuple; | ||
@@ -61,0 +61,0 @@ expression: string; |
@@ -35,3 +35,3 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) { | ||
}; | ||
import { append, cached, throwInternalError, throwParseError } from "@ark/util"; | ||
import { $ark, append, cached, throwInternalError, throwParseError } from "@ark/util"; | ||
import { BaseConstraint } from "../constraint.js"; | ||
@@ -191,3 +191,3 @@ import { appendUniqueFlatRefs, flatRef } from "../node.js"; | ||
} | ||
impliedBasis = (__runInitializers(this, _instanceExtraInitializers), $ark.intrinsic.Array); | ||
impliedBasis = (__runInitializers(this, _instanceExtraInitializers), $ark.intrinsic.Array.internal); | ||
prefix = this.inner.prefix ?? []; | ||
@@ -239,3 +239,3 @@ optionals = this.inner.optionals ?? []; | ||
// key, so we just use the same matcher for variadic | ||
append(element.flatRefs.map(ref => flatRef([$ark.intrinsic.nonNegativeIntegerString, ...ref.path], ref.node)), flatRef([$ark.intrinsic.nonNegativeIntegerString], element)))); | ||
append(element.flatRefs.map(ref => flatRef([$ark.intrinsic.nonNegativeIntegerString.internal, ...ref.path], ref.node)), flatRef([$ark.intrinsic.nonNegativeIntegerString.internal], element)))); | ||
return refs; | ||
@@ -268,3 +268,3 @@ } | ||
_transform(mapper, ctx) { | ||
ctx.path.push($ark.intrinsic.nonNegativeIntegerString); | ||
ctx.path.push($ark.intrinsic.nonNegativeIntegerString.internal); | ||
const result = super._transform(mapper, ctx); | ||
@@ -271,0 +271,0 @@ ctx.path.pop(); |
@@ -0,3 +1,4 @@ | ||
import { type RegisteredReference } from "../shared/registry.js"; | ||
export declare const arrayIndexSource = "^(?:0|[1-9]\\d*)$"; | ||
export declare const arrayIndexMatcher: RegExp; | ||
export declare const arrayIndexMatcherReference: `$ark.${string}`; | ||
export declare const arrayIndexMatcherReference: RegisteredReference; |
@@ -1,4 +0,4 @@ | ||
import { registeredReference } from "@ark/util"; | ||
import { registeredReference } from "../shared/registry.js"; | ||
export const arrayIndexSource = `^(?:0|[1-9]\\d*)$`; | ||
export const arrayIndexMatcher = new RegExp(arrayIndexSource); | ||
export const arrayIndexMatcherReference = registeredReference(arrayIndexMatcher); |
@@ -1,10 +0,12 @@ | ||
import { type array, type Key, type RegisteredReference } from "@ark/util"; | ||
import { type array, type join, type Key, type typeToString } from "@ark/util"; | ||
import { BaseConstraint } from "../constraint.js"; | ||
import type { InferredRoot } from "../inference.js"; | ||
import type { NonNegativeIntegerString } from "../keywords/internal.js"; | ||
import type { TypeKey, TypePath } from "../node.js"; | ||
import type { BaseRoot } from "../roots/root.js"; | ||
import type { RawRootScope } from "../scope.js"; | ||
import type { TypeIndexer, TypeKey } from "../node.js"; | ||
import { type BaseRoot } from "../roots/root.js"; | ||
import type { InternalBaseScope } from "../scope.js"; | ||
import type { NodeCompiler } from "../shared/compile.js"; | ||
import type { BaseMeta, declareNode } from "../shared/declare.js"; | ||
import { type nodeImplementationOf, type StructuralKind } from "../shared/implement.js"; | ||
import { type RegisteredReference } from "../shared/registry.js"; | ||
import type { TraversalContext, TraversalKind, TraverseAllows, TraverseApply } from "../shared/traversal.js"; | ||
@@ -52,6 +54,9 @@ import type { IndexNode, IndexSchema } from "./indexed.js"; | ||
keyof(): BaseRoot; | ||
get(key: TypeKey, ...tail: TypePath): BaseRoot; | ||
assertHasKeys(keys: array<TypeKey>): undefined; | ||
get(indexer: TypeIndexer, ...path: array<TypeIndexer>): BaseRoot; | ||
readonly exhaustive: boolean; | ||
pick(...keys: array<BaseRoot | Key>): StructureNode; | ||
omit(...keys: array<BaseRoot | Key>): StructureNode; | ||
merge(r: StructureNode): StructureNode; | ||
private filterKeys; | ||
traverseAllows: TraverseAllows<object>; | ||
@@ -64,4 +69,3 @@ traverseApply: TraverseApply<object>; | ||
export declare const structureImplementation: nodeImplementationOf<StructureDeclaration>; | ||
export declare const writeRawNumberIndexMessage: (indexExpression: string, sequenceExpression: string) => string; | ||
export declare const writeBadKeyAccessMessage: (key: TypeKey, structuralExpression: string) => string; | ||
export declare const writeNumberIndexMessage: (indexExpression: string, sequenceExpression: string) => string; | ||
export type NormalizedIndex = { | ||
@@ -72,4 +76,8 @@ index?: IndexNode; | ||
/** extract enumerable named props from an index signature */ | ||
export declare const normalizeIndex: (signature: BaseRoot, value: BaseRoot, $: RawRootScope) => NormalizedIndex; | ||
export type indexOf<o> = o extends array ? (number extends o["length"] ? NonNegativeIntegerString : never) | { | ||
export declare const normalizeIndex: (signature: BaseRoot, value: BaseRoot, $: InternalBaseScope) => NormalizedIndex; | ||
export type toArkKey<o, k extends keyof o> = k extends number ? [ | ||
o, | ||
number | ||
] extends [array, k] ? NonNegativeIntegerString : `${k}` : k; | ||
export type arkKeyOf<o> = o extends array ? (number extends o["length"] ? NonNegativeIntegerString : never) | { | ||
[k in keyof o]-?: k extends `${infer index extends number}` ? index | k : never; | ||
@@ -79,2 +87,8 @@ }[keyof o & `${number}`] : { | ||
}[keyof o]; | ||
export type indexInto<o, k extends indexOf<o>> = o[Extract<k extends NonNegativeIntegerString ? number : k, keyof o>]; | ||
export type getArkKey<o, k extends arkKeyOf<o>> = o[Extract<k extends NonNegativeIntegerString ? number : k, keyof o>]; | ||
export declare const typeKeyToString: (k: TypeKey) => string; | ||
export type typeKeyToString<k extends TypeKey> = typeToString<k extends InferredRoot<infer t> ? t : k>; | ||
export declare const writeInvalidKeysMessage: <o extends string, keys extends array<TypeKey>>(o: o, keys: keys) => writeInvalidKeysMessage<o, keys>; | ||
export type writeInvalidKeysMessage<o extends string, keys extends array<TypeKey>> = `Key${keys["length"] extends 1 ? "" : "s"} ${join<{ | ||
[i in keyof keys]: typeKeyToString<keys[i]>; | ||
}, ", ">} ${keys["length"] extends 1 ? "does" : "do"} not exist on ${o}`; |
@@ -35,7 +35,9 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) { | ||
}; | ||
import { append, cached, flatMorph, printable, registeredReference, spliterate, throwParseError } from "@ark/util"; | ||
import { $ark, append, cached, flatMorph, printable, spliterate, throwParseError } from "@ark/util"; | ||
import { BaseConstraint, constraintKeyParser, flattenConstraints, intersectConstraints } from "../constraint.js"; | ||
import { typeOrTermExtends } from "../roots/root.js"; | ||
import { Disjoint } from "../shared/disjoint.js"; | ||
import { implementNode } from "../shared/implement.js"; | ||
import { intersectNodesRoot } from "../shared/intersections.js"; | ||
import { registeredReference } from "../shared/registry.js"; | ||
import { hasArkKind, makeRootAndArrayPropertiesMutable } from "../shared/utils.js"; | ||
@@ -54,3 +56,3 @@ import { arrayIndexMatcherReference } from "./shared.js"; | ||
} | ||
impliedBasis = (__runInitializers(this, _instanceExtraInitializers), $ark.intrinsic.object); | ||
impliedBasis = (__runInitializers(this, _instanceExtraInitializers), $ark.intrinsic.object.internal); | ||
impliedSiblings = this.children.flatMap(n => n.impliedSiblings ?? []); | ||
@@ -78,7 +80,12 @@ props = this.required ? | ||
} | ||
get(key, ...tail) { | ||
assertHasKeys(keys) { | ||
const invalidKeys = keys.filter(k => !typeOrTermExtends(k, this.keyof())); | ||
if (invalidKeys.length) { | ||
return throwParseError(writeInvalidKeysMessage(this.expression, invalidKeys)); | ||
} | ||
} | ||
get(indexer, ...path) { | ||
let value; | ||
let required = false; | ||
if (hasArkKind(key, "root") && key.hasKind("unit")) | ||
key = key.unit; | ||
const key = indexerToKey(indexer); | ||
if ((typeof key === "string" || typeof key === "symbol") && | ||
@@ -90,7 +97,7 @@ this.propsByKey[key]) { | ||
this.index?.forEach(n => { | ||
if (n.signature.includes(key)) | ||
if (typeOrTermExtends(key, n.signature)) | ||
value = value?.and(n.value) ?? n.value; | ||
}); | ||
if (this.sequence && | ||
$ark.intrinsic.nonNegativeIntegerString.includes(key)) { | ||
typeOrTermExtends(key, $ark.intrinsic.nonNegativeIntegerString)) { | ||
if (hasArkKind(key, "root")) { | ||
@@ -122,15 +129,20 @@ if (this.sequence.variadic) | ||
key.extends($ark.intrinsic.number)) { | ||
return throwParseError(writeRawNumberIndexMessage(key.expression, this.sequence.expression)); | ||
return throwParseError(writeNumberIndexMessage(key.expression, this.sequence.expression)); | ||
} | ||
return throwParseError(writeBadKeyAccessMessage(key, this.expression)); | ||
return throwParseError(writeInvalidKeysMessage(this.expression, [key])); | ||
} | ||
const result = value.get(...tail); | ||
const result = value.get(...path); | ||
return required ? result : result.or($ark.intrinsic.undefined); | ||
} | ||
exhaustive = this.undeclared !== undefined || this.index !== undefined; | ||
pick(...keys) { | ||
this.assertHasKeys(keys); | ||
return this.$.node("structure", this.filterKeys("pick", keys)); | ||
} | ||
omit(...keys) { | ||
return this.$.node("structure", omitFromInner(this.inner, keys)); | ||
this.assertHasKeys(keys); | ||
return this.$.node("structure", this.filterKeys("omit", keys)); | ||
} | ||
merge(r) { | ||
const inner = makeRootAndArrayPropertiesMutable(omitFromInner(this.inner, [r.keyof()])); | ||
const inner = makeRootAndArrayPropertiesMutable(this.filterKeys("omit", [r.keyof()])); | ||
if (r.required) | ||
@@ -150,2 +162,16 @@ inner.required = append(inner.required, r.required); | ||
} | ||
filterKeys(operation, keys) { | ||
const result = { ...this.inner }; | ||
const includeKey = (key) => { | ||
const matchesKey = keys.some(k => typeOrTermExtends(key, k)); | ||
return operation === "pick" ? matchesKey : !matchesKey; | ||
}; | ||
if (result.required) | ||
result.required = result.required.filter(prop => includeKey(prop.key)); | ||
if (result.optional) | ||
result.optional = result.optional.filter(prop => includeKey(prop.key)); | ||
if (result.index) | ||
result.index = result.index.filter(index => includeKey(index.signature)); | ||
return result; | ||
} | ||
traverseAllows = (data, ctx) => this._traverse("Allows", data, ctx); | ||
@@ -286,18 +312,8 @@ traverseApply = (data, ctx) => this._traverse("Apply", data, ctx); | ||
export { StructureNode }; | ||
const omitFromInner = (inner, keys) => { | ||
const result = { ...inner }; | ||
keys.forEach(k => { | ||
if (result.required) { | ||
result.required = result.required.filter(b => hasArkKind(k, "root") ? !k.allows(b.key) : k !== b.key); | ||
} | ||
if (result.optional) { | ||
result.optional = result.optional.filter(b => hasArkKind(k, "root") ? !k.allows(b.key) : k !== b.key); | ||
} | ||
if (result.index && hasArkKind(k, "root")) { | ||
// we only have to filter index nodes if the input was a node, as | ||
// literal keys should never subsume an index | ||
result.index = result.index.filter(n => !n.signature.extends(k)); | ||
} | ||
}); | ||
return result; | ||
const indexerToKey = (indexable) => { | ||
if (hasArkKind(indexable, "root") && indexable.hasKind("unit")) | ||
indexable = indexable.unit; | ||
if (typeof indexable === "number") | ||
indexable = `${indexable}`; | ||
return indexable; | ||
}; | ||
@@ -433,4 +449,3 @@ const createStructuralWriter = (childStringProp) => (node) => { | ||
}); | ||
export const writeRawNumberIndexMessage = (indexExpression, sequenceExpression) => `${indexExpression} is not allowed as an array index on ${sequenceExpression}. Use the 'nonNegativeIntegerString' keyword instead.`; | ||
export const writeBadKeyAccessMessage = (key, structuralExpression) => `${printable(key)} does not exist on ${structuralExpression}`; | ||
export const writeNumberIndexMessage = (indexExpression, sequenceExpression) => `${indexExpression} is not allowed as an array index on ${sequenceExpression}. Use the 'nonNegativeIntegerString' keyword instead.`; | ||
/** extract enumerable named props from an index signature */ | ||
@@ -451,1 +466,3 @@ export const normalizeIndex = (signature, value, $) => { | ||
}; | ||
export const typeKeyToString = (k) => hasArkKind(k, "root") ? k.expression : printable(k); | ||
export const writeInvalidKeysMessage = (o, keys) => `Key${keys.length === 1 ? "" : "s"} ${keys.map(typeKeyToString).join(", ")} ${keys.length === 1 ? "does" : "do"} not exist on ${o}`; |
{ | ||
"name": "@ark/schema", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"license": "MIT", | ||
@@ -27,3 +27,3 @@ "author": { | ||
"dependencies": { | ||
"@ark/util": "0.1.0" | ||
"@ark/util": "0.1.1" | ||
}, | ||
@@ -30,0 +30,0 @@ "publishConfig": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
375823
129
8177
+ Added@ark/util@0.1.1(transitive)
- Removed@ark/util@0.1.0(transitive)
Updated@ark/util@0.1.1