@dbml/core 10.4.0-alpha.1 → 10.4.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/export/DbmlExporter.cjs +2 -2
- package/lib/export/DbmlExporter.mjs +5 -2
- package/lib/index.cjs +1 -1
- package/lib/index.mjs +3 -3
- package/lib/model_structure/element.cjs +1 -1
- package/lib/model_structure/element.mjs +2 -5
- package/lib/model_structure/utils.mjs +1 -1
- package/lib/packages/dbml-core/package.json.cjs +1 -1
- package/lib/packages/dbml-core/package.json.mjs +1 -1
- package/lib/parse/ANTLR/ASTGeneration/oraclesql/OracleSQLASTGen.cjs +1 -1
- package/lib/parse/ANTLR/ASTGeneration/oraclesql/OracleSQLASTGen.mjs +1 -1
- package/lib/parse/Parser.cjs +1 -1
- package/lib/parse/Parser.mjs +1 -1
- package/lib/parse/error.cjs +1 -1
- package/lib/parse/error.mjs +1 -1
- package/package.json +4 -4
- package/types/index.d.ts +9 -1
- package/types/model_structure/element.d.ts +2 -30
- package/types/parse/error.d.ts +3 -3
|
@@ -4,7 +4,7 @@ require("../_virtual/_rolldown/runtime.cjs");const e=require("../node_modules/lo
|
|
|
4
4
|
`)}\n}\n`});return n.length?n.join(`
|
|
5
5
|
`):``}static getFieldLines(e,t){return t.tables[e].fieldIds.map(e=>{let n=t.fields[e],i=``;n.type.schemaName&&n.type.schemaName!==`public`&&(i=r.hasWhiteSpace(n.type.schemaName)?`"${n.type.schemaName}".`:`${n.type.schemaName}.`);let a=`"${n.name}" ${i}${r.hasWhiteSpace(n.type.type_name)||r.hasSquareBracket(n.type.type_name)?`"${n.type.type_name}"`:n.type.type_name}`,o=[];if(n.unique&&o.push(`unique`),n.pk&&o.push(`pk`),n.not_null&&o.push(`not null`),n.increment&&o.push(`increment`),n.checkIds&&o.push(...n.checkIds.map(e=>`check: \`${t.checks[e].expression}\``)),n.dbdefault&&!(n.dbdefault.type===`boolean`&&(n.dbdefault.value===null||typeof n.dbdefault.value==`string`&&n.dbdefault.value.toLowerCase()===`null`))){let e=`default: `;switch(n.dbdefault.type){case`boolean`:case`number`:e+=`${n.dbdefault.value}`;break;case`string`:{let t=String(n.dbdefault.value),r=t.includes(`
|
|
6
6
|
`)?`'''`:`'`;e+=`${r}${t}${r}`;break}case`expression`:e+=`\`${n.dbdefault.value}\``;break;default:e+=`\`${n.dbdefault.value}\``;break}o.push(e)}return n.note&&o.push(`note: ${r.escapeNote(n.note)}`),o.length>0&&(a+=` [${o.join(`, `)}]`),a})}static getIndexLines(e,t){return t.tables[e].indexIds.map(e=>{let n=``,r=t.indexes[e];if(r.columnIds.length>1)n=`(${r.columnIds.map(e=>{let n=t.indexColumns[e];return n.type===`expression`?`\`${n.value}\``:n.value}).join(`, `)})`;else if(r.columnIds.length===1){let e=t.indexColumns[r.columnIds[0]];n=e.type===`expression`?`\`${e.value}\``:e.value}let i=[];return r.pk&&i.push(`pk`),r.type&&i.push(`type: ${r.type.toLowerCase()}`),r.unique&&i.push(`unique`),r.name&&i.push(`name: "${r.name}"`),i.length>1?n+=` [${i.join(`, `)}]`:i.length===1&&(n+=` [${i[0]}]`),n})}static getCheckLines(e,t){return t.tables[e].checkIds.map(e=>{let n=``,{expression:r,name:i}=t.checks[e];return n+=`\`${r}\``,i&&(n+=` [name: '${i}']`),n})}static getTableContentArr(e,t){return e.map(e=>({tableId:e,fieldContents:r.getFieldLines(e,t),checkContents:r.getCheckLines(e,t),indexContents:r.getIndexLines(e,t)}))}static getTableSettings(e){let t=``;return e.headerColor&&(t+=`headerColor: ${e.headerColor}, `),t.endsWith(`, `)&&(t=t.replace(/,\s$/,``)),t?` [${t}]`:``}static exportTables(e,n){let o=r.getTableContentArr(e,n).map(e=>{let o=n.tables[e.tableId],s=n.schemas[o.schemaId],c=r.getTableSettings(o),l=`"${o.name}"`;i.shouldPrintSchema(s,n)&&(l=`"${s.name}"."${o.name}"`);let u=o.alias?` as ${(0,a.addDoubleQuoteIfNeeded)(o.alias)}`:``,d=e.fieldContents.map(e=>` ${e}\n`).join(``),f=``;t.default(e.checkContents)||(f=`\n Checks {\n${e.checkContents.map(e=>` ${e}\n`).join(``)} }\n`);let p=``;t.default(e.indexContents)||(p=`\n Indexes {\n${e.indexContents.map(e=>` ${e}\n`).join(``)} }\n`);let m=o.note?` Note: ${r.escapeNote(o.note)}\n`:``;return`Table ${l}${u}${c} {\n${d}${f}${p}${m}}\n`});return o.length?o.join(`
|
|
7
|
-
`):``}static buildFieldName(e,t){let n=e.map(e=>`"${t.fields[e].name}"`).join(`, `);return e.length===1?n:`(${n})`}static exportRefs(e,t){let n=e.map(e=>{let n=t.refs[e],o=n.endpointIds.findIndex(e=>(0,a.parseCardinality)(t.endpoints[e].relation).max===1),s=o===-1?0:o,c=t.endpoints[n.endpointIds[s]],l=t.endpoints[n.endpointIds[1-s]],u=(0,a.getRelationshipOp)(c.relation,l.relation),d=t.fields[c.fieldIds[0]],f=t.tables[d.tableId],p=t.schemas[f.schemaId],m=r.buildFieldName(c.fieldIds,t),h=`Ref`;n.name&&(h+=` ${i.shouldPrintSchema(t.schemas[n.schemaId],t)?`"${t.schemas[n.schemaId].name}".`:``}"${n.name}"`),h+=`:`,h+=`${i.shouldPrintSchema(p,t)?`"${p.name}".`:``}"${f.name}".${m} `;let g=t.fields[l.fieldIds[0]],_=t.tables[g.tableId],v=t.schemas[_.schemaId],y=r.buildFieldName(l.fieldIds,t);h+=`${u} `,h+=`${i.shouldPrintSchema(v,t)?`"${v.name}".`:``}"${_.name}".${y}`;let b=[];return n.onUpdate&&b.push(`update: ${n.onUpdate.toLowerCase()}`),n.onDelete&&b.push(`delete: ${n.onDelete.toLowerCase()}`),n.color&&b.push(`color: ${n.color}`),n.inactive&&b.push(`inactive`),Object.entries(n.metadata??{}).forEach(([e,t])=>{b.push(`${e}: ${r.formatDepCustomValue(t)}`)}),b.length>0&&(h+=` [${b.join(`, `)}]`),h+=`
|
|
7
|
+
`):``}static buildFieldName(e,t){let n=e.map(e=>`"${t.fields[e].name}"`).join(`, `);return e.length===1?n:`(${n})`}static exportRefs(e,t){let n=e.map(e=>{let n=t.refs[e],o=n.endpointIds.findIndex(e=>(0,a.parseCardinality)(t.endpoints[e].relation).max===1),s=o===-1?0:o,c=t.endpoints[n.endpointIds[s]],l=t.endpoints[n.endpointIds[1-s]],u=(0,a.getRelationshipOp)(c.relation,l.relation),d=t.fields[c.fieldIds[0]],f=t.tables[d.tableId],p=t.schemas[f.schemaId],m=r.buildFieldName(c.fieldIds,t),h=`Ref`;n.name&&(h+=` ${i.shouldPrintSchema(t.schemas[n.schemaId],t)?`"${t.schemas[n.schemaId].name}".`:``}"${n.name}"`),h+=`:`,h+=`${i.shouldPrintSchema(p,t)?`"${p.name}".`:``}"${f.name}".${m} `;let g=t.fields[l.fieldIds[0]],_=t.tables[g.tableId],v=t.schemas[_.schemaId],y=r.buildFieldName(l.fieldIds,t);h+=`${u} `,h+=`${i.shouldPrintSchema(v,t)?`"${v.name}".`:``}"${_.name}".${y}`;let b=[];return n.onUpdate&&b.push(`update: ${n.onUpdate.toLowerCase()}`),n.onDelete&&b.push(`delete: ${n.onDelete.toLowerCase()}`),n.color&&b.push(`color: ${n.color}`),n.inactive&&b.push(`inactive`),n.note&&b.push(`note: ${r.escapeNote(n.note)}`),Object.entries(n.metadata??{}).forEach(([e,t])=>{b.push(`${e}: ${r.formatDepCustomValue(t)}`)}),b.length>0&&(h+=` [${b.join(`, `)}]`),h+=`
|
|
8
8
|
`,h});return n.length?n.join(`
|
|
9
9
|
`):``}static getTableGroupSettings(e){let t=[];return e.color&&t.push(`color: ${e.color}`),t.length?` [${t.join(`, `)}]`:``}static formatDepEndpoint(e){let t=e.schemaName?`"${e.schemaName}".`:``,n=`"${e.tableName}"`;return!e.fieldNames||e.fieldNames.length===0?`${t}${n}`:`${t}${n}.${e.fieldNames.length===1?`"${e.fieldNames[0]}"`:`(${e.fieldNames.map(e=>`"${e}"`).join(`, `)})`}`}static formatDepCustomValue(e){return typeof e==`string`?`'${(0,a.escapeString)(e)}'`:e==null?`null`:String(e)}static exportDeps(e,t){let n=e.map(e=>{let n=t.deps[e],i=n.edgeIds.map(e=>t.depEdges[e]),a=!!n.note,o=n.metadata?Object.entries(n.metadata):[],s=a||o.length>0;if(i.length===1&&!s)return`Dep: ${r.formatDepEndpoint(i[0].upstream)} -> ${r.formatDepEndpoint(i[0].downstream)}\n`;let c=`Dep {
|
|
10
10
|
`;return i.forEach(e=>{c+=` ${r.formatDepEndpoint(e.upstream)} -> ${r.formatDepEndpoint(e.downstream)}\n`}),s&&(c+=`
|
|
@@ -13,7 +13,7 @@ require("../_virtual/_rolldown/runtime.cjs");const e=require("../node_modules/lo
|
|
|
13
13
|
`):``}static exportTableGroups(e,t){let n=e.map(e=>{let n=t.tableGroups[e],a=r.getTableGroupSettings(n),o=n.note?` Note: ${r.escapeNote(n.note)}\n`:``;return`TableGroup ${`"${n.name}"`}${a} {\n${n.tableIds.reduce((e,n)=>{let r=t.tables[n],a=t.schemas[r.schemaId];return`${e}${` ${i.shouldPrintSchema(a,t)?`"${a.name}".`:``}"${r.name}"`}\n`},``)}${o}}\n`});return n.length?n.join(`
|
|
14
14
|
`):``}static getStickyNoteSettings(e){let t=``;return e.color&&(t+=`color: ${e.color}`),t?` [${t}]`:``}static exportStickyNotes(e){return n.default(e.notes,(e,t)=>{let n=` ${r.escapeNote(t.content)}`,i=r.getStickyNoteSettings(t),a=`Note ${t.name}${i} {\n${n}\n}\n`;return e?`${e}\n${a}`:a},``)}static exportRecords(n){let{records:r}=n;if(!r||t.default(r))return``;let i=e.default(Object.values(r),e=>`${e.schemaName||``}.${e.tableName}`);return Object.values(i).map(e=>{let{schemaName:t,tableName:n}=e[0],r=t?(0,a.normalizeQualifiedName)(t,n):(0,a.addDoubleQuoteIfNeeded)(n),i=[...new Set(e.flatMap(e=>e.columns))],o=i.map(a.addDoubleQuoteIfNeeded).join(`, `),s=e.flatMap(e=>{let t=i.map(t=>e.columns.indexOf(t));return e.values.map(e=>t.map(t=>t===-1?{value:null,type:`expression`}:e[t]))}).map(e=>` ${e.map(a.formatRecordValue).join(`, `)}`);return`Records ${r}(${o})${e.some(e=>e.example)?` [example]`:``} {\n${s.join(`
|
|
15
15
|
`)}\n}\n`}).join(`
|
|
16
|
-
`)}static exportMetadata(e){let n=[],a=e.database[1],o=(e,t)=>`Metadata ${e} {\n${Object.entries(t).map(([e,t])=>` ${e}: ${r.
|
|
16
|
+
`)}static formatMetadataValue(e){return typeof e==`string`?r.escapeNote(e):String(e)}static exportMetadata(e){let n=[],a=e.database[1],o=(e,t)=>`Metadata ${e} {\n${Object.entries(t).map(([e,t])=>` ${e}: ${r.formatMetadataValue(t)}`).join(`
|
|
17
17
|
`)}\n}\n`;return a.schemaIds.forEach(r=>{let{tableIds:a,tableGroupIds:s}=e.schemas[r];a.forEach(r=>{let a=e.tables[r],s=e.schemas[a.schemaId],c=i.shouldPrintSchema(s,e)?`"${s.name}".`:``;t.default(a.metadata)||n.push(o(`Table ${c}"${a.name}"`,a.metadata)),a.fieldIds.map(t=>e.fields[t]).filter(e=>!t.default(e.metadata)).forEach(e=>n.push(o(`Column ${c}"${a.name}"."${e.name}"`,e.metadata)))}),s.map(t=>e.tableGroups[t]).filter(e=>!t.default(e.metadata)).forEach(e=>n.push(o(`TableGroup "${e.name}"`,e.metadata)))}),Object.values(e.notes).filter(e=>!t.default(e.metadata)).forEach(e=>n.push(o(`Note ${e.name}`,e.metadata))),n.join(`
|
|
18
18
|
`)}static export(e,n){let i=[],a=e.database[1],{includeRecords:o}=n;a.schemaIds.forEach(n=>{let{enumIds:a,tableIds:o,tableGroupIds:s,refIds:c,depIds:l}=e.schemas[n];t.default(a)||i.push(r.exportEnums(a,e)),t.default(o)||i.push(r.exportTables(o,e)),t.default(s)||i.push(r.exportTableGroups(s,e)),t.default(c)||i.push(r.exportRefs(c,e)),t.default(l)||i.push(r.exportDeps(l,e))}),t.default(e.notes)||i.push(r.exportStickyNotes(e)),o&&!t.default(e.records)&&i.push(r.exportRecords(e));let s=r.exportMetadata(e);return s&&i.push(s),i.join(`
|
|
19
19
|
`)}};exports.default=o;
|
|
@@ -115,7 +115,7 @@ var d = class r {
|
|
|
115
115
|
let _ = t.fields[l.fieldIds[0]], v = t.tables[_.tableId], y = t.schemas[v.schemaId], b = r.buildFieldName(l.fieldIds, t);
|
|
116
116
|
g += `${d} `, g += `${i(y, t) ? `"${y.name}".` : ""}"${v.name}".${b}`;
|
|
117
117
|
let x = [];
|
|
118
|
-
return n.onUpdate && x.push(`update: ${n.onUpdate.toLowerCase()}`), n.onDelete && x.push(`delete: ${n.onDelete.toLowerCase()}`), n.color && x.push(`color: ${n.color}`), n.inactive && x.push("inactive"), Object.entries(n.metadata ?? {}).forEach(([e, t]) => {
|
|
118
|
+
return n.onUpdate && x.push(`update: ${n.onUpdate.toLowerCase()}`), n.onDelete && x.push(`delete: ${n.onDelete.toLowerCase()}`), n.color && x.push(`color: ${n.color}`), n.inactive && x.push("inactive"), n.note && x.push(`note: ${r.escapeNote(n.note)}`), Object.entries(n.metadata ?? {}).forEach(([e, t]) => {
|
|
119
119
|
x.push(`${e}: ${r.formatDepCustomValue(t)}`);
|
|
120
120
|
}), x.length > 0 && (g += ` [${x.join(", ")}]`), g += "\n", g;
|
|
121
121
|
});
|
|
@@ -180,8 +180,11 @@ var d = class r {
|
|
|
180
180
|
return `Records ${r}(${o})${e.some((e) => e.example) ? " [example]" : ""} {\n${c.join("\n")}\n}\n`;
|
|
181
181
|
}).join("\n");
|
|
182
182
|
}
|
|
183
|
+
static formatMetadataValue(e) {
|
|
184
|
+
return typeof e == "string" ? r.escapeNote(e) : String(e);
|
|
185
|
+
}
|
|
183
186
|
static exportMetadata(e) {
|
|
184
|
-
let n = [], a = e.database[1], o = (e, t) => `Metadata ${e} {\n${Object.entries(t).map(([e, t]) => ` ${e}: ${r.
|
|
187
|
+
let n = [], a = e.database[1], o = (e, t) => `Metadata ${e} {\n${Object.entries(t).map(([e, t]) => ` ${e}: ${r.formatMetadataValue(t)}`).join("\n")}\n}\n`;
|
|
185
188
|
return a.schemaIds.forEach((r) => {
|
|
186
189
|
let { tableIds: a, tableGroupIds: s } = e.schemas[r];
|
|
187
190
|
a.forEach((r) => {
|
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}}),exports.
|
|
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,"dbmlMonarchTokensProvider",{enumerable:!0,get:function(){return c.dbmlMonarchTokensProvider}}),exports.exporter=n.default,Object.defineProperty(exports,"findDiagramViewBlocks",{enumerable:!0,get:function(){return c.findDiagramViewBlocks}}),Object.defineProperty(exports,"formatRecordValue",{enumerable:!0,get:function(){return c.formatRecordValue}}),Object.defineProperty(exports,"getMultiplicities",{enumerable:!0,get:function(){return c.getMultiplicities}}),Object.defineProperty(exports,"getRelationshipOp",{enumerable:!0,get:function(){return c.getRelationshipOp}}),exports.importer=i.default,exports.inferMultiplicitiesFromColumns=s.inferMultiplicitiesFromColumns,Object.defineProperty(exports,"isBinaryType",{enumerable:!0,get:function(){return c.isBinaryType}}),Object.defineProperty(exports,"isBooleanType",{enumerable:!0,get:function(){return c.isBooleanType}}),Object.defineProperty(exports,"isDateTimeType",{enumerable:!0,get:function(){return c.isDateTimeType}}),Object.defineProperty(exports,"isEndpointManySide",{enumerable:!0,get:function(){return c.isEndpointManySide}}),Object.defineProperty(exports,"isEndpointOneSide",{enumerable:!0,get:function(){return c.isEndpointOneSide}}),Object.defineProperty(exports,"isEndpointOptional",{enumerable:!0,get:function(){return c.isEndpointOptional}}),Object.defineProperty(exports,"isEndpointRequired",{enumerable:!0,get:function(){return c.isEndpointRequired}}),Object.defineProperty(exports,"isFloatType",{enumerable:!0,get:function(){return c.isFloatType}}),Object.defineProperty(exports,"isIntegerType",{enumerable:!0,get:function(){return c.isIntegerType}}),Object.defineProperty(exports,"isNumericType",{enumerable:!0,get:function(){return c.isNumericType}}),Object.defineProperty(exports,"isSerialType",{enumerable:!0,get:function(){return c.isSerialType}}),Object.defineProperty(exports,"isStringType",{enumerable:!0,get:function(){return c.isStringType}}),Object.defineProperty(exports,"makeRelationshipRequired",{enumerable:!0,get:function(){return c.makeRelationshipRequired}}),exports.renameTable=a.renameTable,exports.syncDep=a.syncDep,exports.syncDiagramView=a.syncDiagramView,Object.defineProperty(exports,"tryExtractBoolean",{enumerable:!0,get:function(){return c.tryExtractBoolean}}),Object.defineProperty(exports,"tryExtractDateTime",{enumerable:!0,get:function(){return c.tryExtractDateTime}}),Object.defineProperty(exports,"tryExtractEnum",{enumerable:!0,get:function(){return c.tryExtractEnum}}),Object.defineProperty(exports,"tryExtractInteger",{enumerable:!0,get:function(){return c.tryExtractInteger}}),Object.defineProperty(exports,"tryExtractNumeric",{enumerable:!0,get:function(){return c.tryExtractNumeric}}),Object.defineProperty(exports,"tryExtractString",{enumerable:!0,get:function(){return c.tryExtractString}}),exports.updateElementSetting=a.updateElementSetting,exports.updateElementSettingEdit=a.updateElementSettingEdit;
|
package/lib/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CompilerDiagnostics as e } from "./parse/error.mjs";
|
|
2
2
|
import t from "./parse/Parser.mjs";
|
|
3
3
|
import n from "./export/index.mjs";
|
|
4
4
|
import r from "./export/ModelExporter.mjs";
|
|
@@ -6,5 +6,5 @@ import i from "./import/index.mjs";
|
|
|
6
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
7
|
import { VERSION as d } from "./utils/version.mjs";
|
|
8
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,
|
|
10
|
-
export { p as CARDINALITY_MANY, m as CARDINALITY_MAYBE, h as CARDINALITY_ONE, g as CARDINALITY_SOME, e as
|
|
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, dbmlMonarchTokensProvider as E, formatRecordValue as D, getMultiplicities as O, getRelationshipOp as k, isBinaryType as A, isBooleanType as j, isDateTimeType as M, isEndpointManySide as N, isEndpointOneSide as P, isEndpointOptional as F, isEndpointRequired as I, isFloatType as L, isIntegerType as R, isNumericType as z, isSerialType as B, isStringType as V, makeRelationshipRequired as H, tryExtractBoolean as U, tryExtractDateTime as W, tryExtractEnum as G, tryExtractInteger as K, tryExtractNumeric as q, tryExtractString as J } from "@dbml/parse";
|
|
10
|
+
export { 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 dbmlMonarchTokensProvider, n as exporter, a as findDiagramViewBlocks, D as formatRecordValue, O as getMultiplicities, k as getRelationshipOp, i as importer, f as inferMultiplicitiesFromColumns, A as isBinaryType, j as isBooleanType, M as isDateTimeType, N as isEndpointManySide, P as isEndpointOneSide, F as isEndpointOptional, I as isEndpointRequired, L as isFloatType, R as isIntegerType, z as isNumericType, B as isSerialType, V as isStringType, H as makeRelationshipRequired, o as renameTable, s as syncDep, c as syncDiagramView, U as tryExtractBoolean, W as tryExtractDateTime, G as tryExtractEnum, K as tryExtractInteger, q as tryExtractNumeric, J as tryExtractString, l as updateElementSetting, u as updateElementSettingEdit };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require("../_virtual/_rolldown/runtime.cjs");var e=class extends Error{constructor(e,t
|
|
1
|
+
require("../_virtual/_rolldown/runtime.cjs");var e=class extends Error{constructor(e,t){super(e),this.location=t,this.error=`error`}},t=class{constructor(e){this.token=e}bind(e){this.selection=e}error(t){throw new e(t,this.token)}};exports.default=t;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
//#region src/model_structure/element.
|
|
1
|
+
//#region src/model_structure/element.ts
|
|
2
2
|
var e = class extends Error {
|
|
3
|
-
constructor(e, t
|
|
4
|
-
line: 1,
|
|
5
|
-
column: 1
|
|
6
|
-
} }) {
|
|
3
|
+
constructor(e, t) {
|
|
7
4
|
super(e), this.location = t, this.error = "error";
|
|
8
5
|
}
|
|
9
6
|
}, t = class {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require("../../_virtual/_rolldown/runtime.cjs");var e=`10.4.0-alpha.
|
|
1
|
+
require("../../_virtual/_rolldown/runtime.cjs");var e=`10.4.0-alpha.3`;exports.version=e;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require("../../../../_virtual/_rolldown/runtime.cjs");const e=require("../../../../node_modules/lodash-es/flatten.cjs"),t=require("../../../../node_modules/lodash-es/last.cjs"),n=require("../../../../node_modules/lodash-es/lodash.cjs"),r=require("../../../../node_modules/antlr4/dist/antlr4.web.cjs"),i=require("../../parsers/oraclesql/OracleSqlParserVisitor.cjs"),a=require("../../parsers/oraclesql/OracleSqlParser.cjs"),o=require("../AST.cjs"),s=require("../constants.cjs"),c=require("../helpers.cjs"),l=require("../../../error.cjs");let u=require("@dbml/parse");n.init_lodash();var d={FIELD:`table_field`,INDEX:`table_index`,FK:`table_fk`,UNIQUE:`table_unique`,PK:`table_pk`,DEFAULT:`table_default`,CHECK:`table_check`},f={NOT_NULL:`col_not_null`,NULLABLE:`col_nullable`,UNIQUE:`col_unique`,PK:`col_pk`,DEFAULT:`col_dbdefault`,INCREMENT:`col_increment`,INLINE_REF:`col_inline_ref`,NOTE:`col_note`,CHECK:`col_check`},p=(e,t,n)=>{let r=t??null;return e.find(e=>(e.schemaName??null)===r&&e.name===n)},m=(e,t)=>e.fields.find(e=>e.name===t),h=e=>({value:e.type===s.CONSTRAINT_TYPE.COLUMN?e.rawValue:e.value,type:e.type===s.CONSTRAINT_TYPE.COLUMN?s.DATA_TYPE.EXPRESSION:e.type}),g=e=>{let t;switch(e.type){case s.CONSTRAINT_TYPE.COLUMN:t=s.CONSTRAINT_TYPE.COLUMN;break;case s.DATA_TYPE.STRING:t=s.CONSTRAINT_TYPE.STRING;break;default:t=s.CONSTRAINT_TYPE.EXPRESSION;break}return{value:e.value.toString(),type:t}},_=(e,t)=>l.CompilerError.create([{message:t,location:{start:{line:e.start.line,column:e.start.column+1},end:{line:e.stop.line,column:e.stop.column+c.getOriginalText(e).length+1}}}]),v=(e,t=`"`)=>e.startsWith(t)?e.slice(1,-1).replaceAll(`${t}${t}`,t):e,y=class extends i.default{constructor(){super(),this.data={schemas:[],tables:[],refs:[],deps:[],enums:[],tableGroups:[],aliases:[],project:{},records:[]}}visitCreate_view(e){let t=e.id_expression?e.id_expression():null;if(!t)return;let n=t.getText().replace(/"/g,``),r=e.schema_name?e.schema_name():null,i=r?r.getText().replace(/"/g,``):void 0,a=c.getOriginalText(e);this.data.tables.push({name:n,schemaName:i,fields:[],indexes:[],checks:[],note:null,headerColor:null,custom:{query:a,kind:`view`}}),b(this,e.select_only_statement(),n,i)}visitCreate_materialized_view(e){let t=(e.getText?e.getText():``).match(/MATERIALIZEDVIEW(?:IFNOTEXISTS)?(?:"([^"]+)"\.)?"?([^("\s]+)"?/i);if(!t)return;let n=t[1]||void 0,r=t[2],i=c.getOriginalText(e);this.data.tables.push({name:r,schemaName:n,fields:[],indexes:[],checks:[],note:null,headerColor:null,custom:{query:i,kind:`materialized_view`,materialized:!0}}),b(this,e.select_only_statement(),r,n)}visitSql_script(e){return e.unit_statement()?.forEach(e=>e.accept(this)),this.data}visitUnit_statement(e){e.create_table()?e.create_table().accept(this):e.comment_on_table()?e.comment_on_table().accept(this):e.comment_on_column()?e.comment_on_column().accept(this):e.alter_table()?e.alter_table().accept(this):e.create_index()?e.create_index().accept(this):e.data_manipulation_language_statements()&&e.data_manipulation_language_statements().accept(this)}visitData_manipulation_language_statements(e){e.insert_statement()&&e.insert_statement().accept(this)}visitCreate_table(t){let n=t.table_name().accept(this),r=t.schema_name()?t.schema_name().accept(this):void 0;if(t.relational_table()){let[i,a,s,c]=t.relational_table().accept(this).reduce((e,t)=>(t.type===d.FIELD?e[0].push(t.value):[d.INDEX,d.UNIQUE,d.PK].includes(t.type)?e[1].push(t.value):t.type===d.FK?e[2].push(t.value):t.type===d.CHECK&&e[3].push(...t.value.checks),e),[[],[],[],[]]);this.data.refs.push(...e.default(i.map(e=>e.inline_refs.map(t=>(t.endpoints[0].tableName=n,t.endpoints[0].schemaName=r,t.endpoints[0].fieldNames=[e.field.name],t))))),this.data.refs.push(...s.map(e=>(e.endpoints[0].tableName=n,e.endpoints[0].schemaName=r,e))),this.data.tables.push(new o.Table({name:n,schemaName:r,fields:i.map(e=>e.field),indexes:a,checks:c}))}}visitRelational_table(e){return e.relational_property()?e.relational_property().map(e=>e.accept(this)):[]}visitRelational_property(e){return e.column_definition()?e.column_definition().accept(this):e.out_of_line_constraint()?e.out_of_line_constraint().accept(this):e.out_of_line_ref_constraint()?e.out_of_line_ref_constraint().accept(this):null}visitColumn_definition(e){let n=t.default(e.column_name().accept(this)),r=e.datatype()?.accept(this)||e.type_name()?.accept(this);if(!r)throw _(e,`Importing a column definition without a type is not supported`);let i=(e.inline_constraint()||[]).map(e=>e.accept(this)).filter(Boolean);if(e.DEFAULT()){let t=e.expression().accept(this);i.push({type:f.DEFAULT,value:{dbdefault:h(t)}})}e.identity_clause()&&i.push({type:f.INCREMENT,value:{increment:!0}});let a={checks:[],inline_refs:[]};i.forEach(e=>{switch(e.type){case f.DEFAULT:a.dbdefault=e.value.dbdefault;break;case f.NOT_NULL:a.not_null=!0;break;case f.NULLABLE:a.not_null=!1;break;case f.PK:a.pk=!0;break;case f.UNIQUE:a.unique=!0;break;case f.CHECK:a.checks.push(...e.value.checks);break;case f.INCREMENT:a.increment=!0;break;case f.FK:a.inline_refs.push(...e.value.inline_refs);break;default:}});let s=new o.Field({name:n,type:r,...a});return{type:d.FIELD,value:{field:s,inline_refs:a.inline_refs||[]}}}visitInline_constraint(e){if(e.NULL_()&&e.NOT())return{type:f.NOT_NULL,value:{not_null:!0}};if(e.NULL_())return{type:f.NULLABLE,value:{not_null:!1}};if(e.UNIQUE())return{type:f.UNIQUE,value:{unique:!0}};if(e.PRIMARY())return{type:f.PK,value:{pk:!0}};let t=e.constraint_name()?.accept(this);if(e.references_clause()){let n=e.references_clause().accept(this);return n.name=t,{type:f.FK,value:{inline_refs:[n]}}}if(e.check_constraint()){let n=e.check_constraint();n.isColumn=!0;let r=n.accept(this);return r.value.checks[0].name=t,r}return null}visitOut_of_line_constraint(e){if(e.UNIQUE()){let n=e.column_name().map(e=>({value:t.default(e.accept(this)),type:s.CONSTRAINT_TYPE.COLUMN}));return{type:d.UNIQUE,value:new o.Index({columns:n,unique:!0,name:e.constraint_name()?.accept(this)})}}if(e.PRIMARY()){let n=e.column_name().map(e=>({value:t.default(e.accept(this)),type:s.CONSTRAINT_TYPE.COLUMN}));return{type:d.PK,value:new o.Index({columns:n,pk:!0,name:e.constraint_name()?.accept(this)})}}if(e.foreign_key_clause()){let t=e.foreign_key_clause().accept(this);return t.value.name=e.constraint_name()?.accept(this),t}if(e.condition()){let t=c.getOriginalText(e.condition());return{type:d.CHECK,value:{checks:[{name:e.constraint_name()?.accept(this),expression:t}]}}}return null}visitOut_of_line_ref_constraint(e){let t=e.constraint_name()?.accept(this),n=e.regular_id().map(e=>e.accept(this)),r=e.references_clause().accept(this);return r.endpoints[0].fieldNames=n,t&&(r.name=t),{type:d.FK,value:r}}visitForeign_key_clause(e){let n=e.paren_column_list().accept(this).map(e=>t.default(e)),r=e.references_clause().accept(this);return r.endpoints[0].fieldNames=n,e.on_delete_clause()&&(r.onDelete=e.on_delete_clause().accept(this)),{type:d.FK,value:r}}visitReferences_clause(e){if(!e.paren_column_list())throw _(e.tableview_name(),`Importing a foreign key with implicit referenced columns is not supported`);let n=e.tableview_name().accept(this),r=t.default(n),i=n.length>1?n[n.length-2]:void 0,a=e.paren_column_list().accept(this).map(e=>t.default(e));return new o.Ref({endpoints:[new o.Endpoint({tableName:null,schemaName:null,fieldNames:[],relation:u.CARDINALITY_MANY}),new o.Endpoint({tableName:r,schemaName:i,fieldNames:a,relation:u.CARDINALITY_MAYBE})]})}visitOn_delete_clause(e){return e.CASCADE()?`cascade`:e.SET()&&e.NULL_()?`set null`:null}visitCheck_constraint(e){let t=c.getOriginalText(e.condition());return{type:e.isColumn?f.CHECK:d.CHECK,value:{checks:[{expression:t}]}}}visitColumn_list(e){return e.column_name().map(e=>e.accept(this))}visitTableview_name(e){let t=e.id_expression()?[e.identifier().accept(this)]:[],n=e.id_expression()?e.id_expression().accept(this):e.identifier().accept(this);return[...t,n]}visitSchema_name(e){return e.identifier().accept(this)}visitTable_name(e){return e.identifier().accept(this)}visitColumn_name(e){return[e.identifier().accept(this)].concat(e.id_expression().map(e=>e.accept(this)))}visitIdentifier(e){return v(c.getOriginalText(e))}visitType_name(e){let n=e.id_expression().map(e=>e.accept(this));return{type_name:t.default(n),schemaName:n.length>1?n[n.length-2]:void 0}}visitDatatype(e){return{type_name:v(c.getOriginalText(e))}}visitComment_on_table(e){let n=e.tableview_name().accept(this),r=t.default(n),i=n.length>1?n[n.length-2]:void 0,a=p(this.data.tables,i,r);if(!a)throw _(e.tableview_name(),`Table "${r}" not found`);a.note={value:e.quoted_string().accept(this)}}visitComment_on_column(e){let n=e.column_name().accept(this),r=t.default(n);n.pop();let i=t.default(n);n.pop();let a=t.default(n),o=p(this.data.tables,a,i);if(!o)throw _(e.column_name(),`Table "${i}" not found`);let s=m(o,r);if(!s)throw _(e.column_name(),`Column "${r}" not found in table "${i}"`);s.note={value:e.quoted_string().accept(this)}}visitAlter_table(e){let n=e.tableview_name().accept(this),r=t.default(n),i=n.length>1?n[n.length-2]:void 0,a=p(this.data.tables,i,r);if(!a)throw _(e.tableview_name(),`Table "${r}" not found`);function o(e,t){switch(t.type){case d.FK:case f.FK:t.value.endpoints[0].tableName=r,t.value.endpoints[0].schemaName=i,this.data.refs.push(t.value);break;case d.CHECK:a.checks||=[],a.checks.push(...t.value.checks);break;case f.CHECK:e.checks||(a.checks=[]),e.checks.push(...t.value.checks);break;case f.PK:e.pk=!0,e.unique=void 0;break;case f.UNIQUE:e.unique=!0;break;case d.UNIQUE:case d.INDEX:case d.PK:a.indexes||=[],a.indexes.push(t.value);break;case f.DEFAULT:e.dbdefault=t.value.dbdefault;break;case f.NOT_NULL:e.not_null=!0;break;case f.NULLABLE:e.not_null=!1;break;case f.INCREMENT:e.increment=!0;break;default:}}(e.constraint_clauses()||e.column_clauses())&&(e.constraint_clauses()?[{column:null,constraints:e.constraint_clauses().accept(this)}]:e.column_clauses().accept(this)).forEach(t=>{let n=t.column===null?null:m(a,t.column);if(t.column!==null&&!n)throw _(e.tableview_name(),`Column "${t.column}" not found on Table "${r}"`);t.constraints.forEach(e=>o.bind(this)(n,e))})}visitColumn_clauses(e){return e.add_modify_drop_column_clauses()?e.add_modify_drop_column_clauses().accept(this):[]}visitAdd_modify_drop_column_clauses(e){let t=[];return e.constraint_clauses()&&t.push({column:null,constraints:e.constraint_clauses().flatMap(e=>e.accept(this))}),e.modify_column_clauses()&&t.push(...e.modify_column_clauses().flatMap(e=>e.accept(this))),t}visitModify_column_clauses(e){return e.modify_col_properties().map(e=>e.accept(this))}visitModify_col_properties(e){let n=[],r=t.default(e.column_name().accept(this));if(e.DEFAULT()){let t=e.expression().accept(this);n.push({type:f.DEFAULT,value:{dbdefault:h(t)}})}else e.inline_constraint()&&n.push(...e.inline_constraint().map(e=>e.accept(this)));return{column:r,constraints:n}}visitConstraint_clauses(e){return e.out_of_line_constraint()?e.out_of_line_constraint().map(e=>e.accept(this)).filter(Boolean):e.out_of_line_ref_constraint()?[e.out_of_line_ref_constraint().accept(this)]:[]}visitCreate_index(e){if(!e.table_index_clause())return;let n=!!e.UNIQUE(),r=!!e.BITMAP(),i=e.index_name().accept(this),{names:a,columns:s}=e.table_index_clause().accept(this),c=t.default(a),l=a.length>1?a[a.length-2]:void 0,u=p(this.data.tables,l,c);if(!u)throw _(e.table_index_clause(),`Table ${c} not found`);u.indexes||=[],u.indexes.push(new o.Index({name:i,columns:s,unique:n,type:r?`bitmap`:void 0}))}visitTable_index_clause(e){return{names:e.tableview_name().accept(this),columns:e.index_expr().map(e=>e.accept(this))}}visitConstraint_name(e){return v(c.getOriginalText(e))}visitIndex_name(e){return e.identifier().accept(this)}visitIndex_expr(e){if(e.expression()){let t=g(e.expression().accept(this));return{value:t.value,type:t.type}}return{value:t.default(e.column_name().accept(this)),type:s.CONSTRAINT_TYPE.COLUMN}}visitInsert_statement(e){e.single_table_insert()?e.single_table_insert().accept(this):e.multi_table_insert()&&e.multi_table_insert().accept(this)}visitSingle_table_insert(e){let t=e.insert_into_clause().accept(this),n=e.values_clause().accept(this);if(t&&n){let{tableName:e,schemaName:r,columns:i}=t,{values:a}=n,s=new o.TableRecord({schemaName:r,tableName:e,columns:i,values:a});this.data.records.push(s)}}visitMulti_table_insert(e){if(!e.multi_table_element())return;let t=e.multi_table_element().map(e=>e.accept(this)).filter(Boolean),n=new Map;t.forEach(e=>{let{tableName:t,schemaName:r,columns:i,values:a}=e,o=`${r||``}.${t}.${i.join(`,`)}`;n.has(o)?n.get(o).values.push(...a):n.set(o,{tableName:t,schemaName:r,columns:i,values:a})}),n.forEach(e=>{let t=new o.TableRecord({schemaName:e.schemaName,tableName:e.tableName,columns:e.columns,values:e.values});this.data.records.push(t)})}visitMulti_table_element(e){let t=e.insert_into_clause().accept(this),n=e.values_clause()?.accept(this);if(t&&n){let{tableName:e,schemaName:r,columns:i}=t,{values:a}=n;return{tableName:e,schemaName:r,columns:i,values:a}}return null}visitInsert_into_clause(e){let n=e.general_table_ref().accept(this),r=t.default(n),i=n.length>1?n[n.length-2]:void 0;return{tableName:r,schemaName:i,columns:e.paren_column_list()?e.paren_column_list().accept(this).map(e=>t.default(e)):p(this.data.tables,i,r)?.fields.map(e=>e.name)}}visitGeneral_table_ref(e){return e.dml_table_expression_clause().accept(this)}visitDml_table_expression_clause(e){return e.tableview_name()?e.tableview_name().accept(this):[]}visitParen_column_list(e){return e.column_list().accept(this)}visitValues_clause(e){return{values:[e.expressions_().accept(this).map(e=>({value:e.type===s.CONSTRAINT_TYPE.COLUMN?e.rawValue:e.value,type:e.type===s.CONSTRAINT_TYPE.COLUMN?s.DATA_TYPE.EXPRESSION:e.type}))]}}visitExpressions_(e){return e.expression().map(e=>e.accept(this))}visitId_expression(e){return v(c.getOriginalText(e))}visitExpression(e){let t=c.getOriginalText(e);return e.CHAR_STRING()?{type:s.DATA_TYPE.STRING,value:v(t,`'`)}:e.TRUE()?{type:s.DATA_TYPE.BOOLEAN,value:!0}:e.FALSE()?{type:s.DATA_TYPE.BOOLEAN,value:!1}:e.NULL_()?{type:s.DATA_TYPE.BOOLEAN,value:null}:e.APPROXIMATE_NUM_LIT()||e.UNSIGNED_INTEGER()?{type:s.DATA_TYPE.NUMBER,value:parseFloat(t)}:e.column_name()?{type:s.CONSTRAINT_TYPE.COLUMN,rawValue:v(t),value:v(c.getOriginalText(e.column_name()))}:{type:s.CONSTRAINT_TYPE.EXPRESSION,value:t}}visitQuoted_string(e){return v(c.getOriginalText(e),`'`)}visitRegular_id(e){return v(c.getOriginalText(e),`"`)}};function b(e,n,i,o){if(!n)return;let s=new Set,c=(0,u.normalizeQualifiedName)(o??``,i),l=new r.gn;l.enterEveryRule=n=>{if(!(n instanceof a.default.Tableview_nameContext))return;let r=n.accept(e),l=Array.isArray(r)?t.default(r):r,d=Array.isArray(r)&&r.length>1?r[r.length-2]:void 0,f=(0,u.normalizeQualifiedName)(d??``,l);f!==c&&(s.has(f)||p(e.data.tables,d,l)&&(s.add(f),e.data.deps.push({edges:[{upstream:{schemaName:d,tableName:l,fieldNames:[]},downstream:{schemaName:o,tableName:i,fieldNames:[]}}],note:null,custom:{}})))},r.fn.DEFAULT.walk(l,n)}exports.default=y;
|
|
1
|
+
require("../../../../_virtual/_rolldown/runtime.cjs");const e=require("../../../../node_modules/lodash-es/flatten.cjs"),t=require("../../../../node_modules/lodash-es/last.cjs"),n=require("../../../../node_modules/lodash-es/lodash.cjs"),r=require("../../../../node_modules/antlr4/dist/antlr4.web.cjs"),i=require("../../parsers/oraclesql/OracleSqlParserVisitor.cjs"),a=require("../../parsers/oraclesql/OracleSqlParser.cjs"),o=require("../AST.cjs"),s=require("../constants.cjs"),c=require("../helpers.cjs"),l=require("../../../error.cjs");let u=require("@dbml/parse");n.init_lodash();var d={FIELD:`table_field`,INDEX:`table_index`,FK:`table_fk`,UNIQUE:`table_unique`,PK:`table_pk`,DEFAULT:`table_default`,CHECK:`table_check`},f={NOT_NULL:`col_not_null`,NULLABLE:`col_nullable`,UNIQUE:`col_unique`,PK:`col_pk`,DEFAULT:`col_dbdefault`,INCREMENT:`col_increment`,INLINE_REF:`col_inline_ref`,NOTE:`col_note`,CHECK:`col_check`},p=(e,t,n)=>{let r=t??null;return e.find(e=>(e.schemaName??null)===r&&e.name===n)},m=(e,t)=>e.fields.find(e=>e.name===t),h=e=>({value:e.type===s.CONSTRAINT_TYPE.COLUMN?e.rawValue:e.value,type:e.type===s.CONSTRAINT_TYPE.COLUMN?s.DATA_TYPE.EXPRESSION:e.type}),g=e=>{let t;switch(e.type){case s.CONSTRAINT_TYPE.COLUMN:t=s.CONSTRAINT_TYPE.COLUMN;break;case s.DATA_TYPE.STRING:t=s.CONSTRAINT_TYPE.STRING;break;default:t=s.CONSTRAINT_TYPE.EXPRESSION;break}return{value:e.value.toString(),type:t}},_=(e,t)=>l.CompilerDiagnostics.create([{message:t,location:{start:{line:e.start.line,column:e.start.column+1},end:{line:e.stop.line,column:e.stop.column+c.getOriginalText(e).length+1}}}]),v=(e,t=`"`)=>e.startsWith(t)?e.slice(1,-1).replaceAll(`${t}${t}`,t):e,y=class extends i.default{constructor(){super(),this.data={schemas:[],tables:[],refs:[],deps:[],enums:[],tableGroups:[],aliases:[],project:{},records:[]}}visitCreate_view(e){let t=e.id_expression?e.id_expression():null;if(!t)return;let n=t.getText().replace(/"/g,``),r=e.schema_name?e.schema_name():null,i=r?r.getText().replace(/"/g,``):void 0,a=c.getOriginalText(e);this.data.tables.push({name:n,schemaName:i,fields:[],indexes:[],checks:[],note:null,headerColor:null,custom:{query:a,kind:`view`}}),b(this,e.select_only_statement(),n,i)}visitCreate_materialized_view(e){let t=(e.getText?e.getText():``).match(/MATERIALIZEDVIEW(?:IFNOTEXISTS)?(?:"([^"]+)"\.)?"?([^("\s]+)"?/i);if(!t)return;let n=t[1]||void 0,r=t[2],i=c.getOriginalText(e);this.data.tables.push({name:r,schemaName:n,fields:[],indexes:[],checks:[],note:null,headerColor:null,custom:{query:i,kind:`materialized_view`,materialized:!0}}),b(this,e.select_only_statement(),r,n)}visitSql_script(e){return e.unit_statement()?.forEach(e=>e.accept(this)),this.data}visitUnit_statement(e){e.create_table()?e.create_table().accept(this):e.comment_on_table()?e.comment_on_table().accept(this):e.comment_on_column()?e.comment_on_column().accept(this):e.alter_table()?e.alter_table().accept(this):e.create_index()?e.create_index().accept(this):e.data_manipulation_language_statements()&&e.data_manipulation_language_statements().accept(this)}visitData_manipulation_language_statements(e){e.insert_statement()&&e.insert_statement().accept(this)}visitCreate_table(t){let n=t.table_name().accept(this),r=t.schema_name()?t.schema_name().accept(this):void 0;if(t.relational_table()){let[i,a,s,c]=t.relational_table().accept(this).reduce((e,t)=>(t.type===d.FIELD?e[0].push(t.value):[d.INDEX,d.UNIQUE,d.PK].includes(t.type)?e[1].push(t.value):t.type===d.FK?e[2].push(t.value):t.type===d.CHECK&&e[3].push(...t.value.checks),e),[[],[],[],[]]);this.data.refs.push(...e.default(i.map(e=>e.inline_refs.map(t=>(t.endpoints[0].tableName=n,t.endpoints[0].schemaName=r,t.endpoints[0].fieldNames=[e.field.name],t))))),this.data.refs.push(...s.map(e=>(e.endpoints[0].tableName=n,e.endpoints[0].schemaName=r,e))),this.data.tables.push(new o.Table({name:n,schemaName:r,fields:i.map(e=>e.field),indexes:a,checks:c}))}}visitRelational_table(e){return e.relational_property()?e.relational_property().map(e=>e.accept(this)):[]}visitRelational_property(e){return e.column_definition()?e.column_definition().accept(this):e.out_of_line_constraint()?e.out_of_line_constraint().accept(this):e.out_of_line_ref_constraint()?e.out_of_line_ref_constraint().accept(this):null}visitColumn_definition(e){let n=t.default(e.column_name().accept(this)),r=e.datatype()?.accept(this)||e.type_name()?.accept(this);if(!r)throw _(e,`Importing a column definition without a type is not supported`);let i=(e.inline_constraint()||[]).map(e=>e.accept(this)).filter(Boolean);if(e.DEFAULT()){let t=e.expression().accept(this);i.push({type:f.DEFAULT,value:{dbdefault:h(t)}})}e.identity_clause()&&i.push({type:f.INCREMENT,value:{increment:!0}});let a={checks:[],inline_refs:[]};i.forEach(e=>{switch(e.type){case f.DEFAULT:a.dbdefault=e.value.dbdefault;break;case f.NOT_NULL:a.not_null=!0;break;case f.NULLABLE:a.not_null=!1;break;case f.PK:a.pk=!0;break;case f.UNIQUE:a.unique=!0;break;case f.CHECK:a.checks.push(...e.value.checks);break;case f.INCREMENT:a.increment=!0;break;case f.FK:a.inline_refs.push(...e.value.inline_refs);break;default:}});let s=new o.Field({name:n,type:r,...a});return{type:d.FIELD,value:{field:s,inline_refs:a.inline_refs||[]}}}visitInline_constraint(e){if(e.NULL_()&&e.NOT())return{type:f.NOT_NULL,value:{not_null:!0}};if(e.NULL_())return{type:f.NULLABLE,value:{not_null:!1}};if(e.UNIQUE())return{type:f.UNIQUE,value:{unique:!0}};if(e.PRIMARY())return{type:f.PK,value:{pk:!0}};let t=e.constraint_name()?.accept(this);if(e.references_clause()){let n=e.references_clause().accept(this);return n.name=t,{type:f.FK,value:{inline_refs:[n]}}}if(e.check_constraint()){let n=e.check_constraint();n.isColumn=!0;let r=n.accept(this);return r.value.checks[0].name=t,r}return null}visitOut_of_line_constraint(e){if(e.UNIQUE()){let n=e.column_name().map(e=>({value:t.default(e.accept(this)),type:s.CONSTRAINT_TYPE.COLUMN}));return{type:d.UNIQUE,value:new o.Index({columns:n,unique:!0,name:e.constraint_name()?.accept(this)})}}if(e.PRIMARY()){let n=e.column_name().map(e=>({value:t.default(e.accept(this)),type:s.CONSTRAINT_TYPE.COLUMN}));return{type:d.PK,value:new o.Index({columns:n,pk:!0,name:e.constraint_name()?.accept(this)})}}if(e.foreign_key_clause()){let t=e.foreign_key_clause().accept(this);return t.value.name=e.constraint_name()?.accept(this),t}if(e.condition()){let t=c.getOriginalText(e.condition());return{type:d.CHECK,value:{checks:[{name:e.constraint_name()?.accept(this),expression:t}]}}}return null}visitOut_of_line_ref_constraint(e){let t=e.constraint_name()?.accept(this),n=e.regular_id().map(e=>e.accept(this)),r=e.references_clause().accept(this);return r.endpoints[0].fieldNames=n,t&&(r.name=t),{type:d.FK,value:r}}visitForeign_key_clause(e){let n=e.paren_column_list().accept(this).map(e=>t.default(e)),r=e.references_clause().accept(this);return r.endpoints[0].fieldNames=n,e.on_delete_clause()&&(r.onDelete=e.on_delete_clause().accept(this)),{type:d.FK,value:r}}visitReferences_clause(e){if(!e.paren_column_list())throw _(e.tableview_name(),`Importing a foreign key with implicit referenced columns is not supported`);let n=e.tableview_name().accept(this),r=t.default(n),i=n.length>1?n[n.length-2]:void 0,a=e.paren_column_list().accept(this).map(e=>t.default(e));return new o.Ref({endpoints:[new o.Endpoint({tableName:null,schemaName:null,fieldNames:[],relation:u.CARDINALITY_MANY}),new o.Endpoint({tableName:r,schemaName:i,fieldNames:a,relation:u.CARDINALITY_MAYBE})]})}visitOn_delete_clause(e){return e.CASCADE()?`cascade`:e.SET()&&e.NULL_()?`set null`:null}visitCheck_constraint(e){let t=c.getOriginalText(e.condition());return{type:e.isColumn?f.CHECK:d.CHECK,value:{checks:[{expression:t}]}}}visitColumn_list(e){return e.column_name().map(e=>e.accept(this))}visitTableview_name(e){let t=e.id_expression()?[e.identifier().accept(this)]:[],n=e.id_expression()?e.id_expression().accept(this):e.identifier().accept(this);return[...t,n]}visitSchema_name(e){return e.identifier().accept(this)}visitTable_name(e){return e.identifier().accept(this)}visitColumn_name(e){return[e.identifier().accept(this)].concat(e.id_expression().map(e=>e.accept(this)))}visitIdentifier(e){return v(c.getOriginalText(e))}visitType_name(e){let n=e.id_expression().map(e=>e.accept(this));return{type_name:t.default(n),schemaName:n.length>1?n[n.length-2]:void 0}}visitDatatype(e){return{type_name:v(c.getOriginalText(e))}}visitComment_on_table(e){let n=e.tableview_name().accept(this),r=t.default(n),i=n.length>1?n[n.length-2]:void 0,a=p(this.data.tables,i,r);if(!a)throw _(e.tableview_name(),`Table "${r}" not found`);a.note={value:e.quoted_string().accept(this)}}visitComment_on_column(e){let n=e.column_name().accept(this),r=t.default(n);n.pop();let i=t.default(n);n.pop();let a=t.default(n),o=p(this.data.tables,a,i);if(!o)throw _(e.column_name(),`Table "${i}" not found`);let s=m(o,r);if(!s)throw _(e.column_name(),`Column "${r}" not found in table "${i}"`);s.note={value:e.quoted_string().accept(this)}}visitAlter_table(e){let n=e.tableview_name().accept(this),r=t.default(n),i=n.length>1?n[n.length-2]:void 0,a=p(this.data.tables,i,r);if(!a)throw _(e.tableview_name(),`Table "${r}" not found`);function o(e,t){switch(t.type){case d.FK:case f.FK:t.value.endpoints[0].tableName=r,t.value.endpoints[0].schemaName=i,this.data.refs.push(t.value);break;case d.CHECK:a.checks||=[],a.checks.push(...t.value.checks);break;case f.CHECK:e.checks||(a.checks=[]),e.checks.push(...t.value.checks);break;case f.PK:e.pk=!0,e.unique=void 0;break;case f.UNIQUE:e.unique=!0;break;case d.UNIQUE:case d.INDEX:case d.PK:a.indexes||=[],a.indexes.push(t.value);break;case f.DEFAULT:e.dbdefault=t.value.dbdefault;break;case f.NOT_NULL:e.not_null=!0;break;case f.NULLABLE:e.not_null=!1;break;case f.INCREMENT:e.increment=!0;break;default:}}(e.constraint_clauses()||e.column_clauses())&&(e.constraint_clauses()?[{column:null,constraints:e.constraint_clauses().accept(this)}]:e.column_clauses().accept(this)).forEach(t=>{let n=t.column===null?null:m(a,t.column);if(t.column!==null&&!n)throw _(e.tableview_name(),`Column "${t.column}" not found on Table "${r}"`);t.constraints.forEach(e=>o.bind(this)(n,e))})}visitColumn_clauses(e){return e.add_modify_drop_column_clauses()?e.add_modify_drop_column_clauses().accept(this):[]}visitAdd_modify_drop_column_clauses(e){let t=[];return e.constraint_clauses()&&t.push({column:null,constraints:e.constraint_clauses().flatMap(e=>e.accept(this))}),e.modify_column_clauses()&&t.push(...e.modify_column_clauses().flatMap(e=>e.accept(this))),t}visitModify_column_clauses(e){return e.modify_col_properties().map(e=>e.accept(this))}visitModify_col_properties(e){let n=[],r=t.default(e.column_name().accept(this));if(e.DEFAULT()){let t=e.expression().accept(this);n.push({type:f.DEFAULT,value:{dbdefault:h(t)}})}else e.inline_constraint()&&n.push(...e.inline_constraint().map(e=>e.accept(this)));return{column:r,constraints:n}}visitConstraint_clauses(e){return e.out_of_line_constraint()?e.out_of_line_constraint().map(e=>e.accept(this)).filter(Boolean):e.out_of_line_ref_constraint()?[e.out_of_line_ref_constraint().accept(this)]:[]}visitCreate_index(e){if(!e.table_index_clause())return;let n=!!e.UNIQUE(),r=!!e.BITMAP(),i=e.index_name().accept(this),{names:a,columns:s}=e.table_index_clause().accept(this),c=t.default(a),l=a.length>1?a[a.length-2]:void 0,u=p(this.data.tables,l,c);if(!u)throw _(e.table_index_clause(),`Table ${c} not found`);u.indexes||=[],u.indexes.push(new o.Index({name:i,columns:s,unique:n,type:r?`bitmap`:void 0}))}visitTable_index_clause(e){return{names:e.tableview_name().accept(this),columns:e.index_expr().map(e=>e.accept(this))}}visitConstraint_name(e){return v(c.getOriginalText(e))}visitIndex_name(e){return e.identifier().accept(this)}visitIndex_expr(e){if(e.expression()){let t=g(e.expression().accept(this));return{value:t.value,type:t.type}}return{value:t.default(e.column_name().accept(this)),type:s.CONSTRAINT_TYPE.COLUMN}}visitInsert_statement(e){e.single_table_insert()?e.single_table_insert().accept(this):e.multi_table_insert()&&e.multi_table_insert().accept(this)}visitSingle_table_insert(e){let t=e.insert_into_clause().accept(this),n=e.values_clause().accept(this);if(t&&n){let{tableName:e,schemaName:r,columns:i}=t,{values:a}=n,s=new o.TableRecord({schemaName:r,tableName:e,columns:i,values:a});this.data.records.push(s)}}visitMulti_table_insert(e){if(!e.multi_table_element())return;let t=e.multi_table_element().map(e=>e.accept(this)).filter(Boolean),n=new Map;t.forEach(e=>{let{tableName:t,schemaName:r,columns:i,values:a}=e,o=`${r||``}.${t}.${i.join(`,`)}`;n.has(o)?n.get(o).values.push(...a):n.set(o,{tableName:t,schemaName:r,columns:i,values:a})}),n.forEach(e=>{let t=new o.TableRecord({schemaName:e.schemaName,tableName:e.tableName,columns:e.columns,values:e.values});this.data.records.push(t)})}visitMulti_table_element(e){let t=e.insert_into_clause().accept(this),n=e.values_clause()?.accept(this);if(t&&n){let{tableName:e,schemaName:r,columns:i}=t,{values:a}=n;return{tableName:e,schemaName:r,columns:i,values:a}}return null}visitInsert_into_clause(e){let n=e.general_table_ref().accept(this),r=t.default(n),i=n.length>1?n[n.length-2]:void 0;return{tableName:r,schemaName:i,columns:e.paren_column_list()?e.paren_column_list().accept(this).map(e=>t.default(e)):p(this.data.tables,i,r)?.fields.map(e=>e.name)}}visitGeneral_table_ref(e){return e.dml_table_expression_clause().accept(this)}visitDml_table_expression_clause(e){return e.tableview_name()?e.tableview_name().accept(this):[]}visitParen_column_list(e){return e.column_list().accept(this)}visitValues_clause(e){return{values:[e.expressions_().accept(this).map(e=>({value:e.type===s.CONSTRAINT_TYPE.COLUMN?e.rawValue:e.value,type:e.type===s.CONSTRAINT_TYPE.COLUMN?s.DATA_TYPE.EXPRESSION:e.type}))]}}visitExpressions_(e){return e.expression().map(e=>e.accept(this))}visitId_expression(e){return v(c.getOriginalText(e))}visitExpression(e){let t=c.getOriginalText(e);return e.CHAR_STRING()?{type:s.DATA_TYPE.STRING,value:v(t,`'`)}:e.TRUE()?{type:s.DATA_TYPE.BOOLEAN,value:!0}:e.FALSE()?{type:s.DATA_TYPE.BOOLEAN,value:!1}:e.NULL_()?{type:s.DATA_TYPE.BOOLEAN,value:null}:e.APPROXIMATE_NUM_LIT()||e.UNSIGNED_INTEGER()?{type:s.DATA_TYPE.NUMBER,value:parseFloat(t)}:e.column_name()?{type:s.CONSTRAINT_TYPE.COLUMN,rawValue:v(t),value:v(c.getOriginalText(e.column_name()))}:{type:s.CONSTRAINT_TYPE.EXPRESSION,value:t}}visitQuoted_string(e){return v(c.getOriginalText(e),`'`)}visitRegular_id(e){return v(c.getOriginalText(e),`"`)}};function b(e,n,i,o){if(!n)return;let s=new Set,c=(0,u.normalizeQualifiedName)(o??``,i),l=new r.gn;l.enterEveryRule=n=>{if(!(n instanceof a.default.Tableview_nameContext))return;let r=n.accept(e),l=Array.isArray(r)?t.default(r):r,d=Array.isArray(r)&&r.length>1?r[r.length-2]:void 0,f=(0,u.normalizeQualifiedName)(d??``,l);f!==c&&(s.has(f)||p(e.data.tables,d,l)&&(s.add(f),e.data.deps.push({edges:[{upstream:{schemaName:d,tableName:l,fieldNames:[]},downstream:{schemaName:o,tableName:i,fieldNames:[]}}],note:null,custom:{}})))},r.fn.DEFAULT.walk(l,n)}exports.default=y;
|
|
@@ -7,7 +7,7 @@ import o from "../../parsers/oraclesql/OracleSqlParser.mjs";
|
|
|
7
7
|
import { Endpoint as s, Field as c, Index as l, Ref as u, Table as d, TableRecord as f } from "../AST.mjs";
|
|
8
8
|
import { CONSTRAINT_TYPE as p, DATA_TYPE as m } from "../constants.mjs";
|
|
9
9
|
import { getOriginalText as h } from "../helpers.mjs";
|
|
10
|
-
import {
|
|
10
|
+
import { CompilerDiagnostics as g } from "../../../error.mjs";
|
|
11
11
|
import { CARDINALITY_MANY as _, CARDINALITY_MAYBE as v, normalizeQualifiedName as y } from "@dbml/parse";
|
|
12
12
|
//#region src/parse/ANTLR/ASTGeneration/oraclesql/OracleSQLASTGen.js
|
|
13
13
|
n();
|
package/lib/parse/Parser.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require("../_virtual/_rolldown/runtime.cjs"),t=require("../model_structure/database.cjs"),n=require("./error.cjs"),r=require("./ANTLR/ASTGeneration/index.cjs"),i=require("./deprecated/dbmlParser.cjs"),a=require("./deprecated/mssqlParser.cjs"),o=require("./deprecated/mysqlParser.cjs"),s=require("./deprecated/postgresParser.cjs"),c=require("./deprecated/schemarbParser.cjs");let l=require("@dbml/parse");var u=e.__toESM(i.default),d=e.__toESM(a.default),f=e.__toESM(o.default),p=e.__toESM(s.default),m=e.__toESM(c.default),h=class e{constructor(){this.layout=new l.MemoryProjectLayout,this.DBMLCompiler=new l.Compiler(this.layout)}static parseJSONToDatabase(e,{overrideCardinality:n=!1}={}){let r=new t.default(e);return n&&r.adjustCardinalitiesFromColumns(),r}static parseMySQLToJSONv2(e){return r.parse(e,`mysql`)}static parseMySQLToJSON(e){return f.default.parse(e)}static parsePostgresToJSONv2(e){return r.parse(e,`postgres`)}static parsePostgresToJSON(e){return p.default.parse(e)}static parseDBMLToJSONv2(e){let t=new l.MemoryProjectLayout;t.setSource(l.DEFAULT_ENTRY,e);let r=new l.Compiler(t),i=g(r.parse.errors(l.DEFAULT_ENTRY));if(i.length>0)throw n.
|
|
1
|
+
const e=require("../_virtual/_rolldown/runtime.cjs"),t=require("../model_structure/database.cjs"),n=require("./error.cjs"),r=require("./ANTLR/ASTGeneration/index.cjs"),i=require("./deprecated/dbmlParser.cjs"),a=require("./deprecated/mssqlParser.cjs"),o=require("./deprecated/mysqlParser.cjs"),s=require("./deprecated/postgresParser.cjs"),c=require("./deprecated/schemarbParser.cjs");let l=require("@dbml/parse");var u=e.__toESM(i.default),d=e.__toESM(a.default),f=e.__toESM(o.default),p=e.__toESM(s.default),m=e.__toESM(c.default),h=class e{constructor(){this.layout=new l.MemoryProjectLayout,this.DBMLCompiler=new l.Compiler(this.layout)}static parseJSONToDatabase(e,{overrideCardinality:n=!1}={}){let r=new t.default(e);return n&&r.adjustCardinalitiesFromColumns(),r}static parseMySQLToJSONv2(e){return r.parse(e,`mysql`)}static parseMySQLToJSON(e){return f.default.parse(e)}static parsePostgresToJSONv2(e){return r.parse(e,`postgres`)}static parsePostgresToJSON(e){return p.default.parse(e)}static parseDBMLToJSONv2(e){let t=new l.MemoryProjectLayout;t.setSource(l.DEFAULT_ENTRY,e);let r=new l.Compiler(t),i=g(r.parse.errors(l.DEFAULT_ENTRY));if(i.length>0)throw n.CompilerDiagnostics.create(i);return r.parse.rawDb(l.DEFAULT_ENTRY)}static parseDBMLToJSON(e){return u.default.parse(e)}static parseSchemaRbToJSON(e){return m.default.parse(e)}static parseMSSQLToJSON(e){return d.default.parseWithPegError(e)}static parseMSSQLToJSONv2(e){return r.parse(e,`mssql`)}static parseSnowflakeToJSON(e){return r.parse(e,`snowflake`)}static parseOracleToJSON(e){return r.parse(e,`oracle`)}static parse(t,n){return new e().parse(t,n)}getDbmlSource(e){return e=typeof e==`string`?l.Filepath.from(e):e,this.layout.getSource(e)}setDbmlSource(e,t){e=typeof e==`string`?l.Filepath.from(e):e,t===void 0?this.layout.deleteSource(e):this.layout.setSource(e,t)}deleteDbmlSource(e){e=typeof e==`string`?l.Filepath.from(e):e,this.layout.deleteSource(e)}clearDbmlSource(){this.layout.clearSource()}parseDbmlProject(t){t=typeof t==`string`?l.Filepath.from(t):t;let r=this.DBMLCompiler.interpretFile(t),i=g(r.getErrors());if(i.length>0)throw n.CompilerDiagnostics.create(i);return e.parseJSONToDatabase(r.getValue()||{})}parse(t,r){try{let n={},i=!1;switch(r){case`mysql`:n=e.parseMySQLToJSONv2(t),i=!0;break;case`mysqlLegacy`:n=e.parseMySQLToJSON(t),i=!0;break;case`postgres`:n=e.parsePostgresToJSONv2(t),i=!0;break;case`snowflake`:n=e.parseSnowflakeToJSON(t),i=!0;break;case`postgresLegacy`:n=e.parsePostgresToJSON(t),i=!0;break;case`dbml`:n=e.parseDBMLToJSON(t);break;case`dbmlv2`:n=e.parseDBMLToJSONv2(t);break;case`schemarb`:n=e.parseSchemaRbToJSON(t),i=!0;break;case`mssqlLegacy`:n=e.parseMSSQLToJSON(t),i=!0;break;case`mssql`:n=e.parseMSSQLToJSONv2(t),i=!0;break;case`oracle`:n=e.parseOracleToJSON(t),i=!0;break;case`json`:n=typeof t==`object`?t:JSON.parse(t);break;default:break}return e.parseJSONToDatabase(n,{overrideCardinality:i})}catch(e){throw n.CompilerDiagnostics.create(e)}}};function g(e){return e.map(e=>({message:e.diagnostic,filepath:e.filepath.absolute,location:{start:{line:e.nodeOrToken.startPos.line+1,column:e.nodeOrToken.startPos.column+1},end:{line:e.nodeOrToken.endPos.line+1,column:e.nodeOrToken.endPos.column+1}},code:e.code}))}exports.default=h;
|
package/lib/parse/Parser.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __toESM as e } from "../_virtual/_rolldown/runtime.mjs";
|
|
2
2
|
import t from "../model_structure/database.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { CompilerDiagnostics as n } from "./error.mjs";
|
|
4
4
|
import { parse as r } from "./ANTLR/ASTGeneration/index.mjs";
|
|
5
5
|
import { require_dbmlParser as i } from "./deprecated/dbmlParser.mjs";
|
|
6
6
|
import { require_mssqlParser as a } from "./deprecated/mssqlParser.mjs";
|
package/lib/parse/error.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
require("../_virtual/_rolldown/runtime.cjs");var e=class e{constructor(e){this.diags=e}static create(n){return new e(t(n))}map(t){return e.create(this.diags.map(t))}};function t(n){return Array.isArray(n)?n.flatMap(t):n instanceof e?n.diags:[n]}exports.
|
|
1
|
+
require("../_virtual/_rolldown/runtime.cjs");var e=class e{constructor(e){this.diags=e}static create(n){return new e(t(n))}map(t){return e.create(this.diags.map(t))}};function t(n){return Array.isArray(n)?n.flatMap(t):n instanceof e?n.diags:[n]}exports.CompilerDiagnostics=e;
|
package/lib/parse/error.mjs
CHANGED
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": "10.4.0-alpha.
|
|
4
|
+
"version": "10.4.0-alpha.3",
|
|
5
5
|
"description": "> TODO: description",
|
|
6
6
|
"author": "Holistics <dev@holistics.io>",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -41,14 +41,14 @@
|
|
|
41
41
|
"bench": "vitest bench",
|
|
42
42
|
"build:parser": "node src/parse/deprecated/buildParser.cjs",
|
|
43
43
|
"build:lib": "vite build",
|
|
44
|
-
"build": "
|
|
44
|
+
"build": "rimraf ./lib && npm run build:parser && npm run build:lib",
|
|
45
45
|
"prepublish": "npm run build",
|
|
46
46
|
"lint": "eslint $(git diff --relative --name-only --diff-filter=ACMRTUXB master -- . | grep -E '\\.(js|ts)$')",
|
|
47
47
|
"lint:all": "eslint .",
|
|
48
48
|
"lint:fix": "eslint --fix ."
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@dbml/parse": "^10.4.0-alpha.
|
|
51
|
+
"@dbml/parse": "^10.4.0-alpha.3",
|
|
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": "
|
|
62
|
+
"gitHead": "3c5f2624711c16e2b5011f118c62899f41abca7d",
|
|
63
63
|
"engines": {
|
|
64
64
|
"node": ">=16"
|
|
65
65
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -26,10 +26,14 @@ export type { ExportFormat, ExportOptions } from './export/index';
|
|
|
26
26
|
export type { DbmlExporterOptions } from './export/DbmlExporter';
|
|
27
27
|
export type { JsonExporterOptions } from './export/JsonExporter';
|
|
28
28
|
export type { ImportFormat, ImportOptions } from './import/index';
|
|
29
|
-
export { CompilerDiagnostic,
|
|
29
|
+
export { CompilerDiagnostic, CompilerDiagnostics, EditorPosition, ErrorCode, WarningLevel } from './parse/error';
|
|
30
30
|
export * from './model_structure';
|
|
31
31
|
|
|
32
32
|
export {
|
|
33
|
+
CompileError,
|
|
34
|
+
CompileWarning,
|
|
35
|
+
CompileInfo,
|
|
36
|
+
CompileErrorCode,
|
|
33
37
|
isIntegerType,
|
|
34
38
|
isFloatType,
|
|
35
39
|
isNumericType,
|
|
@@ -68,6 +72,8 @@ export { inferMultiplicitiesFromColumns } from './transform/relations';
|
|
|
68
72
|
|
|
69
73
|
// Re-export types
|
|
70
74
|
export type {
|
|
75
|
+
Diagnostic,
|
|
76
|
+
DiagnosticQuickFix,
|
|
71
77
|
ElementRef,
|
|
72
78
|
DiagramView,
|
|
73
79
|
FilterConfig,
|
|
@@ -88,7 +94,9 @@ export type {
|
|
|
88
94
|
NoteIdentifier,
|
|
89
95
|
TableGroupIdentifier,
|
|
90
96
|
CustomMetadata,
|
|
97
|
+
CustomMetadataValue,
|
|
91
98
|
RelationCardinality,
|
|
92
99
|
RelationshipOp,
|
|
93
100
|
DbmlProjectLayout,
|
|
101
|
+
FileSpecifierInfo,
|
|
94
102
|
} from '@dbml/parse';
|
|
@@ -1,32 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
export type { Color, Token, RawNote } from '../../src/model_structure/element';
|
|
2
|
+
import Element from '../../src/model_structure/element';
|
|
2
3
|
|
|
3
|
-
export type Color = `#${string}` | 'none';
|
|
4
|
-
|
|
5
|
-
export interface Token {
|
|
6
|
-
end: {
|
|
7
|
-
column: number;
|
|
8
|
-
line: number;
|
|
9
|
-
offset: number;
|
|
10
|
-
};
|
|
11
|
-
start: {
|
|
12
|
-
column: number;
|
|
13
|
-
line: number;
|
|
14
|
-
offset: number;
|
|
15
|
-
};
|
|
16
|
-
filepath?: Filepath;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface RawNote {
|
|
20
|
-
value: string;
|
|
21
|
-
token: Token;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
declare class Element {
|
|
25
|
-
token: Token;
|
|
26
|
-
id: number;
|
|
27
|
-
selection: string;
|
|
28
|
-
constructor(token: Token);
|
|
29
|
-
bind(selection: any): void;
|
|
30
|
-
error(message: string): void;
|
|
31
|
-
}
|
|
32
4
|
export default Element;
|
package/types/parse/error.d.ts
CHANGED
|
@@ -22,9 +22,9 @@ export declare interface CompilerDiagnostic {
|
|
|
22
22
|
readonly code?: Readonly<ErrorCode>;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export declare class
|
|
25
|
+
export declare class CompilerDiagnostics {
|
|
26
26
|
diags: CompilerDiagnostic[];
|
|
27
27
|
constructor(diags: CompilerDiagnostic[]);
|
|
28
|
-
static create(nestedDiags: unknown):
|
|
29
|
-
map(callback: (diag: CompilerDiagnostic) => CompilerDiagnostic):
|
|
28
|
+
static create(nestedDiags: unknown): CompilerDiagnostics;
|
|
29
|
+
map(callback: (diag: CompilerDiagnostic) => CompilerDiagnostic): CompilerDiagnostics;
|
|
30
30
|
}
|