Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

odata-query

Package Overview
Dependencies
Maintainers
1
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

odata-query - npm Package Compare versions

Comparing version
8.0.4
to
8.0.5
+1
-1
dist/index.cjs

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

"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const F=["eq","ne","gt","ge","lt","le"],w=["and","or","not"],I=["any","all"],L=["startswith","endswith","contains","matchespattern"],q=["expand","levels","select","skip","top","count","orderby","filter"],T=/\((.*)\)/,_=/(?!indexof)\((\w+)\)/;var N=(e=>(e.sum="sum",e.min="min",e.max="max",e.average="average",e.countdistinct="countdistinct",e))(N||{});const U=e=>({type:"raw",value:e}),D=e=>({type:"guid",value:e}),V=e=>({type:"duration",value:e}),k=e=>({type:"binary",value:e}),G=e=>({type:"json",value:e}),P=(e,o)=>({type:"alias",name:e,value:o}),X=e=>({type:"decimal",value:e}),d="";function M({select:e,search:o,skiptoken:r,format:n,top:p,skip:$,filter:u,transform:l,orderBy:O,key:b,count:s,expand:y,action:i,func:c}={}){let a="",t=[];const f={};if(b!=null&&(a+=`(${h(b,t)})`),(u||typeof s=="object")&&(f.$filter=m(typeof s=="object"?s:u,t)),l&&(f.$apply=S(l)),y&&(f.$expand=E(y)),O&&(f.$orderby=R(O)),s&&(typeof s=="boolean"?f.$count=!0:a+="/$count"),typeof p=="number"&&(f.$top=p),typeof $=="number"&&(f.$skip=$),i&&(a+=`/${i}`),c){if(typeof c=="string")a+=`/${c}`;else if(typeof c=="object"){const[j]=Object.keys(c),A=h(c[j],t);a+=`/${j}`,A!==""&&(a+=`(${A})`)}}return t.length>0&&Object.assign(f,t.reduce((j,A)=>Object.assign(j,{[`@${A.name}`]:h(A.value)}),{})),W(a,{$select:e,$search:o,$skiptoken:r,$format:n,...f})}function C(e,o,r=[]){return`${e} eq ${h(o,r)}`}function m(e={},o=[],r=""){return(Array.isArray(e)?e:[e]).reduce(($,u)=>{if(u){const l=n(u,o,r);l&&$.push(l)}return $},[]).join(" and ");function n($={},u=[],l=""){let O="";return typeof $=="string"?O=$:$&&typeof $=="object"&&(O=Object.keys($).reduce((s,y)=>{const i=$[y];if(i===void 0)return s;let c="";if(l?y===d?c=l:_.test(y)?c=y.replace(_,(a,t)=>t.trim()===d?`(${l})`:`(${l}/${t.trim()})`):T.test(y)?c=y.replace(T,(a,t)=>t.trim()===d?`(${l})`:`(${l}/${t.trim()})`):c=`${l}/${y}`:c=y,y===d&&Array.isArray(i))return s.concat(i.map(a=>C(c,a)));if(["number","string","boolean"].indexOf(typeof i)!==-1||i instanceof Date||i===null)s.push(C(c,i,u));else if(Array.isArray(i)){const a=y,t=i.map(f=>m(f,u,l)).filter(f=>f).map(f=>w.indexOf(a)!==-1?`(${f})`:f);t.length&&(w.indexOf(a)!==-1?t.length&&(a==="not"?s.push(g(t)):s.push(`(${t.join(` ${a} `)})`)):s.push(t.join(` ${a} `)))}else if(w.indexOf(c)!==-1){const a=c,t=Object.keys(i).map(f=>n({[f]:i[f]}));t.length&&(a==="not"?s.push(g(t)):s.push(`(${t.join(` ${a} `)})`))}else if(typeof i=="object")"type"in i?s.push(C(c,i,u)):Object.keys(i).forEach(t=>{if(i[t]!==void 0)if(F.indexOf(t)!==-1)s.push(`${c} ${t} ${h(i[t],u)}`);else if(w.indexOf(t)!==-1)Array.isArray(i[t])?s.push(i[t].map(f=>"("+n(f,u,c)+")").join(` ${t} `)):s.push("("+n(i[t],u,c)+")");else if(I.indexOf(t)!==-1){const f=p(y.toLowerCase(),i[t],t,c);f&&s.push(f)}else if(t==="has")s.push(`${c} ${t} ${h(i[t],u)}`);else if(t==="in"){const f=Array.isArray(i[t])?i[t]:i[t].value.map(j=>({type:i[t].type,value:j}));s.push(c+" in ("+f.map(j=>h(j,u)).join(",")+")")}else if(L.indexOf(t)!==-1)s.push(`${t}(${c},${h(i[t],u)})`);else{const f=n({[t]:i[t]},u,c);f&&s.push(f)}});else throw new Error(`Unexpected value type: ${i}`);return s},[]).join(" and ")),O}function p($,u,l,O){let b="";if(typeof u=="string"||u instanceof String)b=J($,u,l,O);else if(u){const s=Array.isArray(u)?u.reduce((i,c)=>c.hasOwnProperty(d)?(i.hasOwnProperty(d)||(i[d]=[]),i[d].push(c[d]),i):{...i,...c},{}):u,y=n(s,o,$);b=`${O}/${l}(${y?`${$}:${y}`:""})`}return b}}function J(e,o,r,n){let p="";const $=r=="all"?"ne":"eq";return p=`${n}/${r}(${e}: ${e} ${$} '${o}')`,p}function z(e){return e=e.replace(/%/g,"%25"),e=e.replace(/\+/g,"%2B"),e=e.replace(/\//g,"%2F"),e=e.replace(/\?/g,"%3F"),e=e.replace(/#/g,"%23"),e=e.replace(/&/g,"%26"),e=e.replace(/'/g,"''"),e}function h(e,o){if(typeof e=="string")return`'${z(e)}'`;if(e instanceof Date)return e.toISOString();if(typeof e=="number")return e;if(Array.isArray(e))return`[${e.map(r=>h(r)).join(",")}]`;if(e===null)return e;if(typeof e=="object")switch(e.type){case"raw":case"guid":return e.value;case"duration":return`duration'${e.value}'`;case"binary":return`binary'${e.value}'`;case"alias":return Array.isArray(o)&&o.push(e),`@${e.name}`;case"json":return escape(JSON.stringify(e.value));case"decimal":return`${e.value}M`;default:return Object.entries(e).filter(([,r])=>r!==void 0).map(([r,n])=>`${r}=${h(n,o)}`).join(",")}return e}function E(e){if(typeof e=="number")return e;if(typeof e=="string")return e.indexOf("/")===-1?e:e.split("/").reverse().reduce((o,r,n,p)=>n===0?`$expand=${r}`:n===p.length-1?`${r}(${o})`:`$expand=${r}(${o})`,"");if(Array.isArray(e))return`${e.map(o=>E(o)).join(",")}`;if(typeof e=="object"){const o=Object.keys(e);return o.some(r=>q.indexOf(r.toLowerCase())!==-1)?o.map(r=>{let n;switch(r){case"filter":n=m(e[r]);break;case"orderBy":n=R(e[r]);break;case"levels":case"count":case"skip":case"top":n=`${e[r]}`;break;default:n=E(e[r])}return`$${r.toLowerCase()}=${n}`}).join(";"):o.map(r=>{const n=E(e[r]);return n?`${r}(${n})`:r}).join(",")}return""}function S(e){return(Array.isArray(e)?e:[e]).reduce((n,p)=>{const{aggregate:$,filter:u,groupBy:l,...O}=p,b=Object.keys(O);if(b.length)throw new Error(`Unsupported transform(s): ${b}`);if($&&n.push(`aggregate(${H($)})`),u){const s=m(u);s&&n.push(`filter(${m(s)})`)}return l&&n.push(`groupby(${Q(l)})`),n},[]).join("/")||void 0}function H(e){return(Array.isArray(e)?e:[e]).map(r=>typeof r=="string"?r:Object.keys(r).map(n=>{const p=r[n];if(!p.with&&p.as)return`${n} as ${p.as}`;if(!p.with)throw new Error(`'with' property required for '${n}'`);if(!p.as)throw new Error(`'as' property required for '${n}'`);return`${n} with ${p.with} as ${p.as}`})).join(",")}function Q(e){if(!e.properties)throw new Error("'properties' property required for groupBy");let o=`(${e.properties.join(",")})`;return e.transform&&(o+=`,${S(e.transform)}`),o}function R(e,o=""){return Array.isArray(e)?e.map(r=>Array.isArray(r)&&r.length===2&&["asc","desc"].indexOf(r[1])!==-1?r.join(" "):r).map(r=>`${o}${String(r)}`).join(","):typeof e=="object"?Object.entries(e).map(([r,n])=>R(n,`${r}/`)).map(r=>`${o}${r}`).join(","):`${o}${String(e)}`}function W(e,o){const r=Object.getOwnPropertyNames(o).filter(n=>o[n]!==void 0&&o[n]!=="").map(n=>`${n}=${o[n]}`);return r.length?`${e}?${r.join("&")}`:e}function g(e){return`not (${e.join(" and ")})`}exports.ITEM_ROOT=d;exports.StandardAggregateMethods=N;exports.alias=P;exports.binary=k;exports.decimal=X;exports.default=M;exports.duration=V;exports.guid=D;exports.json=G;exports.raw=U;
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const F=["eq","ne","gt","ge","lt","le"],m=["and","or","not"],k=["any","all"],I=["startswith","endswith","contains","matchespattern"],L=["expand","levels","select","skip","top","count","orderby","filter"],R=/\((.*)\)/,T=/(?!indexof)\((\w+)\)/;var N=(e=>(e.sum="sum",e.min="min",e.max="max",e.average="average",e.countdistinct="countdistinct",e))(N||{});const q=e=>({type:"raw",value:e}),U=e=>({type:"guid",value:e}),D=e=>({type:"duration",value:e}),V=e=>({type:"binary",value:e}),G=e=>({type:"json",value:e}),P=(e,o)=>({type:"alias",name:e,value:o}),X=e=>({type:"decimal",value:e}),b="";function M({select:e,search:o,skiptoken:r,format:n,top:a,skip:$,filter:s,transform:p,orderBy:d,key:j,count:u,expand:y,action:i,func:c}={}){let l="",t=[];const f={};if(j!=null&&(l+=`(${O(j,t)})`),(s||typeof u=="object")&&(f.$filter=E(typeof u=="object"?u:s,t)),p&&(f.$apply=S(p)),y&&(f.$expand=w(y)),d&&(f.$orderby=C(d)),u&&(typeof u=="boolean"?f.$count=!0:l+="/$count"),typeof a=="number"&&(f.$top=a),typeof $=="number"&&(f.$skip=$),i&&(l+=`/${i}`),c){if(typeof c=="string")l+=`/${c}`;else if(typeof c=="object"){const[h]=Object.keys(c),A=O(c[h],t);l+=`/${h}`,A!==""&&(l+=`(${A})`)}}return t.length>0&&Object.assign(f,t.reduce((h,A)=>Object.assign(h,{[`@${A.name}`]:O(A.value)}),{})),Q(l,{$select:e,$search:o,$skiptoken:r,$format:n,...f})}function g(e,o,r=[]){return`${e} eq ${O(o,r)}`}function E(e={},o=[],r=""){return(Array.isArray(e)?e:[e]).reduce(($,s)=>{if(s){const p=n(s,o,r);p&&$.push(p)}return $},[]).join(" and ");function n($={},s=[],p=""){let d="";return typeof $=="string"?d=$:$&&typeof $=="object"&&(d=Object.keys($).reduce((u,y)=>{const i=$[y];if(i===void 0)return u;let c="";if(p?y===b?c=p:T.test(y)?c=y.replace(T,(l,t)=>t.trim()===b?`(${p})`:`(${p}/${t.trim()})`):R.test(y)?c=y.replace(R,(l,t)=>t.trim()===b?`(${p})`:`(${p}/${t.trim()})`):c=`${p}/${y}`:c=y,y===b&&Array.isArray(i))return u.concat(i.map(l=>g(c,l)));if(["number","string","boolean"].indexOf(typeof i)!==-1||i instanceof Date||i===null)u.push(g(c,i,s));else if(Array.isArray(i)){const l=y,t=i.map(f=>E(f,s,p)).filter(f=>f).map(f=>m.indexOf(l)!==-1?`(${f})`:f);t.length&&(m.indexOf(l)!==-1?t.length&&(l==="not"?u.push(_(t)):u.push(`(${t.join(` ${l} `)})`)):u.push(t.join(` ${l} `)))}else if(m.indexOf(c)!==-1){const l=c,t=Object.keys(i).map(f=>n({[f]:i[f]}));t.length&&(l==="not"?u.push(_(t)):u.push(`(${t.join(` ${l} `)})`))}else if(typeof i=="object")"type"in i?u.push(g(c,i,s)):Object.keys(i).forEach(t=>{if(i[t]!==void 0)if(F.indexOf(t)!==-1)u.push(`${c} ${t} ${O(i[t],s)}`);else if(m.indexOf(t)!==-1)Array.isArray(i[t])?u.push(i[t].map(f=>"("+n(f,s,c)+")").join(` ${t} `)):u.push("("+n(i[t],s,c)+")");else if(k.indexOf(t)!==-1){const f=a(y.toLowerCase(),i[t],t,c);f&&u.push(f)}else if(t==="has")u.push(`${c} ${t} ${O(i[t],s)}`);else if(t==="in"){const f=Array.isArray(i[t])?i[t]:i[t].value.map(h=>({type:i[t].type,value:h}));u.push(c+" in ("+f.map(h=>O(h,s)).join(",")+")")}else if(I.indexOf(t)!==-1)u.push(`${t}(${c},${O(i[t],s)})`);else{const f=n({[t]:i[t]},s,c);f&&u.push(f)}});else throw new Error(`Unexpected value type: ${i}`);return u},[]).join(" and ")),d}function a($,s,p,d){let j="";if(typeof s=="string"||s instanceof String)j=J($,s,p,d);else if(s){const u=Array.isArray(s)?s.reduce((i,c)=>c.hasOwnProperty(b)?(i.hasOwnProperty(b)||(i[b]=[]),i[b].push(c[b]),i):{...i,...c},{}):s,y=n(u,o,$);j=`${d}/${p}(${y?`${$}:${y}`:""})`}return j}}function J(e,o,r,n){const a=r=="all"?"ne":"eq";return`${n}/${r}(${e}: ${e} ${a} '${o}')`}function z(e){return e=e.replace(/%/g,"%25"),e=e.replace(/\+/g,"%2B"),e=e.replace(/\//g,"%2F"),e=e.replace(/\?/g,"%3F"),e=e.replace(/#/g,"%23"),e=e.replace(/&/g,"%26"),e=e.replace(/'/g,"''"),e}function O(e,o){if(typeof e=="string")return`'${z(e)}'`;if(e instanceof Date)return e.toISOString();if(typeof e=="number")return e;if(Array.isArray(e))return`[${e.map(r=>O(r)).join(",")}]`;if(e===null)return e;if(typeof e=="object")switch(e.type){case"raw":case"guid":return e.value;case"duration":return`duration'${e.value}'`;case"binary":return`binary'${e.value}'`;case"alias":return Array.isArray(o)&&o.push(e),`@${e.name}`;case"json":return escape(JSON.stringify(e.value));case"decimal":return`${e.value}M`;default:return Object.entries(e).filter(([,r])=>r!==void 0).map(([r,n])=>`${r}=${O(n,o)}`).join(",")}return e}function w(e){if(typeof e=="number")return e;if(typeof e=="string")return e.indexOf("/")===-1?e:e.split("/").reverse().reduce((o,r,n,a)=>n===0?`$expand=${r}`:n===a.length-1?`${r}(${o})`:`$expand=${r}(${o})`,"");if(Array.isArray(e))return`${e.map(o=>w(o)).join(",")}`;if(typeof e=="object"){const o=Object.keys(e);return o.some(r=>L.indexOf(r.toLowerCase())!==-1)?o.map(r=>{let n;switch(r){case"filter":n=E(e[r]);break;case"orderBy":n=C(e[r]);break;case"levels":case"count":case"skip":case"top":n=`${e[r]}`;break;default:n=w(e[r])}return`$${r.toLowerCase()}=${n}`}).join(";"):o.map(r=>{const n=w(e[r]);return n?`${r}(${n})`:r}).join(",")}return""}function S(e){return(Array.isArray(e)?e:[e]).reduce((n,a)=>{for(const $ of Object.keys(a))switch($){case"aggregate":{const s=a[$];s&&n.push(`aggregate(${B(s)})`);break}case"filter":{const s=a[$];if(s){const p=E(s);p&&n.push(`filter(${p})`)}break}case"groupBy":{const s=a[$];s&&n.push(`groupby(${H(s)})`);break}default:throw new Error(`Unsupported transform: ${$}`)}return n},[]).join("/")||void 0}function B(e){return(Array.isArray(e)?e:[e]).map(r=>typeof r=="string"?r:Object.keys(r).map(n=>{const a=r[n];if(!a.with&&a.as)return`${n} as ${a.as}`;if(!a.with)throw new Error(`'with' property required for '${n}'`);if(!a.as)throw new Error(`'as' property required for '${n}'`);return`${n} with ${a.with} as ${a.as}`})).join(",")}function H(e){if(!e.properties)throw new Error("'properties' property required for groupBy");let o=`(${e.properties.join(",")})`;return e.transform&&(o+=`,${S(e.transform)}`),o}function C(e,o=""){return Array.isArray(e)?e.map(r=>Array.isArray(r)&&r.length===2&&["asc","desc"].indexOf(r[1])!==-1?r.join(" "):r).map(r=>`${o}${String(r)}`).join(","):typeof e=="object"?Object.entries(e).map(([r,n])=>C(n,`${r}/`)).map(r=>`${o}${r}`).join(","):`${o}${String(e)}`}function Q(e,o){const r=Object.getOwnPropertyNames(o).filter(n=>o[n]!==void 0&&o[n]!=="").map(n=>`${n}=${o[n]}`);return r.length?`${e}?${r.join("&")}`:e}function _(e){return`not (${e.join(" and ")})`}exports.ITEM_ROOT=b;exports.StandardAggregateMethods=N;exports.alias=P;exports.binary=V;exports.decimal=X;exports.default=M;exports.duration=D;exports.guid=U;exports.json=G;exports.raw=q;

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

const S = ["eq", "ne", "gt", "ge", "lt", "le"], w = ["and", "or", "not"], L = ["any", "all"], g = ["startswith", "endswith", "contains", "matchespattern"], q = [
const g = ["eq", "ne", "gt", "ge", "lt", "le"], m = ["and", "or", "not"], S = ["any", "all"], k = ["startswith", "endswith", "contains", "matchespattern"], L = [
"expand",

@@ -11,5 +11,5 @@ "levels",

], N = /\((.*)\)/, F = /(?!indexof)\((\w+)\)/;
var I = /* @__PURE__ */ ((e) => (e.sum = "sum", e.min = "min", e.max = "max", e.average = "average", e.countdistinct = "countdistinct", e))(I || {});
const X = (e) => ({ type: "raw", value: e }), P = (e) => ({ type: "guid", value: e }), J = (e) => ({ type: "duration", value: e }), x = (e) => ({ type: "binary", value: e }), z = (e) => ({ type: "json", value: e }), H = (e, o) => ({ type: "alias", name: e, value: o }), Q = (e) => ({ type: "decimal", value: e }), j = "";
function W({
var q = /* @__PURE__ */ ((e) => (e.sum = "sum", e.min = "min", e.max = "max", e.average = "average", e.countdistinct = "countdistinct", e))(q || {});
const X = (e) => ({ type: "raw", value: e }), P = (e) => ({ type: "guid", value: e }), J = (e) => ({ type: "duration", value: e }), x = (e) => ({ type: "binary", value: e }), z = (e) => ({ type: "json", value: e }), B = (e, o) => ({ type: "alias", name: e, value: o }), H = (e) => ({ type: "decimal", value: e }), h = "";
function Q({
select: e,

@@ -19,88 +19,88 @@ search: o,

format: n,
top: p,
top: a,
skip: $,
filter: u,
transform: l,
filter: s,
transform: p,
orderBy: O,
key: b,
count: s,
key: d,
count: u,
expand: y,
action: i,
func: f
func: c
} = {}) {
let a = "", t = [];
const c = {};
if (b != null && (a += `(${h(b, t)})`), (u || typeof s == "object") && (c.$filter = m(typeof s == "object" ? s : u, t)), l && (c.$apply = _(l)), y && (c.$expand = E(y)), O && (c.$orderby = R(O)), s && (typeof s == "boolean" ? c.$count = !0 : a += "/$count"), typeof p == "number" && (c.$top = p), typeof $ == "number" && (c.$skip = $), i && (a += `/${i}`), f) {
if (typeof f == "string")
a += `/${f}`;
else if (typeof f == "object") {
const [d] = Object.keys(f), A = h(f[d], t);
a += `/${d}`, A !== "" && (a += `(${A})`);
let l = "", t = [];
const f = {};
if (d != null && (l += `(${b(d, t)})`), (s || typeof u == "object") && (f.$filter = E(typeof u == "object" ? u : s, t)), p && (f.$apply = _(p)), y && (f.$expand = w(y)), O && (f.$orderby = R(O)), u && (typeof u == "boolean" ? f.$count = !0 : l += "/$count"), typeof a == "number" && (f.$top = a), typeof $ == "number" && (f.$skip = $), i && (l += `/${i}`), c) {
if (typeof c == "string")
l += `/${c}`;
else if (typeof c == "object") {
const [j] = Object.keys(c), A = b(c[j], t);
l += `/${j}`, A !== "" && (l += `(${A})`);
}
}
return t.length > 0 && Object.assign(c, t.reduce(
(d, A) => Object.assign(d, { [`@${A.name}`]: h(A.value) }),
return t.length > 0 && Object.assign(f, t.reduce(
(j, A) => Object.assign(j, { [`@${A.name}`]: b(A.value) }),
{}
)), G(a, { $select: e, $search: o, $skiptoken: r, $format: n, ...c });
)), G(l, { $select: e, $search: o, $skiptoken: r, $format: n, ...f });
}
function C(e, o, r = []) {
return `${e} eq ${h(o, r)}`;
return `${e} eq ${b(o, r)}`;
}
function m(e = {}, o = [], r = "") {
return (Array.isArray(e) ? e : [e]).reduce(($, u) => {
if (u) {
const l = n(u, o, r);
l && $.push(l);
function E(e = {}, o = [], r = "") {
return (Array.isArray(e) ? e : [e]).reduce(($, s) => {
if (s) {
const p = n(s, o, r);
p && $.push(p);
}
return $;
}, []).join(" and ");
function n($ = {}, u = [], l = "") {
function n($ = {}, s = [], p = "") {
let O = "";
return typeof $ == "string" ? O = $ : $ && typeof $ == "object" && (O = Object.keys($).reduce(
(s, y) => {
(u, y) => {
const i = $[y];
if (i === void 0)
return s;
let f = "";
if (l ? y === j ? f = l : F.test(y) ? f = y.replace(F, (a, t) => t.trim() === j ? `(${l})` : `(${l}/${t.trim()})`) : N.test(y) ? f = y.replace(N, (a, t) => t.trim() === j ? `(${l})` : `(${l}/${t.trim()})`) : f = `${l}/${y}` : f = y, y === j && Array.isArray(i))
return s.concat(
i.map((a) => C(f, a))
return u;
let c = "";
if (p ? y === h ? c = p : F.test(y) ? c = y.replace(F, (l, t) => t.trim() === h ? `(${p})` : `(${p}/${t.trim()})`) : N.test(y) ? c = y.replace(N, (l, t) => t.trim() === h ? `(${p})` : `(${p}/${t.trim()})`) : c = `${p}/${y}` : c = y, y === h && Array.isArray(i))
return u.concat(
i.map((l) => C(c, l))
);
if (["number", "string", "boolean"].indexOf(typeof i) !== -1 || i instanceof Date || i === null)
s.push(C(f, i, u));
u.push(C(c, i, s));
else if (Array.isArray(i)) {
const a = y, t = i.map((c) => m(c, u, l)).filter((c) => c).map((c) => w.indexOf(a) !== -1 ? `(${c})` : c);
t.length && (w.indexOf(a) !== -1 ? t.length && (a === "not" ? s.push(T(t)) : s.push(`(${t.join(` ${a} `)})`)) : s.push(t.join(` ${a} `)));
} else if (w.indexOf(f) !== -1) {
const a = f, t = Object.keys(i).map(
(c) => n({ [c]: i[c] })
const l = y, t = i.map((f) => E(f, s, p)).filter((f) => f).map((f) => m.indexOf(l) !== -1 ? `(${f})` : f);
t.length && (m.indexOf(l) !== -1 ? t.length && (l === "not" ? u.push(T(t)) : u.push(`(${t.join(` ${l} `)})`)) : u.push(t.join(` ${l} `)));
} else if (m.indexOf(c) !== -1) {
const l = c, t = Object.keys(i).map(
(f) => n({ [f]: i[f] })
);
t.length && (a === "not" ? s.push(T(t)) : s.push(`(${t.join(` ${a} `)})`));
t.length && (l === "not" ? u.push(T(t)) : u.push(`(${t.join(` ${l} `)})`));
} else if (typeof i == "object")
"type" in i ? s.push(C(f, i, u)) : Object.keys(i).forEach((t) => {
"type" in i ? u.push(C(c, i, s)) : Object.keys(i).forEach((t) => {
if (i[t] !== void 0)
if (S.indexOf(t) !== -1)
s.push(`${f} ${t} ${h(i[t], u)}`);
else if (w.indexOf(t) !== -1)
Array.isArray(i[t]) ? s.push(
i[t].map((c) => "(" + n(c, u, f) + ")").join(` ${t} `)
) : s.push("(" + n(i[t], u, f) + ")");
else if (L.indexOf(t) !== -1) {
const c = p(y.toLowerCase(), i[t], t, f);
c && s.push(c);
if (g.indexOf(t) !== -1)
u.push(`${c} ${t} ${b(i[t], s)}`);
else if (m.indexOf(t) !== -1)
Array.isArray(i[t]) ? u.push(
i[t].map((f) => "(" + n(f, s, c) + ")").join(` ${t} `)
) : u.push("(" + n(i[t], s, c) + ")");
else if (S.indexOf(t) !== -1) {
const f = a(y.toLowerCase(), i[t], t, c);
f && u.push(f);
} else if (t === "has")
s.push(`${f} ${t} ${h(i[t], u)}`);
u.push(`${c} ${t} ${b(i[t], s)}`);
else if (t === "in") {
const c = Array.isArray(i[t]) ? i[t] : i[t].value.map((d) => ({
const f = Array.isArray(i[t]) ? i[t] : i[t].value.map((j) => ({
type: i[t].type,
value: d
value: j
}));
s.push(
f + " in (" + c.map((d) => h(d, u)).join(",") + ")"
u.push(
c + " in (" + f.map((j) => b(j, s)).join(",") + ")"
);
} else if (g.indexOf(t) !== -1)
s.push(`${t}(${f},${h(i[t], u)})`);
} else if (k.indexOf(t) !== -1)
u.push(`${t}(${c},${b(i[t], s)})`);
else {
const c = n({ [t]: i[t] }, u, f);
c && s.push(c);
const f = n({ [t]: i[t] }, s, c);
f && u.push(f);
}

@@ -110,3 +110,3 @@ });

throw new Error(`Unexpected value type: ${i}`);
return s;
return u;
},

@@ -116,24 +116,23 @@ []

}
function p($, u, l, O) {
let b = "";
if (typeof u == "string" || u instanceof String)
b = U($, u, l, O);
else if (u) {
const s = Array.isArray(u) ? u.reduce((i, f) => f.hasOwnProperty(j) ? (i.hasOwnProperty(j) || (i[j] = []), i[j].push(f[j]), i) : { ...i, ...f }, {}) : u, y = n(s, o, $);
b = `${O}/${l}(${y ? `${$}:${y}` : ""})`;
function a($, s, p, O) {
let d = "";
if (typeof s == "string" || s instanceof String)
d = I($, s, p, O);
else if (s) {
const u = Array.isArray(s) ? s.reduce((i, c) => c.hasOwnProperty(h) ? (i.hasOwnProperty(h) || (i[h] = []), i[h].push(c[h]), i) : { ...i, ...c }, {}) : s, y = n(u, o, $);
d = `${O}/${p}(${y ? `${$}:${y}` : ""})`;
}
return b;
return d;
}
}
function U(e, o, r, n) {
let p = "";
const $ = r == "all" ? "ne" : "eq";
return p = `${n}/${r}(${e}: ${e} ${$} '${o}')`, p;
function I(e, o, r, n) {
const a = r == "all" ? "ne" : "eq";
return `${n}/${r}(${e}: ${e} ${a} '${o}')`;
}
function D(e) {
function U(e) {
return e = e.replace(/%/g, "%25"), e = e.replace(/\+/g, "%2B"), e = e.replace(/\//g, "%2F"), e = e.replace(/\?/g, "%3F"), e = e.replace(/#/g, "%23"), e = e.replace(/&/g, "%26"), e = e.replace(/'/g, "''"), e;
}
function h(e, o) {
function b(e, o) {
if (typeof e == "string")
return `'${D(e)}'`;
return `'${U(e)}'`;
if (e instanceof Date)

@@ -144,3 +143,3 @@ return e.toISOString();

if (Array.isArray(e))
return `[${e.map((r) => h(r)).join(",")}]`;
return `[${e.map((r) => b(r)).join(",")}]`;
if (e === null)

@@ -164,17 +163,17 @@ return e;

default:
return Object.entries(e).filter(([, r]) => r !== void 0).map(([r, n]) => `${r}=${h(n, o)}`).join(",");
return Object.entries(e).filter(([, r]) => r !== void 0).map(([r, n]) => `${r}=${b(n, o)}`).join(",");
}
return e;
}
function E(e) {
function w(e) {
if (typeof e == "number")
return e;
if (typeof e == "string")
return e.indexOf("/") === -1 ? e : e.split("/").reverse().reduce((o, r, n, p) => n === 0 ? `$expand=${r}` : n === p.length - 1 ? `${r}(${o})` : `$expand=${r}(${o})`, "");
return e.indexOf("/") === -1 ? e : e.split("/").reverse().reduce((o, r, n, a) => n === 0 ? `$expand=${r}` : n === a.length - 1 ? `${r}(${o})` : `$expand=${r}(${o})`, "");
if (Array.isArray(e))
return `${e.map((o) => E(o)).join(",")}`;
return `${e.map((o) => w(o)).join(",")}`;
if (typeof e == "object") {
const o = Object.keys(e);
return o.some(
(r) => q.indexOf(r.toLowerCase()) !== -1
(r) => L.indexOf(r.toLowerCase()) !== -1
) ? o.map((r) => {

@@ -184,3 +183,3 @@ let n;

case "filter":
n = m(e[r]);
n = E(e[r]);
break;

@@ -197,7 +196,7 @@ case "orderBy":

default:
n = E(e[r]);
n = w(e[r]);
}
return `$${r.toLowerCase()}=${n}`;
}).join(";") : o.map((r) => {
const n = E(e[r]);
const n = w(e[r]);
return n ? `${r}(${n})` : r;

@@ -209,26 +208,46 @@ }).join(",");

function _(e) {
return (Array.isArray(e) ? e : [e]).reduce((n, p) => {
const { aggregate: $, filter: u, groupBy: l, ...O } = p, b = Object.keys(O);
if (b.length)
throw new Error(`Unsupported transform(s): ${b}`);
if ($ && n.push(`aggregate(${V($)})`), u) {
const s = m(u);
s && n.push(`filter(${m(s)})`);
}
return l && n.push(`groupby(${k(l)})`), n;
return (Array.isArray(e) ? e : [e]).reduce((n, a) => {
for (const $ of Object.keys(a))
switch ($) {
// TODO: support as many of the following:
// topcount, topsum, toppercent,
// bottomsum, bottomcount, bottompercent,
// identity, concat, expand, search, compute, isdefined
case "aggregate": {
const s = a[$];
s && n.push(`aggregate(${D(s)})`);
break;
}
case "filter": {
const s = a[$];
if (s) {
const p = E(s);
p && n.push(`filter(${p})`);
}
break;
}
case "groupBy": {
const s = a[$];
s && n.push(`groupby(${V(s)})`);
break;
}
default:
throw new Error(`Unsupported transform: ${$}`);
}
return n;
}, []).join("/") || void 0;
}
function V(e) {
function D(e) {
return (Array.isArray(e) ? e : [e]).map((r) => typeof r == "string" ? r : Object.keys(r).map((n) => {
const p = r[n];
if (!p.with && p.as)
return `${n} as ${p.as}`;
if (!p.with)
const a = r[n];
if (!a.with && a.as)
return `${n} as ${a.as}`;
if (!a.with)
throw new Error(`'with' property required for '${n}'`);
if (!p.as)
if (!a.as)
throw new Error(`'as' property required for '${n}'`);
return `${n} with ${p.with} as ${p.as}`;
return `${n} with ${a.with} as ${a.as}`;
})).join(",");
}
function k(e) {
function V(e) {
if (!e.properties)

@@ -252,8 +271,8 @@ throw new Error("'properties' property required for groupBy");

export {
j as ITEM_ROOT,
I as StandardAggregateMethods,
H as alias,
h as ITEM_ROOT,
q as StandardAggregateMethods,
B as alias,
x as binary,
Q as decimal,
W as default,
H as decimal,
Q as default,
J as duration,

@@ -260,0 +279,0 @@ P as guid,

{
"name": "odata-query",
"description": "OData v4 query builder that uses a simple object-based syntax similar to MongoDB and js-data",
"version": "8.0.4",
"version": "8.0.5",
"author": "Sean Lynch <techniq35@gmail.com>",

@@ -6,0 +6,0 @@ "license": "MIT",