dbgate-datalib 6.6.3 → 6.6.4

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.
@@ -8,6 +8,7 @@ export interface DisplayColumn {
8
8
  columnName: string;
9
9
  headerText: string;
10
10
  uniqueName: string;
11
+ uniqueNameShorten?: string;
11
12
  uniquePath: string[];
12
13
  notNull?: boolean;
13
14
  autoIncrement?: boolean;
@@ -421,7 +421,9 @@ class GridDisplay {
421
421
  return expr;
422
422
  }
423
423
  }
424
- return Object.assign(Object.assign(Object.assign({ exprType: 'column' }, (!this.dialect.omitTableAliases && { alias: alias || col.columnName })), { source }), col);
424
+ return Object.assign(Object.assign(Object.assign({ exprType: 'column' }, (!this.dialect.omitTableAliases && {
425
+ alias: alias !== null && alias !== void 0 ? alias : col.columnName,
426
+ })), { source }), col);
425
427
  }
426
428
  createSelectBase(name, columns, options, defaultOrderColumnName) {
427
429
  var _a, _b;
@@ -23,43 +23,7 @@ export declare class TableGridDisplay extends GridDisplay {
23
23
  schemaName?: any;
24
24
  pureName: any;
25
25
  }): TableInfo;
26
- getDisplayColumns(table: TableInfo, parentPath: string[]): {
27
- isChecked: boolean;
28
- hintColumnNames: string[];
29
- hintColumnDelimiter: string;
30
- isExpandable: boolean;
31
- pureName: string;
32
- schemaName: string;
33
- headerText: string;
34
- uniqueName: string;
35
- uniquePath: string[];
36
- isPrimaryKey: boolean;
37
- hasAutoValue: boolean;
38
- foreignKey: ForeignKeyInfo;
39
- isForeignKeyUnique: boolean;
40
- pairingId?: string;
41
- columnName: string;
42
- notNull?: boolean;
43
- autoIncrement?: boolean;
44
- dataType: string;
45
- displayedDataType?: string;
46
- precision?: number;
47
- scale?: number;
48
- length?: number;
49
- computedExpression?: string;
50
- isPersisted?: boolean;
51
- isSparse?: boolean;
52
- defaultValue?: string;
53
- defaultConstraint?: string;
54
- columnComment?: string;
55
- isUnsigned?: boolean;
56
- isZerofill?: boolean;
57
- options?: [];
58
- canSelectMultipleOptions?: boolean;
59
- undropColumnName?: string;
60
- contentHash?: string;
61
- engine?: string;
62
- }[];
26
+ getDisplayColumns(table: TableInfo, parentPath: string[]): DisplayColumn[];
63
27
  addJoinsFromExpandedColumns(select: Select, columns: DisplayColumn[], parentAlias: string, columnSources: any): void;
64
28
  addReferenceToSelect(select: Select, parentAlias: string, column: DisplayColumn): void;
65
29
  getFkDictionaryDescription(foreignKey: ForeignKeyInfo): DictionaryDescription;
@@ -60,7 +60,7 @@ class TableGridDisplay extends GridDisplay_1.GridDisplay {
60
60
  var _a, _b;
61
61
  return (((_b = (_a = table === null || table === void 0 ? void 0 : table.columns) === null || _a === void 0 ? void 0 : _a.map(col => this.getDisplayColumn(table, col, parentPath))) === null || _b === void 0 ? void 0 : _b.map(col => {
62
62
  var _a, _b, _c;
63
- return (Object.assign(Object.assign({}, col), { isChecked: this.isColumnChecked(col), hintColumnNames: ((_b = (_a = this.getFkDictionaryDescription(col.isForeignKeyUnique ? col.foreignKey : null)) === null || _a === void 0 ? void 0 : _a.columns) === null || _b === void 0 ? void 0 : _b.map(columnName => `hint_${col.uniqueName}_${columnName}`)) || null, hintColumnDelimiter: (_c = this.getFkDictionaryDescription(col.isForeignKeyUnique ? col.foreignKey : null)) === null || _c === void 0 ? void 0 : _c.delimiter, isExpandable: !!col.foreignKey }));
63
+ return (Object.assign(Object.assign({}, col), { isChecked: this.isColumnChecked(col), hintColumnNames: ((_b = (_a = this.getFkDictionaryDescription(col.isForeignKeyUnique ? col.foreignKey : null)) === null || _a === void 0 ? void 0 : _a.columns) === null || _b === void 0 ? void 0 : _b.map(columnName => (0, dbgate_tools_1.shortenIdentifier)(`hint_${col.uniqueName}_${columnName}`, this.driver.dialect.maxIdentifierLength))) || null, hintColumnDelimiter: (_c = this.getFkDictionaryDescription(col.isForeignKeyUnique ? col.foreignKey : null)) === null || _c === void 0 ? void 0 : _c.delimiter, uniqueNameShorten: (0, dbgate_tools_1.shortenIdentifier)(col.uniqueName, this.driver.dialect.maxIdentifierLength), isExpandable: !!col.foreignKey }));
64
64
  })) || []);
65
65
  }
66
66
  addJoinsFromExpandedColumns(select, columns, parentAlias, columnSources) {
@@ -68,7 +68,7 @@ class TableGridDisplay extends GridDisplay_1.GridDisplay {
68
68
  if (this.isExpandedColumn(column.uniqueName)) {
69
69
  const table = this.getFkTarget(column);
70
70
  if (table) {
71
- const childAlias = `${column.uniqueName}_ref`;
71
+ const childAlias = (0, dbgate_tools_1.shortenIdentifier)(`${column.uniqueName}_ref`, this.driver.dialect.maxIdentifierLength);
72
72
  const subcolumns = this.getDisplayColumns(table, column.uniquePath);
73
73
  this.addReferenceToSelect(select, parentAlias, column);
74
74
  this.addJoinsFromExpandedColumns(select, subcolumns, childAlias, columnSources);
@@ -79,7 +79,7 @@ class TableGridDisplay extends GridDisplay_1.GridDisplay {
79
79
  }
80
80
  addReferenceToSelect(select, parentAlias, column) {
81
81
  var _a, _b, _c, _d, _e, _f, _g;
82
- const childAlias = `${column.uniqueName}_ref`;
82
+ const childAlias = (0, dbgate_tools_1.shortenIdentifier)(`${column.uniqueName}_ref`, this.driver.dialect.maxIdentifierLength);
83
83
  if ((select.from.relations || []).find(x => x.alias == childAlias))
84
84
  return;
85
85
  const table = this.getFkTarget(column);
@@ -139,12 +139,14 @@ class TableGridDisplay extends GridDisplay_1.GridDisplay {
139
139
  const hintDescription = this.getDictionaryDescription(table);
140
140
  if (hintDescription) {
141
141
  const parentUniqueName = column.uniquePath.slice(0, -1).join('.');
142
- this.addReferenceToSelect(select, parentUniqueName ? `${parentUniqueName}_ref` : 'basetbl', column);
143
- const childAlias = `${column.uniqueName}_ref`;
142
+ this.addReferenceToSelect(select, parentUniqueName
143
+ ? (0, dbgate_tools_1.shortenIdentifier)(`${parentUniqueName}_ref`, this.driver.dialect.maxIdentifierLength)
144
+ : 'basetbl', column);
145
+ const childAlias = (0, dbgate_tools_1.shortenIdentifier)(`${column.uniqueName}_ref`, this.driver.dialect.maxIdentifierLength);
144
146
  select.columns.push(...hintDescription.columns.map(columnName => ({
145
147
  exprType: 'column',
146
148
  columnName,
147
- alias: `hint_${column.uniqueName}_${columnName}`,
149
+ alias: (0, dbgate_tools_1.shortenIdentifier)(`hint_${column.uniqueName}_${columnName}`, this.driver.dialect.maxIdentifierLength),
148
150
  source: { alias: childAlias },
149
151
  })));
150
152
  res = true;
@@ -171,7 +173,7 @@ class TableGridDisplay extends GridDisplay_1.GridDisplay {
171
173
  return [];
172
174
  }
173
175
  getFkTarget(column) {
174
- const { uniqueName, foreignKey, isForeignKeyUnique } = column;
176
+ const { foreignKey, isForeignKeyUnique } = column;
175
177
  if (!isForeignKeyUnique)
176
178
  return null;
177
179
  const pureName = foreignKey.refTableName;
@@ -211,9 +213,10 @@ class TableGridDisplay extends GridDisplay_1.GridDisplay {
211
213
  return res;
212
214
  }
213
215
  addAddedColumnsToSelect(select, columns, parentAlias, displayedColumnInfo) {
216
+ var _a;
214
217
  for (const column of columns) {
215
218
  if (this.addAllExpandedColumnsToSelected || this.config.addedColumns.includes(column.uniqueName)) {
216
- select.columns.push(this.createColumnExpression(column, { name: column, alias: parentAlias }, column.uniqueName, 'view'));
219
+ select.columns.push(this.createColumnExpression(column, { name: column, alias: parentAlias }, (_a = column.uniqueNameShorten) !== null && _a !== void 0 ? _a : column.uniqueName, 'view'));
217
220
  displayedColumnInfo[column.uniqueName] = Object.assign(Object.assign({}, column), { sourceAlias: parentAlias });
218
221
  }
219
222
  }
@@ -1,5 +1,5 @@
1
1
  export type ChartTypeEnum = 'bar' | 'line' | 'timeline' | 'pie' | 'polarArea';
2
- export type ChartXTransformFunction = 'identity' | 'date:minute' | 'date:hour' | 'date:day' | 'date:month' | 'date:year';
2
+ export type ChartXTransformFunction = 'identity' | 'date:minute' | 'date:hour' | 'date:day' | 'date:week' | 'date:month' | 'date:year';
3
3
  export type ChartYAggregateFunction = 'sum' | 'first' | 'last' | 'min' | 'max' | 'count' | 'avg';
4
4
  export type ChartDataLabelFormatter = 'number' | 'size:bytes' | 'size:kb' | 'size:mb' | 'size:gb';
5
5
  export declare const ChartConstDefaults: {
@@ -56,6 +56,7 @@ export interface ChartDateParsed {
56
56
  minute?: number;
57
57
  second?: number;
58
58
  fraction?: string;
59
+ week?: number;
59
60
  }
60
61
  export interface ChartAvailableColumn {
61
62
  field: string;
package/lib/chartTools.js CHANGED
@@ -26,6 +26,7 @@ function tryParseChartDate(dateInput) {
26
26
  return {
27
27
  year: dateInput.getFullYear(),
28
28
  month: dateInput.getMonth() + 1,
29
+ week: (0, date_fns_1.getWeek)(dateInput),
29
30
  day: dateInput.getDate(),
30
31
  hour: dateInput.getHours(),
31
32
  minute: dateInput.getMinutes(),
@@ -37,13 +38,18 @@ function tryParseChartDate(dateInput) {
37
38
  return null;
38
39
  const dateMatch = dateInput.match(/^(\d{4})-(\d{2})-(\d{2})(?:[ T](\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?(Z|[+-]\d{2}:\d{2})?)?$/);
39
40
  const monthMatch = dateInput.match(/^(\d{4})-(\d{2})$/);
41
+ const weekMatch = dateInput.match(/^(\d{4})\@(\d{2})$/);
40
42
  // const yearMatch = dateInput.match(/^(\d{4})$/);
41
43
  if (dateMatch) {
42
- const [_notUsed, year, month, day, hour, minute, second, fraction] = dateMatch;
44
+ const [_notUsed, yearStr, monthStr, dayStr, hour, minute, second, fraction] = dateMatch;
45
+ const year = parseInt(yearStr, 10);
46
+ const month = parseInt(monthStr, 10);
47
+ const day = parseInt(dayStr, 10);
43
48
  return {
44
- year: parseInt(year, 10),
45
- month: parseInt(month, 10),
46
- day: parseInt(day, 10),
49
+ year,
50
+ month,
51
+ week: (0, date_fns_1.getWeek)(new Date(year, month - 1, day)),
52
+ day,
47
53
  hour: parseInt(hour, 10) || 0,
48
54
  minute: parseInt(minute, 10) || 0,
49
55
  second: parseInt(second, 10) || 0,
@@ -62,6 +68,18 @@ function tryParseChartDate(dateInput) {
62
68
  fraction: undefined,
63
69
  };
64
70
  }
71
+ if (weekMatch) {
72
+ const [_notUsed, year, week] = weekMatch;
73
+ return {
74
+ year: parseInt(year, 10),
75
+ week: parseInt(week, 10),
76
+ day: 1,
77
+ hour: 0,
78
+ minute: 0,
79
+ second: 0,
80
+ fraction: undefined,
81
+ };
82
+ }
65
83
  // if (yearMatch) {
66
84
  // const [_notUsed, year] = yearMatch;
67
85
  // return {
@@ -81,11 +99,14 @@ function pad2Digits(number) {
81
99
  return ('00' + number).slice(-2);
82
100
  }
83
101
  function stringifyChartDate(value, transform) {
102
+ var _a, _b;
84
103
  switch (transform) {
85
104
  case 'date:year':
86
105
  return `${value.year}`;
87
106
  case 'date:month':
88
107
  return `${value.year}-${pad2Digits(value.month)}`;
108
+ case 'date:week':
109
+ return `${value.year}@${pad2Digits((0, date_fns_1.getWeek)(new Date(value.year, ((_a = value.month) !== null && _a !== void 0 ? _a : 1) - 1, (_b = value.day) !== null && _b !== void 0 ? _b : 1)))}`;
89
110
  case 'date:day':
90
111
  return `${value.year}-${pad2Digits(value.month)}-${pad2Digits(value.day)}`;
91
112
  case 'date:hour':
@@ -108,6 +129,9 @@ function incrementChartDate(value, transform) {
108
129
  case 'date:month':
109
130
  newDateRepresentation = (0, date_fns_1.addMonths)(dateRepresentation, 1);
110
131
  break;
132
+ case 'date:week':
133
+ newDateRepresentation = (0, date_fns_1.addWeeks)(dateRepresentation, 1);
134
+ break;
111
135
  case 'date:day':
112
136
  newDateRepresentation = (0, date_fns_1.addDays)(dateRepresentation, 1);
113
137
  break;
@@ -126,6 +150,11 @@ function incrementChartDate(value, transform) {
126
150
  year: newDateRepresentation.getFullYear(),
127
151
  month: newDateRepresentation.getMonth() + 1,
128
152
  };
153
+ case 'date:week':
154
+ return {
155
+ year: newDateRepresentation.getFullYear(),
156
+ week: (0, date_fns_1.getWeek)(newDateRepresentation),
157
+ };
129
158
  case 'date:day':
130
159
  return {
131
160
  year: newDateRepresentation.getFullYear(),
@@ -157,6 +186,8 @@ function runTransformFunction(value, transformFunction) {
157
186
  return dateParsed ? `${dateParsed.year}` : null;
158
187
  case 'date:month':
159
188
  return dateParsed ? `${dateParsed.year}-${pad2Digits(dateParsed.month)}` : null;
189
+ case 'date:week':
190
+ return dateParsed ? `${dateParsed.year}@${pad2Digits(dateParsed.week)}` : null;
160
191
  case 'date:day':
161
192
  return dateParsed ? `${dateParsed.year}-${pad2Digits(dateParsed.month)}-${pad2Digits(dateParsed.day)}` : null;
162
193
  case 'date:hour':
@@ -185,6 +216,14 @@ function computeChartBucketKey(dateParsed, chart, row) {
185
216
  month: dateParsed.month,
186
217
  },
187
218
  ];
219
+ case 'date:week':
220
+ return [
221
+ dateParsed ? `${dateParsed.year}@${pad2Digits(dateParsed.week)}` : null,
222
+ {
223
+ year: dateParsed.year,
224
+ week: dateParsed.week,
225
+ },
226
+ ];
188
227
  case 'date:day':
189
228
  return [
190
229
  dateParsed ? `${dateParsed.year}-${pad2Digits(dateParsed.month)}-${pad2Digits(dateParsed.day)}` : null,
@@ -231,6 +270,8 @@ function computeDateBucketDistance(begin, end, transform) {
231
270
  return end.year - begin.year;
232
271
  case 'date:month':
233
272
  return (end.year - begin.year) * 12 + (end.month - begin.month);
273
+ case 'date:week':
274
+ return (end.year - begin.year) * 52 + (end.week - begin.week);
234
275
  case 'date:day':
235
276
  return ((end.year - begin.year) * 365 +
236
277
  (end.month - begin.month) * 30 + // rough approximation
@@ -258,6 +299,8 @@ function compareChartDatesParsed(a, b, transform) {
258
299
  return a.year - b.year;
259
300
  case 'date:month':
260
301
  return a.year === b.year ? a.month - b.month : a.year - b.year;
302
+ case 'date:week':
303
+ return a.year === b.year ? a.week - b.week : a.year - b.year;
261
304
  case 'date:day':
262
305
  return a.year === b.year && a.month === b.month
263
306
  ? a.day - b.day
@@ -305,6 +348,8 @@ function getParentDateBucketKey(bucketKey, transform, isGrouped) {
305
348
  return null; // no parent for year
306
349
  case 'date:month':
307
350
  return bucketKey.slice(0, 4);
351
+ case 'date:week':
352
+ return bucketKey.slice(0, 4);
308
353
  case 'date:day':
309
354
  return bucketKey.slice(0, 7);
310
355
  case 'date:hour':
@@ -319,6 +364,8 @@ function getParentDateBucketTransform(transform) {
319
364
  return null; // no parent for year
320
365
  case 'date:month':
321
366
  return 'date:year';
367
+ case 'date:week':
368
+ return 'date:year';
322
369
  case 'date:day':
323
370
  return 'date:month';
324
371
  case 'date:hour':
@@ -335,6 +382,8 @@ function getParentKeyParsed(date, transform) {
335
382
  return null; // no parent for year
336
383
  case 'date:month':
337
384
  return { year: date.year };
385
+ case 'date:week':
386
+ return { year: date.week };
338
387
  case 'date:day':
339
388
  return { year: date.year, month: date.month };
340
389
  case 'date:hour':
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "6.6.3",
2
+ "version": "6.6.4",
3
3
  "name": "dbgate-datalib",
4
4
  "main": "lib/index.js",
5
5
  "typings": "lib/index.d.ts",
@@ -15,14 +15,14 @@
15
15
  ],
16
16
  "dependencies": {
17
17
  "date-fns": "^4.1.0",
18
- "dbgate-filterparser": "^6.6.3",
19
- "dbgate-sqltree": "^6.6.3",
20
- "dbgate-tools": "^6.6.3",
18
+ "dbgate-filterparser": "^6.6.4",
19
+ "dbgate-sqltree": "^6.6.4",
20
+ "dbgate-tools": "^6.6.4",
21
21
  "uuid": "^3.4.0"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@types/node": "^13.7.0",
25
- "dbgate-types": "^6.6.3",
25
+ "dbgate-types": "^6.6.4",
26
26
  "jest": "^28.1.3",
27
27
  "ts-jest": "^28.0.7",
28
28
  "typescript": "^4.4.3"