prostgles-server 3.0.39 → 3.0.41
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/DBSchemaBuilder.d.ts.map +1 -1
- package/dist/DBSchemaBuilder.js.map +1 -1
- package/dist/DboBuilder/QueryBuilder/QueryBuilder.d.ts +2 -1
- package/dist/DboBuilder/QueryBuilder/QueryBuilder.d.ts.map +1 -1
- package/dist/DboBuilder/QueryBuilder/QueryBuilder.js +2 -1
- package/dist/DboBuilder/QueryBuilder/QueryBuilder.js.map +1 -1
- package/dist/DboBuilder/QueryBuilder/makeSelectQuery.d.ts +1 -1
- package/dist/DboBuilder/QueryBuilder/makeSelectQuery.d.ts.map +1 -1
- package/dist/DboBuilder/QueryBuilder/makeSelectQuery.js.map +1 -1
- package/dist/DboBuilder/TableHandler.d.ts +62 -0
- package/dist/DboBuilder/TableHandler.d.ts.map +1 -0
- package/dist/DboBuilder/TableHandler.js +304 -0
- package/dist/DboBuilder/TableHandler.js.map +1 -0
- package/dist/DboBuilder/ViewHandler.d.ts +137 -0
- package/dist/DboBuilder/ViewHandler.d.ts.map +1 -0
- package/dist/DboBuilder/ViewHandler.js +1292 -0
- package/dist/DboBuilder/ViewHandler.js.map +1 -0
- package/dist/DboBuilder/delete.d.ts +2 -1
- package/dist/DboBuilder/delete.d.ts.map +1 -1
- package/dist/DboBuilder/delete.js.map +1 -1
- package/dist/DboBuilder/getColumns.d.ts +12 -0
- package/dist/DboBuilder/getColumns.d.ts.map +1 -0
- package/dist/DboBuilder/getColumns.js +95 -0
- package/dist/DboBuilder/getColumns.js.map +1 -0
- package/dist/DboBuilder/insert.d.ts +2 -1
- package/dist/DboBuilder/insert.d.ts.map +1 -1
- package/dist/DboBuilder/insert.js +1 -1
- package/dist/DboBuilder/insert.js.map +1 -1
- package/dist/DboBuilder/insertDataParse.d.ts +2 -1
- package/dist/DboBuilder/insertDataParse.d.ts.map +1 -1
- package/dist/DboBuilder/insertDataParse.js +2 -3
- package/dist/DboBuilder/insertDataParse.js.map +1 -1
- package/dist/DboBuilder/parseUpdateRules.d.ts +18 -0
- package/dist/DboBuilder/parseUpdateRules.d.ts.map +1 -0
- package/dist/DboBuilder/parseUpdateRules.js +119 -0
- package/dist/DboBuilder/parseUpdateRules.js.map +1 -0
- package/dist/DboBuilder/update.d.ts +2 -1
- package/dist/DboBuilder/update.d.ts.map +1 -1
- package/dist/DboBuilder/update.js.map +1 -1
- package/dist/DboBuilder/uploadFile.d.ts +2 -1
- package/dist/DboBuilder/uploadFile.d.ts.map +1 -1
- package/dist/DboBuilder/uploadFile.js.map +1 -1
- package/dist/DboBuilder.d.ts +5 -185
- package/dist/DboBuilder.d.ts.map +1 -1
- package/dist/DboBuilder.js +7 -1774
- package/dist/DboBuilder.js.map +1 -1
- package/dist/FileManager.d.ts.map +1 -1
- package/dist/FileManager.js +4 -4
- package/dist/FileManager.js.map +1 -1
- package/dist/PublishParser.d.ts.map +1 -1
- package/dist/PublishParser.js.map +1 -1
- package/dist/index.js +0 -38
- package/dist/index.js.map +1 -1
- package/lib/DBSchemaBuilder.d.ts.map +1 -1
- package/lib/DBSchemaBuilder.ts +1 -1
- package/lib/DboBuilder/QueryBuilder/QueryBuilder.d.ts +2 -1
- package/lib/DboBuilder/QueryBuilder/QueryBuilder.d.ts.map +1 -1
- package/lib/DboBuilder/QueryBuilder/QueryBuilder.js +2 -1
- package/lib/DboBuilder/QueryBuilder/QueryBuilder.ts +3 -1
- package/lib/DboBuilder/QueryBuilder/makeSelectQuery.d.ts +1 -1
- package/lib/DboBuilder/QueryBuilder/makeSelectQuery.d.ts.map +1 -1
- package/lib/DboBuilder/QueryBuilder/makeSelectQuery.ts +2 -1
- package/lib/DboBuilder/TableHandler.d.ts +54 -0
- package/lib/DboBuilder/TableHandler.d.ts.map +1 -0
- package/lib/DboBuilder/TableHandler.js +303 -0
- package/lib/DboBuilder/TableHandler.ts +365 -0
- package/lib/DboBuilder/ViewHandler.d.ts +133 -0
- package/lib/DboBuilder/ViewHandler.d.ts.map +1 -0
- package/lib/DboBuilder/ViewHandler.js +1291 -0
- package/lib/DboBuilder/ViewHandler.ts +1542 -0
- package/lib/DboBuilder/delete.d.ts +2 -1
- package/lib/DboBuilder/delete.d.ts.map +1 -1
- package/lib/DboBuilder/delete.ts +2 -1
- package/lib/DboBuilder/getColumns.d.ts +12 -0
- package/lib/DboBuilder/getColumns.d.ts.map +1 -0
- package/lib/DboBuilder/getColumns.js +94 -0
- package/lib/DboBuilder/getColumns.ts +133 -0
- package/lib/DboBuilder/insert.d.ts +2 -1
- package/lib/DboBuilder/insert.d.ts.map +1 -1
- package/lib/DboBuilder/insert.js +1 -1
- package/lib/DboBuilder/insert.ts +3 -2
- package/lib/DboBuilder/insertDataParse.d.ts +2 -1
- package/lib/DboBuilder/insertDataParse.d.ts.map +1 -1
- package/lib/DboBuilder/insertDataParse.js +2 -3
- package/lib/DboBuilder/insertDataParse.ts +6 -5
- package/lib/DboBuilder/parseUpdateRules.d.ts +18 -0
- package/lib/DboBuilder/parseUpdateRules.d.ts.map +1 -0
- package/lib/DboBuilder/parseUpdateRules.js +118 -0
- package/lib/DboBuilder/parseUpdateRules.ts +156 -0
- package/lib/DboBuilder/update.d.ts +2 -1
- package/lib/DboBuilder/update.d.ts.map +1 -1
- package/lib/DboBuilder/update.ts +2 -1
- package/lib/DboBuilder/uploadFile.d.ts +2 -1
- package/lib/DboBuilder/uploadFile.d.ts.map +1 -1
- package/lib/DboBuilder/uploadFile.ts +2 -1
- package/lib/DboBuilder.d.ts +5 -185
- package/lib/DboBuilder.d.ts.map +1 -1
- package/lib/DboBuilder.js +7 -1774
- package/lib/DboBuilder.ts +169 -2297
- package/lib/FileManager.d.ts.map +1 -1
- package/lib/FileManager.js +4 -4
- package/lib/FileManager.ts +3 -1
- package/lib/PublishParser.d.ts.map +1 -1
- package/lib/PublishParser.ts +3 -1
- package/lib/SyncReplication.ts +1 -1
- package/lib/index.js +0 -38
- package/lib/index.ts +1 -53
- package/package.json +1 -1
- package/tests/client/PID.txt +1 -1
- package/tests/server/package-lock.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5,42 +5,4 @@ function prostgles(params) {
|
|
|
5
5
|
return prgl.init(params.onReady);
|
|
6
6
|
}
|
|
7
7
|
module.exports = prostgles;
|
|
8
|
-
// declare const init (params: InitOptions) => {
|
|
9
|
-
// let prgl = new Prostgles(params);
|
|
10
|
-
// prgl.init(params.isReady);
|
|
11
|
-
// }
|
|
12
|
-
// module.exports = {
|
|
13
|
-
// pgp,
|
|
14
|
-
// init,
|
|
15
|
-
// Prostgles
|
|
16
|
-
// }
|
|
17
|
-
// module.exports = prostgles;
|
|
18
|
-
// module.exports = init;
|
|
19
|
-
// declare module "ProstglesServer" {
|
|
20
|
-
// function iinit(params: InitOptions): void ;
|
|
21
|
-
// // namespace iinit {
|
|
22
|
-
// // interface ReduxLoggerOptions {
|
|
23
|
-
// // actionTransformer?: (action: any) => any;
|
|
24
|
-
// // collapsed?: boolean;
|
|
25
|
-
// // duration?: boolean;
|
|
26
|
-
// // level?: string;
|
|
27
|
-
// // logger?: any;
|
|
28
|
-
// // predicate?: (getState: Function, action: any) => boolean;
|
|
29
|
-
// // timestamp?: boolean;
|
|
30
|
-
// // transformer?: (state:any) => any;
|
|
31
|
-
// // }
|
|
32
|
-
// // }
|
|
33
|
-
// export = iinit;
|
|
34
|
-
// // export = init;
|
|
35
|
-
// }
|
|
36
|
-
//var init =
|
|
37
|
-
// export function init(params: InitOptions){
|
|
38
|
-
// let prgl = new Prostgles(params);
|
|
39
|
-
// prgl.init(params.isReady);
|
|
40
|
-
// }
|
|
41
|
-
// declare const init (params: InitOptions) => {
|
|
42
|
-
// let prgl = new Prostgles(params);
|
|
43
|
-
// prgl.init(params.isReady);
|
|
44
|
-
// }
|
|
45
|
-
// export = init;
|
|
46
8
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";AACA,2CAA0E;AAE1E,SAAS,SAAS,CAAoD,MAAsC;IAExG,IAAI,IAAI,GAAG,IAAI,qBAAS,CAAC,MAAa,CAAC,CAAC;IACxC,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAc,CAAC,CAAC;AAC5C,CAAC;AACD,iBAAS,SAAS,CAAC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";AACA,2CAA0E;AAE1E,SAAS,SAAS,CAAoD,MAAsC;IAExG,IAAI,IAAI,GAAG,IAAI,qBAAS,CAAC,MAAa,CAAC,CAAC;IACxC,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAc,CAAC,CAAC;AAC5C,CAAC;AACD,iBAAS,SAAS,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DBSchemaBuilder.d.ts","sourceRoot":"","sources":["DBSchemaBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAY,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAGhF,OAAO,EAAE,eAAe,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"DBSchemaBuilder.d.ts","sourceRoot":"","sources":["DBSchemaBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAY,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAGhF,OAAO,EAAE,eAAe,EAAE,UAAU,EAAmC,MAAM,cAAc,CAAC;AAC5F,OAAO,EAAE,mBAAmB,EAAiB,gBAAgB,EAAE,eAAe,EAAI,MAAM,iBAAiB,CAAC;AAI1G,eAAO,MAAM,WAAW,eAAgB,UAAU,KAAG,MAyCpD,CAAA;AAED,aAAK,yBAAyB,CAAC,MAAM,GAAG,IAAI,IAAI,MAAM,SAAS,QAAQ,GAAE;KACtE,QAAQ,IAAI,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,SAAS,IAAI,GAClE,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,GACxC,YAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC;CAC5C,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;AAEjC,oBAAY,aAAa,CAAC,MAAM,GAAG,IAAI,IAAI,MAAM,SAAS,QAAQ,GAAE,CAChE,yBAAyB,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,GAAG,KAAK,CAAC,CAC3G,GACD,eAAe,CAAC;AAKlB,oBAAY,iBAAiB,CAAC,MAAM,GAAG,IAAI,IAAI,MAAM,SAAS,QAAQ,GAAE,CACpE,mBAAmB,GACnB;KACC,QAAQ,IAAI,MAAM,OAAO,CAAC,MAAM,CAAC,GAC9B,mBAAmB,GACnB,CACA,MAAM,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,SAAS,IAAI,GACtC,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,GACpD,gBAAgB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,CACxD;CACJ,CACF,GAAG,CACA,mBAAmB,GACnB,MAAM,CAAC,MAAM,EAAE,eAAe,GAAG,gBAAgB,GAAG,mBAAmB,CAAC,CAC3E,CAAC"}
|
package/lib/DBSchemaBuilder.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DBSchema, isObject, TableHandler, ViewHandler } from "prostgles-types";
|
|
2
2
|
import prostgles from ".";
|
|
3
3
|
import { Auth } from "./AuthHandler";
|
|
4
|
-
import { DBHandlerServer, DboBuilder, escapeTSNames, postgresToTsType
|
|
4
|
+
import { DBHandlerServer, DboBuilder, escapeTSNames, postgresToTsType } from "./DboBuilder";
|
|
5
5
|
import { PublishAllOrNothing, PublishParams, PublishTableRule, PublishViewRule, } from "./PublishParser";
|
|
6
6
|
import { getJSONBSchemaTSTypes } from "./validation";
|
|
7
7
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Filter, LocalParams,
|
|
1
|
+
import { Filter, LocalParams, SortItem } from "../../DboBuilder";
|
|
2
2
|
import { TableRule } from "../../PublishParser";
|
|
3
3
|
import { SelectParams, ColumnInfo, PG_COLUMN_UDT_DATA_TYPE, Select } from "prostgles-types";
|
|
4
|
+
import { TableHandler } from "../TableHandler";
|
|
4
5
|
export declare type SelectItem = {
|
|
5
6
|
type: "column" | "function" | "aggregation" | "joinedColumn" | "computed";
|
|
6
7
|
getFields: (args?: any[]) => string[] | "*";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryBuilder.d.ts","sourceRoot":"","sources":["QueryBuilder.ts"],"names":[],"mappings":"AAMA,OAAO,EAAO,MAAM,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"QueryBuilder.d.ts","sourceRoot":"","sources":["QueryBuilder.ts"],"names":[],"mappings":"AAMA,OAAO,EAAO,MAAM,EAAE,WAAW,EAAmC,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACvG,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAqE,UAAU,EAAE,uBAAuB,EAAY,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzK,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAI/C,oBAAY,UAAU,GAAG;IACvB,IAAI,EAAE,QAAQ,GAAG,UAAU,GAAG,aAAa,GAAG,cAAc,GAAG,UAAU,CAAC;IAC1E,SAAS,EAAE,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,KAAK,MAAM,EAAE,GAAG,GAAG,CAAC;IAC5C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OAAO,CAAC,8BAA8B,CAAW;IACjD,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,OAAO,CAAe;gBAElB,MAAM,EAAE;QAAE,aAAa,EAAE,MAAM,EAAE,CAAC;QAAC,oBAAoB,EAAE,MAAM,EAAE,CAAC;QAAC,cAAc,EAAE,SAAS,EAAE,CAAC;QAAC,SAAS,EAAE,YAAY,EAAE,CAAC;QAAC,SAAS,EAAE,MAAM,EAAE,CAAC;QAAC,MAAM,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,UAAU,EAAE,CAAC;KAAE;IAoBrM,OAAO,CAAC,UAAU,CASjB;IAED,OAAO,CAAC,OAAO,CAUd;IAED,OAAO,CAAC,WAAW,CAkBlB;IAED,SAAS,cAAe,MAAM,YAAY,OAAO,UA6BhD;IAED,eAAe,eAAsB,MAAM,oBAAoB,MAAM,OAAO,GAAG,kBAAkB,MAAM,KAAK,GAAG,KAAK,GAAG,oBAiGtH;CAEF;AAED,wBAAsB,WAAW,CAC/B,KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,CAAC,YAAY,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAO,EACvD,aAAa,KAAO,EACpB,UAAU,EAAE,SAAS,GAAG,SAAS,EACjC,WAAW,EAAE,WAAW,GAAG,SAAS,EACpC,OAAO,EAAE,UAAU,EAAE,GACpB,OAAO,CAAC,QAAQ,CAAC,CAkJnB"}
|
|
@@ -8,6 +8,7 @@ exports.getNewQuery = exports.SelectItemBuilder = exports.COMPUTED_FIELDS = expo
|
|
|
8
8
|
const DboBuilder_1 = require("../../DboBuilder");
|
|
9
9
|
const prostgles_types_1 = require("prostgles-types");
|
|
10
10
|
const utils_1 = require("../../utils");
|
|
11
|
+
const ViewHandler_1 = require("../ViewHandler");
|
|
11
12
|
const asNameAlias = (field, tableAlias) => {
|
|
12
13
|
let result = (0, prostgles_types_1.asName)(field);
|
|
13
14
|
if (tableAlias)
|
|
@@ -716,7 +717,7 @@ exports.FUNCTIONS = [
|
|
|
716
717
|
canBeUsedForFilter: true,
|
|
717
718
|
getFields: (args) => args[0],
|
|
718
719
|
getQuery: ({ allowedFields, args, tableAlias, allColumns }) => {
|
|
719
|
-
const cols =
|
|
720
|
+
const cols = ViewHandler_1.ViewHandler._parseFieldFilter(args[0], false, allowedFields);
|
|
720
721
|
let term = args[1];
|
|
721
722
|
const rawTerm = args[1];
|
|
722
723
|
let { edgeTruncate, noFields = false, returnType, matchCase = false } = args[2] || {};
|
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
* Licensed under the MIT License. See LICENSE in the project root for license information.
|
|
5
5
|
*--------------------------------------------------------------------------------------------*/
|
|
6
6
|
|
|
7
|
-
import { pgp, Filter, LocalParams, isPlainObject,
|
|
7
|
+
import { pgp, Filter, LocalParams, isPlainObject, postgresToTsType, SortItem } from "../../DboBuilder";
|
|
8
8
|
import { TableRule } from "../../PublishParser";
|
|
9
9
|
import { SelectParams, isEmpty, FieldFilter, asName, TextFilter_FullTextSearchFilterKeys, ColumnInfo, PG_COLUMN_UDT_DATA_TYPE, isObject, Select } from "prostgles-types";
|
|
10
10
|
import { get } from "../../utils";
|
|
11
|
+
import { TableHandler } from "../TableHandler";
|
|
12
|
+
import { ViewHandler } from "../ViewHandler";
|
|
11
13
|
|
|
12
14
|
|
|
13
15
|
export type SelectItem = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { TableHandler } from "../../DboBuilder";
|
|
2
1
|
import { SelectParams } from "prostgles-types";
|
|
3
2
|
import { NewQuery } from "./QueryBuilder";
|
|
3
|
+
import { TableHandler } from "../TableHandler";
|
|
4
4
|
export declare function makeSelectQuery(_this: TableHandler, q: NewQuery, depth?: number, joinFields?: string[], selectParams?: SelectParams): string;
|
|
5
5
|
//# sourceMappingURL=makeSelectQuery.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"makeSelectQuery.d.ts","sourceRoot":"","sources":["makeSelectQuery.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"makeSelectQuery.d.ts","sourceRoot":"","sources":["makeSelectQuery.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAU,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAc,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAG/C,wBAAgB,eAAe,CAC7B,KAAK,EAAE,YAAY,EACnB,CAAC,EAAE,QAAQ,EACX,KAAK,GAAE,MAAU,EACjB,UAAU,GAAE,MAAM,EAAO,EACzB,YAAY,GAAE,YAAiB,GAC9B,MAAM,CA2RR"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
|
|
2
|
-
import { prepareSort
|
|
2
|
+
import { prepareSort } from "../../DboBuilder";
|
|
3
3
|
import { SelectParams, asName } from "prostgles-types";
|
|
4
4
|
import { NewQuery, SelectItem } from "./QueryBuilder";
|
|
5
|
+
import { TableHandler } from "../TableHandler";
|
|
5
6
|
|
|
6
7
|
/* No validation/authorisation at this point */
|
|
7
8
|
export function makeSelectQuery(
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import pgPromise from "pg-promise";
|
|
2
|
+
import { AnyObject, DeleteParams, FieldFilter, InsertParams, Select, SelectParams, SubscribeParams, UpdateParams } from "prostgles-types";
|
|
3
|
+
import { DboBuilder, Filter, LocalParams, TableHandlers, TableSchema } from "../DboBuilder";
|
|
4
|
+
import { DB } from "../Prostgles";
|
|
5
|
+
import { TableRule } from "../PublishParser";
|
|
6
|
+
import { insertDataParse } from "./insertDataParse";
|
|
7
|
+
import { SelectItem } from "./QueryBuilder/QueryBuilder";
|
|
8
|
+
import { JoinPaths, ViewHandler } from "./ViewHandler";
|
|
9
|
+
declare type ValidatedParams = {
|
|
10
|
+
row: AnyObject;
|
|
11
|
+
forcedData?: AnyObject;
|
|
12
|
+
allowedFields?: FieldFilter;
|
|
13
|
+
tableRules?: TableRule;
|
|
14
|
+
fixIssues: boolean;
|
|
15
|
+
};
|
|
16
|
+
export declare class TableHandler extends ViewHandler {
|
|
17
|
+
io_stats: {
|
|
18
|
+
throttle_queries_per_sec: number;
|
|
19
|
+
since: number;
|
|
20
|
+
queries: number;
|
|
21
|
+
batching: string[] | null;
|
|
22
|
+
};
|
|
23
|
+
constructor(db: DB, tableOrViewInfo: TableSchema, dboBuilder: DboBuilder, t?: pgPromise.ITask<{}>, dbTX?: TableHandlers, joinPaths?: JoinPaths);
|
|
24
|
+
willBatch(query: string): boolean;
|
|
25
|
+
subscribe(filter: Filter, params: SubscribeParams, localFunc: (items: AnyObject[]) => any): Promise<{
|
|
26
|
+
unsubscribe: () => any;
|
|
27
|
+
}>;
|
|
28
|
+
subscribe(filter: Filter, params: SubscribeParams, localFunc?: (items: AnyObject[]) => any, table_rules?: TableRule, localParams?: LocalParams): Promise<string>;
|
|
29
|
+
subscribeOne(filter: Filter, params: SubscribeParams, localFunc: (item: AnyObject) => any): Promise<{
|
|
30
|
+
unsubscribe: () => any;
|
|
31
|
+
}>;
|
|
32
|
+
subscribeOne(filter: Filter, params: SubscribeParams, localFunc: (item: AnyObject) => any, table_rules?: TableRule, localParams?: LocalParams): Promise<string>;
|
|
33
|
+
updateBatch(data: [Filter, AnyObject][], params?: UpdateParams, tableRules?: TableRule, localParams?: LocalParams): Promise<any>;
|
|
34
|
+
parseUpdateRules: any;
|
|
35
|
+
update: any;
|
|
36
|
+
validateNewData({ row, forcedData, allowedFields, tableRules, fixIssues }: ValidatedParams): {
|
|
37
|
+
data: any;
|
|
38
|
+
allowedCols: string[];
|
|
39
|
+
};
|
|
40
|
+
insertDataParse: typeof insertDataParse;
|
|
41
|
+
insert(rowOrRows: (AnyObject | AnyObject[]), param2?: InsertParams, param3_unused?: undefined, tableRules?: TableRule, _localParams?: LocalParams): Promise<any | any[] | boolean>;
|
|
42
|
+
prepareReturning: (returning: Select | undefined, allowedFields: string[]) => Promise<SelectItem[]>;
|
|
43
|
+
makeReturnQuery(items?: SelectItem[]): string;
|
|
44
|
+
delete(filter?: Filter, params?: DeleteParams, param3_unused?: undefined, table_rules?: TableRule, localParams?: LocalParams): Promise<any>;
|
|
45
|
+
remove(filter: Filter, params?: UpdateParams, param3_unused?: undefined, tableRules?: TableRule, localParams?: LocalParams): Promise<any>;
|
|
46
|
+
upsert(filter: Filter, newData: AnyObject, params?: UpdateParams, table_rules?: TableRule, localParams?: LocalParams): Promise<any>;
|
|
47
|
+
sync(filter: Filter, params: SelectParams, param3_unused: undefined, table_rules: TableRule, localParams: LocalParams): Promise<{
|
|
48
|
+
channelName: string;
|
|
49
|
+
id_fields: string[];
|
|
50
|
+
synced_field: string;
|
|
51
|
+
}>;
|
|
52
|
+
}
|
|
53
|
+
export {};
|
|
54
|
+
//# sourceMappingURL=TableHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TableHandler.d.ts","sourceRoot":"","sources":["TableHandler.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,SAAS,EAAU,YAAY,EAAE,WAAW,EAAW,YAAY,EAAuB,MAAM,EAAE,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAChL,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAuB,aAAa,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjH,OAAO,EAAE,EAAE,EAAE,MAAM,cAAc,CAAC;AAClC,OAAO,EAAY,SAAS,EAA8C,MAAM,kBAAkB,CAAC;AAInG,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAA8B,UAAU,EAAqB,MAAM,6BAA6B,CAAC;AAExG,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAIvD,aAAK,eAAe,GAAG;IACrB,GAAG,EAAE,SAAS,CAA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AE,YAAY,EAAE,aAAa,CAAC,EAAE,SAAS,EAAE,UAAU,CAAC,EAAE,SAAS,EAAE,WAAW,CAAC,EAAE,WAAW;IAIpH,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,YAAY,EAAE,WAAW,CAAC,EAAE,SAAS,EAAE,WAAW,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC;IA0BnI,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW;;;;;CAiG5H"}
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TableHandler = void 0;
|
|
4
|
+
const prostgles_types_1 = require("prostgles-types");
|
|
5
|
+
const DboBuilder_1 = require("../DboBuilder");
|
|
6
|
+
const PubSubManager_1 = require("../PubSubManager");
|
|
7
|
+
const delete_1 = require("./delete");
|
|
8
|
+
const insert_1 = require("./insert");
|
|
9
|
+
const insertDataParse_1 = require("./insertDataParse");
|
|
10
|
+
const QueryBuilder_1 = require("./QueryBuilder/QueryBuilder");
|
|
11
|
+
const update_1 = require("./update");
|
|
12
|
+
const ViewHandler_1 = require("./ViewHandler");
|
|
13
|
+
const parseUpdateRules_1 = require("./parseUpdateRules");
|
|
14
|
+
class TableHandler extends ViewHandler_1.ViewHandler {
|
|
15
|
+
constructor(db, tableOrViewInfo, dboBuilder, t, dbTX, joinPaths) {
|
|
16
|
+
super(db, tableOrViewInfo, dboBuilder, t, dbTX, joinPaths);
|
|
17
|
+
this.parseUpdateRules = parseUpdateRules_1.parseUpdateRules.bind(this);
|
|
18
|
+
this.update = update_1.update.bind(this);
|
|
19
|
+
this.insertDataParse = insertDataParse_1.insertDataParse;
|
|
20
|
+
this.prepareReturning = async (returning, allowedFields) => {
|
|
21
|
+
let result = [];
|
|
22
|
+
if (returning) {
|
|
23
|
+
let sBuilder = new QueryBuilder_1.SelectItemBuilder({
|
|
24
|
+
allFields: this.column_names.slice(0),
|
|
25
|
+
allowedFields,
|
|
26
|
+
allowedOrderByFields: allowedFields,
|
|
27
|
+
computedFields: QueryBuilder_1.COMPUTED_FIELDS,
|
|
28
|
+
functions: QueryBuilder_1.FUNCTIONS.filter(f => f.type === "function" && f.singleColArg),
|
|
29
|
+
isView: this.is_view,
|
|
30
|
+
columns: this.columns,
|
|
31
|
+
});
|
|
32
|
+
await sBuilder.parseUserSelect(returning);
|
|
33
|
+
return sBuilder.select;
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
this.remove = this.delete;
|
|
38
|
+
this.io_stats = {
|
|
39
|
+
since: Date.now(),
|
|
40
|
+
queries: 0,
|
|
41
|
+
throttle_queries_per_sec: 500,
|
|
42
|
+
batching: null
|
|
43
|
+
};
|
|
44
|
+
this.is_view = false;
|
|
45
|
+
this.is_media = dboBuilder.prostgles.isMedia(this.name);
|
|
46
|
+
}
|
|
47
|
+
/* TO DO: Maybe finished query batching */
|
|
48
|
+
willBatch(query) {
|
|
49
|
+
const now = Date.now();
|
|
50
|
+
if (this.io_stats.since < Date.now()) {
|
|
51
|
+
this.io_stats.since = Date.now();
|
|
52
|
+
this.io_stats.queries = 0;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
this.io_stats.queries++;
|
|
56
|
+
}
|
|
57
|
+
if (this.io_stats.queries > this.io_stats.throttle_queries_per_sec) {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async subscribe(filter, params = {}, localFunc, table_rules, localParams) {
|
|
62
|
+
try {
|
|
63
|
+
if (this.is_view)
|
|
64
|
+
throw "Cannot subscribe to a view";
|
|
65
|
+
if (this.t)
|
|
66
|
+
throw "subscribe not allowed within transactions";
|
|
67
|
+
if (!localParams && !localFunc)
|
|
68
|
+
throw " missing data. provide -> localFunc | localParams { socket } ";
|
|
69
|
+
if (localParams && localParams.socket && localFunc) {
|
|
70
|
+
console.error({ localParams, localFunc });
|
|
71
|
+
throw " Cannot have localFunc AND socket ";
|
|
72
|
+
}
|
|
73
|
+
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"]);
|
|
74
|
+
// const { subOne = false } = localParams || {};
|
|
75
|
+
const filterSize = JSON.stringify(filter || {}).length;
|
|
76
|
+
if (filterSize * 4 > 2704) {
|
|
77
|
+
throw "filter too big. Might exceed the btree version 4 maximum 2704";
|
|
78
|
+
}
|
|
79
|
+
if (!localFunc) {
|
|
80
|
+
if (!this.dboBuilder.prostgles.isSuperUser)
|
|
81
|
+
throw "Subscribe not possible. Must be superuser to add triggers 1856";
|
|
82
|
+
return await this.find(filter, { ...selectParams, limit: 0 }, undefined, table_rules, localParams)
|
|
83
|
+
.then(async (isValid) => {
|
|
84
|
+
const { socket } = localParams ?? {};
|
|
85
|
+
const pubSubManager = await this.dboBuilder.getPubSubManager();
|
|
86
|
+
return pubSubManager.addSub({
|
|
87
|
+
table_info: this.tableOrViewInfo,
|
|
88
|
+
socket,
|
|
89
|
+
table_rules,
|
|
90
|
+
condition: condition,
|
|
91
|
+
func: undefined,
|
|
92
|
+
filter: { ...filter },
|
|
93
|
+
params: { ...selectParams },
|
|
94
|
+
socket_id: socket?.id,
|
|
95
|
+
table_name: this.name,
|
|
96
|
+
throttle,
|
|
97
|
+
last_throttled: 0,
|
|
98
|
+
// subOne
|
|
99
|
+
}).then(channelName => ({ channelName }));
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
const pubSubManager = await this.dboBuilder.getPubSubManager();
|
|
104
|
+
pubSubManager.addSub({
|
|
105
|
+
table_info: this.tableOrViewInfo,
|
|
106
|
+
socket: undefined,
|
|
107
|
+
table_rules,
|
|
108
|
+
condition,
|
|
109
|
+
func: localFunc,
|
|
110
|
+
filter: { ...filter },
|
|
111
|
+
params: { ...selectParams },
|
|
112
|
+
socket_id: undefined,
|
|
113
|
+
table_name: this.name,
|
|
114
|
+
throttle,
|
|
115
|
+
last_throttled: 0,
|
|
116
|
+
// subOne
|
|
117
|
+
}).then(channelName => ({ channelName }));
|
|
118
|
+
const unsubscribe = async () => {
|
|
119
|
+
const pubSubManager = await this.dboBuilder.getPubSubManager();
|
|
120
|
+
pubSubManager.removeLocalSub(this.name, condition, localFunc);
|
|
121
|
+
};
|
|
122
|
+
let res = Object.freeze({ unsubscribe });
|
|
123
|
+
return res;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
catch (e) {
|
|
127
|
+
if (localParams && localParams.testRule)
|
|
128
|
+
throw e;
|
|
129
|
+
throw (0, DboBuilder_1.parseError)(e, `dbo.${this.name}.subscribe()`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
subscribeOne(filter, params = {}, localFunc, table_rules, localParams) {
|
|
133
|
+
let func = localParams ? undefined : (rows) => localFunc(rows[0]);
|
|
134
|
+
return this.subscribe(filter, { ...params, limit: 2 }, func, table_rules, localParams);
|
|
135
|
+
}
|
|
136
|
+
async updateBatch(data, params, tableRules, localParams) {
|
|
137
|
+
try {
|
|
138
|
+
const queries = await Promise.all(data.map(async ([filter, data]) => await this.update(filter, data, { ...(params || {}), returning: undefined }, tableRules, { ...(localParams || {}), returnQuery: true })));
|
|
139
|
+
const keys = (data && data.length) ? Object.keys(data[0]) : [];
|
|
140
|
+
return this.db.tx(t => {
|
|
141
|
+
const _queries = queries.map(q => t.none(q));
|
|
142
|
+
return t.batch(_queries);
|
|
143
|
+
}).catch(err => (0, DboBuilder_1.makeErr)(err, localParams, this, keys));
|
|
144
|
+
}
|
|
145
|
+
catch (e) {
|
|
146
|
+
if (localParams && localParams.testRule)
|
|
147
|
+
throw e;
|
|
148
|
+
throw (0, DboBuilder_1.parseError)(e, `dbo.${this.name}.update()`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
validateNewData({ row, forcedData, allowedFields, tableRules, fixIssues = false }) {
|
|
152
|
+
const synced_field = (tableRules ?? {})?.sync?.synced_field;
|
|
153
|
+
/* Update synced_field if sync is on and missing */
|
|
154
|
+
if (synced_field && !row[synced_field]) {
|
|
155
|
+
row[synced_field] = Date.now();
|
|
156
|
+
}
|
|
157
|
+
let data = this.prepareFieldValues(row, forcedData, allowedFields, fixIssues);
|
|
158
|
+
const dataKeys = (0, prostgles_types_1.getKeys)(data);
|
|
159
|
+
dataKeys.map(col => {
|
|
160
|
+
this.dboBuilder.prostgles?.tableConfigurator?.checkColVal({ table: this.name, col, value: data[col] });
|
|
161
|
+
const colConfig = this.dboBuilder.prostgles?.tableConfigurator?.getColumnConfig(this.name, col);
|
|
162
|
+
if (colConfig && (0, prostgles_types_1.isObject)(colConfig) && "isText" in colConfig && data[col]) {
|
|
163
|
+
if (colConfig.lowerCased) {
|
|
164
|
+
data[col] = data[col].toString().toLowerCase();
|
|
165
|
+
}
|
|
166
|
+
if (colConfig.trimmed) {
|
|
167
|
+
data[col] = data[col].toString().trim();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
return { data, allowedCols: this.columns.filter(c => dataKeys.includes(c.name)).map(c => c.name) };
|
|
172
|
+
}
|
|
173
|
+
async insert(rowOrRows, param2, param3_unused, tableRules, _localParams) {
|
|
174
|
+
return insert_1.insert.bind(this)(rowOrRows, param2, param3_unused, tableRules, _localParams);
|
|
175
|
+
}
|
|
176
|
+
makeReturnQuery(items) {
|
|
177
|
+
if (items?.length)
|
|
178
|
+
return " RETURNING " + items.map(s => s.getQuery() + " AS " + (0, prostgles_types_1.asName)(s.alias)).join(", ");
|
|
179
|
+
return "";
|
|
180
|
+
}
|
|
181
|
+
async delete(filter, params, param3_unused, table_rules, localParams) {
|
|
182
|
+
return delete_1._delete.bind(this)(filter, params, param3_unused, table_rules, localParams);
|
|
183
|
+
}
|
|
184
|
+
;
|
|
185
|
+
remove(filter, params, param3_unused, tableRules, localParams) {
|
|
186
|
+
return this.delete(filter, params, param3_unused, tableRules, localParams);
|
|
187
|
+
}
|
|
188
|
+
async upsert(filter, newData, params, table_rules, localParams) {
|
|
189
|
+
try {
|
|
190
|
+
/* Do it within a transaction to ensure consisency */
|
|
191
|
+
if (!this.t) {
|
|
192
|
+
return this.dboBuilder.getTX(dbTX => _upsert(dbTX[this.name]));
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
return _upsert(this);
|
|
196
|
+
}
|
|
197
|
+
async function _upsert(tblH) {
|
|
198
|
+
return tblH.find(filter, { select: "", limit: 1 }, undefined, table_rules, localParams)
|
|
199
|
+
.then(exists => {
|
|
200
|
+
if (exists && exists.length) {
|
|
201
|
+
return tblH.update(filter, newData, params, table_rules, localParams);
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
return tblH.insert({ ...newData, ...filter }, params, undefined, table_rules, localParams);
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
catch (e) {
|
|
210
|
+
if (localParams && localParams.testRule)
|
|
211
|
+
throw e;
|
|
212
|
+
throw (0, DboBuilder_1.parseError)(e, `dbo.${this.name}.upsert()`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
;
|
|
216
|
+
/* External request. Cannot sync from server */
|
|
217
|
+
async sync(filter, params, param3_unused, table_rules, localParams) {
|
|
218
|
+
if (!localParams)
|
|
219
|
+
throw "Sync not allowed within the same server code";
|
|
220
|
+
const { socket } = localParams;
|
|
221
|
+
if (!socket)
|
|
222
|
+
throw "INTERNAL ERROR: socket missing";
|
|
223
|
+
if (!table_rules || !table_rules.sync || !table_rules.select)
|
|
224
|
+
throw "INTERNAL ERROR: sync or select rules missing";
|
|
225
|
+
if (this.t)
|
|
226
|
+
throw "Sync not allowed within transactions";
|
|
227
|
+
const ALLOWED_PARAMS = ["select"];
|
|
228
|
+
const invalidParams = Object.keys(params || {}).filter(k => !ALLOWED_PARAMS.includes(k));
|
|
229
|
+
if (invalidParams.length)
|
|
230
|
+
throw "Invalid or dissallowed params found: " + invalidParams.join(", ");
|
|
231
|
+
try {
|
|
232
|
+
let { id_fields, synced_field, allow_delete } = table_rules.sync;
|
|
233
|
+
const syncFields = [...id_fields, synced_field];
|
|
234
|
+
if (!id_fields || !synced_field) {
|
|
235
|
+
const err = "INTERNAL ERROR: id_fields OR synced_field missing from publish";
|
|
236
|
+
console.error(err);
|
|
237
|
+
throw err;
|
|
238
|
+
}
|
|
239
|
+
id_fields = this.parseFieldFilter(id_fields, false);
|
|
240
|
+
let allowedSelect = this.parseFieldFilter(table_rules?.select.fields ?? false);
|
|
241
|
+
if (syncFields.find(f => !allowedSelect.includes(f))) {
|
|
242
|
+
throw `INTERNAL ERROR: sync field missing from publish.${this.name}.select.fields`;
|
|
243
|
+
}
|
|
244
|
+
let select = this.getAllowedSelectFields((params || {})?.select || "*", allowedSelect, false);
|
|
245
|
+
if (!select.length)
|
|
246
|
+
throw "Empty select not allowed";
|
|
247
|
+
/* Add sync fields if missing */
|
|
248
|
+
syncFields.map(sf => {
|
|
249
|
+
if (!select.includes(sf))
|
|
250
|
+
select.push(sf);
|
|
251
|
+
});
|
|
252
|
+
/* Step 1: parse command and params */
|
|
253
|
+
return this.find(filter, { select, limit: 0 }, undefined, table_rules, localParams)
|
|
254
|
+
.then(async (isValid) => {
|
|
255
|
+
const { filterFields, forcedFilter } = table_rules?.select || {};
|
|
256
|
+
const condition = (await this.prepareWhere({ filter, forcedFilter, filterFields, addKeywords: false, localParams, tableRule: table_rules })).where;
|
|
257
|
+
// let final_filter = getFindFilter(filter, table_rules);
|
|
258
|
+
const pubSubManager = await this.dboBuilder.getPubSubManager();
|
|
259
|
+
return pubSubManager.addSync({
|
|
260
|
+
table_info: this.tableOrViewInfo,
|
|
261
|
+
condition,
|
|
262
|
+
id_fields, synced_field,
|
|
263
|
+
allow_delete,
|
|
264
|
+
socket,
|
|
265
|
+
table_rules,
|
|
266
|
+
filter: { ...filter },
|
|
267
|
+
params: { select }
|
|
268
|
+
}).then(channelName => ({ channelName, id_fields, synced_field }));
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
catch (e) {
|
|
272
|
+
if (localParams && localParams.testRule)
|
|
273
|
+
throw e;
|
|
274
|
+
throw (0, DboBuilder_1.parseError)(e, `dbo.${this.name}.sync()`);
|
|
275
|
+
}
|
|
276
|
+
/*
|
|
277
|
+
REPLICATION
|
|
278
|
+
|
|
279
|
+
1 Sync proccess (NO DELETES ALLOWED):
|
|
280
|
+
|
|
281
|
+
Client sends:
|
|
282
|
+
"sync-request"
|
|
283
|
+
{ min_id, max_id, count, max_synced }
|
|
284
|
+
|
|
285
|
+
Server sends:
|
|
286
|
+
"sync-pull"
|
|
287
|
+
{ from_synced }
|
|
288
|
+
|
|
289
|
+
Client sends:
|
|
290
|
+
"sync-push"
|
|
291
|
+
{ data } -> WHERE synced >= from_synced
|
|
292
|
+
|
|
293
|
+
Server upserts:
|
|
294
|
+
WHERE not exists synced = synced AND id = id
|
|
295
|
+
UNTIL
|
|
296
|
+
|
|
297
|
+
Server sends
|
|
298
|
+
"sync-push"
|
|
299
|
+
{ data } -> WHERE synced >= from_synced
|
|
300
|
+
*/
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
exports.TableHandler = TableHandler;
|