-
-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathintrinsic.ts
More file actions
74 lines (67 loc) · 1.59 KB
/
Copy pathintrinsic.ts
File metadata and controls
74 lines (67 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { FileConstructor } from "@ark/util"
import { node, schemaScope } from "./scope.ts"
import { $ark } from "./shared/registry.ts"
import { arrayIndexSource } from "./structure/shared.ts"
const intrinsicBases = schemaScope(
{
bigint: "bigint",
// since we know this won't be reduced, it can be safely cast to a union
boolean: [{ unit: false }, { unit: true }],
false: { unit: false },
never: [],
null: { unit: null },
number: "number",
object: "object",
string: "string",
symbol: "symbol",
true: { unit: true },
unknown: {},
undefined: { unit: undefined },
Array,
Date,
File: FileConstructor
},
{ prereducedAliases: true }
).export()
$ark.intrinsic = { ...intrinsicBases } as never
const intrinsicRoots = schemaScope(
{
integer: {
domain: "number",
divisor: 1
},
lengthBoundable: ["string", Array],
key: ["string", "symbol"],
nonNegativeIntegerString: { domain: "string", pattern: arrayIndexSource }
},
{ prereducedAliases: true }
).export()
// needed to parse index signatures for JSON
Object.assign($ark.intrinsic, intrinsicRoots)
const intrinsicJson = schemaScope(
{
jsonPrimitive: [
"string",
"number",
{ unit: true },
{ unit: false },
{ unit: null }
],
jsonObject: {
domain: "object",
index: {
signature: "string",
value: "$jsonData"
}
},
jsonData: ["$jsonPrimitive", "$jsonObject"]
},
{ prereducedAliases: true }
).export()
export const intrinsic = {
...intrinsicBases,
...intrinsicRoots,
...intrinsicJson,
emptyStructure: node("structure", {}, { prereduced: true })
}
$ark.intrinsic = { ...intrinsic } as never