arktype 2.0.0-rc.14 → 2.0.0-rc.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/out/{keywords/inference.d.ts → attributes.d.ts} +143 -54
  2. package/out/attributes.js +2 -0
  3. package/out/keywords/constructors/Array.d.ts +1 -1
  4. package/out/keywords/constructors/Date.d.ts +23 -18
  5. package/out/keywords/constructors/FormData.d.ts +1 -1
  6. package/out/keywords/keywords.d.ts +4 -4
  7. package/out/keywords/number/epoch.d.ts +2 -1
  8. package/out/keywords/number/number.d.ts +28 -28
  9. package/out/keywords/string/alpha.d.ts +2 -2
  10. package/out/keywords/string/alphanumeric.d.ts +2 -2
  11. package/out/keywords/string/base64.d.ts +3 -3
  12. package/out/keywords/string/capitalize.d.ts +2 -2
  13. package/out/keywords/string/creditCard.d.ts +2 -2
  14. package/out/keywords/string/date.d.ts +4 -4
  15. package/out/keywords/string/digits.d.ts +2 -2
  16. package/out/keywords/string/email.d.ts +2 -2
  17. package/out/keywords/string/integer.d.ts +2 -2
  18. package/out/keywords/string/ip.d.ts +4 -4
  19. package/out/keywords/string/json.d.ts +2 -2
  20. package/out/keywords/string/lower.d.ts +2 -2
  21. package/out/keywords/string/normalize.d.ts +5 -5
  22. package/out/keywords/string/numeric.d.ts +2 -2
  23. package/out/keywords/string/semver.d.ts +2 -2
  24. package/out/keywords/string/string.d.ts +26 -7
  25. package/out/keywords/string/trim.d.ts +2 -2
  26. package/out/keywords/string/upper.d.ts +2 -2
  27. package/out/keywords/string/url.d.ts +2 -2
  28. package/out/keywords/string/uuid.d.ts +10 -10
  29. package/out/keywords/ts.d.ts +1 -1
  30. package/out/methods/array.d.ts +6 -6
  31. package/out/methods/base.d.ts +96 -12
  32. package/out/methods/date.d.ts +5 -5
  33. package/out/methods/instantiate.d.ts +1 -1
  34. package/out/methods/morph.d.ts +5 -1
  35. package/out/methods/number.d.ts +6 -6
  36. package/out/methods/object.d.ts +31 -3
  37. package/out/methods/string.d.ts +7 -7
  38. package/out/parser/ast/bounds.d.ts +1 -1
  39. package/out/parser/ast/infer.d.ts +8 -7
  40. package/out/parser/objectLiteral.d.ts +1 -1
  41. package/out/parser/reduce/dynamic.d.ts +1 -1
  42. package/out/parser/reduce/shared.d.ts +1 -1
  43. package/out/parser/reduce/static.d.ts +1 -1
  44. package/out/parser/shift/operand/date.d.ts +1 -1
  45. package/out/parser/shift/operand/enclosed.d.ts +2 -2
  46. package/out/parser/shift/operator/bounds.d.ts +1 -1
  47. package/out/parser/shift/operator/default.d.ts +1 -1
  48. package/out/parser/tuple.d.ts +4 -4
  49. package/out/scope.d.ts +6 -1
  50. package/out/scope.js +3 -1
  51. package/out/type.d.ts +17 -1
  52. package/package.json +3 -3
  53. package/out/keywords/inference.js +0 -2
  54. package/out/keywords/string/brands.d.ts +0 -17
  55. package/out/keywords/string/brands.js +0 -1
@@ -1,6 +1,6 @@
1
1
  import type { BaseParseContext, BaseRoot } from "@ark/schema";
2
2
  import { type requireKeys } from "@ark/util";
3
- import type { LimitLiteral } from "../../keywords/inference.ts";
3
+ import type { LimitLiteral } from "../../attributes.ts";
4
4
  import type { Scanner } from "../shift/scanner.ts";
5
5
  import { type Comparator, type MinComparator, type OpenLeftBound, type StringifiablePrefixOperator } from "./shared.ts";
6
6
  type BranchState = {
@@ -1,4 +1,4 @@
1
- import type { LimitLiteral } from "../../keywords/inference.ts";
1
+ import type { LimitLiteral } from "../../attributes.ts";
2
2
  export type StringifiablePrefixOperator = "keyof";
3
3
  export declare const minComparators: {
4
4
  readonly ">": true;
@@ -1,5 +1,5 @@
1
1
  import type { Completion, ErrorMessage, defined } from "@ark/util";
2
- import type { LimitLiteral } from "../../keywords/inference.ts";
2
+ import type { LimitLiteral } from "../../attributes.ts";
3
3
  import type { Scanner } from "../shift/scanner.ts";
4
4
  import type { Comparator, InvertedComparators, MaxComparator, MinComparator, OpenLeftBound, StringifiablePrefixOperator, writeMultipleLeftBoundsMessage, writeOpenRangeMessage, writeUnclosedGroupMessage, writeUnmatchedGroupCloseMessage, writeUnpairableComparatorMessage } from "./shared.ts";
5
5
  export type StaticState = {
@@ -1,4 +1,4 @@
1
- import type { DateLiteral } from "../../../keywords/inference.ts";
1
+ import type { DateLiteral } from "../../../attributes.ts";
2
2
  export declare const isDateLiteral: (value: unknown) => value is DateLiteral;
3
3
  export declare const isValidDate: (d: Date) => boolean;
4
4
  export declare const extractDateLiteralSource: <literal extends DateLiteral>(literal: literal) => extractDateLiteralSource<literal>;
@@ -1,5 +1,5 @@
1
+ import type { string } from "../../../attributes.ts";
1
2
  import type { Date } from "../../../keywords/constructors/Date.ts";
2
- import type { string } from "../../../keywords/inference.ts";
3
3
  import type { InferredAst } from "../../ast/infer.ts";
4
4
  import type { DynamicState } from "../../reduce/dynamic.ts";
5
5
  import type { StaticState, state } from "../../reduce/static.ts";
@@ -8,7 +8,7 @@ export type StringLiteral<Text extends string = string> = DoubleQuotedStringLite
8
8
  export type DoubleQuotedStringLiteral<Text extends string = string> = `"${Text}"`;
9
9
  export type SingleQuotedStringLiteral<Text extends string = string> = `'${Text}'`;
10
10
  export declare const parseEnclosed: (s: DynamicState, enclosing: EnclosingStartToken) => void;
11
- export type parseEnclosed<s extends StaticState, enclosingStart extends EnclosingStartToken, unscanned extends string> = Scanner.shiftUntil<unscanned, EnclosingTokens[enclosingStart]> extends (Scanner.shiftResult<infer scanned, infer nextUnscanned>) ? nextUnscanned extends "" ? state.error<writeUnterminatedEnclosedMessage<scanned, enclosingStart>> : state.setRoot<s, InferredAst<enclosingStart extends EnclosingQuote ? scanned : enclosingStart extends "/" ? string.matching<scanned> : Date.literal<scanned>, `${enclosingStart}${scanned}${EnclosingTokens[enclosingStart]}`>, nextUnscanned extends Scanner.shift<string, infer unscanned> ? unscanned : ""> : never;
11
+ export type parseEnclosed<s extends StaticState, enclosingStart extends EnclosingStartToken, unscanned extends string> = Scanner.shiftUntil<unscanned, EnclosingTokens[enclosingStart]> extends (Scanner.shiftResult<infer scanned, infer nextUnscanned>) ? nextUnscanned extends "" ? state.error<writeUnterminatedEnclosedMessage<scanned, enclosingStart>> : state.setRoot<s, InferredAst<enclosingStart extends EnclosingQuote ? scanned : enclosingStart extends "/" ? string.matching<scanned> : Date.nominal<scanned>, `${enclosingStart}${scanned}${EnclosingTokens[enclosingStart]}`>, nextUnscanned extends Scanner.shift<string, infer unscanned> ? unscanned : ""> : never;
12
12
  export declare const enclosingQuote: {
13
13
  readonly "'": 1;
14
14
  readonly '"': 1;
@@ -1,6 +1,6 @@
1
1
  import { type BaseRoot, type BoundKind } from "@ark/schema";
2
2
  import { type keySet } from "@ark/util";
3
- import type { DateLiteral } from "../../../keywords/inference.ts";
3
+ import type { DateLiteral } from "../../../attributes.ts";
4
4
  import type { InferredAst } from "../../ast/infer.ts";
5
5
  import type { astToString } from "../../ast/utils.ts";
6
6
  import type { DynamicState, DynamicStateWithRoot } from "../../reduce/dynamic.ts";
@@ -1,6 +1,6 @@
1
1
  import type { BaseRoot } from "@ark/schema";
2
2
  import type { BigintLiteral, ErrorMessage, NumberLiteral, trim } from "@ark/util";
3
- import type { DateLiteral } from "../../../keywords/inference.ts";
3
+ import type { DateLiteral } from "../../../attributes.ts";
4
4
  import type { DynamicStateWithRoot } from "../../reduce/dynamic.ts";
5
5
  import type { StringLiteral } from "../operand/enclosed.ts";
6
6
  type UnitLiteralKeyword = "null" | "undefined" | "true" | "false";
@@ -1,6 +1,6 @@
1
1
  import { type BaseParseContext, type BaseRoot, type MetaSchema, type Morph, type Predicate } from "@ark/schema";
2
- import { type anyOrNever, type array, type BuiltinObjectKind, type conform, type Constructor, type Domain, type ErrorMessage, type show } from "@ark/util";
3
- import type { applyAttribute, Default, DefaultFor, distill, inferIntersection, inferMorphOut, inferPredicate, InferredOptional, Optional, Out } from "../keywords/inference.ts";
2
+ import { type anyOrNever, type array, type BuiltinObjectKind, type conform, type Constructor, type Domain, type ErrorMessage, type show, type Thunk } from "@ark/util";
3
+ import type { associateAttributes, Default, DefaultFor, distill, inferIntersection, inferMorphOut, inferPredicate, InferredOptional, Optional, Out } from "../attributes.ts";
4
4
  import type { type } from "../keywords/keywords.ts";
5
5
  import type { PostfixExpression } from "./ast/infer.ts";
6
6
  import type { inferDefinition, validateDefinition } from "./definition.ts";
@@ -111,7 +111,7 @@ type optionalPostVariadicMessage = typeof optionalPostVariadicMessage;
111
111
  export declare const spreadOptionalMessage = "A spread element cannot be optional";
112
112
  type spreadOptionalMessage = typeof optionalPostVariadicMessage;
113
113
  export type inferTuple<def extends array, $, args> = def extends TupleExpression ? inferTupleExpression<def, $, args> : inferTupleLiteral<def, $, args>;
114
- 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;
114
+ 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 "=" ? associateAttributes<inferDefinition<def[0], $, args>, Default<def[2] extends Thunk<infer returnValue> ? returnValue : def[2]>> : def[1] extends "?" ? associateAttributes<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;
115
115
  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;
116
116
  export type validatePostfixExpression<def extends PostfixExpression, $, args> = conform<def, readonly [validateDefinition<def[0], $, args>, "[]" | "?"]>;
117
117
  export type validateInfixExpression<def extends InfixExpression, $, args> = def["length"] extends 2 ? readonly [def[0], writeMissingRightOperandMessage<def[1]>] : readonly [
@@ -136,7 +136,7 @@ export type TupleInfixOperator = "&" | "|" | "=>" | ":" | "@" | "=";
136
136
  export type IndexOneExpression<token extends IndexOneOperator = IndexOneOperator> = readonly [unknown, token, ...unknown[]];
137
137
  export declare const parseMorphTuple: IndexOneParser<"=>">;
138
138
  export declare const writeMalformedFunctionalExpressionMessage: (operator: ":" | "=>", value: unknown) => string;
139
- export type parseMorph<inDef, morph, $, args> = morph extends Morph ? inferMorphOut<morph> extends infer out ? (In: distill.brandable.In<inferDefinition<inDef, $, args>>) => Out<out> : never : never;
139
+ export type parseMorph<inDef, morph, $, args> = morph extends Morph ? inferMorphOut<morph> extends infer out ? (In: distill.withAttributes.In<inferDefinition<inDef, $, args>>) => Out<out> : never : never;
140
140
  export declare const parseNarrowTuple: IndexOneParser<":">;
141
141
  export type IndexZeroOperator = "keyof" | "instanceof" | "===";
142
142
  export type IndexZeroExpression<token extends IndexZeroOperator = IndexZeroOperator> = readonly [token, ...unknown[]];
package/out/scope.d.ts CHANGED
@@ -7,7 +7,12 @@ import type { BoundModule, Module, Submodule, instantiateExport } from "./module
7
7
  import type { DefAst, InferredAst } from "./parser/ast/infer.ts";
8
8
  import { type inferDefinition, type validateDefinition } from "./parser/definition.ts";
9
9
  import { InternalTypeParser, type DeclarationParser, type DefinitionParser, type EnumeratedTypeParser, type SchemaParser, type TypeParser, type UnitTypeParser } from "./type.ts";
10
- export type ScopeParser = <const def>(def: scope.validate<def>, config?: ArkScopeConfig) => Scope<scope.infer<def>>;
10
+ /** The convenience properties attached to `scope` */
11
+ export type ScopeParserAttachments = Omit<ScopeParser, never>;
12
+ export interface ScopeParser {
13
+ <const def>(def: scope.validate<def>, config?: ArkScopeConfig): Scope<scope.infer<def>>;
14
+ define: <const def>(def: scope.validate<def>) => def;
15
+ }
11
16
  export type ModuleParser = <const def>(def: scope.validate<def>, config?: ArkScopeConfig) => scope.infer<def> extends infer $ ? Module<{
12
17
  [k in exportedNameOf<$>]: $[k];
13
18
  }> : never;
package/out/scope.js CHANGED
@@ -100,6 +100,8 @@ export class InternalScope extends BaseScope {
100
100
  static scope = ((def, config = {}) => new InternalScope(def, config));
101
101
  static module = ((def, config = {}) => this.scope(def, config).export());
102
102
  }
103
- export const scope = InternalScope.scope;
103
+ export const scope = Object.assign(InternalScope.scope, {
104
+ define: def => def
105
+ });
104
106
  export const module = InternalScope.module;
105
107
  export const Scope = InternalScope;
package/out/type.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ArkErrors, BaseRoot, type BaseParseOptions, type MetaSchema, type Morph, type Predicate, type RootSchema } from "@ark/schema";
2
2
  import { Callable, Hkt, type Constructor, type array, type conform } from "@ark/util";
3
+ import type { DefaultFor, distill } from "./attributes.ts";
3
4
  import type { Generic, GenericParser, ParameterString, baseGenericConstraints, parseValidGenericParams, validateParameterString } from "./generic.ts";
4
- import type { DefaultFor, distill } from "./keywords/inference.ts";
5
5
  import type { Ark, keywords, type } from "./keywords/keywords.ts";
6
6
  import type { BaseType } from "./methods/base.ts";
7
7
  import type { instantiateType } from "./methods/instantiate.ts";
@@ -14,6 +14,11 @@ export interface TypeParser<$ = {}> extends Ark.boundTypeAttachments<$> {
14
14
  <const def, r = Type<type.infer<def, $>, $>>(def: type.validate<def, $>): r;
15
15
  <const params extends ParameterString, const def>(params: validateParameterString<params, $>, def: validateDefinition<def, $, baseGenericConstraints<parseValidGenericParams<params, $>>>): Generic<parseValidGenericParams<params, $>, def, $>;
16
16
  <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;
17
+ /**
18
+ * Error class for validation errors
19
+ * Calling type instance returns an instance of this class on failure
20
+ * @example if ( T(data) instanceof type.errors ) { ... }
21
+ */
17
22
  errors: typeof ArkErrors;
18
23
  hkt: typeof Hkt;
19
24
  keywords: typeof keywords;
@@ -24,7 +29,18 @@ export interface TypeParser<$ = {}> extends Ark.boundTypeAttachments<$> {
24
29
  define: DefinitionParser<$>;
25
30
  generic: GenericParser<$>;
26
31
  schema: SchemaParser<$>;
32
+ /**
33
+ * Create a `Type` that is satisfied only by a value strictly equal (`===`) to the argument passed to this function.
34
+ * @example const foo = type.unit('foo') // Type<'foo'>
35
+ * @example const sym: unique symbol = Symbol(); type.unit(sym) // Type<typeof sym>
36
+ */
27
37
  unit: UnitTypeParser<$>;
38
+ /**
39
+ * Create a `Type` that is satisfied only by a value strictly equal (`===`) to one of the arguments passed to this function.
40
+ * @example const enum = type.enumerated('foo', 'bar', obj) // obj is a by-reference object
41
+ * @example const tupleForm = type(['===', 'foo', 'bar', obj])
42
+ * @example const argsForm = type('===', 'foo', 'bar', obj)
43
+ */
28
44
  enumerated: EnumeratedTypeParser<$>;
29
45
  }
30
46
  export declare class InternalTypeParser extends Callable<(...args: unknown[]) => BaseRoot | Generic, TypeParserAttachments> {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "arktype",
3
3
  "description": "TypeScript's 1:1 validator, optimized from editor to runtime",
4
- "version": "2.0.0-rc.14",
4
+ "version": "2.0.0-rc.16",
5
5
  "license": "MIT",
6
6
  "author": {
7
7
  "name": "David Blass",
@@ -34,8 +34,8 @@
34
34
  "out"
35
35
  ],
36
36
  "dependencies": {
37
- "@ark/util": "0.16.0",
38
- "@ark/schema": "0.16.0"
37
+ "@ark/util": "0.18.0",
38
+ "@ark/schema": "0.18.0"
39
39
  },
40
40
  "publishConfig": {
41
41
  "access": "public"
@@ -1,2 +0,0 @@
1
- import { noSuggest } from "@ark/util";
2
- export const ofKey = noSuggest("of");
@@ -1,17 +0,0 @@
1
- import type { AtLeastLength, AtMostLength, Default, ExactlyLength, LessThanLength, MoreThanLength, Narrowed, Optional, Predicate, brand } from "../inference.ts";
2
- import type { Matching } from "./string.ts";
3
- declare namespace string {
4
- type atLeastLength<rule> = brand<string, AtLeastLength<rule>>;
5
- type moreThanLength<rule> = brand<string, MoreThanLength<rule>>;
6
- type atMostLength<rule> = brand<string, AtMostLength<rule>>;
7
- type lessThanLength<rule> = brand<string, LessThanLength<rule>>;
8
- type exactlyLength<rule> = brand<string, ExactlyLength<rule>>;
9
- type matching<rule> = brand<string, Matching<rule>>;
10
- type narrowed = brand<string, Narrowed>;
11
- type optional = brand<string, Optional>;
12
- type defaultsTo<rule> = brand<string, Default<rule>>;
13
- type branded<rule> = brand<string, Predicate<rule>>;
14
- type is<attributes> = brand<string, attributes>;
15
- type applyBrand<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 Predicate<infer rule> ? branded<rule> : never;
16
- }
17
- export type { string as brandedString };
@@ -1 +0,0 @@
1
- export {};