@mrleebo/prisma-ast
Advanced tools
Comparing version 0.8.1 to 0.9.0
@@ -12,5 +12,5 @@ import { PrismaVisitor } from './visitor'; | ||
} | ||
export type Block = Model | View | Datasource | Generator | Enum | Comment | Break; | ||
export type Block = Model | View | Datasource | Generator | Enum | Comment | Break | Type; | ||
export interface Object { | ||
type: 'model' | 'view'; | ||
type: 'model' | 'view' | 'type'; | ||
name: string; | ||
@@ -27,2 +27,6 @@ properties: Array<Property | Comment | Break>; | ||
} | ||
export interface Type extends Object { | ||
type: 'type'; | ||
location?: CstNodeLocation; | ||
} | ||
export interface Datasource { | ||
@@ -67,3 +71,3 @@ type: 'datasource'; | ||
type: 'attribute'; | ||
kind: 'object' | 'view'; | ||
kind: 'object' | 'view' | 'type'; | ||
group?: string; | ||
@@ -70,0 +74,0 @@ name: string; |
@@ -8,2 +8,3 @@ import { Lexer, IMultiModeLexerDefinition } from 'chevrotain'; | ||
export declare const Enum: import("chevrotain").TokenType; | ||
export declare const Type: import("chevrotain").TokenType; | ||
export declare const True: import("chevrotain").TokenType; | ||
@@ -10,0 +11,0 @@ export declare const False: import("chevrotain").TokenType; |
import * as Types from './getSchema'; | ||
type Block = 'generator' | 'datasource' | 'model' | 'view' | 'enum' | 'type'; | ||
export interface PrintOptions { | ||
sort?: boolean; | ||
locales?: string | string[]; | ||
sortOrder?: Array<'generator' | 'datasource' | 'model' | 'view' | 'enum'>; | ||
sortOrder?: Block[]; | ||
} | ||
export declare function printSchema(schema: Types.Schema, options?: PrintOptions): string; | ||
export {}; |
@@ -38,2 +38,7 @@ 'use strict'; | ||
}); | ||
var Type = /*#__PURE__*/chevrotain.createToken({ | ||
name: 'Type', | ||
pattern: /type/, | ||
push_mode: 'block' | ||
}); | ||
var True = /*#__PURE__*/chevrotain.createToken({ | ||
@@ -162,3 +167,3 @@ name: 'True', | ||
modes: { | ||
global: /*#__PURE__*/[].concat(naTokens, [Datasource, Generator, Model, View, Enum]), | ||
global: /*#__PURE__*/[].concat(naTokens, [Datasource, Generator, Model, View, Enum, Type]), | ||
block: /*#__PURE__*/[].concat(naTokens, [Attribute, BlockAttribute, FieldAttribute, Dot, QuestionMark, LCurly, RCurly, LSquare, RSquare, LRound, RRound, Comma, Colon, Equals, True, False, Null, StringLiteral, NumberLiteral, Identifier]) | ||
@@ -183,3 +188,3 @@ }, | ||
var schemaObjects = ['model', 'view']; | ||
var schemaObjects = ['model', 'view', 'type']; | ||
function isSchemaObject(obj) { | ||
@@ -397,3 +402,3 @@ return obj != null && 'type' in obj && schemaObjects.includes(obj.type); | ||
var isEnum = componentType === 'enum'; | ||
var isObject = componentType === 'model' || componentType === 'view'; | ||
var isObject = componentType === 'model' || componentType === 'view' || componentType === 'type'; | ||
_this.CONSUME(LCurly); | ||
@@ -562,2 +567,8 @@ _this.CONSUME1(LineBreak); | ||
} | ||
}, { | ||
ALT: function ALT() { | ||
return _this.CONSUME(Type, { | ||
LABEL: 'type' | ||
}); | ||
} | ||
}]); | ||
@@ -687,2 +698,8 @@ _this.OR2([{ | ||
}; | ||
case 'type': | ||
return { | ||
type: 'type', | ||
name: name.image, | ||
properties: list | ||
}; | ||
default: | ||
@@ -912,2 +929,3 @@ throw new Error("Unexpected block type: " + type); | ||
case 'view': | ||
case 'type': | ||
return printObject(block); | ||
@@ -1193,2 +1211,14 @@ case 'break': | ||
}; | ||
_proto.type = function type(name) { | ||
var type = this.schema.list.reduce(function (memo, block) { | ||
return block.type === 'type' && block.name === name ? block : memo; | ||
}, { | ||
type: 'type', | ||
name: name, | ||
properties: [] | ||
}); | ||
if (!this.schema.list.includes(type)) this.schema.list.push(type); | ||
this._subject = type; | ||
return this; | ||
}; | ||
_proto["enum"] = function _enum(name, enumeratorNames) { | ||
@@ -1235,3 +1265,3 @@ if (enumeratorNames === void 0) { | ||
var parent = this.getParent(); | ||
if (!isSchemaObject(parent)) throw new Error('Subject must be a prisma model or view!'); | ||
if (!isSchemaObject(parent)) throw new Error('Subject must be a prisma model, view, or type!'); | ||
subject = this._subject = parent; | ||
@@ -1362,3 +1392,3 @@ } | ||
var subject = this.getSubject(); | ||
var allowed = ['datasource', 'enum', 'generator', 'model', 'view']; | ||
var allowed = ['datasource', 'enum', 'generator', 'model', 'view', 'type']; | ||
if (!subject || !('type' in subject) || !allowed.includes(subject.type)) { | ||
@@ -1429,3 +1459,3 @@ var parent = this.getParent(); | ||
var parent = this.getParent(); | ||
if (!isSchemaObject(parent)) throw new Error('Subject must be a prisma model or view!'); | ||
if (!isSchemaObject(parent)) throw new Error('Subject must be a prisma model or view or composite type!'); | ||
subject = this._subject = parent; | ||
@@ -1449,3 +1479,3 @@ } | ||
var parent = this.getParent(); | ||
if (!isSchemaObject(parent)) throw new Error('Subject must be a prisma model or view!'); | ||
if (!isSchemaObject(parent)) throw new Error('Subject must be a prisma model or view or composite type!'); | ||
subject = this._subject = parent; | ||
@@ -1452,0 +1482,0 @@ } |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("chevrotain"),t=require("lilconfig"),n=require("os"),r=e.createToken({name:"Identifier",pattern:/[a-zA-Z]\w*/}),a=e.createToken({name:"Datasource",pattern:/datasource/,push_mode:"block"}),i=e.createToken({name:"Generator",pattern:/generator/,push_mode:"block"}),u=e.createToken({name:"Model",pattern:/model/,push_mode:"block"}),o=e.createToken({name:"View",pattern:/view/,push_mode:"block"}),s=e.createToken({name:"Enum",pattern:/enum/,push_mode:"block"}),c=e.createToken({name:"True",pattern:/true/,longer_alt:r}),m=e.createToken({name:"False",pattern:/false/,longer_alt:r}),l=e.createToken({name:"Null",pattern:/null/,longer_alt:r}),p=e.createToken({name:"Comment",pattern:e.Lexer.NA}),f=e.createToken({name:"DocComment",pattern:/\/\/\/[ \t]*(.*)/,categories:[p]}),L=e.createToken({name:"LineComment",pattern:/\/\/[ \t]*(.*)/,categories:[p]}),d=e.createToken({name:"Attribute",pattern:e.Lexer.NA}),y=e.createToken({name:"BlockAttribute",pattern:/@@/,label:"'@@'",categories:[d]}),v=e.createToken({name:"FieldAttribute",pattern:/@/,label:"'@'",categories:[d]}),h=e.createToken({name:"Dot",pattern:/\./,label:"'.'"}),E=e.createToken({name:"QuestionMark",pattern:/\?/,label:"'?'"}),b=e.createToken({name:"LCurly",pattern:/{/,label:"'{'"}),g=e.createToken({name:"RCurly",pattern:/}/,label:"'}'",pop_mode:!0}),A=e.createToken({name:"LRound",pattern:/\(/,label:"'('"}),U=e.createToken({name:"RRound",pattern:/\)/,label:"')'"}),k=e.createToken({name:"LSquare",pattern:/\[/,label:"'['"}),S=e.createToken({name:"RSquare",pattern:/\]/,label:"']'"}),O=e.createToken({name:"Comma",pattern:/,/,label:"','"}),T=e.createToken({name:"Colon",pattern:/:/,label:"':'"}),B=e.createToken({name:"Equals",pattern:/=/,label:"'='"}),N=e.createToken({name:"StringLiteral",pattern:/"(:?[^\\"\n\r]|\\(:?[bfnrtv"\\/]|u[0-9a-fA-F]{4}))*"/}),C=e.createToken({name:"NumberLiteral",pattern:/-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?/}),w=e.createToken({name:"WhiteSpace",pattern:/\s+/,group:e.Lexer.SKIPPED}),M=e.createToken({name:"LineBreak",pattern:/\n|\r\n/,line_breaks:!0,label:"LineBreak"}),j=[p,f,L,M,w],R={modes:{global:[].concat(j,[a,i,u,o,s]),block:[].concat(j,[d,y,v,h,E,b,g,k,S,A,U,O,T,B,c,m,l,N,C,r])},defaultMode:"global"},_=new e.Lexer(R);function x(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,P(e,t)}function P(e,t){return P=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},P(e,t)}var D=["model","view"];function I(e){return null!=e&&"type"in e&&D.includes(e.type)}function V(e){return null!=e&&"type"in e&&"field"===e.type}function F(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];var a=n.reduce((function(e,t){if(!t)return e;var n=e.endColumn,r=void 0===n?-Infinity:n,a=e.endLine,i=void 0===a?-Infinity:a,u=e.endOffset,o=void 0===u?-Infinity:u,s=e.startColumn,c=void 0===s?Infinity:s,m=e.startLine,l=e.startOffset,p=void 0===l?Infinity:l;return null!=t.startLine&&t.startLine<(void 0===m?Infinity:m)&&(e.startLine=t.startLine),null!=t.startColumn&&t.startColumn<c&&(e.startColumn=t.startColumn),null!=t.startOffset&&t.startOffset<p&&(e.startOffset=t.startOffset),null!=t.endLine&&t.endLine>i&&(e.endLine=t.endLine),null!=t.endColumn&&t.endColumn>r&&(e.endColumn=t.endColumn),null!=t.endOffset&&t.endOffset>o&&(e.endOffset=t.endOffset),e}),{});return Object.assign(e,{location:a})}var q,G={parser:{nodeLocationTracking:"none"}},Y=function(e){function t(t){var n;return(n=e.call(this,R,t)||this).config=void 0,n.break=n.RULE("break",(function(){n.CONSUME1(M),n.CONSUME2(M)})),n.keyedArg=n.RULE("keyedArg",(function(){n.CONSUME(r,{LABEL:"keyName"}),n.CONSUME(T),n.SUBRULE(n.value)})),n.array=n.RULE("array",(function(){n.CONSUME(k),n.MANY_SEP({SEP:O,DEF:function(){n.SUBRULE(n.value)}}),n.CONSUME(S)})),n.func=n.RULE("func",(function(){n.CONSUME(r,{LABEL:"funcName"}),n.CONSUME(A),n.MANY_SEP({SEP:O,DEF:function(){n.OR([{ALT:function(){return n.SUBRULE(n.keyedArg)}},{ALT:function(){return n.SUBRULE(n.value)}}])}}),n.CONSUME(U)})),n.value=n.RULE("value",(function(){n.OR([{ALT:function(){return n.CONSUME(N,{LABEL:"value"})}},{ALT:function(){return n.CONSUME(C,{LABEL:"value"})}},{ALT:function(){return n.SUBRULE(n.array,{LABEL:"value"})}},{ALT:function(){return n.SUBRULE(n.func,{LABEL:"value"})}},{ALT:function(){return n.CONSUME(c,{LABEL:"value"})}},{ALT:function(){return n.CONSUME(m,{LABEL:"value"})}},{ALT:function(){return n.CONSUME(l,{LABEL:"value"})}},{ALT:function(){return n.CONSUME(r,{LABEL:"value"})}}])})),n.property=n.RULE("property",(function(){n.CONSUME(r,{LABEL:"propertyName"}),n.CONSUME(B),n.SUBRULE(n.value,{LABEL:"propertyValue"})})),n.assignment=n.RULE("assignment",(function(){n.CONSUME(r,{LABEL:"assignmentName"}),n.CONSUME(B),n.SUBRULE(n.value,{LABEL:"assignmentValue"})})),n.field=n.RULE("field",(function(){n.CONSUME(r,{LABEL:"fieldName"}),n.SUBRULE(n.value,{LABEL:"fieldType"}),n.OPTION1((function(){n.OR([{ALT:function(){n.CONSUME(k,{LABEL:"array"}),n.CONSUME(S,{LABEL:"array"})}},{ALT:function(){return n.CONSUME(E,{LABEL:"optional"})}}])})),n.MANY((function(){n.SUBRULE(n.attribute,{LABEL:"attributeList"})})),n.OPTION2((function(){n.CONSUME(p,{LABEL:"comment"})}))})),n.block=n.RULE("block",(function(e){void 0===e&&(e={});var t=e.componentType,r="enum"===t,a="model"===t||"view"===t;n.CONSUME(b),n.CONSUME1(M),n.MANY((function(){n.OR([{ALT:function(){return n.SUBRULE(n.comment,{LABEL:"list"})}},{GATE:function(){return a},ALT:function(){return n.SUBRULE(n.property,{LABEL:"list"})}},{ALT:function(){return n.SUBRULE(n.attribute,{LABEL:"list"})}},{GATE:function(){return a},ALT:function(){return n.SUBRULE(n.field,{LABEL:"list"})}},{GATE:function(){return r},ALT:function(){return n.SUBRULE(n.enum,{LABEL:"list"})}},{GATE:function(){return!a},ALT:function(){return n.SUBRULE(n.assignment,{LABEL:"list"})}},{ALT:function(){return n.SUBRULE(n.break,{LABEL:"list"})}},{ALT:function(){return n.CONSUME2(M)}}])})),n.CONSUME(g)})),n.enum=n.RULE("enum",(function(){n.CONSUME(r,{LABEL:"enumName"}),n.OPTION((function(){n.CONSUME(p,{LABEL:"comment"})}))})),n.attribute=n.RULE("attribute",(function(){n.OR1([{ALT:function(){return n.CONSUME(y,{LABEL:"blockAttribute"})}},{ALT:function(){return n.CONSUME(v,{LABEL:"fieldAttribute"})}}]),n.OR2([{ALT:function(){n.CONSUME1(r,{LABEL:"groupName"}),n.CONSUME(h),n.CONSUME2(r,{LABEL:"attributeName"})}},{ALT:function(){return n.CONSUME(r,{LABEL:"attributeName"})}}]),n.OPTION((function(){n.CONSUME(A),n.MANY_SEP({SEP:O,DEF:function(){n.SUBRULE(n.attributeArg)}}),n.CONSUME(U)}))})),n.attributeArg=n.RULE("attributeArg",(function(){n.OR([{ALT:function(){return n.SUBRULE(n.keyedArg,{LABEL:"value"})}},{ALT:function(){return n.SUBRULE(n.value,{LABEL:"value"})}}])})),n.component=n.RULE("component",(function(){var e=n.OR1([{ALT:function(){return n.CONSUME(a,{LABEL:"type"})}},{ALT:function(){return n.CONSUME(i,{LABEL:"type"})}},{ALT:function(){return n.CONSUME(u,{LABEL:"type"})}},{ALT:function(){return n.CONSUME(o,{LABEL:"type"})}},{ALT:function(){return n.CONSUME(s,{LABEL:"type"})}}]);n.OR2([{ALT:function(){n.CONSUME1(r,{LABEL:"groupName"}),n.CONSUME(h),n.CONSUME2(r,{LABEL:"componentName"})}},{ALT:function(){return n.CONSUME(r,{LABEL:"componentName"})}}]),n.SUBRULE(n.block,{ARGS:[{componentType:e.image}]})})),n.comment=n.RULE("comment",(function(){n.CONSUME(p,{LABEL:"text"})})),n.schema=n.RULE("schema",(function(){n.MANY((function(){n.OR([{ALT:function(){return n.SUBRULE(n.comment,{LABEL:"list"})}},{ALT:function(){return n.SUBRULE(n.component,{LABEL:"list"})}},{ALT:function(){return n.SUBRULE(n.break,{LABEL:"list"})}},{ALT:function(){return n.CONSUME(M)}}])}))})),n.performSelfAnalysis(),n.config=t,n}return x(t,e),t}(e.CstParser),z=new Y(function(){if(null!=q)return q;var e=t.lilconfigSync("prisma-ast").search();return q=Object.assign(G,null==e?void 0:e.config)}().parser),W=function(e){return function(t){function n(){var e;return(e=t.call(this)||this).validateVisitor(),e}x(n,t);var r=n.prototype;return r.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])})))||[]}},r.component=function(e){var t=e.type[0],n=e.componentName[0],r=this.visit(e.block),a=function(){switch(t.image){case"datasource":return{type:"datasource",name:n.image,assignments:r};case"generator":return{type:"generator",name:n.image,assignments:r};case"model":return{type:"model",name:n.image,properties:r};case"view":return{type:"view",name:n.image,properties:r};case"enum":return{type:"enum",name:n.image,enumerators:r};default:throw new Error("Unexpected block type: "+t)}}();return this.maybeAppendLocationData(a,t,n)},r.break=function(){return{type:"break"}},r.comment=function(e){var t=e.text[0];return this.maybeAppendLocationData({type:"comment",text:t.image},t)},r.block=function(e){var t,n=this;return null==(t=e.list)?void 0:t.map((function(e){return n.visit([e])}))},r.assignment=function(e){var t=this.visit(e.assignmentValue),n=e.assignmentName[0];return this.maybeAppendLocationData({type:"assignment",key:n.image,value:t},n)},r.field=function(e){var t,n,r,a=this,i=this.visit(e.fieldType),u=e.fieldName[0],o=e.attributeList&&e.attributeList.map((function(e){return a.visit([e])})),s=null==(t=e.comment)||null==(t=t[0])?void 0:t.image;return this.maybeAppendLocationData({type:"field",name:u.image,fieldType:i,array:null!=e.array,optional:null!=e.optional,attributes:o,comment:s},u,null==(n=e.optional)?void 0:n[0],null==(r=e.array)?void 0:r[0])},r.attribute=function(e){var t=this,n=e.attributeName[0],r=(e.groupName||[{}])[0],a=e.attributeArg&&e.attributeArg.map((function(e){return t.visit(e)})),i=null!=e.blockAttribute?"object":"field";return this.maybeAppendLocationData.apply(this,[{type:"attribute",name:n.image,kind:i,group:r.image,args:a},n].concat("object"===i?e.blockAttribute:e.fieldAttribute,[r]))},r.attributeArg=function(e){return{type:"attributeArgument",value:this.visit(e.value)}},r.func=function(e){var t=this,n=e.funcName[0],r=e.value&&e.value.map((function(e){return t.visit([e])})),a=e.keyedArg&&e.keyedArg.map((function(e){return t.visit([e])})),i=(r||a)&&[].concat(null!=r?r:[],null!=a?a:[]);return this.maybeAppendLocationData({type:"function",name:n.image,params:i},n)},r.array=function(e){var t=this;return{type:"array",args:e.value&&e.value.map((function(e){return t.visit([e])}))}},r.keyedArg=function(e){var t=e.keyName[0],n=this.visit(e.value);return this.maybeAppendLocationData({type:"keyValue",key:t.image,value:n},t)},r.value=function(e){return"image"in e.value[0]?e.value[0].image:this.visit(e.value)},r.enum=function(e){var t,n=e.enumName[0],r=null==(t=e.comment)||null==(t=t[0])?void 0:t.image;return this.maybeAppendLocationData({type:"enumerator",name:n.image,comment:r},n)},r.maybeAppendLocationData=function(t){if("none"===e.config.nodeLocationTracking)return t;for(var n=arguments.length,r=new Array(n>1?n-1:0),a=1;a<n;a++)r[a-1]=arguments[a];return F.apply(void 0,[t].concat(r))},n}(e.getBaseCstVisitorConstructorWithDefaults())},K=new(W(z));function Q(e,t){var n,r,a=_.tokenize(e),i=null!=(n=null==t?void 0:t.parser)?n:z;i.input=a.tokens;var u=i.schema();if(i.errors.length>0)throw i.errors[0];return(null!=(r=null==t?void 0:t.visitor)?r:K).visit(u)}var Z=["break","comment"],H=["generator","datasource","model","view","enum","break","comment"];function J(e,t){void 0===t&&(t={});var r=t.sort,a=t.locales,i=void 0===a?void 0:a,u=t.sortOrder,o=void 0===u?void 0:u,s=e.list;if(void 0!==r&&r){s=e.list=s.filter((function(e){return"break"!==e.type}));var c=function(e,t,n){return void 0===n&&(n=H),function(r,a){if(-1!==Z.indexOf(r.type)!=(-1!==Z.indexOf(a.type)))return e.list.indexOf(r)-e.list.indexOf(a);n!==H&&(n=n.concat(H));var i=n.indexOf(r.type)-n.indexOf(a.type);return 0!==i?i:"name"in r&&"name"in a?r.name.localeCompare(a.name,t):0}}(e,i,o);s.sort(c)}return s.map(X).filter(Boolean).join(n.EOL).replace(/(\r?\n\s*){3,}/g,n.EOL+n.EOL)+n.EOL}function X(e){switch(e.type){case"comment":return $(e);case"datasource":return r=oe((t=e).assignments),"\ndatasource "+t.name+" {\n "+r+"\n}";case"enum":return function(e){var t=e.enumerators.map(te).filter(Boolean).join(n.EOL+" ").replace(/(\r?\n\s*){3,}/g,n.EOL+n.EOL+" ");return"\nenum "+e.name+" {\n "+t+"\n}"}(e);case"generator":return function(e){var t=oe(e.assignments);return"\ngenerator "+e.name+" {\n "+t+"\n}"}(e);case"model":case"view":return function(e){var t,r,a,i,u,o=(r=0,a=(t=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}),[[]]),i=a.map((function(e){return e.reduce((function(e,t){return Math.max(e,"field"===t.type?t.name.length:0)}),0)})),u=a.map((function(e){return e.reduce((function(e,t){return Math.max(e,"field"===t.type?ae(t).length:0)}),0)})),t.map((function(e,t,n){return t>0&&"break"!==e.type&&"break"===n[t-1].type&&(i.shift(),u.shift()),function(e,t,n){switch(void 0===t&&(t=0),void 0===n&&(n=0),e.type){case"attribute":return ne(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=ae(e).padEnd(n),i=e.attributes?e.attributes.map(ne):[],u=e.comment;return[r,a].concat(i).filter(Boolean).join(" ").trim()+(u?" "+u:"")}(e,t,n);case"comment":return $(e);case"break":return ee();default:throw new Error("Unrecognized property type")}}(e,i[0],u[0])})).filter(Boolean).join(n.EOL+" ").replace(/(\r?\n\s*){3,}/g,n.EOL+n.EOL+" "));return"\n"+e.type+" "+e.name+" {\n "+o+"\n}"}(e);case"break":return ee();default:throw new Error("Unrecognized block type")}var t,r}function $(e){return e.text}function ee(){return n.EOL}function te(e){switch(e.type){case"enumerator":return[e.name,e.comment].filter(Boolean).join(" ");case"attribute":return ne(e);case"comment":return $(e);case"break":return ee();default:throw new Error("Unexpected enumerator type")}}function ne(e){var t=e.args&&e.args.length>0?"("+e.args.map(re).filter(Boolean).join(", ")+")":"",n=[e.name];return e.group&&n.unshift(e.group),("field"===e.kind?"@":"@@")+n.join(".")+t}function re(e){return ue(e.value)}function ae(e){var t=e.array?"[]":e.optional?"?":"";if("object"==typeof e.fieldType){if("function"===e.fieldType.type)return""+ie(e.fieldType)+t;throw new Error("Unexpected field type")}return""+e.fieldType+t}function ie(e){var t=e.params?e.params.map(ue):"";return e.name+"("+t+")"}function ue(e){if("object"==typeof e){if("type"in e)switch(e.type){case"keyValue":return e.key+": "+ue(e.value);case"function":return ie(e);case"array":return"["+(null!=e.args?e.args.map(ue).join(", "):"")+"]";default:throw new Error("Unexpected value type")}throw new Error("Unexpected object value")}return String(e)}function oe(e){var t=0,r=e.reduce((function(e,n,r,a){return"break"===n.type||(r>0&&"break"===a[r-1].type&&(e[++t]=[]),e[t].push(n)),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 $(e);case"break":return ee();case"assignment":return e.key.padEnd(t)+" = "+ue(e.value);default:throw new Error("Unexpected assignment type")}}(e,r[0])})).filter(Boolean).join(n.EOL+" ").replace(/(\r?\n\s*){3,}/g,n.EOL+n.EOL+" ")}var se=function(){function e(e){void 0===e&&(e=""),this.schema=void 0,this._subject=void 0,this._parent=void 0,this.schema=Q(e)}var t=e.prototype;return t.print=function(e){return void 0===e&&(e={}),J(this.schema,e)},t.getSchema=function(){return this.schema},t.generator=function(e,t){void 0===t&&(t="prisma-client-js");var n=this.schema.list.reduce((function(t,n){return"generator"===n.type&&n.name===e?n:t}),{type:"generator",name:e,assignments:[{type:"assignment",key:"provider",value:'"'+t+'"'}]});return this.schema.list.includes(n)||this.schema.list.push(n),this._subject=n,this},t.drop=function(e){var t=this.schema.list.findIndex((function(t){return"name"in t&&t.name===e}));return-1!==t&&this.schema.list.splice(t,1),this},t.datasource=function(e,t){var n={type:"datasource",name:"db",assignments:[{type:"assignment",key:"url",value:"string"==typeof t?'"'+t+'"':{type:"function",name:"env",params:['"'+t.env+'"']}},{type:"assignment",key:"provider",value:e}]},r=this.schema.list.findIndex((function(e){return"datasource"===e.type}));return this.schema.list.splice(r,-1!==r?1:0,n),this._subject=n,this},t.model=function(e){var t=this.schema.list.reduce((function(t,n){return"model"===n.type&&n.name===e?n:t}),{type:"model",name:e,properties:[]});return this.schema.list.includes(t)||this.schema.list.push(t),this._subject=t,this},t.view=function(e){var t=this.schema.list.reduce((function(t,n){return"view"===n.type&&n.name===e?n:t}),{type:"view",name:e,properties:[]});return this.schema.list.includes(t)||this.schema.list.push(t),this._subject=t,this},t.enum=function(e,t){void 0===t&&(t=[]);var n=this.schema.list.reduce((function(t,n){return"enum"===n.type&&n.name===e?n:t}),{type:"enum",name:e,enumerators:t.map((function(e){return{type:"enumerator",name:e}}))});return this.schema.list.includes(n)||this.schema.list.push(n),this._subject=n,this},t.enumerator=function(e){var t=this.getSubject();if(!t||!("type"in t)||"enum"!==t.type)throw new Error("Subject must be a prisma enum!");return t.enumerators.push({type:"enumerator",name:e}),this},t.getSubject=function(){return this._subject},t.getParent=function(){return this._parent},t.blockAttribute=function(e,t){var n=this.getSubject();if(!I(n)){var r=this.getParent();if(!I(r))throw new Error("Subject must be a prisma model or view!");n=this._subject=r}var a=t?"string"==typeof t?[{type:"attributeArgument",value:'"'+t+'"'}]:Array.isArray(t)?[{type:"attributeArgument",value:{type:"array",args:t}}]:Object.entries(t).map((function(e){return{type:"attributeArgument",value:{type:"keyValue",key:e[0],value:e[1]}}})):[];return n.properties.push({type:"attribute",kind:"object",name:e,args:a}),this},t.attribute=function(e,t){var n=this.getParent(),r=this.getSubject();if(!I(n))throw new Error("Parent must be a prisma model or view!");if(!V(r))throw new Error("Subject must be a prisma field!");r.attributes||(r.attributes=[]);var a=r.attributes.reduce((function(t,n){return"attribute"===n.type&&(n.group?n.group+".":"")+n.name===e?n:t}),{type:"attribute",kind:"field",name:e});if(Array.isArray(t)){var i=function e(t){var n,r;return"string"==typeof t?t:{type:"function",name:t.name,params:null!=(n=null==(r=t.function)?void 0:r.map(e))?n:[]}};t.length>0&&(a.args=t.map((function(e){return{type:"attributeArgument",value:i(e)}})))}else"object"==typeof t&&(a.args=Object.entries(t).map((function(e){return{type:"attributeArgument",value:{type:"keyValue",key:e[0],value:{type:"array",args:e[1]}}}})));return r.attributes.includes(a)||r.attributes.push(a),this},t.removeAttribute=function(e){var t=this.getParent(),n=this.getSubject();if(!I(t))throw new Error("Parent must be a prisma model or view!");if(!V(n))throw new Error("Subject must be a prisma field!");return n.attributes||(n.attributes=[]),n.attributes=n.attributes.filter((function(t){return!("attribute"===t.type&&t.name===e)})),this},t.assignment=function(e,t){var n=this.getSubject();if(!n||!("type"in n)||!["generator","datasource"].includes(n.type))throw new Error("Subject must be a prisma generator or datasource!");var r=n.assignments.reduce((function(n,r){return"assignment"===r.type&&r.key===e?function(e,n){return e.value='"'+t+'"',e}(r):n}),{type:"assignment",key:e,value:'"'+t+'"'});return n.assignments.includes(r)||n.assignments.push(r),this},t.blockInsert=function(e){var t=this.getSubject(),n=["datasource","enum","generator","model","view"];if(!t||!("type"in t)||!n.includes(t.type)){var r=this.getParent();if(!r||!("type"in r)||!n.includes(r.type))throw new Error("Subject must be a prisma block!");t=this._subject=r}switch(t.type){case"datasource":case"generator":t.assignments.push(e);break;case"enum":t.enumerators.push(e);break;case"model":t.properties.push(e)}return this},t.break=function(){return this.blockInsert({type:"break"})},t.comment=function(e,t){return void 0===t&&(t=!1),this.blockInsert({type:"comment",text:"//"+(t?"/":"")+" "+e})},t.schemaComment=function(e,t){return void 0===t&&(t=!1),this.schema.list.push({type:"comment",text:"//"+(t?"/":"")+" "+e}),this},t.field=function(e,t){void 0===t&&(t="String");var n=this.getSubject();if(!I(n)){var r=this.getParent();if(!I(r))throw new Error("Subject must be a prisma model or view!");n=this._subject=r}var a=n.properties.reduce((function(t,n){return"field"===n.type&&n.name===e?n:t}),{type:"field",name:e,fieldType:t});return n.properties.includes(a)||n.properties.push(a),this._parent=n,this._subject=a,this},t.removeField=function(e){var t=this.getSubject();if(!I(t)){var n=this.getParent();if(!I(n))throw new Error("Subject must be a prisma model or view!");t=this._subject=n}return t.properties=t.properties.filter((function(t){return!("field"===t.type&&t.name===e)})),this},t.then=function(e){return e(this._subject),this},e}();exports.ConcretePrismaSchemaBuilder=se,exports.PrismaParser=Y,exports.VisitorClassFactory=W,exports.createPrismaSchemaBuilder=function(e){return new se(e)},exports.getSchema=Q,exports.printSchema=J; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("chevrotain"),t=require("lilconfig"),n=require("os"),r=e.createToken({name:"Identifier",pattern:/[a-zA-Z]\w*/}),a=e.createToken({name:"Datasource",pattern:/datasource/,push_mode:"block"}),i=e.createToken({name:"Generator",pattern:/generator/,push_mode:"block"}),u=e.createToken({name:"Model",pattern:/model/,push_mode:"block"}),o=e.createToken({name:"View",pattern:/view/,push_mode:"block"}),s=e.createToken({name:"Enum",pattern:/enum/,push_mode:"block"}),c=e.createToken({name:"Type",pattern:/type/,push_mode:"block"}),m=e.createToken({name:"True",pattern:/true/,longer_alt:r}),p=e.createToken({name:"False",pattern:/false/,longer_alt:r}),l=e.createToken({name:"Null",pattern:/null/,longer_alt:r}),f=e.createToken({name:"Comment",pattern:e.Lexer.NA}),L=e.createToken({name:"DocComment",pattern:/\/\/\/[ \t]*(.*)/,categories:[f]}),d=e.createToken({name:"LineComment",pattern:/\/\/[ \t]*(.*)/,categories:[f]}),y=e.createToken({name:"Attribute",pattern:e.Lexer.NA}),h=e.createToken({name:"BlockAttribute",pattern:/@@/,label:"'@@'",categories:[y]}),v=e.createToken({name:"FieldAttribute",pattern:/@/,label:"'@'",categories:[y]}),E=e.createToken({name:"Dot",pattern:/\./,label:"'.'"}),b=e.createToken({name:"QuestionMark",pattern:/\?/,label:"'?'"}),g=e.createToken({name:"LCurly",pattern:/{/,label:"'{'"}),A=e.createToken({name:"RCurly",pattern:/}/,label:"'}'",pop_mode:!0}),U=e.createToken({name:"LRound",pattern:/\(/,label:"'('"}),k=e.createToken({name:"RRound",pattern:/\)/,label:"')'"}),S=e.createToken({name:"LSquare",pattern:/\[/,label:"'['"}),O=e.createToken({name:"RSquare",pattern:/\]/,label:"']'"}),T=e.createToken({name:"Comma",pattern:/,/,label:"','"}),B=e.createToken({name:"Colon",pattern:/:/,label:"':'"}),N=e.createToken({name:"Equals",pattern:/=/,label:"'='"}),C=e.createToken({name:"StringLiteral",pattern:/"(:?[^\\"\n\r]|\\(:?[bfnrtv"\\/]|u[0-9a-fA-F]{4}))*"/}),w=e.createToken({name:"NumberLiteral",pattern:/-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?/}),M=e.createToken({name:"WhiteSpace",pattern:/\s+/,group:e.Lexer.SKIPPED}),j=e.createToken({name:"LineBreak",pattern:/\n|\r\n/,line_breaks:!0,label:"LineBreak"}),R=[f,L,d,j,M],_={modes:{global:[].concat(R,[a,i,u,o,s,c]),block:[].concat(R,[y,h,v,E,b,g,A,S,O,U,k,T,B,N,m,p,l,C,w,r])},defaultMode:"global"},x=new e.Lexer(_);function P(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,D(e,t)}function D(e,t){return D=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},D(e,t)}var I=["model","view","type"];function V(e){return null!=e&&"type"in e&&I.includes(e.type)}function F(e){return null!=e&&"type"in e&&"field"===e.type}function q(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];var a=n.reduce((function(e,t){if(!t)return e;var n=e.endColumn,r=void 0===n?-Infinity:n,a=e.endLine,i=void 0===a?-Infinity:a,u=e.endOffset,o=void 0===u?-Infinity:u,s=e.startColumn,c=void 0===s?Infinity:s,m=e.startLine,p=e.startOffset,l=void 0===p?Infinity:p;return null!=t.startLine&&t.startLine<(void 0===m?Infinity:m)&&(e.startLine=t.startLine),null!=t.startColumn&&t.startColumn<c&&(e.startColumn=t.startColumn),null!=t.startOffset&&t.startOffset<l&&(e.startOffset=t.startOffset),null!=t.endLine&&t.endLine>i&&(e.endLine=t.endLine),null!=t.endColumn&&t.endColumn>r&&(e.endColumn=t.endColumn),null!=t.endOffset&&t.endOffset>o&&(e.endOffset=t.endOffset),e}),{});return Object.assign(e,{location:a})}var G,Y={parser:{nodeLocationTracking:"none"}},z=function(e){function t(t){var n;return(n=e.call(this,_,t)||this).config=void 0,n.break=n.RULE("break",(function(){n.CONSUME1(j),n.CONSUME2(j)})),n.keyedArg=n.RULE("keyedArg",(function(){n.CONSUME(r,{LABEL:"keyName"}),n.CONSUME(B),n.SUBRULE(n.value)})),n.array=n.RULE("array",(function(){n.CONSUME(S),n.MANY_SEP({SEP:T,DEF:function(){n.SUBRULE(n.value)}}),n.CONSUME(O)})),n.func=n.RULE("func",(function(){n.CONSUME(r,{LABEL:"funcName"}),n.CONSUME(U),n.MANY_SEP({SEP:T,DEF:function(){n.OR([{ALT:function(){return n.SUBRULE(n.keyedArg)}},{ALT:function(){return n.SUBRULE(n.value)}}])}}),n.CONSUME(k)})),n.value=n.RULE("value",(function(){n.OR([{ALT:function(){return n.CONSUME(C,{LABEL:"value"})}},{ALT:function(){return n.CONSUME(w,{LABEL:"value"})}},{ALT:function(){return n.SUBRULE(n.array,{LABEL:"value"})}},{ALT:function(){return n.SUBRULE(n.func,{LABEL:"value"})}},{ALT:function(){return n.CONSUME(m,{LABEL:"value"})}},{ALT:function(){return n.CONSUME(p,{LABEL:"value"})}},{ALT:function(){return n.CONSUME(l,{LABEL:"value"})}},{ALT:function(){return n.CONSUME(r,{LABEL:"value"})}}])})),n.property=n.RULE("property",(function(){n.CONSUME(r,{LABEL:"propertyName"}),n.CONSUME(N),n.SUBRULE(n.value,{LABEL:"propertyValue"})})),n.assignment=n.RULE("assignment",(function(){n.CONSUME(r,{LABEL:"assignmentName"}),n.CONSUME(N),n.SUBRULE(n.value,{LABEL:"assignmentValue"})})),n.field=n.RULE("field",(function(){n.CONSUME(r,{LABEL:"fieldName"}),n.SUBRULE(n.value,{LABEL:"fieldType"}),n.OPTION1((function(){n.OR([{ALT:function(){n.CONSUME(S,{LABEL:"array"}),n.CONSUME(O,{LABEL:"array"})}},{ALT:function(){return n.CONSUME(b,{LABEL:"optional"})}}])})),n.MANY((function(){n.SUBRULE(n.attribute,{LABEL:"attributeList"})})),n.OPTION2((function(){n.CONSUME(f,{LABEL:"comment"})}))})),n.block=n.RULE("block",(function(e){void 0===e&&(e={});var t=e.componentType,r="enum"===t,a="model"===t||"view"===t||"type"===t;n.CONSUME(g),n.CONSUME1(j),n.MANY((function(){n.OR([{ALT:function(){return n.SUBRULE(n.comment,{LABEL:"list"})}},{GATE:function(){return a},ALT:function(){return n.SUBRULE(n.property,{LABEL:"list"})}},{ALT:function(){return n.SUBRULE(n.attribute,{LABEL:"list"})}},{GATE:function(){return a},ALT:function(){return n.SUBRULE(n.field,{LABEL:"list"})}},{GATE:function(){return r},ALT:function(){return n.SUBRULE(n.enum,{LABEL:"list"})}},{GATE:function(){return!a},ALT:function(){return n.SUBRULE(n.assignment,{LABEL:"list"})}},{ALT:function(){return n.SUBRULE(n.break,{LABEL:"list"})}},{ALT:function(){return n.CONSUME2(j)}}])})),n.CONSUME(A)})),n.enum=n.RULE("enum",(function(){n.CONSUME(r,{LABEL:"enumName"}),n.OPTION((function(){n.CONSUME(f,{LABEL:"comment"})}))})),n.attribute=n.RULE("attribute",(function(){n.OR1([{ALT:function(){return n.CONSUME(h,{LABEL:"blockAttribute"})}},{ALT:function(){return n.CONSUME(v,{LABEL:"fieldAttribute"})}}]),n.OR2([{ALT:function(){n.CONSUME1(r,{LABEL:"groupName"}),n.CONSUME(E),n.CONSUME2(r,{LABEL:"attributeName"})}},{ALT:function(){return n.CONSUME(r,{LABEL:"attributeName"})}}]),n.OPTION((function(){n.CONSUME(U),n.MANY_SEP({SEP:T,DEF:function(){n.SUBRULE(n.attributeArg)}}),n.CONSUME(k)}))})),n.attributeArg=n.RULE("attributeArg",(function(){n.OR([{ALT:function(){return n.SUBRULE(n.keyedArg,{LABEL:"value"})}},{ALT:function(){return n.SUBRULE(n.value,{LABEL:"value"})}}])})),n.component=n.RULE("component",(function(){var e=n.OR1([{ALT:function(){return n.CONSUME(a,{LABEL:"type"})}},{ALT:function(){return n.CONSUME(i,{LABEL:"type"})}},{ALT:function(){return n.CONSUME(u,{LABEL:"type"})}},{ALT:function(){return n.CONSUME(o,{LABEL:"type"})}},{ALT:function(){return n.CONSUME(s,{LABEL:"type"})}},{ALT:function(){return n.CONSUME(c,{LABEL:"type"})}}]);n.OR2([{ALT:function(){n.CONSUME1(r,{LABEL:"groupName"}),n.CONSUME(E),n.CONSUME2(r,{LABEL:"componentName"})}},{ALT:function(){return n.CONSUME(r,{LABEL:"componentName"})}}]),n.SUBRULE(n.block,{ARGS:[{componentType:e.image}]})})),n.comment=n.RULE("comment",(function(){n.CONSUME(f,{LABEL:"text"})})),n.schema=n.RULE("schema",(function(){n.MANY((function(){n.OR([{ALT:function(){return n.SUBRULE(n.comment,{LABEL:"list"})}},{ALT:function(){return n.SUBRULE(n.component,{LABEL:"list"})}},{ALT:function(){return n.SUBRULE(n.break,{LABEL:"list"})}},{ALT:function(){return n.CONSUME(j)}}])}))})),n.performSelfAnalysis(),n.config=t,n}return P(t,e),t}(e.CstParser),W=new z(function(){if(null!=G)return G;var e=t.lilconfigSync("prisma-ast").search();return G=Object.assign(Y,null==e?void 0:e.config)}().parser),K=function(e){return function(t){function n(){var e;return(e=t.call(this)||this).validateVisitor(),e}P(n,t);var r=n.prototype;return r.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])})))||[]}},r.component=function(e){var t=e.type[0],n=e.componentName[0],r=this.visit(e.block),a=function(){switch(t.image){case"datasource":return{type:"datasource",name:n.image,assignments:r};case"generator":return{type:"generator",name:n.image,assignments:r};case"model":return{type:"model",name:n.image,properties:r};case"view":return{type:"view",name:n.image,properties:r};case"enum":return{type:"enum",name:n.image,enumerators:r};case"type":return{type:"type",name:n.image,properties:r};default:throw new Error("Unexpected block type: "+t)}}();return this.maybeAppendLocationData(a,t,n)},r.break=function(){return{type:"break"}},r.comment=function(e){var t=e.text[0];return this.maybeAppendLocationData({type:"comment",text:t.image},t)},r.block=function(e){var t,n=this;return null==(t=e.list)?void 0:t.map((function(e){return n.visit([e])}))},r.assignment=function(e){var t=this.visit(e.assignmentValue),n=e.assignmentName[0];return this.maybeAppendLocationData({type:"assignment",key:n.image,value:t},n)},r.field=function(e){var t,n,r,a=this,i=this.visit(e.fieldType),u=e.fieldName[0],o=e.attributeList&&e.attributeList.map((function(e){return a.visit([e])})),s=null==(t=e.comment)||null==(t=t[0])?void 0:t.image;return this.maybeAppendLocationData({type:"field",name:u.image,fieldType:i,array:null!=e.array,optional:null!=e.optional,attributes:o,comment:s},u,null==(n=e.optional)?void 0:n[0],null==(r=e.array)?void 0:r[0])},r.attribute=function(e){var t=this,n=e.attributeName[0],r=(e.groupName||[{}])[0],a=e.attributeArg&&e.attributeArg.map((function(e){return t.visit(e)})),i=null!=e.blockAttribute?"object":"field";return this.maybeAppendLocationData.apply(this,[{type:"attribute",name:n.image,kind:i,group:r.image,args:a},n].concat("object"===i?e.blockAttribute:e.fieldAttribute,[r]))},r.attributeArg=function(e){return{type:"attributeArgument",value:this.visit(e.value)}},r.func=function(e){var t=this,n=e.funcName[0],r=e.value&&e.value.map((function(e){return t.visit([e])})),a=e.keyedArg&&e.keyedArg.map((function(e){return t.visit([e])})),i=(r||a)&&[].concat(null!=r?r:[],null!=a?a:[]);return this.maybeAppendLocationData({type:"function",name:n.image,params:i},n)},r.array=function(e){var t=this;return{type:"array",args:e.value&&e.value.map((function(e){return t.visit([e])}))}},r.keyedArg=function(e){var t=e.keyName[0],n=this.visit(e.value);return this.maybeAppendLocationData({type:"keyValue",key:t.image,value:n},t)},r.value=function(e){return"image"in e.value[0]?e.value[0].image:this.visit(e.value)},r.enum=function(e){var t,n=e.enumName[0],r=null==(t=e.comment)||null==(t=t[0])?void 0:t.image;return this.maybeAppendLocationData({type:"enumerator",name:n.image,comment:r},n)},r.maybeAppendLocationData=function(t){if("none"===e.config.nodeLocationTracking)return t;for(var n=arguments.length,r=new Array(n>1?n-1:0),a=1;a<n;a++)r[a-1]=arguments[a];return q.apply(void 0,[t].concat(r))},n}(e.getBaseCstVisitorConstructorWithDefaults())},Q=new(K(W));function Z(e,t){var n,r,a=x.tokenize(e),i=null!=(n=null==t?void 0:t.parser)?n:W;i.input=a.tokens;var u=i.schema();if(i.errors.length>0)throw i.errors[0];return(null!=(r=null==t?void 0:t.visitor)?r:Q).visit(u)}var H=["break","comment"],J=["generator","datasource","model","view","enum","break","comment"];function X(e,t){void 0===t&&(t={});var r=t.sort,a=t.locales,i=void 0===a?void 0:a,u=t.sortOrder,o=void 0===u?void 0:u,s=e.list;if(void 0!==r&&r){s=e.list=s.filter((function(e){return"break"!==e.type}));var c=function(e,t,n){return void 0===n&&(n=J),function(r,a){if(-1!==H.indexOf(r.type)!=(-1!==H.indexOf(a.type)))return e.list.indexOf(r)-e.list.indexOf(a);n!==J&&(n=n.concat(J));var i=n.indexOf(r.type)-n.indexOf(a.type);return 0!==i?i:"name"in r&&"name"in a?r.name.localeCompare(a.name,t):0}}(e,i,o);s.sort(c)}return s.map($).filter(Boolean).join(n.EOL).replace(/(\r?\n\s*){3,}/g,n.EOL+n.EOL)+n.EOL}function $(e){switch(e.type){case"comment":return ee(e);case"datasource":return r=se((t=e).assignments),"\ndatasource "+t.name+" {\n "+r+"\n}";case"enum":return function(e){var t=e.enumerators.map(ne).filter(Boolean).join(n.EOL+" ").replace(/(\r?\n\s*){3,}/g,n.EOL+n.EOL+" ");return"\nenum "+e.name+" {\n "+t+"\n}"}(e);case"generator":return function(e){var t=se(e.assignments);return"\ngenerator "+e.name+" {\n "+t+"\n}"}(e);case"model":case"view":case"type":return function(e){var t,r,a,i,u,o=(r=0,a=(t=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}),[[]]),i=a.map((function(e){return e.reduce((function(e,t){return Math.max(e,"field"===t.type?t.name.length:0)}),0)})),u=a.map((function(e){return e.reduce((function(e,t){return Math.max(e,"field"===t.type?ie(t).length:0)}),0)})),t.map((function(e,t,n){return t>0&&"break"!==e.type&&"break"===n[t-1].type&&(i.shift(),u.shift()),function(e,t,n){switch(void 0===t&&(t=0),void 0===n&&(n=0),e.type){case"attribute":return re(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=ie(e).padEnd(n),i=e.attributes?e.attributes.map(re):[],u=e.comment;return[r,a].concat(i).filter(Boolean).join(" ").trim()+(u?" "+u:"")}(e,t,n);case"comment":return ee(e);case"break":return te();default:throw new Error("Unrecognized property type")}}(e,i[0],u[0])})).filter(Boolean).join(n.EOL+" ").replace(/(\r?\n\s*){3,}/g,n.EOL+n.EOL+" "));return"\n"+e.type+" "+e.name+" {\n "+o+"\n}"}(e);case"break":return te();default:throw new Error("Unrecognized block type")}var t,r}function ee(e){return e.text}function te(){return n.EOL}function ne(e){switch(e.type){case"enumerator":return[e.name,e.comment].filter(Boolean).join(" ");case"attribute":return re(e);case"comment":return ee(e);case"break":return te();default:throw new Error("Unexpected enumerator type")}}function re(e){var t=e.args&&e.args.length>0?"("+e.args.map(ae).filter(Boolean).join(", ")+")":"",n=[e.name];return e.group&&n.unshift(e.group),("field"===e.kind?"@":"@@")+n.join(".")+t}function ae(e){return oe(e.value)}function ie(e){var t=e.array?"[]":e.optional?"?":"";if("object"==typeof e.fieldType){if("function"===e.fieldType.type)return""+ue(e.fieldType)+t;throw new Error("Unexpected field type")}return""+e.fieldType+t}function ue(e){var t=e.params?e.params.map(oe):"";return e.name+"("+t+")"}function oe(e){if("object"==typeof e){if("type"in e)switch(e.type){case"keyValue":return e.key+": "+oe(e.value);case"function":return ue(e);case"array":return"["+(null!=e.args?e.args.map(oe).join(", "):"")+"]";default:throw new Error("Unexpected value type")}throw new Error("Unexpected object value")}return String(e)}function se(e){var t=0,r=e.reduce((function(e,n,r,a){return"break"===n.type||(r>0&&"break"===a[r-1].type&&(e[++t]=[]),e[t].push(n)),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 ee(e);case"break":return te();case"assignment":return e.key.padEnd(t)+" = "+oe(e.value);default:throw new Error("Unexpected assignment type")}}(e,r[0])})).filter(Boolean).join(n.EOL+" ").replace(/(\r?\n\s*){3,}/g,n.EOL+n.EOL+" ")}var ce=function(){function e(e){void 0===e&&(e=""),this.schema=void 0,this._subject=void 0,this._parent=void 0,this.schema=Z(e)}var t=e.prototype;return t.print=function(e){return void 0===e&&(e={}),X(this.schema,e)},t.getSchema=function(){return this.schema},t.generator=function(e,t){void 0===t&&(t="prisma-client-js");var n=this.schema.list.reduce((function(t,n){return"generator"===n.type&&n.name===e?n:t}),{type:"generator",name:e,assignments:[{type:"assignment",key:"provider",value:'"'+t+'"'}]});return this.schema.list.includes(n)||this.schema.list.push(n),this._subject=n,this},t.drop=function(e){var t=this.schema.list.findIndex((function(t){return"name"in t&&t.name===e}));return-1!==t&&this.schema.list.splice(t,1),this},t.datasource=function(e,t){var n={type:"datasource",name:"db",assignments:[{type:"assignment",key:"url",value:"string"==typeof t?'"'+t+'"':{type:"function",name:"env",params:['"'+t.env+'"']}},{type:"assignment",key:"provider",value:e}]},r=this.schema.list.findIndex((function(e){return"datasource"===e.type}));return this.schema.list.splice(r,-1!==r?1:0,n),this._subject=n,this},t.model=function(e){var t=this.schema.list.reduce((function(t,n){return"model"===n.type&&n.name===e?n:t}),{type:"model",name:e,properties:[]});return this.schema.list.includes(t)||this.schema.list.push(t),this._subject=t,this},t.view=function(e){var t=this.schema.list.reduce((function(t,n){return"view"===n.type&&n.name===e?n:t}),{type:"view",name:e,properties:[]});return this.schema.list.includes(t)||this.schema.list.push(t),this._subject=t,this},t.type=function(e){var t=this.schema.list.reduce((function(t,n){return"type"===n.type&&n.name===e?n:t}),{type:"type",name:e,properties:[]});return this.schema.list.includes(t)||this.schema.list.push(t),this._subject=t,this},t.enum=function(e,t){void 0===t&&(t=[]);var n=this.schema.list.reduce((function(t,n){return"enum"===n.type&&n.name===e?n:t}),{type:"enum",name:e,enumerators:t.map((function(e){return{type:"enumerator",name:e}}))});return this.schema.list.includes(n)||this.schema.list.push(n),this._subject=n,this},t.enumerator=function(e){var t=this.getSubject();if(!t||!("type"in t)||"enum"!==t.type)throw new Error("Subject must be a prisma enum!");return t.enumerators.push({type:"enumerator",name:e}),this},t.getSubject=function(){return this._subject},t.getParent=function(){return this._parent},t.blockAttribute=function(e,t){var n=this.getSubject();if(!V(n)){var r=this.getParent();if(!V(r))throw new Error("Subject must be a prisma model, view, or type!");n=this._subject=r}var a=t?"string"==typeof t?[{type:"attributeArgument",value:'"'+t+'"'}]:Array.isArray(t)?[{type:"attributeArgument",value:{type:"array",args:t}}]:Object.entries(t).map((function(e){return{type:"attributeArgument",value:{type:"keyValue",key:e[0],value:e[1]}}})):[];return n.properties.push({type:"attribute",kind:"object",name:e,args:a}),this},t.attribute=function(e,t){var n=this.getParent(),r=this.getSubject();if(!V(n))throw new Error("Parent must be a prisma model or view!");if(!F(r))throw new Error("Subject must be a prisma field!");r.attributes||(r.attributes=[]);var a=r.attributes.reduce((function(t,n){return"attribute"===n.type&&(n.group?n.group+".":"")+n.name===e?n:t}),{type:"attribute",kind:"field",name:e});if(Array.isArray(t)){var i=function e(t){var n,r;return"string"==typeof t?t:{type:"function",name:t.name,params:null!=(n=null==(r=t.function)?void 0:r.map(e))?n:[]}};t.length>0&&(a.args=t.map((function(e){return{type:"attributeArgument",value:i(e)}})))}else"object"==typeof t&&(a.args=Object.entries(t).map((function(e){return{type:"attributeArgument",value:{type:"keyValue",key:e[0],value:{type:"array",args:e[1]}}}})));return r.attributes.includes(a)||r.attributes.push(a),this},t.removeAttribute=function(e){var t=this.getParent(),n=this.getSubject();if(!V(t))throw new Error("Parent must be a prisma model or view!");if(!F(n))throw new Error("Subject must be a prisma field!");return n.attributes||(n.attributes=[]),n.attributes=n.attributes.filter((function(t){return!("attribute"===t.type&&t.name===e)})),this},t.assignment=function(e,t){var n=this.getSubject();if(!n||!("type"in n)||!["generator","datasource"].includes(n.type))throw new Error("Subject must be a prisma generator or datasource!");var r=n.assignments.reduce((function(n,r){return"assignment"===r.type&&r.key===e?function(e,n){return e.value='"'+t+'"',e}(r):n}),{type:"assignment",key:e,value:'"'+t+'"'});return n.assignments.includes(r)||n.assignments.push(r),this},t.blockInsert=function(e){var t=this.getSubject(),n=["datasource","enum","generator","model","view","type"];if(!t||!("type"in t)||!n.includes(t.type)){var r=this.getParent();if(!r||!("type"in r)||!n.includes(r.type))throw new Error("Subject must be a prisma block!");t=this._subject=r}switch(t.type){case"datasource":case"generator":t.assignments.push(e);break;case"enum":t.enumerators.push(e);break;case"model":t.properties.push(e)}return this},t.break=function(){return this.blockInsert({type:"break"})},t.comment=function(e,t){return void 0===t&&(t=!1),this.blockInsert({type:"comment",text:"//"+(t?"/":"")+" "+e})},t.schemaComment=function(e,t){return void 0===t&&(t=!1),this.schema.list.push({type:"comment",text:"//"+(t?"/":"")+" "+e}),this},t.field=function(e,t){void 0===t&&(t="String");var n=this.getSubject();if(!V(n)){var r=this.getParent();if(!V(r))throw new Error("Subject must be a prisma model or view or composite type!");n=this._subject=r}var a=n.properties.reduce((function(t,n){return"field"===n.type&&n.name===e?n:t}),{type:"field",name:e,fieldType:t});return n.properties.includes(a)||n.properties.push(a),this._parent=n,this._subject=a,this},t.removeField=function(e){var t=this.getSubject();if(!V(t)){var n=this.getParent();if(!V(n))throw new Error("Subject must be a prisma model or view or composite type!");t=this._subject=n}return t.properties=t.properties.filter((function(t){return!("field"===t.type&&t.name===e)})),this},t.then=function(e){return e(this._subject),this},e}();exports.ConcretePrismaSchemaBuilder=ce,exports.PrismaParser=z,exports.VisitorClassFactory=K,exports.createPrismaSchemaBuilder=function(e){return new ce(e)},exports.getSchema=Z,exports.printSchema=X; | ||
//# sourceMappingURL=prisma-ast.cjs.production.min.js.map |
@@ -34,2 +34,7 @@ import { Lexer, createToken, CstParser } from 'chevrotain'; | ||
}); | ||
var Type = /*#__PURE__*/createToken({ | ||
name: 'Type', | ||
pattern: /type/, | ||
push_mode: 'block' | ||
}); | ||
var True = /*#__PURE__*/createToken({ | ||
@@ -158,3 +163,3 @@ name: 'True', | ||
modes: { | ||
global: /*#__PURE__*/[].concat(naTokens, [Datasource, Generator, Model, View, Enum]), | ||
global: /*#__PURE__*/[].concat(naTokens, [Datasource, Generator, Model, View, Enum, Type]), | ||
block: /*#__PURE__*/[].concat(naTokens, [Attribute, BlockAttribute, FieldAttribute, Dot, QuestionMark, LCurly, RCurly, LSquare, RSquare, LRound, RRound, Comma, Colon, Equals, True, False, Null, StringLiteral, NumberLiteral, Identifier]) | ||
@@ -179,3 +184,3 @@ }, | ||
var schemaObjects = ['model', 'view']; | ||
var schemaObjects = ['model', 'view', 'type']; | ||
function isSchemaObject(obj) { | ||
@@ -393,3 +398,3 @@ return obj != null && 'type' in obj && schemaObjects.includes(obj.type); | ||
var isEnum = componentType === 'enum'; | ||
var isObject = componentType === 'model' || componentType === 'view'; | ||
var isObject = componentType === 'model' || componentType === 'view' || componentType === 'type'; | ||
_this.CONSUME(LCurly); | ||
@@ -558,2 +563,8 @@ _this.CONSUME1(LineBreak); | ||
} | ||
}, { | ||
ALT: function ALT() { | ||
return _this.CONSUME(Type, { | ||
LABEL: 'type' | ||
}); | ||
} | ||
}]); | ||
@@ -683,2 +694,8 @@ _this.OR2([{ | ||
}; | ||
case 'type': | ||
return { | ||
type: 'type', | ||
name: name.image, | ||
properties: list | ||
}; | ||
default: | ||
@@ -908,2 +925,3 @@ throw new Error("Unexpected block type: " + type); | ||
case 'view': | ||
case 'type': | ||
return printObject(block); | ||
@@ -1189,2 +1207,14 @@ case 'break': | ||
}; | ||
_proto.type = function type(name) { | ||
var type = this.schema.list.reduce(function (memo, block) { | ||
return block.type === 'type' && block.name === name ? block : memo; | ||
}, { | ||
type: 'type', | ||
name: name, | ||
properties: [] | ||
}); | ||
if (!this.schema.list.includes(type)) this.schema.list.push(type); | ||
this._subject = type; | ||
return this; | ||
}; | ||
_proto["enum"] = function _enum(name, enumeratorNames) { | ||
@@ -1231,3 +1261,3 @@ if (enumeratorNames === void 0) { | ||
var parent = this.getParent(); | ||
if (!isSchemaObject(parent)) throw new Error('Subject must be a prisma model or view!'); | ||
if (!isSchemaObject(parent)) throw new Error('Subject must be a prisma model, view, or type!'); | ||
subject = this._subject = parent; | ||
@@ -1358,3 +1388,3 @@ } | ||
var subject = this.getSubject(); | ||
var allowed = ['datasource', 'enum', 'generator', 'model', 'view']; | ||
var allowed = ['datasource', 'enum', 'generator', 'model', 'view', 'type']; | ||
if (!subject || !('type' in subject) || !allowed.includes(subject.type)) { | ||
@@ -1425,3 +1455,3 @@ var parent = this.getParent(); | ||
var parent = this.getParent(); | ||
if (!isSchemaObject(parent)) throw new Error('Subject must be a prisma model or view!'); | ||
if (!isSchemaObject(parent)) throw new Error('Subject must be a prisma model or view or composite type!'); | ||
subject = this._subject = parent; | ||
@@ -1445,3 +1475,3 @@ } | ||
var parent = this.getParent(); | ||
if (!isSchemaObject(parent)) throw new Error('Subject must be a prisma model or view!'); | ||
if (!isSchemaObject(parent)) throw new Error('Subject must be a prisma model or view or composite type!'); | ||
subject = this._subject = parent; | ||
@@ -1448,0 +1478,0 @@ } |
@@ -12,3 +12,3 @@ import * as schema from './getSchema'; | ||
type PrismaSchemaBuilder<K extends keyof ConcretePrismaSchemaBuilder> = { | ||
[U in K]: U extends ExtractKeys ? ConcretePrismaSchemaBuilder[U] : U extends NeutralKeys ? ConcretePrismaSchemaBuilder[U] : U extends 'datasource' ? PrismaSchemaSubset<U, 'datasource' | EnumKeys | FieldKeys | BlockKeys> : U extends 'generator' ? PrismaSchemaSubset<U, EnumKeys | FieldKeys | BlockKeys> : U extends 'model' ? PrismaSchemaSubset<U, DatasourceOrGeneratorKeys | EnumKeys | FieldKeys> : U extends 'view' ? PrismaSchemaSubset<U, DatasourceOrGeneratorKeys | EnumKeys | FieldKeys> : U extends 'field' ? PrismaSchemaSubset<U, DatasourceOrGeneratorKeys | EnumKeys> : U extends 'removeField' ? PrismaSchemaSubset<U, DatasourceOrGeneratorKeys | EnumKeys | FieldKeys> : U extends 'enum' ? PrismaSchemaSubset<U, DatasourceOrGeneratorKeys | BlockKeys | FieldKeys> : U extends 'removeAttribute' ? PrismaSchemaSubset<U, DatasourceOrGeneratorKeys | EnumKeys> : PrismaSchemaSubset<U, DatasourceOrGeneratorKeys | EnumKeys | FieldKeys | BlockKeys | 'comment'>; | ||
[U in K]: U extends ExtractKeys ? ConcretePrismaSchemaBuilder[U] : U extends NeutralKeys ? ConcretePrismaSchemaBuilder[U] : U extends 'datasource' ? PrismaSchemaSubset<U, 'datasource' | EnumKeys | FieldKeys | BlockKeys> : U extends 'generator' ? PrismaSchemaSubset<U, EnumKeys | FieldKeys | BlockKeys> : U extends 'model' ? PrismaSchemaSubset<U, DatasourceOrGeneratorKeys | EnumKeys | FieldKeys> : U extends 'view' ? PrismaSchemaSubset<U, DatasourceOrGeneratorKeys | EnumKeys | FieldKeys> : U extends 'type' ? PrismaSchemaSubset<U, DatasourceOrGeneratorKeys | EnumKeys | FieldKeys> : U extends 'field' ? PrismaSchemaSubset<U, DatasourceOrGeneratorKeys | EnumKeys> : U extends 'removeField' ? PrismaSchemaSubset<U, DatasourceOrGeneratorKeys | EnumKeys | FieldKeys> : U extends 'enum' ? PrismaSchemaSubset<U, DatasourceOrGeneratorKeys | BlockKeys | FieldKeys> : U extends 'removeAttribute' ? PrismaSchemaSubset<U, DatasourceOrGeneratorKeys | EnumKeys> : PrismaSchemaSubset<U, DatasourceOrGeneratorKeys | EnumKeys | FieldKeys | BlockKeys | 'comment'>; | ||
}; | ||
@@ -34,2 +34,3 @@ type Arg = string | { | ||
view(name: string): this; | ||
type(name: string): this; | ||
enum(name: string, enumeratorNames?: string[]): this; | ||
@@ -36,0 +37,0 @@ enumerator(value: string): this; |
{ | ||
"version": "0.8.1", | ||
"version": "0.9.0", | ||
"license": "MIT", | ||
@@ -4,0 +4,0 @@ "main": "dist/index.js", |
@@ -237,2 +237,32 @@ # @mrleebo/prisma-ast | ||
### Add or update a view | ||
If the view with that name already exists in the schema, it will be selected and any fields that follow will be appended to the view. Otherwise, the view will be created and added to the schema. | ||
```ts | ||
builder.view('Project').field('name', 'String'); | ||
``` | ||
```prisma | ||
model Project { | ||
name String | ||
} | ||
``` | ||
### Add or update a composite type | ||
If the composite type with that name already exists in the schema, it will be selected and any fields that follow will be appended to the type. Otherwise, the composite type will be created and added to the schema. | ||
```ts | ||
builder.type('Photo').field('width', 'Int').field('height', 'Int').field('url', 'String'); | ||
``` | ||
```prisma | ||
type Photo { | ||
width Int | ||
height Int | ||
url String | ||
} | ||
``` | ||
### Access a model programmatically | ||
@@ -239,0 +269,0 @@ |
@@ -47,6 +47,7 @@ import { PrismaLexer } from './lexer'; | ||
| Comment | ||
| Break; | ||
| Break | ||
| Type; | ||
export interface Object { | ||
type: 'model' | 'view'; | ||
type: 'model' | 'view' | 'type'; | ||
name: string; | ||
@@ -66,2 +67,7 @@ properties: Array<Property | Comment | Break>; | ||
export interface Type extends Object { | ||
type: 'type'; | ||
location?: CstNodeLocation; | ||
} | ||
export interface Datasource { | ||
@@ -114,3 +120,3 @@ type: 'datasource'; | ||
type: 'attribute'; | ||
kind: 'object' | 'view'; | ||
kind: 'object' | 'view' | 'type'; | ||
group?: string; | ||
@@ -117,0 +123,0 @@ name: string; |
@@ -32,2 +32,7 @@ import { createToken, Lexer, IMultiModeLexerDefinition } from 'chevrotain'; | ||
}); | ||
export const Type = createToken({ | ||
name: 'Type', | ||
pattern: /type/, | ||
push_mode: 'block', | ||
}); | ||
export const True = createToken({ | ||
@@ -159,3 +164,3 @@ name: 'True', | ||
modes: { | ||
global: [...naTokens, Datasource, Generator, Model, View, Enum], | ||
global: [...naTokens, Datasource, Generator, Model, View, Enum, Type], | ||
block: [ | ||
@@ -162,0 +167,0 @@ ...naTokens, |
@@ -5,3 +5,9 @@ import { CstParser } from 'chevrotain'; | ||
type ComponentType = 'datasource' | 'generator' | 'model' | 'view' | 'enum'; | ||
type ComponentType = | ||
| 'datasource' | ||
| 'generator' | ||
| 'model' | ||
| 'view' | ||
| 'enum' | ||
| 'type'; | ||
export class PrismaParser extends CstParser { | ||
@@ -109,3 +115,6 @@ readonly config: PrismaAstParserConfig; | ||
const isEnum = componentType === 'enum'; | ||
const isObject = componentType === 'model' || componentType === 'view'; | ||
const isObject = | ||
componentType === 'model' || | ||
componentType === 'view' || | ||
componentType === 'type'; | ||
@@ -202,2 +211,3 @@ this.CONSUME(lexer.LCurly); | ||
{ ALT: () => this.CONSUME(lexer.Enum, { LABEL: 'type' }) }, | ||
{ ALT: () => this.CONSUME(lexer.Type, { LABEL: 'type' }) }, | ||
]); | ||
@@ -204,0 +214,0 @@ this.OR2([ |
@@ -5,6 +5,8 @@ import * as Types from './getSchema'; | ||
type Block = 'generator' | 'datasource' | 'model' | 'view' | 'enum' | 'type'; | ||
export interface PrintOptions { | ||
sort?: boolean; | ||
locales?: string | string[]; | ||
sortOrder?: Array<'generator' | 'datasource' | 'model' | 'view' | 'enum'>; | ||
sortOrder?: Block[]; | ||
} | ||
@@ -51,2 +53,3 @@ | ||
case 'view': | ||
case 'type': | ||
return printObject(block); | ||
@@ -53,0 +56,0 @@ case 'break': |
@@ -64,2 +64,4 @@ import * as schema from './getSchema'; | ||
? PrismaSchemaSubset<U, DatasourceOrGeneratorKeys | EnumKeys | FieldKeys> | ||
: U extends 'type' | ||
? PrismaSchemaSubset<U, DatasourceOrGeneratorKeys | EnumKeys | FieldKeys> | ||
: U extends 'field' | ||
@@ -189,2 +191,14 @@ ? PrismaSchemaSubset<U, DatasourceOrGeneratorKeys | EnumKeys> | ||
/** Adds or updates a type based on the name. Can be chained with .field() or .blockAttribute() to add to it. */ | ||
type(name: string): this { | ||
const type = this.schema.list.reduce<schema.Type>( | ||
(memo, block) => | ||
block.type === 'type' && block.name === name ? block : memo, | ||
{ type: 'type', name, properties: [] } | ||
); | ||
if (!this.schema.list.includes(type)) this.schema.list.push(type); | ||
this._subject = type; | ||
return this; | ||
} | ||
/** Adds or updates an enum based on the name. Can be chained with .enumerator() to add a value to it. */ | ||
@@ -249,3 +263,3 @@ enum(name: string, enumeratorNames: string[] = []): this { | ||
if (!isSchemaObject(parent)) | ||
throw new Error('Subject must be a prisma model or view!'); | ||
throw new Error('Subject must be a prisma model, view, or type!'); | ||
@@ -395,3 +409,10 @@ subject = this._subject = parent; | ||
let subject = this.getSubject<schema.Block>(); | ||
const allowed = ['datasource', 'enum', 'generator', 'model', 'view']; | ||
const allowed = [ | ||
'datasource', | ||
'enum', | ||
'generator', | ||
'model', | ||
'view', | ||
'type', | ||
]; | ||
if (!subject || !('type' in subject) || !allowed.includes(subject.type)) { | ||
@@ -469,3 +490,5 @@ const parent = this.getParent<schema.Block>(); | ||
if (!isSchemaObject(parent)) | ||
throw new Error('Subject must be a prisma model or view!'); | ||
throw new Error( | ||
'Subject must be a prisma model or view or composite type!' | ||
); | ||
@@ -491,3 +514,3 @@ subject = this._subject = parent; | ||
/** Drop a field from the current model or view. */ | ||
/** Drop a field from the current model or view or composite type. */ | ||
removeField(name: string): this { | ||
@@ -498,3 +521,5 @@ let subject = this.getSubject<schema.Object>(); | ||
if (!isSchemaObject(parent)) | ||
throw new Error('Subject must be a prisma model or view!'); | ||
throw new Error( | ||
'Subject must be a prisma model or view or composite type!' | ||
); | ||
@@ -501,0 +526,0 @@ subject = this._subject = parent; |
import type { CstNode, IToken } from 'chevrotain'; | ||
import * as schema from './getSchema'; | ||
const schemaObjects = ['model', 'view']; | ||
const schemaObjects = ['model', 'view', 'type']; | ||
/** Returns true if the value is an Object, such as a model or view. */ | ||
/** Returns true if the value is an Object, such as a model or view or composite type. */ | ||
export function isSchemaObject(obj: schema.Object): boolean { | ||
@@ -8,0 +8,0 @@ return obj != null && 'type' in obj && schemaObjects.includes(obj.type); |
@@ -8,4 +8,6 @@ import { CstNode, IToken } from '@chevrotain/types'; | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
type Class<T> = new (...args: any[]) => T; | ||
export type PrismaVisitor = ICstVisitor<any, any>; | ||
/* eslint-enable @typescript-eslint/no-explicit-any */ | ||
@@ -70,2 +72,8 @@ export const VisitorClassFactory = ( | ||
} as const; | ||
case 'type': | ||
return { | ||
type: 'type', | ||
name: name.image, | ||
properties: list, | ||
} as const; | ||
default: | ||
@@ -72,0 +80,0 @@ throw new Error(`Unexpected block type: ${type}`); |
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
502257
5007
556