dtable-utils 0.0.1
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/README.md +20 -0
- package/dist/index.js +1 -0
- package/es/cell-value-get/cell-value.js +165 -0
- package/es/cell-value-get/collaborator.js +33 -0
- package/es/cell-value-get/date.js +53 -0
- package/es/cell-value-get/digital-sign.js +10 -0
- package/es/cell-value-get/duration.js +86 -0
- package/es/cell-value-get/geolocation.js +74 -0
- package/es/cell-value-get/long-text.js +11 -0
- package/es/cell-value-get/number.js +222 -0
- package/es/cell-value-get/option.js +32 -0
- package/es/cell-value-set/number.js +53 -0
- package/es/column/common.js +41 -0
- package/es/column/date.js +17 -0
- package/es/column/number.js +31 -0
- package/es/common.js +16 -0
- package/es/constants/cell-type.js +33 -0
- package/es/constants/column.js +45 -0
- package/es/constants/filter/filter-column-options.js +65 -0
- package/es/constants/filter/filter-is-within.js +6 -0
- package/es/constants/filter/filter-modifier.js +29 -0
- package/es/constants/filter/filter-predicate.js +33 -0
- package/es/constants/filter/index.js +16 -0
- package/es/constants/formula.js +14 -0
- package/es/constants/select-option.js +129 -0
- package/es/date.js +226 -0
- package/es/helper/number-precision/index.js +64 -0
- package/es/index.js +26 -0
- package/es/validate/email.js +10 -0
- package/es/validate/filter.js +447 -0
- package/lib/cell-value-get/cell-value.js +170 -0
- package/lib/cell-value-get/collaborator.js +38 -0
- package/lib/cell-value-get/date.js +61 -0
- package/lib/cell-value-get/digital-sign.js +14 -0
- package/lib/cell-value-get/duration.js +90 -0
- package/lib/cell-value-get/geolocation.js +78 -0
- package/lib/cell-value-get/long-text.js +15 -0
- package/lib/cell-value-get/number.js +227 -0
- package/lib/cell-value-get/option.js +37 -0
- package/lib/cell-value-set/number.js +58 -0
- package/lib/column/common.js +46 -0
- package/lib/column/date.js +21 -0
- package/lib/column/number.js +36 -0
- package/lib/common.js +20 -0
- package/lib/constants/cell-type.js +37 -0
- package/lib/constants/column.js +63 -0
- package/lib/constants/filter/filter-column-options.js +73 -0
- package/lib/constants/filter/filter-is-within.js +11 -0
- package/lib/constants/filter/filter-modifier.js +38 -0
- package/lib/constants/filter/filter-predicate.js +42 -0
- package/lib/constants/filter/index.js +27 -0
- package/lib/constants/formula.js +23 -0
- package/lib/constants/select-option.js +134 -0
- package/lib/date.js +235 -0
- package/lib/helper/number-precision/index.js +69 -0
- package/lib/index.js +79 -0
- package/lib/validate/email.js +14 -0
- package/lib/validate/filter.js +458 -0
- package/package.json +44 -0
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _typeof = require('@babel/runtime/helpers/typeof');
|
|
6
|
+
var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
|
|
7
|
+
var _createClass = require('@babel/runtime/helpers/createClass');
|
|
8
|
+
var cellType = require('../constants/cell-type.js');
|
|
9
|
+
var column = require('../constants/column.js');
|
|
10
|
+
var formula = require('../constants/formula.js');
|
|
11
|
+
var index = require('../constants/filter/index.js');
|
|
12
|
+
var common = require('../column/common.js');
|
|
13
|
+
var date = require('../column/date.js');
|
|
14
|
+
var filterPredicate = require('../constants/filter/filter-predicate.js');
|
|
15
|
+
var filterModifier = require('../constants/filter/filter-modifier.js');
|
|
16
|
+
var filterColumnOptions = require('../constants/filter/filter-column-options.js');
|
|
17
|
+
var filterIsWithin = require('../constants/filter/filter-is-within.js');
|
|
18
|
+
|
|
19
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
20
|
+
|
|
21
|
+
var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
|
|
22
|
+
var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallCheck);
|
|
23
|
+
var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass);
|
|
24
|
+
|
|
25
|
+
var TERM_TYPE_MAP = {
|
|
26
|
+
NUMBER: 'number',
|
|
27
|
+
STRING: 'string',
|
|
28
|
+
BOOLEAN: 'boolean',
|
|
29
|
+
ARRAY: 'array'
|
|
30
|
+
};
|
|
31
|
+
var TEXT_COLUMN_TYPES = [cellType.CellType.TEXT, cellType.CellType.STRING];
|
|
32
|
+
var CHECK_EMPTY_PREDICATES = [filterPredicate.FILTER_PREDICATE_TYPE.EMPTY, filterPredicate.FILTER_PREDICATE_TYPE.NOT_EMPTY];
|
|
33
|
+
var PREDICATES_REQUIRE_ARRAY_TERM = [filterPredicate.FILTER_PREDICATE_TYPE.IS_ANY_OF, filterPredicate.FILTER_PREDICATE_TYPE.IS_NONE_OF];
|
|
34
|
+
var DATE_MODIFIERS_REQUIRE_TERM = [filterModifier.FILTER_TERM_MODIFIER_TYPE.NUMBER_OF_DAYS_AGO, filterModifier.FILTER_TERM_MODIFIER_TYPE.NUMBER_OF_DAYS_FROM_NOW, filterModifier.FILTER_TERM_MODIFIER_TYPE.THE_NEXT_NUMBERS_OF_DAYS, filterModifier.FILTER_TERM_MODIFIER_TYPE.THE_PAST_NUMBERS_OF_DAYS, filterModifier.FILTER_TERM_MODIFIER_TYPE.EXACT_DATE];
|
|
35
|
+
var MODIFIERS_REQUIRE_NUMERIC_TERM = [filterModifier.FILTER_TERM_MODIFIER_TYPE.NUMBER_OF_DAYS_AGO, filterModifier.FILTER_TERM_MODIFIER_TYPE.NUMBER_OF_DAYS_FROM_NOW, filterModifier.FILTER_TERM_MODIFIER_TYPE.THE_NEXT_NUMBERS_OF_DAYS, filterModifier.FILTER_TERM_MODIFIER_TYPE.THE_PAST_NUMBERS_OF_DAYS];
|
|
36
|
+
var ValidateFilter = /*#__PURE__*/function () {
|
|
37
|
+
function ValidateFilter() {
|
|
38
|
+
_classCallCheck__default["default"](this, ValidateFilter);
|
|
39
|
+
}
|
|
40
|
+
_createClass__default["default"](ValidateFilter, null, [{
|
|
41
|
+
key: "validate",
|
|
42
|
+
value:
|
|
43
|
+
/**
|
|
44
|
+
* Check filter is valid. The error_message from returns will be null if the filter is valid.
|
|
45
|
+
* 1.incomplete filter which should be ignored
|
|
46
|
+
* - column_key: required
|
|
47
|
+
* - filter_predicate: required
|
|
48
|
+
* - filter_term_modifier: determined by the column to filter with
|
|
49
|
+
* - filter_term: determined by filter_predicate / the column to filter with
|
|
50
|
+
* 2.illegal filter
|
|
51
|
+
* - column missing: cannot find the column to filter
|
|
52
|
+
* - column not support: the column to filter is not support
|
|
53
|
+
* - mismatch: filter_predicate, filter_term_modifier mismatch
|
|
54
|
+
* - wrong data type: filter_term with wrong data type
|
|
55
|
+
* @param {object} filter e.g. { column_key, filter_term, ... }
|
|
56
|
+
* @param {array} columns e.g. [{ key, name, ... }, ...]
|
|
57
|
+
* @param {bool} isValidTerm No longer to validate filter term if false. default as false
|
|
58
|
+
* @returns { error_message }, object
|
|
59
|
+
*/
|
|
60
|
+
function validate(filter, columns) {
|
|
61
|
+
var isValidTerm = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
62
|
+
var column_key = filter.column_key,
|
|
63
|
+
filter_predicate = filter.filter_predicate,
|
|
64
|
+
filter_term_modifier = filter.filter_term_modifier,
|
|
65
|
+
filter_term = filter.filter_term;
|
|
66
|
+
var _this$validateColumn = this.validateColumn(column_key, columns),
|
|
67
|
+
column_error_message = _this$validateColumn.error_message;
|
|
68
|
+
if (column_error_message) {
|
|
69
|
+
return {
|
|
70
|
+
error_message: column_error_message
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
var filterColumn = columns.find(function (column) {
|
|
74
|
+
return column.key === column_key;
|
|
75
|
+
});
|
|
76
|
+
var _this$validatePredica = this.validatePredicate(filter_predicate, filterColumn),
|
|
77
|
+
predicate_error_message = _this$validatePredica.error_message;
|
|
78
|
+
if (predicate_error_message) {
|
|
79
|
+
return {
|
|
80
|
+
error_message: predicate_error_message
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
if (this.isFilterOnlyWithPredicate(filter_predicate, filterColumn)) {
|
|
84
|
+
return {
|
|
85
|
+
error_message: null
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
var _this$validateModifie = this.validateModifier(filter_term_modifier, filter_predicate, filterColumn),
|
|
89
|
+
modifier_error_message = _this$validateModifie.error_message;
|
|
90
|
+
if (modifier_error_message) {
|
|
91
|
+
return {
|
|
92
|
+
error_message: modifier_error_message
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
if (this.isFilterOnlyWithModifier(filter_term_modifier, filterColumn)) {
|
|
96
|
+
return {
|
|
97
|
+
error_message: null
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
if (isValidTerm) {
|
|
101
|
+
var _this$validateTerm = this.validateTerm(filter_term, filter_predicate, filter_term_modifier, filterColumn),
|
|
102
|
+
term_error_message = _this$validateTerm.error_message;
|
|
103
|
+
if (term_error_message) {
|
|
104
|
+
return {
|
|
105
|
+
error_message: term_error_message
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
error_message: null
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}, {
|
|
114
|
+
key: "validateColumn",
|
|
115
|
+
value: function validateColumn(column_key, columns) {
|
|
116
|
+
if (!column_key) {
|
|
117
|
+
return {
|
|
118
|
+
error_message: index.FILTER_ERR_MSG.INCOMPLETE_FILTER
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
var filterColumn = columns.find(function (column) {
|
|
122
|
+
return column.key === column_key;
|
|
123
|
+
});
|
|
124
|
+
if (!filterColumn) {
|
|
125
|
+
return {
|
|
126
|
+
error_message: index.FILTER_ERR_MSG.COLUMN_MISSING
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
if (!this.isValidColumnType(filterColumn)) {
|
|
130
|
+
return {
|
|
131
|
+
error_message: index.FILTER_ERR_MSG.COLUMN_NOT_SUPPORTED
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
error_message: null
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* the column to filter must be available
|
|
141
|
+
*/
|
|
142
|
+
}, {
|
|
143
|
+
key: "validatePredicate",
|
|
144
|
+
value: function validatePredicate(predicate, filterColumn) {
|
|
145
|
+
if (!predicate) {
|
|
146
|
+
return {
|
|
147
|
+
error_message: index.FILTER_ERR_MSG.INCOMPLETE_FILTER
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
var columnType = filterColumn.type,
|
|
151
|
+
data = filterColumn.data;
|
|
152
|
+
var filterConfigs = filterColumnOptions.FILTER_COLUMN_OPTIONS[columnType];
|
|
153
|
+
var predicateList = filterConfigs.filterPredicateList;
|
|
154
|
+
if (formula.FORMULA_COLUMN_TYPES_MAP[columnType] || columnType === cellType.CellType.LINK) {
|
|
155
|
+
var result_type = data.result_type;
|
|
156
|
+
if (result_type === formula.FORMULA_RESULT_TYPE.ARRAY) {
|
|
157
|
+
return this.validatePredicateWithArrayType(predicate, filterColumn);
|
|
158
|
+
}
|
|
159
|
+
return this.validatePredicate(predicate, {
|
|
160
|
+
type: result_type
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
if (!predicateList.includes(predicate)) {
|
|
164
|
+
return {
|
|
165
|
+
error_message: index.FILTER_ERR_MSG.UNMATCHED_PREDICATE
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
error_message: null
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
}, {
|
|
173
|
+
key: "validatePredicateWithArrayType",
|
|
174
|
+
value: function validatePredicateWithArrayType(predicate, filterColumn) {
|
|
175
|
+
var data = filterColumn.data;
|
|
176
|
+
var array_type = data.array_type;
|
|
177
|
+
if (array_type === cellType.CellType.SINGLE_SELECT) {
|
|
178
|
+
return this.validatePredicate(predicate, {
|
|
179
|
+
type: cellType.CellType.MULTIPLE_SELECT
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
if (column.COLLABORATOR_COLUMN_TYPES.includes(array_type)) {
|
|
183
|
+
return this.validatePredicate(predicate, {
|
|
184
|
+
type: cellType.CellType.COLLABORATOR
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
return this.validatePredicate(predicate, {
|
|
188
|
+
type: array_type
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* filter predicate must be available.
|
|
194
|
+
* filterColumn the column to filter must be available
|
|
195
|
+
*/
|
|
196
|
+
}, {
|
|
197
|
+
key: "isFilterOnlyWithPredicate",
|
|
198
|
+
value: function isFilterOnlyWithPredicate(predicate, filterColumn) {
|
|
199
|
+
if (CHECK_EMPTY_PREDICATES.includes(predicate)) {
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
var columnType = filterColumn.type,
|
|
203
|
+
data = filterColumn.data;
|
|
204
|
+
if (formula.FORMULA_COLUMN_TYPES_MAP[columnType] || columnType === cellType.CellType.LINK) {
|
|
205
|
+
var result_type = data.result_type,
|
|
206
|
+
array_type = data.array_type;
|
|
207
|
+
if (result_type === formula.FORMULA_RESULT_TYPE.ARRAY) {
|
|
208
|
+
return this.isFilterOnlyWithPredicate(predicate, {
|
|
209
|
+
type: array_type
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
return this.isFilterOnlyWithPredicate(predicate, {
|
|
213
|
+
type: result_type
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
var IS_CURRENT_USER_ID = filterPredicate.FILTER_PREDICATE_TYPE.IS_CURRENT_USER_ID,
|
|
217
|
+
INCLUDE_ME = filterPredicate.FILTER_PREDICATE_TYPE.INCLUDE_ME;
|
|
218
|
+
if (predicate === IS_CURRENT_USER_ID && TEXT_COLUMN_TYPES.includes(columnType)) {
|
|
219
|
+
return true;
|
|
220
|
+
}
|
|
221
|
+
if (predicate === INCLUDE_ME && column.COLLABORATOR_COLUMN_TYPES.includes(columnType)) {
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* filter predicate must be available.
|
|
229
|
+
* the column to filter must be available
|
|
230
|
+
*/
|
|
231
|
+
}, {
|
|
232
|
+
key: "validateModifier",
|
|
233
|
+
value: function validateModifier(modifier, predicate, filterColumn) {
|
|
234
|
+
if (!date.isDateColumn(filterColumn)) {
|
|
235
|
+
return {
|
|
236
|
+
error_message: null
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
if (!modifier) {
|
|
240
|
+
return {
|
|
241
|
+
error_message: index.FILTER_ERR_MSG.INCOMPLETE_FILTER
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
if (predicate === filterPredicate.FILTER_PREDICATE_TYPE.IS_WITHIN) {
|
|
245
|
+
if (filterIsWithin.filterTermModifierIsWithin.includes(modifier)) {
|
|
246
|
+
return {
|
|
247
|
+
error_message: null
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
} else if (filterIsWithin.filterTermModifierNotWithin.includes(modifier)) {
|
|
251
|
+
return {
|
|
252
|
+
error_message: null
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
return {
|
|
256
|
+
error_message: index.FILTER_ERR_MSG.UNMATCHED_MODIFIER
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* filter predicate must be available.
|
|
262
|
+
* filter modifier must be available.
|
|
263
|
+
* the column to filter must be available
|
|
264
|
+
*/
|
|
265
|
+
}, {
|
|
266
|
+
key: "isFilterOnlyWithModifier",
|
|
267
|
+
value: function isFilterOnlyWithModifier(modifier, filterColumn) {
|
|
268
|
+
if (date.isDateColumn(filterColumn)) {
|
|
269
|
+
return !DATE_MODIFIERS_REQUIRE_TERM.includes(modifier);
|
|
270
|
+
}
|
|
271
|
+
return false;
|
|
272
|
+
}
|
|
273
|
+
}, {
|
|
274
|
+
key: "validateTerm",
|
|
275
|
+
value: function validateTerm(term, predicate, modifier, filterColumn) {
|
|
276
|
+
if (this.isTermMissing(term)) {
|
|
277
|
+
return {
|
|
278
|
+
error_message: index.FILTER_ERR_MSG.INCOMPLETE_FILTER
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
if (!this.isValidTerm(term, predicate, modifier, filterColumn)) {
|
|
282
|
+
return {
|
|
283
|
+
error_message: index.FILTER_ERR_MSG.INVALID_TERM
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
return {
|
|
287
|
+
error_message: null
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
}, {
|
|
291
|
+
key: "isTermMissing",
|
|
292
|
+
value: function isTermMissing(term) {
|
|
293
|
+
return !term && term !== 0 && term !== false || Array.isArray(term) && term.length === 0;
|
|
294
|
+
}
|
|
295
|
+
}, {
|
|
296
|
+
key: "isValidTerm",
|
|
297
|
+
value: function isValidTerm(term, predicate, modifier, filterColumn) {
|
|
298
|
+
switch (filterColumn.type) {
|
|
299
|
+
case cellType.CellType.TEXT:
|
|
300
|
+
case cellType.CellType.GEOLOCATION:
|
|
301
|
+
case cellType.CellType.AUTO_NUMBER:
|
|
302
|
+
case cellType.CellType.EMAIL:
|
|
303
|
+
case cellType.CellType.URL:
|
|
304
|
+
case cellType.CellType.STRING:
|
|
305
|
+
{
|
|
306
|
+
return this.isValidTermType(term, TERM_TYPE_MAP.STRING);
|
|
307
|
+
}
|
|
308
|
+
case cellType.CellType.SINGLE_SELECT:
|
|
309
|
+
{
|
|
310
|
+
var options = common.getColumnOptions(filterColumn);
|
|
311
|
+
if (PREDICATES_REQUIRE_ARRAY_TERM.includes(predicate)) {
|
|
312
|
+
if (!this.isValidTermType(term, TERM_TYPE_MAP.ARRAY)) {
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// contains deleted option(s)
|
|
317
|
+
return this.isValidSelectedOptions(term, options);
|
|
318
|
+
}
|
|
319
|
+
if (!this.isValidTermType(term, TERM_TYPE_MAP.STRING)) {
|
|
320
|
+
return false;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// invalid filter_term if selected option is deleted
|
|
324
|
+
return !!options.find(function (option) {
|
|
325
|
+
return term === option.id;
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
case cellType.CellType.NUMBER:
|
|
329
|
+
case cellType.CellType.DURATION:
|
|
330
|
+
case cellType.CellType.RATE:
|
|
331
|
+
{
|
|
332
|
+
return this.isValidTermType(term, TERM_TYPE_MAP.NUMBER);
|
|
333
|
+
}
|
|
334
|
+
case cellType.CellType.CHECKBOX:
|
|
335
|
+
case cellType.CellType.BOOL:
|
|
336
|
+
{
|
|
337
|
+
return this.isValidTermType(term, TERM_TYPE_MAP.BOOLEAN);
|
|
338
|
+
}
|
|
339
|
+
case cellType.CellType.COLLABORATOR:
|
|
340
|
+
case cellType.CellType.CREATOR:
|
|
341
|
+
case cellType.CellType.LAST_MODIFIER:
|
|
342
|
+
{
|
|
343
|
+
return this.isValidTermType(term, TERM_TYPE_MAP.ARRAY);
|
|
344
|
+
}
|
|
345
|
+
case cellType.CellType.MULTIPLE_SELECT:
|
|
346
|
+
{
|
|
347
|
+
if (!this.isValidTermType(term, TERM_TYPE_MAP.ARRAY)) {
|
|
348
|
+
return false;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// contains deleted option(s)
|
|
352
|
+
var _options = common.getColumnOptions(filterColumn);
|
|
353
|
+
return this.isValidSelectedOptions(term, _options);
|
|
354
|
+
}
|
|
355
|
+
case cellType.CellType.DATE:
|
|
356
|
+
case cellType.CellType.CTIME:
|
|
357
|
+
case cellType.CellType.MTIME:
|
|
358
|
+
{
|
|
359
|
+
if (MODIFIERS_REQUIRE_NUMERIC_TERM.includes(modifier)) {
|
|
360
|
+
return this.isValidTermType(term, TERM_TYPE_MAP.NUMBER);
|
|
361
|
+
}
|
|
362
|
+
return this.isValidTermType(term, TERM_TYPE_MAP.STRING);
|
|
363
|
+
}
|
|
364
|
+
case cellType.CellType.FORMULA:
|
|
365
|
+
case cellType.CellType.LINK_FORMULA:
|
|
366
|
+
{
|
|
367
|
+
var data = filterColumn.data;
|
|
368
|
+
var result_type = data.result_type;
|
|
369
|
+
if (result_type === formula.FORMULA_RESULT_TYPE.ARRAY) {
|
|
370
|
+
return this.isValidTermWithArrayType(term, predicate, modifier, filterColumn);
|
|
371
|
+
}
|
|
372
|
+
return this.isValidTerm(term, predicate, modifier, {
|
|
373
|
+
type: result_type
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
case cellType.CellType.LINK:
|
|
377
|
+
{
|
|
378
|
+
return this.isValidTermWithArrayType(term, predicate, modifier, filterColumn);
|
|
379
|
+
}
|
|
380
|
+
default:
|
|
381
|
+
{
|
|
382
|
+
return false;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}, {
|
|
387
|
+
key: "isValidTermType",
|
|
388
|
+
value: function isValidTermType(term, type) {
|
|
389
|
+
if (type === TERM_TYPE_MAP.ARRAY) {
|
|
390
|
+
return Array.isArray(term) && term.length > 0;
|
|
391
|
+
}
|
|
392
|
+
if (type === cellType.CellType.NUMBER) {
|
|
393
|
+
// is a number or a number string
|
|
394
|
+
// eslint-disable-next-line
|
|
395
|
+
return _typeof__default["default"](term) === type || !isNaN(Number(term));
|
|
396
|
+
}
|
|
397
|
+
// eslint-disable-next-line
|
|
398
|
+
return _typeof__default["default"](term) === type;
|
|
399
|
+
}
|
|
400
|
+
}, {
|
|
401
|
+
key: "isValidTermWithArrayType",
|
|
402
|
+
value: function isValidTermWithArrayType(term, predicate, modifier, filterColumn) {
|
|
403
|
+
var data = filterColumn.data;
|
|
404
|
+
var array_type = data.array_type,
|
|
405
|
+
array_data = data.array_data;
|
|
406
|
+
if (array_type === cellType.CellType.SINGLE_SELECT) {
|
|
407
|
+
return this.isValidTerm(term, predicate, modifier, {
|
|
408
|
+
type: cellType.CellType.MULTIPLE_SELECT,
|
|
409
|
+
data: array_data
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
if (column.COLLABORATOR_COLUMN_TYPES.includes(array_type)) {
|
|
413
|
+
return this.isValidTerm(term, predicate, modifier, {
|
|
414
|
+
type: cellType.CellType.COLLABORATOR
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
return this.isValidTerm(term, predicate, modifier, {
|
|
418
|
+
type: array_type,
|
|
419
|
+
data: array_data
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
}, {
|
|
423
|
+
key: "isValidColumnType",
|
|
424
|
+
value: function isValidColumnType(filterColumn) {
|
|
425
|
+
var columnType = filterColumn.type,
|
|
426
|
+
data = filterColumn.data;
|
|
427
|
+
if (formula.FORMULA_COLUMN_TYPES_MAP[columnType] || columnType === cellType.CellType.LINK) {
|
|
428
|
+
if (!data) {
|
|
429
|
+
return false;
|
|
430
|
+
}
|
|
431
|
+
var result_type = data.result_type,
|
|
432
|
+
array_type = data.array_type;
|
|
433
|
+
if (result_type === formula.FORMULA_RESULT_TYPE.ARRAY) {
|
|
434
|
+
return this.isValidColumnType({
|
|
435
|
+
type: array_type
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
return this.isValidColumnType({
|
|
439
|
+
type: result_type
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
// eslint-disable-next-line
|
|
443
|
+
return filterColumnOptions.FILTER_COLUMN_OPTIONS.hasOwnProperty(columnType);
|
|
444
|
+
}
|
|
445
|
+
}, {
|
|
446
|
+
key: "isValidSelectedOptions",
|
|
447
|
+
value: function isValidSelectedOptions(selectedOptionIds, options) {
|
|
448
|
+
var validSelectedOptions = options.filter(function (option) {
|
|
449
|
+
return selectedOptionIds.includes(option.id);
|
|
450
|
+
});
|
|
451
|
+
return selectedOptionIds.length === validSelectedOptions.length;
|
|
452
|
+
}
|
|
453
|
+
}]);
|
|
454
|
+
return ValidateFilter;
|
|
455
|
+
}();
|
|
456
|
+
|
|
457
|
+
exports.DATE_MODIFIERS_REQUIRE_TERM = DATE_MODIFIERS_REQUIRE_TERM;
|
|
458
|
+
exports.ValidateFilter = ValidateFilter;
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "dtable-utils",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "dtable common utils",
|
|
5
|
+
"main": "./lib/index.js",
|
|
6
|
+
"module": "./es/index.js",
|
|
7
|
+
"private": false,
|
|
8
|
+
"scripts": {
|
|
9
|
+
"test": "jest -c --watchAll",
|
|
10
|
+
"eslint": "eslint ./src/**",
|
|
11
|
+
"build": "rm -rf dist lib es && rollup -c",
|
|
12
|
+
"prepublishOnly": "npm run build"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"utils",
|
|
16
|
+
"JavaScript"
|
|
17
|
+
],
|
|
18
|
+
"author": "SeaTable",
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"lib",
|
|
22
|
+
"es",
|
|
23
|
+
"package.json"
|
|
24
|
+
],
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"dayjs": "1.10.7"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@babel/core": "^7.22.5",
|
|
30
|
+
"@babel/plugin-transform-runtime": "^7.22.5",
|
|
31
|
+
"@babel/preset-env": "^7.22.5",
|
|
32
|
+
"@rollup/plugin-babel": "^6.0.3",
|
|
33
|
+
"@rollup/plugin-commonjs": "^25.0.2",
|
|
34
|
+
"@rollup/plugin-eslint": "^9.0.4",
|
|
35
|
+
"@rollup/plugin-json": "^6.0.0",
|
|
36
|
+
"@rollup/plugin-node-resolve": "^15.1.0",
|
|
37
|
+
"@rollup/plugin-terser": "^0.4.3",
|
|
38
|
+
"babel-jest": "^29.5.0",
|
|
39
|
+
"eslint": "^8.43.0",
|
|
40
|
+
"eslint-config-airbnb": "^19.0.4",
|
|
41
|
+
"jest": "^29.5.0",
|
|
42
|
+
"rollup": "2.79.1"
|
|
43
|
+
}
|
|
44
|
+
}
|