dbgate-tools 5.0.8 → 5.1.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.
package/lib/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,4 +1,4 @@
1
- import { ColumnInfo, DatabaseInfo, DatabaseInfoObjects, SqlDialect, TableInfo } from 'dbgate-types';
1
+ import { ColumnInfo, DatabaseInfo, DatabaseInfoObjects, NamedObjectInfo, SqlDialect, TableInfo } from 'dbgate-types';
2
2
  export declare function fullNameFromString(name: any): {
3
3
  schemaName: any;
4
4
  pureName: any;
@@ -16,10 +16,11 @@ export declare function quoteFullName(dialect: any, { schemaName, pureName }: {
16
16
  pureName: any;
17
17
  }): string;
18
18
  export declare function equalStringLike(s1: any, s2: any): boolean;
19
+ export declare function equalFullName(name1: NamedObjectInfo, name2: NamedObjectInfo): boolean;
19
20
  export declare function findObjectLike({ pureName, schemaName }: {
20
21
  pureName: any;
21
22
  schemaName: any;
22
23
  }, dbinfo: DatabaseInfo, objectTypeField: keyof DatabaseInfoObjects): import("dbgate-types").CollectionInfo;
23
- export declare function findForeignKeyForColumn(table: TableInfo, column: ColumnInfo): import("dbgate-types").ForeignKeyInfo;
24
+ export declare function findForeignKeyForColumn(table: TableInfo, column: ColumnInfo | string): import("dbgate-types").ForeignKeyInfo;
24
25
  export declare function makeUniqueColumnNames(res: ColumnInfo[]): void;
25
26
  export declare function fillConstraintNames(table: TableInfo, dialect: SqlDialect): TableInfo;
package/lib/nameTools.js CHANGED
@@ -3,8 +3,9 @@ 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.fillConstraintNames = exports.makeUniqueColumnNames = exports.findForeignKeyForColumn = exports.findObjectLike = exports.equalStringLike = exports.quoteFullName = exports.fullNameToLabel = exports.fullNameToString = exports.fullNameFromString = void 0;
7
- const lodash_1 = __importDefault(require("lodash"));
6
+ exports.fillConstraintNames = exports.makeUniqueColumnNames = exports.findForeignKeyForColumn = exports.findObjectLike = exports.equalFullName = exports.equalStringLike = exports.quoteFullName = exports.fullNameToLabel = exports.fullNameToString = exports.fullNameFromString = void 0;
7
+ const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
8
+ const isString_1 = __importDefault(require("lodash/isString"));
8
9
  function fullNameFromString(name) {
9
10
  const m = name.match(/\[([^\]]+)\]\.\[([^\]]+)\]/);
10
11
  if (m) {
@@ -43,6 +44,12 @@ function equalStringLike(s1, s2) {
43
44
  return (s1 || '').toLowerCase().trim() == (s2 || '').toLowerCase().trim();
44
45
  }
45
46
  exports.equalStringLike = equalStringLike;
47
+ function equalFullName(name1, name2) {
48
+ if (!name1 || !name2)
49
+ return name1 == name2;
50
+ return name1.pureName == name2.pureName && name1.schemaName == name2.schemaName;
51
+ }
52
+ exports.equalFullName = equalFullName;
46
53
  function findObjectLike({ pureName, schemaName }, dbinfo, objectTypeField) {
47
54
  var _a, _b;
48
55
  if (!dbinfo)
@@ -56,6 +63,9 @@ function findObjectLike({ pureName, schemaName }, dbinfo, objectTypeField) {
56
63
  }
57
64
  exports.findObjectLike = findObjectLike;
58
65
  function findForeignKeyForColumn(table, column) {
66
+ if ((0, isString_1.default)(column)) {
67
+ return (table.foreignKeys || []).find(fk => fk.columns.find(col => col.columnName == column));
68
+ }
59
69
  return (table.foreignKeys || []).find(fk => fk.columns.find(col => col.columnName == column.columnName));
60
70
  }
61
71
  exports.findForeignKeyForColumn = findForeignKeyForColumn;
@@ -78,7 +88,7 @@ function columnsConstraintName(prefix, table, columns) {
78
88
  function fillConstraintNames(table, dialect) {
79
89
  if (!table)
80
90
  return table;
81
- const res = lodash_1.default.cloneDeep(table);
91
+ const res = (0, cloneDeep_1.default)(table);
82
92
  if (res.primaryKey && !res.primaryKey.constraintName && !dialect.anonymousPrimaryKey) {
83
93
  res.primaryKey.constraintName = `PK_${res.pureName}`;
84
94
  }
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "5.0.8",
2
+ "version": "5.1.1",
3
3
  "name": "dbgate-tools",
4
4
  "main": "lib/index.js",
5
5
  "typings": "lib/index.d.ts",
@@ -25,15 +25,17 @@
25
25
  ],
26
26
  "devDependencies": {
27
27
  "@types/node": "^13.7.0",
28
- "dbgate-types": "^5.0.8",
28
+ "dbgate-types": "^5.1.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
- "lodash": "^4.17.21",
35
34
  "dbgate-query-splitter": "^4.9.0",
36
- "dbgate-sqltree": "^5.0.8",
35
+ "dbgate-sqltree": "^5.1.1",
36
+ "debug": "^4.3.4",
37
+ "json-stable-stringify": "^1.0.1",
38
+ "lodash": "^4.17.21",
37
39
  "uuid": "^3.4.0"
38
40
  }
39
41
  }