tablevu 0.1.4 → 0.2.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/LICENSE +21 -21
- package/README.md +119 -29
- package/dist/array.js +1 -0
- package/dist/get.js +1 -0
- package/dist/odata.js +1 -1
- package/dist/table.js +1 -1
- package/dist/webapi.js +1 -1
- package/index.js +5 -5
- package/package.json +35 -35
- package/src/array.js +42 -0
- package/src/get.js +29 -0
- package/src/odata.js +141 -106
- package/src/table.js +580 -382
- package/src/webapi.js +33 -31
package/src/odata.js
CHANGED
|
@@ -1,106 +1,141 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
1
|
+
import get from './get.js';
|
|
2
|
+
|
|
3
|
+
function filter(q) {
|
|
4
|
+
|
|
5
|
+
function fuval(q) {
|
|
6
|
+
if (q === null) {
|
|
7
|
+
return 'null'
|
|
8
|
+
} else if (typeof(q) === 'string') {
|
|
9
|
+
if (q.length == 10 && q[4] == '-' && q[7] == '-' && Date.parse(q)) { // input date return iso string
|
|
10
|
+
return q;
|
|
11
|
+
} else
|
|
12
|
+
return '\'' + q + '\'';
|
|
13
|
+
} else {
|
|
14
|
+
if (typeof(q) === 'number')
|
|
15
|
+
return q;
|
|
16
|
+
else {
|
|
17
|
+
if (q.getMonth && typeof q.getMonth === "function")
|
|
18
|
+
return q.toISOString()
|
|
19
|
+
else
|
|
20
|
+
return q.func + '(' + q.params.join(',') + ')';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let s = '';
|
|
26
|
+
|
|
27
|
+
if (q && q.filters)
|
|
28
|
+
for (let i = 0; i < q.filters.length; i++) {
|
|
29
|
+
if (i > 0)
|
|
30
|
+
s = s + ` ${q.type || 'and'} `;
|
|
31
|
+
|
|
32
|
+
if (q.filters[i].column) {
|
|
33
|
+
if (q.filters[i].operator == 'in')
|
|
34
|
+
s = s + fuval(q.filters[i].value) + ' ' + q.filters[i].operator + ' ' + q.filters[i].column;
|
|
35
|
+
else
|
|
36
|
+
s = s + q.filters[i].column + ' ' + q.filters[i].operator + ' ' + fuval(q.filters[i].value);
|
|
37
|
+
} else {
|
|
38
|
+
if (q.filters[i].func)
|
|
39
|
+
s = s + q.filters[i].func + '(' + q.filters[i].params.map(m => fuval(m)).join(',') + ')';
|
|
40
|
+
else
|
|
41
|
+
if (q.filters[i])
|
|
42
|
+
s = s + '(' + filter(q.filters[i]) + ')';
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return s;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function sefs(url, query, seperator) {
|
|
50
|
+
let r = '';
|
|
51
|
+
|
|
52
|
+
if (query.select && query.select.length > 0) {
|
|
53
|
+
if (seperator)
|
|
54
|
+
r += '$select=' + query.select.join(',');
|
|
55
|
+
else
|
|
56
|
+
url.searchParams.append('$select', query.select.join(','));
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
if (query.expand && query.expand.length > 0) {
|
|
60
|
+
let a = [];
|
|
61
|
+
|
|
62
|
+
query.expand.forEach(e => {
|
|
63
|
+
let q = sefs(null, e, ';');
|
|
64
|
+
|
|
65
|
+
if (q)
|
|
66
|
+
a.push(e.name + '(' + q + ')');
|
|
67
|
+
else
|
|
68
|
+
a.push(e.name);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
if (seperator)
|
|
72
|
+
r += (r.length > 0 ? seperator: '') + '$expand=' + a.join(',');
|
|
73
|
+
else
|
|
74
|
+
url.searchParams.append('$expand', a.join(','));
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
return r;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export default class odata {
|
|
81
|
+
constructor(req, data, events) {
|
|
82
|
+
this.adapter = (props) => {
|
|
83
|
+
const u = new URL(req.url);
|
|
84
|
+
|
|
85
|
+
// Paging //
|
|
86
|
+
if (props.pageSize) {
|
|
87
|
+
u.searchParams.append('$skip', props.pageSize * (props.currPage - 1));
|
|
88
|
+
u.searchParams.append('$top', props.pageSize);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
sefs(u, data);
|
|
92
|
+
/*
|
|
93
|
+
// Select //
|
|
94
|
+
if (data.select && data.select.length > 0)
|
|
95
|
+
u.searchParams.append('$select', data.select.join(','));
|
|
96
|
+
|
|
97
|
+
// Expand //
|
|
98
|
+
if (data.expand && data.expand.length > 0) {
|
|
99
|
+
const a =
|
|
100
|
+
u.searchParams.append('$expand', data.expand.map(m => m.name + ((m.select && m.select.length > 0) ? '($select=' + m.select.join(',') + ')' : '')).join(','));
|
|
101
|
+
}*/
|
|
102
|
+
// Filter //
|
|
103
|
+
let f = [];
|
|
104
|
+
|
|
105
|
+
if (props.filter && Object.prototype.hasOwnProperty.call(props.filter, 'filters')) {
|
|
106
|
+
let l = filter(props.filter);
|
|
107
|
+
if (l)
|
|
108
|
+
f.push(l);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (props.filter) {
|
|
112
|
+
let l = filter(props.filter);
|
|
113
|
+
if (l)
|
|
114
|
+
f.push(l);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Search //
|
|
118
|
+
if (props.search) {
|
|
119
|
+
let l = props.cols.filter(q => q.searchable == undefined || q.searchable == true).map(q => "contains(" + q.name.replaceAll('.', '/') + ",'" + props.search + "')").join(" or ");
|
|
120
|
+
|
|
121
|
+
if (l)
|
|
122
|
+
f.push('(' + l + ')');
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (f && f.length > 0)
|
|
126
|
+
u.searchParams.append('$filter', f.join(' and '));
|
|
127
|
+
|
|
128
|
+
// Sort //
|
|
129
|
+
if (props.sort && props.sort.length > 0)
|
|
130
|
+
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
|
+
|
|
132
|
+
let r = null;
|
|
133
|
+
if (events.onfetch && typeof events.onfetch == 'function')
|
|
134
|
+
r = events.onfetch(new Request(u, req))
|
|
135
|
+
else
|
|
136
|
+
r = new Request(u, req);
|
|
137
|
+
|
|
138
|
+
return get(r);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|