Comparing version 2.0.0-rc.17 to 2.0.0-rc.18
@@ -114,4 +114,4 @@ import type { ArkError, ArkErrors, Constraint, constraintKindOf, Morph, NodeSchema } from "@ark/schema"; | ||
export type brandAttributes<t, attributes extends Attributes> = attachAttributes<t, attributes, "brand">; | ||
type attachAttributes<t, attributes extends Attributes, behavior extends AttributeInferenceBehavior = "associate"> = t extends InferredMorph<infer i, infer o> ? (In: leftIfEqual<i, _attachAttributes<i, attributes, behavior>>) => o : leftIfEqual<t, _attachAttributes<t, attributes, behavior>>; | ||
type _attachAttributes<t, attributes extends Attributes, behavior extends AttributeInferenceBehavior> = t extends null | undefined ? t : t extends of<infer base, infer existingAttributes> ? "brand" extends keyof t[attributesKey] | behavior ? brandMultiple<base, existingAttributes & attributes> : associateMultiple<base, existingAttributes & attributes> : extractIfSingleAttributeEntry<attributes> extends (AttributeEntry<infer kind, infer value>) ? "brand" extends behavior ? brandSingle<t, attributes, kind, value> : associateSingle<t, attributes, kind, value> : "brand" extends behavior ? brandMultiple<t, attributes> : associateMultiple<t, attributes>; | ||
type attachAttributes<t, attributes extends Attributes, behavior extends AttributeInferenceBehavior = "associate", unmorphedT = Exclude<t, InferredMorph>> = t extends InferredMorph<infer i, infer o> ? (In: leftIfEqual<i, _attachAttributes<i, attributes, behavior>>) => o : leftIfEqual<unmorphedT, _attachAttributes<unmorphedT, attributes, behavior>>; | ||
type _attachAttributes<t, attributes extends Attributes, behavior extends AttributeInferenceBehavior, distributed = t> = distributed extends null | undefined ? distributed : distributed extends of<infer base, infer existingAttributes> ? "brand" extends keyof distributed[attributesKey] | behavior ? brandMultiple<base, existingAttributes & attributes> : associateMultiple<base, existingAttributes & attributes> : extractIfSingleAttributeEntry<attributes> extends (AttributeEntry<infer kind, infer value>) ? "brand" extends behavior ? brandSingle<t, attributes, kind, value> : associateSingle<t, attributes, kind, value> : "brand" extends behavior ? brandMultiple<t, attributes> : associateMultiple<t, attributes>; | ||
type associateMultiple<t, attributes extends Attributes> = [ | ||
@@ -166,2 +166,6 @@ t, | ||
export type associateAttributesFromSchema<t, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = associateAttributes<t, schemaToAttributes<kind, schema>>; | ||
export type associateAttributesFromStringSchema<t extends string, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = conform<associateAttributes<t, schemaToAttributes<kind, schema>>, string>; | ||
export type associateAttributesFromNumberSchema<t extends number, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = conform<associateAttributes<t, schemaToAttributes<kind, schema>>, number>; | ||
export type associateAttributesFromDateSchema<t extends Date, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = conform<associateAttributes<t, schemaToAttributes<kind, schema>>, Date>; | ||
export type associateAttributesFromArraySchema<t extends readonly unknown[], kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = conform<associateAttributes<t, schemaToAttributes<kind, schema>>, readonly unknown[]>; | ||
export type schemaToAttributes<kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = normalizePrimitiveConstraintRoot<schema> extends infer rule ? kind extends "pattern" ? Matching<rule> : kind extends "divisor" ? DivisibleBy<rule> : kind extends "min" ? number.minSchemaToConstraint<schema, rule> : kind extends "max" ? number.maxSchemaToConstraint<schema, rule> : kind extends "minLength" ? minLengthSchemaToConstraint<schema, rule> : kind extends "maxLength" ? maxLengthSchemaToConstraint<schema, rule> : kind extends "exactLength" ? ExactlyLength<rule> : kind extends "after" ? Date.afterSchemaToConstraint<schema, rule> : kind extends "before" ? Date.beforeSchemaToConstraint<schema, rule> : Anonymous : never; | ||
@@ -168,0 +172,0 @@ export type distill<t, opts extends distill.Options = {}> = finalizeDistillation<t, _distill<t, opts>>; |
@@ -29,2 +29,4 @@ import type { ArkErrors, arkKind } from "@ark/schema"; | ||
Record: arkTsGenerics.$["Record"]; | ||
Date: arkPrototypes.$["Date"]; | ||
Array: arkPrototypes.$["Array"]["root"]; | ||
} | ||
@@ -31,0 +33,0 @@ interface boundTypeAttachments<$> extends Omit<BoundModule<typeAttachments, $>, arkKind> { |
@@ -10,3 +10,5 @@ import { $arkTypeRegistry, scope } from "../scope.js"; | ||
Key: arkBuiltins.Key, | ||
Record: arkTsGenerics.Record | ||
Record: arkTsGenerics.Record, | ||
Array: arkPrototypes.Array.root, | ||
Date: arkPrototypes.Date | ||
}; | ||
@@ -13,0 +15,0 @@ export const ark = scope({ |
import type { ExactLength, ExclusiveNumericRangeSchema, exclusivizeRangeSchema, InclusiveNumericRangeSchema } from "@ark/schema"; | ||
import type { associateAttributesFromSchema } from "../attributes.ts"; | ||
import type { associateAttributesFromArraySchema } from "../attributes.ts"; | ||
import type { ObjectType } from "./object.ts"; | ||
@@ -7,8 +7,8 @@ interface Type< | ||
out t extends readonly unknown[] = readonly unknown[], $ = {}> extends ObjectType<t, $> { | ||
atLeastLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromSchema<t, "minLength", schema>, $>; | ||
atMostLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromSchema<t, "maxLength", schema>, $>; | ||
moreThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromSchema<t, "minLength", exclusivizeRangeSchema<schema>>, $>; | ||
lessThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromSchema<t, "maxLength", exclusivizeRangeSchema<schema>>, $>; | ||
exactlyLength<const schema extends ExactLength.Schema>(schema: schema): Type<associateAttributesFromSchema<t, "exactLength", schema>, $>; | ||
atLeastLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromArraySchema<t, "minLength", schema>, $>; | ||
atMostLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromArraySchema<t, "maxLength", schema>, $>; | ||
moreThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromArraySchema<t, "minLength", exclusivizeRangeSchema<schema>>, $>; | ||
lessThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromArraySchema<t, "maxLength", exclusivizeRangeSchema<schema>>, $>; | ||
exactlyLength<const schema extends ExactLength.Schema>(schema: schema): Type<associateAttributesFromArraySchema<t, "exactLength", schema>, $>; | ||
} | ||
export type { Type as ArrayType }; |
import type { ExclusiveDateRangeSchema, exclusivizeRangeSchema, InclusiveDateRangeSchema } from "@ark/schema"; | ||
import type { associateAttributesFromSchema } from "../attributes.ts"; | ||
import type { associateAttributesFromDateSchema } from "../attributes.ts"; | ||
import type { ObjectType } from "./object.ts"; | ||
/** @ts-ignore cast variance */ | ||
interface Type<out t extends globalThis.Date = globalThis.Date, $ = {}> extends ObjectType<t, $> { | ||
atOrAfter<const schema extends InclusiveDateRangeSchema>(schema: schema): Type<associateAttributesFromSchema<t, "after", schema>, $>; | ||
atOrBefore<const schema extends InclusiveDateRangeSchema>(schema: schema): Type<associateAttributesFromSchema<t, "before", schema>, $>; | ||
laterThan<const schema extends ExclusiveDateRangeSchema>(schema: schema): Type<associateAttributesFromSchema<t, "after", exclusivizeRangeSchema<schema>>, $>; | ||
earlierThan<const schema extends ExclusiveDateRangeSchema>(schema: schema): Type<associateAttributesFromSchema<t, "before", exclusivizeRangeSchema<schema>>, $>; | ||
atOrAfter<const schema extends InclusiveDateRangeSchema>(schema: schema): Type<associateAttributesFromDateSchema<t, "after", schema>, $>; | ||
atOrBefore<const schema extends InclusiveDateRangeSchema>(schema: schema): Type<associateAttributesFromDateSchema<t, "before", schema>, $>; | ||
laterThan<const schema extends ExclusiveDateRangeSchema>(schema: schema): Type<associateAttributesFromDateSchema<t, "after", exclusivizeRangeSchema<schema>>, $>; | ||
earlierThan<const schema extends ExclusiveDateRangeSchema>(schema: schema): Type<associateAttributesFromDateSchema<t, "before", exclusivizeRangeSchema<schema>>, $>; | ||
} | ||
export type { Type as DateType }; |
import type { Divisor, ExclusiveNumericRangeSchema, exclusivizeRangeSchema, InclusiveNumericRangeSchema } from "@ark/schema"; | ||
import type { associateAttributesFromSchema } from "../attributes.ts"; | ||
import type { associateAttributesFromNumberSchema } from "../attributes.ts"; | ||
import type { BaseType } from "./base.ts"; | ||
/** @ts-ignore cast variance */ | ||
interface Type<out t extends number = number, $ = {}> extends BaseType<t, $> { | ||
divisibleBy<const schema extends Divisor.Schema>(schema: schema): Type<associateAttributesFromSchema<t, "divisor", schema>, $>; | ||
atLeast<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromSchema<t, "min", schema>, $>; | ||
atMost<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromSchema<t, "max", schema>, $>; | ||
moreThan<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromSchema<t, "min", exclusivizeRangeSchema<schema>>, $>; | ||
lessThan<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromSchema<t, "max", exclusivizeRangeSchema<schema>>, $>; | ||
divisibleBy<const schema extends Divisor.Schema>(schema: schema): Type<associateAttributesFromNumberSchema<t, "divisor", schema>, $>; | ||
atLeast<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromNumberSchema<t, "min", schema>, $>; | ||
atMost<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromNumberSchema<t, "max", schema>, $>; | ||
moreThan<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromNumberSchema<t, "min", exclusivizeRangeSchema<schema>>, $>; | ||
lessThan<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromNumberSchema<t, "max", exclusivizeRangeSchema<schema>>, $>; | ||
} | ||
export type { Type as NumberType }; |
import type { ExactLength, ExclusiveNumericRangeSchema, exclusivizeRangeSchema, InclusiveNumericRangeSchema, Pattern } from "@ark/schema"; | ||
import type { associateAttributesFromSchema } from "../attributes.ts"; | ||
import type { associateAttributesFromStringSchema } from "../attributes.ts"; | ||
import type { BaseType } from "./base.ts"; | ||
/** @ts-ignore cast variance */ | ||
interface Type<out t extends string = string, $ = {}> extends BaseType<t, $> { | ||
matching<const schema extends Pattern.Schema>(schema: schema): Type<associateAttributesFromSchema<t, "pattern", schema>, $>; | ||
atLeastLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromSchema<t, "minLength", schema>, $>; | ||
atMostLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromSchema<t, "maxLength", schema>, $>; | ||
moreThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromSchema<t, "minLength", exclusivizeRangeSchema<schema>>, $>; | ||
lessThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromSchema<t, "maxLength", exclusivizeRangeSchema<schema>>, $>; | ||
exactlyLength<const schema extends ExactLength.Schema>(schema: schema): Type<associateAttributesFromSchema<t, "exactLength", schema>, $>; | ||
matching<const schema extends Pattern.Schema>(schema: schema): Type<associateAttributesFromStringSchema<t, "pattern", schema>, $>; | ||
atLeastLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromStringSchema<t, "minLength", schema>, $>; | ||
atMostLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromStringSchema<t, "maxLength", schema>, $>; | ||
moreThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromStringSchema<t, "minLength", exclusivizeRangeSchema<schema>>, $>; | ||
lessThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<associateAttributesFromStringSchema<t, "maxLength", exclusivizeRangeSchema<schema>>, $>; | ||
exactlyLength<const schema extends ExactLength.Schema>(schema: schema): Type<associateAttributesFromStringSchema<t, "exactLength", schema>, $>; | ||
} | ||
export type { Type as StringType }; |
@@ -9,3 +9,3 @@ import { BaseScope, type AliasDefEntry, type ArkScopeConfig, type BaseNode, type BaseParseContext, type BaseParseContextInput, type BaseParseOptions, type BaseRoot, type GenericAst, type GenericParamAst, type GenericParamDef, type NodeKind, type NodeSchema, type PreparsedNodeResolution, type PrivateDeclaration, type RootKind, type RootSchema, type arkKind, type exportedNameOf, type nodeOfKind, type reducibleKindOf, type toInternalScope, type writeDuplicateAliasError } from "@ark/schema"; | ||
import { type inferDefinition, type validateDefinition } from "./parser/definition.ts"; | ||
import { InternalTypeParser, type DeclarationParser, type DefinitionParser, type EnumeratedTypeParser, type SchemaParser, type TypeParser, type UnitTypeParser } from "./type.ts"; | ||
import { InternalTypeParser, type DeclarationParser, type DefinitionParser, type EnumeratedTypeParser, type InstanceOfTypeParser, type SchemaParser, type TypeParser, type UnitTypeParser } from "./type.ts"; | ||
/** The convenience properties attached to `scope` */ | ||
@@ -78,2 +78,3 @@ export type ScopeParserAttachments = Omit<ScopeParser, never>; | ||
enumerated: EnumeratedTypeParser<$>; | ||
instanceOf: InstanceOfTypeParser<$>; | ||
type: InternalTypeParser; | ||
@@ -80,0 +81,0 @@ declare: () => { |
@@ -95,2 +95,3 @@ import { $ark, BaseScope, hasArkKind, parseGeneric } from "@ark/schema"; | ||
enumerated = (...values) => this.units(values); | ||
instanceOf = ctor => this.node("proto", { proto: ctor }, { prereduced: true }); | ||
type = new InternalTypeParser(this); | ||
@@ -97,0 +98,0 @@ declare = () => ({ |
@@ -45,2 +45,7 @@ import { ArkErrors, BaseRoot, type BaseParseOptions, type MetaSchema, type Morph, type Predicate, type RootSchema } from "@ark/schema"; | ||
enumerated: EnumeratedTypeParser<$>; | ||
/** | ||
* Create a `Type` that is satisfied only by a value of a specific class. | ||
* @example const array = type.instanceOf(Array) | ||
*/ | ||
instanceOf: InstanceOfTypeParser<$>; | ||
} | ||
@@ -54,2 +59,3 @@ export declare class InternalTypeParser extends Callable<(...args: unknown[]) => BaseRoot | Generic, TypeParserAttachments> { | ||
export type UnitTypeParser<$> = <const t>(value: t) => Type<t, $>; | ||
export type InstanceOfTypeParser<$> = <const t extends object>(ctor: Constructor<t>) => Type<t, $>; | ||
export type EnumeratedTypeParser<$> = <const values extends readonly unknown[]>(...values: values) => Type<values[number], $>; | ||
@@ -56,0 +62,0 @@ export type DefinitionParser<$> = <const def>(def: type.validate<def, $>) => def; |
@@ -18,3 +18,4 @@ import { ArkErrors, BaseRoot, GenericRoot } from "@ark/schema"; | ||
unit: $.unit, | ||
enumerated: $.enumerated | ||
enumerated: $.enumerated, | ||
instanceOf: $.instanceOf | ||
}, | ||
@@ -21,0 +22,0 @@ // also won't be defined during bootstrapping |
{ | ||
"name": "arktype", | ||
"description": "TypeScript's 1:1 validator, optimized from editor to runtime", | ||
"version": "2.0.0-rc.17", | ||
"version": "2.0.0-rc.18", | ||
"license": "MIT", | ||
@@ -37,4 +37,4 @@ "author": { | ||
"dependencies": { | ||
"@ark/util": "0.18.0", | ||
"@ark/schema": "0.19.0" | ||
"@ark/util": "0.19.0", | ||
"@ark/schema": "0.20.0" | ||
}, | ||
@@ -41,0 +41,0 @@ "publishConfig": { |
248337
4778
+ Added@ark/schema@0.20.0(transitive)
+ Added@ark/util@0.19.0(transitive)
- Removed@ark/schema@0.19.0(transitive)
- Removed@ark/util@0.18.0(transitive)
Updated@ark/schema@0.20.0
Updated@ark/util@0.19.0