@morphql/core 0.1.9 → 0.1.11
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 +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { M as MorphQLCache } from './cache-DDvLhPfR.cjs';
|
|
2
2
|
|
|
3
|
+
interface DataAdapter {
|
|
4
|
+
parse(content: string, options?: any): any;
|
|
5
|
+
serialize(data: any, options?: any): string;
|
|
6
|
+
}
|
|
7
|
+
declare function registerAdapter(name: string, adapter: DataAdapter): void;
|
|
8
|
+
declare function getAdapter(name: string): DataAdapter;
|
|
9
|
+
|
|
3
10
|
type MorphType = 'string' | 'number' | 'boolean' | 'null' | 'object' | 'array' | 'any';
|
|
4
11
|
interface SchemaNode {
|
|
5
12
|
type: MorphType;
|
|
@@ -44,4 +51,4 @@ declare function morphQL(strings: TemplateStringsArray, ...values: any[]): strin
|
|
|
44
51
|
*/
|
|
45
52
|
declare function greet(name: string): string;
|
|
46
53
|
|
|
47
|
-
export { type AnalyzeResult, type CompileOptions, type MorphEngine, MorphQLCache, type MorphType, type SchemaNode, compile, greet, morphQL };
|
|
54
|
+
export { type AnalyzeResult, type CompileOptions, type DataAdapter, type MorphEngine, MorphQLCache, type MorphType, type SchemaNode, compile, getAdapter, greet, morphQL, registerAdapter };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { M as MorphQLCache } from './cache-DDvLhPfR.js';
|
|
2
2
|
|
|
3
|
+
interface DataAdapter {
|
|
4
|
+
parse(content: string, options?: any): any;
|
|
5
|
+
serialize(data: any, options?: any): string;
|
|
6
|
+
}
|
|
7
|
+
declare function registerAdapter(name: string, adapter: DataAdapter): void;
|
|
8
|
+
declare function getAdapter(name: string): DataAdapter;
|
|
9
|
+
|
|
3
10
|
type MorphType = 'string' | 'number' | 'boolean' | 'null' | 'object' | 'array' | 'any';
|
|
4
11
|
interface SchemaNode {
|
|
5
12
|
type: MorphType;
|
|
@@ -44,4 +51,4 @@ declare function morphQL(strings: TemplateStringsArray, ...values: any[]): strin
|
|
|
44
51
|
*/
|
|
45
52
|
declare function greet(name: string): string;
|
|
46
53
|
|
|
47
|
-
export { type AnalyzeResult, type CompileOptions, type MorphEngine, MorphQLCache, type MorphType, type SchemaNode, compile, greet, morphQL };
|
|
54
|
+
export { type AnalyzeResult, type CompileOptions, type DataAdapter, type MorphEngine, MorphQLCache, type MorphType, type SchemaNode, compile, getAdapter, greet, morphQL, registerAdapter };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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)=>{
|
|
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}),N=createToken({name:"To",pattern:/to/i,longer_alt:h}),R=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}),O=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:/\+/}),b=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,N,R,B,M,I,q,P,w,k,O,z,_,j,F,x,D,Y,W,Q,G,J,V,H,X,y,K,Z,tt,et,b,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(N),this.SUBRULE1(this.typeFormat,{LABEL:"targetType"}),this.OPTION(()=>{this.CONSUME(R),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(O),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(b,{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(b,{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(O,{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(N,{LABEL:"subqueryTo"}),this.SUBRULE1(this.typeFormat,{LABEL:"subqueryTargetType"}),this.OPTION2(()=>{this.CONSUME(R,{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 = [];
|
|
@@ -80,5 +80,5 @@ import {createToken,Lexer,CstParser}from'chevrotain';import {XMLBuilder,XMLParse
|
|
|
80
80
|
return target;
|
|
81
81
|
})(${a});
|
|
82
82
|
}
|
|
83
|
-
`,this.scopeStack.pop(),g}},ht=new lt;var dt={};function
|
|
83
|
+
`,this.scopeStack.pop(),g}},ht=new lt;var dt={};function U(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}U("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});U("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})}});U("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})}});U("object",{parse:s=>s,serialize:s=>s});async function te(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 ee(s,...t){return s.reduce((e,r,n)=>e+r+(t[n]??""),"")}function re(s){return `Hello, ${s}! The Morph engine is ready.`}export{te as compile,pt as getAdapter,re as greet,ee as morphQL,U as registerAdapter};//# sourceMappingURL=index.js.map
|
|
84
84
|
//# sourceMappingURL=index.js.map
|