prostgles-server 4.2.357 → 4.2.359
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/initProstgles.d.ts +4 -7
- package/dist/initProstgles.d.ts.map +1 -1
- package/dist/initProstgles.js +6 -54
- package/dist/initProstgles.js.map +1 -1
- package/dist/updateConfiguration.d.ts +9 -0
- package/dist/updateConfiguration.d.ts.map +1 -0
- package/dist/updateConfiguration.js +58 -0
- package/dist/updateConfiguration.js.map +1 -0
- package/lib/initProstgles.ts +24 -69
- package/lib/updateConfiguration.ts +66 -0
- package/package.json +1 -1
package/dist/initProstgles.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type pgPromise from "pg-promise";
|
|
1
2
|
import type pg from "pg-promise/typescript/pg-subset";
|
|
2
3
|
import type { AuthClientRequest, SessionUser } from "./Auth/AuthTypes";
|
|
3
4
|
import type { DBOFullyTyped } from "./DBSchemaBuilder/DBSchemaBuilder";
|
|
@@ -5,8 +6,8 @@ import type { DBHandlerServer, Prostgles } from "./Prostgles";
|
|
|
5
6
|
import type { ProstglesInitOptions } from "./ProstglesTypes";
|
|
6
7
|
import type { DbTableInfo } from "./PublishParser/PublishParser";
|
|
7
8
|
import { type PermissionScope } from "./PublishParser/PublishParser";
|
|
9
|
+
import { type clientOnlyUpdateKeys } from "./updateConfiguration";
|
|
8
10
|
import { getClientHandlers } from "./WebsocketAPI/getClientHandlers";
|
|
9
|
-
import type pgPromise from "pg-promise";
|
|
10
11
|
/**
|
|
11
12
|
* Database connection details
|
|
12
13
|
*/
|
|
@@ -40,8 +41,8 @@ export type OnReadyParamsBasic = OnReadyParamsCommon & {
|
|
|
40
41
|
export type OnReadyParams<S> = OnReadyParamsCommon & {
|
|
41
42
|
dbo: DBOFullyTyped<S>;
|
|
42
43
|
};
|
|
43
|
-
export type OnReadyCallback<S = void> = (params: OnReadyParams<S
|
|
44
|
-
export type OnReadyCallbackBasic = (params: OnReadyParamsBasic) => any;
|
|
44
|
+
export type OnReadyCallback<S = void> = (params: OnReadyParams<S>, update: InitResult["update"]) => any;
|
|
45
|
+
export type OnReadyCallbackBasic = (params: OnReadyParamsBasic, update: InitResult["update"]) => any;
|
|
45
46
|
export type InitResult<S = void, SUser extends SessionUser = SessionUser> = {
|
|
46
47
|
db: DBOFullyTyped<S>;
|
|
47
48
|
_db: DB;
|
|
@@ -57,10 +58,6 @@ export type InitResult<S = void, SUser extends SessionUser = SessionUser> = {
|
|
|
57
58
|
options: ProstglesInitOptions<S, SUser>;
|
|
58
59
|
getClientDBHandlers: (clientReq: AuthClientRequest, scope: PermissionScope | undefined) => ReturnType<typeof getClientHandlers<S>>;
|
|
59
60
|
};
|
|
60
|
-
/**
|
|
61
|
-
* Changes that do not affect the server so onReady does not need to be called again
|
|
62
|
-
*/
|
|
63
|
-
declare const clientOnlyUpdateKeys: ["auth", "publish", "publishMethods", "publishRawSQL"];
|
|
64
61
|
export declare const initProstgles: (this: Prostgles, onReady: OnReadyCallbackBasic, reason: OnInitReason) => Promise<InitResult>;
|
|
65
62
|
export {};
|
|
66
63
|
//# sourceMappingURL=initProstgles.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initProstgles.d.ts","sourceRoot":"","sources":["../lib/initProstgles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"initProstgles.d.ts","sourceRoot":"","sources":["../lib/initProstgles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,MAAM,iCAAiC,CAAC;AACtD,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAEvE,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,aA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E,KAAK,CAAC,CAAC,CAAC;IAC7C,OAAO,EAAE,oBAAoB,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IACxC,mBAAmB,EAAE,CACnB,SAAS,EAAE,iBAAiB,EAC5B,KAAK,EAAE,eAAe,GAAG,SAAS,KAC/B,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC;CAC9C,CAAC;AAEF,eAAO,MAAM,aAAa,SAClB,SAAS,WACN,oBAAoB,UACrB,YAAY,KACnB,QAAQ,UAAU,CAgKpB,CAAC"}
|
package/dist/initProstgles.js
CHANGED
|
@@ -1,25 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.initProstgles = void 0;
|
|
4
|
-
const prostgles_types_1 = require("prostgles-types");
|
|
5
4
|
const removeExpressRoute_1 = require("./Auth/utils/removeExpressRoute");
|
|
6
5
|
const DBEventsManager_1 = require("./DBEventsManager");
|
|
6
|
+
const getDbConnection_1 = require("./getDbConnection");
|
|
7
7
|
const Prostgles_1 = require("./Prostgles");
|
|
8
8
|
const PublishParser_1 = require("./PublishParser/PublishParser");
|
|
9
9
|
const SchemaWatch_1 = require("./SchemaWatch/SchemaWatch");
|
|
10
10
|
const runSQLFile_1 = require("./TableConfig/runSQLFile");
|
|
11
|
+
const updateConfiguration_1 = require("./updateConfiguration");
|
|
11
12
|
const utils_1 = require("./utils/utils");
|
|
12
13
|
const getClientHandlers_1 = require("./WebsocketAPI/getClientHandlers");
|
|
13
|
-
const getDbConnection_1 = require("./getDbConnection");
|
|
14
|
-
/**
|
|
15
|
-
* Changes that do not affect the server so onReady does not need to be called again
|
|
16
|
-
*/
|
|
17
|
-
const clientOnlyUpdateKeys = [
|
|
18
|
-
"auth",
|
|
19
|
-
"publish",
|
|
20
|
-
"publishMethods",
|
|
21
|
-
"publishRawSQL",
|
|
22
|
-
];
|
|
23
14
|
const initProstgles = async function (onReady, reason) {
|
|
24
15
|
this.loaded = false;
|
|
25
16
|
const expressApp = this.opts.fileTable?.expressApp ??
|
|
@@ -108,6 +99,8 @@ const initProstgles = async function (onReady, reason) {
|
|
|
108
99
|
db: this.db,
|
|
109
100
|
tables: this.dboBuilder.tables,
|
|
110
101
|
reason,
|
|
102
|
+
}, async (...args) => {
|
|
103
|
+
await (0, updateConfiguration_1.updateConfiguration)(this, onReady, ...args);
|
|
111
104
|
});
|
|
112
105
|
}
|
|
113
106
|
catch (err) {
|
|
@@ -122,49 +115,8 @@ const initProstgles = async function (onReady, reason) {
|
|
|
122
115
|
io: this.opts.io,
|
|
123
116
|
getTSSchema: this.getTSFileContent,
|
|
124
117
|
options: this.opts,
|
|
125
|
-
update: async (
|
|
126
|
-
|
|
127
|
-
.map((entry) => {
|
|
128
|
-
const [k, v] = entry;
|
|
129
|
-
if (force || !(0, prostgles_types_1.isEqual)(this.opts[k], newOpts[k])) {
|
|
130
|
-
//@ts-ignore
|
|
131
|
-
this.opts[k] = v;
|
|
132
|
-
return entry;
|
|
133
|
-
}
|
|
134
|
-
return;
|
|
135
|
-
})
|
|
136
|
-
.filter(prostgles_types_1.isDefined);
|
|
137
|
-
if (!optionsThatChanged.length) {
|
|
138
|
-
console.warn("No options changed");
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
if ("fileTable" in newOpts) {
|
|
142
|
-
await this.initFileTable();
|
|
143
|
-
}
|
|
144
|
-
if ("restApi" in newOpts) {
|
|
145
|
-
this.initRestApi();
|
|
146
|
-
}
|
|
147
|
-
if ("tableConfig" in newOpts) {
|
|
148
|
-
await this.initTableConfig({ type: "prgl.update", newOpts });
|
|
149
|
-
}
|
|
150
|
-
if ("schema" in newOpts) {
|
|
151
|
-
await this.refreshDBO();
|
|
152
|
-
}
|
|
153
|
-
if ("auth" in newOpts) {
|
|
154
|
-
this.initAuthHandler();
|
|
155
|
-
}
|
|
156
|
-
if ((0, prostgles_types_1.isEmpty)(newOpts))
|
|
157
|
-
return;
|
|
158
|
-
/**
|
|
159
|
-
* Some of these changes require clients to reconnect
|
|
160
|
-
* While others also affect the server and onReady should be called
|
|
161
|
-
*/
|
|
162
|
-
if ((0, prostgles_types_1.getKeys)(newOpts).every((updatedKey) => clientOnlyUpdateKeys.some((key) => key === updatedKey))) {
|
|
163
|
-
this.setupSocketIO();
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
await this.init(onReady, { type: "prgl.update", newOpts });
|
|
167
|
-
}
|
|
118
|
+
update: async (...args) => {
|
|
119
|
+
await (0, updateConfiguration_1.updateConfiguration)(this, onReady, ...args);
|
|
168
120
|
},
|
|
169
121
|
restart: () => this.init(onReady, { type: "prgl.restart" }),
|
|
170
122
|
destroy: async () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initProstgles.js","sourceRoot":"","sources":["../lib/initProstgles.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"initProstgles.js","sourceRoot":"","sources":["../lib/initProstgles.ts"],"names":[],"mappings":";;;AAGA,wEAA0E;AAC1E,uDAAoD;AAEpD,uDAAoD;AAEpD,2CAA6C;AAG7C,iEAAoF;AACpF,2DAAwD;AACxD,yDAAsD;AACtD,+DAAuF;AACvF,yCAAsC;AACtC,wEAAqE;AAgF9D,MAAM,aAAa,GAAG,KAAK,WAEhC,OAA6B,EAC7B,MAAoB;IAEpB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACpB,MAAM,UAAU,GACd,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU;QAC/B,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU;QAC7B,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,iBAAiB,EAAE,GAAG,CAAC;IAEzC,2EAA2E;IAC3E,IAAI,UAAU,EAAE,CAAC;QACf,MAAM,IAAA,4CAAuB,EAAC,UAAU,CAAC,CAAC;IAC5C,CAAC;IAED,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;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B,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;gBAChC,IAAI,CAAC,WAAW,EAAE,OAAO,EAAE,CAAC;gBAC5B,MAAM,IAAI,CAAC,iBAAiB,EAAE,OAAO,EAAE,CAAC;gBACxC,IAAI,CAAC,GAAG,GAAG,SAAS,CAAC;gBACrB,IAAI,CAAC,EAAE,GAAG,SAAS,CAAC;gBACpB,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;gBACrB,MAAM,IAAA,aAAK,EAAC,IAAI,CAAC,CAAC;gBAClB,OAAO,IAAI,CAAC;YACd,CAAC;YACD,mBAAmB,EAAE,CAAC,SAA4B,EAAE,KAAkC,EAAE,EAAE,CACxF,IAAA,qCAAiB,EAAC,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC;SAC5C,CAAC;QAEF,OAAO,UAAU,CAAC;IACpB,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACjB,MAAM,eAAe,GAAI,CAAW,CAAC,QAAQ,EAAE,CAAC;IAClD,CAAC;AACH,CAAC,CAAC;AApKW,QAAA,aAAa,iBAoKxB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SessionUser } from "./Auth/AuthTypes";
|
|
2
|
+
import type { OnReadyCallbackBasic, UpdateableOptions } from "./initProstgles";
|
|
3
|
+
import type { Prostgles } from "./Prostgles";
|
|
4
|
+
export declare const updateConfiguration: <DBSchema, UserSchema extends SessionUser>(prgl: Prostgles, onReady: OnReadyCallbackBasic, newOpts: UpdateableOptions<DBSchema, UserSchema>, force?: true) => Promise<void>;
|
|
5
|
+
/**
|
|
6
|
+
* Changes that do not affect the server so onReady does not need to be called again
|
|
7
|
+
*/
|
|
8
|
+
export declare const clientOnlyUpdateKeys: ["auth", "publish", "publishMethods", "publishRawSQL"];
|
|
9
|
+
//# sourceMappingURL=updateConfiguration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateConfiguration.d.ts","sourceRoot":"","sources":["../lib/updateConfiguration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC/E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,eAAO,MAAM,mBAAmB,mDACxB,SAAS,WACN,oBAAoB,4DAErB,IAAI,kBA8Cb,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,wDAKe,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.clientOnlyUpdateKeys = exports.updateConfiguration = void 0;
|
|
4
|
+
const prostgles_types_1 = require("prostgles-types");
|
|
5
|
+
const updateConfiguration = async (prgl, onReady, newOpts, force) => {
|
|
6
|
+
const optionsThatChanged = (0, prostgles_types_1.getKeys)(newOpts)
|
|
7
|
+
.map((k) => {
|
|
8
|
+
if (force || !(0, prostgles_types_1.isEqual)(prgl.opts[k], newOpts[k])) {
|
|
9
|
+
//@ts-ignore
|
|
10
|
+
prgl.opts[k] = newOpts[k];
|
|
11
|
+
return k;
|
|
12
|
+
}
|
|
13
|
+
return;
|
|
14
|
+
})
|
|
15
|
+
.filter(prostgles_types_1.isDefined);
|
|
16
|
+
if (!optionsThatChanged.length) {
|
|
17
|
+
console.warn("No options changed");
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if ("fileTable" in newOpts) {
|
|
21
|
+
await prgl.initFileTable();
|
|
22
|
+
}
|
|
23
|
+
if ("restApi" in newOpts) {
|
|
24
|
+
prgl.initRestApi();
|
|
25
|
+
}
|
|
26
|
+
if ("tableConfig" in newOpts) {
|
|
27
|
+
await prgl.initTableConfig({ type: "prgl.update", newOpts });
|
|
28
|
+
}
|
|
29
|
+
if ("schema" in newOpts) {
|
|
30
|
+
await prgl.refreshDBO();
|
|
31
|
+
}
|
|
32
|
+
if ("auth" in newOpts) {
|
|
33
|
+
prgl.initAuthHandler();
|
|
34
|
+
}
|
|
35
|
+
if ((0, prostgles_types_1.isEmpty)(newOpts))
|
|
36
|
+
return;
|
|
37
|
+
/**
|
|
38
|
+
* Some of these changes require clients to reconnect
|
|
39
|
+
* While others also affect the server and onReady should be called
|
|
40
|
+
*/
|
|
41
|
+
if ((0, prostgles_types_1.getKeys)(newOpts).every((updatedKey) => exports.clientOnlyUpdateKeys.some((key) => key === updatedKey))) {
|
|
42
|
+
prgl.setupSocketIO();
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
await prgl.init(onReady, { type: "prgl.update", newOpts });
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
exports.updateConfiguration = updateConfiguration;
|
|
49
|
+
/**
|
|
50
|
+
* Changes that do not affect the server so onReady does not need to be called again
|
|
51
|
+
*/
|
|
52
|
+
exports.clientOnlyUpdateKeys = [
|
|
53
|
+
"auth",
|
|
54
|
+
"publish",
|
|
55
|
+
"publishMethods",
|
|
56
|
+
"publishRawSQL",
|
|
57
|
+
];
|
|
58
|
+
//# sourceMappingURL=updateConfiguration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateConfiguration.js","sourceRoot":"","sources":["../lib/updateConfiguration.ts"],"names":[],"mappings":";;;AAAA,qDAAuE;AAKhE,MAAM,mBAAmB,GAAG,KAAK,EACtC,IAAe,EACf,OAA6B,EAC7B,OAAgD,EAChD,KAAY,EACZ,EAAE;IACF,MAAM,kBAAkB,GAAG,IAAA,yBAAO,EAAC,OAAO,CAAC;SACxC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACT,IAAI,KAAK,IAAI,CAAC,IAAA,yBAAO,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,OA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EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC,CAAC;AAlDW,QAAA,mBAAmB,uBAkD9B;AAEF;;GAEG;AACU,QAAA,oBAAoB,GAAG;IAClC,MAAM;IACN,SAAS;IACT,gBAAgB;IAChB,eAAe;CAC+B,CAAC"}
|
package/lib/initProstgles.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import type pgPromise from "pg-promise";
|
|
1
2
|
import type pg from "pg-promise/typescript/pg-subset";
|
|
2
|
-
import { getKeys, getObjectEntries, isDefined, isEmpty, isEqual } from "prostgles-types";
|
|
3
3
|
import type { AuthClientRequest, SessionUser } from "./Auth/AuthTypes";
|
|
4
4
|
import { removeExpressRoutesTest } from "./Auth/utils/removeExpressRoute";
|
|
5
5
|
import { DBEventsManager } from "./DBEventsManager";
|
|
6
6
|
import type { DBOFullyTyped } from "./DBSchemaBuilder/DBSchemaBuilder";
|
|
7
|
+
import { getDbConnection } from "./getDbConnection";
|
|
7
8
|
import type { DBHandlerServer, Prostgles } from "./Prostgles";
|
|
8
9
|
import { getIsSuperUser } from "./Prostgles";
|
|
9
10
|
import type { ProstglesInitOptions } from "./ProstglesTypes";
|
|
@@ -11,10 +12,9 @@ import type { DbTableInfo } from "./PublishParser/PublishParser";
|
|
|
11
12
|
import { PublishParser, type PermissionScope } from "./PublishParser/PublishParser";
|
|
12
13
|
import { SchemaWatch } from "./SchemaWatch/SchemaWatch";
|
|
13
14
|
import { runSQLFile } from "./TableConfig/runSQLFile";
|
|
15
|
+
import { updateConfiguration, type clientOnlyUpdateKeys } from "./updateConfiguration";
|
|
14
16
|
import { sleep } from "./utils/utils";
|
|
15
17
|
import { getClientHandlers } from "./WebsocketAPI/getClientHandlers";
|
|
16
|
-
import { getDbConnection } from "./getDbConnection";
|
|
17
|
-
import type pgPromise from "pg-promise";
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Database connection details
|
|
@@ -66,8 +66,14 @@ export type OnReadyParams<S> = OnReadyParamsCommon & {
|
|
|
66
66
|
dbo: DBOFullyTyped<S>;
|
|
67
67
|
};
|
|
68
68
|
|
|
69
|
-
export type OnReadyCallback<S = void> = (
|
|
70
|
-
|
|
69
|
+
export type OnReadyCallback<S = void> = (
|
|
70
|
+
params: OnReadyParams<S>,
|
|
71
|
+
update: InitResult["update"]
|
|
72
|
+
) => any;
|
|
73
|
+
export type OnReadyCallbackBasic = (
|
|
74
|
+
params: OnReadyParamsBasic,
|
|
75
|
+
update: InitResult["update"]
|
|
76
|
+
) => any;
|
|
71
77
|
|
|
72
78
|
export type InitResult<S = void, SUser extends SessionUser = SessionUser> = {
|
|
73
79
|
db: DBOFullyTyped<S>;
|
|
@@ -88,16 +94,6 @@ export type InitResult<S = void, SUser extends SessionUser = SessionUser> = {
|
|
|
88
94
|
) => ReturnType<typeof getClientHandlers<S>>;
|
|
89
95
|
};
|
|
90
96
|
|
|
91
|
-
/**
|
|
92
|
-
* Changes that do not affect the server so onReady does not need to be called again
|
|
93
|
-
*/
|
|
94
|
-
const clientOnlyUpdateKeys = [
|
|
95
|
-
"auth",
|
|
96
|
-
"publish",
|
|
97
|
-
"publishMethods",
|
|
98
|
-
"publishRawSQL",
|
|
99
|
-
] as const satisfies (keyof UpdateableOptions)[];
|
|
100
|
-
|
|
101
97
|
export const initProstgles = async function (
|
|
102
98
|
this: Prostgles,
|
|
103
99
|
onReady: OnReadyCallbackBasic,
|
|
@@ -197,12 +193,17 @@ export const initProstgles = async function (
|
|
|
197
193
|
if (this.destroyed) {
|
|
198
194
|
console.trace("Prostgles: Instance is destroyed");
|
|
199
195
|
}
|
|
200
|
-
onReady(
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
196
|
+
onReady(
|
|
197
|
+
{
|
|
198
|
+
dbo: this.dbo!,
|
|
199
|
+
db: this.db,
|
|
200
|
+
tables: this.dboBuilder.tables,
|
|
201
|
+
reason,
|
|
202
|
+
},
|
|
203
|
+
async (...args) => {
|
|
204
|
+
await updateConfiguration(this, onReady, ...args);
|
|
205
|
+
}
|
|
206
|
+
);
|
|
206
207
|
} catch (err) {
|
|
207
208
|
console.error("Prostgles: Error within onReady: \n", err);
|
|
208
209
|
}
|
|
@@ -216,54 +217,8 @@ export const initProstgles = async function (
|
|
|
216
217
|
io: this.opts.io,
|
|
217
218
|
getTSSchema: this.getTSFileContent,
|
|
218
219
|
options: this.opts,
|
|
219
|
-
update: async (
|
|
220
|
-
|
|
221
|
-
.map((entry) => {
|
|
222
|
-
const [k, v] = entry;
|
|
223
|
-
if (force || !isEqual(this.opts[k], newOpts[k])) {
|
|
224
|
-
//@ts-ignore
|
|
225
|
-
this.opts[k] = v;
|
|
226
|
-
return entry;
|
|
227
|
-
}
|
|
228
|
-
return;
|
|
229
|
-
})
|
|
230
|
-
.filter(isDefined);
|
|
231
|
-
if (!optionsThatChanged.length) {
|
|
232
|
-
console.warn("No options changed");
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
if ("fileTable" in newOpts) {
|
|
237
|
-
await this.initFileTable();
|
|
238
|
-
}
|
|
239
|
-
if ("restApi" in newOpts) {
|
|
240
|
-
this.initRestApi();
|
|
241
|
-
}
|
|
242
|
-
if ("tableConfig" in newOpts) {
|
|
243
|
-
await this.initTableConfig({ type: "prgl.update", newOpts });
|
|
244
|
-
}
|
|
245
|
-
if ("schema" in newOpts) {
|
|
246
|
-
await this.refreshDBO();
|
|
247
|
-
}
|
|
248
|
-
if ("auth" in newOpts) {
|
|
249
|
-
this.initAuthHandler();
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if (isEmpty(newOpts)) return;
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Some of these changes require clients to reconnect
|
|
256
|
-
* While others also affect the server and onReady should be called
|
|
257
|
-
*/
|
|
258
|
-
if (
|
|
259
|
-
getKeys(newOpts).every((updatedKey) =>
|
|
260
|
-
clientOnlyUpdateKeys.some((key) => key === updatedKey)
|
|
261
|
-
)
|
|
262
|
-
) {
|
|
263
|
-
this.setupSocketIO();
|
|
264
|
-
} else {
|
|
265
|
-
await this.init(onReady, { type: "prgl.update", newOpts });
|
|
266
|
-
}
|
|
220
|
+
update: async (...args) => {
|
|
221
|
+
await updateConfiguration(this, onReady, ...args);
|
|
267
222
|
},
|
|
268
223
|
restart: () => this.init(onReady, { type: "prgl.restart" }),
|
|
269
224
|
destroy: async () => {
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { getKeys, isDefined, isEmpty, isEqual } from "prostgles-types";
|
|
2
|
+
import type { SessionUser } from "./Auth/AuthTypes";
|
|
3
|
+
import type { OnReadyCallbackBasic, UpdateableOptions } from "./initProstgles";
|
|
4
|
+
import type { Prostgles } from "./Prostgles";
|
|
5
|
+
|
|
6
|
+
export const updateConfiguration = async <DBSchema, UserSchema extends SessionUser>(
|
|
7
|
+
prgl: Prostgles,
|
|
8
|
+
onReady: OnReadyCallbackBasic,
|
|
9
|
+
newOpts: UpdateableOptions<DBSchema, UserSchema>,
|
|
10
|
+
force?: true
|
|
11
|
+
) => {
|
|
12
|
+
const optionsThatChanged = getKeys(newOpts)
|
|
13
|
+
.map((k) => {
|
|
14
|
+
if (force || !isEqual(prgl.opts[k], newOpts[k])) {
|
|
15
|
+
//@ts-ignore
|
|
16
|
+
prgl.opts[k] = newOpts[k];
|
|
17
|
+
return k;
|
|
18
|
+
}
|
|
19
|
+
return;
|
|
20
|
+
})
|
|
21
|
+
.filter(isDefined);
|
|
22
|
+
if (!optionsThatChanged.length) {
|
|
23
|
+
console.warn("No options changed");
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if ("fileTable" in newOpts) {
|
|
28
|
+
await prgl.initFileTable();
|
|
29
|
+
}
|
|
30
|
+
if ("restApi" in newOpts) {
|
|
31
|
+
prgl.initRestApi();
|
|
32
|
+
}
|
|
33
|
+
if ("tableConfig" in newOpts) {
|
|
34
|
+
await prgl.initTableConfig({ type: "prgl.update", newOpts });
|
|
35
|
+
}
|
|
36
|
+
if ("schema" in newOpts) {
|
|
37
|
+
await prgl.refreshDBO();
|
|
38
|
+
}
|
|
39
|
+
if ("auth" in newOpts) {
|
|
40
|
+
prgl.initAuthHandler();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (isEmpty(newOpts)) return;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Some of these changes require clients to reconnect
|
|
47
|
+
* While others also affect the server and onReady should be called
|
|
48
|
+
*/
|
|
49
|
+
if (
|
|
50
|
+
getKeys(newOpts).every((updatedKey) => clientOnlyUpdateKeys.some((key) => key === updatedKey))
|
|
51
|
+
) {
|
|
52
|
+
prgl.setupSocketIO();
|
|
53
|
+
} else {
|
|
54
|
+
await prgl.init(onReady, { type: "prgl.update", newOpts });
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Changes that do not affect the server so onReady does not need to be called again
|
|
60
|
+
*/
|
|
61
|
+
export const clientOnlyUpdateKeys = [
|
|
62
|
+
"auth",
|
|
63
|
+
"publish",
|
|
64
|
+
"publishMethods",
|
|
65
|
+
"publishRawSQL",
|
|
66
|
+
] as const satisfies (keyof UpdateableOptions)[];
|