arktype 2.0.0-rc.26 → 2.0.0-rc.27
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 +61 -241
- package/out/attributes.js +1 -2
- package/out/generic.d.ts +4 -4
- package/out/keywords/{constructors/Array.d.ts → Array.d.ts} +2 -2
- package/out/keywords/{constructors/Array.js → Array.js} +1 -1
- package/out/keywords/{constructors/FormData.d.ts → FormData.d.ts} +2 -2
- package/out/keywords/{constructors/FormData.js → FormData.js} +1 -1
- package/out/keywords/{constructors/TypedArray.d.ts → TypedArray.d.ts} +1 -1
- package/out/keywords/{constructors/TypedArray.js → TypedArray.js} +1 -1
- package/out/keywords/{constructors/constructors.d.ts → constructors.d.ts} +1 -1
- package/out/keywords/{constructors/constructors.js → constructors.js} +1 -1
- package/out/keywords/keywords.d.ts +6 -9
- package/out/keywords/keywords.js +3 -3
- package/out/keywords/number.d.ts +23 -0
- package/out/keywords/{number/epoch.js → number.js} +23 -1
- package/out/keywords/string.d.ts +327 -0
- package/out/keywords/string.js +398 -0
- package/out/methods/array.d.ts +6 -7
- package/out/methods/base.d.ts +10 -14
- package/out/methods/date.d.ts +5 -6
- package/out/methods/number.d.ts +6 -7
- package/out/methods/object.d.ts +5 -5
- package/out/methods/string.d.ts +7 -8
- package/out/parser/ast/generic.d.ts +17 -0
- package/out/parser/ast/infer.d.ts +4 -18
- package/out/parser/ast/validate.d.ts +10 -6
- package/out/parser/ast/validate.js +2 -0
- package/out/parser/definition.d.ts +17 -8
- package/out/parser/definition.js +20 -2
- package/out/parser/objectLiteral.d.ts +39 -39
- package/out/parser/objectLiteral.js +75 -49
- package/out/parser/property.d.ts +37 -0
- package/out/parser/property.js +16 -0
- package/out/parser/reduce/dynamic.d.ts +1 -1
- package/out/parser/shift/operand/enclosed.d.ts +1 -3
- package/out/parser/shift/operand/unenclosed.d.ts +2 -1
- package/out/parser/shift/operator/default.d.ts +2 -1
- package/out/parser/shift/operator/default.js +1 -1
- package/out/parser/string.d.ts +5 -4
- package/out/parser/string.js +18 -1
- package/out/parser/tupleExpressions.d.ts +47 -0
- package/out/parser/tupleExpressions.js +67 -0
- package/out/parser/tupleLiteral.d.ts +80 -0
- package/out/parser/tupleLiteral.js +119 -0
- package/out/scope.d.ts +8 -7
- package/out/scope.js +12 -32
- package/out/type.d.ts +5 -5
- package/package.json +3 -3
- package/out/keywords/constructors/Date.d.ts +0 -37
- package/out/keywords/number/epoch.d.ts +0 -10
- 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 -58
- 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/base64.d.ts +0 -21
- package/out/keywords/string/base64.js +0 -6
- 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 -54
- 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 -135
- package/out/keywords/string/string.js +0 -43
- 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/parser/tuple.d.ts +0 -148
- package/out/parser/tuple.js +0 -164
- /package/out/{keywords/constructors/Date.js → parser/ast/generic.js} +0 -0
package/out/parser/string.js
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
import { throwInternalError, throwParseError } from "@ark/util";
|
|
2
|
+
import { DynamicState } from "./reduce/dynamic.js";
|
|
2
3
|
import { parseDefault } from "./shift/operator/default.js";
|
|
3
4
|
import { writeUnexpectedCharacterMessage } from "./shift/operator/operator.js";
|
|
5
|
+
import { ArkTypeScanner } from "./shift/scanner.js";
|
|
6
|
+
export const parseString = (def, ctx) => {
|
|
7
|
+
const aliasResolution = ctx.$.maybeResolveRoot(def);
|
|
8
|
+
if (aliasResolution)
|
|
9
|
+
return aliasResolution;
|
|
10
|
+
const aliasArrayResolution = def.endsWith("[]") ?
|
|
11
|
+
ctx.$.maybeResolveRoot(def.slice(0, -2))?.array()
|
|
12
|
+
: undefined;
|
|
13
|
+
if (aliasArrayResolution)
|
|
14
|
+
return aliasArrayResolution;
|
|
15
|
+
const s = new DynamicState(new ArkTypeScanner(def), ctx);
|
|
16
|
+
const node = fullStringParse(s);
|
|
17
|
+
if (s.finalizer === ">")
|
|
18
|
+
throwParseError(writeUnexpectedCharacterMessage(">"));
|
|
19
|
+
return node;
|
|
20
|
+
};
|
|
4
21
|
export const fullStringParse = (s) => {
|
|
5
22
|
s.parseOperand();
|
|
6
23
|
let result = parseUntilFinalizer(s).root;
|
|
@@ -10,7 +27,7 @@ export const fullStringParse = (s) => {
|
|
|
10
27
|
if (s.finalizer === "=")
|
|
11
28
|
result = parseDefault(s);
|
|
12
29
|
else if (s.finalizer === "?")
|
|
13
|
-
result = result
|
|
30
|
+
result = [result, "?"];
|
|
14
31
|
s.scanner.shiftUntilNonWhitespace();
|
|
15
32
|
if (s.scanner.lookahead) {
|
|
16
33
|
// throw a parse error if non-whitespace characters made it here without being parsed
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type BaseParseContext, type BaseRoot, type MetaSchema, type Morph, type Predicate, type unwrapDefault } from "@ark/schema";
|
|
2
|
+
import { type array, type BuiltinObjectKind, type Constructor, type Domain, type show } from "@ark/util";
|
|
3
|
+
import type { defaultFor, distill, inferIntersection, inferMorphOut, inferPredicate, Out, withDefault } from "../attributes.ts";
|
|
4
|
+
import type { type } from "../keywords/keywords.ts";
|
|
5
|
+
import type { inferDefinition, validateDefinition } from "./definition.ts";
|
|
6
|
+
import { writeMissingRightOperandMessage } from "./shift/operand/unenclosed.ts";
|
|
7
|
+
import type { ArkTypeScanner } from "./shift/scanner.ts";
|
|
8
|
+
import type { BaseCompletions } from "./string.ts";
|
|
9
|
+
export declare const maybeParseTupleExpression: (def: array, ctx: BaseParseContext) => BaseRoot | null;
|
|
10
|
+
export type maybeValidateTupleExpression<def extends array, $, args> = def extends IndexZeroExpression ? validatePrefixExpression<def, $, args> : def extends IndexOneExpression ? validateIndexOneExpression<def, $, args> : def extends (readonly ["", ...unknown[]] | readonly [unknown, "", ...unknown[]]) ? readonly [
|
|
11
|
+
def[0] extends "" ? BaseCompletions<$, args, IndexZeroOperator | "..."> : def[0],
|
|
12
|
+
def[1] extends "" ? BaseCompletions<$, args, IndexOneOperator | "..."> : def[1]
|
|
13
|
+
] : null;
|
|
14
|
+
export type inferTupleExpression<def extends TupleExpression, $, args> = def[1] extends "[]" ? inferDefinition<def[0], $, 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 "=" ? withDefault<inferDefinition<def[0], $, args>, unwrapDefault<def[2]>> : def[1] extends "@" ? inferDefinition<def[0], $, args> : 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;
|
|
15
|
+
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;
|
|
16
|
+
export type validateIndexOneExpression<def extends IndexOneExpression, $, args> = def[1] extends TuplePostfixOperator ? readonly [validateDefinition<def[0], $, args>, def[1]] : readonly [
|
|
17
|
+
validateDefinition<def[0], $, args>,
|
|
18
|
+
def["length"] extends 2 ? writeMissingRightOperandMessage<def[1]> : def[1],
|
|
19
|
+
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 "=" ? defaultFor<type.infer.In<def[0], $, args>> : def[1] extends "@" ? MetaSchema : validateDefinition<def[2], $, args>
|
|
20
|
+
];
|
|
21
|
+
export type UnparsedTupleExpressionInput = {
|
|
22
|
+
instanceof: Constructor;
|
|
23
|
+
"===": unknown;
|
|
24
|
+
};
|
|
25
|
+
export type UnparsedTupleOperator = show<keyof UnparsedTupleExpressionInput>;
|
|
26
|
+
export declare const parseKeyOfTuple: PrefixParser<"keyof">;
|
|
27
|
+
export type inferKeyOfExpression<operandDef, $, args> = show<keyof inferDefinition<operandDef, $, args>>;
|
|
28
|
+
export type IndexOneParser<token extends IndexOneOperator> = (def: IndexOneExpression<token>, ctx: BaseParseContext) => BaseRoot;
|
|
29
|
+
export type PrefixParser<token extends IndexZeroOperator> = (def: IndexZeroExpression<token>, ctx: BaseParseContext) => BaseRoot;
|
|
30
|
+
export type TupleExpression = IndexZeroExpression | IndexOneExpression;
|
|
31
|
+
export type TupleExpressionOperator = IndexZeroOperator | IndexOneOperator;
|
|
32
|
+
export type IndexOneOperator = TuplePostfixOperator | TupleInfixOperator;
|
|
33
|
+
export type TuplePostfixOperator = "[]" | "?";
|
|
34
|
+
export type TupleInfixOperator = "&" | "|" | "=>" | "=" | ":" | "@";
|
|
35
|
+
export type IndexOneExpression<token extends IndexOneOperator = IndexOneOperator> = readonly [unknown, token, ...unknown[]];
|
|
36
|
+
export declare const parseMorphTuple: IndexOneParser<"=>">;
|
|
37
|
+
export declare const writeMalformedFunctionalExpressionMessage: (operator: ":" | "=>", value: unknown) => string;
|
|
38
|
+
export type parseMorph<inDef, morph, $, args> = morph extends Morph ? inferMorphOut<morph> extends infer out ? (In: distill.In<inferDefinition<inDef, $, args>>) => Out<out> : never : never;
|
|
39
|
+
export declare const parseNarrowTuple: IndexOneParser<":">;
|
|
40
|
+
export type IndexZeroOperator = "keyof" | "instanceof" | "===";
|
|
41
|
+
export type IndexZeroExpression<token extends IndexZeroOperator = IndexZeroOperator> = readonly [token, ...unknown[]];
|
|
42
|
+
export type InfixExpression = readonly [
|
|
43
|
+
unknown,
|
|
44
|
+
ArkTypeScanner.InfixToken,
|
|
45
|
+
...unknown[]
|
|
46
|
+
];
|
|
47
|
+
export declare const writeInvalidConstructorMessage: <actual extends Domain | BuiltinObjectKind>(actual: actual) => string;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Disjoint, intersectNodesRoot } from "@ark/schema";
|
|
2
|
+
import { objectKindOrDomainOf, throwParseError } from "@ark/util";
|
|
3
|
+
import { shallowDefaultableMessage, shallowOptionalMessage } from "./ast/validate.js";
|
|
4
|
+
import { writeMissingRightOperandMessage } from "./shift/operand/unenclosed.js";
|
|
5
|
+
export const maybeParseTupleExpression = (def, ctx) => isIndexZeroExpression(def) ? prefixParsers[def[0]](def, ctx)
|
|
6
|
+
: isIndexOneExpression(def) ? indexOneParsers[def[1]](def, ctx)
|
|
7
|
+
: null;
|
|
8
|
+
export const parseKeyOfTuple = (def, ctx) => ctx.$.parseOwnDefinitionFormat(def[1], ctx).keyof();
|
|
9
|
+
const parseBranchTuple = (def, ctx) => {
|
|
10
|
+
if (def[2] === undefined)
|
|
11
|
+
return throwParseError(writeMissingRightOperandMessage(def[1], ""));
|
|
12
|
+
const l = ctx.$.parseOwnDefinitionFormat(def[0], ctx);
|
|
13
|
+
const r = ctx.$.parseOwnDefinitionFormat(def[2], ctx);
|
|
14
|
+
if (def[1] === "|")
|
|
15
|
+
return ctx.$.node("union", { branches: [l, r] });
|
|
16
|
+
const result = intersectNodesRoot(l, r, ctx.$);
|
|
17
|
+
if (result instanceof Disjoint)
|
|
18
|
+
return result.throw();
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
const parseArrayTuple = (def, ctx) => ctx.$.parseOwnDefinitionFormat(def[0], ctx).array();
|
|
22
|
+
const isIndexOneExpression = (def) => indexOneParsers[def[1]] !== undefined;
|
|
23
|
+
export const parseMorphTuple = (def, ctx) => {
|
|
24
|
+
if (typeof def[2] !== "function") {
|
|
25
|
+
return throwParseError(writeMalformedFunctionalExpressionMessage("=>", def[2]));
|
|
26
|
+
}
|
|
27
|
+
return ctx.$.parseOwnDefinitionFormat(def[0], ctx).pipe(def[2]);
|
|
28
|
+
};
|
|
29
|
+
export const writeMalformedFunctionalExpressionMessage = (operator, value) => `${operator === ":" ? "Narrow" : "Morph"} expression requires a function following '${operator}' (was ${typeof value})`;
|
|
30
|
+
export const parseNarrowTuple = (def, ctx) => {
|
|
31
|
+
if (typeof def[2] !== "function") {
|
|
32
|
+
return throwParseError(writeMalformedFunctionalExpressionMessage(":", def[2]));
|
|
33
|
+
}
|
|
34
|
+
return ctx.$.parseOwnDefinitionFormat(def[0], ctx).constrain("predicate", def[2]);
|
|
35
|
+
};
|
|
36
|
+
const parseAttributeTuple = (def, ctx) => ctx.$.parseOwnDefinitionFormat(def[0], ctx).configureShallowDescendants(def[2]);
|
|
37
|
+
const indexOneParsers = {
|
|
38
|
+
"[]": parseArrayTuple,
|
|
39
|
+
"|": parseBranchTuple,
|
|
40
|
+
"&": parseBranchTuple,
|
|
41
|
+
":": parseNarrowTuple,
|
|
42
|
+
"=>": parseMorphTuple,
|
|
43
|
+
"@": parseAttributeTuple,
|
|
44
|
+
// since object and tuple literals parse there via `parseProperty`,
|
|
45
|
+
// they must be shallow if parsed directly as a tuple expression
|
|
46
|
+
"=": () => throwParseError(shallowDefaultableMessage),
|
|
47
|
+
"?": () => throwParseError(shallowOptionalMessage)
|
|
48
|
+
};
|
|
49
|
+
const prefixParsers = {
|
|
50
|
+
keyof: parseKeyOfTuple,
|
|
51
|
+
instanceof: (def, ctx) => {
|
|
52
|
+
if (typeof def[1] !== "function") {
|
|
53
|
+
return throwParseError(writeInvalidConstructorMessage(objectKindOrDomainOf(def[1])));
|
|
54
|
+
}
|
|
55
|
+
const branches = def
|
|
56
|
+
.slice(1)
|
|
57
|
+
.map(ctor => typeof ctor === "function" ?
|
|
58
|
+
ctx.$.node("proto", { proto: ctor })
|
|
59
|
+
: throwParseError(writeInvalidConstructorMessage(objectKindOrDomainOf(ctor))));
|
|
60
|
+
return branches.length === 1 ?
|
|
61
|
+
branches[0]
|
|
62
|
+
: ctx.$.node("union", { branches });
|
|
63
|
+
},
|
|
64
|
+
"===": (def, ctx) => ctx.$.units(def.slice(1))
|
|
65
|
+
};
|
|
66
|
+
const isIndexZeroExpression = (def) => prefixParsers[def[0]] !== undefined;
|
|
67
|
+
export const writeInvalidConstructorMessage = (actual) => `Expected a constructor following 'instanceof' operator (was ${actual})`;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { type BaseParseContext, type BaseRoot, type Sequence } from "@ark/schema";
|
|
2
|
+
import { type array, type conform, type ErrorMessage, type satisfy } from "@ark/util";
|
|
3
|
+
import type { inferDefinition, validateInnerDefinition } from "./definition.ts";
|
|
4
|
+
import { type DefaultablePropertyTuple, type OptionalPropertyDefinition, type PossibleDefaultableStringDefinition } from "./property.ts";
|
|
5
|
+
export declare const parseTupleLiteral: (def: array, ctx: BaseParseContext) => BaseRoot;
|
|
6
|
+
export type validateTupleLiteral<def extends array, $, args> = parseSequence<def, $, args> extends infer s extends SequenceParseState ? Readonly<s["validated"]> : never;
|
|
7
|
+
export type inferTupleLiteral<def extends array, $, args> = parseSequence<def, $, args> extends infer s extends SequenceParseState ? s["inferred"] : never;
|
|
8
|
+
type SequenceParsePhase = satisfy<keyof Sequence.Inner, "prefix" | "optionals" | "defaultables" | "postfix">;
|
|
9
|
+
type SequenceParseState = {
|
|
10
|
+
unscanned: array;
|
|
11
|
+
inferred: array;
|
|
12
|
+
validated: array;
|
|
13
|
+
phase: SequenceParsePhase;
|
|
14
|
+
};
|
|
15
|
+
type parseSequence<def extends array, $, args> = parseNextElement<{
|
|
16
|
+
unscanned: def;
|
|
17
|
+
inferred: [];
|
|
18
|
+
validated: [];
|
|
19
|
+
phase: "prefix";
|
|
20
|
+
}, $, args>;
|
|
21
|
+
type PreparsedElementKind = "required" | "optionals" | "defaultables";
|
|
22
|
+
type PreparsedElement = {
|
|
23
|
+
head: unknown;
|
|
24
|
+
tail: array;
|
|
25
|
+
inferred: unknown;
|
|
26
|
+
validated: unknown;
|
|
27
|
+
kind: PreparsedElementKind;
|
|
28
|
+
spread: boolean;
|
|
29
|
+
};
|
|
30
|
+
declare namespace PreparsedElement {
|
|
31
|
+
type from<result extends PreparsedElement> = result;
|
|
32
|
+
}
|
|
33
|
+
type preparseNextState<s extends SequenceParseState, $, args> = s["unscanned"] extends readonly ["...", infer head, ...infer tail] ? preparseNextElement<head, tail, true, $, args> : s["unscanned"] extends readonly [infer head, ...infer tail] ? preparseNextElement<head, tail, false, $, args> : null;
|
|
34
|
+
type preparseNextElement<head, tail extends array, spread extends boolean, $, args> = PreparsedElement.from<{
|
|
35
|
+
head: head;
|
|
36
|
+
tail: tail;
|
|
37
|
+
inferred: inferDefinition<head, $, args>;
|
|
38
|
+
validated: validateInnerDefinition<head, $, args>;
|
|
39
|
+
kind: head extends OptionalPropertyDefinition ? "optionals" : head extends DefaultablePropertyTuple ? "defaultables" : head extends PossibleDefaultableStringDefinition ? "defaultables" : "required";
|
|
40
|
+
spread: spread;
|
|
41
|
+
}>;
|
|
42
|
+
type parseNextElement<s extends SequenceParseState, $, args> = preparseNextState<s, $, args> extends infer next extends PreparsedElement ? parseNextElement<{
|
|
43
|
+
unscanned: next["tail"];
|
|
44
|
+
inferred: nextInferred<s, next>;
|
|
45
|
+
validated: nextValidated<s, next>;
|
|
46
|
+
phase: next["kind"] extends "optionals" | "defaultables" ? next["kind"] : number extends nextInferred<s, next>["length"] ? "postfix" : "prefix";
|
|
47
|
+
}, $, args> : s;
|
|
48
|
+
type nextInferred<s extends SequenceParseState, next extends PreparsedElement> = next["spread"] extends true ? [
|
|
49
|
+
...s["inferred"],
|
|
50
|
+
...conform<next["inferred"], array>
|
|
51
|
+
] : next["kind"] extends "optionals" ? [...s["inferred"], next["inferred"]?] : [...s["inferred"], next["inferred"]];
|
|
52
|
+
type nextValidated<s extends SequenceParseState, next extends PreparsedElement> = [
|
|
53
|
+
...s["validated"],
|
|
54
|
+
...nextValidatedSpreadOperatorIfPresent<s, next>,
|
|
55
|
+
nextValidatedElement<s, next>
|
|
56
|
+
];
|
|
57
|
+
type nextValidatedSpreadOperatorIfPresent<s extends SequenceParseState, next extends PreparsedElement> = next["spread"] extends true ? [
|
|
58
|
+
next["inferred"] extends infer spreadOperand extends array ? [
|
|
59
|
+
s["phase"],
|
|
60
|
+
number
|
|
61
|
+
] extends ["postfix", spreadOperand["length"]] ? ErrorMessage<multipleVariadicMessage> : "..." : ErrorMessage<writeNonArraySpreadMessage<next["head"]>>
|
|
62
|
+
] : [];
|
|
63
|
+
type nextValidatedElement<s extends SequenceParseState, next extends PreparsedElement> = next["kind"] extends "optionals" ? next["spread"] extends true ? ErrorMessage<spreadOptionalMessage> : s["phase"] extends "postfix" ? ErrorMessage<optionalPostVariadicMessage> : next["validated"] : next["kind"] extends "defaultables" ? next["spread"] extends true ? ErrorMessage<spreadDefaultableMessage> : s["phase"] extends "optionals" ? ErrorMessage<defaultablePostOptionalMessage> : s["phase"] extends "postfix" ? ErrorMessage<defaultablePostVariadicMessage> : next["validated"] : [s["phase"], next["spread"]] extends ["optionals" | " defaults", false] ? ErrorMessage<requiredPostOptionalMessage> : next["validated"];
|
|
64
|
+
export declare const writeNonArraySpreadMessage: <operand extends string>(operand: operand) => writeNonArraySpreadMessage<operand>;
|
|
65
|
+
type writeNonArraySpreadMessage<operand> = `Spread element must be an array${operand extends string ? ` (was ${operand})` : ""}`;
|
|
66
|
+
export declare const multipleVariadicMesage = "A tuple may have at most one variadic element";
|
|
67
|
+
type multipleVariadicMessage = typeof multipleVariadicMesage;
|
|
68
|
+
export declare const requiredPostOptionalMessage = "A required element may not follow an optional element";
|
|
69
|
+
type requiredPostOptionalMessage = typeof requiredPostOptionalMessage;
|
|
70
|
+
export declare const optionalPostVariadicMessage = "An optional element may not follow a variadic element";
|
|
71
|
+
type optionalPostVariadicMessage = typeof optionalPostVariadicMessage;
|
|
72
|
+
export declare const spreadOptionalMessage = "A spread element cannot be optional";
|
|
73
|
+
type spreadOptionalMessage = typeof spreadOptionalMessage;
|
|
74
|
+
export declare const spreadDefaultableMessage = "A spread element cannot have a default";
|
|
75
|
+
type spreadDefaultableMessage = typeof spreadDefaultableMessage;
|
|
76
|
+
export declare const defaultablePostVariadicMessage = "A defaultable element may not follow a variadic element";
|
|
77
|
+
type defaultablePostVariadicMessage = typeof defaultablePostVariadicMessage;
|
|
78
|
+
export declare const defaultablePostOptionalMessage = "A defaultable element may not follow an optional element without a default";
|
|
79
|
+
type defaultablePostOptionalMessage = typeof defaultablePostOptionalMessage;
|
|
80
|
+
export {};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { $ark, makeRootAndArrayPropertiesMutable } from "@ark/schema";
|
|
2
|
+
import { append, isArray, isEmptyObject, throwParseError } from "@ark/util";
|
|
3
|
+
import { parseProperty } from "./property.js";
|
|
4
|
+
export const parseTupleLiteral = (def, ctx) => {
|
|
5
|
+
let sequences = [{}];
|
|
6
|
+
let i = 0;
|
|
7
|
+
while (i < def.length) {
|
|
8
|
+
let spread = false;
|
|
9
|
+
if (def[i] === "..." && i < def.length - 1) {
|
|
10
|
+
spread = true;
|
|
11
|
+
i++;
|
|
12
|
+
}
|
|
13
|
+
const parsedProperty = parseProperty(def[i], ctx);
|
|
14
|
+
const [valueNode, operator, possibleDefaultValue] = !isArray(parsedProperty) ? [parsedProperty] : parsedProperty;
|
|
15
|
+
i++;
|
|
16
|
+
if (spread) {
|
|
17
|
+
if (!valueNode.extends($ark.intrinsic.Array))
|
|
18
|
+
return throwParseError(writeNonArraySpreadMessage(valueNode.expression));
|
|
19
|
+
// a spread must be distributed over branches e.g.:
|
|
20
|
+
// def: [string, ...(number[] | [true, false])]
|
|
21
|
+
// nodes: [string, ...number[]] | [string, true, false]
|
|
22
|
+
sequences = sequences.flatMap(base =>
|
|
23
|
+
// since appendElement mutates base, we have to shallow-ish clone it for each branch
|
|
24
|
+
valueNode.distribute(branch => appendSpreadBranch(makeRootAndArrayPropertiesMutable(base), branch)));
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
sequences = sequences.map(base => {
|
|
28
|
+
if (operator === "?")
|
|
29
|
+
return appendOptionalElement(base, valueNode);
|
|
30
|
+
if (operator === "=")
|
|
31
|
+
return appendDefaultableElement(base, valueNode, possibleDefaultValue);
|
|
32
|
+
return appendRequiredElement(base, valueNode);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return ctx.$.parseSchema(sequences.map(sequence => isEmptyObject(sequence) ?
|
|
37
|
+
{
|
|
38
|
+
proto: Array,
|
|
39
|
+
exactLength: 0
|
|
40
|
+
}
|
|
41
|
+
: {
|
|
42
|
+
proto: Array,
|
|
43
|
+
sequence
|
|
44
|
+
}));
|
|
45
|
+
};
|
|
46
|
+
const appendRequiredElement = (base, element) => {
|
|
47
|
+
if (base.optionals)
|
|
48
|
+
// e.g. [string?, number]
|
|
49
|
+
return throwParseError(requiredPostOptionalMessage);
|
|
50
|
+
if (base.variadic) {
|
|
51
|
+
// e.g. [...string[], number]
|
|
52
|
+
base.postfix = append(base.postfix, element);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
// e.g. [string, number]
|
|
56
|
+
base.prefix = append(base.prefix, element);
|
|
57
|
+
}
|
|
58
|
+
return base;
|
|
59
|
+
};
|
|
60
|
+
const appendOptionalElement = (base, element) => {
|
|
61
|
+
if (base.variadic)
|
|
62
|
+
// e.g. [...string[], number?]
|
|
63
|
+
return throwParseError(optionalPostVariadicMessage);
|
|
64
|
+
// e.g. [string, number?]
|
|
65
|
+
base.optionals = append(base.optionals, element);
|
|
66
|
+
return base;
|
|
67
|
+
};
|
|
68
|
+
const appendDefaultableElement = (base, element, value) => {
|
|
69
|
+
if (base.variadic)
|
|
70
|
+
// e.g. [...string[], number = 0]
|
|
71
|
+
return throwParseError(defaultablePostVariadicMessage);
|
|
72
|
+
if (base.optionals)
|
|
73
|
+
// e.g. [string?, number = 0]
|
|
74
|
+
return throwParseError(defaultablePostOptionalMessage);
|
|
75
|
+
// value's assignability to element will be checked when the
|
|
76
|
+
// sequence is instantiated by @ark/schema
|
|
77
|
+
// e.g. [string, number = 0]
|
|
78
|
+
base.defaultables = append(base.defaultables, [[element, value]]);
|
|
79
|
+
return base;
|
|
80
|
+
};
|
|
81
|
+
const appendVariadicElement = (base, element) => {
|
|
82
|
+
// e.g. [...string[], number, ...string[]]
|
|
83
|
+
if (base.postfix)
|
|
84
|
+
throwParseError(multipleVariadicMesage);
|
|
85
|
+
if (base.variadic) {
|
|
86
|
+
if (!base.variadic.equals(element)) {
|
|
87
|
+
// e.g. [...string[], ...number[]]
|
|
88
|
+
throwParseError(multipleVariadicMesage);
|
|
89
|
+
}
|
|
90
|
+
// e.g. [...string[], ...string[]]
|
|
91
|
+
// do nothing, second spread doesn't change the type
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
// e.g. [string, ...number[]]
|
|
95
|
+
base.variadic = element.internal;
|
|
96
|
+
}
|
|
97
|
+
return base;
|
|
98
|
+
};
|
|
99
|
+
const appendSpreadBranch = (base, branch) => {
|
|
100
|
+
const spread = branch.firstReferenceOfKind("sequence");
|
|
101
|
+
if (!spread) {
|
|
102
|
+
// the only array with no sequence reference is unknown[]
|
|
103
|
+
return appendVariadicElement(base, $ark.intrinsic.unknown);
|
|
104
|
+
}
|
|
105
|
+
spread.prefix?.forEach(node => appendRequiredElement(base, node));
|
|
106
|
+
spread.optionals?.forEach(node => appendOptionalElement(base, node));
|
|
107
|
+
if (spread.variadic)
|
|
108
|
+
appendVariadicElement(base, spread.variadic);
|
|
109
|
+
spread.postfix?.forEach(node => appendRequiredElement(base, node));
|
|
110
|
+
return base;
|
|
111
|
+
};
|
|
112
|
+
export const writeNonArraySpreadMessage = (operand) => `Spread element must be an array (was ${operand})`;
|
|
113
|
+
export const multipleVariadicMesage = "A tuple may have at most one variadic element";
|
|
114
|
+
export const requiredPostOptionalMessage = "A required element may not follow an optional element";
|
|
115
|
+
export const optionalPostVariadicMessage = "An optional element may not follow a variadic element";
|
|
116
|
+
export const spreadOptionalMessage = "A spread element cannot be optional";
|
|
117
|
+
export const spreadDefaultableMessage = "A spread element cannot have a default";
|
|
118
|
+
export const defaultablePostVariadicMessage = "A defaultable element may not follow a variadic element";
|
|
119
|
+
export const defaultablePostOptionalMessage = "A defaultable element may not follow an optional element without a default";
|
package/out/scope.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
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";
|
|
2
|
-
import { type ErrorType, type
|
|
2
|
+
import { type Brand, type ErrorType, type JsonStructure, type anyOrNever, type array, type flattenListable, type noSuggest } from "@ark/util";
|
|
3
3
|
import type { ArkSchemaRegistry } from "./config.ts";
|
|
4
4
|
import { type GenericDeclaration, type GenericParser, type ParameterString, type baseGenericConstraints, type parseGenericParams, type parseValidGenericParams } from "./generic.ts";
|
|
5
5
|
import type { Ark, type } from "./keywords/keywords.ts";
|
|
6
6
|
import type { BoundModule, Module, Submodule, instantiateExport } from "./module.ts";
|
|
7
7
|
import type { DefAst, InferredAst } from "./parser/ast/infer.ts";
|
|
8
|
-
import { type inferDefinition
|
|
8
|
+
import { type inferDefinition } from "./parser/definition.ts";
|
|
9
|
+
import type { ParsedOptionalProperty } from "./parser/property.ts";
|
|
10
|
+
import type { ParsedDefaultableProperty } from "./parser/shift/operator/default.ts";
|
|
9
11
|
import { InternalTypeParser, type DeclarationParser, type DefinitionParser, type EnumeratedTypeParser, type InstanceOfTypeParser, type SchemaParser, type TypeParser, type UnitTypeParser } from "./type.ts";
|
|
10
12
|
/** The convenience properties attached to `scope` */
|
|
11
13
|
export type ScopeParserAttachments = Omit<ScopeParser, never>;
|
|
@@ -20,7 +22,7 @@ export type bindThis<def> = {
|
|
|
20
22
|
this: Def<def>;
|
|
21
23
|
};
|
|
22
24
|
/** nominal type for an unparsed definition used during scope bootstrapping */
|
|
23
|
-
type Def<def = {}> =
|
|
25
|
+
type Def<def = {}> = Brand<def, "unparsed">;
|
|
24
26
|
/** sentinel indicating a scope that will be associated with a generic has not yet been parsed */
|
|
25
27
|
export type UnparsedScope = "$";
|
|
26
28
|
/** These are legal as values of a scope but not as definitions in other contexts */
|
|
@@ -63,7 +65,6 @@ export interface InternalScope {
|
|
|
63
65
|
constructor: typeof InternalScope;
|
|
64
66
|
}
|
|
65
67
|
export declare class InternalScope<$ extends {} = {}> extends BaseScope<$> {
|
|
66
|
-
private parseCache;
|
|
67
68
|
protected cacheGetter<name extends keyof this>(name: name, value: this[name]): this[name];
|
|
68
69
|
get ambientAttachments(): Ark.boundTypeAttachments<$> | undefined;
|
|
69
70
|
protected preparseOwnAliasEntry(k: string, v: unknown): AliasDefEntry;
|
|
@@ -71,7 +72,6 @@ export declare class InternalScope<$ extends {} = {}> extends BaseScope<$> {
|
|
|
71
72
|
protected normalizeRootScopeValue(resolution: unknown): unknown;
|
|
72
73
|
protected preparseOwnDefinitionFormat(def: unknown, opts: BaseParseOptions): BaseRoot | BaseParseContextInput;
|
|
73
74
|
parseOwnDefinitionFormat(def: unknown, ctx: BaseParseContext): BaseRoot;
|
|
74
|
-
parseString(def: string, ctx: BaseParseContext): BaseRoot;
|
|
75
75
|
unit: UnitTypeParser<$>;
|
|
76
76
|
enumerated: EnumeratedTypeParser<$>;
|
|
77
77
|
instanceOf: InstanceOfTypeParser<$>;
|
|
@@ -86,7 +86,7 @@ export declare class InternalScope<$ extends {} = {}> extends BaseScope<$> {
|
|
|
86
86
|
export declare const scope: ScopeParser;
|
|
87
87
|
export declare namespace scope {
|
|
88
88
|
type validate<def> = {
|
|
89
|
-
[k in keyof def]: k extends noSuggest ? unknown : parseScopeKey<k, def>["params"] extends infer params ? params extends array<GenericParamAst> ? params["length"] extends 0 ? def[k] extends type.Any | PreparsedResolution ? def[k] : k extends (PrivateDeclaration<infer name extends keyof def & string>) ? ErrorType<writeDuplicateAliasError<name>> :
|
|
89
|
+
[k in keyof def]: k extends noSuggest ? unknown : parseScopeKey<k, def>["params"] extends infer params ? params extends array<GenericParamAst> ? params["length"] extends 0 ? def[k] extends type.Any | PreparsedResolution ? def[k] : k extends (PrivateDeclaration<infer name extends keyof def & string>) ? ErrorType<writeDuplicateAliasError<name>> : type.validate<def[k], bootstrapAliases<def>, {}> : type.validate<def[k], bootstrapAliases<def>, baseGenericConstraints<params>> : params : never;
|
|
90
90
|
};
|
|
91
91
|
type infer<def> = inferBootstrapped<bootstrapAliases<def>>;
|
|
92
92
|
}
|
|
@@ -96,7 +96,7 @@ export interface Scope<$ = {}> {
|
|
|
96
96
|
[arkKind]: "scope";
|
|
97
97
|
config: ArkScopeConfig;
|
|
98
98
|
references: readonly BaseNode[];
|
|
99
|
-
json:
|
|
99
|
+
json: JsonStructure;
|
|
100
100
|
exportedNames: array<exportedNameOf<$>>;
|
|
101
101
|
/** The set of names defined at the root-level of the scope mapped to their
|
|
102
102
|
* corresponding definitions.**/
|
|
@@ -139,4 +139,5 @@ type parseGenericScopeKey<name extends string, params extends string, def> = {
|
|
|
139
139
|
name: name;
|
|
140
140
|
params: parseGenericParams<params, bootstrapAliases<def>>;
|
|
141
141
|
};
|
|
142
|
+
export type InnerParseResult = BaseRoot | ParsedOptionalProperty | ParsedDefaultableProperty;
|
|
142
143
|
export {};
|
package/out/scope.js
CHANGED
|
@@ -1,15 +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 { writeUnexpectedCharacterMessage } from "./parser/shift/operator/operator.js";
|
|
4
|
+
import { shallowDefaultableMessage, shallowOptionalMessage } from "./parser/ast/validate.js";
|
|
5
|
+
import { parseInnerDefinition } from "./parser/definition.js";
|
|
7
6
|
import { ArkTypeScanner } from "./parser/shift/scanner.js";
|
|
8
|
-
import { fullStringParse } from "./parser/string.js";
|
|
9
7
|
import { InternalTypeParser } from "./type.js";
|
|
10
8
|
export const $arkTypeRegistry = $ark;
|
|
11
9
|
export class InternalScope extends BaseScope {
|
|
12
|
-
parseCache = {};
|
|
13
10
|
cacheGetter(name, value) {
|
|
14
11
|
Object.defineProperty(this, name, { value });
|
|
15
12
|
return value;
|
|
@@ -60,35 +57,18 @@ 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 ArkTypeScanner(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);
|
package/out/type.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
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 {
|
|
3
|
+
import type { distill } from "./attributes.ts";
|
|
4
4
|
import type { Generic, GenericParser, ParameterString, baseGenericConstraints, parseValidGenericParams, validateParameterString } from "./generic.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";
|
|
8
|
-
import type { validateDeclared
|
|
9
|
-
import type { IndexOneOperator, IndexZeroOperator, TupleInfixOperator } from "./parser/
|
|
8
|
+
import type { validateDeclared } from "./parser/definition.ts";
|
|
9
|
+
import type { IndexOneOperator, 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
14
|
<const def, r = Type<type.infer<def, $>, $>>(def: type.validate<def, $>): r;
|
|
15
|
-
<const params extends ParameterString, const def>(params: validateParameterString<params, $>, def:
|
|
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] :
|
|
15
|
+
<const params extends ParameterString, const def>(params: validateParameterString<params, $>, def: type.validate<def, $, baseGenericConstraints<parseValidGenericParams<params, $>>>): Generic<parseValidGenericParams<params, $>, def, $>;
|
|
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] : [type.validate<rest[0], $>] : []): r;
|
|
17
17
|
/**
|
|
18
18
|
* Error class for validation errors
|
|
19
19
|
* Calling type instance returns an instance of this class on failure
|
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.
|
|
4
|
+
"version": "2.0.0-rc.27",
|
|
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/
|
|
38
|
-
"@ark/
|
|
37
|
+
"@ark/util": "0.27.0",
|
|
38
|
+
"@ark/schema": "0.27.0"
|
|
39
39
|
},
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { satisfy } from "@ark/util";
|
|
2
|
-
import type { After, Anonymous, AtOrAfter, AtOrBefore, AttributeKind, Attributes, Before, brand, Default, Nominal, normalizeLimit, of, Optional } from "../../attributes.ts";
|
|
3
|
-
export declare namespace Date {
|
|
4
|
-
type atOrAfter<rule> = of<Date, AtOrAfter<rule>>;
|
|
5
|
-
type after<rule> = of<Date, After<rule>>;
|
|
6
|
-
type atOrBefore<rule> = of<Date, AtOrBefore<rule>>;
|
|
7
|
-
type before<rule> = of<Date, Before<rule>>;
|
|
8
|
-
type anonymous = of<Date, Anonymous>;
|
|
9
|
-
type nominal<rule> = of<Date, Nominal<rule>>;
|
|
10
|
-
type optional = of<Date, Optional>;
|
|
11
|
-
type defaultsTo<rule> = of<Date, Default<rule>>;
|
|
12
|
-
type is<attributes extends Attributes> = of<Date, attributes>;
|
|
13
|
-
type afterSchemaToConstraint<schema, rule> = schema extends {
|
|
14
|
-
exclusive: true;
|
|
15
|
-
} ? After<normalizeLimit<rule>> : AtOrAfter<normalizeLimit<rule>>;
|
|
16
|
-
type beforeSchemaToConstraint<schema, rule> = schema extends {
|
|
17
|
-
exclusive: true;
|
|
18
|
-
} ? Before<normalizeLimit<rule>> : AtOrBefore<normalizeLimit<rule>>;
|
|
19
|
-
type AttributableKind = satisfy<AttributeKind, "after" | "atOrAfter" | "before" | "atOrBefore">;
|
|
20
|
-
type withSingleAttribute<kind extends AttributableKind, value extends Attributes[kind]> = raw.withSingleAttribute<kind, value>;
|
|
21
|
-
namespace raw {
|
|
22
|
-
type withSingleAttribute<kind, value> = kind extends "nominal" ? nominal<value> : kind extends "after" ? after<value> : kind extends "atOrAfter" ? atOrAfter<value> : kind extends "before" ? before<value> : kind extends "atOrBefore" ? atOrBefore<value> : kind extends "optional" ? optional : kind extends "defaultsTo" ? defaultsTo<value> : never;
|
|
23
|
-
}
|
|
24
|
-
type branded<rule> = brand<Date, Nominal<rule>>;
|
|
25
|
-
namespace branded {
|
|
26
|
-
type atOrAfter<rule> = brand<Date, AtOrAfter<rule>>;
|
|
27
|
-
type after<rule> = brand<Date, After<rule>>;
|
|
28
|
-
type atOrBefore<rule> = brand<Date, AtOrBefore<rule>>;
|
|
29
|
-
type before<rule> = brand<Date, Before<rule>>;
|
|
30
|
-
type anonymous = brand<Date, Anonymous>;
|
|
31
|
-
type is<attributes extends Attributes> = brand<Date, attributes>;
|
|
32
|
-
type withSingleAttribute<kind extends AttributableKind, value extends Attributes[kind]> = raw.withSingleAttribute<kind, value>;
|
|
33
|
-
namespace raw {
|
|
34
|
-
type withSingleAttribute<kind, value> = kind extends "nominal" ? branded<value> : kind extends "after" ? after<value> : kind extends "atOrAfter" ? atOrAfter<value> : kind extends "before" ? before<value> : kind extends "atOrBefore" ? atOrBefore<value> : never;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { AtLeast, AtMost, DivisibleBy } from "../../attributes.ts";
|
|
2
|
-
import type { number } from "./number.ts";
|
|
3
|
-
/**
|
|
4
|
-
* As per the ECMA-262 specification:
|
|
5
|
-
* A time value supports a slightly smaller range of -8,640,000,000,000,000 to 8,640,000,000,000,000 milliseconds.
|
|
6
|
-
*
|
|
7
|
-
* @see https://262.ecma-international.org/15.0/index.html#sec-time-values-and-time-range
|
|
8
|
-
*/
|
|
9
|
-
export declare const epoch: import("@ark/schema").BaseRoot<import("@ark/schema").InternalRootDeclaration>;
|
|
10
|
-
export type epoch = number.is<DivisibleBy<1> & AtMost<8640000000000000> & AtLeast<-8640000000000000>>;
|