@dbml/core 8.2.4 → 8.3.0-alpha.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.
- package/lib/index.cjs +3 -3
- package/lib/index.mjs +10 -6
- package/package.json +3 -3
- package/types/model_structure/database.d.ts +7 -7
- package/types/model_structure/element.d.ts +2 -0
- package/types/model_structure/ref.d.ts +4 -4
- package/types/model_structure/schema.d.ts +3 -3
- package/types/model_structure/stickyNote.d.ts +6 -6
- package/types/model_structure/table.d.ts +6 -6
- package/types/model_structure/tableGroup.d.ts +6 -6
- package/types/model_structure/tablePartial.d.ts +6 -6
package/lib/index.cjs
CHANGED
|
@@ -7,7 +7,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
7
7
|
`):``}static buildFieldName(e,t){let n=e.map(e=>`"${t.fields[e].name}"`).join(`, `);return e.length===1?n:`(${n})`}static exportRefs(t,n){let r=t.map(t=>{let r=n.refs[t],i=r.endpointIds.findIndex(e=>n.endpoints[e].relation===`1`),a=i===-1,o=a?0:i,s=r.endpointIds[1-o],c=r.endpointIds[o],l=n.endpoints[s],u=n.endpoints[c],d=`Ref`,f=n.fields[u.fieldIds[0]],p=n.tables[f.tableId],m=n.schemas[p.schemaId],h=e.buildFieldName(u.fieldIds,n);r.name&&(d+=` ${mm(n.schemas[r.schemaId],n)?`"${n.schemas[r.schemaId].name}".`:``}"${r.name}"`),d+=`:`,d+=`${mm(m,n)?`"${m.name}".`:``}"${p.name}".${h} `;let g=n.fields[l.fieldIds[0]],_=n.tables[g.tableId],v=n.schemas[_.schemaId],y=e.buildFieldName(l.fieldIds,n);a?d+=`<> `:l.relation===`1`?d+=`- `:d+=`< `,d+=`${mm(v,n)?`"${v.name}".`:``}"${_.name}".${y}`;let b=[];return r.onUpdate&&b.push(`update: ${r.onUpdate.toLowerCase()}`),r.onDelete&&b.push(`delete: ${r.onDelete.toLowerCase()}`),r.inactive&&b.push(`inactive`),b.length>0&&(d+=` [${b.join(`, `)}]`),d+=`
|
|
8
8
|
`,d});return r.length?r.join(`
|
|
9
9
|
`):``}static getTableGroupSettings(e){let t=[];return e.color&&t.push(`color: ${e.color}`),t.length?` [${t.join(`, `)}]`:``}static exportTableGroups(t,n){let r=t.map(t=>{let r=n.tableGroups[t],i=n.schemas[r.schemaId],a=e.getTableGroupSettings(r),o=r.note?` Note: ${e.escapeNote(r.note)}\n`:``;return`TableGroup ${`${mm(i,n)?`"${i.name}".`:``}"${r.name}"`}${a} {\n${r.tableIds.reduce((e,t)=>{let r=n.tables[t],i=n.schemas[r.schemaId];return`${e}${` ${mm(i,n)?`"${i.name}".`:``}"${r.name}"`}\n`},``)}${o}}\n`});return r.length?r.join(`
|
|
10
|
-
`):``}static exportStickyNotes(t){return cd(t.notes,(t,n)=>{let r=` ${e.escapeNote(n.content)}`,i=`Note ${n.name} {\n${r}\n}\n`;return t?`${t}\n${
|
|
10
|
+
`):``}static getStickyNoteSettings(e){let t=``;return e.color&&(t+=`color: ${e.color}`),t?` [${t}]`:``}static exportStickyNotes(t){return cd(t.notes,(t,n)=>{let r=` ${e.escapeNote(n.content)}`,i=e.getStickyNoteSettings(n),a=`Note ${n.name}${i} {\n${r}\n}\n`;return t?`${t}\n${a}`:a},``)}static exportRecords(e){let{records:t}=e;if(!t||qu(t))return``;let n=Vu(Object.values(t),e=>`${e.schemaName||``}.${e.tableName}`);return Object.values(n).map(e=>{let{schemaName:t,tableName:n}=e[0],r=t?`${(0,f.addDoubleQuoteIfNeeded)(t)}.${(0,f.addDoubleQuoteIfNeeded)(n)}`:(0,f.addDoubleQuoteIfNeeded)(n),i=[...new Set(e.flatMap(e=>e.columns))];return`Records ${r}(${i.map(f.addDoubleQuoteIfNeeded).join(`, `)}) {\n${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(f.formatRecordValue).join(`, `)}`).join(`
|
|
11
11
|
`)}\n}\n`}).join(`
|
|
12
12
|
`)}static export(t,n){let r=[],i=t.database[1],{includeRecords:a}=n;return i.schemaIds.forEach(n=>{let{enumIds:i,tableIds:a,tableGroupIds:o,refIds:s}=t.schemas[n];qu(i)||r.push(e.exportEnums(i,t)),qu(a)||r.push(e.exportTables(a,t)),qu(o)||r.push(e.exportTableGroups(o,t)),qu(s)||r.push(e.exportRefs(s,t))}),qu(t.notes)||r.push(e.exportStickyNotes(t)),a&&!qu(t.records)&&r.push(e.exportRecords(t)),r.join(`
|
|
13
13
|
`)}},Pne=Nne;ud();var Fne=class e{static exportRecords(e){let t=Object.values(e.records||{});return qu(t)?[]:t.map(e=>{let{schemaName:t,tableName:n,columns:r,values:i}=e,a=t?`\`${t}\`.\`${n}\``:`\`${n}\``,o=r.length>0?`(\`${r.join("`, `")}\`)`:``,s=e=>e.value===null?`NULL`:e.type===`expression`||(0,f.isNumericType)(e.type)?e.value:(0,f.isBooleanType)(e.type)?String(e.value).toUpperCase()===`TRUE`?`TRUE`:`FALSE`:(0,f.isStringType)(e.type)||(0,f.isBinaryType)(e.type)||(0,f.isDateTimeType)(e.type)?`'${e.value.replace(/'/g,`''`).replace(/\\/g,`\\\\`)}'`:`CAST('${e.value.replace(/'/g,`''`).replace(/\\/g,`\\\\`)}' AS ${e.type})`;return`INSERT INTO ${a} ${o}\nVALUES\n ${i.map(e=>`(${e.map(s).join(`, `)})`).join(`,
|
|
@@ -27,7 +27,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
27
27
|
`;return r})}static exportIndexes(e,t){return e.filter(e=>!t.indexes[e].pk).map(e=>{let n=t.indexes[e],r=t.tables[n.tableId],i=t.schemas[r.schemaId],a=`CREATE`;n.unique&&(a+=` UNIQUE`);let o=n.name?`"${n.name}"`:``;a+=` INDEX`,o&&(a+=` ${o}`),a+=` ON ${mm(i,t)?`"${i.name}".`:``}"${r.name}"`,n.type&&(a+=` USING ${n.type.toUpperCase()}`);let s=[];return n.columnIds.forEach(e=>{let n=t.indexColumns[e],r=``;r=n.type===`expression`?`(${n.value})`:`"${n.value}"`,s.push(r)}),a+=` (${s.join(`, `)})`,a+=`;
|
|
28
28
|
`,a})}static exportComments(e,t){return e.map(e=>{let n=`COMMENT ON`,r=t.tables[e.tableId],i=t.schemas[r.schemaId];switch(e.type){case`table`:n+=` TABLE ${mm(i,t)?`"${i.name}".`:``}"${r.name}" IS '${r.note.replace(/'/g,`''`)}'`;break;case`column`:{let a=t.fields[e.fieldId];n+=` COLUMN ${mm(i,t)?`"${i.name}".`:``}"${r.name}"."${a.name}" IS '${a.note.replace(/'/g,`''`)}'`;break}default:break}return n+=`;
|
|
29
29
|
`,n})}static export(t){let n=t.database[1],r=new Set(Object.values(t.tables).map(e=>e.name)),i=new Set,a=n.schemaIds.reduce((n,r)=>{let a=t.schemas[r],{enumIds:o}=a;return mm(a,t)&&n.schemas.push(`CREATE SCHEMA "${a.name}";\n`),qu(o)||e.exportEnums(o,t).forEach(e=>{let[t,r]=e;n.enums.push(r),i.add(t)}),n},{schemas:[],enums:[],tables:[],indexes:[],comments:[],refs:[]}),o=n.schemaIds.reduce((n,a)=>{let{tableIds:o,refIds:s}=t.schemas[a];qu(o)||n.tables.push(...e.exportTables(o,t,i));let c=io(o.map(e=>t.tables[e].indexIds));qu(c)||n.indexes.push(...e.exportIndexes(c,t));let l=io(o.map(e=>{let{fieldIds:n,note:r}=t.tables[e],i=n.filter(e=>t.fields[e].note).map(t=>({type:`column`,fieldId:t,tableId:e}));return r?[{type:`table`,tableId:e}].concat(i):i}));return qu(l)||n.comments.push(...e.exportComments(l,t)),qu(s)||n.refs.push(...e.exportRefs(s,t,r)),n},a),s=e.exportRecords(t),c=qu(s)?[]:[`-- Defer constraint checking for INSERT`,`BEGIN;`,`SET CONSTRAINTS ALL DEFERRED;`,``,...s,``,`SET CONSTRAINTS ALL IMMEDIATE;`,`COMMIT;`];return ac(o.schemas,o.enums,o.tables,o.indexes,o.comments,o.refs,c).join(`
|
|
30
|
-
`)}},Vne=Bne,Hne=class{constructor(){this.dbId=1,this.schemaId=1,this.enumId=1,this.tableGroupId=1,this.refId=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}},Une=class extends Error{constructor(e,t={start:{line:1,column:1}}){super(e),this.location=t,this.error=`error`}},Wne=class{constructor(e){this.token=e}bind(e){this.selection=e}error(e){throw new Une(e,this.token)}},bm=Wne;ud();var Gne=class extends bm{constructor({name:e,token:t,note:n,_enum:r,noteToken:i=null}={}){super(t),e||this.error(`Enum value must have a name`),this.name=e,this.note=n?Ga(n,`value`,n):null,this.noteToken=n?Ga(n,`token`,i):null,this._enum=r,this.dbState=this._enum.dbState,this.generateId()}generateId(){this.id=this.dbState.generateId(`enumValueId`)}export(){return{...this.shallowExport()}}exportParentIds(){return{enumId:this._enum.id}}shallowExport(){return{name:this.name,note:this.note}}normalize(e){e.enumValues[this.id]={id:this.id,...this.shallowExport(),...this.exportParentIds()}}},Kne=Gne;ud();var qne=class extends bm{constructor({name:e,token:t,values:n,note:r,schema:i,noteToken:a=null}={}){super(t),e||this.error(`Enum must have a name`),this.name=e,this.note=r?Ga(r,`value`,r):null,this.noteToken=r?Ga(r,`token`,a):null,this.values=[],this.fields=[],this.schema=i,this.dbState=this.schema.dbState,this.generateId(),this.processValues(n)}generateId(){this.id=this.dbState.generateId(`enumId`)}processValues(e){e.forEach(e=>{this.pushValue(new Kne({...e,_enum:this}))})}pushValue(e){this.checkValue(e),this.values.push(e)}checkValue(e){this.values.some(t=>t.name===e.name)&&e.error(`Enum value "${e.name}" existed in enum ${ym(this.schema)?`"${this.schema.name}".`:``}"${this.name}"`)}pushField(e){this.checkField(e),this.fields.push(e)}checkField(e){this.fields.some(t=>t.id===e.id)&&this.error(`Field ${ym(e.table.schema)?`"${e.table.schema.name}".`:``}"${e.table.name}"."${e.name}" already associated with enum ${ym(this.schema)?`"${this.schema.name}".`:``}${this.name}"`)}export(){return{...this.shallowExport(),...this.exportChild()}}exportChild(){return{values:this.values.map(e=>e.export())}}exportChildIds(){return{valueIds:this.values.map(e=>e.id),fieldIds:this.fields.map(e=>e.id)}}exportParentIds(){return{schemaId:this.schema.id}}shallowExport(){return{name:this.name,note:this.note}}normalize(e){e.enums[this.id]={id:this.id,...this.shallowExport(),...this.exportChildIds(),...this.exportParentIds()},this.values.forEach(t=>t.normalize(e))}},Jne=qne,Yne=class extends bm{constructor({tableName:e,schemaName:t,fieldNames:n,relation:r,token:i,ref:a}){super(i),this.relation=r,this.schemaName=t,this.tableName=e,this.fieldNames=n,this.fields=[],this.ref=a,this.dbState=this.ref.dbState,this.generateId();let o=a.schema.database.findOrCreateSchema(t||`public`).database.findTable(t,e);o||this.error(`Can't find table ${Lne(t)?`"${t}".`:``}"${e}"`),this.setFields(n,o)}generateId(){this.id=this.dbState.generateId(`endpointId`)}equals(e){return this.fields.length===e.fields.length?this.compareFields(e):!1}compareFields(e){let t=this.fields.map(e=>e.id).sort(),n=e.fields.map(e=>e.id).sort();for(let e=0;e<t.length;e+=1)if(t[e]!==n[e])return!1;return!0}export(){return{...this.shallowExport()}}exportParentIds(){return{refId:this.ref.id,fieldIds:this.fields.map(e=>e.id)}}shallowExport(){return{schemaName:this.schemaName,tableName:this.tableName,fieldNames:this.fieldNames,relation:this.relation}}setFields(e,t){let n=e&&e.length?[...e]:[];if(!n.length){let e=t.fields.find(e=>e.pk);if(e)n.push(e.name);else{let e=t.indexes.find(e=>e.pk);e?n=e.columns.map(e=>e.value):this.error(`Can't find primary or composite key in table ${ym(t.schema)?`"${t.schema.name}".`:``}"${t.name}"`)}}n.forEach(e=>{let n=t.findField(e);n||this.error(`Can't find field ${ym(t.schema)?`"${t.schema.name}".`:``}"${e}" in table "${t.name}"`),this.fields.push(n),n.pushEndpoint(this)})}normalize(e){e.endpoints[this.id]={id:this.id,...this.shallowExport(),...this.exportParentIds()}}},Xne=Yne;function Zne(e,t){return e[0].equals(t[0])&&e[1].equals(t[1])}var Qne=class extends bm{constructor({name:e,color:t,endpoints:n,onDelete:r,onUpdate:i,inactive:a,token:o,schema:s={},injectedPartial:c=null}={}){super(o),this.name=e,this.color=t,this.onDelete=r,this.onUpdate=i,this.inactive=a,this.endpoints=[],this.schema=s,this.injectedPartial=c,this.dbState=this.schema.dbState,this.generateId(),this.processEndpoints(n)}generateId(){this.id=this.dbState.generateId(`refId`)}processEndpoints(e){e.forEach(e=>{this.endpoints.push(new Xne({...e,ref:this})),e.schemaName}),this.endpoints[0].equals(this.endpoints[1])&&this.error(`Two endpoints are the same`),this.endpoints[0].fields.length!==this.endpoints[1].fields.length&&this.error(`Two endpoints have unequal number of fields`)}equals(e){return Zne(this.endpoints,e.endpoints)||Zne(this.endpoints,e.endpoints.slice().reverse())}export(){return{...this.shallowExport(),...this.exportChild()}}shallowExport(){return{name:this.name,color:this.color,onDelete:this.onDelete,onUpdate:this.onUpdate,inactive:this.inactive,injectedPartialId:this.injectedPartial?.id}}exportChild(){return{endpoints:this.endpoints.map(e=>e.export())}}exportChildIds(){return{endpointIds:this.endpoints.map(e=>e.id)}}exportParentIds(){return{schemaId:this.schema.id}}normalize(e){e.refs[this.id]={id:this.id,...this.shallowExport(),...this.exportChildIds(),...this.exportParentIds()},this.endpoints.forEach(t=>t.normalize(e))}},$ne=Qne,ere=class extends bm{constructor({token:e,name:t,expression:n,table:r,column:i=null,injectedPartial:a=null}={}){super(e),this.name=t,this.expression=n,this.table=r,this.column=i,this.injectedPartial=a,this.dbState=this.table.dbState,this.generateId()}generateId(){this.id=this.dbState.generateId(`checkId`)}export(){return{...this.shallowExport()}}exportParentIds(){return{tableId:this.table.id,columnId:this.column?.id,injectedPartialId:this.injectedPartial?.id}}shallowExport(){return{name:this.name,expression:this.expression}}normalize(e){e.checks[this.id]={id:this.id,...this.shallowExport(),...this.exportParentIds()}}},tre=ere;ud();var nre=class extends bm{constructor({name:e,type:t,unique:n,pk:r,token:i,not_null:a,note:o,dbdefault:s,increment:c,checks:l=[],table:u={},noteToken:d=null,injectedPartial:f=null,injectedToken:p=null}={}){super(i),e||this.error(`Field must have a name`),t||this.error(`Field must have a type`),this.name=e,this.type=t,this.unique=n,this.pk=r,this.not_null=a,this.note=o?Ga(o,`value`,o):null,this.noteToken=o?Ga(o,`token`,d):null,this.dbdefault=s,this.increment=c,this.checks=[],this.endpoints=[],this.table=u,this.injectedPartial=f,this.injectedToken=p,this.dbState=this.table.dbState,this.generateId(),this.bindType(),this.processChecks(l)}generateId(){this.id=this.dbState.generateId(`fieldId`)}bindType(){let e=this.type.type_name,t=this.type.schemaName||`public`;if(this.type.schemaName){let n=this.table.schema.database.findEnum(t,e);if(!n){this.type.type_name=`${t}.${e}`,this.type.originalTypeName=e;return}this._enum=n,n.pushField(this)}else{let n=this.table.schema.database.findEnum(t,e);if(!n)return;this._enum=n,n.pushField(this)}}pushEndpoint(e){this.endpoints.push(e)}export(){return{...this.shallowExport()}}exportParentIds(){return{tableId:this.table.id,enumId:this._enum?this._enum.id:null}}exportChildIds(){return{endpointIds:this.endpoints.map(e=>e.id)}}shallowExport(){return{name:this.name,type:this.type,unique:this.unique,pk:this.pk,not_null:this.not_null,note:this.note,dbdefault:this.dbdefault,increment:this.increment,injectedPartialId:this.injectedPartial?.id??null,checkIds:this.checks.map(e=>e.id)}}normalize(e){e.fields[this.id]={id:this.id,...this.shallowExport(),...this.exportChildIds(),...this.exportParentIds()},this.checks.forEach(t=>t.normalize(e))}processChecks(e){e.forEach(e=>{this.checks.push(new tre({...e,table:this.table,column:this}))})}},rre=nre,ire=class extends bm{constructor({type:e,value:t,index:n,token:r}){super(),this.type=e,this.value=t,this.index=n,this.token=r,this.dbState=this.index.dbState,this.generateId()}generateId(){this.id=this.dbState.generateId(`indexColumnId`)}export(){return{...this.shallowExport()}}exportParentIds(){return{indexId:this.index.id}}shallowExport(){return{type:this.type,value:this.value}}normalize(e){e.indexColumns[this.id]={id:this.id,...this.shallowExport(),...this.exportParentIds()}}},are=ire,ore=class extends bm{constructor({columns:e,type:t,unique:n,pk:r,token:i,name:a,note:o,table:s={},injectedPartial:c=null}={}){super(i),this.name=a,this.type=t,this.unique=n,this.note=o?o.value:null,this.noteToken=o?o.token:null,this.pk=r,this.columns=[],this.table=s,this.injectedPartial=c,this.dbState=this.table.dbState,this.generateId(),this.processIndexColumns(e)}generateId(){this.id=this.dbState.generateId(`indexId`)}processIndexColumns(e){e.forEach(e=>{this.pushIndexColumn(new are({...e,index:this}))})}pushIndexColumn(e){this.checkIndexColumn(e),this.columns.push(e)}checkIndexColumn(e){this.columns.some(t=>t.type===e.type&&t.value===e.value)&&e.error(`Index column ${e.value} existed`)}export(){return{...this.shallowExport(),...this.exportChild()}}exportChild(){return{columns:this.columns.map(e=>e.export())}}exportChildIds(){return{columnIds:this.columns.map(e=>e.id)}}exportParentIds(){return{tableId:this.table.id}}shallowExport(){return{name:this.name,type:this.type,unique:this.unique,pk:this.pk,note:this.note,injectedPartialId:this.injectedPartial?.id}}normalize(e){e.indexes[this.id]={id:this.id,...this.shallowExport(),...this.exportChildIds(),...this.exportParentIds()},this.columns.forEach(t=>t.normalize(e))}},sre=ore;ud();var cre=class extends bm{constructor({name:e,alias:t,note:n,fields:r=[],indexes:i=[],checks:a=[],schema:o={},token:s,headerColor:c,noteToken:l=null,partials:u=[]}={}){super(s),this.name=e,this.alias=t,this.note=n?Ga(n,`value`,n):null,this.noteToken=n?Ga(n,`token`,l):null,this.headerColor=c,this.fields=[],this.indexes=[],this.checks=[],this.schema=o,this.partials=u,this.records=[],this.dbState=this.schema.dbState,this.generateId(),this.processFields(r),this.processPartials(),this.checkFieldCount(),this.processIndexes(i),this.processChecks(a)}generateId(){this.id=this.dbState.generateId(`tableId`)}checkFieldCount(){this.fields.length===0&&this.error(`Table must have at least one field`)}processFields(e){e.forEach(e=>{this.pushField(new rre({...e,table:this}))})}pushField(e){this.checkField(e),this.fields.push(e)}checkField(e){this.fields.some(t=>t.name===e.name)&&e.error(`Field "${e.name}" existed in table ${ym(this.schema)?`"${this.schema.name}".`:``}"${this.name}"`)}processIndexes(e){e.forEach(e=>{this.pushIndex(new sre({...e,table:this}))})}pushIndex(e){this.checkIndex(e),this.indexes.push(e)}checkIndex(e){e.columns.forEach(t=>{t.type===`column`&&!this.findField(t.value)&&e.error(`Column "${t.value}" do not exist in table ${ym(this.schema)?`"${this.schema.name}".`:``}"${this.name}"`)})}processChecks(e){e.forEach(e=>{this.pushCheck(new tre({...e,table:this}))})}pushCheck(e){this.checks.push(e)}findField(e){return this.fields.find(t=>t.name===e)}checkSameId(e){return this.schema.checkSameId(e.schemaName||`public`)&&(this.name===e.name||this.alias===e.name||this.name===e.alias||this.alias&&this.alias===e.alias)}processPartials(){if(!this.partials?.length)return;let e=new Set(this.fields.map(e=>e.name)),t=new Set;Xu(this.note)||t.add(`note`),Xu(this.headerColor)||t.add(`headerColor`);let n=this.partials.sort((e,t)=>t.order-e.order);n.toReversed().forEach(e=>{this.fields.splice(e.order,0,`dummy`)}),n.forEach(n=>{let r=this.schema.database.findTablePartial(n.name);if(r||this.error(`Table partial ${n.name} not found`,n.token),n.id=r.id,r.fields){let t=r.fields.filter(t=>!e.has(t.name)).map(t=>(e.add(t.name),t.inline_refs&&t.inline_refs.forEach(e=>{let n={token:t.token,endpoints:[{tableName:this.name,schemaName:this.schema?.name,fieldNames:[t.name],relation:[`-`,`<`].includes(e.relation)?`1`:`*`,token:t.token},{tableName:e.tableName,schemaName:e.schemaName,fieldNames:e.fieldNames,relation:[`-`,`>`].includes(e.relation)?`1`:`*`,token:e.token}],injectedPartial:r};this.schema.database.injectedRawRefs.push(n)}),new rre({...t,noteToken:null,table:this,injectedPartial:r,injectedToken:n.token})));this.fields.splice(n.order,1,...t)}else this.fields.splice(n.order,1);!t.has(`note`)&&!Xu(r.note)&&(this.noteToken=null,this.note=r.note,t.add(`note`)),!t.has(`headerColor`)&&!Xu(r.headerColor)&&(this.headerColor=r.headerColor,t.add(`headerColor`)),r.indexes.forEach(e=>{this.indexes.push(new sre({...e,table:this,injectedPartial:r}))}),r.checks.forEach(e=>{this.checks.push(new tre({...e,name:e.name&&`${this.name}.${e.name}`,table:this,injectedPartial:r}))})})}export(){return{...this.shallowExport(),...this.exportChild()}}exportChild(){return{fields:this.fields.map(e=>e.export()),indexes:this.indexes.map(e=>e.export())}}exportChildIds(){return{fieldIds:this.fields.map(e=>e.id),indexIds:this.indexes.map(e=>e.id),checkIds:this.checks.map(e=>e.id)}}exportParentIds(){return{schemaId:this.schema.id,groupId:this.group?this.group.id:null}}shallowExport(){return{name:this.name,alias:this.alias,note:this.note,headerColor:this.headerColor,partials:this.partials,recordIds:this.records.map(e=>e.id)}}normalize(e){e.tables[this.id]={id:this.id,...this.shallowExport(),...this.exportChildIds(),...this.exportParentIds()},this.fields.forEach(t=>t.normalize(e)),this.indexes.forEach(t=>t.normalize(e)),this.checks.forEach(t=>t.normalize(e))}},lre=cre;ud();var ure=class extends bm{constructor({name:e,token:t,tables:n=[],schema:r={},note:i,color:a,noteToken:o=null}){super(t),this.name=e,this.tables=[],this.schema=r,this.dbState=this.schema.dbState,this.note=i?Ga(i,`value`,i):null,this.noteToken=i?Ga(i,`token`,o):null,this.color=a,this.generateId(),this.processTables(n)}generateId(){this.id=this.dbState.generateId(`tableGroupId`)}processTables(e){e.forEach(e=>{let t=this.schema.database.findTable(e.schemaName,e.name);t||this.error(`Table ${e.schemaName?`"${e.schemaName}".`:``}${e.name} don't exist`),this.pushTable(t)})}pushTable(e){this.checkTable(e),this.tables.push(e),e.group=this}checkTable(e){this.tables.some(t=>t.id===e.id)&&this.error(`Table ${ym(e.schema)?`"${e.schema.name}".`:``}.${e.name} is already in the group`),e.group&&this.error(`Table ${ym(e.schema)?`"${e.schema.name}".`:``}.${e.name} is already in group ${ym(e.group.schema)?`"${e.group.schema.name}".`:``}${e.group.name}`)}export(){return{...this.shallowExport(),...this.exportChild()}}exportChild(){return{tables:this.tables.map(e=>({tableName:e.name,schemaName:e.schema.name}))}}exportChildIds(){return{tableIds:this.tables.map(e=>e.id)}}exportParentIds(){return{schemaId:this.schema.id}}shallowExport(){return{name:this.name,note:this.note,color:this.color}}normalize(e){e.tableGroups[this.id]={id:this.id,...this.shallowExport(),...this.exportChildIds(),...this.exportParentIds()}}},dre=ure;ud();var fre=class extends bm{constructor({name:e,alias:t,note:n,tables:r=[],refs:i=[],enums:a=[],tableGroups:o=[],token:s,database:c={},noteToken:l=null}={}){super(s),this.tables=[],this.enums=[],this.tableGroups=[],this.refs=[],this.name=e,this.note=n?Ga(n,`value`,n):null,this.noteToken=n?Ga(n,`token`,l):null,this.alias=t,this.database=c,this.dbState=this.database.dbState,this.generateId(),this.processEnums(a),this.processTables(r),this.processRefs(i),this.processTableGroups(o)}generateId(){this.id=this.dbState.generateId(`schemaId`)}processTables(e){e.forEach(e=>{this.pushTable(new lre({...e,schema:this}))})}pushTable(e){this.checkTable(e),this.tables.push(e)}checkTable(e){this.tables.some(t=>t.name===e.name)&&e.error(`Table ${ym(this)?`"${this.name}".`:``}"${e.name}" existed`)}findTable(e){return this.tables.find(t=>t.name===e)}processEnums(e){e.forEach(e=>{this.pushEnum(new Jne({...e,schema:this}))})}pushEnum(e){this.checkEnum(e),this.enums.push(e)}checkEnum(e){this.enums.some(t=>t.name===e.name)&&e.error(`Enum ${ym(this)?`"${this.name}".`:``}"${e.name}" existed`)}processRefs(e){e.forEach(e=>{this.pushRef(new $ne({...e,schema:this}))})}pushRef(e){this.checkRef(e),this.refs.push(e)}checkRef(e){if(this.refs.some(t=>t.equals(e))){let t=e.endpoints[0],n=t.fieldNames.map(JSON.stringify).join(`, `),r=e.endpoints[1],i=r.fieldNames.map(JSON.stringify).join(`, `),a=`"${t.schemaName?`${t.schemaName}"."`:``}${t.tableName}"(${n})`,o=`"${r.schemaName?`${r.schemaName}"."`:``}${r.tableName}"(${i})`;e.error(`Reference with the same endpoints already exists: ${a} references ${o}`)}}processTableGroups(e){e.forEach(e=>{this.pushTableGroup(new dre({...e,schema:this}))})}pushTableGroup(e){this.checkTableGroup(e),this.tableGroups.push(e)}checkTableGroup(e){this.tableGroups.some(t=>t.name===e.name)&&e.error(`Table Group ${ym(this)?`"${this.name}".`:``}"${e.name}" existed`)}checkSameId(e){return this.name===e.name||this.alias===e.name||this.name===e.alias||this.alias&&this.alias===e.alias}export(){return{...this.shallowExport(),...this.exportChild()}}exportChild(){return{tables:this.tables.map(e=>e.export()),enums:this.enums.map(e=>e.export()),tableGroups:this.tableGroups.map(e=>e.export()),refs:this.refs.map(e=>e.export())}}exportChildIds(){return{tableIds:this.tables.map(e=>e.id),enumIds:this.enums.map(e=>e.id),tableGroupIds:this.tableGroups.map(e=>e.id),refIds:this.refs.map(e=>e.id)}}exportParentIds(){return{databaseId:this.database.id}}shallowExport(){return{name:this.name,note:this.note,alias:this.alias}}normalize(e){e.schemas[this.id]={id:this.id,...this.shallowExport(),...this.exportChildIds(),...this.exportParentIds()},this.tables.forEach(t=>t.normalize(e)),this.enums.forEach(t=>t.normalize(e)),this.tableGroups.forEach(t=>t.normalize(e)),this.refs.forEach(t=>t.normalize(e))}},pre=fre,mre=class extends bm{constructor({name:e,content:t,headerColor:n,token:r,database:i={}}={}){super(r),this.name=e,this.content=t,this.headerColor=n,this.database=i,this.dbState=this.database.dbState,this.generateId()}generateId(){this.id=this.dbState.generateId(`noteId`)}export(){return{name:this.name,content:this.content,headerColor:this.headerColor}}normalize(e){e.notes[this.id]={id:this.id,...this.export()}}},hre=mre;ud();var gre=class extends bm{constructor({name:e,note:t,fields:n=[],indexes:r=[],checks:i=[],token:a,headerColor:o,noteToken:s=null,dbState:c}={}){super(a),this.name=e,this.note=t?Ga(t,`value`,t):null,this.noteToken=t?Ga(t,`token`,s):null,this.headerColor=o,this.fields=n,this.indexes=r,this.checks=i,this.dbState=c,this.generateId()}generateId(){this.id=this.dbState.generateId(`tablePartialId`)}export(){return{...this.shallowExport()}}shallowExport(){return{name:this.name,note:this.note,headerColor:this.headerColor,fields:this.fields,indexes:this.indexes}}normalize(e){e.tablePartials[this.id]={id:this.id,...this.shallowExport()}}},_re=gre;ud();var vre=class extends bm{constructor({schemas:e=[],tables:t=[],notes:n=[],enums:r=[],refs:i=[],tableGroups:a=[],project:o={},aliases:s=[],records:c=[],tablePartials:l=[],diagramViews:u=[]}){super(),this.dbState=new Hne,this.generateId(),this.hasDefaultSchema=!1,this.schemas=[],this.notes=[],this.note=o.note?Ga(o,`note.value`,o.note):null,this.noteToken=o.note?Ga(o,`note.token`,o.noteToken):null,this.databaseType=o.database_type,this.name=o.name,this.token=o.token,this.aliases=s,this.records=[],this.tablePartials=[],this.diagramViews=u,this.injectedRawRefs=[],this.processNotes(n),this.processRecords(c),this.processTablePartials(l),this.processSchemas(e),this.processSchemaElements(r,Ene),this.processSchemaElements(t,wne),this.linkRecordsToTables(),this.processSchemaElements(n,`note`),this.processSchemaElements(i,`ref`),this.processSchemaElements(a,One),this.injectedRawRefs.forEach(e=>{let t=this.findOrCreateSchema(fm),n=new $ne({...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 hre({...e,database:this}))})}processRecords(e){e.forEach(({schemaName:e,tableName:t,columns:n,values:r,token:i})=>{this.records.push({id:this.dbState.generateId(`recordId`),schemaName:e,tableName:t,columns:n,values:r,token:i})})}processTablePartials(e){e.forEach(e=>{this.tablePartials.push(new _re({...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 pre({...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(fm),t){case wne:n.pushTable(new lre({...e,schema:n}));break;case Ene:n.pushEnum(new Jne({...e,schema:n}));break;case One:n.pushTableGroup(new dre({...e,schema:n}));break;case`ref`:n.pushRef(new $ne({...e,schema:n}));break;default:break}})}linkRecordsToTables(){let e={};this.schemas.forEach(t=>{e[t.name]={},t.tables.forEach(n=>{e[t.name][n.name]=n})}),this.records.forEach(t=>{let n=e[t.schemaName??`public`]?.[t.tableName];n&&(t.tableId=n.id,n.records.push(t))})}findOrCreateSchema(e){let t=this.schemas.find(t=>t.name===e||t.alias===e);return t||(t=new pre({name:e,note:{value:e===`public`?`Default ${Xo(fm)} Schema`:null},database:this}),this.pushSchema(t)),t}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)}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);return n?n.enums.find(e=>e.name===t):null}findTablePartial(e){return this.tablePartials.find(t=>t.name===e)}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:{},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}},xm=vre,yre=class{static export(e,t){let{isNormalized:n}=t;return!n&&e instanceof xm?JSON.stringify(e.export(),null,2):JSON.stringify(e,null,2)}},bre=yre;ud();var xre=class e{static exportRecords(e){let t=Object.values(e.records||{});return qu(t)?[]:t.map(e=>{let{schemaName:t,tableName:n,columns:r,values:i}=e,a=t?`[${t}].[${n}]`:`[${n}]`,o=r.length>0?`([${r.join(`], [`)}])`:``,s=e=>e.value===null?`NULL`:e.type===`expression`||(0,f.isNumericType)(e.type)?e.value:(0,f.isBooleanType)(e.type)?String(e.value).toUpperCase()===`TRUE`?`1`:`0`:(0,f.isStringType)(e.type)||(0,f.isDateTimeType)(e.type)?`'${e.value.replace(/'/g,`''`)}'`:(0,f.isBinaryType)(e.type)?`0x${e.value}`:`CAST('${e.value.replace(/'/g,`''`)}' AS ${e.type})`;return`INSERT INTO ${a} ${o}\nVALUES\n ${i.map(e=>`(${e.map(s).join(`, `)})`).join(`,
|
|
30
|
+
`)}},Vne=Bne,Hne=class{constructor(){this.dbId=1,this.schemaId=1,this.enumId=1,this.tableGroupId=1,this.refId=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}},Une=class extends Error{constructor(e,t={start:{line:1,column:1}}){super(e),this.location=t,this.error=`error`}},Wne=class{constructor(e){this.token=e}bind(e){this.selection=e}error(e){throw new Une(e,this.token)}},bm=Wne;ud();var Gne=class extends bm{constructor({name:e,token:t,note:n,_enum:r,noteToken:i=null}={}){super(t),e||this.error(`Enum value must have a name`),this.name=e,this.note=n?Ga(n,`value`,n):null,this.noteToken=n?Ga(n,`token`,i):null,this._enum=r,this.dbState=this._enum.dbState,this.generateId()}generateId(){this.id=this.dbState.generateId(`enumValueId`)}export(){return{...this.shallowExport()}}exportParentIds(){return{enumId:this._enum.id}}shallowExport(){return{name:this.name,note:this.note}}normalize(e){e.enumValues[this.id]={id:this.id,...this.shallowExport(),...this.exportParentIds()}}},Kne=Gne;ud();var qne=class extends bm{constructor({name:e,token:t,values:n,note:r,schema:i,noteToken:a=null}={}){super(t),e||this.error(`Enum must have a name`),this.name=e,this.note=r?Ga(r,`value`,r):null,this.noteToken=r?Ga(r,`token`,a):null,this.values=[],this.fields=[],this.schema=i,this.dbState=this.schema.dbState,this.generateId(),this.processValues(n)}generateId(){this.id=this.dbState.generateId(`enumId`)}processValues(e){e.forEach(e=>{this.pushValue(new Kne({...e,_enum:this}))})}pushValue(e){this.checkValue(e),this.values.push(e)}checkValue(e){this.values.some(t=>t.name===e.name)&&e.error(`Enum value "${e.name}" existed in enum ${ym(this.schema)?`"${this.schema.name}".`:``}"${this.name}"`)}pushField(e){this.checkField(e),this.fields.push(e)}checkField(e){this.fields.some(t=>t.id===e.id)&&this.error(`Field ${ym(e.table.schema)?`"${e.table.schema.name}".`:``}"${e.table.name}"."${e.name}" already associated with enum ${ym(this.schema)?`"${this.schema.name}".`:``}${this.name}"`)}export(){return{...this.shallowExport(),...this.exportChild()}}exportChild(){return{values:this.values.map(e=>e.export())}}exportChildIds(){return{valueIds:this.values.map(e=>e.id),fieldIds:this.fields.map(e=>e.id)}}exportParentIds(){return{schemaId:this.schema.id}}shallowExport(){return{name:this.name,note:this.note}}normalize(e){e.enums[this.id]={id:this.id,...this.shallowExport(),...this.exportChildIds(),...this.exportParentIds()},this.values.forEach(t=>t.normalize(e))}},Jne=qne,Yne=class extends bm{constructor({tableName:e,schemaName:t,fieldNames:n,relation:r,token:i,ref:a}){super(i),this.relation=r,this.schemaName=t,this.tableName=e,this.fieldNames=n,this.fields=[],this.ref=a,this.dbState=this.ref.dbState,this.generateId();let o=a.schema.database.findOrCreateSchema(t||`public`).database.findTable(t,e);o||this.error(`Can't find table ${Lne(t)?`"${t}".`:``}"${e}"`),this.setFields(n,o)}generateId(){this.id=this.dbState.generateId(`endpointId`)}equals(e){return this.fields.length===e.fields.length?this.compareFields(e):!1}compareFields(e){let t=this.fields.map(e=>e.id).sort(),n=e.fields.map(e=>e.id).sort();for(let e=0;e<t.length;e+=1)if(t[e]!==n[e])return!1;return!0}export(){return{...this.shallowExport()}}exportParentIds(){return{refId:this.ref.id,fieldIds:this.fields.map(e=>e.id)}}shallowExport(){return{schemaName:this.schemaName,tableName:this.tableName,fieldNames:this.fieldNames,relation:this.relation}}setFields(e,t){let n=e&&e.length?[...e]:[];if(!n.length){let e=t.fields.find(e=>e.pk);if(e)n.push(e.name);else{let e=t.indexes.find(e=>e.pk);e?n=e.columns.map(e=>e.value):this.error(`Can't find primary or composite key in table ${ym(t.schema)?`"${t.schema.name}".`:``}"${t.name}"`)}}n.forEach(e=>{let n=t.findField(e);n||this.error(`Can't find field ${ym(t.schema)?`"${t.schema.name}".`:``}"${e}" in table "${t.name}"`),this.fields.push(n),n.pushEndpoint(this)})}normalize(e){e.endpoints[this.id]={id:this.id,...this.shallowExport(),...this.exportParentIds()}}},Xne=Yne;function Zne(e,t){return e[0].equals(t[0])&&e[1].equals(t[1])}var Qne=class extends bm{constructor({name:e,color:t,endpoints:n,onDelete:r,onUpdate:i,inactive:a,token:o,schema:s={},injectedPartial:c=null}={}){super(o),this.name=e,this.color=t,this.onDelete=r,this.onUpdate=i,this.inactive=a,this.endpoints=[],this.schema=s,this.injectedPartial=c,this.dbState=this.schema.dbState,this.generateId(),this.processEndpoints(n)}generateId(){this.id=this.dbState.generateId(`refId`)}processEndpoints(e){e.forEach(e=>{this.endpoints.push(new Xne({...e,ref:this})),e.schemaName}),this.endpoints[0].equals(this.endpoints[1])&&this.error(`Two endpoints are the same`),this.endpoints[0].fields.length!==this.endpoints[1].fields.length&&this.error(`Two endpoints have unequal number of fields`)}equals(e){return Zne(this.endpoints,e.endpoints)||Zne(this.endpoints,e.endpoints.slice().reverse())}export(){return{...this.shallowExport(),...this.exportChild()}}shallowExport(){return{name:this.name,color:this.color,onDelete:this.onDelete,onUpdate:this.onUpdate,inactive:this.inactive,injectedPartialId:this.injectedPartial?.id}}exportChild(){return{endpoints:this.endpoints.map(e=>e.export())}}exportChildIds(){return{endpointIds:this.endpoints.map(e=>e.id)}}exportParentIds(){return{schemaId:this.schema.id}}normalize(e){e.refs[this.id]={id:this.id,...this.shallowExport(),...this.exportChildIds(),...this.exportParentIds()},this.endpoints.forEach(t=>t.normalize(e))}},$ne=Qne,ere=class extends bm{constructor({token:e,name:t,expression:n,table:r,column:i=null,injectedPartial:a=null}={}){super(e),this.name=t,this.expression=n,this.table=r,this.column=i,this.injectedPartial=a,this.dbState=this.table.dbState,this.generateId()}generateId(){this.id=this.dbState.generateId(`checkId`)}export(){return{...this.shallowExport()}}exportParentIds(){return{tableId:this.table.id,columnId:this.column?.id,injectedPartialId:this.injectedPartial?.id}}shallowExport(){return{name:this.name,expression:this.expression}}normalize(e){e.checks[this.id]={id:this.id,...this.shallowExport(),...this.exportParentIds()}}},tre=ere;ud();var nre=class extends bm{constructor({name:e,type:t,unique:n,pk:r,token:i,not_null:a,note:o,dbdefault:s,increment:c,checks:l=[],table:u={},noteToken:d=null,injectedPartial:f=null,injectedToken:p=null}={}){super(i),e||this.error(`Field must have a name`),t||this.error(`Field must have a type`),this.name=e,this.type=t,this.unique=n,this.pk=r,this.not_null=a,this.note=o?Ga(o,`value`,o):null,this.noteToken=o?Ga(o,`token`,d):null,this.dbdefault=s,this.increment=c,this.checks=[],this.endpoints=[],this.table=u,this.injectedPartial=f,this.injectedToken=p,this.dbState=this.table.dbState,this.generateId(),this.bindType(),this.processChecks(l)}generateId(){this.id=this.dbState.generateId(`fieldId`)}bindType(){let e=this.type.type_name,t=this.type.schemaName||`public`;if(this.type.schemaName){let n=this.table.schema.database.findEnum(t,e);if(!n){this.type.type_name=`${t}.${e}`,this.type.originalTypeName=e;return}this._enum=n,n.pushField(this)}else{let n=this.table.schema.database.findEnum(t,e);if(!n)return;this._enum=n,n.pushField(this)}}pushEndpoint(e){this.endpoints.push(e)}export(){return{...this.shallowExport()}}exportParentIds(){return{tableId:this.table.id,enumId:this._enum?this._enum.id:null}}exportChildIds(){return{endpointIds:this.endpoints.map(e=>e.id)}}shallowExport(){return{name:this.name,type:this.type,unique:this.unique,pk:this.pk,not_null:this.not_null,note:this.note,dbdefault:this.dbdefault,increment:this.increment,injectedPartialId:this.injectedPartial?.id??null,checkIds:this.checks.map(e=>e.id)}}normalize(e){e.fields[this.id]={id:this.id,...this.shallowExport(),...this.exportChildIds(),...this.exportParentIds()},this.checks.forEach(t=>t.normalize(e))}processChecks(e){e.forEach(e=>{this.checks.push(new tre({...e,table:this.table,column:this}))})}},rre=nre,ire=class extends bm{constructor({type:e,value:t,index:n,token:r}){super(),this.type=e,this.value=t,this.index=n,this.token=r,this.dbState=this.index.dbState,this.generateId()}generateId(){this.id=this.dbState.generateId(`indexColumnId`)}export(){return{...this.shallowExport()}}exportParentIds(){return{indexId:this.index.id}}shallowExport(){return{type:this.type,value:this.value}}normalize(e){e.indexColumns[this.id]={id:this.id,...this.shallowExport(),...this.exportParentIds()}}},are=ire,ore=class extends bm{constructor({columns:e,type:t,unique:n,pk:r,token:i,name:a,note:o,table:s={},injectedPartial:c=null}={}){super(i),this.name=a,this.type=t,this.unique=n,this.note=o?o.value:null,this.noteToken=o?o.token:null,this.pk=r,this.columns=[],this.table=s,this.injectedPartial=c,this.dbState=this.table.dbState,this.generateId(),this.processIndexColumns(e)}generateId(){this.id=this.dbState.generateId(`indexId`)}processIndexColumns(e){e.forEach(e=>{this.pushIndexColumn(new are({...e,index:this}))})}pushIndexColumn(e){this.checkIndexColumn(e),this.columns.push(e)}checkIndexColumn(e){this.columns.some(t=>t.type===e.type&&t.value===e.value)&&e.error(`Index column ${e.value} existed`)}export(){return{...this.shallowExport(),...this.exportChild()}}exportChild(){return{columns:this.columns.map(e=>e.export())}}exportChildIds(){return{columnIds:this.columns.map(e=>e.id)}}exportParentIds(){return{tableId:this.table.id}}shallowExport(){return{name:this.name,type:this.type,unique:this.unique,pk:this.pk,note:this.note,injectedPartialId:this.injectedPartial?.id}}normalize(e){e.indexes[this.id]={id:this.id,...this.shallowExport(),...this.exportChildIds(),...this.exportParentIds()},this.columns.forEach(t=>t.normalize(e))}},sre=ore;ud();var cre=class extends bm{constructor({name:e,alias:t,note:n,fields:r=[],indexes:i=[],checks:a=[],schema:o={},token:s,headerColor:c,noteToken:l=null,partials:u=[]}={}){super(s),this.name=e,this.alias=t,this.note=n?Ga(n,`value`,n):null,this.noteToken=n?Ga(n,`token`,l):null,this.headerColor=c,this.fields=[],this.indexes=[],this.checks=[],this.schema=o,this.partials=u,this.records=[],this.dbState=this.schema.dbState,this.generateId(),this.processFields(r),this.processPartials(),this.checkFieldCount(),this.processIndexes(i),this.processChecks(a)}generateId(){this.id=this.dbState.generateId(`tableId`)}checkFieldCount(){this.fields.length===0&&this.error(`Table must have at least one field`)}processFields(e){e.forEach(e=>{this.pushField(new rre({...e,table:this}))})}pushField(e){this.checkField(e),this.fields.push(e)}checkField(e){this.fields.some(t=>t.name===e.name)&&e.error(`Field "${e.name}" existed in table ${ym(this.schema)?`"${this.schema.name}".`:``}"${this.name}"`)}processIndexes(e){e.forEach(e=>{this.pushIndex(new sre({...e,table:this}))})}pushIndex(e){this.checkIndex(e),this.indexes.push(e)}checkIndex(e){e.columns.forEach(t=>{t.type===`column`&&!this.findField(t.value)&&e.error(`Column "${t.value}" do not exist in table ${ym(this.schema)?`"${this.schema.name}".`:``}"${this.name}"`)})}processChecks(e){e.forEach(e=>{this.pushCheck(new tre({...e,table:this}))})}pushCheck(e){this.checks.push(e)}findField(e){return this.fields.find(t=>t.name===e)}checkSameId(e){return this.schema.checkSameId(e.schemaName||`public`)&&(this.name===e.name||this.alias===e.name||this.name===e.alias||this.alias&&this.alias===e.alias)}processPartials(){if(!this.partials?.length)return;let e=new Set(this.fields.map(e=>e.name)),t=new Set;Xu(this.note)||t.add(`note`),Xu(this.headerColor)||t.add(`headerColor`);let n=this.partials.sort((e,t)=>t.order-e.order);n.toReversed().forEach(e=>{this.fields.splice(e.order,0,`dummy`)}),n.forEach(n=>{let r=this.schema.database.findTablePartial(n.name);if(r||this.error(`Table partial ${n.name} not found`,n.token),n.id=r.id,r.fields){let t=r.fields.filter(t=>!e.has(t.name)).map(t=>(e.add(t.name),t.inline_refs&&t.inline_refs.forEach(e=>{let n={token:t.token,endpoints:[{tableName:this.name,schemaName:this.schema?.name,fieldNames:[t.name],relation:[`-`,`<`].includes(e.relation)?`1`:`*`,token:t.token},{tableName:e.tableName,schemaName:e.schemaName,fieldNames:e.fieldNames,relation:[`-`,`>`].includes(e.relation)?`1`:`*`,token:e.token}],injectedPartial:r};this.schema.database.injectedRawRefs.push(n)}),new rre({...t,noteToken:null,table:this,injectedPartial:r,injectedToken:n.token})));this.fields.splice(n.order,1,...t)}else this.fields.splice(n.order,1);!t.has(`note`)&&!Xu(r.note)&&(this.noteToken=null,this.note=r.note,t.add(`note`)),!t.has(`headerColor`)&&!Xu(r.headerColor)&&(this.headerColor=r.headerColor,t.add(`headerColor`)),r.indexes.forEach(e=>{this.indexes.push(new sre({...e,table:this,injectedPartial:r}))}),r.checks.forEach(e=>{this.checks.push(new tre({...e,name:e.name&&`${this.name}.${e.name}`,table:this,injectedPartial:r}))})})}export(){return{...this.shallowExport(),...this.exportChild()}}exportChild(){return{fields:this.fields.map(e=>e.export()),indexes:this.indexes.map(e=>e.export())}}exportChildIds(){return{fieldIds:this.fields.map(e=>e.id),indexIds:this.indexes.map(e=>e.id),checkIds:this.checks.map(e=>e.id)}}exportParentIds(){return{schemaId:this.schema.id,groupId:this.group?this.group.id:null}}shallowExport(){return{name:this.name,alias:this.alias,note:this.note,headerColor:this.headerColor,partials:this.partials,recordIds:this.records.map(e=>e.id)}}normalize(e){e.tables[this.id]={id:this.id,...this.shallowExport(),...this.exportChildIds(),...this.exportParentIds()},this.fields.forEach(t=>t.normalize(e)),this.indexes.forEach(t=>t.normalize(e)),this.checks.forEach(t=>t.normalize(e))}},lre=cre;ud();var ure=class extends bm{constructor({name:e,token:t,tables:n=[],schema:r={},note:i,color:a,noteToken:o=null}){super(t),this.name=e,this.tables=[],this.schema=r,this.dbState=this.schema.dbState,this.note=i?Ga(i,`value`,i):null,this.noteToken=i?Ga(i,`token`,o):null,this.color=a,this.generateId(),this.processTables(n)}generateId(){this.id=this.dbState.generateId(`tableGroupId`)}processTables(e){e.forEach(e=>{let t=this.schema.database.findTable(e.schemaName,e.name);t||this.error(`Table ${e.schemaName?`"${e.schemaName}".`:``}${e.name} don't exist`),this.pushTable(t)})}pushTable(e){this.checkTable(e),this.tables.push(e),e.group=this}checkTable(e){this.tables.some(t=>t.id===e.id)&&this.error(`Table ${ym(e.schema)?`"${e.schema.name}".`:``}.${e.name} is already in the group`),e.group&&this.error(`Table ${ym(e.schema)?`"${e.schema.name}".`:``}.${e.name} is already in group ${ym(e.group.schema)?`"${e.group.schema.name}".`:``}${e.group.name}`)}export(){return{...this.shallowExport(),...this.exportChild()}}exportChild(){return{tables:this.tables.map(e=>({tableName:e.name,schemaName:e.schema.name}))}}exportChildIds(){return{tableIds:this.tables.map(e=>e.id)}}exportParentIds(){return{schemaId:this.schema.id}}shallowExport(){return{name:this.name,note:this.note,color:this.color}}normalize(e){e.tableGroups[this.id]={id:this.id,...this.shallowExport(),...this.exportChildIds(),...this.exportParentIds()}}},dre=ure;ud();var fre=class extends bm{constructor({name:e,alias:t,note:n,tables:r=[],refs:i=[],enums:a=[],tableGroups:o=[],token:s,database:c={},noteToken:l=null}={}){super(s),this.tables=[],this.enums=[],this.tableGroups=[],this.refs=[],this.name=e,this.note=n?Ga(n,`value`,n):null,this.noteToken=n?Ga(n,`token`,l):null,this.alias=t,this.database=c,this.dbState=this.database.dbState,this.generateId(),this.processEnums(a),this.processTables(r),this.processRefs(i),this.processTableGroups(o)}generateId(){this.id=this.dbState.generateId(`schemaId`)}processTables(e){e.forEach(e=>{this.pushTable(new lre({...e,schema:this}))})}pushTable(e){this.checkTable(e),this.tables.push(e)}checkTable(e){this.tables.some(t=>t.name===e.name)&&e.error(`Table ${ym(this)?`"${this.name}".`:``}"${e.name}" existed`)}findTable(e){return this.tables.find(t=>t.name===e)}processEnums(e){e.forEach(e=>{this.pushEnum(new Jne({...e,schema:this}))})}pushEnum(e){this.checkEnum(e),this.enums.push(e)}checkEnum(e){this.enums.some(t=>t.name===e.name)&&e.error(`Enum ${ym(this)?`"${this.name}".`:``}"${e.name}" existed`)}processRefs(e){e.forEach(e=>{this.pushRef(new $ne({...e,schema:this}))})}pushRef(e){this.checkRef(e),this.refs.push(e)}checkRef(e){if(this.refs.some(t=>t.equals(e))){let t=e.endpoints[0],n=t.fieldNames.map(JSON.stringify).join(`, `),r=e.endpoints[1],i=r.fieldNames.map(JSON.stringify).join(`, `),a=`"${t.schemaName?`${t.schemaName}"."`:``}${t.tableName}"(${n})`,o=`"${r.schemaName?`${r.schemaName}"."`:``}${r.tableName}"(${i})`;e.error(`Reference with the same endpoints already exists: ${a} references ${o}`)}}processTableGroups(e){e.forEach(e=>{this.pushTableGroup(new dre({...e,schema:this}))})}pushTableGroup(e){this.checkTableGroup(e),this.tableGroups.push(e)}checkTableGroup(e){this.tableGroups.some(t=>t.name===e.name)&&e.error(`Table Group ${ym(this)?`"${this.name}".`:``}"${e.name}" existed`)}checkSameId(e){return this.name===e.name||this.alias===e.name||this.name===e.alias||this.alias&&this.alias===e.alias}export(){return{...this.shallowExport(),...this.exportChild()}}exportChild(){return{tables:this.tables.map(e=>e.export()),enums:this.enums.map(e=>e.export()),tableGroups:this.tableGroups.map(e=>e.export()),refs:this.refs.map(e=>e.export())}}exportChildIds(){return{tableIds:this.tables.map(e=>e.id),enumIds:this.enums.map(e=>e.id),tableGroupIds:this.tableGroups.map(e=>e.id),refIds:this.refs.map(e=>e.id)}}exportParentIds(){return{databaseId:this.database.id}}shallowExport(){return{name:this.name,note:this.note,alias:this.alias}}normalize(e){e.schemas[this.id]={id:this.id,...this.shallowExport(),...this.exportChildIds(),...this.exportParentIds()},this.tables.forEach(t=>t.normalize(e)),this.enums.forEach(t=>t.normalize(e)),this.tableGroups.forEach(t=>t.normalize(e)),this.refs.forEach(t=>t.normalize(e))}},pre=fre,mre=class extends bm{constructor({name:e,content:t,color:n,token:r,database:i={}}={}){super(r),this.name=e,this.content=t,this.color=n,this.database=i,this.dbState=this.database.dbState,this.generateId()}generateId(){this.id=this.dbState.generateId(`noteId`)}export(){return{name:this.name,content:this.content,color:this.color}}normalize(e){e.notes[this.id]={id:this.id,...this.export()}}},hre=mre;ud();var gre=class extends bm{constructor({name:e,note:t,fields:n=[],indexes:r=[],checks:i=[],token:a,headerColor:o,noteToken:s=null,dbState:c}={}){super(a),this.name=e,this.note=t?Ga(t,`value`,t):null,this.noteToken=t?Ga(t,`token`,s):null,this.headerColor=o,this.fields=n,this.indexes=r,this.checks=i,this.dbState=c,this.generateId()}generateId(){this.id=this.dbState.generateId(`tablePartialId`)}export(){return{...this.shallowExport()}}shallowExport(){return{name:this.name,note:this.note,headerColor:this.headerColor,fields:this.fields,indexes:this.indexes}}normalize(e){e.tablePartials[this.id]={id:this.id,...this.shallowExport()}}},_re=gre;ud();var vre=class extends bm{constructor({schemas:e=[],tables:t=[],notes:n=[],enums:r=[],refs:i=[],tableGroups:a=[],project:o={},aliases:s=[],records:c=[],tablePartials:l=[],diagramViews:u=[]}){super(),this.dbState=new Hne,this.generateId(),this.hasDefaultSchema=!1,this.schemas=[],this.notes=[],this.note=o.note?Ga(o,`note.value`,o.note):null,this.noteToken=o.note?Ga(o,`note.token`,o.noteToken):null,this.databaseType=o.database_type,this.name=o.name,this.token=o.token,this.aliases=s,this.records=[],this.tablePartials=[],this.diagramViews=u,this.injectedRawRefs=[],this.processNotes(n),this.processRecords(c),this.processTablePartials(l),this.processSchemas(e),this.processSchemaElements(r,Ene),this.processSchemaElements(t,wne),this.linkRecordsToTables(),this.processSchemaElements(n,`note`),this.processSchemaElements(i,`ref`),this.processSchemaElements(a,One),this.injectedRawRefs.forEach(e=>{let t=this.findOrCreateSchema(fm),n=new $ne({...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 hre({...e,database:this}))})}processRecords(e){e.forEach(({schemaName:e,tableName:t,columns:n,values:r,token:i})=>{this.records.push({id:this.dbState.generateId(`recordId`),schemaName:e,tableName:t,columns:n,values:r,token:i})})}processTablePartials(e){e.forEach(e=>{this.tablePartials.push(new _re({...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 pre({...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(fm),t){case wne:n.pushTable(new lre({...e,schema:n}));break;case Ene:n.pushEnum(new Jne({...e,schema:n}));break;case One:n.pushTableGroup(new dre({...e,schema:n}));break;case`ref`:n.pushRef(new $ne({...e,schema:n}));break;default:break}})}linkRecordsToTables(){let e={};this.schemas.forEach(t=>{e[t.name]={},t.tables.forEach(n=>{e[t.name][n.name]=n})}),this.records.forEach(t=>{let n=e[t.schemaName??`public`]?.[t.tableName];n&&(t.tableId=n.id,n.records.push(t))})}findOrCreateSchema(e){let t=this.schemas.find(t=>t.name===e||t.alias===e);return t||(t=new pre({name:e,note:{value:e===`public`?`Default ${Xo(fm)} Schema`:null},database:this}),this.pushSchema(t)),t}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)}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);return n?n.enums.find(e=>e.name===t):null}findTablePartial(e){return this.tablePartials.find(t=>t.name===e)}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:{},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}},xm=vre,yre=class{static export(e,t){let{isNormalized:n}=t;return!n&&e instanceof xm?JSON.stringify(e.export(),null,2):JSON.stringify(e,null,2)}},bre=yre;ud();var xre=class e{static exportRecords(e){let t=Object.values(e.records||{});return qu(t)?[]:t.map(e=>{let{schemaName:t,tableName:n,columns:r,values:i}=e,a=t?`[${t}].[${n}]`:`[${n}]`,o=r.length>0?`([${r.join(`], [`)}])`:``,s=e=>e.value===null?`NULL`:e.type===`expression`||(0,f.isNumericType)(e.type)?e.value:(0,f.isBooleanType)(e.type)?String(e.value).toUpperCase()===`TRUE`?`1`:`0`:(0,f.isStringType)(e.type)||(0,f.isDateTimeType)(e.type)?`'${e.value.replace(/'/g,`''`)}'`:(0,f.isBinaryType)(e.type)?`0x${e.value}`:`CAST('${e.value.replace(/'/g,`''`)}' AS ${e.type})`;return`INSERT INTO ${a} ${o}\nVALUES\n ${i.map(e=>`(${e.map(s).join(`, `)})`).join(`,
|
|
31
31
|
`)};\nGO`})}static getFieldLines(e,t){return t.tables[e].fieldIds.map(e=>{let n=t.fields[e],r=``;if(n.enumId){let e=t.enums[n.enumId];r=`[${n.name}] nvarchar(255) NOT NULL CHECK ([${n.name}] IN (`;let i=e.valueIds.map(e=>`'${t.enumValues[e].name}'`);r+=`${i.join(`, `)}))`}else r=`[${n.name}] ${n.type.type_name===`varchar`?`nvarchar(255)`:n.type.type_name}`;if(n.unique&&(r+=` UNIQUE`),n.pk&&(r+=` PRIMARY KEY`),n.not_null&&(r+=` NOT NULL`),n.increment&&(r+=` IDENTITY(1, 1)`),n.checkIds&&n.checkIds.length>0)if(n.checkIds.length===1){let e=t.checks[n.checkIds[0]];e.name&&(r+=` CONSTRAINT [${e.name}]`),r+=` CHECK (${e.expression})`}else{let e=n.checkIds.map(e=>`(${t.checks[e].expression})`);r+=` CHECK (${e.join(` AND `)})`}return n.dbdefault&&(n.dbdefault.type===`boolean`&&(n.dbdefault.value===null||typeof n.dbdefault.value==`string`&&n.dbdefault.value.toLowerCase()===`null`)||(n.dbdefault.type===`expression`?r+=` DEFAULT (${n.dbdefault.value})`:n.dbdefault.type===`string`?r+=` DEFAULT '${n.dbdefault.value}'`:r+=` DEFAULT (${n.dbdefault.value})`)),r})}static getCompositePKs(e,t){let n=t.tables[e];return(n.indexIds?n.indexIds.filter(e=>t.indexes[e].pk):[]).map(e=>{let n=t.indexes[e],r=`PRIMARY KEY`,i=[];return n.columnIds.forEach(e=>{let n=t.indexColumns[e],r=``;r=n.type===`expression`?`(${n.value})`:`[${n.value}]`,i.push(r)}),r+=` (${i.join(`, `)})`,r})}static getCheckLines(e,t){let n=t.tables[e];return!n.checkIds||n.checkIds.length===0?[]:n.checkIds.map(e=>{let n=t.checks[e],r=``;return n.name&&(r=`CONSTRAINT [${n.name}] `),r+=`CHECK (${n.expression})`,r})}static getTableContentArr(t,n){return t.map(t=>({tableId:t,fieldContents:e.getFieldLines(t,n),checkContents:e.getCheckLines(t,n),compositePKs:e.getCompositePKs(t,n)}))}static exportTables(t,n){return e.getTableContentArr(t,n).map(e=>{let t=[...e.fieldContents,...e.checkContents,...e.compositePKs],r=n.tables[e.tableId],i=n.schemas[r.schemaId];return`CREATE TABLE ${mm(i,n)?`[${i.name}].`:``}[${r.name}] (\n${t.map(e=>` ${e}`).join(`,
|
|
32
32
|
`)}\n)\nGO\n`})}static buildTableManyToMany(e,t,n,r,i){let a=`CREATE TABLE ${mm(r,i)?`[${r.name}].`:``}[${n}] (\n`,o=[...e.keys()].join(`], [`),s=[...t.keys()].join(`], [`);return e.forEach((e,t)=>{a+=` [${t}] ${e},\n`}),t.forEach((e,t)=>{a+=` [${t}] ${e},\n`}),a+=` PRIMARY KEY ([${o}], [${s}])\n`,a+=`);
|
|
33
33
|
GO
|
|
@@ -121,4 +121,4 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
121
121
|
`,!1),pt=`
|
|
122
122
|
`,mt=Dt(`
|
|
123
123
|
`,!1),ht=At(`whitespace`),gt=/^[ \t\r\n\r]/,_t=Ot([` `,` `,`\r`,`
|
|
124
|
-
`,`\r`],!1,!1),vt=` `,yt=Dt(` `,!1),S=0,bt=0,xt=[{line:1,column:1}],St=0,Ct=[],wt=0,Tt;if(`startRule`in t){if(!(t.startRule in i))throw Error(`Can't start parsing from rule "`+t.startRule+`".`);a=i[t.startRule]}function Et(e,t){throw t=t===void 0?Mt(bt,S):t,Pt(e,t)}function Dt(e,t){return{type:`literal`,text:e,ignoreCase:t}}function Ot(e,t,n){return{type:`class`,parts:e,inverted:t,ignoreCase:n}}function kt(){return{type:`end`}}function At(e){return{type:`other`,description:e}}function jt(t){var n=xt[t],r;if(n)return n;for(r=t-1;!xt[r];)r--;for(n=xt[r],n={line:n.line,column:n.column};r<t;)e.charCodeAt(r)===10?(n.line++,n.column=1):n.column++,r++;return xt[t]=n,n}function Mt(e,t){var n=jt(e),r=jt(t);return{start:{offset:e,line:n.line,column:n.column},end:{offset:t,line:r.line,column:r.column}}}function Nt(e){S<St||(S>St&&(St=S,Ct=[]),Ct.push(e))}function Pt(e,t){return new r(e,null,null,t)}function Ft(e,t,n){return new r(r.buildMessage(e,t),e,t,n)}function It(){for(var e=S,t=[],r=Lt();r!==n;)t.push(r),r=Lt();return t!==n&&(bt=e,t=o()),e=t,e}function Lt(){for(var e=S,t=[],r=Dn();r!==n;)t.push(r),r=Dn();return t===n?(S=e,e=n):(r=Rt(),r===n?(S=e,e=n):(t=[t,r],e=t)),e===n&&(e=vn(),e===n&&(e=_n(),e===n&&(e=Cn()))),e}function Rt(){var e=S,t=Ht();return t!==n&&(bt=e,t=s(t)),e=t,e===n&&(e=S,t=Bt(),t!==n&&(bt=e,t=c(t)),e=t,e===n&&(e=zt(),e===n&&(e=ln()))),e}function zt(){for(var t=S,r=[],i=On(),a,o,s,c,f,p,m;i!==n;)r.push(i),i=On();if(r!==n)if(i=rn(),i!==n){for(a=[],o=On();o!==n;)a.push(o),o=On();if(a!==n)if(o=pn(),o===n&&(o=un()),o!==n)if(e.charCodeAt(S)===44?(s=l,S++):(s=n,wt===0&&Nt(u)),s!==n){for(c=[],f=On();f!==n;)c.push(f),f=On();if(c!==n)if(f=un(),f!==n){for(p=[],m=Zt();m!==n;)p.push(m),m=Zt();p===n?(S=t,t=n):(bt=t,r=d(o,f,p),t=r)}else S=t,t=n;else S=t,t=n}else S=t,t=n;else S=t,t=n;else S=t,t=n}else S=t,t=n;else S=t,t=n;return t}function Bt(){for(var t=S,r=[],i=On(),a,o,s,c,d,p,m;i!==n;)r.push(i),i=On();if(r!==n)if(i=an(),i!==n){for(a=[],o=On();o!==n;)a.push(o),o=On();if(a!==n)if(o=un(),o!==n)if(e.charCodeAt(S)===44?(s=l,S++):(s=n,wt===0&&Nt(u)),s!==n){for(c=[],d=On();d!==n;)c.push(d),d=On();if(c!==n)if(d=un(),d!==n){for(p=[],m=Vt();m!==n;)p.push(m),m=Vt();p===n?(S=t,t=n):(bt=t,r=f(o,d,p),t=r)}else S=t,t=n;else S=t,t=n}else S=t,t=n;else S=t,t=n;else S=t,t=n}else S=t,t=n;else S=t,t=n;return t}function Vt(){var t=S,r,i,a,o,s,c;if(e.charCodeAt(S)===44?(r=l,S++):(r=n,wt===0&&Nt(u)),r!==n){for(i=[],a=On();a!==n;)i.push(a),a=On();if(i!==n)if(a=on(),a!==n)if(e.charCodeAt(S)===58?(o=p,S++):(o=n,wt===0&&Nt(m)),o!==n){for(s=[],c=On();c!==n;)s.push(c),c=On();s===n?(S=t,t=n):(c=un(),c===n?(S=t,t=n):(bt=t,r=h(c),t=r))}else S=t,t=n;else S=t,t=n;else S=t,t=n}else S=t,t=n;if(t===n){if(t=S,e.charCodeAt(S)===44?(r=l,S++):(r=n,wt===0&&Nt(u)),r!==n){for(i=[],a=On();a!==n;)i.push(a),a=On();if(i!==n)if(a=sn(),a!==n)if(e.charCodeAt(S)===58?(o=p,S++):(o=n,wt===0&&Nt(m)),o!==n){for(s=[],c=On();c!==n;)s.push(c),c=On();s===n?(S=t,t=n):(c=un(),c===n?(S=t,t=n):(bt=t,r=g(c),t=r))}else S=t,t=n;else S=t,t=n;else S=t,t=n}else S=t,t=n;if(t===n)if(t=S,e.charCodeAt(S)===44?(r=l,S++):(r=n,wt===0&&Nt(u)),r!==n){for(i=[],a=On();a!==n;)i.push(a),a=On();if(i!==n)if(a=Qt(),a!==n)if(e.charCodeAt(S)===58?(o=p,S++):(o=n,wt===0&&Nt(m)),o!==n){for(s=[],c=On();c!==n;)s.push(c),c=On();s===n?(S=t,t=n):(c=pn(),c===n?(S=t,t=n):(bt=t,r=_(a,c),t=r))}else S=t,t=n;else S=t,t=n;else S=t,t=n}else S=t,t=n}return t}function Ht(){var e=S,t=$t(),r,i,a,o,s,c;if(t!==n){for(r=[],i=On();i!==n;)r.push(i),i=On();r===n?(S=e,e=n):(i=un(),i===n?(S=e,e=n):(a=yn(),a===n?(S=e,e=n):(o=wn(),o===n?(S=e,e=n):(s=Ut(),s===n?(S=e,e=n):(c=_n(),c===n?(S=e,e=n):(bt=e,t=v(i,s),e=t))))))}else S=e,e=n;return e}function Ut(){for(var e=S,t=[],r=Wt();r!==n;)t.push(r),r=Wt();return t!==n&&(bt=e,t=y(t)),e=t,e}function Wt(){for(var e=S,t=[],r=Dn(),i,a;r!==n;)t.push(r),r=Dn();if(t!==n)if(r=Gt(),r!==n){for(i=[],a=bn();a!==n;)i.push(a),a=bn();i===n?(S=e,e=n):(a=wn(),a===n?(S=e,e=n):(bt=e,t=b(r),e=t))}else S=e,e=n;else S=e,e=n;return e}function Gt(){var e=Kt(),t;return e===n&&(e=S,t=qt(),t!==n&&(bt=e,t=x(t)),e=t,e===n&&(e=S,t=Jt(),t!==n&&(bt=e,t=ee(t)),e=t,e===n&&(e=S,t=Yt(),t!==n&&(bt=e,t=te(t)),e=t))),e}function Kt(){var e=S,t=en(),r,i;if(t!==n){if(r=[],i=On(),i!==n)for(;i!==n;)r.push(i),i=On();else r=n;r===n?(S=e,e=n):(i=yn(),i===n?(S=e,e=n):(t=[t,r,i],e=t))}else S=e,e=n;return e}function qt(){var e=S,t=tn(),r,i;if(t!==n){if(r=[],i=On(),i!==n)for(;i!==n;)r.push(i),i=On();else r=n;r===n?(S=e,e=n):(i=Xt(),i===n?(S=e,e=n):(bt=e,t=ne(i),e=t))}else S=e,e=n;return e}function Jt(){var e=S,t=nn(),r,i,a,o;if(t!==n){if(r=[],i=On(),i!==n)for(;i!==n;)r.push(i),i=On();else r=n;if(r!==n)if(i=un(),i!==n){for(a=[],o=Zt();o!==n;)a.push(o),o=Zt();a===n?(S=e,e=n):(bt=e,t=re(i,a),e=t)}else S=e,e=n;else S=e,e=n}else S=e,e=n;return e}function Yt(){var e=S,t=hn(),r,i;if(t!==n){if(r=[],i=On(),i!==n)for(;i!==n;)r.push(i),i=On();else r=n;r===n?(S=e,e=n):(i=un(),i===n?(S=e,e=n):(bt=e,t=ie(t,i),e=t))}else S=e,e=n;return e}function Xt(){var t=S,r,i;return e.charCodeAt(S)===58?(r=p,S++):(r=n,wt===0&&Nt(m)),r===n?(S=t,t=n):(i=mn(),i===n?(S=t,t=n):(bt=t,r=ae(i),t=r)),t===n&&(t=S,r=un(),r!==n&&(bt=t,r=ae(r)),t=r),t}function Zt(){var t=S,r,i,a,o,s,c;if(e.charCodeAt(S)===44?(r=l,S++):(r=n,wt===0&&Nt(u)),r!==n){for(i=[],a=On();a!==n;)i.push(a),a=On();if(i!==n)if(e.substr(S,4).toLowerCase()===oe?(a=e.substr(S,4),S+=4):(a=n,wt===0&&Nt(se)),a!==n)if(e.charCodeAt(S)===58?(o=p,S++):(o=n,wt===0&&Nt(m)),o!==n){for(s=[],c=On();c!==n;)s.push(c),c=On();s===n?(S=t,t=n):(c=un(),c===n?(S=t,t=n):(bt=t,r=ce(c),t=r))}else S=t,t=n;else S=t,t=n;else S=t,t=n}else S=t,t=n;return t}function Qt(){var t;return e.substr(S,9).toLowerCase()===le?(t=e.substr(S,9),S+=9):(t=n,wt===0&&Nt(ue)),t===n&&(e.substr(S,9).toLowerCase()===de?(t=e.substr(S,9),S+=9):(t=n,wt===0&&Nt(fe))),t}function $t(){var t;return wt++,e.substr(S,12).toLowerCase()===me?(t=e.substr(S,12),S+=12):(t=n,wt===0&&Nt(he)),wt--,t===n&&wt===0&&Nt(pe),t}function en(){var t,r,i;return wt++,t=S,r=gn(),r===n?(S=t,t=n):(e.substr(S,6)===_e?(i=_e,S+=6):(i=n,wt===0&&Nt(ve)),i===n?(S=t,t=n):(r=[r,i],t=r)),wt--,t===n&&(r=n,wt===0&&Nt(ge)),t}function tn(){var t,r,i;return wt++,t=S,r=gn(),r===n?(S=t,t=n):(e.substr(S,11)===be?(i=be,S+=11):(i=n,wt===0&&Nt(xe)),i===n?(S=t,t=n):(r=[r,i],t=r)),wt--,t===n&&(r=n,wt===0&&Nt(ye)),t}function nn(){var t,r,i;return wt++,t=S,r=gn(),r===n?(S=t,t=n):(e.substr(S,17)===Ce?(i=Ce,S+=17):(i=n,wt===0&&Nt(we)),i===n?(S=t,t=n):(r=[r,i],t=r)),wt--,t===n&&(r=n,wt===0&&Nt(Se)),t}function rn(){var t;return wt++,e.substr(S,20).toLowerCase()===Ee?(t=e.substr(S,20),S+=20):(t=n,wt===0&&Nt(De)),wt--,t===n&&wt===0&&Nt(Te),t}function an(){var t;return wt++,e.substr(S,15).toLowerCase()===ke?(t=e.substr(S,15),S+=15):(t=n,wt===0&&Nt(Ae)),wt--,t===n&&wt===0&&Nt(Oe),t}function on(){var t;return wt++,e.substr(S,6)===Me?(t=Me,S+=6):(t=n,wt===0&&Nt(Ne)),wt--,t===n&&wt===0&&Nt(je),t}function sn(){var t;return wt++,e.substr(S,11)===Fe?(t=Fe,S+=11):(t=n,wt===0&&Nt(Ie)),wt--,t===n&&wt===0&&Nt(Pe),t}function cn(){var t;return e.substr(S,3)===Le?(t=Le,S+=3):(t=n,wt===0&&Nt(Re)),t}function ln(){var e=S,t=mn(),r,i;return t===n?(S=e,e=n):(r=yn(),r===n?(S=e,e=n):(i=wn(),i===n&&(i=null),i===n?(S=e,e=n):(t=[t,r,i],e=t))),e}function un(){var e=dn();return e===n&&(e=fn()),e}function dn(){var t=S,r=Sn(),i,a;if(r!==n){for(i=[],ze.test(e.charAt(S))?(a=e.charAt(S),S++):(a=n,wt===0&&Nt(Be));a!==n;)i.push(a),ze.test(e.charAt(S))?(a=e.charAt(S),S++):(a=n,wt===0&&Nt(Be));i===n?(S=t,t=n):(a=Sn(),a===n?(S=t,t=n):(bt=t,r=Ve(i),t=r))}else S=t,t=n;return t}function fn(){var t=S,r=xn(),i,a;if(r!==n){for(i=[],He.test(e.charAt(S))?(a=e.charAt(S),S++):(a=n,wt===0&&Nt(Ue));a!==n;)i.push(a),He.test(e.charAt(S))?(a=e.charAt(S),S++):(a=n,wt===0&&Nt(Ue));i===n?(S=t,t=n):(a=xn(),a===n?(S=t,t=n):(bt=t,r=Ve(i),t=r))}else S=t,t=n;return t}function pn(){var t=S,r,i,a;if(e.charCodeAt(S)===58?(r=p,S++):(r=n,wt===0&&Nt(m)),r!==n){for(i=[],a=gn();a!==n;)i.push(a),a=gn();i===n?(S=t,t=n):(bt=t,r=Ve(i),t=r)}else S=t,t=n;return t}function mn(){var e=S,t=[],r=gn();if(r!==n)for(;r!==n;)t.push(r),r=gn();else t=n;return t!==n&&(bt=e,t=Ve(t)),e=t,e}function hn(){var t=S,r=gn(),i,a,o;if(r!==n)if(e.charCodeAt(S)===46?(i=We,S++):(i=n,wt===0&&Nt(Ge)),i!==n){if(a=[],o=gn(),o!==n)for(;o!==n;)a.push(o),o=gn();else a=n;a===n?(S=t,t=n):(bt=t,r=Ve(a),t=r)}else S=t,t=n;else S=t,t=n;return t}function gn(){var t;return wt++,qe.test(e.charAt(S))?(t=e.charAt(S),S++):(t=n,wt===0&&Nt(Je)),wt--,t===n&&wt===0&&Nt(Ke),t}function _n(){for(var e=S,t=[],r=Dn(),i;r!==n;)t.push(r),r=Dn();return t===n?(S=e,e=n):(r=cn(),r===n?(S=e,e=n):(i=wn(),i===n&&(i=null),i===n?(S=e,e=n):(t=[t,r,i],e=t))),e}function vn(){var t,r,i,a,o;for(wt++,t=S,r=[],i=Dn();i!==n;)r.push(i),i=Dn();return r===n?(S=t,t=n):(e.charCodeAt(S)===35?(i=Xe,S++):(i=n,wt===0&&Nt(Ze)),i===n?(S=t,t=n):(a=yn(),a===n?(S=t,t=n):(o=wn(),o===n&&(o=null),o===n?(S=t,t=n):(r=[r,i,a,o],t=r)))),wt--,t===n&&(r=n,wt===0&&Nt(Ye)),t}function yn(){var t,r;for(wt++,t=[],$e.test(e.charAt(S))?(r=e.charAt(S),S++):(r=n,wt===0&&Nt(et));r!==n;)t.push(r),$e.test(e.charAt(S))?(r=e.charAt(S),S++):(r=n,wt===0&&Nt(et));return wt--,t===n&&(r=n,wt===0&&Nt(Qe)),t}function bn(){var t;return $e.test(e.charAt(S))?(t=e.charAt(S),S++):(t=n,wt===0&&Nt(et)),t}function xn(){var t;return e.charCodeAt(S)===39?(t=tt,S++):(t=n,wt===0&&Nt(nt)),t}function Sn(){var t;return e.charCodeAt(S)===34?(t=rt,S++):(t=n,wt===0&&Nt(it)),t}function Cn(){var e=[],t=Tn();if(t===n&&(t=Dn()),t!==n)for(;t!==n;)e.push(t),t=Tn(),t===n&&(t=Dn());else e=n;return e}function wn(){for(var e=S,t=[],r=On();r!==n;)t.push(r),r=On();return t===n?(S=e,e=n):(r=En(),r===n?(S=e,e=n):(t=[t,r],e=t)),e}function Tn(){var t,r,i;return wt++,t=S,e.substr(S,2)===ot?(r=ot,S+=2):(r=n,wt===0&&Nt(st)),r===n?(S=t,t=n):(ct.test(e.charAt(S))?(i=e.charAt(S),S++):(i=n,wt===0&&Nt(lt)),i===n&&(i=null),i===n?(S=t,t=n):(r=[r,i],t=r)),wt--,t===n&&(r=n,wt===0&&Nt(at)),t}function En(){var t;return wt++,e.substr(S,2)===dt?(t=dt,S+=2):(t=n,wt===0&&Nt(ft)),t===n&&(e.charCodeAt(S)===10?(t=pt,S++):(t=n,wt===0&&Nt(mt))),wt--,t===n&&wt===0&&Nt(ut),t}function Dn(){var t;return wt++,gt.test(e.charAt(S))?(t=e.charAt(S),S++):(t=n,wt===0&&Nt(_t)),wt--,t===n&&wt===0&&Nt(ht),t}function On(){var t;return e.charCodeAt(S)===32?(t=vt,S++):(t=n,wt===0&&Nt(yt)),t}var kn=$7(),An=Q7();let jn={tables:[],refs:[]};function Mn(e){jn.tables.find(t=>t.name==e.name)?Et(`Duplicated table name`):(e.fields.find(e=>e.name===`id`)||e.fields.unshift({name:`id`,type:{type_name:`varchar`}}),jn.tables.push(e))}function Nn(e,t,n){let r=jn.tables.find(t=>t.name===e);r||Et("Table ${tableName} not found"),r.checks||=[];let i={expression:t};n&&(i.name=n),r.checks.push(i)}function Pn(e=[],t=[]){let n=t.find(e=>e.name===`primary_key`);return n?e.find(e=>e.name===n.value)?e.map(({name:e,type:t})=>({name:e,type:t,PK:n.value===field.name})):[{name:n.value,type:{type_name:`varchar`},PK:!0}].concat(e):e}function Fn(e,t){return e.tableName==t.tableName&&An.isEqual(An.sortBy(e.fieldNames),An.sortBy(t.fieldNames))}function In(e,t){return Fn(e[0],t[0])&&Fn(e[1],t[1])}function Ln(e,t){return In(e.endpoints,t.endpoints)||In(e.endpoints,t.endpoints.slice().reverse())}function Rn(e){e&&(jn.refs.find(t=>Ln(t,e))&&Et(`Duplicated references`),jn.refs.push(e))}function zn(e=[]){if(!(!e||e.length===0))for(let t=0;t<e.length;t+=1)Rn(e[t])}function Bn(e){let{tables:t}=jn,{endpoints:n}=e,r=t.find(e=>e.name===n[0].tableName);if(!r||!t.find(e=>e.name===n[1].tableName))return null;if(!n[0].fieldNames){let e=`${kn.singular(n[1].tableName)}_id`;if(n[0].fieldNames=[e],!r.fields.find(t=>t.name===e))return null;n[0].fieldNames=[e]}return n[1].fieldNames||(n[1].fieldNames=[`id`]),e}function Vn(e,t,n){let r=[{tableName:e,relation:`1`},{tableName:t,relation:`1`}],i={};for(let e=0;e<n.length;e+=1){let t=n[e];t.columnName&&(r[0].fieldNames=[t.columnName]),t.primaryKey&&(r[1].fieldNames=[t.primaryKey]),t.onDelete&&(i={...i,onDelete:t.onDelete}),t.onUpdate&&(i={...i,onUpdate:t.onUpdate})}return{name:`fk_rails_${e}_${t}`,endpoints:r,...i}}function Hn(e,t){if(!t||t.length===0)return[];let n=[];for(let r=0;r<t.length;r+=1){let i=t[r],a=kn.plural(i),{tables:o}=jn,s=o.find(e=>e.name===a);if(!s)continue;let c=`${i}_id`,l=e.fields.find(e=>e.name===c),u=s.fields.find(e=>e.name===`id`);l||e.fields.push({name:c,type:{type_name:u?u.type.type_name:`varchar`}}),n.push({name:`fk_rails_${e.name}_${a}`,endpoints:[{tableName:e.name,fieldNames:[c],relation:`1`},{tableName:a,fieldNames:[`id`],relation:`1`}]})}return n}function Un(e){let{tables:t,refs:n}=e,r=t.map(e=>{let{name:t}=e;return{name:t,field:`${kn.singular(t)}_id`}});for(let e=0;e<t.length;e+=1){let i=t[e],{fields:a}=i;for(let e=0;e<a.length;e+=1){let t=a[e],o=r.find(e=>e.field===t.name);if(o){let e={name:`fk_rails_${i.name}_${o.name}`,endpoints:[{tableName:i.name,fieldNames:[t.name],relation:`1`},{tableName:o.name,fieldNames:[`id`],relation:`1`}]};n.find(t=>Ln(t,e))||n.push(e)}}}return e}if(Tt=a(),Tt!==n&&S===e.length)return Tt;throw Tt!==n&&S<e.length&&Nt(kt()),Ft(Ct,St<e.length?e.charAt(St):null,St<e.length?Mt(St,St+1):Mt(St,St))}t.exports={SyntaxError:r,parse:i}})),pRe=u(oPe()),mRe=u(lRe()),hRe=u(uRe()),gRe=u(dRe()),_Re=u(fRe()),vRe=class e{constructor(){this.layout=new f.MemoryProjectLayout,this.DBMLCompiler=new f.Compiler(this.layout)}static parseJSONToDatabase(e){return new xm(e)}static parseMySQLToJSONv2(e){return Z7(e,`mysql`)}static parseMySQLToJSON(e){return hRe.default.parse(e)}static parsePostgresToJSONv2(e){return Z7(e,`postgres`)}static parsePostgresToJSON(e){return gRe.default.parse(e)}static parseDBMLToJSONv2(e){let t=new f.MemoryProjectLayout;t.setSource(f.DEFAULT_ENTRY,e);let n=new f.Compiler(t),r=bRe(n.parse.errors(f.DEFAULT_ENTRY));if(r.length>0)throw W7.create(r);return n.parse.rawDb(f.DEFAULT_ENTRY)}static parseDBMLToJSON(e){return pRe.default.parse(e)}static parseSchemaRbToJSON(e){return _Re.default.parse(e)}static parseMSSQLToJSON(e){return mRe.default.parseWithPegError(e)}static parseMSSQLToJSONv2(e){return Z7(e,`mssql`)}static parseSnowflakeToJSON(e){return Z7(e,`snowflake`)}static parseOracleToJSON(e){return Z7(e,`oracle`)}static parse(t,n){return new e().parse(t,n)}getDbmlSource(e){return e=typeof e==`string`?f.Filepath.from(e):e,this.layout.getSource(e)}setDbmlSource(e,t){e=typeof e==`string`?f.Filepath.from(e):e,t===void 0?this.layout.deleteSource(e):this.layout.setSource(e,t)}deleteDbmlSource(e){e=typeof e==`string`?f.Filepath.from(e):e,this.layout.deleteSource(e)}clearDbmlSource(){this.layout.clearSource()}parseDbmlProject(t){t=typeof t==`string`?f.Filepath.from(t):t;let n=this.DBMLCompiler.interpretFile(t),r=bRe(n.getErrors());if(r.length>0)throw W7.create(r);return e.parseJSONToDatabase(n.getValue()||{})}parse(t,n){try{let r={};switch(n){case`mysql`:r=e.parseMySQLToJSONv2(t);break;case`mysqlLegacy`:r=e.parseMySQLToJSON(t);break;case`postgres`:r=e.parsePostgresToJSONv2(t);break;case`snowflake`:r=e.parseSnowflakeToJSON(t);break;case`postgresLegacy`:r=e.parsePostgresToJSON(t);break;case`dbml`:r=e.parseDBMLToJSON(t);break;case`dbmlv2`:r=e.parseDBMLToJSONv2(t);break;case`schemarb`:r=e.parseSchemaRbToJSON(t);break;case`mssqlLegacy`:r=e.parseMSSQLToJSON(t);break;case`mssql`:r=e.parseMSSQLToJSONv2(t);break;case`oracle`:r=e.parseOracleToJSON(t);break;case`json`:r=typeof t==`object`?t:JSON.parse(t);break;default:break}return e.parseJSONToDatabase(r)}catch(e){throw W7.create(e)}}},yRe=vRe;function bRe(e){return e.map(e=>({message:e.diagnostic,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}))}function xRe(e,t,n={isNormalized:!0,includeRecords:!0}){let r=SRe(n),i=new yRe().parse(e,`dbmlv2`);return $9.export(i.normalize(),t,r)}function SRe(e={}){if(typeof e==`boolean`)return{isNormalized:e,includeRecords:!0};let{isNormalized:t=!0,includeRecords:n=!0}=e;return{isNormalized:t,includeRecords:n}}var CRe={export:xRe},wRe=class{static export(e,t,n={isNormalized:!0,includeRecords:!0}){let{isNormalized:r,includeRecords:i}=SRe(n),a=e instanceof xm?e.normalize():e,o=``;switch(t){case`dbml`:o=Pne.export(a,{includeRecords:i});break;case`mysql`:o=Ine.export(a);break;case`postgres`:o=Vne.export(a);break;case`json`:o=bre.export(e,{isNormalized:r});break;case`mssql`:o=Sre.export(a);break;case`oracle`:o=wre.export(a);break;default:break}return o}},$9=wRe,TRe=e=>new xm(e),ERe=e=>e.map(e=>{let{name:t,endpoints:n,onDelete:r,onUpdate:i}=e;return new RNe({name:t,endpoints:n.map(e=>new M7(e)),onDelete:r,onUpdate:i}).toJSON()}),DRe=e=>e.map(e=>{let{name:t,schemaName:n,values:r}=e;return new N7({name:t,schemaName:n,values:r})}),ORe=(e,t)=>e.map(e=>{let n=t[e.name]||{};return new A7({name:e.name,type:e.type,dbdefault:e.dbdefault,not_null:e.not_null,increment:e.increment,pk:n.pk||e.pk,unique:n.unique||e.unique,note:e.note,checks:n.checks})}),kRe=e=>e.map(e=>{let{name:t,unique:n,pk:r,type:i,columns:a}=e;return new k7({name:t,unique:n,pk:r,type:i,columns:a})}),ARe=(e,t,n,r,i)=>e.map(e=>{let{name:a,schemaName:o,note:s}=e,c=o?`${o}.${a}`:`${a}`,l=i[c]||{};return new j7({name:a,schemaName:o,fields:ORe(t[c],l),indexes:kRe(n[c]||[]),note:s,checks:r[c]})}),jRe=e=>{let{tables:t,fields:n,indexes:r,refs:i,enums:a,tableConstraints:o,checks:s}=e;try{let e=ARe(t,n,r,s,o),c=DRe(a);return TRe({schemas:[],tables:e,refs:ERe(i),enums:c,tableGroups:[],aliases:[],project:{}})}catch(e){throw Error(e)}};function MRe(e,t,n={includeRecords:!0}){let{includeRecords:r=!0}=n,i=new yRe().parse(e,t);return $9.export(i.normalize(),`dbml`,{includeRecords:r})}function NRe(e){let t=jRe(e);return $9.export(t.normalize(),`dbml`)}var PRe={import:MRe,generateDbml:NRe};function FRe(e,t,n){let r=new f.MemoryProjectLayout;return r.setSource(f.DEFAULT_ENTRY,n),new f.Compiler(r).renameTable(f.DEFAULT_ENTRY,e,t).get(f.DEFAULT_ENTRY.absolute)??n}function IRe(e,t,n){let r=new f.MemoryProjectLayout;return r.setSource(f.DEFAULT_ENTRY,e),new f.Compiler(r).syncDiagramView(f.DEFAULT_ENTRY,t,n)}function LRe(e){let t=new f.MemoryProjectLayout;return t.setSource(f.DEFAULT_ENTRY,e),new f.Compiler(t).findDiagramViewBlocks(f.DEFAULT_ENTRY)}const RRe=`8.2.4`,zRe=`8.2.4`;exports.CompilerError=W7,Object.defineProperty(exports,`DEFAULT_ENTRY`,{enumerable:!0,get:function(){return f.DEFAULT_ENTRY}}),Object.defineProperty(exports,`Filepath`,{enumerable:!0,get:function(){return f.Filepath}}),exports.ModelExporter=$9,exports.Parser=yRe,exports.VERSION=`8.2.4`,Object.defineProperty(exports,`addDoubleQuoteIfNeeded`,{enumerable:!0,get:function(){return f.addDoubleQuoteIfNeeded}}),Object.defineProperty(exports,`dbmlMonarchTokensProvider`,{enumerable:!0,get:function(){return f.dbmlMonarchTokensProvider}}),exports.exporter=CRe,exports.findDiagramViewBlocks=LRe,Object.defineProperty(exports,`formatRecordValue`,{enumerable:!0,get:function(){return f.formatRecordValue}}),exports.importer=PRe,Object.defineProperty(exports,`isBinaryType`,{enumerable:!0,get:function(){return f.isBinaryType}}),Object.defineProperty(exports,`isBooleanType`,{enumerable:!0,get:function(){return f.isBooleanType}}),Object.defineProperty(exports,`isDateTimeType`,{enumerable:!0,get:function(){return f.isDateTimeType}}),Object.defineProperty(exports,`isFloatType`,{enumerable:!0,get:function(){return f.isFloatType}}),Object.defineProperty(exports,`isIntegerType`,{enumerable:!0,get:function(){return f.isIntegerType}}),Object.defineProperty(exports,`isNumericType`,{enumerable:!0,get:function(){return f.isNumericType}}),Object.defineProperty(exports,`isSerialType`,{enumerable:!0,get:function(){return f.isSerialType}}),Object.defineProperty(exports,`isStringType`,{enumerable:!0,get:function(){return f.isStringType}}),exports.renameTable=FRe,exports.syncDiagramView=IRe,Object.defineProperty(exports,`tryExtractBoolean`,{enumerable:!0,get:function(){return f.tryExtractBoolean}}),Object.defineProperty(exports,`tryExtractDateTime`,{enumerable:!0,get:function(){return f.tryExtractDateTime}}),Object.defineProperty(exports,`tryExtractEnum`,{enumerable:!0,get:function(){return f.tryExtractEnum}}),Object.defineProperty(exports,`tryExtractInteger`,{enumerable:!0,get:function(){return f.tryExtractInteger}}),Object.defineProperty(exports,`tryExtractNumeric`,{enumerable:!0,get:function(){return f.tryExtractNumeric}}),Object.defineProperty(exports,`tryExtractString`,{enumerable:!0,get:function(){return f.tryExtractString}});
|
|
124
|
+
`,`\r`],!1,!1),vt=` `,yt=Dt(` `,!1),S=0,bt=0,xt=[{line:1,column:1}],St=0,Ct=[],wt=0,Tt;if(`startRule`in t){if(!(t.startRule in i))throw Error(`Can't start parsing from rule "`+t.startRule+`".`);a=i[t.startRule]}function Et(e,t){throw t=t===void 0?Mt(bt,S):t,Pt(e,t)}function Dt(e,t){return{type:`literal`,text:e,ignoreCase:t}}function Ot(e,t,n){return{type:`class`,parts:e,inverted:t,ignoreCase:n}}function kt(){return{type:`end`}}function At(e){return{type:`other`,description:e}}function jt(t){var n=xt[t],r;if(n)return n;for(r=t-1;!xt[r];)r--;for(n=xt[r],n={line:n.line,column:n.column};r<t;)e.charCodeAt(r)===10?(n.line++,n.column=1):n.column++,r++;return xt[t]=n,n}function Mt(e,t){var n=jt(e),r=jt(t);return{start:{offset:e,line:n.line,column:n.column},end:{offset:t,line:r.line,column:r.column}}}function Nt(e){S<St||(S>St&&(St=S,Ct=[]),Ct.push(e))}function Pt(e,t){return new r(e,null,null,t)}function Ft(e,t,n){return new r(r.buildMessage(e,t),e,t,n)}function It(){for(var e=S,t=[],r=Lt();r!==n;)t.push(r),r=Lt();return t!==n&&(bt=e,t=o()),e=t,e}function Lt(){for(var e=S,t=[],r=Dn();r!==n;)t.push(r),r=Dn();return t===n?(S=e,e=n):(r=Rt(),r===n?(S=e,e=n):(t=[t,r],e=t)),e===n&&(e=vn(),e===n&&(e=_n(),e===n&&(e=Cn()))),e}function Rt(){var e=S,t=Ht();return t!==n&&(bt=e,t=s(t)),e=t,e===n&&(e=S,t=Bt(),t!==n&&(bt=e,t=c(t)),e=t,e===n&&(e=zt(),e===n&&(e=ln()))),e}function zt(){for(var t=S,r=[],i=On(),a,o,s,c,f,p,m;i!==n;)r.push(i),i=On();if(r!==n)if(i=rn(),i!==n){for(a=[],o=On();o!==n;)a.push(o),o=On();if(a!==n)if(o=pn(),o===n&&(o=un()),o!==n)if(e.charCodeAt(S)===44?(s=l,S++):(s=n,wt===0&&Nt(u)),s!==n){for(c=[],f=On();f!==n;)c.push(f),f=On();if(c!==n)if(f=un(),f!==n){for(p=[],m=Zt();m!==n;)p.push(m),m=Zt();p===n?(S=t,t=n):(bt=t,r=d(o,f,p),t=r)}else S=t,t=n;else S=t,t=n}else S=t,t=n;else S=t,t=n;else S=t,t=n}else S=t,t=n;else S=t,t=n;return t}function Bt(){for(var t=S,r=[],i=On(),a,o,s,c,d,p,m;i!==n;)r.push(i),i=On();if(r!==n)if(i=an(),i!==n){for(a=[],o=On();o!==n;)a.push(o),o=On();if(a!==n)if(o=un(),o!==n)if(e.charCodeAt(S)===44?(s=l,S++):(s=n,wt===0&&Nt(u)),s!==n){for(c=[],d=On();d!==n;)c.push(d),d=On();if(c!==n)if(d=un(),d!==n){for(p=[],m=Vt();m!==n;)p.push(m),m=Vt();p===n?(S=t,t=n):(bt=t,r=f(o,d,p),t=r)}else S=t,t=n;else S=t,t=n}else S=t,t=n;else S=t,t=n;else S=t,t=n}else S=t,t=n;else S=t,t=n;return t}function Vt(){var t=S,r,i,a,o,s,c;if(e.charCodeAt(S)===44?(r=l,S++):(r=n,wt===0&&Nt(u)),r!==n){for(i=[],a=On();a!==n;)i.push(a),a=On();if(i!==n)if(a=on(),a!==n)if(e.charCodeAt(S)===58?(o=p,S++):(o=n,wt===0&&Nt(m)),o!==n){for(s=[],c=On();c!==n;)s.push(c),c=On();s===n?(S=t,t=n):(c=un(),c===n?(S=t,t=n):(bt=t,r=h(c),t=r))}else S=t,t=n;else S=t,t=n;else S=t,t=n}else S=t,t=n;if(t===n){if(t=S,e.charCodeAt(S)===44?(r=l,S++):(r=n,wt===0&&Nt(u)),r!==n){for(i=[],a=On();a!==n;)i.push(a),a=On();if(i!==n)if(a=sn(),a!==n)if(e.charCodeAt(S)===58?(o=p,S++):(o=n,wt===0&&Nt(m)),o!==n){for(s=[],c=On();c!==n;)s.push(c),c=On();s===n?(S=t,t=n):(c=un(),c===n?(S=t,t=n):(bt=t,r=g(c),t=r))}else S=t,t=n;else S=t,t=n;else S=t,t=n}else S=t,t=n;if(t===n)if(t=S,e.charCodeAt(S)===44?(r=l,S++):(r=n,wt===0&&Nt(u)),r!==n){for(i=[],a=On();a!==n;)i.push(a),a=On();if(i!==n)if(a=Qt(),a!==n)if(e.charCodeAt(S)===58?(o=p,S++):(o=n,wt===0&&Nt(m)),o!==n){for(s=[],c=On();c!==n;)s.push(c),c=On();s===n?(S=t,t=n):(c=pn(),c===n?(S=t,t=n):(bt=t,r=_(a,c),t=r))}else S=t,t=n;else S=t,t=n;else S=t,t=n}else S=t,t=n}return t}function Ht(){var e=S,t=$t(),r,i,a,o,s,c;if(t!==n){for(r=[],i=On();i!==n;)r.push(i),i=On();r===n?(S=e,e=n):(i=un(),i===n?(S=e,e=n):(a=yn(),a===n?(S=e,e=n):(o=wn(),o===n?(S=e,e=n):(s=Ut(),s===n?(S=e,e=n):(c=_n(),c===n?(S=e,e=n):(bt=e,t=v(i,s),e=t))))))}else S=e,e=n;return e}function Ut(){for(var e=S,t=[],r=Wt();r!==n;)t.push(r),r=Wt();return t!==n&&(bt=e,t=y(t)),e=t,e}function Wt(){for(var e=S,t=[],r=Dn(),i,a;r!==n;)t.push(r),r=Dn();if(t!==n)if(r=Gt(),r!==n){for(i=[],a=bn();a!==n;)i.push(a),a=bn();i===n?(S=e,e=n):(a=wn(),a===n?(S=e,e=n):(bt=e,t=b(r),e=t))}else S=e,e=n;else S=e,e=n;return e}function Gt(){var e=Kt(),t;return e===n&&(e=S,t=qt(),t!==n&&(bt=e,t=x(t)),e=t,e===n&&(e=S,t=Jt(),t!==n&&(bt=e,t=ee(t)),e=t,e===n&&(e=S,t=Yt(),t!==n&&(bt=e,t=te(t)),e=t))),e}function Kt(){var e=S,t=en(),r,i;if(t!==n){if(r=[],i=On(),i!==n)for(;i!==n;)r.push(i),i=On();else r=n;r===n?(S=e,e=n):(i=yn(),i===n?(S=e,e=n):(t=[t,r,i],e=t))}else S=e,e=n;return e}function qt(){var e=S,t=tn(),r,i;if(t!==n){if(r=[],i=On(),i!==n)for(;i!==n;)r.push(i),i=On();else r=n;r===n?(S=e,e=n):(i=Xt(),i===n?(S=e,e=n):(bt=e,t=ne(i),e=t))}else S=e,e=n;return e}function Jt(){var e=S,t=nn(),r,i,a,o;if(t!==n){if(r=[],i=On(),i!==n)for(;i!==n;)r.push(i),i=On();else r=n;if(r!==n)if(i=un(),i!==n){for(a=[],o=Zt();o!==n;)a.push(o),o=Zt();a===n?(S=e,e=n):(bt=e,t=re(i,a),e=t)}else S=e,e=n;else S=e,e=n}else S=e,e=n;return e}function Yt(){var e=S,t=hn(),r,i;if(t!==n){if(r=[],i=On(),i!==n)for(;i!==n;)r.push(i),i=On();else r=n;r===n?(S=e,e=n):(i=un(),i===n?(S=e,e=n):(bt=e,t=ie(t,i),e=t))}else S=e,e=n;return e}function Xt(){var t=S,r,i;return e.charCodeAt(S)===58?(r=p,S++):(r=n,wt===0&&Nt(m)),r===n?(S=t,t=n):(i=mn(),i===n?(S=t,t=n):(bt=t,r=ae(i),t=r)),t===n&&(t=S,r=un(),r!==n&&(bt=t,r=ae(r)),t=r),t}function Zt(){var t=S,r,i,a,o,s,c;if(e.charCodeAt(S)===44?(r=l,S++):(r=n,wt===0&&Nt(u)),r!==n){for(i=[],a=On();a!==n;)i.push(a),a=On();if(i!==n)if(e.substr(S,4).toLowerCase()===oe?(a=e.substr(S,4),S+=4):(a=n,wt===0&&Nt(se)),a!==n)if(e.charCodeAt(S)===58?(o=p,S++):(o=n,wt===0&&Nt(m)),o!==n){for(s=[],c=On();c!==n;)s.push(c),c=On();s===n?(S=t,t=n):(c=un(),c===n?(S=t,t=n):(bt=t,r=ce(c),t=r))}else S=t,t=n;else S=t,t=n;else S=t,t=n}else S=t,t=n;return t}function Qt(){var t;return e.substr(S,9).toLowerCase()===le?(t=e.substr(S,9),S+=9):(t=n,wt===0&&Nt(ue)),t===n&&(e.substr(S,9).toLowerCase()===de?(t=e.substr(S,9),S+=9):(t=n,wt===0&&Nt(fe))),t}function $t(){var t;return wt++,e.substr(S,12).toLowerCase()===me?(t=e.substr(S,12),S+=12):(t=n,wt===0&&Nt(he)),wt--,t===n&&wt===0&&Nt(pe),t}function en(){var t,r,i;return wt++,t=S,r=gn(),r===n?(S=t,t=n):(e.substr(S,6)===_e?(i=_e,S+=6):(i=n,wt===0&&Nt(ve)),i===n?(S=t,t=n):(r=[r,i],t=r)),wt--,t===n&&(r=n,wt===0&&Nt(ge)),t}function tn(){var t,r,i;return wt++,t=S,r=gn(),r===n?(S=t,t=n):(e.substr(S,11)===be?(i=be,S+=11):(i=n,wt===0&&Nt(xe)),i===n?(S=t,t=n):(r=[r,i],t=r)),wt--,t===n&&(r=n,wt===0&&Nt(ye)),t}function nn(){var t,r,i;return wt++,t=S,r=gn(),r===n?(S=t,t=n):(e.substr(S,17)===Ce?(i=Ce,S+=17):(i=n,wt===0&&Nt(we)),i===n?(S=t,t=n):(r=[r,i],t=r)),wt--,t===n&&(r=n,wt===0&&Nt(Se)),t}function rn(){var t;return wt++,e.substr(S,20).toLowerCase()===Ee?(t=e.substr(S,20),S+=20):(t=n,wt===0&&Nt(De)),wt--,t===n&&wt===0&&Nt(Te),t}function an(){var t;return wt++,e.substr(S,15).toLowerCase()===ke?(t=e.substr(S,15),S+=15):(t=n,wt===0&&Nt(Ae)),wt--,t===n&&wt===0&&Nt(Oe),t}function on(){var t;return wt++,e.substr(S,6)===Me?(t=Me,S+=6):(t=n,wt===0&&Nt(Ne)),wt--,t===n&&wt===0&&Nt(je),t}function sn(){var t;return wt++,e.substr(S,11)===Fe?(t=Fe,S+=11):(t=n,wt===0&&Nt(Ie)),wt--,t===n&&wt===0&&Nt(Pe),t}function cn(){var t;return e.substr(S,3)===Le?(t=Le,S+=3):(t=n,wt===0&&Nt(Re)),t}function ln(){var e=S,t=mn(),r,i;return t===n?(S=e,e=n):(r=yn(),r===n?(S=e,e=n):(i=wn(),i===n&&(i=null),i===n?(S=e,e=n):(t=[t,r,i],e=t))),e}function un(){var e=dn();return e===n&&(e=fn()),e}function dn(){var t=S,r=Sn(),i,a;if(r!==n){for(i=[],ze.test(e.charAt(S))?(a=e.charAt(S),S++):(a=n,wt===0&&Nt(Be));a!==n;)i.push(a),ze.test(e.charAt(S))?(a=e.charAt(S),S++):(a=n,wt===0&&Nt(Be));i===n?(S=t,t=n):(a=Sn(),a===n?(S=t,t=n):(bt=t,r=Ve(i),t=r))}else S=t,t=n;return t}function fn(){var t=S,r=xn(),i,a;if(r!==n){for(i=[],He.test(e.charAt(S))?(a=e.charAt(S),S++):(a=n,wt===0&&Nt(Ue));a!==n;)i.push(a),He.test(e.charAt(S))?(a=e.charAt(S),S++):(a=n,wt===0&&Nt(Ue));i===n?(S=t,t=n):(a=xn(),a===n?(S=t,t=n):(bt=t,r=Ve(i),t=r))}else S=t,t=n;return t}function pn(){var t=S,r,i,a;if(e.charCodeAt(S)===58?(r=p,S++):(r=n,wt===0&&Nt(m)),r!==n){for(i=[],a=gn();a!==n;)i.push(a),a=gn();i===n?(S=t,t=n):(bt=t,r=Ve(i),t=r)}else S=t,t=n;return t}function mn(){var e=S,t=[],r=gn();if(r!==n)for(;r!==n;)t.push(r),r=gn();else t=n;return t!==n&&(bt=e,t=Ve(t)),e=t,e}function hn(){var t=S,r=gn(),i,a,o;if(r!==n)if(e.charCodeAt(S)===46?(i=We,S++):(i=n,wt===0&&Nt(Ge)),i!==n){if(a=[],o=gn(),o!==n)for(;o!==n;)a.push(o),o=gn();else a=n;a===n?(S=t,t=n):(bt=t,r=Ve(a),t=r)}else S=t,t=n;else S=t,t=n;return t}function gn(){var t;return wt++,qe.test(e.charAt(S))?(t=e.charAt(S),S++):(t=n,wt===0&&Nt(Je)),wt--,t===n&&wt===0&&Nt(Ke),t}function _n(){for(var e=S,t=[],r=Dn(),i;r!==n;)t.push(r),r=Dn();return t===n?(S=e,e=n):(r=cn(),r===n?(S=e,e=n):(i=wn(),i===n&&(i=null),i===n?(S=e,e=n):(t=[t,r,i],e=t))),e}function vn(){var t,r,i,a,o;for(wt++,t=S,r=[],i=Dn();i!==n;)r.push(i),i=Dn();return r===n?(S=t,t=n):(e.charCodeAt(S)===35?(i=Xe,S++):(i=n,wt===0&&Nt(Ze)),i===n?(S=t,t=n):(a=yn(),a===n?(S=t,t=n):(o=wn(),o===n&&(o=null),o===n?(S=t,t=n):(r=[r,i,a,o],t=r)))),wt--,t===n&&(r=n,wt===0&&Nt(Ye)),t}function yn(){var t,r;for(wt++,t=[],$e.test(e.charAt(S))?(r=e.charAt(S),S++):(r=n,wt===0&&Nt(et));r!==n;)t.push(r),$e.test(e.charAt(S))?(r=e.charAt(S),S++):(r=n,wt===0&&Nt(et));return wt--,t===n&&(r=n,wt===0&&Nt(Qe)),t}function bn(){var t;return $e.test(e.charAt(S))?(t=e.charAt(S),S++):(t=n,wt===0&&Nt(et)),t}function xn(){var t;return e.charCodeAt(S)===39?(t=tt,S++):(t=n,wt===0&&Nt(nt)),t}function Sn(){var t;return e.charCodeAt(S)===34?(t=rt,S++):(t=n,wt===0&&Nt(it)),t}function Cn(){var e=[],t=Tn();if(t===n&&(t=Dn()),t!==n)for(;t!==n;)e.push(t),t=Tn(),t===n&&(t=Dn());else e=n;return e}function wn(){for(var e=S,t=[],r=On();r!==n;)t.push(r),r=On();return t===n?(S=e,e=n):(r=En(),r===n?(S=e,e=n):(t=[t,r],e=t)),e}function Tn(){var t,r,i;return wt++,t=S,e.substr(S,2)===ot?(r=ot,S+=2):(r=n,wt===0&&Nt(st)),r===n?(S=t,t=n):(ct.test(e.charAt(S))?(i=e.charAt(S),S++):(i=n,wt===0&&Nt(lt)),i===n&&(i=null),i===n?(S=t,t=n):(r=[r,i],t=r)),wt--,t===n&&(r=n,wt===0&&Nt(at)),t}function En(){var t;return wt++,e.substr(S,2)===dt?(t=dt,S+=2):(t=n,wt===0&&Nt(ft)),t===n&&(e.charCodeAt(S)===10?(t=pt,S++):(t=n,wt===0&&Nt(mt))),wt--,t===n&&wt===0&&Nt(ut),t}function Dn(){var t;return wt++,gt.test(e.charAt(S))?(t=e.charAt(S),S++):(t=n,wt===0&&Nt(_t)),wt--,t===n&&wt===0&&Nt(ht),t}function On(){var t;return e.charCodeAt(S)===32?(t=vt,S++):(t=n,wt===0&&Nt(yt)),t}var kn=$7(),An=Q7();let jn={tables:[],refs:[]};function Mn(e){jn.tables.find(t=>t.name==e.name)?Et(`Duplicated table name`):(e.fields.find(e=>e.name===`id`)||e.fields.unshift({name:`id`,type:{type_name:`varchar`}}),jn.tables.push(e))}function Nn(e,t,n){let r=jn.tables.find(t=>t.name===e);r||Et("Table ${tableName} not found"),r.checks||=[];let i={expression:t};n&&(i.name=n),r.checks.push(i)}function Pn(e=[],t=[]){let n=t.find(e=>e.name===`primary_key`);return n?e.find(e=>e.name===n.value)?e.map(({name:e,type:t})=>({name:e,type:t,PK:n.value===field.name})):[{name:n.value,type:{type_name:`varchar`},PK:!0}].concat(e):e}function Fn(e,t){return e.tableName==t.tableName&&An.isEqual(An.sortBy(e.fieldNames),An.sortBy(t.fieldNames))}function In(e,t){return Fn(e[0],t[0])&&Fn(e[1],t[1])}function Ln(e,t){return In(e.endpoints,t.endpoints)||In(e.endpoints,t.endpoints.slice().reverse())}function Rn(e){e&&(jn.refs.find(t=>Ln(t,e))&&Et(`Duplicated references`),jn.refs.push(e))}function zn(e=[]){if(!(!e||e.length===0))for(let t=0;t<e.length;t+=1)Rn(e[t])}function Bn(e){let{tables:t}=jn,{endpoints:n}=e,r=t.find(e=>e.name===n[0].tableName);if(!r||!t.find(e=>e.name===n[1].tableName))return null;if(!n[0].fieldNames){let e=`${kn.singular(n[1].tableName)}_id`;if(n[0].fieldNames=[e],!r.fields.find(t=>t.name===e))return null;n[0].fieldNames=[e]}return n[1].fieldNames||(n[1].fieldNames=[`id`]),e}function Vn(e,t,n){let r=[{tableName:e,relation:`1`},{tableName:t,relation:`1`}],i={};for(let e=0;e<n.length;e+=1){let t=n[e];t.columnName&&(r[0].fieldNames=[t.columnName]),t.primaryKey&&(r[1].fieldNames=[t.primaryKey]),t.onDelete&&(i={...i,onDelete:t.onDelete}),t.onUpdate&&(i={...i,onUpdate:t.onUpdate})}return{name:`fk_rails_${e}_${t}`,endpoints:r,...i}}function Hn(e,t){if(!t||t.length===0)return[];let n=[];for(let r=0;r<t.length;r+=1){let i=t[r],a=kn.plural(i),{tables:o}=jn,s=o.find(e=>e.name===a);if(!s)continue;let c=`${i}_id`,l=e.fields.find(e=>e.name===c),u=s.fields.find(e=>e.name===`id`);l||e.fields.push({name:c,type:{type_name:u?u.type.type_name:`varchar`}}),n.push({name:`fk_rails_${e.name}_${a}`,endpoints:[{tableName:e.name,fieldNames:[c],relation:`1`},{tableName:a,fieldNames:[`id`],relation:`1`}]})}return n}function Un(e){let{tables:t,refs:n}=e,r=t.map(e=>{let{name:t}=e;return{name:t,field:`${kn.singular(t)}_id`}});for(let e=0;e<t.length;e+=1){let i=t[e],{fields:a}=i;for(let e=0;e<a.length;e+=1){let t=a[e],o=r.find(e=>e.field===t.name);if(o){let e={name:`fk_rails_${i.name}_${o.name}`,endpoints:[{tableName:i.name,fieldNames:[t.name],relation:`1`},{tableName:o.name,fieldNames:[`id`],relation:`1`}]};n.find(t=>Ln(t,e))||n.push(e)}}}return e}if(Tt=a(),Tt!==n&&S===e.length)return Tt;throw Tt!==n&&S<e.length&&Nt(kt()),Ft(Ct,St<e.length?e.charAt(St):null,St<e.length?Mt(St,St+1):Mt(St,St))}t.exports={SyntaxError:r,parse:i}})),pRe=u(oPe()),mRe=u(lRe()),hRe=u(uRe()),gRe=u(dRe()),_Re=u(fRe()),vRe=class e{constructor(){this.layout=new f.MemoryProjectLayout,this.DBMLCompiler=new f.Compiler(this.layout)}static parseJSONToDatabase(e){return new xm(e)}static parseMySQLToJSONv2(e){return Z7(e,`mysql`)}static parseMySQLToJSON(e){return hRe.default.parse(e)}static parsePostgresToJSONv2(e){return Z7(e,`postgres`)}static parsePostgresToJSON(e){return gRe.default.parse(e)}static parseDBMLToJSONv2(e){let t=new f.MemoryProjectLayout;t.setSource(f.DEFAULT_ENTRY,e);let n=new f.Compiler(t),r=bRe(n.parse.errors(f.DEFAULT_ENTRY));if(r.length>0)throw W7.create(r);return n.parse.rawDb(f.DEFAULT_ENTRY)}static parseDBMLToJSON(e){return pRe.default.parse(e)}static parseSchemaRbToJSON(e){return _Re.default.parse(e)}static parseMSSQLToJSON(e){return mRe.default.parseWithPegError(e)}static parseMSSQLToJSONv2(e){return Z7(e,`mssql`)}static parseSnowflakeToJSON(e){return Z7(e,`snowflake`)}static parseOracleToJSON(e){return Z7(e,`oracle`)}static parse(t,n){return new e().parse(t,n)}getDbmlSource(e){return e=typeof e==`string`?f.Filepath.from(e):e,this.layout.getSource(e)}setDbmlSource(e,t){e=typeof e==`string`?f.Filepath.from(e):e,t===void 0?this.layout.deleteSource(e):this.layout.setSource(e,t)}deleteDbmlSource(e){e=typeof e==`string`?f.Filepath.from(e):e,this.layout.deleteSource(e)}clearDbmlSource(){this.layout.clearSource()}parseDbmlProject(t){t=typeof t==`string`?f.Filepath.from(t):t;let n=this.DBMLCompiler.interpretFile(t),r=bRe(n.getErrors());if(r.length>0)throw W7.create(r);return e.parseJSONToDatabase(n.getValue()||{})}parse(t,n){try{let r={};switch(n){case`mysql`:r=e.parseMySQLToJSONv2(t);break;case`mysqlLegacy`:r=e.parseMySQLToJSON(t);break;case`postgres`:r=e.parsePostgresToJSONv2(t);break;case`snowflake`:r=e.parseSnowflakeToJSON(t);break;case`postgresLegacy`:r=e.parsePostgresToJSON(t);break;case`dbml`:r=e.parseDBMLToJSON(t);break;case`dbmlv2`:r=e.parseDBMLToJSONv2(t);break;case`schemarb`:r=e.parseSchemaRbToJSON(t);break;case`mssqlLegacy`:r=e.parseMSSQLToJSON(t);break;case`mssql`:r=e.parseMSSQLToJSONv2(t);break;case`oracle`:r=e.parseOracleToJSON(t);break;case`json`:r=typeof t==`object`?t:JSON.parse(t);break;default:break}return e.parseJSONToDatabase(r)}catch(e){throw W7.create(e)}}},yRe=vRe;function bRe(e){return e.map(e=>({message:e.diagnostic,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}))}function xRe(e,t,n={isNormalized:!0,includeRecords:!0}){let r=SRe(n),i=new yRe().parse(e,`dbmlv2`);return $9.export(i.normalize(),t,r)}function SRe(e={}){if(typeof e==`boolean`)return{isNormalized:e,includeRecords:!0};let{isNormalized:t=!0,includeRecords:n=!0}=e;return{isNormalized:t,includeRecords:n}}var CRe={export:xRe},wRe=class{static export(e,t,n={isNormalized:!0,includeRecords:!0}){let{isNormalized:r,includeRecords:i}=SRe(n),a=e instanceof xm?e.normalize():e,o=``;switch(t){case`dbml`:o=Pne.export(a,{includeRecords:i});break;case`mysql`:o=Ine.export(a);break;case`postgres`:o=Vne.export(a);break;case`json`:o=bre.export(e,{isNormalized:r});break;case`mssql`:o=Sre.export(a);break;case`oracle`:o=wre.export(a);break;default:break}return o}},$9=wRe,TRe=e=>new xm(e),ERe=e=>e.map(e=>{let{name:t,endpoints:n,onDelete:r,onUpdate:i}=e;return new RNe({name:t,endpoints:n.map(e=>new M7(e)),onDelete:r,onUpdate:i}).toJSON()}),DRe=e=>e.map(e=>{let{name:t,schemaName:n,values:r}=e;return new N7({name:t,schemaName:n,values:r})}),ORe=(e,t)=>e.map(e=>{let n=t[e.name]||{};return new A7({name:e.name,type:e.type,dbdefault:e.dbdefault,not_null:e.not_null,increment:e.increment,pk:n.pk||e.pk,unique:n.unique||e.unique,note:e.note,checks:n.checks})}),kRe=e=>e.map(e=>{let{name:t,unique:n,pk:r,type:i,columns:a}=e;return new k7({name:t,unique:n,pk:r,type:i,columns:a})}),ARe=(e,t,n,r,i)=>e.map(e=>{let{name:a,schemaName:o,note:s}=e,c=o?`${o}.${a}`:`${a}`,l=i[c]||{};return new j7({name:a,schemaName:o,fields:ORe(t[c],l),indexes:kRe(n[c]||[]),note:s,checks:r[c]})}),jRe=e=>{let{tables:t,fields:n,indexes:r,refs:i,enums:a,tableConstraints:o,checks:s}=e;try{let e=ARe(t,n,r,s,o),c=DRe(a);return TRe({schemas:[],tables:e,refs:ERe(i),enums:c,tableGroups:[],aliases:[],project:{}})}catch(e){throw Error(e)}};function MRe(e,t,n={includeRecords:!0}){let{includeRecords:r=!0}=n,i=new yRe().parse(e,t);return $9.export(i.normalize(),`dbml`,{includeRecords:r})}function NRe(e){let t=jRe(e);return $9.export(t.normalize(),`dbml`)}var PRe={import:MRe,generateDbml:NRe};function FRe(e,t,n){let r=new f.MemoryProjectLayout;return r.setSource(f.DEFAULT_ENTRY,n),new f.Compiler(r).renameTable(f.DEFAULT_ENTRY,e,t).get(f.DEFAULT_ENTRY.absolute)??n}function IRe(e,t,n){let r=new f.MemoryProjectLayout;return r.setSource(f.DEFAULT_ENTRY,e),new f.Compiler(r).syncDiagramView(f.DEFAULT_ENTRY,t,n)}function LRe(e){let t=new f.MemoryProjectLayout;return t.setSource(f.DEFAULT_ENTRY,e),new f.Compiler(t).findDiagramViewBlocks(f.DEFAULT_ENTRY)}const RRe=`8.3.0-alpha.0`,zRe=`8.3.0-alpha.0`;exports.CompilerError=W7,Object.defineProperty(exports,`DEFAULT_ENTRY`,{enumerable:!0,get:function(){return f.DEFAULT_ENTRY}}),Object.defineProperty(exports,`Filepath`,{enumerable:!0,get:function(){return f.Filepath}}),exports.ModelExporter=$9,exports.Parser=yRe,exports.VERSION=`8.3.0-alpha.0`,Object.defineProperty(exports,`addDoubleQuoteIfNeeded`,{enumerable:!0,get:function(){return f.addDoubleQuoteIfNeeded}}),Object.defineProperty(exports,`dbmlMonarchTokensProvider`,{enumerable:!0,get:function(){return f.dbmlMonarchTokensProvider}}),exports.exporter=CRe,exports.findDiagramViewBlocks=LRe,Object.defineProperty(exports,`formatRecordValue`,{enumerable:!0,get:function(){return f.formatRecordValue}}),exports.importer=PRe,Object.defineProperty(exports,`isBinaryType`,{enumerable:!0,get:function(){return f.isBinaryType}}),Object.defineProperty(exports,`isBooleanType`,{enumerable:!0,get:function(){return f.isBooleanType}}),Object.defineProperty(exports,`isDateTimeType`,{enumerable:!0,get:function(){return f.isDateTimeType}}),Object.defineProperty(exports,`isFloatType`,{enumerable:!0,get:function(){return f.isFloatType}}),Object.defineProperty(exports,`isIntegerType`,{enumerable:!0,get:function(){return f.isIntegerType}}),Object.defineProperty(exports,`isNumericType`,{enumerable:!0,get:function(){return f.isNumericType}}),Object.defineProperty(exports,`isSerialType`,{enumerable:!0,get:function(){return f.isSerialType}}),Object.defineProperty(exports,`isStringType`,{enumerable:!0,get:function(){return f.isStringType}}),exports.renameTable=FRe,exports.syncDiagramView=IRe,Object.defineProperty(exports,`tryExtractBoolean`,{enumerable:!0,get:function(){return f.tryExtractBoolean}}),Object.defineProperty(exports,`tryExtractDateTime`,{enumerable:!0,get:function(){return f.tryExtractDateTime}}),Object.defineProperty(exports,`tryExtractEnum`,{enumerable:!0,get:function(){return f.tryExtractEnum}}),Object.defineProperty(exports,`tryExtractInteger`,{enumerable:!0,get:function(){return f.tryExtractInteger}}),Object.defineProperty(exports,`tryExtractNumeric`,{enumerable:!0,get:function(){return f.tryExtractNumeric}}),Object.defineProperty(exports,`tryExtractString`,{enumerable:!0,get:function(){return f.tryExtractString}});
|
package/lib/index.mjs
CHANGED
|
@@ -4802,10 +4802,14 @@ var DbmlExporter_default = class _ {
|
|
|
4802
4802
|
});
|
|
4803
4803
|
return HY.length ? HY.join("\n") : "";
|
|
4804
4804
|
}
|
|
4805
|
+
static getStickyNoteSettings(_) {
|
|
4806
|
+
let VY = "";
|
|
4807
|
+
return _.color && (VY += `color: ${_.color}`), VY ? ` [${VY}]` : "";
|
|
4808
|
+
}
|
|
4805
4809
|
static exportStickyNotes(VY) {
|
|
4806
4810
|
return reduce_default(VY.notes, (VY, P) => {
|
|
4807
|
-
let HY = ` ${_.escapeNote(P.content)}`, UY = `Note ${P.name} {\n${HY}\n}\n`;
|
|
4808
|
-
return VY ? `${VY}\n${
|
|
4811
|
+
let HY = ` ${_.escapeNote(P.content)}`, UY = _.getStickyNoteSettings(P), WY = `Note ${P.name}${UY} {\n${HY}\n}\n`;
|
|
4812
|
+
return VY ? `${VY}\n${WY}` : WY;
|
|
4809
4813
|
}, "");
|
|
4810
4814
|
}
|
|
4811
4815
|
static exportRecords(_) {
|
|
@@ -5894,8 +5898,8 @@ var schema_default = class extends element_default {
|
|
|
5894
5898
|
}, this.tables.forEach((VY) => VY.normalize(_)), this.enums.forEach((VY) => VY.normalize(_)), this.tableGroups.forEach((VY) => VY.normalize(_)), this.refs.forEach((VY) => VY.normalize(_));
|
|
5895
5899
|
}
|
|
5896
5900
|
}, stickyNote_default = class extends element_default {
|
|
5897
|
-
constructor({ name: _, content: VY,
|
|
5898
|
-
super(HY), this.name = _, this.content = VY, this.
|
|
5901
|
+
constructor({ name: _, content: VY, color: P, token: HY, database: UY = {} } = {}) {
|
|
5902
|
+
super(HY), this.name = _, this.content = VY, this.color = P, this.database = UY, this.dbState = this.database.dbState, this.generateId();
|
|
5899
5903
|
}
|
|
5900
5904
|
generateId() {
|
|
5901
5905
|
this.id = this.dbState.generateId("noteId");
|
|
@@ -5904,7 +5908,7 @@ var schema_default = class extends element_default {
|
|
|
5904
5908
|
return {
|
|
5905
5909
|
name: this.name,
|
|
5906
5910
|
content: this.content,
|
|
5907
|
-
|
|
5911
|
+
color: this.color
|
|
5908
5912
|
};
|
|
5909
5913
|
}
|
|
5910
5914
|
normalize(_) {
|
|
@@ -1810994,5 +1810998,5 @@ function findDiagramViewBlocks(VY) {
|
|
|
1810994
1810998
|
let HY = new MemoryProjectLayout();
|
|
1810995
1810999
|
return HY.setSource(DEFAULT_ENTRY$1, VY), new Compiler(HY).findDiagramViewBlocks(DEFAULT_ENTRY$1);
|
|
1810996
1811000
|
}
|
|
1810997
|
-
const VERSION = "8.
|
|
1811001
|
+
const VERSION = "8.3.0-alpha.0";
|
|
1810998
1811002
|
export { CompilerError, DEFAULT_ENTRY, Filepath, ModelExporter_default as ModelExporter, Parser_default as Parser, VERSION, addDoubleQuoteIfNeeded, dbmlMonarchTokensProvider, export_default as exporter, findDiagramViewBlocks, formatRecordValue, import_default as importer, isBinaryType, isBooleanType, isDateTimeType, isFloatType, isIntegerType, isNumericType, isSerialType, isStringType, renameTable, syncDiagramView, tryExtractBoolean, tryExtractDateTime, tryExtractEnum, tryExtractInteger, tryExtractNumeric, tryExtractString };
|
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": "8.
|
|
4
|
+
"version": "8.3.0-alpha.0",
|
|
5
5
|
"description": "> TODO: description",
|
|
6
6
|
"author": "Holistics <dev@holistics.io>",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"lint:fix": "eslint --fix ."
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@dbml/parse": "^8.
|
|
49
|
+
"@dbml/parse": "^8.3.0-alpha.0",
|
|
50
50
|
"antlr4": "^4.13.1",
|
|
51
51
|
"lodash": "^4.18.1",
|
|
52
52
|
"lodash-es": "^4.18.1",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"bluebird": "^3.5.5"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "75cec6fdf26767726449c7c7b370797b8379c4bc",
|
|
61
61
|
"engines": {
|
|
62
62
|
"node": ">=16"
|
|
63
63
|
}
|
|
@@ -4,7 +4,7 @@ import Enum, { NormalizedEnumIdMap } from './enum';
|
|
|
4
4
|
import TableGroup, { NormalizedTableGroupIdMap } from './tableGroup';
|
|
5
5
|
import Table, { NormalizedTableIdMap } from './table';
|
|
6
6
|
import StickyNote, { NormalizedNoteIdMap } from './stickyNote';
|
|
7
|
-
import Element, { RawNote, Token } from './element';
|
|
7
|
+
import Element, { RawNote, Token, Color } from './element';
|
|
8
8
|
import DbState from './dbState';
|
|
9
9
|
import { NormalizedEndpointIdMap } from './endpoint';
|
|
10
10
|
import { NormalizedEnumValueIdMap } from './enumValue';
|
|
@@ -113,7 +113,7 @@ declare class Database extends Element {
|
|
|
113
113
|
name: string;
|
|
114
114
|
alias: string;
|
|
115
115
|
note: string;
|
|
116
|
-
headerColor:
|
|
116
|
+
headerColor: Color;
|
|
117
117
|
}[];
|
|
118
118
|
enums: {
|
|
119
119
|
values: {
|
|
@@ -149,7 +149,7 @@ declare class Database extends Element {
|
|
|
149
149
|
id: number;
|
|
150
150
|
name: string;
|
|
151
151
|
content: string;
|
|
152
|
-
headerColor:
|
|
152
|
+
headerColor: Color;
|
|
153
153
|
}[];
|
|
154
154
|
records: {
|
|
155
155
|
id: number;
|
|
@@ -164,7 +164,7 @@ declare class Database extends Element {
|
|
|
164
164
|
tablePartials: {
|
|
165
165
|
name: string;
|
|
166
166
|
note: string;
|
|
167
|
-
headerColor:
|
|
167
|
+
headerColor: Color;
|
|
168
168
|
fields: {
|
|
169
169
|
name: string;
|
|
170
170
|
type: any;
|
|
@@ -222,7 +222,7 @@ declare class Database extends Element {
|
|
|
222
222
|
name: string;
|
|
223
223
|
alias: string;
|
|
224
224
|
note: string;
|
|
225
|
-
headerColor:
|
|
225
|
+
headerColor: Color;
|
|
226
226
|
}[];
|
|
227
227
|
enums: {
|
|
228
228
|
values: {
|
|
@@ -258,12 +258,12 @@ declare class Database extends Element {
|
|
|
258
258
|
id: number;
|
|
259
259
|
name: string;
|
|
260
260
|
content: string;
|
|
261
|
-
headerColor:
|
|
261
|
+
headerColor: Color;
|
|
262
262
|
}[];
|
|
263
263
|
tablePartials: {
|
|
264
264
|
name: string;
|
|
265
265
|
note: string;
|
|
266
|
-
headerColor:
|
|
266
|
+
headerColor: Color;
|
|
267
267
|
fields: {
|
|
268
268
|
name: string;
|
|
269
269
|
type: any;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Element, { Token } from './element';
|
|
1
|
+
import Element, { Token, Color } from './element';
|
|
2
2
|
import Endpoint from './endpoint';
|
|
3
3
|
import Schema from './schema';
|
|
4
4
|
import DbState from './dbState';
|
|
@@ -6,7 +6,7 @@ import Database, { NormalizedModel } from './database';
|
|
|
6
6
|
import TablePartial from './tablePartial';
|
|
7
7
|
export interface RawRef {
|
|
8
8
|
name: string;
|
|
9
|
-
color?:
|
|
9
|
+
color?: Color;
|
|
10
10
|
endpoints: Endpoint[];
|
|
11
11
|
onDelete: any;
|
|
12
12
|
onUpdate: any;
|
|
@@ -16,7 +16,7 @@ export interface RawRef {
|
|
|
16
16
|
}
|
|
17
17
|
declare class Ref extends Element {
|
|
18
18
|
name: string;
|
|
19
|
-
color?:
|
|
19
|
+
color?: Color;
|
|
20
20
|
endpoints: Endpoint[];
|
|
21
21
|
onDelete: any;
|
|
22
22
|
onUpdate: any;
|
|
@@ -67,7 +67,7 @@ declare class Ref extends Element {
|
|
|
67
67
|
export interface NormalizedRef {
|
|
68
68
|
id: number;
|
|
69
69
|
name: string | null;
|
|
70
|
-
color?:
|
|
70
|
+
color?: Color;
|
|
71
71
|
onUpdate?: string;
|
|
72
72
|
onDelete?: string;
|
|
73
73
|
inactive?: boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Table from './table';
|
|
2
|
-
import Element, { RawNote, Token } from './element';
|
|
2
|
+
import Element, { RawNote, Token, Color } from './element';
|
|
3
3
|
import Enum from './enum';
|
|
4
4
|
import TableGroup from './tableGroup';
|
|
5
5
|
import Ref from './ref';
|
|
@@ -70,7 +70,7 @@ declare class Schema extends Element {
|
|
|
70
70
|
name: string;
|
|
71
71
|
alias: string;
|
|
72
72
|
note: string;
|
|
73
|
-
headerColor:
|
|
73
|
+
headerColor: Color;
|
|
74
74
|
}[];
|
|
75
75
|
enums: {
|
|
76
76
|
values: {
|
|
@@ -128,7 +128,7 @@ declare class Schema extends Element {
|
|
|
128
128
|
name: string;
|
|
129
129
|
alias: string;
|
|
130
130
|
note: string;
|
|
131
|
-
headerColor:
|
|
131
|
+
headerColor: Color;
|
|
132
132
|
}[];
|
|
133
133
|
enums: {
|
|
134
134
|
values: {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Element, { Token } from './element';
|
|
1
|
+
import Element, { Token, Color } from './element';
|
|
2
2
|
import Database from './database';
|
|
3
3
|
import DbState from './dbState';
|
|
4
4
|
import { NormalizedModel } from './database';
|
|
@@ -8,23 +8,23 @@ export interface RawStickyNote {
|
|
|
8
8
|
content: string;
|
|
9
9
|
database: Database;
|
|
10
10
|
token: Token;
|
|
11
|
-
|
|
11
|
+
color?: Color;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
declare class StickyNote extends Element {
|
|
15
15
|
name: string;
|
|
16
16
|
content: string;
|
|
17
17
|
noteToken: Token;
|
|
18
|
-
|
|
18
|
+
color?: Color;
|
|
19
19
|
database: Database;
|
|
20
20
|
dbState: DbState;
|
|
21
21
|
id: number;
|
|
22
|
-
constructor({ name, content, token,
|
|
22
|
+
constructor({ name, content, token, color, database }: RawStickyNote);
|
|
23
23
|
generateId(): void;
|
|
24
24
|
export(): {
|
|
25
25
|
name: string;
|
|
26
26
|
content: string;
|
|
27
|
-
|
|
27
|
+
color?: Color;
|
|
28
28
|
};
|
|
29
29
|
normalize(model: NormalizedModel): void;
|
|
30
30
|
}
|
|
@@ -32,7 +32,7 @@ export interface NormalizedNote {
|
|
|
32
32
|
id: number;
|
|
33
33
|
name: string;
|
|
34
34
|
content: string;
|
|
35
|
-
|
|
35
|
+
color?: Color;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
export interface NormalizedNoteIdMap {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Element, { RawNote, Token } from './element';
|
|
1
|
+
import Element, { RawNote, Token, Color } from './element';
|
|
2
2
|
import Field from './field';
|
|
3
3
|
import Index from './indexes';
|
|
4
4
|
import Check from './check';
|
|
@@ -17,7 +17,7 @@ export interface RawTable {
|
|
|
17
17
|
checks?: any[];
|
|
18
18
|
schema: Schema;
|
|
19
19
|
token: Token;
|
|
20
|
-
headerColor:
|
|
20
|
+
headerColor: Color;
|
|
21
21
|
partials: TablePartial[];
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -30,7 +30,7 @@ declare class Table extends Element {
|
|
|
30
30
|
indexes: Index[];
|
|
31
31
|
checks: Check[];
|
|
32
32
|
schema: Schema;
|
|
33
|
-
headerColor:
|
|
33
|
+
headerColor: Color;
|
|
34
34
|
dbState: DbState;
|
|
35
35
|
id: number;
|
|
36
36
|
group: TableGroup;
|
|
@@ -75,7 +75,7 @@ declare class Table extends Element {
|
|
|
75
75
|
name: string;
|
|
76
76
|
alias: string;
|
|
77
77
|
note: string;
|
|
78
|
-
headerColor:
|
|
78
|
+
headerColor: Color;
|
|
79
79
|
partials: TablePartial[];
|
|
80
80
|
};
|
|
81
81
|
exportChild(): {
|
|
@@ -114,7 +114,7 @@ declare class Table extends Element {
|
|
|
114
114
|
name: string;
|
|
115
115
|
alias: string;
|
|
116
116
|
note: string;
|
|
117
|
-
headerColor:
|
|
117
|
+
headerColor: Color;
|
|
118
118
|
partials: TablePartial[];
|
|
119
119
|
recordIds: number[];
|
|
120
120
|
};
|
|
@@ -126,7 +126,7 @@ export interface NormalizedTable {
|
|
|
126
126
|
name: string;
|
|
127
127
|
alias: string | null;
|
|
128
128
|
note: string | null;
|
|
129
|
-
headerColor:
|
|
129
|
+
headerColor: Color;
|
|
130
130
|
fieldIds: number[];
|
|
131
131
|
indexIds: number[];
|
|
132
132
|
checkIds: number[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NormalizedModel } from './database';
|
|
2
2
|
import DbState from './dbState';
|
|
3
|
-
import Element, { RawNote, Token} from './element';
|
|
3
|
+
import Element, { RawNote, Token, Color } from './element';
|
|
4
4
|
import Schema from './schema';
|
|
5
5
|
import Table from './table';
|
|
6
6
|
|
|
@@ -10,7 +10,7 @@ export interface RawTableGroup {
|
|
|
10
10
|
schema: Schema;
|
|
11
11
|
token: Token;
|
|
12
12
|
note: RawNote;
|
|
13
|
-
color:
|
|
13
|
+
color: Color;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
declare class TableGroup extends Element {
|
|
@@ -21,7 +21,7 @@ declare class TableGroup extends Element {
|
|
|
21
21
|
id: number;
|
|
22
22
|
note: string;
|
|
23
23
|
noteToken: Token;
|
|
24
|
-
color:
|
|
24
|
+
color: Color;
|
|
25
25
|
constructor({ name, token, tables, schema, note, color }: RawTableGroup);
|
|
26
26
|
generateId(): void;
|
|
27
27
|
processTables(rawTables: any): void;
|
|
@@ -34,7 +34,7 @@ declare class TableGroup extends Element {
|
|
|
34
34
|
}[];
|
|
35
35
|
name: string;
|
|
36
36
|
note: string;
|
|
37
|
-
color:
|
|
37
|
+
color: Color;
|
|
38
38
|
};
|
|
39
39
|
exportChild(): {
|
|
40
40
|
tables: {
|
|
@@ -51,7 +51,7 @@ declare class TableGroup extends Element {
|
|
|
51
51
|
shallowExport(): {
|
|
52
52
|
name: string;
|
|
53
53
|
note: string;
|
|
54
|
-
color:
|
|
54
|
+
color: Color;
|
|
55
55
|
};
|
|
56
56
|
normalize(model: NormalizedModel): void;
|
|
57
57
|
}
|
|
@@ -59,7 +59,7 @@ export interface NormalizedTableGroup {
|
|
|
59
59
|
id: number;
|
|
60
60
|
name: string;
|
|
61
61
|
note: string | null;
|
|
62
|
-
color:
|
|
62
|
+
color: Color;
|
|
63
63
|
tableIds: number[];
|
|
64
64
|
schemaId: number;
|
|
65
65
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Element, { RawNote, Token } from './element';
|
|
1
|
+
import Element, { RawNote, Token, Color } from './element';
|
|
2
2
|
import Field from './field';
|
|
3
3
|
import Index from './indexes';
|
|
4
4
|
import Check from './check';
|
|
@@ -12,7 +12,7 @@ export interface RawTablePartial {
|
|
|
12
12
|
indexes: Index[];
|
|
13
13
|
checks?: any[];
|
|
14
14
|
token: Token;
|
|
15
|
-
headerColor:
|
|
15
|
+
headerColor: Color;
|
|
16
16
|
dbState: DbState;
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -23,7 +23,7 @@ declare class TablePartial extends Element {
|
|
|
23
23
|
fields: Field[];
|
|
24
24
|
indexes: Index[];
|
|
25
25
|
checks: Check[];
|
|
26
|
-
headerColor:
|
|
26
|
+
headerColor: Color;
|
|
27
27
|
dbState: DbState;
|
|
28
28
|
id: number;
|
|
29
29
|
|
|
@@ -32,7 +32,7 @@ declare class TablePartial extends Element {
|
|
|
32
32
|
export(): {
|
|
33
33
|
name: string;
|
|
34
34
|
note: string;
|
|
35
|
-
headerColor:
|
|
35
|
+
headerColor: Color;
|
|
36
36
|
fields: {
|
|
37
37
|
name: string;
|
|
38
38
|
type: any;
|
|
@@ -59,7 +59,7 @@ declare class TablePartial extends Element {
|
|
|
59
59
|
shallowExport(): {
|
|
60
60
|
name: string;
|
|
61
61
|
note: string;
|
|
62
|
-
headerColor:
|
|
62
|
+
headerColor: Color;
|
|
63
63
|
fields: {
|
|
64
64
|
name: string;
|
|
65
65
|
type: any;
|
|
@@ -90,7 +90,7 @@ export interface NormalizedTablePartial {
|
|
|
90
90
|
id: number;
|
|
91
91
|
name: string;
|
|
92
92
|
note: string;
|
|
93
|
-
headerColor:
|
|
93
|
+
headerColor: Color;
|
|
94
94
|
fieldIds: number[];
|
|
95
95
|
indexIds: number[];
|
|
96
96
|
checkIds: number[];
|