prostgles-server 3.0.155 → 4.0.2
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/dist/AuthHandler.d.ts.map +1 -1
- package/dist/AuthHandler.js +6 -3
- package/dist/AuthHandler.js.map +1 -1
- package/dist/DBEventsManager.d.ts.map +1 -1
- package/dist/DBEventsManager.js +5 -4
- package/dist/DBEventsManager.js.map +1 -1
- package/dist/DBSchemaBuilder.js +14 -14
- package/dist/DBSchemaBuilder.js.map +1 -1
- package/dist/DboBuilder/QueryBuilder/Functions.js +1 -1
- package/dist/DboBuilder/QueryBuilder/Functions.js.map +1 -1
- package/dist/DboBuilder/QueryBuilder/makeSelectQuery.js.map +1 -1
- package/dist/DboBuilder/TableHandler.js +1 -2
- package/dist/DboBuilder/TableHandler.js.map +1 -1
- package/dist/DboBuilder/ViewHandler.d.ts +3 -3
- package/dist/DboBuilder/ViewHandler.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler.js +12 -10
- package/dist/DboBuilder/ViewHandler.js.map +1 -1
- package/dist/DboBuilder/getCondition.js +1 -1
- package/dist/DboBuilder/getCondition.js.map +1 -1
- package/dist/DboBuilder/insert.js +1 -1
- package/dist/DboBuilder/insert.js.map +1 -1
- package/dist/DboBuilder/insertDataParse.js +4 -3
- package/dist/DboBuilder/insertDataParse.js.map +1 -1
- package/dist/DboBuilder/subscribe.d.ts +7 -4
- package/dist/DboBuilder/subscribe.d.ts.map +1 -1
- package/dist/DboBuilder/subscribe.js +11 -12
- package/dist/DboBuilder/subscribe.js.map +1 -1
- package/dist/DboBuilder.d.ts.map +1 -1
- package/dist/DboBuilder.js +5 -4
- package/dist/DboBuilder.js.map +1 -1
- package/dist/FileManager.js +1 -1
- package/dist/FileManager.js.map +1 -1
- package/dist/Filtering.js.map +1 -1
- package/dist/JSONBValidation/validation.js.map +1 -1
- package/dist/Prostgles.js +1 -1
- package/dist/Prostgles.js.map +1 -1
- package/dist/PubSubManager/PubSubManager.d.ts +14 -6
- package/dist/PubSubManager/PubSubManager.d.ts.map +1 -1
- package/dist/PubSubManager/PubSubManager.js +20 -50
- package/dist/PubSubManager/PubSubManager.js.map +1 -1
- package/dist/PubSubManager/addSub.d.ts +2 -1
- package/dist/PubSubManager/addSub.d.ts.map +1 -1
- package/dist/PubSubManager/addSub.js +43 -27
- package/dist/PubSubManager/addSub.js.map +1 -1
- package/dist/PubSubManager/notifListener.d.ts.map +1 -1
- package/dist/PubSubManager/notifListener.js +6 -4
- package/dist/PubSubManager/notifListener.js.map +1 -1
- package/dist/PubSubManager/pushSubData.d.ts +3 -0
- package/dist/PubSubManager/pushSubData.d.ts.map +1 -0
- package/dist/PubSubManager/pushSubData.js +48 -0
- package/dist/PubSubManager/pushSubData.js.map +1 -0
- package/dist/PublishParser.d.ts.map +1 -1
- package/dist/PublishParser.js +4 -3
- package/dist/PublishParser.js.map +1 -1
- package/dist/TableConfig/TableConfig.js.map +1 -1
- package/dist/TableConfig/getConstraintDefinitionQueries.js.map +1 -1
- package/dist/TableConfig/getTableColumnQueries.js.map +1 -1
- package/lib/AuthHandler.d.ts.map +1 -1
- package/lib/AuthHandler.js +6 -3
- package/lib/AuthHandler.ts +12 -7
- package/lib/DBEventsManager.d.ts.map +1 -1
- package/lib/DBEventsManager.js +5 -4
- package/lib/DBEventsManager.ts +10 -9
- package/lib/DBSchemaBuilder.js +14 -14
- package/lib/DBSchemaBuilder.ts +14 -14
- package/lib/DboBuilder/QueryBuilder/Functions.js +1 -1
- package/lib/DboBuilder/QueryBuilder/Functions.ts +2 -2
- package/lib/DboBuilder/QueryBuilder/makeSelectQuery.ts +1 -1
- package/lib/DboBuilder/TableHandler.js +1 -2
- package/lib/DboBuilder/TableHandler.ts +3 -3
- package/lib/DboBuilder/ViewHandler.d.ts +3 -3
- package/lib/DboBuilder/ViewHandler.d.ts.map +1 -1
- package/lib/DboBuilder/ViewHandler.js +12 -10
- package/lib/DboBuilder/ViewHandler.ts +27 -25
- package/lib/DboBuilder/getCondition.js +1 -1
- package/lib/DboBuilder/getCondition.ts +2 -2
- package/lib/DboBuilder/insert.js +1 -1
- package/lib/DboBuilder/insert.ts +1 -1
- package/lib/DboBuilder/insertDataParse.js +4 -3
- package/lib/DboBuilder/insertDataParse.ts +15 -13
- package/lib/DboBuilder/subscribe.d.ts +7 -4
- package/lib/DboBuilder/subscribe.d.ts.map +1 -1
- package/lib/DboBuilder/subscribe.js +11 -12
- package/lib/DboBuilder/subscribe.ts +20 -18
- package/lib/DboBuilder.d.ts.map +1 -1
- package/lib/DboBuilder.js +5 -4
- package/lib/DboBuilder.ts +15 -21
- package/lib/FileManager.js +1 -1
- package/lib/FileManager.ts +5 -5
- package/lib/Filtering.ts +1 -1
- package/lib/JSONBValidation/validation.ts +3 -3
- package/lib/Prostgles.js +1 -1
- package/lib/Prostgles.ts +3 -3
- package/lib/PubSubManager/PubSubManager.d.ts +13 -5
- package/lib/PubSubManager/PubSubManager.d.ts.map +1 -1
- package/lib/PubSubManager/PubSubManager.js +18 -48
- package/lib/PubSubManager/PubSubManager.ts +25 -51
- package/lib/PubSubManager/addSub.d.ts +2 -1
- package/lib/PubSubManager/addSub.d.ts.map +1 -1
- package/lib/PubSubManager/addSub.js +43 -27
- package/lib/PubSubManager/addSub.ts +49 -33
- package/lib/PubSubManager/notifListener.d.ts.map +1 -1
- package/lib/PubSubManager/notifListener.js +6 -4
- package/lib/PubSubManager/notifListener.ts +6 -4
- package/lib/PubSubManager/pushSubData.d.ts +3 -0
- package/lib/PubSubManager/pushSubData.d.ts.map +1 -0
- package/lib/PubSubManager/pushSubData.js +47 -0
- package/lib/PubSubManager/pushSubData.ts +47 -0
- package/lib/PublishParser.d.ts.map +1 -1
- package/lib/PublishParser.js +4 -3
- package/lib/PublishParser.ts +4 -3
- package/lib/TableConfig/TableConfig.ts +7 -7
- package/lib/TableConfig/getConstraintDefinitionQueries.ts +1 -1
- package/lib/TableConfig/getTableColumnQueries.ts +2 -2
- package/package.json +2 -2
- package/tests/client/PID.txt +1 -1
- package/tests/client/package-lock.json +15 -15
- package/tests/client/package.json +1 -1
- package/tests/server/DBoGenerated.d.ts +2 -2
- package/tests/server/package-lock.json +3 -3
- package/tsconfig.json +1 -1
|
@@ -36,7 +36,7 @@ class ColSet {
|
|
|
36
36
|
* Add conversion functions for PostGIS data
|
|
37
37
|
*/
|
|
38
38
|
let escapedVal = "";
|
|
39
|
-
if (["geometry", "geography"].includes(col.udt_name) &&
|
|
39
|
+
if (["geometry", "geography"].includes(col.udt_name) && (0, prostgles_types_1.isObject)(row[key])) {
|
|
40
40
|
const basicFunc = (args) => {
|
|
41
41
|
return args.map(arg => (0, PubSubManager_1.asValue)(arg)).join(", ");
|
|
42
42
|
};
|
|
@@ -212,10 +212,10 @@ class ViewHandler {
|
|
|
212
212
|
const getJoinCondition = (on, leftTable, rightTable) => {
|
|
213
213
|
return on.map(cond => Object.keys(cond).map(lKey => `${leftTable}.${lKey} = ${rightTable}.${cond[lKey]}`).join("\nAND ")).join(" OR ");
|
|
214
214
|
};
|
|
215
|
-
let toOne = true;
|
|
215
|
+
// let toOne = true;
|
|
216
216
|
const query = this.joins.map(({ tables, on, type }, i) => {
|
|
217
217
|
if (type.split("-")[1] === "many") {
|
|
218
|
-
toOne = false;
|
|
218
|
+
// toOne = false;
|
|
219
219
|
}
|
|
220
220
|
const tl = `tl${startAlias + i}`, tr = `tr${startAlias + i}`;
|
|
221
221
|
return `FROM ${tables[0]} ${tl} ${isInner ? "INNER" : "LEFT"} JOIN ${tables[1]} ${tr} ON ${getJoinCondition(on, tl, tr)}`;
|
|
@@ -278,7 +278,7 @@ class ViewHandler {
|
|
|
278
278
|
const on = [];
|
|
279
279
|
jo.on.map(cond => {
|
|
280
280
|
const condArr = [];
|
|
281
|
-
|
|
281
|
+
(0, prostgles_types_1.getKeys)(cond).map(leftKey => {
|
|
282
282
|
const rightKey = cond[leftKey];
|
|
283
283
|
/* Left table is joining on keys */
|
|
284
284
|
if (jo.tables[0] === t1) {
|
|
@@ -589,9 +589,9 @@ class ViewHandler {
|
|
|
589
589
|
throw (0, DboBuilder_1.parseError)(e, `Issue with dbo.${this.name}.findOne()`);
|
|
590
590
|
}
|
|
591
591
|
}
|
|
592
|
-
async subscribe(filter, params,
|
|
592
|
+
async subscribe(filter, params, localFuncs, table_rules, localParams) {
|
|
593
593
|
//@ts-ignore
|
|
594
|
-
return subscribe_1.subscribe.bind(this)(filter, params,
|
|
594
|
+
return subscribe_1.subscribe.bind(this)(filter, params, localFuncs, table_rules, localParams);
|
|
595
595
|
}
|
|
596
596
|
subscribeOne(filter, params = {}, localFunc, table_rules, localParams) {
|
|
597
597
|
//@ts-ignore
|
|
@@ -727,7 +727,7 @@ class ViewHandler {
|
|
|
727
727
|
const thisTable = this.name;
|
|
728
728
|
const isNotExists = ["$notExists", "$notExistsJoined"].includes(eConfig.existType);
|
|
729
729
|
const { f2, tables, isJoined } = eConfig;
|
|
730
|
-
const t2 = tables
|
|
730
|
+
const t2 = tables.at(-1);
|
|
731
731
|
tables.forEach(t => {
|
|
732
732
|
if (!this.dboBuilder.dbo[t])
|
|
733
733
|
throw { stack: ["prepareExistCondition()"], message: `Invalid or dissallowed table: ${t}` };
|
|
@@ -740,7 +740,7 @@ class ViewHandler {
|
|
|
740
740
|
let joinPaths = [];
|
|
741
741
|
let expectOne = true;
|
|
742
742
|
tables.map((t2, depth) => {
|
|
743
|
-
const t1 = depth ? tables[depth - 1] : thisTable;
|
|
743
|
+
const t1 = (depth ? tables[depth - 1] : thisTable);
|
|
744
744
|
let exactPaths = [t1, t2];
|
|
745
745
|
if (!depth && eConfig.shortestJoin)
|
|
746
746
|
exactPaths = undefined;
|
|
@@ -753,8 +753,10 @@ class ViewHandler {
|
|
|
753
753
|
function makeJoin(joinInfo, ji) {
|
|
754
754
|
const { paths } = joinInfo;
|
|
755
755
|
const jp = paths[ji];
|
|
756
|
+
if (!jp)
|
|
757
|
+
throw "jp undef";
|
|
756
758
|
// let prevTable = ji? paths[ji - 1].table : jp.source;
|
|
757
|
-
const table =
|
|
759
|
+
const table = jp.table;
|
|
758
760
|
const tableAlias = (0, prostgles_types_1.asName)(ji < paths.length - 1 ? `jd${ji}` : table);
|
|
759
761
|
const prevTableAlias = (0, prostgles_types_1.asName)(ji ? `jd${ji - 1}` : thisTable);
|
|
760
762
|
const cond = `${jp.on.map(c => {
|
|
@@ -867,7 +869,7 @@ class ViewHandler {
|
|
|
867
869
|
/* [string] */
|
|
868
870
|
_ob = _orderBy.map(key => ({ key, asc: true }));
|
|
869
871
|
}
|
|
870
|
-
else if (_orderBy.find(v => (0,
|
|
872
|
+
else if (_orderBy.find(v => (0, prostgles_types_1.isObject)(v) && !(0, prostgles_types_1.isEmpty)(v))) {
|
|
871
873
|
_ob = _orderBy.map(v => parseOrderObj(v, true)[0]);
|
|
872
874
|
}
|
|
873
875
|
else
|
|
@@ -26,7 +26,7 @@ import { TableHandler } from "./TableHandler";
|
|
|
26
26
|
import { asNameAlias, getNewQuery, SelectItem, SelectItemValidated } from "./QueryBuilder/QueryBuilder";
|
|
27
27
|
import { COMPUTED_FIELDS, FieldSpec } from "./QueryBuilder/Functions";
|
|
28
28
|
import { getColumns } from "./getColumns";
|
|
29
|
-
import {
|
|
29
|
+
import { LocalFuncs, subscribe } from "./subscribe";
|
|
30
30
|
export type JoinPaths = {
|
|
31
31
|
t1: string;
|
|
32
32
|
t2: string;
|
|
@@ -77,7 +77,7 @@ class ColSet {
|
|
|
77
77
|
* Add conversion functions for PostGIS data
|
|
78
78
|
*/
|
|
79
79
|
let escapedVal = "";
|
|
80
|
-
if (["geometry", "geography"].includes(col.udt_name) &&
|
|
80
|
+
if (["geometry", "geography"].includes(col.udt_name) && isObject(row[key])) {
|
|
81
81
|
|
|
82
82
|
const basicFunc = (args: any[]) => {
|
|
83
83
|
return args.map(arg => asValue(arg)).join(", ")
|
|
@@ -86,13 +86,14 @@ class ColSet {
|
|
|
86
86
|
type ConvertionFunc = { name: string; getQuery: (args: any[]) => string; }
|
|
87
87
|
const convertionFuncs: ConvertionFunc[] = [
|
|
88
88
|
...[
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
89
|
+
"ST_GeomFromText",
|
|
90
|
+
"ST_Point",
|
|
91
|
+
"ST_MakePoint",
|
|
92
|
+
"ST_MakePointM",
|
|
93
|
+
"ST_PointFromText",
|
|
94
|
+
"ST_GeomFromEWKT",
|
|
95
|
+
"ST_GeomFromGeoJSON"
|
|
96
|
+
].map(name => ({
|
|
96
97
|
name,
|
|
97
98
|
getQuery: () => `${name}(${basicFunc(funcArgs)})`
|
|
98
99
|
})),
|
|
@@ -103,7 +104,7 @@ class ColSet {
|
|
|
103
104
|
];
|
|
104
105
|
|
|
105
106
|
const dataKeys = Object.keys(row[key]);
|
|
106
|
-
const funcName = dataKeys[0]
|
|
107
|
+
const funcName = dataKeys[0]!;
|
|
107
108
|
const func = convertionFuncs.find(f => f.name === funcName);
|
|
108
109
|
const funcArgs = row[key]?.[funcName]
|
|
109
110
|
if (dataKeys.length !== 1 || !func || !Array.isArray(funcArgs)) {
|
|
@@ -287,10 +288,10 @@ export class ViewHandler {
|
|
|
287
288
|
return on.map(cond => Object.keys(cond).map(lKey => `${leftTable}.${lKey} = ${rightTable}.${cond[lKey]}`).join("\nAND ")).join(" OR ")
|
|
288
289
|
}
|
|
289
290
|
|
|
290
|
-
let toOne = true;
|
|
291
|
+
// let toOne = true;
|
|
291
292
|
const query = this.joins.map(({ tables, on, type }, i) => {
|
|
292
293
|
if (type.split("-")[1] === "many") {
|
|
293
|
-
toOne = false;
|
|
294
|
+
// toOne = false;
|
|
294
295
|
}
|
|
295
296
|
const tl = `tl${startAlias + i}`,
|
|
296
297
|
tr = `tr${startAlias + i}`;
|
|
@@ -347,7 +348,7 @@ export class ViewHandler {
|
|
|
347
348
|
|
|
348
349
|
/* Make the join chain info excluding root table */
|
|
349
350
|
paths = (path || jp.path).slice(1).map((t2, i, arr) => {
|
|
350
|
-
const t1 = i === 0 ? source : arr[i - 1]
|
|
351
|
+
const t1 = i === 0 ? source : arr[i - 1]!;
|
|
351
352
|
|
|
352
353
|
this.joins ??= this.dboBuilder.joins;
|
|
353
354
|
|
|
@@ -359,8 +360,8 @@ export class ViewHandler {
|
|
|
359
360
|
|
|
360
361
|
jo.on.map(cond => {
|
|
361
362
|
const condArr: [string, string][] = [];
|
|
362
|
-
|
|
363
|
-
const rightKey = cond[leftKey]
|
|
363
|
+
getKeys(cond).map(leftKey => {
|
|
364
|
+
const rightKey = cond[leftKey]!;
|
|
364
365
|
|
|
365
366
|
/* Left table is joining on keys */
|
|
366
367
|
if (jo.tables[0] === t1) {
|
|
@@ -691,12 +692,12 @@ export class ViewHandler {
|
|
|
691
692
|
}
|
|
692
693
|
}
|
|
693
694
|
|
|
694
|
-
async subscribe(filter: Filter, params: SubscribeParams,
|
|
695
|
-
async subscribe(filter: Filter, params: SubscribeParams,
|
|
696
|
-
async subscribe(filter: Filter, params: SubscribeParams,
|
|
695
|
+
async subscribe(filter: Filter, params: SubscribeParams, localFuncs: LocalFuncs): Promise<{ unsubscribe: () => any }>
|
|
696
|
+
async subscribe(filter: Filter, params: SubscribeParams, localFuncs: undefined, table_rules: TableRule | undefined, localParams: LocalParams): Promise<string>
|
|
697
|
+
async subscribe(filter: Filter, params: SubscribeParams, localFuncs?: LocalFuncs, table_rules?: TableRule, localParams?: LocalParams):
|
|
697
698
|
Promise<{ unsubscribe: () => any } | string> {
|
|
698
699
|
//@ts-ignore
|
|
699
|
-
return subscribe.bind(this)(filter, params,
|
|
700
|
+
return subscribe.bind(this)(filter, params, localFuncs, table_rules, localParams);
|
|
700
701
|
}
|
|
701
702
|
|
|
702
703
|
/* This should only be called from server */
|
|
@@ -857,7 +858,7 @@ export class ViewHandler {
|
|
|
857
858
|
const isNotExists = ["$notExists", "$notExistsJoined"].includes(eConfig.existType);
|
|
858
859
|
|
|
859
860
|
const { f2, tables, isJoined } = eConfig;
|
|
860
|
-
const t2 = tables
|
|
861
|
+
const t2 = tables.at(-1)!;
|
|
861
862
|
|
|
862
863
|
tables.forEach(t => {
|
|
863
864
|
if (!this.dboBuilder.dbo[t]) throw { stack: ["prepareExistCondition()"], message: `Invalid or dissallowed table: ${t}` };
|
|
@@ -874,7 +875,7 @@ export class ViewHandler {
|
|
|
874
875
|
let joinPaths: JoinInfo["paths"] = [];
|
|
875
876
|
let expectOne = true;
|
|
876
877
|
tables.map((t2, depth) => {
|
|
877
|
-
const t1 = depth ? tables[depth - 1] : thisTable
|
|
878
|
+
const t1 = (depth ? tables[depth - 1] : thisTable)!;
|
|
878
879
|
let exactPaths: string[] | undefined = [t1, t2];
|
|
879
880
|
|
|
880
881
|
if (!depth && eConfig.shortestJoin) exactPaths = undefined;
|
|
@@ -889,9 +890,10 @@ export class ViewHandler {
|
|
|
889
890
|
function makeJoin(joinInfo: JoinInfo, ji: number) {
|
|
890
891
|
const { paths } = joinInfo;
|
|
891
892
|
const jp = paths[ji];
|
|
893
|
+
if(!jp) throw "jp undef";
|
|
892
894
|
|
|
893
895
|
// let prevTable = ji? paths[ji - 1].table : jp.source;
|
|
894
|
-
const table =
|
|
896
|
+
const table = jp.table;
|
|
895
897
|
const tableAlias = asName(ji < paths.length - 1 ? `jd${ji}` : table);
|
|
896
898
|
const prevTableAlias = asName(ji ? `jd${ji - 1}` : thisTable);
|
|
897
899
|
|
|
@@ -1024,8 +1026,8 @@ export class ViewHandler {
|
|
|
1024
1026
|
if (_orderBy && !_orderBy.find(v => typeof v !== "string")) {
|
|
1025
1027
|
/* [string] */
|
|
1026
1028
|
_ob = _orderBy.map(key => ({ key, asc: true }));
|
|
1027
|
-
} else if (_orderBy.find(v =>
|
|
1028
|
-
_ob = _orderBy.map(v => parseOrderObj(v, true)[0]);
|
|
1029
|
+
} else if (_orderBy.find(v => isObject(v) && !isEmpty(v))) {
|
|
1030
|
+
_ob = _orderBy.map(v => parseOrderObj(v, true)[0]!);
|
|
1029
1031
|
} else return throwErr();
|
|
1030
1032
|
} else return throwErr();
|
|
1031
1033
|
|
|
@@ -1090,7 +1092,7 @@ export class ViewHandler {
|
|
|
1090
1092
|
/* If no limit then set as the lesser of (100, maxLimit) */
|
|
1091
1093
|
// } else
|
|
1092
1094
|
if (_limit !== null && !Number.isInteger(_limit) && p.select.maxLimit !== null) {
|
|
1093
|
-
_limit = [100, p.select.maxLimit].filter(Number.isInteger).sort((a, b) => a - b)[0]
|
|
1095
|
+
_limit = [100, p.select.maxLimit].filter(Number.isInteger).sort((a, b) => a - b)[0]!;
|
|
1094
1096
|
} else {
|
|
1095
1097
|
|
|
1096
1098
|
/* If a limit higher than maxLimit specified throw error */
|
|
@@ -21,7 +21,7 @@ async function getCondition(params) {
|
|
|
21
21
|
const ERR = "Invalid exists filter. \nExpecting somethibng like: \n | { $exists: { tableName.tableName2: Filter } } \n | { $exists: { \"**.tableName3\": Filter } }\n | { path: string[]; filter: AnyObject }";
|
|
22
22
|
const SP_WILDCARD = "**";
|
|
23
23
|
const exists = (0, prostgles_types_1.getKeys)(filter)
|
|
24
|
-
.filter(k => prostgles_types_1.EXISTS_KEYS.includes(k) && Object.keys(filter[k] ?? {}).length)
|
|
24
|
+
.filter((k) => prostgles_types_1.EXISTS_KEYS.includes(k) && !!Object.keys(filter[k] ?? {}).length)
|
|
25
25
|
.map(key => {
|
|
26
26
|
const isJoined = key.toLowerCase().includes("join");
|
|
27
27
|
const filterValue = filter[key];
|
|
@@ -35,7 +35,7 @@ export async function getCondition(
|
|
|
35
35
|
const ERR = "Invalid exists filter. \nExpecting somethibng like: \n | { $exists: { tableName.tableName2: Filter } } \n | { $exists: { \"**.tableName3\": Filter } }\n | { path: string[]; filter: AnyObject }"
|
|
36
36
|
const SP_WILDCARD = "**";
|
|
37
37
|
const exists: ExistsFilterConfig[] = getKeys(filter)
|
|
38
|
-
.filter(k => EXISTS_KEYS.includes(k as EXISTS_KEY) && Object.keys(filter[k] ?? {}).length)
|
|
38
|
+
.filter((k ): k is typeof EXISTS_KEYS[number] => EXISTS_KEYS.includes(k as EXISTS_KEY) && !!Object.keys(filter[k] ?? {}).length)
|
|
39
39
|
.map(key => {
|
|
40
40
|
|
|
41
41
|
const isJoined = key.toLowerCase().includes("join");
|
|
@@ -49,7 +49,7 @@ export async function getCondition(
|
|
|
49
49
|
const dataKeys = Object.keys(filterValue);
|
|
50
50
|
const isDetailed = dataKeys.length === 2 && dataKeys.every(key => ["path", "filter"].includes(key));
|
|
51
51
|
|
|
52
|
-
const firstKey = dataKeys[0]
|
|
52
|
+
const firstKey = dataKeys[0]!;
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
55
|
* Prevent some errors with table names that contain "."
|
package/lib/DboBuilder/insert.js
CHANGED
|
@@ -37,7 +37,7 @@ async function insert(rowOrRows, param2, param3_unused, tableRules, localParams)
|
|
|
37
37
|
const keys = Object.keys(forcedData);
|
|
38
38
|
if (keys.length) {
|
|
39
39
|
const dataCols = keys.filter(k => this.column_names.includes(k));
|
|
40
|
-
const nestedInsertCols = keys.filter(k => !this.column_names.includes(k) && this.dboBuilder.dbo[k]
|
|
40
|
+
const nestedInsertCols = keys.filter(k => !this.column_names.includes(k) && this.dboBuilder.dbo[k]?.insert);
|
|
41
41
|
if (nestedInsertCols.length) {
|
|
42
42
|
throw `Nested insert not supported for forcedData rule: ${nestedInsertCols}`;
|
|
43
43
|
}
|
package/lib/DboBuilder/insert.ts
CHANGED
|
@@ -45,7 +45,7 @@ export async function insert(this: TableHandler, rowOrRows: (AnyObject | AnyObje
|
|
|
45
45
|
const keys = Object.keys(forcedData);
|
|
46
46
|
if (keys.length) {
|
|
47
47
|
const dataCols = keys.filter(k => this.column_names.includes(k));
|
|
48
|
-
const nestedInsertCols = keys.filter(k => !this.column_names.includes(k) && this.dboBuilder.dbo[k]
|
|
48
|
+
const nestedInsertCols = keys.filter(k => !this.column_names.includes(k) && this.dboBuilder.dbo[k]?.insert);
|
|
49
49
|
if(nestedInsertCols.length){
|
|
50
50
|
throw `Nested insert not supported for forcedData rule: ${nestedInsertCols}`;
|
|
51
51
|
}
|
|
@@ -164,8 +164,8 @@ async function insertDataParse(data, param2, param3_unused, tableRules, _localPa
|
|
|
164
164
|
throw "Only media allowed to have nested inserts more than 2 tables apart";
|
|
165
165
|
}
|
|
166
166
|
/* We expect tbl2 to have only 2 columns (media_id and foreign_id) */
|
|
167
|
-
if (!cols2 || !(cols2.filter(c => c.references?.[0]
|
|
168
|
-
cols2.filter(c => c.references?.[0]
|
|
167
|
+
if (!cols2 || !(cols2.filter(c => c.references?.[0]?.ftable === fileTable).length === 1 &&
|
|
168
|
+
cols2.filter(c => c.references?.[0]?.ftable === _this.name).length === 1)) {
|
|
169
169
|
console.log({ tbl1, tbl2, tbl3, name: _this.name, tthisName: this.name });
|
|
170
170
|
throw "Second joining table (" + tbl2 + ") not of expected format. Must contain exactly one reference column for each table (file table and target table) ";
|
|
171
171
|
}
|
|
@@ -235,8 +235,9 @@ const getJoinPath = async (tableHandler, targetTable) => {
|
|
|
235
235
|
const referencedInsert = async (tableHandler, dbTX, localParams, targetTable, targetData) => {
|
|
236
236
|
const thisInfo = await tableHandler.getInfo();
|
|
237
237
|
await getJoinPath(tableHandler, targetTable);
|
|
238
|
-
if (!targetData || !dbTX?.[targetTable] || !("insert" in dbTX[targetTable]))
|
|
238
|
+
if (!targetData || !dbTX?.[targetTable] || !("insert" in dbTX[targetTable])) {
|
|
239
239
|
throw new Error("childInsertErr: Table handler missing for referenced table: " + targetTable);
|
|
240
|
+
}
|
|
240
241
|
const childRules = await canInsert(tableHandler, targetTable, localParams);
|
|
241
242
|
if (thisInfo.has_media === "one" && thisInfo.media_table_name === targetTable && Array.isArray(targetData) && targetData.length > 1) {
|
|
242
243
|
throw "Constraint check fail: Cannot insert more than one record into " + JSON.stringify(targetTable);
|
|
@@ -65,9 +65,9 @@ export async function insertDataParse(
|
|
|
65
65
|
}
|
|
66
66
|
if (insertedCol) {
|
|
67
67
|
return {
|
|
68
|
-
tableName: insertedCol.references![0]
|
|
68
|
+
tableName: insertedCol.references![0]!.ftable!,
|
|
69
69
|
col: insertedCol.name,
|
|
70
|
-
fcol: insertedCol.references![0]
|
|
70
|
+
fcol: insertedCol.references![0]!.fcols[0]!
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
return undefined;
|
|
@@ -145,11 +145,11 @@ export async function insertDataParse(
|
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
const colRows = await referencedInsert(_this, dbTX, newLocalParams, colInsert.tableName, row[colInsert.col]);
|
|
148
|
-
if (!Array.isArray(colRows) || colRows.length !== 1 || [null, undefined].includes(colRows[0][colInsert.fcol])) {
|
|
148
|
+
if (!Array.isArray(colRows) || colRows.length !== 1 || [null, undefined].includes(colRows[0]![colInsert.fcol])) {
|
|
149
149
|
throw new Error("Could not do nested column insert: Unexpected return " + JSON.stringify(colRows))
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
const foreignKey = colRows[0][colInsert.fcol];
|
|
152
|
+
const foreignKey = colRows[0]![colInsert.fcol];
|
|
153
153
|
rootData[colInsert.col] = foreignKey;
|
|
154
154
|
}
|
|
155
155
|
}
|
|
@@ -179,8 +179,8 @@ export async function insertDataParse(
|
|
|
179
179
|
const [tbl1, tbl2, tbl3] = path;
|
|
180
180
|
targetTableRules = await canInsert(this, targetTable, localParams); // tbl3
|
|
181
181
|
|
|
182
|
-
const cols2 = this.dboBuilder.dbo[tbl2]
|
|
183
|
-
if (!this.dboBuilder.dbo[tbl2]) throw "Invalid/disallowed table: " + tbl2;
|
|
182
|
+
const cols2 = this.dboBuilder.dbo[tbl2!]!.columns || [];
|
|
183
|
+
if (!this.dboBuilder.dbo[tbl2!]) throw "Invalid/disallowed table: " + tbl2;
|
|
184
184
|
const colsRefT1 = cols2?.filter(c => c.references?.some(rc => rc.cols.length === 1 && rc.ftable === tbl1));
|
|
185
185
|
|
|
186
186
|
|
|
@@ -196,7 +196,7 @@ export async function insertDataParse(
|
|
|
196
196
|
childDataItems.map((d: AnyObject) => {
|
|
197
197
|
const result = { ...d };
|
|
198
198
|
colsRefT1.map(col => {
|
|
199
|
-
result[col.references![0]
|
|
199
|
+
result[col.references![0]!.cols[0]!] = fullRootResult[col.references![0]!.fcols[0]!]
|
|
200
200
|
})
|
|
201
201
|
return result;
|
|
202
202
|
}),
|
|
@@ -216,8 +216,8 @@ export async function insertDataParse(
|
|
|
216
216
|
|
|
217
217
|
/* We expect tbl2 to have only 2 columns (media_id and foreign_id) */
|
|
218
218
|
if (!cols2 || !(
|
|
219
|
-
cols2.filter(c => c.references?.[0]
|
|
220
|
-
cols2.filter(c => c.references?.[0]
|
|
219
|
+
cols2.filter(c => c.references?.[0]?.ftable === fileTable).length === 1 &&
|
|
220
|
+
cols2.filter(c => c.references?.[0]?.ftable === _this.name).length === 1
|
|
221
221
|
)) {
|
|
222
222
|
console.log({ tbl1, tbl2, tbl3, name: _this.name, tthisName: this.name })
|
|
223
223
|
throw "Second joining table (" + tbl2 + ") not of expected format. Must contain exactly one reference column for each table (file table and target table) ";
|
|
@@ -230,14 +230,14 @@ export async function insertDataParse(
|
|
|
230
230
|
const tbl2Row: AnyObject = {};
|
|
231
231
|
|
|
232
232
|
colsRefT3.map(col => {
|
|
233
|
-
tbl2Row[col.name] = t3Child[col.references![0]
|
|
233
|
+
tbl2Row[col.name] = t3Child[col.references![0]!.fcols[0]!];
|
|
234
234
|
})
|
|
235
235
|
colsRefT1.map(col => {
|
|
236
|
-
tbl2Row[col.name] = fullRootResult[col.references![0]
|
|
236
|
+
tbl2Row[col.name] = fullRootResult[col.references![0]!.fcols[0]!];
|
|
237
237
|
})
|
|
238
238
|
// console.log({ rootResult, tbl2Row, t3Child, colsRefT3, colsRefT1, t: this.t?.ctx?.start });
|
|
239
239
|
|
|
240
|
-
await childInsert(tbl2Row, tbl2);//.then(() => {});
|
|
240
|
+
await childInsert(tbl2Row, tbl2!);//.then(() => {});
|
|
241
241
|
}));
|
|
242
242
|
|
|
243
243
|
} else {
|
|
@@ -307,7 +307,9 @@ const referencedInsert = async (tableHandler: TableHandler, dbTX: TableHandlers
|
|
|
307
307
|
const thisInfo = await tableHandler.getInfo();
|
|
308
308
|
await getJoinPath(tableHandler, targetTable);
|
|
309
309
|
|
|
310
|
-
if (!targetData || !dbTX?.[targetTable] || !("insert" in dbTX[targetTable]))
|
|
310
|
+
if (!targetData || !dbTX?.[targetTable] || !("insert" in dbTX[targetTable]!)) {
|
|
311
|
+
throw new Error("childInsertErr: Table handler missing for referenced table: " + targetTable);
|
|
312
|
+
}
|
|
311
313
|
|
|
312
314
|
const childRules = await canInsert(tableHandler, targetTable, localParams);
|
|
313
315
|
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { AnyObject, SubscribeParams } from "prostgles-types";
|
|
1
|
+
import { AnyObject, SubscribeParams, SubscriptionChannels } from "prostgles-types";
|
|
2
2
|
import { Filter, LocalParams } from "../DboBuilder";
|
|
3
3
|
import { TableRule } from "../PublishParser";
|
|
4
4
|
import { ViewHandler } from "./ViewHandler";
|
|
5
|
-
export type
|
|
6
|
-
|
|
5
|
+
export type LocalFuncs = {
|
|
6
|
+
onData: (items: AnyObject[]) => any;
|
|
7
|
+
onError?: (error: any) => void;
|
|
8
|
+
};
|
|
9
|
+
declare function subscribe(this: ViewHandler, filter: Filter, params: SubscribeParams, localFuncs: LocalFuncs): Promise<{
|
|
7
10
|
unsubscribe: () => any;
|
|
8
11
|
}>;
|
|
9
|
-
declare function subscribe(this: ViewHandler, filter: Filter, params: SubscribeParams,
|
|
12
|
+
declare function subscribe(this: ViewHandler, filter: Filter, params: SubscribeParams, localFuncs: undefined, table_rules: TableRule | undefined, localParams: LocalParams): Promise<SubscriptionChannels>;
|
|
10
13
|
export { subscribe };
|
|
11
14
|
//# sourceMappingURL=subscribe.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscribe.d.ts","sourceRoot":"","sources":["subscribe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"subscribe.d.ts","sourceRoot":"","sources":["subscribe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACnF,OAAO,EAAE,MAAM,EAAE,WAAW,EAAc,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,MAAM,MAAM,UAAU,GAAG;IACvB,MAAM,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,GAAG,CAAC;IACpC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;CAChC,CAAA;AAED,iBAAe,SAAS,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC;IAAE,WAAW,EAAE,MAAM,GAAG,CAAA;CAAE,CAAC,CAAA;AACjJ,iBAAe,SAAS,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,GAAG,SAAS,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAA;AAqFxM,OAAO,EAAE,SAAS,EAAE,CAAA"}
|
|
@@ -4,17 +4,17 @@ exports.subscribe = void 0;
|
|
|
4
4
|
const DboBuilder_1 = require("../DboBuilder");
|
|
5
5
|
const PubSubManager_1 = require("../PubSubManager/PubSubManager");
|
|
6
6
|
const getSubscribeRelatedTables_1 = require("./getSubscribeRelatedTables");
|
|
7
|
-
async function subscribe(filter, params,
|
|
7
|
+
async function subscribe(filter, params, localFuncs, table_rules, localParams) {
|
|
8
8
|
try {
|
|
9
9
|
// if (this.is_view) throw "Cannot subscribe to a view";
|
|
10
10
|
if (this.t) {
|
|
11
11
|
throw "subscribe not allowed within transactions";
|
|
12
12
|
}
|
|
13
|
-
if (!localParams && !
|
|
13
|
+
if (!localParams && !localFuncs) {
|
|
14
14
|
throw " missing data. provide -> localFunc | localParams { socket } ";
|
|
15
15
|
}
|
|
16
|
-
if (localParams?.socket &&
|
|
17
|
-
console.error({ localParams,
|
|
16
|
+
if (localParams?.socket && localFuncs) {
|
|
17
|
+
console.error({ localParams, localFuncs });
|
|
18
18
|
throw " Cannot have localFunc AND socket ";
|
|
19
19
|
}
|
|
20
20
|
const { filterFields, forcedFilter } = table_rules?.select || {}, filterOpts = await this.prepareWhere({ filter, forcedFilter, addKeywords: false, filterFields, tableAlias: undefined, localParams, tableRule: table_rules }), condition = filterOpts.where, throttle = params?.throttle || 0, selectParams = (0, PubSubManager_1.omitKeys)(params || {}, ["throttle"]);
|
|
@@ -42,27 +42,26 @@ async function subscribe(filter, params, localFunc, table_rules, localParams) {
|
|
|
42
42
|
throttle,
|
|
43
43
|
last_throttled: 0,
|
|
44
44
|
};
|
|
45
|
-
|
|
45
|
+
const pubSubManager = await this.dboBuilder.getPubSubManager();
|
|
46
|
+
if (!localFuncs) {
|
|
46
47
|
const { socket } = localParams ?? {};
|
|
47
|
-
const pubSubManager = await this.dboBuilder.getPubSubManager();
|
|
48
48
|
return pubSubManager.addSub({
|
|
49
49
|
...commonSubOpts,
|
|
50
50
|
socket,
|
|
51
|
-
|
|
51
|
+
localFuncs: undefined,
|
|
52
52
|
socket_id: socket?.id,
|
|
53
|
-
})
|
|
53
|
+
});
|
|
54
54
|
}
|
|
55
55
|
else {
|
|
56
|
-
const pubSubManager = await this.dboBuilder.getPubSubManager();
|
|
57
56
|
pubSubManager.addSub({
|
|
58
57
|
...commonSubOpts,
|
|
59
58
|
socket: undefined,
|
|
60
|
-
|
|
59
|
+
localFuncs,
|
|
61
60
|
socket_id: undefined,
|
|
62
|
-
})
|
|
61
|
+
});
|
|
63
62
|
const unsubscribe = async () => {
|
|
64
63
|
const pubSubManager = await this.dboBuilder.getPubSubManager();
|
|
65
|
-
pubSubManager.removeLocalSub(this.name, condition,
|
|
64
|
+
pubSubManager.removeLocalSub(this.name, condition, localFuncs);
|
|
66
65
|
};
|
|
67
66
|
const res = Object.freeze({ unsubscribe });
|
|
68
67
|
return res;
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import { AnyObject, SubscribeParams } from "prostgles-types";
|
|
1
|
+
import { AnyObject, SubscribeParams, SubscriptionChannels } from "prostgles-types";
|
|
2
2
|
import { Filter, LocalParams, parseError } from "../DboBuilder";
|
|
3
3
|
import { TableRule } from "../PublishParser";
|
|
4
4
|
import { omitKeys } from "../PubSubManager/PubSubManager";
|
|
5
5
|
import { ViewHandler } from "./ViewHandler";
|
|
6
6
|
import { getSubscribeRelatedTables } from "./getSubscribeRelatedTables";
|
|
7
7
|
|
|
8
|
-
export type
|
|
8
|
+
export type LocalFuncs = {
|
|
9
|
+
onData: (items: AnyObject[]) => any;
|
|
10
|
+
onError?: (error: any) => void;
|
|
11
|
+
}
|
|
9
12
|
|
|
10
|
-
async function subscribe(this: ViewHandler, filter: Filter, params: SubscribeParams,
|
|
11
|
-
async function subscribe(this: ViewHandler, filter: Filter, params: SubscribeParams,
|
|
12
|
-
async function subscribe(this: ViewHandler, filter: Filter, params: SubscribeParams,
|
|
13
|
+
async function subscribe(this: ViewHandler, filter: Filter, params: SubscribeParams, localFuncs: LocalFuncs): Promise<{ unsubscribe: () => any }>
|
|
14
|
+
async function subscribe(this: ViewHandler, filter: Filter, params: SubscribeParams, localFuncs: undefined, table_rules: TableRule | undefined, localParams: LocalParams): Promise<SubscriptionChannels>
|
|
15
|
+
async function subscribe(this: ViewHandler, filter: Filter, params: SubscribeParams, localFuncs?: LocalFuncs, table_rules?: TableRule, localParams?: LocalParams): Promise<{ unsubscribe: () => any } | SubscriptionChannels>
|
|
13
16
|
{
|
|
14
17
|
|
|
15
18
|
try {
|
|
@@ -18,11 +21,11 @@ async function subscribe(this: ViewHandler, filter: Filter, params: SubscribePar
|
|
|
18
21
|
if (this.t) {
|
|
19
22
|
throw "subscribe not allowed within transactions";
|
|
20
23
|
}
|
|
21
|
-
if (!localParams && !
|
|
24
|
+
if (!localParams && !localFuncs) {
|
|
22
25
|
throw " missing data. provide -> localFunc | localParams { socket } ";
|
|
23
26
|
}
|
|
24
|
-
if (localParams?.socket &&
|
|
25
|
-
console.error({ localParams,
|
|
27
|
+
if (localParams?.socket && localFuncs) {
|
|
28
|
+
console.error({ localParams, localFuncs })
|
|
26
29
|
throw " Cannot have localFunc AND socket ";
|
|
27
30
|
}
|
|
28
31
|
|
|
@@ -60,30 +63,29 @@ async function subscribe(this: ViewHandler, filter: Filter, params: SubscribePar
|
|
|
60
63
|
last_throttled: 0,
|
|
61
64
|
} as const;
|
|
62
65
|
|
|
63
|
-
|
|
66
|
+
const pubSubManager = await this.dboBuilder.getPubSubManager();
|
|
67
|
+
if (!localFuncs) {
|
|
64
68
|
|
|
65
69
|
const { socket } = localParams ?? {};
|
|
66
|
-
const pubSubManager = await this.dboBuilder.getPubSubManager();
|
|
67
70
|
return pubSubManager.addSub({
|
|
68
71
|
...commonSubOpts,
|
|
69
72
|
socket,
|
|
70
|
-
|
|
73
|
+
localFuncs: undefined,
|
|
71
74
|
socket_id: socket?.id,
|
|
72
|
-
})
|
|
73
|
-
|
|
75
|
+
});
|
|
76
|
+
|
|
74
77
|
} else {
|
|
75
78
|
|
|
76
|
-
const pubSubManager = await this.dboBuilder.getPubSubManager();
|
|
77
79
|
pubSubManager.addSub({
|
|
78
80
|
...commonSubOpts,
|
|
79
81
|
socket: undefined,
|
|
80
|
-
|
|
82
|
+
localFuncs,
|
|
81
83
|
socket_id: undefined,
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
+
});
|
|
85
|
+
|
|
84
86
|
const unsubscribe = async () => {
|
|
85
87
|
const pubSubManager = await this.dboBuilder.getPubSubManager();
|
|
86
|
-
pubSubManager.removeLocalSub(this.name, condition,
|
|
88
|
+
pubSubManager.removeLocalSub(this.name, condition, localFuncs)
|
|
87
89
|
};
|
|
88
90
|
const res: { unsubscribe: () => any } = Object.freeze({ unsubscribe })
|
|
89
91
|
return res;
|
package/lib/DboBuilder.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DboBuilder.d.ts","sourceRoot":"","sources":["DboBuilder.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,SAAS,MAAM,YAAY,CAAC;AAExC,OAAO,EAAE,GAAG,QAAQ,iCAAiC,CAAC,CAAC;AACvD,OAAO,EACL,UAAU,EAAE,UAAU,EACtB,WAAW,EACX,uBAAuB,EACvB,WAAW,EACX,SAAS,IAAI,KAAK,EAClB,UAAU,EACV,SAAS,
|
|
1
|
+
{"version":3,"file":"DboBuilder.d.ts","sourceRoot":"","sources":["DboBuilder.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,SAAS,MAAM,YAAY,CAAC;AAExC,OAAO,EAAE,GAAG,QAAQ,iCAAiC,CAAC,CAAC;AACvD,OAAO,EACL,UAAU,EAAE,UAAU,EACtB,WAAW,EACX,uBAAuB,EACvB,WAAW,EACX,SAAS,IAAI,KAAK,EAClB,UAAU,EACV,SAAS,EAGU,cAAc,EAAiB,UAAU,EAC7D,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,QAAQ,GAAG;IACrB,GAAG,EAAE,OAAO,CAAC;IACb,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,GAAG,CAAC;IACH,UAAU,EAAE,MAAM,CAAC;CACpB,GAAG;IACF,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC,CAAC;AAEH,MAAM,MAAM,WAAW,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,WAAW,GAAG,cAA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AE,OAAO,CAAC;QAChB,MAAM,EAAE,OAAO,CAAC;KACjB,CAAA;CACF,CAAA;AAED,KAAK,YAAY,GAAG;IAElB;;OAEG;IACH,OAAO,EACL,GAAG,GACH,GAAG,GACH,GAAG,CAAA;IAEL;;OAEG;IACH,MAAM,EAAE,MAAM,EAAE,CAAC;IAEjB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AA8NF,wBAAgB,aAAa,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAE9D;AAED,wBAAgB,gBAAgB,CAAC,aAAa,EAAE,uBAAuB,GAAG,MAAM,OAAO,WAAW,CAKjG;AAiTD,eAAO,MAAM,WAAW,UAAW,QAAQ,EAAE,6BAAyB,MASrE,CAAA;AAED,eAAO,MAAM,UAAU,8BAUtB,CAAA"}
|
package/lib/DboBuilder.js
CHANGED
|
@@ -73,12 +73,12 @@ function canBeUsedAsIsInTypescript(str) {
|
|
|
73
73
|
if (!str)
|
|
74
74
|
return false;
|
|
75
75
|
const isAlphaNumericOrUnderline = str.match(/^[a-z0-9_]+$/i);
|
|
76
|
-
const startsWithCharOrUnderscore = str[0]
|
|
76
|
+
const startsWithCharOrUnderscore = str[0]?.match(/^[a-z_]+$/i);
|
|
77
77
|
return Boolean(isAlphaNumericOrUnderline && startsWithCharOrUnderscore);
|
|
78
78
|
}
|
|
79
79
|
function escapeTSNames(str, capitalize = false) {
|
|
80
80
|
let res = str;
|
|
81
|
-
res = (capitalize ? str[0]
|
|
81
|
+
res = (capitalize ? str[0]?.toUpperCase() : str[0]) + str.slice(1);
|
|
82
82
|
if (canBeUsedAsIsInTypescript(res))
|
|
83
83
|
return res;
|
|
84
84
|
return JSON.stringify(res);
|
|
@@ -103,8 +103,9 @@ function makeErrorFromPGError(err, localParams, view, allowedKeys) {
|
|
|
103
103
|
if (constraint) {
|
|
104
104
|
const cols = view.columns.filter(c => (!allowedKeys || allowedKeys.includes(c.name)) &&
|
|
105
105
|
constraint.conkey.includes(c.ordinal_position));
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
const [firstCol] = cols;
|
|
107
|
+
if (firstCol) {
|
|
108
|
+
errObject.column = firstCol.name;
|
|
108
109
|
errObject.columns = cols.map(c => c.name);
|
|
109
110
|
}
|
|
110
111
|
}
|