prostgles-server 4.2.350 → 4.2.354

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.
@@ -0,0 +1,9 @@
1
+ import type { ProstglesInitOptions } from "./ProstglesTypes";
2
+ import type { DB, PGP } from "./initProstgles";
3
+ type GetDbConnectionArgs = Pick<ProstglesInitOptions, "DEBUG_MODE" | "onQuery" | "dbConnection" | "onNotice" | "onConnectionError">;
4
+ export declare const getDbConnection: ({ dbConnection, onQuery, onConnectionError, DEBUG_MODE, onNotice, }: GetDbConnectionArgs) => {
5
+ db: DB;
6
+ pgp: PGP;
7
+ };
8
+ export {};
9
+ //# sourceMappingURL=getDbConnection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getDbConnection.d.ts","sourceRoot":"","sources":["../lib/getDbConnection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,KAAK,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAG/C,KAAK,mBAAmB,GAAG,IAAI,CAC7B,oBAAoB,EACpB,YAAY,GAAG,SAAS,GAAG,cAAc,GAAG,UAAU,GAAG,mBAAmB,CAC7E,CAAC;AACF,eAAO,MAAM,eAAe,wEAMzB,mBAAmB;;SAAkB,GAAG;CA2E1C,CAAC"}
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDbConnection = void 0;
4
+ const pgPromise = require("pg-promise");
5
+ const getDbConnection = function ({ dbConnection, onQuery, onConnectionError, DEBUG_MODE, onNotice, }) {
6
+ const onQueryOrError = !onQuery && !DEBUG_MODE ?
7
+ undefined
8
+ : (error, ctx) => {
9
+ if (onQuery) {
10
+ onQuery(error, ctx);
11
+ }
12
+ else if (DEBUG_MODE) {
13
+ if (error) {
14
+ console.error(error, ctx);
15
+ }
16
+ else {
17
+ console.log(ctx);
18
+ }
19
+ }
20
+ };
21
+ const pgp = pgPromise({
22
+ ...(onQueryOrError && {
23
+ query: (ctx) => onQueryOrError(undefined, ctx),
24
+ }),
25
+ error: (err, ctx) => {
26
+ if (ctx.cn) {
27
+ onConnectionError?.(err, ctx);
28
+ }
29
+ onQueryOrError?.(err, ctx);
30
+ },
31
+ ...((onNotice || DEBUG_MODE) && {
32
+ connect: function ({ client, useCount }) {
33
+ const isFresh = !useCount;
34
+ if (isFresh && !client.listeners("notice").length) {
35
+ client.on("notice", function (msg) {
36
+ if (onNotice) {
37
+ onNotice(msg, msg?.message);
38
+ }
39
+ else {
40
+ console.log("notice: %j", msg?.message);
41
+ }
42
+ });
43
+ }
44
+ if (isFresh && !client.listeners("error").length) {
45
+ client.on("error", function (msg) {
46
+ if (onNotice) {
47
+ onNotice(msg, msg?.message);
48
+ }
49
+ else {
50
+ console.log("error: %j", msg?.message);
51
+ }
52
+ });
53
+ }
54
+ },
55
+ }),
56
+ });
57
+ // pgp.pg.defaults.max = 70;
58
+ // /* Casts count/sum/max to bigint. Needs rework to remove casting "+count" and other issues; */
59
+ // pgp.pg.types.setTypeParser(20, BigInt);
60
+ /**
61
+ * Prevent timestamp casting to ensure we don't lose the microseconds.
62
+ * This is needed to ensure the filters work as expected for a given row
63
+ *
64
+ register(1114, parseTimestamp) // timestamp without time zone
65
+ register(1184, parseTimestampTz) // timestamp with time zone
66
+ */
67
+ // pgp.pg.types.setTypeParser(1114, v => v); // timestamp without time zone
68
+ // pgp.pg.types.setTypeParser(1184, v => v); // timestamp with time zone
69
+ // pgp.pg.types.setTypeParser(1182, v => v); // date
70
+ pgp.pg.types.setTypeParser(pgp.pg.types.builtins.TIMESTAMP, (v) => v); // timestamp without time zone
71
+ pgp.pg.types.setTypeParser(pgp.pg.types.builtins.TIMESTAMPTZ, (v) => v); // timestamp with time zone
72
+ pgp.pg.types.setTypeParser(pgp.pg.types.builtins.DATE, (v) => v); // date
73
+ return {
74
+ db: pgp(dbConnection),
75
+ pgp,
76
+ };
77
+ };
78
+ exports.getDbConnection = getDbConnection;
79
+ //# sourceMappingURL=getDbConnection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getDbConnection.js","sourceRoot":"","sources":["../lib/getDbConnection.ts"],"names":[],"mappings":";;;AAAA,wCAAwC;AASjC,MAAM,eAAe,GAAG,UAAU,EACvC,YAAY,EACZ,OAAO,EACP,iBAAiB,EACjB,UAAU,EACV,QAAQ,GACY;IACpB,MAAM,cAAc,GAGlB,CAAC,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC;QACvB,SAAS;QACX,CAAC,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;YACb,IAAI,OAAO,EAAE,CAAC;gBACZ,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;YACtB,CAAC;iBAAM,IAAI,UAAU,EAAE,CAAC;gBACtB,IAAI,KAAK,EAAE,CAAC;oBACV,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;gBAC5B,CAAC;qBAAM,CAAC;oBACN,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;gBACnB,CAAC;YACH,CAAC;QACH,CAAC,CAAC;IAEN,MAAM,GAAG,GAAQ,SAAS,CAAC;QACzB,GAAG,CAAC,cAAc,IAAI;YACpB,KAAK,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,cAAc,CAAC,SAAS,EAAE,GAAG,CAAC;SAC/C,CAAC;QACF,KAAK,EAAE,CAAC,GAAU,EAAE,GAAG,EAAE,EAAE;YACzB,IAAI,GAAG,CAAC,EAAE,EAAE,CAAC;gBACX,iBAAiB,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;YAChC,CAAC;YACD,cAAc,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAC7B,CAAC;QACD,GAAG,CAAC,CAAC,QAAQ,IAAI,UAAU,CAAC,IAAI;YAC9B,OAAO,EAAE,UAAU,EAAE,MAAM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,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,2BAA2B;IACpG,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO;IAEzE,OAAO;QACL,EAAE,EAAE,GAAG,CAAC,YAAY,CAAC;QACrB,GAAG;KACJ,CAAC;AACJ,CAAC,CAAC;AAjFW,QAAA,eAAe,mBAiF1B"}
@@ -1,4 +1,3 @@
1
- import * as pgPromise from "pg-promise";
2
1
  import type pg from "pg-promise/typescript/pg-subset";
3
2
  import type { AuthClientRequest, SessionUser } from "./Auth/AuthTypes";
4
3
  import type { DBOFullyTyped } from "./DBSchemaBuilder/DBSchemaBuilder";
@@ -7,6 +6,7 @@ import type { ProstglesInitOptions } from "./ProstglesTypes";
7
6
  import type { DbTableInfo } from "./PublishParser/PublishParser";
8
7
  import { type PermissionScope } from "./PublishParser/PublishParser";
9
8
  import { getClientHandlers } from "./WebsocketAPI/getClientHandlers";
9
+ import type pgPromise from "pg-promise";
10
10
  /**
11
11
  * Database connection details
12
12
  */
@@ -18,7 +18,7 @@ string | pg.IConnectionParameters<pg.IClient>;
18
18
  export type DbConnectionOpts = pg.IDefaults;
19
19
  export type PGP = pgPromise.IMain<{}, pg.IClient>;
20
20
  export type DB = pgPromise.IDatabase<{}, pg.IClient>;
21
- export type UpdateableOptions<S = void, SUser extends SessionUser = SessionUser> = Pick<ProstglesInitOptions<S, SUser>, "fileTable" | "restApi" | "tableConfig" | "schemaFilter" | "auth">;
21
+ export type UpdateableOptions<S = void, SUser extends SessionUser = SessionUser> = Pick<ProstglesInitOptions<S, SUser>, "fileTable" | "restApi" | "tableConfig" | "schemaFilter" | "auth" | "publish" | "publishMethods" | "publishRawSQL">;
22
22
  export type OnInitReason = {
23
23
  type: "schema change";
24
24
  query: string;
@@ -52,12 +52,12 @@ export type InitResult<S = void, SUser extends SessionUser = SessionUser> = {
52
52
  * Generated database public schema TS types for all tables and views
53
53
  */
54
54
  getTSSchema: () => string;
55
- update: (newOpts: UpdateableOptions<S, SUser>) => Promise<void>;
55
+ update: (newOpts: UpdateableOptions<S, SUser>, force?: true) => Promise<void>;
56
56
  restart: () => Promise<InitResult<S, SUser>>;
57
57
  options: ProstglesInitOptions<S, SUser>;
58
58
  getClientDBHandlers: (clientReq: AuthClientRequest, scope: PermissionScope | undefined) => ReturnType<typeof getClientHandlers<S>>;
59
59
  };
60
- declare const clientOnlyUpdateKeys: ["auth"];
60
+ declare const clientOnlyUpdateKeys: ["auth", "publish", "publishMethods", "publishRawSQL"];
61
61
  export declare const initProstgles: (this: Prostgles, onReady: OnReadyCallbackBasic, reason: OnInitReason) => Promise<InitResult>;
62
62
  export {};
63
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,SAAS,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,MAAM,iCAAiC,CAAC;AAEtD,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE9D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAiB,KAAK,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAIpF,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AA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,EAAE,KAAK,CAAC,EAAE,KAAK,CAAC,EAAE,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9E,OAAO,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC,EAAE,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,QAAA,MAAM,oBAAoB,wDAKsB,CAAC;AAEjD,eAAO,MAAM,aAAa,SAClB,SAAS,WACN,oBAAoB,UACrB,YAAY,KACnB,QAAQ,UAAU,CAyMpB,CAAC"}
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.initProstgles = void 0;
4
- const pgPromise = require("pg-promise");
5
4
  const prostgles_types_1 = require("prostgles-types");
6
5
  const removeExpressRoute_1 = require("./Auth/utils/removeExpressRoute");
7
6
  const DBEventsManager_1 = require("./DBEventsManager");
@@ -11,7 +10,13 @@ const SchemaWatch_1 = require("./SchemaWatch/SchemaWatch");
11
10
  const runSQLFile_1 = require("./TableConfig/runSQLFile");
12
11
  const utils_1 = require("./utils/utils");
13
12
  const getClientHandlers_1 = require("./WebsocketAPI/getClientHandlers");
14
- const clientOnlyUpdateKeys = ["auth"];
13
+ const getDbConnection_1 = require("./getDbConnection");
14
+ const clientOnlyUpdateKeys = [
15
+ "auth",
16
+ "publish",
17
+ "publishMethods",
18
+ "publishRawSQL",
19
+ ];
15
20
  const initProstgles = async function (onReady, reason) {
16
21
  this.loaded = false;
17
22
  const expressApp = this.opts.fileTable?.expressApp ??
@@ -46,7 +51,7 @@ const initProstgles = async function (onReady, reason) {
46
51
  : this.opts.dbConnection;
47
52
  const application_name = `prostgles ${this.appId} ${existingAppName}`;
48
53
  /* 1. Connect to db */
49
- const { db, pgp } = getDbConnection({
54
+ const { db, pgp } = (0, getDbConnection_1.getDbConnection)({
50
55
  onQuery: this.opts.onQuery,
51
56
  onConnectionError: this.opts.onConnectionError,
52
57
  DEBUG_MODE: this.opts.DEBUG_MODE,
@@ -114,16 +119,19 @@ const initProstgles = async function (onReady, reason) {
114
119
  io: this.opts.io,
115
120
  getTSSchema: this.getTSFileContent,
116
121
  options: this.opts,
117
- update: async (newOpts) => {
118
- let optsHaveChanged = false;
119
- (0, prostgles_types_1.getKeys)(newOpts).forEach((k) => {
120
- if (!(0, prostgles_types_1.isEqual)(this.opts[k], newOpts[k])) {
121
- optsHaveChanged = true;
122
+ update: async (newOpts, force) => {
123
+ const optionsThatChanged = (0, prostgles_types_1.getObjectEntries)(newOpts)
124
+ .map((entry) => {
125
+ const [k, v] = entry;
126
+ if (force || !(0, prostgles_types_1.isEqual)(this.opts[k], newOpts[k])) {
122
127
  //@ts-ignore
123
- this.opts[k] = newOpts[k];
128
+ this.opts[k] = v;
129
+ return entry;
124
130
  }
125
- });
126
- if (!optsHaveChanged) {
131
+ return;
132
+ })
133
+ .filter(prostgles_types_1.isDefined);
134
+ if (!optionsThatChanged.length) {
127
135
  console.warn("No options changed");
128
136
  return;
129
137
  }
@@ -193,77 +201,4 @@ const initProstgles = async function (onReady, reason) {
193
201
  }
194
202
  };
195
203
  exports.initProstgles = initProstgles;
196
- const getDbConnection = function ({ dbConnection, onQuery, onConnectionError, DEBUG_MODE, onNotice, }) {
197
- const onQueryOrError = !onQuery && !DEBUG_MODE ?
198
- undefined
199
- : (error, ctx) => {
200
- if (onQuery) {
201
- onQuery(error, ctx);
202
- }
203
- else if (DEBUG_MODE) {
204
- if (error) {
205
- console.error(error, ctx);
206
- }
207
- else {
208
- console.log(ctx);
209
- }
210
- }
211
- };
212
- const pgp = pgPromise({
213
- ...(onQueryOrError && {
214
- query: (ctx) => onQueryOrError(undefined, ctx),
215
- }),
216
- error: (err, ctx) => {
217
- if (ctx.cn) {
218
- onConnectionError?.(err, ctx);
219
- }
220
- onQueryOrError?.(err, ctx);
221
- },
222
- ...((onNotice || DEBUG_MODE) && {
223
- connect: function ({ client, useCount }) {
224
- const isFresh = !useCount;
225
- if (isFresh && !client.listeners("notice").length) {
226
- client.on("notice", function (msg) {
227
- if (onNotice) {
228
- onNotice(msg, msg?.message);
229
- }
230
- else {
231
- console.log("notice: %j", msg?.message);
232
- }
233
- });
234
- }
235
- if (isFresh && !client.listeners("error").length) {
236
- client.on("error", function (msg) {
237
- if (onNotice) {
238
- onNotice(msg, msg?.message);
239
- }
240
- else {
241
- console.log("error: %j", msg?.message);
242
- }
243
- });
244
- }
245
- },
246
- }),
247
- });
248
- // pgp.pg.defaults.max = 70;
249
- // /* Casts count/sum/max to bigint. Needs rework to remove casting "+count" and other issues; */
250
- // pgp.pg.types.setTypeParser(20, BigInt);
251
- /**
252
- * Prevent timestamp casting to ensure we don't lose the microseconds.
253
- * This is needed to ensure the filters work as expected for a given row
254
- *
255
- register(1114, parseTimestamp) // timestamp without time zone
256
- register(1184, parseTimestampTz) // timestamp with time zone
257
- */
258
- // pgp.pg.types.setTypeParser(1114, v => v); // timestamp without time zone
259
- // pgp.pg.types.setTypeParser(1184, v => v); // timestamp with time zone
260
- // pgp.pg.types.setTypeParser(1182, v => v); // date
261
- pgp.pg.types.setTypeParser(pgp.pg.types.builtins.TIMESTAMP, (v) => v); // timestamp without time zone
262
- pgp.pg.types.setTypeParser(pgp.pg.types.builtins.TIMESTAMPTZ, (v) => v); // timestamp with time zone
263
- pgp.pg.types.setTypeParser(pgp.pg.types.builtins.DATE, (v) => v); // date
264
- return {
265
- db: pgp(dbConnection),
266
- pgp,
267
- };
268
- };
269
204
  //# sourceMappingURL=initProstgles.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"initProstgles.js","sourceRoot":"","sources":["../lib/initProstgles.ts"],"names":[],"mappings":";;;AAAA,wCAAwC;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C;gBACD,IAAI,CAAC,WAAW,EAAE,OAAO,EAAE,CAAC;gBAC5B,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;AA7MW,QAAA,aAAa,iBA6MxB"}
@@ -0,0 +1,91 @@
1
+ import * as pgPromise from "pg-promise";
2
+ import type { ProstglesInitOptions } from "./ProstglesTypes";
3
+ import type { DB, PGP } from "./initProstgles";
4
+ import type pg from "pg-promise/typescript/pg-subset";
5
+
6
+ type GetDbConnectionArgs = Pick<
7
+ ProstglesInitOptions,
8
+ "DEBUG_MODE" | "onQuery" | "dbConnection" | "onNotice" | "onConnectionError"
9
+ >;
10
+ export const getDbConnection = function ({
11
+ dbConnection,
12
+ onQuery,
13
+ onConnectionError,
14
+ DEBUG_MODE,
15
+ onNotice,
16
+ }: GetDbConnectionArgs): { db: DB; pgp: PGP } {
17
+ const onQueryOrError:
18
+ | undefined
19
+ | ((error: any, ctx: pgPromise.IEventContext<pg.IClient>) => void) =
20
+ !onQuery && !DEBUG_MODE ?
21
+ undefined
22
+ : (error, ctx) => {
23
+ if (onQuery) {
24
+ onQuery(error, ctx);
25
+ } else if (DEBUG_MODE) {
26
+ if (error) {
27
+ console.error(error, ctx);
28
+ } else {
29
+ console.log(ctx);
30
+ }
31
+ }
32
+ };
33
+
34
+ const pgp: PGP = pgPromise({
35
+ ...(onQueryOrError && {
36
+ query: (ctx) => onQueryOrError(undefined, ctx),
37
+ }),
38
+ error: (err: Error, ctx) => {
39
+ if (ctx.cn) {
40
+ onConnectionError?.(err, ctx);
41
+ }
42
+ onQueryOrError?.(err, ctx);
43
+ },
44
+ ...((onNotice || DEBUG_MODE) && {
45
+ connect: function ({ client, useCount }) {
46
+ const isFresh = !useCount;
47
+ if (isFresh && !client.listeners("notice").length) {
48
+ client.on("notice", function (msg) {
49
+ if (onNotice) {
50
+ onNotice(msg, msg?.message);
51
+ } else {
52
+ console.log("notice: %j", msg?.message);
53
+ }
54
+ });
55
+ }
56
+ if (isFresh && !client.listeners("error").length) {
57
+ client.on("error", function (msg) {
58
+ if (onNotice) {
59
+ onNotice(msg, msg?.message);
60
+ } else {
61
+ console.log("error: %j", msg?.message);
62
+ }
63
+ });
64
+ }
65
+ },
66
+ }),
67
+ });
68
+ // pgp.pg.defaults.max = 70;
69
+
70
+ // /* Casts count/sum/max to bigint. Needs rework to remove casting "+count" and other issues; */
71
+ // pgp.pg.types.setTypeParser(20, BigInt);
72
+
73
+ /**
74
+ * Prevent timestamp casting to ensure we don't lose the microseconds.
75
+ * This is needed to ensure the filters work as expected for a given row
76
+ *
77
+ register(1114, parseTimestamp) // timestamp without time zone
78
+ register(1184, parseTimestampTz) // timestamp with time zone
79
+ */
80
+ // pgp.pg.types.setTypeParser(1114, v => v); // timestamp without time zone
81
+ // pgp.pg.types.setTypeParser(1184, v => v); // timestamp with time zone
82
+ // pgp.pg.types.setTypeParser(1182, v => v); // date
83
+ pgp.pg.types.setTypeParser(pgp.pg.types.builtins.TIMESTAMP, (v) => v); // timestamp without time zone
84
+ pgp.pg.types.setTypeParser(pgp.pg.types.builtins.TIMESTAMPTZ, (v) => v); // timestamp with time zone
85
+ pgp.pg.types.setTypeParser(pgp.pg.types.builtins.DATE, (v) => v); // date
86
+
87
+ return {
88
+ db: pgp(dbConnection),
89
+ pgp,
90
+ };
91
+ };
@@ -1,6 +1,5 @@
1
- import * as pgPromise from "pg-promise";
2
1
  import type pg from "pg-promise/typescript/pg-subset";
3
- import { getKeys, isEmpty, isEqual } from "prostgles-types";
2
+ import { getKeys, getObjectEntries, isDefined, isEmpty, isEqual } from "prostgles-types";
4
3
  import type { AuthClientRequest, SessionUser } from "./Auth/AuthTypes";
5
4
  import { removeExpressRoutesTest } from "./Auth/utils/removeExpressRoute";
6
5
  import { DBEventsManager } from "./DBEventsManager";
@@ -14,6 +13,8 @@ import { SchemaWatch } from "./SchemaWatch/SchemaWatch";
14
13
  import { runSQLFile } from "./TableConfig/runSQLFile";
15
14
  import { sleep } from "./utils/utils";
16
15
  import { getClientHandlers } from "./WebsocketAPI/getClientHandlers";
16
+ import { getDbConnection } from "./getDbConnection";
17
+ import type pgPromise from "pg-promise";
17
18
 
18
19
  /**
19
20
  * Database connection details
@@ -30,7 +31,14 @@ export type DB = pgPromise.IDatabase<{}, pg.IClient>;
30
31
 
31
32
  export type UpdateableOptions<S = void, SUser extends SessionUser = SessionUser> = Pick<
32
33
  ProstglesInitOptions<S, SUser>,
33
- "fileTable" | "restApi" | "tableConfig" | "schemaFilter" | "auth"
34
+ | "fileTable"
35
+ | "restApi"
36
+ | "tableConfig"
37
+ | "schemaFilter"
38
+ | "auth"
39
+ | "publish"
40
+ | "publishMethods"
41
+ | "publishRawSQL"
34
42
  >;
35
43
  export type OnInitReason =
36
44
  | {
@@ -71,7 +79,7 @@ export type InitResult<S = void, SUser extends SessionUser = SessionUser> = {
71
79
  * Generated database public schema TS types for all tables and views
72
80
  */
73
81
  getTSSchema: () => string;
74
- update: (newOpts: UpdateableOptions<S, SUser>) => Promise<void>;
82
+ update: (newOpts: UpdateableOptions<S, SUser>, force?: true) => Promise<void>;
75
83
  restart: () => Promise<InitResult<S, SUser>>;
76
84
  options: ProstglesInitOptions<S, SUser>;
77
85
  getClientDBHandlers: (
@@ -80,7 +88,12 @@ export type InitResult<S = void, SUser extends SessionUser = SessionUser> = {
80
88
  ) => ReturnType<typeof getClientHandlers<S>>;
81
89
  };
82
90
 
83
- const clientOnlyUpdateKeys = ["auth"] as const satisfies (keyof UpdateableOptions)[];
91
+ const clientOnlyUpdateKeys = [
92
+ "auth",
93
+ "publish",
94
+ "publishMethods",
95
+ "publishRawSQL",
96
+ ] as const satisfies (keyof UpdateableOptions)[];
84
97
 
85
98
  export const initProstgles = async function (
86
99
  this: Prostgles,
@@ -200,16 +213,19 @@ export const initProstgles = async function (
200
213
  io: this.opts.io,
201
214
  getTSSchema: this.getTSFileContent,
202
215
  options: this.opts,
203
- update: async (newOpts) => {
204
- let optsHaveChanged = false as boolean;
205
- getKeys(newOpts).forEach((k) => {
206
- if (!isEqual(this.opts[k], newOpts[k])) {
207
- optsHaveChanged = true;
208
- //@ts-ignore
209
- this.opts[k] = newOpts[k];
210
- }
211
- });
212
- if (!optsHaveChanged) {
216
+ update: async (newOpts, force) => {
217
+ const optionsThatChanged = getObjectEntries(newOpts)
218
+ .map((entry) => {
219
+ const [k, v] = entry;
220
+ if (force || !isEqual(this.opts[k], newOpts[k])) {
221
+ //@ts-ignore
222
+ this.opts[k] = v;
223
+ return entry;
224
+ }
225
+ return;
226
+ })
227
+ .filter(isDefined);
228
+ if (!optionsThatChanged.length) {
213
229
  console.warn("No options changed");
214
230
  return;
215
231
  }
@@ -285,90 +301,3 @@ export const initProstgles = async function (
285
301
  throw "init issues: " + (e as Error).toString();
286
302
  }
287
303
  };
288
-
289
- type GetDbConnectionArgs = Pick<
290
- ProstglesInitOptions,
291
- "DEBUG_MODE" | "onQuery" | "dbConnection" | "onNotice" | "onConnectionError"
292
- >;
293
- const getDbConnection = function ({
294
- dbConnection,
295
- onQuery,
296
- onConnectionError,
297
- DEBUG_MODE,
298
- onNotice,
299
- }: GetDbConnectionArgs): { db: DB; pgp: PGP } {
300
- const onQueryOrError:
301
- | undefined
302
- | ((error: any, ctx: pgPromise.IEventContext<pg.IClient>) => void) =
303
- !onQuery && !DEBUG_MODE ?
304
- undefined
305
- : (error, ctx) => {
306
- if (onQuery) {
307
- onQuery(error, ctx);
308
- } else if (DEBUG_MODE) {
309
- if (error) {
310
- console.error(error, ctx);
311
- } else {
312
- console.log(ctx);
313
- }
314
- }
315
- };
316
-
317
- const pgp: PGP = pgPromise({
318
- ...(onQueryOrError && {
319
- query: (ctx) => onQueryOrError(undefined, ctx),
320
- }),
321
- error: (err: Error, ctx) => {
322
- if (ctx.cn) {
323
- onConnectionError?.(err, ctx);
324
- }
325
- onQueryOrError?.(err, ctx);
326
- },
327
- ...((onNotice || DEBUG_MODE) && {
328
- connect: function ({ client, useCount }) {
329
- const isFresh = !useCount;
330
- if (isFresh && !client.listeners("notice").length) {
331
- client.on("notice", function (msg) {
332
- if (onNotice) {
333
- onNotice(msg, msg?.message);
334
- } else {
335
- console.log("notice: %j", msg?.message);
336
- }
337
- });
338
- }
339
- if (isFresh && !client.listeners("error").length) {
340
- client.on("error", function (msg) {
341
- if (onNotice) {
342
- onNotice(msg, msg?.message);
343
- } else {
344
- console.log("error: %j", msg?.message);
345
- }
346
- });
347
- }
348
- },
349
- }),
350
- });
351
- // pgp.pg.defaults.max = 70;
352
-
353
- // /* Casts count/sum/max to bigint. Needs rework to remove casting "+count" and other issues; */
354
- // pgp.pg.types.setTypeParser(20, BigInt);
355
-
356
- /**
357
- * Prevent timestamp casting to ensure we don't lose the microseconds.
358
- * This is needed to ensure the filters work as expected for a given row
359
- *
360
- register(1114, parseTimestamp) // timestamp without time zone
361
- register(1184, parseTimestampTz) // timestamp with time zone
362
- */
363
- // pgp.pg.types.setTypeParser(1114, v => v); // timestamp without time zone
364
- // pgp.pg.types.setTypeParser(1184, v => v); // timestamp with time zone
365
- // pgp.pg.types.setTypeParser(1182, v => v); // date
366
- pgp.pg.types.setTypeParser(pgp.pg.types.builtins.TIMESTAMP, (v) => v); // timestamp without time zone
367
- pgp.pg.types.setTypeParser(pgp.pg.types.builtins.TIMESTAMPTZ, (v) => v); // timestamp with time zone
368
- pgp.pg.types.setTypeParser(pgp.pg.types.builtins.DATE, (v) => v); // date
369
-
370
- return {
371
- db: pgp(dbConnection),
372
- pgp,
373
- };
374
- };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prostgles-server",
3
- "version": "4.2.350",
3
+ "version": "4.2.354",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",