true-pg 0.4.3 → 0.4.4
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/lib/index.js +27 -5
- package/lib/kysely/builtins.js +6 -1
- package/lib/zod/builtins.js +6 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
@@ -10,6 +10,16 @@ const time = (start) => {
|
|
10
10
|
const end = performance.now();
|
11
11
|
return (end - start).toFixed(2);
|
12
12
|
};
|
13
|
+
const filter_overloaded_functions = (functions) => {
|
14
|
+
const counts = functions.reduce((acc, func) => {
|
15
|
+
acc[func.name] = (acc[func.name] ?? 0) + 1;
|
16
|
+
return acc;
|
17
|
+
}, {});
|
18
|
+
return [
|
19
|
+
functions.filter(func => counts[func.name] === 1),
|
20
|
+
functions.filter(func => counts[func.name] > 1),
|
21
|
+
];
|
22
|
+
};
|
13
23
|
const filter_function = (func) => {
|
14
24
|
const typesToFilter = [
|
15
25
|
"pg_catalog.trigger",
|
@@ -44,6 +54,11 @@ const filter_function = (func) => {
|
|
44
54
|
}
|
45
55
|
return func;
|
46
56
|
};
|
57
|
+
const filter_unsupported_functions = (functions) => {
|
58
|
+
const filtered = functions.filter(filter_function);
|
59
|
+
const unsupported = filtered.filter(func => !filtered.includes(func));
|
60
|
+
return [filtered, unsupported];
|
61
|
+
};
|
47
62
|
const write = (filename, file) => writeFile(filename, file + "\n");
|
48
63
|
const multifile = async (generators, schemas, opts) => {
|
49
64
|
const { out } = opts;
|
@@ -78,13 +93,20 @@ const multifile = async (generators, schemas, opts) => {
|
|
78
93
|
for (const schema of Object.values(schemas)) {
|
79
94
|
console.log("Selected schema '%s':\n", schema.name);
|
80
95
|
const schemaDir = joinpath(out, schema.name);
|
81
|
-
|
82
|
-
|
96
|
+
const [supported_functions, unsupported_functions] = filter_unsupported_functions(schema.functions);
|
97
|
+
const [unique_functions, overloaded_functions] = filter_overloaded_functions(supported_functions);
|
98
|
+
schema.functions = unique_functions;
|
99
|
+
{
|
100
|
+
const skipped = unsupported_functions.map(f => ` - ${f.name}`);
|
101
|
+
if (skipped.length) {
|
102
|
+
warnings.push(`Skipping ${skipped.length} functions not representable in JavaScript (safe to ignore):\n` +
|
103
|
+
skipped.join("\n"));
|
104
|
+
}
|
105
|
+
}
|
83
106
|
{
|
84
|
-
const skipped =
|
85
|
-
const skipped_functions = skipped.map(f => ` - ${f.name}`).join("\n");
|
107
|
+
const skipped = overloaded_functions.map(f => ` - ${f.name}`);
|
86
108
|
if (skipped.length) {
|
87
|
-
warnings.push(`Skipping ${skipped.length} functions
|
109
|
+
warnings.push(`Skipping ${skipped.length} overloaded functions (not supported):\n` + skipped.join("\n"));
|
88
110
|
}
|
89
111
|
}
|
90
112
|
let createIndex = false;
|
package/lib/kysely/builtins.js
CHANGED
@@ -17,7 +17,6 @@ export const builtins = {
|
|
17
17
|
"pg_catalog.varchar": "string",
|
18
18
|
"pg_catalog.text": "string",
|
19
19
|
"pg_catalog.uuid": "string",
|
20
|
-
"pg_catalog.inet": "string",
|
21
20
|
"pg_catalog.date": "Date",
|
22
21
|
"pg_catalog.time": "Date",
|
23
22
|
"pg_catalog.timetz": "Date",
|
@@ -32,6 +31,12 @@ export const builtins = {
|
|
32
31
|
"pg_catalog.record": "Record<string, unknown>",
|
33
32
|
"pg_catalog.void": "void",
|
34
33
|
"pg_catalog.bytea": "string",
|
34
|
+
"pg_catalog.inet": "string",
|
35
|
+
"pg_catalog.cidr": "string",
|
36
|
+
"pg_catalog.macaddr": "string",
|
37
|
+
"pg_catalog.macaddr8": "string",
|
38
|
+
"pg_catalog.oid": "number",
|
39
|
+
"pg_catalog.refcursor": "string",
|
35
40
|
"pg_catalog.vector": "number[]",
|
36
41
|
"pg_catalog.tsvector": "string[]",
|
37
42
|
};
|
package/lib/zod/builtins.js
CHANGED
@@ -17,7 +17,6 @@ export const builtins = {
|
|
17
17
|
"pg_catalog.varchar": "z.string()",
|
18
18
|
"pg_catalog.text": "z.string()",
|
19
19
|
"pg_catalog.uuid": "z.string()",
|
20
|
-
"pg_catalog.inet": "z.string()",
|
21
20
|
"pg_catalog.date": "z.coerce.date()",
|
22
21
|
"pg_catalog.time": "z.coerce.date()",
|
23
22
|
"pg_catalog.timetz": "z.coerce.date()",
|
@@ -32,6 +31,12 @@ export const builtins = {
|
|
32
31
|
"pg_catalog.record": "z.record(z.string(), z.unknown())",
|
33
32
|
"pg_catalog.void": "z.void()",
|
34
33
|
"pg_catalog.bytea": "z.string()",
|
34
|
+
"pg_catalog.inet": "z.string()",
|
35
|
+
"pg_catalog.cidr": "z.string()",
|
36
|
+
"pg_catalog.macaddr": "z.string()",
|
37
|
+
"pg_catalog.macaddr8": "z.string()",
|
38
|
+
"pg_catalog.oid": "z.number()",
|
39
|
+
"pg_catalog.refcursor": "z.string()",
|
35
40
|
"pg_catalog.vector": "z.number().array()",
|
36
41
|
"pg_catalog.tsvector": "z.string().array()",
|
37
42
|
};
|