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/scope.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"scope.js","sourceRoot":"","sources":["../scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAON,cAAc,EAQd,UAAU,EAEV,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAEN,QAAQ,EACR,SAAS,EAET,OAAO,EAIP,eAAe,EACf,MAAM,eAAe,CAAA;AAEtB,OAA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D,OAAO,IAAI,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE,CAAU,CAAU,CAAA;YACrD,CAAC;YACD,wEAAwE;YACxE,0EAA0E;YAC1E,uDAAuD;YACvD,OAAO,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;QACzB,CAAC,EACD,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,qBAAqB,EAAE,CAC1C,CAAA;IACF,CAAC;CACD;AAoID,MAAM,CAAC,MAAM,IAAI,GAAoB,SAAkB,CAAA"}
|
package/parser/definition.ts
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { type RawSchema, hasArkKind, type string } from "@arktype/schema"
|
|
2
|
-
import {
|
|
3
|
-
type Dict,
|
|
4
|
-
type ErrorMessage,
|
|
5
|
-
type Primitive,
|
|
6
|
-
type array,
|
|
7
|
-
type defined,
|
|
8
|
-
type equals,
|
|
9
|
-
type isAny,
|
|
10
|
-
isThunk,
|
|
11
|
-
type isUnknown,
|
|
12
|
-
objectKindOf,
|
|
13
|
-
type objectKindOrDomainOf,
|
|
14
|
-
type optionalKeyOf,
|
|
15
|
-
printable,
|
|
16
|
-
type requiredKeyOf,
|
|
17
|
-
type show,
|
|
18
|
-
throwParseError
|
|
19
|
-
} from "@arktype/util"
|
|
20
|
-
import type { type } from "../ark.js"
|
|
21
|
-
import type { ParseContext } from "../scope.js"
|
|
22
|
-
import {
|
|
23
|
-
type inferObjectLiteral,
|
|
24
|
-
parseObjectLiteral,
|
|
25
|
-
type validateObjectLiteral
|
|
26
|
-
} from "./objectLiteral.js"
|
|
27
|
-
import type { validateString } from "./semantic/validate.js"
|
|
28
|
-
import type { BaseCompletions, inferString } from "./string/string.js"
|
|
29
|
-
import {
|
|
30
|
-
type TupleExpression,
|
|
31
|
-
type inferTuple,
|
|
32
|
-
parseTuple,
|
|
33
|
-
type validateTuple
|
|
34
|
-
} from "./tuple.js"
|
|
35
|
-
|
|
36
|
-
export const parseObject = (def: object, ctx: ParseContext): RawSchema => {
|
|
37
|
-
const objectKind = objectKindOf(def)
|
|
38
|
-
switch (objectKind) {
|
|
39
|
-
case undefined:
|
|
40
|
-
if (hasArkKind(def, "schema")) return def
|
|
41
|
-
return parseObjectLiteral(def as Dict, ctx)
|
|
42
|
-
case "Array":
|
|
43
|
-
return parseTuple(def as array, ctx)
|
|
44
|
-
case "RegExp":
|
|
45
|
-
return ctx.$.node(
|
|
46
|
-
"intersection",
|
|
47
|
-
{
|
|
48
|
-
domain: "string",
|
|
49
|
-
regex: def as RegExp
|
|
50
|
-
},
|
|
51
|
-
{ prereduced: true }
|
|
52
|
-
)
|
|
53
|
-
case "Function": {
|
|
54
|
-
const resolvedDef = isThunk(def) ? def() : def
|
|
55
|
-
if (hasArkKind(resolvedDef, "schema")) return resolvedDef
|
|
56
|
-
return throwParseError(writeBadDefinitionTypeMessage("Function"))
|
|
57
|
-
}
|
|
58
|
-
default:
|
|
59
|
-
return throwParseError(
|
|
60
|
-
writeBadDefinitionTypeMessage(objectKind ?? printable(def))
|
|
61
|
-
)
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export type inferDefinition<def, $, args> =
|
|
66
|
-
isAny<def> extends true ? never
|
|
67
|
-
: def extends type.cast<infer t> | ThunkCast<infer t> ? t
|
|
68
|
-
: def extends string ? inferString<def, $, args>
|
|
69
|
-
: def extends array ? inferTuple<def, $, args>
|
|
70
|
-
: def extends RegExp ? string.matching<string>
|
|
71
|
-
: def extends object ? inferObjectLiteral<def, $, args>
|
|
72
|
-
: never
|
|
73
|
-
|
|
74
|
-
export type validateDefinition<def, $, args> =
|
|
75
|
-
null extends undefined ?
|
|
76
|
-
ErrorMessage<`'strict' or 'strictNullChecks' must be set to true in your tsconfig's 'compilerOptions'`>
|
|
77
|
-
: [def] extends [Terminal] ? def
|
|
78
|
-
: def extends string ? validateString<def, $, args>
|
|
79
|
-
: def extends array ? validateTuple<def, $, args>
|
|
80
|
-
: def extends BadDefinitionType ?
|
|
81
|
-
writeBadDefinitionTypeMessage<objectKindOrDomainOf<def>>
|
|
82
|
-
: isUnknown<def> extends true ?
|
|
83
|
-
// this allows the initial list of autocompletions to be populated when a user writes "type()",
|
|
84
|
-
// before having specified a definition
|
|
85
|
-
BaseCompletions<$, args> | {}
|
|
86
|
-
: validateObjectLiteral<def, $, args>
|
|
87
|
-
|
|
88
|
-
export type validateDeclared<declared, def, $, args> =
|
|
89
|
-
def extends validateDefinition<def, $, args> ?
|
|
90
|
-
validateInference<def, declared, $, args>
|
|
91
|
-
: validateDefinition<def, $, args>
|
|
92
|
-
|
|
93
|
-
type validateInference<def, declared, $, args> =
|
|
94
|
-
def extends RegExp | type.cast<unknown> | ThunkCast | TupleExpression ?
|
|
95
|
-
validateShallowInference<def, declared, $, args>
|
|
96
|
-
: def extends array ?
|
|
97
|
-
declared extends array ?
|
|
98
|
-
{
|
|
99
|
-
[i in keyof declared]: i extends keyof def ?
|
|
100
|
-
validateInference<def[i], declared[i], $, args>
|
|
101
|
-
: unknown
|
|
102
|
-
}
|
|
103
|
-
: show<declarationMismatch<def, declared, $, args>>
|
|
104
|
-
: def extends object ?
|
|
105
|
-
show<
|
|
106
|
-
{
|
|
107
|
-
[k in requiredKeyOf<declared>]: k extends keyof def ?
|
|
108
|
-
validateInference<def[k], declared[k], $, args>
|
|
109
|
-
: unknown
|
|
110
|
-
} & {
|
|
111
|
-
[k in optionalKeyOf<declared> & string as `${k}?`]: `${k}?` extends (
|
|
112
|
-
keyof def
|
|
113
|
-
) ?
|
|
114
|
-
validateInference<def[`${k}?`], defined<declared[k]>, $, args>
|
|
115
|
-
: unknown
|
|
116
|
-
}
|
|
117
|
-
>
|
|
118
|
-
: validateShallowInference<def, declared, $, args>
|
|
119
|
-
|
|
120
|
-
type validateShallowInference<def, declared, $, args> =
|
|
121
|
-
equals<inferDefinition<def, $, args>, declared> extends true ? def
|
|
122
|
-
: show<declarationMismatch<def, declared, $, args>>
|
|
123
|
-
|
|
124
|
-
type declarationMismatch<def, declared, $, args> = {
|
|
125
|
-
declared: declared
|
|
126
|
-
inferred: inferDefinition<def, $, args>
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// functions are ignored in validation so that cyclic thunk definitions can be
|
|
130
|
-
// inferred in scopes
|
|
131
|
-
type Terminal = RegExp | type.cast<unknown> | ((...args: never[]) => unknown)
|
|
132
|
-
|
|
133
|
-
export type ThunkCast<t = unknown> = () => type.cast<t>
|
|
134
|
-
|
|
135
|
-
type BadDefinitionType = Exclude<Primitive, string>
|
|
136
|
-
|
|
137
|
-
export const writeBadDefinitionTypeMessage = <actual extends string>(
|
|
138
|
-
actual: actual
|
|
139
|
-
): writeBadDefinitionTypeMessage<actual> =>
|
|
140
|
-
`Type definitions must be strings or objects (was ${actual})`
|
|
141
|
-
|
|
142
|
-
type writeBadDefinitionTypeMessage<actual extends string> =
|
|
143
|
-
`Type definitions must be strings or objects (was ${actual})`
|
package/parser/generic.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { type keyError, throwParseError } from "@arktype/util"
|
|
2
|
-
import { writeUnexpectedCharacterMessage } from "./string/shift/operator/operator.js"
|
|
3
|
-
import { Scanner } from "./string/shift/scanner.js"
|
|
4
|
-
|
|
5
|
-
export type GenericDeclaration<
|
|
6
|
-
name extends string = string,
|
|
7
|
-
params extends string = string
|
|
8
|
-
> = `${name}<${params}>`
|
|
9
|
-
|
|
10
|
-
// we put the error in a tuple so that parseGenericParams always returns a string[]
|
|
11
|
-
export type GenericParamsParseError<message extends string = string> = [
|
|
12
|
-
keyError<message>
|
|
13
|
-
]
|
|
14
|
-
|
|
15
|
-
export const parseGenericParams = (def: string): string[] =>
|
|
16
|
-
_parseGenericParams(new Scanner(def))
|
|
17
|
-
|
|
18
|
-
export type parseGenericParams<def extends string> =
|
|
19
|
-
_parseParams<def, "", []> extends infer result extends string[] ?
|
|
20
|
-
"" extends result[number] ?
|
|
21
|
-
GenericParamsParseError<emptyGenericParameterMessage>
|
|
22
|
-
: result
|
|
23
|
-
: never
|
|
24
|
-
|
|
25
|
-
export const emptyGenericParameterMessage =
|
|
26
|
-
"An empty string is not a valid generic parameter name"
|
|
27
|
-
|
|
28
|
-
export type emptyGenericParameterMessage = typeof emptyGenericParameterMessage
|
|
29
|
-
|
|
30
|
-
const _parseGenericParams = (scanner: Scanner): string[] => {
|
|
31
|
-
const param = scanner.shiftUntilNextTerminator()
|
|
32
|
-
if (param === "") throwParseError(emptyGenericParameterMessage)
|
|
33
|
-
|
|
34
|
-
scanner.shiftUntilNonWhitespace()
|
|
35
|
-
const nextNonWhitespace = scanner.shift()
|
|
36
|
-
return (
|
|
37
|
-
nextNonWhitespace === "" ? [param]
|
|
38
|
-
: nextNonWhitespace === "," ? [param, ..._parseGenericParams(scanner)]
|
|
39
|
-
: throwParseError(writeUnexpectedCharacterMessage(nextNonWhitespace, ","))
|
|
40
|
-
)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
type _parseParams<
|
|
44
|
-
unscanned extends string,
|
|
45
|
-
param extends string,
|
|
46
|
-
result extends string[]
|
|
47
|
-
> =
|
|
48
|
-
unscanned extends `${infer lookahead}${infer nextUnscanned}` ?
|
|
49
|
-
lookahead extends "," ? _parseParams<nextUnscanned, "", [...result, param]>
|
|
50
|
-
: lookahead extends Scanner.WhiteSpaceToken ?
|
|
51
|
-
param extends "" ?
|
|
52
|
-
// if the next char is whitespace and we aren't in the middle of a param, skip to the next one
|
|
53
|
-
_parseParams<Scanner.skipWhitespace<nextUnscanned>, "", result>
|
|
54
|
-
: Scanner.skipWhitespace<nextUnscanned> extends (
|
|
55
|
-
`${infer nextNonWhitespace}${infer rest}`
|
|
56
|
-
) ?
|
|
57
|
-
nextNonWhitespace extends "," ?
|
|
58
|
-
_parseParams<rest, "", [...result, param]>
|
|
59
|
-
: GenericParamsParseError<
|
|
60
|
-
writeUnexpectedCharacterMessage<nextNonWhitespace, ",">
|
|
61
|
-
>
|
|
62
|
-
: // params end with a single whitespace character, add the current token
|
|
63
|
-
[...result, param]
|
|
64
|
-
: _parseParams<nextUnscanned, `${param}${lookahead}`, result>
|
|
65
|
-
: param extends "" ? result
|
|
66
|
-
: [...result, param]
|
package/parser/objectLiteral.ts
DELETED
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type NodeDef,
|
|
3
|
-
type RawSchema,
|
|
4
|
-
tsKeywords,
|
|
5
|
-
type writeInvalidPropertyKeyMessage
|
|
6
|
-
} from "@arktype/schema"
|
|
7
|
-
import {
|
|
8
|
-
type Dict,
|
|
9
|
-
type ErrorMessage,
|
|
10
|
-
type Key,
|
|
11
|
-
type merge,
|
|
12
|
-
printable,
|
|
13
|
-
type show,
|
|
14
|
-
spliterate,
|
|
15
|
-
stringAndSymbolicEntriesOf,
|
|
16
|
-
throwParseError
|
|
17
|
-
} from "@arktype/util"
|
|
18
|
-
import type { ParseContext } from "../scope.js"
|
|
19
|
-
import type { inferDefinition, validateDefinition } from "./definition.js"
|
|
20
|
-
import type { astToString } from "./semantic/utils.js"
|
|
21
|
-
import type { validateString } from "./semantic/validate.js"
|
|
22
|
-
import { Scanner } from "./string/shift/scanner.js"
|
|
23
|
-
|
|
24
|
-
export const parseObjectLiteral = (def: Dict, ctx: ParseContext): RawSchema => {
|
|
25
|
-
const propNodes: NodeDef<"prop">[] = []
|
|
26
|
-
const indexNodes: NodeDef<"index">[] = []
|
|
27
|
-
// We only allow a spread operator to be used as the first key in an object
|
|
28
|
-
// because to match JS behavior any keys before the spread are overwritten
|
|
29
|
-
// by the values in the target object, so there'd be no useful purpose in having it
|
|
30
|
-
// anywhere except for the beginning.
|
|
31
|
-
const parsedEntries = stringAndSymbolicEntriesOf(def).map(parseEntry)
|
|
32
|
-
if (parsedEntries[0]?.kind === "spread") {
|
|
33
|
-
// remove the spread entry so we can iterate over the remaining entries
|
|
34
|
-
// expecting non-spread entries
|
|
35
|
-
const spreadEntry = parsedEntries.shift()!
|
|
36
|
-
const spreadNode = ctx.$.parse(spreadEntry.value, ctx)
|
|
37
|
-
if (
|
|
38
|
-
!spreadNode.hasKind("intersection") ||
|
|
39
|
-
!spreadNode.extends(tsKeywords.object)
|
|
40
|
-
) {
|
|
41
|
-
return throwParseError(
|
|
42
|
-
writeInvalidSpreadTypeMessage(printable(spreadEntry.value))
|
|
43
|
-
)
|
|
44
|
-
}
|
|
45
|
-
// TODO: move to props group merge in schema
|
|
46
|
-
// For each key on spreadNode, add it to our object.
|
|
47
|
-
// We filter out keys from the spreadNode that will be defined later on this same object
|
|
48
|
-
// because the currently parsed definition will overwrite them.
|
|
49
|
-
spreadNode.prop?.forEach(
|
|
50
|
-
spreadRequired =>
|
|
51
|
-
!parsedEntries.some(
|
|
52
|
-
({ inner: innerKey }) => innerKey === spreadRequired.key
|
|
53
|
-
) && propNodes.push(spreadRequired)
|
|
54
|
-
)
|
|
55
|
-
}
|
|
56
|
-
for (const entry of parsedEntries) {
|
|
57
|
-
if (entry.kind === "spread") return throwParseError(nonLeadingSpreadError)
|
|
58
|
-
|
|
59
|
-
if (entry.kind === "index") {
|
|
60
|
-
// handle key parsing first to match type behavior
|
|
61
|
-
const key = ctx.$.parse(entry.inner, ctx)
|
|
62
|
-
const value = ctx.$.parse(entry.value, ctx)
|
|
63
|
-
|
|
64
|
-
// extract enumerable named props from the index signature
|
|
65
|
-
const [enumerable, nonEnumerable] = spliterate(key.branches, k =>
|
|
66
|
-
k.hasKind("unit")
|
|
67
|
-
)
|
|
68
|
-
|
|
69
|
-
if (enumerable.length) {
|
|
70
|
-
propNodes.push(
|
|
71
|
-
...enumerable.map(k =>
|
|
72
|
-
ctx.$.node("prop", { key: k.unit as Key, value })
|
|
73
|
-
)
|
|
74
|
-
)
|
|
75
|
-
if (nonEnumerable.length)
|
|
76
|
-
indexNodes.push(ctx.$.node("index", { key: nonEnumerable, value }))
|
|
77
|
-
} else indexNodes.push(ctx.$.node("index", { key, value }))
|
|
78
|
-
} else {
|
|
79
|
-
const value = ctx.$.parse(entry.value, ctx)
|
|
80
|
-
propNodes.push({
|
|
81
|
-
key: entry.inner,
|
|
82
|
-
value,
|
|
83
|
-
optional: entry.kind === "optional"
|
|
84
|
-
})
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return ctx.$.schema({
|
|
89
|
-
domain: "object",
|
|
90
|
-
prop: propNodes,
|
|
91
|
-
index: indexNodes
|
|
92
|
-
})
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export const nonLeadingSpreadError =
|
|
96
|
-
"Spread operator may only be used as the first key in an object"
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Infers the contents of an object literal, ignoring a spread definition
|
|
100
|
-
* You probably want to use {@link inferObjectLiteral} instead.
|
|
101
|
-
*/
|
|
102
|
-
type inferObjectLiteralInner<def extends object, $, args> = {
|
|
103
|
-
// since def is a const parameter, we remove the readonly modifier here
|
|
104
|
-
// support for builtin readonly tracked here:
|
|
105
|
-
// https://github.com/arktypeio/arktype/issues/808
|
|
106
|
-
-readonly [k in keyof def as nonOptionalKeyFrom<k, $, args>]: inferDefinition<
|
|
107
|
-
def[k],
|
|
108
|
-
$,
|
|
109
|
-
args
|
|
110
|
-
>
|
|
111
|
-
} & {
|
|
112
|
-
-readonly [k in keyof def as optionalKeyFrom<k>]?: inferDefinition<
|
|
113
|
-
def[k],
|
|
114
|
-
$,
|
|
115
|
-
args
|
|
116
|
-
>
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export type inferObjectLiteral<def extends object, $, args> = show<
|
|
120
|
-
"..." extends keyof def ?
|
|
121
|
-
merge<
|
|
122
|
-
inferDefinition<def["..."], $, args>,
|
|
123
|
-
inferObjectLiteralInner<def, $, args>
|
|
124
|
-
>
|
|
125
|
-
: inferObjectLiteralInner<def, $, args>
|
|
126
|
-
>
|
|
127
|
-
|
|
128
|
-
export type validateObjectLiteral<def, $, args> = {
|
|
129
|
-
[k in keyof def]: k extends IndexKey<infer indexDef> ?
|
|
130
|
-
validateString<indexDef, $, args> extends ErrorMessage<infer message> ?
|
|
131
|
-
// add a nominal type here to avoid allowing the error message as input
|
|
132
|
-
indexParseError<message>
|
|
133
|
-
: inferDefinition<indexDef, $, args> extends PropertyKey ?
|
|
134
|
-
// if the indexDef is syntactically and semantically valid,
|
|
135
|
-
// move on to the validating the value definition
|
|
136
|
-
validateDefinition<def[k], $, args>
|
|
137
|
-
: indexParseError<writeInvalidPropertyKeyMessage<indexDef>>
|
|
138
|
-
: k extends "..." ?
|
|
139
|
-
inferDefinition<def[k], $, args> extends object ?
|
|
140
|
-
validateDefinition<def[k], $, args>
|
|
141
|
-
: indexParseError<writeInvalidSpreadTypeMessage<astToString<def[k]>>>
|
|
142
|
-
: validateDefinition<def[k], $, args>
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
type nonOptionalKeyFrom<k, $, args> =
|
|
146
|
-
parseKey<k> extends PreparsedKey<"required", infer inner> ? inner
|
|
147
|
-
: parseKey<k> extends PreparsedKey<"index", infer inner> ?
|
|
148
|
-
inferDefinition<inner, $, args> & Key
|
|
149
|
-
: // spread key is handled at the type root so is handled neither here nor in optionalKeyFrom
|
|
150
|
-
never
|
|
151
|
-
|
|
152
|
-
type optionalKeyFrom<k> =
|
|
153
|
-
parseKey<k> extends PreparsedKey<"optional", infer inner> ? inner : never
|
|
154
|
-
|
|
155
|
-
type PreparsedKey<
|
|
156
|
-
kind extends ParsedKeyKind = ParsedKeyKind,
|
|
157
|
-
inner extends Key = Key
|
|
158
|
-
> = {
|
|
159
|
-
kind: kind
|
|
160
|
-
inner: inner
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
namespace PreparsedKey {
|
|
164
|
-
export type from<t extends PreparsedKey> = t
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
type ParsedKeyKind = "required" | "optional" | "index" | "spread"
|
|
168
|
-
|
|
169
|
-
export type IndexKey<def extends string = string> = `[${def}]`
|
|
170
|
-
|
|
171
|
-
type PreparsedEntry = PreparsedKey & { value: unknown }
|
|
172
|
-
|
|
173
|
-
export const parseEntry = (entry: readonly [Key, unknown]): PreparsedEntry =>
|
|
174
|
-
Object.assign(parseKey(entry[0]), { value: entry[1] })
|
|
175
|
-
|
|
176
|
-
const parseKey = (key: Key): PreparsedKey =>
|
|
177
|
-
typeof key === "symbol" ? { inner: key, kind: "required" }
|
|
178
|
-
: key.at(-1) === "?" ?
|
|
179
|
-
key.at(-2) === Scanner.escapeToken ?
|
|
180
|
-
{ inner: `${key.slice(0, -2)}?`, kind: "required" }
|
|
181
|
-
: {
|
|
182
|
-
inner: key.slice(0, -1),
|
|
183
|
-
kind: "optional"
|
|
184
|
-
}
|
|
185
|
-
: key[0] === "[" && key.at(-1) === "]" ?
|
|
186
|
-
{ inner: key.slice(1, -1), kind: "index" }
|
|
187
|
-
: key[0] === Scanner.escapeToken && key[1] === "[" && key.at(-1) === "]" ?
|
|
188
|
-
{ inner: key.slice(1), kind: "required" }
|
|
189
|
-
: key === "..." ? { inner: "...", kind: "spread" }
|
|
190
|
-
: { inner: key === "\\..." ? "..." : key, kind: "required" }
|
|
191
|
-
|
|
192
|
-
type parseKey<k> =
|
|
193
|
-
k extends `${infer inner}?` ?
|
|
194
|
-
inner extends `${infer baseName}${Scanner.EscapeToken}` ?
|
|
195
|
-
PreparsedKey.from<{
|
|
196
|
-
kind: "required"
|
|
197
|
-
inner: `${baseName}?`
|
|
198
|
-
}>
|
|
199
|
-
: PreparsedKey.from<{
|
|
200
|
-
kind: "optional"
|
|
201
|
-
inner: inner
|
|
202
|
-
}>
|
|
203
|
-
: k extends "..." ? PreparsedKey.from<{ kind: "spread"; inner: "..." }>
|
|
204
|
-
: k extends `${Scanner.EscapeToken}...` ?
|
|
205
|
-
PreparsedKey.from<{ kind: "required"; inner: "..." }>
|
|
206
|
-
: k extends IndexKey<infer def> ?
|
|
207
|
-
PreparsedKey.from<{
|
|
208
|
-
kind: "index"
|
|
209
|
-
inner: def
|
|
210
|
-
}>
|
|
211
|
-
: PreparsedKey.from<{
|
|
212
|
-
kind: "required"
|
|
213
|
-
inner: k extends (
|
|
214
|
-
`${Scanner.EscapeToken}${infer escapedIndexKey extends IndexKey}`
|
|
215
|
-
) ?
|
|
216
|
-
escapedIndexKey
|
|
217
|
-
: k extends Key ? k
|
|
218
|
-
: `${k & number}`
|
|
219
|
-
}>
|
|
220
|
-
|
|
221
|
-
declare const indexParseSymbol: unique symbol
|
|
222
|
-
|
|
223
|
-
export type indexParseError<message extends string = string> = {
|
|
224
|
-
[indexParseSymbol]: message
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
export const writeInvalidSpreadTypeMessage = <def extends string>(
|
|
228
|
-
def: def
|
|
229
|
-
): writeInvalidSpreadTypeMessage<def> =>
|
|
230
|
-
`Spread operand must resolve to an object literal type (was ${def})`
|
|
231
|
-
|
|
232
|
-
type writeInvalidSpreadTypeMessage<def extends string> =
|
|
233
|
-
`Spread operand must resolve to an object literal type (was ${def})`
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import type { LimitLiteral, writeUnboundableMessage } from "@arktype/schema"
|
|
2
|
-
import type { ErrorMessage, array } from "@arktype/util"
|
|
3
|
-
import type {
|
|
4
|
-
Comparator,
|
|
5
|
-
InvertedComparators
|
|
6
|
-
} from "../string/reduce/shared.js"
|
|
7
|
-
import type {
|
|
8
|
-
BoundExpressionKind,
|
|
9
|
-
writeInvalidLimitMessage
|
|
10
|
-
} from "../string/shift/operator/bounds.js"
|
|
11
|
-
import type { inferAstIn } from "./infer.js"
|
|
12
|
-
import type { astToString } from "./utils.js"
|
|
13
|
-
import type { validateAst } from "./validate.js"
|
|
14
|
-
|
|
15
|
-
export type validateRange<l, comparator extends Comparator, r, $, args> =
|
|
16
|
-
l extends LimitLiteral ?
|
|
17
|
-
validateBound<r, InvertedComparators[comparator], l, "left", $, args>
|
|
18
|
-
: l extends [infer leftAst, Comparator, unknown] ?
|
|
19
|
-
ErrorMessage<writeDoubleRightBoundMessage<astToString<leftAst>>>
|
|
20
|
-
: validateBound<l, comparator, r & LimitLiteral, "right", $, args>
|
|
21
|
-
|
|
22
|
-
export type validateBound<
|
|
23
|
-
boundedAst,
|
|
24
|
-
comparator extends Comparator,
|
|
25
|
-
limit extends LimitLiteral,
|
|
26
|
-
boundKind extends BoundExpressionKind,
|
|
27
|
-
$,
|
|
28
|
-
args
|
|
29
|
-
> =
|
|
30
|
-
inferAstIn<boundedAst, $, args> extends infer bounded ?
|
|
31
|
-
isNumericallyBoundable<bounded> extends true ?
|
|
32
|
-
limit extends number ?
|
|
33
|
-
validateAst<boundedAst, $, args>
|
|
34
|
-
: ErrorMessage<writeInvalidLimitMessage<comparator, limit, boundKind>>
|
|
35
|
-
: bounded extends Date ?
|
|
36
|
-
// allow numeric or date literal as a Date limit
|
|
37
|
-
validateAst<boundedAst, $, args>
|
|
38
|
-
: ErrorMessage<
|
|
39
|
-
writeUnboundableMessage<
|
|
40
|
-
astToString<
|
|
41
|
-
boundKind extends "left" ? boundedAst[0 & keyof boundedAst]
|
|
42
|
-
: boundedAst
|
|
43
|
-
>
|
|
44
|
-
>
|
|
45
|
-
>
|
|
46
|
-
: never
|
|
47
|
-
|
|
48
|
-
// Check each numerically boundable type individually so an expression comprised
|
|
49
|
-
// of mixed bound kinds like (string|number)<5 isn't allowed
|
|
50
|
-
type isNumericallyBoundable<bounded> =
|
|
51
|
-
[bounded] extends [number] ? true
|
|
52
|
-
: [bounded] extends [string] ? true
|
|
53
|
-
: [bounded] extends [array] ? true
|
|
54
|
-
: false
|
|
55
|
-
|
|
56
|
-
export const writeDoubleRightBoundMessage = <root extends string>(
|
|
57
|
-
root: root
|
|
58
|
-
): writeDoubleRightBoundMessage<root> =>
|
|
59
|
-
`Expression ${root} must have at most one right bound`
|
|
60
|
-
|
|
61
|
-
type writeDoubleRightBoundMessage<root extends string> =
|
|
62
|
-
`Expression ${root} must have at most one right bound`
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Schema, writeIndivisibleMessage } from "@arktype/schema"
|
|
2
|
-
import type { ErrorMessage } from "@arktype/util"
|
|
3
|
-
import type { inferAstIn } from "./infer.js"
|
|
4
|
-
import type { validateAst } from "./validate.js"
|
|
5
|
-
|
|
6
|
-
export type validateDivisor<l, $, args> =
|
|
7
|
-
inferAstIn<l, $, args> extends infer data ?
|
|
8
|
-
[data] extends [number] ?
|
|
9
|
-
validateAst<l, $, args>
|
|
10
|
-
: ErrorMessage<writeIndivisibleMessage<Schema<data>>>
|
|
11
|
-
: never
|
package/parser/semantic/infer.ts
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Date,
|
|
3
|
-
DateLiteral,
|
|
4
|
-
GenericProps,
|
|
5
|
-
LimitLiteral,
|
|
6
|
-
RegexLiteral,
|
|
7
|
-
constrain,
|
|
8
|
-
distillIn,
|
|
9
|
-
inferIntersection,
|
|
10
|
-
normalizeLimit,
|
|
11
|
-
string
|
|
12
|
-
} from "@arktype/schema"
|
|
13
|
-
import type { BigintLiteral, array } from "@arktype/util"
|
|
14
|
-
import type {
|
|
15
|
-
UnparsedScope,
|
|
16
|
-
resolve,
|
|
17
|
-
tryInferSubmoduleReference
|
|
18
|
-
} from "../../scope.js"
|
|
19
|
-
import type { inferDefinition } from "../definition.js"
|
|
20
|
-
import type { Comparator, MinComparator } from "../string/reduce/shared.js"
|
|
21
|
-
import type { StringLiteral } from "../string/shift/operand/enclosed.js"
|
|
22
|
-
|
|
23
|
-
export type inferAstRoot<ast, $, args> = inferConstrainableAst<ast, $, args>
|
|
24
|
-
|
|
25
|
-
export type inferAstIn<ast, $, args> = distillIn<inferAstRoot<ast, $, args>>
|
|
26
|
-
|
|
27
|
-
export type inferConstrainableAst<ast, $, args> =
|
|
28
|
-
ast extends array ? inferExpression<ast, $, args>
|
|
29
|
-
: ast extends string ? inferTerminal<ast, $, args>
|
|
30
|
-
: never
|
|
31
|
-
|
|
32
|
-
export type GenericInstantiationAst<
|
|
33
|
-
generic extends GenericProps = GenericProps,
|
|
34
|
-
argAsts extends unknown[] = unknown[]
|
|
35
|
-
> = [generic, "<>", argAsts]
|
|
36
|
-
|
|
37
|
-
export type inferExpression<ast extends array, $, args> =
|
|
38
|
-
ast extends GenericInstantiationAst<infer generic, infer argAsts> ?
|
|
39
|
-
inferDefinition<
|
|
40
|
-
generic["def"],
|
|
41
|
-
generic["$"]["$"] extends UnparsedScope ?
|
|
42
|
-
// If the generic was defined in the current scope, its definition can be
|
|
43
|
-
// resolved using the same scope as that of the input args.
|
|
44
|
-
$
|
|
45
|
-
: // Otherwise, use the scope that was explicitly associated with it.
|
|
46
|
-
generic["$"]["$"],
|
|
47
|
-
{
|
|
48
|
-
// Using keyof g["params"] & number here results in the element types
|
|
49
|
-
// being mixed- another reason TS should not have separate `${number}` and number keys!
|
|
50
|
-
[i in keyof generic["params"] &
|
|
51
|
-
`${number}` as generic["params"][i]]: inferConstrainableAst<
|
|
52
|
-
argAsts[i & keyof argAsts],
|
|
53
|
-
$,
|
|
54
|
-
args
|
|
55
|
-
>
|
|
56
|
-
}
|
|
57
|
-
>
|
|
58
|
-
: ast[1] extends "[]" ? inferConstrainableAst<ast[0], $, args>[]
|
|
59
|
-
: ast[1] extends "|" ?
|
|
60
|
-
| inferConstrainableAst<ast[0], $, args>
|
|
61
|
-
| inferConstrainableAst<ast[2], $, args>
|
|
62
|
-
: ast[1] extends "&" ?
|
|
63
|
-
inferIntersection<
|
|
64
|
-
inferConstrainableAst<ast[0], $, args>,
|
|
65
|
-
inferConstrainableAst<ast[2], $, args>
|
|
66
|
-
>
|
|
67
|
-
: ast[1] extends Comparator ?
|
|
68
|
-
ast[0] extends LimitLiteral ?
|
|
69
|
-
constrainBound<inferConstrainableAst<ast[2], $, args>, ast[1], ast[0]>
|
|
70
|
-
: constrainBound<inferConstrainableAst<ast[0], $, args>, ast[1], ast[2]>
|
|
71
|
-
: ast[1] extends "%" ?
|
|
72
|
-
constrain<
|
|
73
|
-
inferConstrainableAst<ast[0], $, args>,
|
|
74
|
-
"divisor",
|
|
75
|
-
ast[2] & number
|
|
76
|
-
>
|
|
77
|
-
: ast[0] extends "keyof" ? keyof inferConstrainableAst<ast[1], $, args>
|
|
78
|
-
: never
|
|
79
|
-
|
|
80
|
-
export type constrainBound<
|
|
81
|
-
constrainableIn,
|
|
82
|
-
comparator extends Comparator,
|
|
83
|
-
limit
|
|
84
|
-
> =
|
|
85
|
-
distillIn<constrainableIn> extends infer In ?
|
|
86
|
-
comparator extends "==" ?
|
|
87
|
-
In extends number ? limit
|
|
88
|
-
: In extends Date ? Date.literal<normalizeLimit<limit>>
|
|
89
|
-
: constrain<constrainableIn, "exactLength", limit & number>
|
|
90
|
-
: constrain<
|
|
91
|
-
constrainableIn,
|
|
92
|
-
In extends number ?
|
|
93
|
-
comparator extends MinComparator ?
|
|
94
|
-
"min"
|
|
95
|
-
: "max"
|
|
96
|
-
: In extends string | array ?
|
|
97
|
-
comparator extends MinComparator ?
|
|
98
|
-
"minLength"
|
|
99
|
-
: "maxLength"
|
|
100
|
-
: comparator extends MinComparator ? "after"
|
|
101
|
-
: "before",
|
|
102
|
-
{
|
|
103
|
-
rule: normalizeLimit<limit>
|
|
104
|
-
exclusive: comparator extends ">" | "<" ? true : false
|
|
105
|
-
}
|
|
106
|
-
>
|
|
107
|
-
: never
|
|
108
|
-
|
|
109
|
-
export type PrefixOperator = "keyof" | "instanceof" | "===" | "node"
|
|
110
|
-
|
|
111
|
-
export type PrefixExpression<
|
|
112
|
-
operator extends PrefixOperator = PrefixOperator,
|
|
113
|
-
operand = unknown
|
|
114
|
-
> = [operator, operand]
|
|
115
|
-
|
|
116
|
-
export type PostfixOperator = "[]"
|
|
117
|
-
|
|
118
|
-
export type PostfixExpression<
|
|
119
|
-
operator extends PostfixOperator = PostfixOperator,
|
|
120
|
-
operand = unknown
|
|
121
|
-
> = readonly [operand, operator]
|
|
122
|
-
|
|
123
|
-
export type InfixOperator = "|" | "&" | Comparator | "%" | ":" | "=>" | "@"
|
|
124
|
-
|
|
125
|
-
export type InfixExpression<
|
|
126
|
-
operator extends InfixOperator = InfixOperator,
|
|
127
|
-
l = unknown,
|
|
128
|
-
r = unknown
|
|
129
|
-
> = [l, operator, r]
|
|
130
|
-
|
|
131
|
-
export type inferTerminal<token extends string, $, args> =
|
|
132
|
-
token extends keyof args | keyof $ ? resolve<token, $, args>
|
|
133
|
-
: `#${token}` extends keyof $ ? resolve<`#${token}`, $, args>
|
|
134
|
-
: token extends StringLiteral<infer text> ? text
|
|
135
|
-
: token extends `${infer n extends number}` ? n
|
|
136
|
-
: token extends BigintLiteral<infer b> ? b
|
|
137
|
-
: token extends RegexLiteral<infer source> ? string.matching<source>
|
|
138
|
-
: token extends DateLiteral<infer source> ? Date.literal<source>
|
|
139
|
-
: // doing this last allows us to infer never if it isn't valid rather than check
|
|
140
|
-
// if it's a valid submodule reference ahead of time
|
|
141
|
-
tryInferSubmoduleReference<$, token>
|
package/parser/semantic/utils.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Stringifiable } from "@arktype/util"
|
|
2
|
-
import type { Comparator } from "../string/reduce/shared.js"
|
|
3
|
-
import type { InfixExpression, PostfixExpression } from "./infer.js"
|
|
4
|
-
|
|
5
|
-
export type astToString<ast> =
|
|
6
|
-
ast extends PostfixExpression<infer operator, infer operand> ?
|
|
7
|
-
operator extends "[]" ?
|
|
8
|
-
`${astToString<operand>}[]`
|
|
9
|
-
: never
|
|
10
|
-
: ast extends InfixExpression<infer operator, infer l, infer r> ?
|
|
11
|
-
operator extends "&" | "|" | "%" | Comparator ?
|
|
12
|
-
`${astToString<l>} ${operator} ${astToString<r>}`
|
|
13
|
-
: never
|
|
14
|
-
: ast extends Stringifiable ? `${ast extends bigint ? `${ast}n` : ast}`
|
|
15
|
-
: "..."
|