Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mrleebo/prisma-ast

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mrleebo/prisma-ast - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

2

dist/prisma-ast.cjs.development.js

@@ -797,3 +797,3 @@ 'use strict';

function printSchema(schema) {
return schema.list.map(printBlock).filter(Boolean).join(os.EOL).replace(/(\r?\n\s*){3,}/g, os.EOL + os.EOL);
return schema.list.map(printBlock).filter(Boolean).join(os.EOL).replace(/(\r?\n\s*){3,}/g, os.EOL + os.EOL) + os.EOL;
}

@@ -800,0 +800,0 @@

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("chevrotain"),t=require("os"),n=e.createToken({name:"Identifier",pattern:/[a-zA-Z]\w*/}),r=e.createToken({name:"Datasource",pattern:/datasource/,longer_alt:n}),a=e.createToken({name:"Generator",pattern:/generator/,longer_alt:n}),u=e.createToken({name:"Model",pattern:/model/,longer_alt:n}),i=e.createToken({name:"Enum",pattern:/enum/,longer_alt:n}),o=e.createToken({name:"True",pattern:/true/,longer_alt:n}),c=e.createToken({name:"False",pattern:/false/,longer_alt:n}),l=e.createToken({name:"Null",pattern:/null/,longer_alt:n}),m=e.createToken({name:"Comment",pattern:e.Lexer.NA}),L=e.createToken({name:"DocComment",pattern:/\/\/\/\s*(.+)/,categories:[m]}),s=e.createToken({name:"LineComment",pattern:/\/\/\s*(.+)/,categories:[m]}),f=e.createToken({name:"Attribute",pattern:e.Lexer.NA}),p=e.createToken({name:"ModelAttribute",pattern:/@@/,label:"'@@'",categories:[f]}),E=e.createToken({name:"FieldAttribute",pattern:/@/,label:"'@'",categories:[f]}),A=e.createToken({name:"Dot",pattern:/\./,label:"'.'"}),U=e.createToken({name:"QuestionMark",pattern:/\?/,label:"'?'"}),y=e.createToken({name:"Array",pattern:/\[\]/,label:"'[]'"}),d=e.createToken({name:"LCurly",pattern:/{/,label:"'{'"}),v=e.createToken({name:"RCurly",pattern:/}/,label:"'}'"}),S=e.createToken({name:"LRound",pattern:/\(/,label:"'('"}),g=e.createToken({name:"RRound",pattern:/\)/,label:"')'"}),T=e.createToken({name:"LSquare",pattern:/\[/,label:"'['"}),b=e.createToken({name:"RSquare",pattern:/\]/,label:"']'"}),B=e.createToken({name:"Comma",pattern:/,/,label:"','"}),N=e.createToken({name:"Colon",pattern:/:/,label:"':'"}),k=e.createToken({name:"Equals",pattern:/=/,label:"'='"}),O=e.createToken({name:"StringLiteral",pattern:/"(:?[^\\"\n\r]+|\\(:?[bfnrtv"\\/]|u[0-9a-fA-F]{4}))*"/}),M=e.createToken({name:"NumberLiteral",pattern:/-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?/}),h=e.createToken({name:"WhiteSpace",pattern:/\s+/,group:e.Lexer.SKIPPED}),C=e.createToken({name:"LineBreak",pattern:/\n|\r\n/,line_breaks:!0,label:"LineBreak"}),R=[m,L,s,C,h,f,p,E,A,U,y,d,v,T,b,S,g,B,N,k,o,c,l,r,a,u,i,O,M,n],w=new e.Lexer(R);function x(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 _=new(function(e){function t(){var t;return(t=e.call(this,R)||this).break=t.RULE("break",(function(){t.CONSUME1(C),t.CONSUME2(C)})),t.keyedArg=t.RULE("keyedArg",(function(){t.CONSUME(n,{LABEL:"keyName"}),t.CONSUME(N),t.SUBRULE(t.value)})),t.array=t.RULE("array",(function(){t.CONSUME(T),t.MANY_SEP({SEP:B,DEF:function(){t.SUBRULE(t.value)}}),t.CONSUME(b)})),t.func=t.RULE("func",(function(){t.CONSUME(n,{LABEL:"funcName"}),t.CONSUME(S),t.MANY_SEP({SEP:B,DEF:function(){t.SUBRULE(t.value)}}),t.CONSUME(g)})),t.value=t.RULE("value",(function(){t.OR([{ALT:function(){return t.CONSUME(O,{LABEL:"value"})}},{ALT:function(){return t.CONSUME(M,{LABEL:"value"})}},{ALT:function(){return t.SUBRULE(t.array,{LABEL:"value"})}},{ALT:function(){return t.SUBRULE(t.func,{LABEL:"value"})}},{ALT:function(){return t.CONSUME(o,{LABEL:"value"})}},{ALT:function(){return t.CONSUME(c,{LABEL:"value"})}},{ALT:function(){return t.CONSUME(l,{LABEL:"value"})}},{ALT:function(){return t.CONSUME(n,{LABEL:"value"})}}])})),t.property=t.RULE("property",(function(){t.CONSUME(n,{LABEL:"propertyName"}),t.CONSUME(k),t.SUBRULE(t.value,{LABEL:"propertyValue"})})),t.assignment=t.RULE("assignment",(function(){t.CONSUME(n,{LABEL:"assignmentName"}),t.CONSUME(k),t.SUBRULE(t.value,{LABEL:"assignmentValue"})})),t.field=t.RULE("field",(function(){t.CONSUME(n,{LABEL:"fieldName"}),t.SUBRULE(t.value,{LABEL:"fieldType"}),t.OPTION((function(){t.OR([{ALT:function(){return t.CONSUME(y,{LABEL:"array"})}},{ALT:function(){return t.CONSUME(U,{LABEL:"optional"})}}])})),t.MANY((function(){t.SUBRULE(t.attribute,{LABEL:"attributeList"})}))})),t.block=t.RULE("block",(function(e){var n=(void 0===e?{}:e).componentType,r="enum"===n,a="model"===n;t.CONSUME(d),t.CONSUME1(C),t.MANY((function(){t.OR([{ALT:function(){return t.SUBRULE(t.comment,{LABEL:"list"})}},{GATE:function(){return a},ALT:function(){return t.SUBRULE(t.property,{LABEL:"list"})}},{GATE:function(){return a},ALT:function(){return t.SUBRULE(t.attribute,{LABEL:"list"})}},{GATE:function(){return a},ALT:function(){return t.SUBRULE(t.field,{LABEL:"list"})}},{GATE:function(){return r},ALT:function(){return t.SUBRULE(t.enum,{LABEL:"list"})}},{GATE:function(){return!a},ALT:function(){return t.SUBRULE(t.assignment,{LABEL:"list"})}},{ALT:function(){return t.SUBRULE(t.break,{LABEL:"list"})}},{ALT:function(){return t.CONSUME2(C)}}])})),t.CONSUME(v)})),t.enum=t.RULE("enum",(function(){t.CONSUME(n,{LABEL:"enumName"})})),t.attribute=t.RULE("attribute",(function(){t.OR1([{ALT:function(){return t.CONSUME(p,{LABEL:"modelAttribute"})}},{ALT:function(){return t.CONSUME(E,{LABEL:"fieldAttribute"})}}]),t.OR2([{ALT:function(){t.CONSUME1(n,{LABEL:"groupName"}),t.CONSUME(A),t.CONSUME2(n,{LABEL:"attributeName"})}},{ALT:function(){return t.CONSUME(n,{LABEL:"attributeName"})}}]),t.OPTION((function(){t.CONSUME(S),t.MANY_SEP({SEP:B,DEF:function(){t.SUBRULE(t.attributeArg)}}),t.CONSUME(g)}))})),t.attributeArg=t.RULE("attributeArg",(function(){t.OR([{ALT:function(){return t.SUBRULE(t.keyedArg,{LABEL:"value"})}},{ALT:function(){return t.SUBRULE(t.value,{LABEL:"value"})}}])})),t.component=t.RULE("component",(function(){var e=t.OR1([{ALT:function(){return t.CONSUME(r,{LABEL:"type"})}},{ALT:function(){return t.CONSUME(a,{LABEL:"type"})}},{ALT:function(){return t.CONSUME(u,{LABEL:"type"})}},{ALT:function(){return t.CONSUME(i,{LABEL:"type"})}}]);t.OR2([{ALT:function(){t.CONSUME1(n,{LABEL:"groupName"}),t.CONSUME(A),t.CONSUME2(n,{LABEL:"componentName"})}},{ALT:function(){return t.CONSUME(n,{LABEL:"componentName"})}}]),t.SUBRULE(t.block,{ARGS:[{componentType:e.image}]})})),t.comment=t.RULE("comment",(function(){t.CONSUME(m,{LABEL:"text"})})),t.schema=t.RULE("schema",(function(){t.MANY((function(){t.OR([{ALT:function(){return t.SUBRULE(t.comment,{LABEL:"list"})}},{ALT:function(){return t.SUBRULE(t.component,{LABEL:"list"})}},{ALT:function(){return t.SUBRULE(t.break,{LABEL:"list"})}},{ALT:function(){return t.CONSUME(C)}}])}))})),t.performSelfAnalysis(),t}return x(t,e),t}(e.CstParser)),j=function(e){function t(){var t;return(t=e.call(this)||this).validateVisitor(),t}x(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.break=function(){return{type:"break"}},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}(_.getBaseCstVisitorConstructorWithDefaults());function P(e){switch(e.type){case"comment":return D(e);case"datasource":return r=I((n=e).assignments),"\ndatasource "+n.name+" {\n "+r+"\n}";case"enum":return function(e){var n=e.enumerators.map(V).filter(Boolean).join(t.EOL+" ").replace(/(\r?\n\s*){3,}/g,t.EOL+t.EOL+" ");return"\nenum "+e.name+" {\n "+n+"\n}"}(e);case"generator":return function(e){var t=I(e.assignments);return"\ngenerator "+e.name+" {\n "+t+"\n}"}(e);case"model":return function(e){var n,r,a,u,i,o=(r=0,a=(n=e.properties).reduce((function(e,t,n,a){return"break"===t.type||(n>0&&"break"===a[n-1].type&&(e[++r]=[]),e[r].push(t)),e}),[[]]),u=a.map((function(e){return e.reduce((function(e,t){return Math.max(e,"field"===t.type?t.name.length:0)}),0)})),i=a.map((function(e){return e.reduce((function(e,t){return Math.max(e,"field"===t.type?q(t).length:0)}),0)})),n.map((function(e,t,n){return t>0&&"break"!==e.type&&"break"===n[t-1].type&&(u.shift(),i.shift()),function(e,t,n){switch(void 0===t&&(t=0),void 0===n&&(n=0),e.type){case"attribute":return F(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=q(e).padEnd(n),u=e.attributes?e.attributes.map(F):[];return[r,a].concat(u).filter(Boolean).join(" ").trim()}(e,t,n);case"comment":return D(e);case"break":return G();default:throw new Error("Unrecognized property type")}}(e,u[0],i[0])})).filter(Boolean).join(t.EOL+" ").replace(/(\r?\n\s*){3,}/g,t.EOL+t.EOL+" "));return"\nmodel "+e.name+" {\n "+o+"\n}"}(e);case"break":return G();default:throw new Error("Unrecognized block type")}var n,r}function D(e){return e.text}function G(){return t.EOL}function V(e){switch(e.type){case"enumerator":return e.name;case"comment":return D(e);case"break":return G();default:throw new Error("Unexpected enumerator type")}}function F(e){var t=e.args&&e.args.length>0?"("+e.args.map(Y).filter(Boolean).join(", ")+")":"";return("field"===e.kind?"@":"@@")+e.name+t}function Y(e){return z(e.value)}function q(e){var t=e.array?"[]":e.optional?"?":"";if("object"==typeof e.fieldType)switch(e.fieldType.type){case"function":var n=e.fieldType.params.map(z);return e.fieldType.name+"("+n+")"+t;default:throw new Error("Unexpected field type")}return""+e.fieldType+t}function z(e){switch(typeof e){case"object":if("type"in e)switch(e.type){case"keyValue":return e.key+": "+z(e.value);case"function":return e.name+"("+(e.params?e.params.map(z):"")+")";case"array":return"["+e.args.join(", ")+"]";default:throw new Error("Unexpected value type")}throw new Error("Unexpected object value");default:return String(e)}}function I(e){var n=0,r=e.reduce((function(e,t,r,a){return"break"===t.type||(r>0&&"break"===a[r-1].type&&(e[++n]=[]),e[n].push(t)),e}),[[]]).map((function(e){return e.reduce((function(e,t){return Math.max(e,"assignment"===t.type?t.key.length:0)}),0)}));return e.map((function(e,t,n){return t>0&&"break"!==e.type&&"break"===n[t-1].type&&r.shift(),function(e,t){switch(void 0===t&&(t=0),e.type){case"comment":return D(e);case"break":return G();case"assignment":return e.key.padEnd(t)+" = "+z(e.value);default:throw new Error("Unexpected assignment type")}}(e,r[0])})).filter(Boolean).join(t.EOL+" ").replace(/(\r?\n\s*){3,}/g,t.EOL+t.EOL+" ")}exports.getSchema=function(e){var t=w.tokenize(e);_.input=t.tokens;var n=_.schema();if(_.errors.length>0)throw _.errors[0];return(new j).visit(n)},exports.printSchema=function(e){return e.list.map(P).filter(Boolean).join(t.EOL).replace(/(\r?\n\s*){3,}/g,t.EOL+t.EOL)};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("chevrotain"),t=require("os"),n=e.createToken({name:"Identifier",pattern:/[a-zA-Z]\w*/}),r=e.createToken({name:"Datasource",pattern:/datasource/,longer_alt:n}),a=e.createToken({name:"Generator",pattern:/generator/,longer_alt:n}),u=e.createToken({name:"Model",pattern:/model/,longer_alt:n}),i=e.createToken({name:"Enum",pattern:/enum/,longer_alt:n}),o=e.createToken({name:"True",pattern:/true/,longer_alt:n}),c=e.createToken({name:"False",pattern:/false/,longer_alt:n}),l=e.createToken({name:"Null",pattern:/null/,longer_alt:n}),m=e.createToken({name:"Comment",pattern:e.Lexer.NA}),L=e.createToken({name:"DocComment",pattern:/\/\/\/\s*(.+)/,categories:[m]}),s=e.createToken({name:"LineComment",pattern:/\/\/\s*(.+)/,categories:[m]}),f=e.createToken({name:"Attribute",pattern:e.Lexer.NA}),p=e.createToken({name:"ModelAttribute",pattern:/@@/,label:"'@@'",categories:[f]}),E=e.createToken({name:"FieldAttribute",pattern:/@/,label:"'@'",categories:[f]}),A=e.createToken({name:"Dot",pattern:/\./,label:"'.'"}),U=e.createToken({name:"QuestionMark",pattern:/\?/,label:"'?'"}),y=e.createToken({name:"Array",pattern:/\[\]/,label:"'[]'"}),d=e.createToken({name:"LCurly",pattern:/{/,label:"'{'"}),v=e.createToken({name:"RCurly",pattern:/}/,label:"'}'"}),S=e.createToken({name:"LRound",pattern:/\(/,label:"'('"}),g=e.createToken({name:"RRound",pattern:/\)/,label:"')'"}),T=e.createToken({name:"LSquare",pattern:/\[/,label:"'['"}),b=e.createToken({name:"RSquare",pattern:/\]/,label:"']'"}),B=e.createToken({name:"Comma",pattern:/,/,label:"','"}),N=e.createToken({name:"Colon",pattern:/:/,label:"':'"}),k=e.createToken({name:"Equals",pattern:/=/,label:"'='"}),O=e.createToken({name:"StringLiteral",pattern:/"(:?[^\\"\n\r]+|\\(:?[bfnrtv"\\/]|u[0-9a-fA-F]{4}))*"/}),M=e.createToken({name:"NumberLiteral",pattern:/-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?/}),h=e.createToken({name:"WhiteSpace",pattern:/\s+/,group:e.Lexer.SKIPPED}),C=e.createToken({name:"LineBreak",pattern:/\n|\r\n/,line_breaks:!0,label:"LineBreak"}),R=[m,L,s,C,h,f,p,E,A,U,y,d,v,T,b,S,g,B,N,k,o,c,l,r,a,u,i,O,M,n],w=new e.Lexer(R);function x(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 _=new(function(e){function t(){var t;return(t=e.call(this,R)||this).break=t.RULE("break",(function(){t.CONSUME1(C),t.CONSUME2(C)})),t.keyedArg=t.RULE("keyedArg",(function(){t.CONSUME(n,{LABEL:"keyName"}),t.CONSUME(N),t.SUBRULE(t.value)})),t.array=t.RULE("array",(function(){t.CONSUME(T),t.MANY_SEP({SEP:B,DEF:function(){t.SUBRULE(t.value)}}),t.CONSUME(b)})),t.func=t.RULE("func",(function(){t.CONSUME(n,{LABEL:"funcName"}),t.CONSUME(S),t.MANY_SEP({SEP:B,DEF:function(){t.SUBRULE(t.value)}}),t.CONSUME(g)})),t.value=t.RULE("value",(function(){t.OR([{ALT:function(){return t.CONSUME(O,{LABEL:"value"})}},{ALT:function(){return t.CONSUME(M,{LABEL:"value"})}},{ALT:function(){return t.SUBRULE(t.array,{LABEL:"value"})}},{ALT:function(){return t.SUBRULE(t.func,{LABEL:"value"})}},{ALT:function(){return t.CONSUME(o,{LABEL:"value"})}},{ALT:function(){return t.CONSUME(c,{LABEL:"value"})}},{ALT:function(){return t.CONSUME(l,{LABEL:"value"})}},{ALT:function(){return t.CONSUME(n,{LABEL:"value"})}}])})),t.property=t.RULE("property",(function(){t.CONSUME(n,{LABEL:"propertyName"}),t.CONSUME(k),t.SUBRULE(t.value,{LABEL:"propertyValue"})})),t.assignment=t.RULE("assignment",(function(){t.CONSUME(n,{LABEL:"assignmentName"}),t.CONSUME(k),t.SUBRULE(t.value,{LABEL:"assignmentValue"})})),t.field=t.RULE("field",(function(){t.CONSUME(n,{LABEL:"fieldName"}),t.SUBRULE(t.value,{LABEL:"fieldType"}),t.OPTION((function(){t.OR([{ALT:function(){return t.CONSUME(y,{LABEL:"array"})}},{ALT:function(){return t.CONSUME(U,{LABEL:"optional"})}}])})),t.MANY((function(){t.SUBRULE(t.attribute,{LABEL:"attributeList"})}))})),t.block=t.RULE("block",(function(e){var n=(void 0===e?{}:e).componentType,r="enum"===n,a="model"===n;t.CONSUME(d),t.CONSUME1(C),t.MANY((function(){t.OR([{ALT:function(){return t.SUBRULE(t.comment,{LABEL:"list"})}},{GATE:function(){return a},ALT:function(){return t.SUBRULE(t.property,{LABEL:"list"})}},{GATE:function(){return a},ALT:function(){return t.SUBRULE(t.attribute,{LABEL:"list"})}},{GATE:function(){return a},ALT:function(){return t.SUBRULE(t.field,{LABEL:"list"})}},{GATE:function(){return r},ALT:function(){return t.SUBRULE(t.enum,{LABEL:"list"})}},{GATE:function(){return!a},ALT:function(){return t.SUBRULE(t.assignment,{LABEL:"list"})}},{ALT:function(){return t.SUBRULE(t.break,{LABEL:"list"})}},{ALT:function(){return t.CONSUME2(C)}}])})),t.CONSUME(v)})),t.enum=t.RULE("enum",(function(){t.CONSUME(n,{LABEL:"enumName"})})),t.attribute=t.RULE("attribute",(function(){t.OR1([{ALT:function(){return t.CONSUME(p,{LABEL:"modelAttribute"})}},{ALT:function(){return t.CONSUME(E,{LABEL:"fieldAttribute"})}}]),t.OR2([{ALT:function(){t.CONSUME1(n,{LABEL:"groupName"}),t.CONSUME(A),t.CONSUME2(n,{LABEL:"attributeName"})}},{ALT:function(){return t.CONSUME(n,{LABEL:"attributeName"})}}]),t.OPTION((function(){t.CONSUME(S),t.MANY_SEP({SEP:B,DEF:function(){t.SUBRULE(t.attributeArg)}}),t.CONSUME(g)}))})),t.attributeArg=t.RULE("attributeArg",(function(){t.OR([{ALT:function(){return t.SUBRULE(t.keyedArg,{LABEL:"value"})}},{ALT:function(){return t.SUBRULE(t.value,{LABEL:"value"})}}])})),t.component=t.RULE("component",(function(){var e=t.OR1([{ALT:function(){return t.CONSUME(r,{LABEL:"type"})}},{ALT:function(){return t.CONSUME(a,{LABEL:"type"})}},{ALT:function(){return t.CONSUME(u,{LABEL:"type"})}},{ALT:function(){return t.CONSUME(i,{LABEL:"type"})}}]);t.OR2([{ALT:function(){t.CONSUME1(n,{LABEL:"groupName"}),t.CONSUME(A),t.CONSUME2(n,{LABEL:"componentName"})}},{ALT:function(){return t.CONSUME(n,{LABEL:"componentName"})}}]),t.SUBRULE(t.block,{ARGS:[{componentType:e.image}]})})),t.comment=t.RULE("comment",(function(){t.CONSUME(m,{LABEL:"text"})})),t.schema=t.RULE("schema",(function(){t.MANY((function(){t.OR([{ALT:function(){return t.SUBRULE(t.comment,{LABEL:"list"})}},{ALT:function(){return t.SUBRULE(t.component,{LABEL:"list"})}},{ALT:function(){return t.SUBRULE(t.break,{LABEL:"list"})}},{ALT:function(){return t.CONSUME(C)}}])}))})),t.performSelfAnalysis(),t}return x(t,e),t}(e.CstParser)),j=function(e){function t(){var t;return(t=e.call(this)||this).validateVisitor(),t}x(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.break=function(){return{type:"break"}},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}(_.getBaseCstVisitorConstructorWithDefaults());function P(e){switch(e.type){case"comment":return D(e);case"datasource":return r=I((n=e).assignments),"\ndatasource "+n.name+" {\n "+r+"\n}";case"enum":return function(e){var n=e.enumerators.map(V).filter(Boolean).join(t.EOL+" ").replace(/(\r?\n\s*){3,}/g,t.EOL+t.EOL+" ");return"\nenum "+e.name+" {\n "+n+"\n}"}(e);case"generator":return function(e){var t=I(e.assignments);return"\ngenerator "+e.name+" {\n "+t+"\n}"}(e);case"model":return function(e){var n,r,a,u,i,o=(r=0,a=(n=e.properties).reduce((function(e,t,n,a){return"break"===t.type||(n>0&&"break"===a[n-1].type&&(e[++r]=[]),e[r].push(t)),e}),[[]]),u=a.map((function(e){return e.reduce((function(e,t){return Math.max(e,"field"===t.type?t.name.length:0)}),0)})),i=a.map((function(e){return e.reduce((function(e,t){return Math.max(e,"field"===t.type?q(t).length:0)}),0)})),n.map((function(e,t,n){return t>0&&"break"!==e.type&&"break"===n[t-1].type&&(u.shift(),i.shift()),function(e,t,n){switch(void 0===t&&(t=0),void 0===n&&(n=0),e.type){case"attribute":return F(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=q(e).padEnd(n),u=e.attributes?e.attributes.map(F):[];return[r,a].concat(u).filter(Boolean).join(" ").trim()}(e,t,n);case"comment":return D(e);case"break":return G();default:throw new Error("Unrecognized property type")}}(e,u[0],i[0])})).filter(Boolean).join(t.EOL+" ").replace(/(\r?\n\s*){3,}/g,t.EOL+t.EOL+" "));return"\nmodel "+e.name+" {\n "+o+"\n}"}(e);case"break":return G();default:throw new Error("Unrecognized block type")}var n,r}function D(e){return e.text}function G(){return t.EOL}function V(e){switch(e.type){case"enumerator":return e.name;case"comment":return D(e);case"break":return G();default:throw new Error("Unexpected enumerator type")}}function F(e){var t=e.args&&e.args.length>0?"("+e.args.map(Y).filter(Boolean).join(", ")+")":"";return("field"===e.kind?"@":"@@")+e.name+t}function Y(e){return z(e.value)}function q(e){var t=e.array?"[]":e.optional?"?":"";if("object"==typeof e.fieldType)switch(e.fieldType.type){case"function":var n=e.fieldType.params.map(z);return e.fieldType.name+"("+n+")"+t;default:throw new Error("Unexpected field type")}return""+e.fieldType+t}function z(e){switch(typeof e){case"object":if("type"in e)switch(e.type){case"keyValue":return e.key+": "+z(e.value);case"function":return e.name+"("+(e.params?e.params.map(z):"")+")";case"array":return"["+e.args.join(", ")+"]";default:throw new Error("Unexpected value type")}throw new Error("Unexpected object value");default:return String(e)}}function I(e){var n=0,r=e.reduce((function(e,t,r,a){return"break"===t.type||(r>0&&"break"===a[r-1].type&&(e[++n]=[]),e[n].push(t)),e}),[[]]).map((function(e){return e.reduce((function(e,t){return Math.max(e,"assignment"===t.type?t.key.length:0)}),0)}));return e.map((function(e,t,n){return t>0&&"break"!==e.type&&"break"===n[t-1].type&&r.shift(),function(e,t){switch(void 0===t&&(t=0),e.type){case"comment":return D(e);case"break":return G();case"assignment":return e.key.padEnd(t)+" = "+z(e.value);default:throw new Error("Unexpected assignment type")}}(e,r[0])})).filter(Boolean).join(t.EOL+" ").replace(/(\r?\n\s*){3,}/g,t.EOL+t.EOL+" ")}exports.getSchema=function(e){var t=w.tokenize(e);_.input=t.tokens;var n=_.schema();if(_.errors.length>0)throw _.errors[0];return(new j).visit(n)},exports.printSchema=function(e){return e.list.map(P).filter(Boolean).join(t.EOL).replace(/(\r?\n\s*){3,}/g,t.EOL+t.EOL)+t.EOL};
//# sourceMappingURL=prisma-ast.cjs.production.min.js.map

@@ -793,3 +793,3 @@ import { Lexer, createToken, CstParser } from 'chevrotain';

function printSchema(schema) {
return schema.list.map(printBlock).filter(Boolean).join(EOL).replace(/(\r?\n\s*){3,}/g, EOL + EOL);
return schema.list.map(printBlock).filter(Boolean).join(EOL).replace(/(\r?\n\s*){3,}/g, EOL + EOL) + EOL;
}

@@ -796,0 +796,0 @@

{
"version": "0.2.2",
"version": "0.2.3",
"license": "MIT",

@@ -4,0 +4,0 @@ "main": "dist/index.js",

@@ -5,7 +5,9 @@ import * as Types from './getSchema';

export function printSchema(schema: Types.Schema): string {
return schema.list
.map(printBlock)
.filter(Boolean)
.join(EOL)
.replace(/(\r?\n\s*){3,}/g, EOL + EOL);
return (
schema.list
.map(printBlock)
.filter(Boolean)
.join(EOL)
.replace(/(\r?\n\s*){3,}/g, EOL + EOL) + EOL
);
}

@@ -12,0 +14,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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc