prostgles-server 4.2.440 → 4.2.442
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/ViewHandler.d.ts +6 -6
- package/dist/DboBuilder/ViewHandler/ViewHandler.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/ViewHandler.js +6 -8
- package/dist/DboBuilder/ViewHandler/ViewHandler.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/subscribe.d.ts +4 -12
- package/dist/DboBuilder/ViewHandler/subscribe.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/subscribe.js +11 -25
- package/dist/DboBuilder/ViewHandler/subscribe.js.map +1 -1
- package/dist/Logging.d.ts +2 -1
- package/dist/Logging.d.ts.map +1 -1
- package/dist/PubSubManager/PubSubManager.d.ts +19 -11
- package/dist/PubSubManager/PubSubManager.d.ts.map +1 -1
- package/dist/PubSubManager/PubSubManager.js +35 -25
- package/dist/PubSubManager/PubSubManager.js.map +1 -1
- package/dist/PubSubManager/addSub.d.ts.map +1 -1
- package/dist/PubSubManager/addSub.js +6 -6
- package/dist/PubSubManager/addSub.js.map +1 -1
- package/dist/PubSubManager/init/getDataWatchFunctionQuery.d.ts.map +1 -1
- package/dist/PubSubManager/init/getDataWatchFunctionQuery.js +22 -1
- package/dist/PubSubManager/init/getDataWatchFunctionQuery.js.map +1 -1
- package/dist/PubSubManager/notifListener.js +3 -3
- package/dist/PubSubManager/notifListener.js.map +1 -1
- package/dist/PubSubManager/pushSubData.d.ts +1 -1
- package/dist/PubSubManager/pushSubData.d.ts.map +1 -1
- package/dist/PubSubManager/pushSubData.js +21 -42
- package/dist/PubSubManager/pushSubData.js.map +1 -1
- package/dist/PubSubManager/refreshTriggers.d.ts.map +1 -1
- package/dist/PubSubManager/refreshTriggers.js +6 -5
- package/dist/PubSubManager/refreshTriggers.js.map +1 -1
- package/dist/PublishParser/PublishParser.d.ts +2 -1
- package/dist/PublishParser/PublishParser.d.ts.map +1 -1
- package/dist/PublishParser/PublishParser.js +38 -18
- package/dist/PublishParser/PublishParser.js.map +1 -1
- package/dist/PublishParser/getSchemaFromPublish.js +11 -11
- package/dist/PublishParser/getSchemaFromPublish.js.map +1 -1
- package/dist/PublishParser/getTableRulesWithoutFileTable.d.ts.map +1 -1
- package/dist/PublishParser/getTableRulesWithoutFileTable.js +2 -2
- package/dist/PublishParser/getTableRulesWithoutFileTable.js.map +1 -1
- package/dist/initProstgles.d.ts.map +1 -1
- package/dist/initProstgles.js +13 -0
- package/dist/initProstgles.js.map +1 -1
- package/dist/runClientRequest.d.ts.map +1 -1
- package/dist/runClientRequest.js +2 -1
- package/dist/runClientRequest.js.map +1 -1
- package/lib/DboBuilder/ViewHandler/ViewHandler.ts +32 -30
- package/lib/DboBuilder/ViewHandler/subscribe.ts +22 -48
- package/lib/Logging.ts +3 -1
- package/lib/PubSubManager/PubSubManager.ts +50 -42
- package/lib/PubSubManager/addSub.ts +13 -8
- package/lib/PubSubManager/init/getDataWatchFunctionQuery.ts +28 -1
- package/lib/PubSubManager/notifListener.ts +8 -8
- package/lib/PubSubManager/pushSubData.ts +20 -35
- package/lib/PubSubManager/refreshTriggers.ts +9 -8
- package/lib/PublishParser/PublishParser.ts +43 -27
- package/lib/PublishParser/getSchemaFromPublish.ts +21 -21
- package/lib/PublishParser/getTableRulesWithoutFileTable.ts +5 -6
- package/lib/initProstgles.ts +18 -0
- package/lib/runClientRequest.ts +4 -3
- package/package.json +2 -2
|
@@ -20,7 +20,7 @@ const SUBSCRIBE_METHODS = ["subscribe", "subscribeOne", "sync", "unsubscribe", "
|
|
|
20
20
|
export async function getSchemaFromPublish(
|
|
21
21
|
this: PublishParser,
|
|
22
22
|
{ userData, ...clientReq }: Args,
|
|
23
|
-
scope: PermissionScope | undefined
|
|
23
|
+
scope: PermissionScope | undefined,
|
|
24
24
|
): Promise<{
|
|
25
25
|
schema: TableSchemaForClient;
|
|
26
26
|
tables: DBSchemaTable[];
|
|
@@ -60,7 +60,7 @@ export async function getSchemaFromPublish(
|
|
|
60
60
|
!tableNames.includes(fileTableName)
|
|
61
61
|
) {
|
|
62
62
|
const isReferenced = this.prostgles.dboBuilder.tablesOrViews?.some((t) =>
|
|
63
|
-
t.columns.some((c) => c.references?.some((r) => r.ftable === fileTableName))
|
|
63
|
+
t.columns.some((c) => c.references?.some((r) => r.ftable === fileTableName)),
|
|
64
64
|
);
|
|
65
65
|
if (isReferenced) {
|
|
66
66
|
tableNames.unshift(fileTableName);
|
|
@@ -77,17 +77,17 @@ export async function getSchemaFromPublish(
|
|
|
77
77
|
throw errMsg;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
const
|
|
80
|
+
const parsedTableRule = await this.getTableRules({ clientReq, tableName }, clientInfo);
|
|
81
81
|
|
|
82
|
-
if (!
|
|
83
|
-
if (!isObject(
|
|
82
|
+
if (!parsedTableRule || isEmpty(parsedTableRule)) return;
|
|
83
|
+
if (!isObject(parsedTableRule)) {
|
|
84
84
|
throw `Invalid tableRules for table ${tableName}. Expecting an object`;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
schema[tableName] = {};
|
|
88
88
|
const tableSchema = schema[tableName];
|
|
89
|
-
const methods = getKeys(
|
|
90
|
-
(m) => canSubscribe || !includes(SUBSCRIBE_METHODS, m)
|
|
89
|
+
const methods = getKeys(parsedTableRule).filter(
|
|
90
|
+
(m) => canSubscribe || !includes(SUBSCRIBE_METHODS, m),
|
|
91
91
|
);
|
|
92
92
|
let tableInfo: TableInfo | undefined;
|
|
93
93
|
let tableColumns: DBSchemaTable["columns"] | undefined;
|
|
@@ -98,25 +98,25 @@ export async function getSchemaFromPublish(
|
|
|
98
98
|
.map(async (method) => {
|
|
99
99
|
if (method === "sync") {
|
|
100
100
|
/* Pass sync info */
|
|
101
|
-
tableSchema[method] =
|
|
102
|
-
} else if (includes(getKeys(
|
|
101
|
+
tableSchema[method] = parsedTableRule[method];
|
|
102
|
+
} else if (includes(getKeys(parsedTableRule), method) && parsedTableRule[method]) {
|
|
103
103
|
//@ts-ignore
|
|
104
104
|
tableSchema[method] =
|
|
105
105
|
method === "insert" ?
|
|
106
|
-
pickKeys(
|
|
106
|
+
pickKeys(parsedTableRule[method], ["allowedNestedInserts"])
|
|
107
107
|
: ({} as AnyObject);
|
|
108
108
|
|
|
109
109
|
/* Test for issues with the common table CRUD methods () */
|
|
110
110
|
if (includes(TABLE_METHODS, method)) {
|
|
111
111
|
try {
|
|
112
|
-
|
|
112
|
+
this.validateRequestRule(
|
|
113
113
|
{
|
|
114
114
|
tableName,
|
|
115
115
|
command: method,
|
|
116
116
|
clientReq,
|
|
117
117
|
},
|
|
118
|
-
|
|
119
|
-
scope
|
|
118
|
+
parsedTableRule,
|
|
119
|
+
scope,
|
|
120
120
|
);
|
|
121
121
|
if (this.prostgles.opts.testRulesOnConnect) {
|
|
122
122
|
await (this.dbo[tableName] as TableHandler)[method](
|
|
@@ -128,7 +128,7 @@ export async function getSchemaFromPublish(
|
|
|
128
128
|
...clientReq,
|
|
129
129
|
isRemoteRequest: {},
|
|
130
130
|
testRule: true,
|
|
131
|
-
}
|
|
131
|
+
},
|
|
132
132
|
);
|
|
133
133
|
}
|
|
134
134
|
} catch (e) {
|
|
@@ -146,17 +146,17 @@ export async function getSchemaFromPublish(
|
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
if (method === "getInfo" || method === "getColumns") {
|
|
149
|
-
|
|
149
|
+
this.validateRequestRule(
|
|
150
150
|
{ tableName, command: method, clientReq },
|
|
151
|
-
|
|
152
|
-
scope
|
|
151
|
+
parsedTableRule,
|
|
152
|
+
scope,
|
|
153
153
|
);
|
|
154
154
|
const res = await (this.dbo[tableName] as TableHandler)[method](
|
|
155
155
|
undefined,
|
|
156
156
|
undefined,
|
|
157
157
|
undefined,
|
|
158
|
-
|
|
159
|
-
{ ...clientReq, isRemoteRequest: {} }
|
|
158
|
+
parsedTableRule,
|
|
159
|
+
{ ...clientReq, isRemoteRequest: {} },
|
|
160
160
|
);
|
|
161
161
|
if (method === "getInfo") {
|
|
162
162
|
tableInfo = res as TableInfo;
|
|
@@ -165,7 +165,7 @@ export async function getSchemaFromPublish(
|
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
|
-
})
|
|
168
|
+
}),
|
|
169
169
|
);
|
|
170
170
|
|
|
171
171
|
if (tableInfo && tableColumns) {
|
|
@@ -175,7 +175,7 @@ export async function getSchemaFromPublish(
|
|
|
175
175
|
columns: tableColumns,
|
|
176
176
|
});
|
|
177
177
|
}
|
|
178
|
-
})
|
|
178
|
+
}),
|
|
179
179
|
);
|
|
180
180
|
}
|
|
181
181
|
} catch (error) {
|
|
@@ -9,7 +9,6 @@ import type {
|
|
|
9
9
|
ParsedPublishTable,
|
|
10
10
|
PublishTableRule,
|
|
11
11
|
PublishViewRule,
|
|
12
|
-
SubscribeRule,
|
|
13
12
|
} from "./publishTypesAndUtils";
|
|
14
13
|
import { type PublishObject, RULE_TO_METHODS } from "./publishTypesAndUtils";
|
|
15
14
|
|
|
@@ -17,7 +16,7 @@ export async function getTableRulesWithoutFileTable(
|
|
|
17
16
|
this: PublishParser,
|
|
18
17
|
{ tableName, clientReq }: DboTable,
|
|
19
18
|
clientInfo: AuthResultWithSID | undefined,
|
|
20
|
-
overridenPublish?: PublishObject
|
|
19
|
+
overridenPublish?: PublishObject,
|
|
21
20
|
): Promise<ParsedPublishTable | undefined> {
|
|
22
21
|
if (!tableName) throw new Error("tableName is missing in getTableRules");
|
|
23
22
|
|
|
@@ -111,7 +110,7 @@ export async function getTableRulesWithoutFileTable(
|
|
|
111
110
|
const rule = parsedTableRule[method];
|
|
112
111
|
|
|
113
112
|
const ruleInfo = MY_RULES.find(
|
|
114
|
-
(r) => r.rule === method || (r.methods as readonly string[]).includes(method)
|
|
113
|
+
(r) => r.rule === method || (r.methods as readonly string[]).includes(method),
|
|
115
114
|
);
|
|
116
115
|
if (!ruleInfo) {
|
|
117
116
|
let extraInfo = "";
|
|
@@ -120,7 +119,7 @@ export async function getTableRulesWithoutFileTable(
|
|
|
120
119
|
RULE_TO_METHODS.find(
|
|
121
120
|
(r) =>
|
|
122
121
|
r.table_only &&
|
|
123
|
-
(r.rule === method || (r.methods as readonly string[]).includes(method))
|
|
122
|
+
(r.rule === method || (r.methods as readonly string[]).includes(method)),
|
|
124
123
|
)
|
|
125
124
|
) {
|
|
126
125
|
extraInfo = "You've specified table rules to a view\n";
|
|
@@ -159,8 +158,8 @@ export async function getTableRulesWithoutFileTable(
|
|
|
159
158
|
if (method === "select" && !dissallowedRuleKeys.includes(subKey)) {
|
|
160
159
|
const sr = MY_RULES.find((r) => r.rule === subKey);
|
|
161
160
|
if (sr && canSubscribe) {
|
|
162
|
-
parsedTableRule[subKey] = { ...
|
|
163
|
-
parsedTableRule.subscribeOne = { ...
|
|
161
|
+
parsedTableRule[subKey] = { ...sr.no_limits };
|
|
162
|
+
parsedTableRule.subscribeOne = { ...sr.no_limits };
|
|
164
163
|
}
|
|
165
164
|
}
|
|
166
165
|
});
|
package/lib/initProstgles.ts
CHANGED
|
@@ -155,6 +155,24 @@ export const initProstgles = async function (
|
|
|
155
155
|
}
|
|
156
156
|
},
|
|
157
157
|
});
|
|
158
|
+
|
|
159
|
+
/** Drop stale triggers */
|
|
160
|
+
await db
|
|
161
|
+
.any(
|
|
162
|
+
`
|
|
163
|
+
WITH active_app_ids AS (
|
|
164
|
+
SELECT DISTINCT (string_to_array(application_name, ' '))[2] AS app_id
|
|
165
|
+
FROM pg_stat_activity
|
|
166
|
+
WHERE application_name LIKE 'prostgles %'
|
|
167
|
+
)
|
|
168
|
+
DELETE FROM prostgles.app_triggers
|
|
169
|
+
WHERE app_id NOT IN (SELECT app_id FROM active_app_ids)
|
|
170
|
+
AND app_id != $1
|
|
171
|
+
`,
|
|
172
|
+
[this.appId],
|
|
173
|
+
)
|
|
174
|
+
.catch(() => {});
|
|
175
|
+
|
|
158
176
|
this.db = db;
|
|
159
177
|
this.pgp = pgp;
|
|
160
178
|
this.isSuperUser = await getIsSuperUser(db);
|
package/lib/runClientRequest.ts
CHANGED
|
@@ -101,11 +101,12 @@ export const runClientRequest = async function (
|
|
|
101
101
|
if (clientInfo === "new-session-redirect") {
|
|
102
102
|
throw clientInfo;
|
|
103
103
|
}
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
|
|
105
|
+
const parsedTableRule = await this.publishParser.getParsedTableRule(
|
|
106
|
+
{ tableName, clientReq },
|
|
106
107
|
clientInfo,
|
|
107
|
-
scope,
|
|
108
108
|
);
|
|
109
|
+
this.publishParser.validateRequestRule({ tableName, command, clientReq }, parsedTableRule, scope);
|
|
109
110
|
|
|
110
111
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
111
112
|
if (!parsedTableRule) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prostgles-server",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.442",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"pg": "^8.15.6",
|
|
58
58
|
"pg-cursor": "^2.17.0",
|
|
59
59
|
"pg-promise": "^12.6.0",
|
|
60
|
-
"prostgles-types": "^4.0.
|
|
60
|
+
"prostgles-types": "^4.0.209"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@eslint/js": "^9.22.0",
|