prostgles-server 2.0.173 → 2.0.176

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.
Files changed (64) hide show
  1. package/.vscode/settings.json +3 -0
  2. package/dist/AuthHandler.d.ts +13 -12
  3. package/dist/AuthHandler.d.ts.map +1 -1
  4. package/dist/AuthHandler.js +5 -2
  5. package/dist/AuthHandler.js.map +1 -1
  6. package/dist/DBSchemaBuilder.d.ts +11 -0
  7. package/dist/DBSchemaBuilder.d.ts.map +1 -0
  8. package/dist/DBSchemaBuilder.js +56 -0
  9. package/dist/DBSchemaBuilder.js.map +1 -0
  10. package/dist/DboBuilder.d.ts +23 -22
  11. package/dist/DboBuilder.d.ts.map +1 -1
  12. package/dist/DboBuilder.js +36 -61
  13. package/dist/DboBuilder.js.map +1 -1
  14. package/dist/FileManager.d.ts +2 -2
  15. package/dist/FileManager.d.ts.map +1 -1
  16. package/dist/Filtering.d.ts.map +1 -1
  17. package/dist/Filtering.js.map +1 -1
  18. package/dist/Prostgles.d.ts +25 -257
  19. package/dist/Prostgles.d.ts.map +1 -1
  20. package/dist/Prostgles.js +12 -376
  21. package/dist/Prostgles.js.map +1 -1
  22. package/dist/PubSubManager.d.ts +6 -5
  23. package/dist/PubSubManager.d.ts.map +1 -1
  24. package/dist/PubSubManager.js.map +1 -1
  25. package/dist/PublishParser.d.ts +262 -0
  26. package/dist/PublishParser.d.ts.map +1 -0
  27. package/dist/PublishParser.js +391 -0
  28. package/dist/PublishParser.js.map +1 -0
  29. package/dist/QueryBuilder.d.ts +20 -4
  30. package/dist/QueryBuilder.d.ts.map +1 -1
  31. package/dist/QueryBuilder.js.map +1 -1
  32. package/dist/TableConfig.d.ts +6 -3
  33. package/dist/TableConfig.d.ts.map +1 -1
  34. package/dist/TableConfig.js +28 -1
  35. package/dist/TableConfig.js.map +1 -1
  36. package/dist/index.d.ts +3 -3
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +4 -0
  39. package/dist/index.js.map +1 -1
  40. package/lib/AuthHandler.ts +25 -19
  41. package/lib/DBSchemaBuilder.ts +91 -0
  42. package/lib/DboBuilder.ts +84 -98
  43. package/lib/FileManager.ts +2 -2
  44. package/lib/Filtering.ts +3 -3
  45. package/lib/Prostgles.ts +33 -704
  46. package/lib/PubSubManager.ts +6 -5
  47. package/lib/PublishParser.ts +723 -0
  48. package/lib/QueryBuilder.ts +6 -5
  49. package/lib/TableConfig.ts +36 -5
  50. package/lib/index.ts +4 -4
  51. package/package.json +2 -2
  52. package/tests/client/PID.txt +1 -1
  53. package/tests/client/index.js +2 -2
  54. package/tests/client/index.ts +2 -2
  55. package/tests/client/package-lock.json +15 -15
  56. package/tests/client/package.json +1 -1
  57. package/tests/client_only_queries.js +24 -1
  58. package/tests/client_only_queries.ts +23 -1
  59. package/tests/isomorphic_queries.js +3 -0
  60. package/tests/isomorphic_queries.ts +5 -2
  61. package/tests/server/DBoGenerated.d.ts +428 -286
  62. package/tests/server/index.js +1 -14
  63. package/tests/server/index.ts +5 -19
  64. package/tests/server/package-lock.json +3 -3
@@ -5,8 +5,8 @@
5
5
  *--------------------------------------------------------------------------------------------*/
6
6
 
7
7
  import { pgp, Filter, LocalParams, isPlainObject, TableHandler, ViewHandler, postgresToTsType } from "./DboBuilder";
8
- import { TableRule } from "./Prostgles";
9
- import { SelectParamsBasic as SelectParams, isEmpty, FieldFilter, asName, TextFilter_FullTextSearchFilterKeys, ColumnInfo, PG_COLUMN_UDT_DATA_TYPE, isObject } from "prostgles-types";
8
+ import { TableRule } from "./PublishParser";
9
+ import { SelectParams, isEmpty, FieldFilter, asName, TextFilter_FullTextSearchFilterKeys, ColumnInfo, PG_COLUMN_UDT_DATA_TYPE, isObject, Select } from "prostgles-types";
10
10
  import { get } from "./utils";
11
11
 
12
12
 
@@ -200,7 +200,7 @@ const FTS_Funcs: FunctionSpec[] =
200
200
  if(isPlainObject(qVal)){
201
201
  const keys = Object.keys(qVal);
202
202
  if(!keys.length) throw "Bad arg";
203
- if(keys.length !==1 || !searchTypes.includes(keys[0])) throw "Expecting a an object with a single key named one of: " + searchTypes.join(", ");
203
+ if(keys.length !==1 || !searchTypes.includes(keys[0] as any)) throw "Expecting a an object with a single key named one of: " + searchTypes.join(", ");
204
204
  qType = keys[0];
205
205
  qVal = asValue(qVal[qType]);
206
206
 
@@ -1094,7 +1094,7 @@ export class SelectItemBuilder {
1094
1094
  });
1095
1095
  }
1096
1096
 
1097
- parseUserSelect = async (userSelect: FieldFilter, joinParse?: (key: string, val: any, throwErr: (msg: string) => any) => any) => {
1097
+ parseUserSelect = async (userSelect: Select, joinParse?: (key: string, val: any, throwErr: (msg: string) => any) => any) => {
1098
1098
 
1099
1099
  /* Array select */
1100
1100
  if(Array.isArray(userSelect)){
@@ -1113,7 +1113,8 @@ export class SelectItemBuilder {
1113
1113
  return [];
1114
1114
  } else if(userSelect === "*"){
1115
1115
  this.allowedFields.map(key => this.addColumn(key, true) );
1116
- } else if(isPlainObject(userSelect) && !isEmpty(userSelect as object)){
1116
+
1117
+ } else if(isPlainObject(userSelect) && !isEmpty(userSelect)){
1117
1118
  const selectKeys = Object.keys(userSelect),
1118
1119
  selectValues = Object.values(userSelect);
1119
1120
 
@@ -1,7 +1,7 @@
1
1
  import { getKeys, asName } from "prostgles-types";
2
2
  import { JoinInfo } from "./DboBuilder";
3
3
  import { ALLOWED_EXTENSION, ALLOWED_CONTENT_TYPE } from "./FileManager";
4
- import { DB, DbHandler, Prostgles } from "./Prostgles";
4
+ import { DB, DBHandlerServer, Prostgles } from "./Prostgles";
5
5
  import { asValue } from "./PubSubManager";
6
6
 
7
7
  type ColExtraInfo = {
@@ -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: {
@@ -184,7 +184,7 @@ export type TableConfig<LANG_IDS = { en: 1 }> = {
184
184
  export default class TableConfigurator {
185
185
 
186
186
  config?: TableConfig;
187
- get dbo(): DbHandler {
187
+ get dbo(): DBHandlerServer {
188
188
  if(!this.prostgles.dbo) throw "this.prostgles.dbo missing"
189
189
  return this.prostgles.dbo
190
190
  };
@@ -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
- return (this.config as any)[params.table]?.[params.col]?.info;
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/lib/index.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import { Prostgles, ProstglesInitOptions } from "./Prostgles";
2
- import { DbHandler, TableHandler, ViewHandler } from "./DboBuilder";
2
+ import { DBSchema } from "prostgles-types";
3
3
 
4
- function prostgles<DBObj = DbHandler>(params: ProstglesInitOptions<DBObj>){
4
+ function prostgles<S extends DBSchema = any>(params: ProstglesInitOptions<S>){
5
5
 
6
- let prgl = new Prostgles<DBObj>(params as any);
6
+ let prgl = new Prostgles<S>(params as any);
7
7
  return prgl.init(params.onReady);
8
8
  }
9
+ export = prostgles;//{ , TableHandler, ViewHandler };
9
10
 
10
11
 
11
12
  // declare const init (params: InitOptions) => {
@@ -13,7 +14,6 @@ function prostgles<DBObj = DbHandler>(params: ProstglesInitOptions<DBObj>){
13
14
  // prgl.init(params.isReady);
14
15
  // }
15
16
 
16
- export = prostgles;//{ , TableHandler, ViewHandler };
17
17
 
18
18
 
19
19
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prostgles-server",
3
- "version": "2.0.173",
3
+ "version": "2.0.176",
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.135",
32
+ "prostgles-types": "^1.5.153",
33
33
  "sharp": "^0.30.5"
34
34
  },
35
35
  "devDependencies": {
@@ -1 +1 @@
1
- 38236
1
+ 78625
@@ -45,7 +45,7 @@ try {
45
45
  onReconnect: (socket) => {
46
46
  log("Reconnected");
47
47
  },
48
- onReady: async (db, methods, fullSchema, auth) => {
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
  // }
@@ -50,7 +50,7 @@ try {
50
50
  onReconnect: (socket) => {
51
51
  log("Reconnected")
52
52
  },
53
- onReady: async (db, methods, fullSchema, auth) => {
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.147",
13
+ "prostgles-client": "^1.5.153",
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.147",
71
- "resolved": "https://registry.npmjs.org/prostgles-client/-/prostgles-client-1.5.147.tgz",
72
- "integrity": "sha512-OHKHn9/Ynv/v3QSB53ZvhVvWp4pWsrLIy8ZDXloQprB8IUXSS2SdCWnbdkBoD9JH9Z4tUBoq88lTdS7G1KZY3w==",
70
+ "version": "1.5.153",
71
+ "resolved": "https://registry.npmjs.org/prostgles-client/-/prostgles-client-1.5.153.tgz",
72
+ "integrity": "sha512-kveb392Ye8XNgcWGmaMUg9PTQFVdb+f1RegK9TNVLLFG1b03hmsaVBAXCQvO5VvmGkW4rgQ5fZvfsEre5t+flg==",
73
73
  "dependencies": {
74
- "prostgles-types": "^1.5.133"
74
+ "prostgles-types": "^1.5.153"
75
75
  }
76
76
  },
77
77
  "node_modules/prostgles-types": {
78
- "version": "1.5.133",
79
- "resolved": "https://registry.npmjs.org/prostgles-types/-/prostgles-types-1.5.133.tgz",
80
- "integrity": "sha512-WVSuoiWAo1hgDl+9QSBPVhszwhxuX1WRi6CdE4epede1eD2Q5rQfO22bli0BBCQXyhE6l/A0Tt6UxhAIlDDSmw=="
78
+ "version": "1.5.153",
79
+ "resolved": "https://registry.npmjs.org/prostgles-types/-/prostgles-types-1.5.153.tgz",
80
+ "integrity": "sha512-TIPtsMFBGH3M01zGXMT1m7aVkr9cJgFryE8mOotJGTZUcaTaNA3s21wwGo4tbOVnyNqnyEgBolItb1s1DuNexg=="
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.147",
180
- "resolved": "https://registry.npmjs.org/prostgles-client/-/prostgles-client-1.5.147.tgz",
181
- "integrity": "sha512-OHKHn9/Ynv/v3QSB53ZvhVvWp4pWsrLIy8ZDXloQprB8IUXSS2SdCWnbdkBoD9JH9Z4tUBoq88lTdS7G1KZY3w==",
179
+ "version": "1.5.153",
180
+ "resolved": "https://registry.npmjs.org/prostgles-client/-/prostgles-client-1.5.153.tgz",
181
+ "integrity": "sha512-kveb392Ye8XNgcWGmaMUg9PTQFVdb+f1RegK9TNVLLFG1b03hmsaVBAXCQvO5VvmGkW4rgQ5fZvfsEre5t+flg==",
182
182
  "requires": {
183
- "prostgles-types": "^1.5.133"
183
+ "prostgles-types": "^1.5.153"
184
184
  }
185
185
  },
186
186
  "prostgles-types": {
187
- "version": "1.5.133",
188
- "resolved": "https://registry.npmjs.org/prostgles-types/-/prostgles-types-1.5.133.tgz",
189
- "integrity": "sha512-WVSuoiWAo1hgDl+9QSBPVhszwhxuX1WRi6CdE4epede1eD2Q5rQfO22bli0BBCQXyhE6l/A0Tt6UxhAIlDDSmw=="
187
+ "version": "1.5.153",
188
+ "resolved": "https://registry.npmjs.org/prostgles-types/-/prostgles-types-1.5.153.tgz",
189
+ "integrity": "sha512-TIPtsMFBGH3M01zGXMT1m7aVkr9cJgFryE8mOotJGTZUcaTaNA3s21wwGo4tbOVnyNqnyEgBolItb1s1DuNexg=="
190
190
  },
191
191
  "socket.io-client": {
192
192
  "version": "4.5.1",
@@ -13,7 +13,7 @@
13
13
  "license": "ISC",
14
14
  "dependencies": {
15
15
  "@types/node": "^14.14.16",
16
- "prostgles-client": "^1.5.147",
16
+ "prostgles-client": "^1.5.153",
17
17
  "prostgles-types": "^1.5.68",
18
18
  "socket.io-client": "^4.5.1"
19
19
  }
@@ -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
 
@@ -140,6 +140,9 @@ async function isomorphic(db) {
140
140
  },
141
141
  {
142
142
  "label": "fr_t1",
143
+ hint: "hint...",
144
+ min: "a",
145
+ max: "b",
143
146
  "name": "t1",
144
147
  "data_type": "text",
145
148
  "udt_name": "text",
@@ -1,6 +1,6 @@
1
1
  import { strict as assert } from 'assert';
2
2
 
3
- import { DbHandler} from "../dist/Prostgles";
3
+ import { DBHandlerServer} from "../dist/Prostgles";
4
4
  import { DBHandlerClient } from "./client/index";
5
5
  import * as fs from "fs";
6
6
 
@@ -29,7 +29,7 @@ export function tryRunP(desc: string, func: (resolve: any, reject: any) => any,
29
29
  });
30
30
  }
31
31
 
32
- export default async function isomorphic(db: Partial<DbHandler> | Partial<DBHandlerClient>) {
32
+ export default async function isomorphic(db: Partial<DBHandlerServer> | Partial<DBHandlerClient>) {
33
33
  console.log("Starting isomorphic queries");
34
34
 
35
35
  if(await db.items.count()){
@@ -126,6 +126,9 @@ export default async function isomorphic(db: Partial<DbHandler> | Partial<DBHand
126
126
  },
127
127
  {
128
128
  "label": "fr_t1",
129
+ hint: "hint...",
130
+ min: "a",
131
+ max: "b",
129
132
  "name": "t1",
130
133
  "data_type": "text",
131
134
  "udt_name": "text",