prostgles-server 2.0.183 → 2.0.184

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.
@@ -1,7 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseI18N = void 0;
3
4
  const prostgles_types_1 = require("prostgles-types");
5
+ const DboBuilder_1 = require("./DboBuilder");
4
6
  const PubSubManager_1 = require("./PubSubManager");
7
+ const parseI18N = (params) => {
8
+ const { config, lang, defaultLang, defaultValue } = params;
9
+ if (config) {
10
+ if ((0, DboBuilder_1.isPlainObject)(config)) {
11
+ //@ts-ignore
12
+ return config[lang] ?? config[defaultLang];
13
+ }
14
+ else if (typeof config === "string") {
15
+ return config;
16
+ }
17
+ }
18
+ return defaultValue;
19
+ };
20
+ exports.parseI18N = parseI18N;
5
21
  /**
6
22
  * Will be run between initSQL and fileTable
7
23
  */
@@ -10,10 +26,16 @@ class TableConfigurator {
10
26
  this.getColumnConfig = (tableName, colName) => {
11
27
  const tconf = this.config?.[tableName];
12
28
  if (tconf && "columns" in tconf) {
13
- return tconf.columns[colName];
29
+ return tconf.columns?.[colName];
14
30
  }
15
31
  return undefined;
16
32
  };
33
+ this.getTableInfo = (params) => {
34
+ const tconf = this.config?.[params.tableName];
35
+ return {
36
+ label: (0, exports.parseI18N)({ config: tconf?.info?.label, lang: params.lang, defaultLang: "en", defaultValue: params.tableName })
37
+ };
38
+ };
17
39
  this.getColInfo = (params) => {
18
40
  const colConf = this.getColumnConfig(params.table, params.col);
19
41
  let result = undefined;
@@ -61,7 +83,7 @@ class TableConfigurator {
61
83
  this.config[sourceTable] &&
62
84
  "columns" in this.config[sourceTable]) {
63
85
  const td = this.config[sourceTable];
64
- if ("columns" in td && td.columns[targetTable]) {
86
+ if ("columns" in td && td.columns?.[targetTable]) {
65
87
  const cd = td.columns[targetTable];
66
88
  if ("joinDef" in cd) {
67
89
  const { joinDef } = cd;
@@ -167,29 +189,31 @@ class TableConfigurator {
167
189
  }
168
190
  };
169
191
  const colDefs = [];
170
- Object.keys(tableConf.columns).filter(c => !("joinDef" in tableConf.columns[c])).map(colName => {
171
- const colConf = tableConf.columns[colName];
172
- if (!this.dbo[tableName]) {
173
- colDefs.push(getColDef(colName, colConf));
174
- }
175
- else if (!colDefs.length && !this.dbo[tableName].columns?.find(c => colName === c.name)) {
176
- if ("references" in colConf && colConf.references) {
177
- const { tableName: lookupTable, } = colConf.references;
178
- queries.push(`
179
- ALTER TABLE ${(0, prostgles_types_1.asName)(tableName)}
180
- ADD COLUMN ${getColDef(colName, colConf)};
181
- `);
182
- console.log(`TableConfigurator: ${tableName}(${colName})` + " referenced lookup table " + lookupTable);
192
+ if (tableConf.columns) {
193
+ (0, prostgles_types_1.getKeys)(tableConf?.columns).filter(c => !("joinDef" in tableConf.columns[c])).map(colName => {
194
+ const colConf = tableConf.columns[colName];
195
+ if (!this.dbo[tableName]) {
196
+ colDefs.push(getColDef(colName, colConf));
183
197
  }
184
- else if ("sqlDefinition" in colConf && colConf.sqlDefinition) {
185
- queries.push(`
198
+ else if (!colDefs.length && !this.dbo[tableName].columns?.find(c => colName === c.name)) {
199
+ if ("references" in colConf && colConf.references) {
200
+ const { tableName: lookupTable, } = colConf.references;
201
+ queries.push(`
202
+ ALTER TABLE ${(0, prostgles_types_1.asName)(tableName)}
203
+ ADD COLUMN ${getColDef(colName, colConf)};
204
+ `);
205
+ console.log(`TableConfigurator: ${tableName}(${colName})` + " referenced lookup table " + lookupTable);
206
+ }
207
+ else if ("sqlDefinition" in colConf && colConf.sqlDefinition) {
208
+ queries.push(`
186
209
  ALTER TABLE ${(0, prostgles_types_1.asName)(tableName)}
187
210
  ADD COLUMN ${getColDef(colName, colConf)};
188
211
  `);
189
- console.log(`TableConfigurator: created/added column ${tableName}(${colName}) ` + colConf.sqlDefinition);
212
+ console.log(`TableConfigurator: created/added column ${tableName}(${colName}) ` + colConf.sqlDefinition);
213
+ }
190
214
  }
191
- }
192
- });
215
+ });
216
+ }
193
217
  if (colDefs.length) {
194
218
  queries.push(`CREATE TABLE ${(0, prostgles_types_1.asName)(tableName)} (
195
219
  ${colDefs.join(", \n")}