sql-typechecker 0.0.1
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/.envrc +2 -0
- package/esbuild.js +12 -0
- package/package.json +28 -0
- package/sample/nested/sample2.sql +7 -0
- package/sample/out.ts +13 -0
- package/sample/sample1.sql +10 -0
- package/school/out.ts +59 -0
- package/school/sql.sql +985 -0
- package/shell.nix +16 -0
- package/src/builtincasts.ts +277 -0
- package/src/builtinoperators.ts +5144 -0
- package/src/builtinunaryoperators.ts +291 -0
- package/src/cli.ts +187 -0
- package/src/readme.md +23 -0
- package/src/typecheck.ts +1869 -0
- package/template1.sql +43 -0
- package/test/test.ts +1378 -0
- package/tsconfig.json +20 -0
package/shell.nix
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
let
|
|
2
|
+
pinnedNixpkgs = import (builtins.fetchTarball {
|
|
3
|
+
name = "pinned-nixpkgs-for-tsc-test";
|
|
4
|
+
url = https://github.com/NixOS/nixpkgs/archive/20.09.tar.gz;
|
|
5
|
+
# Hash obtained using `nix-prefetch-url --unpack <url>`
|
|
6
|
+
# sha256 = "0mhqhq21y5vrr1f30qd2bvydv4bbbslvyzclhw0kdxmkgg3z4c92";
|
|
7
|
+
}) {};
|
|
8
|
+
in
|
|
9
|
+
{ pkgs ? pinnedNixpkgs }:
|
|
10
|
+
|
|
11
|
+
pkgs.stdenv.mkDerivation rec {
|
|
12
|
+
name = "test-typescript";
|
|
13
|
+
buildInputs = [
|
|
14
|
+
pkgs.nodejs-14_x
|
|
15
|
+
];
|
|
16
|
+
}
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { CastType, ScalarT } from "./typecheck";
|
|
2
|
+
|
|
3
|
+
export const builtincasts: {
|
|
4
|
+
source: ScalarT;
|
|
5
|
+
target: ScalarT;
|
|
6
|
+
type: CastType;
|
|
7
|
+
}[] = [
|
|
8
|
+
{ source: "bigint", target: "bit", type: "no" },
|
|
9
|
+
{ source: "bigint", target: "double precision", type: "yes" },
|
|
10
|
+
{ source: "bigint", target: "integer", type: "in assignment" },
|
|
11
|
+
{ source: "bigint", target: "money", type: "in assignment" },
|
|
12
|
+
{ source: "bigint", target: "numeric", type: "yes" },
|
|
13
|
+
{ source: "bigint", target: "oid", type: "yes" },
|
|
14
|
+
{ source: "bigint", target: "real", type: "yes" },
|
|
15
|
+
{ source: "bigint", target: "regclass", type: "yes" },
|
|
16
|
+
{ source: "bigint", target: "regconfig", type: "yes" },
|
|
17
|
+
{ source: "bigint", target: "regdictionary", type: "yes" },
|
|
18
|
+
{ source: "bigint", target: "regnamespace", type: "yes" },
|
|
19
|
+
{ source: "bigint", target: "regoper", type: "yes" },
|
|
20
|
+
{ source: "bigint", target: "regoperator", type: "yes" },
|
|
21
|
+
{ source: "bigint", target: "regproc", type: "yes" },
|
|
22
|
+
{ source: "bigint", target: "regprocedure", type: "yes" },
|
|
23
|
+
{ source: "bigint", target: "regrole", type: "yes" },
|
|
24
|
+
{ source: "bigint", target: "regtype", type: "yes" },
|
|
25
|
+
{ source: "bigint", target: "smallint", type: "in assignment" },
|
|
26
|
+
{ source: "bit", target: "bigint", type: "no" },
|
|
27
|
+
{ source: "bit", target: "bit", type: "yes" },
|
|
28
|
+
{ source: "bit", target: "bit varying", type: "yes" },
|
|
29
|
+
{ source: "bit", target: "integer", type: "no" },
|
|
30
|
+
{ source: "bit varying", target: "bit", type: "yes" },
|
|
31
|
+
{ source: "bit varying", target: "bit varying", type: "yes" },
|
|
32
|
+
{ source: "boolean", target: "character", type: "in assignment" },
|
|
33
|
+
{ source: "boolean", target: "character varying", type: "in assignment" },
|
|
34
|
+
{ source: "boolean", target: "integer", type: "no" },
|
|
35
|
+
{ source: "boolean", target: "text", type: "in assignment" },
|
|
36
|
+
{ source: "box", target: "circle", type: "no" },
|
|
37
|
+
{ source: "box", target: "lseg", type: "no" },
|
|
38
|
+
{ source: "box", target: "point", type: "no" },
|
|
39
|
+
{ source: "box", target: "polygon", type: "in assignment" },
|
|
40
|
+
{ source: "char", target: "character", type: "in assignment" },
|
|
41
|
+
{ source: "char", target: "character varying", type: "in assignment" },
|
|
42
|
+
{ source: "char", target: "integer", type: "no" },
|
|
43
|
+
{ source: "char", target: "text", type: "yes" },
|
|
44
|
+
{ source: "character", target: "char", type: "in assignment" },
|
|
45
|
+
{ source: "character", target: "character", type: "yes" },
|
|
46
|
+
{ source: "character", target: "character varying", type: "yes" },
|
|
47
|
+
{ source: "character", target: "name", type: "yes" },
|
|
48
|
+
{ source: "character", target: "text", type: "yes" },
|
|
49
|
+
{ source: "character", target: "xml", type: "no" },
|
|
50
|
+
{ source: "character varying", target: "char", type: "in assignment" },
|
|
51
|
+
{ source: "character varying", target: "character", type: "yes" },
|
|
52
|
+
{ source: "character varying", target: "character varying", type: "yes" },
|
|
53
|
+
{ source: "character varying", target: "name", type: "yes" },
|
|
54
|
+
{ source: "character varying", target: "regclass", type: "yes" },
|
|
55
|
+
{ source: "character varying", target: "text", type: "yes" },
|
|
56
|
+
{ source: "character varying", target: "xml", type: "no" },
|
|
57
|
+
{ source: "cidr", target: "character", type: "in assignment" },
|
|
58
|
+
{ source: "cidr", target: "character varying", type: "in assignment" },
|
|
59
|
+
{ source: "cidr", target: "inet", type: "yes" },
|
|
60
|
+
{ source: "cidr", target: "text", type: "in assignment" },
|
|
61
|
+
{ source: "circle", target: "box", type: "no" },
|
|
62
|
+
{ source: "circle", target: "point", type: "no" },
|
|
63
|
+
{ source: "circle", target: "polygon", type: "no" },
|
|
64
|
+
{ source: "date", target: "timestamp without time zone", type: "yes" },
|
|
65
|
+
{ source: "date", target: "timestamp with time zone", type: "yes" },
|
|
66
|
+
{ source: "double precision", target: "bigint", type: "in assignment" },
|
|
67
|
+
{ source: "double precision", target: "integer", type: "in assignment" },
|
|
68
|
+
{ source: "double precision", target: "numeric", type: "in assignment" },
|
|
69
|
+
{ source: "double precision", target: "real", type: "in assignment" },
|
|
70
|
+
{ source: "double precision", target: "smallint", type: "in assignment" },
|
|
71
|
+
{ source: "inet", target: "character", type: "in assignment" },
|
|
72
|
+
{ source: "inet", target: "character varying", type: "in assignment" },
|
|
73
|
+
{ source: "inet", target: "cidr", type: "in assignment" },
|
|
74
|
+
{ source: "inet", target: "text", type: "in assignment" },
|
|
75
|
+
{ source: "integer", target: "bigint", type: "yes" },
|
|
76
|
+
{ source: "integer", target: "bit", type: "no" },
|
|
77
|
+
{ source: "integer", target: "boolean", type: "no" },
|
|
78
|
+
{ source: "integer", target: "char", type: "no" },
|
|
79
|
+
{ source: "integer", target: "double precision", type: "yes" },
|
|
80
|
+
{ source: "integer", target: "money", type: "in assignment" },
|
|
81
|
+
{ source: "integer", target: "numeric", type: "yes" },
|
|
82
|
+
{ source: "integer", target: "oid", type: "yes" },
|
|
83
|
+
{ source: "integer", target: "real", type: "yes" },
|
|
84
|
+
{ source: "integer", target: "regclass", type: "yes" },
|
|
85
|
+
{ source: "integer", target: "regconfig", type: "yes" },
|
|
86
|
+
{ source: "integer", target: "regdictionary", type: "yes" },
|
|
87
|
+
{ source: "integer", target: "regnamespace", type: "yes" },
|
|
88
|
+
{ source: "integer", target: "regoper", type: "yes" },
|
|
89
|
+
{ source: "integer", target: "regoperator", type: "yes" },
|
|
90
|
+
{ source: "integer", target: "regproc", type: "yes" },
|
|
91
|
+
{ source: "integer", target: "regprocedure", type: "yes" },
|
|
92
|
+
{ source: "integer", target: "regrole", type: "yes" },
|
|
93
|
+
{ source: "integer", target: "regtype", type: "yes" },
|
|
94
|
+
{ source: "integer", target: "smallint", type: "in assignment" },
|
|
95
|
+
{ source: "interval", target: "interval", type: "yes" },
|
|
96
|
+
{
|
|
97
|
+
source: "interval",
|
|
98
|
+
target: "time without time zone",
|
|
99
|
+
type: "in assignment",
|
|
100
|
+
},
|
|
101
|
+
{ source: "json", target: "jsonb", type: "in assignment" },
|
|
102
|
+
{ source: "jsonb", target: "bigint", type: "no" },
|
|
103
|
+
{ source: "jsonb", target: "boolean", type: "no" },
|
|
104
|
+
{ source: "jsonb", target: "double precision", type: "no" },
|
|
105
|
+
{ source: "jsonb", target: "integer", type: "no" },
|
|
106
|
+
{ source: "jsonb", target: "json", type: "in assignment" },
|
|
107
|
+
{ source: "jsonb", target: "numeric", type: "no" },
|
|
108
|
+
{ source: "jsonb", target: "real", type: "no" },
|
|
109
|
+
{ source: "jsonb", target: "smallint", type: "no" },
|
|
110
|
+
{ source: "lseg", target: "point", type: "no" },
|
|
111
|
+
{ source: "macaddr", target: "macaddr8", type: "yes" },
|
|
112
|
+
{ source: "macaddr8", target: "macaddr", type: "yes" },
|
|
113
|
+
{ source: "money", target: "numeric", type: "in assignment" },
|
|
114
|
+
{ source: "name", target: "character", type: "in assignment" },
|
|
115
|
+
{ source: "name", target: "character varying", type: "in assignment" },
|
|
116
|
+
{ source: "name", target: "text", type: "yes" },
|
|
117
|
+
{ source: "numeric", target: "bigint", type: "in assignment" },
|
|
118
|
+
{ source: "numeric", target: "double precision", type: "yes" },
|
|
119
|
+
{ source: "numeric", target: "integer", type: "in assignment" },
|
|
120
|
+
{ source: "numeric", target: "money", type: "in assignment" },
|
|
121
|
+
{ source: "numeric", target: "numeric", type: "yes" },
|
|
122
|
+
{ source: "numeric", target: "real", type: "yes" },
|
|
123
|
+
{ source: "numeric", target: "smallint", type: "in assignment" },
|
|
124
|
+
{ source: "oid", target: "bigint", type: "in assignment" },
|
|
125
|
+
{ source: "oid", target: "integer", type: "in assignment" },
|
|
126
|
+
{ source: "oid", target: "regclass", type: "yes" },
|
|
127
|
+
{ source: "oid", target: "regconfig", type: "yes" },
|
|
128
|
+
{ source: "oid", target: "regdictionary", type: "yes" },
|
|
129
|
+
{ source: "oid", target: "regnamespace", type: "yes" },
|
|
130
|
+
{ source: "oid", target: "regoper", type: "yes" },
|
|
131
|
+
{ source: "oid", target: "regoperator", type: "yes" },
|
|
132
|
+
{ source: "oid", target: "regproc", type: "yes" },
|
|
133
|
+
{ source: "oid", target: "regprocedure", type: "yes" },
|
|
134
|
+
{ source: "oid", target: "regrole", type: "yes" },
|
|
135
|
+
{ source: "oid", target: "regtype", type: "yes" },
|
|
136
|
+
{ source: "path", target: "point", type: "no" },
|
|
137
|
+
{ source: "path", target: "polygon", type: "in assignment" },
|
|
138
|
+
{ source: "pg_dependencies", target: "bytea", type: "yes" },
|
|
139
|
+
{ source: "pg_dependencies", target: "text", type: "yes" },
|
|
140
|
+
{ source: "pg_mcv_list", target: "bytea", type: "yes" },
|
|
141
|
+
{ source: "pg_mcv_list", target: "text", type: "yes" },
|
|
142
|
+
{ source: "pg_ndistinct", target: "bytea", type: "yes" },
|
|
143
|
+
{ source: "pg_ndistinct", target: "text", type: "yes" },
|
|
144
|
+
{ source: "pg_node_tree", target: "text", type: "yes" },
|
|
145
|
+
{ source: "point", target: "box", type: "in assignment" },
|
|
146
|
+
{ source: "polygon", target: "box", type: "no" },
|
|
147
|
+
{ source: "polygon", target: "circle", type: "no" },
|
|
148
|
+
{ source: "polygon", target: "path", type: "in assignment" },
|
|
149
|
+
{ source: "polygon", target: "point", type: "no" },
|
|
150
|
+
{ source: "real", target: "bigint", type: "in assignment" },
|
|
151
|
+
{ source: "real", target: "double precision", type: "yes" },
|
|
152
|
+
{ source: "real", target: "integer", type: "in assignment" },
|
|
153
|
+
{ source: "real", target: "numeric", type: "in assignment" },
|
|
154
|
+
{ source: "real", target: "smallint", type: "in assignment" },
|
|
155
|
+
{ source: "regclass", target: "bigint", type: "in assignment" },
|
|
156
|
+
{ source: "regclass", target: "integer", type: "in assignment" },
|
|
157
|
+
{ source: "regclass", target: "oid", type: "yes" },
|
|
158
|
+
{ source: "regconfig", target: "bigint", type: "in assignment" },
|
|
159
|
+
{ source: "regconfig", target: "integer", type: "in assignment" },
|
|
160
|
+
{ source: "regconfig", target: "oid", type: "yes" },
|
|
161
|
+
{ source: "regdictionary", target: "bigint", type: "in assignment" },
|
|
162
|
+
{ source: "regdictionary", target: "integer", type: "in assignment" },
|
|
163
|
+
{ source: "regdictionary", target: "oid", type: "yes" },
|
|
164
|
+
{ source: "regnamespace", target: "bigint", type: "in assignment" },
|
|
165
|
+
{ source: "regnamespace", target: "integer", type: "in assignment" },
|
|
166
|
+
{ source: "regnamespace", target: "oid", type: "yes" },
|
|
167
|
+
{ source: "regoper", target: "bigint", type: "in assignment" },
|
|
168
|
+
{ source: "regoper", target: "integer", type: "in assignment" },
|
|
169
|
+
{ source: "regoper", target: "oid", type: "yes" },
|
|
170
|
+
{ source: "regoper", target: "regoperator", type: "yes" },
|
|
171
|
+
{ source: "regoperator", target: "bigint", type: "in assignment" },
|
|
172
|
+
{ source: "regoperator", target: "integer", type: "in assignment" },
|
|
173
|
+
{ source: "regoperator", target: "oid", type: "yes" },
|
|
174
|
+
{ source: "regoperator", target: "regoper", type: "yes" },
|
|
175
|
+
{ source: "regproc", target: "bigint", type: "in assignment" },
|
|
176
|
+
{ source: "regproc", target: "integer", type: "in assignment" },
|
|
177
|
+
{ source: "regproc", target: "oid", type: "yes" },
|
|
178
|
+
{ source: "regproc", target: "regprocedure", type: "yes" },
|
|
179
|
+
{ source: "regprocedure", target: "bigint", type: "in assignment" },
|
|
180
|
+
{ source: "regprocedure", target: "integer", type: "in assignment" },
|
|
181
|
+
{ source: "regprocedure", target: "oid", type: "yes" },
|
|
182
|
+
{ source: "regprocedure", target: "regproc", type: "yes" },
|
|
183
|
+
{ source: "regrole", target: "bigint", type: "in assignment" },
|
|
184
|
+
{ source: "regrole", target: "integer", type: "in assignment" },
|
|
185
|
+
{ source: "regrole", target: "oid", type: "yes" },
|
|
186
|
+
{ source: "regtype", target: "bigint", type: "in assignment" },
|
|
187
|
+
{ source: "regtype", target: "integer", type: "in assignment" },
|
|
188
|
+
{ source: "regtype", target: "oid", type: "yes" },
|
|
189
|
+
{ source: "smallint", target: "bigint", type: "yes" },
|
|
190
|
+
{ source: "smallint", target: "double precision", type: "yes" },
|
|
191
|
+
{ source: "smallint", target: "integer", type: "yes" },
|
|
192
|
+
{ source: "smallint", target: "numeric", type: "yes" },
|
|
193
|
+
{ source: "smallint", target: "oid", type: "yes" },
|
|
194
|
+
{ source: "smallint", target: "real", type: "yes" },
|
|
195
|
+
{ source: "smallint", target: "regclass", type: "yes" },
|
|
196
|
+
{ source: "smallint", target: "regconfig", type: "yes" },
|
|
197
|
+
{ source: "smallint", target: "regdictionary", type: "yes" },
|
|
198
|
+
{ source: "smallint", target: "regnamespace", type: "yes" },
|
|
199
|
+
{ source: "smallint", target: "regoper", type: "yes" },
|
|
200
|
+
{ source: "smallint", target: "regoperator", type: "yes" },
|
|
201
|
+
{ source: "smallint", target: "regproc", type: "yes" },
|
|
202
|
+
{ source: "smallint", target: "regprocedure", type: "yes" },
|
|
203
|
+
{ source: "smallint", target: "regrole", type: "yes" },
|
|
204
|
+
{ source: "smallint", target: "regtype", type: "yes" },
|
|
205
|
+
{ source: "text", target: "char", type: "in assignment" },
|
|
206
|
+
{ source: "text", target: "character", type: "yes" },
|
|
207
|
+
{ source: "text", target: "character varying", type: "yes" },
|
|
208
|
+
{ source: "text", target: "name", type: "yes" },
|
|
209
|
+
{ source: "text", target: "regclass", type: "yes" },
|
|
210
|
+
{ source: "text", target: "xml", type: "no" },
|
|
211
|
+
{
|
|
212
|
+
source: "timestamp without time zone",
|
|
213
|
+
target: "date",
|
|
214
|
+
type: "in assignment",
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
source: "timestamp without time zone",
|
|
218
|
+
target: "timestamp without time zone",
|
|
219
|
+
type: "yes",
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
source: "timestamp without time zone",
|
|
223
|
+
target: "timestamp with time zone",
|
|
224
|
+
type: "yes",
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
source: "timestamp without time zone",
|
|
228
|
+
target: "time without time zone",
|
|
229
|
+
type: "in assignment",
|
|
230
|
+
},
|
|
231
|
+
{ source: "timestamp with time zone", target: "date", type: "in assignment" },
|
|
232
|
+
{
|
|
233
|
+
source: "timestamp with time zone",
|
|
234
|
+
target: "timestamp without time zone",
|
|
235
|
+
type: "in assignment",
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
source: "timestamp with time zone",
|
|
239
|
+
target: "timestamp with time zone",
|
|
240
|
+
type: "yes",
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
source: "timestamp with time zone",
|
|
244
|
+
target: "time without time zone",
|
|
245
|
+
type: "in assignment",
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
source: "timestamp with time zone",
|
|
249
|
+
target: "time with time zone",
|
|
250
|
+
type: "in assignment",
|
|
251
|
+
},
|
|
252
|
+
{ source: "time without time zone", target: "interval", type: "yes" },
|
|
253
|
+
{
|
|
254
|
+
source: "time without time zone",
|
|
255
|
+
target: "time without time zone",
|
|
256
|
+
type: "yes",
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
source: "time without time zone",
|
|
260
|
+
target: "time with time zone",
|
|
261
|
+
type: "yes",
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
source: "time with time zone",
|
|
265
|
+
target: "time without time zone",
|
|
266
|
+
type: "in assignment",
|
|
267
|
+
},
|
|
268
|
+
{ source: "time with time zone", target: "time with time zone", type: "yes" },
|
|
269
|
+
{ source: "xml", target: "character", type: "in assignment" },
|
|
270
|
+
{ source: "xml", target: "character varying", type: "in assignment" },
|
|
271
|
+
{ source: "xml", target: "text", type: "in assignment" },
|
|
272
|
+
].map((s) => ({
|
|
273
|
+
source: { kind: "scalar", name: { name: s.source } },
|
|
274
|
+
target: { kind: "scalar", name: { name: s.target } },
|
|
275
|
+
type:
|
|
276
|
+
s.type === "no" ? "explicit" : s.type === "yes" ? "implicit" : "assignment",
|
|
277
|
+
}));
|