prostgles-server 4.2.41 → 4.2.42
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/DboBuilder.d.ts +4 -1
- package/dist/DboBuilder/DboBuilder.d.ts.map +1 -1
- package/dist/DboBuilder/DboBuilder.js +7 -18
- package/dist/DboBuilder/DboBuilder.js.map +1 -1
- package/dist/DboBuilder/QueryStreamer.d.ts +1 -1
- package/dist/DboBuilder/QueryStreamer.d.ts.map +1 -1
- package/dist/DboBuilder/QueryStreamer.js +2 -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 +3 -3
- package/dist/DboBuilder/dboBuilderUtils.js.map +1 -1
- package/dist/DboBuilder/runSQL.d.ts +0 -7
- package/dist/DboBuilder/runSQL.d.ts.map +1 -1
- package/dist/DboBuilder/runSQL.js +3 -18
- package/dist/DboBuilder/runSQL.js.map +1 -1
- package/dist/PostgresNotifListenManager.d.ts +1 -1
- package/dist/PostgresNotifListenManager.d.ts.map +1 -1
- package/dist/PostgresNotifListenManager.js +1 -1
- package/dist/PostgresNotifListenManager.js.map +1 -1
- package/dist/Prostgles.d.ts +8 -20
- package/dist/Prostgles.d.ts.map +1 -1
- package/dist/Prostgles.js +6 -57
- package/dist/Prostgles.js.map +1 -1
- package/dist/PubSubManager/PubSubManager.d.ts +13 -20
- package/dist/PubSubManager/PubSubManager.d.ts.map +1 -1
- package/dist/PubSubManager/PubSubManager.js +74 -80
- package/dist/PubSubManager/PubSubManager.js.map +1 -1
- package/dist/PubSubManager/addSub.js +0 -59
- package/dist/PubSubManager/addSub.js.map +1 -1
- package/dist/PubSubManager/getInitQuery.d.ts.map +1 -1
- package/dist/PubSubManager/getInitQuery.js +6 -6
- package/dist/PubSubManager/getInitQuery.js.map +1 -1
- package/dist/PubSubManager/initPubSubManager.d.ts.map +1 -1
- package/dist/PubSubManager/initPubSubManager.js +13 -35
- package/dist/PubSubManager/initPubSubManager.js.map +1 -1
- package/dist/PubSubManager/notifListener.d.ts.map +1 -1
- package/dist/PubSubManager/notifListener.js +5 -5
- package/dist/PubSubManager/notifListener.js.map +1 -1
- package/dist/SchemaWatch/SCHEMA_WATCH_QUERIES.d.ts +2 -0
- package/dist/SchemaWatch/SCHEMA_WATCH_QUERIES.d.ts.map +1 -0
- package/dist/SchemaWatch/SCHEMA_WATCH_QUERIES.js +53 -0
- package/dist/SchemaWatch/SCHEMA_WATCH_QUERIES.js.map +1 -0
- package/dist/SchemaWatch/SchemaWatch.d.ts +19 -0
- package/dist/SchemaWatch/SchemaWatch.d.ts.map +1 -0
- package/dist/SchemaWatch/SchemaWatch.js +71 -0
- package/dist/SchemaWatch/SchemaWatch.js.map +1 -0
- package/dist/SchemaWatch/getValidatedWatchSchemaType.d.ts +14 -0
- package/dist/SchemaWatch/getValidatedWatchSchemaType.d.ts.map +1 -0
- package/dist/SchemaWatch/getValidatedWatchSchemaType.js +38 -0
- package/dist/SchemaWatch/getValidatedWatchSchemaType.js.map +1 -0
- package/dist/SchemaWatch/getWatchSchemaTagList.d.ts +3 -0
- package/dist/SchemaWatch/getWatchSchemaTagList.d.ts.map +1 -0
- package/dist/SchemaWatch/getWatchSchemaTagList.js +29 -0
- package/dist/SchemaWatch/getWatchSchemaTagList.js.map +1 -0
- package/dist/SchemaWatch.d.ts +26 -9
- package/dist/SchemaWatch.d.ts.map +1 -1
- package/dist/SchemaWatch.js +116 -25
- package/dist/SchemaWatch.js.map +1 -1
- package/dist/initProstgles.d.ts.map +1 -1
- package/dist/initProstgles.js +3 -2
- package/dist/initProstgles.js.map +1 -1
- package/lib/DboBuilder/DboBuilder.ts +12 -21
- package/lib/DboBuilder/QueryStreamer.ts +2 -2
- package/lib/DboBuilder/dboBuilderUtils.ts +1 -1
- package/lib/DboBuilder/runSQL.ts +1 -18
- package/lib/PostgresNotifListenManager.ts +1 -1
- package/lib/Prostgles.ts +8 -69
- package/lib/PubSubManager/PubSubManager.ts +75 -83
- package/lib/PubSubManager/addSub.ts +0 -63
- package/lib/PubSubManager/getInitQuery.ts +7 -7
- package/lib/PubSubManager/initPubSubManager.ts +16 -41
- package/lib/PubSubManager/notifListener.ts +6 -6
- package/lib/PublishParser/PublishParser.ts +1 -1
- package/lib/SchemaWatch/SchemaWatch.ts +79 -0
- package/lib/SchemaWatch/getValidatedWatchSchemaType.ts +45 -0
- package/lib/SchemaWatch/getWatchSchemaTagList.ts +27 -0
- package/lib/initProstgles.ts +6 -4
- package/package.json +1 -1
- package/tests/server/package-lock.json +1 -1
- package/lib/SchemaWatch.ts +0 -40
- package/lib/SchemaWatchManager.ts +0 -72
package/dist/SchemaWatch.js
CHANGED
|
@@ -1,36 +1,127 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SchemaWatch = void 0;
|
|
3
|
+
exports.watchSchemaFallback = exports.getWatchSchemaTagList = exports.SchemaWatch = void 0;
|
|
4
|
+
const Event_Trigger_Tags_1 = require("./Event_Trigger_Tags");
|
|
4
5
|
const prostgles_types_1 = require("prostgles-types");
|
|
5
|
-
const
|
|
6
|
+
const PubSubManager_1 = require("./PubSubManager/PubSubManager");
|
|
6
7
|
class SchemaWatch {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
constructor(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (
|
|
13
|
-
|
|
8
|
+
dboBuilder;
|
|
9
|
+
type;
|
|
10
|
+
constructor(dboBuilder) {
|
|
11
|
+
this.dboBuilder = dboBuilder;
|
|
12
|
+
this.type = getValidatedWatchSchemaType(dboBuilder);
|
|
13
|
+
if (this.type.watchType === "NONE") {
|
|
14
|
+
this.onSchemaChange = undefined;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
static create = async (dboBuilder) => {
|
|
18
|
+
const instance = new SchemaWatch(dboBuilder);
|
|
19
|
+
if (instance.type.watchType === "DDL_trigger") {
|
|
20
|
+
await dboBuilder.getPubSubManager();
|
|
14
21
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
return instance;
|
|
23
|
+
};
|
|
24
|
+
onSchemaChange = async (event) => {
|
|
25
|
+
if (this.type.watchType === "NONE")
|
|
26
|
+
return;
|
|
27
|
+
const { watchSchema, onReady, tsGeneratedTypesDir } = this.dboBuilder.prostgles.opts;
|
|
28
|
+
if (watchSchema && this.dboBuilder.prostgles.loaded) {
|
|
29
|
+
(0, PubSubManager_1.log)("Schema changed");
|
|
30
|
+
const { query, command } = event;
|
|
31
|
+
if (typeof query === "string" && query.includes(PubSubManager_1.PubSubManager.EXCLUDE_QUERY_FROM_SCHEMA_WATCH_ID)) {
|
|
32
|
+
(0, PubSubManager_1.log)("Schema change event excluded from triggers due to EXCLUDE_QUERY_FROM_SCHEMA_WATCH_ID");
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (typeof watchSchema === "function") {
|
|
36
|
+
/* Only call the provided func */
|
|
37
|
+
watchSchema(event);
|
|
20
38
|
}
|
|
21
|
-
|
|
22
|
-
if (
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
39
|
+
else if (watchSchema === "hotReloadMode") {
|
|
40
|
+
if (tsGeneratedTypesDir) {
|
|
41
|
+
/* Hot reload integration. Will only touch tsGeneratedTypesDir */
|
|
42
|
+
console.log("watchSchema: Re-writing TS schema");
|
|
43
|
+
await this.dboBuilder.prostgles.refreshDBO();
|
|
44
|
+
this.dboBuilder.prostgles.writeDBSchema(true);
|
|
27
45
|
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
46
|
+
}
|
|
47
|
+
else if (watchSchema) {
|
|
48
|
+
/* Full re-init. Sockets must reconnect */
|
|
49
|
+
console.log("watchSchema: Full re-initialisation", { query });
|
|
50
|
+
this.dboBuilder.prostgles.init(onReady, { type: "schema change", query, command });
|
|
51
|
+
}
|
|
32
52
|
}
|
|
33
|
-
}
|
|
53
|
+
};
|
|
34
54
|
}
|
|
35
55
|
exports.SchemaWatch = SchemaWatch;
|
|
56
|
+
const getValidatedWatchSchemaType = (dboBuilder) => {
|
|
57
|
+
const { watchSchema, watchSchemaType, tsGeneratedTypesDir } = dboBuilder.prostgles.opts;
|
|
58
|
+
if (!watchSchema)
|
|
59
|
+
return { watchType: "NONE" };
|
|
60
|
+
if (watchSchema === "hotReloadMode" && !tsGeneratedTypesDir) {
|
|
61
|
+
throw "tsGeneratedTypesDir option is needed for watchSchema: hotReloadMode to work ";
|
|
62
|
+
}
|
|
63
|
+
const onChange = typeof watchSchema === "function" ? watchSchema : undefined;
|
|
64
|
+
if (watchSchemaType === "DDL_trigger" || !watchSchemaType) {
|
|
65
|
+
if (!dboBuilder.prostgles.isSuperUser) {
|
|
66
|
+
if (watchSchemaType === "DDL_trigger") {
|
|
67
|
+
console.error(`watchSchemaType "DDL_trigger" cannot be used because db user is not a superuser. Will fallback to watchSchemaType "prostgles_queries" `);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
console.warn(`watchSchema fallback to watchSchemaType "prostgles_queries" due to non-superuser`);
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
watchType: "prostgles_queries",
|
|
74
|
+
onChange,
|
|
75
|
+
isFallbackFromDDL: true
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
watchType: "DDL_trigger",
|
|
80
|
+
onChange
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
watchType: watchSchemaType,
|
|
85
|
+
isFallbackFromDDL: false,
|
|
86
|
+
onChange
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
const getWatchSchemaTagList = (watchSchema) => {
|
|
90
|
+
if (!watchSchema)
|
|
91
|
+
return undefined;
|
|
92
|
+
if (watchSchema === "*") {
|
|
93
|
+
return Event_Trigger_Tags_1.EVENT_TRIGGER_TAGS.slice(0);
|
|
94
|
+
}
|
|
95
|
+
if ((0, prostgles_types_1.isObject)(watchSchema) && typeof watchSchema !== "function") {
|
|
96
|
+
const watchSchemaKeys = (0, prostgles_types_1.getKeys)(watchSchema);
|
|
97
|
+
const isInclusive = Object.values(watchSchema).every(v => v);
|
|
98
|
+
return Event_Trigger_Tags_1.EVENT_TRIGGER_TAGS
|
|
99
|
+
.slice(0)
|
|
100
|
+
.filter(v => {
|
|
101
|
+
const matches = watchSchemaKeys.includes(v);
|
|
102
|
+
return isInclusive ? matches : !matches;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
const coreTags = [
|
|
106
|
+
'COMMENT', 'CREATE TABLE', 'ALTER TABLE', 'DROP TABLE', 'CREATE VIEW',
|
|
107
|
+
'DROP VIEW', 'ALTER VIEW', 'CREATE TABLE AS', 'SELECT INTO', 'CREATE POLICY'
|
|
108
|
+
];
|
|
109
|
+
return coreTags;
|
|
110
|
+
};
|
|
111
|
+
exports.getWatchSchemaTagList = getWatchSchemaTagList;
|
|
112
|
+
/**
|
|
113
|
+
* Fallback for watchSchema in case of not a superuser (cannot add db event listener)
|
|
114
|
+
*/
|
|
115
|
+
const watchSchemaFallback = async function ({ queryWithoutRLS, command }) {
|
|
116
|
+
const SCHEMA_ALTERING_COMMANDS = Event_Trigger_Tags_1.EVENT_TRIGGER_TAGS; // ["CREATE", "ALTER", "DROP", "REVOKE", "GRANT"];
|
|
117
|
+
const isNotPickedUpByDDLTrigger = ["REVOKE", "GRANT"].includes(command);
|
|
118
|
+
const { watchSchema, watchSchemaType } = this.prostgles?.opts || {};
|
|
119
|
+
if (watchSchema &&
|
|
120
|
+
(!this.prostgles.isSuperUser || watchSchemaType === "prostgles_queries" || isNotPickedUpByDDLTrigger)) {
|
|
121
|
+
if (SCHEMA_ALTERING_COMMANDS.includes(command)) {
|
|
122
|
+
this.prostgles.schemaWatch?.onSchemaChange?.({ command, query: queryWithoutRLS });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
exports.watchSchemaFallback = watchSchemaFallback;
|
|
36
127
|
//# sourceMappingURL=SchemaWatch.js.map
|
package/dist/SchemaWatch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaWatch.js","sourceRoot":"","sources":["../lib/SchemaWatch.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"SchemaWatch.js","sourceRoot":"","sources":["../lib/SchemaWatch.ts"],"names":[],"mappings":";;;AACA,6DAA0D;AAE1D,qDAAoD;AACpD,iEAAmE;AAInE,MAAa,WAAW;IAEtB,UAAU,CAAa;IACvB,IAAI,CAA2B;IAC/B,YAAoB,UAAsB;QACxC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC,UAAU,CAAC,CAAC;QACpD,IAAG,IAAI,CAAC,IAAI,CAAC,SAAS,KAAK,MAAM,EAAE,CAAC;YAClC,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC;QAClC,CAAC;IACH,CAAC;IAED,MAAM,CAAC,MAAM,GAAG,KAAK,EAAE,UAAsB,EAAE,EAAE;QAC/C,MAAM,QAAQ,GAAG,IAAI,WAAW,CAAC,UAAU,CAAC,CAAC;QAC7C,IAAG,QAAQ,CAAC,IAAI,CAAC,SAAS,KAAK,aAAa,EAAE,CAAC;YAC7C,MAAM,UAAU,CAAC,gBAAgB,EAAE,CAAA;QACrC,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAA;IAED,cAAc,GAAuC,KAAK,EAAE,KAAK,EAAE,EAAE;QACnE,IAAG,IAAI,CAAC,IAAI,CAAC,SAAS,KAAK,MAAM;YAAE,OAAO;QAE1C,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,mBAAmB,EAAE,G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,WAAW,EAAE,cAAc,EAAE,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,CAAC,CAAA;QACnF,CAAC;IACH,CAAC;AACH,CAAC,CAAA;AAZY,QAAA,mBAAmB,uBAY/B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initProstgles.d.ts","sourceRoot":"","sources":["../lib/initProstgles.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,SAAS,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAIjD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,oBAAoB,
|
|
1
|
+
{"version":3,"file":"initProstgles.d.ts","sourceRoot":"","sources":["../lib/initProstgles.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,SAAS,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAIjD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,oBAAoB,EAAkB,MAAM,aAAa,CAAC;AAC/F,OAAO,EAAE,WAAW,EAAiB,MAAM,+BAA+B,CAAC;AAI3E,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,EAAE,CAAC,qBAAqB,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;AACzE,MAAM,MAAM,gBAAgB,GAAG,EAAE,CAAC,SAAS,CAAC;AAE5C,MAAM,MAAM,GAAG,GAAG,SAAS,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC;AAClD,MAAM,MAAM,EAAE,GAAG,SAAS,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC;AAErD,MAAM,MAAM,YAAY,GACpB;IACA,IAAI,EAAE,eAAe,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,O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,9 +9,9 @@ const DBEventsManager_1 = require("./DBEventsManager");
|
|
|
9
9
|
const Prostgles_1 = require("./Prostgles");
|
|
10
10
|
const PublishParser_1 = require("./PublishParser/PublishParser");
|
|
11
11
|
const utils_1 = require("./utils");
|
|
12
|
+
const SchemaWatch_1 = require("./SchemaWatch/SchemaWatch");
|
|
12
13
|
const initProstgles = async function (onReady, reason) {
|
|
13
14
|
this.loaded = false;
|
|
14
|
-
this.initWatchSchema(onReady);
|
|
15
15
|
/* 1. Connect to db */
|
|
16
16
|
if (!this.db) {
|
|
17
17
|
const { db, pgp } = getDbConnection(this.opts.dbConnection, this.opts.dbOptions, this.opts.DEBUG_MODE, notice => {
|
|
@@ -23,7 +23,7 @@ const initProstgles = async function (onReady, reason) {
|
|
|
23
23
|
});
|
|
24
24
|
this.db = db;
|
|
25
25
|
this.pgp = pgp;
|
|
26
|
-
this.isSuperUser = await (0, Prostgles_1.
|
|
26
|
+
this.isSuperUser = await (0, Prostgles_1.getIsSuperUser)(db);
|
|
27
27
|
}
|
|
28
28
|
this.checkDb();
|
|
29
29
|
const db = this.db;
|
|
@@ -37,6 +37,7 @@ const initProstgles = async function (onReady, reason) {
|
|
|
37
37
|
await this.initTableConfig(reason);
|
|
38
38
|
await this.initFileTable();
|
|
39
39
|
await this.initRestApi();
|
|
40
|
+
this.schemaWatch = await SchemaWatch_1.SchemaWatch.create(this.dboBuilder);
|
|
40
41
|
if (this.opts.publish) {
|
|
41
42
|
if (!this.opts.io)
|
|
42
43
|
console.warn("IO missing. Publish has no effect without io");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initProstgles.js","sourceRoot":"","sources":["../lib/initProstgles.ts"],"names":[],"mappings":";;;AAAA,oCAAoC;AACpC,wCAAwC;AAExC,qDAAoD;AACpD,+CAAwC;AACxC,uDAAoD;AAEpD,
|
|
1
|
+
{"version":3,"file":"initProstgles.js","sourceRoot":"","sources":["../lib/initProstgles.ts"],"names":[],"mappings":";;;AAAA,oCA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K,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,2BAA2B;IAClG,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO;IAGvE,IAAI,OAAO,EAAE,CAAC;QACZ,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO;QACL,EAAE,EAAE,GAAG,CAAC,YAAY,CAAC;QACrB,GAAG;KACJ,CAAC;AACJ,CAAC"}
|
|
@@ -26,10 +26,11 @@ import { QueryStreamer } from "./QueryStreamer";
|
|
|
26
26
|
import { TableHandler } from "./TableHandler/TableHandler";
|
|
27
27
|
import { JoinPaths, ViewHandler } from "./ViewHandler/ViewHandler";
|
|
28
28
|
import { parseJoinPath } from "./ViewHandler/parseJoinPath";
|
|
29
|
-
import { PGConstraint,
|
|
29
|
+
import { PGConstraint, getCanExecute, getConstraints, getSerializedClientErrorFromPGError } from "./dboBuilderUtils";
|
|
30
30
|
import { getTablesForSchemaPostgresSQL } from "./getTablesForSchemaPostgresSQL";
|
|
31
31
|
import { prepareShortestJoinPaths } from "./prepareShortestJoinPaths";
|
|
32
32
|
import { runSQL } from "./runSQL";
|
|
33
|
+
import { PostgresNotifListenManager } from "../PostgresNotifListenManager";
|
|
33
34
|
|
|
34
35
|
export * from "./DboBuilderTypes";
|
|
35
36
|
export * from "./dboBuilderUtils";
|
|
@@ -64,7 +65,11 @@ export class DboBuilder {
|
|
|
64
65
|
db: DB;
|
|
65
66
|
|
|
66
67
|
dbo: DBHandlerServer;
|
|
67
|
-
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Undefined if cannot create table triggers
|
|
71
|
+
*/
|
|
72
|
+
private _pubSubManager?: PubSubManager;
|
|
68
73
|
|
|
69
74
|
/**
|
|
70
75
|
* Used for db.sql field type details
|
|
@@ -85,24 +90,12 @@ export class DboBuilder {
|
|
|
85
90
|
|
|
86
91
|
getPubSubManager = async (): Promise<PubSubManager> => {
|
|
87
92
|
if (!this._pubSubManager) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (!canEXECUTE) throw "PubSubManager based subscriptions not possible: Cannot run EXECUTE statements on this connection";
|
|
92
|
-
|
|
93
|
-
if (this.prostgles.opts.watchSchema && this.prostgles.opts.watchSchemaType === "DDL_trigger") {
|
|
94
|
-
if (!isSuperUs) {
|
|
95
|
-
console.warn(`watchSchemaType "${this.prostgles.opts.watchSchemaType}" cannot be used because db user is not a superuser. Will fallback to watchSchemaType "prostgles_queries" `)
|
|
96
|
-
} else {
|
|
97
|
-
onSchemaChange = (event: { command: string; query: string }) => {
|
|
98
|
-
this.prostgles.onSchemaChange(event)
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
93
|
+
|
|
94
|
+
const canExecute = await getCanExecute(this.db)
|
|
95
|
+
if (!canExecute) throw "PubSubManager based subscriptions not possible: Cannot run EXECUTE statements on this connection";
|
|
102
96
|
|
|
103
97
|
this._pubSubManager = await PubSubManager.create({
|
|
104
98
|
dboBuilder: this,
|
|
105
|
-
onSchemaChange
|
|
106
99
|
});
|
|
107
100
|
}
|
|
108
101
|
if (!this._pubSubManager) {
|
|
@@ -132,12 +125,10 @@ export class DboBuilder {
|
|
|
132
125
|
|
|
133
126
|
private init = async () => {
|
|
134
127
|
|
|
135
|
-
/* If watchSchema is enabled then PubSubManager must be created (if possible) */
|
|
136
128
|
await this.build();
|
|
129
|
+
/* If watchSchema is enabled then PubSubManager must be created (if possible) because it creates the event trigger */
|
|
137
130
|
if (
|
|
138
|
-
this.prostgles.
|
|
139
|
-
(this.prostgles.opts.watchSchemaType === "DDL_trigger" || !this.prostgles.opts.watchSchemaType) &&
|
|
140
|
-
this.prostgles.isSuperUser
|
|
131
|
+
this.prostgles.schemaWatch?.type.watchType === "DDL_trigger"
|
|
141
132
|
) {
|
|
142
133
|
await this.getPubSubManager()
|
|
143
134
|
}
|
|
@@ -5,9 +5,9 @@ import { DB } from "../initProstgles";
|
|
|
5
5
|
import { DboBuilder } from "./DboBuilder";
|
|
6
6
|
import { PRGLIOSocket } from "./DboBuilderTypes";
|
|
7
7
|
import { getErrorAsObject, getSerializedClientErrorFromPGError } from "./dboBuilderUtils";
|
|
8
|
-
import { getDetailedFieldInfo
|
|
8
|
+
import { getDetailedFieldInfo } from "./runSQL";
|
|
9
9
|
import CursorType from 'pg-cursor'
|
|
10
|
-
import { VoidFunction } from "../SchemaWatch";
|
|
10
|
+
import { VoidFunction, watchSchemaFallback } from "../SchemaWatch/SchemaWatch";
|
|
11
11
|
const Cursor: typeof CursorType = require('pg-cursor');
|
|
12
12
|
|
|
13
13
|
type ClientStreamedRequest = {
|
|
@@ -180,7 +180,7 @@ export const prepareOrderByQuery = (items: SortItem[], tableAlias?: string): str
|
|
|
180
180
|
}).join(", ")]
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
-
export const
|
|
183
|
+
export const getCanExecute = async (db: DB) => {
|
|
184
184
|
|
|
185
185
|
try {
|
|
186
186
|
await db.any(`DO $$ BEGIN EXECUTE 'select 1'; END $$;`);
|
package/lib/DboBuilder/runSQL.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ParameterizedQuery as PQ, ParameterizedQuery } from 'pg-promise';
|
|
2
2
|
import pg from "pg-promise/typescript/pg-subset";
|
|
3
3
|
import { AnyObject, SQLOptions, SQLResult, SQLResultInfo } from "prostgles-types";
|
|
4
|
-
import { EVENT_TRIGGER_TAGS } from "../Event_Trigger_Tags";
|
|
5
4
|
import { DB, Prostgles } from "../Prostgles";
|
|
6
5
|
import { DboBuilder, LocalParams, pgp, postgresToTsType } from "./DboBuilder";
|
|
6
|
+
import { watchSchemaFallback } from "../SchemaWatch/SchemaWatch";
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
export async function runSQL(this: DboBuilder, queryWithoutRLS: string, args: undefined | AnyObject | any[], options: SQLOptions | undefined, localParams?: LocalParams) {
|
|
@@ -102,23 +102,6 @@ const onSQLResult = async function(this: DboBuilder, queryWithoutRLS: string, {
|
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
/**
|
|
106
|
-
* Fallback for watchSchema in case of not a superuser (cannot add db event listener)
|
|
107
|
-
*/
|
|
108
|
-
export const watchSchemaFallback = async function(this: DboBuilder, { queryWithoutRLS, command }: { queryWithoutRLS: string; command: string; }){
|
|
109
|
-
const SCHEMA_ALTERING_COMMANDS = EVENT_TRIGGER_TAGS;// ["CREATE", "ALTER", "DROP", "REVOKE", "GRANT"];
|
|
110
|
-
const isNotPickedUpByDDLTrigger = ["REVOKE", "GRANT"].includes(command);
|
|
111
|
-
const { watchSchema, watchSchemaType } = this.prostgles?.opts || {};
|
|
112
|
-
if (
|
|
113
|
-
watchSchema &&
|
|
114
|
-
(!this.prostgles.isSuperUser || watchSchemaType === "prostgles_queries" || isNotPickedUpByDDLTrigger)
|
|
115
|
-
) {
|
|
116
|
-
if (SCHEMA_ALTERING_COMMANDS.includes(command as any)) {
|
|
117
|
-
this.prostgles.onSchemaChange({ command, query: queryWithoutRLS })
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
105
|
export async function cacheDBTypes(this: DboBuilder) {
|
|
123
106
|
this.DATA_TYPES ??= await this.db.any("SELECT oid, typname FROM pg_type") ?? [];
|
|
124
107
|
this.USER_TABLES ??= await this.db.any(`
|
package/lib/Prostgles.ts
CHANGED
|
@@ -7,7 +7,7 @@ import * as pgPromise from 'pg-promise';
|
|
|
7
7
|
import AuthHandler, { Auth, AuthRequestParams, SessionUser } from "./AuthHandler";
|
|
8
8
|
import { EventTriggerTagFilter } from "./Event_Trigger_Tags";
|
|
9
9
|
import { CloudClient, FileManager, ImageOptions, LocalConfig } from "./FileManager/FileManager";
|
|
10
|
-
import { SchemaWatch } from "./SchemaWatch";
|
|
10
|
+
import { SchemaWatch } from "./SchemaWatch/SchemaWatch";
|
|
11
11
|
import { DbConnection, DbConnectionOpts, OnInitReason, OnReadyCallback, OnReadyCallbackBasic, initProstgles } from "./initProstgles";
|
|
12
12
|
import { clientCanRunSqlRequest, runClientMethod, runClientRequest, runClientSqlRequest } from "./runClientRequest";
|
|
13
13
|
import pg = require('pg-promise/typescript/pg-subset');
|
|
@@ -124,6 +124,7 @@ export type FileTableConfig = {
|
|
|
124
124
|
imageOptions?: ImageOptions
|
|
125
125
|
};
|
|
126
126
|
|
|
127
|
+
export type OnSchemaChangeCallback = ((event: { command: string; query: string }) => void);
|
|
127
128
|
|
|
128
129
|
export type ProstglesInitOptions<S = void, SUser extends SessionUser = SessionUser> = {
|
|
129
130
|
dbConnection: DbConnection;
|
|
@@ -160,11 +161,6 @@ export type ProstglesInitOptions<S = void, SUser extends SessionUser = SessionUs
|
|
|
160
161
|
*/
|
|
161
162
|
| "prostgles_queries"
|
|
162
163
|
|
|
163
|
-
/**
|
|
164
|
-
* Schema checked for changes every 'checkIntervalMillis" milliseconds
|
|
165
|
-
*/
|
|
166
|
-
| { checkIntervalMillis: number };
|
|
167
|
-
|
|
168
164
|
/**
|
|
169
165
|
* If truthy then DBoGenerated.d.ts will be updated and "onReady" will be called with new schema on both client and server
|
|
170
166
|
*/
|
|
@@ -188,7 +184,7 @@ export type ProstglesInitOptions<S = void, SUser extends SessionUser = SessionUs
|
|
|
188
184
|
/**
|
|
189
185
|
* Function called when schema changes. Nothing else triggered
|
|
190
186
|
*/
|
|
191
|
-
|
|
|
187
|
+
| OnSchemaChangeCallback;
|
|
192
188
|
|
|
193
189
|
keywords?: Keywords;
|
|
194
190
|
onNotice?: (notice: AnyObject, message?: string) => void;
|
|
@@ -270,7 +266,10 @@ export class Prostgles {
|
|
|
270
266
|
dbo?: DBHandlerServer;
|
|
271
267
|
_dboBuilder?: DboBuilder;
|
|
272
268
|
get dboBuilder(): DboBuilder {
|
|
273
|
-
if (!this._dboBuilder)
|
|
269
|
+
if (!this._dboBuilder) {
|
|
270
|
+
console.trace(1)
|
|
271
|
+
throw "get dboBuilder: it's undefined";
|
|
272
|
+
}
|
|
274
273
|
return this._dboBuilder;
|
|
275
274
|
}
|
|
276
275
|
set dboBuilder(d: DboBuilder) {
|
|
@@ -329,37 +328,6 @@ export class Prostgles {
|
|
|
329
328
|
|
|
330
329
|
destroyed = false;
|
|
331
330
|
|
|
332
|
-
async onSchemaChange(event: { command: string; query: string }) {
|
|
333
|
-
const { watchSchema, watchSchemaType, onReady, tsGeneratedTypesDir } = this.opts;
|
|
334
|
-
if (watchSchema && this.loaded) {
|
|
335
|
-
log("Schema changed");
|
|
336
|
-
const { query, command } = event;
|
|
337
|
-
if (typeof query === "string" && query.includes(PubSubManager.EXCLUDE_QUERY_FROM_SCHEMA_WATCH_ID)) {
|
|
338
|
-
log("Schema change event excluded from triggers due to EXCLUDE_QUERY_FROM_SCHEMA_WATCH_ID");
|
|
339
|
-
return;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
if (typeof watchSchema === "function") {
|
|
343
|
-
/* Only call the provided func */
|
|
344
|
-
watchSchema(event);
|
|
345
|
-
|
|
346
|
-
} else if (watchSchema === "hotReloadMode") {
|
|
347
|
-
if (tsGeneratedTypesDir) {
|
|
348
|
-
/* Hot reload integration. Will only touch tsGeneratedTypesDir */
|
|
349
|
-
console.log("watchSchema: Re-writing TS schema");
|
|
350
|
-
|
|
351
|
-
await this.refreshDBO();
|
|
352
|
-
this.writeDBSchema(true);
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
} else if (watchSchema || isObject(watchSchemaType) && "checkIntervalMillis" in watchSchemaType) {
|
|
356
|
-
/* Full re-init. Sockets must reconnect */
|
|
357
|
-
console.log("watchSchema: Full re-initialisation", { query })
|
|
358
|
-
this.init(onReady as any, { type: "schema change", query, command });
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
|
|
363
331
|
checkDb() {
|
|
364
332
|
if (!this.db || !this.db.connect) throw "something went wrong getting a db connection";
|
|
365
333
|
}
|
|
@@ -429,34 +397,6 @@ export class Prostgles {
|
|
|
429
397
|
return this.dbo;
|
|
430
398
|
}
|
|
431
399
|
|
|
432
|
-
initWatchSchema = (onReady: OnReadyCallbackBasic) => {
|
|
433
|
-
|
|
434
|
-
if (this.opts.watchSchema === "hotReloadMode" && !this.opts.tsGeneratedTypesDir) {
|
|
435
|
-
throw "tsGeneratedTypesDir option is needed for watchSchema: hotReloadMode to work ";
|
|
436
|
-
} else if (
|
|
437
|
-
this.opts.watchSchema &&
|
|
438
|
-
typeof this.opts.watchSchemaType === "object" &&
|
|
439
|
-
"checkIntervalMillis" in this.opts.watchSchemaType &&
|
|
440
|
-
typeof this.opts.watchSchemaType.checkIntervalMillis === "number"
|
|
441
|
-
) {
|
|
442
|
-
|
|
443
|
-
if (this.schema_checkIntervalMillis) {
|
|
444
|
-
clearInterval(this.schema_checkIntervalMillis);
|
|
445
|
-
}
|
|
446
|
-
this.schema_checkIntervalMillis = setInterval(async () => {
|
|
447
|
-
if(!this.loaded) return;
|
|
448
|
-
const dbuilder = await DboBuilder.create(this);
|
|
449
|
-
if (dbuilder.tsTypesDefinition !== this.dboBuilder.tsTypesDefinition) {
|
|
450
|
-
await this.refreshDBO();
|
|
451
|
-
const reason: OnInitReason = { type: "schema change", command: "", query: "schema_checkIntervalMillis tsTypesDefinition changed" }
|
|
452
|
-
this.init(onReady, reason);
|
|
453
|
-
}
|
|
454
|
-
}, this.opts.watchSchemaType.checkIntervalMillis);
|
|
455
|
-
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
}
|
|
459
|
-
|
|
460
400
|
initRestApi = async () => {
|
|
461
401
|
if (this.opts.restApi) {
|
|
462
402
|
this.restApi = new RestApi({ prostgles: this, ...this.opts.restApi });
|
|
@@ -526,7 +466,6 @@ export class Prostgles {
|
|
|
526
466
|
}
|
|
527
467
|
|
|
528
468
|
isSuperUser = false;
|
|
529
|
-
schema_checkIntervalMillis?: NodeJS.Timeout;
|
|
530
469
|
|
|
531
470
|
init = initProstgles.bind(this);
|
|
532
471
|
|
|
@@ -787,6 +726,6 @@ type SocketMethodRequest = {
|
|
|
787
726
|
}
|
|
788
727
|
|
|
789
728
|
|
|
790
|
-
export async function
|
|
729
|
+
export async function getIsSuperUser(db: DB): Promise<boolean> {
|
|
791
730
|
return db.oneOrNone("select usesuper from pg_user where usename = CURRENT_USER;").then(r => r.usesuper);
|
|
792
731
|
}
|