@dbml/core 11.0.1 → 11.0.2-arch.0.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.
Files changed (39) hide show
  1. package/LICENSE +0 -0
  2. package/README.md +0 -0
  3. package/lib/index.cjs +1 -1
  4. package/lib/index.mjs +5 -5
  5. package/lib/model_structure/database.cjs +1 -1
  6. package/lib/model_structure/database.mjs +68 -9
  7. package/lib/model_structure/dbState.cjs +1 -1
  8. package/lib/model_structure/dbState.mjs +1 -1
  9. package/lib/model_structure/group.cjs +1 -0
  10. package/lib/model_structure/group.mjs +30 -0
  11. package/lib/model_structure/link.cjs +1 -0
  12. package/lib/model_structure/link.mjs +28 -0
  13. package/lib/model_structure/node.cjs +1 -0
  14. package/lib/model_structure/node.mjs +31 -0
  15. package/lib/packages/dbml-core/package.json.cjs +1 -1
  16. package/lib/packages/dbml-core/package.json.mjs +1 -1
  17. package/lib/transform/index.cjs +1 -1
  18. package/lib/transform/index.mjs +9 -5
  19. package/package.json +3 -3
  20. package/types/export/DbmlExporter.d.ts +0 -0
  21. package/types/export/JsonExporter.d.ts +0 -0
  22. package/types/export/ModelExporter.d.ts +0 -0
  23. package/types/export/index.d.ts +0 -0
  24. package/types/index.d.ts +8 -0
  25. package/types/model_structure/check.d.ts +0 -0
  26. package/types/model_structure/database.d.ts +26 -0
  27. package/types/model_structure/dbState.d.ts +3 -0
  28. package/types/model_structure/element.d.ts +0 -0
  29. package/types/model_structure/enum.d.ts +0 -0
  30. package/types/model_structure/enumValue.d.ts +0 -0
  31. package/types/model_structure/group.d.ts +41 -0
  32. package/types/model_structure/index.d.ts +0 -0
  33. package/types/model_structure/indexes.d.ts +0 -0
  34. package/types/model_structure/link.d.ts +37 -0
  35. package/types/model_structure/node.d.ts +41 -0
  36. package/types/model_structure/ref.d.ts +0 -0
  37. package/types/model_structure/tablePartial.d.ts +0 -0
  38. package/types/parse/Parser.d.ts +0 -0
  39. package/types/transform/index.d.ts +7 -0
package/LICENSE CHANGED
File without changes
package/README.md CHANGED
File without changes
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,"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}}),Object.defineProperty(exports,"CompileError",{enumerable:!0,get:function(){return c.CompileError}}),Object.defineProperty(exports,"CompileErrorCode",{enumerable:!0,get:function(){return c.CompileErrorCode}}),Object.defineProperty(exports,"CompileInfo",{enumerable:!0,get:function(){return c.CompileInfo}}),Object.defineProperty(exports,"CompileWarning",{enumerable:!0,get:function(){return c.CompileWarning}}),exports.CompilerDiagnostics=e.CompilerDiagnostics,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,"applyTextEdits",{enumerable:!0,get:function(){return c.applyTextEdits}}),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,"formatTypedValue",{enumerable:!0,get:function(){return c.formatTypedValue}}),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.renameTable=a.renameTable,exports.syncDep=a.syncDep,exports.syncDiagramView=a.syncDiagramView,Object.defineProperty(exports,"syncElementMetadata",{enumerable:!0,get:function(){return c.syncElementMetadata}}),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}}),Object.defineProperty(exports,"CompileError",{enumerable:!0,get:function(){return c.CompileError}}),Object.defineProperty(exports,"CompileErrorCode",{enumerable:!0,get:function(){return c.CompileErrorCode}}),Object.defineProperty(exports,"CompileInfo",{enumerable:!0,get:function(){return c.CompileInfo}}),Object.defineProperty(exports,"CompileWarning",{enumerable:!0,get:function(){return c.CompileWarning}}),exports.CompilerDiagnostics=e.CompilerDiagnostics,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,"applyTextEdits",{enumerable:!0,get:function(){return c.applyTextEdits}}),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,"formatTypedValue",{enumerable:!0,get:function(){return c.formatTypedValue}}),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,"syncElementMetadata",{enumerable:!0,get:function(){return c.syncElementMetadata}}),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
@@ -3,8 +3,8 @@ import t from "./parse/Parser.mjs";
3
3
  import n from "./export/index.mjs";
4
4
  import r from "./export/ModelExporter.mjs";
5
5
  import i from "./import/index.mjs";
6
- import { findDiagramViewBlocks as a, renameTable as o, syncDep as s, syncDiagramView as c, updateElementSetting as l, updateElementSettingEdit as u } from "./transform/index.mjs";
7
- import { VERSION as d } from "./utils/version.mjs";
8
- import { inferMultiplicitiesFromColumns as f } from "./transform/relations.mjs";
9
- import { CARDINALITY_MANY as p, CARDINALITY_MAYBE as m, CARDINALITY_ONE as h, CARDINALITY_SOME as g, CompileError as _, CompileErrorCode as v, CompileInfo as y, CompileWarning as b, DEFAULT_ENTRY as x, Filepath as S, MetadataKind as C, SymbolKind as w, addDoubleQuoteIfNeeded as T, applyTextEdits as E, dbmlMonarchTokensProvider as D, formatTypedValue as O, getMultiplicities as k, getRelationshipOp as A, isBinaryType as j, isBooleanType as M, isDateTimeType as N, isEndpointManySide as P, isEndpointOneSide as F, isEndpointOptional as I, isEndpointRequired as L, isFloatType as R, isIntegerType as z, isNumericType as B, isSerialType as V, isStringType as H, makeRelationshipRequired as U, syncElementMetadata as W, tryExtractBoolean as G, tryExtractDateTime as K, tryExtractEnum as q, tryExtractInteger as J, tryExtractNumeric as Y, tryExtractString as X } from "@dbml/parse";
10
- export { p as CARDINALITY_MANY, m as CARDINALITY_MAYBE, h as CARDINALITY_ONE, g as CARDINALITY_SOME, _ as CompileError, v as CompileErrorCode, y as CompileInfo, b as CompileWarning, e as CompilerDiagnostics, x as DEFAULT_ENTRY, S as Filepath, C as MetadataKind, r as ModelExporter, t as Parser, w as SymbolKind, d as VERSION, T as addDoubleQuoteIfNeeded, E as applyTextEdits, D as dbmlMonarchTokensProvider, n as exporter, a as findDiagramViewBlocks, O as formatTypedValue, k as getMultiplicities, A as getRelationshipOp, i as importer, f as inferMultiplicitiesFromColumns, j as isBinaryType, M as isBooleanType, N as isDateTimeType, P as isEndpointManySide, F as isEndpointOneSide, I as isEndpointOptional, L as isEndpointRequired, R as isFloatType, z as isIntegerType, B as isNumericType, V as isSerialType, H as isStringType, U as makeRelationshipRequired, o as renameTable, s as syncDep, c as syncDiagramView, W as syncElementMetadata, G as tryExtractBoolean, K as tryExtractDateTime, q as tryExtractEnum, J as tryExtractInteger, Y as tryExtractNumeric, X as tryExtractString, l as updateElementSetting, u as updateElementSettingEdit };
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
+ import { VERSION as f } from "./utils/version.mjs";
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, CompileError as y, CompileErrorCode as b, CompileInfo as x, CompileWarning as S, DEFAULT_ENTRY as C, Filepath as w, MetadataKind as T, NAME_PRECEDENCE as E, SymbolKind as D, addDoubleQuoteIfNeeded as O, applyTextEdits as k, dbmlMonarchTokensProvider as A, formatTypedValue as j, fullName as M, getMultiplicities as N, getRelationshipOp as P, isBinaryType as F, isBooleanType as I, isDateTimeType as L, isEndpointManySide as R, isEndpointOneSide as z, isEndpointOptional as B, isEndpointRequired as V, isFloatType as H, isIntegerType as U, isNumericType as W, isSerialType as G, isStringType as K, makeRelationshipRequired as q, syncElementMetadata as J, tryExtractBoolean as Y, tryExtractDateTime as X, tryExtractEnum as Z, tryExtractInteger as Q, tryExtractNumeric as $, tryExtractString as ee } from "@dbml/parse";
10
+ export { m as BUILTIN_ROLES, h as CARDINALITY_MANY, g as CARDINALITY_MAYBE, _ as CARDINALITY_ONE, v as CARDINALITY_SOME, y as CompileError, b as CompileErrorCode, x as CompileInfo, S as CompileWarning, e as CompilerDiagnostics, C as DEFAULT_ENTRY, w as Filepath, T as MetadataKind, r as ModelExporter, E as NAME_PRECEDENCE, t as Parser, D as SymbolKind, f as VERSION, O as addDoubleQuoteIfNeeded, k as applyTextEdits, A as dbmlMonarchTokensProvider, n as exporter, a as findDiagramViewBlocks, j as formatTypedValue, M as fullName, N as getMultiplicities, P as getRelationshipOp, i as importer, p as inferMultiplicitiesFromColumns, F as isBinaryType, I as isBooleanType, L as isDateTimeType, R as isEndpointManySide, z as isEndpointOneSide, B as isEndpointOptional, V as isEndpointRequired, H as isFloatType, U as isIntegerType, W as isNumericType, G as isSerialType, K as isStringType, q as makeRelationshipRequired, o as renameElement, s as renameTable, c as syncDep, l as syncDiagramView, J as syncElementMetadata, Y as tryExtractBoolean, X as tryExtractDateTime, Z as tryExtractEnum, Q as tryExtractInteger, $ as tryExtractNumeric, ee 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");let m=require("@dbml/parse");n.init_lodash();var h=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=[]}={}){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)})}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}))}})}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=t.schemaName??`public`,r=e[n]?.[t.tableName];r&&(t.tableId=r.id,r.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,m.parseCardinality)(e.relation).max===`*`),n=e.endpoints.find(e=>(0,m.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,m.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}))}}exportChildIds(){return{schemaIds:this.schemas.map(e=>e.id),noteIds:this.notes.map(e=>e.id)}}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)),e}};exports.default=h;
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.diagramType=b??null,this.frontMatter=y??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}))}})}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=t.schemaName??`public`,r=e[n]?.[t.tableName];r&&(t.tableId=r.id,r.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.diagramType?{diagramType:this.diagramType}:{},...this.frontMatter?{frontMatter:this.frontMatter}:{}}}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;
@@ -12,17 +12,52 @@ import m from "./tableGroup.mjs";
12
12
  import h from "./schema.mjs";
13
13
  import g from "./stickyNote.mjs";
14
14
  import _ from "./tablePartial.mjs";
15
- import { makeCardinalityRequired as v, parseCardinality as y } from "@dbml/parse";
15
+ import v from "./node.mjs";
16
+ import y from "./group.mjs";
17
+ import b from "./link.mjs";
18
+ import { makeCardinalityRequired as x, parseCardinality as S } from "@dbml/parse";
16
19
  //#region src/model_structure/database.ts
17
20
  n();
18
- var b = class extends l {
19
- constructor({ schemas: t = [], tables: n = [], notes: l = [], enums: u = [], refs: d = [], deps: p = [], tableGroups: m = [], project: h = {}, aliases: g = [], records: _ = [], tablePartials: v = [], diagramViews: y = [] } = {}) {
21
+ var C = class extends l {
22
+ 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 = [], frontMatter: C, diagramType: w } = {}) {
20
23
  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) => {
21
24
  let t = this.findOrCreateSchema(r), n = new f({
22
25
  ...e,
23
26
  schema: t
24
27
  });
25
28
  t.refs.some((e) => e.equals(n)) || t.pushRef(n);
29
+ }), this.nodes = [], this.groups = [], this.links = [], this.diagramType = w ?? null, this.frontMatter = C ?? null, this.processArch(b, x, S);
30
+ }
31
+ processArch(e, t, n) {
32
+ e.forEach((e) => this.nodes.push(new v({
33
+ ...e,
34
+ database: this
35
+ }))), t.forEach((e) => this.groups.push(new y({
36
+ ...e,
37
+ database: this
38
+ })));
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
44
+ });
45
+ };
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));
50
+ });
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,
59
+ database: this
60
+ }));
26
61
  });
27
62
  }
28
63
  generateId() {
@@ -155,10 +190,10 @@ var b = class extends l {
155
190
  adjustCardinalitiesFromColumns() {
156
191
  this.schemas.forEach((e) => {
157
192
  e.refs.forEach((e) => {
158
- let t = e.endpoints.find((e) => y(e.relation).max === "*"), n = e.endpoints.find((e) => y(e.relation).max === 1);
193
+ let t = e.endpoints.find((e) => S(e.relation).max === "*"), n = e.endpoints.find((e) => S(e.relation).max === 1);
159
194
  if (!n) return;
160
195
  let r, i;
161
- 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 = v(i.relation));
196
+ 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 = x(i.relation));
162
197
  });
163
198
  });
164
199
  }
@@ -177,13 +212,35 @@ var b = class extends l {
177
212
  return {
178
213
  schemas: this.schemas.map((e) => e.export()),
179
214
  notes: this.notes.map((e) => e.export()),
180
- records: this.records.map((e) => ({ ...e }))
215
+ records: this.records.map((e) => ({ ...e })),
216
+ ...this.archEntries((e) => e.map((e) => e.export()))
181
217
  };
182
218
  }
183
219
  exportChildIds() {
184
220
  return {
185
221
  schemaIds: this.schemas.map((e) => e.id),
186
- noteIds: this.notes.map((e) => e.id)
222
+ noteIds: this.notes.map((e) => e.id),
223
+ ...this.archIds(),
224
+ ...this.diagramType ? { diagramType: this.diagramType } : {},
225
+ ...this.frontMatter ? { frontMatter: this.frontMatter } : {}
226
+ };
227
+ }
228
+ archEntries(e) {
229
+ let t = {}, n = {
230
+ nodes: this.nodes,
231
+ groups: this.groups,
232
+ links: this.links
233
+ };
234
+ return Object.entries(n).forEach(([n, r]) => {
235
+ r.length && (t[n] = e(r));
236
+ }), t;
237
+ }
238
+ archIds() {
239
+ let e = this.archEntries((e) => e.map((e) => e.id));
240
+ return {
241
+ ...e.nodes ? { nodeIds: e.nodes } : {},
242
+ ...e.groups ? { groupIds: e.groups } : {},
243
+ ...e.links ? { linkIds: e.links } : {}
187
244
  };
188
245
  }
189
246
  normalize() {
@@ -212,8 +269,10 @@ var b = class extends l {
212
269
  };
213
270
  return this.schemas.forEach((t) => t.normalize(e)), this.notes.forEach((t) => t.normalize(e)), this.records.forEach((t) => {
214
271
  e.records[t.id] = { ...t };
215
- }), this.tablePartials.forEach((t) => t.normalize(e)), e;
272
+ }), this.tablePartials.forEach((t) => t.normalize(e)), Object.entries(this.archEntries((e) => e)).forEach(([t, n]) => {
273
+ e[t] = {}, n.forEach((t) => t.normalize(e));
274
+ }), e;
216
275
  }
217
276
  };
218
277
  //#endregion
219
- export { b as default };
278
+ export { C 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}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}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;
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;
5
5
  }
6
6
  generateId(e) {
7
7
  let t = this[e];
@@ -0,0 +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,metadata:i={},note:a,token:o,database:s}){super(o),this.name=e,this.alias=t,this.children=n,this.childIds=[],this.childTypes=[],this.settings=r,this.metadata=i,this.note=a?.value??null,this.noteToken=a?.token??null,this.groupId=null,this.database=s,this.dbState=s.dbState,this.generateId()}generateId(){this.id=this.dbState.generateId(`groupId`)}export(){return{name:this.name,alias:this.alias,settings:this.settings,metadata:this.metadata,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;
@@ -0,0 +1,30 @@
1
+ import e from "./element.mjs";
2
+ //#region src/model_structure/group.ts
3
+ var t = class extends e {
4
+ constructor({ name: e, alias: t, children: n, settings: r, metadata: i = {}, note: a, token: o, database: s }) {
5
+ super(o), this.name = e, this.alias = t, this.children = n, this.childIds = [], this.childTypes = [], this.settings = r, this.metadata = i, this.note = a?.value ?? null, this.noteToken = a?.token ?? null, this.groupId = null, this.database = s, this.dbState = s.dbState, this.generateId();
6
+ }
7
+ generateId() {
8
+ this.id = this.dbState.generateId("groupId");
9
+ }
10
+ export() {
11
+ return {
12
+ name: this.name,
13
+ alias: this.alias,
14
+ settings: this.settings,
15
+ metadata: this.metadata,
16
+ note: this.note
17
+ };
18
+ }
19
+ normalize(e) {
20
+ e.groups[this.id] = {
21
+ id: this.id,
22
+ ...this.export(),
23
+ childIds: this.childIds,
24
+ childTypes: this.childTypes,
25
+ groupId: this.groupId
26
+ };
27
+ }
28
+ };
29
+ //#endregion
30
+ export { t as default };
@@ -0,0 +1 @@
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;
@@ -0,0 +1,28 @@
1
+ import e from "./element.mjs";
2
+ //#region src/model_structure/link.ts
3
+ var t = class extends e {
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
+ }
7
+ generateId() {
8
+ this.id = this.dbState.generateId("linkId");
9
+ }
10
+ export() {
11
+ return {
12
+ op: this.op,
13
+ settings: this.settings
14
+ };
15
+ }
16
+ normalize(e) {
17
+ e.links[this.id] = {
18
+ id: this.id,
19
+ ...this.export(),
20
+ fromId: this.fromId,
21
+ fromType: this.fromType,
22
+ toId: this.toId,
23
+ toType: this.toType
24
+ };
25
+ }
26
+ };
27
+ //#endregion
28
+ export { t as default };
@@ -0,0 +1 @@
1
+ require("../_virtual/_rolldown/runtime.cjs");const e=require("./element.cjs");var t=class extends e.default{constructor({name:e,alias:t,role:n,type:r,icon:i,settings:a,metadata:o={},note:s,token:c,database:l}){super(c),this.name=e,this.alias=t,this.role=n,this.type=r,this.icon=i,this.settings=a,this.metadata=o,this.note=s?.value??null,this.noteToken=s?.token??null,this.groupId=null,this.database=l,this.dbState=l.dbState,this.generateId()}generateId(){this.id=this.dbState.generateId(`nodeId`)}export(){return{name:this.name,alias:this.alias,role:this.role,type:this.type,icon:this.icon,settings:this.settings,metadata:this.metadata,note:this.note}}normalize(e){e.nodes[this.id]={id:this.id,...this.export(),groupId:this.groupId}}};exports.default=t;
@@ -0,0 +1,31 @@
1
+ import e from "./element.mjs";
2
+ //#region src/model_structure/node.ts
3
+ var t = class extends e {
4
+ constructor({ name: e, alias: t, role: n, type: r, icon: i, settings: a, metadata: o = {}, note: s, token: c, database: l }) {
5
+ super(c), this.name = e, this.alias = t, this.role = n, this.type = r, this.icon = i, this.settings = a, this.metadata = o, this.note = s?.value ?? null, this.noteToken = s?.token ?? null, this.groupId = null, this.database = l, this.dbState = l.dbState, this.generateId();
6
+ }
7
+ generateId() {
8
+ this.id = this.dbState.generateId("nodeId");
9
+ }
10
+ export() {
11
+ return {
12
+ name: this.name,
13
+ alias: this.alias,
14
+ role: this.role,
15
+ type: this.type,
16
+ icon: this.icon,
17
+ settings: this.settings,
18
+ metadata: this.metadata,
19
+ note: this.note
20
+ };
21
+ }
22
+ normalize(e) {
23
+ e.nodes[this.id] = {
24
+ id: this.id,
25
+ ...this.export(),
26
+ groupId: this.groupId
27
+ };
28
+ }
29
+ };
30
+ //#endregion
31
+ export { t as default };
@@ -1 +1 @@
1
- require("../../_virtual/_rolldown/runtime.cjs");var e=`11.0.1`;exports.version=e;
1
+ require("../../_virtual/_rolldown/runtime.cjs");var e=`11.0.2-arch.0.0`;exports.version=e;
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var e = "11.0.1";
2
+ var e = "11.0.2-arch.0.0";
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,t),new e.Compiler(i).syncDiagramView(e.DEFAULT_ENTRY,n,r)}function r(t,n){let r=new e.MemoryProjectLayout;return r.setSource(e.DEFAULT_ENTRY,t),new e.Compiler(r).syncDep(e.DEFAULT_ENTRY,n)}function i(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 a(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.renameTable=t,exports.syncDep=r,exports.syncDiagramView=n,exports.updateElementSetting=a,exports.updateElementSettingEdit=i;
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,21 +4,25 @@ 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) {
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
+ }
11
+ function o(r, i, a) {
8
12
  let o = new n();
9
13
  return o.setSource(t, r), new e(o).syncDiagramView(t, i, a);
10
14
  }
11
- function o(r, i) {
15
+ function s(r, i) {
12
16
  let a = new n();
13
17
  return a.setSource(t, r), new e(a).syncDep(t, i);
14
18
  }
15
- function s(r, i, a, o) {
19
+ function c(r, i, a, o) {
16
20
  let s = new n();
17
21
  return s.setSource(t, r), new e(s).updateElementSettingEdit(t, i, a, o);
18
22
  }
19
- function c(r, i, a, o) {
23
+ function l(r, i, a, o) {
20
24
  let s = new n();
21
25
  return s.setSource(t, r), new e(s).updateElementSetting(t, i, a, o);
22
26
  }
23
27
  //#endregion
24
- export { r as findDiagramViewBlocks, i as renameTable, o as syncDep, a as syncDiagramView, c as updateElementSetting, s as updateElementSettingEdit };
28
+ export { r as findDiagramViewBlocks, a as renameElement, i as renameTable, s as syncDep, o as syncDiagramView, l as updateElementSetting, c as updateElementSettingEdit };
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.1",
4
+ "version": "11.0.2-arch.0.0",
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.1",
51
+ "@dbml/parse": "11.0.2-arch.0.0",
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": "0418f4b2e67a160852e500bddf1992e10196d5ac",
62
+ "gitHead": "74af6a5d1699f45d51e5512fa3ce5988c1ae60a9",
63
63
  "engines": {
64
64
  "node": ">=16"
65
65
  }
File without changes
File without changes
File without changes
File without changes
package/types/index.d.ts CHANGED
@@ -4,6 +4,7 @@ import importer from './import';
4
4
  import exporter from './export';
5
5
  import {
6
6
  renameTable,
7
+ renameElement,
7
8
  updateElementSetting,
8
9
  updateElementSettingEdit,
9
10
  syncDiagramView,
@@ -12,6 +13,7 @@ import {
12
13
  } from './transform';
13
14
  export {
14
15
  renameTable,
16
+ renameElement,
15
17
  updateElementSetting,
16
18
  updateElementSettingEdit,
17
19
  syncDiagramView,
@@ -68,6 +70,9 @@ export {
68
70
  isEndpointOptional,
69
71
  isEndpointRequired,
70
72
  makeRelationshipRequired,
73
+ BUILTIN_ROLES,
74
+ NAME_PRECEDENCE,
75
+ fullName,
71
76
  } from '@dbml/parse';
72
77
 
73
78
  export { inferMultiplicitiesFromColumns } from './transform/relations';
@@ -95,11 +100,14 @@ export type {
95
100
  DepIdentifier,
96
101
  NoteIdentifier,
97
102
  TableGroupIdentifier,
103
+ ArchElementIdentifier,
104
+ ArchLinkIdentifier,
98
105
  CustomMetadata,
99
106
  CustomMetadataValue,
100
107
  CustomMetadataValueType,
101
108
  RelationCardinality,
102
109
  RelationshipOp,
103
110
  DbmlProjectLayout,
111
+ RoleSpec,
104
112
  FileSpecifierInfo,
105
113
  } from '@dbml/parse';
File without changes
@@ -16,6 +16,12 @@ import { NormalizedIndexIdMap } from './indexes';
16
16
  import { NormalizedCheckIdMap } from './check';
17
17
  import TablePartial, { NormalizedTablePartialIdMap } from './tablePartial';
18
18
  import { TokenPosition, DiagramView } from '@dbml/parse';
19
+ import type {
20
+ Group as RawGroup, Link as RawLink, Node as RawNode,
21
+ } from '@dbml/parse';
22
+ import Node, { NormalizedNodeIdMap } from './node';
23
+ import Group, { NormalizedGroupIdMap } from './group';
24
+ import Link, { NormalizedLinkIdMap } from './link';
19
25
  export interface Project {
20
26
  note: RawNote;
21
27
  database_type: string;
@@ -66,6 +72,11 @@ export interface RawDatabase {
66
72
  records: RawTableRecord[];
67
73
  tablePartials: TablePartial[];
68
74
  diagramViews: DiagramView[];
75
+ nodes?: RawNode[];
76
+ groups?: RawGroup[];
77
+ links?: RawLink[];
78
+ frontMatter?: Record<string, string>;
79
+ diagramType?: 'arch';
69
80
  }
70
81
 
71
82
  declare class Database extends Element {
@@ -79,6 +90,11 @@ declare class Database extends Element {
79
90
  name: string;
80
91
  records: TableRecord[];
81
92
  diagramViews: DiagramView[];
93
+ nodes: Node[];
94
+ groups: Group[];
95
+ links: Link[];
96
+ diagramType: 'arch' | null;
97
+ frontMatter: Record<string, string> | null;
82
98
  id: number;
83
99
  constructor({ schemas, tables, enums, refs, tableGroups, project, records }: RawDatabase);
84
100
  generateId(): void;
@@ -307,6 +323,12 @@ export interface NormalizedDatabase {
307
323
  name: string;
308
324
  schemaIds: number[];
309
325
  noteIds: number[];
326
+ // Present only for a file with architecture content
327
+ nodeIds?: number[];
328
+ groupIds?: number[];
329
+ linkIds?: number[];
330
+ diagramType?: 'arch';
331
+ frontMatter?: Record<string, string>;
310
332
  }
311
333
 
312
334
  export interface NormalizedDatabaseIdMap {
@@ -331,5 +353,9 @@ export interface NormalizedModel {
331
353
  checks: NormalizedCheckIdMap;
332
354
  tablePartials: NormalizedTablePartialIdMap;
333
355
  records: NormalizedRecordIdMap;
356
+ // Present only when non-empty
357
+ nodes?: NormalizedNodeIdMap;
358
+ groups?: NormalizedGroupIdMap;
359
+ links?: NormalizedLinkIdMap;
334
360
  }
335
361
  export default Database;
@@ -16,5 +16,8 @@ export default class DbState {
16
16
  indexColumnId: number;
17
17
  recordId: number;
18
18
  tablePartialId: number;
19
+ nodeId: number;
20
+ groupId: number;
21
+ linkId: number;
19
22
  generateId(el: Exclude<keyof DbState, 'generateId'>): number;
20
23
  }
File without changes
File without changes
File without changes
@@ -0,0 +1,41 @@
1
+ import type { ArchRef, ArchSettings, CustomMetadata, Group as RawGroup } from '@dbml/parse';
2
+ import Element, { Token } from './element';
3
+ import Database from './database';
4
+ import DbState from './dbState';
5
+ import type { NormalizedModel } from './database';
6
+ import type { ArchElementType } from './link';
7
+
8
+ declare class Group extends Element {
9
+ id: number;
10
+ name: string;
11
+ alias: string | null;
12
+ children: ArchRef[];
13
+ childIds: number[];
14
+ childTypes: ArchElementType[];
15
+ settings: ArchSettings;
16
+ metadata: CustomMetadata;
17
+ note: string | null;
18
+ noteToken: Token | null;
19
+ groupId: number | null;
20
+ database: Database;
21
+ dbState: DbState;
22
+ constructor(raw: RawGroup & { database: Database });
23
+ generateId(): void;
24
+ export(): Omit<NormalizedGroup, 'id' | 'childIds' | 'childTypes' | 'groupId'>;
25
+ normalize(model: NormalizedModel): void;
26
+ }
27
+ export interface NormalizedGroup {
28
+ id: number;
29
+ name: string;
30
+ alias: string | null;
31
+ childIds: number[];
32
+ childTypes: ArchElementType[];
33
+ settings: ArchSettings;
34
+ metadata: CustomMetadata;
35
+ note: string | null;
36
+ groupId: number | null;
37
+ }
38
+ export interface NormalizedGroupIdMap {
39
+ [_id: number]: NormalizedGroup;
40
+ }
41
+ export default Group;
File without changes
File without changes
@@ -0,0 +1,37 @@
1
+ import type { ArchSettings, LinkOp, Link as RawLink } 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
+ // What an arch link end or group member is; ids are counted per type
8
+ export type ArchElementType = 'node' | 'group' | 'note';
9
+
10
+ declare class Link extends Element {
11
+ id: number;
12
+ fromId: number;
13
+ fromType: ArchElementType;
14
+ toId: number;
15
+ toType: ArchElementType;
16
+ op: LinkOp;
17
+ settings: ArchSettings;
18
+ database: Database;
19
+ dbState: DbState;
20
+ constructor(raw: Omit<RawLink, 'from' | 'fromRole' | 'to' | 'toRole'> & { fromId: number; fromType: ArchElementType; toId: number; toType: ArchElementType; database: Database });
21
+ generateId(): void;
22
+ export(): Omit<NormalizedLink, 'id' | 'fromId' | 'fromType' | 'toId' | 'toType'>;
23
+ normalize(model: NormalizedModel): void;
24
+ }
25
+ export interface NormalizedLink {
26
+ id: number;
27
+ fromId: number;
28
+ fromType: ArchElementType;
29
+ toId: number;
30
+ toType: ArchElementType;
31
+ op: LinkOp;
32
+ settings: ArchSettings;
33
+ }
34
+ export interface NormalizedLinkIdMap {
35
+ [_id: number]: NormalizedLink;
36
+ }
37
+ export default Link;
@@ -0,0 +1,41 @@
1
+ import type { ArchSettings, CustomMetadata, Node as RawNode } from '@dbml/parse';
2
+ import Element, { Token } from './element';
3
+ import Database from './database';
4
+ import DbState from './dbState';
5
+ import type { NormalizedModel } from './database';
6
+
7
+ declare class Node extends Element {
8
+ id: number;
9
+ name: string;
10
+ alias: string | null;
11
+ role: string;
12
+ type: string | null;
13
+ icon: string | null;
14
+ settings: ArchSettings;
15
+ metadata: CustomMetadata;
16
+ note: string | null;
17
+ noteToken: Token | null;
18
+ groupId: number | null;
19
+ database: Database;
20
+ dbState: DbState;
21
+ constructor(raw: RawNode & { database: Database });
22
+ generateId(): void;
23
+ export(): Omit<NormalizedNode, 'id' | 'groupId'>;
24
+ normalize(model: NormalizedModel): void;
25
+ }
26
+ export interface NormalizedNode {
27
+ id: number;
28
+ name: string;
29
+ alias: string | null;
30
+ role: string;
31
+ type: string | null;
32
+ icon: string | null;
33
+ settings: ArchSettings;
34
+ metadata: CustomMetadata;
35
+ note: string | null;
36
+ groupId: number | null;
37
+ }
38
+ export interface NormalizedNodeIdMap {
39
+ [_id: number]: NormalizedNode;
40
+ }
41
+ export default Node;
File without changes
File without changes
File without changes
@@ -9,6 +9,13 @@ export function renameTable(
9
9
  dbmlCode: string
10
10
  ): string;
11
11
 
12
+ export function renameElement(
13
+ oldHandle: string,
14
+ newName: string,
15
+ dbmlCode: string,
16
+ role?: string,
17
+ ): string;
18
+
12
19
  export function updateElementSettingEdit(
13
20
  dbmlCode: string,
14
21
  target: ElementIdentifier,