@dbml/core 2.4.4 → 2.5.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/model_structure/database.js +5 -2
- package/lib/model_structure/enum.js +2 -1
- package/lib/model_structure/enumValue.js +2 -1
- package/lib/model_structure/field.js +4 -3
- package/lib/model_structure/indexes.js +2 -1
- package/lib/model_structure/schema.js +2 -3
- package/lib/model_structure/table.js +2 -1
- package/lib/parse/dbml/parser.pegjs +12 -2
- package/lib/parse/dbmlParser.js +434 -428
- package/lib/parse/mssql/statements/actions.js +10 -6
- package/lib/parse/mssql/statements/statement_types/comments/actions.js +23 -23
- package/lib/parse/mysql/parser.pegjs +5 -5
- package/lib/parse/mysqlParser.js +6 -2
- package/lib/parse/postgresParser.js +1 -1
- package/lib/parse/postgresql/parser.pegjs +2 -2
- package/package.json +2 -2
- package/types/.DS_Store +0 -0
- package/types/model_structure/database.d.ts +3 -2
- package/types/model_structure/element.d.ts +6 -0
- package/types/model_structure/enum.d.ts +3 -2
- package/types/model_structure/enumValue.d.ts +3 -2
- package/types/model_structure/field.d.ts +6 -2
- package/types/model_structure/indexes.d.ts +3 -2
- package/types/model_structure/schema.d.ts +3 -2
- package/types/model_structure/table.d.ts +3 -2
|
@@ -59,16 +59,14 @@ function handleEnums(_enum, ast) {
|
|
|
59
59
|
}).join(', ');
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
function handleComment(comment, ast) {
|
|
63
|
-
if (comment.type === 'table') handleTableNote(comment, ast);else if (comment.type === 'column') handleFieldNote(comment, ast);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
62
|
function handleTableNote(comment, ast) {
|
|
67
63
|
var schemaName = comment.schemaName;
|
|
68
64
|
if (schemaName === 'dbo') schemaName = null; // treat `dbo` as public schema
|
|
69
65
|
|
|
70
66
|
var foundTable = findTable(ast, comment.tableName, schemaName);
|
|
71
|
-
if (foundTable) foundTable.note = comment.note
|
|
67
|
+
if (foundTable) foundTable.note = comment.note ? {
|
|
68
|
+
value: comment.note
|
|
69
|
+
} : null;
|
|
72
70
|
}
|
|
73
71
|
|
|
74
72
|
function handleFieldNote(comment, ast) {
|
|
@@ -79,10 +77,16 @@ function handleFieldNote(comment, ast) {
|
|
|
79
77
|
|
|
80
78
|
if (foundTable) {
|
|
81
79
|
var foundField = findField(foundTable, comment.columnName);
|
|
82
|
-
if (foundField) foundField.note = comment.note
|
|
80
|
+
if (foundField) foundField.note = comment.note ? {
|
|
81
|
+
value: comment.note
|
|
82
|
+
} : null;
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
function handleComment(comment, ast) {
|
|
87
|
+
if (comment.type === 'table') handleTableNote(comment, ast);else if (comment.type === 'column') handleFieldNote(comment, ast);
|
|
88
|
+
}
|
|
89
|
+
|
|
86
90
|
function handleStatement(_statements) {
|
|
87
91
|
var ast = {
|
|
88
92
|
tables: [],
|
|
@@ -1,12 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var isSchema = function isSchema(type) {
|
|
4
|
+
return type.toLowerCase() === 'schema';
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
var isTable = function isTable(type) {
|
|
8
|
+
return type.toLowerCase() === 'table';
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
var isColumn = function isColumn(type) {
|
|
12
|
+
return type.toLowerCase() === 'column';
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
var isValidTableNote = function isValidTableNote(level) {
|
|
16
|
+
return level.length === 2 && isSchema(level[0].type) && isTable(level[1].type);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
var isValidColumnNote = function isValidColumnNote(level) {
|
|
20
|
+
return level.length === 3 && isSchema(level[0].type) && isTable(level[1].type) && isColumn(level[2].type);
|
|
21
|
+
};
|
|
22
|
+
|
|
3
23
|
function handleComment(_ref) {
|
|
4
24
|
var note = _ref.note,
|
|
5
25
|
level = _ref.level;
|
|
6
26
|
var type = 'unsupported';
|
|
7
|
-
var schemaName = null
|
|
8
|
-
|
|
9
|
-
|
|
27
|
+
var schemaName = null;
|
|
28
|
+
var tableName = null;
|
|
29
|
+
var columnName = null;
|
|
10
30
|
|
|
11
31
|
if (isValidTableNote(level)) {
|
|
12
32
|
schemaName = level[0].name;
|
|
@@ -32,26 +52,6 @@ function handleComment(_ref) {
|
|
|
32
52
|
};
|
|
33
53
|
}
|
|
34
54
|
|
|
35
|
-
var isSchema = function isSchema(type) {
|
|
36
|
-
return type.toLowerCase() === 'schema';
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
var isTable = function isTable(type) {
|
|
40
|
-
return type.toLowerCase() === 'table';
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
var isColumn = function isColumn(type) {
|
|
44
|
-
return type.toLowerCase() === 'column';
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
var isValidTableNote = function isValidTableNote(level) {
|
|
48
|
-
return level.length === 2 && isSchema(level[0].type) && isTable(level[1].type);
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
var isValidColumnNote = function isValidColumnNote(level) {
|
|
52
|
-
return level.length === 3 && isSchema(level[0].type) && isTable(level[1].type) && isColumn(level[2].type);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
55
|
module.exports = {
|
|
56
56
|
handleComment: handleComment
|
|
57
57
|
};
|
|
@@ -86,7 +86,7 @@ TableSyntax
|
|
|
86
86
|
|
|
87
87
|
let res = {...table_name, fields};
|
|
88
88
|
|
|
89
|
-
if (options && options.comment) res.note = options.comment;
|
|
89
|
+
if (options && options.comment) res.note = { value: options.comment };
|
|
90
90
|
if (indexes) res.indexes = indexes;
|
|
91
91
|
// return statement
|
|
92
92
|
return res;
|
|
@@ -225,12 +225,12 @@ FieldSettings = fieldSettingsArray:FieldSetting*
|
|
|
225
225
|
{
|
|
226
226
|
const fieldSettings = {};
|
|
227
227
|
fieldSettingsArray.forEach(field => {
|
|
228
|
-
if(field === "null")
|
|
228
|
+
if (field === "null")
|
|
229
229
|
fieldSettings["not_null"] = false;
|
|
230
|
-
else if(field.type === "default")
|
|
230
|
+
else if (field.type === "default" && field.value)
|
|
231
231
|
fieldSettings.dbdefault = field.value;
|
|
232
|
-
else if(field.type === "comment")
|
|
233
|
-
fieldSettings.note = field.value;
|
|
232
|
+
else if (field.type === "comment" && field.value)
|
|
233
|
+
fieldSettings.note = { value: field.value };
|
|
234
234
|
else if (field !== "not_supported") {
|
|
235
235
|
fieldSettings[field] = true;
|
|
236
236
|
}
|
package/lib/parse/mysqlParser.js
CHANGED
|
@@ -197,7 +197,9 @@ function peg$parse(input, options) {
|
|
|
197
197
|
fields: fields
|
|
198
198
|
});
|
|
199
199
|
|
|
200
|
-
if (options && options.comment) res.note =
|
|
200
|
+
if (options && options.comment) res.note = {
|
|
201
|
+
value: options.comment
|
|
202
|
+
};
|
|
201
203
|
if (indexes) res.indexes = indexes; // return statement
|
|
202
204
|
|
|
203
205
|
return res;
|
|
@@ -395,7 +397,9 @@ function peg$parse(input, options) {
|
|
|
395
397
|
peg$c41 = function peg$c41(fieldSettingsArray) {
|
|
396
398
|
var fieldSettings = {};
|
|
397
399
|
fieldSettingsArray.forEach(function (field) {
|
|
398
|
-
if (field === "null") fieldSettings["not_null"] = false;else if (field.type === "default") fieldSettings.dbdefault = field.value;else if (field.type === "comment") fieldSettings.note =
|
|
400
|
+
if (field === "null") fieldSettings["not_null"] = false;else if (field.type === "default" && field.value) fieldSettings.dbdefault = field.value;else if (field.type === "comment" && field.value) fieldSettings.note = {
|
|
401
|
+
value: field.value
|
|
402
|
+
};else if (field !== "not_supported") {
|
|
399
403
|
fieldSettings[field] = true;
|
|
400
404
|
}
|
|
401
405
|
});
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/"use strict";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;}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;}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;}function _toConsumableArray(arr){return _arrayWithoutHoles(arr)||_iterableToArray(arr)||_unsupportedIterableToArray(arr)||_nonIterableSpread();}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen);}function _iterableToArray(iter){if(typeof Symbol!=="undefined"&&Symbol.iterator in Object(iter))return Array.from(iter);}function _arrayWithoutHoles(arr){if(Array.isArray(arr))return _arrayLikeToArray(arr);}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++){arr2[i]=arr[i];}return arr2;}var _=require("lodash"),pluralize=require("pluralize");function peg$subclass(child,parent){function ctor(){this.constructor=child;}ctor.prototype=parent.prototype;child.prototype=new ctor();}function peg$SyntaxError(message,expected,found,location){this.message=message;this.expected=expected;this.found=found;this.location=location;this.name="SyntaxError";if(typeof Error.captureStackTrace==="function"){Error.captureStackTrace(this,peg$SyntaxError);}}peg$subclass(peg$SyntaxError,Error);peg$SyntaxError.buildMessage=function(expected,found){var DESCRIBE_EXPECTATION_FNS={literal:function literal(expectation){return"\""+literalEscape(expectation.text)+"\"";},"class":function _class(expectation){var escapedParts="",i;for(i=0;i<expectation.parts.length;i++){escapedParts+=expectation.parts[i]instanceof Array?classEscape(expectation.parts[i][0])+"-"+classEscape(expectation.parts[i][1]):classEscape(expectation.parts[i]);}return"["+(expectation.inverted?"^":"")+escapedParts+"]";},any:function any(expectation){return"any character";},end:function end(expectation){return"end of input";},other:function other(expectation){return expectation.description;}};function hex(ch){return ch.charCodeAt(0).toString(16).toUpperCase();}function literalEscape(s){return s.replace(/\\/g,'\\\\').replace(/"/g,'\\"').replace(/\0/g,'\\0').replace(/\t/g,'\\t').replace(/\n/g,'\\n').replace(/\r/g,'\\r').replace(/[\x00-\x0F]/g,function(ch){return'\\x0'+hex(ch);}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(ch){return'\\x'+hex(ch);});}function classEscape(s){return s.replace(/\\/g,'\\\\').replace(/\]/g,'\\]').replace(/\^/g,'\\^').replace(/-/g,'\\-').replace(/\0/g,'\\0').replace(/\t/g,'\\t').replace(/\n/g,'\\n').replace(/\r/g,'\\r').replace(/[\x00-\x0F]/g,function(ch){return'\\x0'+hex(ch);}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(ch){return'\\x'+hex(ch);});}function describeExpectation(expectation){return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);}function describeExpected(expected){var descriptions=new Array(expected.length),i,j;for(i=0;i<expected.length;i++){descriptions[i]=describeExpectation(expected[i]);}descriptions.sort();if(descriptions.length>0){for(i=1,j=1;i<descriptions.length;i++){if(descriptions[i-1]!==descriptions[i]){descriptions[j]=descriptions[i];j++;}}descriptions.length=j;}switch(descriptions.length){case 1:return descriptions[0];case 2:return descriptions[0]+" or "+descriptions[1];default:return descriptions.slice(0,-1).join(", ")+", or "+descriptions[descriptions.length-1];}}function describeFound(found){return found?"\""+literalEscape(found)+"\"":"end of input";}return"Expected "+describeExpected(expected)+" but "+describeFound(found)+" found.";};function peg$parse(input,options){options=options!==void 0?options:{};var peg$FAILED={},peg$startRuleFunctions={parser:peg$parseparser},peg$startRuleFunction=peg$parseparser,peg$c0=function peg$c0(commands){commands.forEach(function(cmd){var command_name=cmd.command_name,_cmd$value=cmd.value,syntax_name=_cmd$value.syntax_name,value=_cmd$value.value,warning=cmd.warning;switch(command_name.toLowerCase()){case"create_table":var table=value;switch(syntax_name.toLowerCase()){case"create_table_normal":tables.push(table);var pkList=[];table.fields.forEach(function(field){// process inline_refs
|
|
6
6
|
if(field.inline_refs){refs.push.apply(refs,_toConsumableArray(field.inline_refs.map(function(ref){return{name:ref.name,endpoints:[{tableName:table.name,schemaName:table.schemaName,fieldNames:[field.name],relation:"*"},ref.endpoint],onDelete:ref.onDelete,onUpdate:ref.onUpdate};})));}// process composite primary key, if primary key is in composite form, push it into indexes
|
|
7
7
|
if(field.pk){pkList.push(field);}});if(pkList.length>1){table.fields=table.fields.map(function(field){delete field.pk;return field;});var index={columns:pkList.map(function(field){return{value:field.name,type:'column'};}),pk:true};if(table.indexes){table.indexes.push(index);}else{table.indexes=[index];}}break;case"create_table_of":break;case"create_table_partition_of":break;}break;case"create_index":var table_name=value.table_name;delete value.table_name;// remove table_name from column
|
|
8
|
-
var table_index=findTable(table_name.schemaName,table_name.name);if(table_index.indexes){table_index.indexes.push(value);}else{table_index.indexes=[value];}break;case"create_type":switch(syntax_name.toLowerCase()){case"create_type_enum":enums.push(value);break;case"create_type_range":break;}break;case"alter_table":switch(syntax_name.toLowerCase()){case"alter_table_action":value.forEach(function(v){var type=v.type;switch(type.toLowerCase()){case"fk":v.t_value.forEach(function(endpoints){refs.push(endpoints);});}});break;}break;case"comment":switch(syntax_name.toLowerCase()){case"column":{var schemaName=value.schemaName,tableName=value.tableName,columnName=value.columnName;var foundTable=findTable(schemaName,tableName);if(foundTable){var foundField=findField(foundTable,columnName);if(foundField)foundField.note=value.text;}break;}case"table":{var _value$table_name=value.table_name,_schemaName=_value$table_name.schemaName,_tableName=_value$table_name.name;var _foundTable=findTable(_schemaName,_tableName);if(_foundTable)_foundTable.note=value.text;break;}}break;case"ignore_syntax":// warnings.push(warning);
|
|
8
|
+
var table_index=findTable(table_name.schemaName,table_name.name);if(table_index.indexes){table_index.indexes.push(value);}else{table_index.indexes=[value];}break;case"create_type":switch(syntax_name.toLowerCase()){case"create_type_enum":enums.push(value);break;case"create_type_range":break;}break;case"alter_table":switch(syntax_name.toLowerCase()){case"alter_table_action":value.forEach(function(v){var type=v.type;switch(type.toLowerCase()){case"fk":v.t_value.forEach(function(endpoints){refs.push(endpoints);});}});break;}break;case"comment":switch(syntax_name.toLowerCase()){case"column":{var schemaName=value.schemaName,tableName=value.tableName,columnName=value.columnName;var foundTable=findTable(schemaName,tableName);if(foundTable){var foundField=findField(foundTable,columnName);if(foundField)foundField.note=value.text?{value:value.text}:null;}break;}case"table":{var _value$table_name=value.table_name,_schemaName=_value$table_name.schemaName,_tableName=_value$table_name.name;var _foundTable=findTable(_schemaName,_tableName);if(_foundTable)_foundTable.note=value.text?{value:value.text}:null;break;}}break;case"ignore_syntax":// warnings.push(warning);
|
|
9
9
|
break;}});return{tables:tables,refs:refs,enums:enums};},peg$c1="create",peg$c2=peg$literalExpectation("CREATE",true),peg$c3="alter",peg$c4=peg$literalExpectation("ALTER",true),peg$c5="unique",peg$c6=peg$literalExpectation("UNIQUE",true),peg$c7="index",peg$c8=peg$literalExpectation("INDEX",true),peg$c9="type",peg$c10=peg$literalExpectation("TYPE",true),peg$c11="enum",peg$c12=peg$literalExpectation("ENUM",true),peg$c13="concurrenly",peg$c14=peg$literalExpectation("CONCURRENLY",true),peg$c15="foreign",peg$c16=peg$literalExpectation("FOREIGN",true),peg$c17="key",peg$c18=peg$literalExpectation("KEY",true),peg$c19="references",peg$c20=peg$literalExpectation("REFERENCES",true),peg$c21="on",peg$c22=peg$literalExpectation("ON",true),peg$c23="using",peg$c24=peg$literalExpectation("USING",true),peg$c25="table",peg$c26=peg$literalExpectation("TABLE",true),peg$c27="if",peg$c28=peg$literalExpectation("IF",true),peg$c29="not",peg$c30=peg$literalExpectation("NOT",true),peg$c31="exists",peg$c32=peg$literalExpectation("EXISTS",true),peg$c33="global",peg$c34=peg$literalExpectation("GLOBAL",true),peg$c35="local",peg$c36=peg$literalExpectation("LOCAL",true),peg$c37="temporary",peg$c38=peg$literalExpectation("TEMPORARY",true),peg$c39="temp",peg$c40=peg$literalExpectation("TEMP",true),peg$c41="unlogged",peg$c42=peg$literalExpectation("UNLOGGED",true),peg$c43="collate",peg$c44=peg$literalExpectation("COLLATE",true),peg$c45="collation",peg$c46=peg$literalExpectation("COLLATION",true),peg$c47="partition",peg$c48=peg$literalExpectation("PARTITION",true),peg$c49="by",peg$c50=peg$literalExpectation("BY",true),peg$c51="range",peg$c52=peg$literalExpectation("RANGE",true),peg$c53="list",peg$c54=peg$literalExpectation("LIST",true),peg$c55="hash",peg$c56=peg$literalExpectation("HASH",true),peg$c57="like",peg$c58=peg$literalExpectation("LIKE",true),peg$c59="inherits",peg$c60=peg$literalExpectation("INHERITS",true),peg$c61="inherit",peg$c62=peg$literalExpectation("INHERIT",true),peg$c63="with",peg$c64=peg$literalExpectation("WITH",true),peg$c65="without",peg$c66=peg$literalExpectation("WITHOUT",true),peg$c67="oids",peg$c68=peg$literalExpectation("OIDS",true),peg$c69="commit",peg$c70=peg$literalExpectation("COMMIT",true),peg$c71="preserve",peg$c72=peg$literalExpectation("PRESERVE",true),peg$c73="rows",peg$c74=peg$literalExpectation("ROWS",true),peg$c75="delete",peg$c76=peg$literalExpectation("DELETE",true),peg$c77="drop",peg$c78=peg$literalExpectation("DROP",true),peg$c79="tablespace",peg$c80=peg$literalExpectation("TABLESPACE",true),peg$c81="constraint",peg$c82=peg$literalExpectation("CONSTRAINT",true),peg$c83="no",peg$c84=peg$literalExpectation("NO",true),peg$c85="null",peg$c86=peg$literalExpectation("NULL",true),peg$c87="check",peg$c88=peg$literalExpectation("CHECK",true),peg$c89="default",peg$c90=peg$literalExpectation("DEFAULT",true),peg$c91="primary",peg$c92=peg$literalExpectation("PRIMARY",true),peg$c93="match",peg$c94=peg$literalExpectation("MATCH",true),peg$c95="full",peg$c96=peg$literalExpectation("FULL",true),peg$c97="partial",peg$c98=peg$literalExpectation("PARTIAL",true),peg$c99="simple",peg$c100=peg$literalExpectation("SIMPLE",true),peg$c101="update",peg$c102=peg$literalExpectation("UPDATE",true),peg$c103="deferrable",peg$c104=peg$literalExpectation("DEFERRABLE",true),peg$c105="initially",peg$c106=peg$literalExpectation("INITIALLY",true),peg$c107="deferred",peg$c108=peg$literalExpectation("DEFERRED",true),peg$c109="immediate",peg$c110=peg$literalExpectation("IMMEDIATE",true),peg$c111="exclude",peg$c112=peg$literalExpectation("EXCLUDE",true),peg$c113="where",peg$c114=peg$literalExpectation("WHERE",true),peg$c115="including",peg$c116=peg$literalExpectation("INCLUDING",true),peg$c117="excluding",peg$c118=peg$literalExpectation("EXCLUDING",true),peg$c119="comments",peg$c120=peg$literalExpectation("COMMENTS",true),peg$c121="constraints",peg$c122=peg$literalExpectation("CONSTRAINTS",true),peg$c123="generated",peg$c124=peg$literalExpectation("GENERATED",true),peg$c125="always",peg$c126=peg$literalExpectation("ALWAYS",true),peg$c127="as",peg$c128=peg$literalExpectation("AS",true),peg$c129="add",peg$c130=peg$literalExpectation("ADD",true),peg$c131="only",peg$c132=peg$literalExpectation("ONLY",true),peg$c133="defaults",peg$c134=peg$literalExpectation("DEFAULTS",true),peg$c135="identity",peg$c136=peg$literalExpectation("IDENTITY",true),peg$c137="indexes",peg$c138=peg$literalExpectation("INDEXES",true),peg$c139="statistics",peg$c140=peg$literalExpectation("STATISTICS",true),peg$c141="storage",peg$c142=peg$literalExpectation("STORAGE",true),peg$c143="include",peg$c144=peg$literalExpectation("INCLUDE",true),peg$c145="includes",peg$c146=peg$literalExpectation("INCLUDES",true),peg$c147="all",peg$c148=peg$literalExpectation("ALL",true),peg$c149="of",peg$c150=peg$literalExpectation("OF",true),peg$c151="options",peg$c152=peg$literalExpectation("OPTIONS",true),peg$c153="for",peg$c154=peg$literalExpectation("FOR",true),peg$c155="values",peg$c156=peg$literalExpectation("VALUES",true),peg$c157="in",peg$c158=peg$literalExpectation("IN",true),peg$c159="from",peg$c160=peg$literalExpectation("FROM",true),peg$c161="to",peg$c162=peg$literalExpectation("TO",true),peg$c163="modulus",peg$c164=peg$literalExpectation("MODULUS",true),peg$c165="remainder",peg$c166=peg$literalExpectation("REMAINDER",true),peg$c167="true",peg$c168=peg$literalExpectation("TRUE",true),peg$c169="false",peg$c170=peg$literalExpectation("FALSE",true),peg$c171="maxvalue",peg$c172=peg$literalExpectation("MAXVALUE",true),peg$c173="minvalue",peg$c174=peg$literalExpectation("MINVALUE",true),peg$c175="subtype",peg$c176=peg$literalExpectation("SUBTYPE",true),peg$c177="subtype_opclass",peg$c178=peg$literalExpectation("SUBTYPE_OPCLASS",true),peg$c179="canonical",peg$c180=peg$literalExpectation("CANONICAL",true),peg$c181="subtype_diff",peg$c182=peg$literalExpectation("SUBTYPE_DIFF",true),peg$c183="valid",peg$c184=peg$literalExpectation("VALID",true),peg$c185="column",peg$c186=peg$literalExpectation("COLUMN",true),peg$c187="set",peg$c188=peg$literalExpectation("SET",true),peg$c189="data",peg$c190=peg$literalExpectation("DATA",true),peg$c191="reset",peg$c192=peg$literalExpectation("RESET",true),peg$c193="plain",peg$c194=peg$literalExpectation("PLAIN",true),peg$c195="external",peg$c196=peg$literalExpectation("EXTERNAL",true),peg$c197="extended",peg$c198=peg$literalExpectation("EXTENDED",true),peg$c199="main",peg$c200=peg$literalExpectation("MAIN",true),peg$c201="asc",peg$c202=peg$literalExpectation("ASC",true),peg$c203="desc",peg$c204=peg$literalExpectation("DESC",true),peg$c205="nulls",peg$c206=peg$literalExpectation("NULLS",true),peg$c207="first",peg$c208=peg$literalExpectation("FIRST",true),peg$c209="last",peg$c210=peg$literalExpectation("LAST",true),peg$c211="comment",peg$c212=peg$literalExpectation("COMMENT",true),peg$c213="IS",peg$c214=peg$literalExpectation("IS",false),peg$c215="insert",peg$c216=peg$literalExpectation("INSERT",true),peg$c217="select",peg$c218=peg$literalExpectation("SELECT",true),peg$c219="use",peg$c220=peg$literalExpectation("USE",true),peg$c221="sequence",peg$c222=peg$literalExpectation("SEQUENCE",true),peg$c223="schema",peg$c224=peg$literalExpectation("SCHEMA",true),peg$c225="view",peg$c226=peg$literalExpectation("VIEW",true),peg$c227="rename",peg$c228=peg$literalExpectation("RENAME",true),peg$c229="owned",peg$c230=peg$literalExpectation("OWNED",true),peg$c231="attach",peg$c232=peg$literalExpectation("ATTACH",true),peg$c233="detach",peg$c234=peg$literalExpectation("DETACH",true),peg$c235=peg$otherExpectation("expression"),peg$c236=function peg$c236(factors){return removeReduntdantSpNewline(_.flattenDeep(factors).join(""));},peg$c237="(",peg$c238=peg$literalExpectation("(",false),peg$c239=")",peg$c240=peg$literalExpectation(")",false),peg$c241=",",peg$c242=peg$literalExpectation(",",false),peg$c243=");",peg$c244=peg$literalExpectation(");",false),peg$c245=peg$anyExpectation(),peg$c246=function peg$c246(factors){return _.flattenDeep(factors).join("");},peg$c247=/^["',.a-z0-9_+-:<>=!*]/i,peg$c248=peg$classExpectation(["\"","'",",",".",["a","z"],["0","9"],"_",["+",":"],"<",">","=","!","*"],false,true),peg$c249=/^['.a-z0-9_+\-]/i,peg$c250=peg$classExpectation(["'",".",["a","z"],["0","9"],"_","+","-"],false,true),peg$c251=peg$otherExpectation("valid column name"),peg$c252=".",peg$c253=peg$literalExpectation(".",false),peg$c254=function peg$c254(names){var dbName=null;var schemaName=null;if(names&&names.length>0){if(names.length===1)schemaName=names[0][0];else{dbName=names[0][0];schemaName=names[1][0];}}return{dbName:dbName,schemaName:schemaName};},peg$c255=peg$otherExpectation("valid table name"),peg$c256=function peg$c256(pathName,name){return _objectSpread(_objectSpread({},pathName),{},{name:name});},peg$c257=peg$otherExpectation("valid enum name"),peg$c258=peg$otherExpectation("string"),peg$c259="'",peg$c260=peg$literalExpectation("'",false),peg$c261=function peg$c261(c){return c.join('');},peg$c262="''",peg$c263=peg$literalExpectation("''",false),peg$c264=function peg$c264(){return"'";},peg$c265=/^[^']/,peg$c266=peg$classExpectation(["'"],true,false),peg$c267="\"",peg$c268=peg$literalExpectation("\"",false),peg$c269=function peg$c269(c){return c.join('');},peg$c270="\"\"",peg$c271=peg$literalExpectation("\"\"",false),peg$c272=function peg$c272(){return'"';},peg$c273=/^[^"]/,peg$c274=peg$classExpectation(["\""],true,false),peg$c275=peg$otherExpectation("number"),peg$c276="e",peg$c277=peg$literalExpectation("e",false),peg$c278="+",peg$c279=peg$literalExpectation("+",false),peg$c280="-",peg$c281=peg$literalExpectation("-",false),peg$c282=function peg$c282(a){return _.flattenDeep(a).filter(function(ele){return ele;}).join('');},peg$c283=function peg$c283(d){return d.join('');},peg$c284=/^[0-9]/,peg$c285=peg$classExpectation([["0","9"]],false,false),peg$c286=peg$otherExpectation("VALID TYPE"),peg$c287="character",peg$c288=peg$literalExpectation("CHARACTER",true),peg$c289="varying",peg$c290=peg$literalExpectation("VARYING",true),peg$c291=function peg$c291(c1,c2,args,dimensions){var c="".concat(c1," ").concat(c2);c=args?c+'('+args[1]+')':c;return{type_name:c+(dimensions?dimensions.map(function(dimension){return'['+dimension+']';}).join(''):''),args:args?args[1]:null};},peg$c292="timestamptz",peg$c293=peg$literalExpectation("timestamptz",true),peg$c294=function peg$c294(number,dimensions){var args=number?number[2]:null;return{type_name:(args!==null?"timestamptz(".concat(args,")"):"timestamptz")+(dimensions?dimensions.map(function(dimension){return'['+dimension+']';}).join(''):''),args:args};},peg$c295="timestamp",peg$c296=peg$literalExpectation("timestamp",true),peg$c297=peg$literalExpectation("without",true),peg$c298=peg$literalExpectation("with",true),peg$c299="time",peg$c300=peg$literalExpectation("time",true),peg$c301="zone",peg$c302=peg$literalExpectation("zone",true),peg$c303=function peg$c303(number,dimensions){var args=number?number[2]:null;return{type_name:(args!==null?"timestamp(".concat(args,")"):"timestamp")+(dimensions?dimensions.map(function(dimension){return'['+dimension+']';}).join(''):''),args:args};},peg$c304="timetz",peg$c305=peg$literalExpectation("timetz",true),peg$c306=function peg$c306(number,dimensions){var args=number?number[2]:null;return{type_name:(args!==null?"timetz(".concat(args,")"):"timetz")+(dimensions?dimensions.map(function(dimension){return'['+dimension+']';}).join(''):''),args:args};},peg$c307=function peg$c307(number,dimensions){var args=number?number[2]:null;return{type_name:(args!==null?"time(".concat(args,")"):"time")+(dimensions?dimensions.map(function(dimension){return'['+dimension+']';}).join(''):''),args:args};},peg$c308=function peg$c308(c,dimensions){var args=c.args;return{type_name:c.type_name+(dimensions?dimensions.map(function(dimension){return'['+dimension+']';}).join(''):''),schemaName:c.schemaName,args:args};},peg$c309=/^[^"\n]/,peg$c310=peg$classExpectation(["\"","\n"],true,false),peg$c311=function peg$c311(c){return{type_name:c.join(""),args:null};},peg$c312=function peg$c312(pathName,c,args){var type_name=c.join("");args=args?args[1]:null;if(type_name.toLowerCase()!=='enum'){type_name=args?type_name+'('+args+')':type_name;}return _objectSpread(_objectSpread({},pathName),{},{type_name:type_name,args:args});},peg$c313="array",peg$c314=peg$literalExpectation("array",true),peg$c315="[",peg$c316=peg$literalExpectation("[",false),peg$c317="]",peg$c318=peg$literalExpectation("]",false),peg$c319=function peg$c319(singledimenson){return[singledimenson?singledimenson[3]:''];},peg$c320=function peg$c320(multidimenson){// this will parse into Array(Array('[', _ , expression , _ ']'))
|
|
10
10
|
return multidimenson.map(function(dimension){return dimension[2];});},peg$c321=function peg$c321(val){return{value:val,type:'string'};},peg$c322=function peg$c322(val){return{value:val,type:'number'};},peg$c323=function peg$c323(val){return{value:val,type:'boolean'};},peg$c324=function peg$c324(val){var str=val;if(val&&val.length>2&&val[0]==='('&&val[val.length-1]===')'){str=val.slice(1,-1);}return{value:str,type:'expression'};},peg$c325=" ",peg$c326=peg$literalExpectation(" ",false),peg$c327="\t",peg$c328=peg$literalExpectation("\t",false),peg$c329=";",peg$c330=peg$literalExpectation(";",false),peg$c331=peg$otherExpectation("endline"),peg$c332=peg$otherExpectation("newline"),peg$c333="\r\n",peg$c334=peg$literalExpectation("\r\n",false),peg$c335="\n",peg$c336=peg$literalExpectation("\n",false),peg$c337=peg$otherExpectation("space"),peg$c338=peg$otherExpectation("comment"),peg$c339="--",peg$c340=peg$literalExpectation("--",false),peg$c341=/^[^\n]/,peg$c342=peg$classExpectation(["\n"],true,false),peg$c343="/*",peg$c344=peg$literalExpectation("/*",false),peg$c345="*/",peg$c346=peg$literalExpectation("*/",false),peg$c347=peg$otherExpectation("letter, number or underscore"),peg$c348=/^[a-z0-9_]/i,peg$c349=peg$classExpectation([["a","z"],["0","9"],"_"],false,true),peg$c350="&&",peg$c351=peg$literalExpectation("&&",false),peg$c352="=",peg$c353=peg$literalExpectation("=",false),peg$c354=function peg$c354(table_name,table_properties){var table={name:table_name.name,schemaName:table_name.schemaName,fields:[],indexes:[]};// process table_properties
|
|
11
11
|
table_properties.forEach(function(_ref){var table_property_name=_ref.table_property_name,value=_ref.value;switch(table_property_name.toLowerCase()){case"column":// if column contains inline_refs
|
|
@@ -112,14 +112,14 @@ parser = commands:command* {
|
|
|
112
112
|
const foundTable = findTable(schemaName, tableName);
|
|
113
113
|
if (foundTable) {
|
|
114
114
|
const foundField = findField(foundTable, columnName);
|
|
115
|
-
if (foundField) foundField.note = value.text;
|
|
115
|
+
if (foundField) foundField.note = value.text ? { value: value.text } : null;
|
|
116
116
|
}
|
|
117
117
|
break;
|
|
118
118
|
}
|
|
119
119
|
case "table": {
|
|
120
120
|
const { schemaName, name: tableName } = value.table_name;
|
|
121
121
|
const foundTable = findTable(schemaName, tableName);
|
|
122
|
-
if (foundTable) foundTable.note = value.text;
|
|
122
|
+
if (foundTable) foundTable.note = value.text ? { value: value.text } : null;
|
|
123
123
|
break;
|
|
124
124
|
}
|
|
125
125
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dbml/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "Holistics <dev@holistics.io>",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"\\.(?!json$)[^.]*$": "jest-raw-loader"
|
|
57
57
|
}
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "b78340400449b8ef88f785556916a3a91c925c9a"
|
|
60
60
|
}
|
package/types/.DS_Store
ADDED
|
Binary file
|
|
@@ -3,7 +3,7 @@ import Ref, { NormalizedRef } from './ref';
|
|
|
3
3
|
import Enum, { NormalizedEnum } from './enum';
|
|
4
4
|
import TableGroup, { NormalizedTableGroup } from './tableGroup';
|
|
5
5
|
import Table, { NormalizedTable } from './table';
|
|
6
|
-
import Element from './element';
|
|
6
|
+
import Element, { RawNote, Token } from './element';
|
|
7
7
|
import DbState from './dbState';
|
|
8
8
|
import { NormalizedEndpoint } from './endpoint';
|
|
9
9
|
import { NormalizedEnumValue } from './enumValue';
|
|
@@ -11,7 +11,7 @@ import { NormalizedField } from './field';
|
|
|
11
11
|
import { NormalizedIndexColumn } from './indexColumn';
|
|
12
12
|
import { NormalizedIndex } from './indexes';
|
|
13
13
|
export interface Project {
|
|
14
|
-
note:
|
|
14
|
+
note: RawNote;
|
|
15
15
|
database_type: string;
|
|
16
16
|
name: string;
|
|
17
17
|
}
|
|
@@ -28,6 +28,7 @@ declare class Database extends Element {
|
|
|
28
28
|
hasDefaultSchema: boolean;
|
|
29
29
|
schemas: Schema[];
|
|
30
30
|
note: string;
|
|
31
|
+
noteToken: Token;
|
|
31
32
|
databaseType: string;
|
|
32
33
|
name: string;
|
|
33
34
|
id: number;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NormalizedDatabase } from './database';
|
|
2
2
|
import DbState from './dbState';
|
|
3
|
-
import Element, { Token } from './element';
|
|
3
|
+
import Element, { Token, RawNote } from './element';
|
|
4
4
|
import EnumValue from './enumValue';
|
|
5
5
|
import Field from './field';
|
|
6
6
|
import Schema from './schema';
|
|
@@ -8,7 +8,7 @@ interface RawEnum {
|
|
|
8
8
|
name: string;
|
|
9
9
|
token: Token;
|
|
10
10
|
values: EnumValue[];
|
|
11
|
-
note:
|
|
11
|
+
note: RawNote;
|
|
12
12
|
schema: Schema;
|
|
13
13
|
}
|
|
14
14
|
declare class Enum extends Element {
|
|
@@ -16,6 +16,7 @@ declare class Enum extends Element {
|
|
|
16
16
|
token: Token;
|
|
17
17
|
values: EnumValue[];
|
|
18
18
|
note: string;
|
|
19
|
+
noteToken: Token;
|
|
19
20
|
schema: Schema;
|
|
20
21
|
fields: Field[];
|
|
21
22
|
dbState: DbState;
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { NormalizedDatabase } from './database';
|
|
2
2
|
import DbState from './dbState';
|
|
3
|
-
import Element, { Token } from './element';
|
|
3
|
+
import Element, { Token, RawNote } from './element';
|
|
4
4
|
import Enum from './enum';
|
|
5
5
|
interface RawEnumValue {
|
|
6
6
|
name: string;
|
|
7
7
|
token: Token;
|
|
8
|
-
note:
|
|
8
|
+
note: RawNote;
|
|
9
9
|
_enum: Enum;
|
|
10
10
|
}
|
|
11
11
|
declare class EnumValue extends Element {
|
|
12
12
|
name: string;
|
|
13
13
|
note: string;
|
|
14
|
+
noteToken: Token;
|
|
14
15
|
_enum: Enum;
|
|
15
16
|
dbState: DbState;
|
|
16
17
|
constructor({ name, token, note, _enum }: RawEnumValue);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NormalizedDatabase } from './database';
|
|
2
2
|
import DbState from './dbState';
|
|
3
|
-
import Element, { Token } from './element';
|
|
3
|
+
import Element, { Token, RawNote } from './element';
|
|
4
4
|
import Endpoint from './endpoint';
|
|
5
5
|
import Enum from './enum';
|
|
6
6
|
import Table from './table';
|
|
@@ -11,7 +11,7 @@ interface RawField {
|
|
|
11
11
|
pk: boolean;
|
|
12
12
|
token: Token;
|
|
13
13
|
not_null: boolean;
|
|
14
|
-
note:
|
|
14
|
+
note: RawNote;
|
|
15
15
|
dbdefault: any;
|
|
16
16
|
increment: boolean;
|
|
17
17
|
table: Table;
|
|
@@ -24,6 +24,7 @@ declare class Field extends Element {
|
|
|
24
24
|
dbState: DbState;
|
|
25
25
|
not_null: boolean;
|
|
26
26
|
note: string;
|
|
27
|
+
noteToken: Token;
|
|
27
28
|
dbdefault: any;
|
|
28
29
|
increment: boolean;
|
|
29
30
|
table: Table;
|
|
@@ -72,6 +73,9 @@ export interface NormalizedField {
|
|
|
72
73
|
note: string;
|
|
73
74
|
dbdefault: any;
|
|
74
75
|
increment: boolean;
|
|
76
|
+
tableId: number;
|
|
77
|
+
endpointIds: number[];
|
|
78
|
+
enumId: number;
|
|
75
79
|
};
|
|
76
80
|
}
|
|
77
81
|
export default Field;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NormalizedDatabase } from './database';
|
|
2
2
|
import DbState from './dbState';
|
|
3
|
-
import Element, { Token } from './element';
|
|
3
|
+
import Element, { RawNote, Token } from './element';
|
|
4
4
|
import IndexColumn from './indexColumn';
|
|
5
5
|
import Table from './table';
|
|
6
6
|
interface RawIndex {
|
|
@@ -9,7 +9,7 @@ interface RawIndex {
|
|
|
9
9
|
unique: boolean;
|
|
10
10
|
pk: string;
|
|
11
11
|
name: string;
|
|
12
|
-
note:
|
|
12
|
+
note: RawNote;
|
|
13
13
|
table: Table;
|
|
14
14
|
token: Token;
|
|
15
15
|
}
|
|
@@ -20,6 +20,7 @@ declare class Index extends Element {
|
|
|
20
20
|
pk: string;
|
|
21
21
|
name: string;
|
|
22
22
|
note: string;
|
|
23
|
+
noteToken: Token;
|
|
23
24
|
table: Table;
|
|
24
25
|
dbState: DbState;
|
|
25
26
|
constructor({ columns, type, unique, pk, token, name, note, table }: RawIndex);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Table from './table';
|
|
2
|
-
import Element, { Token } from './element';
|
|
2
|
+
import Element, { RawNote, Token } from './element';
|
|
3
3
|
import Enum from './enum';
|
|
4
4
|
import TableGroup from './tableGroup';
|
|
5
5
|
import Ref from './ref';
|
|
@@ -8,7 +8,7 @@ import DbState from './dbState';
|
|
|
8
8
|
export interface RawSchema {
|
|
9
9
|
name: string;
|
|
10
10
|
alias?: string;
|
|
11
|
-
note?:
|
|
11
|
+
note?: RawNote;
|
|
12
12
|
tables?: Table[];
|
|
13
13
|
refs?: Ref[];
|
|
14
14
|
enums?: Enum[];
|
|
@@ -20,6 +20,7 @@ declare class Schema extends Element {
|
|
|
20
20
|
name: string;
|
|
21
21
|
alias: string;
|
|
22
22
|
note: string;
|
|
23
|
+
noteToken: Token;
|
|
23
24
|
tables: Table[];
|
|
24
25
|
refs: Ref[];
|
|
25
26
|
enums: Enum[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Element, { Token } from './element';
|
|
1
|
+
import Element, { RawNote, Token } from './element';
|
|
2
2
|
import Field from './field';
|
|
3
3
|
import Index from './indexes';
|
|
4
4
|
import Schema from './schema';
|
|
@@ -8,7 +8,7 @@ import { NormalizedDatabase } from './database';
|
|
|
8
8
|
interface RawTable {
|
|
9
9
|
name: string;
|
|
10
10
|
alias: string;
|
|
11
|
-
note:
|
|
11
|
+
note: RawNote;
|
|
12
12
|
fields: Field[];
|
|
13
13
|
indexes: Index[];
|
|
14
14
|
schema: Schema;
|
|
@@ -19,6 +19,7 @@ declare class Table extends Element {
|
|
|
19
19
|
name: string;
|
|
20
20
|
alias: string;
|
|
21
21
|
note: string;
|
|
22
|
+
noteToken: Token;
|
|
22
23
|
fields: Field[];
|
|
23
24
|
indexes: Index[];
|
|
24
25
|
schema: Schema;
|