@typeslayer/validate 0.0.0 → 0.1.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.
@@ -0,0 +1 @@
1
+ export const CPU_PROFILE_FILENAME = "tsc.cpuprofile";
@@ -0,0 +1,17 @@
1
+ import type { ResolvedType } from "./types-json";
2
+
3
+ /**
4
+ * Think of a TypeRegistry like an object that you'd use to look up types by their ID.
5
+ *
6
+ */
7
+ export type TypeRegistry = ResolvedType[];
8
+
9
+ const ALL_LIFE_IS_SUFFERING_THAT_BASKS_IN_NOTHINGNESS___ALL_LIFE_IS_TEMPORARY___WHAT_LASTS_IS_CONSCIOUSNESS: [
10
+ ResolvedType,
11
+ ] = [{ id: 0, recursionId: -1, flags: [] }];
12
+
13
+ export const createTypeRegistry = (typesJson: ResolvedType[]): TypeRegistry => {
14
+ return ALL_LIFE_IS_SUFFERING_THAT_BASKS_IN_NOTHINGNESS___ALL_LIFE_IS_TEMPORARY___WHAT_LASTS_IS_CONSCIOUSNESS.concat(
15
+ typesJson,
16
+ );
17
+ };
@@ -0,0 +1,144 @@
1
+ import { z } from "zod/v4";
2
+ import { location, typeId } from "./utils";
3
+
4
+ export const TYPES_JSON_FILENAME = "types.json";
5
+
6
+ const flag = z.enum([
7
+ "Any",
8
+ "Unknown",
9
+ "String",
10
+ "Number",
11
+ "Boolean",
12
+ "Enum",
13
+ "BigInt",
14
+ "StringLiteral",
15
+ "NumberLiteral",
16
+ "BooleanLiteral",
17
+ "EnumLiteral",
18
+ "BigIntLiteral",
19
+ "ESSymbol",
20
+ "UniqueESSymbol",
21
+ "Void",
22
+ "Undefined",
23
+ "Null",
24
+ "Never",
25
+ "TypeParameter",
26
+ "Object",
27
+ "Union",
28
+ "Intersection",
29
+ "Index",
30
+ "IndexedAccess",
31
+ "Conditional",
32
+ "Substitution",
33
+ "NonPrimitive",
34
+ "TemplateLiteral",
35
+ "StringMapping",
36
+ "Reserved1",
37
+ "Reserved2",
38
+ "AnyOrUnknown",
39
+ "Nullable",
40
+ "Literal",
41
+ "Unit",
42
+ "Freshable",
43
+ "StringOrNumberLiteral",
44
+ "StringOrNumberLiteralOrUnique",
45
+ "DefinitelyFalsy",
46
+ "PossiblyFalsy",
47
+ "Intrinsic",
48
+ "StringLike",
49
+ "NumberLike",
50
+ "BigIntLike",
51
+ "BooleanLike",
52
+ "EnumLike",
53
+ "ESSymbolLike",
54
+ "VoidLike",
55
+ "Primitive",
56
+ "DefinitelyNonNullable",
57
+ "DisjointDomains",
58
+ "UnionOrIntersection",
59
+ "StructuredType",
60
+ "TypeVariable",
61
+ "InstantiableNonPrimitive",
62
+ "InstantiablePrimitive",
63
+ "Instantiable",
64
+ "StructuredOrInstantiable",
65
+ "ObjectFlagsType",
66
+ "Simplifiable",
67
+ "Singleton",
68
+ "Narrowable",
69
+ "IncludesMask",
70
+ "IncludesMissingType",
71
+ "IncludesNonWideningType",
72
+ "IncludesWildcard",
73
+ "IncludesEmptyObject",
74
+ "IncludesInstantiable",
75
+ "IncludesConstrainedTypeVariable",
76
+ "IncludesError",
77
+ "NotPrimitiveUnion",
78
+ ]);
79
+
80
+ export const resolvedType = z
81
+ .object({
82
+ id: typeId,
83
+ flags: z.array(flag),
84
+
85
+ recursionId: z.number().optional(),
86
+ intrinsicName: z
87
+ .enum([
88
+ "any",
89
+ "error",
90
+ "unresolved",
91
+ "unknown",
92
+ "true",
93
+ "false",
94
+ "never",
95
+ "void",
96
+ "symbol",
97
+ "bigint",
98
+ "null",
99
+ "undefined",
100
+ "intrinsic",
101
+ "object",
102
+ "boolean",
103
+ "number",
104
+ "string",
105
+ ])
106
+ .optional(),
107
+
108
+ firstDeclaration: location.optional(),
109
+ referenceLocation: location.optional(),
110
+ destructuringPattern: location.optional(),
111
+
112
+ // TODO, awards for all of these
113
+ typeArguments: z.array(typeId).optional(),
114
+ unionTypes: z.array(typeId).optional(),
115
+ intersectionTypes: z.array(typeId).optional(),
116
+ aliasTypeArguments: z.array(typeId).optional(),
117
+
118
+ instantiatedType: typeId.optional(),
119
+ substitutionBaseType: typeId.optional(),
120
+ constraintType: typeId.optional(),
121
+ indexedAccessObjectType: typeId.optional(),
122
+ indexedAccessIndexType: typeId.optional(),
123
+ conditionalCheckType: typeId.optional(),
124
+ conditionalExtendsType: typeId.optional(),
125
+ conditionalTrueType: typeId.optional(),
126
+ conditionalFalseType: typeId.optional(),
127
+ keyofType: typeId.optional(),
128
+ aliasType: typeId.optional(),
129
+ evolvingArrayElementType: typeId.optional(),
130
+ evolvingArrayFinalType: typeId.optional(),
131
+ reverseMappedSourceType: typeId.optional(),
132
+ reverseMappedMappedType: typeId.optional(),
133
+ reverseMappedConstraintType: typeId.optional(),
134
+
135
+ isTuple: z.literal(true).optional(),
136
+
137
+ symbolName: z.string().optional(),
138
+ display: z.string().optional(),
139
+ })
140
+ .strict();
141
+
142
+ export type ResolvedType = z.infer<typeof resolvedType>;
143
+ export const typesJsonSchema = z.array(resolvedType);
144
+ export type TypesJsonSchema = z.infer<typeof typesJsonSchema>;
package/src/utils.ts ADDED
@@ -0,0 +1,20 @@
1
+ import { z } from "zod/v4";
2
+
3
+ export const CPU_PROFILE_FILENAME = "tsc.cpuprofile";
4
+
5
+ export const typeId = z.number().int().positive().or(z.literal(-1));
6
+
7
+ export type TypeId = z.infer<typeof typeId>;
8
+
9
+ export const position = z.object({
10
+ line: typeId,
11
+ character: z.number(),
12
+ });
13
+
14
+ export const absolutePath = z.string();
15
+
16
+ export const location = z.object({
17
+ path: absolutePath,
18
+ start: position,
19
+ end: position,
20
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2024",
4
+ "module": "ES2022",
5
+ "moduleResolution": "bundler",
6
+ "declaration": true,
7
+ "outDir": "dist",
8
+ "strict": true,
9
+ "esModuleInterop": false,
10
+ "forceConsistentCasingInFileNames": true,
11
+ "noEmitOnError": true,
12
+ "resolveJsonModule": true,
13
+ "skipLibCheck": true
14
+ },
15
+ "include": ["**/*.ts"]
16
+ }
package/tsup.config.ts ADDED
@@ -0,0 +1,11 @@
1
+ import { defineConfig } from "tsup";
2
+
3
+ export default defineConfig({
4
+ entry: ["src/index.ts", "src/node.ts"],
5
+ format: ["esm"],
6
+ target: "es2024",
7
+ dts: true,
8
+ splitting: true,
9
+ sourcemap: true,
10
+ clean: true,
11
+ });