dbgate-tools 5.3.4 → 5.4.1

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.
@@ -111,5 +111,5 @@ export declare class SqlDumper implements AlterProcessor {
111
111
  createSqlObject(obj: SqlObjectInfo): void;
112
112
  getSqlObjectSqlName(ojectTypeField: string): "PROCEDURE" | "VIEW" | "FUNCTION" | "TRIGGER" | "MATERIALIZED VIEW";
113
113
  dropSqlObject(obj: SqlObjectInfo): void;
114
- fillPreloadedRows(table: NamedObjectInfo, oldRows: any[], newRows: any[], key: string[], insertOnly: string[]): void;
114
+ fillPreloadedRows(table: NamedObjectInfo, oldRows: any[], newRows: any[], key: string[], insertOnly: string[], autoIncrementColumn: string): void;
115
115
  }
package/lib/SqlDumper.js CHANGED
@@ -125,11 +125,29 @@ class SqlDumper {
125
125
  i++;
126
126
  switch (c) {
127
127
  case '^':
128
+ if (format[i] == '^') {
129
+ this.putRaw('^');
130
+ i++;
131
+ break;
132
+ }
128
133
  while (i < length && format[i].match(/[a-z0-9_]/i)) {
129
134
  this.putRaw(SqlDumper.convertKeywordCase(format[i]));
130
135
  i++;
131
136
  }
132
137
  break;
138
+ case '~':
139
+ if (format[i] == '~') {
140
+ this.putRaw('~');
141
+ i++;
142
+ break;
143
+ }
144
+ let ident = '';
145
+ while (i < length && format[i].match(/[a-z0-9_]/i)) {
146
+ ident += format[i];
147
+ i++;
148
+ }
149
+ this.putRaw(this.dialect.quoteIdentifier(ident));
150
+ break;
133
151
  case '%':
134
152
  c = format[i];
135
153
  i++;
@@ -571,7 +589,7 @@ class SqlDumper {
571
589
  dropSqlObject(obj) {
572
590
  this.putCmd('^drop %s %f', this.getSqlObjectSqlName(obj.objectTypeField), obj);
573
591
  }
574
- fillPreloadedRows(table, oldRows, newRows, key, insertOnly) {
592
+ fillPreloadedRows(table, oldRows, newRows, key, insertOnly, autoIncrementColumn) {
575
593
  let was = false;
576
594
  for (const row of newRows) {
577
595
  const old = oldRows === null || oldRows === void 0 ? void 0 : oldRows.find(r => key.every(col => r[col] == row[col]));
@@ -597,7 +615,12 @@ class SqlDumper {
597
615
  if (was)
598
616
  this.put(';\n');
599
617
  was = true;
618
+ const autoinc = rowKeys.includes(autoIncrementColumn);
619
+ if (autoinc)
620
+ this.allowIdentityInsert(table, true);
600
621
  this.put('^insert ^into %f (%,i) ^values (%,v)', table, rowKeys, rowKeys.map(x => row[x]));
622
+ if (autoinc)
623
+ this.allowIdentityInsert(table, false);
601
624
  }
602
625
  }
603
626
  if (was) {
@@ -69,6 +69,7 @@ interface AlterOperation_FillPreloadedRows {
69
69
  newRows: any[];
70
70
  key: string[];
71
71
  insertOnly: string[];
72
+ autoIncrementColumn: string;
72
73
  }
73
74
  type AlterOperation = AlterOperation_CreateColumn | AlterOperation_ChangeColumn | AlterOperation_DropColumn | AlterOperation_CreateConstraint | AlterOperation_ChangeConstraint | AlterOperation_DropConstraint | AlterOperation_CreateTable | AlterOperation_DropTable | AlterOperation_RenameTable | AlterOperation_RenameColumn | AlterOperation_RenameConstraint | AlterOperation_CreateSqlObject | AlterOperation_DropSqlObject | AlterOperation_RecreateTable | AlterOperation_FillPreloadedRows;
74
75
  export declare class AlterPlan {
@@ -97,7 +98,7 @@ export declare class AlterPlan {
97
98
  renameColumn(column: ColumnInfo, newName: string): void;
98
99
  renameConstraint(constraint: ConstraintInfo, newName: string): void;
99
100
  recreateTable(table: TableInfo, operations: AlterOperation[]): void;
100
- fillPreloadedRows(table: NamedObjectInfo, oldRows: any[], newRows: any[], key: string[], insertOnly: string[]): void;
101
+ fillPreloadedRows(table: NamedObjectInfo, oldRows: any[], newRows: any[], key: string[], insertOnly: string[], autoIncrementColumn: string): void;
101
102
  run(processor: AlterProcessor): void;
102
103
  _getDependendColumnConstraints(column: ColumnInfo, dependencyDefinition: any): import("dbgate-types/dbinfo").PrimaryKeyInfo[];
103
104
  _addLogicalDependencies(): AlterOperation[];
package/lib/alterPlan.js CHANGED
@@ -112,7 +112,7 @@ class AlterPlan {
112
112
  });
113
113
  this.recreates.tables += 1;
114
114
  }
115
- fillPreloadedRows(table, oldRows, newRows, key, insertOnly) {
115
+ fillPreloadedRows(table, oldRows, newRows, key, insertOnly, autoIncrementColumn) {
116
116
  this.operations.push({
117
117
  operationType: 'fillPreloadedRows',
118
118
  table,
@@ -120,6 +120,7 @@ class AlterPlan {
120
120
  newRows,
121
121
  key,
122
122
  insertOnly,
123
+ autoIncrementColumn,
123
124
  });
124
125
  }
125
126
  run(processor) {
@@ -408,7 +409,7 @@ function runAlterOperation(op, processor) {
408
409
  processor.dropSqlObject(op.oldObject);
409
410
  break;
410
411
  case 'fillPreloadedRows':
411
- processor.fillPreloadedRows(op.table, op.oldRows, op.newRows, op.key, op.insertOnly);
412
+ processor.fillPreloadedRows(op.table, op.oldRows, op.newRows, op.key, op.insertOnly, op.autoIncrementColumn);
412
413
  break;
413
414
  case 'recreateTable':
414
415
  {
@@ -16,5 +16,5 @@ export declare class DatabaseInfoAlterProcessor {
16
16
  renameColumn(column: ColumnInfo, newName: string): void;
17
17
  renameConstraint(constraint: ConstraintInfo, newName: string): void;
18
18
  recreateTable(oldTable: TableInfo, newTable: TableInfo): void;
19
- fillPreloadedRows(table: NamedObjectInfo, oldRows: any[], newRows: any[], key: string[], insertOnly: string[]): void;
19
+ fillPreloadedRows(table: NamedObjectInfo, oldRows: any[], newRows: any[], key: string[], insertOnly: string[], autoIncrementColumn: string): void;
20
20
  }
@@ -93,7 +93,7 @@ class DatabaseInfoAlterProcessor {
93
93
  recreateTable(oldTable, newTable) {
94
94
  throw new Error('recreateTable not implemented for DatabaseInfoAlterProcessor');
95
95
  }
96
- fillPreloadedRows(table, oldRows, newRows, key, insertOnly) {
96
+ fillPreloadedRows(table, oldRows, newRows, key, insertOnly, autoIncrementColumn) {
97
97
  const tableInfo = this.db.tables.find(x => x.pureName == table.pureName && x.schemaName == table.schemaName);
98
98
  tableInfo.preloadedRows = newRows;
99
99
  tableInfo.preloadedRowsKey = key;
@@ -0,0 +1,2 @@
1
+ import { FilterBehaviour } from 'dbgate-types';
2
+ export declare function detectSqlFilterBehaviour(dataType: string): FilterBehaviour;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.detectSqlFilterBehaviour = void 0;
4
+ const filterBehaviours_1 = require("./filterBehaviours");
5
+ const commonTypeParser_1 = require("./commonTypeParser");
6
+ function detectSqlFilterBehaviour(dataType) {
7
+ if (!dataType)
8
+ return filterBehaviours_1.stringFilterBehaviour;
9
+ if ((0, commonTypeParser_1.isTypeNumber)(dataType))
10
+ return filterBehaviours_1.numberFilterBehaviour;
11
+ if ((0, commonTypeParser_1.isTypeString)(dataType))
12
+ return filterBehaviours_1.stringFilterBehaviour;
13
+ if ((0, commonTypeParser_1.isTypeLogical)(dataType))
14
+ return filterBehaviours_1.logicalFilterBehaviour;
15
+ if ((0, commonTypeParser_1.isTypeDateTime)(dataType))
16
+ return filterBehaviours_1.datetimeFilterBehaviour;
17
+ return filterBehaviours_1.stringFilterBehaviour;
18
+ }
19
+ exports.detectSqlFilterBehaviour = detectSqlFilterBehaviour;
package/lib/diffTools.js CHANGED
@@ -63,6 +63,13 @@ function testEqualFullNames(lft, rgt, opts) {
63
63
  return lft == rgt;
64
64
  return testEqualSchemas(lft.schemaName, rgt.schemaName, opts) && testEqualNames(lft.pureName, rgt.pureName, opts);
65
65
  }
66
+ function testEqualDefaultValues(value1, value2) {
67
+ if (value1 == null)
68
+ return value2 == null || value2 == 'NULL';
69
+ if (value2 == null)
70
+ return value1 == null || value1 == 'NULL';
71
+ return value1 == value2;
72
+ }
66
73
  function testEqualColumns(a, b, checkName, checkDefault, opts = {}) {
67
74
  if (checkName && !testEqualNames(a.columnName, b.columnName, opts)) {
68
75
  // opts.DiffLogger.Trace("Column, different name: {0}; {1}", a, b);
@@ -88,31 +95,16 @@ function testEqualColumns(a, b, checkName, checkDefault, opts = {}) {
88
95
  return true;
89
96
  }
90
97
  if (checkDefault) {
91
- if (a.defaultValue == null) {
92
- if (a.defaultValue != b.defaultValue) {
93
- console.debug(`Column ${a.pureName}.${a.columnName}, ${b.pureName}.${b.columnName}: different default value: ${a.defaultValue}, ${b.defaultValue}`);
94
- // opts.DiffLogger.Trace(
95
- // 'Column {0}, {1}: different default values: {2}; {3}',
96
- // a,
97
- // b,
98
- // a.DefaultValue,
99
- // b.DefaultValue
100
- // );
101
- return false;
102
- }
103
- }
104
- else {
105
- if (a.defaultValue != b.defaultValue) {
106
- console.debug(`Column ${a.pureName}.${a.columnName}, ${b.pureName}.${b.columnName}: different default value: ${a.defaultValue}, ${b.defaultValue}`);
107
- // opts.DiffLogger.Trace(
108
- // 'Column {0}, {1}: different default values: {2}; {3}',
109
- // a,
110
- // b,
111
- // a.DefaultValue,
112
- // b.DefaultValue
113
- // );
114
- return false;
115
- }
98
+ if (!testEqualDefaultValues(a.defaultValue, b.defaultValue)) {
99
+ console.debug(`Column ${a.pureName}.${a.columnName}, ${b.pureName}.${b.columnName}: different default value: ${a.defaultValue}, ${b.defaultValue}`);
100
+ // opts.DiffLogger.Trace(
101
+ // 'Column {0}, {1}: different default values: {2}; {3}',
102
+ // a,
103
+ // b,
104
+ // a.DefaultValue,
105
+ // b.DefaultValue
106
+ // );
107
+ return false;
116
108
  }
117
109
  if (a.defaultConstraint != b.defaultConstraint) {
118
110
  console.debug(`Column ${a.pureName}.${a.columnName}, ${b.pureName}.${b.columnName}: different default constraint: ${a.defaultConstraint}, ${b.defaultConstraint}`);
@@ -254,10 +246,10 @@ function createPairs(oldList, newList, additionalCondition = null) {
254
246
  return res;
255
247
  }
256
248
  function planTablePreload(plan, oldTable, newTable) {
257
- var _a, _b, _c;
249
+ var _a, _b, _c, _d;
258
250
  const key = newTable.preloadedRowsKey || ((_b = (_a = newTable.primaryKey) === null || _a === void 0 ? void 0 : _a.columns) === null || _b === void 0 ? void 0 : _b.map(x => x.columnName));
259
251
  if (((_c = newTable.preloadedRows) === null || _c === void 0 ? void 0 : _c.length) > 0 && (key === null || key === void 0 ? void 0 : key.length) > 0) {
260
- plan.fillPreloadedRows(newTable, oldTable === null || oldTable === void 0 ? void 0 : oldTable.preloadedRows, newTable.preloadedRows, key, newTable.preloadedRowsInsertOnly);
252
+ plan.fillPreloadedRows(newTable, oldTable === null || oldTable === void 0 ? void 0 : oldTable.preloadedRows, newTable.preloadedRows, key, newTable.preloadedRowsInsertOnly, (_d = newTable.columns.find(x => x.autoIncrement)) === null || _d === void 0 ? void 0 : _d.columnName);
261
253
  }
262
254
  }
263
255
  function planAlterTable(plan, oldTable, newTable, opts) {
@@ -26,6 +26,7 @@ export declare const driverBase: {
26
26
  analyseIncremental(pool: any, structure: any, version: any): Promise<any>;
27
27
  createDumper(options?: any): SqlDumper;
28
28
  script(pool: any, sql: any, options: RunScriptOptions): Promise<void>;
29
+ operation(pool: any, operation: any, options: RunScriptOptions): Promise<never>;
29
30
  getNewObjectTemplates(): {
30
31
  label: string;
31
32
  sql: string;
@@ -34,4 +35,14 @@ export declare const driverBase: {
34
35
  readJsonQuery(pool: any, select: any, structure: any): any;
35
36
  showConnectionField: (field: any, values: any) => boolean;
36
37
  showConnectionTab: (field: any) => boolean;
38
+ getAccessTokenFromAuth: (connection: any, req: any) => Promise<any>;
39
+ getFilterBehaviour(dataType: string, standardFilterBehaviours: any): import("dbgate-types").FilterBehaviour;
40
+ getCollectionExportQueryScript(collection: string, condition: any, sort: any): any;
41
+ getCollectionExportQueryJson(collection: string, condition: any, sort: any): any;
42
+ getScriptTemplates(objectTypeField: any): any[];
43
+ getScriptTemplateContent(scriptTemplate: any, props: any): any;
44
+ dataEditorTypesBehaviour: {
45
+ parseSqlNull: boolean;
46
+ parseHexAsBuffer: boolean;
47
+ };
37
48
  };
package/lib/driverBase.js CHANGED
@@ -17,6 +17,7 @@ const compact_1 = __importDefault(require("lodash/compact"));
17
17
  const SqlDumper_1 = require("./SqlDumper");
18
18
  const dbgate_query_splitter_1 = require("dbgate-query-splitter");
19
19
  const dbgate_sqltree_1 = require("dbgate-sqltree");
20
+ const detectSqlFilterBehaviour_1 = require("./detectSqlFilterBehaviour");
20
21
  const dialect = {
21
22
  limitSelect: true,
22
23
  rangeSelect: true,
@@ -101,6 +102,11 @@ exports.driverBase = {
101
102
  }
102
103
  });
103
104
  },
105
+ operation(pool, operation, options) {
106
+ return __awaiter(this, void 0, void 0, function* () {
107
+ throw new Error('Operation not defined in target driver');
108
+ });
109
+ },
104
110
  getNewObjectTemplates() {
105
111
  if (this.databaseEngineTypes.includes('sql')) {
106
112
  return [{ label: 'New view', sql: 'CREATE VIEW myview\nAS\nSELECT * FROM table1' }];
@@ -164,4 +170,24 @@ exports.driverBase = {
164
170
  },
165
171
  showConnectionField: (field, values) => false,
166
172
  showConnectionTab: field => true,
173
+ getAccessTokenFromAuth: (connection, req) => __awaiter(void 0, void 0, void 0, function* () { return null; }),
174
+ getFilterBehaviour(dataType, standardFilterBehaviours) {
175
+ return (0, detectSqlFilterBehaviour_1.detectSqlFilterBehaviour)(dataType);
176
+ },
177
+ getCollectionExportQueryScript(collection, condition, sort) {
178
+ return null;
179
+ },
180
+ getCollectionExportQueryJson(collection, condition, sort) {
181
+ return null;
182
+ },
183
+ getScriptTemplates(objectTypeField) {
184
+ return [];
185
+ },
186
+ getScriptTemplateContent(scriptTemplate, props) {
187
+ return null;
188
+ },
189
+ dataEditorTypesBehaviour: {
190
+ parseSqlNull: true,
191
+ parseHexAsBuffer: true,
192
+ },
167
193
  };
@@ -0,0 +1,10 @@
1
+ import { FilterBehaviour } from 'dbgate-types';
2
+ export declare const numberFilterBehaviour: FilterBehaviour;
3
+ export declare const stringFilterBehaviour: FilterBehaviour;
4
+ export declare const logicalFilterBehaviour: FilterBehaviour;
5
+ export declare const datetimeFilterBehaviour: FilterBehaviour;
6
+ export declare const mongoFilterBehaviour: FilterBehaviour;
7
+ export declare const evalFilterBehaviour: FilterBehaviour;
8
+ export declare const standardFilterBehaviours: {
9
+ [id: string]: FilterBehaviour;
10
+ };
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.standardFilterBehaviours = exports.evalFilterBehaviour = exports.mongoFilterBehaviour = exports.datetimeFilterBehaviour = exports.logicalFilterBehaviour = exports.stringFilterBehaviour = exports.numberFilterBehaviour = void 0;
4
+ exports.numberFilterBehaviour = {
5
+ supportEquals: true,
6
+ supportNumberLikeComparison: true,
7
+ supportNullTesting: true,
8
+ supportSqlCondition: true,
9
+ allowNumberToken: true,
10
+ };
11
+ exports.stringFilterBehaviour = {
12
+ supportEquals: true,
13
+ supportStringInclusion: true,
14
+ supportEmpty: true,
15
+ supportNumberLikeComparison: true,
16
+ supportNullTesting: true,
17
+ supportSqlCondition: true,
18
+ allowStringToken: true,
19
+ allowHexString: true,
20
+ };
21
+ exports.logicalFilterBehaviour = {
22
+ supportBooleanValues: true,
23
+ supportNullTesting: true,
24
+ supportSqlCondition: true,
25
+ };
26
+ exports.datetimeFilterBehaviour = {
27
+ supportNullTesting: true,
28
+ supportSqlCondition: true,
29
+ supportDatetimeSymbols: true,
30
+ supportDatetimeComparison: true,
31
+ };
32
+ exports.mongoFilterBehaviour = {
33
+ supportEquals: true,
34
+ supportArrayTesting: true,
35
+ supportNumberLikeComparison: true,
36
+ supportStringInclusion: true,
37
+ supportBooleanValues: true,
38
+ supportExistsTesting: true,
39
+ allowStringToken: true,
40
+ allowNumberDualTesting: true,
41
+ allowObjectIdTesting: true,
42
+ };
43
+ exports.evalFilterBehaviour = {
44
+ supportEquals: true,
45
+ supportStringInclusion: true,
46
+ supportEmpty: true,
47
+ supportNumberLikeComparison: true,
48
+ supportNullTesting: true,
49
+ allowStringToken: true,
50
+ };
51
+ exports.standardFilterBehaviours = {
52
+ numberFilterBehaviour: exports.numberFilterBehaviour,
53
+ stringFilterBehaviour: exports.stringFilterBehaviour,
54
+ logicalFilterBehaviour: exports.logicalFilterBehaviour,
55
+ datetimeFilterBehaviour: exports.datetimeFilterBehaviour,
56
+ mongoFilterBehaviour: exports.mongoFilterBehaviour,
57
+ evalFilterBehaviour: exports.evalFilterBehaviour,
58
+ };
@@ -0,0 +1,5 @@
1
+ export declare function getDatabaseFileLabel(databaseFile: any): any;
2
+ export declare function getConnectionLabel(connection: any, { allowExplicitDatabase, showUnsaved }?: {
3
+ allowExplicitDatabase?: boolean;
4
+ showUnsaved?: boolean;
5
+ }): any;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getConnectionLabel = exports.getDatabaseFileLabel = void 0;
4
+ function getDatabaseFileLabel(databaseFile) {
5
+ if (!databaseFile)
6
+ return databaseFile;
7
+ const m = databaseFile.match(/[\/]([^\/]+)$/);
8
+ if (m)
9
+ return m[1];
10
+ return databaseFile;
11
+ }
12
+ exports.getDatabaseFileLabel = getDatabaseFileLabel;
13
+ function getConnectionLabelCore(connection, { allowExplicitDatabase = true } = {}) {
14
+ if (!connection) {
15
+ return null;
16
+ }
17
+ if (connection.displayName) {
18
+ return connection.displayName;
19
+ }
20
+ if (connection.useDatabaseUrl) {
21
+ return `${connection.databaseUrl}`;
22
+ }
23
+ if (connection.singleDatabase && connection.server && allowExplicitDatabase && connection.defaultDatabase) {
24
+ return `${connection.defaultDatabase} on ${connection.server}`;
25
+ }
26
+ if (connection.databaseFile) {
27
+ return getDatabaseFileLabel(connection.databaseFile);
28
+ }
29
+ if (connection.server) {
30
+ return connection.server;
31
+ }
32
+ if (connection.singleDatabase && connection.defaultDatabase) {
33
+ return `${connection.defaultDatabase}`;
34
+ }
35
+ return '';
36
+ }
37
+ function getConnectionLabel(connection, { allowExplicitDatabase = true, showUnsaved = false } = {}) {
38
+ const res = getConnectionLabelCore(connection, { allowExplicitDatabase });
39
+ if (res && showUnsaved && (connection === null || connection === void 0 ? void 0 : connection.unsaved)) {
40
+ return `${res} - unsaved`;
41
+ }
42
+ return res;
43
+ }
44
+ exports.getConnectionLabel = getConnectionLabel;
package/lib/index.d.ts CHANGED
@@ -20,3 +20,6 @@ export * from './computeDiffRows';
20
20
  export * from './preloadedRowsTools';
21
21
  export * from './ScriptWriter';
22
22
  export * from './getLogger';
23
+ export * from './getConnectionLabel';
24
+ export * from './detectSqlFilterBehaviour';
25
+ export * from './filterBehaviours';
package/lib/index.js CHANGED
@@ -36,3 +36,6 @@ __exportStar(require("./computeDiffRows"), exports);
36
36
  __exportStar(require("./preloadedRowsTools"), exports);
37
37
  __exportStar(require("./ScriptWriter"), exports);
38
38
  __exportStar(require("./getLogger"), exports);
39
+ __exportStar(require("./getConnectionLabel"), exports);
40
+ __exportStar(require("./detectSqlFilterBehaviour"), exports);
41
+ __exportStar(require("./filterBehaviours"), exports);
@@ -20,7 +20,7 @@ export declare function equalFullName(name1: NamedObjectInfo, name2: NamedObject
20
20
  export declare function findObjectLike({ pureName, schemaName }: {
21
21
  pureName: any;
22
22
  schemaName: any;
23
- }, dbinfo: DatabaseInfo, objectTypeField: keyof DatabaseInfoObjects): import("dbgate-types").CollectionInfo;
23
+ }, dbinfo: DatabaseInfo, objectTypeField: keyof DatabaseInfoObjects): any;
24
24
  export declare function findForeignKeyForColumn(table: TableInfo, column: ColumnInfo | string): import("dbgate-types").ForeignKeyInfo;
25
25
  export declare function makeUniqueColumnNames(res: ColumnInfo[]): void;
26
26
  export declare function fillConstraintNames(table: TableInfo, dialect: SqlDialect): TableInfo;
@@ -1,11 +1,26 @@
1
+ import { DataEditorTypesBehaviour } from 'dbgate-types';
2
+ export type EditorDataType = 'null' | 'objectid' | 'string' | 'number' | 'object' | 'date' | 'array' | 'boolean' | 'unknown';
1
3
  export declare function arrayToHexString(byteArray: any): any;
2
4
  export declare function hexStringToArray(inputString: any): any[];
3
- export declare function parseCellValue(value: any): any;
4
- export declare function stringifyCellValue(value: any): any;
5
+ export declare function parseCellValue(value: any, editorTypes?: DataEditorTypesBehaviour): any;
6
+ export declare function stringifyCellValue(value: any, intent: 'gridCellIntent' | 'inlineEditorIntent' | 'multilineEditorIntent' | 'stringConversionIntent' | 'exportIntent', editorTypes?: DataEditorTypesBehaviour, gridFormattingOptions?: {
7
+ useThousandsSeparator?: boolean;
8
+ }, jsonParsedValue?: any): {
9
+ value: string;
10
+ gridStyle?: 'textCellStyle' | 'valueCellStyle' | 'nullCellStyle';
11
+ gridTitle?: string;
12
+ };
5
13
  export declare function safeJsonParse(json: any, defaultValue?: any, logError?: boolean): any;
14
+ export declare function shouldOpenMultilineDialog(value: any): boolean;
6
15
  export declare function isJsonLikeLongString(value: any): RegExpMatchArray;
7
16
  export declare function getIconForRedisType(type: any): "img folder" | "img type-string" | "img type-hash" | "img type-set" | "img type-list" | "img type-zset" | "img type-stream" | "img type-binary" | "img type-rejson";
8
17
  export declare function isWktGeometry(s: any): boolean;
9
18
  export declare function arrayBufferToBase64(buffer: any): string;
10
19
  export declare function getAsImageSrc(obj: any): string;
11
20
  export declare function parseSqlDefaultValue(value: string): string | number;
21
+ export declare function detectCellDataType(value: any): EditorDataType;
22
+ export declare function detectTypeIcon(value: any): "icon type-null" | "icon type-objectid" | "icon type-date" | "icon type-string" | "icon type-number" | "icon type-object" | "icon type-array" | "icon type-boolean" | "icon type-unknown";
23
+ export declare function getConvertValueMenu(value: any, onSetValue: any, editorTypes?: DataEditorTypesBehaviour): {
24
+ text: string;
25
+ onClick: () => any;
26
+ }[];
@@ -3,10 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.parseSqlDefaultValue = exports.getAsImageSrc = exports.arrayBufferToBase64 = exports.isWktGeometry = exports.getIconForRedisType = exports.isJsonLikeLongString = exports.safeJsonParse = exports.stringifyCellValue = exports.parseCellValue = exports.hexStringToArray = exports.arrayToHexString = void 0;
6
+ exports.getConvertValueMenu = exports.detectTypeIcon = exports.detectCellDataType = exports.parseSqlDefaultValue = exports.getAsImageSrc = exports.arrayBufferToBase64 = exports.isWktGeometry = exports.getIconForRedisType = exports.isJsonLikeLongString = exports.shouldOpenMultilineDialog = exports.safeJsonParse = exports.stringifyCellValue = exports.parseCellValue = exports.hexStringToArray = exports.arrayToHexString = void 0;
7
7
  const isString_1 = __importDefault(require("lodash/isString"));
8
8
  const isArray_1 = __importDefault(require("lodash/isArray"));
9
+ const isNumber_1 = __importDefault(require("lodash/isNumber"));
9
10
  const isPlainObject_1 = __importDefault(require("lodash/isPlainObject"));
11
+ const pad_1 = __importDefault(require("lodash/pad"));
12
+ const dateTimeStorageRegex = /^([0-9]+)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])[Tt]([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?(([Zz])|()|([\+|\-]([01][0-9]|2[0-3]):[0-5][0-9]))$/;
13
+ const dateTimeParseRegex = /^(\d{4})-(\d{2})-(\d{2})[Tt ](\d{2}):(\d{2}):(\d{2})(\.[0-9]+)?(([Zz])|()|([\+|\-]([01][0-9]|2[0-3]):[0-5][0-9]))$/;
10
14
  function arrayToHexString(byteArray) {
11
15
  return byteArray.reduce((output, elem) => output + ('0' + elem.toString(16)).slice(-2), '').toUpperCase();
12
16
  }
@@ -20,38 +24,247 @@ function hexStringToArray(inputString) {
20
24
  return res;
21
25
  }
22
26
  exports.hexStringToArray = hexStringToArray;
23
- function parseCellValue(value) {
27
+ function parseCellValue(value, editorTypes) {
24
28
  if (!(0, isString_1.default)(value))
25
29
  return value;
26
- if (value == '(NULL)')
27
- return null;
28
- const mHex = value.match(/^0x([0-9a-fA-F][0-9a-fA-F])+$/);
29
- if (mHex) {
30
- return {
31
- type: 'Buffer',
32
- data: hexStringToArray(value.substring(2)),
33
- };
30
+ if (editorTypes === null || editorTypes === void 0 ? void 0 : editorTypes.parseSqlNull) {
31
+ if (value == '(NULL)')
32
+ return null;
33
+ }
34
+ if (editorTypes === null || editorTypes === void 0 ? void 0 : editorTypes.parseHexAsBuffer) {
35
+ const mHex = value.match(/^0x([0-9a-fA-F][0-9a-fA-F])+$/);
36
+ if (mHex) {
37
+ return {
38
+ type: 'Buffer',
39
+ data: hexStringToArray(value.substring(2)),
40
+ };
41
+ }
34
42
  }
35
- const mOid = value.match(/^ObjectId\("([0-9a-f]{24})"\)$/);
36
- if (mOid) {
37
- return { $oid: mOid[1] };
43
+ if (editorTypes === null || editorTypes === void 0 ? void 0 : editorTypes.parseObjectIdAsDollar) {
44
+ const mOid = value.match(/^ObjectId\("([0-9a-f]{24})"\)$/);
45
+ if (mOid) {
46
+ return { $oid: mOid[1] };
47
+ }
48
+ }
49
+ if (editorTypes === null || editorTypes === void 0 ? void 0 : editorTypes.parseDateAsDollar) {
50
+ const m = value.match(dateTimeParseRegex);
51
+ if (m) {
52
+ return {
53
+ $date: `${m[1]}-${m[2]}-${m[3]}T${m[4]}:${m[5]}:${m[6]}Z`,
54
+ };
55
+ }
56
+ }
57
+ if (editorTypes === null || editorTypes === void 0 ? void 0 : editorTypes.parseJsonNull) {
58
+ if (value == 'null')
59
+ return null;
60
+ }
61
+ if (editorTypes === null || editorTypes === void 0 ? void 0 : editorTypes.parseJsonBoolean) {
62
+ if (value == 'true')
63
+ return true;
64
+ if (value == 'false')
65
+ return false;
66
+ }
67
+ if (editorTypes === null || editorTypes === void 0 ? void 0 : editorTypes.parseNumber) {
68
+ if (/^-?[0-9]+(?:\.[0-9]+)?$/.test(value)) {
69
+ return parseFloat(value);
70
+ }
71
+ }
72
+ if ((editorTypes === null || editorTypes === void 0 ? void 0 : editorTypes.parseJsonArray) || (editorTypes === null || editorTypes === void 0 ? void 0 : editorTypes.parseJsonObject)) {
73
+ const jsonValue = safeJsonParse(value);
74
+ if ((0, isPlainObject_1.default)(jsonValue) && (editorTypes === null || editorTypes === void 0 ? void 0 : editorTypes.parseJsonObject))
75
+ return jsonValue;
76
+ if ((0, isArray_1.default)(jsonValue) && (editorTypes === null || editorTypes === void 0 ? void 0 : editorTypes.parseJsonArray))
77
+ return jsonValue;
38
78
  }
39
79
  return value;
40
80
  }
41
81
  exports.parseCellValue = parseCellValue;
42
- function stringifyCellValue(value) {
43
- if (value === null)
44
- return '(NULL)';
45
- if (value === undefined)
46
- return '(NoField)';
47
- if ((value === null || value === void 0 ? void 0 : value.type) == 'Buffer' && (0, isArray_1.default)(value.data))
48
- return '0x' + arrayToHexString(value.data);
82
+ function parseFunc_ObjectIdAsDollar(value) {
49
83
  if (value === null || value === void 0 ? void 0 : value.$oid)
50
- return `ObjectId("${value === null || value === void 0 ? void 0 : value.$oid}")`;
51
- if ((0, isPlainObject_1.default)(value) || (0, isArray_1.default)(value))
52
- return JSON.stringify(value);
84
+ return value;
85
+ if ((0, isString_1.default)(value)) {
86
+ if (value.match(/^[0-9a-f]{24}$/))
87
+ return { $oid: value };
88
+ const mOid = value.match(/^ObjectId\("([0-9a-f]{24})"\)$/);
89
+ if (mOid) {
90
+ return { $oid: mOid[1] };
91
+ }
92
+ }
93
+ return value;
94
+ }
95
+ function parseFunc_DateAsDollar(value) {
96
+ if (value === null || value === void 0 ? void 0 : value.$date)
97
+ return value;
98
+ if ((0, isString_1.default)(value)) {
99
+ const m = value.match(dateTimeParseRegex);
100
+ if (m) {
101
+ return { $date: `${m[1]}-${m[2]}-${m[3]}T${m[4]}:${m[5]}:${m[6]}Z` };
102
+ }
103
+ }
104
+ return value;
105
+ }
106
+ function makeBulletString(value) {
107
+ return (0, pad_1.default)('', value.length, '•');
108
+ }
109
+ function highlightSpecialCharacters(value) {
110
+ value = value.replace(/\n/g, '↲');
111
+ value = value.replace(/\r/g, '');
112
+ value = value.replace(/^(\s+)/, makeBulletString);
113
+ value = value.replace(/(\s+)$/, makeBulletString);
114
+ value = value.replace(/(\s\s+)/g, makeBulletString);
53
115
  return value;
54
116
  }
117
+ function stringifyJsonToGrid(value) {
118
+ if ((0, isPlainObject_1.default)(value)) {
119
+ const svalue = JSON.stringify(value, undefined, 2);
120
+ if (svalue.length < 100) {
121
+ return { value: svalue, gridStyle: 'nullCellStyle' };
122
+ }
123
+ else {
124
+ return { value: '(JSON)', gridStyle: 'nullCellStyle', gridTitle: svalue };
125
+ }
126
+ }
127
+ if ((0, isArray_1.default)(value)) {
128
+ return {
129
+ value: `[${value.length} items]`,
130
+ gridStyle: 'nullCellStyle',
131
+ gridTitle: value.map(x => JSON.stringify(x)).join('\n'),
132
+ };
133
+ }
134
+ return { value: '(JSON)', gridStyle: 'nullCellStyle' };
135
+ }
136
+ function stringifyCellValue(value, intent, editorTypes, gridFormattingOptions, jsonParsedValue) {
137
+ if (editorTypes === null || editorTypes === void 0 ? void 0 : editorTypes.parseSqlNull) {
138
+ if (value === null) {
139
+ switch (intent) {
140
+ case 'exportIntent':
141
+ return { value: '' };
142
+ default:
143
+ return { value: '(NULL)', gridStyle: 'nullCellStyle' };
144
+ }
145
+ }
146
+ }
147
+ if (value === undefined) {
148
+ switch (intent) {
149
+ case 'gridCellIntent':
150
+ return { value: '(No Field)', gridStyle: 'nullCellStyle' };
151
+ default:
152
+ return { value: '' };
153
+ }
154
+ }
155
+ if (editorTypes === null || editorTypes === void 0 ? void 0 : editorTypes.parseJsonNull) {
156
+ if (value === null) {
157
+ return { value: 'null', gridStyle: 'valueCellStyle' };
158
+ }
159
+ }
160
+ if (value === true)
161
+ return { value: 'true', gridStyle: 'valueCellStyle' };
162
+ if (value === false)
163
+ return { value: 'false', gridStyle: 'valueCellStyle' };
164
+ if (editorTypes === null || editorTypes === void 0 ? void 0 : editorTypes.parseHexAsBuffer) {
165
+ if ((value === null || value === void 0 ? void 0 : value.type) == 'Buffer' && (0, isArray_1.default)(value.data)) {
166
+ return { value: '0x' + arrayToHexString(value.data), gridStyle: 'valueCellStyle' };
167
+ }
168
+ }
169
+ if (editorTypes === null || editorTypes === void 0 ? void 0 : editorTypes.parseObjectIdAsDollar) {
170
+ if (value === null || value === void 0 ? void 0 : value.$oid) {
171
+ switch (intent) {
172
+ case 'exportIntent':
173
+ case 'stringConversionIntent':
174
+ return { value: value.$oid };
175
+ default:
176
+ return { value: `ObjectId("${value.$oid}")`, gridStyle: 'valueCellStyle' };
177
+ }
178
+ }
179
+ }
180
+ if (editorTypes === null || editorTypes === void 0 ? void 0 : editorTypes.parseDateAsDollar) {
181
+ if (value === null || value === void 0 ? void 0 : value.$date) {
182
+ switch (intent) {
183
+ case 'exportIntent':
184
+ case 'stringConversionIntent':
185
+ return { value: value.$date };
186
+ default:
187
+ const m = value.$date.match(dateTimeStorageRegex);
188
+ if (m) {
189
+ return { value: `${m[1]}-${m[2]}-${m[3]} ${m[4]}:${m[5]}:${m[6]}`, gridStyle: 'valueCellStyle' };
190
+ }
191
+ else {
192
+ return { value: value.$date.replaCE('T', ' '), gridStyle: 'valueCellStyle' };
193
+ }
194
+ }
195
+ }
196
+ }
197
+ if ((0, isArray_1.default)(value)) {
198
+ switch (intent) {
199
+ case 'gridCellIntent':
200
+ return stringifyJsonToGrid(value);
201
+ case 'multilineEditorIntent':
202
+ return { value: JSON.stringify(value, null, 2) };
203
+ default:
204
+ return { value: JSON.stringify(value), gridStyle: 'valueCellStyle' };
205
+ }
206
+ }
207
+ if ((0, isPlainObject_1.default)(value)) {
208
+ switch (intent) {
209
+ case 'gridCellIntent':
210
+ return stringifyJsonToGrid(value);
211
+ case 'multilineEditorIntent':
212
+ return { value: JSON.stringify(value, null, 2) };
213
+ default:
214
+ return { value: JSON.stringify(value), gridStyle: 'valueCellStyle' };
215
+ }
216
+ }
217
+ if ((0, isNumber_1.default)(value)) {
218
+ switch (intent) {
219
+ case 'gridCellIntent':
220
+ return {
221
+ value: (gridFormattingOptions === null || gridFormattingOptions === void 0 ? void 0 : gridFormattingOptions.useThousandsSeparator) && (value >= 10000 || value <= -10000)
222
+ ? value.toLocaleString()
223
+ : value.toString(),
224
+ gridStyle: 'valueCellStyle',
225
+ };
226
+ default:
227
+ return { value: value.toString() };
228
+ }
229
+ }
230
+ if ((0, isString_1.default)(value)) {
231
+ switch (intent) {
232
+ case 'gridCellIntent':
233
+ if (jsonParsedValue && !(editorTypes === null || editorTypes === void 0 ? void 0 : editorTypes.explicitDataType)) {
234
+ return stringifyJsonToGrid(jsonParsedValue);
235
+ }
236
+ else {
237
+ if (!(editorTypes === null || editorTypes === void 0 ? void 0 : editorTypes.explicitDataType)) {
238
+ // reformat datetime for implicit date types
239
+ const m = value.match(dateTimeStorageRegex);
240
+ if (m) {
241
+ return {
242
+ value: `${m[1]}-${m[2]}-${m[3]} ${m[4]}:${m[5]}:${m[6]}`,
243
+ gridStyle: 'valueCellStyle',
244
+ };
245
+ }
246
+ }
247
+ return { value: highlightSpecialCharacters(value), gridStyle: 'textCellStyle' };
248
+ }
249
+ default:
250
+ return { value: value };
251
+ }
252
+ }
253
+ if (value === null || value === undefined) {
254
+ switch (intent) {
255
+ case 'gridCellIntent':
256
+ return { value: '(n/a)', gridStyle: 'nullCellStyle' };
257
+ default:
258
+ return { value: '' };
259
+ }
260
+ }
261
+ switch (intent) {
262
+ case 'gridCellIntent':
263
+ return { value: '(Unknown)', gridStyle: 'nullCellStyle' };
264
+ default:
265
+ return { value: '' };
266
+ }
267
+ }
55
268
  exports.stringifyCellValue = stringifyCellValue;
56
269
  function safeJsonParse(json, defaultValue, logError = false) {
57
270
  if ((0, isArray_1.default)(json) || (0, isPlainObject_1.default)(json)) {
@@ -68,6 +281,28 @@ function safeJsonParse(json, defaultValue, logError = false) {
68
281
  }
69
282
  }
70
283
  exports.safeJsonParse = safeJsonParse;
284
+ function shouldOpenMultilineDialog(value) {
285
+ if ((0, isString_1.default)(value)) {
286
+ if (value.includes('\n')) {
287
+ return true;
288
+ }
289
+ const parsed = safeJsonParse(value);
290
+ if (parsed && ((0, isPlainObject_1.default)(parsed) || (0, isArray_1.default)(parsed))) {
291
+ return true;
292
+ }
293
+ }
294
+ if (value === null || value === void 0 ? void 0 : value.$oid) {
295
+ return false;
296
+ }
297
+ if (value === null || value === void 0 ? void 0 : value.$date) {
298
+ return false;
299
+ }
300
+ if ((0, isPlainObject_1.default)(value) || (0, isArray_1.default)(value)) {
301
+ return true;
302
+ }
303
+ return false;
304
+ }
305
+ exports.shouldOpenMultilineDialog = shouldOpenMultilineDialog;
71
306
  function isJsonLikeLongString(value) {
72
307
  return (0, isString_1.default)(value) && value.length > 100 && value.match(/^\s*\{.*\}\s*$|^\s*\[.*\]\s*$/);
73
308
  }
@@ -135,3 +370,75 @@ function parseSqlDefaultValue(value) {
135
370
  return undefined;
136
371
  }
137
372
  exports.parseSqlDefaultValue = parseSqlDefaultValue;
373
+ function detectCellDataType(value) {
374
+ if (value === null)
375
+ return 'null';
376
+ if (value === null || value === void 0 ? void 0 : value.$oid)
377
+ return 'objectid';
378
+ if (value === null || value === void 0 ? void 0 : value.$date)
379
+ return 'date';
380
+ if ((0, isString_1.default)(value))
381
+ return 'string';
382
+ if ((0, isNumber_1.default)(value))
383
+ return 'number';
384
+ if ((0, isPlainObject_1.default)(value))
385
+ return 'object';
386
+ if ((0, isArray_1.default)(value))
387
+ return 'array';
388
+ if (value === true || value === false)
389
+ return 'boolean';
390
+ return 'unknown';
391
+ }
392
+ exports.detectCellDataType = detectCellDataType;
393
+ function detectTypeIcon(value) {
394
+ switch (detectCellDataType(value)) {
395
+ case 'null':
396
+ return 'icon type-null';
397
+ case 'objectid':
398
+ return 'icon type-objectid';
399
+ case 'date':
400
+ return 'icon type-date';
401
+ case 'string':
402
+ return 'icon type-string';
403
+ case 'number':
404
+ return 'icon type-number';
405
+ case 'object':
406
+ return 'icon type-object';
407
+ case 'array':
408
+ return 'icon type-array';
409
+ case 'boolean':
410
+ return 'icon type-boolean';
411
+ default:
412
+ return 'icon type-unknown';
413
+ }
414
+ }
415
+ exports.detectTypeIcon = detectTypeIcon;
416
+ function getConvertValueMenu(value, onSetValue, editorTypes) {
417
+ return [
418
+ (editorTypes === null || editorTypes === void 0 ? void 0 : editorTypes.supportStringType) && {
419
+ text: 'String',
420
+ onClick: () => onSetValue(stringifyCellValue(value, 'stringConversionIntent', editorTypes).value),
421
+ },
422
+ (editorTypes === null || editorTypes === void 0 ? void 0 : editorTypes.supportNumberType) && { text: 'Number', onClick: () => onSetValue(parseFloat(value)) },
423
+ (editorTypes === null || editorTypes === void 0 ? void 0 : editorTypes.supportNullType) && { text: 'Null', onClick: () => onSetValue(null) },
424
+ (editorTypes === null || editorTypes === void 0 ? void 0 : editorTypes.supportBooleanType) && {
425
+ text: 'Boolean',
426
+ onClick: () => { var _a; return onSetValue(((_a = value === null || value === void 0 ? void 0 : value.toString()) === null || _a === void 0 ? void 0 : _a.toLowerCase()) == 'true' || value == '1'); },
427
+ },
428
+ (editorTypes === null || editorTypes === void 0 ? void 0 : editorTypes.supportObjectIdType) && {
429
+ text: 'ObjectId',
430
+ onClick: () => onSetValue(parseFunc_ObjectIdAsDollar(value)),
431
+ },
432
+ (editorTypes === null || editorTypes === void 0 ? void 0 : editorTypes.supportDateType) && { text: 'Date', onClick: () => onSetValue(parseFunc_DateAsDollar(value)) },
433
+ (editorTypes === null || editorTypes === void 0 ? void 0 : editorTypes.supportJsonType) && {
434
+ text: 'JSON',
435
+ onClick: () => {
436
+ const jsonValue = safeJsonParse(value);
437
+ if (jsonValue != null) {
438
+ onSetValue(jsonValue);
439
+ }
440
+ },
441
+ },
442
+ ];
443
+ }
444
+ exports.getConvertValueMenu = getConvertValueMenu;
@@ -7,4 +7,7 @@ interface CompiledPermissions {
7
7
  }
8
8
  export declare function compilePermissions(permissions: string[] | string): CompiledPermissions;
9
9
  export declare function testPermission(tested: string, permissions: CompiledPermissions): boolean;
10
+ export declare function testSubPermission(tested: string, permissions: string[], allowSamePermission?: boolean): true | false | null;
11
+ export declare function getPredefinedPermissions(predefinedRoleName: string): string[];
12
+ export declare function sortPermissionsFromTheSameLevel(permissions: string[]): string[];
10
13
  export {};
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.testPermission = exports.compilePermissions = void 0;
6
+ exports.sortPermissionsFromTheSameLevel = exports.getPredefinedPermissions = exports.testSubPermission = exports.testPermission = exports.compilePermissions = void 0;
7
7
  const escapeRegExp_1 = __importDefault(require("lodash/escapeRegExp"));
8
8
  const isString_1 = __importDefault(require("lodash/isString"));
9
9
  const compact_1 = __importDefault(require("lodash/compact"));
@@ -64,3 +64,40 @@ function testPermission(tested, permissions) {
64
64
  return allow;
65
65
  }
66
66
  exports.testPermission = testPermission;
67
+ function testSubPermission(tested, permissions, allowSamePermission = true) {
68
+ let result = null;
69
+ for (const permWithSign of permissions) {
70
+ const perm = permWithSign.startsWith('~') ? permWithSign.substring(1) : permWithSign;
71
+ const deny = permWithSign.startsWith('~');
72
+ if (perm.endsWith('*')) {
73
+ const prefix = perm.substring(0, perm.length - 1);
74
+ if (tested.startsWith(prefix)) {
75
+ result = !deny;
76
+ }
77
+ }
78
+ else {
79
+ if (allowSamePermission && tested == perm) {
80
+ result = !deny;
81
+ }
82
+ }
83
+ }
84
+ return result;
85
+ }
86
+ exports.testSubPermission = testSubPermission;
87
+ function getPredefinedPermissions(predefinedRoleName) {
88
+ switch (predefinedRoleName) {
89
+ case 'superadmin':
90
+ return ['*', '~widgets/*', 'widgets/admin', 'widgets/database', '~all-connections'];
91
+ case 'logged-user':
92
+ return ['*', '~widgets/admin', '~admin/*', '~internal-storage', '~all-connections'];
93
+ case 'anonymous-user':
94
+ return ['*', '~widgets/admin', '~admin/*', '~internal-storage', '~all-connections'];
95
+ default:
96
+ return null;
97
+ }
98
+ }
99
+ exports.getPredefinedPermissions = getPredefinedPermissions;
100
+ function sortPermissionsFromTheSameLevel(permissions) {
101
+ return [...permissions.filter(x => x.startsWith('~')), ...permissions.filter(x => !x.startsWith('~'))];
102
+ }
103
+ exports.sortPermissionsFromTheSameLevel = sortPermissionsFromTheSameLevel;
@@ -6,6 +6,8 @@ export interface ColumnInfoYaml {
6
6
  length?: number;
7
7
  autoIncrement?: boolean;
8
8
  references?: string;
9
+ refDeleteAction?: string;
10
+ refUpdateAction?: string;
9
11
  primaryKey?: boolean;
10
12
  default?: string;
11
13
  }
@@ -27,4 +29,4 @@ export interface ForeignKeyInfoYaml {
27
29
  }
28
30
  export declare function tableInfoToYaml(table: TableInfo): TableInfoYaml;
29
31
  export declare function tableInfoFromYaml(table: TableInfoYaml, allTables: TableInfoYaml[]): TableInfo;
30
- export declare function databaseInfoFromYamlModel(files: DatabaseModelFile[]): DatabaseInfo;
32
+ export declare function databaseInfoFromYamlModel(filesOrDbInfo: DatabaseModelFile[] | DatabaseInfo): DatabaseInfo;
@@ -66,6 +66,8 @@ function convertForeignKeyFromYaml(col, table, allTables) {
66
66
  constraintType: 'foreignKey',
67
67
  pureName: table.name,
68
68
  refTableName: col.references,
69
+ deleteAction: col.refDeleteAction,
70
+ updateAction: col.refUpdateAction,
69
71
  columns: [
70
72
  {
71
73
  columnName: col.name,
@@ -93,10 +95,13 @@ function tableInfoFromYaml(table, allTables) {
93
95
  return res;
94
96
  }
95
97
  exports.tableInfoFromYaml = tableInfoFromYaml;
96
- function databaseInfoFromYamlModel(files) {
98
+ function databaseInfoFromYamlModel(filesOrDbInfo) {
99
+ if (!Array.isArray(filesOrDbInfo)) {
100
+ return filesOrDbInfo;
101
+ }
97
102
  const model = DatabaseAnalyser_1.DatabaseAnalyser.createEmptyStructure();
98
103
  const tablesYaml = [];
99
- for (const file of files) {
104
+ for (const file of filesOrDbInfo) {
100
105
  if (file.name.endsWith('.table.yaml') || file.name.endsWith('.sql')) {
101
106
  if (file.name.endsWith('.table.yaml')) {
102
107
  tablesYaml.push(file.json);
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "5.3.4",
2
+ "version": "5.4.1",
3
3
  "name": "dbgate-tools",
4
4
  "main": "lib/index.js",
5
5
  "typings": "lib/index.d.ts",
@@ -25,14 +25,14 @@
25
25
  ],
26
26
  "devDependencies": {
27
27
  "@types/node": "^13.7.0",
28
- "dbgate-types": "^5.3.4",
28
+ "dbgate-types": "^5.4.1",
29
29
  "jest": "^24.9.0",
30
30
  "ts-jest": "^25.2.1",
31
31
  "typescript": "^4.4.3"
32
32
  },
33
33
  "dependencies": {
34
- "dbgate-query-splitter": "^4.10.1",
35
- "dbgate-sqltree": "^5.3.4",
34
+ "dbgate-query-splitter": "^4.10.3",
35
+ "dbgate-sqltree": "^5.4.1",
36
36
  "debug": "^4.3.4",
37
37
  "json-stable-stringify": "^1.0.1",
38
38
  "lodash": "^4.17.21",