prostgles-server 3.0.70 → 3.0.72
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/PubSubManager.d.ts +4 -4
- package/dist/PubSubManager/PubSubManager.d.ts.map +1 -1
- package/dist/PubSubManager/PubSubManager.js.map +1 -1
- package/dist/PubSubManager/initPubSubManager.d.ts.map +1 -1
- package/dist/PubSubManager/initPubSubManager.js +52 -36
- package/dist/PubSubManager/initPubSubManager.js.map +1 -1
- package/lib/AuthHandler.js +213 -209
- package/lib/DBEventsManager.js +34 -31
- package/lib/DboBuilder/QueryBuilder/QueryBuilder.js +163 -155
- package/lib/DboBuilder/TableHandler.js +21 -20
- package/lib/DboBuilder/ViewHandler.js +23 -8
- package/lib/DboBuilder/runSQL.js +5 -5
- package/lib/DboBuilder.js +85 -65
- package/lib/FileManager.js +369 -364
- package/lib/PostgresNotifListenManager.js +26 -20
- package/lib/Prostgles.js +194 -177
- package/lib/PubSubManager/PubSubManager.d.ts +4 -4
- package/lib/PubSubManager/PubSubManager.d.ts.map +1 -1
- package/lib/PubSubManager/PubSubManager.js +249 -239
- package/lib/PubSubManager/PubSubManager.ts +1 -1
- package/lib/PubSubManager/initPubSubManager.d.ts.map +1 -1
- package/lib/PubSubManager/initPubSubManager.js +52 -36
- package/lib/PubSubManager/initPubSubManager.ts +53 -37
- package/lib/PublishParser.js +7 -2
- package/lib/SchemaWatch.js +2 -1
- package/lib/TableConfig.js +94 -91
- package/package.json +2 -2
- package/tests/client/PID.txt +1 -1
- package/tests/client/tsconfig.json +2 -2
- package/tests/server/package-lock.json +3 -3
- package/tests/server/tsconfig.json +2 -2
|
@@ -6,23 +6,17 @@
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.PostgresNotifListenManager = void 0;
|
|
8
8
|
class PostgresNotifListenManager {
|
|
9
|
+
connection;
|
|
10
|
+
db_pg;
|
|
11
|
+
notifListener;
|
|
12
|
+
db_channel_name;
|
|
13
|
+
isListening;
|
|
14
|
+
client;
|
|
15
|
+
static create = (db_pg, notifListener, db_channel_name) => {
|
|
16
|
+
let res = new PostgresNotifListenManager(db_pg, notifListener, db_channel_name, true);
|
|
17
|
+
return res.init();
|
|
18
|
+
};
|
|
9
19
|
constructor(db_pg, notifListener, db_channel_name, noInit = false) {
|
|
10
|
-
this.destroyed = false;
|
|
11
|
-
this.destroy = () => {
|
|
12
|
-
if (this.connection) {
|
|
13
|
-
this.destroyed = true;
|
|
14
|
-
this.connection.done();
|
|
15
|
-
this.connection = undefined;
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
this.stopListening = () => {
|
|
19
|
-
if (this.db_channel_name) {
|
|
20
|
-
if (this.connection)
|
|
21
|
-
this.connection.none('UNLISTEN $1~', this.db_channel_name);
|
|
22
|
-
if (this.client)
|
|
23
|
-
this.client.query('UNLISTEN $1~', this.db_channel_name);
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
20
|
if (!db_pg || !notifListener || !db_channel_name)
|
|
27
21
|
throw "PostgresNotifListenManager: db_pg OR notifListener OR db_channel_name MISSING";
|
|
28
22
|
this.db_pg = db_pg;
|
|
@@ -66,6 +60,22 @@ class PostgresNotifListenManager {
|
|
|
66
60
|
console.log('PostgresNotifListenManager: Failed Initial Connection:', error);
|
|
67
61
|
});
|
|
68
62
|
}
|
|
63
|
+
destroyed = false;
|
|
64
|
+
destroy = () => {
|
|
65
|
+
if (this.connection) {
|
|
66
|
+
this.destroyed = true;
|
|
67
|
+
this.connection.done();
|
|
68
|
+
this.connection = undefined;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
stopListening = () => {
|
|
72
|
+
if (this.db_channel_name) {
|
|
73
|
+
if (this.connection)
|
|
74
|
+
this.connection.none('UNLISTEN $1~', this.db_channel_name);
|
|
75
|
+
if (this.client)
|
|
76
|
+
this.client.query('UNLISTEN $1~', this.db_channel_name);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
69
79
|
reconnect(delay = 0, maxAttempts = 0) {
|
|
70
80
|
if (!this.db_pg || !this.notifListener)
|
|
71
81
|
throw "db_pg OR notifListener missing";
|
|
@@ -122,7 +132,3 @@ class PostgresNotifListenManager {
|
|
|
122
132
|
}
|
|
123
133
|
}
|
|
124
134
|
exports.PostgresNotifListenManager = PostgresNotifListenManager;
|
|
125
|
-
PostgresNotifListenManager.create = (db_pg, notifListener, db_channel_name) => {
|
|
126
|
-
let res = new PostgresNotifListenManager(db_pg, notifListener, db_channel_name, true);
|
|
127
|
-
return res.init();
|
|
128
|
-
};
|
package/lib/Prostgles.js
CHANGED
|
@@ -117,173 +117,48 @@ const DEFAULT_KEYWORDS = {
|
|
|
117
117
|
};
|
|
118
118
|
const fs = __importStar(require("fs"));
|
|
119
119
|
class Prostgles {
|
|
120
|
+
opts = {
|
|
121
|
+
DEBUG_MODE: false,
|
|
122
|
+
dbConnection: {
|
|
123
|
+
host: "localhost",
|
|
124
|
+
port: 5432,
|
|
125
|
+
application_name: "prostgles_app"
|
|
126
|
+
},
|
|
127
|
+
onReady: () => { },
|
|
128
|
+
schema: "public",
|
|
129
|
+
watchSchema: false,
|
|
130
|
+
watchSchemaType: "DDL_trigger",
|
|
131
|
+
};
|
|
132
|
+
// dbConnection: DbConnection = {
|
|
133
|
+
// host: "localhost",
|
|
134
|
+
// port: 5432,
|
|
135
|
+
// application_name: "prostgles_app"
|
|
136
|
+
// };
|
|
137
|
+
// dbOptions: DbConnectionOpts;
|
|
138
|
+
db;
|
|
139
|
+
pgp;
|
|
140
|
+
dbo;
|
|
141
|
+
_dboBuilder;
|
|
142
|
+
get dboBuilder() {
|
|
143
|
+
if (!this._dboBuilder)
|
|
144
|
+
throw "get dboBuilder: it's undefined";
|
|
145
|
+
return this._dboBuilder;
|
|
146
|
+
}
|
|
147
|
+
set dboBuilder(d) {
|
|
148
|
+
this._dboBuilder = d;
|
|
149
|
+
}
|
|
150
|
+
publishParser;
|
|
151
|
+
authHandler;
|
|
152
|
+
schemaWatch;
|
|
153
|
+
keywords = DEFAULT_KEYWORDS;
|
|
154
|
+
loaded = false;
|
|
155
|
+
dbEventsManager;
|
|
156
|
+
fileManager;
|
|
157
|
+
tableConfigurator;
|
|
158
|
+
isMedia(tableName) {
|
|
159
|
+
return this.opts?.fileTable?.tableName === tableName;
|
|
160
|
+
}
|
|
120
161
|
constructor(params) {
|
|
121
|
-
this.opts = {
|
|
122
|
-
DEBUG_MODE: false,
|
|
123
|
-
dbConnection: {
|
|
124
|
-
host: "localhost",
|
|
125
|
-
port: 5432,
|
|
126
|
-
application_name: "prostgles_app"
|
|
127
|
-
},
|
|
128
|
-
onReady: () => { },
|
|
129
|
-
schema: "public",
|
|
130
|
-
watchSchema: false,
|
|
131
|
-
watchSchemaType: "DDL_trigger",
|
|
132
|
-
};
|
|
133
|
-
this.keywords = DEFAULT_KEYWORDS;
|
|
134
|
-
this.loaded = false;
|
|
135
|
-
this.destroyed = false;
|
|
136
|
-
this.getTSFileContent = () => {
|
|
137
|
-
const header = `/* This file was generated by Prostgles \n` +
|
|
138
|
-
// `* ${(new Date).toUTCString()} \n`
|
|
139
|
-
`*/ \n\n `;
|
|
140
|
-
return header + this.dboBuilder.tsTypesDefinition;
|
|
141
|
-
};
|
|
142
|
-
/**
|
|
143
|
-
* Will re-create the dbo object
|
|
144
|
-
*/
|
|
145
|
-
this.refreshDBO = async () => {
|
|
146
|
-
if (this._dboBuilder) {
|
|
147
|
-
await this._dboBuilder.build();
|
|
148
|
-
// this._dboBuilder.destroy();
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
this.dboBuilder = await DboBuilder_1.DboBuilder.create(this);
|
|
152
|
-
}
|
|
153
|
-
if (!this.dboBuilder)
|
|
154
|
-
throw "this.dboBuilder";
|
|
155
|
-
this.dbo = this.dboBuilder.dbo;
|
|
156
|
-
return this.dbo;
|
|
157
|
-
};
|
|
158
|
-
this.initWatchSchema = (onReady) => {
|
|
159
|
-
if (this.opts.watchSchema === "hotReloadMode" && !this.opts.tsGeneratedTypesDir) {
|
|
160
|
-
throw "tsGeneratedTypesDir option is needed for watchSchema: hotReloadMode to work ";
|
|
161
|
-
}
|
|
162
|
-
else if (this.opts.watchSchema &&
|
|
163
|
-
typeof this.opts.watchSchemaType === "object" &&
|
|
164
|
-
"checkIntervalMillis" in this.opts.watchSchemaType &&
|
|
165
|
-
typeof this.opts.watchSchemaType.checkIntervalMillis === "number") {
|
|
166
|
-
if (this.schema_checkIntervalMillis) {
|
|
167
|
-
clearInterval(this.schema_checkIntervalMillis);
|
|
168
|
-
}
|
|
169
|
-
this.schema_checkIntervalMillis = setInterval(async () => {
|
|
170
|
-
if (!this.loaded)
|
|
171
|
-
return;
|
|
172
|
-
const dbuilder = await DboBuilder_1.DboBuilder.create(this);
|
|
173
|
-
if (dbuilder.tsTypesDefinition !== this.dboBuilder.tsTypesDefinition) {
|
|
174
|
-
await this.refreshDBO();
|
|
175
|
-
this.init(onReady);
|
|
176
|
-
}
|
|
177
|
-
}, this.opts.watchSchemaType.checkIntervalMillis);
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
/* Create media table if required */
|
|
181
|
-
this.initFileTable = async () => {
|
|
182
|
-
if (this.opts.fileTable) {
|
|
183
|
-
const { awsS3Config, localConfig, imageOptions } = this.opts.fileTable;
|
|
184
|
-
await this.refreshDBO();
|
|
185
|
-
if (!awsS3Config && !localConfig)
|
|
186
|
-
throw "fileTable missing param: Must provide awsS3Config OR localConfig";
|
|
187
|
-
this.fileManager = new FileManager_1.default(awsS3Config || localConfig, imageOptions);
|
|
188
|
-
try {
|
|
189
|
-
await this.fileManager.init(this);
|
|
190
|
-
}
|
|
191
|
-
catch (e) {
|
|
192
|
-
console.error("FileManager: ", e);
|
|
193
|
-
throw e;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
await this.refreshDBO();
|
|
197
|
-
};
|
|
198
|
-
this.isSuperUser = false;
|
|
199
|
-
this.connectedSockets = [];
|
|
200
|
-
this.pushSocketSchema = async (socket) => {
|
|
201
|
-
try {
|
|
202
|
-
let { auth, userData } = await this.authHandler?.makeSocketAuth(socket) || {};
|
|
203
|
-
// let needType = this.publishRawSQL && typeof this.publishRawSQL === "function";
|
|
204
|
-
// let DATA_TYPES = !needType? [] : await this.db.any("SELECT oid, typname FROM pg_type");
|
|
205
|
-
// let USER_TABLES = !needType? [] : await this.db.any("SELECT relid, relname FROM pg_catalog.pg_statio_user_tables");
|
|
206
|
-
const { dbo, db, pgp, publishParser } = this;
|
|
207
|
-
let fullSchema;
|
|
208
|
-
let publishValidationError;
|
|
209
|
-
let rawSQL = false;
|
|
210
|
-
try {
|
|
211
|
-
if (!publishParser)
|
|
212
|
-
throw "publishParser undefined";
|
|
213
|
-
fullSchema = await publishParser.getSchemaFromPublish(socket, userData);
|
|
214
|
-
}
|
|
215
|
-
catch (e) {
|
|
216
|
-
publishValidationError = "Server Error: PUBLISH VALIDATION ERROR";
|
|
217
|
-
console.error(`\nProstgles PUBLISH VALIDATION ERROR (after socket connected):\n ->`, e);
|
|
218
|
-
}
|
|
219
|
-
socket.prostgles = socket.prostgles || {};
|
|
220
|
-
socket.prostgles.schema = fullSchema?.schema;
|
|
221
|
-
/* RUN Raw sql from client IF PUBLISHED
|
|
222
|
-
*/
|
|
223
|
-
if (this.opts.publishRawSQL && typeof this.opts.publishRawSQL === "function") {
|
|
224
|
-
const canRunSQL = async () => {
|
|
225
|
-
const publishParams = await this.publishParser?.getPublishParams({ socket });
|
|
226
|
-
let res = await this.opts.publishRawSQL?.(publishParams);
|
|
227
|
-
return Boolean(res && typeof res === "boolean" || res === "*");
|
|
228
|
-
};
|
|
229
|
-
if (await canRunSQL()) {
|
|
230
|
-
socket.removeAllListeners(prostgles_types_1.CHANNELS.SQL);
|
|
231
|
-
socket.on(prostgles_types_1.CHANNELS.SQL, async ({ query, params, options }, cb = (...callback) => { }) => {
|
|
232
|
-
if (!this.dbo?.sql)
|
|
233
|
-
throw "Internal error: sql handler missing";
|
|
234
|
-
this.dbo.sql(query, params, options, { socket }).then(res => {
|
|
235
|
-
cb(null, res);
|
|
236
|
-
}).catch(err => {
|
|
237
|
-
makeSocketError(cb, err);
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
if (db) {
|
|
241
|
-
// let allTablesViews = await db.any(STEP2_GET_ALL_TABLES_AND_COLUMNS);
|
|
242
|
-
// fullSchema = allTablesViews;
|
|
243
|
-
rawSQL = true;
|
|
244
|
-
}
|
|
245
|
-
else
|
|
246
|
-
console.error("db missing");
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
const { schema, tables } = fullSchema ?? { schema: {}, tables: [] };
|
|
250
|
-
let joinTables2 = [];
|
|
251
|
-
if (this.opts.joins) {
|
|
252
|
-
let _joinTables2 = this.dboBuilder.getJoinPaths()
|
|
253
|
-
.filter(jp => ![jp.t1, jp.t2].find(t => !schema[t] || !schema[t].findOne)).map(jp => [jp.t1, jp.t2].sort());
|
|
254
|
-
_joinTables2.map(jt => {
|
|
255
|
-
if (!joinTables2.find(_jt => _jt.join() === jt.join())) {
|
|
256
|
-
joinTables2.push(jt);
|
|
257
|
-
}
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
const methods = await publishParser?.getAllowedMethods(socket, userData);
|
|
261
|
-
const methodSchema = !methods ? [] : (0, prostgles_types_1.getKeys)(methods).map(methodName => {
|
|
262
|
-
const method = methods[methodName];
|
|
263
|
-
if ((0, prostgles_types_1.isObject)(method) && "run" in method) {
|
|
264
|
-
return {
|
|
265
|
-
name: methodName,
|
|
266
|
-
...(0, PubSubManager_1.pickKeys)(method, ["input", "output"])
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
return methodName;
|
|
270
|
-
});
|
|
271
|
-
const clientSchema = {
|
|
272
|
-
schema,
|
|
273
|
-
methods: methodSchema,
|
|
274
|
-
tableSchema: tables,
|
|
275
|
-
rawSQL,
|
|
276
|
-
joinTables: joinTables2,
|
|
277
|
-
auth,
|
|
278
|
-
version,
|
|
279
|
-
err: publishValidationError
|
|
280
|
-
};
|
|
281
|
-
socket.emit(prostgles_types_1.CHANNELS.SCHEMA, clientSchema);
|
|
282
|
-
}
|
|
283
|
-
catch (err) {
|
|
284
|
-
socket.emit(prostgles_types_1.CHANNELS.SCHEMA, { err });
|
|
285
|
-
}
|
|
286
|
-
};
|
|
287
162
|
if (!params)
|
|
288
163
|
throw "ProstglesInitOptions missing";
|
|
289
164
|
if (!params.io)
|
|
@@ -311,17 +186,7 @@ class Prostgles {
|
|
|
311
186
|
...params.keywords,
|
|
312
187
|
};
|
|
313
188
|
}
|
|
314
|
-
|
|
315
|
-
if (!this._dboBuilder)
|
|
316
|
-
throw "get dboBuilder: it's undefined";
|
|
317
|
-
return this._dboBuilder;
|
|
318
|
-
}
|
|
319
|
-
set dboBuilder(d) {
|
|
320
|
-
this._dboBuilder = d;
|
|
321
|
-
}
|
|
322
|
-
isMedia(tableName) {
|
|
323
|
-
return this.opts?.fileTable?.tableName === tableName;
|
|
324
|
-
}
|
|
189
|
+
destroyed = false;
|
|
325
190
|
async onSchemaChange(event) {
|
|
326
191
|
const { watchSchema, watchSchemaType, onReady, tsGeneratedTypesDir } = this.opts;
|
|
327
192
|
if (watchSchema && this.loaded) {
|
|
@@ -369,6 +234,12 @@ class Prostgles {
|
|
|
369
234
|
});
|
|
370
235
|
});
|
|
371
236
|
}
|
|
237
|
+
getTSFileContent = () => {
|
|
238
|
+
const header = `/* This file was generated by Prostgles \n` +
|
|
239
|
+
// `* ${(new Date).toUTCString()} \n`
|
|
240
|
+
`*/ \n\n `;
|
|
241
|
+
return header + this.dboBuilder.tsTypesDefinition;
|
|
242
|
+
};
|
|
372
243
|
/**
|
|
373
244
|
* Will write the Schema Typescript definitions to file (tsGeneratedTypesDir)
|
|
374
245
|
*/
|
|
@@ -387,6 +258,64 @@ class Prostgles {
|
|
|
387
258
|
console.error("Schema changed. tsGeneratedTypesDir needs to be set to reload server");
|
|
388
259
|
}
|
|
389
260
|
}
|
|
261
|
+
/**
|
|
262
|
+
* Will re-create the dbo object
|
|
263
|
+
*/
|
|
264
|
+
refreshDBO = async () => {
|
|
265
|
+
if (this._dboBuilder) {
|
|
266
|
+
await this._dboBuilder.build();
|
|
267
|
+
// this._dboBuilder.destroy();
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
this.dboBuilder = await DboBuilder_1.DboBuilder.create(this);
|
|
271
|
+
}
|
|
272
|
+
if (!this.dboBuilder)
|
|
273
|
+
throw "this.dboBuilder";
|
|
274
|
+
this.dbo = this.dboBuilder.dbo;
|
|
275
|
+
return this.dbo;
|
|
276
|
+
};
|
|
277
|
+
initWatchSchema = (onReady) => {
|
|
278
|
+
if (this.opts.watchSchema === "hotReloadMode" && !this.opts.tsGeneratedTypesDir) {
|
|
279
|
+
throw "tsGeneratedTypesDir option is needed for watchSchema: hotReloadMode to work ";
|
|
280
|
+
}
|
|
281
|
+
else if (this.opts.watchSchema &&
|
|
282
|
+
typeof this.opts.watchSchemaType === "object" &&
|
|
283
|
+
"checkIntervalMillis" in this.opts.watchSchemaType &&
|
|
284
|
+
typeof this.opts.watchSchemaType.checkIntervalMillis === "number") {
|
|
285
|
+
if (this.schema_checkIntervalMillis) {
|
|
286
|
+
clearInterval(this.schema_checkIntervalMillis);
|
|
287
|
+
}
|
|
288
|
+
this.schema_checkIntervalMillis = setInterval(async () => {
|
|
289
|
+
if (!this.loaded)
|
|
290
|
+
return;
|
|
291
|
+
const dbuilder = await DboBuilder_1.DboBuilder.create(this);
|
|
292
|
+
if (dbuilder.tsTypesDefinition !== this.dboBuilder.tsTypesDefinition) {
|
|
293
|
+
await this.refreshDBO();
|
|
294
|
+
this.init(onReady);
|
|
295
|
+
}
|
|
296
|
+
}, this.opts.watchSchemaType.checkIntervalMillis);
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
/* Create media table if required */
|
|
300
|
+
initFileTable = async () => {
|
|
301
|
+
if (this.opts.fileTable) {
|
|
302
|
+
const { awsS3Config, localConfig, imageOptions } = this.opts.fileTable;
|
|
303
|
+
await this.refreshDBO();
|
|
304
|
+
if (!awsS3Config && !localConfig)
|
|
305
|
+
throw "fileTable missing param: Must provide awsS3Config OR localConfig";
|
|
306
|
+
this.fileManager = new FileManager_1.default(awsS3Config || localConfig, imageOptions);
|
|
307
|
+
try {
|
|
308
|
+
await this.fileManager.init(this);
|
|
309
|
+
}
|
|
310
|
+
catch (e) {
|
|
311
|
+
console.error("FileManager: ", e);
|
|
312
|
+
throw e;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
await this.refreshDBO();
|
|
316
|
+
};
|
|
317
|
+
isSuperUser = false;
|
|
318
|
+
schema_checkIntervalMillis;
|
|
390
319
|
async init(onReady) {
|
|
391
320
|
this.loaded = false;
|
|
392
321
|
this.initWatchSchema(onReady);
|
|
@@ -520,6 +449,7 @@ class Prostgles {
|
|
|
520
449
|
throw err;
|
|
521
450
|
});
|
|
522
451
|
}
|
|
452
|
+
connectedSockets = [];
|
|
523
453
|
async setSocketEvents() {
|
|
524
454
|
this.checkDb();
|
|
525
455
|
if (!this.dbo)
|
|
@@ -629,6 +559,93 @@ class Prostgles {
|
|
|
629
559
|
}
|
|
630
560
|
});
|
|
631
561
|
}
|
|
562
|
+
pushSocketSchema = async (socket) => {
|
|
563
|
+
try {
|
|
564
|
+
let { auth, userData } = await this.authHandler?.makeSocketAuth(socket) || {};
|
|
565
|
+
// let needType = this.publishRawSQL && typeof this.publishRawSQL === "function";
|
|
566
|
+
// let DATA_TYPES = !needType? [] : await this.db.any("SELECT oid, typname FROM pg_type");
|
|
567
|
+
// let USER_TABLES = !needType? [] : await this.db.any("SELECT relid, relname FROM pg_catalog.pg_statio_user_tables");
|
|
568
|
+
const { dbo, db, pgp, publishParser } = this;
|
|
569
|
+
let fullSchema;
|
|
570
|
+
let publishValidationError;
|
|
571
|
+
let rawSQL = false;
|
|
572
|
+
try {
|
|
573
|
+
if (!publishParser)
|
|
574
|
+
throw "publishParser undefined";
|
|
575
|
+
fullSchema = await publishParser.getSchemaFromPublish(socket, userData);
|
|
576
|
+
}
|
|
577
|
+
catch (e) {
|
|
578
|
+
publishValidationError = "Server Error: PUBLISH VALIDATION ERROR";
|
|
579
|
+
console.error(`\nProstgles PUBLISH VALIDATION ERROR (after socket connected):\n ->`, e);
|
|
580
|
+
}
|
|
581
|
+
socket.prostgles = socket.prostgles || {};
|
|
582
|
+
socket.prostgles.schema = fullSchema?.schema;
|
|
583
|
+
/* RUN Raw sql from client IF PUBLISHED
|
|
584
|
+
*/
|
|
585
|
+
if (this.opts.publishRawSQL && typeof this.opts.publishRawSQL === "function") {
|
|
586
|
+
const canRunSQL = async () => {
|
|
587
|
+
const publishParams = await this.publishParser?.getPublishParams({ socket });
|
|
588
|
+
let res = await this.opts.publishRawSQL?.(publishParams);
|
|
589
|
+
return Boolean(res && typeof res === "boolean" || res === "*");
|
|
590
|
+
};
|
|
591
|
+
if (await canRunSQL()) {
|
|
592
|
+
socket.removeAllListeners(prostgles_types_1.CHANNELS.SQL);
|
|
593
|
+
socket.on(prostgles_types_1.CHANNELS.SQL, async ({ query, params, options }, cb = (...callback) => { }) => {
|
|
594
|
+
if (!this.dbo?.sql)
|
|
595
|
+
throw "Internal error: sql handler missing";
|
|
596
|
+
this.dbo.sql(query, params, options, { socket }).then(res => {
|
|
597
|
+
cb(null, res);
|
|
598
|
+
}).catch(err => {
|
|
599
|
+
makeSocketError(cb, err);
|
|
600
|
+
});
|
|
601
|
+
});
|
|
602
|
+
if (db) {
|
|
603
|
+
// let allTablesViews = await db.any(STEP2_GET_ALL_TABLES_AND_COLUMNS);
|
|
604
|
+
// fullSchema = allTablesViews;
|
|
605
|
+
rawSQL = true;
|
|
606
|
+
}
|
|
607
|
+
else
|
|
608
|
+
console.error("db missing");
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
const { schema, tables } = fullSchema ?? { schema: {}, tables: [] };
|
|
612
|
+
let joinTables2 = [];
|
|
613
|
+
if (this.opts.joins) {
|
|
614
|
+
let _joinTables2 = this.dboBuilder.getJoinPaths()
|
|
615
|
+
.filter(jp => ![jp.t1, jp.t2].find(t => !schema[t] || !schema[t].findOne)).map(jp => [jp.t1, jp.t2].sort());
|
|
616
|
+
_joinTables2.map(jt => {
|
|
617
|
+
if (!joinTables2.find(_jt => _jt.join() === jt.join())) {
|
|
618
|
+
joinTables2.push(jt);
|
|
619
|
+
}
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
const methods = await publishParser?.getAllowedMethods(socket, userData);
|
|
623
|
+
const methodSchema = !methods ? [] : (0, prostgles_types_1.getKeys)(methods).map(methodName => {
|
|
624
|
+
const method = methods[methodName];
|
|
625
|
+
if ((0, prostgles_types_1.isObject)(method) && "run" in method) {
|
|
626
|
+
return {
|
|
627
|
+
name: methodName,
|
|
628
|
+
...(0, PubSubManager_1.pickKeys)(method, ["input", "output"])
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
return methodName;
|
|
632
|
+
});
|
|
633
|
+
const clientSchema = {
|
|
634
|
+
schema,
|
|
635
|
+
methods: methodSchema,
|
|
636
|
+
tableSchema: tables,
|
|
637
|
+
rawSQL,
|
|
638
|
+
joinTables: joinTables2,
|
|
639
|
+
auth,
|
|
640
|
+
version,
|
|
641
|
+
err: publishValidationError
|
|
642
|
+
};
|
|
643
|
+
socket.emit(prostgles_types_1.CHANNELS.SCHEMA, clientSchema);
|
|
644
|
+
}
|
|
645
|
+
catch (err) {
|
|
646
|
+
socket.emit(prostgles_types_1.CHANNELS.SCHEMA, { err });
|
|
647
|
+
}
|
|
648
|
+
};
|
|
632
649
|
}
|
|
633
650
|
exports.Prostgles = Prostgles;
|
|
634
651
|
function makeSocketError(cb, err) {
|
|
@@ -129,10 +129,10 @@ export declare class PubSubManager {
|
|
|
129
129
|
appChecking: boolean;
|
|
130
130
|
init: any;
|
|
131
131
|
DB_OBJ_NAMES: {
|
|
132
|
-
trigger_add_remove_func:
|
|
133
|
-
data_watch_func:
|
|
134
|
-
schema_watch_func:
|
|
135
|
-
schema_watch_trigger:
|
|
132
|
+
readonly trigger_add_remove_func: "prostgles.trigger_add_remove_func";
|
|
133
|
+
readonly data_watch_func: "prostgles.prostgles_trigger_function";
|
|
134
|
+
readonly schema_watch_func: "prostgles.schema_watch_func";
|
|
135
|
+
readonly schema_watch_trigger: "prostgles_schema_watch_trigger_new";
|
|
136
136
|
};
|
|
137
137
|
static SCHEMA_ALTERING_QUERIES: string[];
|
|
138
138
|
static EXCLUDE_QUERY_FROM_SCHEMA_WATCH_ID: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PubSubManager.d.ts","sourceRoot":"","sources":["PubSubManager.ts"],"names":[],"mappings":";AAKA,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAE3E,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,YAAY,EAAc,MAAM,eAAe,CAAC;AAClH,OAAO,EAAE,EAAE,EAAe,MAAM,cAAc,CAAC;AAO/C,OAAO,EAAE,YAAY,EAAE,WAAW,EAAU,GAAG,EAAW,SAAS,EAAW,MAAM,iBAAiB,CAAC;AAEtG,OAAO,EAAE,iBAAiB,EAAY,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAO7C,eAAO,MAAM,OAAO,MAAO,GAAG,WAA6B,CAAC;AAC5D,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAE1C,eAAO,MAAM,GAAG,YAAa,GAAG,EAAE,SAIjC,CAAA;AAED,oBAAY,aAAa,GAAG,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,GAAG,KAAK,IAAI,CAAA;AAE1D,oBAAY,UAAU,GAAG;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW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