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
|
@@ -50,12 +50,11 @@ export const getSchemaUtils = async (prostgles: Pick<Prostgles, "db" | "opts">)
|
|
|
50
50
|
const MAX_IDENTIFIER_LENGTH = +(
|
|
51
51
|
await db.one<{ max_identifier_length: number }>("SHOW max_identifier_length;")
|
|
52
52
|
).max_identifier_length;
|
|
53
|
-
|
|
54
53
|
if (!Number.isFinite(MAX_IDENTIFIER_LENGTH))
|
|
55
54
|
throw `Could not obtain a valid max_identifier_length`;
|
|
56
55
|
const asName = (v: string) => {
|
|
57
|
-
if (v.length > MAX_IDENTIFIER_LENGTH
|
|
58
|
-
throw `The identifier name provided (${v}) is longer than the allowed limit (max_identifier_length
|
|
56
|
+
if (v.length > MAX_IDENTIFIER_LENGTH) {
|
|
57
|
+
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))} `;
|
|
59
58
|
}
|
|
60
59
|
|
|
61
60
|
return _asName(v);
|
|
@@ -62,7 +62,7 @@ export async function getClientSchema(
|
|
|
62
62
|
const methodSchema: ClientSchema["methods"] =
|
|
63
63
|
!methods ?
|
|
64
64
|
[]
|
|
65
|
-
:
|
|
65
|
+
: Array.from(methods.entries())
|
|
66
66
|
.map(([methodName, method]) => {
|
|
67
67
|
if (isObject(method) && "run" in method) {
|
|
68
68
|
return {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AnyObject} from "prostgles-types";
|
|
2
|
-
import { CHANNELS } from "prostgles-types";
|
|
1
|
+
import type { AnyObject } from "prostgles-types";
|
|
2
|
+
import { CHANNELS, getSerialisableError, isObject } from "prostgles-types";
|
|
3
3
|
import type { Prostgles, TABLE_METHODS } from "../Prostgles";
|
|
4
4
|
import type { PRGLIOSocket } from "../DboBuilder/DboBuilderTypes";
|
|
5
5
|
import { runClientMethod, runClientRequest } from "../runClientRequest";
|
|
@@ -151,7 +151,8 @@ export async function onSocketConnected(this: Prostgles, socket: PRGLIOSocket) {
|
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
export function makeSocketError(cb: (err: AnyObject) => void, err: any) {
|
|
154
|
-
|
|
154
|
+
const serializedError = getSerialisableError(err);
|
|
155
|
+
cb(isObject(serializedError) ? serializedError : { serializedError });
|
|
155
156
|
}
|
|
156
157
|
|
|
157
158
|
type SocketRequestParams = {
|
package/lib/initProstgles.ts
CHANGED
|
@@ -367,10 +367,6 @@ const getDbConnection = function ({
|
|
|
367
367
|
pgp.pg.types.setTypeParser(pgp.pg.types.builtins.TIMESTAMPTZ, (v) => v); // timestamp with time zone
|
|
368
368
|
pgp.pg.types.setTypeParser(pgp.pg.types.builtins.DATE, (v) => v); // date
|
|
369
369
|
|
|
370
|
-
// if (dbOptions) {
|
|
371
|
-
// Object.assign(pgp.pg.defaults, dbOptions);
|
|
372
|
-
// }
|
|
373
|
-
|
|
374
370
|
return {
|
|
375
371
|
db: pgp(dbConnection),
|
|
376
372
|
pgp,
|
package/lib/runClientRequest.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
SQLRequest,
|
|
3
|
-
TableHandler,
|
|
4
|
-
UserLike} from "prostgles-types";
|
|
1
|
+
import type { SQLRequest, TableHandler, UserLike } from "prostgles-types";
|
|
5
2
|
import {
|
|
3
|
+
getJSONBObjectSchemaValidationError,
|
|
6
4
|
getKeys,
|
|
7
5
|
pickKeys,
|
|
8
6
|
type AnyObject,
|
|
@@ -13,7 +11,7 @@ import type { TableHandler as TableHandlerServer } from "./DboBuilder/TableHandl
|
|
|
13
11
|
import { parseFieldFilter } from "./DboBuilder/ViewHandler/parseFieldFilter";
|
|
14
12
|
import { canRunSQL } from "./DboBuilder/runSQL";
|
|
15
13
|
import type { Prostgles } from "./Prostgles";
|
|
16
|
-
import type { ParsedTableRule} from "./PublishParser/publishTypesAndUtils";
|
|
14
|
+
import type { ParsedTableRule } from "./PublishParser/publishTypesAndUtils";
|
|
17
15
|
import { type PermissionScope } from "./PublishParser/publishTypesAndUtils";
|
|
18
16
|
|
|
19
17
|
const TABLE_METHODS = {
|
|
@@ -41,11 +39,11 @@ const SOCKET_ONLY_COMMANDS = [
|
|
|
41
39
|
] as const satisfies typeof TABLE_METHODS_KEYS;
|
|
42
40
|
|
|
43
41
|
type Args = {
|
|
44
|
-
tableName:
|
|
45
|
-
command:
|
|
46
|
-
param1:
|
|
47
|
-
param2:
|
|
48
|
-
param3:
|
|
42
|
+
tableName: unknown;
|
|
43
|
+
command: unknown;
|
|
44
|
+
param1: unknown;
|
|
45
|
+
param2: unknown;
|
|
46
|
+
param3: unknown;
|
|
49
47
|
};
|
|
50
48
|
|
|
51
49
|
type TableMethodFunctionWithRulesAndLocalParams = (
|
|
@@ -58,7 +56,7 @@ type TableMethodFunctionWithRulesAndLocalParams = (
|
|
|
58
56
|
|
|
59
57
|
export const runClientRequest = async function (
|
|
60
58
|
this: Prostgles,
|
|
61
|
-
|
|
59
|
+
nonValidatedArgs: Args,
|
|
62
60
|
clientReq: AuthClientRequest,
|
|
63
61
|
scope: PermissionScope | undefined
|
|
64
62
|
) {
|
|
@@ -67,11 +65,22 @@ export const runClientRequest = async function (
|
|
|
67
65
|
throw "socket/httpReq or authhandler missing";
|
|
68
66
|
}
|
|
69
67
|
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
const validation = getJSONBObjectSchemaValidationError(
|
|
69
|
+
{
|
|
70
|
+
tableName: { type: "string" },
|
|
71
|
+
command: { enum: TABLE_METHODS_KEYS },
|
|
72
|
+
param1: { type: "any", optional: true },
|
|
73
|
+
param2: { type: "any", optional: true },
|
|
74
|
+
param3: { type: "any", optional: true },
|
|
75
|
+
},
|
|
76
|
+
nonValidatedArgs,
|
|
77
|
+
"tableName"
|
|
78
|
+
);
|
|
79
|
+
if (validation.error !== undefined) {
|
|
80
|
+
throw validation.error;
|
|
73
81
|
}
|
|
74
|
-
const command
|
|
82
|
+
const { tableName, command, param1, param2, param3 } = validation.data;
|
|
83
|
+
|
|
75
84
|
if (!clientReq.socket && SOCKET_ONLY_COMMANDS.some((v) => v === command)) {
|
|
76
85
|
throw (
|
|
77
86
|
"The following commands cannot be completed over a non-websocket connection: " +
|
|
@@ -79,6 +88,10 @@ export const runClientRequest = async function (
|
|
|
79
88
|
);
|
|
80
89
|
}
|
|
81
90
|
|
|
91
|
+
if (!this.dboBuilder.dboMap.has(tableName)) {
|
|
92
|
+
throw `tableName ${tableName} is invalid or not allowed`;
|
|
93
|
+
}
|
|
94
|
+
|
|
82
95
|
const clientInfo = await this.authHandler?.getSidAndUserFromRequest(clientReq);
|
|
83
96
|
if (clientInfo === "new-session-redirect") {
|
|
84
97
|
throw clientInfo;
|
|
@@ -159,7 +172,7 @@ export const clientCanRunSqlRequest = async function (
|
|
|
159
172
|
|
|
160
173
|
export const runClientSqlRequest = async function (
|
|
161
174
|
this: Prostgles,
|
|
162
|
-
|
|
175
|
+
unvalidatedArgs: SQLRequest,
|
|
163
176
|
clientReq: AuthClientRequest
|
|
164
177
|
) {
|
|
165
178
|
const { allowed } = await clientCanRunSqlRequest.bind(this)(clientReq);
|
|
@@ -167,23 +180,48 @@ export const runClientSqlRequest = async function (
|
|
|
167
180
|
throw "Not allowed to execute sql";
|
|
168
181
|
}
|
|
169
182
|
if (!this.dbo?.sql) throw "Internal error: sql handler missing";
|
|
183
|
+
const validation = getJSONBObjectSchemaValidationError(
|
|
184
|
+
{
|
|
185
|
+
query: { type: "string" },
|
|
186
|
+
params: { type: "any", optional: true },
|
|
187
|
+
options: { type: "any", optional: true },
|
|
188
|
+
},
|
|
189
|
+
unvalidatedArgs,
|
|
190
|
+
"query"
|
|
191
|
+
);
|
|
192
|
+
if (validation.error !== undefined) {
|
|
193
|
+
throw validation.error;
|
|
194
|
+
}
|
|
195
|
+
const reqData = validation.data;
|
|
170
196
|
const { query, params, options } = reqData;
|
|
171
197
|
return this.dbo.sql(query, params, options, { clientReq });
|
|
172
198
|
};
|
|
173
199
|
|
|
174
200
|
type ArgsMethod = {
|
|
175
|
-
method:
|
|
201
|
+
method: unknown;
|
|
176
202
|
params?: any[];
|
|
177
203
|
};
|
|
178
204
|
export const runClientMethod = async function (
|
|
179
205
|
this: Prostgles,
|
|
180
|
-
|
|
206
|
+
unvalidatedArgs: ArgsMethod,
|
|
181
207
|
clientReq: AuthClientRequest
|
|
182
208
|
) {
|
|
209
|
+
const validation = getJSONBObjectSchemaValidationError(
|
|
210
|
+
{
|
|
211
|
+
method: { type: "string" },
|
|
212
|
+
params: { type: "any[]", optional: true },
|
|
213
|
+
},
|
|
214
|
+
unvalidatedArgs,
|
|
215
|
+
"method"
|
|
216
|
+
);
|
|
217
|
+
if (validation.error !== undefined) {
|
|
218
|
+
throw validation.error;
|
|
219
|
+
}
|
|
220
|
+
const reqArgs = validation.data;
|
|
183
221
|
const { method, params = [] } = reqArgs;
|
|
184
222
|
const methods = await this.publishParser?.getAllowedMethods(clientReq, undefined);
|
|
185
223
|
|
|
186
|
-
const methodDef = methods?.
|
|
224
|
+
const methodDef = methods?.get(method);
|
|
187
225
|
if (!methods || !methodDef) {
|
|
188
226
|
throw "Disallowed/missing method " + JSON.stringify(method);
|
|
189
227
|
}
|
package/lib/shortestPath.ts
CHANGED
|
@@ -25,7 +25,7 @@ export const findShortestPath = (
|
|
|
25
25
|
// establish object for recording distances from the start node
|
|
26
26
|
let distances: AnyObject = {};
|
|
27
27
|
distances[endNode] = "Infinity";
|
|
28
|
-
distances =
|
|
28
|
+
distances = { ...distances, ...graph[startNode] };
|
|
29
29
|
|
|
30
30
|
// track paths
|
|
31
31
|
const parents: AnyObject = { endNode: null };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prostgles-server",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.348",
|
|
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.14.6",
|
|
59
59
|
"pg-promise": "^11.13.0",
|
|
60
|
-
"prostgles-types": "^4.0.
|
|
60
|
+
"prostgles-types": "^4.0.183"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@eslint/js": "^9.22.0",
|