dbgate-tools 6.5.4 → 6.5.5

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.
@@ -619,6 +619,8 @@ function parseNumberSafe(value) {
619
619
  exports.parseNumberSafe = parseNumberSafe;
620
620
  const frontMatterRe = /^--\ >>>[ \t\r]*\n(.*)\n-- <<<[ \t\r]*\n/s;
621
621
  function getSqlFrontMatter(text, yamlModule) {
622
+ if (!text || !(0, isString_1.default)(text))
623
+ return null;
622
624
  const match = text.match(frontMatterRe);
623
625
  if (!match)
624
626
  return null;
@@ -627,6 +629,8 @@ function getSqlFrontMatter(text, yamlModule) {
627
629
  }
628
630
  exports.getSqlFrontMatter = getSqlFrontMatter;
629
631
  function removeSqlFrontMatter(text) {
632
+ if (!text || !(0, isString_1.default)(text))
633
+ return null;
630
634
  return text.replace(frontMatterRe, '');
631
635
  }
632
636
  exports.removeSqlFrontMatter = removeSqlFrontMatter;
@@ -646,6 +650,6 @@ function setSqlFrontMatter(text, data, yamlModule) {
646
650
  .map(line => '-- ' + line)
647
651
  .join('\n');
648
652
  const frontMatterContent = `-- >>>\n${yamlContentMapped}\n-- <<<\n`;
649
- return frontMatterContent + textClean;
653
+ return frontMatterContent + (textClean || '');
650
654
  }
651
655
  exports.setSqlFrontMatter = setSqlFrontMatter;
@@ -1,4 +1,4 @@
1
- import type { DatabaseInfo, TableInfo, ApplicationDefinition, ViewInfo, CollectionInfo } from 'dbgate-types';
1
+ import type { DatabaseInfo, TableInfo, ApplicationDefinition, ViewInfo, CollectionInfo, EngineDriver } from 'dbgate-types';
2
2
  export declare function addTableDependencies(db: DatabaseInfo): DatabaseInfo;
3
3
  export declare function extendTableInfo(table: TableInfo): TableInfo;
4
4
  export declare function extendDatabaseInfo(db: DatabaseInfo): DatabaseInfo;
@@ -30,3 +30,4 @@ export declare function skipDbGateInternalObjects(db: DatabaseInfo): {
30
30
  triggers: import("dbgate-types").TriggerInfo[];
31
31
  schedulerEvents: import("dbgate-types").SchedulerEventInfo[];
32
32
  };
33
+ export declare function adaptDatabaseInfo(db: DatabaseInfo, driver: EngineDriver): DatabaseInfo;
@@ -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.skipDbGateInternalObjects = exports.removePreloadedRowsFromStructure = exports.detectChangesInPreloadedRows = exports.skipNamesInStructureByRegex = exports.replaceSchemaInStructure = exports.getSchemasUsedByStructure = exports.filterStructureBySchema = exports.isCollectionInfo = exports.isViewInfo = exports.isTableInfo = exports.isTableColumnUnique = exports.extendDatabaseInfoFromApps = exports.extendDatabaseInfo = exports.extendTableInfo = exports.addTableDependencies = void 0;
6
+ exports.adaptDatabaseInfo = exports.skipDbGateInternalObjects = exports.removePreloadedRowsFromStructure = exports.detectChangesInPreloadedRows = exports.skipNamesInStructureByRegex = exports.replaceSchemaInStructure = exports.getSchemasUsedByStructure = exports.filterStructureBySchema = exports.isCollectionInfo = exports.isViewInfo = exports.isTableInfo = exports.isTableColumnUnique = exports.extendDatabaseInfoFromApps = exports.extendDatabaseInfo = exports.extendTableInfo = exports.addTableDependencies = void 0;
7
7
  const flatten_1 = __importDefault(require("lodash/flatten"));
8
8
  const uniq_1 = __importDefault(require("lodash/uniq"));
9
9
  const keys_1 = __importDefault(require("lodash/keys"));
@@ -293,3 +293,11 @@ function skipDbGateInternalObjects(db) {
293
293
  };
294
294
  }
295
295
  exports.skipDbGateInternalObjects = skipDbGateInternalObjects;
296
+ function adaptDatabaseInfo(db, driver) {
297
+ const modelAdapted = {
298
+ ...db,
299
+ tables: db.tables.map(table => driver.adaptTableInfo(table)),
300
+ };
301
+ return modelAdapted;
302
+ }
303
+ exports.adaptDatabaseInfo = adaptDatabaseInfo;
@@ -23,12 +23,17 @@ export interface IndexInfoYaml {
23
23
  columns: string[];
24
24
  included?: string[];
25
25
  }
26
+ export interface UniqueInfoYaml {
27
+ name: string;
28
+ columns: string[];
29
+ }
26
30
  export interface TableInfoYaml {
27
31
  name: string;
28
32
  columns: ColumnInfoYaml[];
29
33
  primaryKey?: string[];
30
34
  sortingKey?: string[];
31
35
  indexes?: IndexInfoYaml[];
36
+ uniques?: UniqueInfoYaml[];
32
37
  insertKey?: string[];
33
38
  insertOnly?: string[];
34
39
  data?: any[];
@@ -46,7 +46,7 @@ function columnInfoFromYaml(column, table) {
46
46
  return res;
47
47
  }
48
48
  function tableInfoToYaml(table) {
49
- var _a;
49
+ var _a, _b;
50
50
  const tableCopy = (0, cloneDeep_1.default)(table);
51
51
  const res = {
52
52
  name: tableCopy.pureName,
@@ -74,6 +74,12 @@ function tableInfoToYaml(table) {
74
74
  return idx;
75
75
  });
76
76
  }
77
+ if (((_b = tableCopy.uniques) === null || _b === void 0 ? void 0 : _b.length) > 0) {
78
+ res.uniques = tableCopy.uniques.map(unique => ({
79
+ name: unique.constraintName,
80
+ columns: unique.columns.map(x => x.columnName),
81
+ }));
82
+ }
77
83
  return res;
78
84
  }
79
85
  exports.tableInfoToYaml = tableInfoToYaml;
@@ -97,7 +103,7 @@ function convertForeignKeyFromYaml(col, table, allTables) {
97
103
  };
98
104
  }
99
105
  function tableInfoFromYaml(table, allTables) {
100
- var _a;
106
+ var _a, _b;
101
107
  const res = {
102
108
  pureName: table.name,
103
109
  columns: table.columns.map(c => columnInfoFromYaml(c, table)),
@@ -113,6 +119,12 @@ function tableInfoFromYaml(table, allTables) {
113
119
  ...(index.included || []).map(columnName => ({ columnName, isIncludedColumn: true })),
114
120
  ],
115
121
  })),
122
+ uniques: (_b = table.uniques) === null || _b === void 0 ? void 0 : _b.map(unique => ({
123
+ constraintName: unique.name,
124
+ pureName: table.name,
125
+ constraintType: 'unique',
126
+ columns: unique.columns.map(columnName => ({ columnName })),
127
+ })),
116
128
  };
117
129
  if (table.primaryKey) {
118
130
  res.primaryKey = {
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "6.5.4",
2
+ "version": "6.5.5",
3
3
  "name": "dbgate-tools",
4
4
  "main": "lib/index.js",
5
5
  "typings": "lib/index.d.ts",
@@ -26,14 +26,14 @@
26
26
  ],
27
27
  "devDependencies": {
28
28
  "@types/node": "^13.7.0",
29
- "dbgate-types": "^6.5.4",
29
+ "dbgate-types": "^6.5.5",
30
30
  "jest": "^28.1.3",
31
31
  "ts-jest": "^28.0.7",
32
32
  "typescript": "^4.4.3"
33
33
  },
34
34
  "dependencies": {
35
35
  "dbgate-query-splitter": "^4.11.5",
36
- "dbgate-sqltree": "^6.5.4",
36
+ "dbgate-sqltree": "^6.5.5",
37
37
  "debug": "^4.3.4",
38
38
  "json-stable-stringify": "^1.0.1",
39
39
  "lodash": "^4.17.21",