@dbml/core 2.2.0 → 2.4.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/export/DbmlExporter.js +15 -4
- package/lib/export/JsonExporter.js +1 -3
- package/lib/export/ModelExporter.js +1 -3
- package/lib/export/MysqlExporter.js +50 -42
- package/lib/export/PostgresExporter.js +64 -49
- package/lib/export/SqlServerExporter.js +52 -46
- package/lib/model_structure/database.js +73 -28
- package/lib/model_structure/dbState.js +1 -3
- package/lib/model_structure/element.js +13 -13
- package/lib/model_structure/endpoint.js +18 -14
- package/lib/model_structure/enum.js +18 -14
- package/lib/model_structure/enumValue.js +16 -12
- package/lib/model_structure/field.js +47 -13
- package/lib/model_structure/indexColumn.js +16 -12
- package/lib/model_structure/indexes.js +18 -14
- package/lib/model_structure/ref.js +19 -16
- package/lib/model_structure/schema.js +24 -36
- package/lib/model_structure/table.js +19 -15
- package/lib/model_structure/tableGroup.js +18 -14
- package/lib/model_structure/utils.js +5 -0
- package/lib/parse/Parser.js +2 -4
- package/lib/parse/buildParser.js +1 -3
- package/lib/parse/dbml/parser.pegjs +64 -20
- package/lib/parse/dbmlParser.js +1401 -899
- package/lib/parse/mssql/constraint_definition/actions.js +2 -2
- package/lib/parse/mssql/fk_definition/actions.js +10 -3
- package/lib/parse/mssql/keyword_parsers.js +0 -1
- package/lib/parse/mssql/statements/actions.js +9 -6
- package/lib/parse/mssql/statements/statement_types/alter_table/actions.js +11 -5
- package/lib/parse/mssql/statements/statement_types/create_index/actions.js +6 -1
- package/lib/parse/mssql/statements/statement_types/create_table/actions.js +12 -10
- package/lib/parse/mssql/utils.js +16 -1
- package/lib/parse/mysql/parser.pegjs +57 -34
- package/lib/parse/mysqlParser.js +270 -218
- package/lib/parse/postgresParser.js +12 -10
- package/lib/parse/postgresql/Base_rules.pegjs +45 -10
- package/lib/parse/postgresql/Commands/Alter_table/Alter_table.pegjs +2 -1
- package/lib/parse/postgresql/Commands/Create_table/Create_table_normal.pegjs +5 -3
- package/lib/parse/postgresql/Commands/Create_table/Create_table_of.pegjs +1 -1
- package/lib/parse/postgresql/Commands/Create_table/Create_table_partition_of.pegjs +1 -1
- package/lib/parse/postgresql/Commands/Create_type/Create_type_enum.pegjs +2 -2
- package/lib/parse/postgresql/InitializerUtils.pegjs +10 -0
- package/lib/parse/postgresql/parser.pegjs +2 -1
- package/lib/parse/schemarbParser.js +3 -3
- package/package.json +5 -3
- package/types/export/ModelExporter.d.ts +5 -0
- package/types/export/index.d.ts +5 -0
- package/types/import/index.d.ts +5 -0
- package/types/index.d.ts +5 -0
- package/types/model_structure/database.d.ts +195 -0
- package/types/model_structure/dbState.d.ts +14 -0
- package/types/model_structure/element.d.ts +21 -0
- package/types/model_structure/endpoint.d.ts +55 -0
- package/types/model_structure/enum.d.ts +67 -0
- package/types/model_structure/enumValue.d.ts +39 -0
- package/types/model_structure/field.d.ts +77 -0
- package/types/model_structure/indexColumn.d.ts +37 -0
- package/types/model_structure/indexes.d.ts +74 -0
- package/types/model_structure/ref.d.ts +66 -0
- package/types/model_structure/schema.d.ts +188 -0
- package/types/model_structure/table.d.ts +118 -0
- package/types/model_structure/tableGroup.d.ts +54 -0
- package/types/parse/Parser.d.ts +11 -0
- package/lib/export/Exporter.js +0 -80
- package/lib/export/SchemaExporter.js +0 -99
- package/lib/parse/dbml/multiline_content.txt +0 -7
- package/lib/parse/dbml/multiline_string.pegjs +0 -17
- package/lib/parse/dbml/parser1.json +0 -219
- package/lib/parse/dbml/parser1.pegjs +0 -702
- package/lib/parse/dbml/parser1_content.txt +0 -29
- package/lib/parse/dbml/test_multiline.js +0 -53
- package/lib/parse/dbml/test_parser1.js +0 -16
- package/lib/parse/mssql/base_utils.js +0 -28
- package/lib/parse/mssql/composite_parsers.js +0 -109
- package/lib/parse/mssql/statement_types/alter_table/actions.js +0 -29
- package/lib/parse/mssql/statement_types/alter_table/add/actions.js +0 -8
- package/lib/parse/mssql/statement_types/alter_table/add/index.js +0 -58
- package/lib/parse/mssql/statement_types/alter_table/index.js +0 -32
- package/lib/parse/mssql/statement_types/create_index/actions.js +0 -25
- package/lib/parse/mssql/statement_types/create_index/index.js +0 -50
- package/lib/parse/mssql/statement_types/create_table/actions.js +0 -95
- package/lib/parse/mssql/statement_types/create_table/index.js +0 -50
- package/lib/parse/mssql/statement_types/index.js +0 -13
- package/lib/schema/element.js +0 -84
- package/lib/schema/endpoint.js +0 -102
- package/lib/schema/enum.js +0 -102
- package/lib/schema/enumValue.js +0 -70
- package/lib/schema/field.js +0 -104
- package/lib/schema/indexes.js +0 -74
- package/lib/schema/ref.js +0 -93
- package/lib/schema/schema.js +0 -245
- package/lib/schema/table.js +0 -163
- package/lib/schema/tableGroup.js +0 -93
|
@@ -1,8 +1,27 @@
|
|
|
1
1
|
// Base rules:
|
|
2
2
|
// collumn_name, table_name
|
|
3
3
|
column_name "valid column name" = identifier
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
|
|
5
|
+
path_name = names:(identifier _ "." _)* {
|
|
6
|
+
let dbName = null;
|
|
7
|
+
let schemaName = null;
|
|
8
|
+
if (names && names.length > 0) {
|
|
9
|
+
if (names.length === 1) schemaName = names[0][0];
|
|
10
|
+
else {
|
|
11
|
+
dbName = names[0][0];
|
|
12
|
+
schemaName = names[1][0];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return { dbName, schemaName }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
table_name "valid table name" = pathName:path_name name:identifier {
|
|
19
|
+
return { ...pathName, name }
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
enum_name "valid enum name" = pathName:path_name? name:identifier {
|
|
23
|
+
return { ...pathName, name }
|
|
24
|
+
}
|
|
6
25
|
|
|
7
26
|
// string constant
|
|
8
27
|
string_constant "string" = "'" c:char_inside_single_quote+ "'" {
|
|
@@ -32,36 +51,43 @@ digits = d:digit+ { return d.join('') }
|
|
|
32
51
|
digit = [0-9]
|
|
33
52
|
|
|
34
53
|
// type
|
|
35
|
-
data_type "VALID TYPE" = c1:"CHARACTER"i _ c2:"VARYING"i _ args:("("expression")")? {
|
|
54
|
+
data_type "VALID TYPE" = c1:"CHARACTER"i _ c2:"VARYING"i _ args:("("expression")")? dimensions:(array_extension)? {
|
|
36
55
|
let c = `${c1} ${c2}`;
|
|
37
56
|
c = args ? c + '(' + args[1] + ')' : c;
|
|
38
57
|
return {
|
|
39
|
-
type_name: c,
|
|
58
|
+
type_name: c + (dimensions ? dimensions.map((dimension) => '[' + dimension + ']').join('') : ''),
|
|
40
59
|
args: args ? args[1] : null
|
|
41
60
|
}
|
|
42
61
|
}
|
|
43
|
-
/ "timestamp"i _ number:("(" _ numeric_constant _ ")" _)? (("without"i/"with"i) _ "time"i _ "zone"i)? {
|
|
62
|
+
/ "timestamp"i _ number:("(" _ numeric_constant _ ")" _)? (("without"i/"with"i) _ "time"i _ "zone"i)? dimensions:(array_extension)? {
|
|
44
63
|
const args = number ? number[2] : null;
|
|
45
64
|
return {
|
|
46
|
-
type_name: args !== null ? `timestamp(${args})`: `timestamp
|
|
65
|
+
type_name: (args !== null ? `timestamp(${args})`: `timestamp`) + (dimensions ? dimensions.map((dimension) => '[' + dimension + ']').join('') : ''),
|
|
47
66
|
args
|
|
48
67
|
}
|
|
49
68
|
}
|
|
50
|
-
/ "time"i _ number:("(" _ numeric_constant _ ")" _)? (("without"i/"with"i) _ "time"i _ "zone"i)? {
|
|
69
|
+
/ "time"i _ number:("(" _ numeric_constant _ ")" _)? (("without"i/"with"i) _ "time"i _ "zone"i)? dimensions:(array_extension)? {
|
|
51
70
|
const args = number ? number[2] : null;
|
|
52
71
|
return {
|
|
53
|
-
type_name: args !== null ? `time(${args})`: `time
|
|
72
|
+
type_name: (args !== null ? `time(${args})`: `time`) + (dimensions ? dimensions.map((dimension) => '[' + dimension + ']').join('') : ''),
|
|
54
73
|
args
|
|
55
74
|
}
|
|
56
75
|
}
|
|
57
|
-
/ c:type_name {
|
|
76
|
+
/ c:type_name dimensions:(array_extension)? {
|
|
77
|
+
const args = c.args;
|
|
78
|
+
return {
|
|
79
|
+
type_name: c.type_name + (dimensions ? dimensions.map((dimension) => '[' + dimension + ']').join('') : ''),
|
|
80
|
+
schemaName: c.schemaName,
|
|
81
|
+
args
|
|
82
|
+
};
|
|
83
|
+
}
|
|
58
84
|
/ double_quote c:[^\"\n]+ double_quote {
|
|
59
85
|
return {
|
|
60
86
|
type_name: c.join(""),
|
|
61
87
|
args: null
|
|
62
88
|
}
|
|
63
89
|
}
|
|
64
|
-
type_name = c:(character)+ _ args:("(" expression ")")? {
|
|
90
|
+
type_name = pathName:path_name? c:(character)+ _ args:("(" expression ")")? {
|
|
65
91
|
let type_name = c.join("");
|
|
66
92
|
args = args ? args[1] : null;
|
|
67
93
|
if (type_name.toLowerCase() !== 'enum') {
|
|
@@ -69,10 +95,19 @@ type_name = c:(character)+ _ args:("(" expression ")")? {
|
|
|
69
95
|
}
|
|
70
96
|
|
|
71
97
|
return {
|
|
98
|
+
...pathName,
|
|
72
99
|
type_name,
|
|
73
100
|
args
|
|
74
101
|
}
|
|
75
102
|
}
|
|
103
|
+
//https://www.postgresql.org/docs/13/arrays.html
|
|
104
|
+
array_extension = _ "array"i singledimenson:(_ "[" _ expression _ "]")? {
|
|
105
|
+
return [singledimenson ? singledimenson[3] : ''];
|
|
106
|
+
}
|
|
107
|
+
/ _ multidimenson:("[" _ expression _ "]")+ {
|
|
108
|
+
// this will parse into Array(Array('[', _ , expression , _ ']'))
|
|
109
|
+
return multidimenson.map((dimension) => dimension[2]);
|
|
110
|
+
}
|
|
76
111
|
|
|
77
112
|
// Default
|
|
78
113
|
default_expr = val:string_constant { return { value: val, type: 'string' }}
|
|
@@ -11,7 +11,8 @@ alter_table_action = _ ALTER __ TABLE (__ IF_EXISTS)? (__ ONLY)? __ name:table_n
|
|
|
11
11
|
switch(type.toLowerCase()) {
|
|
12
12
|
case "fk":
|
|
13
13
|
t_value.forEach(({ endpoints }) => {
|
|
14
|
-
endpoints[0].tableName = name
|
|
14
|
+
endpoints[0].tableName = name.name;
|
|
15
|
+
endpoints[0].schemaName = name.schemaName;
|
|
15
16
|
})
|
|
16
17
|
}
|
|
17
18
|
})
|
|
@@ -7,7 +7,7 @@ create_table_normal =
|
|
|
7
7
|
(__ ON __ COMMIT __ (PRESERVE __ ROWS/ DELETE __ ROWS/ DROP))?
|
|
8
8
|
(__ TABLESPACE __ tablespace_name:identifier)?
|
|
9
9
|
_ semicolon _ {
|
|
10
|
-
const table = { name: table_name, fields: [], indexes: [] }
|
|
10
|
+
const table = { name: table_name.name, schemaName: table_name.schemaName, fields: [], indexes: [] }
|
|
11
11
|
// process table_properties
|
|
12
12
|
table_properties.forEach(({ table_property_name, value }) => {
|
|
13
13
|
switch(table_property_name.toLowerCase()) {
|
|
@@ -156,7 +156,8 @@ column_constraint = (CONSTRAINT __ constraint_name:identifier __)?
|
|
|
156
156
|
type: "fk",
|
|
157
157
|
value: {
|
|
158
158
|
endpoint: {
|
|
159
|
-
tableName: reftable,
|
|
159
|
+
tableName: reftable.name,
|
|
160
|
+
schemaName: reftable.schemaName,
|
|
160
161
|
fieldNames: refcolumn ? [refcolumn] : null,
|
|
161
162
|
relation: "1"
|
|
162
163
|
},
|
|
@@ -192,7 +193,8 @@ table_constraint = (CONSTRAINT __ constraint_name:identifier __)?
|
|
|
192
193
|
relation: "*",
|
|
193
194
|
},
|
|
194
195
|
{
|
|
195
|
-
tableName: reftable,
|
|
196
|
+
tableName: reftable.name,
|
|
197
|
+
schemaName: reftable.schemaName,
|
|
196
198
|
fieldNames: refcolumn,// ? refcolumn[key] : null,
|
|
197
199
|
relation: "1",
|
|
198
200
|
},
|
|
@@ -6,7 +6,7 @@ create_table_of =
|
|
|
6
6
|
(__ ON __ COMMIT __ (PRESERVE __ ROWS/ DELETE __ ROWS/ DROP))?
|
|
7
7
|
(__ TABLESPACE __ tablespace_name:identifier)?
|
|
8
8
|
_ semicolon _ {
|
|
9
|
-
const table = { name: table_name, type: type_name}
|
|
9
|
+
const table = { name: table_name.name, schemaName: table_name.schemaName, type: type_name}
|
|
10
10
|
return {
|
|
11
11
|
syntax_name: "create_table_of",
|
|
12
12
|
value: table
|
|
@@ -7,7 +7,7 @@ create_table_partition_of =
|
|
|
7
7
|
(__ ON __ COMMIT __ (PRESERVE __ ROWS/ DELETE __ ROWS/ DROP))?
|
|
8
8
|
(__ TABLESPACE __ tablespace_name:identifier)?
|
|
9
9
|
_ semicolon _ {
|
|
10
|
-
const table = { name: table_name, parent_table: parent_table}
|
|
10
|
+
const table = { name: table_name.name, schemaName: table_name.schemaName, parent_table: parent_table}
|
|
11
11
|
return {
|
|
12
12
|
syntax_name: "create_table_partition_of",
|
|
13
13
|
value: table
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
create_type_enum =
|
|
2
|
-
_ CREATE __ TYPE __
|
|
2
|
+
_ CREATE __ TYPE __ enumName:enum_name __ AS __ ENUM _
|
|
3
3
|
"(" _ labels:labels _ ")"
|
|
4
4
|
_ semicolon _ {
|
|
5
5
|
const values = labels.map(name => ({ name }))
|
|
6
6
|
return {
|
|
7
7
|
syntax_name: "create_type_enum",
|
|
8
8
|
value: {
|
|
9
|
-
|
|
9
|
+
...enumName,
|
|
10
10
|
values,
|
|
11
11
|
}
|
|
12
12
|
}
|
|
@@ -14,4 +14,14 @@
|
|
|
14
14
|
});
|
|
15
15
|
return arrAfterTrim.join(', ');
|
|
16
16
|
}
|
|
17
|
+
|
|
18
|
+
// TODO: support configurable default schema name other than 'public'
|
|
19
|
+
const findTable = (schemaName, tableName) => {
|
|
20
|
+
const realSchemaName = schemaName || 'public';
|
|
21
|
+
const table = tables.find(table => {
|
|
22
|
+
const targetSchemaName = table.schemaName || 'public';
|
|
23
|
+
return targetSchemaName === realSchemaName && table.name === tableName;
|
|
24
|
+
});
|
|
25
|
+
return table;
|
|
26
|
+
};
|
|
17
27
|
}
|
|
@@ -23,6 +23,7 @@ parser = commands:command* {
|
|
|
23
23
|
endpoints: [
|
|
24
24
|
{
|
|
25
25
|
tableName: table.name,
|
|
26
|
+
schemaName: table.schemaName,
|
|
26
27
|
fieldNames: [field.name],
|
|
27
28
|
relation: "*",
|
|
28
29
|
},
|
|
@@ -70,7 +71,7 @@ parser = commands:command* {
|
|
|
70
71
|
case "create_index":
|
|
71
72
|
const { table_name } = value;
|
|
72
73
|
delete value.table_name; // remove table_name from column
|
|
73
|
-
|
|
74
|
+
const table_index = findTable(table_name.schemaName, table_name.name);
|
|
74
75
|
if (table_index.indexes) {
|
|
75
76
|
table_index.indexes.push(value);
|
|
76
77
|
} else {
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
9
9
|
|
|
10
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
10
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
11
11
|
|
|
12
12
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
13
13
|
|
|
@@ -2738,13 +2738,13 @@ function peg$parse(input, options) {
|
|
|
2738
2738
|
}
|
|
2739
2739
|
|
|
2740
2740
|
if (currentProp.onDelete) {
|
|
2741
|
-
refProp = _objectSpread({}, refProp, {
|
|
2741
|
+
refProp = _objectSpread(_objectSpread({}, refProp), {}, {
|
|
2742
2742
|
onDelete: currentProp.onDelete
|
|
2743
2743
|
});
|
|
2744
2744
|
}
|
|
2745
2745
|
|
|
2746
2746
|
if (currentProp.onUpdate) {
|
|
2747
|
-
refProp = _objectSpread({}, refProp, {
|
|
2747
|
+
refProp = _objectSpread(_objectSpread({}, refProp), {}, {
|
|
2748
2748
|
onUpdate: currentProp.onUpdate
|
|
2749
2749
|
});
|
|
2750
2750
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dbml/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "Holistics <dev@holistics.io>",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -15,8 +15,10 @@
|
|
|
15
15
|
"test": "__tests__"
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
|
-
"lib"
|
|
18
|
+
"lib",
|
|
19
|
+
"types"
|
|
19
20
|
],
|
|
21
|
+
"types": "./types/index.d.ts",
|
|
20
22
|
"main": "lib/index.js",
|
|
21
23
|
"publishConfig": {
|
|
22
24
|
"access": "public"
|
|
@@ -54,5 +56,5 @@
|
|
|
54
56
|
"\\.(?!json$)[^.]*$": "jest-raw-loader"
|
|
55
57
|
}
|
|
56
58
|
},
|
|
57
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "bbc1d589c6dcefce089bd6007a24cad2808a3818"
|
|
58
60
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import Database, { NormalizedDatabase } from '../model_structure/database';
|
|
2
|
+
declare class ModelExporter {
|
|
3
|
+
static export(model: Database | NormalizedDatabase, format: 'dbml' | 'mysql' | 'postgres' | 'json' | 'mssql', isNormalized?: boolean): string;
|
|
4
|
+
}
|
|
5
|
+
export default ModelExporter;
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import Schema, { NormalizedSchema, RawSchema } from './schema';
|
|
2
|
+
import Ref, { NormalizedRef } from './ref';
|
|
3
|
+
import Enum, { NormalizedEnum } from './enum';
|
|
4
|
+
import TableGroup, { NormalizedTableGroup } from './tableGroup';
|
|
5
|
+
import Table, { NormalizedTable } from './table';
|
|
6
|
+
import Element from './element';
|
|
7
|
+
import DbState from './dbState';
|
|
8
|
+
import { NormalizedEndpoint } from './endpoint';
|
|
9
|
+
import { NormalizedEnumValue } from './enumValue';
|
|
10
|
+
import { NormalizedField } from './field';
|
|
11
|
+
import { NormalizedIndexColumn } from './indexColumn';
|
|
12
|
+
import { NormalizedIndex } from './indexes';
|
|
13
|
+
export interface Project {
|
|
14
|
+
note: string;
|
|
15
|
+
database_type: string;
|
|
16
|
+
name: string;
|
|
17
|
+
}
|
|
18
|
+
export interface RawDatabase {
|
|
19
|
+
schemas: Schema[];
|
|
20
|
+
tables: Table[];
|
|
21
|
+
enums: Enum[];
|
|
22
|
+
refs: Ref[];
|
|
23
|
+
tableGroups: TableGroup[];
|
|
24
|
+
project: Project;
|
|
25
|
+
}
|
|
26
|
+
declare class Database extends Element {
|
|
27
|
+
dbState: DbState;
|
|
28
|
+
hasDefaultSchema: boolean;
|
|
29
|
+
schemas: Schema[];
|
|
30
|
+
note: string;
|
|
31
|
+
databaseType: string;
|
|
32
|
+
name: string;
|
|
33
|
+
id: number;
|
|
34
|
+
constructor({ schemas, tables, enums, refs, tableGroups, project }: RawDatabase);
|
|
35
|
+
generateId(): void;
|
|
36
|
+
processSchemas(rawSchemas: RawSchema[]): void;
|
|
37
|
+
pushSchema(schema: Schema): void;
|
|
38
|
+
checkSchema(schema: Schema): void;
|
|
39
|
+
processSchemaElements(elements: Schema[] | Table[] | Enum[] | TableGroup[] | Ref[], elementType: any): void;
|
|
40
|
+
findOrCreateSchema(schemaName: string): Schema;
|
|
41
|
+
findTable(rawTable: any): Table;
|
|
42
|
+
export(): {
|
|
43
|
+
schemas: {
|
|
44
|
+
tables: {
|
|
45
|
+
fields: {
|
|
46
|
+
name: string;
|
|
47
|
+
type: any;
|
|
48
|
+
unique: boolean;
|
|
49
|
+
pk: boolean;
|
|
50
|
+
not_null: boolean;
|
|
51
|
+
note: string;
|
|
52
|
+
dbdefault: any;
|
|
53
|
+
increment: boolean;
|
|
54
|
+
}[];
|
|
55
|
+
indexes: {
|
|
56
|
+
columns: {
|
|
57
|
+
type: any;
|
|
58
|
+
value: any;
|
|
59
|
+
}[];
|
|
60
|
+
name: string;
|
|
61
|
+
type: any;
|
|
62
|
+
unique: boolean;
|
|
63
|
+
pk: string;
|
|
64
|
+
note: string;
|
|
65
|
+
}[];
|
|
66
|
+
name: string;
|
|
67
|
+
alias: string;
|
|
68
|
+
note: string;
|
|
69
|
+
headerColor: string;
|
|
70
|
+
}[];
|
|
71
|
+
enums: {
|
|
72
|
+
values: {
|
|
73
|
+
name: string;
|
|
74
|
+
note: string;
|
|
75
|
+
}[];
|
|
76
|
+
name: string;
|
|
77
|
+
note: string;
|
|
78
|
+
}[];
|
|
79
|
+
tableGroups: {
|
|
80
|
+
tables: {
|
|
81
|
+
tableName: string;
|
|
82
|
+
schemaName: string;
|
|
83
|
+
}[];
|
|
84
|
+
name: string;
|
|
85
|
+
}[];
|
|
86
|
+
refs: {
|
|
87
|
+
endpoints: {
|
|
88
|
+
schemaName: string;
|
|
89
|
+
tableName: string;
|
|
90
|
+
fieldNames: string[];
|
|
91
|
+
relation: any;
|
|
92
|
+
}[];
|
|
93
|
+
name: string;
|
|
94
|
+
onDelete: any;
|
|
95
|
+
onUpdate: any;
|
|
96
|
+
}[];
|
|
97
|
+
name: string;
|
|
98
|
+
note: string;
|
|
99
|
+
alias: string;
|
|
100
|
+
}[];
|
|
101
|
+
};
|
|
102
|
+
shallowExport(): {
|
|
103
|
+
hasDefaultSchema: boolean;
|
|
104
|
+
note: string;
|
|
105
|
+
databaseType: string;
|
|
106
|
+
name: string;
|
|
107
|
+
};
|
|
108
|
+
exportChild(): {
|
|
109
|
+
schemas: {
|
|
110
|
+
tables: {
|
|
111
|
+
fields: {
|
|
112
|
+
name: string;
|
|
113
|
+
type: any;
|
|
114
|
+
unique: boolean;
|
|
115
|
+
pk: boolean;
|
|
116
|
+
not_null: boolean;
|
|
117
|
+
note: string;
|
|
118
|
+
dbdefault: any;
|
|
119
|
+
increment: boolean;
|
|
120
|
+
}[];
|
|
121
|
+
indexes: {
|
|
122
|
+
columns: {
|
|
123
|
+
type: any;
|
|
124
|
+
value: any;
|
|
125
|
+
}[];
|
|
126
|
+
name: string;
|
|
127
|
+
type: any;
|
|
128
|
+
unique: boolean;
|
|
129
|
+
pk: string;
|
|
130
|
+
note: string;
|
|
131
|
+
}[];
|
|
132
|
+
name: string;
|
|
133
|
+
alias: string;
|
|
134
|
+
note: string;
|
|
135
|
+
headerColor: string;
|
|
136
|
+
}[];
|
|
137
|
+
enums: {
|
|
138
|
+
values: {
|
|
139
|
+
name: string;
|
|
140
|
+
note: string;
|
|
141
|
+
}[];
|
|
142
|
+
name: string;
|
|
143
|
+
note: string;
|
|
144
|
+
}[];
|
|
145
|
+
tableGroups: {
|
|
146
|
+
tables: {
|
|
147
|
+
tableName: string;
|
|
148
|
+
schemaName: string;
|
|
149
|
+
}[];
|
|
150
|
+
name: string;
|
|
151
|
+
}[];
|
|
152
|
+
refs: {
|
|
153
|
+
endpoints: {
|
|
154
|
+
schemaName: string;
|
|
155
|
+
tableName: string;
|
|
156
|
+
fieldNames: string[];
|
|
157
|
+
relation: any;
|
|
158
|
+
}[];
|
|
159
|
+
name: string;
|
|
160
|
+
onDelete: any;
|
|
161
|
+
onUpdate: any;
|
|
162
|
+
}[];
|
|
163
|
+
name: string;
|
|
164
|
+
note: string;
|
|
165
|
+
alias: string;
|
|
166
|
+
}[];
|
|
167
|
+
};
|
|
168
|
+
exportChildIds(): {
|
|
169
|
+
schemaIds: number[];
|
|
170
|
+
};
|
|
171
|
+
normalize(): NormalizedDatabase;
|
|
172
|
+
}
|
|
173
|
+
export interface NormalizedDatabase {
|
|
174
|
+
database: {
|
|
175
|
+
[_id: number]: {
|
|
176
|
+
id: number;
|
|
177
|
+
hasDefaultSchema: boolean;
|
|
178
|
+
note: string;
|
|
179
|
+
databaseType: string;
|
|
180
|
+
name: string;
|
|
181
|
+
schemaIds: number[];
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
schemas: NormalizedSchema;
|
|
185
|
+
refs: NormalizedRef;
|
|
186
|
+
enums: NormalizedEnum;
|
|
187
|
+
tableGroups: NormalizedTableGroup;
|
|
188
|
+
tables: NormalizedTable;
|
|
189
|
+
endpoints: NormalizedEndpoint;
|
|
190
|
+
enumValues: NormalizedEnumValue;
|
|
191
|
+
indexes: NormalizedIndex;
|
|
192
|
+
indexColumns: NormalizedIndexColumn;
|
|
193
|
+
fields: NormalizedField;
|
|
194
|
+
}
|
|
195
|
+
export default Database;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export default class DbState {
|
|
2
|
+
dbId: number;
|
|
3
|
+
schemaId: number;
|
|
4
|
+
enumId: number;
|
|
5
|
+
tableGroupId: number;
|
|
6
|
+
refId: number;
|
|
7
|
+
tableId: number;
|
|
8
|
+
enumValueId: number;
|
|
9
|
+
endpointId: number;
|
|
10
|
+
indexId: number;
|
|
11
|
+
fieldId: number;
|
|
12
|
+
indexColumnId: number;
|
|
13
|
+
generateId(el: string): any;
|
|
14
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface Token {
|
|
2
|
+
end: {
|
|
3
|
+
column: number;
|
|
4
|
+
line: number;
|
|
5
|
+
offset: number;
|
|
6
|
+
};
|
|
7
|
+
start: {
|
|
8
|
+
column: number;
|
|
9
|
+
line: number;
|
|
10
|
+
offset: number;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
declare class Element {
|
|
14
|
+
token: Token;
|
|
15
|
+
id: number;
|
|
16
|
+
selection: string;
|
|
17
|
+
constructor(token: Token);
|
|
18
|
+
bind(selection: any): void;
|
|
19
|
+
error(message: string): void;
|
|
20
|
+
}
|
|
21
|
+
export default Element;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import Element from './element';
|
|
2
|
+
import Field from './field';
|
|
3
|
+
import Ref from './ref';
|
|
4
|
+
import DbState from './dbState';
|
|
5
|
+
import { NormalizedDatabase } from './database';
|
|
6
|
+
declare class Endpoint extends Element {
|
|
7
|
+
relation: any;
|
|
8
|
+
schemaName: string;
|
|
9
|
+
tableName: string;
|
|
10
|
+
fieldNames: string[];
|
|
11
|
+
fields: Field[];
|
|
12
|
+
ref: Ref;
|
|
13
|
+
dbState: DbState;
|
|
14
|
+
constructor({ tableName, schemaName, fieldNames, relation, token, ref }: {
|
|
15
|
+
tableName: any;
|
|
16
|
+
schemaName: any;
|
|
17
|
+
fieldNames: any;
|
|
18
|
+
relation: any;
|
|
19
|
+
token: any;
|
|
20
|
+
ref: any;
|
|
21
|
+
});
|
|
22
|
+
generateId(): void;
|
|
23
|
+
equals(endpoint: any): boolean;
|
|
24
|
+
compareFields(endpoint: any): boolean;
|
|
25
|
+
export(): {
|
|
26
|
+
schemaName: string;
|
|
27
|
+
tableName: string;
|
|
28
|
+
fieldNames: string[];
|
|
29
|
+
relation: any;
|
|
30
|
+
};
|
|
31
|
+
exportParentIds(): {
|
|
32
|
+
refId: number;
|
|
33
|
+
fieldIds: number[];
|
|
34
|
+
};
|
|
35
|
+
shallowExport(): {
|
|
36
|
+
schemaName: string;
|
|
37
|
+
tableName: string;
|
|
38
|
+
fieldNames: string[];
|
|
39
|
+
relation: any;
|
|
40
|
+
};
|
|
41
|
+
setFields(fieldNames: any, table: any): void;
|
|
42
|
+
normalize(model: NormalizedDatabase): void;
|
|
43
|
+
}
|
|
44
|
+
export interface NormalizedEndpoint {
|
|
45
|
+
[_id: number]: {
|
|
46
|
+
id: number;
|
|
47
|
+
schemaName: string;
|
|
48
|
+
tableName: string;
|
|
49
|
+
fieldNames: string[];
|
|
50
|
+
relation: any;
|
|
51
|
+
refId: number;
|
|
52
|
+
fieldIds: number[];
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export default Endpoint;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { NormalizedDatabase } from './database';
|
|
2
|
+
import DbState from './dbState';
|
|
3
|
+
import Element, { Token } from './element';
|
|
4
|
+
import EnumValue from './enumValue';
|
|
5
|
+
import Field from './field';
|
|
6
|
+
import Schema from './schema';
|
|
7
|
+
interface RawEnum {
|
|
8
|
+
name: string;
|
|
9
|
+
token: Token;
|
|
10
|
+
values: EnumValue[];
|
|
11
|
+
note: string;
|
|
12
|
+
schema: Schema;
|
|
13
|
+
}
|
|
14
|
+
declare class Enum extends Element {
|
|
15
|
+
name: string;
|
|
16
|
+
token: Token;
|
|
17
|
+
values: EnumValue[];
|
|
18
|
+
note: string;
|
|
19
|
+
schema: Schema;
|
|
20
|
+
fields: Field[];
|
|
21
|
+
dbState: DbState;
|
|
22
|
+
id: number;
|
|
23
|
+
constructor({ name, token, values, note, schema }: RawEnum);
|
|
24
|
+
generateId(): void;
|
|
25
|
+
processValues(rawValues: any): void;
|
|
26
|
+
pushValue(value: any): void;
|
|
27
|
+
checkValue(value: any): void;
|
|
28
|
+
pushField(field: any): void;
|
|
29
|
+
checkField(field: any): void;
|
|
30
|
+
export(): {
|
|
31
|
+
values: {
|
|
32
|
+
name: string;
|
|
33
|
+
note: string;
|
|
34
|
+
}[];
|
|
35
|
+
name: string;
|
|
36
|
+
note: string;
|
|
37
|
+
};
|
|
38
|
+
exportChild(): {
|
|
39
|
+
values: {
|
|
40
|
+
name: string;
|
|
41
|
+
note: string;
|
|
42
|
+
}[];
|
|
43
|
+
};
|
|
44
|
+
exportChildIds(): {
|
|
45
|
+
valueIds: number[];
|
|
46
|
+
fieldIds: number[];
|
|
47
|
+
};
|
|
48
|
+
exportParentIds(): {
|
|
49
|
+
schemaId: number;
|
|
50
|
+
};
|
|
51
|
+
shallowExport(): {
|
|
52
|
+
name: string;
|
|
53
|
+
note: string;
|
|
54
|
+
};
|
|
55
|
+
normalize(model: NormalizedDatabase): void;
|
|
56
|
+
}
|
|
57
|
+
export interface NormalizedEnum {
|
|
58
|
+
[_id: number]: {
|
|
59
|
+
id: number;
|
|
60
|
+
name: string;
|
|
61
|
+
note: string;
|
|
62
|
+
valueIds: number[];
|
|
63
|
+
fieldIds: number[];
|
|
64
|
+
schemaId: number;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export default Enum;
|