@dbml/core
Advanced tools
Comparing version 3.1.2 to 3.1.3-alpha.0
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.TABLE_GROUP = exports.TABLE = exports.REF = exports.ENUM = exports.DEFAULT_SCHEMA_NAME = void 0; | ||
exports.TABLE_GROUP = exports.TABLE = exports.REF = exports.NOTE = exports.ENUM = exports.DEFAULT_SCHEMA_NAME = void 0; | ||
var DEFAULT_SCHEMA_NAME = 'public'; | ||
@@ -12,2 +12,4 @@ exports.DEFAULT_SCHEMA_NAME = DEFAULT_SCHEMA_NAME; | ||
exports.TABLE = TABLE; | ||
var NOTE = 'note'; | ||
exports.NOTE = NOTE; | ||
var ENUM = 'enum'; | ||
@@ -14,0 +16,0 @@ exports.ENUM = ENUM; |
@@ -14,2 +14,3 @@ "use strict"; | ||
var _table = _interopRequireDefault(require("./table")); | ||
var _note = _interopRequireDefault(require("./note")); | ||
var _element = _interopRequireDefault(require("./element")); | ||
@@ -45,2 +46,4 @@ var _config = require("./config"); | ||
tables = _ref$tables === void 0 ? [] : _ref$tables, | ||
_ref$notes = _ref.notes, | ||
notes = _ref$notes === void 0 ? [] : _ref$notes, | ||
_ref$enums = _ref.enums, | ||
@@ -62,2 +65,3 @@ enums = _ref$enums === void 0 ? [] : _ref$enums, | ||
_this.schemas = []; | ||
_this.notes = []; | ||
_this.note = project.note ? (0, _lodash.get)(project, 'note.value', project.note) : null; | ||
@@ -68,3 +72,3 @@ _this.noteToken = project.note ? (0, _lodash.get)(project, 'note.token', project.noteToken) : null; | ||
_this.aliases = aliases; | ||
_this.processNotes(notes); | ||
// The process order is important. Do not change ! | ||
@@ -74,2 +78,3 @@ _this.processSchemas(schemas); | ||
_this.processSchemaElements(tables, _config.TABLE); | ||
_this.processSchemaElements(notes, _config.NOTE); | ||
_this.processSchemaElements(refs, _config.REF); | ||
@@ -85,8 +90,33 @@ _this.processSchemaElements(tableGroups, _config.TABLE_GROUP); | ||
}, { | ||
key: "processNotes", | ||
value: function processNotes(rawNotes) { | ||
var _this2 = this; | ||
rawNotes.forEach(function (note) { | ||
_this2.pushNote(new _note["default"](_objectSpread(_objectSpread({}, note), {}, { | ||
database: _this2 | ||
}))); | ||
}); | ||
} | ||
}, { | ||
key: "pushNote", | ||
value: function pushNote(note) { | ||
this.checkNote(note); | ||
this.notes.push(note); | ||
} | ||
}, { | ||
key: "checkNote", | ||
value: function checkNote(note) { | ||
if (this.notes.some(function (n) { | ||
return n.name === note.name; | ||
})) { | ||
note.error("Notes ".concat(note.name, " existed")); | ||
} | ||
} | ||
}, { | ||
key: "processSchemas", | ||
value: function processSchemas(rawSchemas) { | ||
var _this2 = this; | ||
var _this3 = this; | ||
rawSchemas.forEach(function (schema) { | ||
_this2.pushSchema(new _schema["default"](_objectSpread(_objectSpread({}, schema), {}, { | ||
database: _this2 | ||
_this3.pushSchema(new _schema["default"](_objectSpread(_objectSpread({}, schema), {}, { | ||
database: _this3 | ||
}))); | ||
@@ -113,7 +143,7 @@ }); | ||
value: function processSchemaElements(elements, elementType) { | ||
var _this3 = this; | ||
var _this4 = this; | ||
var schema; | ||
elements.forEach(function (element) { | ||
if (element.schemaName) { | ||
schema = _this3.findOrCreateSchema(element.schemaName); | ||
schema = _this4.findOrCreateSchema(element.schemaName); | ||
if (element.schemaName === _config.DEFAULT_SCHEMA_NAME) { | ||
@@ -123,3 +153,3 @@ // this.hasDefaultSchema = true; | ||
} else { | ||
schema = _this3.findOrCreateSchema(_config.DEFAULT_SCHEMA_NAME); | ||
schema = _this4.findOrCreateSchema(_config.DEFAULT_SCHEMA_NAME); | ||
} | ||
@@ -236,2 +266,5 @@ switch (elementType) { | ||
return s["export"](); | ||
}), | ||
notes: this.notes.map(function (n) { | ||
return n["export"](); | ||
}) | ||
@@ -246,2 +279,5 @@ }; | ||
return s.id; | ||
}), | ||
noteIds: this.notes.map(function (n) { | ||
return n.id; | ||
}) | ||
@@ -258,2 +294,3 @@ }; | ||
schemas: {}, | ||
notes: {}, | ||
refs: {}, | ||
@@ -272,2 +309,5 @@ enums: {}, | ||
}); | ||
this.notes.forEach(function (note) { | ||
return note.normalize(normalizedModel); | ||
}); | ||
return normalizedModel; | ||
@@ -274,0 +314,0 @@ } |
@@ -22,2 +22,3 @@ "use strict"; | ||
this.tableId = 1; | ||
this.noteId = 1; | ||
this.enumValueId = 1; | ||
@@ -24,0 +25,0 @@ this.endpointId = 1; |
@@ -132,2 +132,7 @@ "use strict"; | ||
} | ||
}, { | ||
key: "parse", | ||
value: function parse(str, format) { | ||
return new Parser().parse(str, format); | ||
} | ||
}]); | ||
@@ -134,0 +139,0 @@ return Parser; |
{ | ||
"name": "@dbml/core", | ||
"version": "3.1.2", | ||
"version": "3.1.3-alpha.0", | ||
"description": "> TODO: description", | ||
@@ -35,3 +35,3 @@ "author": "Holistics <dev@holistics.io>", | ||
"dependencies": { | ||
"@dbml/parse": "^3.1.2", | ||
"@dbml/parse": "^3.1.3-alpha.0", | ||
"antlr4": "^4.13.1", | ||
@@ -63,3 +63,3 @@ "lodash": "^4.17.15", | ||
}, | ||
"gitHead": "25628d4ad260b497fb2d1d03bafb2aa253b56978" | ||
"gitHead": "6f824751dd192a8fa6cad73aae62264341d8ae76" | ||
} |
@@ -6,2 +6,3 @@ import Schema, { NormalizedSchema, RawSchema } from './schema'; | ||
import Table, { NormalizedTable } from './table'; | ||
import Note, { NormalizedNote } from './note'; | ||
import Element, { RawNote, Token } from './element'; | ||
@@ -22,2 +23,3 @@ import DbState from './dbState'; | ||
tables: Table[]; | ||
notes: Note[]; | ||
enums: Enum[]; | ||
@@ -32,2 +34,3 @@ refs: Ref[]; | ||
schemas: Schema[]; | ||
notes: Note[]; | ||
note: string; | ||
@@ -105,2 +108,8 @@ noteToken: Token; | ||
}[]; | ||
notes: { | ||
id: number; | ||
name: string; | ||
content: string; | ||
headerColor: string; | ||
}[]; | ||
}; | ||
@@ -172,5 +181,12 @@ shallowExport(): { | ||
}[]; | ||
notes: { | ||
id: number; | ||
name: string; | ||
content: string; | ||
headerColor: string; | ||
}[]; | ||
}; | ||
exportChildIds(): { | ||
schemaIds: number[]; | ||
noteIds: number[]; | ||
}; | ||
@@ -188,5 +204,7 @@ normalize(): NormalizedDatabase; | ||
schemaIds: number[]; | ||
noteIds: number[]; | ||
}; | ||
}; | ||
schemas: NormalizedSchema; | ||
notes: NormalizedNote; | ||
refs: NormalizedRef; | ||
@@ -193,0 +211,0 @@ enums: NormalizedEnum; |
@@ -8,2 +8,3 @@ export default class DbState { | ||
tableId: number; | ||
noteId: number; | ||
enumValueId: number; | ||
@@ -10,0 +11,0 @@ endpointId: number; |
@@ -162,2 +162,3 @@ import Table from './table'; | ||
tableIds: number[]; | ||
noteIds: number[]; | ||
enumIds: number[]; | ||
@@ -184,2 +185,3 @@ tableGroupIds: number[]; | ||
tableIds: number[]; | ||
noteIds: number[]; | ||
enumIds: number[]; | ||
@@ -186,0 +188,0 @@ tableGroupIds: number[]; |
import { Compiler } from '@dbml/parse'; | ||
import Database, { RawDatabase } from '../model_structure/database'; | ||
declare class Parser { | ||
constructor(DBMLCompiler: Compiler?); | ||
constructor(DBMLCompiler?: Compiler); | ||
static parseJSONToDatabase(rawDatabase: RawDatabase): Database; | ||
@@ -12,4 +12,8 @@ static parseMySQLToJSON(str: string): RawDatabase; | ||
static parseMSSQLToJSON(str: string): RawDatabase; | ||
/** | ||
* Should use parse() instance method instead of this static method whenever possible | ||
*/ | ||
static parse(str: string, format: 'mysql' | 'postgres' | 'dbml' | 'dbmlv2' | 'schemarb' | 'mssql' | 'json'): Database; | ||
parse(str: string, format: 'mysql' | 'postgres' | 'dbml' | 'dbmlv2' | 'schemarb' | 'mssql' | 'json'): Database; | ||
} | ||
export default Parser; |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
9269599
133
41472
2
Updated@dbml/parse@^3.1.3-alpha.0