tablevu 0.2.9 → 0.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/odata.js +1 -1
- package/package.json +1 -1
- package/src/odata.js +3 -4
package/dist/odata.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import get from"./get.js";function filter(q){function fuval(q){if(q===null){return"null"}else if(typeof q==="string"){if(q.length==10&&q[4]=="-"&&q[7]=="-"&&Date.parse(q)){return q}else return"'"+q+"'"}else{if(typeof q==="number")return q;else{if(q.getMonth&&typeof q.getMonth==="function")return q.toISOString();else return q.func+"("+q.params.join(",")+")"}}}let s="";if(q&&q.filters)for(let i=0;i<q.filters.length;i++){if(i>0)s=s+` ${q.type||"and"} `;if(q.filters[i].column){if(q.filters[i].operator=="in")s=s+fuval(q.filters[i].value)+" "+q.filters[i].operator+" "+q.filters[i].column;else s=s+q.filters[i].column+" "+q.filters[i].operator+" "+fuval(q.filters[i].value)}else{if(q.filters[i].func)s=s+q.filters[i].func+"("+q.filters[i].params.map(m=>fuval(m)).join(",")+")";else if(q.filters[i])s=s+"("+filter(q.filters[i])+")"}}return s}function sefs(url,query,seperator){let r="";if(query.select&&query.select.length>0){if(seperator)r+="$select="+query.select.join(",");else url.searchParams.append("$select",query.select.join(","))}if(query.expand&&query.expand.length>0){let a=[];query.expand.forEach(e=>{let q=sefs(null,e,";");if(q)a.push(e.name+"("+q+")");else a.push(e.name)});if(seperator)r+=(r.length>0?seperator:"")+"$expand="+a.join(",");else url.searchParams.append("$expand",a.join(","))}return r}export default class odata{constructor(req,data,events){this.adapter=props=>{const u=new URL(req.url);if(props.pageSize){u.searchParams.append("$skip",props.pageSize*(props.currPage-1));u.searchParams.append("$top",props.pageSize)}sefs(u,data);let f=[];if(props.filter&&Object.prototype.hasOwnProperty.call(props.filter,"filters")){let l=filter(props.filter);if(l)f.push(l)}if(props.filter){let l=filter(props.filter);if(l)f.push(l)}if(props.search){let l=props.cols.filter(q=>q.searchable==undefined||q.searchable==true).map(q=>"contains("+q.name.replaceAll(".","/")+",'"+props.search+"')").join(" or ");if(l)f.push("("+l+")")}if(f&&f.length>0)u.searchParams.append("$filter",f.join(" and "));if(props.sort&&props.sort.length>0)u.searchParams.append("$orderby",props.sort.map(m=>{let n={index:-1,name:"",dir:null};if(Object.prototype.hasOwnProperty.call(m,"index")){n.index=m.index}else{n.name=m.name}n.dir=m.dir;return n}).map(m=>{return(m.index>-1?props.cols[m.index].name:m.name).replaceAll(".","/")+(m.dir?" "+m.dir:"")}).join(","));
|
|
1
|
+
import get from"./get.js";function filter(q){function fuval(q){if(q===null){return"null"}else if(typeof q==="string"){if(q.length==10&&q[4]=="-"&&q[7]=="-"&&Date.parse(q)){return q}else return"'"+q+"'"}else{if(typeof q==="number")return q;else{if(q.getMonth&&typeof q.getMonth==="function")return q.toISOString();else return q.func+"("+q.params.join(",")+")"}}}let s="";if(q&&q.filters)for(let i=0;i<q.filters.length;i++){if(i>0)s=s+` ${q.type||"and"} `;if(q.filters[i].column){if(q.filters[i].operator=="in")s=s+fuval(q.filters[i].value)+" "+q.filters[i].operator+" "+q.filters[i].column;else s=s+q.filters[i].column+" "+q.filters[i].operator+" "+fuval(q.filters[i].value)}else{if(q.filters[i].func)s=s+q.filters[i].func+"("+q.filters[i].params.map(m=>fuval(m)).join(",")+")";else if(q.filters[i])s=s+"("+filter(q.filters[i])+")"}}return s}function sefs(url,query,seperator){let r="";if(query.select&&query.select.length>0){if(seperator)r+="$select="+query.select.join(",");else url.searchParams.append("$select",query.select.join(","))}if(query.expand&&query.expand.length>0){let a=[];query.expand.forEach(e=>{let q=sefs(null,e,";");if(q)a.push(e.name+"("+q+")");else a.push(e.name)});if(seperator)r+=(r.length>0?seperator:"")+"$expand="+a.join(",");else url.searchParams.append("$expand",a.join(","))}if(query.count)url.searchParams.append("$count",true);return r}export default class odata{constructor(req,data,events){this.adapter=props=>{const u=new URL(req.url);if(props.pageSize){u.searchParams.append("$skip",props.pageSize*(props.currPage-1));u.searchParams.append("$top",props.pageSize)}sefs(u,data);let f=[];if(props.filter&&Object.prototype.hasOwnProperty.call(props.filter,"filters")){let l=filter(props.filter);if(l)f.push(l)}if(props.filter){let l=filter(props.filter);if(l)f.push(l)}if(props.search){let l=props.cols.filter(q=>q.searchable==undefined||q.searchable==true).map(q=>"contains("+q.name.replaceAll(".","/")+",'"+props.search+"')").join(" or ");if(l)f.push("("+l+")")}if(f&&f.length>0)u.searchParams.append("$filter",f.join(" and "));if(props.sort&&props.sort.length>0)u.searchParams.append("$orderby",props.sort.map(m=>{let n={index:-1,name:"",dir:null};if(Object.prototype.hasOwnProperty.call(m,"index")){n.index=m.index}else{n.name=m.name}n.dir=m.dir;return n}).map(m=>{return(m.index>-1?props.cols[m.index].name:m.name).replaceAll(".","/")+(m.dir?" "+m.dir:"")}).join(","));let r=null;if(events&&events.onfetch&&typeof events.onfetch=="function")r=events.onfetch(new Request(u,req));else r=new Request(u,req);return get(r)}}}
|
package/package.json
CHANGED
package/src/odata.js
CHANGED
|
@@ -74,6 +74,9 @@ function sefs(url, query, seperator) {
|
|
|
74
74
|
url.searchParams.append('$expand', a.join(','));
|
|
75
75
|
};
|
|
76
76
|
|
|
77
|
+
if (query.count)
|
|
78
|
+
url.searchParams.append('$count', true);
|
|
79
|
+
|
|
77
80
|
return r;
|
|
78
81
|
}
|
|
79
82
|
|
|
@@ -129,10 +132,6 @@ export default class odata {
|
|
|
129
132
|
if (props.sort && props.sort.length > 0)
|
|
130
133
|
u.searchParams.append('$orderby', props.sort.map(m => { let n = { index: -1, name: '', dir: null }; if (Object.prototype.hasOwnProperty.call(m, 'index')) { n.index = m.index } else { n.name = m.name }; n.dir = m.dir; return n; }).map(m => { return (m.index > -1 ? props.cols[m.index].name : m.name).replaceAll('.', '/') + (m.dir ? (' ' + m.dir): '') }).join(','));
|
|
131
134
|
|
|
132
|
-
// Count //
|
|
133
|
-
if (props.count)
|
|
134
|
-
u.searchParams.append('$count', true);
|
|
135
|
-
|
|
136
135
|
let r = null;
|
|
137
136
|
if (events && events.onfetch && typeof events.onfetch == 'function')
|
|
138
137
|
r = events.onfetch(new Request(u, req))
|