prostgles-server 4.2.346 → 4.2.348
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/Auth/endpoints/setOAuthRequestHandlers.d.ts.map +1 -1
- package/dist/Auth/endpoints/setOAuthRequestHandlers.js +3 -1
- package/dist/Auth/endpoints/setOAuthRequestHandlers.js.map +1 -1
- package/dist/DboBuilder/DboBuilder.d.ts +2 -0
- package/dist/DboBuilder/DboBuilder.d.ts.map +1 -1
- package/dist/DboBuilder/DboBuilder.js +5 -1
- package/dist/DboBuilder/DboBuilder.js.map +1 -1
- package/dist/DboBuilder/QueryStreamer.d.ts.map +1 -1
- package/dist/DboBuilder/QueryStreamer.js +1 -1
- package/dist/DboBuilder/QueryStreamer.js.map +1 -1
- package/dist/DboBuilder/dboBuilderUtils.d.ts +1 -1
- package/dist/DboBuilder/dboBuilderUtils.d.ts.map +1 -1
- package/dist/DboBuilder/dboBuilderUtils.js +5 -27
- package/dist/DboBuilder/dboBuilderUtils.js.map +1 -1
- package/dist/DboBuilder/runSQL.d.ts +1 -1
- package/dist/Prostgles.d.ts.map +1 -1
- package/dist/Prostgles.js +4 -2
- package/dist/Prostgles.js.map +1 -1
- package/dist/ProstglesTypes.d.ts +2 -2
- package/dist/ProstglesTypes.d.ts.map +1 -1
- package/dist/ProstglesTypes.js.map +1 -1
- package/dist/PublishParser/PublishParser.d.ts +1 -3
- package/dist/PublishParser/PublishParser.d.ts.map +1 -1
- package/dist/PublishParser/PublishParser.js +6 -3
- package/dist/PublishParser/PublishParser.js.map +1 -1
- package/dist/PublishParser/getTableRulesWithoutFileTable.d.ts.map +1 -1
- package/dist/PublishParser/getTableRulesWithoutFileTable.js +1 -1
- package/dist/PublishParser/getTableRulesWithoutFileTable.js.map +1 -1
- package/dist/TableConfig/fetchTableConstraints.d.ts +19 -0
- package/dist/TableConfig/fetchTableConstraints.d.ts.map +1 -0
- package/dist/TableConfig/fetchTableConstraints.js +38 -0
- package/dist/TableConfig/fetchTableConstraints.js.map +1 -0
- package/dist/TableConfig/getConstraintDefinitionQueries.d.ts +0 -18
- package/dist/TableConfig/getConstraintDefinitionQueries.d.ts.map +1 -1
- package/dist/TableConfig/getConstraintDefinitionQueries.js +1 -36
- package/dist/TableConfig/getConstraintDefinitionQueries.js.map +1 -1
- package/dist/TableConfig/getCreateSchemaQueries.js +2 -2
- package/dist/TableConfig/getCreateSchemaQueries.js.map +1 -1
- package/dist/TableConfig/getFutureTableSchema.d.ts +3 -2
- package/dist/TableConfig/getFutureTableSchema.d.ts.map +1 -1
- package/dist/TableConfig/getFutureTableSchema.js +2 -2
- package/dist/TableConfig/getFutureTableSchema.js.map +1 -1
- package/dist/TableConfig/getTableConfigSchemaQueries.d.ts +1 -1
- package/dist/TableConfig/getTableConfigSchemaQueries.d.ts.map +1 -1
- package/dist/TableConfig/initTableConfig.d.ts.map +1 -1
- package/dist/TableConfig/initTableConfig.js +5 -5
- package/dist/TableConfig/initTableConfig.js.map +1 -1
- package/dist/TableConfig/runMigrations.js +2 -2
- package/dist/TableConfig/runMigrations.js.map +1 -1
- package/dist/TableConfig/tableConfigSchemaUtils.d.ts.map +1 -1
- package/dist/TableConfig/tableConfigSchemaUtils.js +2 -2
- package/dist/TableConfig/tableConfigSchemaUtils.js.map +1 -1
- package/dist/WebsocketAPI/getClientSchema.js +1 -1
- package/dist/WebsocketAPI/getClientSchema.js.map +1 -1
- package/dist/WebsocketAPI/onSocketConnected.d.ts.map +1 -1
- package/dist/WebsocketAPI/onSocketConnected.js +2 -2
- package/dist/WebsocketAPI/onSocketConnected.js.map +1 -1
- package/dist/initProstgles.js +0 -3
- package/dist/initProstgles.js.map +1 -1
- package/dist/runClientRequest.d.ts +9 -9
- package/dist/runClientRequest.d.ts.map +1 -1
- package/dist/runClientRequest.js +34 -8
- package/dist/runClientRequest.js.map +1 -1
- package/dist/shortestPath.js +1 -1
- package/dist/shortestPath.js.map +1 -1
- package/lib/Auth/endpoints/setOAuthRequestHandlers.ts +5 -2
- package/lib/DboBuilder/DboBuilder.ts +6 -1
- package/lib/DboBuilder/QueryStreamer.ts +3 -10
- package/lib/DboBuilder/dboBuilderUtils.ts +6 -32
- package/lib/Prostgles.ts +8 -3
- package/lib/ProstglesTypes.ts +5 -6
- package/lib/PublishParser/PublishParser.ts +10 -9
- package/lib/PublishParser/getTableRulesWithoutFileTable.ts +3 -5
- package/lib/TableConfig/fetchTableConstraints.ts +53 -0
- package/lib/TableConfig/getConstraintDefinitionQueries.ts +0 -56
- package/lib/TableConfig/getCreateSchemaQueries.ts +2 -2
- package/lib/TableConfig/getFutureTableSchema.ts +5 -5
- package/lib/TableConfig/initTableConfig.ts +8 -9
- package/lib/TableConfig/runMigrations.ts +2 -2
- package/lib/TableConfig/tableConfigSchemaUtils.ts +2 -3
- package/lib/WebsocketAPI/getClientSchema.ts +1 -1
- package/lib/WebsocketAPI/onSocketConnected.ts +4 -3
- package/lib/initProstgles.ts +0 -4
- package/lib/runClientRequest.ts +57 -19
- package/lib/shortestPath.ts +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runClientRequest.d.ts","sourceRoot":"","sources":["../lib/runClientRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"runClientRequest.d.ts","sourceRoot":"","sources":["../lib/runClientRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA0B,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAIL,KAAK,SAAS,EACf,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAK1D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,sCAAsC,CAAC;AA0B5E,KAAK,IAAI,GAAG;IACV,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAUF,eAAO,MAAM,gBAAgB,SACrB,SAAS,oBACG,IAAI,aACX,iBAAiB,SACrB,eAAe,GAAG,SAAS,mCA0FnC,CAAC;AAEF,eAAO,MAAM,sBAAsB,SAC3B,SAAS,aACJ,iBAAiB;;;;;;;;EAgB7B,CAAC;AAEF,eAAO,MAAM,mBAAmB,SACxB,SAAS,mBACE,UAAU,aAChB,iBAAiB,iBAsB7B,CAAC;AAEF,KAAK,UAAU,GAAG;IAChB,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC;CAChB,CAAC;AACF,eAAO,MAAM,eAAe,SACpB,SAAS,mBACE,UAAU,aAChB,iBAAiB,iBA+B7B,CAAC"}
|
package/dist/runClientRequest.js
CHANGED
|
@@ -26,20 +26,29 @@ const SOCKET_ONLY_COMMANDS = [
|
|
|
26
26
|
"subscribeOne",
|
|
27
27
|
"sync",
|
|
28
28
|
];
|
|
29
|
-
const runClientRequest = async function (
|
|
29
|
+
const runClientRequest = async function (nonValidatedArgs, clientReq, scope) {
|
|
30
30
|
/* Channel name will only include client-sent params so we ignore table_rules enforced params */
|
|
31
31
|
if (!this.publishParser || !this.dbo) {
|
|
32
32
|
throw "socket/httpReq or authhandler missing";
|
|
33
33
|
}
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
const validation = (0, prostgles_types_1.getJSONBObjectSchemaValidationError)({
|
|
35
|
+
tableName: { type: "string" },
|
|
36
|
+
command: { enum: TABLE_METHODS_KEYS },
|
|
37
|
+
param1: { type: "any", optional: true },
|
|
38
|
+
param2: { type: "any", optional: true },
|
|
39
|
+
param3: { type: "any", optional: true },
|
|
40
|
+
}, nonValidatedArgs, "tableName");
|
|
41
|
+
if (validation.error !== undefined) {
|
|
42
|
+
throw validation.error;
|
|
37
43
|
}
|
|
38
|
-
const command =
|
|
44
|
+
const { tableName, command, param1, param2, param3 } = validation.data;
|
|
39
45
|
if (!clientReq.socket && SOCKET_ONLY_COMMANDS.some((v) => v === command)) {
|
|
40
46
|
throw ("The following commands cannot be completed over a non-websocket connection: " +
|
|
41
47
|
SOCKET_ONLY_COMMANDS.join(", "));
|
|
42
48
|
}
|
|
49
|
+
if (!this.dboBuilder.dboMap.has(tableName)) {
|
|
50
|
+
throw `tableName ${tableName} is invalid or not allowed`;
|
|
51
|
+
}
|
|
43
52
|
const clientInfo = await this.authHandler?.getSidAndUserFromRequest(clientReq);
|
|
44
53
|
if (clientInfo === "new-session-redirect") {
|
|
45
54
|
throw clientInfo;
|
|
@@ -98,21 +107,38 @@ const clientCanRunSqlRequest = async function (clientReq) {
|
|
|
98
107
|
return { allowed, reqInfo: clientReq };
|
|
99
108
|
};
|
|
100
109
|
exports.clientCanRunSqlRequest = clientCanRunSqlRequest;
|
|
101
|
-
const runClientSqlRequest = async function (
|
|
110
|
+
const runClientSqlRequest = async function (unvalidatedArgs, clientReq) {
|
|
102
111
|
const { allowed } = await exports.clientCanRunSqlRequest.bind(this)(clientReq);
|
|
103
112
|
if (!allowed) {
|
|
104
113
|
throw "Not allowed to execute sql";
|
|
105
114
|
}
|
|
106
115
|
if (!this.dbo?.sql)
|
|
107
116
|
throw "Internal error: sql handler missing";
|
|
117
|
+
const validation = (0, prostgles_types_1.getJSONBObjectSchemaValidationError)({
|
|
118
|
+
query: { type: "string" },
|
|
119
|
+
params: { type: "any", optional: true },
|
|
120
|
+
options: { type: "any", optional: true },
|
|
121
|
+
}, unvalidatedArgs, "query");
|
|
122
|
+
if (validation.error !== undefined) {
|
|
123
|
+
throw validation.error;
|
|
124
|
+
}
|
|
125
|
+
const reqData = validation.data;
|
|
108
126
|
const { query, params, options } = reqData;
|
|
109
127
|
return this.dbo.sql(query, params, options, { clientReq });
|
|
110
128
|
};
|
|
111
129
|
exports.runClientSqlRequest = runClientSqlRequest;
|
|
112
|
-
const runClientMethod = async function (
|
|
130
|
+
const runClientMethod = async function (unvalidatedArgs, clientReq) {
|
|
131
|
+
const validation = (0, prostgles_types_1.getJSONBObjectSchemaValidationError)({
|
|
132
|
+
method: { type: "string" },
|
|
133
|
+
params: { type: "any[]", optional: true },
|
|
134
|
+
}, unvalidatedArgs, "method");
|
|
135
|
+
if (validation.error !== undefined) {
|
|
136
|
+
throw validation.error;
|
|
137
|
+
}
|
|
138
|
+
const reqArgs = validation.data;
|
|
113
139
|
const { method, params = [] } = reqArgs;
|
|
114
140
|
const methods = await this.publishParser?.getAllowedMethods(clientReq, undefined);
|
|
115
|
-
const methodDef = methods?.
|
|
141
|
+
const methodDef = methods?.get(method);
|
|
116
142
|
if (!methods || !methodDef) {
|
|
117
143
|
throw "Disallowed/missing method " + JSON.stringify(method);
|
|
118
144
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runClientRequest.js","sourceRoot":"","sources":["../lib/runClientRequest.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"runClientRequest.js","sourceRoot":"","sources":["../lib/runClientRequest.ts"],"names":[],"mappings":";;;AACA,qDAKyB;AAIzB,gFAA6E;AAC7E,gDAAgD;AAKhD,MAAM,aAAa,GAAG;IACpB,IAAI,EAAE,CAAC;IACP,OAAO,EAAE,CAAC;IACV,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,MAAM,EAAE,CAAC;IACT,WAAW,EAAE,CAAC;IACd,MAAM,EAAE,CAAC;IACT,MAAM,EAAE,CAAC;IACT,MAAM,EAAE,CAAC;IACT,SAAS,EAAE,CAAC;IACZ,YAAY,EAAE,CAAC;IACf,UAAU,EAAE,CAAC;IACb,OAAO,EAAE,CAAC;IACV,IAAI,EAAE,CAAC;CAC8E,CAAC;AAExF,MAAM,kBAAkB,GAAG,IAAA,yBAAO,EAAC,aAAa,CAAC,CAAC;AAClD,MAAM,oBAAoB,GAAG;IAC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EACf,QAAQ,CACT,CAAC;IACF,IAAI,UAAU,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QACnC,MAAM,UAAU,CAAC,KAAK,CAAC;IACzB,CAAC;IACD,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,CAAC;IAChC,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC;IACxC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,iBAAiB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAElF,MAAM,SAAS,GAAG,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACvC,IAAI,CAAC,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC;QAC3B,MAAM,4BAA4B,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAC9D,CAAC;IAED,MAAM,KAAK,GACT,CACE,OAAO,SAAS,KAAK,UAAU;QAC/B,OAAQ,SAAsC,CAAC,IAAI,KAAK,UAAU,CACnE,CAAC,CAAC;QACA,SAA6C;QAChD,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC;IAClB,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,MAAM,CAAC,CAAC;IACnC,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAlCW,QAAA,eAAe,mBAkC1B"}
|
package/dist/shortestPath.js
CHANGED
|
@@ -15,7 +15,7 @@ const findShortestPath = (graph, startNode, endNode) => {
|
|
|
15
15
|
// establish object for recording distances from the start node
|
|
16
16
|
let distances = {};
|
|
17
17
|
distances[endNode] = "Infinity";
|
|
18
|
-
distances =
|
|
18
|
+
distances = { ...distances, ...graph[startNode] };
|
|
19
19
|
// track paths
|
|
20
20
|
const parents = { endNode: null };
|
|
21
21
|
for (const child in graph[startNode]) {
|
package/dist/shortestPath.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shortestPath.js","sourceRoot":"","sources":["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B,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;gBACxB,CAAC;YACH,CAAC;QACH,CAAC;QACD,mCAAmC;QACnC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnB,oCAAoC;QACpC,IAAI,GAAG,oBAAoB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC;IAED,qDAAqD;IACrD,2BAA2B;IAC3B,MAAM,YAAY,GAAG,CAAC,OAAO,CAAC,CAAC;IAC/B,IAAI,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9B,OAAO,MAAM,EAAE,CAAC;QACd,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC1B,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC3B,CAAC;IACD,YAAY,CAAC,OAAO,EAAE,CAAC;IAEvB,sEAAsE;IACtE,MAAM,OAAO,GAAG;QACd,QAAQ,EAAE,SAAS,CAAC,OAAO,CAAC;QAC5B,IAAI,EAAE,YAAY;KACnB,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AApEW,QAAA,gBAAgB,oBAoE3B;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqCE"}
|
|
@@ -7,7 +7,7 @@ import { Strategy as MicrosoftStrategy } from "passport-microsoft";
|
|
|
7
7
|
import { getObjectEntries, isEmpty } from "prostgles-types";
|
|
8
8
|
import { getErrorAsObject } from "../../DboBuilder/dboBuilderUtils";
|
|
9
9
|
import type { DBOFullyTyped } from "../../DBSchemaBuilder/DBSchemaBuilder";
|
|
10
|
-
import type { AuthHandler} from "../AuthHandler";
|
|
10
|
+
import type { AuthHandler } from "../AuthHandler";
|
|
11
11
|
import { AUTH_ROUTES_AND_PARAMS, HTTP_FAIL_CODES } from "../AuthHandler";
|
|
12
12
|
import type { AuthProviderUserData, LoginWithOAuthConfig } from "../AuthTypes";
|
|
13
13
|
import { getClientRequestIPsInfo } from "../utils/getClientRequestIPsInfo";
|
|
@@ -89,7 +89,10 @@ export function setOAuthRequestHandlers(
|
|
|
89
89
|
type: "OAuth",
|
|
90
90
|
provider: providerName as "customOAuth",
|
|
91
91
|
}).catch((e: any) => {
|
|
92
|
-
res.status(HTTP_FAIL_CODES.INTERNAL_SERVER_ERROR).json(
|
|
92
|
+
res.status(HTTP_FAIL_CODES.INTERNAL_SERVER_ERROR).json(
|
|
93
|
+
//@ts-ignore
|
|
94
|
+
getErrorAsObject(e)
|
|
95
|
+
);
|
|
93
96
|
});
|
|
94
97
|
}
|
|
95
98
|
}
|
|
@@ -78,6 +78,8 @@ export class DboBuilder {
|
|
|
78
78
|
|
|
79
79
|
dbo: DBHandlerServer;
|
|
80
80
|
|
|
81
|
+
dboMap: Map<string, TableHandler | ViewHandler> = new Map();
|
|
82
|
+
|
|
81
83
|
/**
|
|
82
84
|
* Undefined if cannot create table triggers
|
|
83
85
|
*/
|
|
@@ -151,6 +153,7 @@ export class DboBuilder {
|
|
|
151
153
|
if (!this.prostgles.db) throw "db missing";
|
|
152
154
|
this.db = this.prostgles.db;
|
|
153
155
|
this.dbo = {} as unknown as DBHandlerServer;
|
|
156
|
+
this.dboMap = new Map();
|
|
154
157
|
this.queryStreamer = new QueryStreamer(this);
|
|
155
158
|
}
|
|
156
159
|
|
|
@@ -259,13 +262,15 @@ export class DboBuilder {
|
|
|
259
262
|
Alternatively you can rename the table column\n`;
|
|
260
263
|
}
|
|
261
264
|
|
|
262
|
-
|
|
265
|
+
const tableHandler = new (tov.is_view ? ViewHandler : TableHandler)(
|
|
263
266
|
this.db,
|
|
264
267
|
tov,
|
|
265
268
|
this,
|
|
266
269
|
undefined,
|
|
267
270
|
this.shortestJoinPaths
|
|
268
271
|
);
|
|
272
|
+
this.dbo[tov.escaped_identifier] = tableHandler;
|
|
273
|
+
this.dboMap.set(tov.name, tableHandler);
|
|
269
274
|
|
|
270
275
|
if (this.shortestJoinPaths.find((jp) => [jp.t1, jp.t2].includes(tov.name))) {
|
|
271
276
|
const table = tov.name;
|
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import * as pg from "pg";
|
|
2
2
|
import type CursorType from "pg-cursor";
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
SocketSQLStreamPacket,
|
|
6
|
-
SocketSQLStreamServer} from "prostgles-types";
|
|
7
|
-
import {
|
|
8
|
-
CHANNELS,
|
|
9
|
-
omitKeys,
|
|
10
|
-
pickKeys,
|
|
11
|
-
} from "prostgles-types";
|
|
3
|
+
import type { SQLOptions, SocketSQLStreamPacket, SocketSQLStreamServer } from "prostgles-types";
|
|
4
|
+
import { CHANNELS, omitKeys, pickKeys } from "prostgles-types";
|
|
12
5
|
import type { BasicCallback } from "../PubSubManager/PubSubManager";
|
|
13
6
|
import type { VoidFunction } from "../SchemaWatch/SchemaWatch";
|
|
14
7
|
import type { DB } from "../initProstgles";
|
|
@@ -307,7 +300,7 @@ export class QueryStreamer {
|
|
|
307
300
|
cb(processID);
|
|
308
301
|
} catch (err) {
|
|
309
302
|
console.error(err);
|
|
310
|
-
cb(processID, getErrorAsObject(err)
|
|
303
|
+
cb(processID, getErrorAsObject(err));
|
|
311
304
|
}
|
|
312
305
|
runCount++;
|
|
313
306
|
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import type { AnyObject, ProstglesError } from "prostgles-types";
|
|
7
7
|
import { asNameAlias } from "../utils/asNameAlias";
|
|
8
|
-
import { isObject, omitKeys, pickKeys } from "prostgles-types";
|
|
8
|
+
import { getSerialisableError, isObject, omitKeys, pickKeys } from "prostgles-types";
|
|
9
9
|
import type { DB } from "../Prostgles";
|
|
10
10
|
import type { LocalParams, SortItem } from "./DboBuilderTypes";
|
|
11
11
|
import { pgp } from "./DboBuilderTypes";
|
|
@@ -16,38 +16,12 @@ import type { ProstglesInitOptions } from "../ProstglesTypes";
|
|
|
16
16
|
import { sqlErrCodeToMsg } from "./sqlErrCodeToMsg";
|
|
17
17
|
import type { TableHandler } from "./TableHandler/TableHandler";
|
|
18
18
|
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (seen.has(value)) {
|
|
24
|
-
return "[Circular]";
|
|
25
|
-
}
|
|
26
|
-
seen.add(value);
|
|
27
|
-
}
|
|
28
|
-
return value;
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
export const getErrorAsObject = (rawError: any, includeStack = false) => {
|
|
32
|
-
if (["string", "boolean", "number"].includes(typeof rawError)) {
|
|
33
|
-
return { message: rawError };
|
|
19
|
+
export const getErrorAsObject = (rawError: any) => {
|
|
20
|
+
const serializedError = getSerialisableError(rawError);
|
|
21
|
+
if (isObject(serializedError) && !Array.isArray(serializedError)) {
|
|
22
|
+
return omitKeys(serializedError, ["stack"]);
|
|
34
23
|
}
|
|
35
|
-
|
|
36
|
-
const errorObj = Object.getOwnPropertyNames(rawError).reduce(
|
|
37
|
-
(acc, key) => ({
|
|
38
|
-
...acc,
|
|
39
|
-
[key]: (rawError as AnyObject)[key],
|
|
40
|
-
}),
|
|
41
|
-
{} as AnyObject
|
|
42
|
-
);
|
|
43
|
-
const result = JSON.parse(safeStringify(errorObj));
|
|
44
|
-
if (!includeStack) {
|
|
45
|
-
return omitKeys(result, ["stack"]);
|
|
46
|
-
}
|
|
47
|
-
return result;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return rawError;
|
|
24
|
+
return { message: serializedError };
|
|
51
25
|
};
|
|
52
26
|
|
|
53
27
|
const circularError = new Error("Circular error data");
|
package/lib/Prostgles.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import type * as pgPromise from "pg-promise";
|
|
7
7
|
import { AuthHandler } from "./Auth/AuthHandler";
|
|
8
8
|
import { FileManager } from "./FileManager/FileManager";
|
|
9
|
-
import type { OnInitReason} from "./initProstgles";
|
|
9
|
+
import type { OnInitReason } from "./initProstgles";
|
|
10
10
|
import { initProstgles } from "./initProstgles";
|
|
11
11
|
import type { SchemaWatch } from "./SchemaWatch/SchemaWatch";
|
|
12
12
|
import { getClientSchema } from "./WebsocketAPI/getClientSchema";
|
|
@@ -148,7 +148,7 @@ export class Prostgles {
|
|
|
148
148
|
console.error(`Unrecognised ProstglesInitOptions params: ${unknownParams.join()}`);
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
|
|
151
|
+
this.opts = { ...this.opts, ...params };
|
|
152
152
|
|
|
153
153
|
/* set defaults */
|
|
154
154
|
if (this.opts.fileTable) {
|
|
@@ -164,7 +164,12 @@ export class Prostgles {
|
|
|
164
164
|
destroyed = false;
|
|
165
165
|
|
|
166
166
|
checkDb() {
|
|
167
|
-
if (
|
|
167
|
+
if (
|
|
168
|
+
!this.db ||
|
|
169
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
170
|
+
!this.db.connect
|
|
171
|
+
)
|
|
172
|
+
throw "something went wrong getting a db connection";
|
|
168
173
|
}
|
|
169
174
|
|
|
170
175
|
getTSFileName() {
|
package/lib/ProstglesTypes.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { DbConnection, OnReadyCallback } from "./initProstgles";
|
|
|
6
6
|
import type { EventInfo } from "./Logging";
|
|
7
7
|
import type { ExpressApp, RestApiConfig } from "./RestApi";
|
|
8
8
|
import type { OnSchemaChangeCallback } from "./SchemaWatch/SchemaWatch";
|
|
9
|
-
import type {
|
|
9
|
+
import type { PGConstraint } from "./TableConfig/fetchTableConstraints";
|
|
10
10
|
import type { TableConfig } from "./TableConfig/TableConfig";
|
|
11
11
|
import type { Express } from "express";
|
|
12
12
|
|
|
@@ -20,10 +20,9 @@ import type {
|
|
|
20
20
|
Awaitable,
|
|
21
21
|
Publish,
|
|
22
22
|
PublishMethods,
|
|
23
|
-
PublishParams
|
|
24
|
-
import {
|
|
25
|
-
type PublishMethodsV2,
|
|
23
|
+
PublishParams,
|
|
26
24
|
} from "./PublishParser/PublishParser";
|
|
25
|
+
import { type PublishMethodsV2 } from "./PublishParser/PublishParser";
|
|
27
26
|
|
|
28
27
|
/**
|
|
29
28
|
* Allows uploading and downloading files.
|
|
@@ -345,6 +344,6 @@ type OnMigrate = (args: {
|
|
|
345
344
|
getConstraints: (
|
|
346
345
|
table: string,
|
|
347
346
|
column?: string,
|
|
348
|
-
types?:
|
|
349
|
-
) => Promise<
|
|
347
|
+
types?: PGConstraint["type"][]
|
|
348
|
+
) => Promise<PGConstraint[]>;
|
|
350
349
|
}) => void | Promise<void>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Method} from "prostgles-types";
|
|
1
|
+
import type { Method } from "prostgles-types";
|
|
2
2
|
import { getObjectEntries, isObject } from "prostgles-types";
|
|
3
3
|
import type { AuthClientRequest, AuthResultWithSID, SessionUser } from "../Auth/AuthTypes";
|
|
4
4
|
import type { DBOFullyTyped } from "../DBSchemaBuilder/DBSchemaBuilder";
|
|
@@ -14,7 +14,8 @@ import type {
|
|
|
14
14
|
DboTableCommand,
|
|
15
15
|
ParsedTableRule,
|
|
16
16
|
PublishMethods,
|
|
17
|
-
PublishParams
|
|
17
|
+
PublishParams,
|
|
18
|
+
} from "./publishTypesAndUtils";
|
|
18
19
|
import {
|
|
19
20
|
RULE_TO_METHODS,
|
|
20
21
|
parsePublishTableRule,
|
|
@@ -72,18 +73,15 @@ export class PublishParser {
|
|
|
72
73
|
return getV2Methods(publishMethods);
|
|
73
74
|
}
|
|
74
75
|
|
|
75
|
-
async getAllowedMethods(
|
|
76
|
-
|
|
77
|
-
userData: AuthResultWithSID | undefined
|
|
78
|
-
): Promise<{ [key: string]: Method }> {
|
|
79
|
-
const methods: { [key: string]: Method } = {};
|
|
76
|
+
async getAllowedMethods(clientReq: AuthClientRequest, userData: AuthResultWithSID | undefined) {
|
|
77
|
+
const methods: Map<string, Method> = new Map();
|
|
80
78
|
|
|
81
79
|
const publishParams = await this.getPublishParams(clientReq, userData);
|
|
82
80
|
const v2Methods = this.publishMethodsV2;
|
|
83
81
|
if (v2Methods) {
|
|
84
82
|
for (const [name, method] of Object.entries(v2Methods)) {
|
|
85
83
|
if (await method.isAllowed(publishParams)) {
|
|
86
|
-
methods
|
|
84
|
+
methods.set(name, method);
|
|
87
85
|
}
|
|
88
86
|
}
|
|
89
87
|
return methods;
|
|
@@ -92,6 +90,9 @@ export class PublishParser {
|
|
|
92
90
|
const _methods = await applyParamsIfFunc(this.publishMethods, publishParams);
|
|
93
91
|
if (!_methods) return methods;
|
|
94
92
|
getObjectEntries(_methods).map(([key, method]) => {
|
|
93
|
+
if (typeof key !== "string") {
|
|
94
|
+
throw `invalid publishMethods key -> ${String(key)} \n Expecting a string`;
|
|
95
|
+
}
|
|
95
96
|
const isFuncLike = (maybeFunc: VoidFunction | Promise<void> | Promise<any>) =>
|
|
96
97
|
typeof maybeFunc === "function" || typeof maybeFunc.then === "function";
|
|
97
98
|
if (
|
|
@@ -99,7 +100,7 @@ export class PublishParser {
|
|
|
99
100
|
// @ts-ignore
|
|
100
101
|
(isObject(method) && isFuncLike(method.run))
|
|
101
102
|
) {
|
|
102
|
-
methods
|
|
103
|
+
methods.set(key, method);
|
|
103
104
|
} else {
|
|
104
105
|
throw `invalid publishMethods item -> ${key} \n Expecting a function or promise`;
|
|
105
106
|
}
|
|
@@ -9,11 +9,9 @@ import type {
|
|
|
9
9
|
ParsedPublishTable,
|
|
10
10
|
PublishTableRule,
|
|
11
11
|
PublishViewRule,
|
|
12
|
-
SubscribeRule
|
|
13
|
-
import {
|
|
14
|
-
type PublishObject,
|
|
15
|
-
RULE_TO_METHODS
|
|
12
|
+
SubscribeRule,
|
|
16
13
|
} from "./publishTypesAndUtils";
|
|
14
|
+
import { type PublishObject, RULE_TO_METHODS } from "./publishTypesAndUtils";
|
|
17
15
|
|
|
18
16
|
export async function getTableRulesWithoutFileTable(
|
|
19
17
|
this: PublishParser,
|
|
@@ -21,7 +19,7 @@ export async function getTableRulesWithoutFileTable(
|
|
|
21
19
|
clientInfo: AuthResultWithSID | undefined,
|
|
22
20
|
overridenPublish?: PublishObject
|
|
23
21
|
): Promise<ParsedPublishTable | undefined> {
|
|
24
|
-
if (!tableName) throw new Error("
|
|
22
|
+
if (!tableName) throw new Error("tableName is missing in getTableRules");
|
|
25
23
|
|
|
26
24
|
const publish =
|
|
27
25
|
overridenPublish ?? (clientReq && (await this.getPublishAsObject(clientReq, clientInfo)));
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type pgPromise from "pg-promise";
|
|
2
|
+
import type { DB } from "../Prostgles";
|
|
3
|
+
import { asValue } from "../PubSubManager/PubSubManagerUtils";
|
|
4
|
+
|
|
5
|
+
export type PGConstraint = {
|
|
6
|
+
name: string;
|
|
7
|
+
table: string;
|
|
8
|
+
type: "c" | "p" | "u" | "f";
|
|
9
|
+
cols: Array<string>;
|
|
10
|
+
definition: string;
|
|
11
|
+
schema: string;
|
|
12
|
+
};
|
|
13
|
+
export const fetchTableConstraints = ({
|
|
14
|
+
db,
|
|
15
|
+
column,
|
|
16
|
+
table,
|
|
17
|
+
types,
|
|
18
|
+
}: ColConstraintsArgs): Promise<PGConstraint[]> => {
|
|
19
|
+
return db.manyOrNone(getColConstraintsQuery({ column, table, types }));
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
type ColConstraintsArgs = {
|
|
23
|
+
db: DB | pgPromise.ITask<{}>;
|
|
24
|
+
table?: string;
|
|
25
|
+
column?: string;
|
|
26
|
+
types?: PGConstraint["type"][];
|
|
27
|
+
};
|
|
28
|
+
const getColConstraintsQuery = ({ column, table, types }: Omit<ColConstraintsArgs, "db">) => {
|
|
29
|
+
let query = `
|
|
30
|
+
SELECT *
|
|
31
|
+
FROM (
|
|
32
|
+
SELECT distinct c.conname as name, c.contype as type,
|
|
33
|
+
pg_get_constraintdef(c.oid) as definition,
|
|
34
|
+
nsp.nspname as schema,
|
|
35
|
+
(SELECT r.relname from pg_class r where r.oid = c.conrelid) as "table",
|
|
36
|
+
(SELECT array_agg(attname::text) from pg_attribute
|
|
37
|
+
where attrelid = c.conrelid and ARRAY[attnum] <@ c.conkey) as cols
|
|
38
|
+
-- (SELECT array_agg(attname::text) from pg_attribute
|
|
39
|
+
-- where attrelid = c.confrelid and ARRAY[attnum] <@ c.confkey) as fcols,
|
|
40
|
+
-- (SELECT r.relname from pg_class r where r.oid = c.confrelid) as ftable
|
|
41
|
+
FROM pg_catalog.pg_constraint c
|
|
42
|
+
INNER JOIN pg_catalog.pg_class rel
|
|
43
|
+
ON rel.oid = c.conrelid
|
|
44
|
+
INNER JOIN pg_catalog.pg_namespace nsp
|
|
45
|
+
ON nsp.oid = connamespace
|
|
46
|
+
) t
|
|
47
|
+
WHERE TRUE
|
|
48
|
+
`;
|
|
49
|
+
if (table) query += `\nAND "table" = ${asValue(table)}`;
|
|
50
|
+
if (column) query += `\nAND cols @> ARRAY[${asValue(column)}]`;
|
|
51
|
+
if (types?.length) query += `\nAND type IN (${types.map((v) => asValue(v)).join(", ")})`;
|
|
52
|
+
return query;
|
|
53
|
+
};
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import type pgPromise from "pg-promise";
|
|
2
1
|
import { asName } from "prostgles-types";
|
|
3
|
-
import type { DB } from "../Prostgles";
|
|
4
|
-
import { asValue } from "../PubSubManager/PubSubManagerUtils";
|
|
5
2
|
import type { TableConfig } from "./TableConfig";
|
|
6
3
|
|
|
7
4
|
type Args = {
|
|
@@ -50,56 +47,3 @@ export const getConstraintDefinitionQueries = ({
|
|
|
50
47
|
}
|
|
51
48
|
}
|
|
52
49
|
};
|
|
53
|
-
|
|
54
|
-
export type ColConstraint = {
|
|
55
|
-
name: string;
|
|
56
|
-
table: string;
|
|
57
|
-
type: "c" | "p" | "u" | "f";
|
|
58
|
-
cols: Array<string>;
|
|
59
|
-
definition: string;
|
|
60
|
-
schema: string;
|
|
61
|
-
};
|
|
62
|
-
type ColConstraintsArgs = {
|
|
63
|
-
db: DB | pgPromise.ITask<{}>;
|
|
64
|
-
table?: string;
|
|
65
|
-
column?: string;
|
|
66
|
-
types?: ColConstraint["type"][];
|
|
67
|
-
};
|
|
68
|
-
export const getColConstraintsQuery = ({
|
|
69
|
-
column,
|
|
70
|
-
table,
|
|
71
|
-
types,
|
|
72
|
-
}: Omit<ColConstraintsArgs, "db">) => {
|
|
73
|
-
let query = `
|
|
74
|
-
SELECT *
|
|
75
|
-
FROM (
|
|
76
|
-
SELECT distinct c.conname as name, c.contype as type,
|
|
77
|
-
pg_get_constraintdef(c.oid) as definition,
|
|
78
|
-
nsp.nspname as schema,
|
|
79
|
-
(SELECT r.relname from pg_class r where r.oid = c.conrelid) as "table",
|
|
80
|
-
(SELECT array_agg(attname::text) from pg_attribute
|
|
81
|
-
where attrelid = c.conrelid and ARRAY[attnum] <@ c.conkey) as cols
|
|
82
|
-
-- (SELECT array_agg(attname::text) from pg_attribute
|
|
83
|
-
-- where attrelid = c.confrelid and ARRAY[attnum] <@ c.confkey) as fcols,
|
|
84
|
-
-- (SELECT r.relname from pg_class r where r.oid = c.confrelid) as ftable
|
|
85
|
-
FROM pg_catalog.pg_constraint c
|
|
86
|
-
INNER JOIN pg_catalog.pg_class rel
|
|
87
|
-
ON rel.oid = c.conrelid
|
|
88
|
-
INNER JOIN pg_catalog.pg_namespace nsp
|
|
89
|
-
ON nsp.oid = connamespace
|
|
90
|
-
) t
|
|
91
|
-
WHERE TRUE
|
|
92
|
-
`;
|
|
93
|
-
if (table) query += `\nAND "table" = ${asValue(table)}`;
|
|
94
|
-
if (column) query += `\nAND cols @> ARRAY[${asValue(column)}]`;
|
|
95
|
-
if (types?.length) query += `\nAND type IN (${types.map((v) => asValue(v)).join(", ")})`;
|
|
96
|
-
return query;
|
|
97
|
-
};
|
|
98
|
-
export const getColConstraints = ({
|
|
99
|
-
db,
|
|
100
|
-
column,
|
|
101
|
-
table,
|
|
102
|
-
types,
|
|
103
|
-
}: ColConstraintsArgs): Promise<ColConstraint[]> => {
|
|
104
|
-
return db.manyOrNone(getColConstraintsQuery({ column, table, types }));
|
|
105
|
-
};
|
|
@@ -2,7 +2,7 @@ import type pgPromise from "pg-promise";
|
|
|
2
2
|
import { asName } from "prostgles-types";
|
|
3
3
|
import type { DB } from "../initProstgles";
|
|
4
4
|
import type { ProstglesInitOptions, TableConfigMigrations } from "../ProstglesTypes";
|
|
5
|
-
import {
|
|
5
|
+
import { fetchTableConstraints } from "./fetchTableConstraints";
|
|
6
6
|
import type { TableConfig } from "./TableConfig";
|
|
7
7
|
export type RequiredUndefined<T> = {
|
|
8
8
|
[K in keyof Required<T>]: T[K];
|
|
@@ -115,7 +115,7 @@ const getMigration = async (
|
|
|
115
115
|
db: t,
|
|
116
116
|
oldVersion: latestVersion,
|
|
117
117
|
getConstraints: (table, col, types) =>
|
|
118
|
-
|
|
118
|
+
fetchTableConstraints({ db: t, table, column: col, types }),
|
|
119
119
|
});
|
|
120
120
|
|
|
121
121
|
return {
|
|
@@ -3,8 +3,8 @@ import { pgp } from "../DboBuilder/DboBuilder";
|
|
|
3
3
|
import type { DB } from "../Prostgles";
|
|
4
4
|
import type { ColumnMinimalInfo } from "./getColumnSQLDefinitionQuery";
|
|
5
5
|
import { getTableColumns } from "./getColumnSQLDefinitionQuery";
|
|
6
|
-
import type {
|
|
7
|
-
import {
|
|
6
|
+
import type { ConstraintDef } from "./getConstraintDefinitionQueries";
|
|
7
|
+
import { type PGConstraint, fetchTableConstraints } from "./fetchTableConstraints";
|
|
8
8
|
|
|
9
9
|
type Args = {
|
|
10
10
|
db: DB;
|
|
@@ -23,12 +23,12 @@ export const getFutureTableSchema = async ({
|
|
|
23
23
|
constraintDefs = [],
|
|
24
24
|
db,
|
|
25
25
|
}: Args): Promise<{
|
|
26
|
-
constraints:
|
|
26
|
+
constraints: PGConstraint[];
|
|
27
27
|
cols: ColumnMinimalInfo[];
|
|
28
28
|
}> => {
|
|
29
29
|
const { TransactionMode, isolationLevel } = pgp.txMode;
|
|
30
30
|
|
|
31
|
-
let constraints:
|
|
31
|
+
let constraints: PGConstraint[] = [];
|
|
32
32
|
let cols: ColumnMinimalInfo[] = [];
|
|
33
33
|
const txMode = new TransactionMode({
|
|
34
34
|
tiLevel: isolationLevel.serializable,
|
|
@@ -56,7 +56,7 @@ export const getFutureTableSchema = async ({
|
|
|
56
56
|
|
|
57
57
|
await t.any(query);
|
|
58
58
|
|
|
59
|
-
constraints = await
|
|
59
|
+
constraints = await fetchTableConstraints({ db: t, table: tableName });
|
|
60
60
|
cols = await getTableColumns({ db: t, table: tableName });
|
|
61
61
|
|
|
62
62
|
return t.any("ROLLBACK");
|
|
@@ -6,10 +6,8 @@ import {
|
|
|
6
6
|
} from "../PubSubManager/PubSubManagerUtils";
|
|
7
7
|
import type { OnReadyCallbackBasic } from "../initProstgles";
|
|
8
8
|
import type TableConfigurator from "./TableConfig";
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
getConstraintDefinitionQueries,
|
|
12
|
-
} from "./getConstraintDefinitionQueries";
|
|
9
|
+
import { getConstraintDefinitionQueries } from "./getConstraintDefinitionQueries";
|
|
10
|
+
import { fetchTableConstraints } from "./fetchTableConstraints";
|
|
13
11
|
import { getFutureTableSchema } from "./getFutureTableSchema";
|
|
14
12
|
import { getPGIndexes } from "./getPGIndexes";
|
|
15
13
|
import { getTableColumnQueries } from "./getTableColumnQueries";
|
|
@@ -83,13 +81,14 @@ export const initTableConfig = async function (this: TableConfigurator) {
|
|
|
83
81
|
throw "pgp missing";
|
|
84
82
|
}
|
|
85
83
|
|
|
86
|
-
const MAX_IDENTIFIER_LENGTH = +(
|
|
87
|
-
.max_identifier_length;
|
|
84
|
+
const MAX_IDENTIFIER_LENGTH = +(
|
|
85
|
+
await this.db.one<{ max_identifier_length: number }>("SHOW max_identifier_length;")
|
|
86
|
+
).max_identifier_length;
|
|
88
87
|
if (!Number.isFinite(MAX_IDENTIFIER_LENGTH))
|
|
89
88
|
throw `Could not obtain a valid max_identifier_length`;
|
|
90
89
|
const asName = (v: string) => {
|
|
91
|
-
if (v.length > MAX_IDENTIFIER_LENGTH
|
|
92
|
-
throw `The identifier name provided (${v}) is longer than the allowed limit (max_identifier_length
|
|
90
|
+
if (v.length > MAX_IDENTIFIER_LENGTH) {
|
|
91
|
+
throw `The identifier name provided (${v}) is longer than the allowed limit (max_identifier_length = ${MAX_IDENTIFIER_LENGTH} characters )\n Longest allowed: ${_asName(v.slice(0, MAX_IDENTIFIER_LENGTH))} `;
|
|
93
92
|
}
|
|
94
93
|
|
|
95
94
|
return _asName(v);
|
|
@@ -198,7 +197,7 @@ export const initTableConfig = async function (this: TableConfigurator) {
|
|
|
198
197
|
|
|
199
198
|
/** Run this first to ensure any dropped cols drop their constraints as well */
|
|
200
199
|
await runQueries(queries);
|
|
201
|
-
const currCons = await
|
|
200
|
+
const currCons = await fetchTableConstraints({
|
|
202
201
|
db: this.db,
|
|
203
202
|
table: tableName,
|
|
204
203
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type pgPromise from "pg-promise";
|
|
2
2
|
import type { ProstglesInitOptions } from "../ProstglesTypes";
|
|
3
3
|
import { EXCLUDE_QUERY_FROM_SCHEMA_WATCH_ID } from "../PubSubManager/PubSubManagerUtils";
|
|
4
|
-
import {
|
|
4
|
+
import { fetchTableConstraints } from "./fetchTableConstraints";
|
|
5
5
|
|
|
6
6
|
export async function runMigrations(
|
|
7
7
|
t: pgPromise.ITask<{}>,
|
|
@@ -43,7 +43,7 @@ export async function runMigrations(
|
|
|
43
43
|
db: t,
|
|
44
44
|
oldVersion: latestVersion,
|
|
45
45
|
getConstraints: (table, col, types) =>
|
|
46
|
-
|
|
46
|
+
fetchTableConstraints({ db: t, table, column: col, types }),
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
|