arktype 2.0.0-dev.9 → 2.0.0-rc.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/LICENSE +7 -0
- package/out/config.d.ts +25 -0
- package/out/config.js +2 -0
- package/out/generic.d.ts +154 -18
- package/out/generic.js +37 -23
- package/out/index.d.ts +7 -0
- package/out/index.js +6 -0
- package/out/intersect.d.ts +28 -0
- package/out/intersect.js +1 -0
- package/out/keys.d.ts +16 -0
- package/out/keys.js +1 -0
- package/out/keywords/ark.d.ts +33 -0
- package/out/keywords/ark.js +18 -0
- package/out/keywords/ast.d.ts +193 -0
- package/out/keywords/ast.js +2 -0
- package/out/keywords/builtin.d.ts +13 -0
- package/out/keywords/builtin.js +10 -0
- package/out/keywords/constructors/Array.d.ts +16 -0
- package/out/keywords/constructors/Array.js +19 -0
- package/out/keywords/constructors/FormData.d.ts +9 -0
- package/out/keywords/constructors/FormData.js +25 -0
- package/out/keywords/constructors/TypedArray.d.ts +15 -0
- package/out/keywords/constructors/TypedArray.js +14 -0
- package/out/keywords/constructors/constructors.d.ts +41 -0
- package/out/keywords/constructors/constructors.js +31 -0
- package/out/keywords/number/epoch.d.ts +10 -0
- package/out/keywords/number/epoch.js +26 -0
- package/out/keywords/number/integer.d.ts +3 -0
- package/out/keywords/number/integer.js +5 -0
- package/out/keywords/number/number.d.ts +26 -0
- package/out/keywords/number/number.js +9 -0
- package/out/keywords/string/alpha.d.ts +7 -0
- package/out/keywords/string/alpha.js +2 -0
- package/out/keywords/string/alphanumeric.d.ts +7 -0
- package/out/keywords/string/alphanumeric.js +2 -0
- package/out/keywords/string/capitalize.d.ts +14 -0
- package/out/keywords/string/capitalize.js +12 -0
- package/out/keywords/string/creditCard.d.ts +8 -0
- package/out/keywords/string/creditCard.js +37 -0
- package/out/keywords/string/date.d.ts +54 -0
- package/out/keywords/string/date.js +98 -0
- package/out/keywords/string/digits.d.ts +7 -0
- package/out/keywords/string/digits.js +2 -0
- package/out/keywords/string/email.d.ts +7 -0
- package/out/keywords/string/email.js +4 -0
- package/out/keywords/string/integer.d.ts +15 -0
- package/out/keywords/string/integer.js +16 -0
- package/out/keywords/string/ip.d.ts +20 -0
- package/out/keywords/string/ip.js +23 -0
- package/out/keywords/string/json.d.ts +14 -0
- package/out/keywords/string/json.js +45 -0
- package/out/keywords/string/lower.d.ts +14 -0
- package/out/keywords/string/lower.js +12 -0
- package/out/keywords/string/normalize.d.ts +72 -0
- package/out/keywords/string/normalize.js +43 -0
- package/out/keywords/string/numeric.d.ts +14 -0
- package/out/keywords/string/numeric.js +13 -0
- package/out/keywords/string/semver.d.ts +7 -0
- package/out/keywords/string/semver.js +4 -0
- package/out/keywords/string/string.d.ts +57 -0
- package/out/keywords/string/string.js +41 -0
- package/out/keywords/string/trim.d.ts +14 -0
- package/out/keywords/string/trim.js +14 -0
- package/out/keywords/string/upper.d.ts +14 -0
- package/out/keywords/string/upper.js +12 -0
- package/out/keywords/string/url.d.ts +14 -0
- package/out/keywords/string/url.js +37 -0
- package/out/keywords/string/utils.d.ts +2 -0
- package/out/keywords/string/utils.js +10 -0
- package/out/keywords/string/uuid.d.ts +38 -0
- package/out/keywords/string/uuid.js +19 -0
- package/out/keywords/ts.d.ts +53 -0
- package/out/keywords/ts.js +51 -0
- package/out/keywords/utils.d.ts +1 -0
- package/out/keywords/utils.js +2 -0
- package/out/module.d.ts +21 -9
- package/out/module.js +3 -3
- package/out/parser/definition.d.ts +20 -15
- package/out/parser/definition.js +5 -5
- package/out/parser/objectLiteral.d.ts +53 -35
- package/out/parser/objectLiteral.js +75 -50
- package/out/parser/semantic/bounds.d.ts +10 -9
- package/out/parser/semantic/default.d.ts +8 -0
- package/out/parser/semantic/default.js +1 -0
- package/out/parser/semantic/divisor.d.ts +5 -5
- package/out/parser/semantic/divisor.js +1 -0
- package/out/parser/semantic/infer.d.ts +21 -12
- package/out/parser/semantic/infer.js +1 -0
- package/out/parser/semantic/keyof.d.ts +7 -0
- package/out/parser/semantic/keyof.js +1 -0
- package/out/parser/semantic/utils.d.ts +3 -3
- package/out/parser/semantic/utils.js +1 -0
- package/out/parser/semantic/validate.d.ts +21 -17
- package/out/parser/semantic/validate.js +0 -1
- package/out/parser/string/reduce/dynamic.d.ts +16 -14
- package/out/parser/string/reduce/dynamic.js +8 -7
- package/out/parser/string/reduce/shared.d.ts +15 -15
- package/out/parser/string/reduce/shared.js +4 -2
- package/out/parser/string/reduce/static.d.ts +22 -23
- package/out/parser/string/reduce/static.js +1 -0
- package/out/parser/string/shift/operand/date.d.ts +2 -4
- package/out/parser/string/shift/operand/date.js +1 -1
- package/out/parser/string/shift/operand/enclosed.d.ts +10 -6
- package/out/parser/string/shift/operand/enclosed.js +5 -4
- package/out/parser/string/shift/operand/genericArgs.d.ts +13 -13
- package/out/parser/string/shift/operand/genericArgs.js +7 -12
- package/out/parser/string/shift/operand/operand.d.ts +8 -7
- package/out/parser/string/shift/operand/operand.js +5 -6
- package/out/parser/string/shift/operand/unenclosed.d.ts +29 -16
- package/out/parser/string/shift/operand/unenclosed.js +9 -12
- package/out/parser/string/shift/operator/bounds.d.ts +15 -20
- package/out/parser/string/shift/operator/bounds.js +11 -16
- package/out/parser/string/shift/operator/default.d.ts +19 -0
- package/out/parser/string/shift/operator/default.js +17 -0
- package/out/parser/string/shift/operator/divisor.d.ts +3 -3
- package/out/parser/string/shift/operator/divisor.js +1 -1
- package/out/parser/string/shift/operator/operator.d.ts +7 -6
- package/out/parser/string/shift/operator/operator.js +1 -1
- package/out/parser/string/shift/scanner.d.ts +26 -30
- package/out/parser/string/shift/scanner.js +23 -20
- package/out/parser/string/string.d.ts +14 -11
- package/out/parser/string/string.js +5 -2
- package/out/parser/tuple.d.ts +21 -19
- package/out/parser/tuple.js +12 -23
- package/out/scope.d.ts +102 -55
- package/out/scope.js +61 -60
- package/out/subtypes/array.d.ts +13 -0
- package/out/subtypes/array.js +1 -0
- package/out/subtypes/base.d.ts +84 -0
- package/out/subtypes/base.js +1 -0
- package/out/subtypes/date.d.ts +11 -0
- package/out/subtypes/date.js +1 -0
- package/out/subtypes/instantiate.d.ts +16 -0
- package/out/subtypes/instantiate.js +1 -0
- package/out/subtypes/morph.d.ts +13 -0
- package/out/subtypes/morph.js +1 -0
- package/out/subtypes/number.d.ts +12 -0
- package/out/subtypes/number.js +1 -0
- package/out/subtypes/object.d.ts +33 -0
- package/out/subtypes/object.js +1 -0
- package/out/subtypes/string.d.ts +13 -0
- package/out/subtypes/string.js +1 -0
- package/out/subtypes/validator.d.ts +11 -0
- package/out/subtypes/validator.js +1 -0
- package/out/type.d.ts +30 -49
- package/out/type.js +19 -14
- package/package.json +46 -45
- package/__tests__/array.test.ts +0 -391
- package/__tests__/badDefinitionType.test.ts +0 -58
- package/__tests__/basis.test.ts +0 -50
- package/__tests__/bounds.test.ts +0 -318
- package/__tests__/cast.test.ts +0 -37
- package/__tests__/completions.test.ts +0 -51
- package/__tests__/config.test.ts +0 -96
- package/__tests__/dateLiteral.test.ts +0 -36
- package/__tests__/declared.test.ts +0 -124
- package/__tests__/discrimination.test.ts +0 -74
- package/__tests__/divisor.test.ts +0 -114
- package/__tests__/enclosed.test.ts +0 -107
- package/__tests__/examples.test.ts +0 -56
- package/__tests__/expressions.test.ts +0 -210
- package/__tests__/generateBenchData.ts +0 -89
- package/__tests__/generated/cyclic.ts +0 -3058
- package/__tests__/generic.test.ts +0 -313
- package/__tests__/group.test.ts +0 -85
- package/__tests__/hkt.test.ts +0 -22
- package/__tests__/imports.test.ts +0 -126
- package/__tests__/instanceof.test.ts +0 -104
- package/__tests__/intersection.test.ts +0 -108
- package/__tests__/keyTraversal.test.ts +0 -77
- package/__tests__/keyof.test.ts +0 -150
- package/__tests__/keywords.test.ts +0 -214
- package/__tests__/literal.test.ts +0 -90
- package/__tests__/match.bench.ts +0 -31
- package/__tests__/match.test.ts +0 -234
- package/__tests__/methods.bench.ts +0 -22
- package/__tests__/narrow.test.ts +0 -100
- package/__tests__/object.bench.ts +0 -28
- package/__tests__/objectLiteral.test.ts +0 -442
- package/__tests__/operand.bench.ts +0 -45
- package/__tests__/operator.bench.ts +0 -130
- package/__tests__/pipe.test.ts +0 -501
- package/__tests__/realWorld.test.ts +0 -63
- package/__tests__/regex.test.ts +0 -68
- package/__tests__/scope.bench.ts +0 -39
- package/__tests__/scope.test.ts +0 -374
- package/__tests__/serialization.test.ts +0 -19
- package/__tests__/string.test.ts +0 -52
- package/__tests__/submodule.test.ts +0 -86
- package/__tests__/this.test.ts +0 -83
- package/__tests__/thunk.test.ts +0 -86
- package/__tests__/traverse.test.ts +0 -141
- package/__tests__/tsGenerics.test.ts +0 -12
- package/__tests__/type.test.ts +0 -36
- package/__tests__/typeReference.test.ts +0 -39
- package/__tests__/unenclosed.test.ts +0 -136
- package/__tests__/union.test.ts +0 -214
- package/ark.ts +0 -47
- package/generic.ts +0 -69
- package/main.ts +0 -6
- package/match.ts +0 -218
- package/module.ts +0 -15
- package/out/ark.d.ts +0 -28
- package/out/ark.js +0 -10
- package/out/ark.js.map +0 -1
- package/out/generic.js.map +0 -1
- package/out/main.d.ts +0 -6
- package/out/main.js +0 -5
- package/out/main.js.map +0 -1
- package/out/match.d.ts +0 -71
- package/out/match.js +0 -52
- package/out/match.js.map +0 -1
- package/out/module.js.map +0 -1
- package/out/parser/definition.js.map +0 -1
- package/out/parser/generic.d.ts +0 -16
- package/out/parser/generic.js +0 -15
- package/out/parser/generic.js.map +0 -1
- package/out/parser/objectLiteral.js.map +0 -1
- package/out/parser/semantic/bounds.js.map +0 -1
- package/out/parser/semantic/divisor.js.map +0 -1
- package/out/parser/semantic/infer.js.map +0 -1
- package/out/parser/semantic/utils.js.map +0 -1
- package/out/parser/semantic/validate.js.map +0 -1
- package/out/parser/string/reduce/dynamic.js.map +0 -1
- package/out/parser/string/reduce/shared.js.map +0 -1
- package/out/parser/string/reduce/static.js.map +0 -1
- package/out/parser/string/shift/operand/date.js.map +0 -1
- package/out/parser/string/shift/operand/enclosed.js.map +0 -1
- package/out/parser/string/shift/operand/genericArgs.js.map +0 -1
- package/out/parser/string/shift/operand/operand.js.map +0 -1
- package/out/parser/string/shift/operand/unenclosed.js.map +0 -1
- package/out/parser/string/shift/operator/bounds.js.map +0 -1
- package/out/parser/string/shift/operator/divisor.js.map +0 -1
- package/out/parser/string/shift/operator/operator.js.map +0 -1
- package/out/parser/string/shift/scanner.js.map +0 -1
- package/out/parser/string/string.js.map +0 -1
- package/out/parser/tuple.js.map +0 -1
- package/out/scope.js.map +0 -1
- package/out/type.js.map +0 -1
- package/parser/definition.ts +0 -143
- package/parser/generic.ts +0 -66
- package/parser/objectLiteral.ts +0 -233
- package/parser/semantic/bounds.ts +0 -62
- package/parser/semantic/divisor.ts +0 -11
- package/parser/semantic/infer.ts +0 -141
- package/parser/semantic/utils.ts +0 -15
- package/parser/semantic/validate.ts +0 -117
- package/parser/string/reduce/dynamic.ts +0 -208
- package/parser/string/reduce/shared.ts +0 -99
- package/parser/string/reduce/static.ts +0 -296
- package/parser/string/shift/operand/date.ts +0 -55
- package/parser/string/shift/operand/enclosed.ts +0 -123
- package/parser/string/shift/operand/genericArgs.ts +0 -128
- package/parser/string/shift/operand/operand.ts +0 -42
- package/parser/string/shift/operand/unenclosed.ts +0 -217
- package/parser/string/shift/operator/bounds.ts +0 -270
- package/parser/string/shift/operator/divisor.ts +0 -33
- package/parser/string/shift/operator/operator.ts +0 -71
- package/parser/string/shift/scanner.ts +0 -210
- package/parser/string/string.ts +0 -85
- package/parser/tuple.ts +0 -542
- package/scope.ts +0 -291
- package/type.ts +0 -266
package/out/module.d.ts
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
4
|
-
type
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
export declare class Module<$ = any> extends DynamicBase<exportScope<$>> {
|
|
8
|
-
readonly [arkKind]: "module";
|
|
1
|
+
import { RootModule, type GenericAst, type PreparsedNodeResolution } from "@ark/schema";
|
|
2
|
+
import type { anyOrNever, inferred } from "@ark/util";
|
|
3
|
+
import type { Generic } from "./generic.ts";
|
|
4
|
+
import type { Type } from "./type.ts";
|
|
5
|
+
export declare const Module: new <$ extends {}>(exports: exportScope<$>) => Module<$>;
|
|
6
|
+
export interface Module<$ extends {} = {}> extends RootModule<exportScope<$>> {
|
|
9
7
|
}
|
|
10
|
-
export
|
|
8
|
+
export type exportScope<$> = bindExportsToScope<$, $>;
|
|
9
|
+
export declare const BoundModule: new <exports extends {}, $ extends {}>(exports: bindExportsToScope<exports, $>, $: $) => BoundModule<exports, $>;
|
|
10
|
+
export interface BoundModule<exports extends {}, $> extends RootModule<bindExportsToScope<exports, $>> {
|
|
11
|
+
}
|
|
12
|
+
export type bindExportsToScope<exports, $> = {
|
|
13
|
+
[k in keyof exports]: instantiateExport<exports[k], $>;
|
|
14
|
+
} & unknown;
|
|
15
|
+
export type Submodule<exports extends {}> = RootModule<exports & ("$root" extends keyof exports ? {
|
|
16
|
+
[inferred]: exports["$root"];
|
|
17
|
+
} : {})>;
|
|
18
|
+
export type instantiateExport<t, $> = [
|
|
19
|
+
t
|
|
20
|
+
] extends [PreparsedNodeResolution] ? [
|
|
21
|
+
t
|
|
22
|
+
] extends [anyOrNever] ? Type<t, $> : t extends GenericAst<infer params, infer body, infer body$> ? Generic<params, body, body$, $> : t extends Submodule<infer exports> ? BoundModule<exports, $> : never : Type<t, $>;
|
package/out/module.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
3
|
-
|
|
1
|
+
import { RootModule } from "@ark/schema";
|
|
2
|
+
export const Module = RootModule;
|
|
3
|
+
export const BoundModule = RootModule;
|
|
@@ -1,28 +1,33 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { type ErrorMessage, type
|
|
3
|
-
import type { type } from "../ark.
|
|
4
|
-
import type {
|
|
5
|
-
import
|
|
6
|
-
import type
|
|
7
|
-
import type {
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
export
|
|
11
|
-
export type
|
|
1
|
+
import { type BaseRoot } from "@ark/schema";
|
|
2
|
+
import { type ErrorMessage, type Fn, type Primitive, type anyOrNever, type array, type defined, type equals, type objectKindOrDomainOf, type optionalKeyOf, type requiredKeyOf, type show } from "@ark/util";
|
|
3
|
+
import type { type } from "../keywords/ark.ts";
|
|
4
|
+
import type { string } from "../keywords/string/string.ts";
|
|
5
|
+
import type { ParseContext } from "../scope.ts";
|
|
6
|
+
import { type inferObjectLiteral, type validateObjectLiteral } from "./objectLiteral.ts";
|
|
7
|
+
import type { validateString } from "./semantic/validate.ts";
|
|
8
|
+
import type { BaseCompletions, inferString } from "./string/string.ts";
|
|
9
|
+
import { type TupleExpression, type inferTuple, type validateTuple } from "./tuple.ts";
|
|
10
|
+
export declare const parseObject: (def: object, ctx: ParseContext) => BaseRoot;
|
|
11
|
+
export type inferDefinition<def, $, args> = [
|
|
12
|
+
def
|
|
13
|
+
] extends [anyOrNever] ? def : def extends type.cast<infer t> ? {} extends t ? [
|
|
14
|
+
t
|
|
15
|
+
] extends [anyOrNever] ? t : object : t : def extends ThunkCast<infer t> ? t : def extends string ? inferString<def, $, args> : def extends array ? inferTuple<def, $, args> : def extends RegExp ? string.matching<string> : def extends object ? inferObjectLiteral<def, $, args> : never;
|
|
16
|
+
export type validateDefinition<def, $, args> = null extends undefined ? ErrorMessage<`'strict' or 'strictNullChecks' must be set to true in your tsconfig's 'compilerOptions'`> : [def] extends [Terminal] ? def : def extends string ? validateString<def, $, args> : def extends array ? validateTuple<def, $, args> : def extends BadDefinitionType ? ErrorMessage<writeBadDefinitionTypeMessage<objectKindOrDomainOf<def>>> : unknown extends def ? BaseCompletions<$, args> | {} : validateObjectLiteral<def, $, args>;
|
|
12
17
|
export type validateDeclared<declared, def, $, args> = def extends validateDefinition<def, $, args> ? validateInference<def, declared, $, args> : validateDefinition<def, $, args>;
|
|
13
18
|
type validateInference<def, declared, $, args> = def extends RegExp | type.cast<unknown> | ThunkCast | TupleExpression ? validateShallowInference<def, declared, $, args> : def extends array ? declared extends array ? {
|
|
14
|
-
[i in keyof declared]: i extends keyof def ? validateInference<def[i], declared[i], $, args> :
|
|
19
|
+
[i in keyof declared]: i extends keyof def ? validateInference<def[i], declared[i], $, args> : declared[i];
|
|
15
20
|
} : show<declarationMismatch<def, declared, $, args>> : def extends object ? show<{
|
|
16
|
-
[k in requiredKeyOf<declared>]: k extends keyof def ? validateInference<def[k], declared[k], $, args> :
|
|
21
|
+
[k in requiredKeyOf<declared>]: k extends keyof def ? validateInference<def[k], declared[k], $, args> : declared[k];
|
|
17
22
|
} & {
|
|
18
|
-
[k in optionalKeyOf<declared> & string as `${k}?`]: `${k}?` extends (keyof def) ? validateInference<def[`${k}?`], defined<declared[k]>, $, args> :
|
|
23
|
+
[k in optionalKeyOf<declared> & string as `${k}?`]: `${k}?` extends (keyof def) ? validateInference<def[`${k}?`], defined<declared[k]>, $, args> : declared[k];
|
|
19
24
|
}> : validateShallowInference<def, declared, $, args>;
|
|
20
25
|
type validateShallowInference<def, declared, $, args> = equals<inferDefinition<def, $, args>, declared> extends true ? def : show<declarationMismatch<def, declared, $, args>>;
|
|
21
26
|
type declarationMismatch<def, declared, $, args> = {
|
|
22
27
|
declared: declared;
|
|
23
28
|
inferred: inferDefinition<def, $, args>;
|
|
24
29
|
};
|
|
25
|
-
type Terminal = RegExp | type.cast<unknown> |
|
|
30
|
+
type Terminal = RegExp | type.cast<unknown> | Fn;
|
|
26
31
|
export type ThunkCast<t = unknown> = () => type.cast<t>;
|
|
27
32
|
type BadDefinitionType = Exclude<Primitive, string>;
|
|
28
33
|
export declare const writeBadDefinitionTypeMessage: <actual extends string>(actual: actual) => writeBadDefinitionTypeMessage<actual>;
|
package/out/parser/definition.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { hasArkKind } from "@
|
|
2
|
-
import { isThunk, objectKindOf, printable, throwParseError } from "@
|
|
1
|
+
import { hasArkKind } from "@ark/schema";
|
|
2
|
+
import { isThunk, objectKindOf, printable, throwParseError } from "@ark/util";
|
|
3
3
|
import { parseObjectLiteral } from "./objectLiteral.js";
|
|
4
4
|
import { parseTuple } from "./tuple.js";
|
|
5
5
|
export const parseObject = (def, ctx) => {
|
|
6
6
|
const objectKind = objectKindOf(def);
|
|
7
7
|
switch (objectKind) {
|
|
8
8
|
case undefined:
|
|
9
|
-
if (hasArkKind(def, "
|
|
9
|
+
if (hasArkKind(def, "root"))
|
|
10
10
|
return def;
|
|
11
11
|
return parseObjectLiteral(def, ctx);
|
|
12
12
|
case "Array":
|
|
@@ -14,11 +14,11 @@ export const parseObject = (def, ctx) => {
|
|
|
14
14
|
case "RegExp":
|
|
15
15
|
return ctx.$.node("intersection", {
|
|
16
16
|
domain: "string",
|
|
17
|
-
|
|
17
|
+
pattern: def
|
|
18
18
|
}, { prereduced: true });
|
|
19
19
|
case "Function": {
|
|
20
20
|
const resolvedDef = isThunk(def) ? def() : def;
|
|
21
|
-
if (hasArkKind(resolvedDef, "
|
|
21
|
+
if (hasArkKind(resolvedDef, "root"))
|
|
22
22
|
return resolvedDef;
|
|
23
23
|
return throwParseError(writeBadDefinitionTypeMessage("Function"));
|
|
24
24
|
}
|
|
@@ -1,64 +1,82 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { type Dict, type ErrorMessage, type Key, type merge, type show } from "@
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
import {
|
|
8
|
-
export declare const parseObjectLiteral: (def: Dict, ctx: ParseContext) =>
|
|
1
|
+
import { type BaseRoot, type Index, type Optional, type Required, type UndeclaredKeyBehavior, type writeInvalidPropertyKeyMessage } from "@ark/schema";
|
|
2
|
+
import { type anyOrNever, type conform, type Dict, type ErrorMessage, type ErrorType, type EscapeToken, type Key, type listable, type merge, type show } from "@ark/util";
|
|
3
|
+
import type { constrain, Default } from "../keywords/ast.ts";
|
|
4
|
+
import type { ParseContext } from "../scope.ts";
|
|
5
|
+
import type { inferDefinition, validateDefinition } from "./definition.ts";
|
|
6
|
+
import type { astToString } from "./semantic/utils.ts";
|
|
7
|
+
import type { validateString } from "./semantic/validate.ts";
|
|
8
|
+
export declare const parseObjectLiteral: (def: Dict, ctx: ParseContext) => BaseRoot;
|
|
9
|
+
export declare const writeInvalidUndeclaredBehaviorMessage: (actual: unknown) => string;
|
|
9
10
|
export declare const nonLeadingSpreadError = "Spread operator may only be used as the first key in an object";
|
|
11
|
+
export type inferObjectLiteral<def extends object, $, args> = show<"..." extends keyof def ? merge<inferDefinition<def["..."], $, args>, _inferObjectLiteral<def, $, args>> : _inferObjectLiteral<def, $, args>>;
|
|
10
12
|
/**
|
|
11
13
|
* Infers the contents of an object literal, ignoring a spread definition
|
|
12
|
-
* You probably want to use {@link inferObjectLiteral} instead.
|
|
13
14
|
*/
|
|
14
|
-
type
|
|
15
|
-
-readonly [k in keyof def as nonOptionalKeyFrom<k, $, args>]:
|
|
15
|
+
type _inferObjectLiteral<def extends object, $, args> = {
|
|
16
|
+
-readonly [k in keyof def as nonOptionalKeyFrom<k, $, args>]: def[k] extends (DefaultValueTuple<infer baseDef, infer defaultValue>) ? [
|
|
17
|
+
def[k]
|
|
18
|
+
] extends [anyOrNever] ? def[k] : (In?: inferDefinition<baseDef, $, args>) => Default<defaultValue> : inferDefinition<def[k], $, args>;
|
|
16
19
|
} & {
|
|
17
20
|
-readonly [k in keyof def as optionalKeyFrom<k>]?: inferDefinition<def[k], $, args>;
|
|
18
21
|
};
|
|
19
|
-
export type inferObjectLiteral<def extends object, $, args> = show<"..." extends keyof def ? merge<inferDefinition<def["..."], $, args>, inferObjectLiteralInner<def, $, args>> : inferObjectLiteralInner<def, $, args>>;
|
|
20
22
|
export type validateObjectLiteral<def, $, args> = {
|
|
21
|
-
[k in keyof def]: k extends IndexKey<infer indexDef> ? validateString<indexDef, $, args> extends ErrorMessage<infer message> ?
|
|
23
|
+
[k in keyof def]: k extends IndexKey<infer indexDef> ? validateString<indexDef, $, args> extends ErrorMessage<infer message> ? ErrorType<message> : inferDefinition<indexDef, $, args> extends Key | constrain<Key, {}> ? validateDefinition<def[k], $, args> : ErrorType<writeInvalidPropertyKeyMessage<indexDef>> : k extends "..." ? inferDefinition<def[k], $, args> extends object ? validateDefinition<def[k], $, args> : ErrorType<writeInvalidSpreadTypeMessage<astToString<def[k]>>> : k extends "+" ? UndeclaredKeyBehavior : validateDefaultableValue<def, k, $, args>;
|
|
22
24
|
};
|
|
23
|
-
type
|
|
25
|
+
type validateDefaultableValue<def, k extends keyof def, $, args> = def[k] extends DefaultValueTuple ? validateDefaultValueTuple<def[k], k, $, args> : validateDefinition<def[k], $, args>;
|
|
26
|
+
type DefaultValueTuple<baseDef = unknown, defaultValue = unknown> = readonly [
|
|
27
|
+
baseDef,
|
|
28
|
+
"=",
|
|
29
|
+
defaultValue
|
|
30
|
+
];
|
|
31
|
+
type validateDefaultValueTuple<def extends DefaultValueTuple, k extends PropertyKey, $, args> = parseKey<k>["kind"] extends "required" ? conform<def, readonly [
|
|
32
|
+
validateDefinition<def[0], $, args>,
|
|
33
|
+
"=",
|
|
34
|
+
inferDefinition<def[0], $, args>
|
|
35
|
+
]> : ErrorMessage<invalidDefaultKeyKindMessage>;
|
|
36
|
+
type nonOptionalKeyFrom<k, $, args> = parseKey<k> extends PreparsedKey<"required", infer inner> ? inner : parseKey<k> extends PreparsedKey<"index", infer inner> ? inferDefinition<inner, $, args> extends infer t extends Key ? t : never : never;
|
|
24
37
|
type optionalKeyFrom<k> = parseKey<k> extends PreparsedKey<"optional", infer inner> ? inner : never;
|
|
25
|
-
type PreparsedKey<kind extends ParsedKeyKind = ParsedKeyKind,
|
|
38
|
+
type PreparsedKey<kind extends ParsedKeyKind = ParsedKeyKind, key extends Key = Key> = {
|
|
26
39
|
kind: kind;
|
|
27
|
-
|
|
40
|
+
key: key;
|
|
28
41
|
};
|
|
29
42
|
declare namespace PreparsedKey {
|
|
30
43
|
type from<t extends PreparsedKey> = t;
|
|
31
44
|
}
|
|
32
|
-
type ParsedKeyKind = "required" | "optional" | "index" |
|
|
45
|
+
type ParsedKeyKind = "required" | "optional" | "index" | MetaKey;
|
|
46
|
+
export type MetaKey = "..." | "+";
|
|
33
47
|
export type IndexKey<def extends string = string> = `[${def}]`;
|
|
34
|
-
type
|
|
35
|
-
|
|
48
|
+
export type ParsedEntry = ParsedUndeclaredEntry | ParsedSpreadEntry | Required.Node | Optional.Node | Index.Node;
|
|
49
|
+
export type ParsedUndeclaredEntry = {
|
|
50
|
+
kind: "undeclared";
|
|
51
|
+
behavior: UndeclaredKeyBehavior;
|
|
36
52
|
};
|
|
37
|
-
export
|
|
38
|
-
|
|
39
|
-
|
|
53
|
+
export type ParsedSpreadEntry = {
|
|
54
|
+
kind: "spread";
|
|
55
|
+
node: BaseRoot;
|
|
56
|
+
};
|
|
57
|
+
export declare const parseEntry: (key: Key, value: unknown, ctx: ParseContext) => listable<ParsedEntry>;
|
|
58
|
+
export declare const invalidDefaultKeyKindMessage = "Only required keys may specify default values, e.g. { value: 'number = 0' }";
|
|
59
|
+
export type invalidDefaultKeyKindMessage = typeof invalidDefaultKeyKindMessage;
|
|
60
|
+
declare const parseKey: (key: Key) => PreparsedKey;
|
|
61
|
+
type parseKey<k> = k extends `${infer inner}?` ? inner extends `${infer baseName}${EscapeToken}` ? PreparsedKey.from<{
|
|
40
62
|
kind: "required";
|
|
41
|
-
|
|
63
|
+
key: `${baseName}?`;
|
|
42
64
|
}> : PreparsedKey.from<{
|
|
43
65
|
kind: "optional";
|
|
44
|
-
|
|
45
|
-
}> : k extends
|
|
46
|
-
kind:
|
|
47
|
-
|
|
48
|
-
}> : k extends `${
|
|
66
|
+
key: inner;
|
|
67
|
+
}> : k extends MetaKey ? PreparsedKey.from<{
|
|
68
|
+
kind: k;
|
|
69
|
+
key: k;
|
|
70
|
+
}> : k extends `${EscapeToken}${infer escapedMeta extends MetaKey}` ? PreparsedKey.from<{
|
|
49
71
|
kind: "required";
|
|
50
|
-
|
|
72
|
+
key: escapedMeta;
|
|
51
73
|
}> : k extends IndexKey<infer def> ? PreparsedKey.from<{
|
|
52
74
|
kind: "index";
|
|
53
|
-
|
|
75
|
+
key: def;
|
|
54
76
|
}> : PreparsedKey.from<{
|
|
55
77
|
kind: "required";
|
|
56
|
-
|
|
78
|
+
key: k extends `${EscapeToken}${infer escapedIndexKey extends IndexKey}` ? escapedIndexKey : k extends Key ? k : `${k & number}`;
|
|
57
79
|
}>;
|
|
58
|
-
declare const indexParseSymbol: unique symbol;
|
|
59
|
-
export type indexParseError<message extends string = string> = {
|
|
60
|
-
[indexParseSymbol]: message;
|
|
61
|
-
};
|
|
62
80
|
export declare const writeInvalidSpreadTypeMessage: <def extends string>(def: def) => writeInvalidSpreadTypeMessage<def>;
|
|
63
81
|
type writeInvalidSpreadTypeMessage<def extends string> = `Spread operand must resolve to an object literal type (was ${def})`;
|
|
64
82
|
export {};
|
|
@@ -1,75 +1,100 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { ArkErrors, normalizeIndex } from "@ark/schema";
|
|
2
|
+
import { append, escapeToken, isArray, printable, stringAndSymbolicEntriesOf, throwParseError } from "@ark/util";
|
|
3
|
+
import { writeUnassignableDefaultValueMessage } from "./semantic/default.js";
|
|
4
4
|
export const parseObjectLiteral = (def, ctx) => {
|
|
5
|
-
|
|
6
|
-
const
|
|
5
|
+
let spread;
|
|
6
|
+
const structure = {};
|
|
7
7
|
// We only allow a spread operator to be used as the first key in an object
|
|
8
8
|
// because to match JS behavior any keys before the spread are overwritten
|
|
9
9
|
// by the values in the target object, so there'd be no useful purpose in having it
|
|
10
10
|
// anywhere except for the beginning.
|
|
11
|
-
const parsedEntries = stringAndSymbolicEntriesOf(def).
|
|
11
|
+
const parsedEntries = stringAndSymbolicEntriesOf(def).flatMap(entry => parseEntry(entry[0], entry[1], ctx));
|
|
12
12
|
if (parsedEntries[0]?.kind === "spread") {
|
|
13
13
|
// remove the spread entry so we can iterate over the remaining entries
|
|
14
14
|
// expecting non-spread entries
|
|
15
15
|
const spreadEntry = parsedEntries.shift();
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return throwParseError(writeInvalidSpreadTypeMessage(printable(spreadEntry.value)));
|
|
16
|
+
if (!spreadEntry.node.hasKind("intersection") ||
|
|
17
|
+
!spreadEntry.node.structure) {
|
|
18
|
+
return throwParseError(writeInvalidSpreadTypeMessage(typeof spreadEntry.node.expression));
|
|
20
19
|
}
|
|
21
|
-
|
|
22
|
-
// For each key on spreadNode, add it to our object.
|
|
23
|
-
// We filter out keys from the spreadNode that will be defined later on this same object
|
|
24
|
-
// because the currently parsed definition will overwrite them.
|
|
25
|
-
spreadNode.prop?.forEach(spreadRequired => !parsedEntries.some(({ inner: innerKey }) => innerKey === spreadRequired.key) && propNodes.push(spreadRequired));
|
|
20
|
+
spread = spreadEntry.node.structure;
|
|
26
21
|
}
|
|
27
22
|
for (const entry of parsedEntries) {
|
|
28
23
|
if (entry.kind === "spread")
|
|
29
24
|
return throwParseError(nonLeadingSpreadError);
|
|
30
|
-
if (entry.kind === "
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const value = ctx.$.parse(entry.value, ctx);
|
|
34
|
-
// extract enumerable named props from the index signature
|
|
35
|
-
const [enumerable, nonEnumerable] = spliterate(key.branches, k => k.hasKind("unit"));
|
|
36
|
-
if (enumerable.length) {
|
|
37
|
-
propNodes.push(...enumerable.map(k => ctx.$.node("prop", { key: k.unit, value })));
|
|
38
|
-
if (nonEnumerable.length)
|
|
39
|
-
indexNodes.push(ctx.$.node("index", { key: nonEnumerable, value }));
|
|
40
|
-
}
|
|
41
|
-
else
|
|
42
|
-
indexNodes.push(ctx.$.node("index", { key, value }));
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
const value = ctx.$.parse(entry.value, ctx);
|
|
46
|
-
propNodes.push({
|
|
47
|
-
key: entry.inner,
|
|
48
|
-
value,
|
|
49
|
-
optional: entry.kind === "optional"
|
|
50
|
-
});
|
|
25
|
+
if (entry.kind === "undeclared") {
|
|
26
|
+
structure.undeclared = entry.behavior;
|
|
27
|
+
continue;
|
|
51
28
|
}
|
|
29
|
+
structure[entry.kind] = append(structure[entry.kind], entry);
|
|
52
30
|
}
|
|
53
|
-
|
|
31
|
+
const structureNode = ctx.$.node("structure", structure);
|
|
32
|
+
return ctx.$.rootNode({
|
|
54
33
|
domain: "object",
|
|
55
|
-
|
|
56
|
-
index: indexNodes
|
|
34
|
+
structure: spread?.merge(structureNode) ?? structureNode
|
|
57
35
|
});
|
|
58
36
|
};
|
|
37
|
+
export const writeInvalidUndeclaredBehaviorMessage = (actual) => `Value of '+' key must be 'reject', 'delete', or 'ignore' (was ${printable(actual)})`;
|
|
59
38
|
export const nonLeadingSpreadError = "Spread operator may only be used as the first key in an object";
|
|
60
|
-
export const parseEntry = (
|
|
61
|
-
const
|
|
39
|
+
export const parseEntry = (key, value, ctx) => {
|
|
40
|
+
const parsedKey = parseKey(key);
|
|
41
|
+
if (parsedKey.kind === "+") {
|
|
42
|
+
if (value !== "reject" && value !== "delete" && value !== "ignore")
|
|
43
|
+
throwParseError(writeInvalidUndeclaredBehaviorMessage(value));
|
|
44
|
+
return { kind: "undeclared", behavior: value };
|
|
45
|
+
}
|
|
46
|
+
if (parsedKey.kind === "...")
|
|
47
|
+
return { kind: "spread", node: ctx.$.parse(value, ctx) };
|
|
48
|
+
const parsedValue = isArray(value) && value[1] === "=" ?
|
|
49
|
+
[ctx.$.parse(value[0], ctx), "=", value[2]]
|
|
50
|
+
: ctx.$.parse(value, ctx, true);
|
|
51
|
+
if (isArray(parsedValue)) {
|
|
52
|
+
if (parsedKey.kind !== "required")
|
|
53
|
+
throwParseError(invalidDefaultKeyKindMessage);
|
|
54
|
+
const out = parsedValue[0].traverse(parsedValue[2]);
|
|
55
|
+
if (out instanceof ArkErrors) {
|
|
56
|
+
throwParseError(writeUnassignableDefaultValueMessage(printable(parsedKey.key), out.message));
|
|
57
|
+
}
|
|
58
|
+
return ctx.$.node("optional", {
|
|
59
|
+
key: parsedKey.key,
|
|
60
|
+
value: parsedValue[0],
|
|
61
|
+
default: parsedValue[2]
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
if (parsedKey.kind === "index") {
|
|
65
|
+
const signature = ctx.$.parse(parsedKey.key, ctx);
|
|
66
|
+
const normalized = normalizeIndex(signature, parsedValue, ctx.$);
|
|
67
|
+
return (normalized.index ?
|
|
68
|
+
normalized.required ?
|
|
69
|
+
[normalized.index, ...normalized.required]
|
|
70
|
+
: normalized.index
|
|
71
|
+
: (normalized.required ?? []));
|
|
72
|
+
}
|
|
73
|
+
return ctx.$.node(parsedKey.kind, {
|
|
74
|
+
key: parsedKey.key,
|
|
75
|
+
value: parsedValue
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
// single quote use here is better for TypeScript's inlined error to avoid escapes
|
|
79
|
+
export const invalidDefaultKeyKindMessage = `Only required keys may specify default values, e.g. { value: 'number = 0' }`;
|
|
80
|
+
const parseKey = (key) => typeof key === "symbol" ? { kind: "required", key }
|
|
62
81
|
: key.at(-1) === "?" ?
|
|
63
|
-
key.at(-2) ===
|
|
64
|
-
{
|
|
82
|
+
key.at(-2) === escapeToken ?
|
|
83
|
+
{ kind: "required", key: `${key.slice(0, -2)}?` }
|
|
65
84
|
: {
|
|
66
|
-
|
|
67
|
-
|
|
85
|
+
kind: "optional",
|
|
86
|
+
key: key.slice(0, -1)
|
|
68
87
|
}
|
|
69
88
|
: key[0] === "[" && key.at(-1) === "]" ?
|
|
70
|
-
{
|
|
71
|
-
: key[0] ===
|
|
72
|
-
{
|
|
73
|
-
: key === "..." ? {
|
|
74
|
-
:
|
|
89
|
+
{ kind: "index", key: key.slice(1, -1) }
|
|
90
|
+
: key[0] === escapeToken && key[1] === "[" && key.at(-1) === "]" ?
|
|
91
|
+
{ kind: "required", key: key.slice(1) }
|
|
92
|
+
: key === "..." ? { kind: key, key }
|
|
93
|
+
: key === "+" ? { kind: key, key }
|
|
94
|
+
: {
|
|
95
|
+
kind: "required",
|
|
96
|
+
key: key === "\\..." ? "..."
|
|
97
|
+
: key === "\\+" ? "+"
|
|
98
|
+
: key
|
|
99
|
+
};
|
|
75
100
|
export const writeInvalidSpreadTypeMessage = (def) => `Spread operand must resolve to an object literal type (was ${def})`;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { ErrorMessage, array } from "@
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
8
|
-
|
|
9
|
-
export type
|
|
1
|
+
import type { writeUnboundableMessage } from "@ark/schema";
|
|
2
|
+
import type { ErrorMessage, array, typeToString } from "@ark/util";
|
|
3
|
+
import type { LimitLiteral } from "../../keywords/ast.ts";
|
|
4
|
+
import type { Comparator } from "../string/reduce/shared.ts";
|
|
5
|
+
import type { BoundExpressionKind, writeInvalidLimitMessage } from "../string/shift/operator/bounds.ts";
|
|
6
|
+
import type { inferAstIn } from "./infer.ts";
|
|
7
|
+
import type { astToString } from "./utils.ts";
|
|
8
|
+
import type { validateAst } from "./validate.ts";
|
|
9
|
+
export type validateRange<l, comparator extends Comparator, r, $, args> = l extends LimitLiteral ? validateBound<r, comparator, l, "left", $, args> : l extends [infer leftAst, Comparator, unknown] ? ErrorMessage<writeDoubleRightBoundMessage<astToString<leftAst>>> : validateBound<l, comparator, r & LimitLiteral, "right", $, args>;
|
|
10
|
+
export type validateBound<boundedAst, comparator extends Comparator, limit extends LimitLiteral, boundKind extends BoundExpressionKind, $, args> = inferAstIn<boundedAst, $, args> extends infer bounded ? isNumericallyBoundable<bounded> extends true ? limit extends number ? validateAst<boundedAst, $, args> : ErrorMessage<writeInvalidLimitMessage<comparator, limit, boundKind>> : [bounded] extends [Date] ? validateAst<boundedAst, $, args> : ErrorMessage<writeUnboundableMessage<typeToString<bounded>>> : never;
|
|
10
11
|
type isNumericallyBoundable<bounded> = [
|
|
11
12
|
bounded
|
|
12
13
|
] extends [number] ? true : [bounded] extends [string] ? true : [bounded] extends [array] ? true : false;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ErrorMessage } from "@ark/util";
|
|
2
|
+
import type { UnitLiteral } from "../string/shift/operator/default.ts";
|
|
3
|
+
import type { inferAstOut, inferTerminal } from "./infer.ts";
|
|
4
|
+
import type { astToString } from "./utils.ts";
|
|
5
|
+
import type { validateAst } from "./validate.ts";
|
|
6
|
+
export type validateDefault<baseAst, unitLiteral extends UnitLiteral, $, args> = validateAst<baseAst, $, args> extends infer e extends ErrorMessage ? e : inferTerminal<unitLiteral, $, args> extends inferAstOut<baseAst, $, args> ? undefined : ErrorMessage<writeUnassignableDefaultValueMessage<astToString<baseAst>, unitLiteral>>;
|
|
7
|
+
export declare const writeUnassignableDefaultValueMessage: <key extends string, message extends string>(key: key, message: message) => string;
|
|
8
|
+
export type writeUnassignableDefaultValueMessage<baseDef extends string, defaultValue extends string> = `Default value ${defaultValue} is not assignable to ${baseDef}`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const writeUnassignableDefaultValueMessage = (key, message) => `Default value at ${key} ${message}`;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { ErrorMessage } from "@
|
|
3
|
-
import type { inferAstIn } from "./infer.
|
|
4
|
-
import type { validateAst } from "./validate.
|
|
1
|
+
import type { writeIndivisibleMessage } from "@ark/schema";
|
|
2
|
+
import type { ErrorMessage } from "@ark/util";
|
|
3
|
+
import type { inferAstIn } from "./infer.ts";
|
|
4
|
+
import type { validateAst } from "./validate.ts";
|
|
5
5
|
export type validateDivisor<l, $, args> = inferAstIn<l, $, args> extends infer data ? [
|
|
6
6
|
data
|
|
7
|
-
] extends [number] ? validateAst<l, $, args> : ErrorMessage<writeIndivisibleMessage<
|
|
7
|
+
] extends [number] ? validateAst<l, $, args> : ErrorMessage<writeIndivisibleMessage<data>> : never;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,17 +1,25 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { BigintLiteral, array } from "@
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
1
|
+
import type { GenericAst } from "@ark/schema";
|
|
2
|
+
import type { BigintLiteral, Hkt, array } from "@ark/util";
|
|
3
|
+
import type { ArkAmbient } from "../../config.ts";
|
|
4
|
+
import type { inferIntersection } from "../../intersect.ts";
|
|
5
|
+
import type { Date, DateLiteral, Default, LimitLiteral, RegexLiteral, applyConstraint, distillIn, distillOut, normalizeLimit } from "../../keywords/ast.ts";
|
|
6
|
+
import type { string } from "../../keywords/string/string.ts";
|
|
7
|
+
import type { UnparsedScope, resolve, tryInferSubmoduleReference } from "../../scope.ts";
|
|
8
|
+
import type { inferDefinition } from "../definition.ts";
|
|
9
|
+
import type { Comparator, MinComparator } from "../string/reduce/shared.ts";
|
|
10
|
+
import type { StringLiteral } from "../string/shift/operand/enclosed.ts";
|
|
7
11
|
export type inferAstRoot<ast, $, args> = inferConstrainableAst<ast, $, args>;
|
|
8
12
|
export type inferAstIn<ast, $, args> = distillIn<inferAstRoot<ast, $, args>>;
|
|
13
|
+
export type inferAstOut<ast, $, args> = distillOut<inferAstRoot<ast, $, args>>;
|
|
9
14
|
export type inferConstrainableAst<ast, $, args> = ast extends array ? inferExpression<ast, $, args> : ast extends string ? inferTerminal<ast, $, args> : never;
|
|
10
|
-
export type GenericInstantiationAst<generic extends
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
export type GenericInstantiationAst<generic extends GenericAst = GenericAst, argAsts extends unknown[] = unknown[]> = [generic, "<>", argAsts];
|
|
16
|
+
type resolveScope<g$, $> = g$ extends UnparsedScope ? $ : g$;
|
|
17
|
+
export type inferExpression<ast extends array, $, args> = ast extends GenericInstantiationAst<infer g, infer argAsts> ? g["bodyDef"] extends Hkt ? Hkt.apply<g["bodyDef"], {
|
|
18
|
+
[i in keyof argAsts]: inferConstrainableAst<argAsts[i], $, args>;
|
|
19
|
+
}> : inferDefinition<g["bodyDef"], resolveScope<g["$"], $>, {
|
|
20
|
+
[i in keyof g["names"] & `${number}` as g["names"][i]]: inferConstrainableAst<argAsts[i & keyof argAsts], resolveScope<g["arg$"], $>, args>;
|
|
21
|
+
}> : ast[1] extends "[]" ? inferConstrainableAst<ast[0], $, args>[] : ast[1] extends "|" ? inferConstrainableAst<ast[0], $, args> | inferConstrainableAst<ast[2], $, args> : ast[1] extends "&" ? inferIntersection<inferConstrainableAst<ast[0], $, args>, inferConstrainableAst<ast[2], $, args>> : ast[1] extends "=" ? inferTerminal<ast[2] & string, $, args> extends infer defaultValue ? (In?: inferConstrainableAst<ast[0], $, args>) => Default<defaultValue> : never : ast[1] extends Comparator ? ast[0] extends LimitLiteral ? constrainBound<inferConstrainableAst<ast[2], $, args>, ast[1], ast[0]> : constrainBound<inferConstrainableAst<ast[0], $, args>, ast[1], ast[2]> : ast[1] extends "%" ? applyConstraint<inferConstrainableAst<ast[0], $, args>, "divisor", ast[2] & number> : ast[0] extends "keyof" ? keyof inferConstrainableAst<ast[1], $, args> : never;
|
|
22
|
+
export type constrainBound<constrainableIn, comparator extends Comparator, limit> = distillIn<constrainableIn> extends infer In ? comparator extends "==" ? In extends number ? limit : In extends Date ? Date.literal<normalizeLimit<limit>> : applyConstraint<constrainableIn, "exactLength", limit & number> : applyConstraint<constrainableIn, In extends number ? comparator extends MinComparator ? "min" : "max" : In extends string | array ? comparator extends MinComparator ? "minLength" : "maxLength" : comparator extends MinComparator ? "after" : "before", {
|
|
15
23
|
rule: normalizeLimit<limit>;
|
|
16
24
|
exclusive: comparator extends ">" | "<" ? true : false;
|
|
17
25
|
}> : never;
|
|
@@ -21,4 +29,5 @@ export type PostfixOperator = "[]";
|
|
|
21
29
|
export type PostfixExpression<operator extends PostfixOperator = PostfixOperator, operand = unknown> = readonly [operand, operator];
|
|
22
30
|
export type InfixOperator = "|" | "&" | Comparator | "%" | ":" | "=>" | "@";
|
|
23
31
|
export type InfixExpression<operator extends InfixOperator = InfixOperator, l = unknown, r = unknown> = [l, operator, r];
|
|
24
|
-
export type inferTerminal<token extends string, $, args> = token extends keyof args | keyof $ ? resolve<token, $, args> : `#${token}` extends keyof $ ? resolve<`#${token}`, $, args> : token extends StringLiteral<infer text> ? text : token extends `${infer n extends number}` ? n : token extends BigintLiteral<infer b> ? b : token extends RegexLiteral<infer source> ? string.matching<source> : token extends DateLiteral<infer source> ? Date.literal<source> : tryInferSubmoduleReference<$, token>;
|
|
32
|
+
export type inferTerminal<token extends string, $, args> = token extends keyof args | keyof $ ? resolve<token, $, args> : token extends keyof ArkAmbient.$ ? resolve<token, ArkAmbient.$, args> : `#${token}` extends keyof $ ? resolve<`#${token}`, $, args> : token extends StringLiteral<infer text> ? text : token extends `${infer n extends number}` ? n : token extends BigintLiteral<infer b> ? b : token extends RegexLiteral<infer source> ? string.matching<source> : token extends DateLiteral<infer source> ? Date.literal<source> : tryInferSubmoduleReference<$, token>;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { writeNonStructuralOperandMessage } from "@ark/schema";
|
|
2
|
+
import type { ErrorMessage, typeToString } from "@ark/util";
|
|
3
|
+
import type { inferAstRoot } from "./infer.ts";
|
|
4
|
+
import type { validateAst } from "./validate.ts";
|
|
5
|
+
export type validateKeyof<operandAst, $, args> = inferAstRoot<operandAst, $, args> extends infer data ? [
|
|
6
|
+
data
|
|
7
|
+
] extends [object] ? validateAst<operandAst, $, args> : ErrorMessage<writeNonStructuralOperandMessage<"keyof", typeToString<data>>> : never;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Stringifiable } from "@
|
|
2
|
-
import type { Comparator } from "../string/reduce/shared.
|
|
3
|
-
import type { InfixExpression, PostfixExpression } from "./infer.
|
|
1
|
+
import type { Stringifiable } from "@ark/util";
|
|
2
|
+
import type { Comparator } from "../string/reduce/shared.ts";
|
|
3
|
+
import type { InfixExpression, PostfixExpression } from "./infer.ts";
|
|
4
4
|
export type astToString<ast> = ast extends PostfixExpression<infer operator, infer operand> ? operator extends "[]" ? `${astToString<operand>}[]` : never : ast extends InfixExpression<infer operator, infer l, infer r> ? operator extends "&" | "|" | "%" | Comparator ? `${astToString<l>} ${operator} ${astToString<r>}` : never : ast extends Stringifiable ? `${ast extends bigint ? `${ast}n` : ast}` : "...";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,25 +1,29 @@
|
|
|
1
|
-
import type { arkKind,
|
|
2
|
-
import type { BigintLiteral, charsAfterFirst, Completion, ErrorMessage,
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
8
|
-
import type {
|
|
9
|
-
import type {
|
|
10
|
-
|
|
1
|
+
import type { arkKind, GenericParamAst, PrivateDeclaration, writeMissingSubmoduleAccessMessage, writeUnsatisfiedParameterConstraintMessage } from "@ark/schema";
|
|
2
|
+
import type { anyOrNever, array, BigintLiteral, charsAfterFirst, Completion, ErrorMessage, typeToString, writeMalformedNumericLiteralMessage } from "@ark/util";
|
|
3
|
+
import type { Generic } from "../../generic.ts";
|
|
4
|
+
import type { Comparator } from "../string/reduce/shared.ts";
|
|
5
|
+
import type { writeInvalidGenericArgCountMessage } from "../string/shift/operand/genericArgs.ts";
|
|
6
|
+
import type { UnitLiteral } from "../string/shift/operator/default.ts";
|
|
7
|
+
import type { parseString } from "../string/string.ts";
|
|
8
|
+
import type { validateRange } from "./bounds.ts";
|
|
9
|
+
import type { validateDefault } from "./default.ts";
|
|
10
|
+
import type { validateDivisor } from "./divisor.ts";
|
|
11
|
+
import type { GenericInstantiationAst, inferAstRoot, InfixExpression, PostfixExpression } from "./infer.ts";
|
|
12
|
+
import type { validateKeyof } from "./keyof.ts";
|
|
13
|
+
import type { astToString } from "./utils.ts";
|
|
14
|
+
export type validateAst<ast, $, args> = ast extends string ? validateStringAst<ast, $> : ast extends PostfixExpression<infer operator, infer operand> ? operator extends "[]" ? validateAst<operand, $, args> : never : ast extends InfixExpression<infer operator, infer l, infer r> ? operator extends "&" | "|" ? validateInfix<ast, $, args> : operator extends Comparator ? validateRange<l, operator, r, $, args> : operator extends "%" ? validateDivisor<l, $, args> : undefined : ast extends [infer baseAst, "=", infer unitLiteral extends UnitLiteral] ? validateDefault<baseAst, unitLiteral, $, args> : ast extends ["keyof", infer operand] ? validateKeyof<operand, $, args> : ast extends GenericInstantiationAst<infer g, infer argAsts> ? validateGenericArgs<g["paramsAst"], argAsts, $, args, []> : ErrorMessage<writeUnexpectedExpressionMessage<astToString<ast>>> & {
|
|
11
15
|
ast: ast;
|
|
12
16
|
};
|
|
13
17
|
type writeUnexpectedExpressionMessage<expression extends string> = `Unexpectedly failed to parse the expression resulting from ${expression}`;
|
|
14
|
-
type validateGenericArgs<argAsts extends
|
|
15
|
-
export declare const
|
|
16
|
-
export type writeUnsatisfiableExpressionError<expression extends string> = `${expression} results in an unsatisfiable type`;
|
|
17
|
-
export declare const writePrefixedPrivateReferenceMessage: <def extends `#${string}`>(def: def) => writePrefixedPrivateReferenceMessage<def>;
|
|
18
|
+
type validateGenericArgs<params extends array<GenericParamAst>, argAsts extends array, $, args, indices extends 1[]> = argAsts extends readonly [infer arg, ...infer argsTail] ? validateAst<arg, $, args> extends infer e extends ErrorMessage ? e : inferAstRoot<arg, $, args> extends params[indices["length"]][1] ? validateGenericArgs<params, argsTail, $, args, [...indices, 1]> : ErrorMessage<writeUnsatisfiedParameterConstraintMessage<params[indices["length"]][0], typeToString<params[indices["length"]][1]>, astToString<arg>>> : undefined;
|
|
19
|
+
export declare const writePrefixedPrivateReferenceMessage: <def extends PrivateDeclaration>(def: def) => writePrefixedPrivateReferenceMessage<def>;
|
|
18
20
|
export type writePrefixedPrivateReferenceMessage<def extends PrivateDeclaration> = `Private type references should not include '#'. Use '${charsAfterFirst<def>}' instead.`;
|
|
19
|
-
type validateStringAst<def extends string, $> = def extends `${infer n extends number}` ? number extends n ? ErrorMessage<writeMalformedNumericLiteralMessage<def, "number">> : undefined : def extends BigintLiteral<infer b> ? bigint extends b ? ErrorMessage<writeMalformedNumericLiteralMessage<def, "bigint">> : undefined : maybeExtractAlias<def, $> extends infer alias extends keyof $ ?
|
|
21
|
+
type validateStringAst<def extends string, $> = def extends `${infer n extends number}` ? number extends n ? ErrorMessage<writeMalformedNumericLiteralMessage<def, "number">> : undefined : def extends BigintLiteral<infer b> ? bigint extends b ? ErrorMessage<writeMalformedNumericLiteralMessage<def, "bigint">> : undefined : maybeExtractAlias<def, $> extends infer alias extends keyof $ ? [
|
|
22
|
+
$[alias]
|
|
23
|
+
] extends [anyOrNever] ? def : def extends PrivateDeclaration ? ErrorMessage<writePrefixedPrivateReferenceMessage<def>> : $[alias] extends Generic ? ErrorMessage<writeInvalidGenericArgCountMessage<def, $[alias]["names"], []>> : $[alias] extends {
|
|
20
24
|
[arkKind]: "module";
|
|
21
|
-
} ? ErrorMessage<writeMissingSubmoduleAccessMessage<def>> : undefined : def extends ErrorMessage ? def : undefined;
|
|
25
|
+
} ? "$root" extends keyof $[alias] ? undefined : ErrorMessage<writeMissingSubmoduleAccessMessage<def>> : undefined : def extends ErrorMessage ? def : undefined;
|
|
22
26
|
export type maybeExtractAlias<def extends string, $> = def extends keyof $ ? def : `#${def}` extends keyof $ ? `#${def}` : null;
|
|
23
27
|
export type validateString<def extends string, $, args> = validateAst<parseString<def, $, args>, $, args> extends (infer result extends ErrorMessage) ? result extends Completion<infer text> ? text : result : def;
|
|
24
|
-
type validateInfix<ast extends InfixExpression, $, args> = validateAst<ast[0], $, args> extends
|
|
28
|
+
type validateInfix<ast extends InfixExpression, $, args> = validateAst<ast[0], $, args> extends infer e extends ErrorMessage ? e : validateAst<ast[2], $, args> extends infer e extends ErrorMessage ? e : undefined;
|
|
25
29
|
export {};
|