arktype 2.0.0-dev.2 → 2.0.0-dev.3
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 +225 -82
- package/__tests__/divisor.test.ts +6 -2
- package/__tests__/instanceof.test.ts +1 -1
- package/match.ts +3 -3
- package/out/match.d.ts +3 -3
- package/out/parser/objectLiteral.d.ts.map +1 -1
- package/out/parser/objectLiteral.js +31 -35
- package/out/parser/objectLiteral.js.map +1 -1
- package/out/parser/semantic/semantic.d.ts +4 -5
- package/out/parser/semantic/semantic.d.ts.map +1 -1
- package/out/parser/shared.d.ts +6 -0
- package/out/parser/shared.d.ts.map +1 -1
- package/out/parser/shared.js +5 -4
- package/out/parser/shared.js.map +1 -1
- package/out/parser/tuple.d.ts +14 -13
- package/out/parser/tuple.d.ts.map +1 -1
- package/out/parser/tuple.js +92 -50
- package/out/parser/tuple.js.map +1 -1
- package/out/scope.d.ts.map +1 -1
- package/out/scope.js +7 -4
- package/out/scope.js.map +1 -1
- package/out/type.d.ts +1 -2
- package/out/type.d.ts.map +1 -1
- package/out/type.js +3 -3
- package/out/type.js.map +1 -1
- package/package.json +3 -3
- package/parser/objectLiteral.ts +51 -55
- package/parser/semantic/semantic.ts +5 -5
- package/parser/semantic/validate.ts +1 -1
- package/parser/shared.ts +8 -5
- package/parser/tuple.ts +169 -81
- package/scope.ts +7 -4
- package/type.ts +4 -4
- package/parser/semantic/intersections.ts +0 -46
package/__tests__/array.test.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { writeUnresolvableMessage } from "../parser/string/shift/operand/unenclo
|
|
|
4
4
|
import { incompleteArrayTokenMessage } from "../parser/string/shift/operator/operator.js"
|
|
5
5
|
import {
|
|
6
6
|
multipleVariadicMesage,
|
|
7
|
-
|
|
7
|
+
writeNonArraySpreadMessage
|
|
8
8
|
} from "../parser/tuple.js"
|
|
9
9
|
|
|
10
10
|
describe("array", () => {
|
|
@@ -109,17 +109,23 @@ describe("array", () => {
|
|
|
109
109
|
const t = type(["string", "number"])
|
|
110
110
|
attest<[string, number]>(t.infer)
|
|
111
111
|
attest(t.allows(["", 0])).equals(true)
|
|
112
|
-
attest(t(["", 0]).out).snap()
|
|
112
|
+
attest(t(["", 0]).out).snap(["", 0])
|
|
113
113
|
attest(t.allows([true, 0])).equals(false)
|
|
114
|
-
attest(t([true, 0]).errors?.summary).snap(
|
|
114
|
+
attest(t([true, 0]).errors?.summary).snap(
|
|
115
|
+
"Value at [0] must be a string (was boolean)"
|
|
116
|
+
)
|
|
115
117
|
attest(t.allows([0, false])).equals(false)
|
|
116
|
-
attest(t([0, false]).errors?.summary)
|
|
118
|
+
attest(t([0, false]).errors?.summary)
|
|
119
|
+
.snap(`Value at [0] must be a string (was number)
|
|
120
|
+
Value at [1] must be a number (was boolean)`)
|
|
117
121
|
// too short
|
|
118
122
|
attest(t.allows([""])).equals(false)
|
|
119
|
-
attest(t([""]).errors?.summary).snap()
|
|
123
|
+
attest(t([""]).errors?.summary).snap("Must be at least length 2 (was 1)")
|
|
120
124
|
// too long
|
|
121
125
|
attest(t.allows(["", 0, 1])).equals(false)
|
|
122
|
-
attest(t(["", 0, 1]).errors?.summary).snap(
|
|
126
|
+
attest(t(["", 0, 1]).errors?.summary).snap(
|
|
127
|
+
"Must be at most length 2 (was 3)"
|
|
128
|
+
)
|
|
123
129
|
// non-array
|
|
124
130
|
attest(
|
|
125
131
|
t.allows({
|
|
@@ -134,102 +140,94 @@ describe("array", () => {
|
|
|
134
140
|
0: "",
|
|
135
141
|
1: 0
|
|
136
142
|
}).errors?.summary
|
|
137
|
-
).snap()
|
|
143
|
+
).snap("Must be an array (was object)")
|
|
138
144
|
})
|
|
139
145
|
|
|
140
146
|
it("nested", () => {
|
|
141
|
-
const t = type([["string", "number"], [{ a: "
|
|
147
|
+
const t = type([["string", "number"], [{ a: "bigint", b: ["null"] }]])
|
|
142
148
|
attest<
|
|
143
149
|
[
|
|
144
150
|
[string, number],
|
|
145
151
|
[
|
|
146
152
|
{
|
|
147
|
-
a:
|
|
153
|
+
a: bigint
|
|
148
154
|
b: [null]
|
|
149
155
|
}
|
|
150
156
|
]
|
|
151
157
|
]
|
|
152
158
|
>(t.infer)
|
|
153
|
-
|
|
154
|
-
attest(t.allows(
|
|
155
|
-
attest(t(
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
t([["foo", 1], [{ a: true, b: [undefined] }]]).errors?.summary
|
|
162
|
-
).snap("[1][0].b[0] must be null (was undefined)")
|
|
159
|
+
const valid: typeof t.infer = [["", 0], [{ a: 0n, b: [null] }]]
|
|
160
|
+
attest(t.allows(valid)).equals(true)
|
|
161
|
+
attest(t(valid).out).equals(valid)
|
|
162
|
+
const invalid = [["", 0], [{ a: 0n, b: [undefined] }]]
|
|
163
|
+
attest(t.allows(invalid)).equals(false)
|
|
164
|
+
attest(t(invalid).errors?.summary).snap(
|
|
165
|
+
"Value at [1][0].b[0] must be null (was undefined)"
|
|
166
|
+
)
|
|
163
167
|
})
|
|
164
168
|
})
|
|
165
169
|
describe("variadic tuple", () => {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
})
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
type(["...number[]", "string"])
|
|
212
|
-
).throwsAndHasTypeError(multipleVariadicMesage)
|
|
213
|
-
attest(() =>
|
|
170
|
+
it("spreads simple arrays", () => {
|
|
171
|
+
const wellRested = type(["string", "...number[]"])
|
|
172
|
+
attest<[string, ...number[]]>(wellRested.infer)
|
|
173
|
+
attest(wellRested(["foo"]).out).equals(["foo"])
|
|
174
|
+
attest(wellRested(["foo", 1, 2]).out).equals(["foo", 1, 2])
|
|
175
|
+
})
|
|
176
|
+
it("tuple expression", () => {
|
|
177
|
+
const wellRestedTuple = type(["number", ["...", [{ a: "string" }, "[]"]]])
|
|
178
|
+
attest<[number, ...{ a: string }[]]>(wellRestedTuple.infer)
|
|
179
|
+
})
|
|
180
|
+
it("spreads array expressions", () => {
|
|
181
|
+
const greatSpread = type(["0", "...(Date|RegExp)[]"])
|
|
182
|
+
attest<[0, ...(RegExp | Date)[]]>(greatSpread.infer)
|
|
183
|
+
})
|
|
184
|
+
it("distributes spread unions", () => {
|
|
185
|
+
const t = type(["1", "...(Date[] | RegExp[])"])
|
|
186
|
+
attest<[1, ...(Date[] | RegExp[])]>(t.infer)
|
|
187
|
+
const expected = type(["1", "...Date[]"]).or(["1", "...RegExp[]"])
|
|
188
|
+
attest(t.json).equals(expected.json)
|
|
189
|
+
})
|
|
190
|
+
it("allows array keyword", () => {
|
|
191
|
+
const types = scope({
|
|
192
|
+
myArrayKeyword: "boolean[]",
|
|
193
|
+
myVariadicKeyword: ["string", "...myArrayKeyword"]
|
|
194
|
+
}).export()
|
|
195
|
+
attest<[string, ...boolean[]]>(types.myVariadicKeyword.infer)
|
|
196
|
+
})
|
|
197
|
+
it("errors on non-array", () => {
|
|
198
|
+
attest(() =>
|
|
199
|
+
// @ts-expect-error
|
|
200
|
+
type(["email", "...symbol"])
|
|
201
|
+
).throwsAndHasTypeError(writeNonArraySpreadMessage("a symbol"))
|
|
202
|
+
attest(() =>
|
|
203
|
+
// @ts-expect-error
|
|
204
|
+
type(["number", ["...", "string"]])
|
|
205
|
+
).throwsAndHasTypeError(writeNonArraySpreadMessage("a string"))
|
|
206
|
+
})
|
|
207
|
+
it("errors on multiple variadic", () => {
|
|
208
|
+
attest(() =>
|
|
209
|
+
// @ts-expect-error
|
|
210
|
+
type(["...number[]", "...string[]"])
|
|
211
|
+
).throwsAndHasTypeError(multipleVariadicMesage)
|
|
212
|
+
attest(() =>
|
|
213
|
+
type([
|
|
214
|
+
["...", "string[]"],
|
|
214
215
|
// @ts-expect-error
|
|
215
|
-
|
|
216
|
-
)
|
|
217
|
-
|
|
216
|
+
["...", "number[]"]
|
|
217
|
+
])
|
|
218
|
+
).throwsAndHasTypeError(multipleVariadicMesage)
|
|
218
219
|
})
|
|
219
220
|
})
|
|
220
221
|
describe("intersection", () => {
|
|
221
222
|
it("shallow array intersection", () => {
|
|
222
|
-
const
|
|
223
|
-
const expected = type("'foo'[]")
|
|
224
|
-
attest(
|
|
223
|
+
const t = type("string[]&'foo'[]")
|
|
224
|
+
const expected = type("'foo'[]")
|
|
225
|
+
attest(t.json).equals(expected.json)
|
|
225
226
|
})
|
|
226
227
|
it("deep array intersection", () => {
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
]).json
|
|
231
|
-
const expected = type([{ a: "string", b: "number" }, "[]"]).json
|
|
232
|
-
attest(actual).is(expected)
|
|
228
|
+
const t = type([{ a: "string" }, "[]"]).and([{ b: "number" }, "[]"])
|
|
229
|
+
const expected = type([{ a: "string", b: "number" }, "[]"])
|
|
230
|
+
attest(t.json).equals(expected.json)
|
|
233
231
|
})
|
|
234
232
|
it("tuple intersection", () => {
|
|
235
233
|
const t = type([[{ a: "string" }], "&", [{ b: "boolean" }]])
|
|
@@ -241,6 +239,7 @@ describe("array", () => {
|
|
|
241
239
|
}
|
|
242
240
|
]
|
|
243
241
|
>(t.infer)
|
|
242
|
+
const expected = type([{ a: "string", b: "boolean" }])
|
|
244
243
|
})
|
|
245
244
|
it("tuple and array", () => {
|
|
246
245
|
const tupleAndArray = type([
|
|
@@ -271,9 +270,9 @@ describe("array", () => {
|
|
|
271
270
|
]
|
|
272
271
|
>(arrayAndTuple.infer)
|
|
273
272
|
|
|
274
|
-
const expected = type([{ a: "string", b: "boolean" }])
|
|
275
|
-
attest(tupleAndArray.json).
|
|
276
|
-
attest(arrayAndTuple.json).
|
|
273
|
+
const expected = type([{ a: "string", b: "boolean" }])
|
|
274
|
+
attest(tupleAndArray.json).equals(expected.json)
|
|
275
|
+
attest(arrayAndTuple.json).equals(expected.json)
|
|
277
276
|
})
|
|
278
277
|
it("variadic and tuple", () => {
|
|
279
278
|
const b = type([{ b: "boolean" }, "[]"])
|
|
@@ -297,6 +296,150 @@ describe("array", () => {
|
|
|
297
296
|
attest<typeof expected.infer>(t.infer)
|
|
298
297
|
attest(t.json).equals(expected.json)
|
|
299
298
|
})
|
|
299
|
+
// based on the equivalent type-level test from @arktype/util
|
|
300
|
+
it("kitchen sink", () => {
|
|
301
|
+
const l = type([
|
|
302
|
+
{ a: "0" },
|
|
303
|
+
[{ b: "1" }, "?"],
|
|
304
|
+
[{ c: "2" }, "?"],
|
|
305
|
+
["...", [{ d: "3" }, "[]"]]
|
|
306
|
+
])
|
|
307
|
+
const r = type([
|
|
308
|
+
[{ e: "4" }, "?"],
|
|
309
|
+
[{ f: "5" }, "?"],
|
|
310
|
+
["...", [{ g: "6" }, "[]"]]
|
|
311
|
+
])
|
|
312
|
+
const result = l.and(r)
|
|
313
|
+
|
|
314
|
+
const expected = type([
|
|
315
|
+
{ a: "0", e: "4" },
|
|
316
|
+
[{ b: "1", f: "5" }, "?"],
|
|
317
|
+
[{ c: "2", g: "6" }, "?"],
|
|
318
|
+
["...", [{ d: "3", g: "6" }, "[]"]]
|
|
319
|
+
])
|
|
320
|
+
|
|
321
|
+
attest<typeof expected>(result)
|
|
322
|
+
attest(result.json).equals(expected.json)
|
|
323
|
+
})
|
|
324
|
+
it("prefix and postfix", () => {
|
|
325
|
+
const l = type([["...", [{ a: "0" }, "[]"]], { b: "0" }, { c: "0" }])
|
|
326
|
+
const r = type([{ x: "0" }, { y: "0" }, ["...", [{ z: "0" }, "[]"]]])
|
|
327
|
+
|
|
328
|
+
// currently getting this "Expected" result at a type-level incurs
|
|
329
|
+
// too high a performance cost for such a niche intersection.
|
|
330
|
+
type Expected =
|
|
331
|
+
| [
|
|
332
|
+
{ a: 0; x: 0 },
|
|
333
|
+
{ a: 0; y: 0 },
|
|
334
|
+
...{ a: 0; z: 0 }[],
|
|
335
|
+
{ b: 0; z: 0 },
|
|
336
|
+
{ c: 0; z: 0 }
|
|
337
|
+
]
|
|
338
|
+
| [{ a: 0; x: 0 }, { b: 0; y: 0 }, { c: 0; z: 0 }]
|
|
339
|
+
| [{ b: 0; x: 0 }, { c: 0; y: 0 }]
|
|
340
|
+
|
|
341
|
+
const result = l.and(r)
|
|
342
|
+
attest(result.json).snap([
|
|
343
|
+
{
|
|
344
|
+
basis: "Array",
|
|
345
|
+
maxLength: 2,
|
|
346
|
+
minLength: 2,
|
|
347
|
+
sequence: {
|
|
348
|
+
prefix: [
|
|
349
|
+
{
|
|
350
|
+
basis: "object",
|
|
351
|
+
required: [
|
|
352
|
+
{ key: "b", value: { unit: 0 } },
|
|
353
|
+
{ key: "x", value: { unit: 0 } }
|
|
354
|
+
]
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
basis: "object",
|
|
358
|
+
required: [
|
|
359
|
+
{ key: "c", value: { unit: 0 } },
|
|
360
|
+
{ key: "y", value: { unit: 0 } }
|
|
361
|
+
]
|
|
362
|
+
}
|
|
363
|
+
]
|
|
364
|
+
}
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
basis: "Array",
|
|
368
|
+
maxLength: 3,
|
|
369
|
+
minLength: 3,
|
|
370
|
+
sequence: {
|
|
371
|
+
prefix: [
|
|
372
|
+
{
|
|
373
|
+
basis: "object",
|
|
374
|
+
required: [
|
|
375
|
+
{ key: "a", value: { unit: 0 } },
|
|
376
|
+
{ key: "x", value: { unit: 0 } }
|
|
377
|
+
]
|
|
378
|
+
},
|
|
379
|
+
{
|
|
380
|
+
basis: "object",
|
|
381
|
+
required: [
|
|
382
|
+
{ key: "b", value: { unit: 0 } },
|
|
383
|
+
{ key: "y", value: { unit: 0 } }
|
|
384
|
+
]
|
|
385
|
+
},
|
|
386
|
+
{
|
|
387
|
+
basis: "object",
|
|
388
|
+
required: [
|
|
389
|
+
{ key: "c", value: { unit: 0 } },
|
|
390
|
+
{ key: "z", value: { unit: 0 } }
|
|
391
|
+
]
|
|
392
|
+
}
|
|
393
|
+
]
|
|
394
|
+
}
|
|
395
|
+
},
|
|
396
|
+
{
|
|
397
|
+
basis: "Array",
|
|
398
|
+
minLength: 4,
|
|
399
|
+
sequence: {
|
|
400
|
+
postfix: [
|
|
401
|
+
{
|
|
402
|
+
basis: "object",
|
|
403
|
+
required: [
|
|
404
|
+
{ key: "b", value: { unit: 0 } },
|
|
405
|
+
{ key: "z", value: { unit: 0 } }
|
|
406
|
+
]
|
|
407
|
+
},
|
|
408
|
+
{
|
|
409
|
+
basis: "object",
|
|
410
|
+
required: [
|
|
411
|
+
{ key: "c", value: { unit: 0 } },
|
|
412
|
+
{ key: "z", value: { unit: 0 } }
|
|
413
|
+
]
|
|
414
|
+
}
|
|
415
|
+
],
|
|
416
|
+
prefix: [
|
|
417
|
+
{
|
|
418
|
+
basis: "object",
|
|
419
|
+
required: [
|
|
420
|
+
{ key: "a", value: { unit: 0 } },
|
|
421
|
+
{ key: "x", value: { unit: 0 } }
|
|
422
|
+
]
|
|
423
|
+
},
|
|
424
|
+
{
|
|
425
|
+
basis: "object",
|
|
426
|
+
required: [
|
|
427
|
+
{ key: "a", value: { unit: 0 } },
|
|
428
|
+
{ key: "y", value: { unit: 0 } }
|
|
429
|
+
]
|
|
430
|
+
}
|
|
431
|
+
],
|
|
432
|
+
variadic: {
|
|
433
|
+
basis: "object",
|
|
434
|
+
required: [
|
|
435
|
+
{ key: "a", value: { unit: 0 } },
|
|
436
|
+
{ key: "z", value: { unit: 0 } }
|
|
437
|
+
]
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
])
|
|
442
|
+
})
|
|
300
443
|
})
|
|
301
444
|
// TODO: reenable
|
|
302
445
|
// describe("traversal", () => {
|
|
@@ -9,6 +9,10 @@ describe("divisibility", () => {
|
|
|
9
9
|
const divisibleByTwo = type("number%2")
|
|
10
10
|
attest<number>(divisibleByTwo.infer)
|
|
11
11
|
attest(divisibleByTwo.json).snap({ basis: "number", divisor: 2 })
|
|
12
|
+
attest(divisibleByTwo(4).out).snap(4)
|
|
13
|
+
attest(divisibleByTwo(5).errors?.summary).snap(
|
|
14
|
+
"Must be a multiple of 2 (was 5)"
|
|
15
|
+
)
|
|
12
16
|
})
|
|
13
17
|
it("whitespace after %", () => {
|
|
14
18
|
const t = type("number % 5")
|
|
@@ -82,8 +86,8 @@ describe("divisibility", () => {
|
|
|
82
86
|
attest(t.json).equals(type("0").json)
|
|
83
87
|
})
|
|
84
88
|
it("invalid literal", () => {
|
|
85
|
-
attest(() => type("number%3&8")).throws(
|
|
86
|
-
"Intersection of
|
|
89
|
+
attest(() => type("number%3&8")).throws.snap(
|
|
90
|
+
"Error: Intersection of 8 and a number and a multiple of 3 results in an unsatisfiable type"
|
|
87
91
|
)
|
|
88
92
|
})
|
|
89
93
|
})
|
|
@@ -13,7 +13,7 @@ describe("instanceof", () => {
|
|
|
13
13
|
attest(t.json).equals(schema(Error).json)
|
|
14
14
|
const e = new Error()
|
|
15
15
|
attest(t(e).out).equals(e)
|
|
16
|
-
attest(t({}).errors?.summary).snap("Must be an Error (was
|
|
16
|
+
attest(t({}).errors?.summary).snap("Must be an Error (was object)")
|
|
17
17
|
})
|
|
18
18
|
it("inherited", () => {
|
|
19
19
|
const t = type(["instanceof", TypeError])
|
package/match.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
2
|
+
AnonymousConstraintKey,
|
|
3
3
|
Morph,
|
|
4
4
|
distill,
|
|
5
5
|
intersectConstrainables,
|
|
@@ -47,8 +47,8 @@ type matcherInputs<ctx extends MatchParserContext> = Parameters<
|
|
|
47
47
|
>[0]
|
|
48
48
|
|
|
49
49
|
type AnonymouslyRefined = {
|
|
50
|
-
[k in
|
|
51
|
-
}[
|
|
50
|
+
[k in AnonymousConstraintKey]: { [_ in k]: true }
|
|
51
|
+
}[AnonymousConstraintKey]
|
|
52
52
|
|
|
53
53
|
type getHandledBranches<ctx extends MatchParserContext> = Exclude<
|
|
54
54
|
matcherInputs<ctx>,
|
package/out/match.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AnonymousConstraintKey, distill, intersectConstrainables, is } from "@arktype/schema";
|
|
2
2
|
import type { ErrorMessage, UnknownUnion, isDisjoint, numericStringKeyOf, replaceKey, unionToTuple, valueOf } from "@arktype/util";
|
|
3
3
|
import type { Scope } from "./scope.js";
|
|
4
4
|
import { type inferTypeRoot, type validateTypeRoot } from "./type.js";
|
|
@@ -25,10 +25,10 @@ export type MatchParser<$> = CaseMatchParser<{
|
|
|
25
25
|
};
|
|
26
26
|
type matcherInputs<ctx extends MatchParserContext> = Parameters<ctx["thens"][number]>[0];
|
|
27
27
|
type AnonymouslyRefined = {
|
|
28
|
-
[k in
|
|
28
|
+
[k in AnonymousConstraintKey]: {
|
|
29
29
|
[_ in k]: true;
|
|
30
30
|
};
|
|
31
|
-
}[
|
|
31
|
+
}[AnonymousConstraintKey];
|
|
32
32
|
type getHandledBranches<ctx extends MatchParserContext> = Exclude<matcherInputs<ctx>, is<unknown, AnonymouslyRefined>>;
|
|
33
33
|
type getUnhandledBranches<ctx extends MatchParserContext> = Exclude<unknown extends ctx["exhaustiveOver"] ? UnknownUnion : ctx["exhaustiveOver"], getHandledBranches<ctx>>;
|
|
34
34
|
type addBranches<ctx extends MatchParserContext, branches extends unknown[]> = replaceKey<ctx, "thens", [...ctx["thens"], ...branches]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"objectLiteral.d.ts","sourceRoot":"","sources":["../../parser/objectLiteral.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAC7E,OAAO,EAGN,KAAK,IAAI,EACT,KAAK,YAAY,EACjB,KAAK,QAAQ,EACb,KAAK,KAAK,EACV,MAAM,eAAe,CAAA;AAEtB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAC1E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,EACN,UAAU,EACV,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,MAAM,aAAa,CAAA;AAOpB,eAAO,MAAM,kBAAkB,QAAS,IAAI,OAAO,YAAY,KAAG,
|
|
1
|
+
{"version":3,"file":"objectLiteral.d.ts","sourceRoot":"","sources":["../../parser/objectLiteral.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAC7E,OAAO,EAGN,KAAK,IAAI,EACT,KAAK,YAAY,EACjB,KAAK,QAAQ,EACb,KAAK,KAAK,EACV,MAAM,eAAe,CAAA;AAEtB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAC1E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAA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CAAC,UAAU,CAAC,GAClB,KAAK,CAAA;AAER,OAAO,CAAC,MAAM,gBAAgB,EAAE,OAAO,MAAM,CAAA;AAE7C,MAAM,MAAM,eAAe,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM,IAAI;IAC9D,CAAC,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B,CAAA;AAED,eAAO,MAAM,8BAA8B,4HAG+B,CAAA;AAE1E,KAAK,8BAA8B,CAAC,QAAQ,SAAS,MAAM,IAC1D,2BAA2B,QAAQ,sCAAsC,CAAA;AAE1E,eAAO,MAAM,6BAA6B,wGAG2B,CAAA;AAErE,KAAK,6BAA6B,CAAC,GAAG,SAAS,MAAM,IACpD,8DAA8D,GAAG,GAAG,CAAA"}
|
|
@@ -14,46 +14,42 @@ export const parseObjectLiteral = (def, ctx) => {
|
|
|
14
14
|
// anywhere except for the beginning.
|
|
15
15
|
// Discussion in ArkType Discord:
|
|
16
16
|
// https://discord.com/channels/957797212103016458/1103023445035462678/1182814502471860334
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (spreadNode.kind !== "intersection" ||
|
|
27
|
-
!spreadNode.extends(keywords.object)) {
|
|
28
|
-
return throwParseError(writeInvalidSpreadTypeMessage(printable(result.innerValue)));
|
|
29
|
-
}
|
|
30
|
-
// For each key on spreadNode, add it to our object.
|
|
31
|
-
// We filter out keys from the spreadNode that will be defined later on this same object
|
|
32
|
-
// because the currently parsed definition will overwrite them.
|
|
33
|
-
const requiredEntriesFromSpread = (spreadNode.props?.required ?? []).filter((e) => !entries.some(([k]) => k === e.key));
|
|
34
|
-
const optionalEntriesFromSpread = (spreadNode.props?.optional ?? []).filter((e) => !entries.some(([k]) => k === e.key));
|
|
35
|
-
required.push(...requiredEntriesFromSpread);
|
|
36
|
-
optional.push(...optionalEntriesFromSpread);
|
|
37
|
-
continue;
|
|
17
|
+
const parsedEntries = stringAndSymbolicEntriesOf(def).map(parseEntry);
|
|
18
|
+
if (parsedEntries[0].kind === "spread") {
|
|
19
|
+
// remove the spread entry so we can iterate over the remaining entries
|
|
20
|
+
// expecting non-spread entries
|
|
21
|
+
const spreadEntry = parsedEntries.shift();
|
|
22
|
+
const spreadNode = ctx.scope.parse(spreadEntry.innerValue, ctx);
|
|
23
|
+
if (spreadNode.kind !== "intersection" ||
|
|
24
|
+
!spreadNode.extends(keywords.object)) {
|
|
25
|
+
return throwParseError(writeInvalidSpreadTypeMessage(printable(spreadEntry.innerValue)));
|
|
38
26
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
27
|
+
// TODO: move to props group merge in schema
|
|
28
|
+
// For each key on spreadNode, add it to our object.
|
|
29
|
+
// We filter out keys from the spreadNode that will be defined later on this same object
|
|
30
|
+
// because the currently parsed definition will overwrite them.
|
|
31
|
+
spreadNode.required?.forEach((spreadRequired) => !parsedEntries.some(({ innerKey }) => innerKey === spreadRequired.key) && required.push(spreadRequired));
|
|
32
|
+
spreadNode.optional?.forEach((spreadOptional) => !parsedEntries.some(({ innerKey }) => innerKey === spreadOptional.key) && optional.push(spreadOptional));
|
|
33
|
+
}
|
|
34
|
+
for (const entry of parsedEntries) {
|
|
35
|
+
if (entry.kind === "spread") {
|
|
36
|
+
return throwParseError("Spread operator may only be used as the first key in an object");
|
|
37
|
+
}
|
|
38
|
+
ctx.path.push(`${typeof entry.innerKey === "symbol"
|
|
39
|
+
? `[${printable(entry.innerKey)}]`
|
|
40
|
+
: entry.innerKey}`);
|
|
41
|
+
const value = ctx.scope.parse(entry.innerValue, ctx);
|
|
42
|
+
const inner = {
|
|
43
|
+
key: entry.innerKey,
|
|
44
|
+
value
|
|
45
|
+
};
|
|
46
|
+
if (entry.kind === "optional") {
|
|
47
|
+
optional.push(inner);
|
|
48
48
|
}
|
|
49
49
|
else {
|
|
50
|
-
required.push(
|
|
51
|
-
key: result.innerKey,
|
|
52
|
-
value: valueNode
|
|
53
|
-
});
|
|
50
|
+
required.push(inner);
|
|
54
51
|
}
|
|
55
52
|
ctx.path.pop();
|
|
56
|
-
hasSeenFirstKey ||= true;
|
|
57
53
|
}
|
|
58
54
|
return schema({
|
|
59
55
|
basis: "object",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"objectLiteral.js","sourceRoot":"","sources":["../../parser/objectLiteral.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAA6B,MAAM,iBAAiB,CAAA;AAC7E,OAAO,EACN,SAAS,EACT,eAAe,EAKf,MAAM,eAAe,CAAA;AAMtB,OAAO,EACN,UAAU,EAKV,MAAM,aAAa,CAAA;AAEpB,MAAM,0BAA0B,GAAG,CAAC,CAAmC,EAAE,EAAE,CAAC;IAC3E,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;IACpB,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAU,CAAC;CACjE,CAAA;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAS,EAAE,GAAiB,EAAY,EAAE;IAC5E,MAAM,QAAQ,GAAwB,EAAE,CAAA;IACxC,MAAM,QAAQ,GAAwB,EAAE,CAAA;IAExC,2EAA2E;IAC3E,0EAA0E;IAC1E,mFAAmF;IACnF,qCAAqC;IACrC,iCAAiC;IACjC,0FAA0F;
|
|
1
|
+
{"version":3,"file":"objectLiteral.js","sourceRoot":"","sources":["../../parser/objectLiteral.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAA6B,MAAM,iBAAiB,CAAA;AAC7E,OAAO,EACN,SAAS,EACT,eAAe,EAKf,MAAM,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EAAE,CAAA;IACf,CAAC;IAED,OAAO,MAAM,CAAC;QACb,KAAK,EAAE,QAAQ;QACf,QAAQ;QACR,QAAQ;KACR,CAAC,CAAA;AACH,CAAC,CAAA;AA0ED,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAC7C,QAAkB,EACyB,EAAE,CAC7C,2BAA2B,QAAQ,sCAAsC,CAAA;AAK1E,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAC5C,GAAQ,EAC6B,EAAE,CACvC,8DAA8D,GAAG,GAAG,CAAA"}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Constraints, DateLiteral, RegexLiteral, distill, inferIntersection, is } from "@arktype/schema";
|
|
2
2
|
import type { BigintLiteral, List, NumberLiteral, evaluate } from "@arktype/util";
|
|
3
3
|
import type { UnparsedScope, resolve, tryInferSubmoduleReference } from "../../scope.js";
|
|
4
4
|
import type { GenericProps } from "../../type.js";
|
|
5
5
|
import type { inferDefinition } from "../definition.js";
|
|
6
6
|
import type { Comparator, InvertedComparators, LimitLiteral } from "../string/reduce/shared.js";
|
|
7
7
|
import type { StringLiteral } from "../string/shift/operand/enclosed.js";
|
|
8
|
-
import type { inferIntersection } from "./intersections.js";
|
|
9
8
|
export type inferAstRoot<ast, $, args> = inferAst<ast, $, args, {}>;
|
|
10
9
|
export type inferAstBase<ast, $, args> = distill<inferAstRoot<ast, $, args>>;
|
|
11
|
-
export type inferAst<ast, $, args, refinements extends
|
|
10
|
+
export type inferAst<ast, $, args, refinements extends Constraints> = ast extends List ? inferExpression<ast, $, args, refinements> : inferTerminal<ast, $, args, refinements>;
|
|
12
11
|
export type GenericInstantiationAst<g extends GenericProps = GenericProps, argAsts extends unknown[] = unknown[]> = [g, "<>", argAsts];
|
|
13
|
-
export type inferExpression<ast extends List, $, args, refinements extends
|
|
12
|
+
export type inferExpression<ast extends List, $, args, refinements extends Constraints> = ast extends GenericInstantiationAst ? inferDefinition<ast[0]["definition"], ast[0]["$"] extends UnparsedScope ? $ : ast[0]["$"], {
|
|
14
13
|
[i in keyof ast[0]["parameters"] & `${number}` as ast[0]["parameters"][i]]: inferAst<ast[2][i & keyof ast[2]], $, args, refinements>;
|
|
15
14
|
}> : ast[1] extends "[]" ? inferAst<ast[0], $, args, refinements>[] : ast[1] extends "|" ? inferAst<ast[0], $, args, refinements> | inferAst<ast[2], $, args, refinements> : ast[1] extends "&" ? inferIntersection<inferAst<ast[0], $, args, refinements>, inferAst<ast[2], $, args, refinements>> : ast[1] extends Comparator ? ast[0] extends LimitLiteral ? inferAst<ast[2], $, args, refinements & {
|
|
16
15
|
[_ in InvertedComparators[ast[1]]]: ast[0];
|
|
@@ -25,7 +24,7 @@ export type PostfixOperator = "[]";
|
|
|
25
24
|
export type PostfixExpression<operator extends PostfixOperator = PostfixOperator, operand = unknown> = readonly [operand, operator];
|
|
26
25
|
export type InfixOperator = "|" | "&" | Comparator | "%" | ":" | "=>" | "@";
|
|
27
26
|
export type InfixExpression<operator extends InfixOperator = InfixOperator, l = unknown, r = unknown> = [l, operator, r];
|
|
28
|
-
export type inferTerminal<token, $, args, refinements extends
|
|
27
|
+
export type inferTerminal<token, $, args, refinements extends Constraints> = token extends keyof args | keyof $ ? {} extends refinements ? resolve<token, $, args> : is<resolve<token, $, args>, evaluate<refinements>> : token extends StringLiteral<infer text> ? text : token extends RegexLiteral ? is<string, evaluate<refinements & {
|
|
29
28
|
[_ in token]: true;
|
|
30
29
|
}>> : token extends DateLiteral ? is<Date, evaluate<refinements & {
|
|
31
30
|
[_ in token]: true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"semantic.d.ts","sourceRoot":"","sources":["../../../parser/semantic/semantic.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,WAAW,EACX,WAAW,EACX,YAAY,EACZ,OAAO,EACP,EAAE,EACF,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EACX,aAAa,EACb,IAAI,EACJ,aAAa,EACb,QAA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G,CAAC,IAAI,KAAK,GAAG,IAAI;CAAE,CAAC,CAAC,GACxD,KAAK,SAAS,aAAa,CAAC,MAAM,KAAK,CAAC,GACxC,KAAK,GACL,KAAK,SAAS,aAAa,CAAC,MAAM,KAAK,CAAC,GACxC,KAAK,GAIL,0BAA0B,CAAC,CAAC,EAAE,KAAK,CAAC,CAAA"}
|
package/out/parser/shared.d.ts
CHANGED
|
@@ -8,9 +8,14 @@ type KeyParseResult<kind extends ParsedKeyKind = ParsedKeyKind> = {
|
|
|
8
8
|
kind: kind;
|
|
9
9
|
innerKey: string | symbol;
|
|
10
10
|
};
|
|
11
|
+
export type EntryValueParseResult<kind extends ParsedValueKind = ParsedValueKind> = {
|
|
12
|
+
kind: kind;
|
|
13
|
+
innerValue: unknown;
|
|
14
|
+
};
|
|
11
15
|
export type EntryParseResult<kind extends ParsedKeyKind = ParsedKeyKind> = evaluate<KeyParseResult<kind> & {
|
|
12
16
|
innerValue: unknown;
|
|
13
17
|
}>;
|
|
18
|
+
type ParsedValueKind = "required" | "optional";
|
|
14
19
|
type ParsedKeyKind = "required" | "optional" | "indexed" | "spread";
|
|
15
20
|
type parsedEntry<result extends EntryParseResult> = result;
|
|
16
21
|
export type OptionalValue<value> = OptionalStringDefinition<value & string> | OptionalTuple<value>;
|
|
@@ -19,6 +24,7 @@ export type IndexedKey<def extends string = string> = `[${def}]`;
|
|
|
19
24
|
export type validateObjectValue<def, $, args> = def extends OptionalTuple<infer value> ? readonly [validateObjectValueString<value, $, args>, "?"] : validateObjectValueString<def, $, args>;
|
|
20
25
|
type validateObjectValueString<def, $, args> = def extends OptionalStringDefinition<infer innerValue> ? `${validateDefinition<innerValue, $, args>}?` : validateDefinition<def, $, args>;
|
|
21
26
|
type DefinitionEntry = readonly [string | symbol, unknown];
|
|
27
|
+
export declare const parseEntryValue: (value: unknown) => EntryValueParseResult;
|
|
22
28
|
export declare const parseEntry: ([key, value]: DefinitionEntry) => EntryParseResult;
|
|
23
29
|
export type parseEntry<keyDef extends PropertyKey, valueDef> = parseKey<keyDef> extends infer keyParseResult extends KeyParseResult ? valueDef extends OptionalValue<infer innerValue> ? parsedEntry<{
|
|
24
30
|
kind: "optional";
|