Comparing version 2.0.0-rc.11 to 2.0.0-rc.12
@@ -1,2 +0,2 @@ | ||
import type { Branded, constrain, constraint, Constraints, Default, Literal, Narrowed, normalizeLimit, Optional } from "../inference.ts"; | ||
import type { Branded, constraint, Default, Literal, Narrowed, normalizeLimit, of, Optional } from "../inference.ts"; | ||
export type AtOrAfter<rule> = { | ||
@@ -15,12 +15,12 @@ atOrAfter: constraint<rule>; | ||
export declare namespace Date { | ||
type atOrAfter<rule> = constrain<Date, AtOrAfter<rule>>; | ||
type after<rule> = constrain<Date, After<rule>>; | ||
type atOrBefore<rule> = constrain<Date, AtOrBefore<rule>>; | ||
type before<rule> = constrain<Date, Before<rule>>; | ||
type narrowed = constrain<Date, Narrowed>; | ||
type optional = constrain<Date, Optional>; | ||
type defaultsTo<rule> = constrain<Date, Default<rule>>; | ||
type branded<rule> = constrain<Date, Branded<rule>>; | ||
type literal<rule> = constrain<Date, Literal<rule>>; | ||
type is<constraints extends Constraints> = constrain<Date, constraints>; | ||
type atOrAfter<rule> = of<Date, AtOrAfter<rule>>; | ||
type after<rule> = of<Date, After<rule>>; | ||
type atOrBefore<rule> = of<Date, AtOrBefore<rule>>; | ||
type before<rule> = of<Date, Before<rule>>; | ||
type narrowed = of<Date, Narrowed>; | ||
type optional = of<Date, Optional>; | ||
type defaultsTo<rule> = of<Date, Default<rule>>; | ||
type branded<rule> = of<Date, Branded<rule>>; | ||
type literal<rule> = of<Date, Literal<rule>>; | ||
type is<attributes> = of<Date, attributes>; | ||
type afterSchemaToConstraint<schema, rule> = schema extends { | ||
@@ -32,3 +32,3 @@ exclusive: true; | ||
} ? Before<normalizeLimit<rule>> : AtOrBefore<normalizeLimit<rule>>; | ||
type withConstraint<constraint> = constraint extends After<infer rule> ? after<rule> : constraint extends Before<infer rule> ? before<rule> : constraint extends AtOrAfter<infer rule> ? atOrAfter<rule> : constraint extends AtOrBefore<infer rule> ? atOrBefore<rule> : constraint extends Optional ? optional : constraint extends Default<infer rule> ? defaultsTo<rule> : constraint extends Narrowed ? narrowed : never; | ||
type applyAttribute<attribute> = attribute extends After<infer rule> ? after<rule> : attribute extends Before<infer rule> ? before<rule> : attribute extends AtOrAfter<infer rule> ? atOrAfter<rule> : attribute extends AtOrBefore<infer rule> ? atOrBefore<rule> : attribute extends Optional ? optional : attribute extends Default<infer rule> ? defaultsTo<rule> : attribute extends Branded<infer rule> ? branded<rule> : never; | ||
} |
import type { ArkError, ArkErrors, Constraint, constraintKindOf, Morph, NodeSchema } from "@ark/schema"; | ||
import { type anyOrNever, type array, type conform, type equals, type Hkt, type intersectArrays, type isSafelyMappable, type leftIfEqual, type objectKindOf, type Primitive, type show } from "@ark/util"; | ||
import { type anyOrNever, type array, type conform, type dict, type equals, type Hkt, type intersectArrays, type isSafelyMappable, type leftIfEqual, type Primitive, type show } from "@ark/util"; | ||
import type { Type } from "../type.ts"; | ||
@@ -19,6 +19,11 @@ import type { arkPrototypes } from "./constructors/constructors.ts"; | ||
}; | ||
export declare const constrained: " arkConstrained"; | ||
export type constrained = typeof constrained; | ||
export type constrain<base, constraints extends Constraints> = base & { | ||
[constrained]: constraints; | ||
export interface BaseAttributes { | ||
predicate?: dict<1>; | ||
default?: unknown; | ||
optional?: 1; | ||
} | ||
export declare const attributes: " arkAttributes"; | ||
export type attributes = typeof attributes; | ||
export type of<base, attributes> = base & { | ||
[attributes]: [base, attributes]; | ||
}; | ||
@@ -58,35 +63,8 @@ export type LimitLiteral = number | DateLiteral; | ||
}; | ||
export type applyConstraintSchema<t, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = applyConstraint<t, schemaToConstraint<kind, schema>>; | ||
export type applyConstraint<t, constraint> = t extends InferredMorph<infer i, infer o> ? (In: leftIfEqual<i, _applyConstraint<i, constraint>>) => o : leftIfEqual<t, _applyConstraint<t, constraint>>; | ||
type _applyConstraint<t, constraint> = parseConstraints<t> extends ([ | ||
infer base, | ||
infer constraints extends Constraints | ||
]) ? [ | ||
export type applyConstraintSchema<t, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = applyAttribute<t, schemaToConstraint<kind, schema>>; | ||
export type applyAttribute<t, attribute> = t extends InferredMorph<infer i, infer o> ? (In: leftIfEqual<i, _applyAttribute<i, attribute>>) => o : leftIfEqual<t, _applyAttribute<t, attribute>>; | ||
type _applyAttribute<t, attribute> = t extends null | undefined ? t : t extends of<infer base, infer attributes> ? [ | ||
number, | ||
base | ||
] extends [base, number] ? number.is<constraint & constraints> : [string, base] extends [base, string] ? string.is<constraint & constraints> : [Date, base] extends [base, Date] ? Date.is<constraint & constraints> : constrain<base, constraints & constraint> : [number, t] extends [t, number] ? number.withConstraint<constraint> : [string, t] extends [t, string] ? string.withConstraint<constraint> : [Date, t] extends [t, Date] ? Date.withConstraint<constraint> : constrain<t, conform<constraint, Constraints>>; | ||
export type parseConstraints<t> = t extends constrain<infer base, infer constraints> ? equals<t, number & { | ||
[constrained]: constraints; | ||
}> extends true ? [ | ||
number, | ||
constraints | ||
] : equals<t, string & { | ||
[constrained]: constraints; | ||
}> extends true ? [ | ||
string, | ||
constraints | ||
] : equals<t, bigint & { | ||
[constrained]: constraints; | ||
}> extends true ? [ | ||
bigint, | ||
constraints | ||
] : equals<t, symbol & { | ||
[constrained]: constraints; | ||
}> extends true ? [ | ||
symbol, | ||
constraints | ||
] : objectKindOf<t> extends infer kind ? kind extends BuiltinTerminalObjectKind ? [ | ||
arkPrototypes.instanceOf<kind>, | ||
constraints | ||
] : kind extends "Array" ? null : kind extends undefined ? [Omit<base, constrained>, constraints] : [base, constraints] : never : null; | ||
] extends [base, number] ? number.is<attribute & attributes> : [string, base] extends [base, string] ? string.is<attribute & attributes> : [Date, base] extends [base, Date] ? Date.is<attribute & attributes> : of<base, attributes & attribute> : [number, t] extends [t, number] ? number.applyAttribute<attribute> : [string, t] extends [t, string] ? string.applyAttribute<attribute> : [Date, t] extends [t, Date] ? Date.applyAttribute<attribute> : of<t, conform<attribute, Constraints>>; | ||
export type normalizePrimitiveConstraintRoot<schema extends NodeSchema<Constraint.PrimitiveKind>> = "rule" extends keyof schema ? conform<schema["rule"], PropertyKey> : conform<schema, PropertyKey>; | ||
@@ -137,25 +115,3 @@ type minLengthSchemaToConstraint<schema, rule> = schema extends { | ||
type finalizeDistillation<t, distilled> = equals<t, distilled> extends true ? t : distilled; | ||
export type includesMorphs<t> = [ | ||
_distill<t, { | ||
endpoint: "in"; | ||
branded: true; | ||
}>, | ||
_distill<t, { | ||
endpoint: "out"; | ||
branded: true; | ||
}> | ||
] extends ([ | ||
_distill<t, { | ||
endpoint: "out"; | ||
branded: true; | ||
}>, | ||
_distill<t, { | ||
endpoint: "in"; | ||
branded: true; | ||
}> | ||
]) ? false : true; | ||
type _distill<t, opts extends distill.Options> = t extends undefined ? t : [t] extends [anyOrNever] ? t : parseConstraints<t> extends ([ | ||
infer base, | ||
infer constraints extends Constraints | ||
]) ? opts["branded"] extends true ? constrain<_distill<base, opts>, constraints> : _distill<base, opts> : unknown extends t ? unknown : t extends TerminallyInferredObject | Primitive ? t : t extends InferredMorph<infer i, infer o> ? opts["branded"] extends true ? distillIo<i, o, opts> : distillUnbrandedIo<t, i, o, opts> : t extends array ? distillArray<t, opts> : t extends Function ? t : isSafelyMappable<t> extends true ? distillMappable<t, opts> : t; | ||
type _distill<t, opts extends distill.Options> = t extends undefined ? t : [t] extends [anyOrNever] ? t : t extends of<infer base, infer attributes> ? opts["branded"] extends true ? of<_distill<base, opts>, attributes> : _distill<base, opts> : unknown extends t ? unknown : t extends TerminallyInferredObject | Primitive ? t : t extends InferredMorph<infer i, infer o> ? opts["branded"] extends true ? distillIo<i, o, opts> : distillUnbrandedIo<t, i, o, opts> : t extends array ? distillArray<t, opts> : t extends Function ? t : isSafelyMappable<t> extends true ? distillMappable<t, opts> : t; | ||
type distillMappable<o, opts extends distill.Options> = opts["endpoint"] extends "in" ? show<{ | ||
@@ -170,15 +126,14 @@ [k in keyof o as k extends inferredOptionalOrDefaultKeyOf<o> ? never : k]: _distill<o[k], opts>; | ||
}>; | ||
type distillUnbrandedIo<t extends InferredMorph, i, o extends Out, opts extends distill.Options> = t extends (InferredMorph<constrain<infer constrainedIn, any>, Out<constrain<infer constrainedOut, any>>>) ? distillIo<constrainedIn, o extends To ? To<constrainedOut> : Out<constrainedOut>, opts> : t extends InferredMorph<constrain<infer constrainedIn, any>> ? distillIo<constrainedIn, o, opts> : t extends InferredMorph<any, Out<constrain<infer constrainedOut, any>>> ? distillIo<i, o extends To ? To<constrainedOut> : Out<constrainedOut>, opts> : distillIo<i, o, opts>; | ||
type distillUnbrandedIo<t extends InferredMorph, i, o extends Out, opts extends distill.Options> = t extends (InferredMorph<of<infer constrainedIn, any>, Out<of<infer constrainedOut, any>>>) ? distillIo<constrainedIn, o extends To ? To<constrainedOut> : Out<constrainedOut>, opts> : t extends InferredMorph<of<infer constrainedIn, any>> ? distillIo<constrainedIn, o, opts> : t extends InferredMorph<any, Out<of<infer constrainedOut, any>>> ? distillIo<i, o extends To ? To<constrainedOut> : Out<constrainedOut>, opts> : distillIo<i, o, opts>; | ||
type distillIo<i, o extends Out, opts extends distill.Options> = opts["endpoint"] extends "in" ? _distill<i, opts> : opts["endpoint"] extends "out.introspectable" ? o extends To<infer validatedOut> ? _distill<validatedOut, opts> : unknown : opts["endpoint"] extends "out" ? _distill<o[1], opts> : _distill<o[1], opts> extends infer r ? o extends To ? (In: i) => To<r> : (In: i) => Out<r> : never; | ||
type inferredOptionalOrDefaultKeyOf<o> = inferredDefaultKeyOf<o> | inferredOptionalKeyOf<o>; | ||
type inferredDefaultKeyOf<o> = keyof o extends infer k ? k extends keyof o ? [ | ||
o[k] | ||
] extends [anyOrNever] ? never : o[k] extends InferredDefault ? k : never : never : never; | ||
type inferredOptionalKeyOf<o> = keyof o extends infer k ? k extends keyof o ? [ | ||
o[k] | ||
] extends [anyOrNever] ? never : o[k] extends InferredOptional ? k : never : never : never; | ||
type inOfValueExtends<v, t> = [ | ||
v | ||
] extends [anyOrNever] ? false : [v] extends [t] ? true : [v] extends [InferredMorph<infer i>] ? inOfValueExtends<i, t> : false; | ||
type inferredDefaultKeyOf<o> = keyof o extends infer k ? k extends keyof o ? inOfValueExtends<o[k], InferredDefault> extends true ? k : never : never : never; | ||
type inferredOptionalKeyOf<o> = keyof o extends infer k ? k extends keyof o ? inOfValueExtends<o[k], InferredOptional> extends true ? k : never : never : never; | ||
type distillArray<t extends array, opts extends distill.Options> = t[number][] extends t ? alignReadonly<_distill<t[number], opts>[], t> : distillNonArraykeys<t, alignReadonly<_distillArray<[...t], opts, []>, t>, opts>; | ||
type alignReadonly<result extends unknown[], original extends array> = original extends unknown[] ? result : Readonly<result>; | ||
type distillNonArraykeys<originalArray extends array, distilledArray, opts extends distill.Options> = keyof originalArray extends keyof distilledArray | constrained ? distilledArray : distilledArray & _distill<{ | ||
[k in keyof originalArray as k extends (keyof distilledArray | (opts["branded"] extends true ? never : constrained)) ? never : k]: originalArray[k]; | ||
type distillNonArraykeys<originalArray extends array, distilledArray, opts extends distill.Options> = keyof originalArray extends keyof distilledArray | attributes ? distilledArray : distilledArray & _distill<{ | ||
[k in keyof originalArray as k extends (keyof distilledArray | (opts["branded"] extends true ? never : attributes)) ? never : k]: originalArray[k]; | ||
}, opts>; | ||
@@ -192,4 +147,4 @@ type _distillArray<t extends array, opts extends distill.Options, prefix extends array> = t extends readonly [infer head, ...infer tail] ? _distillArray<tail, opts, [...prefix, _distill<head, opts>]> : [...prefix, ...distillPostfix<t, opts>]; | ||
type TerminallyInferredObject = arkPrototypes.instanceOf<BuiltinTerminalObjectKind> | ArkEnv.prototypes; | ||
export type inferPredicate<t, predicate> = predicate extends (data: any, ...args: any[]) => data is infer narrowed ? t extends constrain<unknown, infer constraints> ? applyConstraintSchema<constrain<narrowed, constraints>, "predicate", any> : applyConstraintSchema<narrowed, "predicate", any> : applyConstraintSchema<t, "predicate", any>; | ||
export type constrainWithPredicate<t> = t extends constrain<unknown, infer constraints> ? applyConstraintSchema<constrain<t, constraints>, "predicate", any> : applyConstraintSchema<t, "predicate", any>; | ||
export type inferPredicate<t, predicate> = predicate extends (data: any, ...args: any[]) => data is infer narrowed ? t extends of<unknown, infer constraints> ? applyConstraintSchema<of<narrowed, constraints>, "predicate", any> : applyConstraintSchema<narrowed, "predicate", any> : applyConstraintSchema<t, "predicate", any>; | ||
export type constrainWithPredicate<t> = t extends of<unknown, infer constraints> ? applyConstraintSchema<of<t, constraints>, "predicate", any> : applyConstraintSchema<t, "predicate", any>; | ||
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: distill.brandable.In<t>) => Out<out> : never, tail> : t; | ||
@@ -201,11 +156,12 @@ export type inferMorphOut<morph extends Morph> = Exclude<ReturnType<morph>, ArkError | ArkErrors>; | ||
export type Optional = { | ||
optional?: {}; | ||
optional: {}; | ||
}; | ||
export type InferredOptional<t = unknown> = constrain<t, Optional>; | ||
export type InferredOptional<t = unknown> = of<t, Optional>; | ||
export type Default<v = any> = { | ||
default?: { | ||
default: { | ||
value: v; | ||
}; | ||
}; | ||
export type InferredDefault<t = unknown, v = any> = constrain<t, Default<v>>; | ||
export type DefaultFor<t> = (Primitive extends t ? Primitive : t extends Primitive ? t : never) | (() => t); | ||
export type InferredDefault<t = unknown, v = any> = of<t, Default<v>>; | ||
export type termOrType<t> = t | Type<t, any>; | ||
@@ -216,12 +172,3 @@ export type inferIntersection<l, r> = _inferIntersection<l, r, false>; | ||
l & r | ||
] extends [infer t extends anyOrNever] ? t : l extends InferredMorph<infer lIn, infer lOut> ? r extends InferredMorph<any, infer rOut> ? piped extends true ? (In: lIn) => rOut : never : piped extends true ? (In: lIn) => To<r> : (In: _inferIntersection<lIn, r, false>) => lOut : r extends InferredMorph<infer rIn, infer rOut> ? (In: _inferIntersection<rIn, l, false>) => rOut : parseConstraints<l> extends ([ | ||
infer lBase, | ||
infer lConstraints extends Constraints | ||
]) ? parseConstraints<r> extends ([ | ||
infer rBase, | ||
infer rConstraints extends Constraints | ||
]) ? constrain<_inferIntersection<lBase, rBase, piped>, lConstraints & rConstraints> : constrain<_inferIntersection<lBase, r, piped>, lConstraints> : parseConstraints<r> extends ([ | ||
infer rBase, | ||
infer rConstraints extends Constraints | ||
]) ? constrain<_inferIntersection<l, rBase, piped>, rConstraints> : [l, r] extends [object, object] ? intersectObjects<l, r, piped> extends infer result ? result : never : l & r; | ||
] extends [infer t extends anyOrNever] ? t : l extends InferredMorph<infer lIn, infer lOut> ? r extends InferredMorph<any, infer rOut> ? piped extends true ? (In: lIn) => rOut : never : piped extends true ? (In: lIn) => To<r> : (In: _inferIntersection<lIn, r, false>) => lOut : r extends InferredMorph<infer rIn, infer rOut> ? (In: _inferIntersection<rIn, l, false>) => rOut : l extends of<infer lBase, infer lAttributes> ? r extends of<infer rBase, infer rAttributes> ? of<_inferIntersection<lBase, rBase, piped>, lAttributes & rAttributes> : of<_inferIntersection<lBase, r, piped>, lAttributes> : r extends of<infer rBase, infer rAttributes> ? of<_inferIntersection<rBase, l, piped>, rAttributes> : [l, r] extends [object, object] ? intersectObjects<l, r, piped> extends infer result ? result : never : l & r; | ||
interface MorphableIntersection<piped extends boolean> extends Hkt<[unknown, unknown]> { | ||
@@ -228,0 +175,0 @@ body: _inferIntersection<this[0], this[1], piped>; |
import { noSuggest } from "@ark/util"; | ||
export const constrained = noSuggest("arkConstrained"); | ||
export const attributes = noSuggest("arkAttributes"); |
import type { Module, Submodule } from "../../module.ts"; | ||
import type { Branded, constrain, constraint, Constraints, Default, Narrowed, Optional } from "../inference.ts"; | ||
import type { BaseAttributes, Branded, constraint, Default, Narrowed, of, Optional } from "../inference.ts"; | ||
import { epoch } from "./epoch.ts"; | ||
@@ -22,11 +22,15 @@ import { integer } from "./integer.ts"; | ||
export declare namespace number { | ||
type atLeast<rule> = constrain<number, AtLeast<rule>>; | ||
type moreThan<rule> = constrain<number, MoreThan<rule>>; | ||
type atMost<rule> = constrain<number, AtMost<rule>>; | ||
type lessThan<rule> = constrain<number, LessThan<rule>>; | ||
type divisibleBy<rule> = constrain<number, DivisibleBy<rule>>; | ||
type narrowed = constrain<number, Narrowed>; | ||
type optional = constrain<number, Optional>; | ||
type defaultsTo<rule> = constrain<number, Default<rule>>; | ||
type branded<rule> = constrain<number, Branded<rule>>; | ||
type atLeast<rule> = of<number, AtLeast<rule>>; | ||
type moreThan<rule> = of<number, MoreThan<rule>>; | ||
type atMost<rule> = of<number, AtMost<rule>>; | ||
type lessThan<rule> = of<number, LessThan<rule>>; | ||
type divisibleBy<rule> = of<number, DivisibleBy<rule>>; | ||
type narrowed = of<number, Narrowed>; | ||
type optional = of<number, Optional>; | ||
type defaultsTo<rule> = of<number, Default<rule>>; | ||
type branded<rule> = of<number, Branded<rule>>; | ||
interface ownConstraints extends AtLeast<number>, MoreThan<number>, LessThan<number>, AtMost<number>, DivisibleBy<number> { | ||
} | ||
interface Attributes extends BaseAttributes, Partial<ownConstraints> { | ||
} | ||
type NaN = branded<"NaN">; | ||
@@ -36,3 +40,3 @@ type Infinity = branded<"Infinity">; | ||
type safe = branded<"safe">; | ||
type is<constraints extends Constraints> = constrain<number, constraints>; | ||
type is<attributes> = of<number, attributes>; | ||
type minSchemaToConstraint<schema, rule> = schema extends { | ||
@@ -44,3 +48,3 @@ exclusive: true; | ||
} ? LessThan<rule> : AtMost<rule>; | ||
type withConstraint<constraint> = constraint extends MoreThan<infer rule> ? moreThan<rule> : constraint extends AtLeast<infer rule> ? atLeast<rule> : constraint extends AtMost<infer rule> ? atMost<rule> : constraint extends LessThan<infer rule> ? lessThan<rule> : constraint extends DivisibleBy<infer rule> ? divisibleBy<rule> : constraint extends Optional ? optional : constraint extends Default<infer rule> ? defaultsTo<rule> : constraint extends Narrowed ? narrowed : never; | ||
type applyAttribute<attribute> = attribute extends MoreThan<infer rule> ? moreThan<rule> : attribute extends AtLeast<infer rule> ? atLeast<rule> : attribute extends AtMost<infer rule> ? atMost<rule> : attribute extends LessThan<infer rule> ? lessThan<rule> : attribute extends DivisibleBy<infer rule> ? divisibleBy<rule> : attribute extends Optional ? optional : attribute extends Default<infer rule> ? defaultsTo<rule> : attribute extends Branded<infer rule> ? branded<rule> : never; | ||
type module = Module<submodule>; | ||
@@ -47,0 +51,0 @@ type submodule = Submodule<$>; |
@@ -1,4 +0,4 @@ | ||
import type { Branded, constrain } from "../inference.ts"; | ||
import type { Branded, of } from "../inference.ts"; | ||
declare namespace string { | ||
type alpha = constrain<string, Branded<"alpha">>; | ||
type alpha = of<string, Branded<"alpha">>; | ||
} | ||
@@ -5,0 +5,0 @@ export declare const alpha: import("@ark/schema").IntersectionNode; |
@@ -1,4 +0,4 @@ | ||
import type { Branded, constrain } from "../inference.ts"; | ||
import type { Branded, of } from "../inference.ts"; | ||
declare namespace string { | ||
type alphanumeric = constrain<string, Branded<"alphanumeric">>; | ||
type alphanumeric = of<string, Branded<"alphanumeric">>; | ||
} | ||
@@ -5,0 +5,0 @@ export declare const alphanumeric: import("@ark/schema").IntersectionNode; |
import type { Module, Submodule } from "../../module.ts"; | ||
import type { Branded, constrain, To } from "../inference.ts"; | ||
import type { Branded, of, To } from "../inference.ts"; | ||
declare namespace string { | ||
type capitalized = constrain<string, Branded<"capitalized">>; | ||
type capitalized = of<string, Branded<"capitalized">>; | ||
} | ||
@@ -6,0 +6,0 @@ export declare const capitalize: capitalize.module; |
@@ -1,5 +0,5 @@ | ||
import type { Branded, constrain } from "../inference.ts"; | ||
import type { Branded, of } from "../inference.ts"; | ||
export declare const isLuhnValid: (creditCardInput: string) => boolean; | ||
declare namespace string { | ||
type creditCard = constrain<string, Branded<"creditCard">>; | ||
type creditCard = of<string, Branded<"creditCard">>; | ||
} | ||
@@ -6,0 +6,0 @@ export declare const creditCard: import("@ark/schema").BaseRoot<import("@ark/schema").InternalRootDeclaration>; |
import type { Module, Submodule } from "../../module.ts"; | ||
import type { Branded, To, constrain } from "../inference.ts"; | ||
import type { Branded, To, of } from "../inference.ts"; | ||
type DayDelimiter = "." | "/" | "-"; | ||
@@ -24,6 +24,6 @@ type DayPart = DayPatterns[PartKey]; | ||
declare namespace string { | ||
type date = constrain<string, Branded<"date">>; | ||
type date = of<string, Branded<"date">>; | ||
namespace date { | ||
type epoch = constrain<string, Branded<"date.epoch">>; | ||
type iso = constrain<string, Branded<"date.iso">>; | ||
type epoch = of<string, Branded<"date.epoch">>; | ||
type iso = of<string, Branded<"date.iso">>; | ||
} | ||
@@ -30,0 +30,0 @@ } |
@@ -1,4 +0,4 @@ | ||
import type { Branded, constrain } from "../inference.ts"; | ||
import type { Branded, of } from "../inference.ts"; | ||
declare namespace string { | ||
type digits = constrain<string, Branded<"digits">>; | ||
type digits = of<string, Branded<"digits">>; | ||
} | ||
@@ -5,0 +5,0 @@ export declare const digits: import("@ark/schema").IntersectionNode; |
@@ -1,4 +0,4 @@ | ||
import type { Branded, constrain } from "../inference.ts"; | ||
import type { Branded, of } from "../inference.ts"; | ||
declare namespace string { | ||
type email = constrain<string, Branded<"email">>; | ||
type email = of<string, Branded<"email">>; | ||
} | ||
@@ -5,0 +5,0 @@ export declare const email: import("@ark/schema").IntersectionNode; |
import type { Module, Submodule } from "../../module.ts"; | ||
import type { Branded, constrain, To } from "../inference.ts"; | ||
import type { Branded, of, To } from "../inference.ts"; | ||
import type { number } from "../number/number.ts"; | ||
declare namespace string { | ||
type integer = constrain<string, Branded<"integer">>; | ||
type integer = of<string, Branded<"integer">>; | ||
} | ||
@@ -7,0 +7,0 @@ export declare const integer: stringInteger.module; |
import type { Module, Submodule } from "../../module.ts"; | ||
import type { Branded, constrain } from "../inference.ts"; | ||
import type { Branded, of } from "../inference.ts"; | ||
declare namespace string { | ||
type ip = constrain<string, Branded<"ip">>; | ||
type ip = of<string, Branded<"ip">>; | ||
namespace ip { | ||
type v4 = constrain<string, Branded<"ip.v4">>; | ||
type v6 = constrain<string, Branded<"ip.v6">>; | ||
type v4 = of<string, Branded<"ip.v4">>; | ||
type v6 = of<string, Branded<"ip.v6">>; | ||
} | ||
@@ -9,0 +9,0 @@ } |
import type { Module, Submodule } from "../../module.ts"; | ||
import type { Branded, To, constrain } from "../inference.ts"; | ||
import type { Branded, To, of } from "../inference.ts"; | ||
declare namespace string { | ||
type json = constrain<string, Branded<"json">>; | ||
type json = of<string, Branded<"json">>; | ||
} | ||
@@ -6,0 +6,0 @@ export declare const writeJsonSyntaxErrorProblem: (error: unknown) => string; |
import type { Module, Submodule } from "../../module.ts"; | ||
import type { Branded, constrain, To } from "../inference.ts"; | ||
import type { Branded, of, To } from "../inference.ts"; | ||
declare namespace string { | ||
type lowercase = constrain<string, Branded<"lowercase">>; | ||
type lowercase = of<string, Branded<"lowercase">>; | ||
} | ||
@@ -6,0 +6,0 @@ export declare const lower: lower.module; |
import type { Module, Submodule } from "../../module.ts"; | ||
import type { Branded, constrain, To } from "../inference.ts"; | ||
import type { Branded, of, To } from "../inference.ts"; | ||
declare namespace string { | ||
type normalized = normalized.NFC; | ||
namespace normalized { | ||
type NFC = constrain<string, Branded<"normalized.NFC">>; | ||
type NFD = constrain<string, Branded<"normalized.NFD">>; | ||
type NFKC = constrain<string, Branded<"normalized.NFKC">>; | ||
type NFKD = constrain<string, Branded<"normalized.NFKD">>; | ||
type NFC = of<string, Branded<"normalized.NFC">>; | ||
type NFD = of<string, Branded<"normalized.NFD">>; | ||
type NFKC = of<string, Branded<"normalized.NFKC">>; | ||
type NFKD = of<string, Branded<"normalized.NFKD">>; | ||
} | ||
@@ -11,0 +11,0 @@ } |
import type { Module, Submodule } from "../../module.ts"; | ||
import type { Branded, constrain, To } from "../inference.ts"; | ||
import type { Branded, of, To } from "../inference.ts"; | ||
declare namespace string { | ||
type numeric = constrain<string, Branded<"numeric">>; | ||
type numeric = of<string, Branded<"numeric">>; | ||
} | ||
@@ -6,0 +6,0 @@ export declare const numeric: stringNumeric.module; |
@@ -1,4 +0,4 @@ | ||
import type { Branded, constrain } from "../inference.ts"; | ||
import type { Branded, of } from "../inference.ts"; | ||
declare namespace string { | ||
type semver = constrain<string, Branded<"semver">>; | ||
type semver = of<string, Branded<"semver">>; | ||
} | ||
@@ -5,0 +5,0 @@ export declare const semver: import("@ark/schema").IntersectionNode; |
import type { Module, Submodule } from "../../module.ts"; | ||
import type { AtLeastLength, AtMostLength, Branded, Constraints, Default, ExactlyLength, LessThanLength, MoreThanLength, Narrowed, Optional, constrain, constraint } from "../inference.ts"; | ||
import type { AtLeastLength, AtMostLength, Branded, Default, ExactlyLength, LessThanLength, MoreThanLength, Narrowed, Optional, constraint, of } from "../inference.ts"; | ||
import { alpha } from "./alpha.ts"; | ||
@@ -74,14 +74,14 @@ import { alphanumeric } from "./alphanumeric.ts"; | ||
export declare namespace string { | ||
type atLeastLength<rule> = constrain<string, AtLeastLength<rule>>; | ||
type moreThanLength<rule> = constrain<string, MoreThanLength<rule>>; | ||
type atMostLength<rule> = constrain<string, AtMostLength<rule>>; | ||
type lessThanLength<rule> = constrain<string, LessThanLength<rule>>; | ||
type exactlyLength<rule> = constrain<string, ExactlyLength<rule>>; | ||
type matching<rule> = constrain<string, Matching<rule>>; | ||
type narrowed = constrain<string, Narrowed>; | ||
type optional = constrain<string, Optional>; | ||
type defaultsTo<rule> = constrain<string, Default<rule>>; | ||
type branded<rule> = constrain<string, Branded<rule>>; | ||
type is<constraints extends Constraints> = constrain<string, constraints>; | ||
type withConstraint<constraint> = constraint extends ExactlyLength<infer rule> ? exactlyLength<rule> : constraint extends MoreThanLength<infer rule> ? moreThanLength<rule> : constraint extends AtLeastLength<infer rule> ? atLeastLength<rule> : constraint extends AtMostLength<infer rule> ? atMostLength<rule> : constraint extends LessThanLength<infer rule> ? lessThanLength<rule> : constraint extends Matching<infer rule> ? matching<rule> : constraint extends Optional ? optional : constraint extends Default<infer rule> ? defaultsTo<rule> : constraint extends Narrowed ? narrowed : never; | ||
type atLeastLength<rule> = of<string, AtLeastLength<rule>>; | ||
type moreThanLength<rule> = of<string, MoreThanLength<rule>>; | ||
type atMostLength<rule> = of<string, AtMostLength<rule>>; | ||
type lessThanLength<rule> = of<string, LessThanLength<rule>>; | ||
type exactlyLength<rule> = of<string, ExactlyLength<rule>>; | ||
type matching<rule> = of<string, Matching<rule>>; | ||
type narrowed = of<string, Narrowed>; | ||
type optional = of<string, Optional>; | ||
type defaultsTo<rule> = of<string, Default<rule>>; | ||
type branded<rule> = of<string, Branded<rule>>; | ||
type is<attributes> = of<string, attributes>; | ||
type applyAttribute<attribute> = attribute extends ExactlyLength<infer rule> ? exactlyLength<rule> : attribute extends MoreThanLength<infer rule> ? moreThanLength<rule> : attribute extends AtLeastLength<infer rule> ? atLeastLength<rule> : attribute extends AtMostLength<infer rule> ? atMostLength<rule> : attribute extends LessThanLength<infer rule> ? lessThanLength<rule> : attribute extends Matching<infer rule> ? matching<rule> : attribute extends Optional ? optional : attribute extends Default<infer rule> ? defaultsTo<rule> : attribute extends Branded<infer rule> ? branded<rule> : never; | ||
type module = Module<string.submodule>; | ||
@@ -88,0 +88,0 @@ type submodule = Submodule<$>; |
import type { Module, Submodule } from "../../module.ts"; | ||
import type { Branded, constrain, To } from "../inference.ts"; | ||
import type { Branded, of, To } from "../inference.ts"; | ||
declare namespace string { | ||
type trimmed = constrain<string, Branded<"trimmed">>; | ||
type trimmed = of<string, Branded<"trimmed">>; | ||
} | ||
@@ -6,0 +6,0 @@ export declare const trim: trim.module; |
import type { Module, Submodule } from "../../module.ts"; | ||
import type { Branded, constrain, To } from "../inference.ts"; | ||
import type { Branded, of, To } from "../inference.ts"; | ||
declare namespace string { | ||
type uppercase = constrain<string, Branded<"uppercase">>; | ||
type uppercase = of<string, Branded<"uppercase">>; | ||
} | ||
@@ -6,0 +6,0 @@ export declare const upper: upper.module; |
import type { Module, Submodule } from "../../module.ts"; | ||
import type { Branded, constrain, To } from "../inference.ts"; | ||
import type { Branded, of, To } from "../inference.ts"; | ||
declare namespace string { | ||
type url = constrain<string, Branded<"url">>; | ||
type url = of<string, Branded<"url">>; | ||
} | ||
@@ -6,0 +6,0 @@ export declare const url: url.module; |
import type { Module, Submodule } from "../../module.ts"; | ||
import type { Branded, constrain } from "../inference.ts"; | ||
import type { Branded, of } from "../inference.ts"; | ||
export declare const uuid: Module<{ | ||
@@ -15,12 +15,12 @@ root: import("./string.ts").string.matching<string> | "00000000-0000-0000-0000-000000000000" | "ffffffff-ffff-ffff-ffff-ffffffffffff"; | ||
declare namespace string { | ||
type uuid = constrain<string, Branded<"uuid">>; | ||
type uuid = of<string, Branded<"uuid">>; | ||
namespace uuid { | ||
type v1 = constrain<string, Branded<"uuid.v1">>; | ||
type v2 = constrain<string, Branded<"uuid.v2">>; | ||
type v3 = constrain<string, Branded<"uuid.v3">>; | ||
type v4 = constrain<string, Branded<"uuid.v4">>; | ||
type v5 = constrain<string, Branded<"uuid.v5">>; | ||
type v6 = constrain<string, Branded<"uuid.v6">>; | ||
type v7 = constrain<string, Branded<"uuid.v7">>; | ||
type v8 = constrain<string, Branded<"uuid.v8">>; | ||
type v1 = of<string, Branded<"uuid.v1">>; | ||
type v2 = of<string, Branded<"uuid.v2">>; | ||
type v3 = of<string, Branded<"uuid.v3">>; | ||
type v4 = of<string, Branded<"uuid.v4">>; | ||
type v5 = of<string, Branded<"uuid.v5">>; | ||
type v6 = of<string, Branded<"uuid.v6">>; | ||
type v7 = of<string, Branded<"uuid.v7">>; | ||
type v8 = of<string, Branded<"uuid.v8">>; | ||
} | ||
@@ -27,0 +27,0 @@ } |
import type { ArkErrors, BaseRoot, Disjoint, JsonSchema, MetaSchema, Morph, UndeclaredKeyBehavior } from "@ark/schema"; | ||
import type { anyOrNever, array, Callable, ErrorMessage, inferred, Json, unset } from "@ark/util"; | ||
import type { ArkAmbient } from "../config.ts"; | ||
import type { applyConstraint, Default, distill, inferIntersection, inferMorphOut, inferPipes, InferredMorph, Optional, To } from "../keywords/inference.ts"; | ||
import type { applyAttribute, Branded, Default, DefaultFor, distill, inferIntersection, inferMorphOut, inferPipes, InferredMorph, Optional, To } from "../keywords/inference.ts"; | ||
import type { type } from "../keywords/keywords.ts"; | ||
@@ -40,2 +40,3 @@ import type { Scope } from "../scope.ts"; | ||
as<t = unset>(...args: validateChainedAsArgs<t>): instantiateType<t, $>; | ||
brand<const name extends string, r = applyAttribute<t, Branded<name>> extends infer r ? instantiateType<r, $> : never>(name: name): r; | ||
get in(): instantiateType<this["inferBrandableIn"], $>; | ||
@@ -56,4 +57,4 @@ get out(): instantiateType<this["inferIntrospectableOut"], $>; | ||
distribute<mapOut, reduceOut = mapOut[]>(mapBranch: (branch: Type, i: number, branches: array<Type>) => mapOut, reduceMapped?: (mappedBranches: mapOut[]) => reduceOut): NoInfer<reduceOut>; | ||
optional<r = applyConstraint<t, Optional>>(): instantiateType<r, $>; | ||
default<const value extends this["inferIn"], r = applyConstraint<t, Default<value>>>(value: value): instantiateType<r, $>; | ||
optional<r = applyAttribute<t, Optional>>(): instantiateType<r, $>; | ||
default<const value extends this["inferIn"], r = applyAttribute<t, Default<value>>>(value: DefaultFor<value>): NoInfer<instantiateType<r, $>> extends infer result ? result : never; | ||
/** @deprecated */ | ||
@@ -79,9 +80,9 @@ apply: Function["apply"]; | ||
interface ChainedPipeSignature<t, $> { | ||
<a extends Morph<distill.Out<t>>, r = instantiateType<inferPipes<t, [a]>, $>>(a: a): NoInfer<r>; | ||
<a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, r = instantiateType<inferPipes<t, [a, b]>, $>>(a: a, b: b): NoInfer<r>; | ||
<a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, r = instantiateType<inferPipes<t, [a, b, c]>, $>>(a: a, b: b, c: c): NoInfer<r>; | ||
<a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, r = instantiateType<inferPipes<t, [a, b, c, d]>, $>>(a: a, b: b, c: c, d: d): NoInfer<r>; | ||
<a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, r = instantiateType<inferPipes<t, [a, b, c, d, e]>, $>>(a: a, b: b, c: c, d: d, e: e): NoInfer<r>; | ||
<a extends Morph<distill.Out<t>>, 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>>, r = instantiateType<inferPipes<t, [a, b, c, d, e, f]>, $>>(a: a, b: b, c: c, d: d, e: e, f: f): NoInfer<r>; | ||
<a extends Morph<distill.Out<t>>, 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>>, r = instantiateType<inferPipes<t, [a, b, c, d, e, f, g]>, $>>(a: a, b: b, c: c, d: d, e: e, f: f, g: g): NoInfer<r>; | ||
<a extends Morph<distill.Out<t>>, r = instantiateType<inferPipes<t, [a]>, $>>(a: a): NoInfer<r> extends infer result ? result : never; | ||
<a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, r = instantiateType<inferPipes<t, [a, b]>, $>>(a: a, b: b): NoInfer<r> extends infer result ? result : never; | ||
<a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, r = instantiateType<inferPipes<t, [a, b, c]>, $>>(a: a, b: b, c: c): NoInfer<r> extends infer result ? result : never; | ||
<a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, r = instantiateType<inferPipes<t, [a, b, c, d]>, $>>(a: a, b: b, c: c, d: d): NoInfer<r> extends infer result ? result : never; | ||
<a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, r = instantiateType<inferPipes<t, [a, b, c, d, e]>, $>>(a: a, b: b, c: c, d: d, e: e): NoInfer<r> extends infer result ? result : never; | ||
<a extends Morph<distill.Out<t>>, 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>>, r = instantiateType<inferPipes<t, [a, b, c, d, e, f]>, $>>(a: a, b: b, c: c, d: d, e: e, f: f): NoInfer<r> extends infer result ? result : never; | ||
<a extends Morph<distill.Out<t>>, 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>>, r = instantiateType<inferPipes<t, [a, b, c, d, e, f, g]>, $>>(a: a, b: b, c: c, d: d, e: e, f: f, g: g): NoInfer<r> extends infer result ? result : never; | ||
} | ||
@@ -88,0 +89,0 @@ export interface ChainedPipes<t, $> extends ChainedPipeSignature<t, $> { |
import type { BaseMappedPropInner, OptionalMappedPropInner, Prop } from "@ark/schema"; | ||
import type { arkGet, arkIndexableOf, arkKeyOf, array, ErrorType, inferred, intersectUnion, Json, Key, listable, merge, optionalKeyOf, show, toArkKey } from "@ark/util"; | ||
import type { applyConstraint, constrain, Default, Optional, parseConstraints } from "../keywords/inference.ts"; | ||
import type { applyAttribute, Default, of, Optional } from "../keywords/inference.ts"; | ||
import type { type } from "../keywords/keywords.ts"; | ||
@@ -36,6 +36,3 @@ import type { ArrayType } from "./array.ts"; | ||
type typePropOf<o, $> = keyof o extends infer k ? k extends keyof o ? typeProp<o, k, $> : never : never; | ||
type typeProp<o, k extends keyof o, $, t = o[k] & ({} | null)> = parseConstraints<t> extends ([ | ||
infer base, | ||
infer constraints extends Default | Optional | ||
]) ? constraints extends Default<infer defaultValue> ? DefaultedTypeProp<k & Key, keyof constraints extends keyof Default ? base : constrain<base, Omit<constraints, keyof Default>>, defaultValue, $> : constraints extends Optional ? BaseTypeProp<"optional", k & Key, keyof constraints extends keyof Optional ? base : constrain<base, Omit<constraints, keyof Optional>>, $> : never : BaseTypeProp<k extends optionalKeyOf<o> ? "optional" : "required", k & Key, t, $>; | ||
type typeProp<o, k extends keyof o, $, t = o[k] & ({} | null)> = t extends of<infer base, infer attributes> ? attributes extends Default<infer defaultValue> ? DefaultedTypeProp<k & Key, keyof attributes extends keyof Default ? base : of<base, Omit<attributes, keyof Default>>, defaultValue, $> : attributes extends Optional ? BaseTypeProp<"optional", k & Key, keyof attributes extends keyof Optional ? base : of<base, Omit<attributes, keyof Optional>>, $> : never : BaseTypeProp<k extends optionalKeyOf<o> ? "optional" : "required", k & Key, t, $>; | ||
export interface BaseTypeProp<kind extends Prop.Kind = Prop.Kind, k extends Key = Key, | ||
@@ -77,3 +74,3 @@ /** @ts-ignore cast variance */ | ||
default: unknown; | ||
}>["key"]]: applyConstraint<prop["value"][inferred], Default<prop["default" & keyof prop]>>; | ||
}>["key"]]: applyAttribute<prop["value"][inferred], Default<prop["default" & keyof prop]>>; | ||
}>; | ||
@@ -80,0 +77,0 @@ type applyHomomorphicOptionality<t, prop extends MappedTypeProp> = prop["kind"] extends string ? prop : prop & { |
@@ -5,5 +5,5 @@ import type { writeUnassignableDefaultValueMessage } from "@ark/schema"; | ||
import type { UnitLiteral } from "../shift/operator/default.ts"; | ||
import type { inferAstOut } from "./infer.ts"; | ||
import type { inferAstIn } from "./infer.ts"; | ||
import type { astToString } from "./utils.ts"; | ||
import type { validateAst } from "./validate.ts"; | ||
export type validateDefault<baseAst, unitLiteral extends UnitLiteral, $, args> = validateAst<baseAst, $, args> extends infer e extends ErrorMessage ? e : type.infer<unitLiteral> extends inferAstOut<baseAst, $, args> ? undefined : ErrorMessage<writeUnassignableDefaultValueMessage<astToString<baseAst>, unitLiteral>>; | ||
export type validateDefault<baseAst, unitLiteral extends UnitLiteral, $, args> = validateAst<baseAst, $, args> extends infer e extends ErrorMessage ? e : type.infer<unitLiteral> extends inferAstIn<baseAst, $, args> ? undefined : ErrorMessage<writeUnassignableDefaultValueMessage<astToString<baseAst>, unitLiteral>>; |
import type { GenericAst } from "@ark/schema"; | ||
import type { Hkt, arkKeyOf, array } from "@ark/util"; | ||
import type { Date } from "../../keywords/constructors/Date.ts"; | ||
import type { Default, LimitLiteral, Optional, applyConstraint, applyConstraintSchema, distill, inferIntersection, normalizeLimit } from "../../keywords/inference.ts"; | ||
import type { Branded, Default, LimitLiteral, Optional, applyAttribute, applyConstraintSchema, distill, inferIntersection, normalizeLimit } from "../../keywords/inference.ts"; | ||
import type { type } from "../../keywords/keywords.ts"; | ||
@@ -9,2 +9,3 @@ import type { UnparsedScope } from "../../scope.ts"; | ||
import type { Comparator, MinComparator } from "../reduce/shared.ts"; | ||
import type { Scanner } from "../shift/scanner.ts"; | ||
export type inferAstRoot<ast, $, args> = ast extends array ? inferExpression<ast, $, args> : never; | ||
@@ -29,3 +30,3 @@ export type inferAstIn<ast, $, args> = distill.In<inferAstRoot<ast, $, args>>; | ||
[i in keyof g["names"] & `${number}` as g["names"][i]]: inferExpression<argAsts[i & keyof argAsts], resolveScope<g["arg$"], $>, args>; | ||
}> : ast[1] extends "[]" ? inferExpression<ast[0], $, args>[] : ast[1] extends "|" ? inferExpression<ast[0], $, args> | inferExpression<ast[2], $, args> : ast[1] extends "&" ? inferIntersection<inferExpression<ast[0], $, args>, inferExpression<ast[2], $, args>> : ast[1] extends "=" ? type.infer<ast[2]> extends infer defaultValue ? applyConstraint<inferExpression<ast[0], $, args>, Default<defaultValue>> : never : ast[1] extends Comparator ? ast[0] extends LimitLiteral ? brandBound<inferExpression<ast[2], $, args>, ast[1], ast[0]> : brandBound<inferExpression<ast[0], $, args>, ast[1], ast[2] & LimitLiteral> : ast[1] extends "%" ? applyConstraintSchema<inferExpression<ast[0], $, args>, "divisor", ast[2] & number> : ast[1] extends "?" ? applyConstraint<inferExpression<ast[0], $, args>, Optional> : ast[0] extends "keyof" ? arkKeyOf<inferExpression<ast[1], $, args>> : never : never; | ||
}> : ast[1] extends "[]" ? inferExpression<ast[0], $, args>[] : ast[1] extends "|" ? inferExpression<ast[0], $, args> | inferExpression<ast[2], $, args> : ast[1] extends "&" ? inferIntersection<inferExpression<ast[0], $, args>, inferExpression<ast[2], $, args>> : ast[1] extends "=" ? type.infer<ast[2]> extends infer defaultValue ? applyAttribute<inferExpression<ast[0], $, args>, Default<defaultValue>> : never : ast[1] extends "#" ? applyAttribute<inferExpression<ast[0], $, args>, Branded<ast[2]>> : ast[1] extends Comparator ? ast[0] extends LimitLiteral ? brandBound<inferExpression<ast[2], $, args>, ast[1], ast[0]> : brandBound<inferExpression<ast[0], $, args>, ast[1], ast[2] & LimitLiteral> : ast[1] extends "%" ? applyConstraintSchema<inferExpression<ast[0], $, args>, "divisor", ast[2] & number> : ast[1] extends "?" ? applyAttribute<inferExpression<ast[0], $, args>, Optional> : ast[0] extends "keyof" ? arkKeyOf<inferExpression<ast[1], $, args>> : never : never; | ||
export type brandBound<brandableIn, comparator extends Comparator, limit extends LimitLiteral> = distill.In<brandableIn> extends infer In ? comparator extends "==" ? In extends number ? limit : In extends Date ? Date.literal<normalizeLimit<limit>> : applyConstraintSchema<brandableIn, "exactLength", limit & number> : applyConstraintSchema<brandableIn, In extends number ? comparator extends MinComparator ? "min" : "max" : In extends string | array ? comparator extends MinComparator ? "minLength" : "maxLength" : comparator extends MinComparator ? "after" : "before", { | ||
@@ -37,6 +38,4 @@ rule: normalizeLimit<limit>; | ||
export type PrefixExpression<operator extends PrefixOperator = PrefixOperator, operand = unknown> = [operator, operand]; | ||
export type PostfixOperator = "[]" | "?"; | ||
export type PostfixExpression<operator extends PostfixOperator = PostfixOperator, operand = unknown> = readonly [operand, operator]; | ||
export type InfixOperator = "|" | "&" | Comparator | "%" | ":" | "=>" | "@" | "="; | ||
export type InfixExpression<operator extends InfixOperator = InfixOperator, l = unknown, r = unknown> = [l, operator, r]; | ||
export type PostfixExpression<operator extends Scanner.PostfixToken = Scanner.PostfixToken, operand = unknown> = readonly [operand, operator]; | ||
export type InfixExpression<operator extends Scanner.InfixToken = Scanner.InfixToken, l = unknown, r = unknown> = [l, operator, r]; | ||
export {}; |
import type { arkKind, GenericParamAst, PrivateDeclaration, writeMissingSubmoduleAccessMessage, writeUnsatisfiedParameterConstraintMessage } from "@ark/schema"; | ||
import type { anyOrNever, array, BigintLiteral, charsAfterFirst, Completion, ErrorMessage, NumberLiteral, typeToString, writeMalformedNumericLiteralMessage } from "@ark/util"; | ||
import type { anyOrNever, array, BigintLiteral, Completion, ErrorMessage, NumberLiteral, typeToString, writeMalformedNumericLiteralMessage } from "@ark/util"; | ||
import type { Generic } from "../../generic.ts"; | ||
@@ -14,3 +14,3 @@ import type { Comparator } from "../reduce/shared.ts"; | ||
import type { astToString } from "./utils.ts"; | ||
export type validateAst<ast, $, args> = ast extends ErrorMessage ? ast : ast extends InferredAst ? validateInferredAst<ast[0], ast[2]> : ast extends DefAst ? ast[2] extends PrivateDeclaration ? ErrorMessage<writePrefixedPrivateReferenceMessage<ast[2]>> : undefined : ast extends PostfixExpression<infer operator, infer operand> ? operator extends "[]" ? validateAst<operand, $, args> : operator extends "?" ? validateAst<operand, $, args> : never : ast extends InfixExpression<infer operator, infer l, infer r> ? operator extends "&" | "|" ? validateInfix<ast, $, args> : operator extends Comparator ? validateRange<l, operator, r, $, args> : operator extends "%" ? validateDivisor<l, $, args> : operator extends "=" ? validateDefault<l, r & UnitLiteral, $, args> : never : ast extends ["keyof", infer operand] ? validateKeyof<operand, $, args> : ast extends GenericInstantiationAst<infer g, infer argAsts> ? validateGenericArgs<g["paramsAst"], argAsts, $, args, []> : ErrorMessage<writeUnexpectedExpressionMessage<astToString<ast>>> & { | ||
export type validateAst<ast, $, args> = ast extends ErrorMessage ? ast : ast extends InferredAst ? validateInferredAst<ast[0], ast[2]> : ast extends DefAst ? ast[2] extends PrivateDeclaration<infer name> ? ErrorMessage<writePrefixedPrivateReferenceMessage<name>> : undefined : ast extends PostfixExpression<infer operator, infer operand> ? operator extends "[]" ? validateAst<operand, $, args> : operator extends "?" ? validateAst<operand, $, args> : never : ast extends InfixExpression<infer operator, infer l, infer r> ? operator extends "&" | "|" ? validateInfix<ast, $, args> : operator extends Comparator ? validateRange<l, operator, r, $, args> : operator extends "%" ? validateDivisor<l, $, args> : operator extends "=" ? validateDefault<l, r & UnitLiteral, $, args> : operator extends "#" ? validateAst<l, $, args> : ErrorMessage<writeUnexpectedExpressionMessage<astToString<ast>>> : ast extends ["keyof", infer operand] ? validateKeyof<operand, $, args> : ast extends GenericInstantiationAst<infer g, infer argAsts> ? validateGenericArgs<g["paramsAst"], argAsts, $, args, []> : ErrorMessage<writeUnexpectedExpressionMessage<astToString<ast>>> & { | ||
ast: ast; | ||
@@ -20,5 +20,5 @@ }; | ||
type validateGenericArgs<params extends array<GenericParamAst>, argAsts extends array, $, args, indices extends 1[]> = argAsts extends readonly [infer arg, ...infer argsTail] ? validateAst<arg, $, args> extends infer e extends ErrorMessage ? e : inferAstRoot<arg, $, args> extends params[indices["length"]][1] ? validateGenericArgs<params, argsTail, $, args, [...indices, 1]> : ErrorMessage<writeUnsatisfiedParameterConstraintMessage<params[indices["length"]][0], typeToString<params[indices["length"]][1]>, astToString<arg>>> : undefined; | ||
export declare const writePrefixedPrivateReferenceMessage: <def extends PrivateDeclaration>(def: def) => writePrefixedPrivateReferenceMessage<def>; | ||
export type writePrefixedPrivateReferenceMessage<def extends PrivateDeclaration> = `Private type references should not include '#'. Use '${charsAfterFirst<def>}' instead.`; | ||
type validateInferredAst<inferred, def extends string> = def extends NumberLiteral ? number extends inferred ? ErrorMessage<writeMalformedNumericLiteralMessage<def, "number">> : undefined : def extends BigintLiteral ? bigint extends inferred ? ErrorMessage<writeMalformedNumericLiteralMessage<def, "bigint">> : undefined : [inferred] extends [anyOrNever] ? undefined : def extends PrivateDeclaration ? ErrorMessage<writePrefixedPrivateReferenceMessage<def>> : inferred extends Generic ? ErrorMessage<writeInvalidGenericArgCountMessage<def, inferred["names"], []>> : inferred extends { | ||
export declare const writePrefixedPrivateReferenceMessage: <name extends string>(name: name) => writePrefixedPrivateReferenceMessage<name>; | ||
export type writePrefixedPrivateReferenceMessage<name extends string> = `Private type references should not include '#'. Use '${name}' instead.`; | ||
type validateInferredAst<inferred, def extends string> = def extends NumberLiteral ? number extends inferred ? ErrorMessage<writeMalformedNumericLiteralMessage<def, "number">> : undefined : def extends BigintLiteral ? bigint extends inferred ? ErrorMessage<writeMalformedNumericLiteralMessage<def, "bigint">> : undefined : [inferred] extends [anyOrNever] ? undefined : def extends PrivateDeclaration<infer name> ? ErrorMessage<writePrefixedPrivateReferenceMessage<name>> : inferred extends Generic ? ErrorMessage<writeInvalidGenericArgCountMessage<def, inferred["names"], []>> : inferred extends { | ||
[arkKind]: "module"; | ||
@@ -25,0 +25,0 @@ } ? "root" extends keyof inferred ? undefined : ErrorMessage<writeMissingSubmoduleAccessMessage<def>> : def extends ErrorMessage ? def : undefined; |
@@ -1,1 +0,1 @@ | ||
export const writePrefixedPrivateReferenceMessage = (def) => `Private type references should not include '#'. Use '${def.slice(1)}' instead.`; | ||
export const writePrefixedPrivateReferenceMessage = (name) => `Private type references should not include '#'. Use '${name}' instead.`; |
import { type BaseParseContext, type BaseRoot, type Index, type Optional, type Required, type UndeclaredKeyBehavior, type writeInvalidPropertyKeyMessage } from "@ark/schema"; | ||
import { type anyOrNever, type Dict, type ErrorMessage, type ErrorType, type EscapeToken, type Key, type listable, type merge, type show } from "@ark/util"; | ||
import type { constrain } from "../keywords/inference.ts"; | ||
import type { of } from "../keywords/inference.ts"; | ||
import type { astToString } from "./ast/utils.ts"; | ||
@@ -22,3 +22,3 @@ import type { validateString } from "./ast/validate.ts"; | ||
export type validateObjectLiteral<def, $, args> = { | ||
[k in keyof def]: k extends IndexKey<infer indexDef> ? validateString<indexDef, $, args> extends ErrorMessage<infer message> ? ErrorType<message> : inferDefinition<indexDef, $, args> extends Key | constrain<Key, {}> ? validateDefinition<def[k], $, args> : ErrorType<writeInvalidPropertyKeyMessage<indexDef>> : k extends "..." ? inferDefinition<def[k], $, args> extends object ? validateDefinition<def[k], $, args> : ErrorType<writeInvalidSpreadTypeMessage<astToString<def[k]>>> : k extends "+" ? UndeclaredKeyBehavior : validateDefinition<def[k], $, args>; | ||
[k in keyof def]: k extends IndexKey<infer indexDef> ? validateString<indexDef, $, args> extends ErrorMessage<infer message> ? ErrorType<message> : inferDefinition<indexDef, $, args> extends Key | of<Key, {}> ? validateDefinition<def[k], $, args> : ErrorType<writeInvalidPropertyKeyMessage<indexDef>> : k extends "..." ? inferDefinition<def[k], $, args> extends object ? validateDefinition<def[k], $, args> : ErrorType<writeInvalidSpreadTypeMessage<astToString<def[k]>>> : k extends "+" ? UndeclaredKeyBehavior : validateDefinition<def[k], $, args>; | ||
}; | ||
@@ -25,0 +25,0 @@ type nonOptionalKeyFrom<k, $, args> = parseKey<k> extends PreparsedKey<"required", infer inner> ? inner : parseKey<k> extends PreparsedKey<"index", infer inner> ? inferDefinition<inner, $, args> extends infer t extends Key ? t : never : never; |
import type { BaseParseContext, BaseRoot } from "@ark/schema"; | ||
import { type requireKeys } from "@ark/util"; | ||
import type { LimitLiteral } from "../../keywords/inference.ts"; | ||
import type { InfixOperator } from "../ast/infer.ts"; | ||
import type { Scanner } from "../shift/scanner.ts"; | ||
@@ -39,5 +38,5 @@ import { type Comparator, type MinComparator, type OpenLeftBound, type StringifiablePrefixOperator } from "./shared.ts"; | ||
reduceGroupOpen(): void; | ||
previousOperator(): MinComparator | StringifiablePrefixOperator | InfixOperator | undefined; | ||
previousOperator(): MinComparator | StringifiablePrefixOperator | Scanner.InfixToken | undefined; | ||
shiftedByOne(): this; | ||
} | ||
export {}; |
@@ -6,2 +6,3 @@ import { writeUnresolvableMessage, type BaseRoot, type GenericAst, type GenericRoot, type arkKind, type genericParamNames, type resolvableReferenceIn, type writeNonSubmoduleDotMessage } from "@ark/schema"; | ||
import type { GenericInstantiationAst, InferredAst } from "../../ast/infer.ts"; | ||
import { writePrefixedPrivateReferenceMessage } from "../../ast/validate.ts"; | ||
import type { DynamicState } from "../../reduce/dynamic.ts"; | ||
@@ -31,3 +32,6 @@ import type { StaticState, state } from "../../reduce/static.ts"; | ||
* unresolvable error if there are none */ | ||
export type unresolvableState<s extends StaticState, token extends string, resolutions, args, submodulePath extends string[]> = validReferenceFromToken<token, resolutions, args, submodulePath> extends (never) ? state.error<writeUnresolvableMessage<qualifiedReference<token, submodulePath>>> : state.completion<`${s["scanned"]}${qualifiedReference<validReferenceFromToken<token, resolutions, args, submodulePath>, submodulePath>}`>; | ||
export type unresolvableState<s extends StaticState, token extends string, resolutions, args, submodulePath extends string[]> = [ | ||
token, | ||
s["unscanned"] | ||
] extends ["", Scanner.shift<"#", infer unscanned>] ? Scanner.shiftUntilNextTerminator<unscanned> extends (Scanner.shiftResult<infer name, string>) ? state.error<writePrefixedPrivateReferenceMessage<name>> : never : validReferenceFromToken<token, resolutions, args, submodulePath> extends (never) ? state.error<writeUnresolvableMessage<qualifiedReference<token, submodulePath>>> : state.completion<`${s["scanned"]}${qualifiedReference<validReferenceFromToken<token, resolutions, args, submodulePath>, submodulePath>}`>; | ||
type qualifiedReference<reference extends string, submodulePath extends string[]> = join<[...submodulePath, reference], ".">; | ||
@@ -34,0 +38,0 @@ type validReferenceFromToken<token extends string, $, args, submodulePath extends string[]> = Extract<submodulePath["length"] extends 0 ? BaseCompletions<$, args> : resolvableReferenceIn<$>, `${token}${string}`>; |
@@ -22,6 +22,7 @@ import { hasArkKind, writeUnresolvableMessage } from "@ark/schema"; | ||
maybeParseUnenclosedLiteral(s, token) ?? | ||
s.error(token === "" ? writeMissingOperandMessage(s) | ||
: token[0] === "#" ? | ||
writePrefixedPrivateReferenceMessage(token) | ||
: writeUnresolvableMessage(token)); | ||
s.error(token === "" ? | ||
s.scanner.lookahead === "#" ? | ||
writePrefixedPrivateReferenceMessage(s.shiftedByOne().scanner.shiftUntilNextTerminator()) | ||
: writeMissingOperandMessage(s) | ||
: writeUnresolvableMessage(token)); | ||
const maybeParseReference = (s, token) => { | ||
@@ -28,0 +29,0 @@ if (s.ctx.args?.[token]) { |
@@ -10,4 +10,7 @@ export const parseDefault = (s) => { | ||
return s.error(writeNonLiteralDefaultMessage(defaultNode.expression)); | ||
return baseNode.default(defaultNode.unit); | ||
const defaultValue = defaultNode.unit instanceof Date ? | ||
() => new Date(defaultNode.unit) | ||
: defaultNode.unit; | ||
return baseNode.default(defaultValue); | ||
}; | ||
export const writeNonLiteralDefaultMessage = (defaultDef) => `Default value '${defaultDef}' must a literal value`; |
@@ -6,5 +6,6 @@ import { type WhiteSpaceToken } from "@ark/util"; | ||
import { parseBound, type ComparatorStartChar } from "./bounds.ts"; | ||
import { parseBrand } from "./brand.ts"; | ||
import { parseDivisor } from "./divisor.ts"; | ||
export declare const parseOperator: (s: DynamicStateWithRoot) => void; | ||
export type parseOperator<s extends StaticState, $, args> = s["unscanned"] extends Scanner.shift<infer lookahead, infer unscanned> ? lookahead extends "[" ? unscanned extends Scanner.shift<"]", infer nextUnscanned> ? state.setRoot<s, [s["root"], "[]"], nextUnscanned> : state.error<incompleteArrayTokenMessage> : lookahead extends "|" | "&" ? state.reduceBranch<s, lookahead, unscanned> : lookahead extends ")" ? state.finalizeGroup<s, unscanned> : Scanner.lookaheadIsFinalizing<lookahead, unscanned> extends true ? state.finalize<state.scanTo<s, unscanned>, lookahead & Scanner.FinalizingLookahead> : lookahead extends ComparatorStartChar ? parseBound<s, lookahead, unscanned, $, args> : lookahead extends "%" ? parseDivisor<s, unscanned> : lookahead extends WhiteSpaceToken ? parseOperator<state.scanTo<s, unscanned>, $, args> : state.error<writeUnexpectedCharacterMessage<lookahead>> : state.finalize<s, "">; | ||
export type parseOperator<s extends StaticState, $, args> = s["unscanned"] extends Scanner.shift<infer lookahead, infer unscanned> ? lookahead extends "[" ? unscanned extends Scanner.shift<"]", infer nextUnscanned> ? state.setRoot<s, [s["root"], "[]"], nextUnscanned> : state.error<incompleteArrayTokenMessage> : lookahead extends "|" | "&" ? state.reduceBranch<s, lookahead, unscanned> : lookahead extends ")" ? state.finalizeGroup<s, unscanned> : Scanner.lookaheadIsFinalizing<lookahead, unscanned> extends true ? state.finalize<state.scanTo<s, unscanned>, lookahead & Scanner.FinalizingLookahead> : lookahead extends ComparatorStartChar ? parseBound<s, lookahead, unscanned, $, args> : lookahead extends "%" ? parseDivisor<s, unscanned> : lookahead extends "#" ? parseBrand<s, unscanned> : lookahead extends WhiteSpaceToken ? parseOperator<state.scanTo<s, unscanned>, $, args> : state.error<writeUnexpectedCharacterMessage<lookahead>> : state.finalize<s, "">; | ||
export declare const writeUnexpectedCharacterMessage: <char extends string, shouldBe extends string>(char: char, shouldBe?: shouldBe) => writeUnexpectedCharacterMessage<char, shouldBe>; | ||
@@ -11,0 +12,0 @@ export type writeUnexpectedCharacterMessage<char extends string, shouldBe extends string = ""> = `'${char}' is not allowed here${shouldBe extends "" ? "" : ` (should be ${shouldBe})`}`; |
import { isKeyOf, whiteSpaceTokens } from "@ark/util"; | ||
import { Scanner } from "../scanner.js"; | ||
import { comparatorStartChars, parseBound } from "./bounds.js"; | ||
import { parseBrand } from "./brand.js"; | ||
import { parseDivisor } from "./divisor.js"; | ||
@@ -18,6 +19,7 @@ export const parseOperator = (s) => { | ||
: lookahead === "%" ? parseDivisor(s) | ||
: lookahead in whiteSpaceTokens ? parseOperator(s) | ||
: s.error(writeUnexpectedCharacterMessage(lookahead))); | ||
: lookahead === "#" ? parseBrand(s) | ||
: lookahead in whiteSpaceTokens ? parseOperator(s) | ||
: s.error(writeUnexpectedCharacterMessage(lookahead))); | ||
}; | ||
export const writeUnexpectedCharacterMessage = (char, shouldBe = "") => `'${char}' is not allowed here${shouldBe && ` (should be ${shouldBe})`}`; | ||
export const incompleteArrayTokenMessage = `Missing expected ']'`; |
@@ -38,2 +38,3 @@ import { type Dict, type EscapeToken, type WhiteSpaceToken } from "@ark/util"; | ||
readonly "?": true; | ||
readonly "#": true; | ||
}; | ||
@@ -60,4 +61,4 @@ static finalizingLookaheads: { | ||
type FinalizingLookahead = keyof typeof Scanner.finalizingLookaheads; | ||
type InfixToken = Comparator | "|" | "&" | "%" | ":" | "=>"; | ||
type PostfixToken = "[]"; | ||
type InfixToken = Comparator | "|" | "&" | "%" | ":" | "=>" | "#" | "@" | "="; | ||
type PostfixToken = "[]" | "?"; | ||
type OperatorToken = InfixToken | PostfixToken; | ||
@@ -64,0 +65,0 @@ type shift<lookahead extends string, unscanned extends string> = `${lookahead}${unscanned}`; |
@@ -78,2 +78,3 @@ import { escapeToken, isKeyOf, whiteSpaceTokens } from "@ark/util"; | ||
"?": true, | ||
"#": true, | ||
...whiteSpaceTokens | ||
@@ -80,0 +81,0 @@ }; |
import { type BaseParseContext, type BaseRoot, type MetaSchema, type Morph, type Predicate } from "@ark/schema"; | ||
import { type anyOrNever, type array, type BuiltinObjectKind, type conform, type Constructor, type Domain, type ErrorMessage, type show } from "@ark/util"; | ||
import type { applyConstraint, Default, distill, inferIntersection, inferMorphOut, inferPredicate, InferredOptional, Optional, Out } from "../keywords/inference.ts"; | ||
import type { applyAttribute, Default, DefaultFor, distill, inferIntersection, inferMorphOut, inferPredicate, InferredOptional, Optional, Out } from "../keywords/inference.ts"; | ||
import type { type } from "../keywords/keywords.ts"; | ||
import type { InfixOperator, PostfixExpression } from "./ast/infer.ts"; | ||
import type { PostfixExpression } from "./ast/infer.ts"; | ||
import type { inferDefinition, validateDefinition } from "./definition.ts"; | ||
import { writeMissingRightOperandMessage } from "./shift/operand/unenclosed.ts"; | ||
import type { Scanner } from "./shift/scanner.ts"; | ||
import type { BaseCompletions } from "./string.ts"; | ||
export declare const parseTuple: (def: array, ctx: BaseParseContext) => BaseRoot; | ||
export declare const parseTupleLiteral: (def: array, ctx: BaseParseContext) => BaseRoot; | ||
type InfixExpression = readonly [unknown, InfixOperator, ...unknown[]]; | ||
type InfixExpression = readonly [unknown, Scanner.InfixToken, ...unknown[]]; | ||
export type validateTuple<def extends array, $, args> = def extends IndexZeroExpression ? validatePrefixExpression<def, $, args> : def extends PostfixExpression ? validatePostfixExpression<def, $, args> : def extends InfixExpression ? validateInfixExpression<def, $, args> : def extends (readonly ["", ...unknown[]] | readonly [unknown, "", ...unknown[]]) ? readonly [ | ||
@@ -113,3 +114,3 @@ def[0] extends "" ? BaseCompletions<$, args, IndexZeroOperator | "..."> : def[0], | ||
export type inferTuple<def extends array, $, args> = def extends TupleExpression ? inferTupleExpression<def, $, args> : inferTupleLiteral<def, $, args>; | ||
export type inferTupleExpression<def extends TupleExpression, $, args> = def[1] extends "[]" ? inferDefinition<def[0], $, args>[] : def[1] extends "&" ? inferIntersection<inferDefinition<def[0], $, args>, inferDefinition<def[2], $, args>> : def[1] extends "|" ? inferDefinition<def[0], $, args> | inferDefinition<def[2], $, args> : def[1] extends ":" ? inferPredicate<inferDefinition<def[0], $, args>, def[2]> : def[1] extends "=>" ? parseMorph<def[0], def[2], $, args> : def[1] extends "@" ? inferDefinition<def[0], $, args> : def[1] extends "=" ? applyConstraint<inferDefinition<def[0], $, args>, Default<def[2]>> : def[1] extends "?" ? applyConstraint<inferDefinition<def[0], $, args>, Optional> : def extends readonly ["===", ...infer values] ? values[number] : def extends (readonly ["instanceof", ...infer constructors extends Constructor[]]) ? InstanceType<constructors[number]> : def[0] extends "keyof" ? inferKeyOfExpression<def[1], $, args> : never; | ||
export type inferTupleExpression<def extends TupleExpression, $, args> = def[1] extends "[]" ? inferDefinition<def[0], $, args>[] : def[1] extends "&" ? inferIntersection<inferDefinition<def[0], $, args>, inferDefinition<def[2], $, args>> : def[1] extends "|" ? inferDefinition<def[0], $, args> | inferDefinition<def[2], $, args> : def[1] extends ":" ? inferPredicate<inferDefinition<def[0], $, args>, def[2]> : def[1] extends "=>" ? parseMorph<def[0], def[2], $, args> : def[1] extends "@" ? inferDefinition<def[0], $, args> : def[1] extends "=" ? applyAttribute<inferDefinition<def[0], $, args>, Default<def[2]>> : def[1] extends "?" ? applyAttribute<inferDefinition<def[0], $, args>, Optional> : def extends readonly ["===", ...infer values] ? values[number] : def extends (readonly ["instanceof", ...infer constructors extends Constructor[]]) ? InstanceType<constructors[number]> : def[0] extends "keyof" ? inferKeyOfExpression<def[1], $, args> : never; | ||
export type validatePrefixExpression<def extends IndexZeroExpression, $, args> = def["length"] extends 1 ? readonly [writeMissingRightOperandMessage<def[0]>] : def[0] extends "keyof" ? readonly [def[0], validateDefinition<def[1], $, args>] : def[0] extends "===" ? readonly [def[0], ...unknown[]] : def[0] extends "instanceof" ? readonly [def[0], ...Constructor[]] : never; | ||
@@ -120,3 +121,3 @@ export type validatePostfixExpression<def extends PostfixExpression, $, args> = conform<def, readonly [validateDefinition<def[0], $, args>, "[]" | "?"]>; | ||
def[1], | ||
def[1] extends "|" ? validateDefinition<def[2], $, args> : def[1] extends "&" ? validateDefinition<def[2], $, args> : def[1] extends ":" ? Predicate<type.infer.Out<def[0], $, args>> : def[1] extends "=>" ? Morph<type.infer.Out<def[0], $, args>> : def[1] extends "@" ? MetaSchema : def[1] extends "=" ? type.infer.Out<def[0], $, args> : validateDefinition<def[2], $, args> | ||
def[1] extends "|" ? validateDefinition<def[2], $, args> : def[1] extends "&" ? validateDefinition<def[2], $, args> : def[1] extends ":" ? Predicate<type.infer.Out<def[0], $, args>> : def[1] extends "=>" ? Morph<type.infer.Out<def[0], $, args>> : def[1] extends "@" ? MetaSchema : def[1] extends "=" ? DefaultFor<type.infer.In<def[0], $, args>> : validateDefinition<def[2], $, args> | ||
]; | ||
@@ -123,0 +124,0 @@ export type UnparsedTupleExpressionInput = { |
import { ArkErrors, BaseRoot, type BaseParseOptions, type MetaSchema, type Morph, type Predicate, type RootSchema } from "@ark/schema"; | ||
import { Callable, Hkt, type Constructor, type array, type conform } from "@ark/util"; | ||
import type { Generic, GenericParser, ParameterString, baseGenericConstraints, parseValidGenericParams, validateParameterString } from "./generic.ts"; | ||
import type { distill } from "./keywords/inference.ts"; | ||
import type { DefaultFor, distill } from "./keywords/inference.ts"; | ||
import type { Ark, keywords, type } from "./keywords/keywords.ts"; | ||
@@ -16,3 +16,3 @@ import type { BaseType } from "./methods/base.ts"; | ||
<const params extends ParameterString, const def>(params: validateParameterString<params, $>, def: validateDefinition<def, $, baseGenericConstraints<parseValidGenericParams<params, $>>>): Generic<parseValidGenericParams<params, $>, def, $>; | ||
<const zero, const one, const rest extends array, r = Type<type.infer<[zero, one, ...rest], $>, $>>(_0: zero extends IndexZeroOperator ? zero : type.validate<zero, $>, _1: zero extends "keyof" ? type.validate<one, $> : zero extends "instanceof" ? conform<one, Constructor> : zero extends "===" ? conform<one, unknown> : conform<one, IndexOneOperator>, ..._2: zero extends "===" ? rest : zero extends "instanceof" ? conform<rest, readonly Constructor[]> : one extends TupleInfixOperator ? one extends ":" ? [Predicate<distill.In<type.infer<zero, $>>>] : one extends "=>" ? [Morph<distill.Out<type.infer<zero, $>>, unknown>] : one extends "@" ? [MetaSchema] : one extends "=" ? [distill.In<type.infer<NoInfer<zero>, $>>] : [type.validate<rest[0], $>] : []): r; | ||
<const zero, const one, const rest extends array, r = Type<type.infer<[zero, one, ...rest], $>, $>>(_0: zero extends IndexZeroOperator ? zero : type.validate<zero, $>, _1: zero extends "keyof" ? type.validate<one, $> : zero extends "instanceof" ? conform<one, Constructor> : zero extends "===" ? conform<one, unknown> : conform<one, IndexOneOperator>, ..._2: zero extends "===" ? rest : zero extends "instanceof" ? conform<rest, readonly Constructor[]> : one extends TupleInfixOperator ? one extends ":" ? [Predicate<distill.In<type.infer<zero, $>>>] : one extends "=>" ? [Morph<distill.Out<type.infer<zero, $>>, unknown>] : one extends "@" ? [MetaSchema] : one extends "=" ? [DefaultFor<distill.In<type.infer<NoInfer<zero>, $>>>] : [type.validate<rest[0], $>] : []): r; | ||
errors: typeof ArkErrors; | ||
@@ -19,0 +19,0 @@ hkt: typeof Hkt; |
{ | ||
"name": "arktype", | ||
"description": "TypeScript's 1:1 validator, optimized from editor to runtime", | ||
"version": "2.0.0-rc.11", | ||
"version": "2.0.0-rc.12", | ||
"license": "MIT", | ||
@@ -37,4 +37,4 @@ "author": { | ||
"dependencies": { | ||
"@ark/util": "0.13.0", | ||
"@ark/schema": "0.13.0" | ||
"@ark/util": "0.14.0", | ||
"@ark/schema": "0.14.0" | ||
}, | ||
@@ -41,0 +41,0 @@ "publishConfig": { |
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
230281
148
4470
+ Added@ark/schema@0.14.0(transitive)
+ Added@ark/util@0.14.0(transitive)
- Removed@ark/schema@0.13.0(transitive)
- Removed@ark/util@0.13.0(transitive)
Updated@ark/schema@0.14.0
Updated@ark/util@0.14.0