@dbml/core 11.0.0-alpha.3 → 11.0.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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("./noteBox.cjs"),_=require("./link.cjs"),v=require("./kind.cjs");let y=require("@dbml/parse");n.init_lodash();var b=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:_=[],noteBoxes:v=[],links:y=[],kinds:b=[],frontMatter:x,diagramType:S}={}){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.noteBoxes=[],this.links=[],this.kinds=[],this.frontMatter=x??null,this.diagramType=S??null,this.processArch(b,g,_,v,y)}processArch(e,t,n,r,i){e.forEach(e=>this.kinds.push(new v.default({...e,database:this}))),t.forEach(e=>this.nodes.push(new m.default({...e,database:this}))),n.forEach(e=>this.groups.push(new h.default({...e,database:this}))),r.forEach(e=>this.noteBoxes.push(new g.default({...e,database:this})));let a=new Map;[...this.nodes,...this.groups,...this.noteBoxes].forEach(e=>{let t=e.alias??e.name;a.has(t)||a.set(t,e)}),this.groups.forEach(e=>{e.children.forEach(t=>{let n=a.get(t);n&&(e.childIds.push(n.id),n.groupId=e.id)})}),i.forEach(({from:e,to:t,...n})=>{let r=a.get(e),i=a.get(t);!r||!i||this.links.push(new _.default({...n,fromId:r.id,toId:i.id,database:this}))})}findKind(e){return this.kinds.find(t=>t.name===e)}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,y.parseCardinality)(e.relation).max===`*`),n=e.endpoints.find(e=>(0,y.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,y.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,noteBoxes:this.noteBoxes,links:this.links,kinds:this.kinds};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.noteBoxes?{noteBoxIds:e.noteBoxes}:{},...e.links?{linkIds:e.links}:{},...e.kinds?{kindIds:e.kinds}:{}}}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=b;
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"),_=require("./kind.cjs");let v=require("@dbml/parse");n.init_lodash();var y=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=[],kinds:y=[],frontMatter:b,diagramType:x}={}){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.kinds=[],this.frontMatter=b??null,this.diagramType=x??null,this.processArch(y,g,_,v)}processArch(e,t,n,r){e.forEach(e=>this.kinds.push(new _.default({...e,database:this}))),t.forEach(e=>this.nodes.push(new m.default({...e,database:this}))),n.forEach(e=>this.groups.push(new h.default({...e,database:this})));let i=new Map,a=(e,t,n)=>{i.has(e)||i.set(e,{type:t,element:n})};this.nodes.forEach(e=>a(e.alias??e.name,`node`,e)),this.groups.forEach(e=>a(e.alias??e.name,`group`,e)),this.notes.forEach(e=>a(e.name,`note`,e)),this.groups.forEach(e=>{e.children.forEach(t=>{let n=i.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))})}),r.forEach(({from:e,to:t,...n})=>{let r=i.get(e),a=i.get(t);!r||!a||this.links.push(new g.default({...n,fromId:r.element.id,fromType:r.type,toId:a.element.id,toType:a.type,database:this}))})}findKind(e){return this.kinds.find(t=>t.name===e)}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,v.parseCardinality)(e.relation).max===`*`),n=e.endpoints.find(e=>(0,v.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,v.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,kinds:this.kinds};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}:{},...e.kinds?{kindIds:e.kinds}:{}}}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=y;
@@ -14,24 +14,23 @@ import g from "./stickyNote.mjs";
14
14
  import _ from "./tablePartial.mjs";
15
15
  import v from "./node.mjs";
16
16
  import y from "./group.mjs";
17
- import b from "./noteBox.mjs";
18
- import x from "./link.mjs";
19
- import S from "./kind.mjs";
20
- import { makeCardinalityRequired as C, parseCardinality as w } from "@dbml/parse";
17
+ import b from "./link.mjs";
18
+ import x from "./kind.mjs";
19
+ import { makeCardinalityRequired as S, parseCardinality as C } from "@dbml/parse";
21
20
  //#region src/model_structure/database.ts
22
21
  n();
23
- var T = class extends l {
24
- constructor({ schemas: t = [], tables: n = [], notes: l = [], enums: u = [], refs: d = [], deps: p = [], tableGroups: m = [], project: h = {}, aliases: g = [], records: _ = [], tablePartials: v = [], diagramViews: y = [], nodes: b = [], groups: x = [], noteBoxes: S = [], links: C = [], kinds: w = [], frontMatter: T, diagramType: E } = {}) {
22
+ var w = class extends l {
23
+ constructor({ schemas: t = [], tables: n = [], notes: l = [], enums: u = [], refs: d = [], deps: p = [], tableGroups: m = [], project: h = {}, aliases: g = [], records: _ = [], tablePartials: v = [], diagramViews: y = [], nodes: b = [], groups: x = [], links: S = [], kinds: C = [], frontMatter: w, diagramType: T } = {}) {
25
24
  super(), this.dbState = new c(), this.generateId(), this.hasDefaultSchema = !1, this.schemas = [], this.notes = [], this.note = h.note ? e(h, "note.value", typeof h.note == "string" ? h.note : null) : null, this.noteToken = h.note ? e(h, "note.token", h.noteToken) : null, this.databaseType = h.database_type, this.name = h.name, this.token = h.token, this.aliases = g, this.records = [], this.tablePartials = [], this.diagramViews = y, this.injectedRawRefs = [], this.processNotes(l), this.processRecords(_), this.processTablePartials(v), this.processSchemas(t), this.processSchemaElements(u, i), this.processSchemaElements(n, o), this.linkRecordsToTables(), this.processSchemaElements(l, a), this.processSchemaElements(d, "ref"), this.processSchemaElements(p, "dep"), this.processSchemaElements(m, s), this.injectedRawRefs.forEach((e) => {
26
25
  let t = this.findOrCreateSchema(r), n = new f({
27
26
  ...e,
28
27
  schema: t
29
28
  });
30
29
  t.refs.some((e) => e.equals(n)) || t.pushRef(n);
31
- }), this.nodes = [], this.groups = [], this.noteBoxes = [], this.links = [], this.kinds = [], this.frontMatter = T ?? null, this.diagramType = E ?? null, this.processArch(w, b, x, S, C);
30
+ }), this.nodes = [], this.groups = [], this.links = [], this.kinds = [], this.frontMatter = w ?? null, this.diagramType = T ?? null, this.processArch(C, b, x, S);
32
31
  }
33
- processArch(e, t, n, r, i) {
34
- e.forEach((e) => this.kinds.push(new S({
32
+ processArch(e, t, n, r) {
33
+ e.forEach((e) => this.kinds.push(new x({
35
34
  ...e,
36
35
  database: this
37
36
  }))), t.forEach((e) => this.nodes.push(new v({
@@ -40,29 +39,26 @@ var T = class extends l {
40
39
  }))), n.forEach((e) => this.groups.push(new y({
41
40
  ...e,
42
41
  database: this
43
- }))), r.forEach((e) => this.noteBoxes.push(new b({
44
- ...e,
45
- database: this
46
42
  })));
47
- let a = /* @__PURE__ */ new Map();
48
- [
49
- ...this.nodes,
50
- ...this.groups,
51
- ...this.noteBoxes
52
- ].forEach((e) => {
53
- let t = e.alias ?? e.name;
54
- a.has(t) || a.set(t, e);
55
- }), this.groups.forEach((e) => {
43
+ let i = /* @__PURE__ */ new Map(), a = (e, t, n) => {
44
+ i.has(e) || i.set(e, {
45
+ type: t,
46
+ element: n
47
+ });
48
+ };
49
+ this.nodes.forEach((e) => a(e.alias ?? e.name, "node", e)), this.groups.forEach((e) => a(e.alias ?? e.name, "group", e)), this.notes.forEach((e) => a(e.name, "note", e)), this.groups.forEach((e) => {
56
50
  e.children.forEach((t) => {
57
- let n = a.get(t);
58
- n && (e.childIds.push(n.id), n.groupId = e.id);
51
+ let n = i.get(t);
52
+ 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));
59
53
  });
60
- }), i.forEach(({ from: e, to: t, ...n }) => {
61
- let r = a.get(e), i = a.get(t);
62
- !r || !i || this.links.push(new x({
54
+ }), r.forEach(({ from: e, to: t, ...n }) => {
55
+ let r = i.get(e), a = i.get(t);
56
+ !r || !a || this.links.push(new b({
63
57
  ...n,
64
- fromId: r.id,
65
- toId: i.id,
58
+ fromId: r.element.id,
59
+ fromType: r.type,
60
+ toId: a.element.id,
61
+ toType: a.type,
66
62
  database: this
67
63
  }));
68
64
  });
@@ -203,10 +199,10 @@ var T = class extends l {
203
199
  adjustCardinalitiesFromColumns() {
204
200
  this.schemas.forEach((e) => {
205
201
  e.refs.forEach((e) => {
206
- let t = e.endpoints.find((e) => w(e.relation).max === "*"), n = e.endpoints.find((e) => w(e.relation).max === 1);
202
+ let t = e.endpoints.find((e) => C(e.relation).max === "*"), n = e.endpoints.find((e) => C(e.relation).max === 1);
207
203
  if (!n) return;
208
204
  let r, i;
209
- 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 = C(i.relation));
205
+ 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 = S(i.relation));
210
206
  });
211
207
  });
212
208
  }
@@ -242,7 +238,6 @@ var T = class extends l {
242
238
  let t = {}, n = {
243
239
  nodes: this.nodes,
244
240
  groups: this.groups,
245
- noteBoxes: this.noteBoxes,
246
241
  links: this.links,
247
242
  kinds: this.kinds
248
243
  };
@@ -255,7 +250,6 @@ var T = class extends l {
255
250
  return {
256
251
  ...e.nodes ? { nodeIds: e.nodes } : {},
257
252
  ...e.groups ? { groupIds: e.groups } : {},
258
- ...e.noteBoxes ? { noteBoxIds: e.noteBoxes } : {},
259
253
  ...e.links ? { linkIds: e.links } : {},
260
254
  ...e.kinds ? { kindIds: e.kinds } : {}
261
255
  };
@@ -292,4 +286,4 @@ var T = class extends l {
292
286
  }
293
287
  };
294
288
  //#endregion
295
- export { T as default };
289
+ export { w as default };
@@ -1 +1 @@
1
- require("../_virtual/_rolldown/runtime.cjs");var e=class{constructor(){this.dbId=1,this.schemaId=1,this.enumId=1,this.tableGroupId=1,this.refId=1,this.depId=1,this.depEdgeId=1,this.tableId=1,this.noteId=1,this.enumValueId=1,this.endpointId=1,this.indexId=1,this.checkId=1,this.fieldId=1,this.indexColumnId=1,this.recordId=1,this.tablePartialId=1,this.elementId=1,this.linkId=1,this.kindId=1}generateId(e){let t=this[e];return this[e]+=1,t}};exports.default=e;
1
+ require("../_virtual/_rolldown/runtime.cjs");var e=class{constructor(){this.dbId=1,this.schemaId=1,this.enumId=1,this.tableGroupId=1,this.refId=1,this.depId=1,this.depEdgeId=1,this.tableId=1,this.noteId=1,this.enumValueId=1,this.endpointId=1,this.indexId=1,this.checkId=1,this.fieldId=1,this.indexColumnId=1,this.recordId=1,this.tablePartialId=1,this.nodeId=1,this.groupId=1,this.linkId=1,this.kindId=1}generateId(e){let t=this[e];return this[e]+=1,t}};exports.default=e;
@@ -1,7 +1,7 @@
1
1
  //#region src/model_structure/dbState.ts
2
2
  var e = class {
3
3
  constructor() {
4
- this.dbId = 1, this.schemaId = 1, this.enumId = 1, this.tableGroupId = 1, this.refId = 1, this.depId = 1, this.depEdgeId = 1, this.tableId = 1, this.noteId = 1, this.enumValueId = 1, this.endpointId = 1, this.indexId = 1, this.checkId = 1, this.fieldId = 1, this.indexColumnId = 1, this.recordId = 1, this.tablePartialId = 1, this.elementId = 1, this.linkId = 1, this.kindId = 1;
4
+ this.dbId = 1, this.schemaId = 1, this.enumId = 1, this.tableGroupId = 1, this.refId = 1, this.depId = 1, this.depEdgeId = 1, this.tableId = 1, this.noteId = 1, this.enumValueId = 1, this.endpointId = 1, this.indexId = 1, this.checkId = 1, this.fieldId = 1, this.indexColumnId = 1, this.recordId = 1, this.tablePartialId = 1, this.nodeId = 1, this.groupId = 1, this.linkId = 1, this.kindId = 1;
5
5
  }
6
6
  generateId(e) {
7
7
  let t = this[e];
@@ -1 +1 @@
1
- require("../_virtual/_rolldown/runtime.cjs");const e=require("./element.cjs");var t=class extends e.default{constructor({name:e,alias:t,children:n,settings:r,note:i,token:a,database:o}){super(a),this.name=e,this.alias=t,this.children=n,this.childIds=[],this.settings=r,this.note=i?.value??null,this.noteToken=i?.token??null,this.groupId=null,this.database=o,this.dbState=o.dbState,this.generateId()}generateId(){this.id=this.dbState.generateId(`elementId`)}export(){return{name:this.name,alias:this.alias,settings:this.settings,note:this.note}}normalize(e){e.groups[this.id]={id:this.id,...this.export(),childIds:this.childIds,groupId:this.groupId}}};exports.default=t;
1
+ require("../_virtual/_rolldown/runtime.cjs");const e=require("./element.cjs");var t=class extends e.default{constructor({name:e,alias:t,children:n,settings:r,note:i,token:a,database:o}){super(a),this.name=e,this.alias=t,this.children=n,this.childIds=[],this.childTypes=[],this.settings=r,this.note=i?.value??null,this.noteToken=i?.token??null,this.groupId=null,this.database=o,this.dbState=o.dbState,this.generateId()}generateId(){this.id=this.dbState.generateId(`groupId`)}export(){return{name:this.name,alias:this.alias,settings:this.settings,note:this.note}}normalize(e){e.groups[this.id]={id:this.id,...this.export(),childIds:this.childIds,childTypes:this.childTypes,groupId:this.groupId}}};exports.default=t;
@@ -2,10 +2,10 @@ import e from "./element.mjs";
2
2
  //#region src/model_structure/group.ts
3
3
  var t = class extends e {
4
4
  constructor({ name: e, alias: t, children: n, settings: r, note: i, token: a, database: o }) {
5
- super(a), this.name = e, this.alias = t, this.children = n, this.childIds = [], this.settings = r, this.note = i?.value ?? null, this.noteToken = i?.token ?? null, this.groupId = null, this.database = o, this.dbState = o.dbState, this.generateId();
5
+ super(a), this.name = e, this.alias = t, this.children = n, this.childIds = [], this.childTypes = [], this.settings = r, this.note = i?.value ?? null, this.noteToken = i?.token ?? null, this.groupId = null, this.database = o, this.dbState = o.dbState, this.generateId();
6
6
  }
7
7
  generateId() {
8
- this.id = this.dbState.generateId("elementId");
8
+ this.id = this.dbState.generateId("groupId");
9
9
  }
10
10
  export() {
11
11
  return {
@@ -20,6 +20,7 @@ var t = class extends e {
20
20
  id: this.id,
21
21
  ...this.export(),
22
22
  childIds: this.childIds,
23
+ childTypes: this.childTypes,
23
24
  groupId: this.groupId
24
25
  };
25
26
  }
@@ -1 +1 @@
1
- require("../_virtual/_rolldown/runtime.cjs");const e=require("./element.cjs");var t=class extends e.default{constructor({fromId:e,toId:t,op:n,settings:r,token:i,database:a}){super(i),this.fromId=e,this.toId=t,this.op=n,this.settings=r,this.database=a,this.dbState=a.dbState,this.generateId()}generateId(){this.id=this.dbState.generateId(`linkId`)}export(){return{op:this.op,settings:this.settings}}normalize(e){e.links[this.id]={id:this.id,...this.export(),fromId:this.fromId,toId:this.toId}}};exports.default=t;
1
+ require("../_virtual/_rolldown/runtime.cjs");const e=require("./element.cjs");var t=class extends e.default{constructor({fromId:e,fromType:t,toId:n,toType:r,op:i,settings:a,token:o,database:s}){super(o),this.fromId=e,this.fromType=t,this.toId=n,this.toType=r,this.op=i,this.settings=a,this.database=s,this.dbState=s.dbState,this.generateId()}generateId(){this.id=this.dbState.generateId(`linkId`)}export(){return{op:this.op,settings:this.settings}}normalize(e){e.links[this.id]={id:this.id,...this.export(),fromId:this.fromId,fromType:this.fromType,toId:this.toId,toType:this.toType}}};exports.default=t;
@@ -1,8 +1,8 @@
1
1
  import e from "./element.mjs";
2
2
  //#region src/model_structure/link.ts
3
3
  var t = class extends e {
4
- constructor({ fromId: e, toId: t, op: n, settings: r, token: i, database: a }) {
5
- super(i), this.fromId = e, this.toId = t, this.op = n, this.settings = r, this.database = a, this.dbState = a.dbState, this.generateId();
4
+ constructor({ fromId: e, fromType: t, toId: n, toType: r, op: i, settings: a, token: o, database: s }) {
5
+ super(o), this.fromId = e, this.fromType = t, this.toId = n, this.toType = r, this.op = i, this.settings = a, this.database = s, this.dbState = s.dbState, this.generateId();
6
6
  }
7
7
  generateId() {
8
8
  this.id = this.dbState.generateId("linkId");
@@ -18,7 +18,9 @@ var t = class extends e {
18
18
  id: this.id,
19
19
  ...this.export(),
20
20
  fromId: this.fromId,
21
- toId: this.toId
21
+ fromType: this.fromType,
22
+ toId: this.toId,
23
+ toType: this.toType
22
24
  };
23
25
  }
24
26
  };
@@ -1 +1 @@
1
- require("../_virtual/_rolldown/runtime.cjs");const e=require("./element.cjs");var t=class extends e.default{constructor({name:e,alias:t,kind:n,type:r,image:i,settings:a,note:o,token:s,database:c}){super(s),this.name=e,this.alias=t,this.kindId=c.findKind(n)?.id??null,this.type=r,this.image=i,this.settings=a,this.note=o?.value??null,this.noteToken=o?.token??null,this.groupId=null,this.database=c,this.dbState=c.dbState,this.generateId()}generateId(){this.id=this.dbState.generateId(`elementId`)}export(){return{name:this.name,alias:this.alias,type:this.type,image:this.image,settings:this.settings,note:this.note}}normalize(e){e.nodes[this.id]={id:this.id,...this.export(),kindId:this.kindId,groupId:this.groupId}}};exports.default=t;
1
+ require("../_virtual/_rolldown/runtime.cjs");const e=require("./element.cjs");var t=class extends e.default{constructor({name:e,alias:t,kind:n,type:r,image:i,settings:a,note:o,token:s,database:c}){super(s),this.name=e,this.alias=t,this.kindId=c.findKind(n)?.id??null,this.type=r,this.image=i,this.settings=a,this.note=o?.value??null,this.noteToken=o?.token??null,this.groupId=null,this.database=c,this.dbState=c.dbState,this.generateId()}generateId(){this.id=this.dbState.generateId(`nodeId`)}export(){return{name:this.name,alias:this.alias,type:this.type,image:this.image,settings:this.settings,note:this.note}}normalize(e){e.nodes[this.id]={id:this.id,...this.export(),kindId:this.kindId,groupId:this.groupId}}};exports.default=t;
@@ -5,7 +5,7 @@ var t = class extends e {
5
5
  super(s), this.name = e, this.alias = t, this.kindId = c.findKind(n)?.id ?? null, this.type = r, this.image = i, this.settings = a, this.note = o?.value ?? null, this.noteToken = o?.token ?? null, this.groupId = null, this.database = c, this.dbState = c.dbState, this.generateId();
6
6
  }
7
7
  generateId() {
8
- this.id = this.dbState.generateId("elementId");
8
+ this.id = this.dbState.generateId("nodeId");
9
9
  }
10
10
  export() {
11
11
  return {
@@ -1 +1 @@
1
- require("../../_virtual/_rolldown/runtime.cjs");var e=`11.0.0-alpha.3`;exports.version=e;
1
+ require("../../_virtual/_rolldown/runtime.cjs");var e=`11.0.0-alpha.5`;exports.version=e;
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var e = "11.0.0-alpha.3";
2
+ var e = "11.0.0-alpha.5";
3
3
  //#endregion
4
4
  export { e as version };
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.3",
4
+ "version": "11.0.0-alpha.5",
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.3",
51
+ "@dbml/parse": "^11.0.0-alpha.5",
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": "41d44949afde7267a11bd9431ff5cbb7e3051b4d",
62
+ "gitHead": "994edca3bccaf94e0cfc80dfd4f9faf488152787",
63
63
  "engines": {
64
64
  "node": ">=16"
65
65
  }
@@ -17,11 +17,10 @@ import { NormalizedCheckIdMap } from './check';
17
17
  import TablePartial, { NormalizedTablePartialIdMap } from './tablePartial';
18
18
  import { TokenPosition, DiagramView } from '@dbml/parse';
19
19
  import type {
20
- Group as RawGroup, Kind as RawKind, Link as RawLink, Node as RawNode, NoteBox as RawNoteBox,
20
+ Group as RawGroup, Kind as RawKind, Link as RawLink, Node as RawNode,
21
21
  } from '@dbml/parse';
22
22
  import Node, { NormalizedNodeIdMap } from './node';
23
23
  import Group, { NormalizedGroupIdMap } from './group';
24
- import NoteBox, { NormalizedNoteBoxIdMap } from './noteBox';
25
24
  import Link, { NormalizedLinkIdMap } from './link';
26
25
  import Kind, { NormalizedKindIdMap } from './kind';
27
26
  export interface Project {
@@ -76,7 +75,6 @@ export interface RawDatabase {
76
75
  diagramViews: DiagramView[];
77
76
  nodes?: RawNode[];
78
77
  groups?: RawGroup[];
79
- noteBoxes?: RawNoteBox[];
80
78
  links?: RawLink[];
81
79
  kinds?: RawKind[];
82
80
  frontMatter?: Record<string, string>;
@@ -96,7 +94,6 @@ declare class Database extends Element {
96
94
  diagramViews: DiagramView[];
97
95
  nodes: Node[];
98
96
  groups: Group[];
99
- noteBoxes: NoteBox[];
100
97
  links: Link[];
101
98
  kinds: Kind[];
102
99
  frontMatter: Record<string, string> | null;
@@ -333,7 +330,6 @@ export interface NormalizedDatabase {
333
330
  // Present only for a file with architecture content
334
331
  nodeIds?: number[];
335
332
  groupIds?: number[];
336
- noteBoxIds?: number[];
337
333
  linkIds?: number[];
338
334
  kindIds?: number[];
339
335
  frontMatter?: Record<string, string>;
@@ -365,7 +361,6 @@ export interface NormalizedModel {
365
361
  // Present only when non-empty
366
362
  nodes?: NormalizedNodeIdMap;
367
363
  groups?: NormalizedGroupIdMap;
368
- noteBoxes?: NormalizedNoteBoxIdMap;
369
364
  links?: NormalizedLinkIdMap;
370
365
  kinds?: NormalizedKindIdMap;
371
366
  }
@@ -16,8 +16,8 @@ export default class DbState {
16
16
  indexColumnId: number;
17
17
  recordId: number;
18
18
  tablePartialId: number;
19
- // Nodes, groups and note boxes share one counter, so an id names one of them
20
- elementId: number;
19
+ nodeId: number;
20
+ groupId: number;
21
21
  linkId: number;
22
22
  kindId: number;
23
23
  generateId(el: Exclude<keyof DbState, 'generateId'>): number;
@@ -3,6 +3,7 @@ import Element, { Token } from './element';
3
3
  import Database from './database';
4
4
  import DbState from './dbState';
5
5
  import type { NormalizedModel } from './database';
6
+ import type { ArchElementType } from './link';
6
7
 
7
8
  declare class Group extends Element {
8
9
  id: number;
@@ -10,6 +11,7 @@ declare class Group extends Element {
10
11
  alias: string | null;
11
12
  children: string[];
12
13
  childIds: number[];
14
+ childTypes: ArchElementType[];
13
15
  settings: ArchSettings;
14
16
  note: string | null;
15
17
  noteToken: Token | null;
@@ -18,7 +20,7 @@ declare class Group extends Element {
18
20
  dbState: DbState;
19
21
  constructor(raw: RawGroup & { database: Database });
20
22
  generateId(): void;
21
- export(): Omit<NormalizedGroup, 'id' | 'childIds' | 'groupId'>;
23
+ export(): Omit<NormalizedGroup, 'id' | 'childIds' | 'childTypes' | 'groupId'>;
22
24
  normalize(model: NormalizedModel): void;
23
25
  }
24
26
  export interface NormalizedGroup {
@@ -26,6 +28,7 @@ export interface NormalizedGroup {
26
28
  name: string;
27
29
  alias: string | null;
28
30
  childIds: number[];
31
+ childTypes: ArchElementType[];
29
32
  settings: ArchSettings;
30
33
  note: string | null;
31
34
  groupId: number | null;
@@ -4,23 +4,30 @@ import Database from './database';
4
4
  import DbState from './dbState';
5
5
  import type { NormalizedModel } from './database';
6
6
 
7
+ // What an arch link end or group member is; ids are counted per type
8
+ export type ArchElementType = 'node' | 'group' | 'note';
9
+
7
10
  declare class Link extends Element {
8
11
  id: number;
9
12
  fromId: number;
13
+ fromType: ArchElementType;
10
14
  toId: number;
15
+ toType: ArchElementType;
11
16
  op: LinkOp;
12
17
  settings: ArchSettings;
13
18
  database: Database;
14
19
  dbState: DbState;
15
- constructor(raw: Omit<RawLink, 'from' | 'to'> & { fromId: number; toId: number; database: Database });
20
+ constructor(raw: Omit<RawLink, 'from' | 'to'> & { fromId: number; fromType: ArchElementType; toId: number; toType: ArchElementType; database: Database });
16
21
  generateId(): void;
17
- export(): Omit<NormalizedLink, 'id' | 'fromId' | 'toId'>;
22
+ export(): Omit<NormalizedLink, 'id' | 'fromId' | 'fromType' | 'toId' | 'toType'>;
18
23
  normalize(model: NormalizedModel): void;
19
24
  }
20
25
  export interface NormalizedLink {
21
26
  id: number;
22
27
  fromId: number;
28
+ fromType: ArchElementType;
23
29
  toId: number;
30
+ toType: ArchElementType;
24
31
  op: LinkOp;
25
32
  settings: ArchSettings;
26
33
  }
@@ -1 +0,0 @@
1
- require("../_virtual/_rolldown/runtime.cjs");const e=require("./element.cjs");var t=class extends e.default{constructor({name:e,alias:t,content:n,token:r,database:i}){super(r),this.name=e,this.alias=t,this.content=n,this.groupId=null,this.database=i,this.dbState=i.dbState,this.generateId()}generateId(){this.id=this.dbState.generateId(`elementId`)}export(){return{name:this.name,alias:this.alias,content:this.content}}normalize(e){e.noteBoxes[this.id]={id:this.id,...this.export(),groupId:this.groupId}}};exports.default=t;
@@ -1,26 +0,0 @@
1
- import e from "./element.mjs";
2
- //#region src/model_structure/noteBox.ts
3
- var t = class extends e {
4
- constructor({ name: e, alias: t, content: n, token: r, database: i }) {
5
- super(r), this.name = e, this.alias = t, this.content = n, this.groupId = null, this.database = i, this.dbState = i.dbState, this.generateId();
6
- }
7
- generateId() {
8
- this.id = this.dbState.generateId("elementId");
9
- }
10
- export() {
11
- return {
12
- name: this.name,
13
- alias: this.alias,
14
- content: this.content
15
- };
16
- }
17
- normalize(e) {
18
- e.noteBoxes[this.id] = {
19
- id: this.id,
20
- ...this.export(),
21
- groupId: this.groupId
22
- };
23
- }
24
- };
25
- //#endregion
26
- export { t as default };
@@ -1,30 +0,0 @@
1
- import type { NoteBox as RawNoteBox } from '@dbml/parse';
2
- import Element from './element';
3
- import Database from './database';
4
- import DbState from './dbState';
5
- import type { NormalizedModel } from './database';
6
-
7
- declare class NoteBox extends Element {
8
- id: number;
9
- name: string;
10
- alias: string | null;
11
- content: string;
12
- groupId: number | null;
13
- database: Database;
14
- dbState: DbState;
15
- constructor(raw: RawNoteBox & { database: Database });
16
- generateId(): void;
17
- export(): Omit<NormalizedNoteBox, 'id' | 'groupId'>;
18
- normalize(model: NormalizedModel): void;
19
- }
20
- export interface NormalizedNoteBox {
21
- id: number;
22
- name: string;
23
- alias: string | null;
24
- content: string;
25
- groupId: number | null;
26
- }
27
- export interface NormalizedNoteBoxIdMap {
28
- [_id: number]: NormalizedNoteBox;
29
- }
30
- export default NoteBox;