prostgles-server 4.2.44 → 4.2.46
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/PubSubManager/getInitQuery.d.ts.map +1 -1
- package/dist/PubSubManager/getInitQuery.js +6 -4
- package/dist/PubSubManager/getInitQuery.js.map +1 -1
- package/dist/SchemaWatch/SchemaWatch.d.ts.map +1 -1
- package/dist/SchemaWatch/SchemaWatch.js +7 -6
- package/dist/SchemaWatch/SchemaWatch.js.map +1 -1
- package/dist/SchemaWatch/getValidatedWatchSchemaType.js +3 -3
- package/dist/SchemaWatch/getValidatedWatchSchemaType.js.map +1 -1
- package/lib/PubSubManager/getInitQuery.ts +6 -4
- package/lib/SchemaWatch/SchemaWatch.ts +9 -7
- package/lib/SchemaWatch/createSchemaWatchEventTrigger.ts +3 -0
- package/lib/SchemaWatch/getValidatedWatchSchemaType.ts +3 -3
- package/package.json +1 -1
- package/tests/client/renderReactHook.ts +6 -4
- package/tests/client/useProstgles.spec.ts +36 -28
- package/tests/server/package-lock.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getInitQuery.d.ts","sourceRoot":"","sources":["../../lib/PubSubManager/getInitQuery.ts"],"names":[],"mappings":"AACA,OAAO,EAAsC,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGpF,eAAO,MAAM,YAAY;;;;;CAKf,CAAC;AAEX,eAAO,MAAM,YAAY,SAAwB,aAAa,KAAG,QAAQ,MAAM,
|
|
1
|
+
{"version":3,"file":"getInitQuery.d.ts","sourceRoot":"","sources":["../../lib/PubSubManager/getInitQuery.ts"],"names":[],"mappings":"AACA,OAAO,EAAsC,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGpF,eAAO,MAAM,YAAY;;;;;CAKf,CAAC;AAEX,eAAO,MAAM,YAAY,SAAwB,aAAa,KAAG,QAAQ,MAAM,CA0jB9E,CAAA"}
|
|
@@ -492,7 +492,7 @@ BEGIN
|
|
|
492
492
|
json_build_object(
|
|
493
493
|
'TG_OP', TG_OP,
|
|
494
494
|
'duration', (EXTRACT(EPOCH FROM now()) * 1000) - start_time,
|
|
495
|
-
'query', LEFT(current_query(), 400)
|
|
495
|
+
'query', ${this.dboBuilder.prostgles.opts.DEBUG_MODE ? 'LEFT(current_query(), 400)' : "'Only shown in debug mode'"}
|
|
496
496
|
)
|
|
497
497
|
)::TEXT, 7999/4)
|
|
498
498
|
);
|
|
@@ -524,8 +524,6 @@ BEGIN
|
|
|
524
524
|
DECLARE app RECORD;
|
|
525
525
|
|
|
526
526
|
BEGIN
|
|
527
|
-
|
|
528
|
-
--RAISE NOTICE 'SCHEMA_WATCH: %', tg_tag;
|
|
529
527
|
|
|
530
528
|
/*
|
|
531
529
|
This event trigger will outlive a prostgles app instance.
|
|
@@ -547,12 +545,16 @@ BEGIN
|
|
|
547
545
|
SELECT *
|
|
548
546
|
FROM prostgles.apps
|
|
549
547
|
WHERE tg_tag = ANY(watching_schema_tag_names)
|
|
548
|
+
AND curr_query NOT ILIKE '%${PubSubManager_1.PubSubManager.EXCLUDE_QUERY_FROM_SCHEMA_WATCH_ID}%'
|
|
550
549
|
LOOP
|
|
551
550
|
PERFORM pg_notify(
|
|
552
551
|
${(0, PubSubManager_1.asValue)(PubSubManager_1.NOTIF_CHANNEL.preffix)} || app.id,
|
|
553
552
|
LEFT(concat_ws(
|
|
554
553
|
${(0, PubSubManager_1.asValue)(PubSubManager_1.PubSubManager.DELIMITER)},
|
|
555
|
-
${(0, PubSubManager_1.asValue)(PubSubManager_1.NOTIF_TYPE.schema)},
|
|
554
|
+
${(0, PubSubManager_1.asValue)(PubSubManager_1.NOTIF_TYPE.schema)},
|
|
555
|
+
tg_tag ,
|
|
556
|
+
TG_event,
|
|
557
|
+
${this.dboBuilder.prostgles.opts.DEBUG_MODE ? 'curr_query' : "'Only shown in debug mode'"}
|
|
556
558
|
), 7999/4)
|
|
557
559
|
);
|
|
558
560
|
END LOOP;
|
|
@@ -1 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;AACb,CAAC,CAAA;AA1jBY,QAAA,YAAY,gBA0jBxB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaWatch.d.ts","sourceRoot":"","sources":["../../lib/SchemaWatch/SchemaWatch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAE3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEtD,OAAO,EAAE,wBAAwB,EAA+B,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"SchemaWatch.d.ts","sourceRoot":"","sources":["../../lib/SchemaWatch/SchemaWatch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAE3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEtD,OAAO,EAAE,wBAAwB,EAA+B,MAAM,+BAA+B,CAAC;AAOtG,MAAM,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC;AAEtC,qBAAa,WAAW;IAEtB,UAAU,EAAE,UAAU,CAAC;IACvB,IAAI,EAAE,wBAAwB,CAAC;IAC/B,OAAO;IAYP,MAAM,CAAC,MAAM,eAAsB,UAAU,0BAO5C;IAED;;OAEG;IACH,sBAAsB,EAAE,sBAAsB,GAAG,SAAS,CAazD;IAED,cAAc,EAAE,sBAAsB,GAAG,SAAS,CA0BhD;CACH"}
|
|
@@ -5,8 +5,8 @@ const Event_Trigger_Tags_1 = require("../Event_Trigger_Tags");
|
|
|
5
5
|
const PubSubManager_1 = require("../PubSubManager/PubSubManager");
|
|
6
6
|
const getValidatedWatchSchemaType_1 = require("./getValidatedWatchSchemaType");
|
|
7
7
|
const COMMAND_FIRST_KEYWORDS = Event_Trigger_Tags_1.EVENT_TRIGGER_TAGS
|
|
8
|
-
.map(tag => tag.split(" ")[0])
|
|
9
|
-
.
|
|
8
|
+
.map(tag => tag.split(" ")[0])
|
|
9
|
+
.filter(tag => tag !== "SELECT"); /** SELECT INTO is not easily detectable with pg-node (command = "SELECT") */
|
|
10
10
|
const DB_FALLBACK_COMMANDS = Array.from(new Set(COMMAND_FIRST_KEYWORDS));
|
|
11
11
|
class SchemaWatch {
|
|
12
12
|
dboBuilder;
|
|
@@ -26,6 +26,7 @@ class SchemaWatch {
|
|
|
26
26
|
const instance = new SchemaWatch(dboBuilder);
|
|
27
27
|
if (instance.type.watchType === "DDL_trigger") {
|
|
28
28
|
await dboBuilder.getPubSubManager();
|
|
29
|
+
// TODO finish createSchemaWatchEventTrigger to ensure the query is not used in NOTIFY and exclude happens inside Postgres
|
|
29
30
|
}
|
|
30
31
|
return instance;
|
|
31
32
|
};
|
|
@@ -33,6 +34,10 @@ class SchemaWatch {
|
|
|
33
34
|
* Fallback for watchSchema in case of not a superuser (cannot add db event listener)
|
|
34
35
|
*/
|
|
35
36
|
onSchemaChangeFallback = async ({ command, query }) => {
|
|
37
|
+
if (typeof query === "string" && query.includes(PubSubManager_1.PubSubManager.EXCLUDE_QUERY_FROM_SCHEMA_WATCH_ID)) {
|
|
38
|
+
(0, PubSubManager_1.log)("Schema change event excluded from triggers due to EXCLUDE_QUERY_FROM_SCHEMA_WATCH_ID");
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
36
41
|
if (this.type.watchType !== "prostgles_queries" ||
|
|
37
42
|
!this.onSchemaChange ||
|
|
38
43
|
!DB_FALLBACK_COMMANDS.includes(command))
|
|
@@ -44,10 +49,6 @@ class SchemaWatch {
|
|
|
44
49
|
if (watchSchema && this.dboBuilder.prostgles.loaded) {
|
|
45
50
|
(0, PubSubManager_1.log)("Schema changed");
|
|
46
51
|
const { query, command } = event;
|
|
47
|
-
if (typeof query === "string" && query.includes(PubSubManager_1.PubSubManager.EXCLUDE_QUERY_FROM_SCHEMA_WATCH_ID)) {
|
|
48
|
-
(0, PubSubManager_1.log)("Schema change event excluded from triggers due to EXCLUDE_QUERY_FROM_SCHEMA_WATCH_ID");
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
52
|
if (typeof watchSchema === "function") {
|
|
52
53
|
/* Only call the provided func */
|
|
53
54
|
watchSchema(event);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaWatch.js","sourceRoot":"","sources":["../../lib/SchemaWatch/SchemaWatch.ts"],"names":[],"mappings":";;;AACA,8DAA2D;AAE3D,kEAAoE;AACpE,+EAAsG;AACtG,MAAM,sBAAsB,GAAG,uCAAkB;KAC9C,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"SchemaWatch.js","sourceRoot":"","sources":["../../lib/SchemaWatch/SchemaWatch.ts"],"names":[],"mappings":";;;AACA,8DAA2D;AAE3D,kEAAoE;AACpE,+EAAsG;AACtG,MAAM,sBAAsB,GAAG,uCAAkB;KAC9C,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,CAAC;KAC9B,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,8EAA8E;AAElH,MAAM,oBAAoB,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,sBAAsB,CAAC,CAAC,CAAC;AAIzE,MAAa,WAAW;IAEtB,UAAU,CAAa;IACvB,IAAI,CAA2B;IAC/B,YAAoB,UAAsB;QACxC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAA,yDAA2B,EAAC,UAAU,CAAC,CAAC;QACpD,IAAG,IAAI,CAAC,IAAI,CAAC,SAAS,KAAK,MAAM,EAAE,CAAC;YAClC,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC;YAChC,IAAI,CAAC,sBAAsB,GAAG,SAAS,CAAC;QAC1C,CAAC;Q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MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;YAEjC,IAAI,OAAO,WAAW,KAAK,UAAU,EAAE,CAAC;gBACtC,iCAAiC;gBACjC,WAAW,CAAC,KAAK,CAAC,CAAC;YAErB,CAAC;iBAAM,IAAI,WAAW,KAAK,eAAe,EAAE,CAAC;gBAC3C,IAAI,mBAAmB,EAAE,CAAC;oBACxB,iEAAiE;oBACjE,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;oBAEjD,MAAM,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,UAAU,EAAE,CAAC;oBAC7C,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;gBAChD,CAAC;YAEH,CAAC;iBAAM,IAAI,WAAW,EAAE,CAAC;gBACvB,0CAA0C;gBAC1C,OAAO,CAAC,GAAG,CAAC,qCAAqC,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;gBAC7D,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,OAAc,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;YAC5F,CAAC;QACH,CAAC;IACH,CAAC,CAAC;;AArEJ,kCAsEC"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getValidatedWatchSchemaType = void 0;
|
|
4
4
|
const getValidatedWatchSchemaType = (dboBuilder) => {
|
|
5
|
-
const { watchSchema, watchSchemaType, tsGeneratedTypesDir } = dboBuilder.prostgles.opts;
|
|
5
|
+
const { watchSchema, watchSchemaType, tsGeneratedTypesDir, disableRealtime } = dboBuilder.prostgles.opts;
|
|
6
6
|
if (!watchSchema)
|
|
7
7
|
return { watchType: "NONE" };
|
|
8
8
|
if (watchSchema === "hotReloadMode" && !tsGeneratedTypesDir) {
|
|
@@ -10,12 +10,12 @@ const getValidatedWatchSchemaType = (dboBuilder) => {
|
|
|
10
10
|
}
|
|
11
11
|
const onChange = typeof watchSchema === "function" ? watchSchema : undefined;
|
|
12
12
|
if (watchSchemaType === "DDL_trigger" || !watchSchemaType) {
|
|
13
|
-
if (!dboBuilder.prostgles.isSuperUser) {
|
|
13
|
+
if (!dboBuilder.prostgles.isSuperUser || disableRealtime) {
|
|
14
14
|
if (watchSchemaType === "DDL_trigger") {
|
|
15
15
|
console.error(`watchSchemaType "DDL_trigger" cannot be used because db user is not a superuser. Will fallback to watchSchemaType "prostgles_queries" `);
|
|
16
16
|
}
|
|
17
17
|
else {
|
|
18
|
-
console.warn(`watchSchema fallback to watchSchemaType "prostgles_queries" due to non-superuser`);
|
|
18
|
+
console.warn(`watchSchema fallback to watchSchemaType "prostgles_queries" due to ${disableRealtime ? "disableRealtime setting" : "non-superuser"}`);
|
|
19
19
|
}
|
|
20
20
|
return {
|
|
21
21
|
watchType: "prostgles_queries",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getValidatedWatchSchemaType.js","sourceRoot":"","sources":["../../lib/SchemaWatch/getValidatedWatchSchemaType.ts"],"names":[],"mappings":";;;AAQO,MAAM,2BAA2B,GAAG,CAAC,UAAsB,EAA4B,EAAE;IAC9F,MAAM,EAAC,WAAW,EAAE,eAAe,EAAE,mBAAmB,
|
|
1
|
+
{"version":3,"file":"getValidatedWatchSchemaType.js","sourceRoot":"","sources":["../../lib/SchemaWatch/getValidatedWatchSchemaType.ts"],"names":[],"mappings":";;;AAQO,MAAM,2BAA2B,GAAG,CAAC,UAAsB,EAA4B,EAAE;IAC9F,MAAM,EAAC,WAAW,EAAE,eAAe,EAAE,mBAAmB,EAAE,eAAe,EAAE,GAAG,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC;IACxG,IAAG,CAAC,WAAW;QAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;IAE9C,IAAI,WAAW,KAAK,eAAe,IAAI,CAAC,mBAAmB,EAAE,CAAC;QAC5D,MAAM,8EAA8E,CAAC;IACvF,CAAC;IAED,MAAM,QAAQ,GAAG,OAAO,WAAW,KAAK,UAAU,CAAA,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC;IAE5E,IAAG,eAAe,KAAK,aAAa,IAAI,CAAC,eAAe,EAAC,CAAC;QACxD,IAAG,CAAC,UAAU,CAAC,SAAS,CAAC,WAAW,IAAI,eAAe,EAAC,CAAC;YAEvD,IAAG,eAAe,KAAK,aAAa,EAAC,CAAC;gBACpC,OAAO,CAAC,KAAK,CAAC,wIAAwI,CAAC,CAAA;YACzJ,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,IAAI,CAAC,sEAAsE,eAAe,CAAA,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC,CAAA;YACpJ,CAAC;YACD,OAAO;gBACL,SAAS,EAAE,mBAAmB;gBAC9B,QAAQ;gBACR,iBAAiB,EAAE,IAAI;aACxB,CAAA;QACH,CAAC;QAED,OAAO;YACL,SAAS,EAAE,aAAa;YACxB,QAAQ;SACT,CAAC;IACJ,CAAC;IAED,OAAO;QACL,SAAS,EAAE,eAAe;QAC1B,iBAAiB,EAAE,KAAK;QACxB,QAAQ;KACT,CAAA;AACH,CAAC,CAAA;AApCY,QAAA,2BAA2B,+BAoCvC"}
|
|
@@ -494,7 +494,7 @@ BEGIN
|
|
|
494
494
|
json_build_object(
|
|
495
495
|
'TG_OP', TG_OP,
|
|
496
496
|
'duration', (EXTRACT(EPOCH FROM now()) * 1000) - start_time,
|
|
497
|
-
'query', LEFT(current_query(), 400)
|
|
497
|
+
'query', ${this.dboBuilder.prostgles.opts.DEBUG_MODE? 'LEFT(current_query(), 400)' : "'Only shown in debug mode'"}
|
|
498
498
|
)
|
|
499
499
|
)::TEXT, 7999/4)
|
|
500
500
|
);
|
|
@@ -526,8 +526,6 @@ BEGIN
|
|
|
526
526
|
DECLARE app RECORD;
|
|
527
527
|
|
|
528
528
|
BEGIN
|
|
529
|
-
|
|
530
|
-
--RAISE NOTICE 'SCHEMA_WATCH: %', tg_tag;
|
|
531
529
|
|
|
532
530
|
/*
|
|
533
531
|
This event trigger will outlive a prostgles app instance.
|
|
@@ -549,12 +547,16 @@ BEGIN
|
|
|
549
547
|
SELECT *
|
|
550
548
|
FROM prostgles.apps
|
|
551
549
|
WHERE tg_tag = ANY(watching_schema_tag_names)
|
|
550
|
+
AND curr_query NOT ILIKE '%${PubSubManager.EXCLUDE_QUERY_FROM_SCHEMA_WATCH_ID}%'
|
|
552
551
|
LOOP
|
|
553
552
|
PERFORM pg_notify(
|
|
554
553
|
${asValue(NOTIF_CHANNEL.preffix)} || app.id,
|
|
555
554
|
LEFT(concat_ws(
|
|
556
555
|
${asValue(PubSubManager.DELIMITER)},
|
|
557
|
-
${asValue(NOTIF_TYPE.schema)},
|
|
556
|
+
${asValue(NOTIF_TYPE.schema)},
|
|
557
|
+
tg_tag ,
|
|
558
|
+
TG_event,
|
|
559
|
+
${this.dboBuilder.prostgles.opts.DEBUG_MODE? 'curr_query' : "'Only shown in debug mode'"}
|
|
558
560
|
), 7999/4)
|
|
559
561
|
);
|
|
560
562
|
END LOOP;
|
|
@@ -4,8 +4,9 @@ import { OnSchemaChangeCallback } from "../Prostgles";
|
|
|
4
4
|
import { PubSubManager, log } from "../PubSubManager/PubSubManager";
|
|
5
5
|
import { ValidatedWatchSchemaType, getValidatedWatchSchemaType } from "./getValidatedWatchSchemaType";
|
|
6
6
|
const COMMAND_FIRST_KEYWORDS = EVENT_TRIGGER_TAGS
|
|
7
|
-
.map(tag => tag.split(" ")[0]!)
|
|
8
|
-
.
|
|
7
|
+
.map(tag => tag.split(" ")[0]!)
|
|
8
|
+
.filter(tag => tag !== "SELECT"); /** SELECT INTO is not easily detectable with pg-node (command = "SELECT") */
|
|
9
|
+
|
|
9
10
|
const DB_FALLBACK_COMMANDS = Array.from(new Set(COMMAND_FIRST_KEYWORDS));
|
|
10
11
|
|
|
11
12
|
export type VoidFunction = () => void;
|
|
@@ -29,7 +30,8 @@ export class SchemaWatch {
|
|
|
29
30
|
static create = async (dboBuilder: DboBuilder) => {
|
|
30
31
|
const instance = new SchemaWatch(dboBuilder);
|
|
31
32
|
if(instance.type.watchType === "DDL_trigger") {
|
|
32
|
-
await dboBuilder.getPubSubManager()
|
|
33
|
+
await dboBuilder.getPubSubManager();
|
|
34
|
+
// TODO finish createSchemaWatchEventTrigger to ensure the query is not used in NOTIFY and exclude happens inside Postgres
|
|
33
35
|
}
|
|
34
36
|
return instance;
|
|
35
37
|
}
|
|
@@ -39,6 +41,10 @@ export class SchemaWatch {
|
|
|
39
41
|
*/
|
|
40
42
|
onSchemaChangeFallback: OnSchemaChangeCallback | undefined = async ({ command, query }) => {
|
|
41
43
|
|
|
44
|
+
if (typeof query === "string" && query.includes(PubSubManager.EXCLUDE_QUERY_FROM_SCHEMA_WATCH_ID)) {
|
|
45
|
+
log("Schema change event excluded from triggers due to EXCLUDE_QUERY_FROM_SCHEMA_WATCH_ID");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
42
48
|
if(
|
|
43
49
|
this.type.watchType !== "prostgles_queries" ||
|
|
44
50
|
!this.onSchemaChange ||
|
|
@@ -54,10 +60,6 @@ export class SchemaWatch {
|
|
|
54
60
|
if (watchSchema && this.dboBuilder.prostgles.loaded) {
|
|
55
61
|
log("Schema changed");
|
|
56
62
|
const { query, command } = event;
|
|
57
|
-
if (typeof query === "string" && query.includes(PubSubManager.EXCLUDE_QUERY_FROM_SCHEMA_WATCH_ID)) {
|
|
58
|
-
log("Schema change event excluded from triggers due to EXCLUDE_QUERY_FROM_SCHEMA_WATCH_ID");
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
63
|
|
|
62
64
|
if (typeof watchSchema === "function") {
|
|
63
65
|
/* Only call the provided func */
|
|
@@ -7,7 +7,7 @@ export type ValidatedWatchSchemaType =
|
|
|
7
7
|
| { watchType: "prostgles_queries"; onChange?: OnSchemaChangeCallback; isFallbackFromDDL: boolean; }
|
|
8
8
|
|
|
9
9
|
export const getValidatedWatchSchemaType = (dboBuilder: DboBuilder): ValidatedWatchSchemaType => {
|
|
10
|
-
const {watchSchema, watchSchemaType, tsGeneratedTypesDir} = dboBuilder.prostgles.opts;
|
|
10
|
+
const {watchSchema, watchSchemaType, tsGeneratedTypesDir, disableRealtime } = dboBuilder.prostgles.opts;
|
|
11
11
|
if(!watchSchema) return { watchType: "NONE" };
|
|
12
12
|
|
|
13
13
|
if (watchSchema === "hotReloadMode" && !tsGeneratedTypesDir) {
|
|
@@ -17,12 +17,12 @@ export const getValidatedWatchSchemaType = (dboBuilder: DboBuilder): ValidatedWa
|
|
|
17
17
|
const onChange = typeof watchSchema === "function"? watchSchema : undefined;
|
|
18
18
|
|
|
19
19
|
if(watchSchemaType === "DDL_trigger" || !watchSchemaType){
|
|
20
|
-
if(!dboBuilder.prostgles.isSuperUser){
|
|
20
|
+
if(!dboBuilder.prostgles.isSuperUser || disableRealtime){
|
|
21
21
|
|
|
22
22
|
if(watchSchemaType === "DDL_trigger"){
|
|
23
23
|
console.error(`watchSchemaType "DDL_trigger" cannot be used because db user is not a superuser. Will fallback to watchSchemaType "prostgles_queries" `)
|
|
24
24
|
} else {
|
|
25
|
-
console.warn(`watchSchema fallback to watchSchemaType "prostgles_queries" due to non-superuser`)
|
|
25
|
+
console.warn(`watchSchema fallback to watchSchemaType "prostgles_queries" due to ${disableRealtime? "disableRealtime setting" : "non-superuser"}`)
|
|
26
26
|
}
|
|
27
27
|
return {
|
|
28
28
|
watchType: "prostgles_queries",
|
package/package.json
CHANGED
|
@@ -75,20 +75,22 @@ export const renderReactHookManual = async <H extends Hook>(rootArgs: {
|
|
|
75
75
|
*/
|
|
76
76
|
renderDuration?: number;
|
|
77
77
|
onEnd?: OnEnd<H>;
|
|
78
|
+
onRender?: OnEnd<H>;
|
|
78
79
|
}): Promise<{
|
|
79
80
|
setProps: (props: Parameters<H>, opts: { waitFor?: number; onEnd?: OnEnd<H>; }) => void;
|
|
80
81
|
getResults: () => ReturnType<H>[];
|
|
81
82
|
}> => {
|
|
82
|
-
const { hook, onUnmount, renderDuration = 250, onEnd } = rootArgs;
|
|
83
|
+
const { hook, onUnmount, renderDuration = 250, onEnd, onRender } = rootArgs;
|
|
83
84
|
let lastRenderWaitTimeout: NodeJS.Timeout | null = null;
|
|
84
85
|
let didResolve = false;
|
|
85
86
|
let setProps: (props: any[]) => void;
|
|
86
87
|
resetBasicComponent();
|
|
87
88
|
return new Promise((resolve, reject) => {
|
|
88
89
|
const results = [];
|
|
89
|
-
const
|
|
90
|
+
const onCompRender = (result) => {
|
|
90
91
|
results.push(result);
|
|
91
92
|
if(didResolve) return;
|
|
93
|
+
onRender?.(results);
|
|
92
94
|
clearTimeout(lastRenderWaitTimeout);
|
|
93
95
|
lastRenderWaitTimeout = setTimeout(async () => {
|
|
94
96
|
|
|
@@ -117,7 +119,7 @@ export const renderReactHookManual = async <H extends Hook>(rootArgs: {
|
|
|
117
119
|
onUnmount?.();
|
|
118
120
|
};
|
|
119
121
|
}, []);
|
|
120
|
-
|
|
122
|
+
onCompRender(result);
|
|
121
123
|
return React.createElement('h1', null, `Hello`);
|
|
122
124
|
}
|
|
123
125
|
root.render(
|
|
@@ -166,7 +168,7 @@ export const renderReactHook = (rootArgs: RenderHookArgs): Promise<RenderResult>
|
|
|
166
168
|
});
|
|
167
169
|
setTimeout(() => {
|
|
168
170
|
if(!resolved){
|
|
169
|
-
reject(new Error(`Expected ${expectedRerenders} rerenders, got ${results.length}`));
|
|
171
|
+
reject(new Error(`Expected ${expectedRerenders} rerenders, got ${results.length}:\n${JSON.stringify(results)}`));
|
|
170
172
|
}
|
|
171
173
|
}, timeout);
|
|
172
174
|
});
|
|
@@ -7,6 +7,7 @@ import { renderReactHook, renderReactHookManual } from "./renderReactHook";
|
|
|
7
7
|
|
|
8
8
|
export const newly_created_table = "newly_created_table";
|
|
9
9
|
export const useProstglesTest = async (db: DBHandlerClient, getSocketOptions: (watchSchema?: boolean) => AnyObject) => {
|
|
10
|
+
await db.sql(`DROP TABLE IF EXISTS ${newly_created_table};`);
|
|
10
11
|
await describe("useProstgles hook", async (t) => {
|
|
11
12
|
const socketOptions = getSocketOptions();
|
|
12
13
|
await test("useProstglesClient", async (t) => {
|
|
@@ -23,42 +24,49 @@ export const useProstglesTest = async (db: DBHandlerClient, getSocketOptions: (w
|
|
|
23
24
|
typeof (res2 as any)?.dbo.items4.useFind,
|
|
24
25
|
"function"
|
|
25
26
|
);
|
|
27
|
+
assert.equal(
|
|
28
|
+
typeof (res2 as any)?.dbo[newly_created_table],
|
|
29
|
+
"undefined"
|
|
30
|
+
);
|
|
26
31
|
});
|
|
27
32
|
|
|
28
33
|
await test("useProstglesClient with schema reload", async (t) => {
|
|
29
|
-
await db.sql(`DROP TABLE IF EXISTS ${newly_created_table}; DROP TABLE IF EXISTS will_delete;`);
|
|
30
34
|
await db.sql(`select pg_sleep(1)`);
|
|
31
|
-
|
|
32
|
-
const { results: [res1, res2, res3], rerender } = await renderReactHook({
|
|
35
|
+
await renderReactHookManual({
|
|
33
36
|
hook: useProstglesClient,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if(rerenders < 2) return;
|
|
39
|
-
rerenders = -2;
|
|
37
|
+
initialProps: [{ socketOptions: getSocketOptions(true) }],
|
|
38
|
+
renderDuration: 1000,
|
|
39
|
+
onRender: async (results) => {
|
|
40
|
+
if(results.length !== 1) return;
|
|
40
41
|
db.sql(`CREATE TABLE ${newly_created_table}(id integer);`);
|
|
42
|
+
},
|
|
43
|
+
onEnd: async (results) => {
|
|
44
|
+
const [res1, res2, res3] = results;
|
|
45
|
+
assert.equal(
|
|
46
|
+
results.length, 3
|
|
47
|
+
);
|
|
48
|
+
assert.deepStrictEqual(
|
|
49
|
+
res1,
|
|
50
|
+
{ isLoading: true }
|
|
51
|
+
);
|
|
52
|
+
assert.equal(
|
|
53
|
+
res2.isLoading,
|
|
54
|
+
false
|
|
55
|
+
);
|
|
56
|
+
assert.equal(
|
|
57
|
+
typeof (res2 as any)?.dbo[newly_created_table]?.useFind,
|
|
58
|
+
"undefined"
|
|
59
|
+
);
|
|
60
|
+
assert.equal(
|
|
61
|
+
typeof (res3 as any)?.dbo[newly_created_table].useFind,
|
|
62
|
+
"function"
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const count = await (res3 as any)?.dbo[newly_created_table].count();
|
|
66
|
+
assert.equal(count, 0);
|
|
67
|
+
|
|
41
68
|
}
|
|
42
69
|
});
|
|
43
|
-
assert.deepStrictEqual(
|
|
44
|
-
res1,
|
|
45
|
-
{ isLoading: true }
|
|
46
|
-
);
|
|
47
|
-
assert.equal(
|
|
48
|
-
res2.isLoading,
|
|
49
|
-
false
|
|
50
|
-
);
|
|
51
|
-
assert.equal(
|
|
52
|
-
typeof (res2 as any)?.dbo[newly_created_table]?.useFind,
|
|
53
|
-
"undefined"
|
|
54
|
-
);
|
|
55
|
-
assert.equal(
|
|
56
|
-
typeof (res3 as any)?.dbo[newly_created_table].useFind,
|
|
57
|
-
"function"
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
const count = await (res3 as any)?.dbo[newly_created_table].count();
|
|
61
|
-
assert.equal(count, 0);
|
|
62
70
|
});
|
|
63
71
|
|
|
64
72
|
await test("useProstglesClient with initial skip", async (t) => {
|