prostgles-server 4.2.264 → 4.2.266
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/ViewHandler/getValidatedSubscribeOptions.d.ts +4 -0
- package/dist/DboBuilder/ViewHandler/getValidatedSubscribeOptions.d.ts.map +1 -0
- package/dist/DboBuilder/ViewHandler/getValidatedSubscribeOptions.js +65 -0
- package/dist/DboBuilder/ViewHandler/getValidatedSubscribeOptions.js.map +1 -0
- package/dist/DboBuilder/ViewHandler/prepareSortItems.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/prepareSortItems.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/subscribe.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/subscribe.js +5 -5
- package/dist/DboBuilder/ViewHandler/subscribe.js.map +1 -1
- package/dist/JSONBValidation/JSONBValidation.d.ts.map +1 -1
- package/dist/JSONBValidation/JSONBValidation.js +111 -11
- package/dist/JSONBValidation/JSONBValidation.js.map +1 -1
- package/dist/JSONBValidation/JSONBValidation.spec.d.ts +2 -0
- package/dist/JSONBValidation/JSONBValidation.spec.d.ts.map +1 -0
- package/dist/JSONBValidation/JSONBValidation.spec.js +68 -0
- package/dist/JSONBValidation/JSONBValidation.spec.js.map +1 -0
- package/dist/JSONBValidation/getJSONBSchemaTSTypes.d.ts +1 -0
- package/dist/JSONBValidation/getJSONBSchemaTSTypes.d.ts.map +1 -1
- package/dist/JSONBValidation/getJSONBSchemaTSTypes.js +97 -96
- package/dist/JSONBValidation/getJSONBSchemaTSTypes.js.map +1 -1
- package/dist/PubSubManager/PubSubManager.d.ts +7 -23
- package/dist/PubSubManager/PubSubManager.d.ts.map +1 -1
- package/dist/PubSubManager/PubSubManager.js +1 -1
- package/dist/PubSubManager/PubSubManager.js.map +1 -1
- package/dist/PubSubManager/addSub.d.ts +1 -1
- package/dist/PubSubManager/addSub.d.ts.map +1 -1
- package/dist/PubSubManager/addSub.js +17 -21
- package/dist/PubSubManager/addSub.js.map +1 -1
- package/dist/PubSubManager/notifListener.d.ts.map +1 -1
- package/dist/PubSubManager/notifListener.js +9 -4
- package/dist/PubSubManager/notifListener.js.map +1 -1
- package/dist/PubSubManager/pushSubData.js +1 -1
- package/dist/PubSubManager/pushSubData.js.map +1 -1
- package/lib/DboBuilder/ViewHandler/getValidatedSubscribeOptions.ts +72 -0
- package/lib/DboBuilder/ViewHandler/prepareSortItems.ts +1 -4
- package/lib/DboBuilder/ViewHandler/subscribe.ts +9 -6
- package/lib/JSONBValidation/JSONBValidation.spec.ts +129 -0
- package/lib/JSONBValidation/JSONBValidation.ts +108 -13
- package/lib/JSONBValidation/getJSONBSchemaTSTypes.ts +110 -110
- package/lib/PubSubManager/PubSubManager.ts +9 -8
- package/lib/PubSubManager/addSub.ts +20 -24
- package/lib/PubSubManager/notifListener.ts +16 -4
- package/lib/PubSubManager/pushSubData.ts +1 -1
- package/package.json +3 -2
- package/tsconfig.json +3 -0
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
SelectParams,
|
|
30
30
|
SubscribeParams,
|
|
31
31
|
WAL,
|
|
32
|
+
type SubscribeOptions,
|
|
32
33
|
} from "prostgles-types";
|
|
33
34
|
|
|
34
35
|
import { find, pickKeys } from "prostgles-types/dist/util";
|
|
@@ -109,7 +110,7 @@ export type ViewSubscriptionOptions = (
|
|
|
109
110
|
}[];
|
|
110
111
|
};
|
|
111
112
|
|
|
112
|
-
export type SubscriptionParams =
|
|
113
|
+
export type SubscriptionParams = {
|
|
113
114
|
socket_id?: string;
|
|
114
115
|
channel_name: string;
|
|
115
116
|
|
|
@@ -124,22 +125,23 @@ export type SubscriptionParams = Pick<SubscribeParams, "throttle" | "throttleOpt
|
|
|
124
125
|
/* Used as input */
|
|
125
126
|
table_rules?: ParsedTableRule;
|
|
126
127
|
filter: object;
|
|
127
|
-
|
|
128
|
+
selectParams: SelectParams;
|
|
129
|
+
subscribeOptions: SubscribeOptions;
|
|
128
130
|
|
|
129
131
|
localFuncs?: LocalFuncs;
|
|
130
132
|
socket: PRGLIOSocket | undefined;
|
|
131
133
|
|
|
132
|
-
|
|
134
|
+
lastPushed: number;
|
|
133
135
|
is_throttling?: any;
|
|
134
136
|
is_ready?: boolean;
|
|
135
137
|
};
|
|
136
138
|
|
|
137
139
|
export type Subscription = Pick<
|
|
138
140
|
SubscriptionParams,
|
|
139
|
-
| "
|
|
141
|
+
| "selectParams"
|
|
142
|
+
| "subscribeOptions"
|
|
140
143
|
| "is_throttling"
|
|
141
|
-
| "
|
|
142
|
-
| "throttleOpts"
|
|
144
|
+
| "lastPushed"
|
|
143
145
|
| "channel_name"
|
|
144
146
|
| "is_ready"
|
|
145
147
|
| "localFuncs"
|
|
@@ -147,7 +149,6 @@ export type Subscription = Pick<
|
|
|
147
149
|
| "socket_id"
|
|
148
150
|
| "table_info"
|
|
149
151
|
| "filter"
|
|
150
|
-
| "params"
|
|
151
152
|
| "table_rules"
|
|
152
153
|
> & {
|
|
153
154
|
triggers: {
|
|
@@ -298,7 +299,7 @@ export class PubSubManager {
|
|
|
298
299
|
getSubData = async (
|
|
299
300
|
sub: Subscription
|
|
300
301
|
): Promise<{ data: any[]; err?: undefined } | { data?: undefined; err: any }> => {
|
|
301
|
-
const { table_info, filter, params, table_rules } = sub; //, subOne = false
|
|
302
|
+
const { table_info, filter, selectParams: params, table_rules } = sub; //, subOne = false
|
|
302
303
|
const { name: table_name } = table_info;
|
|
303
304
|
|
|
304
305
|
if (!this.dbo[table_name]?.find) {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { SubscriptionChannels } from "prostgles-types";
|
|
2
|
+
import { VoidFunction } from "../SchemaWatch/SchemaWatch";
|
|
3
|
+
import { tout } from "./initPubSubManager";
|
|
2
4
|
import {
|
|
3
5
|
BasicCallback,
|
|
4
6
|
parseCondition,
|
|
@@ -6,7 +8,6 @@ import {
|
|
|
6
8
|
Subscription,
|
|
7
9
|
SubscriptionParams,
|
|
8
10
|
} from "./PubSubManager";
|
|
9
|
-
import { VoidFunction } from "../SchemaWatch/SchemaWatch";
|
|
10
11
|
|
|
11
12
|
type AddSubscriptionParams = SubscriptionParams & {
|
|
12
13
|
condition: string;
|
|
@@ -27,12 +28,11 @@ export async function addSub(
|
|
|
27
28
|
localFuncs,
|
|
28
29
|
table_rules,
|
|
29
30
|
filter = {},
|
|
30
|
-
|
|
31
|
+
selectParams = {},
|
|
31
32
|
condition = "",
|
|
32
|
-
throttle = 0, //subOne = false,
|
|
33
33
|
viewOptions,
|
|
34
34
|
table_info,
|
|
35
|
-
|
|
35
|
+
subscribeOptions,
|
|
36
36
|
} = subscriptionParams;
|
|
37
37
|
const table_name = table_info.name;
|
|
38
38
|
|
|
@@ -43,16 +43,7 @@ export async function addSub(
|
|
|
43
43
|
throw "addSub: cannot have socket AND func";
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
const pubThrottle = table_rules?.subscribe?.throttle || 0;
|
|
48
|
-
if (pubThrottle && Number.isInteger(pubThrottle) && pubThrottle > 0) {
|
|
49
|
-
validated_throttle = pubThrottle;
|
|
50
|
-
}
|
|
51
|
-
if (throttle && Number.isInteger(throttle) && throttle >= pubThrottle) {
|
|
52
|
-
validated_throttle = throttle;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const channel_name = `${this.socketChannelPreffix}.${table_name}.${JSON.stringify(filter)}.${JSON.stringify(params)}.${"m"}.sub`;
|
|
46
|
+
const channel_name = `${this.socketChannelPreffix}.${table_name}.${JSON.stringify(filter)}.${JSON.stringify(selectParams)}.${"m"}.sub`;
|
|
56
47
|
const mainTrigger = {
|
|
57
48
|
table_name: table_name,
|
|
58
49
|
condition: parseCondition(condition),
|
|
@@ -63,16 +54,16 @@ export async function addSub(
|
|
|
63
54
|
channel_name,
|
|
64
55
|
filter,
|
|
65
56
|
localFuncs,
|
|
66
|
-
|
|
67
|
-
|
|
57
|
+
selectParams: selectParams,
|
|
58
|
+
lastPushed: 0,
|
|
68
59
|
socket,
|
|
69
|
-
|
|
60
|
+
subscribeOptions,
|
|
70
61
|
table_info,
|
|
71
62
|
is_ready: true,
|
|
72
63
|
is_throttling: false,
|
|
73
64
|
socket_id: socket?.id,
|
|
74
65
|
table_rules,
|
|
75
|
-
|
|
66
|
+
|
|
76
67
|
triggers: [mainTrigger],
|
|
77
68
|
};
|
|
78
69
|
|
|
@@ -105,14 +96,21 @@ export async function addSub(
|
|
|
105
96
|
}
|
|
106
97
|
}
|
|
107
98
|
|
|
99
|
+
const { skipFirst, throttleOpts, throttle } = subscribeOptions;
|
|
100
|
+
const sendFirstData = async () => {
|
|
101
|
+
if (skipFirst) return;
|
|
102
|
+
if (throttleOpts?.skipFirst && throttle) {
|
|
103
|
+
await tout(throttle);
|
|
104
|
+
}
|
|
105
|
+
void this.pushSubData(newSub);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
108
|
if (localFuncs) {
|
|
109
109
|
/**
|
|
110
110
|
* Must ensure sub will start sending data after all triggers are set up.
|
|
111
111
|
* Socket clients are not affected as they need to confirm they are ready to receive data
|
|
112
112
|
*/
|
|
113
|
-
result.sendFirstData =
|
|
114
|
-
void this.pushSubData(newSub);
|
|
115
|
-
};
|
|
113
|
+
result.sendFirstData = sendFirstData;
|
|
116
114
|
} else if (socket) {
|
|
117
115
|
const removeListeners = () => {
|
|
118
116
|
socket.removeAllListeners(channel_name);
|
|
@@ -121,9 +119,7 @@ export async function addSub(
|
|
|
121
119
|
};
|
|
122
120
|
removeListeners();
|
|
123
121
|
|
|
124
|
-
socket.once(result.channelNameReady,
|
|
125
|
-
void this.pushSubData(newSub);
|
|
126
|
-
});
|
|
122
|
+
socket.once(result.channelNameReady, sendFirstData);
|
|
127
123
|
socket.once(result.channelNameUnsubscribe, (_data: any, cb: BasicCallback) => {
|
|
128
124
|
const res = "ok";
|
|
129
125
|
this.subs = this.subs.filter((s) => {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { parseFieldFilter } from "../DboBuilder/ViewHandler/parseFieldFilter";
|
|
1
2
|
import { log, NOTIF_TYPE, NotifTypeName, pickKeys, PubSubManager } from "./PubSubManager";
|
|
2
3
|
|
|
3
4
|
/* Relay relevant data to relevant subscriptions */
|
|
@@ -128,10 +129,22 @@ export async function notifListener(this: PubSubManager, data: { payload: string
|
|
|
128
129
|
)
|
|
129
130
|
);
|
|
130
131
|
activeAndReadySubs.forEach((sub) => {
|
|
131
|
-
const { throttle = 0, throttleOpts } = sub;
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
const { throttle = 0, throttleOpts, actions } = sub.subscribeOptions;
|
|
133
|
+
|
|
134
|
+
const commandLowerCase = (op_name?.toLowerCase() || "insert") as keyof NonNullable<
|
|
135
|
+
typeof actions
|
|
136
|
+
>;
|
|
137
|
+
|
|
138
|
+
const actionIsIgnored =
|
|
139
|
+
actions &&
|
|
140
|
+
!parseFieldFilter(actions, false, ["insert", "update", "delete"]).includes(
|
|
141
|
+
commandLowerCase as any
|
|
142
|
+
);
|
|
143
|
+
if (actionIsIgnored) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
134
146
|
|
|
147
|
+
if (!throttleOpts?.skipFirst && sub.lastPushed <= Date.now() - throttle) {
|
|
135
148
|
/* It is assumed the policy was checked before this point */
|
|
136
149
|
void this.pushSubData(sub);
|
|
137
150
|
} else if (!sub.is_throttling) {
|
|
@@ -139,7 +152,6 @@ export async function notifListener(this: PubSubManager, data: { payload: string
|
|
|
139
152
|
sub.is_throttling = setTimeout(() => {
|
|
140
153
|
log("throttling finished. pushSubData...");
|
|
141
154
|
sub.is_throttling = null;
|
|
142
|
-
sub.last_throttled = Date.now();
|
|
143
155
|
void this.pushSubData(sub);
|
|
144
156
|
}, throttle);
|
|
145
157
|
}
|
|
@@ -35,6 +35,7 @@ export async function pushSubData(this: PubSubManager, sub: Subscription, err?:
|
|
|
35
35
|
return true;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
sub.lastPushed = Date.now();
|
|
38
39
|
return new Promise(async (resolve, reject) => {
|
|
39
40
|
/* TODO: Retire subOne -> it's redundant */
|
|
40
41
|
|
|
@@ -57,7 +58,6 @@ export async function pushSubData(this: PubSubManager, sub: Subscription, err?:
|
|
|
57
58
|
} else {
|
|
58
59
|
onLog("no client to push data to");
|
|
59
60
|
}
|
|
60
|
-
// sub.last_throttled = Date.now();
|
|
61
61
|
} else {
|
|
62
62
|
onLog("fetch data error");
|
|
63
63
|
const errObj = { _err_msg: err.toString(), err };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prostgles-server",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.266",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"test-only": "cd tests/ && ./test.sh",
|
|
16
16
|
"test-quick": "cd tests/ && ./test.sh -quick",
|
|
17
17
|
"test": "rm -rf ./node_modules/* && rm -rf ./dist/* && npm i && npm run lint && npm run test-only",
|
|
18
|
+
"test-server-funcs": "node --trace-uncaught --test dist/**/*.spec.js",
|
|
18
19
|
"generate-docs": "rm -f ./docs/*.md && cd docs/utils && npm start",
|
|
19
20
|
"pushpublish": "npm run generate-docs && npm version patch --git-tag-version false && git push && npm publish"
|
|
20
21
|
},
|
|
@@ -56,7 +57,7 @@
|
|
|
56
57
|
"pg": "^8.11.5",
|
|
57
58
|
"pg-cursor": "^2.11.0",
|
|
58
59
|
"pg-promise": "^11.9.1",
|
|
59
|
-
"prostgles-types": "^4.0.
|
|
60
|
+
"prostgles-types": "^4.0.164"
|
|
60
61
|
},
|
|
61
62
|
"devDependencies": {
|
|
62
63
|
"@eslint/js": "^9.22.0",
|