prostgles-server 4.2.178 → 4.2.180
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/.vscode/settings.json +10 -1
- package/dist/DboBuilder/TableHandler/DataValidator.d.ts +1 -1
- package/dist/DboBuilder/TableHandler/DataValidator.d.ts.map +1 -1
- package/dist/DboBuilder/TableHandler/DataValidator.js +4 -4
- package/dist/DboBuilder/TableHandler/DataValidator.js.map +1 -1
- package/dist/DboBuilder/TableHandler/TableHandler.d.ts +1 -1
- package/dist/DboBuilder/TableHandler/TableHandler.d.ts.map +1 -1
- package/dist/DboBuilder/TableHandler/insert.js +3 -3
- package/dist/DboBuilder/TableHandler/insert.js.map +1 -1
- package/dist/DboBuilder/TableHandler/update.d.ts.map +1 -1
- package/dist/DboBuilder/TableHandler/update.js +45 -19
- package/dist/DboBuilder/TableHandler/update.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/ViewHandler.d.ts +1 -1
- package/dist/DboBuilder/ViewHandler/ViewHandler.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/ViewHandler.js +2 -2
- package/dist/DboBuilder/ViewHandler/ViewHandler.js.map +1 -1
- package/dist/DboBuilder/parseUpdateRules.js +1 -1
- package/dist/DboBuilder/parseUpdateRules.js.map +1 -1
- package/dist/Logging.d.ts +10 -3
- package/dist/Logging.d.ts.map +1 -1
- package/dist/Prostgles.d.ts +2 -2
- package/dist/Prostgles.d.ts.map +1 -1
- package/dist/Prostgles.js +118 -53
- package/dist/Prostgles.js.map +1 -1
- package/dist/ProstglesTypes.d.ts +77 -23
- package/dist/ProstglesTypes.d.ts.map +1 -1
- package/dist/ProstglesTypes.js.map +1 -1
- package/dist/SyncReplication.js +2 -2
- package/dist/SyncReplication.js.map +1 -1
- package/dist/initProstgles.d.ts +9 -2
- package/dist/initProstgles.d.ts.map +1 -1
- package/dist/initProstgles.js +65 -57
- package/dist/initProstgles.js.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js.map +1 -1
- package/documentation/CLIENT.md +542 -0
- package/documentation/SERVER.md +104 -0
- package/documentation/utils/clientTypes.ts +8436 -0
- package/documentation/utils/dist/clientTypes.d.ts +7705 -0
- package/documentation/utils/dist/clientTypes.d.ts.map +1 -0
- package/documentation/utils/dist/clientTypes.js +8438 -0
- package/documentation/utils/dist/definitions.d.ts +7705 -0
- package/documentation/utils/dist/definitions.d.ts.map +1 -0
- package/documentation/utils/dist/definitions.js +8438 -0
- package/documentation/utils/dist/generateClientDocs.d.ts +3 -0
- package/documentation/utils/dist/generateClientDocs.d.ts.map +1 -0
- package/documentation/utils/dist/generateClientDocs.js +115 -0
- package/documentation/utils/dist/generateDocs.d.ts +2 -0
- package/documentation/utils/dist/generateDocs.d.ts.map +1 -0
- package/documentation/utils/dist/generateDocs.js +6 -0
- package/documentation/utils/dist/generateMarkdown.d.ts +2 -0
- package/documentation/utils/dist/generateMarkdown.d.ts.map +1 -0
- package/documentation/utils/dist/generateMarkdown.js +68 -0
- package/documentation/utils/dist/generateServerDocs.d.ts +2 -0
- package/documentation/utils/dist/generateServerDocs.d.ts.map +1 -0
- package/documentation/utils/dist/generateServerDocs.js +80 -0
- package/documentation/utils/dist/getResolvedTypes.d.ts +15 -0
- package/documentation/utils/dist/getResolvedTypes.d.ts.map +1 -0
- package/documentation/utils/dist/getResolvedTypes.js +29 -0
- package/documentation/utils/dist/getSerializableType.d.ts +69 -0
- package/documentation/utils/dist/getSerializableType.d.ts.map +1 -0
- package/documentation/utils/dist/getSerializableType.js +273 -0
- package/documentation/utils/dist/getSymbolComments.d.ts +11 -0
- package/documentation/utils/dist/getSymbolComments.d.ts.map +1 -0
- package/documentation/utils/dist/getSymbolComments.js +60 -0
- package/documentation/utils/dist/loadTsFile.d.ts +7 -0
- package/documentation/utils/dist/loadTsFile.d.ts.map +1 -0
- package/documentation/utils/dist/loadTsFile.js +33 -0
- package/documentation/utils/dist/moduleResolver.d.ts +9 -0
- package/documentation/utils/dist/moduleResolver.d.ts.map +1 -0
- package/documentation/utils/dist/moduleResolver.js +27 -0
- package/documentation/utils/dist/serverTypes.d.ts +307 -0
- package/documentation/utils/dist/serverTypes.d.ts.map +1 -0
- package/documentation/utils/dist/serverTypes.js +347 -0
- package/documentation/utils/generateClientDocs.ts +142 -0
- package/documentation/utils/generateDocs.ts +4 -0
- package/documentation/utils/generateServerDocs.ts +82 -0
- package/documentation/utils/getResolvedTypes.ts +45 -0
- package/documentation/utils/getSerializableType.ts +479 -0
- package/documentation/utils/loadTsFile.ts +45 -0
- package/documentation/utils/moduleResolver.ts +31 -0
- package/documentation/utils/node_modules/.package-lock.json +67 -0
- package/documentation/utils/node_modules/@types/node/LICENSE +21 -0
- package/documentation/utils/node_modules/@types/node/README.md +15 -0
- package/documentation/utils/node_modules/@types/node/assert/strict.d.ts +8 -0
- package/documentation/utils/node_modules/@types/node/assert.d.ts +1040 -0
- package/documentation/utils/node_modules/@types/node/async_hooks.d.ts +541 -0
- package/documentation/utils/node_modules/@types/node/buffer.buffer.d.ts +385 -0
- package/documentation/utils/node_modules/@types/node/buffer.d.ts +1934 -0
- package/documentation/utils/node_modules/@types/node/child_process.d.ts +1548 -0
- package/documentation/utils/node_modules/@types/node/cluster.d.ts +578 -0
- package/documentation/utils/node_modules/@types/node/compatibility/disposable.d.ts +16 -0
- package/documentation/utils/node_modules/@types/node/compatibility/index.d.ts +9 -0
- package/documentation/utils/node_modules/@types/node/compatibility/indexable.d.ts +20 -0
- package/documentation/utils/node_modules/@types/node/compatibility/iterators.d.ts +21 -0
- package/documentation/utils/node_modules/@types/node/console.d.ts +452 -0
- package/documentation/utils/node_modules/@types/node/constants.d.ts +19 -0
- package/documentation/utils/node_modules/@types/node/crypto.d.ts +4519 -0
- package/documentation/utils/node_modules/@types/node/dgram.d.ts +596 -0
- package/documentation/utils/node_modules/@types/node/diagnostics_channel.d.ts +554 -0
- package/documentation/utils/node_modules/@types/node/dns/promises.d.ts +477 -0
- package/documentation/utils/node_modules/@types/node/dns.d.ts +864 -0
- package/documentation/utils/node_modules/@types/node/dom-events.d.ts +124 -0
- package/documentation/utils/node_modules/@types/node/domain.d.ts +170 -0
- package/documentation/utils/node_modules/@types/node/events.d.ts +931 -0
- package/documentation/utils/node_modules/@types/node/fs/promises.d.ts +1245 -0
- package/documentation/utils/node_modules/@types/node/fs.d.ts +4317 -0
- package/documentation/utils/node_modules/@types/node/globals.d.ts +468 -0
- package/documentation/utils/node_modules/@types/node/globals.typedarray.d.ts +21 -0
- package/documentation/utils/node_modules/@types/node/http.d.ts +1944 -0
- package/documentation/utils/node_modules/@types/node/http2.d.ts +2555 -0
- package/documentation/utils/node_modules/@types/node/https.d.ts +544 -0
- package/documentation/utils/node_modules/@types/node/index.d.ts +91 -0
- package/documentation/utils/node_modules/@types/node/inspector.d.ts +3696 -0
- package/documentation/utils/node_modules/@types/node/module.d.ts +315 -0
- package/documentation/utils/node_modules/@types/node/net.d.ts +1005 -0
- package/documentation/utils/node_modules/@types/node/os.d.ts +495 -0
- package/documentation/utils/node_modules/@types/node/package.json +220 -0
- package/documentation/utils/node_modules/@types/node/path.d.ts +200 -0
- package/documentation/utils/node_modules/@types/node/perf_hooks.d.ts +934 -0
- package/documentation/utils/node_modules/@types/node/process.d.ts +1879 -0
- package/documentation/utils/node_modules/@types/node/punycode.d.ts +117 -0
- package/documentation/utils/node_modules/@types/node/querystring.d.ts +153 -0
- package/documentation/utils/node_modules/@types/node/readline/promises.d.ts +162 -0
- package/documentation/utils/node_modules/@types/node/readline.d.ts +589 -0
- package/documentation/utils/node_modules/@types/node/repl.d.ts +430 -0
- package/documentation/utils/node_modules/@types/node/sea.d.ts +153 -0
- package/documentation/utils/node_modules/@types/node/stream/consumers.d.ts +12 -0
- package/documentation/utils/node_modules/@types/node/stream/promises.d.ts +90 -0
- package/documentation/utils/node_modules/@types/node/stream/web.d.ts +524 -0
- package/documentation/utils/node_modules/@types/node/stream.d.ts +1726 -0
- package/documentation/utils/node_modules/@types/node/string_decoder.d.ts +67 -0
- package/documentation/utils/node_modules/@types/node/test.d.ts +1938 -0
- package/documentation/utils/node_modules/@types/node/timers/promises.d.ts +97 -0
- package/documentation/utils/node_modules/@types/node/timers.d.ts +240 -0
- package/documentation/utils/node_modules/@types/node/tls.d.ts +1217 -0
- package/documentation/utils/node_modules/@types/node/trace_events.d.ts +197 -0
- package/documentation/utils/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +385 -0
- package/documentation/utils/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +19 -0
- package/documentation/utils/node_modules/@types/node/ts5.6/index.d.ts +91 -0
- package/documentation/utils/node_modules/@types/node/tty.d.ts +208 -0
- package/documentation/utils/node_modules/@types/node/url.d.ts +955 -0
- package/documentation/utils/node_modules/@types/node/util.d.ts +2306 -0
- package/documentation/utils/node_modules/@types/node/v8.d.ts +808 -0
- package/documentation/utils/node_modules/@types/node/vm.d.ts +922 -0
- package/documentation/utils/node_modules/@types/node/wasi.d.ts +181 -0
- package/documentation/utils/node_modules/@types/node/worker_threads.d.ts +694 -0
- package/documentation/utils/node_modules/@types/node/zlib.d.ts +539 -0
- package/documentation/utils/node_modules/undici-types/LICENSE +21 -0
- package/documentation/utils/node_modules/undici-types/README.md +6 -0
- package/documentation/utils/node_modules/undici-types/agent.d.ts +31 -0
- package/documentation/utils/node_modules/undici-types/api.d.ts +43 -0
- package/documentation/utils/node_modules/undici-types/balanced-pool.d.ts +29 -0
- package/documentation/utils/node_modules/undici-types/cache.d.ts +36 -0
- package/documentation/utils/node_modules/undici-types/client.d.ts +108 -0
- package/documentation/utils/node_modules/undici-types/connector.d.ts +34 -0
- package/documentation/utils/node_modules/undici-types/content-type.d.ts +21 -0
- package/documentation/utils/node_modules/undici-types/cookies.d.ts +28 -0
- package/documentation/utils/node_modules/undici-types/diagnostics-channel.d.ts +66 -0
- package/documentation/utils/node_modules/undici-types/dispatcher.d.ts +255 -0
- package/documentation/utils/node_modules/undici-types/env-http-proxy-agent.d.ts +21 -0
- package/documentation/utils/node_modules/undici-types/errors.d.ts +149 -0
- package/documentation/utils/node_modules/undici-types/eventsource.d.ts +63 -0
- package/documentation/utils/node_modules/undici-types/fetch.d.ts +209 -0
- package/documentation/utils/node_modules/undici-types/file.d.ts +39 -0
- package/documentation/utils/node_modules/undici-types/filereader.d.ts +54 -0
- package/documentation/utils/node_modules/undici-types/formdata.d.ts +108 -0
- package/documentation/utils/node_modules/undici-types/global-dispatcher.d.ts +9 -0
- package/documentation/utils/node_modules/undici-types/global-origin.d.ts +7 -0
- package/documentation/utils/node_modules/undici-types/handlers.d.ts +15 -0
- package/documentation/utils/node_modules/undici-types/header.d.ts +4 -0
- package/documentation/utils/node_modules/undici-types/index.d.ts +71 -0
- package/documentation/utils/node_modules/undici-types/interceptors.d.ts +15 -0
- package/documentation/utils/node_modules/undici-types/mock-agent.d.ts +50 -0
- package/documentation/utils/node_modules/undici-types/mock-client.d.ts +25 -0
- package/documentation/utils/node_modules/undici-types/mock-errors.d.ts +12 -0
- package/documentation/utils/node_modules/undici-types/mock-interceptor.d.ts +93 -0
- package/documentation/utils/node_modules/undici-types/mock-pool.d.ts +25 -0
- package/documentation/utils/node_modules/undici-types/package.json +55 -0
- package/documentation/utils/node_modules/undici-types/patch.d.ts +71 -0
- package/documentation/utils/node_modules/undici-types/pool-stats.d.ts +19 -0
- package/documentation/utils/node_modules/undici-types/pool.d.ts +39 -0
- package/documentation/utils/node_modules/undici-types/proxy-agent.d.ts +28 -0
- package/documentation/utils/node_modules/undici-types/readable.d.ts +60 -0
- package/documentation/utils/node_modules/undici-types/retry-agent.d.ts +8 -0
- package/documentation/utils/node_modules/undici-types/retry-handler.d.ts +116 -0
- package/documentation/utils/node_modules/undici-types/util.d.ts +18 -0
- package/documentation/utils/node_modules/undici-types/webidl.d.ts +222 -0
- package/documentation/utils/node_modules/undici-types/websocket.d.ts +152 -0
- package/documentation/utils/package-lock.json +75 -0
- package/documentation/utils/package.json +14 -0
- package/documentation/utils/serverTypes.ts +345 -0
- package/documentation/utils/tsconfig.json +28 -0
- package/examples/full-example-typescript/DBoGenerated.d.ts +2 -2
- package/examples/full-example-typescript/DBoGenerated.ts +2 -2
- package/examples/full-example-typescript/index.ts +39 -45
- package/examples/full-example-vanilla/index.js +51 -53
- package/examples/server/typescript/index.ts +24 -30
- package/lib/DboBuilder/TableHandler/DataValidator.ts +5 -5
- package/lib/DboBuilder/TableHandler/TableHandler.ts +1 -1
- package/lib/DboBuilder/TableHandler/insert.ts +3 -3
- package/lib/DboBuilder/TableHandler/update.ts +106 -48
- package/lib/DboBuilder/ViewHandler/ViewHandler.ts +2 -2
- package/lib/DboBuilder/parseUpdateRules.ts +1 -1
- package/lib/Logging.ts +7 -3
- package/lib/Prostgles.ts +209 -142
- package/lib/ProstglesTypes.ts +130 -51
- package/lib/SyncReplication.ts +2 -2
- package/lib/initProstgles.ts +145 -111
- package/lib/utils.ts +4 -5
- package/package.json +3 -2
- package/examples/server/typescript/index.d.ts +0 -2
- package/examples/server/typescript/index.d.ts.map +0 -1
- package/examples/server/typescript/index.js +0 -54
- package/examples/server/typescript/index.js.map +0 -1
package/lib/initProstgles.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as pgPromise from "pg-promise";
|
|
2
2
|
import pg from "pg-promise/typescript/pg-subset";
|
|
3
3
|
import { getKeys, isEmpty } from "prostgles-types";
|
|
4
|
-
import { AuthHandler } from "./Auth/AuthHandler";
|
|
5
4
|
import { DBEventsManager } from "./DBEventsManager";
|
|
6
5
|
import { DBOFullyTyped } from "./DBSchemaBuilder";
|
|
7
6
|
import { DBHandlerServer, Prostgles, getIsSuperUser } from "./Prostgles";
|
|
@@ -10,38 +9,48 @@ import { DbTableInfo, PublishParser } from "./PublishParser/PublishParser";
|
|
|
10
9
|
import { SchemaWatch } from "./SchemaWatch/SchemaWatch";
|
|
11
10
|
import { sleep } from "./utils";
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Database connection details
|
|
14
|
+
*/
|
|
15
|
+
export type DbConnection =
|
|
16
|
+
/**
|
|
17
|
+
* Connection URI
|
|
18
|
+
*/
|
|
19
|
+
string | pg.IConnectionParameters<pg.IClient>;
|
|
14
20
|
export type DbConnectionOpts = pg.IDefaults;
|
|
15
21
|
|
|
16
22
|
export type PGP = pgPromise.IMain<{}, pg.IClient>;
|
|
17
23
|
export type DB = pgPromise.IDatabase<{}, pg.IClient>;
|
|
18
24
|
|
|
19
|
-
export type UpdateableOptions = Pick<
|
|
20
|
-
|
|
21
|
-
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
command: string;
|
|
25
|
-
}
|
|
25
|
+
export type UpdateableOptions = Pick<
|
|
26
|
+
ProstglesInitOptions,
|
|
27
|
+
"fileTable" | "restApi" | "tableConfig" | "schema" | "auth"
|
|
28
|
+
>;
|
|
29
|
+
export type OnInitReason =
|
|
26
30
|
| {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
type: "schema change";
|
|
32
|
+
query: string;
|
|
33
|
+
command: string;
|
|
34
|
+
}
|
|
35
|
+
| {
|
|
36
|
+
type: "prgl.update";
|
|
37
|
+
newOpts: Omit<UpdateableOptions, (typeof clientOnlyUpdateKeys)[number]>;
|
|
38
|
+
}
|
|
39
|
+
| {
|
|
40
|
+
type: "init" | "prgl.restart" | "TableConfig";
|
|
41
|
+
};
|
|
33
42
|
|
|
34
43
|
type OnReadyParamsCommon = {
|
|
35
44
|
db: DB;
|
|
36
45
|
tables: DbTableInfo[];
|
|
37
46
|
reason: OnInitReason;
|
|
38
|
-
}
|
|
47
|
+
};
|
|
39
48
|
export type OnReadyParamsBasic = OnReadyParamsCommon & {
|
|
40
|
-
dbo: DBHandlerServer;
|
|
41
|
-
}
|
|
49
|
+
dbo: DBHandlerServer;
|
|
50
|
+
};
|
|
42
51
|
export type OnReadyParams<S> = OnReadyParamsCommon & {
|
|
43
|
-
dbo: DBOFullyTyped<S>;
|
|
44
|
-
}
|
|
52
|
+
dbo: DBOFullyTyped<S>;
|
|
53
|
+
};
|
|
45
54
|
|
|
46
55
|
export type OnReadyCallback<S = void> = (params: OnReadyParams<S>) => any;
|
|
47
56
|
export type OnReadyCallbackBasic = (params: OnReadyParamsBasic) => any;
|
|
@@ -57,48 +66,54 @@ export type InitResult = {
|
|
|
57
66
|
*/
|
|
58
67
|
getTSSchema: () => string;
|
|
59
68
|
update: (newOpts: UpdateableOptions) => Promise<void>;
|
|
60
|
-
restart: () => Promise<InitResult>;
|
|
69
|
+
restart: () => Promise<InitResult>;
|
|
61
70
|
options: ProstglesInitOptions;
|
|
62
|
-
}
|
|
71
|
+
};
|
|
63
72
|
|
|
64
73
|
const clientOnlyUpdateKeys = ["auth"] as const satisfies (keyof UpdateableOptions)[];
|
|
65
74
|
|
|
66
|
-
export const initProstgles = async function(
|
|
75
|
+
export const initProstgles = async function (
|
|
76
|
+
this: Prostgles,
|
|
77
|
+
onReady: OnReadyCallbackBasic,
|
|
78
|
+
reason: OnInitReason
|
|
79
|
+
): Promise<InitResult> {
|
|
67
80
|
this.loaded = false;
|
|
68
81
|
|
|
69
82
|
if (!this.db) {
|
|
70
83
|
let existingAppName = "";
|
|
71
84
|
let connString = "";
|
|
72
|
-
if(typeof this.opts.dbConnection === "string"){
|
|
85
|
+
if (typeof this.opts.dbConnection === "string") {
|
|
73
86
|
connString = this.opts.dbConnection;
|
|
74
|
-
} else if(this.opts.dbConnection.connectionString){
|
|
87
|
+
} else if (this.opts.dbConnection.connectionString) {
|
|
75
88
|
connString = this.opts.dbConnection.connectionString;
|
|
76
89
|
} else {
|
|
77
90
|
existingAppName = this.opts.dbConnection.application_name ?? "";
|
|
78
91
|
}
|
|
79
92
|
|
|
80
|
-
if(connString){
|
|
93
|
+
if (connString) {
|
|
81
94
|
try {
|
|
82
95
|
const url = new URL(connString);
|
|
83
|
-
existingAppName =
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
96
|
+
existingAppName =
|
|
97
|
+
url.searchParams.get("application_name") ?? url.searchParams.get("ApplicationName") ?? "";
|
|
98
|
+
} catch (e) {}
|
|
87
99
|
}
|
|
88
100
|
|
|
89
|
-
const conObj =
|
|
101
|
+
const conObj =
|
|
102
|
+
typeof this.opts.dbConnection === "string"
|
|
103
|
+
? { connectionString: this.opts.dbConnection }
|
|
104
|
+
: this.opts.dbConnection;
|
|
90
105
|
const application_name = `prostgles ${this.appId} ${existingAppName}`;
|
|
91
106
|
|
|
92
107
|
/* 1. Connect to db */
|
|
93
108
|
const { db, pgp } = getDbConnection({
|
|
94
109
|
...this.opts,
|
|
95
|
-
dbConnection: { ...conObj, application_name },
|
|
96
|
-
onNotice: notice => {
|
|
110
|
+
dbConnection: { ...conObj, application_name },
|
|
111
|
+
onNotice: (notice) => {
|
|
97
112
|
if (this.opts.onNotice) this.opts.onNotice(notice);
|
|
98
113
|
if (this.dbEventsManager) {
|
|
99
|
-
this.dbEventsManager.onNotice(notice)
|
|
114
|
+
this.dbEventsManager.onNotice(notice);
|
|
100
115
|
}
|
|
101
|
-
}
|
|
116
|
+
},
|
|
102
117
|
});
|
|
103
118
|
this.db = db;
|
|
104
119
|
this.pgp = pgp;
|
|
@@ -115,7 +130,6 @@ export const initProstgles = async function(this: Prostgles, onReady: OnReadyCal
|
|
|
115
130
|
}
|
|
116
131
|
|
|
117
132
|
try {
|
|
118
|
-
|
|
119
133
|
await this.refreshDBO();
|
|
120
134
|
await this.initTableConfig(reason);
|
|
121
135
|
await this.initFileTable();
|
|
@@ -124,7 +138,6 @@ export const initProstgles = async function(this: Prostgles, onReady: OnReadyCal
|
|
|
124
138
|
this.schemaWatch = await SchemaWatch.create(this.dboBuilder);
|
|
125
139
|
|
|
126
140
|
if (this.opts.publish) {
|
|
127
|
-
|
|
128
141
|
if (!this.opts.io) {
|
|
129
142
|
console.warn("IO missing. Publish has no effect without io");
|
|
130
143
|
}
|
|
@@ -132,34 +145,39 @@ export const initProstgles = async function(this: Prostgles, onReady: OnReadyCal
|
|
|
132
145
|
/* 3.9 Check auth config */
|
|
133
146
|
await this.initAuthHandler();
|
|
134
147
|
|
|
135
|
-
this.publishParser = new PublishParser(
|
|
148
|
+
this.publishParser = new PublishParser(
|
|
149
|
+
this.opts.publish,
|
|
150
|
+
this.opts.publishMethods as any,
|
|
151
|
+
this.opts.publishRawSQL,
|
|
152
|
+
this.dbo!,
|
|
153
|
+
this.db,
|
|
154
|
+
this as any
|
|
155
|
+
);
|
|
136
156
|
this.dboBuilder.publishParser = this.publishParser;
|
|
137
157
|
|
|
138
158
|
/* 4. Set publish and auth listeners */
|
|
139
159
|
await this.setSocketEvents();
|
|
140
|
-
|
|
141
160
|
} else if (this.opts.auth) {
|
|
142
161
|
throw "Auth config does not work without publish";
|
|
143
162
|
}
|
|
144
163
|
|
|
145
164
|
this.dbEventsManager = new DBEventsManager(db, pgp);
|
|
146
165
|
|
|
147
|
-
|
|
148
166
|
this.writeDBSchema();
|
|
149
167
|
|
|
150
168
|
/* 5. Finish init and provide DBO object */
|
|
151
169
|
try {
|
|
152
170
|
if (this.destroyed) {
|
|
153
|
-
console.trace("Prostgles: Instance is destroyed")
|
|
171
|
+
console.trace("Prostgles: Instance is destroyed");
|
|
154
172
|
}
|
|
155
173
|
onReady({
|
|
156
|
-
dbo: this.dbo as any,
|
|
157
|
-
db: this.db,
|
|
174
|
+
dbo: this.dbo as any,
|
|
175
|
+
db: this.db,
|
|
158
176
|
tables: this.dboBuilder.tables,
|
|
159
|
-
reason
|
|
177
|
+
reason,
|
|
160
178
|
});
|
|
161
179
|
} catch (err) {
|
|
162
|
-
console.error("Prostgles: Error within onReady: \n", err)
|
|
180
|
+
console.error("Prostgles: Error within onReady: \n", err);
|
|
163
181
|
}
|
|
164
182
|
|
|
165
183
|
this.loaded = true;
|
|
@@ -171,36 +189,36 @@ export const initProstgles = async function(this: Prostgles, onReady: OnReadyCal
|
|
|
171
189
|
getTSSchema: this.getTSFileContent,
|
|
172
190
|
options: this.opts,
|
|
173
191
|
update: async (newOpts) => {
|
|
174
|
-
|
|
175
|
-
getKeys(newOpts).forEach(k => {
|
|
192
|
+
getKeys(newOpts).forEach((k) => {
|
|
176
193
|
//@ts-ignore
|
|
177
194
|
this.opts[k] = newOpts[k];
|
|
178
195
|
});
|
|
179
196
|
|
|
180
|
-
|
|
181
|
-
if("fileTable" in newOpts){
|
|
197
|
+
if ("fileTable" in newOpts) {
|
|
182
198
|
await this.initFileTable();
|
|
183
199
|
}
|
|
184
|
-
if("restApi" in newOpts){
|
|
200
|
+
if ("restApi" in newOpts) {
|
|
185
201
|
await this.initRestApi();
|
|
186
202
|
}
|
|
187
|
-
if("tableConfig" in newOpts){
|
|
203
|
+
if ("tableConfig" in newOpts) {
|
|
188
204
|
await this.initTableConfig({ type: "prgl.update", newOpts });
|
|
189
205
|
}
|
|
190
|
-
if("schema" in newOpts){
|
|
206
|
+
if ("schema" in newOpts) {
|
|
191
207
|
await this.refreshDBO();
|
|
192
208
|
}
|
|
193
|
-
if("auth" in newOpts){
|
|
209
|
+
if ("auth" in newOpts) {
|
|
194
210
|
await this.initAuthHandler();
|
|
195
211
|
}
|
|
196
212
|
|
|
197
|
-
if(isEmpty(newOpts)) return;
|
|
213
|
+
if (isEmpty(newOpts)) return;
|
|
198
214
|
|
|
199
|
-
/**
|
|
200
|
-
* Some of these changes require clients to reconnect
|
|
215
|
+
/**
|
|
216
|
+
* Some of these changes require clients to reconnect
|
|
201
217
|
* While others also affect the server and onReady should be called
|
|
202
|
-
|
|
203
|
-
if
|
|
218
|
+
*/
|
|
219
|
+
if (
|
|
220
|
+
getKeys(newOpts).every((updatedKey) => clientOnlyUpdateKeys.includes(updatedKey as any))
|
|
221
|
+
) {
|
|
204
222
|
await this.setSocketEvents();
|
|
205
223
|
} else {
|
|
206
224
|
await this.init(onReady, { type: "prgl.update", newOpts });
|
|
@@ -208,22 +226,22 @@ export const initProstgles = async function(this: Prostgles, onReady: OnReadyCal
|
|
|
208
226
|
},
|
|
209
227
|
restart: () => this.init(onReady, { type: "prgl.restart" }),
|
|
210
228
|
destroy: async () => {
|
|
211
|
-
console.log("destroying prgl instance")
|
|
229
|
+
console.log("destroying prgl instance");
|
|
212
230
|
this.destroyed = true;
|
|
213
231
|
if (this.opts.io) {
|
|
214
232
|
this.opts.io.on("connection", () => {
|
|
215
|
-
console.log("Socket connected to destroyed instance")
|
|
233
|
+
console.log("Socket connected to destroyed instance");
|
|
216
234
|
});
|
|
217
235
|
|
|
218
236
|
/** Try to close IO without stopping http server */
|
|
219
|
-
if(this.opts.io.sockets.constructor.name === "Namespace"){
|
|
237
|
+
if (this.opts.io.sockets.constructor.name === "Namespace") {
|
|
220
238
|
for (const socket of this.opts.io.sockets.sockets.values()) {
|
|
221
239
|
socket._onclose("server shutting down");
|
|
222
240
|
}
|
|
223
241
|
}
|
|
224
|
-
if(this.opts.io.engine.constructor.name ===
|
|
242
|
+
if (this.opts.io.engine.constructor.name === "Server") {
|
|
225
243
|
this.opts.io.engine.close();
|
|
226
|
-
}
|
|
244
|
+
}
|
|
227
245
|
}
|
|
228
246
|
this.fileManager?.destroy();
|
|
229
247
|
this.dboBuilder?.destroy();
|
|
@@ -234,57 +252,74 @@ export const initProstgles = async function(this: Prostgles, onReady: OnReadyCal
|
|
|
234
252
|
await db.$pool.end();
|
|
235
253
|
await sleep(1000);
|
|
236
254
|
return true;
|
|
237
|
-
}
|
|
255
|
+
},
|
|
238
256
|
};
|
|
239
257
|
} catch (e: any) {
|
|
240
|
-
console.trace(e)
|
|
258
|
+
console.trace(e);
|
|
241
259
|
throw "init issues: " + e.toString();
|
|
242
260
|
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
type GetDbConnectionArgs = Pick<
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
const isFresh = !useCount;
|
|
268
|
-
if (isFresh && !client.listeners('notice').length) {
|
|
269
|
-
client.on('notice', function (msg) {
|
|
270
|
-
if (onNotice) {
|
|
271
|
-
onNotice(msg, msg?.message);
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
type GetDbConnectionArgs = Pick<
|
|
264
|
+
ProstglesInitOptions,
|
|
265
|
+
"DEBUG_MODE" | "onQuery" | "dbConnection" | "dbOptions" | "onNotice"
|
|
266
|
+
>;
|
|
267
|
+
const getDbConnection = function ({
|
|
268
|
+
dbConnection,
|
|
269
|
+
onQuery,
|
|
270
|
+
DEBUG_MODE,
|
|
271
|
+
dbOptions,
|
|
272
|
+
onNotice,
|
|
273
|
+
}: GetDbConnectionArgs): { db: DB; pgp: PGP } {
|
|
274
|
+
const onQueryOrError:
|
|
275
|
+
| undefined
|
|
276
|
+
| ((error: any, ctx: pgPromise.IEventContext<pg.IClient>) => void) =
|
|
277
|
+
!onQuery && !DEBUG_MODE
|
|
278
|
+
? undefined
|
|
279
|
+
: (error, ctx) => {
|
|
280
|
+
if (onQuery) {
|
|
281
|
+
onQuery(error, ctx);
|
|
282
|
+
} else if (DEBUG_MODE) {
|
|
283
|
+
if (error) {
|
|
284
|
+
console.error(error, ctx);
|
|
272
285
|
} else {
|
|
273
|
-
console.log(
|
|
286
|
+
console.log(ctx);
|
|
274
287
|
}
|
|
275
|
-
}
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
const pgp: PGP = pgPromise({
|
|
292
|
+
...(onQueryOrError
|
|
293
|
+
? {
|
|
294
|
+
query: (ctx) => onQueryOrError(undefined, ctx),
|
|
295
|
+
error: onQueryOrError,
|
|
276
296
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
297
|
+
: {}),
|
|
298
|
+
...(onNotice || DEBUG_MODE
|
|
299
|
+
? {
|
|
300
|
+
connect: function ({ client, useCount }) {
|
|
301
|
+
const isFresh = !useCount;
|
|
302
|
+
if (isFresh && !client.listeners("notice").length) {
|
|
303
|
+
client.on("notice", function (msg) {
|
|
304
|
+
if (onNotice) {
|
|
305
|
+
onNotice(msg, msg?.message);
|
|
306
|
+
} else {
|
|
307
|
+
console.log("notice: %j", msg?.message);
|
|
308
|
+
}
|
|
309
|
+
});
|
|
283
310
|
}
|
|
284
|
-
|
|
311
|
+
if (isFresh && !client.listeners("error").length) {
|
|
312
|
+
client.on("error", function (msg) {
|
|
313
|
+
if (onNotice) {
|
|
314
|
+
onNotice(msg, msg?.message);
|
|
315
|
+
} else {
|
|
316
|
+
console.log("error: %j", msg?.message);
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
},
|
|
285
321
|
}
|
|
286
|
-
},
|
|
287
|
-
} : {})
|
|
322
|
+
: {}),
|
|
288
323
|
});
|
|
289
324
|
// pgp.pg.defaults.max = 70;
|
|
290
325
|
|
|
@@ -301,10 +336,9 @@ const getDbConnection = function({ dbConnection, onQuery, DEBUG_MODE, dbOptions,
|
|
|
301
336
|
// pgp.pg.types.setTypeParser(1114, v => v); // timestamp without time zone
|
|
302
337
|
// pgp.pg.types.setTypeParser(1184, v => v); // timestamp with time zone
|
|
303
338
|
// pgp.pg.types.setTypeParser(1182, v => v); // date
|
|
304
|
-
pgp.pg.types.setTypeParser(pgp.pg.types.builtins.TIMESTAMP, v => v); // timestamp without time zone
|
|
305
|
-
pgp.pg.types.setTypeParser(pgp.pg.types.builtins.TIMESTAMPTZ, v => v); // timestamp with time zone
|
|
306
|
-
pgp.pg.types.setTypeParser(pgp.pg.types.builtins.DATE, v => v); // date
|
|
307
|
-
|
|
339
|
+
pgp.pg.types.setTypeParser(pgp.pg.types.builtins.TIMESTAMP, (v) => v); // timestamp without time zone
|
|
340
|
+
pgp.pg.types.setTypeParser(pgp.pg.types.builtins.TIMESTAMPTZ, (v) => v); // timestamp with time zone
|
|
341
|
+
pgp.pg.types.setTypeParser(pgp.pg.types.builtins.DATE, (v) => v); // date
|
|
308
342
|
|
|
309
343
|
if (dbOptions) {
|
|
310
344
|
Object.assign(pgp.pg.defaults, dbOptions);
|
|
@@ -312,6 +346,6 @@ const getDbConnection = function({ dbConnection, onQuery, DEBUG_MODE, dbOptions,
|
|
|
312
346
|
|
|
313
347
|
return {
|
|
314
348
|
db: pgp(dbConnection),
|
|
315
|
-
pgp
|
|
349
|
+
pgp,
|
|
316
350
|
};
|
|
317
|
-
}
|
|
351
|
+
};
|
package/lib/utils.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
|
|
2
1
|
export { get } from "prostgles-types";
|
|
3
2
|
export const clone = <T extends any[] | Record<string, any>>(obj: T): T => {
|
|
4
|
-
if(typeof structuredClone !== "undefined"){
|
|
3
|
+
if (typeof structuredClone !== "undefined") {
|
|
5
4
|
return structuredClone(obj);
|
|
6
5
|
}
|
|
7
|
-
|
|
6
|
+
|
|
8
7
|
return JSON.parse(JSON.stringify(obj));
|
|
9
|
-
}
|
|
8
|
+
};
|
|
10
9
|
|
|
11
10
|
export const sleep = function (ms: number) {
|
|
12
11
|
return new Promise((resolve) => {
|
|
13
12
|
setTimeout(resolve, ms);
|
|
14
13
|
});
|
|
15
|
-
}
|
|
14
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prostgles-server",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.180",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"pg": "^8.11.5",
|
|
55
55
|
"pg-cursor": "^2.11.0",
|
|
56
56
|
"pg-promise": "^11.9.1",
|
|
57
|
-
"prostgles-types": "^4.0.
|
|
57
|
+
"prostgles-types": "^4.0.117"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@types/express": "^4.17.21",
|
|
@@ -67,6 +67,7 @@
|
|
|
67
67
|
"@typescript-eslint/eslint-plugin": "^8.15.0",
|
|
68
68
|
"@typescript-eslint/parser": "^8.15.0",
|
|
69
69
|
"eslint": "^8.51.0",
|
|
70
|
+
"prettier": "^3.4.2",
|
|
70
71
|
"socket.io": "^4.8.1",
|
|
71
72
|
"typescript": "^5.3.3"
|
|
72
73
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":""}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const path_1 = __importDefault(require("path"));
|
|
7
|
-
const express_1 = __importDefault(require("express"));
|
|
8
|
-
// const prostgles = require("prostgles-server");
|
|
9
|
-
const index_1 = __importDefault(require("../../../dist/index"));
|
|
10
|
-
const app = express_1.default();
|
|
11
|
-
const http = require('http').createServer(app);
|
|
12
|
-
const io = require("socket.io")(http);
|
|
13
|
-
http.listen(3001);
|
|
14
|
-
index_1.default({
|
|
15
|
-
dbConnection: {
|
|
16
|
-
host: "localhost",
|
|
17
|
-
port: 5432,
|
|
18
|
-
database: "postgres",
|
|
19
|
-
user: process.env.PRGL_USER,
|
|
20
|
-
password: process.env.PRGL_PWD
|
|
21
|
-
},
|
|
22
|
-
sqlFilePath: path_1.default.join(__dirname + '/init.sql'),
|
|
23
|
-
io,
|
|
24
|
-
tsGeneratedTypesDir: path_1.default.join(__dirname + '/'),
|
|
25
|
-
transactions: "tt",
|
|
26
|
-
publish: (socket, dbo) => {
|
|
27
|
-
return "*";
|
|
28
|
-
},
|
|
29
|
-
joins: [
|
|
30
|
-
{
|
|
31
|
-
tables: ["items", "items2"],
|
|
32
|
-
on: { name: "name" },
|
|
33
|
-
type: "many-many"
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
tables: ["items2", "items3"],
|
|
37
|
-
on: { name: "name" },
|
|
38
|
-
type: "many-many"
|
|
39
|
-
}
|
|
40
|
-
],
|
|
41
|
-
onReady: async (dbo, db) => {
|
|
42
|
-
app.get("*", (req, res) => {
|
|
43
|
-
console.log(req.originalUrl);
|
|
44
|
-
});
|
|
45
|
-
try {
|
|
46
|
-
await dbo.items.insert([{ name: "a" }, { name: "a" }]);
|
|
47
|
-
console.log(await dbo.items.find());
|
|
48
|
-
}
|
|
49
|
-
catch (err) {
|
|
50
|
-
console.error(err);
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;AAAA,gDAAwB;AACxB,sDAA8B;AAC9B,iDAAiD;AACjD,gEAA4C;AAC5C,MAAM,GAAG,GAAG,iBAAO,EAAE,CAAC;AACtB,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;AAC/C,MAAM,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC;AACtC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAIlB,eAAS,CAAC;IACT,YAAY,EAAE;QACb,IAAI,EAAE,WAAW;QACjB,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,UAAU;QACpB,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS;QAC3B,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ;KAC9B;IACD,WAAW,EAAE,cAAI,CAAC,IAAI,CAAC,SAAS,GAAC,WAAW,CAAC;IAC7C,EAAE;IACF,mBAAmB,EAAE,cAAI,CAAC,IAAI,CAAC,SAAS,GAAG,GAAG,CAAC;IAC/C,YAAY,EAAE,IAAI;IAClB,OAAO,EAAE,CAAC,MAAM,EAAE,GAAU,EAAE,EAAE;QAE/B,OAAO,GAAG,CAAC;IACZ,CAAC;IACD,KAAK,EAAE;QACN;YACC,MAAM,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC;YAC3B,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;YACpB,IAAI,EAAE,WAAW;SACjB;QACD;YACC,MAAM,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC;YAC5B,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;YACpB,IAAI,EAAE,WAAW;SACjB;KACD;IACD,OAAO,EAAE,KAAK,EAAE,GAAU,EAAE,EAAE,EAAE,EAAE;QAEjC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YACzB,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;QAC7B,CAAC,CAAC,CAAA;QACF,IAAI;YAEH,MAAM,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC;YACvD,OAAO,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;SAGpC;QAAC,OAAM,GAAG,EAAE;YACZ,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;SAClB;IACF,CAAC;CACD,CAAC,CAAC"}
|