sql-typechecker 0.0.12 → 0.0.13
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/out/cli.js +123 -50
- package/out/cli.js.map +2 -2
- package/package.json +1 -1
package/out/cli.js
CHANGED
|
@@ -206264,7 +206264,7 @@ ${frame}`;
|
|
|
206264
206264
|
var require_comments = __commonJS22({
|
|
206265
206265
|
"src/main/comments.js"(exports22, module22) {
|
|
206266
206266
|
"use strict";
|
|
206267
|
-
var
|
|
206267
|
+
var assert2 = require("assert");
|
|
206268
206268
|
var {
|
|
206269
206269
|
builders: {
|
|
206270
206270
|
line,
|
|
@@ -206554,8 +206554,8 @@ ${frame}`;
|
|
|
206554
206554
|
precedingNode: currentCommentPrecedingNode,
|
|
206555
206555
|
followingNode: currentCommentFollowingNode
|
|
206556
206556
|
} = tiesToBreak[indexOfFirstLeadingComment - 1];
|
|
206557
|
-
|
|
206558
|
-
|
|
206557
|
+
assert2.strictEqual(currentCommentPrecedingNode, precedingNode);
|
|
206558
|
+
assert2.strictEqual(currentCommentFollowingNode, followingNode);
|
|
206559
206559
|
const gap = text.slice(options.locEnd(comment), gapEndPos);
|
|
206560
206560
|
if (gapRegExp.test(gap)) {
|
|
206561
206561
|
gapEndPos = options.locStart(comment);
|
|
@@ -207042,7 +207042,7 @@ ${frame}`;
|
|
|
207042
207042
|
var require_range_util = __commonJS22({
|
|
207043
207043
|
"src/main/range-util.js"(exports22, module22) {
|
|
207044
207044
|
"use strict";
|
|
207045
|
-
var
|
|
207045
|
+
var assert2 = require("assert");
|
|
207046
207046
|
var comments = require_comments();
|
|
207047
207047
|
var isJsonParser = ({
|
|
207048
207048
|
parser
|
|
@@ -207158,7 +207158,7 @@ ${frame}`;
|
|
|
207158
207158
|
locStart,
|
|
207159
207159
|
locEnd
|
|
207160
207160
|
} = opts;
|
|
207161
|
-
|
|
207161
|
+
assert2.ok(end > start);
|
|
207162
207162
|
const firstNonWhitespaceCharacterIndex = text.slice(start, end).search(/\S/);
|
|
207163
207163
|
const isAllWhitespace = firstNonWhitespaceCharacterIndex === -1;
|
|
207164
207164
|
if (!isAllWhitespace) {
|
|
@@ -225014,7 +225014,7 @@ ${fromBody}`;
|
|
|
225014
225014
|
var require_function = __commonJS22({
|
|
225015
225015
|
"src/language-js/print/function.js"(exports22, module22) {
|
|
225016
225016
|
"use strict";
|
|
225017
|
-
var
|
|
225017
|
+
var assert2 = require("assert");
|
|
225018
225018
|
var {
|
|
225019
225019
|
printDanglingComments,
|
|
225020
225020
|
printCommentsSeparately
|
|
@@ -225119,7 +225119,7 @@ ${fromBody}`;
|
|
|
225119
225119
|
parts.push("async ");
|
|
225120
225120
|
}
|
|
225121
225121
|
} else {
|
|
225122
|
-
|
|
225122
|
+
assert2.ok(kind === "get" || kind === "set");
|
|
225123
225123
|
parts.push(kind, " ");
|
|
225124
225124
|
}
|
|
225125
225125
|
if (value2.generator) {
|
|
@@ -226022,7 +226022,7 @@ ${fromBody}`;
|
|
|
226022
226022
|
var require_flow = __commonJS22({
|
|
226023
226023
|
"src/language-js/print/flow.js"(exports22, module22) {
|
|
226024
226024
|
"use strict";
|
|
226025
|
-
var
|
|
226025
|
+
var assert2 = require("assert");
|
|
226026
226026
|
var {
|
|
226027
226027
|
printDanglingComments
|
|
226028
226028
|
} = require_comments();
|
|
@@ -226198,7 +226198,7 @@ ${fromBody}`;
|
|
|
226198
226198
|
const {
|
|
226199
226199
|
kind
|
|
226200
226200
|
} = node;
|
|
226201
|
-
|
|
226201
|
+
assert2.ok(kind === "plus" || kind === "minus");
|
|
226202
226202
|
return kind === "plus" ? "+" : "-";
|
|
226203
226203
|
}
|
|
226204
226204
|
case "ObjectTypeCallProperty":
|
|
@@ -226231,7 +226231,7 @@ ${fromBody}`;
|
|
|
226231
226231
|
case "StringLiteralTypeAnnotation":
|
|
226232
226232
|
return printString(rawText(node), options);
|
|
226233
226233
|
case "NumberLiteralTypeAnnotation":
|
|
226234
|
-
|
|
226234
|
+
assert2.strictEqual(typeof node.value, "number");
|
|
226235
226235
|
case "BigIntLiteralTypeAnnotation":
|
|
226236
226236
|
if (node.extra) {
|
|
226237
226237
|
return printNumber(node.extra.raw);
|
|
@@ -226299,7 +226299,7 @@ ${fromBody}`;
|
|
|
226299
226299
|
function printFlowDeclaration(path2, printed) {
|
|
226300
226300
|
const parentExportDecl = getParentExportDeclaration(path2);
|
|
226301
226301
|
if (parentExportDecl) {
|
|
226302
|
-
|
|
226302
|
+
assert2.strictEqual(parentExportDecl.type, "DeclareExportDeclaration");
|
|
226303
226303
|
return printed;
|
|
226304
226304
|
}
|
|
226305
226305
|
return ["declare ", printed];
|
|
@@ -233598,7 +233598,7 @@ ${extracted.content}`;
|
|
|
233598
233598
|
var require_tag = __commonJS22({
|
|
233599
233599
|
"src/language-html/print/tag.js"(exports22, module22) {
|
|
233600
233600
|
"use strict";
|
|
233601
|
-
var
|
|
233601
|
+
var assert2 = require("assert");
|
|
233602
233602
|
var {
|
|
233603
233603
|
isNonEmptyArray
|
|
233604
233604
|
} = require_util();
|
|
@@ -233642,7 +233642,7 @@ ${extracted.content}`;
|
|
|
233642
233642
|
return needsToBorrowParentClosingTagStartMarker(node) ? printClosingTagStartMarker(node.parent, options) : needsToBorrowNextOpeningTagStartMarker(node) ? printOpeningTagStartMarker(node.next) : "";
|
|
233643
233643
|
}
|
|
233644
233644
|
function printClosingTagStartMarker(node, options) {
|
|
233645
|
-
|
|
233645
|
+
assert2(!node.isSelfClosing);
|
|
233646
233646
|
if (shouldNotPrintClosingTag(node, options)) {
|
|
233647
233647
|
return "";
|
|
233648
233648
|
}
|
|
@@ -233760,7 +233760,7 @@ ${extracted.content}`;
|
|
|
233760
233760
|
}
|
|
233761
233761
|
}
|
|
233762
233762
|
function printOpeningTagEndMarker(node) {
|
|
233763
|
-
|
|
233763
|
+
assert2(!node.isSelfClosing);
|
|
233764
233764
|
switch (node.type) {
|
|
233765
233765
|
case "ieConditionalComment":
|
|
233766
233766
|
return "]>";
|
|
@@ -235901,6 +235901,7 @@ var import_pgsql_ast_parser2 = __toModule(require_lib());
|
|
|
235901
235901
|
var prettier = __toModule(require_prettier());
|
|
235902
235902
|
|
|
235903
235903
|
// src/typecheck.ts
|
|
235904
|
+
var import_assert = __toModule(require("assert"));
|
|
235904
235905
|
var import_pgsql_ast_parser = __toModule(require_lib());
|
|
235905
235906
|
|
|
235906
235907
|
// src/normalize.ts
|
|
@@ -242017,7 +242018,24 @@ function deriveNameFromExpr(expr) {
|
|
|
242017
242018
|
}
|
|
242018
242019
|
function elabSelect(g, c, s) {
|
|
242019
242020
|
if (s.type === "select") {
|
|
242020
|
-
const newC =
|
|
242021
|
+
const newC = (() => {
|
|
242022
|
+
const newC_ = addFromsToScope(g, c, s, s.from || []);
|
|
242023
|
+
const inferredNullability = s.where ? inferNullability(newC_, s.where) : [];
|
|
242024
|
+
return {
|
|
242025
|
+
...newC_,
|
|
242026
|
+
froms: newC_.froms.map((fr) => ({
|
|
242027
|
+
name: fr.name,
|
|
242028
|
+
type: {
|
|
242029
|
+
kind: "record",
|
|
242030
|
+
fields: fr.type.fields.map((fi) => {
|
|
242031
|
+
const foundNullabilityInference = inferredNullability.find((inf) => eqQNames(inf.fromName, fr.name) && inf.fieldName === fi.name?.name);
|
|
242032
|
+
const t = foundNullabilityInference ? foundNullabilityInference.isNull === true ? nullify(fi.type) : unnullify(fi.type) : fi.type;
|
|
242033
|
+
return {name: fi.name, type: t};
|
|
242034
|
+
})
|
|
242035
|
+
}
|
|
242036
|
+
}))
|
|
242037
|
+
};
|
|
242038
|
+
})();
|
|
242021
242039
|
if (s.where) {
|
|
242022
242040
|
const t = elabExpr(g, newC, s.where);
|
|
242023
242041
|
requireBoolean(s.where, t);
|
|
@@ -242231,6 +242249,9 @@ function doCreateFunction(g, c, s) {
|
|
|
242231
242249
|
if (!s.language) {
|
|
242232
242250
|
throw new Error("Please provide language for function at " + showLocation(s._location));
|
|
242233
242251
|
}
|
|
242252
|
+
if (s.code === void 0) {
|
|
242253
|
+
throw new ErrorWithLocation(s._location, "Function definition without body");
|
|
242254
|
+
}
|
|
242234
242255
|
if (s.language && s.language.name.toLowerCase() === "sql") {
|
|
242235
242256
|
const inputs = s.arguments.map((arg) => {
|
|
242236
242257
|
if (!arg.name) {
|
|
@@ -242580,45 +242601,66 @@ function elabRef(c, e) {
|
|
|
242580
242601
|
};
|
|
242581
242602
|
}
|
|
242582
242603
|
} else {
|
|
242583
|
-
const
|
|
242584
|
-
if (
|
|
242585
|
-
|
|
242586
|
-
|
|
242587
|
-
|
|
242588
|
-
|
|
242589
|
-
|
|
242590
|
-
|
|
242604
|
+
const found = lookupRef(c, e);
|
|
242605
|
+
if (found instanceof Error) {
|
|
242606
|
+
throw found;
|
|
242607
|
+
} else {
|
|
242608
|
+
return found.type;
|
|
242609
|
+
}
|
|
242610
|
+
}
|
|
242611
|
+
}
|
|
242612
|
+
function lookupRef(c, e) {
|
|
242613
|
+
import_assert.default(e.name !== "*");
|
|
242614
|
+
const tableName = e.table;
|
|
242615
|
+
if (tableName) {
|
|
242616
|
+
const table = c.froms.find((d) => eqQNames(d.name, tableName));
|
|
242617
|
+
if (!table) {
|
|
242618
|
+
return new UnknownIdentifier(e, tableName);
|
|
242619
|
+
}
|
|
242620
|
+
if (!(table.type.kind === "record")) {
|
|
242621
|
+
return new KindMismatch(e, table.type, "Expecting Record");
|
|
242622
|
+
}
|
|
242623
|
+
const field = lookupInRecord(table.type, e);
|
|
242624
|
+
if (!field) {
|
|
242625
|
+
return new UnknownField(e, table.type, e);
|
|
242626
|
+
}
|
|
242627
|
+
return {
|
|
242628
|
+
type: field,
|
|
242629
|
+
from: {
|
|
242630
|
+
fromName: tableName,
|
|
242631
|
+
fieldName: e.name
|
|
242591
242632
|
}
|
|
242592
|
-
|
|
242593
|
-
|
|
242594
|
-
|
|
242633
|
+
};
|
|
242634
|
+
} else {
|
|
242635
|
+
const foundFields = mapPartial(c.froms, (t) => {
|
|
242636
|
+
const foundfield = lookupInRecord(t.type, e);
|
|
242637
|
+
return foundfield ? {fromName: t.name, field: e, type: foundfield} : null;
|
|
242638
|
+
});
|
|
242639
|
+
const foundIdentifiers = mapPartial(c.decls, (t) => {
|
|
242640
|
+
if (t.type.kind === "record" || t.type.kind === "void") {
|
|
242641
|
+
return null;
|
|
242642
|
+
} else {
|
|
242643
|
+
return t.name.name === e.name ? {name: t.name.name, type: t.type} : null;
|
|
242595
242644
|
}
|
|
242596
|
-
|
|
242597
|
-
|
|
242598
|
-
|
|
242599
|
-
|
|
242600
|
-
|
|
242601
|
-
|
|
242602
|
-
const foundIdentifiers = mapPartial(c.decls, (t) => {
|
|
242603
|
-
if (t.type.kind === "record" || t.type.kind === "void") {
|
|
242604
|
-
return null;
|
|
242605
|
-
} else {
|
|
242606
|
-
return t.name.name === e.name ? {name: t.name.name, type: t.type} : null;
|
|
242607
|
-
}
|
|
242608
|
-
});
|
|
242609
|
-
if (foundFields.length === 0) {
|
|
242610
|
-
if (foundIdentifiers.length === 0) {
|
|
242611
|
-
throw new UnknownIdentifier(e, e);
|
|
242612
|
-
} else if (foundIdentifiers.length === 1) {
|
|
242613
|
-
return foundIdentifiers[0].type;
|
|
242614
|
-
} else {
|
|
242615
|
-
throw new AmbiguousIdentifier(e, e, []);
|
|
242616
|
-
}
|
|
242617
|
-
} else if (foundFields.length === 1) {
|
|
242618
|
-
return foundFields[0].type;
|
|
242645
|
+
});
|
|
242646
|
+
if (foundFields.length === 0) {
|
|
242647
|
+
if (foundIdentifiers.length === 0) {
|
|
242648
|
+
return new UnknownIdentifier(e, e);
|
|
242649
|
+
} else if (foundIdentifiers.length === 1) {
|
|
242650
|
+
return {type: foundIdentifiers[0].type, from: null};
|
|
242619
242651
|
} else {
|
|
242620
|
-
|
|
242652
|
+
return new AmbiguousIdentifier(e, e, []);
|
|
242621
242653
|
}
|
|
242654
|
+
} else if (foundFields.length === 1) {
|
|
242655
|
+
return {
|
|
242656
|
+
type: foundFields[0].type,
|
|
242657
|
+
from: {
|
|
242658
|
+
fromName: foundFields[0].fromName,
|
|
242659
|
+
fieldName: foundFields[0].field.name
|
|
242660
|
+
}
|
|
242661
|
+
};
|
|
242662
|
+
} else {
|
|
242663
|
+
return new AmbiguousIdentifier(e, e, foundFields.map((f) => f.fromName));
|
|
242622
242664
|
}
|
|
242623
242665
|
}
|
|
242624
242666
|
}
|
|
@@ -243016,6 +243058,37 @@ function elabExpr(g, c, e) {
|
|
|
243016
243058
|
return checkAllCasesHandled(e.type);
|
|
243017
243059
|
}
|
|
243018
243060
|
}
|
|
243061
|
+
function inferNullability(c, e) {
|
|
243062
|
+
if (e.type === "unary") {
|
|
243063
|
+
if (e.op === "NOT") {
|
|
243064
|
+
return inferNullability(c, e).map((judg) => ({
|
|
243065
|
+
...judg,
|
|
243066
|
+
isNull: !judg.isNull
|
|
243067
|
+
}));
|
|
243068
|
+
}
|
|
243069
|
+
if (e.op === "IS NULL" || e.op === "IS NOT NULL") {
|
|
243070
|
+
if (e.operand.type === "ref") {
|
|
243071
|
+
const found = lookupRef(c, e.operand);
|
|
243072
|
+
if (found instanceof Error) {
|
|
243073
|
+
return [];
|
|
243074
|
+
} else {
|
|
243075
|
+
if (found.from === null) {
|
|
243076
|
+
return [];
|
|
243077
|
+
} else {
|
|
243078
|
+
return [
|
|
243079
|
+
{...found.from, isNull: e.op === "IS NULL" ? true : false}
|
|
243080
|
+
];
|
|
243081
|
+
}
|
|
243082
|
+
}
|
|
243083
|
+
}
|
|
243084
|
+
}
|
|
243085
|
+
return [];
|
|
243086
|
+
} else if (e.type === "binary" && e.op === "AND") {
|
|
243087
|
+
return inferNullability(c, e.left).concat(inferNullability(c, e.right));
|
|
243088
|
+
} else {
|
|
243089
|
+
return [];
|
|
243090
|
+
}
|
|
243091
|
+
}
|
|
243019
243092
|
function elabStatement(g, c, s) {
|
|
243020
243093
|
if (s.type === "select" || s.type === "union" || s.type === "union all" || s.type === "with" || s.type === "with recursive" || s.type === "values") {
|
|
243021
243094
|
return elabExpr(g, c, s);
|