arktype 2.0.0-rc.8 → 2.0.0
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.
- package/out/attributes.d.ts +94 -0
- package/out/attributes.js +3 -0
- package/out/config.d.ts +1 -1
- package/out/generic.d.ts +18 -18
- package/out/generic.js +2 -2
- package/out/index.d.ts +4 -2
- package/out/index.js +3 -2
- package/out/keywords/{constructors/Array.d.ts → Array.d.ts} +2 -2
- package/out/keywords/{constructors/Array.js → Array.js} +2 -2
- package/out/keywords/{constructors/FormData.d.ts → FormData.d.ts} +2 -2
- package/out/keywords/{constructors/FormData.js → FormData.js} +2 -2
- package/out/keywords/{constructors/TypedArray.d.ts → TypedArray.d.ts} +1 -1
- package/out/keywords/{constructors/TypedArray.js → TypedArray.js} +2 -2
- package/out/keywords/builtins.js +2 -2
- package/out/keywords/{constructors/constructors.d.ts → constructors.d.ts} +1 -1
- package/out/keywords/{constructors/constructors.js → constructors.js} +2 -2
- package/out/keywords/{ark.d.ts → keywords.d.ts} +16 -15
- package/out/keywords/keywords.js +30 -0
- package/out/keywords/number.d.ts +23 -0
- package/out/keywords/{number/epoch.js → number.js} +22 -1
- package/out/keywords/string.d.ts +327 -0
- package/out/keywords/string.js +398 -0
- package/out/keywords/ts.d.ts +31 -4
- package/out/keywords/ts.js +21 -8
- package/out/methods/array.d.ts +6 -7
- package/out/methods/base.d.ts +461 -34
- package/out/methods/date.d.ts +5 -6
- package/out/methods/instantiate.d.ts +5 -5
- package/out/methods/morph.d.ts +6 -7
- package/out/methods/number.d.ts +8 -9
- package/out/methods/object.d.ts +80 -31
- package/out/methods/string.d.ts +9 -10
- package/out/parser/{semantic → ast}/bounds.d.ts +3 -3
- package/out/parser/{semantic → ast}/default.d.ts +4 -4
- package/out/parser/ast/generic.d.ts +17 -0
- package/out/parser/ast/infer.d.ts +25 -0
- package/out/parser/{semantic → ast}/utils.d.ts +1 -1
- package/out/parser/ast/validate.d.ts +30 -0
- package/out/parser/ast/validate.js +3 -0
- package/out/parser/definition.d.ts +18 -9
- package/out/parser/definition.js +38 -3
- package/out/parser/objectLiteral.d.ts +40 -40
- package/out/parser/objectLiteral.js +83 -67
- package/out/parser/property.d.ts +36 -0
- package/out/parser/property.js +16 -0
- package/out/parser/{string/reduce → reduce}/dynamic.d.ts +8 -9
- package/out/parser/{string/reduce → reduce}/shared.d.ts +1 -1
- package/out/parser/{string/reduce → reduce}/static.d.ts +4 -4
- package/out/parser/{string/shift → shift}/operand/date.d.ts +1 -1
- package/out/parser/{string/shift → shift}/operand/enclosed.d.ts +4 -5
- package/out/parser/shift/operand/operand.d.ts +9 -0
- package/out/parser/{string/shift → shift}/operand/operand.js +2 -2
- package/out/parser/{string/shift → shift}/operand/unenclosed.d.ts +15 -7
- package/out/parser/{string/shift → shift}/operand/unenclosed.js +6 -5
- package/out/parser/{string/shift → shift}/operator/bounds.d.ts +7 -7
- package/out/parser/{string/shift → shift}/operator/bounds.js +5 -4
- package/out/parser/shift/operator/brand.d.ts +6 -0
- package/out/parser/shift/operator/brand.js +5 -0
- package/out/parser/{string/shift → shift}/operator/default.d.ts +3 -2
- package/out/parser/{string/shift → shift}/operator/default.js +4 -1
- package/out/parser/{string/shift → shift}/operator/divisor.d.ts +2 -2
- package/out/parser/shift/operator/operator.d.ts +14 -0
- package/out/parser/{string/shift → shift}/operator/operator.js +7 -5
- package/out/parser/shift/scanner.d.ts +47 -0
- package/out/parser/shift/scanner.js +43 -0
- package/out/parser/{string/string.d.ts → string.d.ts} +7 -6
- package/out/parser/{string/string.js → string.js} +18 -1
- package/out/parser/tupleExpressions.d.ts +48 -0
- package/out/parser/tupleExpressions.js +67 -0
- package/out/parser/tupleLiteral.d.ts +95 -0
- package/out/parser/tupleLiteral.js +122 -0
- package/out/scope.d.ts +19 -14
- package/out/scope.js +25 -41
- package/out/type.d.ts +67 -9
- package/out/type.js +4 -3
- package/package.json +8 -8
- package/out/intersect.d.ts +0 -26
- package/out/keys.d.ts +0 -18
- package/out/keys.js +0 -1
- package/out/keywords/ark.js +0 -26
- package/out/keywords/ast.d.ts +0 -198
- package/out/keywords/ast.js +0 -2
- package/out/keywords/constructors/Date.d.ts +0 -31
- package/out/keywords/constructors/Date.js +0 -1
- package/out/keywords/number/epoch.d.ts +0 -9
- package/out/keywords/number/integer.d.ts +0 -3
- package/out/keywords/number/integer.js +0 -5
- package/out/keywords/number/number.d.ts +0 -53
- package/out/keywords/number/number.js +0 -21
- package/out/keywords/string/alpha.d.ts +0 -7
- package/out/keywords/string/alpha.js +0 -2
- package/out/keywords/string/alphanumeric.d.ts +0 -7
- package/out/keywords/string/alphanumeric.js +0 -2
- package/out/keywords/string/capitalize.d.ts +0 -15
- package/out/keywords/string/capitalize.js +0 -12
- package/out/keywords/string/creditCard.d.ts +0 -8
- package/out/keywords/string/creditCard.js +0 -37
- package/out/keywords/string/date.d.ts +0 -55
- package/out/keywords/string/date.js +0 -98
- package/out/keywords/string/digits.d.ts +0 -7
- package/out/keywords/string/digits.js +0 -2
- package/out/keywords/string/email.d.ts +0 -7
- package/out/keywords/string/email.js +0 -4
- package/out/keywords/string/integer.d.ts +0 -16
- package/out/keywords/string/integer.js +0 -16
- package/out/keywords/string/ip.d.ts +0 -20
- package/out/keywords/string/ip.js +0 -23
- package/out/keywords/string/json.d.ts +0 -16
- package/out/keywords/string/json.js +0 -53
- package/out/keywords/string/lower.d.ts +0 -15
- package/out/keywords/string/lower.js +0 -12
- package/out/keywords/string/normalize.d.ts +0 -88
- package/out/keywords/string/normalize.js +0 -43
- package/out/keywords/string/numeric.d.ts +0 -15
- package/out/keywords/string/numeric.js +0 -13
- package/out/keywords/string/semver.d.ts +0 -7
- package/out/keywords/string/semver.js +0 -4
- package/out/keywords/string/string.d.ts +0 -108
- package/out/keywords/string/string.js +0 -41
- package/out/keywords/string/trim.d.ts +0 -15
- package/out/keywords/string/trim.js +0 -14
- package/out/keywords/string/upper.d.ts +0 -15
- package/out/keywords/string/upper.js +0 -12
- package/out/keywords/string/url.d.ts +0 -15
- package/out/keywords/string/url.js +0 -37
- package/out/keywords/string/utils.d.ts +0 -2
- package/out/keywords/string/utils.js +0 -10
- package/out/keywords/string/uuid.d.ts +0 -42
- package/out/keywords/string/uuid.js +0 -19
- package/out/keywords/utils.d.ts +0 -1
- package/out/keywords/utils.js +0 -2
- package/out/methods/validator.d.ts +0 -11
- package/out/methods/validator.js +0 -1
- package/out/parser/semantic/infer.d.ts +0 -41
- package/out/parser/semantic/validate.d.ts +0 -26
- package/out/parser/semantic/validate.js +0 -1
- package/out/parser/string/shift/operand/operand.d.ts +0 -9
- package/out/parser/string/shift/operator/operator.d.ts +0 -13
- package/out/parser/string/shift/scanner.d.ts +0 -71
- package/out/parser/string/shift/scanner.js +0 -102
- package/out/parser/tuple.d.ts +0 -144
- package/out/parser/tuple.js +0 -164
- /package/out/parser/{semantic → ast}/bounds.js +0 -0
- /package/out/parser/{semantic → ast}/default.js +0 -0
- /package/out/parser/{semantic → ast}/divisor.d.ts +0 -0
- /package/out/parser/{semantic → ast}/divisor.js +0 -0
- /package/out/{intersect.js → parser/ast/generic.js} +0 -0
- /package/out/parser/{semantic → ast}/infer.js +0 -0
- /package/out/parser/{semantic → ast}/keyof.d.ts +0 -0
- /package/out/parser/{semantic → ast}/keyof.js +0 -0
- /package/out/parser/{semantic → ast}/utils.js +0 -0
- /package/out/parser/{string/reduce → reduce}/dynamic.js +0 -0
- /package/out/parser/{string/reduce → reduce}/shared.js +0 -0
- /package/out/parser/{string/reduce → reduce}/static.js +0 -0
- /package/out/parser/{string/shift → shift}/operand/date.js +0 -0
- /package/out/parser/{string/shift → shift}/operand/enclosed.js +0 -0
- /package/out/parser/{string/shift → shift}/operand/genericArgs.d.ts +0 -0
- /package/out/parser/{string/shift → shift}/operand/genericArgs.js +0 -0
- /package/out/parser/{string/shift → shift}/operator/divisor.js +0 -0
package/out/scope.js
CHANGED
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
import { $ark, BaseScope, hasArkKind, parseGeneric } from "@ark/schema";
|
|
2
|
-
import {
|
|
2
|
+
import { flatMorph, isArray, isThunk, throwParseError } from "@ark/util";
|
|
3
3
|
import { parseGenericParamName } from "./generic.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { Scanner } from "./parser/string/shift/scanner.js";
|
|
8
|
-
import { fullStringParse } from "./parser/string/string.js";
|
|
4
|
+
import { shallowDefaultableMessage, shallowOptionalMessage } from "./parser/ast/validate.js";
|
|
5
|
+
import { parseInnerDefinition } from "./parser/definition.js";
|
|
6
|
+
import { ArkTypeScanner } from "./parser/shift/scanner.js";
|
|
9
7
|
import { InternalTypeParser } from "./type.js";
|
|
10
8
|
export const $arkTypeRegistry = $ark;
|
|
11
9
|
export class InternalScope extends BaseScope {
|
|
12
|
-
parseCache = {};
|
|
13
|
-
cacheGetter(name, value) {
|
|
14
|
-
Object.defineProperty(this, name, { value });
|
|
15
|
-
return value;
|
|
16
|
-
}
|
|
17
10
|
get ambientAttachments() {
|
|
18
11
|
if (!$arkTypeRegistry.typeAttachments)
|
|
19
12
|
return;
|
|
@@ -43,7 +36,11 @@ export class InternalScope extends BaseScope {
|
|
|
43
36
|
];
|
|
44
37
|
}
|
|
45
38
|
parseGenericParams(def, opts) {
|
|
46
|
-
return parseGenericParamName(new
|
|
39
|
+
return parseGenericParamName(new ArkTypeScanner(def), [], this.createParseContext({
|
|
40
|
+
...opts,
|
|
41
|
+
def,
|
|
42
|
+
prefix: "generic"
|
|
43
|
+
}));
|
|
47
44
|
}
|
|
48
45
|
normalizeRootScopeValue(resolution) {
|
|
49
46
|
if (isThunk(resolution) && !hasArkKind(resolution, "generic"))
|
|
@@ -60,46 +57,33 @@ export class InternalScope extends BaseScope {
|
|
|
60
57
|
parseOwnDefinitionFormat(def, ctx) {
|
|
61
58
|
const isScopeAlias = ctx.alias && ctx.alias in this.aliases;
|
|
62
59
|
// if the definition being parsed is not a scope alias and is not a
|
|
63
|
-
// generic instantiation (i.e. opts don't include args), add this as a resolution.
|
|
60
|
+
// generic instantiation (i.e. opts don't include args), add `this` as a resolution.
|
|
61
|
+
// if we're parsing a nested string, ctx.args will have already been set
|
|
64
62
|
if (!isScopeAlias && !ctx.args)
|
|
65
63
|
ctx.args = { this: ctx.id };
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return (this.parseCache[def] ??= this.parseString(def, ctx));
|
|
64
|
+
const result = parseInnerDefinition(def, ctx);
|
|
65
|
+
if (isArray(result)) {
|
|
66
|
+
if (result[1] === "=")
|
|
67
|
+
return throwParseError(shallowDefaultableMessage);
|
|
68
|
+
if (result[1] === "?")
|
|
69
|
+
return throwParseError(shallowOptionalMessage);
|
|
73
70
|
}
|
|
74
|
-
return
|
|
75
|
-
parseObject(def, ctx)
|
|
76
|
-
: throwParseError(writeBadDefinitionTypeMessage(domainOf(def)));
|
|
77
|
-
}
|
|
78
|
-
parseString(def, ctx) {
|
|
79
|
-
const aliasResolution = this.maybeResolveRoot(def);
|
|
80
|
-
if (aliasResolution)
|
|
81
|
-
return aliasResolution;
|
|
82
|
-
const aliasArrayResolution = def.endsWith("[]") ?
|
|
83
|
-
this.maybeResolveRoot(def.slice(0, -2))?.array()
|
|
84
|
-
: undefined;
|
|
85
|
-
if (aliasArrayResolution)
|
|
86
|
-
return aliasArrayResolution;
|
|
87
|
-
const s = new DynamicState(new Scanner(def), ctx);
|
|
88
|
-
const node = fullStringParse(s);
|
|
89
|
-
if (s.finalizer === ">")
|
|
90
|
-
throwParseError(writeUnexpectedCharacterMessage(">"));
|
|
91
|
-
return node;
|
|
71
|
+
return result;
|
|
92
72
|
}
|
|
93
73
|
unit = value => this.units([value]);
|
|
94
74
|
enumerated = (...values) => this.units(values);
|
|
75
|
+
instanceOf = ctor => this.node("proto", { proto: ctor }, { prereduced: true });
|
|
95
76
|
type = new InternalTypeParser(this);
|
|
96
77
|
declare = () => ({
|
|
97
78
|
type: this.type
|
|
98
79
|
});
|
|
99
|
-
define
|
|
80
|
+
define(def) {
|
|
81
|
+
return def;
|
|
82
|
+
}
|
|
100
83
|
static scope = ((def, config = {}) => new InternalScope(def, config));
|
|
101
84
|
static module = ((def, config = {}) => this.scope(def, config).export());
|
|
102
85
|
}
|
|
103
|
-
export const scope = InternalScope.scope
|
|
104
|
-
|
|
86
|
+
export const scope = Object.assign(InternalScope.scope, {
|
|
87
|
+
define: def => def
|
|
88
|
+
});
|
|
105
89
|
export const Scope = InternalScope;
|
package/out/type.d.ts
CHANGED
|
@@ -1,31 +1,88 @@
|
|
|
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 { distill } from "./attributes.ts";
|
|
3
4
|
import type { Generic, GenericParser, ParameterString, baseGenericConstraints, parseValidGenericParams, validateParameterString } from "./generic.ts";
|
|
4
|
-
import type { Ark,
|
|
5
|
-
import type { distill } from "./keywords/ast.ts";
|
|
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";
|
|
8
|
-
import type { validateDeclared
|
|
9
|
-
import type {
|
|
8
|
+
import type { validateDeclared } from "./parser/definition.ts";
|
|
9
|
+
import type { ArgTwoOperator, IndexZeroOperator, TupleInfixOperator } from "./parser/tupleExpressions.ts";
|
|
10
10
|
import type { InternalScope, ModuleParser, Scope, ScopeParser, bindThis } from "./scope.ts";
|
|
11
11
|
/** The convenience properties attached to `type` */
|
|
12
12
|
export type TypeParserAttachments = Omit<TypeParser, never>;
|
|
13
13
|
export interface TypeParser<$ = {}> extends Ark.boundTypeAttachments<$> {
|
|
14
|
+
/**
|
|
15
|
+
* Create a {@link Type} from your definition.
|
|
16
|
+
*
|
|
17
|
+
* @example const person = type({ name: "string" })
|
|
18
|
+
*/
|
|
14
19
|
<const def, r = Type<type.infer<def, $>, $>>(def: type.validate<def, $>): r;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Create a {@link Generic} from a parameter string and body definition.
|
|
22
|
+
*
|
|
23
|
+
* @param params A string like "<t, n extends number>" specifying the
|
|
24
|
+
* {@link Generic}'s parameters and any associated constraints via `extends`.
|
|
25
|
+
*
|
|
26
|
+
* @param def The definition for the body of the {@link Generic}. Can reference the
|
|
27
|
+
* parameter names specified in the previous argument in addition to aliases
|
|
28
|
+
* from its {@link Scope}.
|
|
29
|
+
*
|
|
30
|
+
* @example const boxOf = type("<t extends string | number>", { contents: "t" })
|
|
31
|
+
*/
|
|
32
|
+
<const params extends ParameterString, const def>(params: validateParameterString<params, $>, def: type.validate<def, $, baseGenericConstraints<parseValidGenericParams<params, $>>>): Generic<parseValidGenericParams<params, $>, def, $>;
|
|
33
|
+
/**
|
|
34
|
+
* Create a {@link Type} from a [tuple expression](http://localhost:3000/docs/expressions)
|
|
35
|
+
* spread as this function's arguments.
|
|
36
|
+
*
|
|
37
|
+
* @example type("string", "|", { foo: "number" })
|
|
38
|
+
*/
|
|
39
|
+
<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, ArgTwoOperator>, ..._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] : [type.validate<rest[0], $>] : []): r;
|
|
40
|
+
/**
|
|
41
|
+
* An alias of the {@link ArkErrors} class, an instance of which is returned when a {@link Type}
|
|
42
|
+
* is invoked with invalid input.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* const out = myType(data)
|
|
46
|
+
*
|
|
47
|
+
* if(out instanceof type.errors) console.log(out.summary)
|
|
48
|
+
*
|
|
49
|
+
*/
|
|
19
50
|
errors: typeof ArkErrors;
|
|
20
51
|
hkt: typeof Hkt;
|
|
21
|
-
|
|
52
|
+
keywords: typeof keywords;
|
|
53
|
+
/**
|
|
54
|
+
* The {@link Scope} in which definitions passed to this function will be parsed.
|
|
55
|
+
*/
|
|
56
|
+
$: Scope<$>;
|
|
57
|
+
/**
|
|
58
|
+
* An alias of `type` with no type-level validation or inference.
|
|
59
|
+
*
|
|
60
|
+
* Useful when wrapping `type` or using it to parse a dynamic definition.
|
|
61
|
+
*/
|
|
62
|
+
raw(def: unknown): BaseType<any, $>;
|
|
22
63
|
module: ModuleParser;
|
|
23
64
|
scope: ScopeParser;
|
|
24
65
|
define: DefinitionParser<$>;
|
|
25
66
|
generic: GenericParser<$>;
|
|
26
67
|
schema: SchemaParser<$>;
|
|
68
|
+
/**
|
|
69
|
+
* Create a {@link Type} that is satisfied only by a value strictly equal (`===`) to the argument passed to this function.
|
|
70
|
+
* @example const foo = type.unit('foo') // {@link Type}<'foo'>
|
|
71
|
+
* @example const sym: unique symbol = Symbol(); type.unit(sym) // {@link Type}<typeof sym>
|
|
72
|
+
*/
|
|
27
73
|
unit: UnitTypeParser<$>;
|
|
74
|
+
/**
|
|
75
|
+
* Create a {@link Type} that is satisfied only by a value strictly equal (`===`) to one of the arguments passed to this function.
|
|
76
|
+
* @example const enum = type.enumerated('foo', 'bar', obj) // obj is a by-reference object
|
|
77
|
+
* @example const tupleForm = type(['===', 'foo', 'bar', obj])
|
|
78
|
+
* @example const argsForm = type('===', 'foo', 'bar', obj)
|
|
79
|
+
*/
|
|
28
80
|
enumerated: EnumeratedTypeParser<$>;
|
|
81
|
+
/**
|
|
82
|
+
* Create a {@link Type} that is satisfied only by a value of a specific class.
|
|
83
|
+
* @example const array = type.instanceOf(Array)
|
|
84
|
+
*/
|
|
85
|
+
instanceOf: InstanceOfTypeParser<$>;
|
|
29
86
|
}
|
|
30
87
|
export declare class InternalTypeParser extends Callable<(...args: unknown[]) => BaseRoot | Generic, TypeParserAttachments> {
|
|
31
88
|
constructor($: InternalScope);
|
|
@@ -34,6 +91,7 @@ export type DeclarationParser<$> = <preinferred>() => {
|
|
|
34
91
|
type: <const def>(def: validateDeclared<preinferred, def, $, bindThis<def>>) => Type<preinferred, $>;
|
|
35
92
|
};
|
|
36
93
|
export type UnitTypeParser<$> = <const t>(value: t) => Type<t, $>;
|
|
94
|
+
export type InstanceOfTypeParser<$> = <const t extends object>(ctor: Constructor<t>) => Type<t, $>;
|
|
37
95
|
export type EnumeratedTypeParser<$> = <const values extends readonly unknown[]>(...values: values) => Type<values[number], $>;
|
|
38
96
|
export type DefinitionParser<$> = <const def>(def: type.validate<def, $>) => def;
|
|
39
97
|
export type SchemaParser<$> = (schema: RootSchema, opts?: BaseParseOptions) => Type<unknown, $>;
|
package/out/type.js
CHANGED
|
@@ -13,9 +13,10 @@ export class InternalTypeParser extends Callable {
|
|
|
13
13
|
generic: $.generic,
|
|
14
14
|
schema: $.schema,
|
|
15
15
|
// this won't be defined during bootstrapping, but externally always will be
|
|
16
|
-
|
|
16
|
+
keywords: $.ambient,
|
|
17
17
|
unit: $.unit,
|
|
18
|
-
enumerated: $.enumerated
|
|
18
|
+
enumerated: $.enumerated,
|
|
19
|
+
instanceOf: $.instanceOf
|
|
19
20
|
},
|
|
20
21
|
// also won't be defined during bootstrapping
|
|
21
22
|
$.ambientAttachments);
|
|
@@ -32,7 +33,7 @@ export class InternalTypeParser extends Callable {
|
|
|
32
33
|
// treat as a generic
|
|
33
34
|
const paramString = args[0].slice(1, -1);
|
|
34
35
|
const params = $.parseGenericParams(paramString, {});
|
|
35
|
-
return new GenericRoot(params, args[1], $,
|
|
36
|
+
return new GenericRoot(params, args[1], $, $, null);
|
|
36
37
|
}
|
|
37
38
|
// otherwise, treat as a tuple expression. technically, this also allows
|
|
38
39
|
// non-expression tuple definitions to be parsed, but it's not a supported
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arktype",
|
|
3
3
|
"description": "TypeScript's 1:1 validator, optimized from editor to runtime",
|
|
4
|
-
"version": "2.0.0
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"author": {
|
|
7
|
-
"name": "David Blass",
|
|
8
|
-
"email": "david@arktype.io",
|
|
9
|
-
"url": "https://arktype.io"
|
|
10
|
-
},
|
|
11
6
|
"repository": {
|
|
12
7
|
"type": "git",
|
|
13
8
|
"url": "https://github.com/arktypeio/arktype.git",
|
|
14
9
|
"directory": "ark/type"
|
|
15
10
|
},
|
|
11
|
+
"author": {
|
|
12
|
+
"name": "David Blass",
|
|
13
|
+
"email": "david@arktype.io",
|
|
14
|
+
"url": "https://arktype.io"
|
|
15
|
+
},
|
|
16
16
|
"type": "module",
|
|
17
17
|
"main": "./out/index.js",
|
|
18
18
|
"types": "./out/index.d.ts",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"out"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@ark/
|
|
38
|
-
"@ark/
|
|
37
|
+
"@ark/util": "0.35.0",
|
|
38
|
+
"@ark/schema": "0.35.0"
|
|
39
39
|
},
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|
package/out/intersect.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { anyOrNever, array, Hkt, intersectArrays, show } from "@ark/util";
|
|
2
|
-
import type { constrain, Constraints, MorphAst, parseConstraints, To } from "./keywords/ast.ts";
|
|
3
|
-
export type inferIntersection<l, r> = _inferIntersection<l, r, false>;
|
|
4
|
-
export type inferPipe<l, r> = _inferIntersection<l, r, true>;
|
|
5
|
-
type _inferIntersection<l, r, piped extends boolean> = [
|
|
6
|
-
l & r
|
|
7
|
-
] extends [infer t extends anyOrNever] ? t : l extends MorphAst<infer lIn, infer lOut> ? r extends MorphAst<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 MorphAst<infer rIn, infer rOut> ? (In: _inferIntersection<rIn, l, false>) => rOut : parseConstraints<l> extends ([
|
|
8
|
-
infer lBase,
|
|
9
|
-
infer lConstraints extends Constraints
|
|
10
|
-
]) ? parseConstraints<r> extends ([
|
|
11
|
-
infer rBase,
|
|
12
|
-
infer rConstraints extends Constraints
|
|
13
|
-
]) ? constrain<_inferIntersection<lBase, rBase, piped>, lConstraints & rConstraints> : constrain<_inferIntersection<lBase, r, piped>, lConstraints> : parseConstraints<r> extends ([
|
|
14
|
-
infer rBase,
|
|
15
|
-
infer rConstraints extends Constraints
|
|
16
|
-
]) ? constrain<_inferIntersection<l, rBase, piped>, rConstraints> : [l, r] extends [object, object] ? intersectObjects<l, r, piped> extends infer result ? result : never : l & r;
|
|
17
|
-
interface MorphableIntersection<piped extends boolean> extends Hkt<[unknown, unknown]> {
|
|
18
|
-
body: _inferIntersection<this[0], this[1], piped>;
|
|
19
|
-
}
|
|
20
|
-
type intersectObjects<l, r, piped extends boolean> = l extends array ? r extends array ? intersectArrays<l, r, MorphableIntersection<piped>> : // for an intersection with exactly one array operand like { name: string } & string[],
|
|
21
|
-
l & r : r extends array ? l & r : show<{
|
|
22
|
-
[k in keyof l]: k extends keyof r ? _inferIntersection<l[k], r[k], piped> : l[k];
|
|
23
|
-
} & {
|
|
24
|
-
[k in keyof r]: k extends keyof l ? _inferIntersection<l[k], r[k], piped> : r[k];
|
|
25
|
-
}>;
|
|
26
|
-
export {};
|
package/out/keys.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { array, join, Key, NonNegativeIntegerLiteral, typeToString } from "@ark/util";
|
|
2
|
-
import type { type } from "./keywords/ark.ts";
|
|
3
|
-
import type { termOrType } from "./keywords/ast.ts";
|
|
4
|
-
export type toArkKey<o, k extends keyof o> = k extends number ? [
|
|
5
|
-
o,
|
|
6
|
-
number
|
|
7
|
-
] extends [array, k] ? NonNegativeIntegerLiteral : `${k}` : k;
|
|
8
|
-
export type arkKeyOf<o> = [
|
|
9
|
-
o
|
|
10
|
-
] extends [array] ? (number extends o["length"] ? NonNegativeIntegerLiteral : never) | {
|
|
11
|
-
[k in keyof o]-?: k extends `${infer index extends number}` ? index | k : never;
|
|
12
|
-
}[keyof o & `${number}`] : {
|
|
13
|
-
[k in keyof o]-?: k extends number ? k | `${k}` : k;
|
|
14
|
-
}[keyof o];
|
|
15
|
-
export type arkGet<o, k extends arkKeyOf<o>> = o[Extract<k extends NonNegativeIntegerLiteral ? number : k, keyof o>];
|
|
16
|
-
export type TypeKey = termOrType<Key>;
|
|
17
|
-
export type typeKeyToString<k extends TypeKey> = typeToString<k extends type.cast<infer t> ? t : k>;
|
|
18
|
-
export type writeInvalidKeysMessage<o extends string, keys extends array<string>> = `Key${keys["length"] extends 1 ? "" : "s"} ${join<keys, ", ">} ${keys["length"] extends 1 ? "does" : "do"} not exist on ${o}`;
|
package/out/keys.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/out/keywords/ark.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { $arkTypeRegistry, scope } from "../scope.js";
|
|
2
|
-
import { arkBuiltins } from "./builtins.js";
|
|
3
|
-
import { arkPrototypes } from "./constructors/constructors.js";
|
|
4
|
-
import { number } from "./number/number.js";
|
|
5
|
-
import { string } from "./string/string.js";
|
|
6
|
-
import { arkTsGenerics, arkTsKeywords, unknown } from "./ts.js";
|
|
7
|
-
$arkTypeRegistry.typeAttachments = {
|
|
8
|
-
...arkTsKeywords,
|
|
9
|
-
Key: arkBuiltins.Key,
|
|
10
|
-
Record: arkTsGenerics.Record
|
|
11
|
-
};
|
|
12
|
-
export const ambient = scope({
|
|
13
|
-
...arkTsKeywords,
|
|
14
|
-
...arkTsGenerics,
|
|
15
|
-
...arkPrototypes,
|
|
16
|
-
...arkBuiltins,
|
|
17
|
-
string,
|
|
18
|
-
number,
|
|
19
|
-
unknown
|
|
20
|
-
}, { prereducedAliases: true, ambient: true });
|
|
21
|
-
export const ark = ambient.export();
|
|
22
|
-
export const type = ambient.type;
|
|
23
|
-
export const generic = ambient.generic;
|
|
24
|
-
export const schema = ambient.schema;
|
|
25
|
-
export const define = ambient.define;
|
|
26
|
-
export const declare = ambient.declare;
|
package/out/keywords/ast.d.ts
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
import type { ArkError, ArkErrors, Constraint, constraintKindOf, Morph, NodeSchema } from "@ark/schema";
|
|
2
|
-
import { type anyOrNever, type array, type conform, type equals, type isSafelyMappable, type leftIfEqual, type objectKindOf, type Primitive, type show } from "@ark/util";
|
|
3
|
-
import type { inferPipe } from "../intersect.ts";
|
|
4
|
-
import type { Type } from "../type.ts";
|
|
5
|
-
import type { type } from "./ark.ts";
|
|
6
|
-
import type { arkPrototypes } from "./constructors/constructors.ts";
|
|
7
|
-
import type { Date } from "./constructors/Date.ts";
|
|
8
|
-
import type { DivisibleBy, number } from "./number/number.ts";
|
|
9
|
-
import type { Matching, string } from "./string/string.ts";
|
|
10
|
-
export type { arkPrototypes as object } from "./constructors/constructors.ts";
|
|
11
|
-
export type { number } from "./number/number.ts";
|
|
12
|
-
export type { string } from "./string/string.ts";
|
|
13
|
-
export type Comparator = "<" | "<=" | ">" | ">=" | "==";
|
|
14
|
-
export type RegexLiteral<source extends string = string> = `/${source}/`;
|
|
15
|
-
export type DateLiteral<source extends string = string> = `d"${source}"` | `d'${source}'`;
|
|
16
|
-
export type ConstraintSet = Record<PropertyKey, 1>;
|
|
17
|
-
export type Constraints = Record<string, ConstraintSet>;
|
|
18
|
-
export declare const constrained: " arkConstrained";
|
|
19
|
-
export type constrained = typeof constrained;
|
|
20
|
-
export type constrain<base, constraints extends Constraints> = base & {
|
|
21
|
-
[constrained]: constraints;
|
|
22
|
-
};
|
|
23
|
-
export type LimitLiteral = number | DateLiteral;
|
|
24
|
-
export type normalizeLimit<limit> = limit extends DateLiteral<infer source> ? source : limit extends number | string ? limit : never;
|
|
25
|
-
export type constraint<rule> = {
|
|
26
|
-
[k in rule & PropertyKey]: 1;
|
|
27
|
-
};
|
|
28
|
-
export type Literal<rule> = {
|
|
29
|
-
literal: constraint<rule>;
|
|
30
|
-
};
|
|
31
|
-
export type Narrowed = {
|
|
32
|
-
predicate: {
|
|
33
|
-
"?": 1;
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
export type Branded<rule> = {
|
|
37
|
-
predicate: constraint<rule>;
|
|
38
|
-
};
|
|
39
|
-
export type primitiveConstraintKindOf<In> = Extract<Constraint.PrimitiveKind, constraintKindOf<In>>;
|
|
40
|
-
export type AtLeastLength<rule> = {
|
|
41
|
-
atLeastLength: constraint<rule>;
|
|
42
|
-
};
|
|
43
|
-
export type AtMostLength<rule> = {
|
|
44
|
-
atMostLength: constraint<rule>;
|
|
45
|
-
};
|
|
46
|
-
export type MoreThanLength<rule> = {
|
|
47
|
-
moreThanLength: constraint<rule>;
|
|
48
|
-
};
|
|
49
|
-
export type LessThanLength<rule> = {
|
|
50
|
-
lessThanLength: constraint<rule>;
|
|
51
|
-
};
|
|
52
|
-
export type ExactlyLength<rule> = {
|
|
53
|
-
atLeastLength: constraint<rule>;
|
|
54
|
-
atMostLength: constraint<rule>;
|
|
55
|
-
};
|
|
56
|
-
export type applyConstraintSchema<t, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = t extends MorphAst<infer i, infer o> ? (In: leftIfEqual<i, applyConstraint<i, schemaToConstraint<kind, schema>>>) => o : leftIfEqual<t, applyConstraint<t, schemaToConstraint<kind, schema>>>;
|
|
57
|
-
export type applyConstraint<t, constraint> = parseConstraints<t> extends ([
|
|
58
|
-
infer base,
|
|
59
|
-
infer constraints extends Constraints
|
|
60
|
-
]) ? [
|
|
61
|
-
number,
|
|
62
|
-
base
|
|
63
|
-
] 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>>;
|
|
64
|
-
export type parseConstraints<t> = t extends constrain<infer base, infer constraints> ? equals<t, number & {
|
|
65
|
-
[constrained]: constraints;
|
|
66
|
-
}> extends true ? [
|
|
67
|
-
number,
|
|
68
|
-
constraints
|
|
69
|
-
] : equals<t, string & {
|
|
70
|
-
[constrained]: constraints;
|
|
71
|
-
}> extends true ? [
|
|
72
|
-
string,
|
|
73
|
-
constraints
|
|
74
|
-
] : equals<t, bigint & {
|
|
75
|
-
[constrained]: constraints;
|
|
76
|
-
}> extends true ? [
|
|
77
|
-
bigint,
|
|
78
|
-
constraints
|
|
79
|
-
] : equals<t, symbol & {
|
|
80
|
-
[constrained]: constraints;
|
|
81
|
-
}> extends true ? [
|
|
82
|
-
symbol,
|
|
83
|
-
constraints
|
|
84
|
-
] : objectKindOf<t> extends infer kind ? kind extends BuiltinTerminalObjectKind ? [
|
|
85
|
-
arkPrototypes.instanceOf<kind>,
|
|
86
|
-
constraints
|
|
87
|
-
] : kind extends "Array" ? null : kind extends undefined ? [Omit<base, constrained>, constraints] : [base, constraints] : never : null;
|
|
88
|
-
export type normalizePrimitiveConstraintRoot<schema extends NodeSchema<Constraint.PrimitiveKind>> = "rule" extends keyof schema ? conform<schema["rule"], PropertyKey> : conform<schema, PropertyKey>;
|
|
89
|
-
type minLengthSchemaToConstraint<schema, rule> = schema extends {
|
|
90
|
-
exclusive: true;
|
|
91
|
-
} ? MoreThanLength<rule> : AtLeastLength<rule>;
|
|
92
|
-
type maxLengthSchemaToConstraint<schema, rule> = schema extends {
|
|
93
|
-
exclusive: true;
|
|
94
|
-
} ? LessThanLength<rule> : AtMostLength<rule>;
|
|
95
|
-
export type schemaToConstraint<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> : Narrowed : never;
|
|
96
|
-
export type distill<t, opts extends distill.Options = {}> = finalizeDistillation<t, _distill<t, opts>>;
|
|
97
|
-
export declare namespace distill {
|
|
98
|
-
type Endpoint = "in" | "out" | "out.introspectable";
|
|
99
|
-
type Options = {
|
|
100
|
-
endpoint?: Endpoint;
|
|
101
|
-
branded?: true;
|
|
102
|
-
};
|
|
103
|
-
type In<t> = distill<t, {
|
|
104
|
-
endpoint: "in";
|
|
105
|
-
}>;
|
|
106
|
-
type Out<t> = distill<t, {
|
|
107
|
-
endpoint: "out";
|
|
108
|
-
}>;
|
|
109
|
-
namespace brandable {
|
|
110
|
-
type In<t> = distill<t, {
|
|
111
|
-
endpoint: "in";
|
|
112
|
-
branded: true;
|
|
113
|
-
}>;
|
|
114
|
-
type Out<t> = distill<t, {
|
|
115
|
-
endpoint: "out";
|
|
116
|
-
branded: true;
|
|
117
|
-
}>;
|
|
118
|
-
namespace introspectable {
|
|
119
|
-
type Out<t> = distill<t, {
|
|
120
|
-
endpoint: "out.introspectable";
|
|
121
|
-
branded: true;
|
|
122
|
-
}>;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
type unbranded<t> = distill<t>;
|
|
126
|
-
namespace introspectable {
|
|
127
|
-
type Out<t> = distill<t, {
|
|
128
|
-
endpoint: "out.introspectable";
|
|
129
|
-
}>;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
type finalizeDistillation<t, distilled> = equals<t, distilled> extends true ? t : distilled;
|
|
133
|
-
export type includesMorphs<t> = [
|
|
134
|
-
_distill<t, {
|
|
135
|
-
endpoint: "in";
|
|
136
|
-
branded: true;
|
|
137
|
-
}>,
|
|
138
|
-
_distill<t, {
|
|
139
|
-
endpoint: "out";
|
|
140
|
-
branded: true;
|
|
141
|
-
}>
|
|
142
|
-
] extends ([
|
|
143
|
-
_distill<t, {
|
|
144
|
-
endpoint: "out";
|
|
145
|
-
branded: true;
|
|
146
|
-
}>,
|
|
147
|
-
_distill<t, {
|
|
148
|
-
endpoint: "in";
|
|
149
|
-
branded: true;
|
|
150
|
-
}>
|
|
151
|
-
]) ? false : true;
|
|
152
|
-
type _distill<t, opts extends distill.Options> = t extends undefined ? t : [t] extends [anyOrNever] ? t : parseConstraints<t> extends ([
|
|
153
|
-
infer base,
|
|
154
|
-
infer constraints extends Constraints
|
|
155
|
-
]) ? opts["branded"] extends true ? constrain<_distill<base, opts>, constraints> : _distill<base, opts> : unknown extends t ? unknown : t extends TerminallyInferredObject | Primitive ? t : t extends MorphAst<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 DefaultedAst<infer t> ? _distill<t, opts> : t extends Function ? t : isSafelyMappable<t> extends true ? distillMappable<t, opts> : t;
|
|
156
|
-
type distillMappable<o, opts extends distill.Options> = opts["endpoint"] extends "in" ? show<{
|
|
157
|
-
[k in keyof o as k extends optionalInputKeyOf<o> ? never : k]: _distill<o[k], opts>;
|
|
158
|
-
} & {
|
|
159
|
-
[k in optionalInputKeyOf<o>]?: _distill<o[k], opts>;
|
|
160
|
-
}> : show<{
|
|
161
|
-
[k in keyof o as k extends metaOptionalKeyOf<o> ? never : k]: _distill<o[k], opts>;
|
|
162
|
-
} & {
|
|
163
|
-
[k in keyof o as k extends metaOptionalKeyOf<o> ? k : never]?: _distill<o[k], opts>;
|
|
164
|
-
}>;
|
|
165
|
-
type distillUnbrandedIo<t extends MorphAst, i, o extends Out, opts extends distill.Options> = t extends (MorphAst<constrain<infer constrainedIn, any>, Out<constrain<infer constrainedOut, any>>>) ? distillIo<constrainedIn, o extends To ? To<constrainedOut> : Out<constrainedOut>, opts> : t extends MorphAst<constrain<infer constrainedIn, any>> ? distillIo<constrainedIn, o, opts> : t extends MorphAst<any, Out<constrain<infer constrainedOut, any>>> ? distillIo<i, o extends To ? To<constrainedOut> : Out<constrainedOut>, opts> : distillIo<i, o, opts>;
|
|
166
|
-
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;
|
|
167
|
-
type optionalInputKeyOf<o> = metaDefaultedKeyOf<o> | metaOptionalKeyOf<o>;
|
|
168
|
-
type metaDefaultedKeyOf<o> = {
|
|
169
|
-
[k in keyof o]: [o[k]] extends [anyOrNever] ? never : o[k] extends DefaultedAst ? k : never;
|
|
170
|
-
}[keyof o];
|
|
171
|
-
type metaOptionalKeyOf<o> = {
|
|
172
|
-
[k in keyof o]: [o[k]] extends [anyOrNever] ? never : o[k] extends OptionalAst ? k : never;
|
|
173
|
-
}[keyof o];
|
|
174
|
-
type distillArray<t extends array, opts extends distill.Options> = _distillArray<[...t], opts, []> extends infer result ? distillNonArraykeys<t, t extends unknown[] ? result : Readonly<t>, opts> : never;
|
|
175
|
-
type distillNonArraykeys<originalArray extends array, distilledArray, opts extends distill.Options> = keyof originalArray extends keyof distilledArray | constrained ? distilledArray : distilledArray & _distill<{
|
|
176
|
-
[k in keyof originalArray as k extends (keyof distilledArray | (opts["branded"] extends true ? never : constrained)) ? never : k]: originalArray[k];
|
|
177
|
-
}, opts>;
|
|
178
|
-
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>];
|
|
179
|
-
type distillPostfix<t extends array, opts extends distill.Options, postfix extends array = []> = t extends readonly [...infer init, infer last] ? distillPostfix<init, opts, [_distill<last, opts>, ...postfix]> : [...{
|
|
180
|
-
[i in keyof t]: _distill<t[i], opts>;
|
|
181
|
-
}, ...postfix];
|
|
182
|
-
type BuiltinTerminalObjectKind = Exclude<keyof arkPrototypes.instances, "Array" | "Function">;
|
|
183
|
-
/** Objects we don't want to expand during inference like Date or Promise */
|
|
184
|
-
type TerminallyInferredObject = arkPrototypes.instanceOf<BuiltinTerminalObjectKind> | ArkEnv.prototypes;
|
|
185
|
-
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>;
|
|
186
|
-
export type constrainWithPredicate<t> = t extends constrain<unknown, infer constraints> ? applyConstraintSchema<constrain<t, constraints>, "predicate", any> : applyConstraintSchema<t, "predicate", any>;
|
|
187
|
-
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;
|
|
188
|
-
export type inferMorphOut<morph extends Morph> = Exclude<ReturnType<morph>, ArkError | ArkErrors>;
|
|
189
|
-
export type Out<o = any> = ["=>", o, boolean];
|
|
190
|
-
export type To<o = any> = ["=>", o, true];
|
|
191
|
-
export type MorphAst<i = any, o extends Out = Out> = (In: i) => o;
|
|
192
|
-
export type Optional = {
|
|
193
|
-
optional?: {};
|
|
194
|
-
};
|
|
195
|
-
export type OptionalAst<t = unknown> = constrain<t, Optional>;
|
|
196
|
-
export type Default<v = any> = ["=", v];
|
|
197
|
-
export type DefaultedAst<t = any, v = any> = (In?: t) => Default<v>;
|
|
198
|
-
export type termOrType<t> = t | Type<t, any>;
|
package/out/keywords/ast.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { Branded, constrain, constraint, Constraints, Literal, Narrowed, normalizeLimit, Optional } from "../ast.ts";
|
|
2
|
-
export type AtOrAfter<rule> = {
|
|
3
|
-
atOrAfter: constraint<rule>;
|
|
4
|
-
};
|
|
5
|
-
export type AtOrBefore<rule> = {
|
|
6
|
-
atOrBefore: constraint<rule>;
|
|
7
|
-
};
|
|
8
|
-
export type After<rule> = {
|
|
9
|
-
after: constraint<rule>;
|
|
10
|
-
};
|
|
11
|
-
export type Before<rule> = {
|
|
12
|
-
before: constraint<rule>;
|
|
13
|
-
};
|
|
14
|
-
export declare namespace Date {
|
|
15
|
-
type atOrAfter<rule> = constrain<Date, AtOrAfter<rule>>;
|
|
16
|
-
type after<rule> = constrain<Date, After<rule>>;
|
|
17
|
-
type atOrBefore<rule> = constrain<Date, AtOrBefore<rule>>;
|
|
18
|
-
type before<rule> = constrain<Date, Before<rule>>;
|
|
19
|
-
type narrowed = constrain<Date, Narrowed>;
|
|
20
|
-
type optional = constrain<Date, Optional>;
|
|
21
|
-
type branded<rule> = constrain<Date, Branded<rule>>;
|
|
22
|
-
type literal<rule> = constrain<Date, Literal<rule>>;
|
|
23
|
-
type is<constraints extends Constraints> = constrain<Date, constraints>;
|
|
24
|
-
type afterSchemaToConstraint<schema, rule> = schema extends {
|
|
25
|
-
exclusive: true;
|
|
26
|
-
} ? After<normalizeLimit<rule>> : AtOrAfter<normalizeLimit<rule>>;
|
|
27
|
-
type beforeSchemaToConstraint<schema, rule> = schema extends {
|
|
28
|
-
exclusive: true;
|
|
29
|
-
} ? Before<normalizeLimit<rule>> : AtOrBefore<normalizeLimit<rule>>;
|
|
30
|
-
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 Narrowed ? narrowed : never;
|
|
31
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { AtLeast, AtMost, DivisibleBy, number } from "./number.ts";
|
|
2
|
-
/**
|
|
3
|
-
* As per the ECMA-262 specification:
|
|
4
|
-
* A time value supports a slightly smaller range of -8,640,000,000,000,000 to 8,640,000,000,000,000 milliseconds.
|
|
5
|
-
*
|
|
6
|
-
* @see https://262.ecma-international.org/15.0/index.html#sec-time-values-and-time-range
|
|
7
|
-
*/
|
|
8
|
-
export declare const epoch: import("@ark/schema").BaseRoot<import("@ark/schema").InternalRootDeclaration>;
|
|
9
|
-
export type epoch = number.is<DivisibleBy<1> & AtMost<8640000000000000> & AtLeast<-8640000000000000>>;
|