arktype 2.0.0-dev.6 → 2.0.0-dev.8
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/__tests__/array.test.ts +23 -25
- package/__tests__/config.test.ts +8 -8
- package/__tests__/cyclic.test.ts +3 -3
- package/__tests__/examples.test.ts +3 -3
- package/__tests__/instanceof.test.ts +7 -7
- package/__tests__/intersection.test.ts +2 -2
- package/__tests__/keyTraversal.test.ts +15 -15
- package/__tests__/keywords.test.ts +50 -37
- package/__tests__/literal.test.ts +2 -2
- package/__tests__/match.bench.ts +6 -6
- package/__tests__/narrow.test.ts +17 -23
- package/__tests__/objectLiteral.test.ts +4 -4
- package/__tests__/operator.bench.ts +4 -4
- package/__tests__/{morph.test.ts → pipe.test.ts} +136 -75
- package/__tests__/scope.test.ts +5 -15
- package/__tests__/traverse.test.ts +36 -35
- package/__tests__/type.test.ts +8 -10
- package/ark.ts +14 -11
- package/generic.ts +8 -6
- package/main.ts +3 -3
- package/match.ts +59 -70
- package/out/ark.d.ts +4 -3
- package/out/ark.d.ts.map +1 -1
- package/out/ark.js +4 -4
- package/out/ark.js.map +1 -1
- package/out/generic.d.ts.map +1 -1
- package/out/generic.js +8 -6
- package/out/generic.js.map +1 -1
- package/out/main.d.ts +3 -3
- package/out/main.d.ts.map +1 -1
- package/out/main.js +3 -2
- package/out/main.js.map +1 -1
- package/out/match.d.ts.map +1 -1
- package/out/match.js +50 -56
- package/out/match.js.map +1 -1
- package/out/parser/generic.d.ts +3 -3
- package/out/parser/generic.d.ts.map +1 -1
- package/out/parser/generic.js +4 -5
- package/out/parser/generic.js.map +1 -1
- package/out/parser/objectLiteral.d.ts.map +1 -1
- package/out/parser/objectLiteral.js +2 -3
- package/out/parser/objectLiteral.js.map +1 -1
- package/out/parser/semantic/validate.d.ts +2 -2
- package/out/parser/semantic/validate.d.ts.map +1 -1
- package/out/parser/semantic/validate.js.map +1 -1
- package/out/parser/string/reduce/dynamic.d.ts.map +1 -1
- package/out/parser/string/reduce/dynamic.js +4 -8
- package/out/parser/string/reduce/dynamic.js.map +1 -1
- package/out/parser/string/shift/operand/date.js +2 -4
- package/out/parser/string/shift/operand/date.js.map +1 -1
- package/out/parser/string/shift/operand/enclosed.js +6 -8
- package/out/parser/string/shift/operand/enclosed.js.map +1 -1
- package/out/parser/string/shift/operand/genericArgs.d.ts +4 -4
- package/out/parser/string/shift/operand/genericArgs.js +4 -5
- package/out/parser/string/shift/operand/genericArgs.js.map +1 -1
- package/out/parser/string/shift/operand/unenclosed.d.ts +4 -4
- package/out/parser/string/shift/operand/unenclosed.d.ts.map +1 -1
- package/out/parser/string/shift/operand/unenclosed.js +5 -10
- package/out/parser/string/shift/operand/unenclosed.js.map +1 -1
- package/out/parser/string/shift/operator/bounds.d.ts.map +1 -1
- package/out/parser/string/shift/operator/bounds.js +4 -8
- package/out/parser/string/shift/operator/bounds.js.map +1 -1
- package/out/parser/string/shift/operator/divisor.d.ts.map +1 -1
- package/out/parser/string/shift/operator/divisor.js +1 -2
- package/out/parser/string/shift/operator/divisor.js.map +1 -1
- package/out/parser/string/shift/scanner.d.ts.map +1 -1
- package/out/parser/string/shift/scanner.js +2 -4
- package/out/parser/string/shift/scanner.js.map +1 -1
- package/out/parser/string/string.d.ts.map +1 -1
- package/out/parser/string/string.js +1 -2
- package/out/parser/string/string.js.map +1 -1
- package/out/parser/tuple.d.ts.map +1 -1
- package/out/parser/tuple.js +12 -15
- package/out/parser/tuple.js.map +1 -1
- package/out/scope.d.ts +9 -9
- package/out/scope.d.ts.map +1 -1
- package/out/scope.js +11 -33
- package/out/scope.js.map +1 -1
- package/out/type.d.ts +38 -18
- package/out/type.d.ts.map +1 -1
- package/out/type.js +32 -1
- package/out/type.js.map +1 -1
- package/package.json +3 -3
- package/parser/generic.ts +11 -12
- package/parser/objectLiteral.ts +2 -4
- package/parser/semantic/validate.ts +2 -3
- package/parser/string/reduce/dynamic.ts +7 -10
- package/parser/string/shift/operand/date.ts +3 -6
- package/parser/string/shift/operand/enclosed.ts +8 -8
- package/parser/string/shift/operand/genericArgs.ts +8 -8
- package/parser/string/shift/operand/unenclosed.ts +14 -23
- package/parser/string/shift/operator/bounds.ts +7 -9
- package/parser/string/shift/operator/divisor.ts +2 -3
- package/parser/string/shift/scanner.ts +2 -4
- package/parser/string/string.ts +2 -3
- package/parser/tuple.ts +15 -16
- package/scope.ts +24 -48
- package/type.ts +150 -35
package/parser/tuple.ts
CHANGED
|
@@ -53,34 +53,33 @@ export const parseTupleLiteral = (def: array, ctx: ParseContext): RawSchema => {
|
|
|
53
53
|
|
|
54
54
|
i++
|
|
55
55
|
if (def[i] === "?") {
|
|
56
|
-
if (spread)
|
|
57
|
-
|
|
58
|
-
}
|
|
56
|
+
if (spread) return throwParseError(spreadOptionalMessage)
|
|
57
|
+
|
|
59
58
|
optional = true
|
|
60
59
|
i++
|
|
61
60
|
}
|
|
62
61
|
if (spread) {
|
|
63
|
-
if (!element.extends(jsObjects.Array))
|
|
62
|
+
if (!element.extends(jsObjects.Array))
|
|
64
63
|
return throwParseError(writeNonArraySpreadMessage(element.expression))
|
|
65
|
-
|
|
64
|
+
|
|
66
65
|
// a spread must be distributed over branches e.g.:
|
|
67
66
|
// def: [string, ...(number[] | [true, false])]
|
|
68
67
|
// nodes: [string, ...number[]] | [string, true, false]
|
|
69
|
-
sequences = sequences.flatMap(
|
|
68
|
+
sequences = sequences.flatMap(base =>
|
|
70
69
|
// since appendElement mutates base, we have to shallow-ish clone it for each branch
|
|
71
|
-
element.branches.map(
|
|
70
|
+
element.branches.map(branch =>
|
|
72
71
|
appendSpreadBranch(makeRootAndArrayPropertiesMutable(base), branch)
|
|
73
72
|
)
|
|
74
73
|
)
|
|
75
74
|
} else {
|
|
76
|
-
sequences = sequences.map(
|
|
75
|
+
sequences = sequences.map(base =>
|
|
77
76
|
appendElement(base, optional ? "optional" : "required", element)
|
|
78
77
|
)
|
|
79
78
|
}
|
|
80
79
|
}
|
|
81
80
|
return ctx.$.raw.schema(
|
|
82
81
|
sequences.map(
|
|
83
|
-
|
|
82
|
+
sequence =>
|
|
84
83
|
({
|
|
85
84
|
proto: Array,
|
|
86
85
|
sequence
|
|
@@ -143,10 +142,10 @@ const appendSpreadBranch = (
|
|
|
143
142
|
// the only array with no sequence reference is unknown[]
|
|
144
143
|
return appendElement(base, "variadic", tsKeywords.unknown)
|
|
145
144
|
}
|
|
146
|
-
spread.prefix.forEach(
|
|
147
|
-
spread.optional.forEach(
|
|
145
|
+
spread.prefix.forEach(node => appendElement(base, "required", node))
|
|
146
|
+
spread.optional.forEach(node => appendElement(base, "optional", node))
|
|
148
147
|
spread.variadic && appendElement(base, "variadic", spread.variadic)
|
|
149
|
-
spread.postfix.forEach(
|
|
148
|
+
spread.postfix.forEach(node => appendElement(base, "required", node))
|
|
150
149
|
return base
|
|
151
150
|
}
|
|
152
151
|
|
|
@@ -414,9 +413,9 @@ export type inferKeyOfExpression<operandDef, $, args> = show<
|
|
|
414
413
|
>
|
|
415
414
|
|
|
416
415
|
const parseBranchTuple: PostfixParser<"|" | "&"> = (def, ctx) => {
|
|
417
|
-
if (def[2] === undefined)
|
|
416
|
+
if (def[2] === undefined)
|
|
418
417
|
return throwParseError(writeMissingRightOperandMessage(def[1], ""))
|
|
419
|
-
|
|
418
|
+
|
|
420
419
|
const l = ctx.$.parse(def[0], ctx)
|
|
421
420
|
const r = ctx.$.parse(def[2], ctx)
|
|
422
421
|
return def[1] === "&" ? l.and(r) : l.or(r)
|
|
@@ -459,7 +458,7 @@ export const parseMorphTuple: PostfixParser<"=>"> = (def, ctx) => {
|
|
|
459
458
|
)
|
|
460
459
|
}
|
|
461
460
|
// TODO: nested morphs?
|
|
462
|
-
return ctx.$.parse(def[0], ctx).
|
|
461
|
+
return ctx.$.parse(def[0], ctx).pipe(def[2] as Morph)
|
|
463
462
|
}
|
|
464
463
|
|
|
465
464
|
export const writeMalformedFunctionalExpressionMessage = (
|
|
@@ -518,7 +517,7 @@ const prefixParsers: {
|
|
|
518
517
|
}
|
|
519
518
|
const branches = def
|
|
520
519
|
.slice(1)
|
|
521
|
-
.map(
|
|
520
|
+
.map(ctor =>
|
|
522
521
|
typeof ctor === "function" ?
|
|
523
522
|
ctx.$.node("proto", { proto: ctor as Constructor })
|
|
524
523
|
: throwParseError(
|
package/scope.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type ArkConfig,
|
|
3
3
|
type GenericProps,
|
|
4
|
+
type NodeParseContext,
|
|
4
5
|
type NodeParseOptions,
|
|
5
6
|
type PreparsedNodeResolution,
|
|
6
7
|
type RawSchema,
|
|
@@ -18,6 +19,7 @@ import {
|
|
|
18
19
|
type Dict,
|
|
19
20
|
domainOf,
|
|
20
21
|
hasDomain,
|
|
22
|
+
type isAnyOrNever,
|
|
21
23
|
isThunk,
|
|
22
24
|
type nominal,
|
|
23
25
|
type show,
|
|
@@ -40,11 +42,12 @@ import {
|
|
|
40
42
|
} from "./parser/generic.js"
|
|
41
43
|
import { DynamicState } from "./parser/string/reduce/dynamic.js"
|
|
42
44
|
import { fullStringParse } from "./parser/string/string.js"
|
|
43
|
-
import
|
|
44
|
-
DeclarationParser,
|
|
45
|
-
DefinitionParser,
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
import {
|
|
46
|
+
type DeclarationParser,
|
|
47
|
+
type DefinitionParser,
|
|
48
|
+
RawTypeParser,
|
|
49
|
+
type Type,
|
|
50
|
+
type TypeParser
|
|
48
51
|
} from "./type.js"
|
|
49
52
|
|
|
50
53
|
export type ScopeParser = <const def>(
|
|
@@ -126,12 +129,9 @@ export type resolve<reference extends keyof $ | keyof args, $, args> =
|
|
|
126
129
|
args[reference]
|
|
127
130
|
: $[reference & keyof $]
|
|
128
131
|
) extends infer resolution ?
|
|
129
|
-
resolution extends
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
resolution
|
|
133
|
-
: inferDefinition<def, $, args>
|
|
134
|
-
: resolution
|
|
132
|
+
isAnyOrNever<resolution> extends true ? resolution
|
|
133
|
+
: resolution extends Def<infer def> ? inferDefinition<def, $, args>
|
|
134
|
+
: resolution
|
|
135
135
|
: never
|
|
136
136
|
|
|
137
137
|
export type moduleKeyOf<$> = {
|
|
@@ -148,7 +148,7 @@ export type tryInferSubmoduleReference<$, token> =
|
|
|
148
148
|
: never
|
|
149
149
|
: never
|
|
150
150
|
|
|
151
|
-
export interface ParseContext extends
|
|
151
|
+
export interface ParseContext extends NodeParseContext {
|
|
152
152
|
$: RawScope
|
|
153
153
|
}
|
|
154
154
|
|
|
@@ -191,65 +191,41 @@ export class RawScope<
|
|
|
191
191
|
super(aliases, config)
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
-
type
|
|
195
|
-
if (args.length === 1) {
|
|
196
|
-
// treat as a simple definition
|
|
197
|
-
return this.parseRoot(args[0])
|
|
198
|
-
}
|
|
199
|
-
if (
|
|
200
|
-
args.length === 2 &&
|
|
201
|
-
typeof args[0] === "string" &&
|
|
202
|
-
args[0][0] === "<" &&
|
|
203
|
-
args[0].at(-1) === ">"
|
|
204
|
-
) {
|
|
205
|
-
// if there are exactly two args, the first of which looks like <${string}>,
|
|
206
|
-
// treat as a generic
|
|
207
|
-
const params = parseGenericParams(args[0].slice(1, -1))
|
|
208
|
-
const def = args[1]
|
|
209
|
-
// TODO: validateUninstantiatedGeneric, remove this cast
|
|
210
|
-
return new Generic(params, def, this as never) as never
|
|
211
|
-
}
|
|
212
|
-
// otherwise, treat as a tuple expression. technically, this also allows
|
|
213
|
-
// non-expression tuple definitions to be parsed, but it's not a supported
|
|
214
|
-
// part of the API as specified by the associated types
|
|
215
|
-
return this.parseRoot(args)
|
|
216
|
-
}
|
|
194
|
+
type = new RawTypeParser(this as never)
|
|
217
195
|
|
|
218
196
|
match: MatchParser<$> = createMatchParser(this as never) as never
|
|
219
197
|
|
|
220
|
-
declare()
|
|
221
|
-
|
|
222
|
-
}
|
|
198
|
+
declare = (() => ({
|
|
199
|
+
type: this.type
|
|
200
|
+
})).bind(this)
|
|
223
201
|
|
|
224
|
-
define(def: unknown)
|
|
225
|
-
return def
|
|
226
|
-
}
|
|
202
|
+
define = ((def: unknown) => def).bind(this)
|
|
227
203
|
|
|
228
204
|
override preparseRoot(def: unknown): unknown {
|
|
229
|
-
if (isThunk(def) && !hasArkKind(def, "generic"))
|
|
230
|
-
|
|
231
|
-
}
|
|
205
|
+
if (isThunk(def) && !hasArkKind(def, "generic")) return def()
|
|
206
|
+
|
|
232
207
|
return def
|
|
233
208
|
}
|
|
234
209
|
|
|
235
210
|
override parseRoot(def: unknown, opts?: NodeParseOptions): RawSchema {
|
|
211
|
+
// args: { this: {} as RawSchema },
|
|
236
212
|
return this.parse(def, {
|
|
237
|
-
args: { this: {} as RawSchema },
|
|
238
213
|
$: this as never,
|
|
214
|
+
raw: def,
|
|
239
215
|
...opts
|
|
240
216
|
}).bindScope(this)
|
|
241
217
|
}
|
|
242
218
|
|
|
243
219
|
parse(def: unknown, ctx: ParseContext): RawSchema {
|
|
244
220
|
if (typeof def === "string") {
|
|
245
|
-
if (ctx.args && Object.keys(ctx.args).every(
|
|
221
|
+
if (ctx.args && Object.keys(ctx.args).every(k => !def.includes(k))) {
|
|
246
222
|
// we can only rely on the cache if there are no contextual
|
|
247
223
|
// resolutions like "this" or generic args
|
|
248
224
|
return this.parseString(def, ctx)
|
|
249
225
|
}
|
|
250
|
-
if (!this.parseCache[def])
|
|
226
|
+
if (!this.parseCache[def])
|
|
251
227
|
this.parseCache[def] = this.parseString(def, ctx)
|
|
252
|
-
|
|
228
|
+
|
|
253
229
|
return this.parseCache[def]
|
|
254
230
|
}
|
|
255
231
|
return hasDomain(def, "object") ?
|
package/type.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
+
ArkErrors,
|
|
2
3
|
type BaseMeta,
|
|
4
|
+
type BaseRoot,
|
|
5
|
+
type Disjoint,
|
|
3
6
|
type Morph,
|
|
4
7
|
type NodeDef,
|
|
5
8
|
type Out,
|
|
@@ -10,31 +13,40 @@ import {
|
|
|
10
13
|
type ambient,
|
|
11
14
|
type constrain,
|
|
12
15
|
type constraintKindOf,
|
|
13
|
-
type distillConstrainableIn,
|
|
14
16
|
type distillConstrainableOut,
|
|
15
17
|
type distillIn,
|
|
16
18
|
type distillOut,
|
|
17
19
|
type includesMorphs,
|
|
18
20
|
type inferIntersection,
|
|
19
21
|
type inferMorphOut,
|
|
20
|
-
type inferNarrow
|
|
22
|
+
type inferNarrow,
|
|
23
|
+
type inferPipes,
|
|
24
|
+
type internalImplementationOf
|
|
21
25
|
} from "@arktype/schema"
|
|
22
|
-
import
|
|
23
|
-
|
|
26
|
+
import {
|
|
27
|
+
Callable,
|
|
28
|
+
type Constructor,
|
|
29
|
+
type array,
|
|
30
|
+
type conform
|
|
31
|
+
} from "@arktype/util"
|
|
32
|
+
import { Generic, type validateParameterString } from "./generic.js"
|
|
24
33
|
import type {
|
|
25
34
|
inferDefinition,
|
|
26
35
|
validateDeclared,
|
|
27
36
|
validateDefinition
|
|
28
37
|
} from "./parser/definition.js"
|
|
29
|
-
import
|
|
38
|
+
import { parseGenericParams } from "./parser/generic.js"
|
|
30
39
|
import type {
|
|
31
40
|
IndexOneOperator,
|
|
32
41
|
IndexZeroOperator,
|
|
33
42
|
TupleInfixOperator
|
|
34
43
|
} from "./parser/tuple.js"
|
|
35
|
-
import type { Scope, bindThis } from "./scope.js"
|
|
44
|
+
import type { RawScope, Scope, bindThis } from "./scope.js"
|
|
45
|
+
export interface TypeParserAttachments {
|
|
46
|
+
errors: typeof ArkErrors
|
|
47
|
+
}
|
|
36
48
|
|
|
37
|
-
export
|
|
49
|
+
export interface TypeParser<$> extends TypeParserAttachments {
|
|
38
50
|
// Parse and check the definition, returning either the original input for a
|
|
39
51
|
// valid definition or a string representing an error message.
|
|
40
52
|
<const def>(def: validateTypeRoot<def, $>): Type<inferTypeRoot<def, $>, $>
|
|
@@ -68,6 +80,44 @@ export type TypeParser<$> = {
|
|
|
68
80
|
): Generic<parseGenericParams<params>, def, $>
|
|
69
81
|
}
|
|
70
82
|
|
|
83
|
+
const typeParserAttachments = Object.freeze({
|
|
84
|
+
errors: ArkErrors
|
|
85
|
+
} satisfies TypeParserAttachments)
|
|
86
|
+
|
|
87
|
+
export class RawTypeParser extends Callable<
|
|
88
|
+
(...args: unknown[]) => RawSchema | Generic,
|
|
89
|
+
TypeParserAttachments
|
|
90
|
+
> {
|
|
91
|
+
constructor($: RawScope) {
|
|
92
|
+
super(
|
|
93
|
+
(...args) => {
|
|
94
|
+
if (args.length === 1) {
|
|
95
|
+
// treat as a simple definition
|
|
96
|
+
return $.parseRoot(args[0])
|
|
97
|
+
}
|
|
98
|
+
if (
|
|
99
|
+
args.length === 2 &&
|
|
100
|
+
typeof args[0] === "string" &&
|
|
101
|
+
args[0][0] === "<" &&
|
|
102
|
+
args[0].at(-1) === ">"
|
|
103
|
+
) {
|
|
104
|
+
// if there are exactly two args, the first of which looks like <${string}>,
|
|
105
|
+
// treat as a generic
|
|
106
|
+
const params = parseGenericParams(args[0].slice(1, -1))
|
|
107
|
+
const def = args[1]
|
|
108
|
+
// TODO: validateUninstantiatedGeneric, remove this cast
|
|
109
|
+
return new Generic(params, def, $ as never) as never
|
|
110
|
+
}
|
|
111
|
+
// otherwise, treat as a tuple expression. technically, this also allows
|
|
112
|
+
// non-expression tuple definitions to be parsed, but it's not a supported
|
|
113
|
+
// part of the API as specified by the associated types
|
|
114
|
+
return $.parseRoot(args)
|
|
115
|
+
},
|
|
116
|
+
{ bind: $, attach: typeParserAttachments }
|
|
117
|
+
)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
71
121
|
export type DeclarationParser<$> = <preinferred>() => {
|
|
72
122
|
// for some reason, making this a const parameter breaks preinferred validation
|
|
73
123
|
type: <def>(
|
|
@@ -75,59 +125,124 @@ export type DeclarationParser<$> = <preinferred>() => {
|
|
|
75
125
|
) => Type<preinferred, $>
|
|
76
126
|
}
|
|
77
127
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
128
|
+
// this is declared as a class internally so we can ensure all "abstract"
|
|
129
|
+
// methods of BaseRoot are overridden, but we end up exporting it as an interface
|
|
130
|
+
// to ensure it is not accessed as a runtime value
|
|
131
|
+
declare class _Type<t = unknown, $ = any>
|
|
132
|
+
extends BaseRoot<t, $>
|
|
133
|
+
implements internalImplementationOf<Schema>
|
|
134
|
+
{
|
|
135
|
+
$: Scope<$>;
|
|
136
|
+
|
|
137
|
+
get in(): Type<this["tIn"], $>
|
|
138
|
+
get out(): Type<this["tOut"], $>
|
|
139
|
+
|
|
140
|
+
intersect<def>(
|
|
84
141
|
def: validateTypeRoot<def, $>
|
|
85
|
-
)
|
|
86
|
-
Schema<t, $>["and"]
|
|
142
|
+
): Type<inferIntersection<t, inferTypeRoot<def, $>>> | Disjoint
|
|
87
143
|
|
|
88
|
-
|
|
144
|
+
and<def>(
|
|
89
145
|
def: validateTypeRoot<def, $>
|
|
90
|
-
)
|
|
91
|
-
Schema<t, $>["or"]
|
|
146
|
+
): Type<inferIntersection<t, inferTypeRoot<def, $>>, $>
|
|
92
147
|
|
|
93
|
-
|
|
94
|
-
get out(): Type<distillConstrainableOut<t>, $>
|
|
148
|
+
or<def>(def: validateTypeRoot<def, $>): Type<t | inferTypeRoot<def, $>, $>
|
|
95
149
|
|
|
96
150
|
array(): Type<t[], $>
|
|
97
151
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
>)
|
|
110
|
-
|
|
152
|
+
keyof(): Type<keyof this["inferIn"], $>
|
|
153
|
+
|
|
154
|
+
pipe<a extends Morph<this["infer"]>>(a: a): Type<inferPipes<t, [a]>, $>
|
|
155
|
+
pipe<a extends Morph<this["infer"]>, b extends Morph<inferMorphOut<a>>>(
|
|
156
|
+
a: a,
|
|
157
|
+
b: b
|
|
158
|
+
): Type<inferPipes<t, [a, b]>, $>
|
|
159
|
+
pipe<
|
|
160
|
+
a extends Morph<this["infer"]>,
|
|
161
|
+
b extends Morph<inferMorphOut<a>>,
|
|
162
|
+
c extends Morph<inferMorphOut<b>>
|
|
163
|
+
>(a: a, b: b, c: c): Type<inferPipes<t, [a, b, c]>, $>
|
|
164
|
+
pipe<
|
|
165
|
+
a extends Morph<this["infer"]>,
|
|
166
|
+
b extends Morph<inferMorphOut<a>>,
|
|
167
|
+
c extends Morph<inferMorphOut<b>>,
|
|
168
|
+
d extends Morph<inferMorphOut<c>>
|
|
169
|
+
>(a: a, b: b, c: c, d: d): Type<inferPipes<t, [a, b, c, d]>, $>
|
|
170
|
+
pipe<
|
|
171
|
+
a extends Morph<this["infer"]>,
|
|
172
|
+
b extends Morph<inferMorphOut<a>>,
|
|
173
|
+
c extends Morph<inferMorphOut<b>>,
|
|
174
|
+
d extends Morph<inferMorphOut<c>>,
|
|
175
|
+
e extends Morph<inferMorphOut<d>>
|
|
176
|
+
>(a: a, b: b, c: c, d: d, e: e): Type<inferPipes<t, [a, b, c, d, e]>, $>
|
|
177
|
+
pipe<
|
|
178
|
+
a extends Morph<this["infer"]>,
|
|
179
|
+
b extends Morph<inferMorphOut<a>>,
|
|
180
|
+
c extends Morph<inferMorphOut<b>>,
|
|
181
|
+
d extends Morph<inferMorphOut<c>>,
|
|
182
|
+
e extends Morph<inferMorphOut<d>>,
|
|
183
|
+
f extends Morph<inferMorphOut<e>>
|
|
184
|
+
>(
|
|
185
|
+
a: a,
|
|
186
|
+
b: b,
|
|
187
|
+
c: c,
|
|
188
|
+
d: d,
|
|
189
|
+
e: e,
|
|
190
|
+
f: f
|
|
191
|
+
): Type<inferPipes<t, [a, b, c, d, e, f]>, $>
|
|
192
|
+
pipe<
|
|
193
|
+
a extends Morph<this["infer"]>,
|
|
194
|
+
b extends Morph<inferMorphOut<a>>,
|
|
195
|
+
c extends Morph<inferMorphOut<b>>,
|
|
196
|
+
d extends Morph<inferMorphOut<c>>,
|
|
197
|
+
e extends Morph<inferMorphOut<d>>,
|
|
198
|
+
f extends Morph<inferMorphOut<e>>,
|
|
199
|
+
g extends Morph<inferMorphOut<f>>
|
|
200
|
+
>(
|
|
201
|
+
a: a,
|
|
202
|
+
b: b,
|
|
203
|
+
c: c,
|
|
204
|
+
d: d,
|
|
205
|
+
e: e,
|
|
206
|
+
f: f,
|
|
207
|
+
g: g
|
|
208
|
+
): Type<inferPipes<t, [a, b, c, d, e, f, g]>, $>
|
|
111
209
|
|
|
112
210
|
// TODO: based on below, should maybe narrow morph output if used after
|
|
113
211
|
narrow<def extends Predicate<distillConstrainableOut<t>>>(
|
|
114
212
|
def: def
|
|
115
213
|
): Type<
|
|
116
214
|
includesMorphs<t> extends true ?
|
|
117
|
-
(In:
|
|
215
|
+
(In: this["tIn"]) => Out<inferNarrow<this["infer"], def>>
|
|
118
216
|
: inferNarrow<this["infer"], def>,
|
|
119
217
|
$
|
|
120
218
|
>
|
|
121
219
|
|
|
220
|
+
equals<def>(
|
|
221
|
+
def: validateTypeRoot<def, $>
|
|
222
|
+
): this is Type<inferTypeRoot<def>, $>
|
|
223
|
+
|
|
224
|
+
// TODO: i/o
|
|
225
|
+
extract<def>(r: validateTypeRoot<def, $>): Type<t, $>
|
|
226
|
+
exclude<def>(r: validateTypeRoot<def, $>): Type<t, $>
|
|
227
|
+
extends<def>(
|
|
228
|
+
other: validateTypeRoot<def, $>
|
|
229
|
+
): this is Type<inferTypeRoot<def>, $>
|
|
230
|
+
|
|
122
231
|
constrain<
|
|
123
232
|
kind extends PrimitiveConstraintKind,
|
|
124
233
|
const def extends NodeDef<kind>
|
|
125
234
|
>(
|
|
126
|
-
kind: conform<kind, constraintKindOf<this["
|
|
235
|
+
kind: conform<kind, constraintKindOf<this["inferIn"]>>,
|
|
127
236
|
def: def
|
|
128
237
|
): Type<constrain<t, kind, def>, $>
|
|
129
238
|
}
|
|
130
239
|
|
|
240
|
+
export interface Type<
|
|
241
|
+
/** @ts-expect-error allow instantiation assignment to the base type */
|
|
242
|
+
out t = unknown,
|
|
243
|
+
$ = any
|
|
244
|
+
> extends _Type<t, $> {}
|
|
245
|
+
|
|
131
246
|
export type TypeConstructor<t = unknown, $ = any> = new (
|
|
132
247
|
def: unknown,
|
|
133
248
|
$: Scope<$>
|