sql-typechecker 0.0.126 → 0.0.128

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,85 @@
1
+ import { types } from "pg";
2
+ import { TypeId } from "pg-types";
3
+ import range from "postgres-range";
4
+ import { LocalDateTime } from "@js-joda/core";
5
+
6
+ // We basically disable most parsing by 'pg', so we can do the parsing
7
+ // ourselves in the generated code
8
+ export function registerSqlTypecheckerTypeParsers() {
9
+ // "date" format: 2020-10-28
10
+ types.setTypeParser(types.builtins.DATE, (v) => v);
11
+
12
+ // "time" format: 17:30:00
13
+ types.setTypeParser(types.builtins.TIME, (v) => v);
14
+
15
+ // "timestamp without time zone" 2020-09-22T15:09:09.145
16
+ types.setTypeParser(types.builtins.TIMESTAMP, (v) => v);
17
+
18
+ // "timestamp with time zone" 2022-06-23T15:52:39.77314+00:00
19
+ types.setTypeParser(types.builtins.TIMESTAMPTZ, (v) => v);
20
+
21
+ // types.builtins.MONEY -> parsed by currency.js
22
+ types.setTypeParser(types.builtins.MONEY, (v) => v);
23
+
24
+ // https://www.npmjs.com/package/postgres-range
25
+ // Range includes Included/Excluded bounds specification!
26
+ types.setTypeParser(3908 as TypeId, range.parse); // tsrange
27
+ types.setTypeParser(3910 as TypeId, range.parse); // tstzrange
28
+ types.setTypeParser(3912 as TypeId, range.parse); // daterange
29
+
30
+ types.setTypeParser(1115 as TypeId, (v) => v); // timestamp without time zone[]
31
+ types.setTypeParser(1182 as TypeId, (v) => v); // date[]
32
+ types.setTypeParser(1185 as TypeId, (v) => v); // timestamp with time zone[]
33
+
34
+ types.setTypeParser(1183 as TypeId, (v) => v); // time[]
35
+ types.setTypeParser(1270 as TypeId, (v) => v); // timetz[]
36
+
37
+ types.setTypeParser(1000 as TypeId, (v) => v); // bool array
38
+ types.setTypeParser(1005 as TypeId, (v) => v); // array int2
39
+ types.setTypeParser(1007 as TypeId, (v) => v); // array int4
40
+ types.setTypeParser(1016 as TypeId, (v) => v); // array int8
41
+ types.setTypeParser(1021 as TypeId, (v) => v); // array float4
42
+ types.setTypeParser(1022 as TypeId, (v) => v); // array float8
43
+ types.setTypeParser(1231 as TypeId, (v) => v); // array numeric
44
+ types.setTypeParser(1014 as TypeId, (v) => v); // array char
45
+ types.setTypeParser(1015 as TypeId, (v) => v); //array varchar
46
+ types.setTypeParser(1008 as TypeId, (v) => v); // array string?
47
+ types.setTypeParser(1009 as TypeId, (v) => v); // array string?
48
+
49
+ return types;
50
+ }
51
+
52
+ export function parseTsmultirange(multirangeStr: string) {
53
+ if (multirangeStr === "{}") {
54
+ return []; // Return an empty array for an empty multirange.
55
+ }
56
+
57
+ // Remove the outer curly braces and split into individual range strings.
58
+ const content = multirangeStr.substring(1, multirangeStr.length - 1);
59
+
60
+ // Regex to capture each range, including brackets and quoted timestamps.
61
+ const rangeRegex = /(\[|\()(\"[^\"]*\"|),(\"[^\"]*\"|)(\]|\))/g;
62
+ const ranges = [];
63
+ let match;
64
+
65
+ while ((match = rangeRegex.exec(content)) !== null) {
66
+ const [_, startBracket, startStr, endStr, endBracket] = match;
67
+
68
+ // Remove double quotes and create Date objects.
69
+ const start = startStr
70
+ ? LocalDateTime.parse(startStr.replace(/"/g, "").replace(" ", "T"))
71
+ : null;
72
+ const end = endStr
73
+ ? LocalDateTime.parse(endStr.replace(/"/g, "").replace(" ", "T"))
74
+ : null;
75
+ const bounds = `${startBracket}${endBracket}`;
76
+
77
+ ranges.push({
78
+ start,
79
+ end,
80
+ bounds,
81
+ });
82
+ }
83
+
84
+ return ranges;
85
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "sql-typechecker",
3
- "version": "0.0.126",
4
- "main": "out/typeparsers.js",
3
+ "version": "0.0.128",
4
+ "main": "out/typeparsers.ts",
5
5
  "files": ["out/**"],
6
6
  "bin": "out/cli.js",
7
7
  "dependencies": {
@@ -11,7 +11,7 @@
11
11
  "trader-pgsql-ast-parser": "10.5.9"
12
12
  },
13
13
  "peerDependencies": {
14
- "@js-joda/core": "^5.3.x"
14
+ "@js-joda/core": "5.5.2"
15
15
  },
16
16
  "scripts": {
17
17
  "check": "tsc -p . --noEmit",