@mrleebo/prisma-ast
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -808,4 +808,4 @@ 'use strict'; | ||
return printAssignment(assignment, keyLength); | ||
}).filter(Boolean).join('\n '); | ||
return "\n datasource " + db.name + " {\n " + children + "\n }"; | ||
}).filter(Boolean).join('\n '); | ||
return "\ndatasource " + db.name + " {\n " + children + "\n}"; | ||
} | ||
@@ -816,9 +816,9 @@ | ||
return enumerator.type === 'comment' ? printComment(enumerator) : enumerator.name; | ||
}).filter(Boolean).join('\n '); | ||
return "\n enum " + enumerator.name + " {\n " + children + "\n }"; | ||
}).filter(Boolean).join('\n '); | ||
return "\nenum " + enumerator.name + " {\n " + children + "\n}"; | ||
} | ||
function printGenerator(generator) { | ||
var children = generator.assignments.map(printAssignment).filter(Boolean).join('\n '); | ||
return "\n generator " + generator.name + " {\n " + children + "\n }"; | ||
var children = generator.assignments.map(printAssignment).filter(Boolean).join('\n '); | ||
return "\ngenerator " + generator.name + " {\n " + children + "\n}"; | ||
} | ||
@@ -835,4 +835,4 @@ | ||
return printProperty(prop, nameLength, typeLength); | ||
}).filter(Boolean).join('\n '); | ||
return "\n model " + model.name + " {\n " + children + "\n }"; | ||
}).filter(Boolean).join('\n '); | ||
return "\nmodel " + model.name + " {\n " + children + "\n}"; | ||
} | ||
@@ -839,0 +839,0 @@ |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("chevrotain"),t=e.createToken({name:"Identifier",pattern:/[a-zA-Z]\w*/}),n=e.createToken({name:"Datasource",pattern:/datasource/,longer_alt:t}),r=e.createToken({name:"Generator",pattern:/generator/,longer_alt:t}),a=e.createToken({name:"Model",pattern:/model/,longer_alt:t}),u=e.createToken({name:"Enum",pattern:/enum/,longer_alt:t}),o=e.createToken({name:"True",pattern:/true/,longer_alt:t}),i=e.createToken({name:"False",pattern:/false/,longer_alt:t}),c=e.createToken({name:"Null",pattern:/null/,longer_alt:t}),l=e.createToken({name:"Comment",pattern:e.Lexer.NA}),m=e.createToken({name:"DocComment",pattern:/\/\/\/\s*(.+)/,categories:[l]}),L=e.createToken({name:"LineComment",pattern:/\/\/\s*(.+)/,categories:[l]}),s=e.createToken({name:"Attribute",pattern:e.Lexer.NA}),f=e.createToken({name:"ModelAttribute",pattern:/@@/,label:"'@@'",categories:[s]}),p=e.createToken({name:"FieldAttribute",pattern:/@/,label:"'@'",categories:[s]}),E=e.createToken({name:"Dot",pattern:/\./,label:"'.'"}),A=e.createToken({name:"QuestionMark",pattern:/\?/,label:"'?'"}),U=e.createToken({name:"Array",pattern:/\[\]/,label:"'[]'"}),v=e.createToken({name:"LCurly",pattern:/{/,label:"'{'"}),y=e.createToken({name:"RCurly",pattern:/}/,label:"'}'"}),d=e.createToken({name:"LRound",pattern:/\(/,label:"'('"}),S=e.createToken({name:"RRound",pattern:/\)/,label:"')'"}),T=e.createToken({name:"LSquare",pattern:/\[/,label:"'['"}),g=e.createToken({name:"RSquare",pattern:/\]/,label:"']'"}),N=e.createToken({name:"Comma",pattern:/,/,label:"','"}),B=e.createToken({name:"Colon",pattern:/:/,label:"':'"}),b=e.createToken({name:"Equals",pattern:/=/,label:"'='"}),O=e.createToken({name:"StringLiteral",pattern:/"(:?[^\\"\n\r]+|\\(:?[bfnrtv"\\/]|u[0-9a-fA-F]{4}))*"/}),k=e.createToken({name:"NumberLiteral",pattern:/-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?/}),M=e.createToken({name:"WhiteSpace",pattern:/\s+/,group:e.Lexer.SKIPPED}),C=e.createToken({name:"LineBreak",pattern:"\n",line_breaks:!0,label:"LineBreak"}),R=[l,m,L,C,M,s,f,p,E,A,U,v,y,T,g,d,S,N,B,b,o,i,c,n,r,a,u,O,k,t],h=new e.Lexer(R);function w(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,(Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var x=new(function(e){function m(){var m;return(m=e.call(this,R)||this).keyedArg=m.RULE("keyedArg",(function(){m.CONSUME(t,{LABEL:"keyName"}),m.CONSUME(B),m.SUBRULE(m.value)})),m.array=m.RULE("array",(function(){m.CONSUME(T),m.MANY_SEP({SEP:N,DEF:function(){m.SUBRULE(m.value)}}),m.CONSUME(g)})),m.func=m.RULE("func",(function(){m.CONSUME(t,{LABEL:"funcName"}),m.CONSUME(d),m.MANY_SEP({SEP:N,DEF:function(){m.SUBRULE(m.value)}}),m.CONSUME(S)})),m.value=m.RULE("value",(function(){m.OR([{ALT:function(){return m.CONSUME(O,{LABEL:"value"})}},{ALT:function(){return m.CONSUME(k,{LABEL:"value"})}},{ALT:function(){return m.SUBRULE(m.array,{LABEL:"value"})}},{ALT:function(){return m.SUBRULE(m.func,{LABEL:"value"})}},{ALT:function(){return m.CONSUME(o,{LABEL:"value"})}},{ALT:function(){return m.CONSUME(i,{LABEL:"value"})}},{ALT:function(){return m.CONSUME(c,{LABEL:"value"})}},{ALT:function(){return m.CONSUME(t,{LABEL:"value"})}}])})),m.property=m.RULE("property",(function(){m.CONSUME(t,{LABEL:"propertyName"}),m.CONSUME(b),m.SUBRULE(m.value,{LABEL:"propertyValue"})})),m.assignment=m.RULE("assignment",(function(){m.CONSUME(t,{LABEL:"assignmentName"}),m.CONSUME(b),m.SUBRULE(m.value,{LABEL:"assignmentValue"})})),m.field=m.RULE("field",(function(){m.CONSUME(t,{LABEL:"fieldName"}),m.SUBRULE(m.value,{LABEL:"fieldType"}),m.OPTION((function(){m.OR([{ALT:function(){return m.CONSUME(U,{LABEL:"array"})}},{ALT:function(){return m.CONSUME(A,{LABEL:"optional"})}}])})),m.MANY((function(){m.SUBRULE(m.attribute,{LABEL:"attributeList"})}))})),m.block=m.RULE("block",(function(e){var t=(void 0===e?{}:e).componentType,n="enum"===t,r="model"===t;m.CONSUME(v),m.CONSUME1(C),m.MANY((function(){m.OR([{ALT:function(){return m.SUBRULE(m.comment,{LABEL:"list"})}},{GATE:function(){return r},ALT:function(){return m.SUBRULE(m.property,{LABEL:"list"})}},{GATE:function(){return r},ALT:function(){return m.SUBRULE(m.attribute,{LABEL:"list"})}},{GATE:function(){return r},ALT:function(){return m.SUBRULE(m.field,{LABEL:"list"})}},{GATE:function(){return n},ALT:function(){return m.SUBRULE(m.enum,{LABEL:"list"})}},{GATE:function(){return!r},ALT:function(){return m.SUBRULE(m.assignment,{LABEL:"list"})}},{ALT:function(){return m.CONSUME2(C)}}])})),m.CONSUME(y)})),m.enum=m.RULE("enum",(function(){m.CONSUME(t,{LABEL:"enumName"})})),m.attribute=m.RULE("attribute",(function(){m.OR1([{ALT:function(){return m.CONSUME(f,{LABEL:"modelAttribute"})}},{ALT:function(){return m.CONSUME(p,{LABEL:"fieldAttribute"})}}]),m.OR2([{ALT:function(){m.CONSUME1(t,{LABEL:"groupName"}),m.CONSUME(E),m.CONSUME2(t,{LABEL:"attributeName"})}},{ALT:function(){return m.CONSUME(t,{LABEL:"attributeName"})}}]),m.OPTION((function(){m.CONSUME(d),m.MANY_SEP({SEP:N,DEF:function(){m.SUBRULE(m.attributeArg)}}),m.CONSUME(S)}))})),m.attributeArg=m.RULE("attributeArg",(function(){m.OR([{ALT:function(){return m.SUBRULE(m.keyedArg,{LABEL:"value"})}},{ALT:function(){return m.SUBRULE(m.value,{LABEL:"value"})}}])})),m.component=m.RULE("component",(function(){var e=m.OR1([{ALT:function(){return m.CONSUME(n,{LABEL:"type"})}},{ALT:function(){return m.CONSUME(r,{LABEL:"type"})}},{ALT:function(){return m.CONSUME(a,{LABEL:"type"})}},{ALT:function(){return m.CONSUME(u,{LABEL:"type"})}}]);m.OR2([{ALT:function(){m.CONSUME1(t,{LABEL:"groupName"}),m.CONSUME(E),m.CONSUME2(t,{LABEL:"componentName"})}},{ALT:function(){return m.CONSUME(t,{LABEL:"componentName"})}}]),m.SUBRULE(m.block,{ARGS:[{componentType:e.image}]})})),m.comment=m.RULE("comment",(function(){m.CONSUME(l,{LABEL:"text"})})),m.schema=m.RULE("schema",(function(){m.MANY((function(){m.OR([{ALT:function(){return m.SUBRULE(m.comment,{LABEL:"list"})}},{ALT:function(){return m.SUBRULE(m.component,{LABEL:"list"})}},{ALT:function(){return m.CONSUME(C)}}])}))})),m.performSelfAnalysis(),m}return w(m,e),m}(e.CstParser)),_=function(e){function t(){var t;return(t=e.call(this)||this).validateVisitor(),t}w(t,e);var n=t.prototype;return n.schema=function(e){var t,n=this;return{type:"schema",list:null==(t=e.list)?void 0:t.map((function(e){return n.visit([e])}))}},n.component=function(e){var t=e.type[0].image,n=e.componentName[0].image,r=this.visit(e.block);switch(t){case"datasource":return{type:"datasource",name:n,assignments:r};case"generator":return{type:"generator",name:n,assignments:r};case"model":return{type:"model",name:n,properties:r};case"enum":return{type:"enum",name:n,enumerators:r};default:throw new Error("Unexpected block type: "+t)}},n.comment=function(e){return{type:"comment",text:e.text[0].image}},n.block=function(e){var t,n=this;return null==(t=e.list)?void 0:t.map((function(e){return n.visit([e])}))},n.assignment=function(e){var t=this.visit(e.assignmentValue);return{type:"assignment",key:e.assignmentName[0].image,value:t}},n.field=function(e){var t=this,n=this.visit(e.fieldType),r=e.fieldName[0].image,a=e.attributeList&&e.attributeList.map((function(e){return t.visit([e])}));return{type:"field",name:r,fieldType:n,array:null!=e.array,optional:null!=e.optional,attributes:a}},n.attribute=function(e){var t=this,n=e.attributeName[0].image,r=(e.groupName||[{}])[0].image,a=e.attributeArg&&e.attributeArg.map((function(e){return t.visit(e)}));return{type:"attribute",name:n,kind:null!=e.modelAttribute?"model":"field",group:r,args:a}},n.attributeArg=function(e){return{type:"attributeArgument",value:this.visit(e.value)}},n.func=function(e){var t=this;return{type:"function",name:e.funcName[0].image,params:e.value&&e.value.map((function(e){return t.visit([e])}))}},n.array=function(e){var t=this;return{type:"array",args:e.value&&e.value.map((function(e){return t.visit([e])}))}},n.keyedArg=function(e){return{type:"keyValue",key:e.keyName[0].image,value:this.visit(e.value)}},n.value=function(e){return"image"in e.value[0]?e.value[0].image:this.visit(e.value)},n.enum=function(e){return{type:"enumerator",name:e.enumName[0].image}},t}(x.getBaseCstVisitorConstructorWithDefaults());function j(e){switch(e.type){case"comment":return P(e);case"datasource":return n=(t=e).assignments.reduce((function(e,t){return Math.max(e,"assignment"===t.type?t.key.length:0)}),0),r=t.assignments.map((function(e){return D(e,n)})).filter(Boolean).join("\n "),"\n datasource "+t.name+" {\n "+r+"\n }";case"enum":return function(e){var t=e.enumerators.map((function(e){return"comment"===e.type?P(e):e.name})).filter(Boolean).join("\n ");return"\n enum "+e.name+" {\n "+t+"\n }"}(e);case"generator":return function(e){var t=e.assignments.map(D).filter(Boolean).join("\n ");return"\n generator "+e.name+" {\n "+t+"\n }"}(e);case"model":return function(e){var t=e.properties.reduce((function(e,t){return Math.max(e,"field"===t.type?t.name.length:0)}),0),n=e.properties.reduce((function(e,t){return Math.max(e,"field"===t.type?F(t).length:0)}),0),r=e.properties.map((function(e){return function(e,t,n){switch(void 0===t&&(t=0),void 0===n&&(n=0),e.type){case"attribute":return G(e);case"field":return function(e,t,n){void 0===t&&(t=0),void 0===n&&(n=0);var r=e.name.padEnd(t),a=F(e).padEnd(n),u=e.attributes?e.attributes.map(G):[];return[r,a].concat(u).filter(Boolean).join(" ").trim()}(e,t,n);case"comment":return P(e);default:throw new Error("Unrecognized property type")}}(e,t,n)})).filter(Boolean).join("\n ");return"\n model "+e.name+" {\n "+r+"\n }"}(e);default:throw new Error("Unrecognized block type")}var t,n,r}function P(e){return e.text}function D(e,t){return void 0===t&&(t=0),"comment"===e.type?P(e):e.key.padEnd(t)+" = "+Y(e.value)}function G(e){var t=e.args&&e.args.length>0?"("+e.args.map(V).filter(Boolean).join(", ")+")":"";return("field"===e.kind?"@":"@@")+e.name+t}function V(e){return Y(e.value)}function F(e){var t=e.array?"[]":e.optional?"?":"";if("object"==typeof e.fieldType)switch(e.fieldType.type){case"function":var n=e.fieldType.params.map(Y);return e.fieldType.name+"("+n+")"+t;default:throw new Error("Unexpected field type")}return""+e.fieldType+t}function Y(e){switch(typeof e){case"object":if("type"in e)switch(e.type){case"keyValue":return e.key+": "+Y(e.value);case"function":return e.name+"("+(e.params?e.params.map(Y):"")+")";case"array":return"["+e.args.join(", ")+"]";default:throw new Error("Unexpected value type")}throw new Error("Unexpected object value");default:return String(e)}}exports.getSchema=function(e){var t=h.tokenize(e);x.input=t.tokens;var n=x.schema();if(x.errors.length>0)throw x.errors[0];return(new _).visit(n)},exports.printSchema=function(e){return e.list.map(j).filter(Boolean).join("\n")}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("chevrotain"),t=e.createToken({name:"Identifier",pattern:/[a-zA-Z]\w*/}),n=e.createToken({name:"Datasource",pattern:/datasource/,longer_alt:t}),r=e.createToken({name:"Generator",pattern:/generator/,longer_alt:t}),a=e.createToken({name:"Model",pattern:/model/,longer_alt:t}),u=e.createToken({name:"Enum",pattern:/enum/,longer_alt:t}),o=e.createToken({name:"True",pattern:/true/,longer_alt:t}),i=e.createToken({name:"False",pattern:/false/,longer_alt:t}),c=e.createToken({name:"Null",pattern:/null/,longer_alt:t}),l=e.createToken({name:"Comment",pattern:e.Lexer.NA}),m=e.createToken({name:"DocComment",pattern:/\/\/\/\s*(.+)/,categories:[l]}),L=e.createToken({name:"LineComment",pattern:/\/\/\s*(.+)/,categories:[l]}),s=e.createToken({name:"Attribute",pattern:e.Lexer.NA}),f=e.createToken({name:"ModelAttribute",pattern:/@@/,label:"'@@'",categories:[s]}),p=e.createToken({name:"FieldAttribute",pattern:/@/,label:"'@'",categories:[s]}),E=e.createToken({name:"Dot",pattern:/\./,label:"'.'"}),A=e.createToken({name:"QuestionMark",pattern:/\?/,label:"'?'"}),U=e.createToken({name:"Array",pattern:/\[\]/,label:"'[]'"}),v=e.createToken({name:"LCurly",pattern:/{/,label:"'{'"}),y=e.createToken({name:"RCurly",pattern:/}/,label:"'}'"}),d=e.createToken({name:"LRound",pattern:/\(/,label:"'('"}),S=e.createToken({name:"RRound",pattern:/\)/,label:"')'"}),T=e.createToken({name:"LSquare",pattern:/\[/,label:"'['"}),g=e.createToken({name:"RSquare",pattern:/\]/,label:"']'"}),N=e.createToken({name:"Comma",pattern:/,/,label:"','"}),B=e.createToken({name:"Colon",pattern:/:/,label:"':'"}),b=e.createToken({name:"Equals",pattern:/=/,label:"'='"}),O=e.createToken({name:"StringLiteral",pattern:/"(:?[^\\"\n\r]+|\\(:?[bfnrtv"\\/]|u[0-9a-fA-F]{4}))*"/}),k=e.createToken({name:"NumberLiteral",pattern:/-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?/}),M=e.createToken({name:"WhiteSpace",pattern:/\s+/,group:e.Lexer.SKIPPED}),C=e.createToken({name:"LineBreak",pattern:"\n",line_breaks:!0,label:"LineBreak"}),R=[l,m,L,C,M,s,f,p,E,A,U,v,y,T,g,d,S,N,B,b,o,i,c,n,r,a,u,O,k,t],h=new e.Lexer(R);function w(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,(Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var x=new(function(e){function m(){var m;return(m=e.call(this,R)||this).keyedArg=m.RULE("keyedArg",(function(){m.CONSUME(t,{LABEL:"keyName"}),m.CONSUME(B),m.SUBRULE(m.value)})),m.array=m.RULE("array",(function(){m.CONSUME(T),m.MANY_SEP({SEP:N,DEF:function(){m.SUBRULE(m.value)}}),m.CONSUME(g)})),m.func=m.RULE("func",(function(){m.CONSUME(t,{LABEL:"funcName"}),m.CONSUME(d),m.MANY_SEP({SEP:N,DEF:function(){m.SUBRULE(m.value)}}),m.CONSUME(S)})),m.value=m.RULE("value",(function(){m.OR([{ALT:function(){return m.CONSUME(O,{LABEL:"value"})}},{ALT:function(){return m.CONSUME(k,{LABEL:"value"})}},{ALT:function(){return m.SUBRULE(m.array,{LABEL:"value"})}},{ALT:function(){return m.SUBRULE(m.func,{LABEL:"value"})}},{ALT:function(){return m.CONSUME(o,{LABEL:"value"})}},{ALT:function(){return m.CONSUME(i,{LABEL:"value"})}},{ALT:function(){return m.CONSUME(c,{LABEL:"value"})}},{ALT:function(){return m.CONSUME(t,{LABEL:"value"})}}])})),m.property=m.RULE("property",(function(){m.CONSUME(t,{LABEL:"propertyName"}),m.CONSUME(b),m.SUBRULE(m.value,{LABEL:"propertyValue"})})),m.assignment=m.RULE("assignment",(function(){m.CONSUME(t,{LABEL:"assignmentName"}),m.CONSUME(b),m.SUBRULE(m.value,{LABEL:"assignmentValue"})})),m.field=m.RULE("field",(function(){m.CONSUME(t,{LABEL:"fieldName"}),m.SUBRULE(m.value,{LABEL:"fieldType"}),m.OPTION((function(){m.OR([{ALT:function(){return m.CONSUME(U,{LABEL:"array"})}},{ALT:function(){return m.CONSUME(A,{LABEL:"optional"})}}])})),m.MANY((function(){m.SUBRULE(m.attribute,{LABEL:"attributeList"})}))})),m.block=m.RULE("block",(function(e){var t=(void 0===e?{}:e).componentType,n="enum"===t,r="model"===t;m.CONSUME(v),m.CONSUME1(C),m.MANY((function(){m.OR([{ALT:function(){return m.SUBRULE(m.comment,{LABEL:"list"})}},{GATE:function(){return r},ALT:function(){return m.SUBRULE(m.property,{LABEL:"list"})}},{GATE:function(){return r},ALT:function(){return m.SUBRULE(m.attribute,{LABEL:"list"})}},{GATE:function(){return r},ALT:function(){return m.SUBRULE(m.field,{LABEL:"list"})}},{GATE:function(){return n},ALT:function(){return m.SUBRULE(m.enum,{LABEL:"list"})}},{GATE:function(){return!r},ALT:function(){return m.SUBRULE(m.assignment,{LABEL:"list"})}},{ALT:function(){return m.CONSUME2(C)}}])})),m.CONSUME(y)})),m.enum=m.RULE("enum",(function(){m.CONSUME(t,{LABEL:"enumName"})})),m.attribute=m.RULE("attribute",(function(){m.OR1([{ALT:function(){return m.CONSUME(f,{LABEL:"modelAttribute"})}},{ALT:function(){return m.CONSUME(p,{LABEL:"fieldAttribute"})}}]),m.OR2([{ALT:function(){m.CONSUME1(t,{LABEL:"groupName"}),m.CONSUME(E),m.CONSUME2(t,{LABEL:"attributeName"})}},{ALT:function(){return m.CONSUME(t,{LABEL:"attributeName"})}}]),m.OPTION((function(){m.CONSUME(d),m.MANY_SEP({SEP:N,DEF:function(){m.SUBRULE(m.attributeArg)}}),m.CONSUME(S)}))})),m.attributeArg=m.RULE("attributeArg",(function(){m.OR([{ALT:function(){return m.SUBRULE(m.keyedArg,{LABEL:"value"})}},{ALT:function(){return m.SUBRULE(m.value,{LABEL:"value"})}}])})),m.component=m.RULE("component",(function(){var e=m.OR1([{ALT:function(){return m.CONSUME(n,{LABEL:"type"})}},{ALT:function(){return m.CONSUME(r,{LABEL:"type"})}},{ALT:function(){return m.CONSUME(a,{LABEL:"type"})}},{ALT:function(){return m.CONSUME(u,{LABEL:"type"})}}]);m.OR2([{ALT:function(){m.CONSUME1(t,{LABEL:"groupName"}),m.CONSUME(E),m.CONSUME2(t,{LABEL:"componentName"})}},{ALT:function(){return m.CONSUME(t,{LABEL:"componentName"})}}]),m.SUBRULE(m.block,{ARGS:[{componentType:e.image}]})})),m.comment=m.RULE("comment",(function(){m.CONSUME(l,{LABEL:"text"})})),m.schema=m.RULE("schema",(function(){m.MANY((function(){m.OR([{ALT:function(){return m.SUBRULE(m.comment,{LABEL:"list"})}},{ALT:function(){return m.SUBRULE(m.component,{LABEL:"list"})}},{ALT:function(){return m.CONSUME(C)}}])}))})),m.performSelfAnalysis(),m}return w(m,e),m}(e.CstParser)),_=function(e){function t(){var t;return(t=e.call(this)||this).validateVisitor(),t}w(t,e);var n=t.prototype;return n.schema=function(e){var t,n=this;return{type:"schema",list:null==(t=e.list)?void 0:t.map((function(e){return n.visit([e])}))}},n.component=function(e){var t=e.type[0].image,n=e.componentName[0].image,r=this.visit(e.block);switch(t){case"datasource":return{type:"datasource",name:n,assignments:r};case"generator":return{type:"generator",name:n,assignments:r};case"model":return{type:"model",name:n,properties:r};case"enum":return{type:"enum",name:n,enumerators:r};default:throw new Error("Unexpected block type: "+t)}},n.comment=function(e){return{type:"comment",text:e.text[0].image}},n.block=function(e){var t,n=this;return null==(t=e.list)?void 0:t.map((function(e){return n.visit([e])}))},n.assignment=function(e){var t=this.visit(e.assignmentValue);return{type:"assignment",key:e.assignmentName[0].image,value:t}},n.field=function(e){var t=this,n=this.visit(e.fieldType),r=e.fieldName[0].image,a=e.attributeList&&e.attributeList.map((function(e){return t.visit([e])}));return{type:"field",name:r,fieldType:n,array:null!=e.array,optional:null!=e.optional,attributes:a}},n.attribute=function(e){var t=this,n=e.attributeName[0].image,r=(e.groupName||[{}])[0].image,a=e.attributeArg&&e.attributeArg.map((function(e){return t.visit(e)}));return{type:"attribute",name:n,kind:null!=e.modelAttribute?"model":"field",group:r,args:a}},n.attributeArg=function(e){return{type:"attributeArgument",value:this.visit(e.value)}},n.func=function(e){var t=this;return{type:"function",name:e.funcName[0].image,params:e.value&&e.value.map((function(e){return t.visit([e])}))}},n.array=function(e){var t=this;return{type:"array",args:e.value&&e.value.map((function(e){return t.visit([e])}))}},n.keyedArg=function(e){return{type:"keyValue",key:e.keyName[0].image,value:this.visit(e.value)}},n.value=function(e){return"image"in e.value[0]?e.value[0].image:this.visit(e.value)},n.enum=function(e){return{type:"enumerator",name:e.enumName[0].image}},t}(x.getBaseCstVisitorConstructorWithDefaults());function j(e){switch(e.type){case"comment":return P(e);case"datasource":return n=(t=e).assignments.reduce((function(e,t){return Math.max(e,"assignment"===t.type?t.key.length:0)}),0),r=t.assignments.map((function(e){return D(e,n)})).filter(Boolean).join("\n "),"\ndatasource "+t.name+" {\n "+r+"\n}";case"enum":return function(e){var t=e.enumerators.map((function(e){return"comment"===e.type?P(e):e.name})).filter(Boolean).join("\n ");return"\nenum "+e.name+" {\n "+t+"\n}"}(e);case"generator":return function(e){var t=e.assignments.map(D).filter(Boolean).join("\n ");return"\ngenerator "+e.name+" {\n "+t+"\n}"}(e);case"model":return function(e){var t=e.properties.reduce((function(e,t){return Math.max(e,"field"===t.type?t.name.length:0)}),0),n=e.properties.reduce((function(e,t){return Math.max(e,"field"===t.type?F(t).length:0)}),0),r=e.properties.map((function(e){return function(e,t,n){switch(void 0===t&&(t=0),void 0===n&&(n=0),e.type){case"attribute":return G(e);case"field":return function(e,t,n){void 0===t&&(t=0),void 0===n&&(n=0);var r=e.name.padEnd(t),a=F(e).padEnd(n),u=e.attributes?e.attributes.map(G):[];return[r,a].concat(u).filter(Boolean).join(" ").trim()}(e,t,n);case"comment":return P(e);default:throw new Error("Unrecognized property type")}}(e,t,n)})).filter(Boolean).join("\n ");return"\nmodel "+e.name+" {\n "+r+"\n}"}(e);default:throw new Error("Unrecognized block type")}var t,n,r}function P(e){return e.text}function D(e,t){return void 0===t&&(t=0),"comment"===e.type?P(e):e.key.padEnd(t)+" = "+Y(e.value)}function G(e){var t=e.args&&e.args.length>0?"("+e.args.map(V).filter(Boolean).join(", ")+")":"";return("field"===e.kind?"@":"@@")+e.name+t}function V(e){return Y(e.value)}function F(e){var t=e.array?"[]":e.optional?"?":"";if("object"==typeof e.fieldType)switch(e.fieldType.type){case"function":var n=e.fieldType.params.map(Y);return e.fieldType.name+"("+n+")"+t;default:throw new Error("Unexpected field type")}return""+e.fieldType+t}function Y(e){switch(typeof e){case"object":if("type"in e)switch(e.type){case"keyValue":return e.key+": "+Y(e.value);case"function":return e.name+"("+(e.params?e.params.map(Y):"")+")";case"array":return"["+e.args.join(", ")+"]";default:throw new Error("Unexpected value type")}throw new Error("Unexpected object value");default:return String(e)}}exports.getSchema=function(e){var t=h.tokenize(e);x.input=t.tokens;var n=x.schema();if(x.errors.length>0)throw x.errors[0];return(new _).visit(n)},exports.printSchema=function(e){return e.list.map(j).filter(Boolean).join("\n")}; | ||
//# sourceMappingURL=prisma-ast.cjs.production.min.js.map |
@@ -804,4 +804,4 @@ import { Lexer, createToken, CstParser } from 'chevrotain'; | ||
return printAssignment(assignment, keyLength); | ||
}).filter(Boolean).join('\n '); | ||
return "\n datasource " + db.name + " {\n " + children + "\n }"; | ||
}).filter(Boolean).join('\n '); | ||
return "\ndatasource " + db.name + " {\n " + children + "\n}"; | ||
} | ||
@@ -812,9 +812,9 @@ | ||
return enumerator.type === 'comment' ? printComment(enumerator) : enumerator.name; | ||
}).filter(Boolean).join('\n '); | ||
return "\n enum " + enumerator.name + " {\n " + children + "\n }"; | ||
}).filter(Boolean).join('\n '); | ||
return "\nenum " + enumerator.name + " {\n " + children + "\n}"; | ||
} | ||
function printGenerator(generator) { | ||
var children = generator.assignments.map(printAssignment).filter(Boolean).join('\n '); | ||
return "\n generator " + generator.name + " {\n " + children + "\n }"; | ||
var children = generator.assignments.map(printAssignment).filter(Boolean).join('\n '); | ||
return "\ngenerator " + generator.name + " {\n " + children + "\n}"; | ||
} | ||
@@ -831,4 +831,4 @@ | ||
return printProperty(prop, nameLength, typeLength); | ||
}).filter(Boolean).join('\n '); | ||
return "\n model " + model.name + " {\n " + children + "\n }"; | ||
}).filter(Boolean).join('\n '); | ||
return "\nmodel " + model.name + " {\n " + children + "\n}"; | ||
} | ||
@@ -835,0 +835,0 @@ |
{ | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"license": "MIT", | ||
@@ -4,0 +4,0 @@ "main": "dist/index.js", |
@@ -40,8 +40,8 @@ import * as Types from './getSchema'; | ||
.filter(Boolean) | ||
.join('\n '); | ||
.join('\n '); | ||
return ` | ||
datasource ${db.name} { | ||
${children} | ||
}`; | ||
datasource ${db.name} { | ||
${children} | ||
}`; | ||
} | ||
@@ -55,8 +55,8 @@ | ||
.filter(Boolean) | ||
.join('\n '); | ||
.join('\n '); | ||
return ` | ||
enum ${enumerator.name} { | ||
${children} | ||
}`; | ||
enum ${enumerator.name} { | ||
${children} | ||
}`; | ||
} | ||
@@ -68,8 +68,8 @@ | ||
.filter(Boolean) | ||
.join('\n '); | ||
.join('\n '); | ||
return ` | ||
generator ${generator.name} { | ||
${children} | ||
}`; | ||
generator ${generator.name} { | ||
${children} | ||
}`; | ||
} | ||
@@ -96,8 +96,8 @@ | ||
.filter(Boolean) | ||
.join('\n '); | ||
.join('\n '); | ||
return ` | ||
model ${model.name} { | ||
${children} | ||
}`; | ||
model ${model.name} { | ||
${children} | ||
}`; | ||
} | ||
@@ -104,0 +104,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
217927