prostgles-server 2.0.151 → 2.0.152
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/DboBuilder.d.ts.map +1 -1
- package/dist/DboBuilder.js +2 -2
- package/dist/DboBuilder.js.map +1 -1
- package/dist/Prostgles.d.ts +2 -2
- package/dist/Prostgles.d.ts.map +1 -1
- package/dist/Prostgles.js +14 -12
- package/dist/Prostgles.js.map +1 -1
- package/dist/QueryBuilder.d.ts.map +1 -1
- package/dist/QueryBuilder.js +1 -1
- package/dist/QueryBuilder.js.map +1 -1
- package/dist/utils.d.ts +0 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -7
- package/dist/utils.js.map +1 -1
- package/lib/DboBuilder.ts +2 -1
- package/lib/Prostgles.ts +18 -19
- package/lib/QueryBuilder.ts +2 -2
- package/lib/utils.ts +0 -6
- package/package.json +2 -2
- package/tests/client/PID.txt +1 -1
- package/tests/client/index.js +2 -1
- package/tests/client/index.ts +1 -1
- package/tests/client/package-lock.json +15 -15
- package/tests/client/package.json +1 -1
- package/tests/client_only_queries.js +8 -10
- package/tests/client_only_queries.ts +8 -11
- package/tests/server/package-lock.json +3 -3
package/lib/DboBuilder.ts
CHANGED
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
SQLResult,
|
|
26
26
|
Select,
|
|
27
27
|
JoinMaker,
|
|
28
|
+
isObject, isDefined
|
|
28
29
|
} from "prostgles-types";
|
|
29
30
|
|
|
30
31
|
export type Media = {
|
|
@@ -73,7 +74,7 @@ export type DbHandler = {
|
|
|
73
74
|
// [key: string]: TX
|
|
74
75
|
// }>
|
|
75
76
|
|
|
76
|
-
import { get
|
|
77
|
+
import { get } from "./utils";
|
|
77
78
|
import { getNewQuery, makeQuery, COMPUTED_FIELDS, SelectItem, FieldSpec, asNameAlias, SelectItemBuilder, FUNCTIONS, parseFunction, parseFunctionObject } from "./QueryBuilder";
|
|
78
79
|
import {
|
|
79
80
|
DB, TableRule, SelectRule, InsertRule, UpdateRule, DeleteRule, SyncRule, Joins, Join, Prostgles, PublishParser, ValidateRow
|
package/lib/Prostgles.ts
CHANGED
|
@@ -21,7 +21,7 @@ import { PubSubManager, DEFAULT_SYNC_BATCH_SIZE, asValue } from "./PubSubManager
|
|
|
21
21
|
export { DbHandler }
|
|
22
22
|
export type PGP = pgPromise.IMain<{}, pg.IClient>;
|
|
23
23
|
|
|
24
|
-
import { SQLRequest,
|
|
24
|
+
import { SQLRequest, TableSchemaForClient, MethodKey, CHANNELS, AnyObject, RULE_METHODS, ClientSchema } from "prostgles-types";
|
|
25
25
|
|
|
26
26
|
import { DBEventsManager } from "./DBEventsManager";
|
|
27
27
|
|
|
@@ -920,13 +920,14 @@ export class Prostgles<DBO = DbHandler> {
|
|
|
920
920
|
// let DATA_TYPES = !needType? [] : await this.db.any("SELECT oid, typname FROM pg_type");
|
|
921
921
|
// let USER_TABLES = !needType? [] : await this.db.any("SELECT relid, relname FROM pg_catalog.pg_statio_user_tables");
|
|
922
922
|
|
|
923
|
-
let schema:
|
|
923
|
+
let schema: TableSchemaForClient = {};
|
|
924
924
|
let publishValidationError;
|
|
925
925
|
let rawSQL = false;
|
|
926
926
|
|
|
927
927
|
const { dbo, db, pgp, publishParser } = this;
|
|
928
928
|
try {
|
|
929
|
-
|
|
929
|
+
if(!publishParser) throw "publishParser undefined";
|
|
930
|
+
schema = await publishParser.getSchemaFromPublish(socket);
|
|
930
931
|
} catch(e){
|
|
931
932
|
publishValidationError = "Server Error: PUBLISH VALIDATION ERROR";
|
|
932
933
|
console.error(`\nProstgles PUBLISH VALIDATION ERROR (after socket connected):\n ->`, e);
|
|
@@ -980,8 +981,7 @@ export class Prostgles<DBO = DbHandler> {
|
|
|
980
981
|
}
|
|
981
982
|
|
|
982
983
|
const methods = await publishParser?.getMethods(socket);
|
|
983
|
-
|
|
984
|
-
socket.emit(CHANNELS.SCHEMA, {
|
|
984
|
+
const clientSchema: ClientSchema = {
|
|
985
985
|
schema,
|
|
986
986
|
methods: getKeys(methods),
|
|
987
987
|
...(fullSchema? { fullSchema } : {}),
|
|
@@ -990,7 +990,8 @@ export class Prostgles<DBO = DbHandler> {
|
|
|
990
990
|
auth,
|
|
991
991
|
version,
|
|
992
992
|
err: publishValidationError
|
|
993
|
-
}
|
|
993
|
+
}
|
|
994
|
+
socket.emit(CHANNELS.SCHEMA, clientSchema);
|
|
994
995
|
}
|
|
995
996
|
}
|
|
996
997
|
function makeSocketError(cb: Function, err: any){
|
|
@@ -1030,13 +1031,11 @@ type DboTableCommand = Request & DboTable & {
|
|
|
1030
1031
|
localParams: LocalParams;
|
|
1031
1032
|
}
|
|
1032
1033
|
|
|
1033
|
-
// const insertParams: Array<keyof InsertRule> = ["fields", "forcedData", "returningFields", "validate"];
|
|
1034
|
-
|
|
1035
1034
|
const RULE_TO_METHODS = [
|
|
1036
1035
|
{
|
|
1037
1036
|
rule: "getColumns",
|
|
1038
1037
|
sqlRule: "select",
|
|
1039
|
-
methods:
|
|
1038
|
+
methods: RULE_METHODS.getColumns,
|
|
1040
1039
|
no_limits: true,
|
|
1041
1040
|
allowed_params: [],
|
|
1042
1041
|
table_only: false,
|
|
@@ -1045,7 +1044,7 @@ const RULE_TO_METHODS = [
|
|
|
1045
1044
|
{
|
|
1046
1045
|
rule: "getInfo",
|
|
1047
1046
|
sqlRule: "select",
|
|
1048
|
-
methods:
|
|
1047
|
+
methods: RULE_METHODS.getInfo,
|
|
1049
1048
|
no_limits: true,
|
|
1050
1049
|
allowed_params: [],
|
|
1051
1050
|
table_only: false,
|
|
@@ -1054,7 +1053,7 @@ const RULE_TO_METHODS = [
|
|
|
1054
1053
|
{
|
|
1055
1054
|
rule: "insert",
|
|
1056
1055
|
sqlRule: "insert",
|
|
1057
|
-
methods:
|
|
1056
|
+
methods: RULE_METHODS.insert,
|
|
1058
1057
|
no_limits: <SelectRule>{ fields: "*" },
|
|
1059
1058
|
table_only: true,
|
|
1060
1059
|
allowed_params: <Array<keyof InsertRule>>["fields", "forcedData", "returningFields", "validate", "preValidate"] ,
|
|
@@ -1063,7 +1062,7 @@ const RULE_TO_METHODS = [
|
|
|
1063
1062
|
{
|
|
1064
1063
|
rule: "update",
|
|
1065
1064
|
sqlRule: "update",
|
|
1066
|
-
methods:
|
|
1065
|
+
methods: RULE_METHODS.update,
|
|
1067
1066
|
no_limits: <UpdateRule>{ fields: "*", filterFields: "*", returningFields: "*" },
|
|
1068
1067
|
table_only: true,
|
|
1069
1068
|
allowed_params: <Array<keyof UpdateRule>>["fields", "filterFields", "forcedFilter", "forcedData", "returningFields", "validate"] ,
|
|
@@ -1072,7 +1071,7 @@ const RULE_TO_METHODS = [
|
|
|
1072
1071
|
{
|
|
1073
1072
|
rule: "select",
|
|
1074
1073
|
sqlRule: "select",
|
|
1075
|
-
methods:
|
|
1074
|
+
methods: RULE_METHODS.select,
|
|
1076
1075
|
no_limits: <SelectRule>{ fields: "*", filterFields: "*" },
|
|
1077
1076
|
table_only: false,
|
|
1078
1077
|
allowed_params: <Array<keyof SelectRule>>["fields", "filterFields", "forcedFilter", "validate", "maxLimit"] ,
|
|
@@ -1081,7 +1080,7 @@ const RULE_TO_METHODS = [
|
|
|
1081
1080
|
{
|
|
1082
1081
|
rule: "delete",
|
|
1083
1082
|
sqlRule: "delete",
|
|
1084
|
-
methods:
|
|
1083
|
+
methods: RULE_METHODS.delete,
|
|
1085
1084
|
no_limits: <DeleteRule>{ filterFields: "*" } ,
|
|
1086
1085
|
table_only: true,
|
|
1087
1086
|
allowed_params: <Array<keyof DeleteRule>>["filterFields", "forcedFilter", "returningFields", "validate"] ,
|
|
@@ -1090,7 +1089,7 @@ const RULE_TO_METHODS = [
|
|
|
1090
1089
|
{
|
|
1091
1090
|
rule: "sync",
|
|
1092
1091
|
sqlRule: "select",
|
|
1093
|
-
methods:
|
|
1092
|
+
methods: RULE_METHODS.sync,
|
|
1094
1093
|
no_limits: null,
|
|
1095
1094
|
table_only: true,
|
|
1096
1095
|
allowed_params: <Array<keyof SyncRule>>["id_fields", "synced_field", "sync_type", "allow_delete", "throttle", "batch_size"],
|
|
@@ -1099,7 +1098,7 @@ const RULE_TO_METHODS = [
|
|
|
1099
1098
|
{
|
|
1100
1099
|
rule: "subscribe",
|
|
1101
1100
|
sqlRule: "select",
|
|
1102
|
-
methods:
|
|
1101
|
+
methods: RULE_METHODS.subscribe,
|
|
1103
1102
|
no_limits: <SubscribeRule>{ throttle: 0 },
|
|
1104
1103
|
table_only: true,
|
|
1105
1104
|
allowed_params: <Array<keyof SubscribeRule>>["throttle"],
|
|
@@ -1379,8 +1378,8 @@ export class PublishParser {
|
|
|
1379
1378
|
|
|
1380
1379
|
|
|
1381
1380
|
/* Prepares schema for client. Only allowed views and commands will be present */
|
|
1382
|
-
async getSchemaFromPublish(socket: any): Promise<
|
|
1383
|
-
let schema:
|
|
1381
|
+
async getSchemaFromPublish(socket: any): Promise<TableSchemaForClient> {
|
|
1382
|
+
let schema: TableSchemaForClient = {};
|
|
1384
1383
|
|
|
1385
1384
|
try {
|
|
1386
1385
|
/* Publish tables and views based on socket */
|
|
@@ -1409,7 +1408,7 @@ export class PublishParser {
|
|
|
1409
1408
|
// if(tableName === "insert_rule") throw {table_rules}
|
|
1410
1409
|
if(table_rules && Object.keys(table_rules).length){
|
|
1411
1410
|
schema[tableName] = {};
|
|
1412
|
-
let methods: Array<
|
|
1411
|
+
let methods: Array<MethodKey> = [];
|
|
1413
1412
|
|
|
1414
1413
|
if(typeof table_rules === "object"){
|
|
1415
1414
|
methods = getKeys(table_rules) as any;
|
package/lib/QueryBuilder.ts
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
import { pgp, Filter, LocalParams, isPlainObject, TableHandler, ViewHandler, postgresToTsType } from "./DboBuilder";
|
|
8
8
|
import { TableRule } from "./Prostgles";
|
|
9
|
-
import { SelectParamsBasic as SelectParams, isEmpty, FieldFilter, asName, TextFilter_FullTextSearchFilterKeys, TS_PG_Types, ColumnInfo, PG_COLUMN_UDT_DATA_TYPE } from "prostgles-types";
|
|
10
|
-
import { get
|
|
9
|
+
import { SelectParamsBasic as SelectParams, isEmpty, FieldFilter, asName, TextFilter_FullTextSearchFilterKeys, TS_PG_Types, ColumnInfo, PG_COLUMN_UDT_DATA_TYPE, isObject } from "prostgles-types";
|
|
10
|
+
import { get } from "./utils";
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
export type SelectItem = {
|
package/lib/utils.ts
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
1
|
export { get } from "prostgles-types";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export function isObject(obj: any): obj is Record<string, any> {
|
|
5
|
-
return Boolean(obj && typeof obj === "object" && !Array.isArray(obj) );
|
|
6
|
-
}
|
|
7
|
-
export const isDefined = <T>(v: T | undefined | void): v is T => v !== undefined && v !== null
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prostgles-server",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.152",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"bluebird": "^3.7.2",
|
|
30
30
|
"file-type": "^16.5.3",
|
|
31
31
|
"pg-promise": "^10.11.1",
|
|
32
|
-
"prostgles-types": "^1.5.
|
|
32
|
+
"prostgles-types": "^1.5.128",
|
|
33
33
|
"sharp": "^0.30.5"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
package/tests/client/PID.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
6948
|
package/tests/client/index.js
CHANGED
|
@@ -14,7 +14,8 @@ const log = (msg, extra) => {
|
|
|
14
14
|
log("Started client...");
|
|
15
15
|
const url = process.env.PRGL_CLIENT_URL || "http://127.0.0.1:3001", path = process.env.PRGL_CLIENT_PATH || "/teztz/s", socket = (0, socket_io_client_1.default)(url, { path, query: { token: "haha" } }), //
|
|
16
16
|
stopTest = (err) => {
|
|
17
|
-
|
|
17
|
+
if (err)
|
|
18
|
+
log("Stopping client due to error: " + JSON.stringify(err));
|
|
18
19
|
setTimeout(() => {
|
|
19
20
|
socket.emit("stop-test", !err ? err : { err: err.toString(), error: err }, cb => {
|
|
20
21
|
log("Stopping client...");
|
package/tests/client/index.ts
CHANGED
|
@@ -15,7 +15,7 @@ const url = process.env.PRGL_CLIENT_URL || "http://127.0.0.1:3001",
|
|
|
15
15
|
path = process.env.PRGL_CLIENT_PATH || "/teztz/s",
|
|
16
16
|
socket = io(url, { path, query: { token: "haha" } }), //
|
|
17
17
|
stopTest = (err?) => {
|
|
18
|
-
log("Stopping client due to error: " + JSON.stringify(err));
|
|
18
|
+
if(err) log("Stopping client due to error: " + JSON.stringify(err));
|
|
19
19
|
|
|
20
20
|
setTimeout(() => {
|
|
21
21
|
socket.emit("stop-test", !err? err : { err: err.toString(), error: err }, cb => {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@types/node": "^14.14.16",
|
|
13
13
|
"@types/socket.io-client": "^1.4.35",
|
|
14
|
-
"prostgles-client": "^1.5.
|
|
14
|
+
"prostgles-client": "^1.5.140",
|
|
15
15
|
"prostgles-types": "^1.5.68",
|
|
16
16
|
"socket.io-client": "^4.5.1"
|
|
17
17
|
}
|
|
@@ -73,17 +73,17 @@
|
|
|
73
73
|
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
|
74
74
|
},
|
|
75
75
|
"node_modules/prostgles-client": {
|
|
76
|
-
"version": "1.5.
|
|
77
|
-
"resolved": "https://registry.npmjs.org/prostgles-client/-/prostgles-client-1.5.
|
|
78
|
-
"integrity": "sha512
|
|
76
|
+
"version": "1.5.140",
|
|
77
|
+
"resolved": "https://registry.npmjs.org/prostgles-client/-/prostgles-client-1.5.140.tgz",
|
|
78
|
+
"integrity": "sha512-jF3/wfkhEHxObiuPz+MLc/MH4Za2TXkescwhN8SeusNTn2mm/cUSimGdsSNr4gOcYOOxwf69rn9Nq9B+RLkyag==",
|
|
79
79
|
"dependencies": {
|
|
80
|
-
"prostgles-types": "^1.5.
|
|
80
|
+
"prostgles-types": "^1.5.127"
|
|
81
81
|
}
|
|
82
82
|
},
|
|
83
83
|
"node_modules/prostgles-types": {
|
|
84
|
-
"version": "1.5.
|
|
85
|
-
"resolved": "https://registry.npmjs.org/prostgles-types/-/prostgles-types-1.5.
|
|
86
|
-
"integrity": "sha512-
|
|
84
|
+
"version": "1.5.127",
|
|
85
|
+
"resolved": "https://registry.npmjs.org/prostgles-types/-/prostgles-types-1.5.127.tgz",
|
|
86
|
+
"integrity": "sha512-Yg1hLBskSJl96hHZPTlzqFFU0XGhgB48qXnb/NZO11srQqxz67Wmxtt5/sZuZ3iNTV6PUGcvx9dSFKOx1MZAdg=="
|
|
87
87
|
},
|
|
88
88
|
"node_modules/socket.io-client": {
|
|
89
89
|
"version": "4.5.1",
|
|
@@ -187,17 +187,17 @@
|
|
|
187
187
|
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
|
188
188
|
},
|
|
189
189
|
"prostgles-client": {
|
|
190
|
-
"version": "1.5.
|
|
191
|
-
"resolved": "https://registry.npmjs.org/prostgles-client/-/prostgles-client-1.5.
|
|
192
|
-
"integrity": "sha512
|
|
190
|
+
"version": "1.5.140",
|
|
191
|
+
"resolved": "https://registry.npmjs.org/prostgles-client/-/prostgles-client-1.5.140.tgz",
|
|
192
|
+
"integrity": "sha512-jF3/wfkhEHxObiuPz+MLc/MH4Za2TXkescwhN8SeusNTn2mm/cUSimGdsSNr4gOcYOOxwf69rn9Nq9B+RLkyag==",
|
|
193
193
|
"requires": {
|
|
194
|
-
"prostgles-types": "^1.5.
|
|
194
|
+
"prostgles-types": "^1.5.127"
|
|
195
195
|
}
|
|
196
196
|
},
|
|
197
197
|
"prostgles-types": {
|
|
198
|
-
"version": "1.5.
|
|
199
|
-
"resolved": "https://registry.npmjs.org/prostgles-types/-/prostgles-types-1.5.
|
|
200
|
-
"integrity": "sha512-
|
|
198
|
+
"version": "1.5.127",
|
|
199
|
+
"resolved": "https://registry.npmjs.org/prostgles-types/-/prostgles-types-1.5.127.tgz",
|
|
200
|
+
"integrity": "sha512-Yg1hLBskSJl96hHZPTlzqFFU0XGhgB48qXnb/NZO11srQqxz67Wmxtt5/sZuZ3iNTV6PUGcvx9dSFKOx1MZAdg=="
|
|
201
201
|
},
|
|
202
202
|
"socket.io-client": {
|
|
203
203
|
"version": "4.5.1",
|
|
@@ -10,7 +10,6 @@ async function client_only(db, auth, log, methods) {
|
|
|
10
10
|
/* METHODS */
|
|
11
11
|
const t222 = await methods.get();
|
|
12
12
|
assert_1.strict.equal(t222, 222, "methods.get() failed");
|
|
13
|
-
log("SQL Full result");
|
|
14
13
|
/* RAWSQL */
|
|
15
14
|
await (0, isomorphic_queries_1.tryRunP)("SQL Full result", async (resolve, reject) => {
|
|
16
15
|
const sqlStatement = await db.sql("SELECT $1", [1], { returnType: "statement" });
|
|
@@ -37,7 +36,6 @@ async function client_only(db, auth, log, methods) {
|
|
|
37
36
|
}], "db.sql query failed");
|
|
38
37
|
resolve(true);
|
|
39
38
|
}, log);
|
|
40
|
-
log("sql LISTEN NOTIFY events");
|
|
41
39
|
await (0, isomorphic_queries_1.tryRunP)("sql LISTEN NOTIFY events", async (resolve, reject) => {
|
|
42
40
|
const sub = await db.sql("LISTEN chnl ");
|
|
43
41
|
// console.log({ sub })
|
|
@@ -50,7 +48,6 @@ async function client_only(db, auth, log, methods) {
|
|
|
50
48
|
});
|
|
51
49
|
db.sql("NOTIFY chnl , 'hello'; ");
|
|
52
50
|
}, log);
|
|
53
|
-
log("sql NOTICE events");
|
|
54
51
|
await (0, isomorphic_queries_1.tryRunP)("sql NOTICE events", async (resolve, reject) => {
|
|
55
52
|
const sub = await db.sql("", {}, { returnType: "noticeSubscription" });
|
|
56
53
|
// console.log({ sub })
|
|
@@ -88,32 +85,32 @@ async function client_only(db, auth, log, methods) {
|
|
|
88
85
|
* subscribe({ x: 10 }
|
|
89
86
|
* sync({}
|
|
90
87
|
*
|
|
91
|
-
* sync starts updating x to 10
|
|
88
|
+
* Then sync starts updating x to 10 for each record
|
|
92
89
|
* subscribe waits for 100 records of x=10 and then updates everything to x=20
|
|
93
90
|
* sync waits for 100 records of x=20 and finishes the test
|
|
94
91
|
*/
|
|
95
92
|
/* After all sync records are updated to x10 here we'll update them to x20 */
|
|
96
93
|
const sP = await db.planes.subscribe({ x: 10 }, {}, async (planes) => {
|
|
97
94
|
const p10 = planes.filter(p => p.x == 10);
|
|
98
|
-
log("sub: x10 -> "
|
|
95
|
+
log(Date.now() + ": sub stats: x10 -> " + p10.length + " x20 ->" + planes.filter(p => p.x == 20).length);
|
|
99
96
|
if (p10.length === 100) {
|
|
100
97
|
// db.planes.findOne({}, { select: { last_updated: "$max"}}).then(log);
|
|
101
98
|
sP.unsubscribe();
|
|
102
|
-
log("
|
|
99
|
+
log(Date.now() + ": sub: db.planes.update({}, { x: 20, last_updated });");
|
|
103
100
|
const dLastUpdated = Math.max(...p10.map(v => +v.last_updated));
|
|
104
101
|
const last_updated = Date.now();
|
|
105
102
|
if (dLastUpdated >= last_updated)
|
|
106
103
|
throw "dLastUpdated >= last_updated should not happen";
|
|
107
104
|
await db.planes.update({}, { x: 20, last_updated });
|
|
108
|
-
log("Updated to x20", await db.planes.count({ x: 20 }));
|
|
105
|
+
log(Date.now() + ": sub: Updated to x20", await db.planes.count({ x: 20 }));
|
|
109
106
|
// db.planes.findOne({}, { select: { last_updated: "$max"}}).then(log)
|
|
110
107
|
}
|
|
111
108
|
});
|
|
112
109
|
let updt = 0;
|
|
113
|
-
const sync = await db.planes.sync({}, { handlesOnData: true, patchText: true }, (planes, deltas) => {
|
|
110
|
+
const sync = await db.planes.sync({}, { handlesOnData: true, patchText: true, }, (planes, deltas) => {
|
|
114
111
|
const x20 = planes.filter(p => p.x == 20).length;
|
|
115
112
|
const x10 = planes.filter(p => p.x == 10);
|
|
116
|
-
log(
|
|
113
|
+
log(Date.now() + `: sync stats: x10 -> ${x10.length} x20 -> ${x20}`);
|
|
117
114
|
let update = false;
|
|
118
115
|
planes.map(p => {
|
|
119
116
|
// if(p.y === 1) window.up = p;
|
|
@@ -123,13 +120,14 @@ async function client_only(db, auth, log, methods) {
|
|
|
123
120
|
updt++;
|
|
124
121
|
update = true;
|
|
125
122
|
p.$update({ x: 10 });
|
|
123
|
+
log(Date.now() + `: sync: p.$update({ x: 10 }); (id: ${p.id})`);
|
|
126
124
|
}
|
|
127
125
|
});
|
|
128
126
|
// if(update) log("$update({ x: 10 })", updt)
|
|
129
127
|
if (x20 === 100) {
|
|
130
128
|
// log(22)
|
|
131
129
|
// console.timeEnd("test")
|
|
132
|
-
log("Finished replication test. Inserting 100 rows then updating two times took: " + (Date.now() - start) + "ms");
|
|
130
|
+
log(Date.now() + ": sync end: Finished replication test. Inserting 100 rows then updating two times took: " + (Date.now() - start) + "ms");
|
|
133
131
|
resolve(true);
|
|
134
132
|
}
|
|
135
133
|
});
|
|
@@ -15,7 +15,6 @@ export default async function client_only(db: DBHandlerClient, auth: Auth, log:
|
|
|
15
15
|
const t222 = await methods.get();
|
|
16
16
|
assert.equal(t222, 222, "methods.get() failed");
|
|
17
17
|
|
|
18
|
-
log("SQL Full result")
|
|
19
18
|
/* RAWSQL */
|
|
20
19
|
await tryRunP("SQL Full result", async (resolve, reject) => {
|
|
21
20
|
const sqlStatement = await db.sql("SELECT $1", [1], { returnType: "statement" });
|
|
@@ -46,8 +45,6 @@ export default async function client_only(db: DBHandlerClient, auth: Auth, log:
|
|
|
46
45
|
resolve(true);
|
|
47
46
|
}, log);
|
|
48
47
|
|
|
49
|
-
log("sql LISTEN NOTIFY events")
|
|
50
|
-
|
|
51
48
|
await tryRunP("sql LISTEN NOTIFY events", async (resolve, reject) => {
|
|
52
49
|
|
|
53
50
|
const sub = await db.sql("LISTEN chnl ");
|
|
@@ -60,7 +57,6 @@ export default async function client_only(db: DBHandlerClient, auth: Auth, log:
|
|
|
60
57
|
db.sql("NOTIFY chnl , 'hello'; ");
|
|
61
58
|
}, log);
|
|
62
59
|
|
|
63
|
-
log("sql NOTICE events")
|
|
64
60
|
await tryRunP("sql NOTICE events", async (resolve, reject) => {
|
|
65
61
|
|
|
66
62
|
const sub = await db.sql("", {}, { returnType: "noticeSubscription" });
|
|
@@ -101,7 +97,7 @@ export default async function client_only(db: DBHandlerClient, auth: Auth, log:
|
|
|
101
97
|
* subscribe({ x: 10 }
|
|
102
98
|
* sync({}
|
|
103
99
|
*
|
|
104
|
-
* sync starts updating x to 10
|
|
100
|
+
* Then sync starts updating x to 10 for each record
|
|
105
101
|
* subscribe waits for 100 records of x=10 and then updates everything to x=20
|
|
106
102
|
* sync waits for 100 records of x=20 and finishes the test
|
|
107
103
|
*/
|
|
@@ -110,28 +106,28 @@ export default async function client_only(db: DBHandlerClient, auth: Auth, log:
|
|
|
110
106
|
const sP = await db.planes.subscribe({ x: 10 }, { }, async planes => {
|
|
111
107
|
|
|
112
108
|
const p10 = planes.filter(p => p.x == 10);
|
|
113
|
-
log("sub: x10 -> "
|
|
109
|
+
log(Date.now() + ": sub stats: x10 -> " + p10.length + " x20 ->" + planes.filter(p => p.x == 20).length);
|
|
114
110
|
|
|
115
111
|
if(p10.length === 100){
|
|
116
112
|
// db.planes.findOne({}, { select: { last_updated: "$max"}}).then(log);
|
|
117
113
|
|
|
118
114
|
sP.unsubscribe();
|
|
119
|
-
log("
|
|
115
|
+
log(Date.now() + ": sub: db.planes.update({}, { x: 20, last_updated });");
|
|
120
116
|
const dLastUpdated = Math.max(...p10.map(v => +v.last_updated))
|
|
121
117
|
const last_updated = Date.now();
|
|
122
118
|
if(dLastUpdated >= last_updated) throw "dLastUpdated >= last_updated should not happen"
|
|
123
119
|
await db.planes.update({}, { x: 20, last_updated });
|
|
124
|
-
log("Updated to x20" , await db.planes.count({ x: 20 }))
|
|
120
|
+
log(Date.now() + ": sub: Updated to x20" , await db.planes.count({ x: 20 }))
|
|
125
121
|
|
|
126
122
|
// db.planes.findOne({}, { select: { last_updated: "$max"}}).then(log)
|
|
127
123
|
}
|
|
128
124
|
});
|
|
129
125
|
|
|
130
126
|
let updt = 0;
|
|
131
|
-
const sync = await db.planes.sync({}, { handlesOnData: true, patchText: true }, (planes, deltas) => {
|
|
127
|
+
const sync = await db.planes.sync({}, { handlesOnData: true, patchText: true, }, (planes, deltas) => {
|
|
132
128
|
const x20 = planes.filter(p => p.x == 20).length;
|
|
133
129
|
const x10 = planes.filter(p => p.x == 10);
|
|
134
|
-
log(
|
|
130
|
+
log(Date.now() + `: sync stats: x10 -> ${x10.length} x20 -> ${x20}`);
|
|
135
131
|
|
|
136
132
|
let update = false;
|
|
137
133
|
planes.map(p => {
|
|
@@ -141,6 +137,7 @@ export default async function client_only(db: DBHandlerClient, auth: Auth, log:
|
|
|
141
137
|
updt++;
|
|
142
138
|
update = true;
|
|
143
139
|
p.$update({ x: 10 });
|
|
140
|
+
log(Date.now() + `: sync: p.$update({ x: 10 }); (id: ${p.id})`);
|
|
144
141
|
}
|
|
145
142
|
});
|
|
146
143
|
// if(update) log("$update({ x: 10 })", updt)
|
|
@@ -148,7 +145,7 @@ export default async function client_only(db: DBHandlerClient, auth: Auth, log:
|
|
|
148
145
|
if(x20 === 100){
|
|
149
146
|
// log(22)
|
|
150
147
|
// console.timeEnd("test")
|
|
151
|
-
log("Finished replication test. Inserting 100 rows then updating two times took: " + (Date.now() - start) + "ms")
|
|
148
|
+
log(Date.now() + ": sync end: Finished replication test. Inserting 100 rows then updating two times took: " + (Date.now() - start) + "ms")
|
|
152
149
|
resolve(true)
|
|
153
150
|
}
|
|
154
151
|
});
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"../..": {
|
|
25
25
|
"name": "prostgles-server",
|
|
26
|
-
"version": "2.0.
|
|
26
|
+
"version": "2.0.151",
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@aws-sdk/client-s3": "^3.95.0",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"bluebird": "^3.7.2",
|
|
32
32
|
"file-type": "^16.5.3",
|
|
33
33
|
"pg-promise": "^10.11.1",
|
|
34
|
-
"prostgles-types": "^1.5.
|
|
34
|
+
"prostgles-types": "^1.5.128",
|
|
35
35
|
"sharp": "^0.30.5"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
@@ -1436,7 +1436,7 @@
|
|
|
1436
1436
|
"bluebird": "^3.7.2",
|
|
1437
1437
|
"file-type": "^16.5.3",
|
|
1438
1438
|
"pg-promise": "^10.11.1",
|
|
1439
|
-
"prostgles-types": "^1.5.
|
|
1439
|
+
"prostgles-types": "^1.5.128",
|
|
1440
1440
|
"sharp": "^0.30.5",
|
|
1441
1441
|
"typescript": "^4.7.2"
|
|
1442
1442
|
}
|