prostgles-server 4.2.60 → 4.2.62
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 +5 -1
- package/dist/AuthHandler.d.ts.map +1 -1
- package/dist/AuthHandler.js +33 -3
- package/dist/AuthHandler.js.map +1 -1
- package/dist/DboBuilder/DboBuilderTypes.d.ts +2 -0
- package/dist/DboBuilder/DboBuilderTypes.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/ViewHandler.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/ViewHandler.js +8 -1
- package/dist/DboBuilder/ViewHandler/ViewHandler.js.map +1 -1
- package/dist/Logging.d.ts +31 -18
- package/dist/Logging.d.ts.map +1 -1
- package/dist/Prostgles.d.ts +4 -4
- package/dist/Prostgles.d.ts.map +1 -1
- package/dist/Prostgles.js +75 -58
- package/dist/Prostgles.js.map +1 -1
- package/dist/PubSubManager/PubSubManager.d.ts +3 -0
- package/dist/PubSubManager/PubSubManager.d.ts.map +1 -1
- package/dist/PubSubManager/PubSubManager.js +2 -0
- package/dist/PubSubManager/PubSubManager.js.map +1 -1
- package/dist/PubSubManager/addSync.d.ts +1 -2
- package/dist/PubSubManager/addSync.d.ts.map +1 -1
- package/dist/PubSubManager/addSync.js +6 -13
- package/dist/PubSubManager/addSync.js.map +1 -1
- package/dist/SyncReplication.d.ts.map +1 -1
- package/dist/SyncReplication.js +30 -19
- package/dist/SyncReplication.js.map +1 -1
- package/dist/initProstgles.js +1 -1
- package/dist/initProstgles.js.map +1 -1
- package/lib/AuthHandler.ts +32 -6
- package/lib/DboBuilder/DboBuilderTypes.ts +2 -1
- package/lib/DboBuilder/ViewHandler/ViewHandler.ts +8 -1
- package/lib/Logging.ts +34 -17
- package/lib/Prostgles.ts +83 -64
- package/lib/PubSubManager/PubSubManager.ts +3 -0
- package/lib/PubSubManager/addSync.ts +7 -17
- package/lib/SyncReplication.ts +38 -24
- package/lib/initProstgles.ts +1 -1
- package/package.json +2 -2
- package/tests/server/package-lock.json +3 -3
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { find, tryCatch } from "prostgles-types/dist/util";
|
|
2
|
-
import { BasicCallback,
|
|
3
|
-
import { AddSyncParams, DEFAULT_SYNC_BATCH_SIZE } from "./PubSubManager";
|
|
2
|
+
import { AddSyncParams, BasicCallback, DEFAULT_SYNC_BATCH_SIZE, PubSubManager, parseCondition } from "./PubSubManager";
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Returns a sync channel
|
|
@@ -8,6 +7,7 @@ import { AddSyncParams, DEFAULT_SYNC_BATCH_SIZE } from "./PubSubManager";
|
|
|
8
7
|
*/
|
|
9
8
|
export async function addSync(this: PubSubManager, syncParams: AddSyncParams) {
|
|
10
9
|
|
|
10
|
+
const sid = this.dboBuilder.prostgles.authHandler?.getSIDNoError({ socket: syncParams.socket });
|
|
11
11
|
const res = await tryCatch(async () => {
|
|
12
12
|
|
|
13
13
|
const {
|
|
@@ -18,7 +18,6 @@ export async function addSync(this: PubSubManager, syncParams: AddSyncParams) {
|
|
|
18
18
|
const conditionParsed = parseCondition(condition);
|
|
19
19
|
if (!socket || !table_info) throw "socket or table_info missing";
|
|
20
20
|
|
|
21
|
-
|
|
22
21
|
const { name: table_name } = table_info;
|
|
23
22
|
const channel_name = `${this.socketChannelPreffix}.${table_name}.${JSON.stringify(filter)}.sync`;
|
|
24
23
|
|
|
@@ -33,12 +32,12 @@ export async function addSync(this: PubSubManager, syncParams: AddSyncParams) {
|
|
|
33
32
|
filter,
|
|
34
33
|
condition: conditionParsed,
|
|
35
34
|
synced_field,
|
|
35
|
+
sid,
|
|
36
36
|
id_fields,
|
|
37
37
|
allow_delete,
|
|
38
38
|
table_rules,
|
|
39
39
|
throttle: Math.max(throttle || 0, table_rules?.sync?.throttle || 0),
|
|
40
40
|
batch_size: table_rules?.sync?.batch_size || DEFAULT_SYNC_BATCH_SIZE,
|
|
41
|
-
// last_throttled: 0,
|
|
42
41
|
socket_id: socket.id,
|
|
43
42
|
is_sync: true,
|
|
44
43
|
last_synced: 0,
|
|
@@ -65,7 +64,9 @@ export async function addSync(this: PubSubManager, syncParams: AddSyncParams) {
|
|
|
65
64
|
socketId: socket.id,
|
|
66
65
|
tableName: table_name,
|
|
67
66
|
condition,
|
|
68
|
-
|
|
67
|
+
sid,
|
|
68
|
+
connectedSocketIds: this.connectedSocketIds,
|
|
69
|
+
duration: -1,
|
|
69
70
|
});
|
|
70
71
|
socket.removeAllListeners(channel_name);
|
|
71
72
|
socket.removeAllListeners(unsyncChn);
|
|
@@ -100,23 +101,14 @@ export async function addSync(this: PubSubManager, syncParams: AddSyncParams) {
|
|
|
100
101
|
4. Upsert data.data | deleted on(data.data | data.deleted)
|
|
101
102
|
*/
|
|
102
103
|
|
|
103
|
-
// if(data.data){
|
|
104
|
-
// console.error("THIS SHOUKD NEVER FIRE !! NEW DATA FROM SYNC");
|
|
105
|
-
// this.upsertClientData(newSync, data.data);
|
|
106
|
-
// } else
|
|
107
104
|
if (data.onSyncRequest) {
|
|
108
|
-
// console.log("syncData from socket")
|
|
109
105
|
this.syncData(newSync, data.onSyncRequest, "client");
|
|
110
106
|
|
|
111
|
-
// console.log("onSyncRequest ", socket._user)
|
|
112
107
|
} else {
|
|
113
108
|
console.error("Unexpected sync request data from client: ", data)
|
|
114
109
|
}
|
|
115
110
|
});
|
|
116
111
|
|
|
117
|
-
// socket.emit(channel_name, { onSyncRequest: true }, (response) => {
|
|
118
|
-
// console.log(response)
|
|
119
|
-
// });
|
|
120
112
|
} else {
|
|
121
113
|
console.warn("UNCLOSED DUPLICATE SYNC FOUND", existing.channel_name);
|
|
122
114
|
}
|
|
@@ -124,9 +116,6 @@ export async function addSync(this: PubSubManager, syncParams: AddSyncParams) {
|
|
|
124
116
|
return newSync;
|
|
125
117
|
};
|
|
126
118
|
|
|
127
|
-
|
|
128
|
-
// const { min_id, max_id, count, max_synced } = params;
|
|
129
|
-
|
|
130
119
|
upsertSync();
|
|
131
120
|
|
|
132
121
|
await this.addTrigger({ table_name, condition: conditionParsed }, undefined, socket);
|
|
@@ -143,6 +132,7 @@ export async function addSync(this: PubSubManager, syncParams: AddSyncParams) {
|
|
|
143
132
|
connectedSocketIds: this.connectedSocketIds,
|
|
144
133
|
duration: res.duration,
|
|
145
134
|
error: res.error,
|
|
135
|
+
sid,
|
|
146
136
|
});
|
|
147
137
|
|
|
148
138
|
if(res.error !== undefined) throw res.error;
|
package/lib/SyncReplication.ts
CHANGED
|
@@ -50,11 +50,14 @@ export async function syncData (this: PubSubManager, sync: SyncParams, clientDat
|
|
|
50
50
|
type: "sync",
|
|
51
51
|
command: "syncData",
|
|
52
52
|
tableName: sync.table_name,
|
|
53
|
+
sid: sync.sid,
|
|
53
54
|
source,
|
|
54
55
|
...pickKeys(sync, ["socket_id", "condition", "last_synced", "is_syncing"]),
|
|
55
56
|
lr: JSON.stringify(sync.lr),
|
|
56
57
|
connectedSocketIds: this.dboBuilder.prostgles.connectedSockets.map(s => s.id),
|
|
57
|
-
localParams: undefined
|
|
58
|
+
localParams: undefined,
|
|
59
|
+
duration: -1,
|
|
60
|
+
socketId: sync.socket_id
|
|
58
61
|
});
|
|
59
62
|
|
|
60
63
|
const {
|
|
@@ -193,16 +196,8 @@ export async function syncData (this: PubSubManager, sync: SyncParams, clientDat
|
|
|
193
196
|
*/
|
|
194
197
|
upsertData = async (data: AnyObject[]) => {
|
|
195
198
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
command: "upsertData",
|
|
199
|
-
tableName: sync.table_name,
|
|
200
|
-
rows: data.length,
|
|
201
|
-
socketId: socket_id,
|
|
202
|
-
connectedSocketIds: this.dboBuilder.prostgles.connectedSockets.map(s => s.id)
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
return this.dboBuilder.getTX(async (dbTX) => {
|
|
199
|
+
const start = Date.now();
|
|
200
|
+
const result = await this.dboBuilder.getTX(async (dbTX) => {
|
|
206
201
|
const tbl = dbTX[table_name] as TableHandler;
|
|
207
202
|
const existingData = await tbl.find(
|
|
208
203
|
{ $or: data.map(d => pickKeys(d, id_fields)) },
|
|
@@ -247,26 +242,32 @@ export async function syncData (this: PubSubManager, sync: SyncParams, clientDat
|
|
|
247
242
|
log(`upsertData: inserted( ${inserts.length} ) updated( ${updates.length} ) total( ${data.length} ) \n last insert ${JSON.stringify(inserts.at(-1))} \n last update ${JSON.stringify(updates.at(-1))}`);
|
|
248
243
|
return { inserted: inserts.length, updated: updates.length, total: data.length };
|
|
249
244
|
})
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
},
|
|
245
|
+
.catch(err => {
|
|
246
|
+
console.trace("Something went wrong with syncing to server: \n ->", err, data.length, id_fields);
|
|
247
|
+
return Promise.reject("Something went wrong with syncing to server: ")
|
|
248
|
+
});
|
|
255
249
|
|
|
256
|
-
/**
|
|
257
|
-
* Pushes the given data to client
|
|
258
|
-
* @param isSynced = true if
|
|
259
|
-
*/
|
|
260
|
-
pushData = async (data?: AnyObject[], isSynced = false, err: any = null) => {
|
|
261
250
|
await this._log({
|
|
262
251
|
type: "sync",
|
|
263
|
-
command: "
|
|
252
|
+
command: "upsertData",
|
|
264
253
|
tableName: sync.table_name,
|
|
265
|
-
rows: data
|
|
254
|
+
rows: data.length,
|
|
266
255
|
socketId: socket_id,
|
|
256
|
+
sid: sync.sid,
|
|
257
|
+
duration: Date.now() - start,
|
|
267
258
|
connectedSocketIds: this.dboBuilder.prostgles.connectedSockets.map(s => s.id)
|
|
268
259
|
});
|
|
269
|
-
|
|
260
|
+
|
|
261
|
+
return result;
|
|
262
|
+
},
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Pushes the given data to client
|
|
266
|
+
* @param isSynced = true if
|
|
267
|
+
*/
|
|
268
|
+
pushData = async (data?: AnyObject[], isSynced = false, err: any = null) => {
|
|
269
|
+
const start = Date.now();
|
|
270
|
+
const result = await new Promise((resolve, reject) => {
|
|
270
271
|
socket.emit(channel_name, { data, isSynced }, (resp?: { ok: boolean }) => {
|
|
271
272
|
|
|
272
273
|
if (resp && resp.ok) {
|
|
@@ -278,6 +279,19 @@ export async function syncData (this: PubSubManager, sync: SyncParams, clientDat
|
|
|
278
279
|
}
|
|
279
280
|
});
|
|
280
281
|
});
|
|
282
|
+
|
|
283
|
+
await this._log({
|
|
284
|
+
type: "sync",
|
|
285
|
+
command: "pushData",
|
|
286
|
+
tableName: sync.table_name,
|
|
287
|
+
rows: data?.length ?? 0,
|
|
288
|
+
socketId: socket_id,
|
|
289
|
+
duration: Date.now() - start,
|
|
290
|
+
sid: sync.sid,
|
|
291
|
+
connectedSocketIds: this.dboBuilder.prostgles.connectedSockets.map(s => s.id)
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
return result;
|
|
281
295
|
},
|
|
282
296
|
|
|
283
297
|
/**
|
package/lib/initProstgles.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as promise from "bluebird";
|
|
|
2
2
|
import * as pgPromise from "pg-promise";
|
|
3
3
|
import pg from "pg-promise/typescript/pg-subset";
|
|
4
4
|
import { isEmpty, pickKeys } from "prostgles-types";
|
|
5
|
-
import AuthHandler from "./AuthHandler";
|
|
5
|
+
import { AuthHandler } from "./AuthHandler";
|
|
6
6
|
import { DBEventsManager } from "./DBEventsManager";
|
|
7
7
|
import { DBOFullyTyped } from "./DBSchemaBuilder";
|
|
8
8
|
import { DBHandlerServer, Prostgles, ProstglesInitOptions, getIsSuperUser } from "./Prostgles";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prostgles-server",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.62",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"pg-cursor": "^2.10.5",
|
|
44
44
|
"pg-promise": "^11.6.0",
|
|
45
45
|
"prostgles-client": "^4.0.53",
|
|
46
|
-
"prostgles-types": "^4.0.
|
|
46
|
+
"prostgles-types": "^4.0.86"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@types/bluebird": "^3.5.36",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
},
|
|
22
22
|
"../..": {
|
|
23
23
|
"name": "prostgles-server",
|
|
24
|
-
"version": "4.2.
|
|
24
|
+
"version": "4.2.61",
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"bluebird": "^3.7.2",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"pg-cursor": "^2.10.5",
|
|
33
33
|
"pg-promise": "^11.6.0",
|
|
34
34
|
"prostgles-client": "^4.0.53",
|
|
35
|
-
"prostgles-types": "^4.0.
|
|
35
|
+
"prostgles-types": "^4.0.86"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/bluebird": "^3.5.36",
|
|
@@ -1548,7 +1548,7 @@
|
|
|
1548
1548
|
"pg-cursor": "^2.10.5",
|
|
1549
1549
|
"pg-promise": "^11.6.0",
|
|
1550
1550
|
"prostgles-client": "^4.0.53",
|
|
1551
|
-
"prostgles-types": "^4.0.
|
|
1551
|
+
"prostgles-types": "^4.0.86",
|
|
1552
1552
|
"typescript": "^5.3.3"
|
|
1553
1553
|
}
|
|
1554
1554
|
},
|