@dbml/core 11.0.0-alpha.6 → 11.0.0-alpha.8

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.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require("./_virtual/_rolldown/runtime.cjs");const e=require("./parse/error.cjs"),t=require("./parse/Parser.cjs"),n=require("./export/index.cjs"),r=require("./export/ModelExporter.cjs"),i=require("./import/index.cjs"),a=require("./transform/index.cjs"),o=require("./utils/version.cjs"),s=require("./transform/relations.cjs");let c=require("@dbml/parse");Object.defineProperty(exports,"BUILTIN_ROLES",{enumerable:!0,get:function(){return c.BUILTIN_ROLES}}),Object.defineProperty(exports,"CARDINALITY_MANY",{enumerable:!0,get:function(){return c.CARDINALITY_MANY}}),Object.defineProperty(exports,"CARDINALITY_MAYBE",{enumerable:!0,get:function(){return c.CARDINALITY_MAYBE}}),Object.defineProperty(exports,"CARDINALITY_ONE",{enumerable:!0,get:function(){return c.CARDINALITY_ONE}}),Object.defineProperty(exports,"CARDINALITY_SOME",{enumerable:!0,get:function(){return c.CARDINALITY_SOME}}),exports.CompilerError=e.CompilerError,Object.defineProperty(exports,"DEFAULT_ENTRY",{enumerable:!0,get:function(){return c.DEFAULT_ENTRY}}),Object.defineProperty(exports,"Filepath",{enumerable:!0,get:function(){return c.Filepath}}),Object.defineProperty(exports,"MetadataKind",{enumerable:!0,get:function(){return c.MetadataKind}}),exports.ModelExporter=r.default,exports.Parser=t.default,Object.defineProperty(exports,"SymbolKind",{enumerable:!0,get:function(){return c.SymbolKind}}),exports.VERSION=o.VERSION,Object.defineProperty(exports,"addDoubleQuoteIfNeeded",{enumerable:!0,get:function(){return c.addDoubleQuoteIfNeeded}}),Object.defineProperty(exports,"dbmlMonarchTokensProvider",{enumerable:!0,get:function(){return c.dbmlMonarchTokensProvider}}),exports.exporter=n.default,Object.defineProperty(exports,"findDiagramViewBlocks",{enumerable:!0,get:function(){return c.findDiagramViewBlocks}}),Object.defineProperty(exports,"formatRecordValue",{enumerable:!0,get:function(){return c.formatRecordValue}}),Object.defineProperty(exports,"getMultiplicities",{enumerable:!0,get:function(){return c.getMultiplicities}}),Object.defineProperty(exports,"getRelationshipOp",{enumerable:!0,get:function(){return c.getRelationshipOp}}),exports.importer=i.default,exports.inferMultiplicitiesFromColumns=s.inferMultiplicitiesFromColumns,Object.defineProperty(exports,"isBinaryType",{enumerable:!0,get:function(){return c.isBinaryType}}),Object.defineProperty(exports,"isBooleanType",{enumerable:!0,get:function(){return c.isBooleanType}}),Object.defineProperty(exports,"isDateTimeType",{enumerable:!0,get:function(){return c.isDateTimeType}}),Object.defineProperty(exports,"isEndpointManySide",{enumerable:!0,get:function(){return c.isEndpointManySide}}),Object.defineProperty(exports,"isEndpointOneSide",{enumerable:!0,get:function(){return c.isEndpointOneSide}}),Object.defineProperty(exports,"isEndpointOptional",{enumerable:!0,get:function(){return c.isEndpointOptional}}),Object.defineProperty(exports,"isEndpointRequired",{enumerable:!0,get:function(){return c.isEndpointRequired}}),Object.defineProperty(exports,"isFloatType",{enumerable:!0,get:function(){return c.isFloatType}}),Object.defineProperty(exports,"isIntegerType",{enumerable:!0,get:function(){return c.isIntegerType}}),Object.defineProperty(exports,"isNumericType",{enumerable:!0,get:function(){return c.isNumericType}}),Object.defineProperty(exports,"isSerialType",{enumerable:!0,get:function(){return c.isSerialType}}),Object.defineProperty(exports,"isStringType",{enumerable:!0,get:function(){return c.isStringType}}),Object.defineProperty(exports,"makeRelationshipRequired",{enumerable:!0,get:function(){return c.makeRelationshipRequired}}),exports.renameElement=a.renameElement,exports.renameTable=a.renameTable,exports.syncDep=a.syncDep,exports.syncDiagramView=a.syncDiagramView,Object.defineProperty(exports,"tryExtractBoolean",{enumerable:!0,get:function(){return c.tryExtractBoolean}}),Object.defineProperty(exports,"tryExtractDateTime",{enumerable:!0,get:function(){return c.tryExtractDateTime}}),Object.defineProperty(exports,"tryExtractEnum",{enumerable:!0,get:function(){return c.tryExtractEnum}}),Object.defineProperty(exports,"tryExtractInteger",{enumerable:!0,get:function(){return c.tryExtractInteger}}),Object.defineProperty(exports,"tryExtractNumeric",{enumerable:!0,get:function(){return c.tryExtractNumeric}}),Object.defineProperty(exports,"tryExtractString",{enumerable:!0,get:function(){return c.tryExtractString}}),exports.updateElementSetting=a.updateElementSetting,exports.updateElementSettingEdit=a.updateElementSettingEdit;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require("./_virtual/_rolldown/runtime.cjs");const e=require("./parse/error.cjs"),t=require("./parse/Parser.cjs"),n=require("./export/index.cjs"),r=require("./export/ModelExporter.cjs"),i=require("./import/index.cjs"),a=require("./transform/index.cjs"),o=require("./utils/version.cjs"),s=require("./transform/relations.cjs");let c=require("@dbml/parse");Object.defineProperty(exports,"BUILTIN_ROLES",{enumerable:!0,get:function(){return c.BUILTIN_ROLES}}),Object.defineProperty(exports,"CARDINALITY_MANY",{enumerable:!0,get:function(){return c.CARDINALITY_MANY}}),Object.defineProperty(exports,"CARDINALITY_MAYBE",{enumerable:!0,get:function(){return c.CARDINALITY_MAYBE}}),Object.defineProperty(exports,"CARDINALITY_ONE",{enumerable:!0,get:function(){return c.CARDINALITY_ONE}}),Object.defineProperty(exports,"CARDINALITY_SOME",{enumerable:!0,get:function(){return c.CARDINALITY_SOME}}),exports.CompilerError=e.CompilerError,Object.defineProperty(exports,"DEFAULT_ENTRY",{enumerable:!0,get:function(){return c.DEFAULT_ENTRY}}),Object.defineProperty(exports,"Filepath",{enumerable:!0,get:function(){return c.Filepath}}),Object.defineProperty(exports,"MetadataKind",{enumerable:!0,get:function(){return c.MetadataKind}}),exports.ModelExporter=r.default,Object.defineProperty(exports,"NAME_PRECEDENCE",{enumerable:!0,get:function(){return c.NAME_PRECEDENCE}}),exports.Parser=t.default,Object.defineProperty(exports,"SymbolKind",{enumerable:!0,get:function(){return c.SymbolKind}}),exports.VERSION=o.VERSION,Object.defineProperty(exports,"addDoubleQuoteIfNeeded",{enumerable:!0,get:function(){return c.addDoubleQuoteIfNeeded}}),Object.defineProperty(exports,"dbmlMonarchTokensProvider",{enumerable:!0,get:function(){return c.dbmlMonarchTokensProvider}}),exports.exporter=n.default,Object.defineProperty(exports,"findDiagramViewBlocks",{enumerable:!0,get:function(){return c.findDiagramViewBlocks}}),Object.defineProperty(exports,"formatRecordValue",{enumerable:!0,get:function(){return c.formatRecordValue}}),Object.defineProperty(exports,"fullName",{enumerable:!0,get:function(){return c.fullName}}),Object.defineProperty(exports,"getMultiplicities",{enumerable:!0,get:function(){return c.getMultiplicities}}),Object.defineProperty(exports,"getRelationshipOp",{enumerable:!0,get:function(){return c.getRelationshipOp}}),exports.importer=i.default,exports.inferMultiplicitiesFromColumns=s.inferMultiplicitiesFromColumns,Object.defineProperty(exports,"isBinaryType",{enumerable:!0,get:function(){return c.isBinaryType}}),Object.defineProperty(exports,"isBooleanType",{enumerable:!0,get:function(){return c.isBooleanType}}),Object.defineProperty(exports,"isDateTimeType",{enumerable:!0,get:function(){return c.isDateTimeType}}),Object.defineProperty(exports,"isEndpointManySide",{enumerable:!0,get:function(){return c.isEndpointManySide}}),Object.defineProperty(exports,"isEndpointOneSide",{enumerable:!0,get:function(){return c.isEndpointOneSide}}),Object.defineProperty(exports,"isEndpointOptional",{enumerable:!0,get:function(){return c.isEndpointOptional}}),Object.defineProperty(exports,"isEndpointRequired",{enumerable:!0,get:function(){return c.isEndpointRequired}}),Object.defineProperty(exports,"isFloatType",{enumerable:!0,get:function(){return c.isFloatType}}),Object.defineProperty(exports,"isIntegerType",{enumerable:!0,get:function(){return c.isIntegerType}}),Object.defineProperty(exports,"isNumericType",{enumerable:!0,get:function(){return c.isNumericType}}),Object.defineProperty(exports,"isSerialType",{enumerable:!0,get:function(){return c.isSerialType}}),Object.defineProperty(exports,"isStringType",{enumerable:!0,get:function(){return c.isStringType}}),Object.defineProperty(exports,"makeRelationshipRequired",{enumerable:!0,get:function(){return c.makeRelationshipRequired}}),exports.renameElement=a.renameElement,exports.renameTable=a.renameTable,exports.syncDep=a.syncDep,exports.syncDiagramView=a.syncDiagramView,Object.defineProperty(exports,"tryExtractBoolean",{enumerable:!0,get:function(){return c.tryExtractBoolean}}),Object.defineProperty(exports,"tryExtractDateTime",{enumerable:!0,get:function(){return c.tryExtractDateTime}}),Object.defineProperty(exports,"tryExtractEnum",{enumerable:!0,get:function(){return c.tryExtractEnum}}),Object.defineProperty(exports,"tryExtractInteger",{enumerable:!0,get:function(){return c.tryExtractInteger}}),Object.defineProperty(exports,"tryExtractNumeric",{enumerable:!0,get:function(){return c.tryExtractNumeric}}),Object.defineProperty(exports,"tryExtractString",{enumerable:!0,get:function(){return c.tryExtractString}}),exports.updateElementSetting=a.updateElementSetting,exports.updateElementSettingEdit=a.updateElementSettingEdit;
package/lib/index.mjs CHANGED
@@ -6,5 +6,5 @@ import i from "./import/index.mjs";
6
6
  import { findDiagramViewBlocks as a, renameElement as o, renameTable as s, syncDep as c, syncDiagramView as l, updateElementSetting as u, updateElementSettingEdit as d } from "./transform/index.mjs";
7
7
  import { VERSION as f } from "./utils/version.mjs";
8
8
  import { inferMultiplicitiesFromColumns as p } from "./transform/relations.mjs";
9
- import { BUILTIN_ROLES as m, CARDINALITY_MANY as h, CARDINALITY_MAYBE as g, CARDINALITY_ONE as _, CARDINALITY_SOME as v, DEFAULT_ENTRY as y, Filepath as b, MetadataKind as x, SymbolKind as S, addDoubleQuoteIfNeeded as C, dbmlMonarchTokensProvider as w, formatRecordValue as T, getMultiplicities as E, getRelationshipOp as D, isBinaryType as O, isBooleanType as k, isDateTimeType as A, isEndpointManySide as j, isEndpointOneSide as M, isEndpointOptional as N, isEndpointRequired as P, isFloatType as F, isIntegerType as I, isNumericType as L, isSerialType as R, isStringType as z, makeRelationshipRequired as B, tryExtractBoolean as V, tryExtractDateTime as H, tryExtractEnum as U, tryExtractInteger as W, tryExtractNumeric as G, tryExtractString as K } from "@dbml/parse";
10
- export { m as BUILTIN_ROLES, h as CARDINALITY_MANY, g as CARDINALITY_MAYBE, _ as CARDINALITY_ONE, v as CARDINALITY_SOME, e as CompilerError, y as DEFAULT_ENTRY, b as Filepath, x as MetadataKind, r as ModelExporter, t as Parser, S as SymbolKind, f as VERSION, C as addDoubleQuoteIfNeeded, w as dbmlMonarchTokensProvider, n as exporter, a as findDiagramViewBlocks, T as formatRecordValue, E as getMultiplicities, D as getRelationshipOp, i as importer, p as inferMultiplicitiesFromColumns, O as isBinaryType, k as isBooleanType, A as isDateTimeType, j as isEndpointManySide, M as isEndpointOneSide, N as isEndpointOptional, P as isEndpointRequired, F as isFloatType, I as isIntegerType, L as isNumericType, R as isSerialType, z as isStringType, B as makeRelationshipRequired, o as renameElement, s as renameTable, c as syncDep, l as syncDiagramView, V as tryExtractBoolean, H as tryExtractDateTime, U as tryExtractEnum, W as tryExtractInteger, G as tryExtractNumeric, K as tryExtractString, u as updateElementSetting, d as updateElementSettingEdit };
9
+ import { BUILTIN_ROLES as m, CARDINALITY_MANY as h, CARDINALITY_MAYBE as g, CARDINALITY_ONE as _, CARDINALITY_SOME as v, DEFAULT_ENTRY as y, Filepath as b, MetadataKind as x, NAME_PRECEDENCE as S, SymbolKind as C, addDoubleQuoteIfNeeded as w, dbmlMonarchTokensProvider as T, formatRecordValue as E, fullName as D, getMultiplicities as O, getRelationshipOp as k, isBinaryType as A, isBooleanType as j, isDateTimeType as M, isEndpointManySide as N, isEndpointOneSide as P, isEndpointOptional as F, isEndpointRequired as I, isFloatType as L, isIntegerType as R, isNumericType as z, isSerialType as B, isStringType as V, makeRelationshipRequired as H, tryExtractBoolean as U, tryExtractDateTime as W, tryExtractEnum as G, tryExtractInteger as K, tryExtractNumeric as q, tryExtractString as J } from "@dbml/parse";
10
+ export { m as BUILTIN_ROLES, h as CARDINALITY_MANY, g as CARDINALITY_MAYBE, _ as CARDINALITY_ONE, v as CARDINALITY_SOME, e as CompilerError, y as DEFAULT_ENTRY, b as Filepath, x as MetadataKind, r as ModelExporter, S as NAME_PRECEDENCE, t as Parser, C as SymbolKind, f as VERSION, w as addDoubleQuoteIfNeeded, T as dbmlMonarchTokensProvider, n as exporter, a as findDiagramViewBlocks, E as formatRecordValue, D as fullName, O as getMultiplicities, k as getRelationshipOp, i as importer, p as inferMultiplicitiesFromColumns, A as isBinaryType, j as isBooleanType, M as isDateTimeType, N as isEndpointManySide, P as isEndpointOneSide, F as isEndpointOptional, I as isEndpointRequired, L as isFloatType, R as isIntegerType, z as isNumericType, B as isSerialType, V as isStringType, H as makeRelationshipRequired, o as renameElement, s as renameTable, c as syncDep, l as syncDiagramView, U as tryExtractBoolean, W as tryExtractDateTime, G as tryExtractEnum, K as tryExtractInteger, q as tryExtractNumeric, J as tryExtractString, u as updateElementSetting, d as updateElementSettingEdit };
@@ -1 +1 @@
1
- require("../_virtual/_rolldown/runtime.cjs");const e=require("../node_modules/lodash-es/get.cjs"),t=require("../node_modules/lodash-es/capitalize.cjs"),n=require("../node_modules/lodash-es/lodash.cjs"),r=require("./config.cjs"),i=require("./dbState.cjs"),a=require("./element.cjs"),o=require("./dep.cjs"),s=require("./enum.cjs"),c=require("./ref.cjs"),l=require("./table.cjs"),u=require("./tableGroup.cjs"),d=require("./schema.cjs"),f=require("./stickyNote.cjs"),p=require("./tablePartial.cjs"),m=require("./node.cjs"),h=require("./group.cjs"),g=require("./link.cjs");let _=require("@dbml/parse");n.init_lodash();var v=class extends a.default{constructor({schemas:t=[],tables:n=[],notes:a=[],enums:o=[],refs:s=[],deps:l=[],tableGroups:u=[],project:d={},aliases:f=[],records:p=[],tablePartials:m=[],diagramViews:h=[],nodes:g=[],groups:_=[],links:v=[],frontMatter:y,diagramType:b}={}){super(),this.dbState=new i.default,this.generateId(),this.hasDefaultSchema=!1,this.schemas=[],this.notes=[],this.note=d.note?e.default(d,`note.value`,typeof d.note==`string`?d.note:null):null,this.noteToken=d.note?e.default(d,`note.token`,d.noteToken):null,this.databaseType=d.database_type,this.name=d.name,this.token=d.token,this.aliases=f,this.records=[],this.tablePartials=[],this.diagramViews=h,this.injectedRawRefs=[],this.processNotes(a),this.processRecords(p),this.processTablePartials(m),this.processSchemas(t),this.processSchemaElements(o,r.ENUM),this.processSchemaElements(n,r.TABLE),this.linkRecordsToTables(),this.processSchemaElements(a,r.NOTE),this.processSchemaElements(s,`ref`),this.processSchemaElements(l,`dep`),this.processSchemaElements(u,r.TABLE_GROUP),this.injectedRawRefs.forEach(e=>{let t=this.findOrCreateSchema(r.DEFAULT_SCHEMA_NAME),n=new c.default({...e,schema:t});t.refs.some(e=>e.equals(n))||t.pushRef(n)}),this.nodes=[],this.groups=[],this.links=[],this.frontMatter=y??null,this.diagramType=b??null,this.processArch(g,_,v)}processArch(e,t,n){e.forEach(e=>this.nodes.push(new m.default({...e,database:this}))),t.forEach(e=>this.groups.push(new h.default({...e,database:this})));let r=new Map,i=(e,t,n)=>{r.has(e)||r.set(e,{type:t,element:n})};this.nodes.forEach(e=>i(e.alias??e.name,`node`,e)),this.groups.forEach(e=>i(e.alias??e.name,`group`,e)),this.notes.forEach(e=>i(e.name,`note`,e)),this.groups.forEach(e=>{e.children.forEach(t=>{let n=r.get(t);n&&(e.childIds.push(n.element.id),e.childTypes.push(n.type),(n.element instanceof m.default||n.element instanceof h.default)&&(n.element.groupId=e.id))})}),n.forEach(({from:e,to:t,...n})=>{let i=r.get(e),a=r.get(t);!i||!a||this.links.push(new g.default({...n,fromId:i.element.id,fromType:i.type,toId:a.element.id,toType:a.type,database:this}))})}generateId(){this.id=this.dbState.generateId(`dbId`)}processNotes(e){e.forEach(e=>{this.pushNote(new f.default({...e,database:this}))})}processRecords(e){e.forEach(({schemaName:e,tableName:t,columns:n,values:r,example:i,token:a})=>{this.records.push({id:this.dbState.generateId(`recordId`),schemaName:e,tableName:t,columns:n,values:r,example:i,token:a})})}processTablePartials(e){e.forEach(e=>{this.tablePartials.push(new p.default({...e,dbState:this.dbState}))})}pushNote(e){this.checkNote(e),this.notes.push(e)}checkNote(e){this.notes.some(t=>t.name===e.name)&&e.error(`Notes ${e.name} existed`)}processSchemas(e){e.forEach(e=>{this.pushSchema(new d.default({...e,database:this}))})}pushSchema(e){this.checkSchema(e),this.schemas.push(e)}checkSchema(e){this.schemas.some(t=>t.name===e.name)&&e.error(`Schemas ${e.name} existed`)}processSchemaElements(e,t){let n;e.forEach(e=>{switch(e.schemaName?(n=this.findOrCreateSchema(e.schemaName),e.schemaName):n=this.findOrCreateSchema(r.DEFAULT_SCHEMA_NAME),t){case r.TABLE:n.pushTable(new l.default({...e,schema:n}));break;case r.ENUM:n.pushEnum(new s.default({...e,schema:n}));break;case r.TABLE_GROUP:n.pushTableGroup(new u.default({...e,schema:n}));break;case`ref`:n.pushRef(new c.default({...e,schema:n}));break;case`dep`:n.pushDep(new o.default({...e,schema:n}));break;default:break}})}linkRecordsToTables(){let e={};this.schemas.forEach(t=>{e[t.name]={},t.tables.forEach(n=>{e[t.name][n.name]=n})}),this.records.forEach(t=>{let n=e[t.schemaName??`public`]?.[t.tableName];n&&(t.tableId=n.id,n.records.push(t))})}findOrCreateSchema(e){let n=this.schemas.find(t=>t.name===e||t.alias===e);return n||(n=new d.default({name:e,note:{value:e===`public`?`Default ${t.default(r.DEFAULT_SCHEMA_NAME)} Schema`:null},database:this}),this.pushSchema(n)),n}findTableAlias(e){let t=this.aliases.find(t=>t.name===e);if(!t||t.kind!==`table`)return null;let n=t.value.schemaName||`public`,r=this.schemas.find(e=>e.name===n);if(!r)return null;let{tableName:i}=t.value;return r.tables.find(e=>e.name===i)||null}findTable(e,t){let n=null;if(!e&&(n=this.findTableAlias(t),n))return n;let r=this.findOrCreateSchema(e||`public`);return r||this.error(`Schema ${e||`public`} don't exist`),r.findTable(t)}findEnum(e,t){let n=this.schemas.find(t=>t.name===e||t.alias===e);if(n)return n.enums.find(e=>e.name===t)}findTablePartial(e){return this.tablePartials.find(t=>t.name===e)}adjustCardinalitiesFromColumns(){this.schemas.forEach(e=>{e.refs.forEach(e=>{let t=e.endpoints.find(e=>(0,_.parseCardinality)(e.relation).max===`*`),n=e.endpoints.find(e=>(0,_.parseCardinality)(e.relation).max===1);if(!n)return;let r,i;t?(r=t,i=n):(r=e.endpoints[1],i=e.endpoints[0]),!(!r||!i)&&r.fields.every(e=>e.not_null||e.pk||e.increment)&&(i.relation=(0,_.makeCardinalityRequired)(i.relation))})})}export(){return{...this.exportChild()}}shallowExport(){return{hasDefaultSchema:this.hasDefaultSchema,note:this.note,databaseType:this.databaseType,name:this.name}}exportChild(){return{schemas:this.schemas.map(e=>e.export()),notes:this.notes.map(e=>e.export()),records:this.records.map(e=>({...e})),...this.archEntries(e=>e.map(e=>e.export()))}}exportChildIds(){return{schemaIds:this.schemas.map(e=>e.id),noteIds:this.notes.map(e=>e.id),...this.archIds(),...this.frontMatter?{frontMatter:this.frontMatter}:{},...this.diagramType?{diagramType:this.diagramType}:{}}}archEntries(e){let t={},n={nodes:this.nodes,groups:this.groups,links:this.links};return Object.entries(n).forEach(([n,r])=>{r.length&&(t[n]=e(r))}),t}archIds(){let e=this.archEntries(e=>e.map(e=>e.id));return{...e.nodes?{nodeIds:e.nodes}:{},...e.groups?{groupIds:e.groups}:{},...e.links?{linkIds:e.links}:{}}}normalize(){let e={database:{[this.id]:{id:this.id,...this.shallowExport(),...this.exportChildIds()}},schemas:{},notes:{},refs:{},deps:{},depEdges:{},enums:{},tableGroups:{},tables:{},endpoints:{},enumValues:{},indexes:{},indexColumns:{},checks:{},fields:{},records:{},tablePartials:{}};return this.schemas.forEach(t=>t.normalize(e)),this.notes.forEach(t=>t.normalize(e)),this.records.forEach(t=>{e.records[t.id]={...t}}),this.tablePartials.forEach(t=>t.normalize(e)),Object.entries(this.archEntries(e=>e)).forEach(([t,n])=>{e[t]={},n.forEach(t=>t.normalize(e))}),e}};exports.default=v;
1
+ require("../_virtual/_rolldown/runtime.cjs");const e=require("../node_modules/lodash-es/get.cjs"),t=require("../node_modules/lodash-es/capitalize.cjs"),n=require("../node_modules/lodash-es/lodash.cjs"),r=require("./config.cjs"),i=require("./dbState.cjs"),a=require("./element.cjs"),o=require("./dep.cjs"),s=require("./enum.cjs"),c=require("./ref.cjs"),l=require("./table.cjs"),u=require("./tableGroup.cjs"),d=require("./schema.cjs"),f=require("./stickyNote.cjs"),p=require("./tablePartial.cjs"),m=require("./node.cjs"),h=require("./group.cjs"),g=require("./link.cjs");let _=require("@dbml/parse");n.init_lodash();var v=class extends a.default{constructor({schemas:t=[],tables:n=[],notes:a=[],enums:o=[],refs:s=[],deps:l=[],tableGroups:u=[],project:d={},aliases:f=[],records:p=[],tablePartials:m=[],diagramViews:h=[],nodes:g=[],groups:_=[],links:v=[],frontMatter:y,diagramType:b}={}){super(),this.dbState=new i.default,this.generateId(),this.hasDefaultSchema=!1,this.schemas=[],this.notes=[],this.note=d.note?e.default(d,`note.value`,typeof d.note==`string`?d.note:null):null,this.noteToken=d.note?e.default(d,`note.token`,d.noteToken):null,this.databaseType=d.database_type,this.name=d.name,this.token=d.token,this.aliases=f,this.records=[],this.tablePartials=[],this.diagramViews=h,this.injectedRawRefs=[],this.processNotes(a),this.processRecords(p),this.processTablePartials(m),this.processSchemas(t),this.processSchemaElements(o,r.ENUM),this.processSchemaElements(n,r.TABLE),this.linkRecordsToTables(),this.processSchemaElements(a,r.NOTE),this.processSchemaElements(s,`ref`),this.processSchemaElements(l,`dep`),this.processSchemaElements(u,r.TABLE_GROUP),this.injectedRawRefs.forEach(e=>{let t=this.findOrCreateSchema(r.DEFAULT_SCHEMA_NAME),n=new c.default({...e,schema:t});t.refs.some(e=>e.equals(n))||t.pushRef(n)}),this.nodes=[],this.groups=[],this.links=[],this.frontMatter=y??null,this.diagramType=b??null,this.processArch(g,_,v)}processArch(e,t,n){e.forEach(e=>this.nodes.push(new m.default({...e,database:this}))),t.forEach(e=>this.groups.push(new h.default({...e,database:this})));let r=(e,t)=>`${t}\u0000${e}`,i=new Map,a=(e,t,n,a)=>{let o=r(e,t);i.has(o)||i.set(o,{type:n,element:a})};this.nodes.forEach(e=>a(e.alias??e.name,e.role,`node`,e)),this.groups.forEach(e=>a(e.alias??e.name,`Group`,`group`,e)),this.notes.forEach(e=>a(e.name,`Note`,`note`,e)),this.groups.forEach(e=>{e.children.forEach(({handle:t,role:n})=>{let a=i.get(r(t,n));a&&(e.childIds.push(a.element.id),e.childTypes.push(a.type),(a.element instanceof m.default||a.element instanceof h.default)&&(a.element.groupId=e.id))})}),n.forEach(({from:e,fromRole:t,to:n,toRole:a,...o})=>{let s=i.get(r(e,t)),c=i.get(r(n,a));!s||!c||this.links.push(new g.default({...o,fromId:s.element.id,fromType:s.type,toId:c.element.id,toType:c.type,database:this}))})}generateId(){this.id=this.dbState.generateId(`dbId`)}processNotes(e){e.forEach(e=>{this.pushNote(new f.default({...e,database:this}))})}processRecords(e){e.forEach(({schemaName:e,tableName:t,columns:n,values:r,example:i,token:a})=>{this.records.push({id:this.dbState.generateId(`recordId`),schemaName:e,tableName:t,columns:n,values:r,example:i,token:a})})}processTablePartials(e){e.forEach(e=>{this.tablePartials.push(new p.default({...e,dbState:this.dbState}))})}pushNote(e){this.checkNote(e),this.notes.push(e)}checkNote(e){this.notes.some(t=>t.name===e.name)&&e.error(`Notes ${e.name} existed`)}processSchemas(e){e.forEach(e=>{this.pushSchema(new d.default({...e,database:this}))})}pushSchema(e){this.checkSchema(e),this.schemas.push(e)}checkSchema(e){this.schemas.some(t=>t.name===e.name)&&e.error(`Schemas ${e.name} existed`)}processSchemaElements(e,t){let n;e.forEach(e=>{switch(e.schemaName?(n=this.findOrCreateSchema(e.schemaName),e.schemaName):n=this.findOrCreateSchema(r.DEFAULT_SCHEMA_NAME),t){case r.TABLE:n.pushTable(new l.default({...e,schema:n}));break;case r.ENUM:n.pushEnum(new s.default({...e,schema:n}));break;case r.TABLE_GROUP:n.pushTableGroup(new u.default({...e,schema:n}));break;case`ref`:n.pushRef(new c.default({...e,schema:n}));break;case`dep`:n.pushDep(new o.default({...e,schema:n}));break;default:break}})}linkRecordsToTables(){let e={};this.schemas.forEach(t=>{e[t.name]={},t.tables.forEach(n=>{e[t.name][n.name]=n})}),this.records.forEach(t=>{let n=e[t.schemaName??`public`]?.[t.tableName];n&&(t.tableId=n.id,n.records.push(t))})}findOrCreateSchema(e){let n=this.schemas.find(t=>t.name===e||t.alias===e);return n||(n=new d.default({name:e,note:{value:e===`public`?`Default ${t.default(r.DEFAULT_SCHEMA_NAME)} Schema`:null},database:this}),this.pushSchema(n)),n}findTableAlias(e){let t=this.aliases.find(t=>t.name===e);if(!t||t.kind!==`table`)return null;let n=t.value.schemaName||`public`,r=this.schemas.find(e=>e.name===n);if(!r)return null;let{tableName:i}=t.value;return r.tables.find(e=>e.name===i)||null}findTable(e,t){let n=null;if(!e&&(n=this.findTableAlias(t),n))return n;let r=this.findOrCreateSchema(e||`public`);return r||this.error(`Schema ${e||`public`} don't exist`),r.findTable(t)}findEnum(e,t){let n=this.schemas.find(t=>t.name===e||t.alias===e);if(n)return n.enums.find(e=>e.name===t)}findTablePartial(e){return this.tablePartials.find(t=>t.name===e)}adjustCardinalitiesFromColumns(){this.schemas.forEach(e=>{e.refs.forEach(e=>{let t=e.endpoints.find(e=>(0,_.parseCardinality)(e.relation).max===`*`),n=e.endpoints.find(e=>(0,_.parseCardinality)(e.relation).max===1);if(!n)return;let r,i;t?(r=t,i=n):(r=e.endpoints[1],i=e.endpoints[0]),!(!r||!i)&&r.fields.every(e=>e.not_null||e.pk||e.increment)&&(i.relation=(0,_.makeCardinalityRequired)(i.relation))})})}export(){return{...this.exportChild()}}shallowExport(){return{hasDefaultSchema:this.hasDefaultSchema,note:this.note,databaseType:this.databaseType,name:this.name}}exportChild(){return{schemas:this.schemas.map(e=>e.export()),notes:this.notes.map(e=>e.export()),records:this.records.map(e=>({...e})),...this.archEntries(e=>e.map(e=>e.export()))}}exportChildIds(){return{schemaIds:this.schemas.map(e=>e.id),noteIds:this.notes.map(e=>e.id),...this.archIds(),...this.frontMatter?{frontMatter:this.frontMatter}:{},...this.diagramType?{diagramType:this.diagramType}:{}}}archEntries(e){let t={},n={nodes:this.nodes,groups:this.groups,links:this.links};return Object.entries(n).forEach(([n,r])=>{r.length&&(t[n]=e(r))}),t}archIds(){let e=this.archEntries(e=>e.map(e=>e.id));return{...e.nodes?{nodeIds:e.nodes}:{},...e.groups?{groupIds:e.groups}:{},...e.links?{linkIds:e.links}:{}}}normalize(){let e={database:{[this.id]:{id:this.id,...this.shallowExport(),...this.exportChildIds()}},schemas:{},notes:{},refs:{},deps:{},depEdges:{},enums:{},tableGroups:{},tables:{},endpoints:{},enumValues:{},indexes:{},indexColumns:{},checks:{},fields:{},records:{},tablePartials:{}};return this.schemas.forEach(t=>t.normalize(e)),this.notes.forEach(t=>t.normalize(e)),this.records.forEach(t=>{e.records[t.id]={...t}}),this.tablePartials.forEach(t=>t.normalize(e)),Object.entries(this.archEntries(e=>e)).forEach(([t,n])=>{e[t]={},n.forEach(t=>t.normalize(e))}),e}};exports.default=v;
@@ -36,25 +36,26 @@ var C = class extends l {
36
36
  ...e,
37
37
  database: this
38
38
  })));
39
- let r = /* @__PURE__ */ new Map(), i = (e, t, n) => {
40
- r.has(e) || r.set(e, {
41
- type: t,
42
- element: n
39
+ let r = (e, t) => `${t}\u0000${e}`, i = /* @__PURE__ */ new Map(), a = (e, t, n, a) => {
40
+ let o = r(e, t);
41
+ i.has(o) || i.set(o, {
42
+ type: n,
43
+ element: a
43
44
  });
44
45
  };
45
- this.nodes.forEach((e) => i(e.alias ?? e.name, "node", e)), this.groups.forEach((e) => i(e.alias ?? e.name, "group", e)), this.notes.forEach((e) => i(e.name, "note", e)), this.groups.forEach((e) => {
46
- e.children.forEach((t) => {
47
- let n = r.get(t);
48
- n && (e.childIds.push(n.element.id), e.childTypes.push(n.type), (n.element instanceof v || n.element instanceof y) && (n.element.groupId = e.id));
46
+ this.nodes.forEach((e) => a(e.alias ?? e.name, e.role, "node", e)), this.groups.forEach((e) => a(e.alias ?? e.name, "Group", "group", e)), this.notes.forEach((e) => a(e.name, "Note", "note", e)), this.groups.forEach((e) => {
47
+ e.children.forEach(({ handle: t, role: n }) => {
48
+ let a = i.get(r(t, n));
49
+ a && (e.childIds.push(a.element.id), e.childTypes.push(a.type), (a.element instanceof v || a.element instanceof y) && (a.element.groupId = e.id));
49
50
  });
50
- }), n.forEach(({ from: e, to: t, ...n }) => {
51
- let i = r.get(e), a = r.get(t);
52
- !i || !a || this.links.push(new b({
53
- ...n,
54
- fromId: i.element.id,
55
- fromType: i.type,
56
- toId: a.element.id,
57
- toType: a.type,
51
+ }), n.forEach(({ from: e, fromRole: t, to: n, toRole: a, ...o }) => {
52
+ let s = i.get(r(e, t)), c = i.get(r(n, a));
53
+ !s || !c || this.links.push(new b({
54
+ ...o,
55
+ fromId: s.element.id,
56
+ fromType: s.type,
57
+ toId: c.element.id,
58
+ toType: c.type,
58
59
  database: this
59
60
  }));
60
61
  });
@@ -1 +1 @@
1
- require("../../_virtual/_rolldown/runtime.cjs");var e=`11.0.0-alpha.6`;exports.version=e;
1
+ require("../../_virtual/_rolldown/runtime.cjs");var e=`11.0.0-alpha.8`;exports.version=e;
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var e = "11.0.0-alpha.6";
2
+ var e = "11.0.0-alpha.8";
3
3
  //#endregion
4
4
  export { e as version };
@@ -1 +1 @@
1
- require("../_virtual/_rolldown/runtime.cjs");let e=require("@dbml/parse");function t(t,n,r){let i=new e.MemoryProjectLayout;return i.setSource(e.DEFAULT_ENTRY,r),new e.Compiler(i).renameTable(e.DEFAULT_ENTRY,t,n).get(e.DEFAULT_ENTRY.absolute)??r}function n(t,n,r){let i=new e.MemoryProjectLayout;return i.setSource(e.DEFAULT_ENTRY,r),new e.Compiler(i).renameElement(e.DEFAULT_ENTRY,t,n).get(e.DEFAULT_ENTRY.absolute)??r}function r(t,n,r){let i=new e.MemoryProjectLayout;return i.setSource(e.DEFAULT_ENTRY,t),new e.Compiler(i).syncDiagramView(e.DEFAULT_ENTRY,n,r)}function i(t,n){let r=new e.MemoryProjectLayout;return r.setSource(e.DEFAULT_ENTRY,t),new e.Compiler(r).syncDep(e.DEFAULT_ENTRY,n)}function a(t,n,r,i){let a=new e.MemoryProjectLayout;return a.setSource(e.DEFAULT_ENTRY,t),new e.Compiler(a).updateElementSettingEdit(e.DEFAULT_ENTRY,n,r,i)}function o(t,n,r,i){let a=new e.MemoryProjectLayout;return a.setSource(e.DEFAULT_ENTRY,t),new e.Compiler(a).updateElementSetting(e.DEFAULT_ENTRY,n,r,i)}exports.renameElement=n,exports.renameTable=t,exports.syncDep=i,exports.syncDiagramView=r,exports.updateElementSetting=o,exports.updateElementSettingEdit=a;
1
+ require("../_virtual/_rolldown/runtime.cjs");let e=require("@dbml/parse");function t(t,n,r){let i=new e.MemoryProjectLayout;return i.setSource(e.DEFAULT_ENTRY,r),new e.Compiler(i).renameTable(e.DEFAULT_ENTRY,t,n).get(e.DEFAULT_ENTRY.absolute)??r}function n(t,n,r,i){let a=new e.MemoryProjectLayout;return a.setSource(e.DEFAULT_ENTRY,r),new e.Compiler(a).renameElement(e.DEFAULT_ENTRY,t,n,i).get(e.DEFAULT_ENTRY.absolute)??r}function r(t,n,r){let i=new e.MemoryProjectLayout;return i.setSource(e.DEFAULT_ENTRY,t),new e.Compiler(i).syncDiagramView(e.DEFAULT_ENTRY,n,r)}function i(t,n){let r=new e.MemoryProjectLayout;return r.setSource(e.DEFAULT_ENTRY,t),new e.Compiler(r).syncDep(e.DEFAULT_ENTRY,n)}function a(t,n,r,i){let a=new e.MemoryProjectLayout;return a.setSource(e.DEFAULT_ENTRY,t),new e.Compiler(a).updateElementSettingEdit(e.DEFAULT_ENTRY,n,r,i)}function o(t,n,r,i){let a=new e.MemoryProjectLayout;return a.setSource(e.DEFAULT_ENTRY,t),new e.Compiler(a).updateElementSetting(e.DEFAULT_ENTRY,n,r,i)}exports.renameElement=n,exports.renameTable=t,exports.syncDep=i,exports.syncDiagramView=r,exports.updateElementSetting=o,exports.updateElementSettingEdit=a;
@@ -4,9 +4,9 @@ function i(r, i, a) {
4
4
  let o = new n();
5
5
  return o.setSource(t, a), new e(o).renameTable(t, r, i).get(t.absolute) ?? a;
6
6
  }
7
- function a(r, i, a) {
8
- let o = new n();
9
- return o.setSource(t, a), new e(o).renameElement(t, r, i).get(t.absolute) ?? a;
7
+ function a(r, i, a, o) {
8
+ let s = new n();
9
+ return s.setSource(t, a), new e(s).renameElement(t, r, i, o).get(t.absolute) ?? a;
10
10
  }
11
11
  function o(r, i, a) {
12
12
  let o = new n();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@dbml/core",
4
- "version": "11.0.0-alpha.6",
4
+ "version": "11.0.0-alpha.8",
5
5
  "description": "> TODO: description",
6
6
  "author": "Holistics <dev@holistics.io>",
7
7
  "license": "Apache-2.0",
@@ -48,7 +48,7 @@
48
48
  "lint:fix": "eslint --fix ."
49
49
  },
50
50
  "dependencies": {
51
- "@dbml/parse": "^11.0.0-alpha.6",
51
+ "@dbml/parse": "11.0.0-alpha.8",
52
52
  "antlr4": "^4.13.1",
53
53
  "lodash": "^4.18.1",
54
54
  "lodash-es": "^4.18.1",
@@ -59,7 +59,7 @@
59
59
  "devDependencies": {
60
60
  "bluebird": "^3.5.5"
61
61
  },
62
- "gitHead": "8d191d7fc27af2f5daab6d9074f7c3882f3541ab",
62
+ "gitHead": "10674f27af2fbd225b63b120e7010b0917e68c85",
63
63
  "engines": {
64
64
  "node": ">=16"
65
65
  }
File without changes
package/types/index.d.ts CHANGED
@@ -65,6 +65,8 @@ export {
65
65
  isEndpointRequired,
66
66
  makeRelationshipRequired,
67
67
  BUILTIN_ROLES,
68
+ NAME_PRECEDENCE,
69
+ fullName,
68
70
  } from '@dbml/parse';
69
71
 
70
72
  export { inferMultiplicitiesFromColumns } from './transform/relations';
@@ -1,4 +1,4 @@
1
- import type { ArchSettings, Group as RawGroup } from '@dbml/parse';
1
+ import type { ArchRef, ArchSettings, Group as RawGroup } from '@dbml/parse';
2
2
  import Element, { Token } from './element';
3
3
  import Database from './database';
4
4
  import DbState from './dbState';
@@ -9,7 +9,7 @@ declare class Group extends Element {
9
9
  id: number;
10
10
  name: string;
11
11
  alias: string | null;
12
- children: string[];
12
+ children: ArchRef[];
13
13
  childIds: number[];
14
14
  childTypes: ArchElementType[];
15
15
  settings: ArchSettings;
@@ -17,7 +17,7 @@ declare class Link extends Element {
17
17
  settings: ArchSettings;
18
18
  database: Database;
19
19
  dbState: DbState;
20
- constructor(raw: Omit<RawLink, 'from' | 'to'> & { fromId: number; fromType: ArchElementType; toId: number; toType: ArchElementType; database: Database });
20
+ constructor(raw: Omit<RawLink, 'from' | 'fromRole' | 'to' | 'toRole'> & { fromId: number; fromType: ArchElementType; toId: number; toType: ArchElementType; database: Database });
21
21
  generateId(): void;
22
22
  export(): Omit<NormalizedLink, 'id' | 'fromId' | 'fromType' | 'toId' | 'toType'>;
23
23
  normalize(model: NormalizedModel): void;
@@ -12,7 +12,8 @@ export function renameTable(
12
12
  export function renameElement(
13
13
  oldHandle: string,
14
14
  newName: string,
15
- dbmlCode: string
15
+ dbmlCode: string,
16
+ role?: string,
16
17
  ): string;
17
18
 
18
19
  export function updateElementSettingEdit(