@cap.core/ql 1.2.5 → 1.3.0

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/@types/cqn.d.ts CHANGED
@@ -111,7 +111,7 @@ interface infix {
111
111
  */
112
112
  export type expr = OneOf< ref | val | xpr | list | func | param | SELECT >
113
113
  export type ref = { ref: OneOf< name | { id:name } &infix >[] }
114
- export type val = { val: scalar }
114
+ export type val = { val: string | number | boolean | null }
115
115
  export type xpr = { xpr: xo[] }
116
116
  export type list = { list: expr[] }
117
117
  export type func = { func: string, args: expr[] }
@@ -126,10 +126,10 @@ export type param = { ref: [ '?' | number | string ], param: true }
126
126
  * including support for native SQL features.
127
127
  */
128
128
  export type xo = OneOf< expr | keyword | operator >
129
- type operator = '=' | '==' | '!=' | '<' | '<=' | '>' | '>='
130
- type keyword = 'in' | 'like' | 'and' | 'or' | 'not'
131
- type scalar = number | string | boolean | null
132
- type name = string
129
+ export type operator = '=' | '==' | '!=' | '<' | '<=' | '>' | '>='
130
+ export type keyword = 'in' | 'like' | 'and' | 'or' | 'not'
131
+ export type scalar = number | string | boolean | null
132
+ export type name = string
133
133
 
134
134
 
135
135
 
package/@types/exprs.d.ts CHANGED
@@ -1,59 +1,51 @@
1
1
  import * as cqn from './cqn'
2
- export function columns () : cqn.column[]
3
- export function orderBy () : cqn.order[]
4
- export function entity () : cqn.ref
5
- export function where () : cqn.xo[]
6
2
 
7
- /**
8
- * This is the template string variant of `expr`. The argument is a template string,
9
- * which can contain interpolations of other CQN expressions, references, and values.
10
- */
11
- export function expr (strings: TemplateStringsArray, ...values: any[]) : cqn.expr
12
-
13
- /**
14
- * This is a fluent variant of `expr` for the case where the argument is a simple
15
- * array of scalar values. In this case, it constructs a CQN `{list}` expression.
16
- */
17
- export function expr (list: cqn.scalar[]) : cqn.list
3
+ type ttl = TemplateStringsArray
4
+ type scalar = cqn.scalar
5
+ type path = string
18
6
 
19
7
  /**
20
- * This is a fluent variant of `expr` for the case where the argument is a single
21
- * scalar value. In this case, it constructs a CQN `{val}` expression.
8
+ * Constructs a `{val}` CQN object. The argument can be either a template string
9
+ * with interpolations of strings, numbers, booleans, null, or a simple scalar value.
22
10
  */
23
- export function expr (val: cqn.scalar) : cqn.val
24
-
11
+ export function val (strings: ttl) : cqn.val
12
+ export function val <T extends scalar> (val: T) : { val: T }
25
13
 
26
14
  /**
27
- * This is the template string variant of `ref`. The argument is a template string,
28
- * which forms a path expression, with optional infix filters.
15
+ * Constructs a `{ref}` CQN object. The argument can be either a template string which
16
+ * can contain complex path expressions, including infix filters, function calls,
17
+ * or a string which will be split into path segments.
29
18
  */
30
- export function ref (strings: TemplateStringsArray, ...values: any[]) : cqn.ref
19
+ export function ref (strings: ttl) : cqn.ref
20
+ export function ref (path: path) : cqn.ref
31
21
 
32
22
  /**
33
- * This is the fluent variant of `ref` for the case where the arguments are simple
34
- * path segments. It constructs a CQN `{ref}` expression.
23
+ * Contstructs a `{xpr}`, `{ref}`, `{val}`, `{func}`, or `{list}` CQN object.
24
+ * The argument can be either a template string which can contain complex expressions
25
+ * with operators, function calls, or a simple value or an array of simple values.
35
26
  */
36
- export function ref (...path: string[]) : cqn.ref
37
-
38
-
39
- /**
40
- * This is the template string variant of `val`. The argument is a template string,
41
- * which can contain interpolations of strings, numbers, booleans, null.
42
- */
43
- export function val (strings: TemplateStringsArray, ...values: any[]) : cqn.val
44
-
45
- /**
46
- * This is the fluent variant of `val` for the case where the argument is a single
47
- * scalar value. In this case, it constructs a CQN `{val}` expression.
48
- */
49
- export function val (val: cqn.scalar) : cqn.val
27
+ export function expr (ttl: ttl) : cqn.expr
28
+ export function expr <T extends scalar> (val: T) : { val: T }
29
+ export function expr (vals: scalar[] ) : cqn.list
50
30
 
31
+ export function subject(): cqn.ref
32
+ export function columns() : cqn.column[]
33
+ export function values(): cqn.val[]
34
+ export function where() : cqn.xo[]
35
+ export function having() : cqn.xo[]
36
+ export function groupBy() : cqn.column[]
37
+ export function orderBy() : cqn.order[]
51
38
 
52
39
 
53
40
  export interface fluent {
41
+ val : typeof val
42
+ ref : typeof ref
54
43
  expr : typeof expr
55
- entity : typeof entity
44
+ subject : typeof subject
56
45
  columns : typeof columns
57
- orderBy : typeof orderBy
46
+ values : typeof values
58
47
  where : typeof where
48
+ having : typeof having
49
+ groupBy : typeof groupBy
50
+ orderBy : typeof orderBy
59
51
  }
package/@types/index.d.ts CHANGED
@@ -1 +1,29 @@
1
+ import { Query } from './query.js'
2
+ import { SELECT as SELECT_ } from './ql/select.js'
3
+ import { INSERT as INSERT_ } from './ql/insert.js'
4
+ import { UPSERT as UPSERT_ } from './ql/insert.js'
5
+ import { UPDATE as UPDATE_ } from './ql/update.js'
6
+ import { DELETE as DELETE_ } from './ql/delete.js'
7
+
8
+ /**
9
+ * This is the central entry point for creating queries from various types of input:
10
+ * - If the input is a `Query` instance already, it's returned as-is.
11
+ * - If the input is a `string` or a template literal, it's parsed into a CQN object.
12
+ * - If the input is an `object` with a recognized query kind, it's cast into an instance of
13
+ * the corresponding query class.
14
+ * @param { Query | string | object } qso - The input, as described above, to be converted into an instance of a Query subclass.
15
+ * @param { ...any } args - Optional arguments for template literals or parameterized queries.
16
+ * @returns { SELECT & INSERT & UPSERT & UPDATE & DELETE }
17
+ */
18
+ export function cql (
19
+ qso: Query | string | object, ...args: any[]
20
+ ): SELECT_ & INSERT_ & UPSERT_ & UPDATE_ & DELETE_
21
+
1
22
  export * from './exprs'
23
+ export { Query }
24
+ export const SELECT: (() => typeof SELECT_) & typeof SELECT_
25
+ export const INSERT: (() => typeof INSERT_) & typeof INSERT_
26
+ export const UPSERT: (() => typeof UPSERT_) & typeof UPSERT_
27
+ export const UPDATE: (() => typeof UPDATE_) & typeof UPDATE_
28
+ export const DELETE: (() => typeof DELETE_) & typeof DELETE_
29
+ export default cql
@@ -0,0 +1,8 @@
1
+ import { Query } from '../query.js';
2
+ import * as cqn from '../cqn'
3
+
4
+ export class DELETE extends Query {
5
+ static from(...args: any[]): DELETE;
6
+ DELETE: cqn.DELETE;
7
+ where(...args: any[]): this;
8
+ }
@@ -0,0 +1,19 @@
1
+ import { Query } from '../query.js';
2
+ import * as cqn from '../cqn'
3
+
4
+ export class XSERT extends Query {
5
+ static entries(...args: any[]): XSERT;
6
+ static into(x: any, ...tail: any[]): XSERT;
7
+ into(...args: any[]): this;
8
+ entries(...args: any[]): this;
9
+ columns(...args: any[]): this;
10
+ values(...args: any[]): this;
11
+ rows(...args: any[]): this;
12
+ from(...args: any[]): this;
13
+ }
14
+ export class INSERT extends XSERT {
15
+ INSERT: cqn.INSERT;
16
+ }
17
+ export class UPSERT extends XSERT {
18
+ UPSERT: cqn.UPSERT;
19
+ }
@@ -0,0 +1,24 @@
1
+ import { Query } from '../query.js';
2
+ import * as cqn from '../cqn'
3
+
4
+ export class SELECT extends Query {
5
+ static from(...args: any[]): SELECT;
6
+ static columns(...args: any[]): SELECT;
7
+ static get localized(): SELECT;
8
+ static get distinct(): SELECT;
9
+ static get one(): SELECT;
10
+ SELECT: cqn.SELECT;
11
+ get localized(): this;
12
+ get distinct(): this;
13
+ get one(): this;
14
+ columns(...args: any[]): this;
15
+ from(...args: any[]): this;
16
+ where(...args: any[]): this;
17
+ having(...args: any[]): this;
18
+ groupBy(...args: any[]): this;
19
+ orderBy(...args: any[]): this;
20
+ limit(...args: any[]): this;
21
+ top(...args: any[]): this;
22
+ skip(...args: any[]): this;
23
+ offset(...args: any[]): this;
24
+ }
@@ -0,0 +1,10 @@
1
+ import { Query } from '../query.js';
2
+ import * as cqn from '../cqn'
3
+
4
+ export class UPDATE extends Query {
5
+ static entity(...args: any[]): UPDATE;
6
+ UPDATE: cqn.UPDATE;
7
+ where(...args: any[]): this;
8
+ with(data: any, x: any): this;
9
+ set(data: any, x: any): this;
10
+ }
@@ -0,0 +1,18 @@
1
+ import * as cqn from './cqn'
2
+
3
+ export class Query {
4
+ /**
5
+ * - Fills in any binding `{param}`s with corresponding `{val}`s from given `args`.
6
+ * - If no `args` are provided, the ones collected during parsing are used.
7
+ */
8
+ bind(...args: any[]): this;
9
+
10
+ /**
11
+ * Returns the main subject `{ref}` of the query, which refers to the entity being queried or modified.
12
+ * - For `SELECT` and `DELETE` queries, this is the `from` clause.
13
+ * - For `INSERT` and `UPSERT` queries, this is the `into` clause.
14
+ * - For `UPDATE` queries, this is the `entity` clause.
15
+ * @returns {ref:string[]} The main subject of the query.
16
+ */
17
+ get subject(): cqn.ref;
18
+ }
package/cql/parser.min.js CHANGED
@@ -1,2 +1 @@
1
- export const $=Object.assign,px=()=>({param:"?"}),ql={SELECT:function(t){Object.defineProperty(Object.assign(this,t),"_",{value:this})},INSERT:function(t){Object.defineProperty(Object.assign(this,t),"_",{value:this})},UPSERT:function(t){Object.defineProperty(Object.assign(this,t),"_",{value:this})},UPDATE:function(t){Object.defineProperty(Object.assign(this,t),"_",{value:this})},DELETE:function(t){Object.defineProperty(Object.assign(this,t),"_",{value:this})},fluent:{subject:px,where:px,expr:px}};class peg$SyntaxError extends SyntaxError{constructor(t,e,n,r){super(t),this.expected=e,this.found=n,this.location=r,this.name="SyntaxError"}format(t){let e="Error: "+this.message;if(this.location){let n=null;const r=t.find(t=>t.source===this.location.source);r&&(n=r.text.split(/\r\n|\n|\r/g));const s=this.location.start,o=this.location.source&&"function"==typeof this.location.source.offset?this.location.source.offset(s):s,u=this.location.source+":"+o.line+":"+o.column;if(n){const t=this.location.end,r="".padEnd(o.line.toString().length," "),l=n[s.line-1],i=(s.line===t.line?t.column:l.length+1)-s.column||1;e+="\n --\x3e "+u+"\n"+r+" |\n"+o.line+" | "+l+"\n"+r+" | "+"".padEnd(s.column-1," ")+"".padEnd(i,"^")}else e+="\n at "+u}return e}static buildMessage(t,e){function n(t){return t.codePointAt(0).toString(16).toUpperCase()}const r=Object.prototype.hasOwnProperty.call(RegExp.prototype,"unicode")?new RegExp("[\\p{C}\\p{Mn}\\p{Mc}]","gu"):null;function s(t){return r?t.replace(r,t=>"\\u{"+n(t)+"}"):t}function o(t){return s(t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,t=>"\\x0"+n(t)).replace(/[\x10-\x1F\x7F-\x9F]/g,t=>"\\x"+n(t)))}function u(t){return s(t.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,t=>"\\x0"+n(t)).replace(/[\x10-\x1F\x7F-\x9F]/g,t=>"\\x"+n(t)))}const l={literal:t=>'"'+o(t.text)+'"',class(t){const e=t.parts.map(t=>Array.isArray(t)?u(t[0])+"-"+u(t[1]):u(t));return"["+(t.inverted?"^":"")+e.join("")+"]"+(t.unicode?"u":"")},any:()=>"any character",end:()=>"end of input",other:t=>t.description};function i(t){return l[t.type](t)}return"Expected "+function(t){const e=t.map(i);if(e.sort(),e.length>0){let t=1;for(let n=1;n<e.length;n++)e[n-1]!==e[n]&&(e[t]=e[n],t++);e.length=t}switch(e.length){case 1:return e[0];case 2:return e[0]+" or "+e[1];default:return e.slice(0,-1).join(", ")+", or "+e[e.length-1]}}(t)+" but "+function(t){return t?'"'+o(t)+'"':"end of input"}(e)+" found."}}function peg$parse(t,e){const n={},r=(e=void 0!==e?e:{}).grammarSource,s={CQL:xn,entity:Rn,columns:vn,ref:Fn,val:In,vals:Dn,expr:Pn,where:_n,groupBy:Sn,orderBy:$n};let o=xn;const u="select",l="localized",i="distinct",c="one",a="from",f="where",h="group by",p="having",d="order by",g="limit",b="offset",C="as",w="*",A="[",x="]",m="asc",E="desc",L="insert",v="upsert",y="into",_="entries",S="columns",O="rows",T="values",R="update",P="entity",j="with",F="set",I="=",D="delete",N=":",U="#",z="?",B="and",q="or",M="in",Z="between",H="like",W="exists",Y="contains",k="case",G="when",Q="then",V="else",J="end",K="is",X="not",tt="null",et="empty",nt="-",rt=".",st="e",ot="'",ut="''",lt="true",it="false",ct="{",at="}",ft="(",ht=")",pt=",",dt=/^[A-Za-z_$]/,gt=/^[A-Za-z0-9_$]/,bt=/^[!=><+\-*\/%&|\^~]/,Ct=/^[0-9]/,wt=/^[^']/,At=/^[A-Za-z_$0-9]/,xt=/^[ \t\n\r]/,mt=pn("SELECT",!0),Et=pn("LOCALIZED",!0),Lt=pn("DISTINCT",!0),vt=pn("ONE",!0),yt=pn("FROM",!0),_t={type:"any"},St=pn("WHERE",!0),$t=pn("GROUP BY",!0),Ot=pn("HAVING",!0),Tt=pn("ORDER BY",!0),Rt=pn("LIMIT",!0),Pt=pn("OFFSET",!0),jt=pn("as",!0),Ft=pn("*",!1),It=pn("[",!1),Dt=pn("]",!1),Nt=pn("asc",!0),Ut=pn("desc",!0),zt=pn("INSERT",!0),Bt=pn("UPSERT",!0),qt=pn("INTO",!0),Mt=pn("ENTRIES",!0),Zt=pn("COLUMNS",!0),Ht=pn("ROWS",!0),Wt=pn("VALUES",!0),Yt=pn("UPDATE",!0),kt=pn("ENTITY",!0),Gt=pn("WITH",!0),Qt=pn("SET",!0),Vt=pn("=",!1),Jt=pn("DELETE",!0),Kt=gn("a name"),Xt=pn("AS",!0),te=pn("from",!0),ee=dn([["A","Z"],["a","z"],"_","$"],!1,!1,!1),ne=dn([["A","Z"],["a","z"],["0","9"],"_","$"],!1,!1,!1),re=gn("an element ref"),se=gn("an entity ref"),oe=pn(":",!1),ue=gn("a reference"),le=gn("a value"),ie=gn("a list"),ce=gn("a function"),ae=gn("a symbol"),fe=pn("#",!1),he=gn("a parameter"),pe=pn("?",!1),de=gn("an operator"),ge=dn(["!","=",">","<","+","-","*","/","%","&","|","^","~"],!1,!1,!1),be=pn("and",!1),Ce=pn("or",!1),we=pn("in",!1),Ae=pn("between",!1),xe=pn("like",!1),me=pn("exists",!1),Ee=pn("contains",!1),Le=pn("case",!1),ve=pn("when",!1),ye=pn("then",!1),_e=pn("else",!1),Se=pn("end",!1),$e=pn("is",!1),Oe=pn("not",!1),Te=pn("null",!1),Re=pn("empty",!1),Pe=gn("a literal"),je=pn("-",!1),Fe=dn([["0","9"]],!1,!1,!1),Ie=pn(".",!1),De=pn("e",!1),Ne=pn("'",!1),Ue=dn(["'"],!0,!1,!1),ze=pn("''",!1),Be=pn("true",!1),qe=pn("false",!1),Me=pn("{",!1),Ze=pn("}",!1),He=pn("(",!1),We=pn(")",!1),Ye=dn([["A","Z"],["a","z"],"_","$",["0","9"]],!1,!1,!1),ke=gn("a comma"),Ge=pn(",",!1),Qe=gn(""),Ve=dn([" ","\t","\n","\r"],!1,!1,!1);function Je(e){return tr===ql.fluent||(or?.length&&(e.params=or),nr?.length&&(e.args=nr),e.source=t.substring(un,on)),e}function Ke(t,e){t.as=e}function Xe(t,e,n){e?t.inline=n:t.expand=n}function tn(t,e){t.as=e}function en(t,e){t.sort=e.toLowerCase()}function nn(t,e,n){t._.with[e]=n}function rn(t,e){return e?{id:t,...e}:t}function sn(){return"'"}let on=0|e.peg$currPos,un=on;const ln=[{line:1,column:1}];let cn,an=on,fn=e.peg$maxFailExpected||[],hn=0|e.peg$silentFails;if(e.startRule){if(!(e.startRule in s))throw new Error("Can't start parsing from rule \""+e.startRule+'".');o=s[e.startRule]}function pn(t,e){return{type:"literal",text:t,ignoreCase:e}}function dn(t,e,n,r){return{type:"class",parts:t,inverted:e,ignoreCase:n,unicode:r}}function gn(t){return{type:"other",description:t}}function bn(e){let n,r=ln[e];if(r)return r;if(e>=ln.length)n=ln.length-1;else for(n=e;!ln[--n];);for(r=ln[n],r={line:r.line,column:r.column};n<e;)10===t.charCodeAt(n)?(r.line++,r.column=1):r.column++,n++;return ln[e]=r,r}function Cn(t,e,n){const s=bn(t),o=bn(e),u={source:r,start:{offset:t,line:s.line,column:s.column},end:{offset:e,line:o.line,column:o.column}};return n&&r&&"function"==typeof r.offset&&(u.start=r.offset(u.start),u.end=r.offset(u.end)),u}function wn(t){on<an||(on>an&&(an=on,fn=[]),fn.push(t))}function An(t,e,n){return new peg$SyntaxError(peg$SyntaxError.buildMessage(t,e),t,e,n)}function xn(){let e,r;return e=on,r=mn(),r===n&&(r=function(){let e,r,s,o,u,l,i,c,a,f,h,p,d,g;e=on,r=on,s=t.substr(on,6),s.toLowerCase()===L?on+=6:(s=n,0===hn&&wn(zt));s===n&&(s=t.substr(on,6),s.toLowerCase()===v?on+=6:(s=n,0===hn&&wn(Bt)));s!==n?(o=Xn(),o!==n?(un=r,r=new ql[s]):(on=r,r=n)):(on=r,r=n);if(r!==n)if(s=on,o=Hn(),o!==n&&(un=s,b=o,o=void(r._.entries=tr.entries(b))),s=o,s===n&&(s=null),o=on,u=on,l=t.substr(on,4),l.toLowerCase()===y?on+=4:(l=n,0===hn&&wn(qt)),l!==n?(i=Xn(),i!==n?(l=[l,i],u=l):(on=u,u=n)):(on=u,u=n),u!==n?(l=Rn(),l!==n?(un=o,o=function(t,e){t._.into=e}(r,l)):(on=o,o=n)):(on=o,o=n),o!==n){if(u=on,l=mn(),l!==n&&(un=u,l=function(t,e){t._.from=e}(r,l)),u=l,u===n){if(u=on,l=on,i=on,c=t.substr(on,7),c.toLowerCase()===_?on+=7:(c=n,0===hn&&wn(Mt)),c!==n?(a=Xn(),a!==n?(c=[c,a],i=c):(on=i,i=n)):(on=i,i=n),i===n&&(i=null),c=on,a=Hn(),a!==n&&(un=c,a=function(t,e){t._entries(e)}(r,a)),c=a,c!==n?(i=[i,c],l=i):(on=l,l=n),l===n&&(l=null),i=on,c=on,a=t.substr(on,7),a.toLowerCase()===S?on+=7:(a=n,0===hn&&wn(Zt)),a!==n?(f=Xn(),f!==n?(a=[a,f],c=a):(on=c,c=n)):(on=c,c=n),c===n&&(c=null),a=Hn(),a===n)if(a=on,f=kn(),f!==n){for(h=on,p=[],d=Tn();d!==n;)p.push(d),d=on,g=Vn(),g!==n?(g=Tn(),g===n?(on=d,d=n):d=g):d=g;p.length<1?(on=h,h=n):h=p,h!==n?(p=Gn(),p!==n?a=h:(on=a,a=n)):(on=a,a=n)}else on=a,a=n;a!==n?(un=i,i=function(t,e){t._.columns=e}(r,a)):(on=i,i=n),i===n&&(i=null),c=on,a=on,f=t.substr(on,4),f.toLowerCase()===O?on+=4:(f=n,0===hn&&wn(Ht)),f!==n?(h=Xn(),h!==n?(f=[f,h],a=f):(on=a,a=n)):(on=a,a=n),a===n&&(a=null),f=Hn(),f!==n?(un=c,c=function(t,e){t._.rows=e}(r,f)):(on=c,c=n),c===n&&(c=null),a=on,f=on,h=t.substr(on,6),h.toLowerCase()===T?on+=6:(h=n,0===hn&&wn(Wt)),h!==n?(p=Xn(),p!==n?(h=[h,p],f=h):(on=f,f=n)):(on=f,f=n),f!==n?(h=Nn(),h!==n?(un=a,a=function(t,e){t._.values=e.list}(r,h)):(on=a,a=n)):(on=a,a=n),a===n&&(a=null),l=[l,i,c,a],u=l}u!==n?e=r:(on=e,e=n)}else on=e,e=n;else on=e,e=n;var b;return e}(),r===n&&(r=function(){let e,r,s,o,u,l,i,c,a,h,p,d,g,b,C,w,A;e=on,r=on,s=t.substr(on,6),s.toLowerCase()===R?on+=6:(s=n,0===hn&&wn(Yt));s!==n?(o=Xn(),o!==n?(un=r,r=new ql.UPDATE):(on=r,r=n)):(on=r,r=n);if(r!==n)if(s=on,o=on,u=t.substr(on,6),u.toLowerCase()===P?on+=6:(u=n,0===hn&&wn(kt)),u!==n?(l=Xn(),l!==n?(u=[u,l],o=u):(on=o,o=n)):(on=o,o=n),o===n&&(o=null),u=Rn(),u!==n?(un=s,x=u,s=void(r._.entity=x)):(on=s,s=n),s!==n){if(o=on,u=t.substr(on,4),u.toLowerCase()===j?on+=4:(u=n,0===hn&&wn(Gt)),u===n&&(u=t.substr(on,3),u.toLowerCase()===F?on+=3:(u=n,0===hn&&wn(Qt))),u!==n)if(l=Xn(),l!==n){if(i=on,c=Hn(),c!==n&&(un=i,c=function(t,e){t._.with=e}(r,c)),i=c,i===n)if(i=on,un=on,c=function(t){t._.with={}}(r),c=c?n:void 0,c!==n){for(a=on,h=[],p=on,d=Tn(),d!==n?(g=Kn(),61===t.charCodeAt(on)?(b=I,on++):(b=n,0===hn&&wn(Vt)),b!==n?(C=Kn(),w=Pn(),w!==n?(un=p,p=nn(r,d,w)):(on=p,p=n)):(on=p,p=n)):(on=p,p=n);p!==n;)h.push(p),p=on,d=Vn(),d!==n?(d=on,g=Tn(),g!==n?(b=Kn(),61===t.charCodeAt(on)?(C=I,on++):(C=n,0===hn&&wn(Vt)),C!==n?(w=Kn(),A=Pn(),A!==n?(un=d,d=nn(r,g,A)):(on=d,d=n)):(on=d,d=n)):(on=d,d=n),d===n?(on=p,p=n):p=d):p=d;h.length<1?(on=a,a=n):a=h,a!==n?(h=Kn(),c=[c,a,h],i=c):(on=i,i=n)}else on=i,i=n;i!==n?(u=[u,l,i],o=u):(on=o,o=n)}else on=o,o=n;else on=o,o=n;o===n&&(o=null),u=on,l=on,i=t.substr(on,5),i.toLowerCase()===f?on+=5:(i=n,0===hn&&wn(St)),i!==n?(c=Xn(),c!==n?(i=[i,c],l=i):(on=l,l=n)):(on=l,l=n),l!==n?(i=_n(),i!==n?(c=Kn(),un=u,u=function(t,e){t._.where=e}(r,i)):(on=u,u=n)):(on=u,u=n),u===n&&(u=null),e=r}else on=e,e=n;else on=e,e=n;var x;return e}(),r===n&&(r=function(){let e,r,s,o,u,l,i;e=on,r=on,s=t.substr(on,6),s.toLowerCase()===D?on+=6:(s=n,0===hn&&wn(Jt));s!==n?(o=Xn(),o!==n?(un=r,r=new ql.DELETE):(on=r,r=n)):(on=r,r=n);r!==n?(s=on,o=on,u=t.substr(on,4),u.toLowerCase()===a?on+=4:(u=n,0===hn&&wn(yt)),u!==n?(l=Xn(),l!==n?(u=[u,l],o=u):(on=o,o=n)):(on=o,o=n),o===n&&(o=null),u=Rn(),u!==n?(l=Kn(),un=s,c=u,s=void(r._.from=c)):(on=s,s=n),s!==n?(o=on,u=on,l=t.substr(on,5),l.toLowerCase()===f?on+=5:(l=n,0===hn&&wn(St)),l!==n?(i=Xn(),i!==n?(l=[l,i],u=l):(on=u,u=n)):(on=u,u=n),u!==n?(l=_n(),l!==n?(i=Kn(),un=o,o=function(t,e){t._.where=e}(r,l)):(on=o,o=n)):(on=o,o=n),o===n&&(o=null),e=r):(on=e,e=n)):(on=e,e=n);var c;return e}()))),r!==n&&(un=e,r=Je(r)),e=r,e}function mn(){let e,r,s,o,f,h,p,d,g,b,C;return e=on,r=on,s=t.substr(on,6),s.toLowerCase()===u?on+=6:(s=n,0===hn&&wn(mt)),s!==n?(o=Xn(),o!==n?(un=r,r=new ql.SELECT):(on=r,r=n)):(on=r,r=n),r!==n?(s=on,o=t.substr(on,9),o.toLowerCase()===l?on+=9:(o=n,0===hn&&wn(Et)),o!==n?(f=Xn(),f!==n?(h=Kn(),un=s,s=void(r._.localized=!0)):(on=s,s=n)):(on=s,s=n),s===n&&(s=null),o=on,f=t.substr(on,8),f.toLowerCase()===i?on+=8:(f=n,0===hn&&wn(Lt)),f!==n?(h=Xn(),h!==n?(p=Kn(),un=o,o=function(t){t._.distinct=!0}(r)):(on=o,o=n)):(on=o,o=n),o===n&&(o=null),f=on,h=t.substr(on,3),h.toLowerCase()===c?on+=3:(h=n,0===hn&&wn(vt)),h!==n?(p=Xn(),p!==n?(d=Kn(),un=f,f=function(t){t._.one=!0}(r)):(on=f,f=n)):(on=f,f=n),f===n&&(f=null),h=on,p=vn(),p!==n?(d=Kn(),un=h,h=function(t,e){t._.columns=e}(r,p)):(on=h,h=n),h===n&&(h=null),p=on,d=on,g=t.substr(on,4),g.toLowerCase()===a?on+=4:(g=n,0===hn&&wn(yt)),g!==n?(b=Xn(),b!==n?(g=[g,b],d=g):(on=d,d=n)):(on=d,d=n),d!==n?(g=Rn(),g===n&&(g=Zn()),g!==n?(un=p,p=function(t,e){t._.from=e}(r,g)):(on=p,p=n)):(on=p,p=n),p===n&&(p=null),d=on,g=Wn(),g!==n?(b=vn(),b!==n?(C=Yn(),C!==n?(un=d,d=function(t,e){t._.columns=e}(r,b)):(on=d,d=n)):(on=d,d=n)):(on=d,d=n),d===n&&(d=null),g=on,b=En(),b!==n&&(un=g,b=function(t,e){Object.assign(t._,e)}(r,b)),g=b,g===n&&(g=null),e=r):(on=e,e=n),e}function En(){let e,r,s,o,u,l,i,c,a,C,w,A;var x;return e=on,r=on,s=on,hn++,t.length>on?(o=t.charAt(on),on++):(o=n,0===hn&&wn(_t)),hn--,o!==n?(on=s,s=void 0):s=n,s!==n&&(un=r,s={}),r=s,r!==n?(s=on,o=on,u=t.substr(on,5),u.toLowerCase()===f?on+=5:(u=n,0===hn&&wn(St)),u!==n?(l=Xn(),l!==n?(u=[u,l],o=u):(on=o,o=n)):(on=o,o=n),o!==n?(u=_n(),u!==n?(l=Kn(),un=s,x=u,s=void(r.where=x)):(on=s,s=n)):(on=s,s=n),s===n&&(s=null),o=on,u=on,l=t.substr(on,8),l.toLowerCase()===h?on+=8:(l=n,0===hn&&wn($t)),l!==n?(i=Xn(),i!==n?(c=Sn(),c!==n?(a=Kn(),un=u,u=function(t,e){t.groupBy=e}(r,c)):(on=u,u=n)):(on=u,u=n)):(on=u,u=n),u!==n?(l=on,i=t.substr(on,6),i.toLowerCase()===p?on+=6:(i=n,0===hn&&wn(Ot)),i!==n?(c=Xn(),c!==n?(a=_n(),a!==n?(C=Kn(),un=l,l=function(t,e){t.having=e}(r,a)):(on=l,l=n)):(on=l,l=n)):(on=l,l=n),l===n&&(l=null),u=[u,l],o=u):(on=o,o=n),o===n&&(o=null),u=on,l=on,i=t.substr(on,8),i.toLowerCase()===d?on+=8:(i=n,0===hn&&wn(Tt)),i!==n?(c=Xn(),c!==n?(i=[i,c],l=i):(on=l,l=n)):(on=l,l=n),l!==n?(i=$n(),i!==n?(c=Kn(),un=u,u=function(t,e){t.orderBy=e}(r,i)):(on=u,u=n)):(on=u,u=n),u===n&&(u=null),l=on,i=on,c=t.substr(on,5),c.toLowerCase()===g?on+=5:(c=n,0===hn&&wn(Rt)),c!==n?(a=Xn(),a!==n?(C=Fn(),C===n&&(C=In()),C!==n?(w=Kn(),un=i,i=function(t,e){t.limit={rows:e}}(r,C)):(on=i,i=n)):(on=i,i=n)):(on=i,i=n),i!==n?(c=on,a=t.substr(on,6),a.toLowerCase()===b?on+=6:(a=n,0===hn&&wn(Pt)),a!==n?(C=Xn(),C!==n?(w=Fn(),w===n&&(w=In()),w!==n?(A=Kn(),un=c,c=function(t,e){t.limit.offset=e}(r,w)):(on=c,c=n)):(on=c,c=n)):(on=c,c=n),c===n&&(c=null),i=[i,c],l=i):(on=l,l=n),l===n&&(l=null),e=r):(on=e,e=n),e}function Ln(){let e,r,s,o,u;return e=on,r=on,s=Kn(),r=t.substring(r,on),s=t.substr(on,2),s.toLowerCase()===C?on+=2:(s=n,0===hn&&wn(jt)),s!==n?(o=Xn(),o!==n?(u=On(),u!==n?e=u:(on=e,e=n)):(on=e,e=n)):(on=e,e=n),e}function vn(){let e,r,s,o,u,l,i,c,a,f,h;for(e=on,r=[],42===t.charCodeAt(on)?(s=w,on++):(s=n,0===hn&&wn(Ft)),s===n&&(s=on,o=Fn(),o!==n?(u=on,l=Ln(),l!==n&&(un=u,l=Ke(o,l)),u=l,u===n&&(u=null),l=Jn(),l===n&&(l=null),i=on,c=Wn(),c!==n?(a=vn(),a!==n?(f=Yn(),f!==n?(un=i,i=Xe(o,l,a)):(on=i,i=n)):(on=i,i=n)):(on=i,i=n),i!==n?s=o:(on=s,s=n)):(on=s,s=n),s===n&&(s=on,o=Pn(),o!==n?(u=on,l=Ln(),l!==n&&(un=u,l=tn(o,l)),u=l,u===n&&(u=null),s=o):(on=s,s=n)));s!==n;)r.push(s),s=on,o=Vn(),o!==n?(42===t.charCodeAt(on)?(o=w,on++):(o=n,0===hn&&wn(Ft)),o===n&&(o=on,u=Fn(),u!==n?(l=on,i=Ln(),i!==n&&(un=l,i=Ke(u,i)),l=i,l===n&&(l=null),i=Jn(),i===n&&(i=null),c=on,a=Wn(),a!==n?(f=vn(),f!==n?(h=Yn(),h!==n?(un=c,c=Xe(u,i,f)):(on=c,c=n)):(on=c,c=n)):(on=c,c=n),c!==n?o=u:(on=o,o=n)):(on=o,o=n),o===n&&(o=on,u=Pn(),u!==n?(l=on,i=Ln(),i!==n&&(un=l,i=tn(u,i)),l=i,l===n&&(l=null),o=u):(on=o,o=n))),o===n?(on=s,s=n):s=o):s=o;return r.length<1?(on=e,e=n):e=r,e}function yn(){let e,r,s,o,u,l,i,c;return e=on,r=Kn(),91===t.charCodeAt(on)?(s=A,on++):(s=n,0===hn&&wn(It)),s!==n?(o=Kn(),u=function(){let e,r,s,o,u;e=on,r=Hn(),r!==n&&(un=e,l=r,r={where:tr.where(l)});var l;if(e=r,e===n){for(e=on,r=on,s=[],o=In();o!==n;)s.push(o),o=on,u=Vn(),u!==n?(u=In(),u===n?(on=o,o=n):o=u):o=u;s.length<1?(on=r,r=n):r=s,r!==n&&(un=e,r={where:r}),e=r,e===n&&(e=on,r=on,hn++,s=on,o=t.substr(on,5),o.toLowerCase()===f?on+=5:(o=n,0===hn&&wn(St)),o!==n?(u=Xn(),u!==n?(o=[o,u],s=o):(on=s,s=n)):(on=s,s=n),hn--,s===n?r=void 0:(on=r,r=n),r!==n?(s=jn(),s!==n?(un=e,e={where:s.xpr}):(on=e,e=n)):(on=e,e=n),e===n&&(e=En()))}return e}(),u!==n?(l=Kn(),93===t.charCodeAt(on)?(i=x,on++):(i=n,0===hn&&wn(Dt)),i!==n?(c=Kn(),e=u):(on=e,e=n)):(on=e,e=n)):(on=e,e=n),e}function _n(){let t,e;var r;return t=on,e=Hn(),e!==n&&(un=t,r=e,e=tr.where(r)),t=e,t===n&&(t=on,e=jn(),e!==n&&(un=t,e=e.xpr),t=e),t}function Sn(){let t,e,r,s,o;for(t=on,e=on,r=[],s=Fn();s!==n;)r.push(s),s=on,o=Vn(),o!==n?(o=Fn(),o===n?(on=s,s=n):s=o):s=o;return r.length<1?(on=e,e=n):e=r,e!==n?t=e:(on=t,t=n),t}function $n(){let e,r,s,o,u,l,i,c,a;for(e=on,r=on,s=[],o=on,u=Fn(),u!==n?(l=on,i=Xn(),i!==n?(c=t.substr(on,3),c.toLowerCase()===m?on+=3:(c=n,0===hn&&wn(Nt)),c===n&&(c=t.substr(on,4),c.toLowerCase()===E?on+=4:(c=n,0===hn&&wn(Ut))),c!==n?(un=l,l=en(u,c)):(on=l,l=n)):(on=l,l=n),l===n&&(l=null),o=u):(on=o,o=n);o!==n;)s.push(o),o=on,u=Vn(),u!==n?(u=on,l=Fn(),l!==n?(i=on,c=Xn(),c!==n?(a=t.substr(on,3),a.toLowerCase()===m?on+=3:(a=n,0===hn&&wn(Nt)),a===n&&(a=t.substr(on,4),a.toLowerCase()===E?on+=4:(a=n,0===hn&&wn(Ut))),a!==n?(un=i,i=en(l,a)):(on=i,i=n)):(on=i,i=n),i===n&&(i=null),u=l):(on=u,u=n),u===n?(on=o,o=n):o=u):o=u;return s.length<1?(on=r,r=n):r=s,r!==n?e=r:(on=e,e=n),e}function On(){let e,r,s,o,u,l,i,c,f;if(hn++,e=on,r=on,hn++,s=t.substr(on,2),s.toLowerCase()===C?on+=2:(s=n,0===hn&&wn(Xt)),hn--,s===n?r=void 0:(on=r,r=n),r!==n)if(s=on,hn++,o=t.substr(on,4),o.toLowerCase()===a?on+=4:(o=n,0===hn&&wn(te)),hn--,o===n?s=void 0:(on=s,s=n),s!==n)if(o=on,hn++,u=Mn(),hn--,u===n?o=void 0:(on=o,o=n),o!==n){if(u=on,l=on,i=t.charAt(on),dt.test(i)?on++:(i=n,0===hn&&wn(ee)),i!==n){for(c=[],f=t.charAt(on),gt.test(f)?on++:(f=n,0===hn&&wn(ne));f!==n;)c.push(f),f=t.charAt(on),gt.test(f)?on++:(f=n,0===hn&&wn(ne));i=[i,c],l=i}else on=l,l=n;u=l!==n?t.substring(u,on):l,u!==n?e=u:(on=e,e=n)}else on=e,e=n;else on=e,e=n;else on=e,e=n;return hn--,e===n&&(r=n,0===hn&&wn(Kt)),e}function Tn(){let e,r,s,o,u,l;for(hn++,e=on,r=on,s=on,o=[],u=On();u!==n;)o.push(u),u=on,l=Jn(),l!==n?(l=On(),l===n?(on=u,u=n):u=l):u=l;return o.length<1?(on=s,s=n):s=o,r=s!==n?t.substring(r,on):s,r!==n?e=r:(on=e,e=n),hn--,e===n&&(r=n,0===hn&&wn(re)),e}function Rn(){let e,r,s,o,u,l,i;var c;if(hn++,e=on,r=Hn(),r!==n&&(un=e,c=r,r=tr.subject(c)),e=r,e===n){for(e=on,r=on,s=[],o=on,u=On(),u!==n?(l=Jn(),l!==n?(u=[u,l],o=u):(on=o,o=n)):(on=o,o=n);o!==n;)s.push(o),o=on,u=On(),u!==n?(l=Jn(),l!==n?(u=[u,l],o=u):(on=o,o=n)):(on=o,o=n);r=t.substring(r,on),s=on,o=On(),o!==n?(u=Kn(),58===t.charCodeAt(on)?(l=N,on++):(l=n,0===hn&&wn(oe)),l!==n?(i=Kn(),s=o):(on=s,s=n)):(on=s,s=n),s===n&&(s=null),o=Fn(),o!==n?(u=Kn(),un=e,e=function(t,e,n){if(e)return{ref:[t+e,...n.ref]};if(t){let[e]=n.ref;e.id?e.id=t+e.id:n.ref[0]=t+e}return n}(r,s,o)):(on=e,e=n)}return hn--,e===n&&(r=n,0===hn&&wn(se)),e}function Pn(){let t,e;var r;return t=on,e=jn(),e!==n&&(un=t,e=(r=e).xpr.length>1?r:r.xpr[0]),t=e,t}function jn(){let t,e,r,s,o,u;if(t=on,e=[],r=Zn(),r===n&&(r=Nn(),r===n&&(r=zn(),r===n&&(r=In(),r===n&&(r=qn(),r===n&&(r=Un(),r===n&&(r=Fn(),r===n&&(r=on,s=kn(),s!==n?(o=Pn(),o!==n?(u=Gn(),u!==n?r=o:(on=r,r=n)):(on=r,r=n)):(on=r,r=n)))))))),r!==n)for(;r!==n;)e.push(r),r=Zn(),r===n&&(r=Nn(),r===n&&(r=zn(),r===n&&(r=In(),r===n&&(r=qn(),r===n&&(r=Un(),r===n&&(r=Fn(),r===n&&(r=on,s=kn(),s!==n?(o=Pn(),o!==n?(u=Gn(),u!==n?r=o:(on=r,r=n)):(on=r,r=n)):(on=r,r=n))))))));else e=n;return e!==n&&(un=t,e={xpr:e}),t=e,t}function Fn(){let t,e,r,s,o,u,l;for(hn++,t=on,e=on,r=[],s=on,o=On(),o!==n?(u=yn(),u===n&&(u=null),un=s,s=rn(o,u)):(on=s,s=n);s!==n;)r.push(s),s=on,o=Jn(),o!==n?(o=on,u=On(),u!==n?(l=yn(),l===n&&(l=null),un=o,o=rn(u,l)):(on=o,o=n),o===n?(on=s,s=n):s=o):s=o;return r.length<1?(on=e,e=n):e=r,e!==n&&(un=t,e={ref:e}),t=e,hn--,t===n&&(e=n,0===hn&&wn(ue)),t}function In(){let e,r;return hn++,e=Bn(),e===n&&(e=on,r=function(){let e,r;hn++,e=function(){let e,r,s,o,u,l;e=on,39===t.charCodeAt(on)?(r=ot,on++):(r=n,0===hn&&wn(Ne));if(r!==n){for(s=on,o=[],u=t.charAt(on),wt.test(u)?on++:(u=n,0===hn&&wn(Ue)),u===n&&(u=on,t.substr(on,2)===ut?(l=ut,on+=2):(l=n,0===hn&&wn(ze)),l!==n&&(un=u,l="'"),u=l);u!==n;)o.push(u),u=t.charAt(on),wt.test(u)?on++:(u=n,0===hn&&wn(Ue)),u===n&&(u=on,t.substr(on,2)===ut?(l=ut,on+=2):(l=n,0===hn&&wn(ze)),l!==n&&(un=u,l=sn()),u=l);s=t.substring(s,on),39===t.charCodeAt(on)?(o=ot,on++):(o=n,0===hn&&wn(Ne)),o!==n?e=s:(on=e,e=n)}else on=e,e=n;return e}(),e===n&&(e=function(){let e,r,s,o,u,l,i,c,a,f;e=on,r=on,s=on,45===t.charCodeAt(on)?(o=nt,on++):(o=n,0===hn&&wn(je));o===n&&(o=null);u=[],l=t.charAt(on),Ct.test(l)?on++:(l=n,0===hn&&wn(Fe));if(l!==n)for(;l!==n;)u.push(l),l=t.charAt(on),Ct.test(l)?on++:(l=n,0===hn&&wn(Fe));else u=n;if(u!==n){if(l=on,46===t.charCodeAt(on)?(i=rt,on++):(i=n,0===hn&&wn(Ie)),i!==n){if(c=[],a=t.charAt(on),Ct.test(a)?on++:(a=n,0===hn&&wn(Fe)),a!==n)for(;a!==n;)c.push(a),a=t.charAt(on),Ct.test(a)?on++:(a=n,0===hn&&wn(Fe));else c=n;c!==n?(i=[i,c],l=i):(on=l,l=n)}else on=l,l=n;if(l===n&&(l=null),i=on,101===t.charCodeAt(on)?(c=st,on++):(c=n,0===hn&&wn(De)),c!==n){if(a=[],f=t.charAt(on),Ct.test(f)?on++:(f=n,0===hn&&wn(Fe)),f!==n)for(;f!==n;)a.push(f),f=t.charAt(on),Ct.test(f)?on++:(f=n,0===hn&&wn(Fe));else a=n;a!==n?(c=[c,a],i=c):(on=i,i=n)}else on=i,i=n;i===n&&(i=null),o=[o,u,l,i],s=o}else on=s,s=n;r=s!==n?t.substring(r,on):s;r!==n&&(un=e,r=Number(r));return e=r,e}(),e===n&&(e=function(){let e,r,s,o;e=on,t.substr(on,4)===lt?(r=lt,on+=4):(r=n,0===hn&&wn(Be));r!==n?(s=on,hn++,o=Qn(),hn--,o===n?s=void 0:(on=s,s=n),s!==n?(un=e,e=!0):(on=e,e=n)):(on=e,e=n);return e}(),e===n&&(e=function(){let e,r,s,o;e=on,t.substr(on,5)===it?(r=it,on+=5):(r=n,0===hn&&wn(qe));r!==n?(s=on,hn++,o=Qn(),hn--,o===n?s=void 0:(on=s,s=n),s!==n?(un=e,e=!1):(on=e,e=n)):(on=e,e=n);return e}(),e===n&&(e=function(){let e,r,s,o;e=on,t.substr(on,4)===tt?(r=tt,on+=4):(r=n,0===hn&&wn(Te));r!==n?(s=on,hn++,o=Qn(),hn--,o===n?s=void 0:(on=s,s=n),s!==n?(un=e,e=null):(on=e,e=n)):(on=e,e=n);return e}()))));hn--,e===n&&(r=n,0===hn&&wn(Pe));return e}(),r!==n&&(un=e,r={val:r}),e=r),hn--,e===n&&(r=n,0===hn&&wn(le)),e}function Dn(){let t,e,r,s;for(hn++,t=on,e=[],r=zn(),r===n&&(r=In(),r===n&&(r=Fn(),r===n&&(r=Un())));r!==n;)e.push(r),r=on,s=Vn(),s!==n?(s=zn(),s===n&&(s=In(),s===n&&(s=Fn(),s===n&&(s=Un()))),s===n?(on=r,r=n):r=s):r=s;return e.length<2?(on=t,t=n):t=e,hn--,t===n&&(e=n,0===hn&&wn(le)),t}function Nn(){let t,e,r,s;return hn++,t=Bn(),t===n&&(t=on,e=kn(),e!==n?(r=on,s=Dn(),s!==n&&(un=r,s={list:s}),r=s,r!==n?(s=Gn(),s!==n?t=r:(on=t,t=n)):(on=t,t=n)):(on=t,t=n)),hn--,t===n&&(e=n,0===hn&&wn(ie)),t}function Un(){let e,r,s,o,u,l,i;if(hn++,e=on,r=On(),r!==n)if(s=kn(),s!==n){for(o=on,u=[],42===t.charCodeAt(on)?(l=w,on++):(l=n,0===hn&&wn(Ft)),l===n&&(l=Pn());l!==n;)u.push(l),l=on,i=Vn(),i!==n?(42===t.charCodeAt(on)?(i=w,on++):(i=n,0===hn&&wn(Ft)),i===n&&(i=Pn()),i===n?(on=l,l=n):l=i):l=i;u.length<1?(on=o,o=n):o=u,o!==n?(u=Gn(),u!==n?(un=e,e={func:r,args:o}):(on=e,e=n)):(on=e,e=n)}else on=e,e=n;else on=e,e=n;return hn--,e===n&&(r=n,0===hn&&wn(ce)),e}function zn(){let e,r,s;return hn++,e=on,35===t.charCodeAt(on)?(r=U,on++):(r=n,0===hn&&wn(fe)),r!==n?(s=On(),s!==n?(un=e,e={"#":s}):(on=e,e=n)):(on=e,e=n),hn--,e===n&&(r=n,0===hn&&wn(ae)),e}function Bn(){let e,r,s,o;return hn++,e=on,r=Kn(),63===t.charCodeAt(on)?(s=z,on++):(s=n,0===hn&&wn(pe)),s!==n?(o=Kn(),un=e,e=sr()):(on=e,e=n),hn--,e===n&&(r=n,0===hn&&wn(he)),e}function qn(){let e,r,s,o,u;if(hn++,e=on,r=Kn(),s=Mn(),s===n){if(s=on,o=[],u=t.charAt(on),bt.test(u)?on++:(u=n,0===hn&&wn(ge)),u!==n)for(;u!==n;)o.push(u),u=t.charAt(on),bt.test(u)?on++:(u=n,0===hn&&wn(ge));else o=n;s=o!==n?t.substring(s,on):o}return s!==n?(o=Kn(),e=s):(on=e,e=n),hn--,e===n&&(r=n,0===hn&&wn(de)),e}function Mn(){let e,r,s,o,u,l,i,c;if(e=on,t.substr(on,3)===B?(r=B,on+=3):(r=n,0===hn&&wn(be)),r===n&&(t.substr(on,2)===q?(r=q,on+=2):(r=n,0===hn&&wn(Ce)),r===n&&(t.substr(on,2)===M?(r=M,on+=2):(r=n,0===hn&&wn(we)),r===n&&(t.substr(on,7)===Z?(r=Z,on+=7):(r=n,0===hn&&wn(Ae)),r===n&&(t.substr(on,4)===H?(r=H,on+=4):(r=n,0===hn&&wn(xe)),r===n&&(t.substr(on,6)===W?(r=W,on+=6):(r=n,0===hn&&wn(me)),r===n&&(t.substr(on,8)===Y?(r=Y,on+=8):(r=n,0===hn&&wn(Ee)))))))),r!==n?(s=on,hn++,o=Qn(),hn--,o===n?s=void 0:(on=s,s=n),s!==n?e=r:(on=e,e=n)):(on=e,e=n),e===n&&(e=on,t.substr(on,4)===k?(r=k,on+=4):(r=n,0===hn&&wn(Le)),r===n&&(t.substr(on,4)===G?(r=G,on+=4):(r=n,0===hn&&wn(ve)),r===n&&(t.substr(on,4)===Q?(r=Q,on+=4):(r=n,0===hn&&wn(ye)),r===n&&(t.substr(on,4)===V?(r=V,on+=4):(r=n,0===hn&&wn(_e)),r===n&&(t.substr(on,3)===J?(r=J,on+=3):(r=n,0===hn&&wn(Se)))))),r!==n?(s=on,hn++,o=Qn(),hn--,o===n?s=void 0:(on=s,s=n),s!==n?e=r:(on=e,e=n)):(on=e,e=n),e===n)){for(e=on,r=on,s=[],o=on,t.substr(on,2)===K?(u=K,on+=2):(u=n,0===hn&&wn($e)),u===n&&(t.substr(on,3)===X?(u=X,on+=3):(u=n,0===hn&&wn(Oe)),u===n&&(t.substr(on,4)===tt?(u=tt,on+=4):(u=n,0===hn&&wn(Te)),u===n&&(t.substr(on,5)===et?(u=et,on+=5):(u=n,0===hn&&wn(Re))))),u!==n?(l=on,hn++,i=Qn(),hn--,i===n?l=void 0:(on=l,l=n),l!==n?(u=[u,l],o=u):(on=o,o=n)):(on=o,o=n);o!==n;)s.push(o),o=on,u=Kn(),u=on,t.substr(on,2)===K?(l=K,on+=2):(l=n,0===hn&&wn($e)),l===n&&(t.substr(on,3)===X?(l=X,on+=3):(l=n,0===hn&&wn(Oe)),l===n&&(t.substr(on,4)===tt?(l=tt,on+=4):(l=n,0===hn&&wn(Te)),l===n&&(t.substr(on,5)===et?(l=et,on+=5):(l=n,0===hn&&wn(Re))))),l!==n?(i=on,hn++,c=Qn(),hn--,c===n?i=void 0:(on=i,i=n),i!==n?(l=[l,i],u=l):(on=u,u=n)):(on=u,u=n),u===n?(on=o,o=n):o=u;s.length<1?(on=r,r=n):r=s,e=r!==n?t.substring(e,on):r}return e}function Zn(){let t,e,r,s;return t=on,e=kn(),e!==n?(r=mn(),r!==n?(s=Gn(),s!==n?t=r:(on=t,t=n)):(on=t,t=n)):(on=t,t=n),t}function Hn(){let e,r,s,o;return e=on,r=Kn(),63===t.charCodeAt(on)?(s=z,on++):(s=n,0===hn&&wn(pe)),s!==n?(o=Kn(),un=e,e=nr.shift()):(on=e,e=n),e}function Wn(){let e,r,s,o;return e=on,r=Kn(),123===t.charCodeAt(on)?(s=ct,on++):(s=n,0===hn&&wn(Me)),s!==n?(o=Kn(),r=[r,s,o],e=r):(on=e,e=n),e}function Yn(){let e,r,s,o;return e=on,r=Kn(),125===t.charCodeAt(on)?(s=at,on++):(s=n,0===hn&&wn(Ze)),s!==n?(o=Kn(),r=[r,s,o],e=r):(on=e,e=n),e}function kn(){let e,r,s,o;return e=on,r=Kn(),40===t.charCodeAt(on)?(s=ft,on++):(s=n,0===hn&&wn(He)),s!==n?(o=Kn(),r=[r,s,o],e=r):(on=e,e=n),e}function Gn(){let e,r,s,o;return e=on,r=Kn(),41===t.charCodeAt(on)?(s=ht,on++):(s=n,0===hn&&wn(We)),s!==n?(o=Kn(),r=[r,s,o],e=r):(on=e,e=n),e}function Qn(){let e;return e=t.charAt(on),At.test(e)?on++:(e=n,0===hn&&wn(Ye)),e}function Vn(){let e,r,s,o;return hn++,e=on,r=Kn(),44===t.charCodeAt(on)?(s=pt,on++):(s=n,0===hn&&wn(Ge)),s!==n?(o=Kn(),e=s):(on=e,e=n),hn--,e===n&&(r=n,0===hn&&wn(ke)),e}function Jn(){let e,r,s,o;return hn++,e=on,r=Kn(),46===t.charCodeAt(on)?(s=rt,on++):(s=n,0===hn&&wn(Ie)),s!==n?(o=Kn(),un=e,e="."):(on=e,e=n),hn--,e===n&&(r=n,0===hn&&wn(Qe)),e}function Kn(){let e,r,s;for(hn++,e=on,r=[],s=t.charAt(on),xt.test(s)?on++:(s=n,0===hn&&wn(Ve));s!==n;)r.push(s),s=t.charAt(on),xt.test(s)?on++:(s=n,0===hn&&wn(Ve));return e=t.substring(e,on),hn--,e}function Xn(){let e,r,s;if(hn++,e=on,r=[],s=t.charAt(on),xt.test(s)?on++:(s=n,0===hn&&wn(Ve)),s!==n)for(;s!==n;)r.push(s),s=t.charAt(on),xt.test(s)?on++:(s=n,0===hn&&wn(Ve));else r=n;return e=r!==n?t.substring(e,on):r,hn--,e===n&&(r=n,0===hn&&wn(Qe)),e}const{fluent:tr=ql.fluent,late_binding:er}=peg$parse,{args:nr=[],startRule:rr}=e,sr=!rr&&er?()=>or[ur++]={ref:["?"],param:!0}:()=>or[ur]=tr.expr(nr[ur++]),or=[];let ur=0;cn=o();const lr=cn!==n&&on===t.length;function ir(){throw cn!==n&&on<t.length&&wn({type:"end"}),An(fn,an<t.length?function(e=on){const n=t.codePointAt(e);return void 0===n?"":String.fromCodePoint(n)}(an):null,an<t.length?Cn(an,an+1):Cn(an,an))}return e.peg$library?{peg$result:cn,peg$currPos:on,peg$FAILED:n,peg$maxFailExpected:fn,peg$maxFailPos:an,peg$success:lr,peg$throw:lr?void 0:ir}:lr?cn:void ir()}const peg$allowedStartRules=["CQL","entity","columns","ref","val","vals","expr","where","groupBy","orderBy"];export{peg$allowedStartRules as StartRules,peg$SyntaxError as SyntaxError,peg$parse as parse};
2
- //# sourceMappingURL=parser.min.js.map
1
+ import*as fluent from"../lib/xl/fluent.js";import{SELECT}from"../lib/ql/select.js";import{INSERT}from"../lib/ql/insert.js";import{UPSERT}from"../lib/ql/insert.js";import{UPDATE}from"../lib/ql/update.js";import{DELETE}from"../lib/ql/delete.js";class peg$SyntaxError extends SyntaxError{constructor(t,e,r,n){super(t),this.expected=e,this.found=r,this.location=n,this.name="SyntaxError"}format(t){let e="Error: "+this.message;if(this.location){let r=null;const n=t.find(t=>t.source===this.location.source);n&&(r=n.text.split(/\r\n|\n|\r/g));const o=this.location.start,s=this.location.source&&"function"==typeof this.location.source.offset?this.location.source.offset(o):o,u=this.location.source+":"+s.line+":"+s.column;if(r){const t=this.location.end,n="".padEnd(s.line.toString().length," "),l=r[o.line-1],i=(o.line===t.line?t.column:l.length+1)-o.column||1;e+="\n --\x3e "+u+"\n"+n+" |\n"+s.line+" | "+l+"\n"+n+" | "+"".padEnd(o.column-1," ")+"".padEnd(i,"^")}else e+="\n at "+u}return e}static buildMessage(t,e){function r(t){return t.codePointAt(0).toString(16).toUpperCase()}const n=Object.prototype.hasOwnProperty.call(RegExp.prototype,"unicode")?new RegExp("[\\p{C}\\p{Mn}\\p{Mc}]","gu"):null;function o(t){return n?t.replace(n,t=>"\\u{"+r(t)+"}"):t}function s(t){return o(t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,t=>"\\x0"+r(t)).replace(/[\x10-\x1F\x7F-\x9F]/g,t=>"\\x"+r(t)))}function u(t){return o(t.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,t=>"\\x0"+r(t)).replace(/[\x10-\x1F\x7F-\x9F]/g,t=>"\\x"+r(t)))}const l={literal:t=>'"'+s(t.text)+'"',class(t){const e=t.parts.map(t=>Array.isArray(t)?u(t[0])+"-"+u(t[1]):u(t));return"["+(t.inverted?"^":"")+e.join("")+"]"+(t.unicode?"u":"")},any:()=>"any character",end:()=>"end of input",other:t=>t.description};function i(t){return l[t.type](t)}return"Expected "+function(t){const e=t.map(i);if(e.sort(),e.length>0){let t=1;for(let r=1;r<e.length;r++)e[r-1]!==e[r]&&(e[t]=e[r],t++);e.length=t}switch(e.length){case 1:return e[0];case 2:return e[0]+" or "+e[1];default:return e.slice(0,-1).join(", ")+", or "+e[e.length-1]}}(t)+" but "+function(t){return t?'"'+s(t)+'"':"end of input"}(e)+" found."}}function peg$parse(t,e){const r={},n=(e=void 0!==e?e:{}).grammarSource,o={CQL:mr,subject:Pr,columns:vr,values:qr,ref:Dr,val:Ur,expr:Or,with:Rr,set:Fr,where:Sr,groupBy:_r,orderBy:$r};let s=mr;const u="select",l="localized",i="distinct",c="one",a="from",f="where",h="group by",p="having",d="order by",g="limit",b="offset",C="as",w="*",A="[",m="]",E="asc",x="desc",L="insert",v="upsert",y="into",S="entries",_="columns",$="rows",T="values",R="{",F=":",j="}",I="update",P="entity",O="with",N="set",D="=",U="delete",z="#",B="?",M="and",Z="or",q="in",H="between",W="like",Y="exists",k="contains",G="case",Q="when",V="then",J="else",K="end",X="is",tt="not",et="null",rt="empty",nt="-",ot=".",st="e",ut="'",lt="''",it="true",ct="false",at="(",ft=")",ht=",",pt=/^[A-Za-z_$]/,dt=/^[A-Za-z0-9_$]/,gt=/^[!=><+\-*\/%&|\^~]/,bt=/^[0-9]/,Ct=/^[^']/,wt=/^[A-Za-z_$0-9]/,At=/^[ \t\n\r]/,mt=pr("SELECT",!0),Et=pr("LOCALIZED",!0),xt=pr("DISTINCT",!0),Lt=pr("ONE",!0),vt=pr("FROM",!0),yt={type:"any"},St=pr("WHERE",!0),_t=pr("GROUP BY",!0),$t=pr("HAVING",!0),Tt=pr("ORDER BY",!0),Rt=pr("LIMIT",!0),Ft=pr("OFFSET",!0),jt=pr("as",!0),It=pr("*",!1),Pt=pr("[",!1),Ot=pr("]",!1),Nt=pr("asc",!0),Dt=pr("desc",!0),Ut=pr("INSERT",!0),zt=pr("UPSERT",!0),Bt=pr("INTO",!0),Mt=pr("ENTRIES",!0),Zt=pr("COLUMNS",!0),qt=pr("ROWS",!0),Ht=pr("VALUES",!0),Wt=pr("{",!1),Yt=pr(":",!1),kt=pr("}",!1),Gt=pr("UPDATE",!0),Qt=pr("ENTITY",!0),Vt=pr("WITH",!0),Jt=pr("SET",!0),Kt=pr("=",!1),Xt=pr("DELETE",!0),te=gr("a name"),ee=pr("AS",!0),re=pr("from",!0),ne=dr([["A","Z"],["a","z"],"_","$"],!1,!1,!1),oe=dr([["A","Z"],["a","z"],["0","9"],"_","$"],!1,!1,!1),se=gr("an element ref"),ue=gr("an entity ref"),le=gr("a reference"),ie=gr("a value"),ce=gr("a list"),ae=gr("a function"),fe=gr("a symbol"),he=pr("#",!1),pe=gr("a parameter"),de=pr("?",!1),ge=gr("an operator"),be=dr(["!","=",">","<","+","-","*","/","%","&","|","^","~"],!1,!1,!1),Ce=pr("and",!1),we=pr("or",!1),Ae=pr("in",!1),me=pr("between",!1),Ee=pr("like",!1),xe=pr("exists",!1),Le=pr("contains",!1),ve=pr("case",!1),ye=pr("when",!1),Se=pr("then",!1),_e=pr("else",!1),$e=pr("end",!1),Te=pr("is",!1),Re=pr("not",!1),Fe=pr("null",!1),je=pr("empty",!1),Ie=gr("a literal"),Pe=pr("-",!1),Oe=dr([["0","9"]],!1,!1,!1),Ne=pr(".",!1),De=pr("e",!1),Ue=pr("'",!1),ze=dr(["'"],!0,!1,!1),Be=pr("''",!1),Me=pr("true",!1),Ze=pr("false",!1),qe=pr("(",!1),He=pr(")",!1),We=dr([["A","Z"],["a","z"],"_","$",["0","9"]],!1,!1,!1),Ye=gr("a comma"),ke=pr(",",!1),Ge=gr(""),Qe=dr([" ","\t","\n","\r"],!1,!1,!1);function Ve(e){return nn?.length&&(e.params=nn),on?.length&&(e.args=on),e.source=t.substring(lr,ur),e}function Je(t,e){t.as=e}function Ke(t,e,r){e?t.inline=r:t.expand=r}function Xe(t,e){t.as=e}function tr(t,e){t.sort=e.toLowerCase()}function er(t){for(let e in t)"val"in t[e]&&(t[e]=t[e].val);return t}function rr(t,e,r){t[e]=r}function nr(t,e,r){t[e]=r}function or(t,e){return e?{id:t,...e}:t}function sr(){return"'"}let ur=0|e.peg$currPos,lr=ur;const ir=[{line:1,column:1}];let cr,ar=ur,fr=e.peg$maxFailExpected||[],hr=0|e.peg$silentFails;if(e.startRule){if(!(e.startRule in o))throw new Error("Can't start parsing from rule \""+e.startRule+'".');s=o[e.startRule]}function pr(t,e){return{type:"literal",text:t,ignoreCase:e}}function dr(t,e,r,n){return{type:"class",parts:t,inverted:e,ignoreCase:r,unicode:n}}function gr(t){return{type:"other",description:t}}function br(e){let r,n=ir[e];if(n)return n;if(e>=ir.length)r=ir.length-1;else for(r=e;!ir[--r];);for(n=ir[r],n={line:n.line,column:n.column};r<e;)10===t.charCodeAt(r)?(n.line++,n.column=1):n.column++,r++;return ir[e]=n,n}function Cr(t,e,r){const o=br(t),s=br(e),u={source:n,start:{offset:t,line:o.line,column:o.column},end:{offset:e,line:s.line,column:s.column}};return r&&n&&"function"==typeof n.offset&&(u.start=n.offset(u.start),u.end=n.offset(u.end)),u}function wr(t){ur<ar||(ur>ar&&(ar=ur,fr=[]),fr.push(t))}function Ar(t,e,r){return new peg$SyntaxError(peg$SyntaxError.buildMessage(t,e),t,e,r)}function mr(){let e,n;return e=ur,n=Er(),n===r&&(n=function(){let e,n,o,s,u,l,i,c,f,h,p,d,g,b;e=ur,n=ur,o=t.substr(ur,6),o.toLowerCase()===L?ur+=6:(o=r,0===hr&&wr(Ut));o!==r?(s=rn(),s!==r?(lr=n,n=new INSERT):(ur=n,n=r)):(ur=n,n=r);n===r&&(n=ur,o=t.substr(ur,6),o.toLowerCase()===v?ur+=6:(o=r,0===hr&&wr(zt)),o!==r?(s=rn(),s!==r?(lr=n,n=new UPSERT):(ur=n,n=r)):(ur=n,n=r));if(n!==r)if(o=ur,s=kr(),s!==r&&(lr=o,C=s,s=void(n._.entries=Array.isArray(C)?C:[C])),o=s,o===r&&(o=null),s=ur,u=ur,l=t.substr(ur,4),l.toLowerCase()===y?ur+=4:(l=r,0===hr&&wr(Bt)),l!==r?(i=rn(),i!==r?(l=[l,i],u=l):(ur=u,u=r)):(ur=u,u=r),u!==r?(l=Pr(),l!==r?(lr=s,s=function(t,e){t._.into=e}(n,l)):(ur=s,s=r)):(ur=s,s=r),s!==r){if(u=ur,l=t.substr(ur,4),l.toLowerCase()===a?ur+=4:(l=r,0===hr&&wr(vt)),l!==r?(i=rn(),i!==r?(c=kr(),c!==r?(lr=u,u=function(t,e){t._.from=e}(n,c)):(ur=u,u=r)):(ur=u,u=r)):(ur=u,u=r),u===r&&(u=ur,l=Er(),l!==r&&(lr=u,l=function(t,e){t._.from=e}(n,l)),u=l),u===r){if(u=ur,l=ur,i=ur,c=t.substr(ur,7),c.toLowerCase()===S?ur+=7:(c=r,0===hr&&wr(Mt)),c!==r?(f=rn(),f!==r?(c=[c,f],i=c):(ur=i,i=r)):(ur=i,i=r),i===r&&(i=null),c=ur,f=kr(),f===r&&(f=function(){let t,e,n,o,s;t=ur,e=[],n=ur,o=Tr(),o!==r&&(lr=n,o=er(o));n=o;for(;n!==r;)e.push(n),n=ur,o=Xr(),o!==r?(o=ur,s=Tr(),s!==r&&(lr=o,s=er(s)),o=s,o===r?(ur=n,n=r):n=o):n=o;e.length<1?(ur=t,t=r):t=e;return t}()),f!==r&&(lr=c,f=function(t,e){t._tail(e)}(n,f)),c=f,c!==r?(i=[i,c],l=i):(ur=l,l=r),l===r&&(l=null),i=ur,c=ur,f=t.substr(ur,7),f.toLowerCase()===_?ur+=7:(f=r,0===hr&&wr(Zt)),f!==r?(h=rn(),h!==r?(f=[f,h],c=f):(ur=c,c=r)):(ur=c,c=r),c===r&&(c=null),f=kr(),f===r)if(f=ur,h=Vr(),h!==r){for(p=ur,d=[],g=Ir();g!==r;)d.push(g),g=ur,b=Xr(),b!==r?(b=Ir(),b===r?(ur=g,g=r):g=b):g=b;d.length<1?(ur=p,p=r):p=d,p!==r?(d=Jr(),d!==r?f=p:(ur=f,f=r)):(ur=f,f=r)}else ur=f,f=r;f!==r?(lr=i,i=function(t,e){t._.columns=e}(n,f)):(ur=i,i=r),i===r&&(i=null),c=ur,f=ur,h=t.substr(ur,4),h.toLowerCase()===$?ur+=4:(h=r,0===hr&&wr(qt)),h!==r?(p=rn(),p!==r?(h=[h,p],f=h):(ur=f,f=r)):(ur=f,f=r),f===r&&(f=null),h=kr(),h!==r?(lr=c,c=function(t,e){t._.rows=e}(n,h)):(ur=c,c=r),c===r&&(c=null),f=ur,h=ur,p=t.substr(ur,6),p.toLowerCase()===T?ur+=6:(p=r,0===hr&&wr(Ht)),p!==r?(d=rn(),d!==r?(p=[p,d],h=p):(ur=h,h=r)):(ur=h,h=r),h!==r?(p=zr(),p!==r?(lr=f,f=function(t,e){t._.values=e.list}(n,p)):(ur=f,f=r)):(ur=f,f=r),f===r&&(f=null),l=[l,i,c,f],u=l}u!==r?e=n:(ur=e,e=r)}else ur=e,e=r;else ur=e,e=r;var C;return e}(),n===r&&(n=function(){let e,n,o,s,u,l,i,c;e=ur,n=ur,o=t.substr(ur,6),o.toLowerCase()===I?ur+=6:(o=r,0===hr&&wr(Gt));o!==r?(s=rn(),s!==r?(lr=n,n=new UPDATE):(ur=n,n=r)):(ur=n,n=r);n!==r?(o=ur,s=ur,u=t.substr(ur,6),u.toLowerCase()===P?ur+=6:(u=r,0===hr&&wr(Qt)),u!==r?(l=rn(),l!==r?(u=[u,l],s=u):(ur=s,s=r)):(ur=s,s=r),s===r&&(s=null),u=Pr(),u!==r?(lr=o,a=u,o=void(n._.entity=a)):(ur=o,o=r),o!==r?(s=ur,u=t.substr(ur,4),u.toLowerCase()===O?ur+=4:(u=r,0===hr&&wr(Vt)),u===r&&(u=t.substr(ur,3),u.toLowerCase()===N?ur+=3:(u=r,0===hr&&wr(Jt))),u!==r?(l=rn(),l!==r?(i=Rr(),i!==r?(c=en(),lr=s,s=function(t,e){Object.assign(t._,e)}(n,i)):(ur=s,s=r)):(ur=s,s=r)):(ur=s,s=r),s===r&&(s=null),u=ur,l=ur,i=t.substr(ur,5),i.toLowerCase()===f?ur+=5:(i=r,0===hr&&wr(St)),i!==r?(c=rn(),c!==r?(i=[i,c],l=i):(ur=l,l=r)):(ur=l,l=r),l!==r?(i=Sr(),i!==r?(c=en(),lr=u,u=function(t,e){t._.where=e}(n,i)):(ur=u,u=r)):(ur=u,u=r),u===r&&(u=null),e=n):(ur=e,e=r)):(ur=e,e=r);var a;return e}(),n===r&&(n=function(){let e,n,o,s,u,l,i;e=ur,n=ur,o=t.substr(ur,6),o.toLowerCase()===U?ur+=6:(o=r,0===hr&&wr(Xt));o!==r?(s=rn(),s!==r?(lr=n,n=new DELETE):(ur=n,n=r)):(ur=n,n=r);n!==r?(o=ur,s=ur,u=t.substr(ur,4),u.toLowerCase()===a?ur+=4:(u=r,0===hr&&wr(vt)),u!==r?(l=rn(),l!==r?(u=[u,l],s=u):(ur=s,s=r)):(ur=s,s=r),s===r&&(s=null),u=Pr(),u!==r?(l=en(),lr=o,c=u,o=void(n._.from=c)):(ur=o,o=r),o!==r?(s=ur,u=ur,l=t.substr(ur,5),l.toLowerCase()===f?ur+=5:(l=r,0===hr&&wr(St)),l!==r?(i=rn(),i!==r?(l=[l,i],u=l):(ur=u,u=r)):(ur=u,u=r),u!==r?(l=Sr(),l!==r?(i=en(),lr=s,s=function(t,e){t._.where=e}(n,l)):(ur=s,s=r)):(ur=s,s=r),s===r&&(s=null),e=n):(ur=e,e=r)):(ur=e,e=r);var c;return e}()))),n!==r&&(lr=e,n=Ve(n)),e=n,e}function Er(){let e,n,o,s,f,h,p,d,g,b,C;return e=ur,n=ur,o=t.substr(ur,6),o.toLowerCase()===u?ur+=6:(o=r,0===hr&&wr(mt)),o!==r?(s=rn(),s!==r?(lr=n,n=new SELECT):(ur=n,n=r)):(ur=n,n=r),n!==r?(o=ur,s=t.substr(ur,9),s.toLowerCase()===l?ur+=9:(s=r,0===hr&&wr(Et)),s!==r?(f=rn(),f!==r?(lr=o,o=void(n._.localized=!0)):(ur=o,o=r)):(ur=o,o=r),o===r&&(o=null),s=ur,f=t.substr(ur,8),f.toLowerCase()===i?ur+=8:(f=r,0===hr&&wr(xt)),f!==r?(h=rn(),h!==r?(lr=s,s=function(t){t._.distinct=!0}(n)):(ur=s,s=r)):(ur=s,s=r),s===r&&(s=null),f=ur,h=t.substr(ur,3),h.toLowerCase()===c?ur+=3:(h=r,0===hr&&wr(Lt)),h!==r?(p=rn(),p!==r?(lr=f,f=function(t){t._.one=!0}(n)):(ur=f,f=r)):(ur=f,f=r),f===r&&(f=null),h=ur,p=vr(),p!==r?(d=en(),lr=h,h=function(t,e){t._.columns=e}(n,p)):(ur=h,h=r),h===r&&(h=null),p=ur,d=ur,g=t.substr(ur,4),g.toLowerCase()===a?ur+=4:(g=r,0===hr&&wr(vt)),g!==r?(b=rn(),b!==r?(g=[g,b],d=g):(ur=d,d=r)):(ur=d,d=r),d!==r?(g=Pr(),g===r&&(g=Yr()),g!==r?(lr=p,p=function(t,e){t._.from=e}(n,g)):(ur=p,p=r)):(ur=p,p=r),p===r&&(p=null),d=ur,g=Gr(),g!==r?(b=vr(),b!==r?(C=Qr(),C!==r?(lr=d,d=function(t,e){t._.columns=e}(n,b)):(ur=d,d=r)):(ur=d,d=r)):(ur=d,d=r),d===r&&(d=null),g=ur,b=xr(),b!==r&&(lr=g,b=function(t,e){Object.assign(t._,e)}(n,b)),g=b,g===r&&(g=null),e=n):(ur=e,e=r),e}function xr(){let e,n,o,s,u,l,i,c,a,C,w,A;var m;return e=ur,n=ur,o=ur,hr++,t.length>ur?(s=t.charAt(ur),ur++):(s=r,0===hr&&wr(yt)),hr--,s!==r?(ur=o,o=void 0):o=r,o!==r&&(lr=n,o={}),n=o,n!==r?(o=ur,s=ur,u=t.substr(ur,5),u.toLowerCase()===f?ur+=5:(u=r,0===hr&&wr(St)),u!==r?(l=rn(),l!==r?(u=[u,l],s=u):(ur=s,s=r)):(ur=s,s=r),s!==r?(u=Sr(),u!==r?(l=en(),lr=o,m=u,o=void(n.where=m)):(ur=o,o=r)):(ur=o,o=r),o===r&&(o=null),s=ur,u=ur,l=t.substr(ur,8),l.toLowerCase()===h?ur+=8:(l=r,0===hr&&wr(_t)),l!==r?(i=rn(),i!==r?(c=_r(),c!==r?(a=en(),lr=u,u=function(t,e){t.groupBy=e}(n,c)):(ur=u,u=r)):(ur=u,u=r)):(ur=u,u=r),u!==r?(l=ur,i=t.substr(ur,6),i.toLowerCase()===p?ur+=6:(i=r,0===hr&&wr($t)),i!==r?(c=rn(),c!==r?(a=Sr(),a!==r?(C=en(),lr=l,l=function(t,e){t.having=e}(n,a)):(ur=l,l=r)):(ur=l,l=r)):(ur=l,l=r),l===r&&(l=null),u=[u,l],s=u):(ur=s,s=r),s===r&&(s=null),u=ur,l=ur,i=t.substr(ur,8),i.toLowerCase()===d?ur+=8:(i=r,0===hr&&wr(Tt)),i!==r?(c=rn(),c!==r?(i=[i,c],l=i):(ur=l,l=r)):(ur=l,l=r),l!==r?(i=$r(),i!==r?(c=en(),lr=u,u=function(t,e){t.orderBy=e}(n,i)):(ur=u,u=r)):(ur=u,u=r),u===r&&(u=null),l=ur,i=ur,c=t.substr(ur,5),c.toLowerCase()===g?ur+=5:(c=r,0===hr&&wr(Rt)),c!==r?(a=rn(),a!==r?(C=Dr(),C===r&&(C=Ur()),C!==r?(w=en(),lr=i,i=function(t,e){t.limit={rows:e}}(n,C)):(ur=i,i=r)):(ur=i,i=r)):(ur=i,i=r),i!==r?(c=ur,a=t.substr(ur,6),a.toLowerCase()===b?ur+=6:(a=r,0===hr&&wr(Ft)),a!==r?(C=rn(),C!==r?(w=Dr(),w===r&&(w=Ur()),w!==r?(A=en(),lr=c,c=function(t,e){t.limit.offset=e}(n,w)):(ur=c,c=r)):(ur=c,c=r)):(ur=c,c=r),c===r&&(c=null),i=[i,c],l=i):(ur=l,l=r),l===r&&(l=null),e=n):(ur=e,e=r),e}function Lr(){let e,n,o,s,u;return e=ur,n=ur,o=en(),n=t.substring(n,ur),o=t.substr(ur,2),o.toLowerCase()===C?ur+=2:(o=r,0===hr&&wr(jt)),o!==r?(s=rn(),s!==r?(u=jr(),u!==r?e=u:(ur=e,e=r)):(ur=e,e=r)):(ur=e,e=r),e}function vr(){let e,n,o,s,u,l,i,c,a,f,h;for(e=ur,n=[],42===t.charCodeAt(ur)?(o=w,ur++):(o=r,0===hr&&wr(It)),o===r&&(o=ur,s=Dr(),s!==r?(u=ur,l=Lr(),l!==r&&(lr=u,l=Je(s,l)),u=l,u===r&&(u=null),l=tn(),l===r&&(l=null),i=ur,c=Gr(),c!==r?(a=vr(),a!==r?(f=Qr(),f!==r?(lr=i,i=Ke(s,l,a)):(ur=i,i=r)):(ur=i,i=r)):(ur=i,i=r),i!==r?o=s:(ur=o,o=r)):(ur=o,o=r),o===r&&(o=ur,s=Or(),s!==r?(u=ur,l=Lr(),l!==r&&(lr=u,l=Xe(s,l)),u=l,u===r&&(u=null),o=s):(ur=o,o=r)));o!==r;)n.push(o),o=ur,s=Xr(),s!==r?(42===t.charCodeAt(ur)?(s=w,ur++):(s=r,0===hr&&wr(It)),s===r&&(s=ur,u=Dr(),u!==r?(l=ur,i=Lr(),i!==r&&(lr=l,i=Je(u,i)),l=i,l===r&&(l=null),i=tn(),i===r&&(i=null),c=ur,a=Gr(),a!==r?(f=vr(),f!==r?(h=Qr(),h!==r?(lr=c,c=Ke(u,i,f)):(ur=c,c=r)):(ur=c,c=r)):(ur=c,c=r),c!==r?s=u:(ur=s,s=r)):(ur=s,s=r),s===r&&(s=ur,u=Or(),u!==r?(l=ur,i=Lr(),i!==r&&(lr=l,i=Xe(u,i)),l=i,l===r&&(l=null),s=u):(ur=s,s=r))),s===r?(ur=o,o=r):o=s):o=s;return n.length<1?(ur=e,e=r):e=n,e}function yr(){let e,n,o,s,u,l,i,c;return e=ur,n=en(),91===t.charCodeAt(ur)?(o=A,ur++):(o=r,0===hr&&wr(Pt)),o!==r?(s=en(),u=function(){let e,n,o,s,u;e=ur,n=kr(),n!==r&&(lr=e,l=n,n={where:fluent.where(l)});var l;if(e=n,e===r){for(e=ur,n=ur,o=[],s=Ur();s!==r;)o.push(s),s=ur,u=Xr(),u!==r?(u=Ur(),u===r?(ur=s,s=r):s=u):s=u;o.length<1?(ur=n,n=r):n=o,n!==r&&(lr=e,n={where:n}),e=n,e===r&&(e=ur,n=ur,hr++,o=ur,s=t.substr(ur,5),s.toLowerCase()===f?ur+=5:(s=r,0===hr&&wr(St)),s!==r?(u=rn(),u!==r?(s=[s,u],o=s):(ur=o,o=r)):(ur=o,o=r),hr--,o===r?n=void 0:(ur=n,n=r),n!==r?(o=Nr(),o!==r?(lr=e,e={where:o.xpr}):(ur=e,e=r)):(ur=e,e=r),e===r&&(e=xr()))}return e}(),u!==r?(l=en(),93===t.charCodeAt(ur)?(i=m,ur++):(i=r,0===hr&&wr(Ot)),i!==r?(c=en(),e=u):(ur=e,e=r)):(ur=e,e=r)):(ur=e,e=r),e}function Sr(){let t,e;var n;return t=ur,e=kr(),e!==r&&(lr=t,n=e,e=fluent.where(n)),t=e,t===r&&(t=ur,e=Nr(),e!==r&&(lr=t,e=e.xpr),t=e),t}function _r(){let t,e,n,o,s;for(t=ur,e=ur,n=[],o=Dr();o!==r;)n.push(o),o=ur,s=Xr(),s!==r?(s=Dr(),s===r?(ur=o,o=r):o=s):o=s;return n.length<1?(ur=e,e=r):e=n,e!==r?t=e:(ur=t,t=r),t}function $r(){let e,n,o,s,u,l,i,c,a;for(e=ur,n=ur,o=[],s=ur,u=Dr(),u!==r?(l=ur,i=rn(),i!==r?(c=t.substr(ur,3),c.toLowerCase()===E?ur+=3:(c=r,0===hr&&wr(Nt)),c===r&&(c=t.substr(ur,4),c.toLowerCase()===x?ur+=4:(c=r,0===hr&&wr(Dt))),c!==r?(lr=l,l=tr(u,c)):(ur=l,l=r)):(ur=l,l=r),l===r&&(l=null),s=u):(ur=s,s=r);s!==r;)o.push(s),s=ur,u=Xr(),u!==r?(u=ur,l=Dr(),l!==r?(i=ur,c=rn(),c!==r?(a=t.substr(ur,3),a.toLowerCase()===E?ur+=3:(a=r,0===hr&&wr(Nt)),a===r&&(a=t.substr(ur,4),a.toLowerCase()===x?ur+=4:(a=r,0===hr&&wr(Dt))),a!==r?(lr=i,i=tr(l,a)):(ur=i,i=r)):(ur=i,i=r),i===r&&(i=null),u=l):(ur=u,u=r),u===r?(ur=s,s=r):s=u):s=u;return o.length<1?(ur=n,n=r):n=o,n!==r?e=n:(ur=e,e=r),e}function Tr(){let e,n,o,s,u,l,i,c,a,f,h;if(e=ur,n=ur,o=en(),123===t.charCodeAt(ur)?(s=R,ur++):(s=r,0===hr&&wr(Wt)),s!==r?(u=en(),lr=n,n={}):(ur=n,n=r),n!==r){for(o=ur,s=[],u=ur,l=Ir(),l!==r?(i=en(),58===t.charCodeAt(ur)?(c=F,ur++):(c=r,0===hr&&wr(Yt)),c!==r?(a=en(),f=Zr(),f===r&&(f=Or()),f!==r?(lr=u,u=rr(n,l,f)):(ur=u,u=r)):(ur=u,u=r)):(ur=u,u=r);u!==r;)s.push(u),u=ur,l=Xr(),l!==r?(l=ur,i=Ir(),i!==r?(c=en(),58===t.charCodeAt(ur)?(a=F,ur++):(a=r,0===hr&&wr(Yt)),a!==r?(f=en(),h=Zr(),h===r&&(h=Or()),h!==r?(lr=l,l=rr(n,i,h)):(ur=l,l=r)):(ur=l,l=r)):(ur=l,l=r),l===r?(ur=u,u=r):u=l):u=l;s.length<1?(ur=o,o=r):o=s,o!==r?(s=en(),125===t.charCodeAt(ur)?(u=j,ur++):(u=r,0===hr&&wr(kt)),u!==r?(l=en(),e=n):(ur=e,e=r)):(ur=e,e=r)}else ur=e,e=r;return e}function Rr(){let t,e;return t=ur,e=kr(),e!==r&&(lr=t,e={data:e}),t=e,t===r&&(t=ur,e=Tr(),e!==r&&(lr=t,e={with:e}),t=e,t===r&&(t=ur,e=Fr(),e!==r&&(lr=t,e={with:e}),t=e)),t}function Fr(){let e,n,o,s,u,l,i,c,a,f,h;for(e=ur,n=ur,o="",lr=n,o={},n=o,o=ur,s=[],u=ur,l=Ir(),l!==r?(i=en(),61===t.charCodeAt(ur)?(c=D,ur++):(c=r,0===hr&&wr(Kt)),c!==r?(a=en(),f=Zr(),f===r&&(f=Or()),f!==r?(lr=u,u=nr(n,l,f)):(ur=u,u=r)):(ur=u,u=r)):(ur=u,u=r);u!==r;)s.push(u),u=ur,l=Xr(),l!==r?(l=ur,i=Ir(),i!==r?(c=en(),61===t.charCodeAt(ur)?(a=D,ur++):(a=r,0===hr&&wr(Kt)),a!==r?(f=en(),h=Zr(),h===r&&(h=Or()),h!==r?(lr=l,l=nr(n,i,h)):(ur=l,l=r)):(ur=l,l=r)):(ur=l,l=r),l===r?(ur=u,u=r):u=l):u=l;return s.length<1?(ur=o,o=r):o=s,o!==r?e=n:(ur=e,e=r),e}function jr(){let e,n,o,s,u,l,i,c,f;if(hr++,e=ur,n=ur,hr++,o=t.substr(ur,2),o.toLowerCase()===C?ur+=2:(o=r,0===hr&&wr(ee)),hr--,o===r?n=void 0:(ur=n,n=r),n!==r)if(o=ur,hr++,s=t.substr(ur,4),s.toLowerCase()===a?ur+=4:(s=r,0===hr&&wr(re)),hr--,s===r?o=void 0:(ur=o,o=r),o!==r)if(s=ur,hr++,u=Wr(),hr--,u===r?s=void 0:(ur=s,s=r),s!==r){if(u=ur,l=ur,i=t.charAt(ur),pt.test(i)?ur++:(i=r,0===hr&&wr(ne)),i!==r){for(c=[],f=t.charAt(ur),dt.test(f)?ur++:(f=r,0===hr&&wr(oe));f!==r;)c.push(f),f=t.charAt(ur),dt.test(f)?ur++:(f=r,0===hr&&wr(oe));i=[i,c],l=i}else ur=l,l=r;u=l!==r?t.substring(u,ur):l,u!==r?e=u:(ur=e,e=r)}else ur=e,e=r;else ur=e,e=r;else ur=e,e=r;return hr--,e===r&&(n=r,0===hr&&wr(te)),e}function Ir(){let e,n,o,s,u,l;for(hr++,e=ur,n=ur,o=ur,s=[],u=jr();u!==r;)s.push(u),u=ur,l=tn(),l!==r?(l=jr(),l===r?(ur=u,u=r):u=l):u=l;return s.length<1?(ur=o,o=r):o=s,n=o!==r?t.substring(n,ur):o,n!==r?e=n:(ur=e,e=r),hr--,e===r&&(n=r,0===hr&&wr(se)),e}function Pr(){let e,n,o,s,u,l,i;var c;if(hr++,e=ur,n=kr(),n!==r&&(lr=e,c=n,n=fluent.subject(c)),e=n,e===r){for(e=ur,n=ur,o=[],s=ur,u=jr(),u!==r?(l=tn(),l!==r?(u=[u,l],s=u):(ur=s,s=r)):(ur=s,s=r);s!==r;)o.push(s),s=ur,u=jr(),u!==r?(l=tn(),l!==r?(u=[u,l],s=u):(ur=s,s=r)):(ur=s,s=r);n=t.substring(n,ur),o=ur,s=jr(),s!==r?(u=en(),58===t.charCodeAt(ur)?(l=F,ur++):(l=r,0===hr&&wr(Yt)),l!==r?(i=en(),o=s):(ur=o,o=r)):(ur=o,o=r),o===r&&(o=null),s=Dr(),s!==r?(u=en(),lr=e,e=function(t,e,r){if(e)return{ref:[t+e,...r.ref]};if(t){let[e]=r.ref;e.id?e.id=t+e.id:r.ref[0]=t+e}return r}(n,o,s)):(ur=e,e=r)}return hr--,e===r&&(n=r,0===hr&&wr(ue)),e}function Or(){let t,e;var n;return t=ur,e=Nr(),e!==r&&(lr=t,e=(n=e).xpr.length>1?n:n.xpr[0]),t=e,t}function Nr(){let t,e,n,o,s,u;if(t=ur,e=[],n=Yr(),n===r&&(n=zr(),n===r&&(n=Mr(),n===r&&(n=Ur(),n===r&&(n=Hr(),n===r&&(n=Br(),n===r&&(n=Dr(),n===r&&(n=ur,o=Vr(),o!==r?(s=Or(),s!==r?(u=Jr(),u!==r?n=s:(ur=n,n=r)):(ur=n,n=r)):(ur=n,n=r)))))))),n!==r)for(;n!==r;)e.push(n),n=Yr(),n===r&&(n=zr(),n===r&&(n=Mr(),n===r&&(n=Ur(),n===r&&(n=Hr(),n===r&&(n=Br(),n===r&&(n=Dr(),n===r&&(n=ur,o=Vr(),o!==r?(s=Or(),s!==r?(u=Jr(),u!==r?n=s:(ur=n,n=r)):(ur=n,n=r)):(ur=n,n=r))))))));else e=r;return e!==r&&(lr=t,e={xpr:e}),t=e,t}function Dr(){let t,e,n,o,s,u,l;for(hr++,t=ur,e=ur,n=[],o=ur,s=jr(),s!==r?(u=yr(),u===r&&(u=null),lr=o,o=or(s,u)):(ur=o,o=r);o!==r;)n.push(o),o=ur,s=tn(),s!==r?(s=ur,u=jr(),u!==r?(l=yr(),l===r&&(l=null),lr=s,s=or(u,l)):(ur=s,s=r),s===r?(ur=o,o=r):o=s):o=s;return n.length<1?(ur=e,e=r):e=n,e!==r&&(lr=t,e={ref:e}),t=e,hr--,t===r&&(e=r,0===hr&&wr(le)),t}function Ur(){let e,n;return hr++,e=Zr(),e===r&&(e=ur,n=function(){let e,n;hr++,e=function(){let e,n,o,s,u,l;e=ur,39===t.charCodeAt(ur)?(n=ut,ur++):(n=r,0===hr&&wr(Ue));if(n!==r){for(o=ur,s=[],u=t.charAt(ur),Ct.test(u)?ur++:(u=r,0===hr&&wr(ze)),u===r&&(u=ur,t.substr(ur,2)===lt?(l=lt,ur+=2):(l=r,0===hr&&wr(Be)),l!==r&&(lr=u,l="'"),u=l);u!==r;)s.push(u),u=t.charAt(ur),Ct.test(u)?ur++:(u=r,0===hr&&wr(ze)),u===r&&(u=ur,t.substr(ur,2)===lt?(l=lt,ur+=2):(l=r,0===hr&&wr(Be)),l!==r&&(lr=u,l=sr()),u=l);o=t.substring(o,ur),39===t.charCodeAt(ur)?(s=ut,ur++):(s=r,0===hr&&wr(Ue)),s!==r?e=o:(ur=e,e=r)}else ur=e,e=r;return e}(),e===r&&(e=function(){let e,n,o,s,u,l,i,c,a,f;e=ur,n=ur,o=ur,45===t.charCodeAt(ur)?(s=nt,ur++):(s=r,0===hr&&wr(Pe));s===r&&(s=null);u=[],l=t.charAt(ur),bt.test(l)?ur++:(l=r,0===hr&&wr(Oe));if(l!==r)for(;l!==r;)u.push(l),l=t.charAt(ur),bt.test(l)?ur++:(l=r,0===hr&&wr(Oe));else u=r;if(u!==r){if(l=ur,46===t.charCodeAt(ur)?(i=ot,ur++):(i=r,0===hr&&wr(Ne)),i!==r){if(c=[],a=t.charAt(ur),bt.test(a)?ur++:(a=r,0===hr&&wr(Oe)),a!==r)for(;a!==r;)c.push(a),a=t.charAt(ur),bt.test(a)?ur++:(a=r,0===hr&&wr(Oe));else c=r;c!==r?(i=[i,c],l=i):(ur=l,l=r)}else ur=l,l=r;if(l===r&&(l=null),i=ur,101===t.charCodeAt(ur)?(c=st,ur++):(c=r,0===hr&&wr(De)),c!==r){if(a=[],f=t.charAt(ur),bt.test(f)?ur++:(f=r,0===hr&&wr(Oe)),f!==r)for(;f!==r;)a.push(f),f=t.charAt(ur),bt.test(f)?ur++:(f=r,0===hr&&wr(Oe));else a=r;a!==r?(c=[c,a],i=c):(ur=i,i=r)}else ur=i,i=r;i===r&&(i=null),s=[s,u,l,i],o=s}else ur=o,o=r;n=o!==r?t.substring(n,ur):o;n!==r&&(lr=e,n=Number(n));return e=n,e}(),e===r&&(e=function(){let e,n,o,s;e=ur,t.substr(ur,4)===it?(n=it,ur+=4):(n=r,0===hr&&wr(Me));n!==r?(o=ur,hr++,s=Kr(),hr--,s===r?o=void 0:(ur=o,o=r),o!==r?(lr=e,e=!0):(ur=e,e=r)):(ur=e,e=r);return e}(),e===r&&(e=function(){let e,n,o,s;e=ur,t.substr(ur,5)===ct?(n=ct,ur+=5):(n=r,0===hr&&wr(Ze));n!==r?(o=ur,hr++,s=Kr(),hr--,s===r?o=void 0:(ur=o,o=r),o!==r?(lr=e,e=!1):(ur=e,e=r)):(ur=e,e=r);return e}(),e===r&&(e=function(){let e,n,o,s;e=ur,t.substr(ur,4)===et?(n=et,ur+=4):(n=r,0===hr&&wr(Fe));n!==r?(o=ur,hr++,s=Kr(),hr--,s===r?o=void 0:(ur=o,o=r),o!==r?(lr=e,e=null):(ur=e,e=r)):(ur=e,e=r);return e}()))));hr--,e===r&&(n=r,0===hr&&wr(Ie));return e}(),n!==r&&(lr=e,n={val:n}),e=n),hr--,e===r&&(n=r,0===hr&&wr(ie)),e}function zr(){let t,e,n,o;return hr++,t=Zr(),t===r&&(t=ur,e=Vr(),e!==r?(n=ur,o=qr(),o!==r&&(lr=n,o={list:o}),n=o,n!==r?(o=Jr(),o!==r?t=n:(ur=t,t=r)):(ur=t,t=r)):(ur=t,t=r)),hr--,t===r&&(e=r,0===hr&&wr(ce)),t}function Br(){let e,n,o,s,u,l,i;if(hr++,e=ur,n=jr(),n!==r)if(o=Vr(),o!==r){for(s=ur,u=[],42===t.charCodeAt(ur)?(l=w,ur++):(l=r,0===hr&&wr(It)),l===r&&(l=Or());l!==r;)u.push(l),l=ur,i=Xr(),i!==r?(42===t.charCodeAt(ur)?(i=w,ur++):(i=r,0===hr&&wr(It)),i===r&&(i=Or()),i===r?(ur=l,l=r):l=i):l=i;u.length<1?(ur=s,s=r):s=u,s!==r?(u=Jr(),u!==r?(lr=e,e={func:n,args:s}):(ur=e,e=r)):(ur=e,e=r)}else ur=e,e=r;else ur=e,e=r;return hr--,e===r&&(n=r,0===hr&&wr(ae)),e}function Mr(){let e,n,o;return hr++,e=ur,35===t.charCodeAt(ur)?(n=z,ur++):(n=r,0===hr&&wr(he)),n!==r?(o=jr(),o!==r?(lr=e,e={"#":o}):(ur=e,e=r)):(ur=e,e=r),hr--,e===r&&(n=r,0===hr&&wr(fe)),e}function Zr(){let e,n,o,s;return hr++,e=ur,n=en(),63===t.charCodeAt(ur)?(o=B,ur++):(o=r,0===hr&&wr(de)),o!==r?(s=en(),lr=e,e=un()):(ur=e,e=r),hr--,e===r&&(n=r,0===hr&&wr(pe)),e}function qr(){let t,e,n,o;for(hr++,t=ur,e=[],n=Mr(),n===r&&(n=Ur(),n===r&&(n=Dr(),n===r&&(n=Br())));n!==r;)e.push(n),n=ur,o=Xr(),o!==r?(o=Mr(),o===r&&(o=Ur(),o===r&&(o=Dr(),o===r&&(o=Br()))),o===r?(ur=n,n=r):n=o):n=o;return e.length<2?(ur=t,t=r):t=e,hr--,t===r&&(e=r,0===hr&&wr(ie)),t}function Hr(){let e,n,o,s,u;if(hr++,e=ur,n=en(),o=Wr(),o===r){if(o=ur,s=[],u=t.charAt(ur),gt.test(u)?ur++:(u=r,0===hr&&wr(be)),u!==r)for(;u!==r;)s.push(u),u=t.charAt(ur),gt.test(u)?ur++:(u=r,0===hr&&wr(be));else s=r;o=s!==r?t.substring(o,ur):s}return o!==r?(s=en(),e=o):(ur=e,e=r),hr--,e===r&&(n=r,0===hr&&wr(ge)),e}function Wr(){let e,n,o,s,u,l,i,c;if(e=ur,t.substr(ur,3)===M?(n=M,ur+=3):(n=r,0===hr&&wr(Ce)),n===r&&(t.substr(ur,2)===Z?(n=Z,ur+=2):(n=r,0===hr&&wr(we)),n===r&&(t.substr(ur,2)===q?(n=q,ur+=2):(n=r,0===hr&&wr(Ae)),n===r&&(t.substr(ur,7)===H?(n=H,ur+=7):(n=r,0===hr&&wr(me)),n===r&&(t.substr(ur,4)===W?(n=W,ur+=4):(n=r,0===hr&&wr(Ee)),n===r&&(t.substr(ur,6)===Y?(n=Y,ur+=6):(n=r,0===hr&&wr(xe)),n===r&&(t.substr(ur,8)===k?(n=k,ur+=8):(n=r,0===hr&&wr(Le)))))))),n!==r?(o=ur,hr++,s=Kr(),hr--,s===r?o=void 0:(ur=o,o=r),o!==r?e=n:(ur=e,e=r)):(ur=e,e=r),e===r&&(e=ur,t.substr(ur,4)===G?(n=G,ur+=4):(n=r,0===hr&&wr(ve)),n===r&&(t.substr(ur,4)===Q?(n=Q,ur+=4):(n=r,0===hr&&wr(ye)),n===r&&(t.substr(ur,4)===V?(n=V,ur+=4):(n=r,0===hr&&wr(Se)),n===r&&(t.substr(ur,4)===J?(n=J,ur+=4):(n=r,0===hr&&wr(_e)),n===r&&(t.substr(ur,3)===K?(n=K,ur+=3):(n=r,0===hr&&wr($e)))))),n!==r?(o=ur,hr++,s=Kr(),hr--,s===r?o=void 0:(ur=o,o=r),o!==r?e=n:(ur=e,e=r)):(ur=e,e=r),e===r)){for(e=ur,n=ur,o=[],s=ur,t.substr(ur,2)===X?(u=X,ur+=2):(u=r,0===hr&&wr(Te)),u===r&&(t.substr(ur,3)===tt?(u=tt,ur+=3):(u=r,0===hr&&wr(Re)),u===r&&(t.substr(ur,4)===et?(u=et,ur+=4):(u=r,0===hr&&wr(Fe)),u===r&&(t.substr(ur,5)===rt?(u=rt,ur+=5):(u=r,0===hr&&wr(je))))),u!==r?(l=ur,hr++,i=Kr(),hr--,i===r?l=void 0:(ur=l,l=r),l!==r?(u=[u,l],s=u):(ur=s,s=r)):(ur=s,s=r);s!==r;)o.push(s),s=ur,u=en(),u=ur,t.substr(ur,2)===X?(l=X,ur+=2):(l=r,0===hr&&wr(Te)),l===r&&(t.substr(ur,3)===tt?(l=tt,ur+=3):(l=r,0===hr&&wr(Re)),l===r&&(t.substr(ur,4)===et?(l=et,ur+=4):(l=r,0===hr&&wr(Fe)),l===r&&(t.substr(ur,5)===rt?(l=rt,ur+=5):(l=r,0===hr&&wr(je))))),l!==r?(i=ur,hr++,c=Kr(),hr--,c===r?i=void 0:(ur=i,i=r),i!==r?(l=[l,i],u=l):(ur=u,u=r)):(ur=u,u=r),u===r?(ur=s,s=r):s=u;o.length<1?(ur=n,n=r):n=o,e=n!==r?t.substring(e,ur):n}return e}function Yr(){let t,e,n,o;return t=ur,e=Vr(),e!==r?(n=Er(),n!==r?(o=Jr(),o!==r?t=n:(ur=t,t=r)):(ur=t,t=r)):(ur=t,t=r),t}function kr(){let e,n,o,s;return e=ur,n=en(),63===t.charCodeAt(ur)?(o=B,ur++):(o=r,0===hr&&wr(de)),o!==r?(s=en(),lr=e,e=on.shift()):(ur=e,e=r),e}function Gr(){let e,n,o,s;return e=ur,n=en(),123===t.charCodeAt(ur)?(o=R,ur++):(o=r,0===hr&&wr(Wt)),o!==r?(s=en(),n=[n,o,s],e=n):(ur=e,e=r),e}function Qr(){let e,n,o,s;return e=ur,n=en(),125===t.charCodeAt(ur)?(o=j,ur++):(o=r,0===hr&&wr(kt)),o!==r?(s=en(),n=[n,o,s],e=n):(ur=e,e=r),e}function Vr(){let e,n,o,s;return e=ur,n=en(),40===t.charCodeAt(ur)?(o=at,ur++):(o=r,0===hr&&wr(qe)),o!==r?(s=en(),n=[n,o,s],e=n):(ur=e,e=r),e}function Jr(){let e,n,o,s;return e=ur,n=en(),41===t.charCodeAt(ur)?(o=ft,ur++):(o=r,0===hr&&wr(He)),o!==r?(s=en(),n=[n,o,s],e=n):(ur=e,e=r),e}function Kr(){let e;return e=t.charAt(ur),wt.test(e)?ur++:(e=r,0===hr&&wr(We)),e}function Xr(){let e,n,o,s;return hr++,e=ur,n=en(),44===t.charCodeAt(ur)?(o=ht,ur++):(o=r,0===hr&&wr(ke)),o!==r?(s=en(),e=o):(ur=e,e=r),hr--,e===r&&(n=r,0===hr&&wr(Ye)),e}function tn(){let e,n,o,s;return hr++,e=ur,n=en(),46===t.charCodeAt(ur)?(o=ot,ur++):(o=r,0===hr&&wr(Ne)),o!==r?(s=en(),lr=e,e="."):(ur=e,e=r),hr--,e===r&&(n=r,0===hr&&wr(Ge)),e}function en(){let e,n,o;for(hr++,e=ur,n=[],o=t.charAt(ur),At.test(o)?ur++:(o=r,0===hr&&wr(Qe));o!==r;)n.push(o),o=t.charAt(ur),At.test(o)?ur++:(o=r,0===hr&&wr(Qe));return e=t.substring(e,ur),hr--,e}function rn(){let e,n,o;if(hr++,e=ur,n=[],o=t.charAt(ur),At.test(o)?ur++:(o=r,0===hr&&wr(Qe)),o!==r)for(;o!==r;)n.push(o),o=t.charAt(ur),At.test(o)?ur++:(o=r,0===hr&&wr(Qe));else n=r;return e=n!==r?t.substring(e,ur):n,hr--,e===r&&(n=r,0===hr&&wr(Ge)),e}const nn=[],on=e.args;let sn=0;const un=!on?.length||!e.startRule&&peg$parse.late_binding?()=>nn[sn++]=ln:()=>nn[sn]=fluent.expr(on[sn++]),ln={ref:["?"],param:!0};cr=s();const cn=cr!==r&&ur===t.length;function an(){throw cr!==r&&ur<t.length&&wr({type:"end"}),Ar(fr,ar<t.length?function(e=ur){const r=t.codePointAt(e);return void 0===r?"":String.fromCodePoint(r)}(ar):null,ar<t.length?Cr(ar,ar+1):Cr(ar,ar))}return e.peg$library?{peg$result:cr,peg$currPos:ur,peg$FAILED:r,peg$maxFailExpected:fr,peg$maxFailPos:ar,peg$success:cn,peg$throw:cn?void 0:an}:cn?cr:void an()}const peg$allowedStartRules=["CQL","subject","columns","values","ref","val","expr","with","set","where","groupBy","orderBy"];export{peg$allowedStartRules as StartRules,peg$SyntaxError as SyntaxError,peg$parse as parse};
package/lib/index.js CHANGED
@@ -1,22 +1,3 @@
1
- import { SELECT as SELECT_ } from './ql/select.js'
2
- import { INSERT as INSERT_ } from './ql/insert.js'
3
- import { UPSERT as UPSERT_ } from './ql/insert.js'
4
- import { UPDATE as UPDATE_ } from './ql/update.js'
5
- import { DELETE as DELETE_ } from './ql/delete.js'
6
-
7
- // Re-export the query classes with fluent interfaces
8
- export const SELECT = SELECT_.chimera (SELECT_.columns)
9
- export const INSERT = INSERT_.chimera (INSERT_.entries)
10
- export const UPSERT = UPSERT_.chimera (UPSERT_.entries)
11
- export const UPDATE = UPDATE_.chimera (UPDATE_.entity)
12
- export const DELETE = DELETE_.chimera (DELETE_.from)
13
-
14
- // Re-export all the helper functions and classes from the xl module
15
- export * from './xl/ttl.js'
16
- import * as peg from '../cql/parser.min.js'
17
- import { Query } from './ql/base-class.js'
18
- export { Query }
19
-
20
1
 
21
2
  /**
22
3
  * This is the central entry point for creating queries from various types of input:
@@ -26,25 +7,61 @@ export { Query }
26
7
  * the corresponding query class.
27
8
  * @param { Query | string | object } qso - The input, as described above, to be converted into an instance of a Query subclass.
28
9
  * @param { ...any } args - Optional arguments for template literals or parameterized queries.
29
- * @import { SELECT } from './ql/select.js'
30
- * @import { INSERT } from './ql/insert.js'
31
- * @import { UPSERT } from './ql/insert.js'
32
- * @import { UPDATE } from './ql/update.js'
33
- * @import { DELETE } from './ql/delete.js'
34
- * @returns { SELECT & INSERT & UPSERT & UPDATE & DELETE }
10
+ * @returns { SELECT_ & INSERT_ & UPSERT_ & UPDATE_ & DELETE_ }
35
11
  */
36
- export function cql (qso, ...args) {
12
+ export const cql = Query.for = (qso, ...args) => {
37
13
  if (!qso || qso instanceof Query) return qso
38
14
  if (qso.raw) return cql.cache.query4 (qso, ...args)
39
15
  if (typeof qso === 'string') return peg.parse (qso, {args})
40
- else for (let k in qso) if (k in peg.ql) //> usually query.kind is first key
41
- return Object.setPrototypeOf (qso, peg.ql[k].prototype)
16
+ else for (let k in qso) if (k in Query.for) //> usually query.kind is first key
17
+ return Object.setPrototypeOf (qso, Query.for[k].prototype)
42
18
  return null //> for any other object
43
19
  }
44
20
  export default cql
45
21
 
46
22
 
23
+ // Re-export all the helper functions and classes from the xl module
24
+ export * from './xl/ttl.js'
25
+ import * as peg from '../cql/parser.min.js'
26
+ import { Query } from './query.js'
27
+ export { Query }
28
+
29
+ // Export fluent variants of the query classes
30
+ import { SELECT as SELECT_ } from './ql/select.js'
31
+ import { INSERT as INSERT_ } from './ql/insert.js'
32
+ import { UPSERT as UPSERT_ } from './ql/insert.js'
33
+ import { UPDATE as UPDATE_ } from './ql/update.js'
34
+ import { DELETE as DELETE_ } from './ql/delete.js'
35
+
36
+ export const SELECT = chimera (SELECT_, SELECT_.columns)
37
+ export const INSERT = chimera (INSERT_, INSERT_.entries)
38
+ export const UPSERT = chimera (UPSERT_, UPSERT_.entries)
39
+ export const UPDATE = chimera (UPDATE_, UPDATE_.entity)
40
+ export const DELETE = chimera (DELETE_, DELETE_.from)
41
+
42
+ /**
43
+ * Turns subclasses of Query into fluent APIs that allow constructing instances with `new`
44
+ * as well as plain function calls. For example, this enables usages like these: @example
45
+ * SELECT`ID,title`.from`Books`
46
+ * UPDATE`Books`.with`${data}`
47
+ * @param factory - The function to be called when the fluent API is invoked without `new`.
48
+ * @type <clazz> (clazz:clazz, factory:()=> clazz) => factory & clazz
49
+ */
50
+ function chimera (clazz, factory) { const kind = clazz.name
51
+ function fx (...args) { return new.target ? new clazz : factory.call (clazz,...args) }
52
+ Object.defineProperty (clazz.prototype, '_', { get(){ return this[kind] }})
53
+ Object.defineProperty (clazz.prototype, 'kind', { value: kind })
54
+ Object.defineProperty (clazz, 'name', { value: 'Query' })
55
+ Object.defineProperty (fx, 'name', { value: kind })
56
+ Object.defineProperty (fx, 'class', { value: clazz })
57
+ Object.defineProperty (fx, 'prototype', { value: clazz.prototype })
58
+ Object.setPrototypeOf (fx,clazz) //> adds static members
59
+ return Query.for[kind] = fx
60
+ }
61
+
62
+
47
63
  // Prepare a cache for parsed queries, and export it as part of the cql facade
48
64
  // for easy access and control over caching behavior.
49
65
  import { QueryCache } from './ql/cache.js'
50
- cql.cache = new QueryCache()
66
+ cql.cache = new QueryCache
67
+ cql.cache.enabled = false //> disable caching by default
package/lib/ql/cache.js CHANGED
@@ -1,12 +1,13 @@
1
1
  import * as peg from '../../cql/parser.min.js'
2
+ import { Query } from '../query.js'
2
3
 
3
- export class QueryCache extends WeakMap {
4
+ export class QueryCache extends Map {
4
5
 
5
6
  cached (strings, ...args) {
6
7
  if (!strings?.raw) return this.parse (strings, ...args)
7
8
  const cached = this.get (strings)
8
9
  if (cached) {
9
- const q = new peg.ql[cached.kind]
10
+ const q = new Query.for[cached.kind]
10
11
  q[q.kind] = cached[cached.kind]
11
12
  q.params = cached.params
12
13
  if (args?.length) q.args = args
@@ -23,16 +24,11 @@ export class QueryCache extends WeakMap {
23
24
  return peg.parse (src, {args})
24
25
  }
25
26
 
26
- enable(){
27
- peg.parse.late_binding = true
28
- this.query4 = this.cached
29
- }
30
-
31
- disable(){
32
- peg.parse.late_binding = false
33
- this.query4 = this.parse
27
+ get enabled () { return peg.parse.late_binding }
28
+ set enabled (v) {
29
+ this.query4 = v ? this.cached : this.parse
30
+ peg.parse.late_binding = v
34
31
  }
35
32
 
36
33
  query4 = this.parse
37
-
38
34
  }
package/lib/ql/delete.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { subject, where } from '../xl/ttl.js'
2
- import { Query } from './base-class.js'
2
+ import { Query } from '../query.js'
3
3
 
4
4
  export class DELETE extends Query { DELETE = {}
5
5
  static from (...args) { return (new this)._set('from', subject (...args)) }
package/lib/ql/insert.js CHANGED
@@ -1,23 +1,24 @@
1
- import { subject, columns, values, fluent, unwrapped } from '../xl/ttl.js'
2
- import { Query } from './base-class.js'
3
- import { cql } from '../index.js'
1
+ import { subject, columns, values } from '../xl/ttl.js'
2
+ import { Query } from '../query.js'
4
3
 
5
- export class XSERT extends Query { INSERT = {}
4
+ const unwrapped = args => Array.isArray(args[0]) ? args[0] : args
5
+
6
+ export class XSERT extends Query {
6
7
  static entries (...args) { return (new this).entries(...args) }
7
8
  static into (x,...tail) {
8
9
  if (x.raw) return (new this)._set ('into', subject(x,...tail)) //> INSERT.into`Foo`
9
10
  const insert = (new this)._set ('into', subject(x)) //> INSERT.into(Foo)
10
- return !tail.length ? insert : insert._entries(...tail) //> INSERT.into(Foo, ...?)
11
- }; _entries (...tail) {
11
+ return !tail.length ? insert : insert._tail(...tail) //> INSERT.into(Foo, ...?)
12
+ }; _tail (...tail) {
12
13
  if (unwrapped(tail)[0]?.split) return this.columns(...tail) //> INSERT.into(Foo, columns)
13
- return this._set ('entries', fluent.entries(...tail)) //> INSERT.into(Foo, entries)
14
+ return this._set ('entries', unwrapped(tail)) //> INSERT.into(Foo, entries)
14
15
  }
15
16
  into (...args) { return this._set('into', subject(...args)) }
16
- entries (...args) { return this._set('entries', fluent.entries(...args)) }
17
+ entries (...args) { return this._set('entries', unwrapped(args)) }
17
18
  columns (...args) { return this._add('columns', columns(...args).map(c => c.ref[0])) }
18
19
  values (...args) { return this._set('values', values(...args)) }
19
20
  rows (...args) { return this._set('rows', unwrapped(args)) }
20
- from (...args) { return this._set('from', cql(...args)) }
21
+ from (...args) { return this._set('from', Query.for(...args)) }
21
22
  get subject() { return this._.into }
22
23
  }
23
24
 
package/lib/ql/select.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { subject, columns, where, orderBy, val } from '../xl/ttl.js'
2
- import { Query } from './base-class.js'
2
+ import { Query } from '../query.js'
3
3
 
4
4
  export class SELECT extends Query { SELECT = {}
5
5
  static from (...args) { return (new this).from (...args) }
package/lib/ql/update.js CHANGED
@@ -1,10 +1,14 @@
1
- import { subject, where } from '../xl/ttl.js'
2
- import { Query } from './base-class.js'
1
+ import { subject, where, ttl } from '../xl/ttl.js'
2
+ import { Query } from '../query.js'
3
3
 
4
4
  export class UPDATE extends Query { UPDATE = {}
5
5
  static entity (...args) { return (new this)._set('entity', subject (...args)) }
6
- where (...args) { return this._add('where', where (...args)) }
7
- with (data,x) { return this._set('with', data.raw ? x : data) }
8
- set (data,x) { return this._set('with', data.raw ? x : data) }
6
+ where (...args) { return this._add ('where', where (...args)) }
7
+ with (...args) {
8
+ if (args[0]?.raw) Object.assign (this._, ttl('with',...args))
9
+ else this._set('data', args[0])
10
+ return this
11
+ }
12
+ set (...args) { return this.with (...args) }
9
13
  get subject() { return this._.entity }
10
14
  }
@@ -1,41 +1,21 @@
1
- import * as peg from '../../cql/parser.min.js'
2
- import { expr } from '../xl/fluent.js'
1
+ import { expr } from './xl/fluent.js'
3
2
 
4
3
  export class Query {
5
4
 
6
- /**
7
- * Turns subclasses of Query into fluent APIs that allow constructing instances with `new`
8
- * as well as plain function calls. For example, this enables usages like these: @example
9
- * SELECT`ID,title`.from`Books`
10
- * UPDATE`Books`.with`${data}`
11
- * @param fn - The function to be called when the fluent API is invoked without `new`.
12
- * @type <T> (this:T, fn:()=>T) => fn & T
13
- */
14
- static chimera (fn) { const self = this, kind = this.name
15
- function fx (...args) { return new.target ? new self : fn.call (self,...args) }
16
- Object.defineProperty (this.prototype, '_', { get(){ return this[kind] }})
17
- Object.defineProperty (this.prototype, 'kind', { value: kind })
18
- Object.defineProperty (this, 'name', { value: 'Query' })
19
- Object.defineProperty (fx, 'name', { value: kind })
20
- Object.defineProperty (fx, 'class', { value: this })
21
- Object.defineProperty (fx, 'prototype', { value: this.prototype })
22
- Object.setPrototypeOf (fx,this) //> adds static members
23
- return peg.ql[kind] = fx
24
- }
5
+ // These are required for Peggy Live Preview in VSCode
6
+ /** @private */ get kind() { return this.constructor.name }
7
+ /** @private */ get _() { return this[this.kind] }
25
8
 
26
9
  /**
27
- * - Creates a shallow clone of the given `query`.
28
- * - Subsequent changes to the clone will not affect the original.
29
- * - However, changes to nested objects will affect both the original and the clone.
30
- * @param clauses - Optional list of objects with clauses to override in the clone.
31
- * @type <T> (this:T, clauses:{columns,from,where,having,groupy,orderBy,limit}[]) => T
10
+ * Returns the main subject `{ref}` of the query, which refers to the entity being queried or modified.
11
+ * @returns {ref:string[]} The main subject of the query.
32
12
  */
33
- clone (...clauses) {
34
- const _ = this.kind || Object.keys(this)[0]
35
- return Object.assign ({ __proto__: this,
36
- [_]: { __proto__: this[_] }
37
- }, ...clauses)
38
- }
13
+ get subject() { return this._.from }
14
+
15
+ // Non-enumerable properties that are only valid within the same process
16
+ /** @private */ set source (cql) { Object.defineProperty (this, 'source', { value: cql, writable: true }) }
17
+ /** @private */ set params (arr) { Object.defineProperty (this, 'params', { value: arr, writable: true }) }
18
+ /** @private */ set args (arr) { Object.defineProperty (this, 'args', { value: arr, writable: true }) }
39
19
 
40
20
  /**
41
21
  * - Fills in any binding `{param}`s with corresponding `{val}`s from given `args`.
@@ -61,6 +41,20 @@ export class Query {
61
41
  return this
62
42
  }
63
43
 
44
+ /**
45
+ * - Creates a shallow clone of the given `query`.
46
+ * - Subsequent changes to the clone will not affect the original.
47
+ * - However, changes to nested objects will affect both the original and the clone.
48
+ * @param clauses - Optional list of objects with clauses to override in the clone.
49
+ * @type <T> (this:T, clauses:{columns,from,where,having,groupy,orderBy,limit}[]) => T
50
+ */
51
+ clone (...clauses) {
52
+ const _ = this.kind || Object.keys(this)[0]
53
+ return Object.assign ({ __proto__: this,
54
+ [_]: { __proto__: this[_] }
55
+ }, ...clauses)
56
+ }
57
+
64
58
  /**
65
59
  * Adds the given values to the specified clause in the CQN. If the clause already
66
60
  * exists, the new values are appended to the existing ones. Otherwise, a clause
@@ -82,17 +76,10 @@ export class Query {
82
76
  return this
83
77
  }
84
78
 
85
- /**
86
- * Returns the main subject `{ref}` of the query, which refers to the entity being queried or modified.
87
- * - For `SELECT` and `DELETE` queries, this is the `from` clause.
88
- * - For `INSERT` and `UPSERT` queries, this is the `into` clause.
89
- * - For `UPDATE` queries, this is the `entity` clause.
90
- * @returns {ref:string[]} The main subject of the query.
91
- */
92
- get subject() { return this._.from }
93
-
94
- // Non-enumerable properties that are only valid within the same process
95
- /** @private */ set source (cql) { Object.defineProperty (this, 'source', { value: cql, writable: true }) }
96
- /** @private */ set params (arr) { Object.defineProperty (this, 'params', { value: arr, writable: true }) }
97
- /** @private */ set args (arr) { Object.defineProperty (this, 'args', { value: arr, writable: true }) }
79
+ // Custom inspect method to improve the output, e.g. in repl, console.log,
80
+ [Symbol.for('nodejs.util.inspect.custom')] (depth, options, inspect) {
81
+ return `${this.kind} ${inspect(this[this.kind], options)}`
82
+ }
98
83
  }
84
+
85
+ /** @private */ Query.for = {} //> filled in from ./index.js
package/lib/xl/fluent.js CHANGED
@@ -1,17 +1,27 @@
1
- export const unwrapped = args => Array.isArray(args[0]) ? args[0] : args
1
+ const unwrapped = args => Array.isArray(args[0]) ? args[0] : args
2
2
 
3
- function entity (e,ref) {
4
- Object.defineProperty (this, 'target', {value:e}) .ref = ref
3
+ export const val = (v) => ({ val: v })
4
+ export const ref = (r) => ({ ref: String(r).split('.') })
5
+ export const expr = (x) => {
6
+ if (Array.isArray(x)) return { list: x.map(expr) }
7
+ if (x && typeof x === 'object') return x //> already a cxn object
8
+ else return val(x)
5
9
  }
6
10
 
7
11
  export const subject = (x,pk) => {
8
- const id = x.name || x, ref = [ !pk ? id : { id, where: where(pk) } ]
9
- return x.name ? new entity(x,ref) : {ref}
12
+ if (x.ref) return x
13
+ if (x.name) return Object.defineProperty ({ref:[x.name]},'target',{value:x})
14
+ let ref = [ !pk ? x : { id:x, where: where(pk) } ]
15
+ return {ref}
16
+ }
17
+
18
+ export const columns = (...args) => {
19
+ return unwrapped(args) .map (a => typeof a === 'string' ? ref(a) : val(a))
10
20
  }
11
21
 
12
- export const entries = (...args) => unwrapped(args)
13
- export const columns = (...args) => unwrapped(args) .map (ref)
14
- export const values = (...args) => unwrapped(args) .map (expr)
22
+ export const values = (...args) => {
23
+ return unwrapped(args) .map (expr)
24
+ }
15
25
 
16
26
  export const where = (x) => {
17
27
  if (!x || typeof x !== 'object') return [ val(x) ]
@@ -19,14 +29,19 @@ export const where = (x) => {
19
29
  .flat().slice(1)
20
30
  }
21
31
 
22
- export const orderBy = (obj) => Object.entries(obj) .map (
23
- ([k,v]) => ({ref:[k], sort: {1:'asc','-1':'desc'}[v] || v})
24
- )
25
-
26
- export const ref = (r) => ({ ref: String(r).split('.') })
27
- export const val = (v) => ({ val: v })
28
- export const expr = (x) => {
29
- if (Array.isArray(x)) return { list: x.map(expr) }
30
- if (x && typeof x === 'object') return x //> already a cxn object
31
- else return val(x)
32
+ export const having = where
33
+ export const groupBy = columns
34
+ export const orderBy = (...args) => {
35
+ // orderBy({ a:1, b:-1 })
36
+ if (typeof (args = unwrapped(args))[0] === 'object')
37
+ return Object.entries(args[0]) .map (
38
+ ([k,v]) => ({ ref:[k], sort: { [1]:'asc',[-1]:'desc' }[v] || v })
39
+ )
40
+ // orderBy('a desc','b')
41
+ else return args.map (ordering_term => {
42
+ const [,c,ad] = /^([^\s]+)(?:\s+(asc|desc))?$/i .exec (ordering_term)
43
+ const ref = { ref: c.split('.') }
44
+ if (ad) ref.sort = ad.toLowerCase()
45
+ return ref
46
+ })
32
47
  }
package/lib/xl/ttl.js CHANGED
@@ -1,29 +1,24 @@
1
- import * as fluent from './fluent.js'; export { fluent }
2
1
  import * as peg from '../../cql/parser.min.js'
2
+ import * as fluent from './fluent.js'
3
+ export { fluent }
3
4
 
4
- export const { unwrapped } = fluent
5
- export const parse = peg.parse
6
- parse.ttl = (startRule, x, ...args) => x?.raw && parse (String.raw (x, ...'?'.repeat(args.length)), { startRule, args })
7
- parse.str = (startRule, x, ...args) => parse (x, { startRule, args })
8
- parse.fluent = fluent
9
-
10
- export const subject = (...args) => parse.ttl ('entity', ...args) || fluent.subject (...args)
11
- export const columns = (...args) => parse.ttl ('columns', ...args) || fluent.columns (...args)
12
- export const values = (...args) => parse.ttl ('vals', ...args) || fluent.values (...args)
13
- export const where = (...args) => parse.ttl ('where', ...args) || fluent.where (...args)
14
- export const having = where
15
- export const groupBy = columns
16
- export const orderBy = (...args) => {
17
- const cxn = parse.ttl ('orderBy', ...args); if (cxn) return cxn
18
- if (typeof (args = unwrapped(args))[0] === 'string')
19
- return parse.str ('orderBy', args.join(','))
20
- else return fluent.orderBy (...args) //> { a:1, b:-1 }
5
+ export const ttl = (rule, x,...args) => {
6
+ const src = String.raw (x,...'?'.repeat(args.length))
7
+ return peg.parse (src, { startRule: rule, args })
21
8
  }
22
9
 
23
- export const ref = (r,...tail) => parse.ttl ('ref', r, ...tail) || { ref: r.split('.') }
24
- export const val = (...args) => parse.ttl ('val', ...args) || { val: args[0] }
25
- export const expr = (...args) => {
26
- const cxn = parse.ttl ('expr', ...args); if (cxn) return cxn
27
- const xpr = args.map (fluent.expr)
28
- return xpr.length === 1 ? xpr[0] : {xpr}
10
+ export const ttl_ = (rule, ffn) => (x,...args) => {
11
+ if (x?.raw) return ttl (rule, x,...args)
12
+ else return ffn (x,...args)
29
13
  }
14
+
15
+ export const val = ttl_('val', fluent.val)
16
+ export const ref = ttl_('ref', fluent.ref)
17
+ export const expr = ttl_('expr', fluent.expr)
18
+ export const subject = ttl_('subject', fluent.subject)
19
+ export const columns = ttl_('columns', fluent.columns)
20
+ export const values = ttl_('values', fluent.values)
21
+ export const where = ttl_('where', fluent.where)
22
+ export const having = ttl_('having', fluent.having)
23
+ export const groupBy = ttl_('groupBy', fluent.groupBy)
24
+ export const orderBy = ttl_('orderBy', fluent.orderBy)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cap.core/ql",
3
- "version": "1.2.5",
4
- "description": "Minimalistic implementation of `cds.ql`, carved out from CAP.",
3
+ "version": "1.3.0",
4
+ "description": "Minimalistic implementation of cds.ql, carved out from CAP.",
5
5
  "repository": "https://github.com/cap-js/ql.git",
6
6
  "author": "daniel.hutzel@sap.com",
7
7
  "type": "module",
@@ -15,9 +15,10 @@
15
15
  "@types/cap.core__ql": "file:./@types"
16
16
  },
17
17
  "scripts": {
18
- "peggy": "npx peggy cql/grammar.pegjs -o cql/parser.js --format es --allowed-start-rules CQL,entity,columns,ref,val,vals,expr,where,groupBy,orderBy",
19
- "terser": "npx terser cql/parser.js -o cql/parser.min.js --compress --mangle --ecma 2022 --source-map \"base=ql/cql,url=parser.min.js.map\"",
20
- "build": "npm run peggy && npm run terser"
18
+ "peggy": "npx peggy cql/grammar.pegjs -o cql/parser.js --format es --allowed-start-rules CQL,subject,columns,values,ref,val,expr,with,set,where,groupBy,orderBy",
19
+ "terser": "npx terser cql/parser.js -o cql/parser.min.js --compress --mangle --ecma 2022 --source-map",
20
+ "build": "npm run peggy && npm run terser",
21
+ "test": "npx vitest run"
21
22
  },
22
23
  "license": "Apache-2.0"
23
24
  }
package/@types/LICENSE DELETED
@@ -1,201 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS
177
-
178
- APPENDIX: How to apply the Apache License to your work.
179
-
180
- To apply the Apache License to your work, attach the following
181
- boilerplate notice, with the fields enclosed by brackets "[]"
182
- replaced with your own identifying information. (Don't include
183
- the brackets!) The text should be enclosed in the appropriate
184
- comment syntax for the file format. We also recommend that a
185
- file or class name and description of purpose be included on the
186
- same "printed page" as the copyright notice for easier
187
- identification within third-party archives.
188
-
189
- Copyright [yyyy] [name of copyright owner]
190
-
191
- Licensed under the Apache License, Version 2.0 (the "License");
192
- you may not use this file except in compliance with the License.
193
- You may obtain a copy of the License at
194
-
195
- http://www.apache.org/licenses/LICENSE-2.0
196
-
197
- Unless required by applicable law or agreed to in writing, software
198
- distributed under the License is distributed on an "AS IS" BASIS,
199
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
- See the License for the specific language governing permissions and
201
- limitations under the License.