sql-typechecker 0.0.25 → 0.0.28
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 +42 -17
- package/out/cli.js.map +2 -2
- package/package.json +1 -1
package/out/cli.js
CHANGED
|
@@ -241797,10 +241797,11 @@ function unifyRecords(e, source, target) {
|
|
|
241797
241797
|
}
|
|
241798
241798
|
const newFields = source.fields.map((sf, i) => {
|
|
241799
241799
|
const tf = target.fields[i];
|
|
241800
|
-
const t = unifySimples(e, sf.type, tf.type);
|
|
241800
|
+
const t = unifySimples(tf.expr || e, sf.type, tf.type);
|
|
241801
241801
|
return {
|
|
241802
241802
|
name: sf.name || tf.name,
|
|
241803
|
-
type: t
|
|
241803
|
+
type: t,
|
|
241804
|
+
expr: tf.expr
|
|
241804
241805
|
};
|
|
241805
241806
|
});
|
|
241806
241807
|
return {
|
|
@@ -241976,7 +241977,8 @@ function doCreateTable(g, s) {
|
|
|
241976
241977
|
} else {
|
|
241977
241978
|
return acc.concat({
|
|
241978
241979
|
name: c.name,
|
|
241979
|
-
type: mkType(c.dataType, c.constraints || [])
|
|
241980
|
+
type: mkType(c.dataType, c.constraints || []),
|
|
241981
|
+
expr: null
|
|
241980
241982
|
});
|
|
241981
241983
|
}
|
|
241982
241984
|
}, []);
|
|
@@ -242051,7 +242053,7 @@ function elabSelect(g, c, s) {
|
|
|
242051
242053
|
const foundNullabilityInference = inferredNullability.find((inf) => eqQNames(inf.fromName, fr.name) && inf.fieldName === fi.name?.name);
|
|
242052
242054
|
if (foundNullabilityInference && isNullable(fi.type)) {
|
|
242053
242055
|
const t = foundNullabilityInference.isNull === true ? BuiltinTypes.Null : unnullify(fi.type);
|
|
242054
|
-
return {name: fi.name, type: t};
|
|
242056
|
+
return {name: fi.name, type: t, expr: fi.expr};
|
|
242055
242057
|
} else {
|
|
242056
242058
|
return fi;
|
|
242057
242059
|
}
|
|
@@ -242081,7 +242083,7 @@ function elabSelect(g, c, s) {
|
|
|
242081
242083
|
if (c2.expr.type === "ref" && c2.expr.name === "*") {
|
|
242082
242084
|
return t.fields;
|
|
242083
242085
|
} else {
|
|
242084
|
-
return [{name: n, type: t.fields[0].type}];
|
|
242086
|
+
return [{name: n, type: t.fields[0].type, expr: c2.expr}];
|
|
242085
242087
|
}
|
|
242086
242088
|
} else {
|
|
242087
242089
|
if (c2.expr.type === "ref" && c2.expr.name === "*") {
|
|
@@ -242091,7 +242093,7 @@ function elabSelect(g, c, s) {
|
|
|
242091
242093
|
}
|
|
242092
242094
|
}
|
|
242093
242095
|
}
|
|
242094
|
-
return [{name: n, type: t}];
|
|
242096
|
+
return [{name: n, type: t, expr: c2.expr}];
|
|
242095
242097
|
});
|
|
242096
242098
|
return {
|
|
242097
242099
|
kind: "record",
|
|
@@ -242115,7 +242117,7 @@ function elabSelect(g, c, s) {
|
|
|
242115
242117
|
if (t === null) {
|
|
242116
242118
|
throw new CantReduceToSimpleT(exp, t_);
|
|
242117
242119
|
} else {
|
|
242118
|
-
return {name: null, type: t};
|
|
242120
|
+
return {name: null, type: t, expr: exp};
|
|
242119
242121
|
}
|
|
242120
242122
|
});
|
|
242121
242123
|
return {
|
|
@@ -242142,7 +242144,8 @@ function elabSelect(g, c, s) {
|
|
|
242142
242144
|
fields: [
|
|
242143
242145
|
{
|
|
242144
242146
|
name: null,
|
|
242145
|
-
type: res
|
|
242147
|
+
type: res,
|
|
242148
|
+
expr: s
|
|
242146
242149
|
}
|
|
242147
242150
|
]
|
|
242148
242151
|
};
|
|
@@ -242208,7 +242211,8 @@ function elabInsert(g, c, s) {
|
|
|
242208
242211
|
} else {
|
|
242209
242212
|
return {
|
|
242210
242213
|
name: selectedCol.alias || deriveNameFromExpr(selectedCol.expr),
|
|
242211
|
-
type: t
|
|
242214
|
+
type: t,
|
|
242215
|
+
expr: selectedCol.expr
|
|
242212
242216
|
};
|
|
242213
242217
|
}
|
|
242214
242218
|
})
|
|
@@ -242246,7 +242250,8 @@ function elabDeleteOrUpdate(g, c, s) {
|
|
|
242246
242250
|
} else {
|
|
242247
242251
|
return {
|
|
242248
242252
|
name: selectedCol.alias || deriveNameFromExpr(selectedCol.expr),
|
|
242249
|
-
type: t
|
|
242253
|
+
type: t,
|
|
242254
|
+
expr: selectedCol.expr
|
|
242250
242255
|
};
|
|
242251
242256
|
}
|
|
242252
242257
|
})
|
|
@@ -242839,7 +242844,11 @@ function elabCall(g, c, e) {
|
|
|
242839
242844
|
if (valTSimple === null) {
|
|
242840
242845
|
throw new CantReduceToSimpleT(e.args[i], argTypes[i]);
|
|
242841
242846
|
}
|
|
242842
|
-
record.fields.push({
|
|
242847
|
+
record.fields.push({
|
|
242848
|
+
name: {name: key.value},
|
|
242849
|
+
type: valTSimple,
|
|
242850
|
+
expr: e.args[i]
|
|
242851
|
+
});
|
|
242843
242852
|
}
|
|
242844
242853
|
return {kind: "jsonknown", record};
|
|
242845
242854
|
} else {
|
|
@@ -242905,7 +242914,7 @@ function elabCall(g, c, e) {
|
|
|
242905
242914
|
return unifyOverloadedCall(e, argTypes, allNumericBuiltinTypes.map((t) => ({expectedArgs: [t], returnT: t})));
|
|
242906
242915
|
}
|
|
242907
242916
|
if (eqQNames(e.function, {name: "count"})) {
|
|
242908
|
-
return unifyCallGeneral(e, argTypes, [BuiltinTypes.AnyScalar], BuiltinTypes.
|
|
242917
|
+
return unifyCallGeneral(e, argTypes, [BuiltinTypes.AnyScalar], BuiltinTypes.Bigint);
|
|
242909
242918
|
}
|
|
242910
242919
|
if (eqQNames(e.function, {name: "coalesce"}) || eqQNames(e.function, {name: "nullif"})) {
|
|
242911
242920
|
if (e.args.length === 0) {
|
|
@@ -243176,7 +243185,7 @@ function nullifyRecord(s) {
|
|
|
243176
243185
|
return {
|
|
243177
243186
|
kind: "record",
|
|
243178
243187
|
fields: s.fields.map((c) => ({
|
|
243179
|
-
|
|
243188
|
+
...c,
|
|
243180
243189
|
type: nullify(c.type)
|
|
243181
243190
|
}))
|
|
243182
243191
|
};
|
|
@@ -243302,7 +243311,7 @@ return ${genDeserializeSimpleT(returnType, "cells[0]")};
|
|
|
243302
243311
|
}
|
|
243303
243312
|
}
|
|
243304
243313
|
function functionToTypescript(f) {
|
|
243305
|
-
const returnTypeAsString = f.returns.kind === "void" ? "void" : showTypeAsTypescriptType(f.returns) + (f.multipleRows ? "[]" : " |
|
|
243314
|
+
const returnTypeAsString = f.returns.kind === "void" ? "void" : showTypeAsTypescriptType(f.returns) + (f.multipleRows ? "[]" : " | null");
|
|
243306
243315
|
const argsType = "{" + f.inputs.map((k) => {
|
|
243307
243316
|
const paramTypeAsString = showTypeAsTypescriptType(k.type);
|
|
243308
243317
|
return k.name.name + ": " + paramTypeAsString;
|
|
@@ -243335,7 +243344,7 @@ const row = res.rows[0];
|
|
|
243335
243344
|
if (row.some(f => f !== null)){
|
|
243336
243345
|
return ${genDeserialization(f.returns, "row")}
|
|
243337
243346
|
} else {
|
|
243338
|
-
return
|
|
243347
|
+
return null;
|
|
243339
243348
|
}`;
|
|
243340
243349
|
return `
|
|
243341
243350
|
export async function ${f.name.name}(pool: Pool, args: ${argsType})
|
|
@@ -243405,6 +243414,20 @@ export async function insert(pool: Pool, row: {${inputRow}}): Promise<{${primary
|
|
|
243405
243414
|
} else {
|
|
243406
243415
|
return null;
|
|
243407
243416
|
}
|
|
243417
|
+
}`;
|
|
243418
|
+
const selectOne = `
|
|
243419
|
+
export async function getOne(pool: Pool, pk: {${primaryKeySingleCol.name.name}: ${showTypeAsTypescriptType(primaryKeySingleCol.type)}}): Promise<${showTypeAsTypescriptType(table.rel)} | null>{
|
|
243420
|
+
|
|
243421
|
+
const res = await pool.query({
|
|
243422
|
+
text: "SELECT * FROM ${showQName(table.name)} WHERE ${primaryKeySingleCol.name.name} = $1",
|
|
243423
|
+
values: [pk.${primaryKeySingleCol.name.name}] as any[],
|
|
243424
|
+
rowMode: "array",
|
|
243425
|
+
});
|
|
243426
|
+
if (res.rows[0]){
|
|
243427
|
+
return ${genDeserialization(table.rel, "res.rows[0]")};
|
|
243428
|
+
} else {
|
|
243429
|
+
return null;
|
|
243430
|
+
}
|
|
243408
243431
|
}`;
|
|
243409
243432
|
const inputRowForUpdate = relWithoutPrim.map((f) => `
|
|
243410
243433
|
${f.name?.name}?: ${showTypeAsTypescriptType(f.type)}`).join(",");
|
|
@@ -243433,6 +243456,7 @@ return null;
|
|
|
243433
243456
|
}`;
|
|
243434
243457
|
return `
|
|
243435
243458
|
${selectAll}
|
|
243459
|
+
${selectOne}
|
|
243436
243460
|
${insert}
|
|
243437
243461
|
${update}
|
|
243438
243462
|
${del}
|
|
@@ -243541,11 +243565,12 @@ async function go() {
|
|
|
243541
243565
|
if (err instanceof ErrorWithLocation && err.l !== void 0) {
|
|
243542
243566
|
const found = findCode(st.code || "", err.l);
|
|
243543
243567
|
if (found) {
|
|
243568
|
+
const prefix = found.lineNumber.toString() + " ";
|
|
243544
243569
|
console.error("");
|
|
243545
243570
|
console.error(`Typechecking error`);
|
|
243546
243571
|
console.error("");
|
|
243547
|
-
console.error(found.line);
|
|
243548
|
-
console.error(import_lodash2.repeat(" ", found.range[0]) + import_lodash2.repeat("^", found.range[1] - found.range[0]));
|
|
243572
|
+
console.error(prefix + found.line);
|
|
243573
|
+
console.error(import_lodash2.repeat(" ", found.range[0] + prefix.length) + import_lodash2.repeat("^", found.range[1] - found.range[0]));
|
|
243549
243574
|
}
|
|
243550
243575
|
}
|
|
243551
243576
|
console.error(err instanceof Error ? err.message : JSON.stringify(err));
|