prostgles-server 2.0.173 → 2.0.174
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/DboBuilder.d.ts +1 -1
- package/dist/DboBuilder.d.ts.map +1 -1
- package/dist/DboBuilder.js +2 -17
- package/dist/DboBuilder.js.map +1 -1
- package/dist/Prostgles.d.ts +5 -2
- package/dist/Prostgles.d.ts.map +1 -1
- package/dist/Prostgles.js +34 -13
- package/dist/Prostgles.js.map +1 -1
- package/dist/TableConfig.d.ts +4 -1
- package/dist/TableConfig.d.ts.map +1 -1
- package/dist/TableConfig.js +28 -1
- package/dist/TableConfig.js.map +1 -1
- package/lib/DboBuilder.ts +9 -17
- package/lib/Prostgles.ts +48 -20
- package/lib/TableConfig.ts +34 -3
- package/package.json +2 -2
- package/tests/client/PID.txt +1 -1
- package/tests/client/index.js +2 -2
- package/tests/client/index.ts +2 -2
- package/tests/client/package-lock.json +15 -15
- package/tests/client/package.json +1 -1
- package/tests/client_only_queries.js +24 -1
- package/tests/client_only_queries.ts +23 -1
- package/tests/isomorphic_queries.js +3 -0
- package/tests/isomorphic_queries.ts +3 -0
- package/tests/server/index.js +1 -1
- package/tests/server/index.ts +1 -1
- package/tests/server/package-lock.json +3 -3
package/lib/Prostgles.ts
CHANGED
|
@@ -21,14 +21,14 @@ import { PubSubManager, DEFAULT_SYNC_BATCH_SIZE, asValue } from "./PubSubManager
|
|
|
21
21
|
export { DbHandler }
|
|
22
22
|
export type PGP = pgPromise.IMain<{}, pg.IClient>;
|
|
23
23
|
|
|
24
|
-
import { SQLRequest, TableSchemaForClient, MethodKey, CHANNELS, AnyObject, RULE_METHODS, ClientSchema, getKeys } from "prostgles-types";
|
|
24
|
+
import { SQLRequest, TableSchemaForClient, MethodKey, CHANNELS, AnyObject, RULE_METHODS, ClientSchema, getKeys, DBSchemaTable, TableInfo } from "prostgles-types";
|
|
25
25
|
|
|
26
26
|
import { DBEventsManager } from "./DBEventsManager";
|
|
27
27
|
|
|
28
28
|
export type DB = pgPromise.IDatabase<{}, pg.IClient>;
|
|
29
29
|
type DbConnection = string | pg.IConnectionParameters<pg.IClient>;
|
|
30
30
|
type DbConnectionOpts = pg.IDefaults;
|
|
31
|
-
const TABLE_METHODS = ["update", "find", "findOne", "insert", "delete", "upsert"];
|
|
31
|
+
const TABLE_METHODS = ["update", "find", "findOne", "insert", "delete", "upsert"] as const;
|
|
32
32
|
function getDbConnection(dbConnection: DbConnection, options: DbConnectionOpts | undefined, debugQueries = false, onNotice: ProstglesInitOptions["onNotice"]): { db: DB, pgp: PGP } {
|
|
33
33
|
let pgp: PGP = pgPromise({
|
|
34
34
|
|
|
@@ -935,24 +935,26 @@ export class Prostgles<DBO = DbHandler> {
|
|
|
935
935
|
// let DATA_TYPES = !needType? [] : await this.db.any("SELECT oid, typname FROM pg_type");
|
|
936
936
|
// let USER_TABLES = !needType? [] : await this.db.any("SELECT relid, relname FROM pg_catalog.pg_statio_user_tables");
|
|
937
937
|
|
|
938
|
-
|
|
938
|
+
const { dbo, db, pgp, publishParser } = this;
|
|
939
|
+
let fullSchema: {
|
|
940
|
+
schema: TableSchemaForClient;
|
|
941
|
+
tables: DBSchemaTable[];
|
|
942
|
+
} | undefined;
|
|
939
943
|
let publishValidationError;
|
|
940
944
|
let rawSQL = false;
|
|
941
945
|
|
|
942
|
-
const { dbo, db, pgp, publishParser } = this;
|
|
943
946
|
try {
|
|
944
947
|
if(!publishParser) throw "publishParser undefined";
|
|
945
|
-
|
|
948
|
+
fullSchema = await publishParser.getSchemaFromPublish(socket);
|
|
946
949
|
} catch(e){
|
|
947
950
|
publishValidationError = "Server Error: PUBLISH VALIDATION ERROR";
|
|
948
951
|
console.error(`\nProstgles PUBLISH VALIDATION ERROR (after socket connected):\n ->`, e);
|
|
949
952
|
}
|
|
950
953
|
socket.prostgles = socket.prostgles || {};
|
|
951
|
-
socket.prostgles.schema = schema;
|
|
954
|
+
socket.prostgles.schema = fullSchema?.schema;
|
|
952
955
|
/* RUN Raw sql from client IF PUBLISHED
|
|
953
956
|
*/
|
|
954
|
-
|
|
955
|
-
let allTablesViews = this.dboBuilder.tablesOrViews ?? [];
|
|
957
|
+
|
|
956
958
|
if(this.opts.publishRawSQL && typeof this.opts.publishRawSQL === "function"){
|
|
957
959
|
const canRunSQL = async () => {
|
|
958
960
|
const publishParams = await this.publishParser?.getPublishParams({ socket })
|
|
@@ -974,13 +976,13 @@ export class Prostgles<DBO = DbHandler> {
|
|
|
974
976
|
});
|
|
975
977
|
if(db){
|
|
976
978
|
// let allTablesViews = await db.any(STEP2_GET_ALL_TABLES_AND_COLUMNS);
|
|
977
|
-
fullSchema = allTablesViews;
|
|
979
|
+
// fullSchema = allTablesViews;
|
|
978
980
|
rawSQL = true;
|
|
979
981
|
} else console.error("db missing");
|
|
980
982
|
}
|
|
981
983
|
}
|
|
982
984
|
|
|
983
|
-
|
|
985
|
+
const { schema, tables } = fullSchema ?? { schema: {}, tables: [] };
|
|
984
986
|
let joinTables2: string[][] = [];
|
|
985
987
|
if(this.opts.joins){
|
|
986
988
|
// joinTables = Array.from(new Set(flat(this.dboBuilder.getJoins().map(j => j.tables)).filter(t => schema[t])));
|
|
@@ -999,7 +1001,7 @@ export class Prostgles<DBO = DbHandler> {
|
|
|
999
1001
|
const clientSchema: ClientSchema = {
|
|
1000
1002
|
schema,
|
|
1001
1003
|
methods: getKeys(methods),
|
|
1002
|
-
|
|
1004
|
+
tableSchema: tables,
|
|
1003
1005
|
rawSQL,
|
|
1004
1006
|
joinTables: joinTables2,
|
|
1005
1007
|
auth,
|
|
@@ -1330,7 +1332,11 @@ export class PublishParser {
|
|
|
1330
1332
|
.find(method => {
|
|
1331
1333
|
let rm = MY_RULES.find(r => r.rule === method || (r.methods as any).includes(method));
|
|
1332
1334
|
if(!rm){
|
|
1333
|
-
|
|
1335
|
+
let extraInfo = "";
|
|
1336
|
+
if(is_view && RULE_TO_METHODS.find(r => !is_view && r.rule === method || (r.methods as any).includes(method))){
|
|
1337
|
+
extraInfo = "You've specified table rules to a view\n";
|
|
1338
|
+
}
|
|
1339
|
+
throw `Invalid rule in publish.${tableName} -> ${method} \n${extraInfo}Expecting any of: ${MY_RULES.flatMap(r => [r.rule, ...r.methods]).join(", ")}`;
|
|
1334
1340
|
}
|
|
1335
1341
|
|
|
1336
1342
|
/** Check user privileges */
|
|
@@ -1393,8 +1399,9 @@ export class PublishParser {
|
|
|
1393
1399
|
|
|
1394
1400
|
|
|
1395
1401
|
/* Prepares schema for client. Only allowed views and commands will be present */
|
|
1396
|
-
async getSchemaFromPublish(socket: any): Promise<TableSchemaForClient> {
|
|
1402
|
+
async getSchemaFromPublish(socket: any): Promise<{schema: TableSchemaForClient; tables: DBSchemaTable[] }> {
|
|
1397
1403
|
let schema: TableSchemaForClient = {};
|
|
1404
|
+
let tables: DBSchemaTable[] = []
|
|
1398
1405
|
|
|
1399
1406
|
try {
|
|
1400
1407
|
/* Publish tables and views based on socket */
|
|
@@ -1420,10 +1427,11 @@ export class PublishParser {
|
|
|
1420
1427
|
|
|
1421
1428
|
const table_rules = await this.getTableRules({ localParams: {socket}, tableName }, clientInfo);
|
|
1422
1429
|
|
|
1423
|
-
// if(tableName === "insert_rule") throw {table_rules}
|
|
1424
1430
|
if(table_rules && Object.keys(table_rules).length){
|
|
1425
1431
|
schema[tableName] = {};
|
|
1426
|
-
let methods:
|
|
1432
|
+
let methods: MethodKey[] = [];
|
|
1433
|
+
let tableInfo: TableInfo | undefined;
|
|
1434
|
+
let tableColumns: DBSchemaTable["columns"] | undefined;
|
|
1427
1435
|
|
|
1428
1436
|
if(typeof table_rules === "object"){
|
|
1429
1437
|
methods = getKeys(table_rules) as any;
|
|
@@ -1438,13 +1446,13 @@ export class PublishParser {
|
|
|
1438
1446
|
|
|
1439
1447
|
schema[tableName][method] = {};
|
|
1440
1448
|
|
|
1441
|
-
/* Test for issues with the
|
|
1442
|
-
if(TABLE_METHODS.includes(method)){
|
|
1449
|
+
/* Test for issues with the common table CRUD methods () */
|
|
1450
|
+
if(TABLE_METHODS.includes(method as any)){
|
|
1443
1451
|
|
|
1444
1452
|
let err = null;
|
|
1445
1453
|
try {
|
|
1446
1454
|
let valid_table_command_rules = await this.getValidatedRequestRule({ tableName, command: method, localParams: {socket} }, clientInfo);
|
|
1447
|
-
await (this.dbo[tableName] as any)[method]({}, {}, {}, valid_table_command_rules, { socket, has_rules: true, testRule: true });
|
|
1455
|
+
await (this.dbo[tableName] as any)[method]({}, {}, {}, valid_table_command_rules, { socket, has_rules: true, testRule: true });
|
|
1448
1456
|
|
|
1449
1457
|
} catch(e) {
|
|
1450
1458
|
err = "INTERNAL PUBLISH ERROR";
|
|
@@ -1453,8 +1461,28 @@ export class PublishParser {
|
|
|
1453
1461
|
throw `publish.${tableName}.${method}: \n -> ${e}`;
|
|
1454
1462
|
}
|
|
1455
1463
|
}
|
|
1464
|
+
|
|
1465
|
+
|
|
1466
|
+
if(method === "getInfo" || method === "getColumns"){
|
|
1467
|
+
let tableRules = await this.getValidatedRequestRule({ tableName, command: method, localParams: {socket} }, clientInfo);
|
|
1468
|
+
const res = await (this.dbo[tableName] as any)[method](undefined, undefined, undefined , tableRules, { socket, has_rules: true });
|
|
1469
|
+
if(method === "getInfo"){
|
|
1470
|
+
tableInfo = res;
|
|
1471
|
+
} else if(method === "getColumns"){
|
|
1472
|
+
tableColumns = res;
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1456
1475
|
}
|
|
1457
1476
|
}));
|
|
1477
|
+
|
|
1478
|
+
if(tableInfo && tableColumns){
|
|
1479
|
+
|
|
1480
|
+
tables.push({
|
|
1481
|
+
name: tableName,
|
|
1482
|
+
info: tableInfo,
|
|
1483
|
+
columns: tableColumns
|
|
1484
|
+
})
|
|
1485
|
+
}
|
|
1458
1486
|
}
|
|
1459
1487
|
|
|
1460
1488
|
return true;
|
|
@@ -1467,8 +1495,8 @@ export class PublishParser {
|
|
|
1467
1495
|
console.error("Prostgles \nERRORS IN PUBLISH: ", JSON.stringify(e));
|
|
1468
1496
|
throw e;
|
|
1469
1497
|
}
|
|
1470
|
-
|
|
1471
|
-
return schema;
|
|
1498
|
+
|
|
1499
|
+
return { schema, tables };
|
|
1472
1500
|
}
|
|
1473
1501
|
|
|
1474
1502
|
}
|
package/lib/TableConfig.ts
CHANGED
|
@@ -117,7 +117,7 @@ type NamedJoinColumn = {
|
|
|
117
117
|
joinDef: JoinDef[];
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
type ColumnConfig<LANG_IDS= { en: 1 }> = NamedJoinColumn | MediaColumn | (BaseColumn<LANG_IDS> & (SQLDefColumn | ReferencedColumn | TextColumn))
|
|
120
|
+
type ColumnConfig<LANG_IDS = { en: 1 }> = NamedJoinColumn | MediaColumn | (BaseColumn<LANG_IDS> & (SQLDefColumn | ReferencedColumn | TextColumn))
|
|
121
121
|
|
|
122
122
|
type TableDefinition<LANG_IDS> = {
|
|
123
123
|
columns: {
|
|
@@ -208,8 +208,39 @@ export default class TableConfigurator {
|
|
|
208
208
|
return undefined;
|
|
209
209
|
}
|
|
210
210
|
|
|
211
|
-
getColInfo = (params: {col: string, table: string}): ColExtraInfo | undefined => {
|
|
212
|
-
|
|
211
|
+
getColInfo = (params: {col: string, table: string, lang?: string }): (ColExtraInfo & { label?: string }) | undefined => {
|
|
212
|
+
const colConf = this.getColumnConfig(params.table, params.col);
|
|
213
|
+
let result: (ColExtraInfo & { label?: string }) | undefined = undefined;
|
|
214
|
+
if(colConf){
|
|
215
|
+
|
|
216
|
+
if("info" in colConf){
|
|
217
|
+
result = {
|
|
218
|
+
...(result ?? {}),
|
|
219
|
+
...colConf?.info
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Get labels from TableConfig if specified
|
|
225
|
+
*/
|
|
226
|
+
if(colConf.label){
|
|
227
|
+
const { lang } = params;
|
|
228
|
+
const lbl = colConf?.label;
|
|
229
|
+
if(["string", "object"].includes(typeof lbl)){
|
|
230
|
+
if(typeof lbl === "string") {
|
|
231
|
+
result ??= {};
|
|
232
|
+
result.label = lbl
|
|
233
|
+
} else if(lang && (lbl?.[lang as "en"] || lbl?.en)) {
|
|
234
|
+
result ??= {};
|
|
235
|
+
result.label = (lbl?.[lang as "en"]) || lbl?.en;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
return result;
|
|
213
244
|
}
|
|
214
245
|
|
|
215
246
|
checkColVal = (params: {col: string, table: string, value: any }): void => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prostgles-server",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.174",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"bluebird": "^3.7.2",
|
|
30
30
|
"file-type": "^16.5.3",
|
|
31
31
|
"pg-promise": "^10.11.1",
|
|
32
|
-
"prostgles-types": "^1.5.
|
|
32
|
+
"prostgles-types": "^1.5.140",
|
|
33
33
|
"sharp": "^0.30.5"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
package/tests/client/PID.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
23576
|
package/tests/client/index.js
CHANGED
|
@@ -45,7 +45,7 @@ try {
|
|
|
45
45
|
onReconnect: (socket) => {
|
|
46
46
|
log("Reconnected");
|
|
47
47
|
},
|
|
48
|
-
onReady: async (db, methods,
|
|
48
|
+
onReady: async (db, methods, tableSchema, auth) => {
|
|
49
49
|
log("onReady.auth", auth);
|
|
50
50
|
try {
|
|
51
51
|
log("Starting Client isomorphic tests");
|
|
@@ -56,7 +56,7 @@ try {
|
|
|
56
56
|
// }
|
|
57
57
|
log("Client isomorphic tests successful");
|
|
58
58
|
// try {
|
|
59
|
-
await (0, client_only_queries_1.default)(db, auth, log, methods);
|
|
59
|
+
await (0, client_only_queries_1.default)(db, auth, log, methods, tableSchema);
|
|
60
60
|
// } catch(e){
|
|
61
61
|
// throw { ClientErr: e }
|
|
62
62
|
// }
|
package/tests/client/index.ts
CHANGED
|
@@ -50,7 +50,7 @@ try {
|
|
|
50
50
|
onReconnect: (socket) => {
|
|
51
51
|
log("Reconnected")
|
|
52
52
|
},
|
|
53
|
-
onReady: async (db, methods,
|
|
53
|
+
onReady: async (db, methods, tableSchema, auth) => {
|
|
54
54
|
log("onReady.auth", auth)
|
|
55
55
|
try {
|
|
56
56
|
log("Starting Client isomorphic tests")
|
|
@@ -62,7 +62,7 @@ try {
|
|
|
62
62
|
log("Client isomorphic tests successful")
|
|
63
63
|
|
|
64
64
|
// try {
|
|
65
|
-
await client_only(db, auth, log, methods);
|
|
65
|
+
await client_only(db, auth, log, methods, tableSchema);
|
|
66
66
|
// } catch(e){
|
|
67
67
|
// throw { ClientErr: e }
|
|
68
68
|
// }
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@types/node": "^14.14.16",
|
|
13
|
-
"prostgles-client": "^1.5.
|
|
13
|
+
"prostgles-client": "^1.5.150",
|
|
14
14
|
"prostgles-types": "^1.5.68",
|
|
15
15
|
"socket.io-client": "^4.5.1"
|
|
16
16
|
}
|
|
@@ -67,17 +67,17 @@
|
|
|
67
67
|
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
|
68
68
|
},
|
|
69
69
|
"node_modules/prostgles-client": {
|
|
70
|
-
"version": "1.5.
|
|
71
|
-
"resolved": "https://registry.npmjs.org/prostgles-client/-/prostgles-client-1.5.
|
|
72
|
-
"integrity": "sha512-
|
|
70
|
+
"version": "1.5.150",
|
|
71
|
+
"resolved": "https://registry.npmjs.org/prostgles-client/-/prostgles-client-1.5.150.tgz",
|
|
72
|
+
"integrity": "sha512-ocdd0We0xjB6vmlT87hWhx33Y9+beydgDkFGGiJWLV3kLCNV5obURon4sGZuI4/qi1Am4EkgCzktFoWzaNPrmQ==",
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"prostgles-types": "^1.5.
|
|
74
|
+
"prostgles-types": "^1.5.140"
|
|
75
75
|
}
|
|
76
76
|
},
|
|
77
77
|
"node_modules/prostgles-types": {
|
|
78
|
-
"version": "1.5.
|
|
79
|
-
"resolved": "https://registry.npmjs.org/prostgles-types/-/prostgles-types-1.5.
|
|
80
|
-
"integrity": "sha512-
|
|
78
|
+
"version": "1.5.140",
|
|
79
|
+
"resolved": "https://registry.npmjs.org/prostgles-types/-/prostgles-types-1.5.140.tgz",
|
|
80
|
+
"integrity": "sha512-nJcrL2yjB2dY4M6whIlIpDDb9USgdfxTwylqUUCMx6Bt+DsSPEMHKD76Ao55WJ6BZAhxNfo6aqg6aOGprY7vRA=="
|
|
81
81
|
},
|
|
82
82
|
"node_modules/socket.io-client": {
|
|
83
83
|
"version": "4.5.1",
|
|
@@ -176,17 +176,17 @@
|
|
|
176
176
|
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
|
177
177
|
},
|
|
178
178
|
"prostgles-client": {
|
|
179
|
-
"version": "1.5.
|
|
180
|
-
"resolved": "https://registry.npmjs.org/prostgles-client/-/prostgles-client-1.5.
|
|
181
|
-
"integrity": "sha512-
|
|
179
|
+
"version": "1.5.150",
|
|
180
|
+
"resolved": "https://registry.npmjs.org/prostgles-client/-/prostgles-client-1.5.150.tgz",
|
|
181
|
+
"integrity": "sha512-ocdd0We0xjB6vmlT87hWhx33Y9+beydgDkFGGiJWLV3kLCNV5obURon4sGZuI4/qi1Am4EkgCzktFoWzaNPrmQ==",
|
|
182
182
|
"requires": {
|
|
183
|
-
"prostgles-types": "^1.5.
|
|
183
|
+
"prostgles-types": "^1.5.140"
|
|
184
184
|
}
|
|
185
185
|
},
|
|
186
186
|
"prostgles-types": {
|
|
187
|
-
"version": "1.5.
|
|
188
|
-
"resolved": "https://registry.npmjs.org/prostgles-types/-/prostgles-types-1.5.
|
|
189
|
-
"integrity": "sha512-
|
|
187
|
+
"version": "1.5.140",
|
|
188
|
+
"resolved": "https://registry.npmjs.org/prostgles-types/-/prostgles-types-1.5.140.tgz",
|
|
189
|
+
"integrity": "sha512-nJcrL2yjB2dY4M6whIlIpDDb9USgdfxTwylqUUCMx6Bt+DsSPEMHKD76Ao55WJ6BZAhxNfo6aqg6aOGprY7vRA=="
|
|
190
190
|
},
|
|
191
191
|
"socket.io-client": {
|
|
192
192
|
"version": "4.5.1",
|
|
@@ -1,8 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const assert_1 = require("assert");
|
|
4
|
+
const dist_1 = require("./client/node_modules/prostgles-types/dist");
|
|
4
5
|
const isomorphic_queries_1 = require("./isomorphic_queries");
|
|
5
|
-
async function client_only(db, auth, log, methods) {
|
|
6
|
+
async function client_only(db, auth, log, methods, tableSchema) {
|
|
7
|
+
/**
|
|
8
|
+
* onReady(dbo, methodsObj, tableSchema, _auth)
|
|
9
|
+
* tableSchema must contan an array of all tables and their columns that have getInfo and getColumns allowed
|
|
10
|
+
*/
|
|
11
|
+
await (0, isomorphic_queries_1.tryRun)("Check tableSchema", async () => {
|
|
12
|
+
const dbTables = Object.keys(db).map(k => {
|
|
13
|
+
const h = db[k];
|
|
14
|
+
return !!(h.getColumns && h.getInfo) ? k : undefined;
|
|
15
|
+
}).filter(dist_1.isDefined);
|
|
16
|
+
const missingTbl = dbTables.find(t => !tableSchema.some(st => st.name === t));
|
|
17
|
+
if (missingTbl)
|
|
18
|
+
throw `${missingTbl} is missing from tableSchema: ${JSON.stringify(tableSchema)}`;
|
|
19
|
+
const missingscTbl = tableSchema.find(t => !dbTables.includes(t.name));
|
|
20
|
+
if (missingscTbl)
|
|
21
|
+
throw `${missingscTbl} is missing from db`;
|
|
22
|
+
await Promise.all(tableSchema.map(async (tbl) => {
|
|
23
|
+
const cols = await db[tbl.name]?.getColumns();
|
|
24
|
+
const info = await db[tbl.name]?.getInfo();
|
|
25
|
+
assert_1.strict.deepStrictEqual(tbl.columns, cols);
|
|
26
|
+
assert_1.strict.deepStrictEqual(tbl.info, info);
|
|
27
|
+
}));
|
|
28
|
+
});
|
|
6
29
|
const testRealtime = () => {
|
|
7
30
|
return new Promise(async (resolve, reject) => {
|
|
8
31
|
try {
|
|
@@ -1,10 +1,32 @@
|
|
|
1
1
|
import { strict as assert } from 'assert';
|
|
2
2
|
|
|
3
3
|
import { DBHandlerClient, Auth } from "./client/index";
|
|
4
|
+
import { DBSchemaTable, isDefined } from "./client/node_modules/prostgles-types/dist";
|
|
4
5
|
import { tryRun, tryRunP } from './isomorphic_queries';
|
|
5
6
|
|
|
6
|
-
export default async function client_only(db: DBHandlerClient, auth: Auth, log: (...args: any[]) => any, methods){
|
|
7
|
+
export default async function client_only(db: DBHandlerClient, auth: Auth, log: (...args: any[]) => any, methods, tableSchema: DBSchemaTable[]){
|
|
7
8
|
|
|
9
|
+
/**
|
|
10
|
+
* onReady(dbo, methodsObj, tableSchema, _auth)
|
|
11
|
+
* tableSchema must contan an array of all tables and their columns that have getInfo and getColumns allowed
|
|
12
|
+
*/
|
|
13
|
+
await tryRun("Check tableSchema", async () => {
|
|
14
|
+
const dbTables = Object.keys(db).map(k => {
|
|
15
|
+
const h = db[k];
|
|
16
|
+
return !!(h.getColumns && h.getInfo)? k : undefined;
|
|
17
|
+
}).filter(isDefined);
|
|
18
|
+
const missingTbl = dbTables.find(t => !tableSchema.some(st => st.name === t));
|
|
19
|
+
if(missingTbl) throw `${missingTbl} is missing from tableSchema: ${JSON.stringify(tableSchema)}`
|
|
20
|
+
const missingscTbl = tableSchema.find(t => !dbTables.includes(t.name));
|
|
21
|
+
if(missingscTbl) throw `${missingscTbl} is missing from db`;
|
|
22
|
+
|
|
23
|
+
await Promise.all(tableSchema.map(async tbl => {
|
|
24
|
+
const cols = await db[tbl.name]?.getColumns();
|
|
25
|
+
const info = await db[tbl.name]?.getInfo();
|
|
26
|
+
assert.deepStrictEqual(tbl.columns, cols);
|
|
27
|
+
assert.deepStrictEqual(tbl.info, info);
|
|
28
|
+
}))
|
|
29
|
+
});
|
|
8
30
|
|
|
9
31
|
const testRealtime = () => {
|
|
10
32
|
|
package/tests/server/index.js
CHANGED
package/tests/server/index.ts
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
},
|
|
22
22
|
"../..": {
|
|
23
23
|
"name": "prostgles-server",
|
|
24
|
-
"version": "2.0.
|
|
24
|
+
"version": "2.0.173",
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@aws-sdk/client-s3": "^3.95.0",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"bluebird": "^3.7.2",
|
|
30
30
|
"file-type": "^16.5.3",
|
|
31
31
|
"pg-promise": "^10.11.1",
|
|
32
|
-
"prostgles-types": "^1.5.
|
|
32
|
+
"prostgles-types": "^1.5.140",
|
|
33
33
|
"sharp": "^0.30.5"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
@@ -1371,7 +1371,7 @@
|
|
|
1371
1371
|
"bluebird": "^3.7.2",
|
|
1372
1372
|
"file-type": "^16.5.3",
|
|
1373
1373
|
"pg-promise": "^10.11.1",
|
|
1374
|
-
"prostgles-types": "^1.5.
|
|
1374
|
+
"prostgles-types": "^1.5.140",
|
|
1375
1375
|
"sharp": "^0.30.5",
|
|
1376
1376
|
"typescript": "^4.7.2"
|
|
1377
1377
|
}
|