prostgles-server 3.0.151 → 3.0.153
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/QueryBuilder/QueryBuilder.d.ts.map +1 -1
- package/dist/DboBuilder/QueryBuilder/QueryBuilder.js +4 -3
- package/dist/DboBuilder/QueryBuilder/QueryBuilder.js.map +1 -1
- package/dist/DboBuilder/getSubscribeRelatedTables.d.ts +20 -0
- package/dist/DboBuilder/getSubscribeRelatedTables.d.ts.map +1 -0
- package/dist/DboBuilder/getSubscribeRelatedTables.js +153 -0
- package/dist/DboBuilder/getSubscribeRelatedTables.js.map +1 -0
- package/dist/DboBuilder/subscribe.d.ts.map +1 -1
- package/dist/DboBuilder/subscribe.js +27 -173
- package/dist/DboBuilder/subscribe.js.map +1 -1
- package/dist/PubSubManager/PubSubManager.d.ts.map +1 -1
- package/dist/PubSubManager/PubSubManager.js +35 -4
- package/dist/PubSubManager/PubSubManager.js.map +1 -1
- package/lib/DboBuilder/QueryBuilder/QueryBuilder.d.ts.map +1 -1
- package/lib/DboBuilder/QueryBuilder/QueryBuilder.js +4 -3
- package/lib/DboBuilder/QueryBuilder/QueryBuilder.ts +7 -6
- package/lib/DboBuilder/getSubscribeRelatedTables.d.ts +20 -0
- package/lib/DboBuilder/getSubscribeRelatedTables.d.ts.map +1 -0
- package/lib/DboBuilder/getSubscribeRelatedTables.js +152 -0
- package/lib/DboBuilder/getSubscribeRelatedTables.ts +183 -0
- package/lib/DboBuilder/subscribe.d.ts.map +1 -1
- package/lib/DboBuilder/subscribe.js +27 -173
- package/lib/DboBuilder/subscribe.ts +38 -200
- package/lib/PubSubManager/PubSubManager.d.ts.map +1 -1
- package/lib/PubSubManager/PubSubManager.js +35 -4
- package/lib/PubSubManager/PubSubManager.ts +61 -27
- package/package.json +1 -1
- package/tests/client/PID.txt +1 -1
- package/tests/server/package-lock.json +1 -1
- package/tsconfig.json +4 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.subscribe = void 0;
|
|
4
|
-
const prostgles_types_1 = require("prostgles-types");
|
|
5
4
|
const DboBuilder_1 = require("../DboBuilder");
|
|
6
5
|
const PubSubManager_1 = require("../PubSubManager/PubSubManager");
|
|
6
|
+
const getSubscribeRelatedTables_1 = require("./getSubscribeRelatedTables");
|
|
7
7
|
async function subscribe(filter, params, localFunc, table_rules, localParams) {
|
|
8
8
|
try {
|
|
9
9
|
// if (this.is_view) throw "Cannot subscribe to a view";
|
|
@@ -25,186 +25,40 @@ async function subscribe(filter, params, localFunc, table_rules, localParams) {
|
|
|
25
25
|
if (filterSize * 4 > 2704) {
|
|
26
26
|
throw "filter too big. Might exceed the btree version 4 maximum 2704. Use a primary key or a $rowhash filter instead";
|
|
27
27
|
}
|
|
28
|
+
if (!this.dboBuilder.prostgles.isSuperUser) {
|
|
29
|
+
throw "Subscribe not possible. Must be superuser to add triggers 1856";
|
|
30
|
+
}
|
|
31
|
+
/** Ensure request is valid */
|
|
32
|
+
await this.find(filter, { ...selectParams, limit: 0 }, undefined, table_rules, localParams);
|
|
33
|
+
const viewOptions = await getSubscribeRelatedTables_1.getSubscribeRelatedTables.bind(this)({ filter, selectParams, table_rules, localParams, condition, filterOpts });
|
|
34
|
+
const commonSubOpts = {
|
|
35
|
+
table_info: this.tableOrViewInfo,
|
|
36
|
+
viewOptions,
|
|
37
|
+
table_rules,
|
|
38
|
+
condition,
|
|
39
|
+
table_name: this.name,
|
|
40
|
+
filter: { ...filter },
|
|
41
|
+
params: { ...selectParams },
|
|
42
|
+
throttle,
|
|
43
|
+
last_throttled: 0,
|
|
44
|
+
};
|
|
28
45
|
if (!localFunc) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const viewNameEscaped = this.escapedName;
|
|
38
|
-
const { current_schema } = await this.db.oneOrNone("SELECT current_schema");
|
|
39
|
-
/** Get list of used columns and their parent tables */
|
|
40
|
-
let { def } = (await this.db.oneOrNone("SELECT pg_get_viewdef(${viewName}) as def", { viewName }));
|
|
41
|
-
def = def.trim();
|
|
42
|
-
if (def.endsWith(";")) {
|
|
43
|
-
def = def.slice(0, -1);
|
|
44
|
-
}
|
|
45
|
-
if (!def || typeof def !== "string") {
|
|
46
|
-
throw (0, DboBuilder_1.makeErrorFromPGError)("Could get view definition");
|
|
47
|
-
}
|
|
48
|
-
const { fields } = await this.dboBuilder.dbo.sql(`SELECT * FROM ( \n ${def} \n ) prostgles_subscribe_view_definition LIMIT 0`, {});
|
|
49
|
-
const tableColumns = fields.filter(f => f.tableName && f.columnName);
|
|
50
|
-
/** Create exists filters for each table */
|
|
51
|
-
const tableIds = Array.from(new Set(tableColumns.map(tc => tc.tableID.toString())));
|
|
52
|
-
viewOptions = {
|
|
53
|
-
type: "view",
|
|
54
|
-
viewName,
|
|
55
|
-
definition: def,
|
|
56
|
-
relatedTables: []
|
|
57
|
-
};
|
|
58
|
-
viewOptions.relatedTables = await Promise.all(tableIds.map(async (tableID) => {
|
|
59
|
-
const table = this.dboBuilder.USER_TABLES.find(t => t.relid === +tableID);
|
|
60
|
-
let tableCols = tableColumns.filter(tc => tc.tableID.toString() === tableID);
|
|
61
|
-
/** If table has primary keys and they are all in this view then use only primary keys */
|
|
62
|
-
if (table?.pkey_columns?.every(pkey => tableCols.some(c => c.columnName === pkey))) {
|
|
63
|
-
tableCols = tableCols.filter(c => table?.pkey_columns?.includes(c.columnName));
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
/** Exclude non comparable data types */
|
|
67
|
-
tableCols = tableCols.filter(c => !["json", "xml"].includes(c.udt_name));
|
|
68
|
-
}
|
|
69
|
-
const { relname: tableName, schemaname: tableSchema } = table;
|
|
70
|
-
if (tableCols.length) {
|
|
71
|
-
const tableNameEscaped = tableSchema === current_schema ? table.relname : [tableSchema, tableName].map(v => JSON.stringify(v)).join(".");
|
|
72
|
-
const fullCondition = `EXISTS (
|
|
73
|
-
SELECT 1
|
|
74
|
-
FROM ${viewNameEscaped}
|
|
75
|
-
WHERE ${tableCols.map(c => `${tableNameEscaped}.${JSON.stringify(c.columnName)} = ${viewNameEscaped}.${JSON.stringify(c.name)}`).join(" AND \n")}
|
|
76
|
-
AND ${condition || "TRUE"}
|
|
77
|
-
)`;
|
|
78
|
-
try {
|
|
79
|
-
const { count } = await this.db.oneOrNone(`
|
|
80
|
-
WITH ${(0, prostgles_types_1.asName)(tableName)} AS (
|
|
81
|
-
SELECT *
|
|
82
|
-
FROM ${(0, prostgles_types_1.asName)(tableName)}
|
|
83
|
-
LIMIT 0
|
|
84
|
-
)
|
|
85
|
-
|
|
86
|
-
SELECT COUNT(*) as count
|
|
87
|
-
FROM (
|
|
88
|
-
${def}
|
|
89
|
-
) prostgles_view_ref_table_test
|
|
90
|
-
`);
|
|
91
|
-
const relatedTableSubscription = {
|
|
92
|
-
tableName: tableName,
|
|
93
|
-
tableNameEscaped,
|
|
94
|
-
condition: fullCondition,
|
|
95
|
-
};
|
|
96
|
-
if (count.toString() === '0') {
|
|
97
|
-
return relatedTableSubscription;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
catch (e) {
|
|
101
|
-
(0, PubSubManager_1.log)(`Could not not override subscribed view (${this.name}) table (${tableName}). Will not check condition`, e);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return {
|
|
105
|
-
tableName,
|
|
106
|
-
tableNameEscaped: JSON.stringify(tableName),
|
|
107
|
-
condition: "TRUE"
|
|
108
|
-
};
|
|
109
|
-
}));
|
|
110
|
-
/** Get list of remaining used inner tables */
|
|
111
|
-
const allUsedTables = await this.db.any("SELECT distinct table_name, table_schema FROM information_schema.view_column_usage WHERE view_name = ${viewName}", { viewName });
|
|
112
|
-
/** Remaining tables will have listeners on all records (condition = "TRUE") */
|
|
113
|
-
const remainingInnerTables = allUsedTables.filter(at => !tableColumns.some(dc => dc.tableName === at.table_name && dc.tableSchema === at.table_schema));
|
|
114
|
-
viewOptions.relatedTables = [
|
|
115
|
-
...viewOptions.relatedTables,
|
|
116
|
-
...remainingInnerTables.map(t => ({
|
|
117
|
-
tableName: t.table_name,
|
|
118
|
-
tableNameEscaped: [t.table_name, t.table_schema].map(v => JSON.stringify(v)).join("."),
|
|
119
|
-
condition: "TRUE"
|
|
120
|
-
}))
|
|
121
|
-
];
|
|
122
|
-
if (!viewOptions.relatedTables.length) {
|
|
123
|
-
throw "Could not subscribe to this view: no related tables found";
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
/** Any joined table used within select or filter must also be added a trigger for this recordset */
|
|
127
|
-
if (!this.is_view) {
|
|
128
|
-
const newQuery = await this.find(filter, { ...selectParams, limit: 0 }, undefined, table_rules, { ...localParams, returnNewQuery: true });
|
|
129
|
-
viewOptions = {
|
|
130
|
-
type: "table",
|
|
131
|
-
relatedTables: []
|
|
132
|
-
};
|
|
133
|
-
/**
|
|
134
|
-
* Avoid nested exists error. Will affect performance
|
|
135
|
-
*/
|
|
136
|
-
const nonExistsFilter = filterOpts.exists.length ? {} : filter;
|
|
137
|
-
for await (const j of (newQuery.joins ?? [])) {
|
|
138
|
-
if (!viewOptions.relatedTables.find(rt => rt.tableName === j.table)) {
|
|
139
|
-
viewOptions.relatedTables.push({
|
|
140
|
-
tableName: j.table,
|
|
141
|
-
tableNameEscaped: (0, prostgles_types_1.asName)(j.table),
|
|
142
|
-
condition: (await this.dboBuilder.dbo[j.table].prepareWhere({
|
|
143
|
-
filter: {
|
|
144
|
-
$existsJoined: {
|
|
145
|
-
[[this.name, ...j.$path ?? [].slice(0).reverse()].join(".")]: nonExistsFilter
|
|
146
|
-
}
|
|
147
|
-
},
|
|
148
|
-
addKeywords: false,
|
|
149
|
-
localParams: undefined,
|
|
150
|
-
tableRule: undefined
|
|
151
|
-
})).where
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
for await (const e of newQuery.whereOpts.exists) {
|
|
156
|
-
const eTable = e.tables.at(-1);
|
|
157
|
-
viewOptions.relatedTables.push({
|
|
158
|
-
tableName: eTable,
|
|
159
|
-
tableNameEscaped: (0, prostgles_types_1.asName)(eTable),
|
|
160
|
-
condition: (await this.dboBuilder.dbo[eTable].prepareWhere({
|
|
161
|
-
filter: {
|
|
162
|
-
$existsJoined: {
|
|
163
|
-
[[this.name, ...e.tables ?? [].slice(0, -1).reverse()].join(".")]: nonExistsFilter
|
|
164
|
-
}
|
|
165
|
-
},
|
|
166
|
-
addKeywords: false,
|
|
167
|
-
localParams: undefined,
|
|
168
|
-
tableRule: undefined
|
|
169
|
-
})).where
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
if (!viewOptions.relatedTables.length) {
|
|
173
|
-
viewOptions = undefined;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
const { socket } = localParams ?? {};
|
|
177
|
-
const pubSubManager = await this.dboBuilder.getPubSubManager();
|
|
178
|
-
return pubSubManager.addSub({
|
|
179
|
-
table_info: this.tableOrViewInfo,
|
|
180
|
-
socket,
|
|
181
|
-
table_rules,
|
|
182
|
-
table_name: this.name,
|
|
183
|
-
condition: condition,
|
|
184
|
-
viewOptions,
|
|
185
|
-
func: undefined,
|
|
186
|
-
filter: { ...filter },
|
|
187
|
-
params: { ...selectParams },
|
|
188
|
-
socket_id: socket?.id,
|
|
189
|
-
throttle,
|
|
190
|
-
last_throttled: 0,
|
|
191
|
-
}).then(channelName => ({ channelName }));
|
|
192
|
-
});
|
|
46
|
+
const { socket } = localParams ?? {};
|
|
47
|
+
const pubSubManager = await this.dboBuilder.getPubSubManager();
|
|
48
|
+
return pubSubManager.addSub({
|
|
49
|
+
...commonSubOpts,
|
|
50
|
+
socket,
|
|
51
|
+
func: undefined,
|
|
52
|
+
socket_id: socket?.id,
|
|
53
|
+
}).then(channelName => ({ channelName }));
|
|
193
54
|
}
|
|
194
55
|
else {
|
|
195
56
|
const pubSubManager = await this.dboBuilder.getPubSubManager();
|
|
196
57
|
pubSubManager.addSub({
|
|
197
|
-
|
|
58
|
+
...commonSubOpts,
|
|
198
59
|
socket: undefined,
|
|
199
|
-
table_rules,
|
|
200
|
-
condition,
|
|
201
60
|
func: localFunc,
|
|
202
|
-
filter: { ...filter },
|
|
203
|
-
params: { ...selectParams },
|
|
204
61
|
socket_id: undefined,
|
|
205
|
-
table_name: this.name,
|
|
206
|
-
throttle,
|
|
207
|
-
last_throttled: 0,
|
|
208
62
|
}).then(channelName => ({ channelName }));
|
|
209
63
|
const unsubscribe = async () => {
|
|
210
64
|
const pubSubManager = await this.dboBuilder.getPubSubManager();
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { AnyObject,
|
|
2
|
-
import { Filter, LocalParams,
|
|
1
|
+
import { AnyObject, SubscribeParams } from "prostgles-types";
|
|
2
|
+
import { Filter, LocalParams, parseError } from "../DboBuilder";
|
|
3
3
|
import { TableRule } from "../PublishParser";
|
|
4
|
-
import {
|
|
5
|
-
import { NewQuery } from "./QueryBuilder/QueryBuilder";
|
|
4
|
+
import { omitKeys } from "../PubSubManager/PubSubManager";
|
|
6
5
|
import { ViewHandler } from "./ViewHandler";
|
|
6
|
+
import { getSubscribeRelatedTables } from "./getSubscribeRelatedTables";
|
|
7
7
|
|
|
8
8
|
export type LocalFunc = (items: AnyObject[]) => any;
|
|
9
9
|
|
|
@@ -39,210 +39,48 @@ async function subscribe(this: ViewHandler, filter: Filter, params: SubscribePar
|
|
|
39
39
|
if (filterSize * 4 > 2704) {
|
|
40
40
|
throw "filter too big. Might exceed the btree version 4 maximum 2704. Use a primary key or a $rowhash filter instead"
|
|
41
41
|
}
|
|
42
|
+
if (!this.dboBuilder.prostgles.isSuperUser) {
|
|
43
|
+
throw "Subscribe not possible. Must be superuser to add triggers 1856";
|
|
44
|
+
}
|
|
42
45
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (!this.dboBuilder.prostgles.isSuperUser) {
|
|
46
|
-
throw "Subscribe not possible. Must be superuser to add triggers 1856";
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return await this.find(filter, { ...selectParams, limit: 0 }, undefined, table_rules, localParams)
|
|
50
|
-
.then(async _isValid => {
|
|
51
|
-
|
|
52
|
-
let viewOptions: ViewSubscriptionOptions | undefined = undefined;
|
|
53
|
-
|
|
54
|
-
if (this.is_view) {
|
|
55
|
-
const viewName = this.name;
|
|
56
|
-
const viewNameEscaped = this.escapedName;
|
|
57
|
-
const { current_schema } = await this.db.oneOrNone("SELECT current_schema")
|
|
58
|
-
|
|
59
|
-
/** Get list of used columns and their parent tables */
|
|
60
|
-
let { def } = (await this.db.oneOrNone("SELECT pg_get_viewdef(${viewName}) as def", { viewName })) as { def: string };
|
|
61
|
-
def = def.trim();
|
|
62
|
-
if (def.endsWith(";")) {
|
|
63
|
-
def = def.slice(0, -1);
|
|
64
|
-
}
|
|
65
|
-
if (!def || typeof def !== "string") {
|
|
66
|
-
throw makeErrorFromPGError("Could get view definition");
|
|
67
|
-
}
|
|
68
|
-
const { fields } = await this.dboBuilder.dbo.sql!(`SELECT * FROM ( \n ${def} \n ) prostgles_subscribe_view_definition LIMIT 0`, {});
|
|
69
|
-
const tableColumns = fields.filter(f => f.tableName && f.columnName);
|
|
70
|
-
|
|
71
|
-
/** Create exists filters for each table */
|
|
72
|
-
const tableIds: string[] = Array.from(new Set(tableColumns.map(tc => tc.tableID!.toString())));
|
|
73
|
-
viewOptions = {
|
|
74
|
-
type: "view",
|
|
75
|
-
viewName,
|
|
76
|
-
definition: def,
|
|
77
|
-
relatedTables: []
|
|
78
|
-
}
|
|
79
|
-
viewOptions.relatedTables = await Promise.all(tableIds.map(async tableID => {
|
|
80
|
-
const table = this.dboBuilder.USER_TABLES!.find(t => t.relid === +tableID)!;
|
|
81
|
-
let tableCols = tableColumns.filter(tc => tc.tableID!.toString() === tableID);
|
|
82
|
-
|
|
83
|
-
/** If table has primary keys and they are all in this view then use only primary keys */
|
|
84
|
-
if (table?.pkey_columns?.every(pkey => tableCols.some(c => c.columnName === pkey))) {
|
|
85
|
-
tableCols = tableCols.filter(c => table?.pkey_columns?.includes(c.columnName!))
|
|
86
|
-
} else {
|
|
87
|
-
/** Exclude non comparable data types */
|
|
88
|
-
tableCols = tableCols.filter(c => !["json", "xml"].includes(c.udt_name))
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const { relname: tableName, schemaname: tableSchema } = table;
|
|
92
|
-
|
|
93
|
-
if(tableCols.length){
|
|
94
|
-
|
|
95
|
-
const tableNameEscaped = tableSchema === current_schema ? table.relname : [tableSchema, tableName].map(v => JSON.stringify(v)).join(".");
|
|
96
|
-
|
|
97
|
-
const fullCondition = `EXISTS (
|
|
98
|
-
SELECT 1
|
|
99
|
-
FROM ${viewNameEscaped}
|
|
100
|
-
WHERE ${tableCols.map(c => `${tableNameEscaped}.${JSON.stringify(c.columnName)} = ${viewNameEscaped}.${JSON.stringify(c.name)}`).join(" AND \n")}
|
|
101
|
-
AND ${condition || "TRUE"}
|
|
102
|
-
)`;
|
|
103
|
-
|
|
104
|
-
try {
|
|
105
|
-
const { count } = await this.db.oneOrNone(`
|
|
106
|
-
WITH ${asName(tableName)} AS (
|
|
107
|
-
SELECT *
|
|
108
|
-
FROM ${asName(tableName)}
|
|
109
|
-
LIMIT 0
|
|
110
|
-
)
|
|
111
|
-
|
|
112
|
-
SELECT COUNT(*) as count
|
|
113
|
-
FROM (
|
|
114
|
-
${def}
|
|
115
|
-
) prostgles_view_ref_table_test
|
|
116
|
-
`);
|
|
117
|
-
|
|
118
|
-
const relatedTableSubscription = {
|
|
119
|
-
tableName: tableName!,
|
|
120
|
-
tableNameEscaped,
|
|
121
|
-
condition: fullCondition,
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if(count.toString() === '0'){
|
|
125
|
-
return relatedTableSubscription;
|
|
126
|
-
}
|
|
127
|
-
} catch(e){
|
|
128
|
-
log(`Could not not override subscribed view (${this.name}) table (${tableName}). Will not check condition`, e);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return {
|
|
133
|
-
tableName,
|
|
134
|
-
tableNameEscaped: JSON.stringify(tableName),// [table.schemaname, table.relname].map(v => JSON.stringify(v)).join("."),
|
|
135
|
-
condition: "TRUE"
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
}))
|
|
139
|
-
|
|
140
|
-
/** Get list of remaining used inner tables */
|
|
141
|
-
const allUsedTables: { table_name: string; table_schema: string; }[] = await this.db.any(
|
|
142
|
-
"SELECT distinct table_name, table_schema FROM information_schema.view_column_usage WHERE view_name = ${viewName}",
|
|
143
|
-
{ viewName }
|
|
144
|
-
);
|
|
46
|
+
/** Ensure request is valid */
|
|
47
|
+
await this.find(filter, { ...selectParams, limit: 0 }, undefined, table_rules, localParams);
|
|
145
48
|
|
|
146
|
-
|
|
147
|
-
const remainingInnerTables = allUsedTables.filter(at => !tableColumns.some(dc => dc.tableName === at.table_name && dc.tableSchema === at.table_schema));
|
|
148
|
-
viewOptions.relatedTables = [
|
|
149
|
-
...viewOptions.relatedTables,
|
|
150
|
-
...remainingInnerTables.map(t => ({
|
|
151
|
-
tableName: t.table_name,
|
|
152
|
-
tableNameEscaped: [t.table_name, t.table_schema].map(v => JSON.stringify(v)).join("."),
|
|
153
|
-
condition: "TRUE"
|
|
154
|
-
}))
|
|
155
|
-
];
|
|
49
|
+
const viewOptions = await getSubscribeRelatedTables.bind(this)({ filter, selectParams, table_rules, localParams, condition, filterOpts })
|
|
156
50
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
51
|
+
const commonSubOpts = {
|
|
52
|
+
table_info: this.tableOrViewInfo,
|
|
53
|
+
viewOptions,
|
|
54
|
+
table_rules,
|
|
55
|
+
condition,
|
|
56
|
+
table_name: this.name,
|
|
57
|
+
filter: { ...filter },
|
|
58
|
+
params: { ...selectParams },
|
|
59
|
+
throttle,
|
|
60
|
+
last_throttled: 0,
|
|
61
|
+
} as const;
|
|
161
62
|
|
|
162
|
-
|
|
163
|
-
if(!this.is_view){
|
|
164
|
-
const newQuery = await this.find(filter, { ...selectParams, limit: 0 }, undefined, table_rules, { ...localParams, returnNewQuery: true }) as unknown as NewQuery;
|
|
165
|
-
viewOptions = {
|
|
166
|
-
type: "table",
|
|
167
|
-
relatedTables: []
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Avoid nested exists error. Will affect performance
|
|
171
|
-
*/
|
|
172
|
-
const nonExistsFilter = filterOpts.exists.length? {} : filter;
|
|
173
|
-
for await (const j of (newQuery.joins ?? [])) {
|
|
174
|
-
if(!viewOptions!.relatedTables.find(rt => rt.tableName === j.table)){
|
|
175
|
-
viewOptions.relatedTables.push({
|
|
176
|
-
tableName: j.table,
|
|
177
|
-
tableNameEscaped: asName(j.table),
|
|
178
|
-
condition: (await this.dboBuilder.dbo[j.table]!.prepareWhere!({
|
|
179
|
-
filter: {
|
|
180
|
-
$existsJoined: {
|
|
181
|
-
|
|
182
|
-
[[this.name, ...j.$path ?? [].slice(0).reverse()].join(".")]: nonExistsFilter
|
|
183
|
-
}
|
|
184
|
-
},
|
|
185
|
-
addKeywords: false,
|
|
186
|
-
localParams: undefined,
|
|
187
|
-
tableRule: undefined
|
|
188
|
-
})).where
|
|
189
|
-
})
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
for await(const e of newQuery.whereOpts.exists) {
|
|
193
|
-
const eTable = e.tables.at(-1)!
|
|
194
|
-
viewOptions.relatedTables.push({
|
|
195
|
-
tableName: eTable,
|
|
196
|
-
tableNameEscaped: asName(eTable),
|
|
197
|
-
condition: (await this.dboBuilder.dbo[eTable]!.prepareWhere!({
|
|
198
|
-
filter: {
|
|
199
|
-
$existsJoined: {
|
|
200
|
-
[[this.name, ...e.tables ?? [].slice(0, -1).reverse()].join(".")]: nonExistsFilter
|
|
201
|
-
}
|
|
202
|
-
},
|
|
203
|
-
addKeywords: false,
|
|
204
|
-
localParams: undefined,
|
|
205
|
-
tableRule: undefined
|
|
206
|
-
})).where
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
if(!viewOptions.relatedTables.length){
|
|
210
|
-
viewOptions = undefined;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
63
|
+
if (!localFunc) {
|
|
213
64
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
func: undefined,
|
|
224
|
-
filter: { ...filter },
|
|
225
|
-
params: { ...selectParams },
|
|
226
|
-
socket_id: socket?.id,
|
|
227
|
-
throttle,
|
|
228
|
-
last_throttled: 0,
|
|
229
|
-
}).then(channelName => ({ channelName }));
|
|
230
|
-
}) as any;
|
|
65
|
+
const { socket } = localParams ?? {};
|
|
66
|
+
const pubSubManager = await this.dboBuilder.getPubSubManager();
|
|
67
|
+
return pubSubManager.addSub({
|
|
68
|
+
...commonSubOpts,
|
|
69
|
+
socket,
|
|
70
|
+
func: undefined,
|
|
71
|
+
socket_id: socket?.id,
|
|
72
|
+
}).then(channelName => ({ channelName })) as any;
|
|
73
|
+
|
|
231
74
|
} else {
|
|
75
|
+
|
|
232
76
|
const pubSubManager = await this.dboBuilder.getPubSubManager();
|
|
233
|
-
pubSubManager.addSub({
|
|
234
|
-
|
|
235
|
-
socket: undefined,
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
func: localFunc,
|
|
239
|
-
filter: { ...filter },
|
|
240
|
-
params: { ...selectParams },
|
|
241
|
-
socket_id: undefined,
|
|
242
|
-
table_name: this.name,
|
|
243
|
-
throttle,
|
|
244
|
-
last_throttled: 0,
|
|
77
|
+
pubSubManager.addSub({
|
|
78
|
+
...commonSubOpts,
|
|
79
|
+
socket: undefined,
|
|
80
|
+
func: localFunc,
|
|
81
|
+
socket_id: undefined,
|
|
245
82
|
}).then(channelName => ({ channelName }));
|
|
83
|
+
|
|
246
84
|
const unsubscribe = async () => {
|
|
247
85
|
const pubSubManager = await this.dboBuilder.getPubSubManager();
|
|
248
86
|
pubSubManager.removeLocalSub(this.name, condition, localFunc)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PubSubManager.d.ts","sourceRoot":"","sources":["PubSubManager.ts"],"names":[],"mappings":";AAKA,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAE3E,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,YAAY,EAAc,MAAM,eAAe,CAAC;AAClH,OAAO,EAAE,EAAE,EAAe,MAAM,cAAc,CAAC;AAO/C,OAAO,EAAE,YAAY,EAAE,WAAW,EAAU,GAAG,EAAW,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE7F,OAAO,EAAE,iBAAiB,EAAY,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAS7C,eAAO,MAAM,OAAO,MAAO,GAAG,WAA6B,CAAC;AAC5D,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAE1C,eAAO,MAAM,GAAG,YAAa,GAAG,EAAE,SAIjC,CAAA;AAED,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,GAAG,KAAK,IAAI,CAAA;AAE1D,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,OAAO,CAAC;IACtB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE;QACN,MAAM,EAAE,WA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AC,EAAE,uBAAuB;CA8D3G;AAKD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA"}
|
|
@@ -268,7 +268,28 @@ class PubSubManager {
|
|
|
268
268
|
return this.postgresNotifListenManager.isListening();
|
|
269
269
|
}
|
|
270
270
|
getSubs(table_name, condition) {
|
|
271
|
-
|
|
271
|
+
const subs = this.subs?.[table_name]?.[condition]?.subs ?? [];
|
|
272
|
+
// if(!subs){
|
|
273
|
+
// log("Subs not found:", { table_name, condition }, this.subs)
|
|
274
|
+
// }
|
|
275
|
+
return subs.flatMap(s => {
|
|
276
|
+
/* Return parentSubs to ensure throttling works */
|
|
277
|
+
if (s.parentSubParams) {
|
|
278
|
+
const parentSubs = [];
|
|
279
|
+
const parentChannel = s.parentSubParams.channel_name;
|
|
280
|
+
for (const tableName in (0, util_1.getKeys)(this.subs)) {
|
|
281
|
+
for (const condition in (0, util_1.getKeys)(this.subs[tableName])) {
|
|
282
|
+
this.subs[tableName][condition].subs.forEach(parentSub => {
|
|
283
|
+
if (!parentSub.parentSubParams && parentSub.channel_name === parentChannel) {
|
|
284
|
+
parentSubs.push(parentSub);
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return parentSubs ?? s;
|
|
290
|
+
}
|
|
291
|
+
return s;
|
|
292
|
+
});
|
|
272
293
|
}
|
|
273
294
|
getSyncs(table_name, condition) {
|
|
274
295
|
return (this.syncs || [])
|
|
@@ -296,12 +317,19 @@ class PubSubManager {
|
|
|
296
317
|
console.error("Unexpected notif type: ", notifType);
|
|
297
318
|
return;
|
|
298
319
|
}
|
|
320
|
+
if (dataArr.length < 3) {
|
|
321
|
+
throw "dataArr length < 3";
|
|
322
|
+
}
|
|
299
323
|
const table_name = dataArr[1], op_name = dataArr[2], condition_ids_str = dataArr[3];
|
|
300
324
|
// const triggers = await this.db.any("SELECT * FROM prostgles.triggers WHERE table_name = $1 AND id IN ($2:csv)", [table_name, condition_ids_str.split(",").map(v => +v)]);
|
|
301
325
|
// const conditions: string[] = triggers.map(t => t.condition);
|
|
326
|
+
/**
|
|
327
|
+
* Trigger error
|
|
328
|
+
*/
|
|
302
329
|
(0, exports.log)("PG Trigger ->", dataArr.join("__"));
|
|
303
330
|
if (condition_ids_str && condition_ids_str.startsWith("error") &&
|
|
304
|
-
this._triggers &&
|
|
331
|
+
this._triggers &&
|
|
332
|
+
this._triggers[table_name]?.length) {
|
|
305
333
|
const pref = "INTERNAL ERROR";
|
|
306
334
|
console.error(`${pref}: condition_ids_str: ${condition_ids_str}`);
|
|
307
335
|
this._triggers[table_name].map(c => {
|
|
@@ -310,6 +338,9 @@ class PubSubManager {
|
|
|
310
338
|
this.pushSubData(s, pref + ". Check server logs. Schema might have changed");
|
|
311
339
|
});
|
|
312
340
|
});
|
|
341
|
+
/**
|
|
342
|
+
* Trigger ok
|
|
343
|
+
*/
|
|
313
344
|
}
|
|
314
345
|
else if (condition_ids_str?.split(",").length &&
|
|
315
346
|
condition_ids_str?.split(",").every((c) => Number.isInteger(+c)) &&
|
|
@@ -762,8 +793,8 @@ class PubSubManager {
|
|
|
762
793
|
triggers.map(t => {
|
|
763
794
|
this._triggers = this._triggers || {};
|
|
764
795
|
this._triggers[t.table_name] = this._triggers[t.table_name] || [];
|
|
765
|
-
if (!this._triggers[t.table_name]
|
|
766
|
-
this._triggers[t.table_name]
|
|
796
|
+
if (!this._triggers[t.table_name]?.includes(t.condition)) {
|
|
797
|
+
this._triggers[t.table_name]?.push(t.condition);
|
|
767
798
|
}
|
|
768
799
|
});
|
|
769
800
|
(0, exports.log)("trigger added.. ", { table_name, condition });
|