@morphql/core 0.1.8 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +30 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +30 -30
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {createToken,Lexer,CstParser}from'chevrotain';import {XMLBuilder,XMLParser}from'fast-xml-parser';import Et from'papaparse';import Ct from'js-beautify';var yt=createToken({name:"WhiteSpace",pattern:/\s+/,group:Lexer.SKIPPED}),At=createToken({name:"LineComment",pattern:/\/\/[^\n\r]*/,group:Lexer.SKIPPED}),Rt=createToken({name:"BlockComment",pattern:/\/\*[\s\S]*?\*\//,group:Lexer.SKIPPED}),u=createToken({name:"Identifier",pattern:/[a-zA-Z_$][a-zA-Z0-9_.\[\]]*/}),v=createToken({name:"QuotedIdentifier",pattern:/`([^`\\]|\\.)*`/}),g=createToken({name:"From",pattern:/from/i,longer_alt:u}),A=createToken({name:"To",pattern:/to/i,longer_alt:u}),R=createToken({name:"Transform",pattern:/transform/i,longer_alt:u}),C=createToken({name:"Set",pattern:/set/i,longer_alt:u}),M=createToken({name:"Section",pattern:/section/i,longer_alt:u}),P=createToken({name:"Multiple",pattern:/multiple/i,longer_alt:u}),q=createToken({name:"Clone",pattern:/clone/i,longer_alt:u}),b=createToken({name:"Delete",pattern:/delete/i,longer_alt:u}),w=createToken({name:"Define",pattern:/define/i,longer_alt:u}),I=createToken({name:"Modify",pattern:/modify/i,longer_alt:u}),N=createToken({name:"If",pattern:/if/i,longer_alt:u}),_=createToken({name:"Else",pattern:/else/i,longer_alt:u}),F=createToken({name:"True",pattern:/true/i,longer_alt:u}),k=createToken({name:"False",pattern:/false/i,longer_alt:u}),x=createToken({name:"Null",pattern:/null/i,longer_alt:u}),j=createToken({name:"Return",pattern:/return/i,longer_alt:u}),z=createToken({name:"Unsafe",pattern:/unsafe/i,longer_alt:u}),W=createToken({name:"EqualsEquals",pattern:/==/}),D=createToken({name:"EqualsEqualsEquals",pattern:/===/}),Y=createToken({name:"NotEquals",pattern:/!=/}),G=createToken({name:"NotEqualsEquals",pattern:/!==/}),Q=createToken({name:"LessThanOrEqual",pattern:/<=/}),J=createToken({name:"GreaterThanOrEqual",pattern:/>=/}),V=createToken({name:"LessThan",pattern:/</}),K=createToken({name:"GreaterThan",pattern:/>/}),Z=createToken({name:"And",pattern:/&&/}),H=createToken({name:"Or",pattern:/\|\|/}),X=createToken({name:"Not",pattern:/!/}),f=createToken({name:"Equals",pattern:/=/}),tt=createToken({name:"Plus",pattern:/\+/}),O=createToken({name:"Minus",pattern:/-/}),et=createToken({name:"Times",pattern:/\*/}),rt=createToken({name:"Divide",pattern:/\//}),h=createToken({name:"LParen",pattern:/\(/}),m=createToken({name:"RParen",pattern:/\)/}),S=createToken({name:"Comma",pattern:/,/}),st=createToken({name:"StringLiteral",pattern:/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/}),it=createToken({name:"NumericLiteral",pattern:/-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/}),nt=[yt,At,Rt,g,A,R,C,M,P,q,b,w,I,N,_,F,k,x,j,z,D,W,G,Y,Q,J,Z,H,f,V,K,X,tt,O,et,rt,h,m,S,st,it,v,u],pt=new Lexer(nt);var at=class extends CstParser{constructor(){super(nt),this.performSelfAnalysis();}query=this.RULE("query",()=>{this.CONSUME(g),this.SUBRULE(this.typeFormat,{LABEL:"sourceType"}),this.CONSUME(A),this.SUBRULE1(this.typeFormat,{LABEL:"targetType"}),this.OPTION(()=>{this.CONSUME(R),this.OPTION1(()=>{this.CONSUME(z);}),this.MANY(()=>{this.SUBRULE(this.action);});});});typeFormat=this.RULE("typeFormat",()=>{this.SUBRULE(this.anyIdentifier,{LABEL:"name"}),this.OPTION(()=>{this.CONSUME(h),this.MANY_SEP({SEP:S,DEF:()=>{this.SUBRULE(this.typeFormatParameter,{LABEL:"params"});}}),this.CONSUME(m);});});typeFormatParameter=this.RULE("typeFormatParameter",()=>{this.OR([{GATE:()=>this.LA(2).tokenType===f,ALT:()=>this.SUBRULE(this.namedParameter)},{ALT:()=>this.SUBRULE(this.literal)}]);});namedParameter=this.RULE("namedParameter",()=>{this.SUBRULE(this.anyIdentifier,{LABEL:"key"}),this.CONSUME(f),this.SUBRULE(this.literal,{LABEL:"value"});});anyIdentifier=this.RULE("anyIdentifier",()=>{this.OR([{ALT:()=>this.CONSUME(u)},{ALT:()=>this.CONSUME(v)}]);});literal=this.RULE("literal",()=>{this.OR([{ALT:()=>this.CONSUME(st)},{ALT:()=>this.CONSUME(it)},{ALT:()=>this.CONSUME(F)},{ALT:()=>this.CONSUME(k)},{ALT:()=>this.CONSUME(x)}]);});action=this.RULE("action",()=>{this.OR([{ALT:()=>this.SUBRULE(this.setRule)},{ALT:()=>this.SUBRULE(this.modifyRule)},{ALT:()=>this.SUBRULE(this.sectionRule)},{ALT:()=>this.SUBRULE(this.cloneRule)},{ALT:()=>this.SUBRULE(this.deleteRule)},{ALT:()=>this.SUBRULE(this.ifAction)},{ALT:()=>this.SUBRULE(this.defineRule)},{ALT:()=>this.SUBRULE(this.returnRule)}]);});returnRule=this.RULE("returnRule",()=>{this.CONSUME(j),this.SUBRULE(this.expression,{LABEL:"expr"});});deleteRule=this.RULE("deleteRule",()=>{this.CONSUME(b),this.SUBRULE(this.anyIdentifier,{LABEL:"field"});});ifAction=this.RULE("ifAction",()=>{this.CONSUME(N),this.CONSUME(h),this.SUBRULE(this.expression,{LABEL:"condition"}),this.CONSUME(m),this.CONSUME2(h),this.MANY(()=>{this.SUBRULE(this.action,{LABEL:"thenActions"});}),this.CONSUME2(m),this.OPTION(()=>{this.CONSUME(_),this.CONSUME3(h),this.MANY2(()=>{this.SUBRULE2(this.action,{LABEL:"elseActions"});}),this.CONSUME3(m);});});cloneRule=this.RULE("cloneRule",()=>{this.CONSUME(q),this.OPTION(()=>{this.CONSUME(h),this.MANY_SEP({SEP:S,DEF:()=>{this.SUBRULE(this.anyIdentifier,{LABEL:"fields"});}}),this.CONSUME(m);});});setRule=this.RULE("setRule",()=>{this.CONSUME(C),this.SUBRULE(this.anyIdentifier,{LABEL:"left"}),this.CONSUME(f),this.SUBRULE(this.expression,{LABEL:"right"});});modifyRule=this.RULE("modifyRule",()=>{this.CONSUME(I),this.SUBRULE(this.anyIdentifier,{LABEL:"left"}),this.CONSUME(f),this.SUBRULE(this.expression,{LABEL:"right"});});expression=this.RULE("expression",()=>{this.SUBRULE(this.logicalOr);});logicalOr=this.RULE("logicalOr",()=>{this.SUBRULE(this.logicalAnd,{LABEL:"lhs"}),this.MANY(()=>{this.CONSUME(H),this.SUBRULE1(this.logicalAnd,{LABEL:"rhs"});});});logicalAnd=this.RULE("logicalAnd",()=>{this.SUBRULE(this.comparison,{LABEL:"lhs"}),this.MANY(()=>{this.CONSUME(Z),this.SUBRULE1(this.comparison,{LABEL:"rhs"});});});comparison=this.RULE("comparison",()=>{this.SUBRULE(this.addition,{LABEL:"lhs"}),this.OPTION(()=>{this.OR([{ALT:()=>this.CONSUME(W,{LABEL:"ops"})},{ALT:()=>this.CONSUME(D,{LABEL:"ops"})},{ALT:()=>this.CONSUME(Y,{LABEL:"ops"})},{ALT:()=>this.CONSUME(G,{LABEL:"ops"})},{ALT:()=>this.CONSUME(Q,{LABEL:"ops"})},{ALT:()=>this.CONSUME(J,{LABEL:"ops"})},{ALT:()=>this.CONSUME(V,{LABEL:"ops"})},{ALT:()=>this.CONSUME(K,{LABEL:"ops"})}]),this.SUBRULE1(this.addition,{LABEL:"rhs"});});});addition=this.RULE("addition",()=>{this.SUBRULE(this.multiplication,{LABEL:"lhs"}),this.MANY(()=>{this.OR([{ALT:()=>this.CONSUME(tt,{LABEL:"ops"})},{ALT:()=>this.CONSUME(O,{LABEL:"ops"})}]),this.SUBRULE1(this.multiplication,{LABEL:"rhs"});});});multiplication=this.RULE("multiplication",()=>{this.SUBRULE(this.unaryExpression,{LABEL:"lhs"}),this.MANY(()=>{this.OR([{ALT:()=>this.CONSUME(et,{LABEL:"ops"})},{ALT:()=>this.CONSUME(rt,{LABEL:"ops"})}]),this.SUBRULE1(this.unaryExpression,{LABEL:"rhs"});});});unaryExpression=this.RULE("unaryExpression",()=>{this.OPTION(()=>{this.OR([{ALT:()=>this.CONSUME(O,{LABEL:"sign"})},{ALT:()=>this.CONSUME(X,{LABEL:"sign"})}]);}),this.SUBRULE(this.atomic);});atomic=this.RULE("atomic",()=>{this.OR([{ALT:()=>this.SUBRULE(this.literal)},{GATE:()=>this.LA(2).tokenType===h,ALT:()=>this.SUBRULE(this.functionCall)},{ALT:()=>this.SUBRULE(this.anyIdentifier)},{ALT:()=>{this.CONSUME(h),this.SUBRULE(this.expression),this.CONSUME(m);}}]);});functionCall=this.RULE("functionCall",()=>{this.OR([{ALT:()=>this.CONSUME(u,{LABEL:"name"})},{ALT:()=>this.CONSUME(N,{LABEL:"name"})}]),this.CONSUME(h),this.MANY_SEP({SEP:S,DEF:()=>{this.SUBRULE(this.expression,{LABEL:"args"});}}),this.CONSUME(m);});sectionRule=this.RULE("sectionRule",()=>{this.CONSUME(M),this.OPTION(()=>{this.CONSUME(P);}),this.SUBRULE(this.anyIdentifier,{LABEL:"sectionName"}),this.CONSUME(h),this.OPTION1(()=>{this.CONSUME(g,{LABEL:"subqueryFrom"}),this.SUBRULE(this.typeFormat,{LABEL:"subquerySourceType"}),this.CONSUME(A,{LABEL:"subqueryTo"}),this.SUBRULE1(this.typeFormat,{LABEL:"subqueryTargetType"}),this.OPTION2(()=>{this.CONSUME(R,{LABEL:"subqueryTransform"});});}),this.MANY(()=>{this.SUBRULE(this.action);}),this.CONSUME(m),this.OPTION3(()=>{this.CONSUME1(g,{LABEL:"followFrom"}),this.SUBRULE2(this.anyIdentifier,{LABEL:"followPath"});});});defineRule=this.RULE("defineRule",()=>{this.CONSUME(w),this.SUBRULE(this.anyIdentifier,{LABEL:"left"}),this.CONSUME(f),this.SUBRULE(this.expression,{LABEL:"right"});})},E=new at;var mt={substring:r=>{if(r.length<2)throw new Error("substring() requires at least 2 arguments (string, start, [length])");let[t,e,s]=r;return s!==void 0?`String(${t}).slice(${e}, (${e}) + (${s}))`:`String(${t}).slice(${e})`},if:r=>{if(r.length!==3)throw new Error("if() requires exactly 3 arguments (condition, trueValue, falseValue)");let[t,e,s]=r;return `((${t}) ? (${e}) : (${s}))`},text:r=>{if(r.length!==1)throw new Error("text() requires exactly 1 argument (string or number)");let[t]=r;return `String(${t})`},replace:r=>{if(r.length!==3)throw new Error("replace() requires exactly 3 arguments (string, search, replacement)");let[t,e,s]=r;return `String(${t}).replace(${e}, ${s})`},number:r=>{if(r.length!==1)throw new Error("number() requires exactly 1 argument (string)");let[t]=r;return `Number(${t})`},extractnumber:r=>{if(r.length!==1)throw new Error("extractNumber() requires exactly 1 argument (string)");let[t]=r;return `(() => { const match = String(${t}).match(/\\d+(\\.\\d+)?/); return match ? Number(match[0]) : null; })()`},uppercase:r=>{if(r.length!==1)throw new Error("uppercase() requires exactly 1 argument (string)");let[t]=r;return `String(${t}).toUpperCase()`},lowercase:r=>{if(r.length!==1)throw new Error("lowercase() requires exactly 1 argument (string)");let[t]=r;return `String(${t}).toLowerCase()`},xmlnode:r=>{if(r.length<1)throw new Error("xmlnode() requires at least 1 argument (string)");let t=r[0],e=[...r.slice(1)],s="";if(e.length>0){let[i,n]=[e,2];i=[...Array(Math.ceil(i.length/n))].map(o=>i.splice(0,n)).map(([o,l])=>{let c=o;return o.startsWith('"')||o.startsWith("'")?c=`"$${o.slice(1,-1)}"`:c=`["$"+${o}]`,`${c}:${l||"null"}`}),s=","+i.join(",");}else return t;return `{_:${t}${s}}`},split:r=>{if(r.length<1)throw new Error("split() requires at least 1 argument (string)");let[t,e,s]=r,i=e!==void 0?e:'""',n=s!==void 0?`, ${s}`:"";return `String(${t}).split(${i}${n})`},to_base64:r=>{if(r.length!==1)throw new Error("to_base64() requires exactly 1 argument (string)");let[t]=r;return `(typeof btoa === 'function' ? btoa(unescape(encodeURIComponent(String(${t})))) : Buffer.from(String(${t}), 'utf-8').toString('base64'))`},from_base64:r=>{if(r.length!==1)throw new Error("from_base64() requires exactly 1 argument (string)");let[t]=r;return `(typeof atob === 'function' ? decodeURIComponent(escape(atob(String(${t})))) : Buffer.from(String(${t}), 'base64').toString('utf-8'))`},aslist:r=>{if(r.length!==1)throw new Error("aslist() requires exactly 1 argument");let[t]=r;return `(Array.isArray(${t}) ? ${t} : (${t} == null ? [] : [${t}]))`},spreadsheet:r=>{if(r.length!==1)throw new Error("spreadsheet() requires exactly 1 argument");let[t]=r;return `((data)=>{
|
|
1
|
+
import {createToken,Lexer,CstParser}from'chevrotain';import {XMLBuilder,XMLParser}from'fast-xml-parser';import gt from'papaparse';import Ct from'js-beautify';var At=createToken({name:"WhiteSpace",pattern:/\s+/,group:Lexer.SKIPPED}),Ut=createToken({name:"LineComment",pattern:/\/\/[^\n\r]*/,group:Lexer.SKIPPED}),Tt=createToken({name:"BlockComment",pattern:/\/\*[\s\S]*?\*\//,group:Lexer.SKIPPED}),h=createToken({name:"Identifier",pattern:/[a-zA-Z_$][a-zA-Z0-9_.[\]]*/}),C=createToken({name:"QuotedIdentifier",pattern:/`([^`\\]|\\.)*`/}),L=createToken({name:"From",pattern:/from/i,longer_alt:h}),T=createToken({name:"To",pattern:/to/i,longer_alt:h}),N=createToken({name:"Transform",pattern:/transform/i,longer_alt:h}),B=createToken({name:"Set",pattern:/set/i,longer_alt:h}),M=createToken({name:"Section",pattern:/section/i,longer_alt:h}),I=createToken({name:"Multiple",pattern:/multiple/i,longer_alt:h}),q=createToken({name:"Clone",pattern:/clone/i,longer_alt:h}),P=createToken({name:"Delete",pattern:/delete/i,longer_alt:h}),w=createToken({name:"Define",pattern:/define/i,longer_alt:h}),k=createToken({name:"Modify",pattern:/modify/i,longer_alt:h}),R=createToken({name:"If",pattern:/if/i,longer_alt:h}),z=createToken({name:"Else",pattern:/else/i,longer_alt:h}),_=createToken({name:"True",pattern:/true/i,longer_alt:h}),j=createToken({name:"False",pattern:/false/i,longer_alt:h}),F=createToken({name:"Null",pattern:/null/i,longer_alt:h}),x=createToken({name:"Return",pattern:/return/i,longer_alt:h}),D=createToken({name:"Unsafe",pattern:/unsafe/i,longer_alt:h}),W=createToken({name:"EqualsEquals",pattern:/==/}),Y=createToken({name:"EqualsEqualsEquals",pattern:/===/}),G=createToken({name:"NotEquals",pattern:/!=/}),Q=createToken({name:"NotEqualsEquals",pattern:/!==/}),J=createToken({name:"LessThanOrEqual",pattern:/<=/}),V=createToken({name:"GreaterThanOrEqual",pattern:/>=/}),K=createToken({name:"LessThan",pattern:/</}),Z=createToken({name:"GreaterThan",pattern:/>/}),H=createToken({name:"And",pattern:/&&/}),X=createToken({name:"Or",pattern:/\|\|/}),tt=createToken({name:"Not",pattern:/!/}),y=createToken({name:"Equals",pattern:/=/}),et=createToken({name:"Plus",pattern:/\+/}),O=createToken({name:"Minus",pattern:/-/}),rt=createToken({name:"Times",pattern:/\*/}),st=createToken({name:"Divide",pattern:/\//}),c=createToken({name:"LParen",pattern:/\(/}),f=createToken({name:"RParen",pattern:/\)/}),S=createToken({name:"Comma",pattern:/,/}),it=createToken({name:"StringLiteral",pattern:/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/}),nt=createToken({name:"NumericLiteral",pattern:/-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/}),at=[At,Ut,Tt,L,T,N,B,M,I,q,P,w,k,R,z,_,j,F,x,D,Y,W,Q,G,J,V,H,X,y,K,Z,tt,et,O,rt,st,c,f,S,it,nt,C,h],mt=new Lexer(at);var ot=class extends CstParser{constructor(){super(at),this.performSelfAnalysis();}query=this.RULE("query",()=>{this.CONSUME(L),this.SUBRULE(this.typeFormat,{LABEL:"sourceType"}),this.CONSUME(T),this.SUBRULE1(this.typeFormat,{LABEL:"targetType"}),this.OPTION(()=>{this.CONSUME(N),this.OPTION1(()=>{this.CONSUME(D);}),this.MANY(()=>{this.SUBRULE(this.action);});});});typeFormat=this.RULE("typeFormat",()=>{this.SUBRULE(this.anyIdentifier,{LABEL:"name"}),this.OPTION(()=>{this.CONSUME(c),this.MANY_SEP({SEP:S,DEF:()=>{this.SUBRULE(this.typeFormatParameter,{LABEL:"params"});}}),this.CONSUME(f);});});typeFormatParameter=this.RULE("typeFormatParameter",()=>{this.OR([{GATE:()=>this.LA(2).tokenType===y,ALT:()=>this.SUBRULE(this.namedParameter)},{ALT:()=>this.SUBRULE(this.literal)}]);});namedParameter=this.RULE("namedParameter",()=>{this.SUBRULE(this.anyIdentifier,{LABEL:"key"}),this.CONSUME(y),this.SUBRULE(this.literal,{LABEL:"value"});});anyIdentifier=this.RULE("anyIdentifier",()=>{this.OR([{ALT:()=>this.CONSUME(h)},{ALT:()=>this.CONSUME(C)}]);});literal=this.RULE("literal",()=>{this.OR([{ALT:()=>this.CONSUME(it)},{ALT:()=>this.CONSUME(nt)},{ALT:()=>this.CONSUME(_)},{ALT:()=>this.CONSUME(j)},{ALT:()=>this.CONSUME(F)}]);});action=this.RULE("action",()=>{this.OR([{ALT:()=>this.SUBRULE(this.setRule)},{ALT:()=>this.SUBRULE(this.modifyRule)},{ALT:()=>this.SUBRULE(this.sectionRule)},{ALT:()=>this.SUBRULE(this.cloneRule)},{ALT:()=>this.SUBRULE(this.deleteRule)},{ALT:()=>this.SUBRULE(this.ifAction)},{ALT:()=>this.SUBRULE(this.defineRule)},{ALT:()=>this.SUBRULE(this.returnRule)}]);});returnRule=this.RULE("returnRule",()=>{this.CONSUME(x),this.SUBRULE(this.expression,{LABEL:"expr"});});deleteRule=this.RULE("deleteRule",()=>{this.CONSUME(P),this.SUBRULE(this.anyIdentifier,{LABEL:"field"});});ifAction=this.RULE("ifAction",()=>{this.CONSUME(R),this.CONSUME(c),this.SUBRULE(this.expression,{LABEL:"condition"}),this.CONSUME(f),this.CONSUME2(c),this.MANY(()=>{this.SUBRULE(this.action,{LABEL:"thenActions"});}),this.CONSUME2(f),this.OPTION(()=>{this.CONSUME(z),this.CONSUME3(c),this.MANY2(()=>{this.SUBRULE2(this.action,{LABEL:"elseActions"});}),this.CONSUME3(f);});});cloneRule=this.RULE("cloneRule",()=>{this.CONSUME(q),this.OPTION(()=>{this.CONSUME(c),this.MANY_SEP({SEP:S,DEF:()=>{this.SUBRULE(this.anyIdentifier,{LABEL:"fields"});}}),this.CONSUME(f);});});setRule=this.RULE("setRule",()=>{this.CONSUME(B),this.SUBRULE(this.anyIdentifier,{LABEL:"left"}),this.CONSUME(y),this.SUBRULE(this.expression,{LABEL:"right"});});modifyRule=this.RULE("modifyRule",()=>{this.CONSUME(k),this.SUBRULE(this.anyIdentifier,{LABEL:"left"}),this.CONSUME(y),this.SUBRULE(this.expression,{LABEL:"right"});});expression=this.RULE("expression",()=>{this.SUBRULE(this.logicalOr);});logicalOr=this.RULE("logicalOr",()=>{this.SUBRULE(this.logicalAnd,{LABEL:"lhs"}),this.MANY(()=>{this.CONSUME(X),this.SUBRULE1(this.logicalAnd,{LABEL:"rhs"});});});logicalAnd=this.RULE("logicalAnd",()=>{this.SUBRULE(this.comparison,{LABEL:"lhs"}),this.MANY(()=>{this.CONSUME(H),this.SUBRULE1(this.comparison,{LABEL:"rhs"});});});comparison=this.RULE("comparison",()=>{this.SUBRULE(this.addition,{LABEL:"lhs"}),this.OPTION(()=>{this.OR([{ALT:()=>this.CONSUME(W,{LABEL:"ops"})},{ALT:()=>this.CONSUME(Y,{LABEL:"ops"})},{ALT:()=>this.CONSUME(G,{LABEL:"ops"})},{ALT:()=>this.CONSUME(Q,{LABEL:"ops"})},{ALT:()=>this.CONSUME(J,{LABEL:"ops"})},{ALT:()=>this.CONSUME(V,{LABEL:"ops"})},{ALT:()=>this.CONSUME(K,{LABEL:"ops"})},{ALT:()=>this.CONSUME(Z,{LABEL:"ops"})}]),this.SUBRULE1(this.addition,{LABEL:"rhs"});});});addition=this.RULE("addition",()=>{this.SUBRULE(this.multiplication,{LABEL:"lhs"}),this.MANY(()=>{this.OR([{ALT:()=>this.CONSUME(et,{LABEL:"ops"})},{ALT:()=>this.CONSUME(O,{LABEL:"ops"})}]),this.SUBRULE1(this.multiplication,{LABEL:"rhs"});});});multiplication=this.RULE("multiplication",()=>{this.SUBRULE(this.unaryExpression,{LABEL:"lhs"}),this.MANY(()=>{this.OR([{ALT:()=>this.CONSUME(rt,{LABEL:"ops"})},{ALT:()=>this.CONSUME(st,{LABEL:"ops"})}]),this.SUBRULE1(this.unaryExpression,{LABEL:"rhs"});});});unaryExpression=this.RULE("unaryExpression",()=>{this.OPTION(()=>{this.OR([{ALT:()=>this.CONSUME(O,{LABEL:"sign"})},{ALT:()=>this.CONSUME(tt,{LABEL:"sign"})}]);}),this.SUBRULE(this.atomic);});atomic=this.RULE("atomic",()=>{this.OR([{ALT:()=>this.SUBRULE(this.literal)},{GATE:()=>this.LA(2).tokenType===c,ALT:()=>this.SUBRULE(this.functionCall)},{ALT:()=>this.SUBRULE(this.anyIdentifier)},{ALT:()=>{this.CONSUME(c),this.SUBRULE(this.expression),this.CONSUME(f);}}]);});functionCall=this.RULE("functionCall",()=>{this.OR([{ALT:()=>this.CONSUME(h,{LABEL:"name"})},{ALT:()=>this.CONSUME(R,{LABEL:"name"})}]),this.CONSUME(c),this.MANY_SEP({SEP:S,DEF:()=>{this.SUBRULE(this.expression,{LABEL:"args"});}}),this.CONSUME(f);});sectionRule=this.RULE("sectionRule",()=>{this.CONSUME(M),this.OPTION(()=>{this.CONSUME(I);}),this.SUBRULE(this.anyIdentifier,{LABEL:"sectionName"}),this.CONSUME(c),this.OPTION1(()=>{this.CONSUME(L,{LABEL:"subqueryFrom"}),this.SUBRULE(this.typeFormat,{LABEL:"subquerySourceType"}),this.CONSUME(T,{LABEL:"subqueryTo"}),this.SUBRULE1(this.typeFormat,{LABEL:"subqueryTargetType"}),this.OPTION2(()=>{this.CONSUME(N,{LABEL:"subqueryTransform"});});}),this.MANY(()=>{this.SUBRULE(this.action);}),this.CONSUME(f),this.OPTION3(()=>{this.CONSUME1(L,{LABEL:"followFrom"}),this.SUBRULE2(this.anyIdentifier,{LABEL:"followPath"});});});defineRule=this.RULE("defineRule",()=>{this.CONSUME(w),this.SUBRULE(this.anyIdentifier,{LABEL:"left"}),this.CONSUME(y),this.SUBRULE(this.expression,{LABEL:"right"});})},d=new ot;var ft={substring:s=>{if(s.length<2)throw new Error("substring() requires at least 2 arguments (string, start, [length])");let[t,e,r]=s;return r!==void 0?`String(${t}).slice(${e}, (${e}) + (${r}))`:`String(${t}).slice(${e})`},if:s=>{if(s.length!==3)throw new Error("if() requires exactly 3 arguments (condition, trueValue, falseValue)");let[t,e,r]=s;return `((${t}) ? (${e}) : (${r}))`},text:s=>{if(s.length!==1)throw new Error("text() requires exactly 1 argument (string or number)");let[t]=s;return `String(${t})`},replace:s=>{if(s.length!==3)throw new Error("replace() requires exactly 3 arguments (string, search, replacement)");let[t,e,r]=s;return `String(${t}).replace(${e}, ${r})`},number:s=>{if(s.length!==1)throw new Error("number() requires exactly 1 argument (string)");let[t]=s;return `Number(${t})`},extractnumber:s=>{if(s.length!==1)throw new Error("extractNumber() requires exactly 1 argument (string)");let[t]=s;return `(() => { const match = String(${t}).match(/\\d+(\\.\\d+)?/); return match ? Number(match[0]) : null; })()`},uppercase:s=>{if(s.length!==1)throw new Error("uppercase() requires exactly 1 argument (string)");let[t]=s;return `String(${t}).toUpperCase()`},lowercase:s=>{if(s.length!==1)throw new Error("lowercase() requires exactly 1 argument (string)");let[t]=s;return `String(${t}).toLowerCase()`},xmlnode:s=>{if(s.length<1)throw new Error("xmlnode() requires at least 1 argument (string)");let t=s[0],e=[...s.slice(1)],r="";if(e.length>0){let i=[...e];i=[...Array(Math.ceil(i.length/2))].map(()=>i.splice(0,2)).map(([a,o])=>{let p=a;return a.startsWith('"')||a.startsWith("'")?p=`"$${a.slice(1,-1)}"`:p=`["$"+${a}]`,`${p}:${o||"null"}`}),r=","+i.join(",");}else return t;return `{_:${t}${r}}`},split:s=>{if(s.length<1)throw new Error("split() requires at least 1 argument (string)");let[t,e,r]=s,n=e!==void 0?e:'""',i=r!==void 0?`, ${r}`:"";return `String(${t}).split(${n}${i})`},to_base64:s=>{if(s.length!==1)throw new Error("to_base64() requires exactly 1 argument (string)");let[t]=s;return `(typeof btoa === 'function' ? btoa(unescape(encodeURIComponent(String(${t})))) : Buffer.from(String(${t}), 'utf-8').toString('base64'))`},from_base64:s=>{if(s.length!==1)throw new Error("from_base64() requires exactly 1 argument (string)");let[t]=s;return `(typeof atob === 'function' ? decodeURIComponent(escape(atob(String(${t})))) : Buffer.from(String(${t}), 'base64').toString('utf-8'))`},aslist:s=>{if(s.length!==1)throw new Error("aslist() requires exactly 1 argument");let[t]=s;return `(Array.isArray(${t}) ? ${t} : (${t} == null ? [] : [${t}]))`},spreadsheet:s=>{if(s.length!==1)throw new Error("spreadsheet() requires exactly 1 argument");let[t]=s;return `((data)=>{
|
|
2
2
|
const spreadsheet = Array.isArray(data) ? data : (data == null ? [] : [data]);
|
|
3
3
|
const out = [];
|
|
4
4
|
const titles = [];
|
|
@@ -18,67 +18,67 @@ import {createToken,Lexer,CstParser}from'chevrotain';import {XMLBuilder,XMLParse
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
return out;
|
|
21
|
-
})(${t})`}};var
|
|
21
|
+
})(${t})`}};var A=class{sourceRoot={type:"object",properties:{}};targetRoot={type:"object",properties:{}};sourceStack=[this.sourceRoot];targetStack=[this.targetRoot];getCurrentSource(){return this.sourceStack[this.sourceStack.length-1]}getCurrentTarget(){return this.targetStack[this.targetStack.length-1]}recordAccess(t,e="any",r=false){let n=r?this.getCurrentTarget():this.getCurrentSource();this.setInNode(n,t,e);}recordAssignment(t,e="any"){this.setInNode(this.getCurrentTarget(),t,e);}recordClone(t){let e=this.getCurrentTarget();t?t.forEach(r=>{this.setInNode(this.getCurrentSource(),r,"any"),this.setInNode(e,r,"any");}):e.isOpen=true;}recordDelete(t){let e=this.getCurrentTarget();this.deleteInNode(e,t);}pushSection(t,e,r){e!=="parent"&&this.setInNode(this.getCurrentSource(),e,r?"array":"object");let n={type:r?"array":"object"};r?n.items={type:"object",properties:{}}:n.properties={};let i={type:"object",properties:{}};this.setInNodeExplicit(this.getCurrentTarget(),t,n),this.targetStack.push(r?n.items:n),this.sourceStack.push(i);}popSection(t,e){let r=this.sourceStack.pop();this.targetStack.pop();let n=this.getCurrentSource();if(t!=="parent"){let i=this.getOrSetNode(n,t,e?"array":"object"),a=e?i.items:i;a&&(a.properties||(a.properties={}),Object.assign(a.properties,r.properties||{}));}else n.properties||(n.properties={}),Object.assign(n.properties,r.properties||{});}setInNode(t,e,r){let n=e.split("."),i=t;for(let a=0;a<n.length;a++){let o=n[a];i.properties||(i.properties={}),a===n.length-1?i.properties[o]||(i.properties[o]={type:r},r==="object"?i.properties[o].properties={}:r==="array"&&(i.properties[o].items={type:"object",properties:{}})):(i.properties[o]||(i.properties[o]={type:"object",properties:{}}),i=i.properties[o]);}}setInNodeExplicit(t,e,r){let n=e.split("."),i=t;for(let a=0;a<n.length;a++){let o=n[a];i.properties||(i.properties={}),a===n.length-1?i.properties[o]=r:(i.properties[o]||(i.properties[o]={type:"object",properties:{}}),i=i.properties[o]);}}deleteInNode(t,e){let r=e.split("."),n=t;for(let i=0;i<r.length;i++){if(!n.properties)return;if(i===r.length-1)delete n.properties[r[i]];else if(n=n.properties[r[i]],!n)return}}getOrSetNode(t,e,r){let n=e.split("."),i=t;for(let a=0;a<n.length;a++){let o=n[a],u=a===n.length-1?r:"object";i.properties||(i.properties={}),i.properties[o]||(i.properties[o]={type:u},u==="object"?i.properties[o].properties={}:u==="array"&&(i.properties[o].items={type:"object",properties:{}})),i=i.properties[o];}return i}getResult(){return {source:this.sourceRoot,target:this.targetRoot}}};var Ot=d.getBaseCstVisitorConstructor(),lt=class extends Ot{readFrom="source";scopeStack=[];safeMode=true;isAnalyzing=false;tracker=new A;lastInferredType="any";constructor(){super(),this.validateVisitor();}visitWithContext(t,e){let r=this.readFrom;this.readFrom=e.readFrom;let n=this.visit(t);return this.readFrom=r,n}query(t){this.isAnalyzing&&(this.tracker=new A);let e=this.visit(t.sourceType),r=this.visit(t.targetType),n=!!t.Unsafe;this.safeMode=!n,this.scopeStack.push({format:r.name,options:r.options,isSerializationScope:true});let i=t.action?t.action.map(m=>this.visit(m)):[];this.scopeStack.pop(),t.Transform||i.push("Object.assign(target, source);");let a=e.name,o=r.name,p=JSON.stringify(e.options),u=JSON.stringify(r.options),g=i.some(m=>typeof m=="string"&&m.trim().startsWith("return "));return {code:`
|
|
22
22
|
return function(input, env) {
|
|
23
23
|
// 1. Parse Input
|
|
24
|
-
const source = env.parse('${
|
|
24
|
+
const source = env.parse('${a}', input, ${p});
|
|
25
25
|
const _rootSource = source;
|
|
26
26
|
|
|
27
27
|
// 2. Transform
|
|
28
28
|
const target = {};
|
|
29
29
|
const _rootTarget = target;
|
|
30
|
-
${
|
|
30
|
+
${i.join(`
|
|
31
31
|
`)}
|
|
32
32
|
|
|
33
33
|
// 3. Serialize Output
|
|
34
|
-
${
|
|
34
|
+
${g?"":`return env.serialize('${o}', target, ${u});`}
|
|
35
35
|
}
|
|
36
|
-
`,sourceType:e,targetType:
|
|
37
|
-
`):"",
|
|
36
|
+
`,sourceType:e,targetType:r,analysis:this.isAnalyzing?this.tracker.getResult():void 0}}typeFormat(t){let e=this.visit(t.name),r={params:[]};return t.params&&t.params.forEach(n=>{let i=this.visit(n);typeof i=="object"&&"key"in i?r[i.key]=this.parseLiteral(i.value):r.params.push(this.parseLiteral(i));}),{name:e.name,options:r}}typeFormatParameter(t){if(t.namedParameter)return this.visit(t.namedParameter);if(t.literal)return this.visit(t.literal)}namedParameter(t){let e=this.visit(t.key).name,r=this.visit(t.value);return {key:e,value:r}}parseLiteral(t){if(t==="true")return true;if(t==="false")return false;if(t==="null")return null;if(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'"))return t.slice(1,-1);let e=Number(t);return isNaN(e)?t:e}genAccess(t,e,r=false){let n=this.safeMode&&!r?"?.":".";return e.quoted||e.name.includes("-")&&!e.name.includes(".")&&!e.name.includes("[")?`${t}${this.safeMode&&!r?"?.":""}["${e.name}"]`:`${t}${n}${e.name}`}anyIdentifier(t){if(t.Identifier)return {name:t.Identifier[0].image,quoted:false};if(t.QuotedIdentifier)return {name:t.QuotedIdentifier[0].image.slice(1,-1).replace(/\\(.)/g,"$1"),quoted:true}}literal(t){if(t.StringLiteral)return this.lastInferredType="string",t.StringLiteral[0].image;if(t.NumericLiteral)return this.lastInferredType="number",t.NumericLiteral[0].image;if(t.True)return this.lastInferredType="boolean","true";if(t.False)return this.lastInferredType="boolean","false";if(t.Null)return this.lastInferredType="null","null"}action(t){if(t.setRule)return this.visit(t.setRule);if(t.modifyRule)return this.visit(t.modifyRule);if(t.sectionRule)return this.visit(t.sectionRule);if(t.cloneRule)return this.visit(t.cloneRule);if(t.ifAction)return this.visit(t.ifAction);if(t.deleteRule)return this.visit(t.deleteRule);if(t.defineRule)return this.visit(t.defineRule);if(t.returnRule)return this.visit(t.returnRule)}deleteRule(t){let e=this.visit(t.field);return this.isAnalyzing&&this.tracker.recordDelete(e.name),`delete ${this.genAccess("target",e,true)};`}ifAction(t){let e=this.visit(t.condition),r=t.thenActions?t.thenActions.map(i=>this.visit(i)).join(`
|
|
37
|
+
`):"",n=t.elseActions?`else { ${t.elseActions.map(i=>this.visit(i)).join(`
|
|
38
38
|
`)} }`:"";return `if (${e}) {
|
|
39
|
-
${
|
|
40
|
-
} ${
|
|
41
|
-
`)
|
|
42
|
-
if (${
|
|
43
|
-
${
|
|
44
|
-
const subSource = env.parse('${
|
|
39
|
+
${r}
|
|
40
|
+
} ${n}`}cloneRule(t){if(t.fields){let e=t.fields.map(r=>this.visit(r));return this.isAnalyzing&&this.tracker.recordClone(e.map(r=>r.name)),e.map(r=>`${this.genAccess("target",r,true)} = ${this.genAccess("source",r)};`).join(`
|
|
41
|
+
`)}return this.isAnalyzing&&this.tracker.recordClone(),"Object.assign(target, source);"}setRule(t){let e=this.visit(t.left);this.lastInferredType="any";let r=this.visit(t.right);return this.isAnalyzing&&this.tracker.recordAssignment(e.name,this.lastInferredType),`${this.genAccess("target",e,true)} = ${r};`}modifyRule(t){let e=this.visit(t.left);this.lastInferredType="any";let r=this.visitWithContext(t.right,{readFrom:"target"});return this.isAnalyzing&&this.tracker.recordAssignment(e.name,this.lastInferredType),`${this.genAccess("target",e,true)} = ${r};`}defineRule(t){let e=this.visit(t.left);this.lastInferredType="any";let r=this.visit(t.right);return this.isAnalyzing&&this.tracker.recordAssignment(e.name,this.lastInferredType),`${this.genAccess("source",e,true)} = ${r};`}returnRule(t){let e=this.visitWithContext(t.expr,{readFrom:"target"}),r=this.scopeStack[this.scopeStack.length-1];if(r&&r.isSerializationScope){let n=JSON.stringify(r.options);return `return env.serialize('${r.format}', ${e}, ${n});`}return `return ${e};`}expression(t){return this.visit(t.logicalOr)}logicalOr(t){let e=this.visit(t.lhs);if(t.rhs&&t.rhs.length>0){this.lastInferredType="boolean";for(let r=0;r<t.rhs.length;r++){let n=this.visit(t.rhs[r]);e=`${e} || ${n}`;}}return e}logicalAnd(t){let e=this.visit(t.lhs);if(t.rhs&&t.rhs.length>0){this.lastInferredType="boolean";for(let r=0;r<t.rhs.length;r++){let n=this.visit(t.rhs[r]);e=`${e} && ${n}`;}}return e}comparison(t){let e=this.visit(t.lhs);if(t.rhs){this.lastInferredType="boolean";let r=t.ops[0].image,n=this.visit(t.rhs[0]);e=`${e} ${r} ${n}`;}return e}addition(t){let e=this.visit(t.lhs),r=this.lastInferredType,n=e;if(t.rhs&&t.rhs.length>0){let i=r==="string",a=r==="number";for(let o=0;o<t.rhs.length;o++){let p=t.ops[o].image,u=this.visit(t.rhs[o]);this.lastInferredType==="string"&&(i=true),this.lastInferredType!=="number"&&(a=false),n=`${n} ${p} ${u}`;}i?this.lastInferredType="string":a?this.lastInferredType="number":this.lastInferredType="any";}else this.lastInferredType=r;return n}multiplication(t){let e=this.visit(t.lhs);if(t.rhs&&t.rhs.length>0){this.lastInferredType="number";for(let r=0;r<t.rhs.length;r++){let n=t.ops[r].image,i=this.visit(t.rhs[r]);e=`${e} ${n} ${i}`;}}return e}unaryExpression(t){let e=this.visit(t.atomic);if(t.sign){let r=t.sign[0].image;return r==="!"&&(this.lastInferredType="boolean"),r==="-"&&(this.lastInferredType="number"),`${r}${e}`}return e}atomic(t){if(t.literal)return this.visit(t.literal);if(t.functionCall)return this.visit(t.functionCall);if(t.anyIdentifier){this.lastInferredType="any";let e=this.visit(t.anyIdentifier);if(["true","false","null"].includes(e.name)&&!e.quoted)return e.name;if(!e.quoted){if(e.name.startsWith("source.")||e.name.startsWith("source["))return this.isAnalyzing&&this.tracker.recordAccess(e.name.substring(7),"any",false),e.name;if(e.name.startsWith("target.")||e.name.startsWith("target["))return this.isAnalyzing&&this.tracker.recordAccess(e.name.substring(7),"any",true),e.name;if(e.name==="target")return "target";if(e.name==="source")return "source";if(e.name==="_source"||e.name.startsWith("_source.")||e.name.startsWith("_source["))return this.isAnalyzing&&this.tracker.recordAccess(e.name.substring(7)||"","any",false),`_rootSource${e.name.substring(7)}`;if(e.name==="_target"||e.name.startsWith("_target.")||e.name.startsWith("_target["))return this.isAnalyzing&&this.tracker.recordAccess(e.name.substring(7)||"","any",true),`_rootTarget${e.name.substring(7)}`}return this.isAnalyzing&&this.tracker.recordAccess(e.name,"any",this.readFrom==="target"),this.genAccess(this.readFrom,e)}if(t.expression)return `(${this.visit(t.expression)})`}functionCall(t){let e=t.name[0].image,r=(e.startsWith("`")?e.slice(1,-1):e).toLowerCase(),n=t.args?t.args.map(a=>this.visit(a)):[],i=ft[r];if(i)return ["substring","text","replace","uppercase","lowercase","to_base64","from_base64"].includes(r)?this.lastInferredType="string":["number","extractnumber"].includes(r)?this.lastInferredType="number":["aslist"].includes(r)?this.lastInferredType="array":r==="asobject"&&(this.lastInferredType="object"),i(n);throw new Error(`Unknown function: ${e}`)}sectionRule(t){let e=this.visit(t.sectionName),r=e.name,n=this.genAccess("target",e,true),i=t.followPath?this.visit(t.followPath):e,a=i.name==="parent"?"source":this.genAccess("source",i),o=!!t.Multiple;if(!!t.subqueryFrom){let E=this.visit(t.subquerySourceType),m=this.visit(t.subqueryTargetType);this.scopeStack.push({format:m.name,options:m.options,isSerializationScope:true});let Lt=!!t.subqueryTransform,$=t.action?t.action.map(St=>this.visit(St)):[];Lt||$.push("Object.assign(target, source);");let ut=JSON.stringify(E.options),ct=JSON.stringify(m.options),v="";return o?v=`
|
|
42
|
+
if (${a} && Array.isArray(${a})) {
|
|
43
|
+
${n} = ${a}.map(item => {
|
|
44
|
+
const subSource = env.parse('${E.name}', item, ${ut});
|
|
45
45
|
const source = subSource;
|
|
46
46
|
const target = {};
|
|
47
47
|
${$.join(`
|
|
48
48
|
`)}
|
|
49
|
-
return env.serialize('${
|
|
49
|
+
return env.serialize('${m.name}', target, ${ct});
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
|
-
`:
|
|
53
|
-
if (${
|
|
54
|
-
${
|
|
55
|
-
const subSource = env.parse('${
|
|
52
|
+
`:v=`
|
|
53
|
+
if (${a}) {
|
|
54
|
+
${n} = (function(innerSource) {
|
|
55
|
+
const subSource = env.parse('${E.name}', innerSource, ${ut});
|
|
56
56
|
const source = subSource;
|
|
57
57
|
const target = {};
|
|
58
58
|
${$.join(`
|
|
59
59
|
`)}
|
|
60
|
-
return env.serialize('${
|
|
61
|
-
})(${
|
|
60
|
+
return env.serialize('${m.name}', target, ${ct});
|
|
61
|
+
})(${a});
|
|
62
62
|
}
|
|
63
|
-
`,this.scopeStack.pop(),
|
|
64
|
-
if (${
|
|
65
|
-
${
|
|
63
|
+
`,this.scopeStack.pop(),v}this.scopeStack.push({format:"object",options:{},isSerializationScope:false}),this.isAnalyzing&&this.tracker.pushSection(r,i.name,o);let u=t.action?t.action.map(E=>this.visit(E)):[];this.isAnalyzing&&this.tracker.popSection(i.name,o);let g="";return o?g=`
|
|
64
|
+
if (${a} && Array.isArray(${a})) {
|
|
65
|
+
${n} = ${a}.map(item => {
|
|
66
66
|
const source = item;
|
|
67
67
|
const target = {};
|
|
68
|
-
${
|
|
68
|
+
${u.join(`
|
|
69
69
|
`)}
|
|
70
70
|
return target;
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
|
-
`:
|
|
74
|
-
if (${
|
|
75
|
-
${
|
|
73
|
+
`:g=`
|
|
74
|
+
if (${a}) {
|
|
75
|
+
${n} = (function(innerSource) {
|
|
76
76
|
const source = innerSource;
|
|
77
77
|
const target = {};
|
|
78
|
-
${
|
|
78
|
+
${u.join(`
|
|
79
79
|
`)}
|
|
80
80
|
return target;
|
|
81
|
-
})(${
|
|
81
|
+
})(${a});
|
|
82
82
|
}
|
|
83
|
-
`,this.scopeStack.pop(),
|
|
83
|
+
`,this.scopeStack.pop(),g}},ht=new lt;var dt={};function b(s,t){dt[s.toLowerCase()]=t;}function pt(s){let t=dt[s.toLowerCase()];if(!t)throw new Error(`No adapter found for format: ${s}`);return t}function $t(s){let t="";for(;s>=0;)t=String.fromCharCode(s%26+65)+t,s=Math.floor(s/26)-1;return t}b("json",{parse:s=>typeof s!="string"?s:JSON.parse(s),serialize:s=>JSON.stringify(s,null,2)});var vt=new XMLBuilder({ignoreAttributes:false,attributeNamePrefix:"$",textNodeName:"_",format:true});b("xml",{parse:(s,t)=>typeof s!="string"?s:new XMLParser({ignoreAttributes:false,removeNSPrefix:true,...t}).parse(s),serialize:(s,t)=>{let e=t?.rootGenerated??t?.params?.[0]??"root";return (t?new XMLBuilder({ignoreAttributes:false,attributeNamePrefix:"$",textNodeName:"_",format:true,...t}):vt).build({[e]:s})}});b("csv",{parse:(s,t)=>{if(typeof s!="string")return s;let e=t?.delimiter??t?.params?.[0]??",";return {rows:gt.parse(s,{delimiter:e,skipEmptyLines:true,...t}).data.map(i=>{let a={};return Array.isArray(i)&&i.forEach((o,p)=>{a[$t(p)]=o;}),a})}},serialize:(s,t)=>{if(!s||!Array.isArray(s.rows))return "";let e=t?.delimiter??t?.params?.[0]??",",r=s.rows.map(n=>Object.keys(n).filter(a=>/^[A-Z]+$/.test(a)).sort((a,o)=>a.length!==o.length?a.length-o.length:a.localeCompare(o)).map(a=>n[a]));return gt.unparse(r,{delimiter:e,...t})}});b("object",{parse:s=>s,serialize:s=>s});async function Xt(s,t){if(t?.cache){let g=await t.cache.retrieve(s);if(g)return Et(g)}let e=mt.tokenize(s);if(e.errors.length>0)throw new Error(`Lexing errors: ${e.errors[0].message}`);d.input=e.tokens;let r=d.query();if(d.errors.length>0)throw new Error(`Parsing errors: ${d.errors[0].message}`);ht.isAnalyzing=!!t?.analyze;let{code:n,analysis:i,sourceType:a,targetType:o}=ht.visit(r),p=Ct.js(n,{indent_size:2,space_in_empty_paren:true,end_with_newline:true});t?.cache&&await t.cache.save(s,p);let u=Et(p);return i&&(i.sourceFormat=a.name,i.targetFormat=o.name,u.analysis=i),u}function Et(s){let e=new Function(s)(),r={parse:(i,a,o)=>pt(i).parse(a,o),serialize:(i,a,o)=>pt(i).serialize(a,o)},n=(i=>e(i,r));return n.code=s,n}function te(s,...t){return s.reduce((e,r,n)=>e+r+(t[n]??""),"")}function ee(s){return `Hello, ${s}! The Morph engine is ready.`}export{Xt as compile,ee as greet,te as morphQL};//# sourceMappingURL=index.js.map
|
|
84
84
|
//# sourceMappingURL=index.js.map
|