dbgate-datalib 5.1.4 → 5.1.6

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,5 +1,5 @@
1
1
  import { GridDisplay, ChangeCacheFunc, ChangeConfigFunc } from './GridDisplay';
2
- import { EngineDriver, ViewInfo, ColumnInfo } from 'dbgate-types';
2
+ import type { EngineDriver, ViewInfo, ColumnInfo } from 'dbgate-types';
3
3
  import { GridConfig, GridCache } from './GridConfig';
4
4
  export declare class ViewGridDisplay extends GridDisplay {
5
5
  view: ViewInfo;
@@ -1,5 +1,5 @@
1
1
  import { Command } from 'dbgate-sqltree';
2
- import { DatabaseInfo } from 'dbgate-types';
2
+ import type { DatabaseInfo } from 'dbgate-types';
3
3
  import { ChangeSet } from './ChangeSet';
4
4
  export interface ChangeSetDeleteCascade {
5
5
  title: string;
package/lib/index.d.ts CHANGED
@@ -19,3 +19,5 @@ export * from './PerspectiveDataProvider';
19
19
  export * from './PerspectiveCache';
20
20
  export * from './PerspectiveConfig';
21
21
  export * from './processPerspectiveDefaultColunns';
22
+ export * from './PerspectiveDataPattern';
23
+ export * from './PerspectiveDataLoader';
package/lib/index.js CHANGED
@@ -35,3 +35,5 @@ __exportStar(require("./PerspectiveDataProvider"), exports);
35
35
  __exportStar(require("./PerspectiveCache"), exports);
36
36
  __exportStar(require("./PerspectiveConfig"), exports);
37
37
  __exportStar(require("./processPerspectiveDefaultColunns"), exports);
38
+ __exportStar(require("./PerspectiveDataPattern"), exports);
39
+ __exportStar(require("./PerspectiveDataLoader"), exports);
@@ -1,4 +1,5 @@
1
1
  import { MultipleDatabaseInfo, PerspectiveConfig } from './PerspectiveConfig';
2
- export declare function perspectiveNodesHaveStructure(config: PerspectiveConfig, dbInfos: MultipleDatabaseInfo, conid: string, database: string): boolean;
3
- export declare function shouldProcessPerspectiveDefaultColunns(config: PerspectiveConfig, dbInfos: MultipleDatabaseInfo, conid: string, database: string): boolean;
4
- export declare function processPerspectiveDefaultColunns(config: PerspectiveConfig, dbInfos: MultipleDatabaseInfo, conid: string, database: string): PerspectiveConfig;
2
+ import { PerspectiveDataPatternDict } from './PerspectiveDataPattern';
3
+ export declare function perspectiveNodesHaveStructure(config: PerspectiveConfig, dbInfos: MultipleDatabaseInfo, dataPatterns: PerspectiveDataPatternDict, conid: string, database: string): boolean;
4
+ export declare function shouldProcessPerspectiveDefaultColunns(config: PerspectiveConfig, dbInfos: MultipleDatabaseInfo, dataPatterns: PerspectiveDataPatternDict, conid: string, database: string): boolean;
5
+ export declare function processPerspectiveDefaultColunns(config: PerspectiveConfig, dbInfos: MultipleDatabaseInfo, dataPatterns: PerspectiveDataPatternDict, conid: string, database: string): PerspectiveConfig;
@@ -3,16 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processPerspectiveDefaultColunns = exports.shouldProcessPerspectiveDefaultColunns = exports.perspectiveNodesHaveStructure = void 0;
4
4
  const dbgate_tools_1 = require("dbgate-tools");
5
5
  const PerspectiveTreeNode_1 = require("./PerspectiveTreeNode");
6
+ const namePredicates = [
7
+ x => x.toLowerCase() == 'name',
8
+ x => x.toLowerCase() == 'title',
9
+ x => x.toLowerCase().includes('name'),
10
+ x => x.toLowerCase().includes('title'),
11
+ x => x.toLowerCase().includes('subject'),
12
+ ];
6
13
  function getPerspectiveDefaultColumns(table, db, circularColumns) {
7
14
  const columns = table.columns.map(x => x.columnName);
8
15
  const predicates = [
9
- x => x.toLowerCase() == 'name',
10
- x => x.toLowerCase() == 'title',
11
- x => x.toLowerCase().includes('name'),
12
- x => x.toLowerCase().includes('title'),
13
- x => x.toLowerCase().includes('subject'),
14
- // x => x.toLowerCase().includes('text'),
15
- // x => x.toLowerCase().includes('desc'),
16
+ ...namePredicates,
16
17
  x => {
17
18
  var _a, _b, _c;
18
19
  return (_c = (_b = (_a = table.columns
@@ -37,7 +38,16 @@ function getPerspectiveDefaultColumns(table, db, circularColumns) {
37
38
  }
38
39
  return [[columns[0]], null];
39
40
  }
40
- function perspectiveNodesHaveStructure(config, dbInfos, conid, database) {
41
+ function getPerspectiveDefaultCollectionColumns(pattern) {
42
+ const columns = pattern.columns.map(x => x.name);
43
+ const predicates = [...namePredicates, x => { var _a, _b; return (_b = (_a = pattern.columns.find(y => y.name == x)) === null || _a === void 0 ? void 0 : _a.types) === null || _b === void 0 ? void 0 : _b.includes('string'); }];
44
+ for (const predicate of predicates) {
45
+ const col = columns.find(predicate);
46
+ if (col)
47
+ return [col];
48
+ }
49
+ }
50
+ function perspectiveNodesHaveStructure(config, dbInfos, dataPatterns, conid, database) {
41
51
  var _a;
42
52
  for (const node of config.nodes) {
43
53
  const db = (_a = dbInfos === null || dbInfos === void 0 ? void 0 : dbInfos[node.conid || conid]) === null || _a === void 0 ? void 0 : _a[node.database || database];
@@ -45,20 +55,23 @@ function perspectiveNodesHaveStructure(config, dbInfos, conid, database) {
45
55
  return false;
46
56
  const table = db.tables.find(x => x.pureName == node.pureName && x.schemaName == node.schemaName);
47
57
  const view = db.views.find(x => x.pureName == node.pureName && x.schemaName == node.schemaName);
48
- if (!table && !view)
58
+ const collection = db.collections.find(x => x.pureName == node.pureName && x.schemaName == node.schemaName);
59
+ if (!table && !view && !collection)
60
+ return false;
61
+ if (collection && !(dataPatterns === null || dataPatterns === void 0 ? void 0 : dataPatterns[node.designerId]))
49
62
  return false;
50
63
  }
51
64
  return true;
52
65
  }
53
66
  exports.perspectiveNodesHaveStructure = perspectiveNodesHaveStructure;
54
- function shouldProcessPerspectiveDefaultColunns(config, dbInfos, conid, database) {
67
+ function shouldProcessPerspectiveDefaultColunns(config, dbInfos, dataPatterns, conid, database) {
55
68
  const nodesNotProcessed = config.nodes.filter(x => !x.defaultColumnsProcessed);
56
69
  if (nodesNotProcessed.length == 0)
57
70
  return false;
58
- return perspectiveNodesHaveStructure(config, dbInfos, conid, database);
71
+ return perspectiveNodesHaveStructure(config, dbInfos, dataPatterns, conid, database);
59
72
  }
60
73
  exports.shouldProcessPerspectiveDefaultColunns = shouldProcessPerspectiveDefaultColunns;
61
- function processPerspectiveDefaultColunnsStep(config, dbInfos, conid, database) {
74
+ function processPerspectiveDefaultColunnsStep(config, dbInfos, dataPatterns, conid, database) {
62
75
  var _a, _b;
63
76
  const rootNode = config.nodes.find(x => x.designerId == config.rootDesignerId);
64
77
  if (!rootNode)
@@ -77,6 +90,7 @@ function processPerspectiveDefaultColunnsStep(config, dbInfos, conid, database)
77
90
  continue;
78
91
  const table = db.tables.find(x => x.pureName == node.pureName && x.schemaName == node.schemaName);
79
92
  const view = db.views.find(x => x.pureName == node.pureName && x.schemaName == node.schemaName);
93
+ const collection = db.collections.find(x => x.pureName == node.pureName && x.schemaName == node.schemaName);
80
94
  if (table || view) {
81
95
  const treeNode = root.findNodeByDesignerId(node.designerId);
82
96
  if (!treeNode) {
@@ -105,15 +119,20 @@ function processPerspectiveDefaultColunnsStep(config, dbInfos, conid, database)
105
119
  ? Object.assign(Object.assign({}, n), { defaultColumnsProcessed: true, checkedColumns: defaultColumns }) : n) });
106
120
  }
107
121
  }
122
+ if (collection) {
123
+ const defaultColumns = getPerspectiveDefaultCollectionColumns(dataPatterns === null || dataPatterns === void 0 ? void 0 : dataPatterns[node.designerId]);
124
+ return Object.assign(Object.assign({}, config), { nodes: config.nodes.map(n => n.designerId == node.designerId
125
+ ? Object.assign(Object.assign({}, n), { defaultColumnsProcessed: true, checkedColumns: defaultColumns }) : n) });
126
+ }
108
127
  }
109
128
  return null;
110
129
  }
111
130
  function markAllProcessed(config) {
112
131
  return Object.assign(Object.assign({}, config), { nodes: config.nodes.map(x => (Object.assign(Object.assign({}, x), { defaultColumnsProcessed: true }))) });
113
132
  }
114
- function processPerspectiveDefaultColunns(config, dbInfos, conid, database) {
133
+ function processPerspectiveDefaultColunns(config, dbInfos, dataPatterns, conid, database) {
115
134
  while (config.nodes.filter(x => !x.defaultColumnsProcessed).length > 0) {
116
- const newConfig = processPerspectiveDefaultColunnsStep(config, dbInfos, conid, database);
135
+ const newConfig = processPerspectiveDefaultColunnsStep(config, dbInfos, dataPatterns, conid, database);
117
136
  if (!newConfig) {
118
137
  return markAllProcessed(config);
119
138
  }
@@ -13,7 +13,7 @@ const artistDataAlbumTrack_1 = __importDefault(require("./artistDataAlbumTrack")
13
13
  const processPerspectiveDefaultColunns_1 = require("../processPerspectiveDefaultColunns");
14
14
  test('test flat view', () => {
15
15
  const artistTable = chinookDbInfo_1.chinookDbInfo.tables.find(x => x.pureName == 'Artist');
16
- const configColumns = (0, processPerspectiveDefaultColunns_1.processPerspectiveDefaultColunns)((0, PerspectiveConfig_1.createPerspectiveConfig)({ pureName: 'Artist' }), { conid: { db: chinookDbInfo_1.chinookDbInfo } }, 'conid', 'db');
16
+ const configColumns = (0, processPerspectiveDefaultColunns_1.processPerspectiveDefaultColunns)((0, PerspectiveConfig_1.createPerspectiveConfig)({ pureName: 'Artist' }), { conid: { db: chinookDbInfo_1.chinookDbInfo } }, null, 'conid', 'db');
17
17
  const root = new PerspectiveTreeNode_1.PerspectiveTableNode(artistTable, { conid: { db: chinookDbInfo_1.chinookDbInfo } }, configColumns, null, null, { conid: 'conid', database: 'db' }, null, configColumns.rootDesignerId);
18
18
  const display = new PerspectiveDisplay_1.PerspectiveDisplay(root, artistDataFlat_1.default);
19
19
  expect(display.rows.length).toEqual(4);
@@ -32,7 +32,7 @@ test('test one level nesting', () => {
32
32
  designerId: '1',
33
33
  columns: [{ source: 'ArtistId', target: 'ArtistId' }],
34
34
  });
35
- const configColumns = (0, processPerspectiveDefaultColunns_1.processPerspectiveDefaultColunns)(config, { conid: { db: chinookDbInfo_1.chinookDbInfo } }, 'conid', 'db');
35
+ const configColumns = (0, processPerspectiveDefaultColunns_1.processPerspectiveDefaultColunns)(config, { conid: { db: chinookDbInfo_1.chinookDbInfo } }, null, 'conid', 'db');
36
36
  // const config = createPerspectiveConfig({ pureName: 'Artist' });
37
37
  // config.nodes[0].checkedColumns = ['Album'];
38
38
  const root = new PerspectiveTreeNode_1.PerspectiveTableNode(artistTable, { conid: { db: chinookDbInfo_1.chinookDbInfo } }, configColumns, null, null, { conid: 'conid', database: 'db' }, null, configColumns.nodes[0].designerId);
@@ -73,7 +73,7 @@ test('test two level nesting', () => {
73
73
  designerId: '2',
74
74
  columns: [{ source: 'AlbumId', target: 'AlbumId' }],
75
75
  });
76
- const configColumns = (0, processPerspectiveDefaultColunns_1.processPerspectiveDefaultColunns)(config, { conid: { db: chinookDbInfo_1.chinookDbInfo } }, 'conid', 'db');
76
+ const configColumns = (0, processPerspectiveDefaultColunns_1.processPerspectiveDefaultColunns)(config, { conid: { db: chinookDbInfo_1.chinookDbInfo } }, null, 'conid', 'db');
77
77
  const root = new PerspectiveTreeNode_1.PerspectiveTableNode(artistTable, { conid: { db: chinookDbInfo_1.chinookDbInfo } }, configColumns, null, null, { conid: 'conid', database: 'db' }, null, configColumns.nodes[0].designerId);
78
78
  const display = new PerspectiveDisplay_1.PerspectiveDisplay(root, artistDataAlbumTrack_1.default);
79
79
  console.log(display.rows);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const PerspectiveDisplay_1 = require("../PerspectiveDisplay");
4
+ const PerspectiveTreeNode_1 = require("../PerspectiveTreeNode");
5
+ const PerspectiveConfig_1 = require("../PerspectiveConfig");
6
+ const processPerspectiveDefaultColunns_1 = require("../processPerspectiveDefaultColunns");
7
+ const dbgate_tools_1 = require("dbgate-tools");
8
+ const PerspectiveDataPattern_1 = require("../PerspectiveDataPattern");
9
+ const PerspectiveDataProvider_1 = require("../PerspectiveDataProvider");
10
+ const accountData = [
11
+ {
12
+ name: 'jan',
13
+ email: 'jan@foo.co',
14
+ follows: [{ name: 'lucie' }, { name: 'petr' }],
15
+ nested: { email: 'jan@nest.cz' },
16
+ },
17
+ {
18
+ name: 'romeo',
19
+ email: 'romeo@foo.co',
20
+ follows: [{ name: 'julie' }, { name: 'wiliam' }],
21
+ nested: { email: 'romeo@nest.cz' },
22
+ },
23
+ ];
24
+ function createDisplay(cfgFunc) {
25
+ const collectionInfo = {
26
+ objectTypeField: 'collections',
27
+ pureName: 'Account',
28
+ };
29
+ const dbInfo = Object.assign(Object.assign({}, dbgate_tools_1.DatabaseAnalyser.createEmptyStructure()), { collections: [collectionInfo] });
30
+ const config = (0, PerspectiveConfig_1.createPerspectiveConfig)({ pureName: 'Account' });
31
+ const dataPatterns = {
32
+ [config.rootDesignerId]: (0, PerspectiveDataPattern_1.analyseDataPattern)({
33
+ conid: 'conid',
34
+ database: 'db',
35
+ pureName: 'Account',
36
+ }, accountData),
37
+ };
38
+ const configColumns = (0, processPerspectiveDefaultColunns_1.processPerspectiveDefaultColunns)(config, { conid: { db: dbInfo } }, dataPatterns, 'conid', 'db');
39
+ if (cfgFunc) {
40
+ cfgFunc(configColumns.nodes[0]);
41
+ }
42
+ const root = new PerspectiveTreeNode_1.PerspectiveTableNode(collectionInfo, { conid: { db: dbInfo } }, configColumns, null, new PerspectiveDataProvider_1.PerspectiveDataProvider(null, null, dataPatterns), { conid: 'conid', database: 'db' }, null, configColumns.rootDesignerId);
43
+ const display = new PerspectiveDisplay_1.PerspectiveDisplay(root, accountData);
44
+ return display;
45
+ }
46
+ test('test nosql display', () => {
47
+ const display = createDisplay();
48
+ expect(display.rows.length).toEqual(2);
49
+ expect(display.rows[0].rowData).toEqual(['jan']);
50
+ expect(display.rows[1].rowData).toEqual(['romeo']);
51
+ });
52
+ test('test nosql nested array display', () => {
53
+ const display = createDisplay(cfg => {
54
+ cfg.checkedColumns = ['name', 'follows::name'];
55
+ });
56
+ expect(display.rows.length).toEqual(4);
57
+ expect(display.rows[0].rowData).toEqual(['jan', 'lucie']);
58
+ expect(display.rows[1].rowData).toEqual([undefined, 'petr']);
59
+ expect(display.rows[2].rowData).toEqual(['romeo', 'julie']);
60
+ expect(display.rows[3].rowData).toEqual([undefined, 'wiliam']);
61
+ });
62
+ test('test nosql nested object', () => {
63
+ const display = createDisplay(cfg => {
64
+ cfg.checkedColumns = ['name', 'nested::email'];
65
+ });
66
+ expect(display.rows.length).toEqual(2);
67
+ expect(display.rows[0].rowData).toEqual(['jan', 'jan@nest.cz']);
68
+ expect(display.rows[1].rowData).toEqual(['romeo', 'romeo@nest.cz']);
69
+ });
@@ -1,2 +1,2 @@
1
- import { DatabaseInfo } from 'dbgate-types';
1
+ import type { DatabaseInfo } from 'dbgate-types';
2
2
  export declare const chinookDbInfo: DatabaseInfo;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "5.1.4",
2
+ "version": "5.1.6",
3
3
  "name": "dbgate-datalib",
4
4
  "main": "lib/index.js",
5
5
  "typings": "lib/index.d.ts",
@@ -13,12 +13,12 @@
13
13
  "lib"
14
14
  ],
15
15
  "dependencies": {
16
- "dbgate-sqltree": "^5.1.4",
17
- "dbgate-tools": "^5.1.4",
18
- "dbgate-filterparser": "^5.1.4"
16
+ "dbgate-sqltree": "^5.1.6",
17
+ "dbgate-tools": "^5.1.6",
18
+ "dbgate-filterparser": "^5.1.6"
19
19
  },
20
20
  "devDependencies": {
21
- "dbgate-types": "^5.1.4",
21
+ "dbgate-types": "^5.1.6",
22
22
  "@types/node": "^13.7.0",
23
23
  "jest": "^28.1.3",
24
24
  "ts-jest": "^28.0.7",