dbgate-datalib 7.1.13 → 7.2.0
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/lib/GridDisplay.d.ts +8 -0
- package/lib/GridDisplay.js +10 -0
- package/lib/JslGridDisplay.d.ts +23 -2
- package/lib/JslGridDisplay.js +129 -5
- package/lib/QueryResultChangeSet.d.ts +5 -0
- package/lib/QueryResultChangeSet.js +33 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/package.json +5 -5
package/lib/GridDisplay.d.ts
CHANGED
|
@@ -25,6 +25,8 @@ export interface DisplayColumn {
|
|
|
25
25
|
dataType?: string;
|
|
26
26
|
filterBehaviour?: FilterBehaviour;
|
|
27
27
|
isStructured?: boolean;
|
|
28
|
+
sourceColumnName?: string;
|
|
29
|
+
queryResultEditable?: boolean;
|
|
28
30
|
}
|
|
29
31
|
export interface DisplayedColumnEx extends DisplayColumn {
|
|
30
32
|
sourceAlias: string;
|
|
@@ -59,6 +61,10 @@ export declare abstract class GridDisplay {
|
|
|
59
61
|
groupable: boolean;
|
|
60
62
|
filterable: boolean;
|
|
61
63
|
editable: boolean;
|
|
64
|
+
allowInsert: boolean;
|
|
65
|
+
allowDelete: boolean;
|
|
66
|
+
allowStructureChange: boolean;
|
|
67
|
+
allowRowDocumentEdit: boolean;
|
|
62
68
|
isLoadedCorrectly: boolean;
|
|
63
69
|
supportsReload: boolean;
|
|
64
70
|
isDynamicStructure: boolean;
|
|
@@ -115,8 +121,10 @@ export declare abstract class GridDisplay {
|
|
|
115
121
|
clearFilters(): void;
|
|
116
122
|
resetConfig(): void;
|
|
117
123
|
getChangeSetCondition(row: any): Pick<any, string>;
|
|
124
|
+
isColumnEditable(uniqueName: string, row?: any): boolean;
|
|
118
125
|
getChangeSetField(row: any, uniqueName: any, insertedRowIndex: any, existingRowIndex?: any, baseNameOmitable?: boolean): ChangeSetFieldDefinition;
|
|
119
126
|
getChangeSetRow(row: any, insertedRowIndex: any, existingRowIndex: any, baseNameOmitable?: boolean): ChangeSetRowDefinition;
|
|
127
|
+
getChangeSetRowDefinitions(row: any, insertedRowIndex: any, existingRowIndex: any, baseNameOmitable?: boolean): ChangeSetRowDefinition[];
|
|
120
128
|
createSelect(options?: {}): Select;
|
|
121
129
|
processReferences(select: Select, displayedColumnInfo: DisplayedColumnInfo, options: any): void;
|
|
122
130
|
createColumnExpression(col: any, source: any, alias?: any, purpose?: 'view' | 'filter'): any;
|
package/lib/GridDisplay.js
CHANGED
|
@@ -27,6 +27,10 @@ class GridDisplay {
|
|
|
27
27
|
this.groupable = false;
|
|
28
28
|
this.filterable = false;
|
|
29
29
|
this.editable = false;
|
|
30
|
+
this.allowInsert = true;
|
|
31
|
+
this.allowDelete = true;
|
|
32
|
+
this.allowStructureChange = true;
|
|
33
|
+
this.allowRowDocumentEdit = true;
|
|
30
34
|
this.isLoadedCorrectly = true;
|
|
31
35
|
this.supportsReload = false;
|
|
32
36
|
this.isDynamicStructure = false;
|
|
@@ -406,6 +410,9 @@ class GridDisplay {
|
|
|
406
410
|
return null;
|
|
407
411
|
return lodash_1.default.pick(row, this.changeSetKeyFields);
|
|
408
412
|
}
|
|
413
|
+
isColumnEditable(uniqueName, row) {
|
|
414
|
+
return this.editable;
|
|
415
|
+
}
|
|
409
416
|
getChangeSetField(row, uniqueName, insertedRowIndex, existingRowIndex = null, baseNameOmitable = false) {
|
|
410
417
|
const col = this.columns.find(x => x.uniqueName == uniqueName);
|
|
411
418
|
if (!col)
|
|
@@ -432,6 +439,9 @@ class GridDisplay {
|
|
|
432
439
|
condition: insertedRowIndex == null && existingRowIndex == null ? this.getChangeSetCondition(row) : null,
|
|
433
440
|
};
|
|
434
441
|
}
|
|
442
|
+
getChangeSetRowDefinitions(row, insertedRowIndex, existingRowIndex, baseNameOmitable = false) {
|
|
443
|
+
return [this.getChangeSetRow(row, insertedRowIndex, existingRowIndex, baseNameOmitable)].filter(Boolean);
|
|
444
|
+
}
|
|
435
445
|
createSelect(options = {}) {
|
|
436
446
|
return null;
|
|
437
447
|
}
|
package/lib/JslGridDisplay.d.ts
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
import { GridDisplay, ChangeCacheFunc, ChangeConfigFunc } from './GridDisplay';
|
|
2
2
|
import { GridConfig, GridCache } from './GridConfig';
|
|
3
|
-
import { EngineDriver } from 'dbgate-types';
|
|
3
|
+
import { DatabaseInfo, EngineDriver } from 'dbgate-types';
|
|
4
4
|
export declare class JslGridDisplay extends GridDisplay {
|
|
5
|
-
|
|
5
|
+
queryResultEditing: boolean;
|
|
6
|
+
private queryResultTableMappings;
|
|
7
|
+
constructor(jslid: any, structure: any, config: GridConfig, setConfig: ChangeConfigFunc, cache: GridCache, setCache: ChangeCacheFunc, rows: any, isDynamicStructure: boolean, supportsReload: boolean, editable?: boolean, driver?: EngineDriver, currentSettings?: any, queryResultEditing?: boolean, dbinfo?: DatabaseInfo);
|
|
8
|
+
private getTableKey;
|
|
9
|
+
private findTable;
|
|
10
|
+
private getEditableQueryResultColumns;
|
|
11
|
+
private hasCompleteQueryResultKey;
|
|
12
|
+
isColumnEditable(uniqueName: string, row?: any): boolean;
|
|
13
|
+
getChangeSetField(row: any, uniqueName: any, insertedRowIndex: any, existingRowIndex?: any, baseNameOmitable?: boolean): import("./ChangeSet").ChangeSetFieldDefinition | {
|
|
14
|
+
pureName: string;
|
|
15
|
+
schemaName: string;
|
|
16
|
+
existingRowIndex: any;
|
|
17
|
+
condition: {};
|
|
18
|
+
uniqueName: any;
|
|
19
|
+
columnName: string;
|
|
20
|
+
};
|
|
21
|
+
getChangeSetRowDefinitions(row: any, insertedRowIndex: any, existingRowIndex: any, baseNameOmitable?: boolean): import("./ChangeSet").ChangeSetRowDefinition[] | {
|
|
22
|
+
pureName: string;
|
|
23
|
+
schemaName: string;
|
|
24
|
+
existingRowIndex: any;
|
|
25
|
+
condition: {};
|
|
26
|
+
}[];
|
|
6
27
|
}
|
package/lib/JslGridDisplay.js
CHANGED
|
@@ -9,17 +9,28 @@ const GridDisplay_1 = require("./GridDisplay");
|
|
|
9
9
|
const CollectionGridDisplay_1 = require("./CollectionGridDisplay");
|
|
10
10
|
const dbgate_tools_1 = require("dbgate-tools");
|
|
11
11
|
class JslGridDisplay extends GridDisplay_1.GridDisplay {
|
|
12
|
-
constructor(jslid, structure, config, setConfig, cache, setCache, rows, isDynamicStructure, supportsReload, editable = false, driver = null, currentSettings = null) {
|
|
12
|
+
constructor(jslid, structure, config, setConfig, cache, setCache, rows, isDynamicStructure, supportsReload, editable = false, driver = null, currentSettings = null, queryResultEditing = false, dbinfo = null) {
|
|
13
13
|
var _a;
|
|
14
|
-
super(config, setConfig, cache, setCache, driver,
|
|
14
|
+
super(config, setConfig, cache, setCache, driver, dbinfo, undefined, currentSettings);
|
|
15
|
+
this.queryResultEditing = queryResultEditing;
|
|
16
|
+
this.queryResultTableMappings = {};
|
|
15
17
|
this.filterable = true;
|
|
16
18
|
this.sortable = true;
|
|
17
19
|
this.supportsReload = supportsReload;
|
|
18
20
|
this.isDynamicStructure = isDynamicStructure;
|
|
19
21
|
this.filterBehaviourOverride = dbgate_tools_1.evalFilterBehaviour;
|
|
20
22
|
this.editable = editable;
|
|
21
|
-
this.editableStructure = editable ? structure : null;
|
|
23
|
+
this.editableStructure = editable && !queryResultEditing ? structure : null;
|
|
24
|
+
if (queryResultEditing) {
|
|
25
|
+
this.allowInsert = false;
|
|
26
|
+
this.allowDelete = false;
|
|
27
|
+
this.allowStructureChange = false;
|
|
28
|
+
this.allowRowDocumentEdit = false;
|
|
29
|
+
}
|
|
22
30
|
if (structure === null || structure === void 0 ? void 0 : structure.columns) {
|
|
31
|
+
const queryResultEditableColumns = queryResultEditing
|
|
32
|
+
? this.getEditableQueryResultColumns(structure.columns, dbinfo)
|
|
33
|
+
: new Set();
|
|
23
34
|
this.columns = lodash_1.default.uniqBy((_a = structure.columns
|
|
24
35
|
.map(col => ({
|
|
25
36
|
columnName: col.columnName,
|
|
@@ -28,8 +39,10 @@ class JslGridDisplay extends GridDisplay_1.GridDisplay {
|
|
|
28
39
|
uniquePath: [col.columnName],
|
|
29
40
|
notNull: col.notNull,
|
|
30
41
|
autoIncrement: col.autoIncrement,
|
|
31
|
-
pureName: null,
|
|
32
|
-
schemaName: null,
|
|
42
|
+
pureName: queryResultEditing ? col.tableName : null,
|
|
43
|
+
schemaName: queryResultEditing ? col.tableSchema : null,
|
|
44
|
+
sourceColumnName: col.sourceColumnName,
|
|
45
|
+
queryResultEditable: queryResultEditableColumns.has(col.columnName),
|
|
33
46
|
}))) === null || _a === void 0 ? void 0 : _a.map(col => (Object.assign(Object.assign({}, col), { isChecked: this.isColumnChecked(col) }))), col => col.uniqueName);
|
|
34
47
|
}
|
|
35
48
|
if (structure === null || structure === void 0 ? void 0 : structure.__isDynamicStructure) {
|
|
@@ -37,7 +50,118 @@ class JslGridDisplay extends GridDisplay_1.GridDisplay {
|
|
|
37
50
|
}
|
|
38
51
|
if (!this.columns)
|
|
39
52
|
this.columns = [];
|
|
53
|
+
if (queryResultEditing) {
|
|
54
|
+
this.editable = this.columns.some(col => col.queryResultEditable);
|
|
55
|
+
}
|
|
40
56
|
this.formColumns = this.columns;
|
|
41
57
|
}
|
|
58
|
+
getTableKey(schemaName, pureName) {
|
|
59
|
+
return `${schemaName || ''}\n${pureName}`;
|
|
60
|
+
}
|
|
61
|
+
findTable(dbinfo, schemaName, pureName) {
|
|
62
|
+
if (!(dbinfo === null || dbinfo === void 0 ? void 0 : dbinfo.tables))
|
|
63
|
+
return null;
|
|
64
|
+
if (schemaName) {
|
|
65
|
+
return dbinfo.tables.find(table => table.schemaName == schemaName && table.pureName == pureName);
|
|
66
|
+
}
|
|
67
|
+
const tables = dbinfo.tables.filter(table => table.pureName == pureName);
|
|
68
|
+
return tables.length == 1 ? tables[0] : null;
|
|
69
|
+
}
|
|
70
|
+
getEditableQueryResultColumns(columns, dbinfo) {
|
|
71
|
+
var _a, _b;
|
|
72
|
+
const res = new Set();
|
|
73
|
+
const groups = lodash_1.default.groupBy(columns.filter(column => column.tableName && column.sourceColumnName), column => this.getTableKey(column.tableSchema, column.tableName));
|
|
74
|
+
for (const groupColumns of Object.values(groups)) {
|
|
75
|
+
const firstColumn = groupColumns[0];
|
|
76
|
+
const table = this.findTable(dbinfo, firstColumn.tableSchema, firstColumn.tableName);
|
|
77
|
+
const sourceToDisplay = new Map(groupColumns.map(column => [column.sourceColumnName, column.columnName]));
|
|
78
|
+
const primaryKeyColumns = ((_b = (_a = table === null || table === void 0 ? void 0 : table.primaryKey) === null || _a === void 0 ? void 0 : _a.columns) === null || _b === void 0 ? void 0 : _b.map(column => column.columnName)) ||
|
|
79
|
+
groupColumns.filter(column => column.isPrimaryKey).map(column => column.sourceColumnName);
|
|
80
|
+
const keyColumns = primaryKeyColumns.length > 0 && primaryKeyColumns.every(columnName => sourceToDisplay.has(columnName))
|
|
81
|
+
? primaryKeyColumns
|
|
82
|
+
: [];
|
|
83
|
+
if (keyColumns.length == 0)
|
|
84
|
+
continue;
|
|
85
|
+
const mapping = {
|
|
86
|
+
pureName: firstColumn.tableName,
|
|
87
|
+
schemaName: firstColumn.tableSchema,
|
|
88
|
+
keyColumns,
|
|
89
|
+
keyDisplayColumns: keyColumns.map(sourceColumnName => ({
|
|
90
|
+
sourceColumnName,
|
|
91
|
+
displayName: sourceToDisplay.get(sourceColumnName),
|
|
92
|
+
})),
|
|
93
|
+
};
|
|
94
|
+
this.queryResultTableMappings[this.getTableKey(firstColumn.tableSchema, firstColumn.tableName)] = mapping;
|
|
95
|
+
for (const column of groupColumns) {
|
|
96
|
+
res.add(column.columnName);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return res;
|
|
100
|
+
}
|
|
101
|
+
hasCompleteQueryResultKey(mapping, row) {
|
|
102
|
+
return mapping.keyDisplayColumns.every(keyColumn => {
|
|
103
|
+
const value = row === null || row === void 0 ? void 0 : row[keyColumn.displayName];
|
|
104
|
+
return value !== null && value !== undefined;
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
isColumnEditable(uniqueName, row) {
|
|
108
|
+
if (!this.queryResultEditing)
|
|
109
|
+
return super.isColumnEditable(uniqueName, row);
|
|
110
|
+
const col = this.columns.find(column => column.uniqueName == uniqueName);
|
|
111
|
+
if (!(col === null || col === void 0 ? void 0 : col.queryResultEditable))
|
|
112
|
+
return false;
|
|
113
|
+
const mapping = this.queryResultTableMappings[this.getTableKey(col.schemaName, col.pureName)];
|
|
114
|
+
return !!mapping && this.hasCompleteQueryResultKey(mapping, row);
|
|
115
|
+
}
|
|
116
|
+
getChangeSetField(row, uniqueName, insertedRowIndex, existingRowIndex = null, baseNameOmitable = false) {
|
|
117
|
+
if (!this.queryResultEditing) {
|
|
118
|
+
return super.getChangeSetField(row, uniqueName, insertedRowIndex, existingRowIndex, baseNameOmitable);
|
|
119
|
+
}
|
|
120
|
+
if (insertedRowIndex != null || !this.isColumnEditable(uniqueName, row))
|
|
121
|
+
return null;
|
|
122
|
+
const col = this.columns.find(column => column.uniqueName == uniqueName);
|
|
123
|
+
if (!col)
|
|
124
|
+
return null;
|
|
125
|
+
const mapping = this.queryResultTableMappings[this.getTableKey(col.schemaName, col.pureName)];
|
|
126
|
+
if (!mapping)
|
|
127
|
+
return null;
|
|
128
|
+
if (!this.hasCompleteQueryResultKey(mapping, row))
|
|
129
|
+
return null;
|
|
130
|
+
const condition = {};
|
|
131
|
+
for (const keyColumn of mapping.keyDisplayColumns) {
|
|
132
|
+
condition[keyColumn.sourceColumnName] = row === null || row === void 0 ? void 0 : row[keyColumn.displayName];
|
|
133
|
+
}
|
|
134
|
+
if (lodash_1.default.isEmpty(condition))
|
|
135
|
+
return null;
|
|
136
|
+
return {
|
|
137
|
+
pureName: mapping.pureName,
|
|
138
|
+
schemaName: mapping.schemaName,
|
|
139
|
+
existingRowIndex,
|
|
140
|
+
condition,
|
|
141
|
+
uniqueName,
|
|
142
|
+
columnName: col.sourceColumnName,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
getChangeSetRowDefinitions(row, insertedRowIndex, existingRowIndex, baseNameOmitable = false) {
|
|
146
|
+
if (!this.queryResultEditing) {
|
|
147
|
+
return super.getChangeSetRowDefinitions(row, insertedRowIndex, existingRowIndex, baseNameOmitable);
|
|
148
|
+
}
|
|
149
|
+
if (insertedRowIndex != null)
|
|
150
|
+
return [];
|
|
151
|
+
return Object.values(this.queryResultTableMappings)
|
|
152
|
+
.filter(mapping => this.hasCompleteQueryResultKey(mapping, row))
|
|
153
|
+
.map(mapping => {
|
|
154
|
+
const condition = {};
|
|
155
|
+
for (const keyColumn of mapping.keyDisplayColumns) {
|
|
156
|
+
condition[keyColumn.sourceColumnName] = row === null || row === void 0 ? void 0 : row[keyColumn.displayName];
|
|
157
|
+
}
|
|
158
|
+
return {
|
|
159
|
+
pureName: mapping.pureName,
|
|
160
|
+
schemaName: mapping.schemaName,
|
|
161
|
+
existingRowIndex,
|
|
162
|
+
condition,
|
|
163
|
+
};
|
|
164
|
+
});
|
|
165
|
+
}
|
|
42
166
|
}
|
|
43
167
|
exports.JslGridDisplay = JslGridDisplay;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createQueryResultSaveChangeSet = void 0;
|
|
7
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
+
const ChangeSet_1 = require("./ChangeSet");
|
|
9
|
+
function createQueryResultSaveChangeSet(changeSet, structure) {
|
|
10
|
+
const res = (0, ChangeSet_1.createChangeSet)();
|
|
11
|
+
const columnMap = lodash_1.default.keyBy(((structure === null || structure === void 0 ? void 0 : structure.columns) || []).filter(column => column.tableName && column.sourceColumnName), 'columnName');
|
|
12
|
+
res.updates = ((changeSet === null || changeSet === void 0 ? void 0 : changeSet.updates) || [])
|
|
13
|
+
.map(update => {
|
|
14
|
+
const fields = {};
|
|
15
|
+
for (const fieldName of Object.keys(update.fields || {})) {
|
|
16
|
+
const column = columnMap[fieldName];
|
|
17
|
+
if (!column)
|
|
18
|
+
continue;
|
|
19
|
+
fields[column.sourceColumnName] = update.fields[fieldName];
|
|
20
|
+
}
|
|
21
|
+
if (lodash_1.default.isEmpty(fields))
|
|
22
|
+
return null;
|
|
23
|
+
return {
|
|
24
|
+
pureName: update.pureName,
|
|
25
|
+
schemaName: update.schemaName,
|
|
26
|
+
condition: update.condition,
|
|
27
|
+
fields,
|
|
28
|
+
};
|
|
29
|
+
})
|
|
30
|
+
.filter(Boolean);
|
|
31
|
+
return res;
|
|
32
|
+
}
|
|
33
|
+
exports.createQueryResultSaveChangeSet = createQueryResultSaveChangeSet;
|
package/lib/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from './PerspectiveTreeNode';
|
|
|
5
5
|
export * from './TableGridDisplay';
|
|
6
6
|
export * from './ViewGridDisplay';
|
|
7
7
|
export * from './JslGridDisplay';
|
|
8
|
+
export * from './QueryResultChangeSet';
|
|
8
9
|
export * from './ChangeSet';
|
|
9
10
|
export * from './MacroDefinition';
|
|
10
11
|
export * from './runMacro';
|
package/lib/index.js
CHANGED
|
@@ -21,6 +21,7 @@ __exportStar(require("./PerspectiveTreeNode"), exports);
|
|
|
21
21
|
__exportStar(require("./TableGridDisplay"), exports);
|
|
22
22
|
__exportStar(require("./ViewGridDisplay"), exports);
|
|
23
23
|
__exportStar(require("./JslGridDisplay"), exports);
|
|
24
|
+
__exportStar(require("./QueryResultChangeSet"), exports);
|
|
24
25
|
__exportStar(require("./ChangeSet"), exports);
|
|
25
26
|
__exportStar(require("./MacroDefinition"), exports);
|
|
26
27
|
__exportStar(require("./runMacro"), exports);
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "7.
|
|
2
|
+
"version": "7.2.0",
|
|
3
3
|
"name": "dbgate-datalib",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"typings": "lib/index.d.ts",
|
|
@@ -19,14 +19,14 @@
|
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"date-fns": "^4.1.0",
|
|
22
|
-
"dbgate-filterparser": "7.
|
|
23
|
-
"dbgate-sqltree": "7.
|
|
24
|
-
"dbgate-tools": "7.
|
|
22
|
+
"dbgate-filterparser": "7.2.0",
|
|
23
|
+
"dbgate-sqltree": "7.2.0",
|
|
24
|
+
"dbgate-tools": "7.2.0",
|
|
25
25
|
"uuid": "^3.4.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/node": "^13.7.0",
|
|
29
|
-
"dbgate-types": "7.
|
|
29
|
+
"dbgate-types": "7.2.0",
|
|
30
30
|
"jest": "^28.1.3",
|
|
31
31
|
"ts-jest": "^28.0.7",
|
|
32
32
|
"typescript": "^4.4.3"
|