@byteluck-fe/model-driven-engine 2.7.0-alpha.0 → 2.7.0-alpha.2
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/esm/common/ActionManager.js +154 -72
- package/dist/esm/common/DataManager.js +128 -60
- package/dist/esm/common/Engine.js +1060 -1111
- package/dist/esm/common/OkWorker.js +75 -106
- package/dist/esm/common/Runtime.js +27 -29
- package/dist/esm/common/Store.js +149 -181
- package/dist/esm/common/checkerValue.js +253 -328
- package/dist/esm/common/index.js +2 -2
- package/dist/esm/common/proxyState.js +47 -47
- package/dist/esm/index.js +3 -3
- package/dist/esm/plugins/CalcPlugin.js +306 -382
- package/dist/esm/plugins/ControlsEventPlugin.js +225 -141
- package/dist/esm/plugins/ES6ModulePlugin.js +38 -56
- package/dist/esm/plugins/LifecycleEventPlugin.js +190 -107
- package/dist/esm/plugins/StylePlugin.js +13 -31
- package/dist/esm/plugins/index.js +5 -5
- package/dist/esm/utils/index.js +1 -1
- package/dist/esm/utils/runtimeUtils.js +5 -7
- package/dist/index.umd.js +9 -9
- package/dist/types/common/Engine.d.ts +6 -6
- package/dist/types/common/Runtime.d.ts +1 -1
- package/dist/types/common/Store.d.ts +5 -5
- package/dist/types/common/proxyState.d.ts +3 -3
- package/dist/types/plugins/ControlsEventPlugin.d.ts +1 -1
- package/dist/types/plugins/ES6ModulePlugin.d.ts +4 -4
- package/dist/types/plugins/LifecycleEventPlugin.d.ts +1 -1
- package/dist/types/plugins/StylePlugin.d.ts +1 -1
- package/package.json +4 -4
|
@@ -17,20 +17,6 @@ function _classCallCheck(instance, Constructor) {
|
|
|
17
17
|
throw new TypeError("Cannot call a class as a function");
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
function _defineProperties(target, props) {
|
|
21
|
-
for(var i = 0; i < props.length; i++){
|
|
22
|
-
var descriptor = props[i];
|
|
23
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
24
|
-
descriptor.configurable = true;
|
|
25
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
26
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
function _createClass(Constructor, protoProps, staticProps) {
|
|
30
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
31
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
32
|
-
return Constructor;
|
|
33
|
-
}
|
|
34
20
|
function _defineProperty(obj, key, value) {
|
|
35
21
|
if (key in obj) {
|
|
36
22
|
Object.defineProperty(obj, key, {
|
|
@@ -65,7 +51,7 @@ function _inherits(subClass, superClass) {
|
|
|
65
51
|
}
|
|
66
52
|
function _instanceof(left, right) {
|
|
67
53
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
68
|
-
return right[Symbol.hasInstance](left);
|
|
54
|
+
return !!right[Symbol.hasInstance](left);
|
|
69
55
|
} else {
|
|
70
56
|
return left instanceof right;
|
|
71
57
|
}
|
|
@@ -164,9 +150,9 @@ function _createSuper(Derived) {
|
|
|
164
150
|
return _possibleConstructorReturn(this, result);
|
|
165
151
|
};
|
|
166
152
|
}
|
|
167
|
-
import { isArray, isFunction, isString, isJSONArray, isJSONObject, isNumber, isNumberAndEmptyStringArray, isPlainObject, isStringArray, FieldTypes, isObject } from
|
|
168
|
-
import { AddressValue, AmountValue, CalcValue, RangeDateValue } from
|
|
169
|
-
import { camelizeKeys } from
|
|
153
|
+
import { isArray, isFunction, isString, isJSONArray, isJSONObject, isNumber, isNumberAndEmptyStringArray, isPlainObject, isStringArray, FieldTypes, isObject } from "@byteluck-fe/model-driven-shared";
|
|
154
|
+
import { AddressValue, AmountValue, CalcValue, RangeDateValue } from "@byteluck-fe/model-driven-core";
|
|
155
|
+
import { camelizeKeys } from "humps";
|
|
170
156
|
var ValueChecker = function ValueChecker() {
|
|
171
157
|
"use strict";
|
|
172
158
|
_classCallCheck(this, ValueChecker);
|
|
@@ -179,29 +165,22 @@ var StringValueChecker = /*#__PURE__*/ function(ValueChecker) {
|
|
|
179
165
|
_classCallCheck(this, StringValueChecker);
|
|
180
166
|
return _super.apply(this, arguments);
|
|
181
167
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
if (value === null || value === undefined) {
|
|
193
|
-
return '';
|
|
194
|
-
}
|
|
195
|
-
if (!isPlainObject(value) && !isFunction(value)) {
|
|
196
|
-
return String(value);
|
|
197
|
-
}
|
|
198
|
-
if (isObject(value)) {
|
|
199
|
-
return JSON.stringify(value);
|
|
200
|
-
}
|
|
201
|
-
throw "".concat(value, " is not a string");
|
|
202
|
-
}
|
|
168
|
+
var _proto = StringValueChecker.prototype;
|
|
169
|
+
_proto.validate = function validate(value) {
|
|
170
|
+
return isString(value);
|
|
171
|
+
};
|
|
172
|
+
_proto.transform = function transform(value) {
|
|
173
|
+
if (value === null || value === undefined) {
|
|
174
|
+
return "";
|
|
175
|
+
}
|
|
176
|
+
if (!isPlainObject(value) && !isFunction(value)) {
|
|
177
|
+
return String(value);
|
|
203
178
|
}
|
|
204
|
-
|
|
179
|
+
if (isObject(value)) {
|
|
180
|
+
return JSON.stringify(value);
|
|
181
|
+
}
|
|
182
|
+
throw "".concat(value, " is not a string");
|
|
183
|
+
};
|
|
205
184
|
return StringValueChecker;
|
|
206
185
|
}(ValueChecker);
|
|
207
186
|
var NumberValueChecker = /*#__PURE__*/ function(ValueChecker) {
|
|
@@ -212,28 +191,21 @@ var NumberValueChecker = /*#__PURE__*/ function(ValueChecker) {
|
|
|
212
191
|
_classCallCheck(this, NumberValueChecker);
|
|
213
192
|
return _super.apply(this, arguments);
|
|
214
193
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
{
|
|
224
|
-
key: "transform",
|
|
225
|
-
value: function transform(value) {
|
|
226
|
-
if (value === null || value === undefined) {
|
|
227
|
-
return '';
|
|
228
|
-
}
|
|
229
|
-
var newValue = !isPlainObject(value) && !isFunction(value) ? Number(value) : undefined;
|
|
230
|
-
if (!Number.isNaN(newValue) && newValue !== undefined) {
|
|
231
|
-
return newValue;
|
|
232
|
-
}
|
|
233
|
-
throw "".concat(value, " is not a number");
|
|
234
|
-
}
|
|
194
|
+
var _proto = NumberValueChecker.prototype;
|
|
195
|
+
// 数字类型允许是空字符串,用于置空数据
|
|
196
|
+
_proto.validate = function validate(value) {
|
|
197
|
+
return isNumber(value) || value === "";
|
|
198
|
+
};
|
|
199
|
+
_proto.transform = function transform(value) {
|
|
200
|
+
if (value === null || value === undefined) {
|
|
201
|
+
return "";
|
|
235
202
|
}
|
|
236
|
-
|
|
203
|
+
var newValue = !isPlainObject(value) && !isFunction(value) ? Number(value) : undefined;
|
|
204
|
+
if (!Number.isNaN(newValue) && newValue !== undefined) {
|
|
205
|
+
return newValue;
|
|
206
|
+
}
|
|
207
|
+
throw "".concat(value, " is not a number");
|
|
208
|
+
};
|
|
237
209
|
return NumberValueChecker;
|
|
238
210
|
}(ValueChecker);
|
|
239
211
|
var StringArrayValueChecker = /*#__PURE__*/ function(ValueChecker) {
|
|
@@ -244,41 +216,34 @@ var StringArrayValueChecker = /*#__PURE__*/ function(ValueChecker) {
|
|
|
244
216
|
_classCallCheck(this, StringArrayValueChecker);
|
|
245
217
|
return _super.apply(this, arguments);
|
|
246
218
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
if (isString(value1) && isJSONArray(value1)) {
|
|
269
|
-
try {
|
|
270
|
-
var newValue = JSON.parse(value1);
|
|
271
|
-
if (Array.isArray(newValue)) {
|
|
272
|
-
return getStringValueArray(newValue);
|
|
273
|
-
}
|
|
274
|
-
} catch (e) {}
|
|
219
|
+
var _proto = StringArrayValueChecker.prototype;
|
|
220
|
+
_proto.validate = function validate(value) {
|
|
221
|
+
return isStringArray(value);
|
|
222
|
+
};
|
|
223
|
+
_proto.transform = function transform(value) {
|
|
224
|
+
var getStringValueArray = function getStringValueArray(value) {
|
|
225
|
+
return value.map(function(item) {
|
|
226
|
+
return !item ? "" : String(item);
|
|
227
|
+
});
|
|
228
|
+
};
|
|
229
|
+
if (value === undefined || value === null) {
|
|
230
|
+
return [];
|
|
231
|
+
}
|
|
232
|
+
if (isArray(value)) {
|
|
233
|
+
return getStringValueArray(value);
|
|
234
|
+
}
|
|
235
|
+
if (isString(value) && isJSONArray(value)) {
|
|
236
|
+
try {
|
|
237
|
+
var newValue = JSON.parse(value);
|
|
238
|
+
if (Array.isArray(newValue)) {
|
|
239
|
+
return getStringValueArray(newValue);
|
|
275
240
|
}
|
|
276
|
-
|
|
277
|
-
String(value1)
|
|
278
|
-
];
|
|
279
|
-
}
|
|
241
|
+
} catch (e) {}
|
|
280
242
|
}
|
|
281
|
-
|
|
243
|
+
return [
|
|
244
|
+
String(value)
|
|
245
|
+
];
|
|
246
|
+
};
|
|
282
247
|
return StringArrayValueChecker;
|
|
283
248
|
}(ValueChecker);
|
|
284
249
|
var NumberArrayValueChecker = /*#__PURE__*/ function(ValueChecker) {
|
|
@@ -289,47 +254,40 @@ var NumberArrayValueChecker = /*#__PURE__*/ function(ValueChecker) {
|
|
|
289
254
|
_classCallCheck(this, NumberArrayValueChecker);
|
|
290
255
|
return _super.apply(this, arguments);
|
|
291
256
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
if (isString(value2) && isJSONArray(value2)) {
|
|
316
|
-
try {
|
|
317
|
-
var newValue = JSON.parse(value2);
|
|
318
|
-
if (isArray(newValue)) {
|
|
319
|
-
return getNumberValueArray(newValue);
|
|
320
|
-
}
|
|
321
|
-
} catch (e) {}
|
|
322
|
-
}
|
|
323
|
-
var newValue1 = Number(value2);
|
|
324
|
-
if (Number.isNaN(newValue1)) {
|
|
325
|
-
throw "".concat(value2, " is not a number array");
|
|
257
|
+
var _proto = NumberArrayValueChecker.prototype;
|
|
258
|
+
_proto.validate = function validate(value) {
|
|
259
|
+
return isNumberAndEmptyStringArray(value);
|
|
260
|
+
};
|
|
261
|
+
_proto.transform = function transform(value) {
|
|
262
|
+
var getNumberValueArray = function getNumberValueArray(value) {
|
|
263
|
+
return value.map(function(item) {
|
|
264
|
+
return !item && item !== 0 ? "" : Number(item);
|
|
265
|
+
}).filter(function(item) {
|
|
266
|
+
return item === "" || !Number.isNaN(item);
|
|
267
|
+
});
|
|
268
|
+
};
|
|
269
|
+
if (value === undefined || value === null) {
|
|
270
|
+
return [];
|
|
271
|
+
}
|
|
272
|
+
if (isArray(value)) {
|
|
273
|
+
return getNumberValueArray(value);
|
|
274
|
+
}
|
|
275
|
+
if (isString(value) && isJSONArray(value)) {
|
|
276
|
+
try {
|
|
277
|
+
var newValue = JSON.parse(value);
|
|
278
|
+
if (isArray(newValue)) {
|
|
279
|
+
return getNumberValueArray(newValue);
|
|
326
280
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
281
|
+
} catch (e) {}
|
|
282
|
+
}
|
|
283
|
+
var newValue1 = Number(value);
|
|
284
|
+
if (Number.isNaN(newValue1)) {
|
|
285
|
+
throw "".concat(value, " is not a number array");
|
|
331
286
|
}
|
|
332
|
-
|
|
287
|
+
return [
|
|
288
|
+
newValue1
|
|
289
|
+
];
|
|
290
|
+
};
|
|
333
291
|
return NumberArrayValueChecker;
|
|
334
292
|
}(ValueChecker);
|
|
335
293
|
var MoneyValueChecker = /*#__PURE__*/ function(ValueChecker) {
|
|
@@ -340,46 +298,39 @@ var MoneyValueChecker = /*#__PURE__*/ function(ValueChecker) {
|
|
|
340
298
|
_classCallCheck(this, MoneyValueChecker);
|
|
341
299
|
return _super.apply(this, arguments);
|
|
342
300
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
301
|
+
var _proto = MoneyValueChecker.prototype;
|
|
302
|
+
_proto.validate = function validate(value) {
|
|
303
|
+
return _instanceof(value, AmountValue) || isPlainObject(value) && "amount" in value && isNumber(value.amount) && "currency" in value && isString(value.currency);
|
|
304
|
+
};
|
|
305
|
+
_proto.transform = function transform(value, oldValue) {
|
|
306
|
+
if (value === undefined || value === null || value === "") {
|
|
307
|
+
return new AmountValue({
|
|
308
|
+
currency: oldValue === null || oldValue === void 0 ? void 0 : oldValue.currency
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
var result;
|
|
312
|
+
if (isPlainObject(value)) {
|
|
313
|
+
result = new AmountValue(_objectSpread({}, oldValue, value));
|
|
314
|
+
}
|
|
315
|
+
if (isString(value) && isJSONObject(value)) {
|
|
316
|
+
try {
|
|
317
|
+
var newValue = JSON.parse(value);
|
|
318
|
+
result = new AmountValue(_objectSpread({}, oldValue, newValue));
|
|
319
|
+
} catch (e) {}
|
|
320
|
+
}
|
|
321
|
+
if (result) {
|
|
322
|
+
var numberChecker = new NumberValueChecker();
|
|
323
|
+
var stringChecker = new StringValueChecker();
|
|
324
|
+
if (!numberChecker.validate(result.amount)) {
|
|
325
|
+
result.amount = numberChecker.transform(result.amount);
|
|
348
326
|
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
key: "transform",
|
|
352
|
-
value: function transform(value, oldValue) {
|
|
353
|
-
if (value === undefined || value === null || value === '') {
|
|
354
|
-
return new AmountValue({
|
|
355
|
-
currency: oldValue === null || oldValue === void 0 ? void 0 : oldValue.currency
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
var result;
|
|
359
|
-
if (isPlainObject(value)) {
|
|
360
|
-
result = new AmountValue(_objectSpread({}, oldValue, value));
|
|
361
|
-
}
|
|
362
|
-
if (isString(value) && isJSONObject(value)) {
|
|
363
|
-
try {
|
|
364
|
-
var newValue = JSON.parse(value);
|
|
365
|
-
result = new AmountValue(_objectSpread({}, oldValue, newValue));
|
|
366
|
-
} catch (e) {}
|
|
367
|
-
}
|
|
368
|
-
if (result) {
|
|
369
|
-
var numberChecker = new NumberValueChecker();
|
|
370
|
-
var stringChecker = new StringValueChecker();
|
|
371
|
-
if (!numberChecker.validate(result.amount)) {
|
|
372
|
-
result.amount = numberChecker.transform(result.amount);
|
|
373
|
-
}
|
|
374
|
-
if (!stringChecker.validate(result.currency)) {
|
|
375
|
-
result.currency = stringChecker.transform(result.currency);
|
|
376
|
-
}
|
|
377
|
-
return result;
|
|
378
|
-
}
|
|
379
|
-
throw "".concat(value, " is not a { amount: number, currency: string } object");
|
|
327
|
+
if (!stringChecker.validate(result.currency)) {
|
|
328
|
+
result.currency = stringChecker.transform(result.currency);
|
|
380
329
|
}
|
|
330
|
+
return result;
|
|
381
331
|
}
|
|
382
|
-
|
|
332
|
+
throw "".concat(value, " is not a { amount: number, currency: string } object");
|
|
333
|
+
};
|
|
383
334
|
return MoneyValueChecker;
|
|
384
335
|
}(ValueChecker);
|
|
385
336
|
var TimeScopeValueChecker = /*#__PURE__*/ function(ValueChecker) {
|
|
@@ -390,43 +341,36 @@ var TimeScopeValueChecker = /*#__PURE__*/ function(ValueChecker) {
|
|
|
390
341
|
_classCallCheck(this, TimeScopeValueChecker);
|
|
391
342
|
return _super.apply(this, arguments);
|
|
392
343
|
}
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
344
|
+
var _proto = TimeScopeValueChecker.prototype;
|
|
345
|
+
_proto.validate = function validate(value) {
|
|
346
|
+
return _instanceof(value, RangeDateValue) || isPlainObject(value) && "min" in value && isString(value.min) && "max" in value && isString(value.max);
|
|
347
|
+
};
|
|
348
|
+
_proto.transform = function transform(value, oldValue) {
|
|
349
|
+
if (value === undefined || value === null || value === "") {
|
|
350
|
+
return new RangeDateValue();
|
|
351
|
+
}
|
|
352
|
+
var result;
|
|
353
|
+
if (isPlainObject(value)) {
|
|
354
|
+
result = new RangeDateValue(_objectSpread({}, oldValue, value));
|
|
355
|
+
}
|
|
356
|
+
if (isString(value) && isJSONObject(value)) {
|
|
357
|
+
try {
|
|
358
|
+
var newValue = JSON.parse(value);
|
|
359
|
+
result = new RangeDateValue(_objectSpread({}, oldValue, newValue));
|
|
360
|
+
} catch (e) {}
|
|
361
|
+
}
|
|
362
|
+
if (result) {
|
|
363
|
+
var stringChecker = new StringValueChecker();
|
|
364
|
+
if (!stringChecker.validate(result.min)) {
|
|
365
|
+
result.min = stringChecker.transform(result.min);
|
|
398
366
|
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
key: "transform",
|
|
402
|
-
value: function transform(value, oldValue) {
|
|
403
|
-
if (value === undefined || value === null || value === '') {
|
|
404
|
-
return new RangeDateValue();
|
|
405
|
-
}
|
|
406
|
-
var result;
|
|
407
|
-
if (isPlainObject(value)) {
|
|
408
|
-
result = new RangeDateValue(_objectSpread({}, oldValue, value));
|
|
409
|
-
}
|
|
410
|
-
if (isString(value) && isJSONObject(value)) {
|
|
411
|
-
try {
|
|
412
|
-
var newValue = JSON.parse(value);
|
|
413
|
-
result = new RangeDateValue(_objectSpread({}, oldValue, newValue));
|
|
414
|
-
} catch (e) {}
|
|
415
|
-
}
|
|
416
|
-
if (result) {
|
|
417
|
-
var stringChecker = new StringValueChecker();
|
|
418
|
-
if (!stringChecker.validate(result.min)) {
|
|
419
|
-
result.min = stringChecker.transform(result.min);
|
|
420
|
-
}
|
|
421
|
-
if (!stringChecker.validate(result.max)) {
|
|
422
|
-
result.max = stringChecker.transform(result.max);
|
|
423
|
-
}
|
|
424
|
-
return result;
|
|
425
|
-
}
|
|
426
|
-
throw "".concat(value, " is not a { min: string, max: string } object");
|
|
367
|
+
if (!stringChecker.validate(result.max)) {
|
|
368
|
+
result.max = stringChecker.transform(result.max);
|
|
427
369
|
}
|
|
370
|
+
return result;
|
|
428
371
|
}
|
|
429
|
-
|
|
372
|
+
throw "".concat(value, " is not a { min: string, max: string } object");
|
|
373
|
+
};
|
|
430
374
|
return TimeScopeValueChecker;
|
|
431
375
|
}(ValueChecker);
|
|
432
376
|
var CalcValueChecker = /*#__PURE__*/ function(ValueChecker) {
|
|
@@ -437,46 +381,39 @@ var CalcValueChecker = /*#__PURE__*/ function(ValueChecker) {
|
|
|
437
381
|
_classCallCheck(this, CalcValueChecker);
|
|
438
382
|
return _super.apply(this, arguments);
|
|
439
383
|
}
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
384
|
+
var _proto = CalcValueChecker.prototype;
|
|
385
|
+
_proto.validate = function validate(value) {
|
|
386
|
+
return _instanceof(value, CalcValue) || isPlainObject(value) && "result" in value && isNumber(value.result) && "unit" in value && isString(value.unit);
|
|
387
|
+
};
|
|
388
|
+
_proto.transform = function transform(value, oldValue) {
|
|
389
|
+
if (value === undefined || value === null || value === "") {
|
|
390
|
+
return new CalcValue({
|
|
391
|
+
unit: oldValue === null || oldValue === void 0 ? void 0 : oldValue.unit
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
var result;
|
|
395
|
+
if (isPlainObject(value)) {
|
|
396
|
+
result = new CalcValue(_objectSpread({}, oldValue, value));
|
|
397
|
+
}
|
|
398
|
+
if (isString(value) && isJSONObject(value)) {
|
|
399
|
+
try {
|
|
400
|
+
var newValue = JSON.parse(value);
|
|
401
|
+
result = new CalcValue(_objectSpread({}, oldValue, newValue));
|
|
402
|
+
} catch (e) {}
|
|
403
|
+
}
|
|
404
|
+
if (result) {
|
|
405
|
+
var numberChecker = new NumberValueChecker();
|
|
406
|
+
var stringChecker = new StringValueChecker();
|
|
407
|
+
if (!numberChecker.validate(result.result)) {
|
|
408
|
+
result.result = numberChecker.transform(result.result);
|
|
445
409
|
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
key: "transform",
|
|
449
|
-
value: function transform(value, oldValue) {
|
|
450
|
-
if (value === undefined || value === null || value === '') {
|
|
451
|
-
return new CalcValue({
|
|
452
|
-
unit: oldValue === null || oldValue === void 0 ? void 0 : oldValue.unit
|
|
453
|
-
});
|
|
454
|
-
}
|
|
455
|
-
var result;
|
|
456
|
-
if (isPlainObject(value)) {
|
|
457
|
-
result = new CalcValue(_objectSpread({}, oldValue, value));
|
|
458
|
-
}
|
|
459
|
-
if (isString(value) && isJSONObject(value)) {
|
|
460
|
-
try {
|
|
461
|
-
var newValue = JSON.parse(value);
|
|
462
|
-
result = new CalcValue(_objectSpread({}, oldValue, newValue));
|
|
463
|
-
} catch (e) {}
|
|
464
|
-
}
|
|
465
|
-
if (result) {
|
|
466
|
-
var numberChecker = new NumberValueChecker();
|
|
467
|
-
var stringChecker = new StringValueChecker();
|
|
468
|
-
if (!numberChecker.validate(result.result)) {
|
|
469
|
-
result.result = numberChecker.transform(result.result);
|
|
470
|
-
}
|
|
471
|
-
if (!stringChecker.validate(result.unit)) {
|
|
472
|
-
result.unit = stringChecker.transform(result.unit);
|
|
473
|
-
}
|
|
474
|
-
return result;
|
|
475
|
-
}
|
|
476
|
-
throw "".concat(value, " is not a { result: string, unit: string } object");
|
|
410
|
+
if (!stringChecker.validate(result.unit)) {
|
|
411
|
+
result.unit = stringChecker.transform(result.unit);
|
|
477
412
|
}
|
|
413
|
+
return result;
|
|
478
414
|
}
|
|
479
|
-
|
|
415
|
+
throw "".concat(value, " is not a { result: string, unit: string } object");
|
|
416
|
+
};
|
|
480
417
|
return CalcValueChecker;
|
|
481
418
|
}(ValueChecker);
|
|
482
419
|
var AddressValueChecker = /*#__PURE__*/ function(ValueChecker) {
|
|
@@ -487,46 +424,39 @@ var AddressValueChecker = /*#__PURE__*/ function(ValueChecker) {
|
|
|
487
424
|
_classCallCheck(this, AddressValueChecker);
|
|
488
425
|
return _super.apply(this, arguments);
|
|
489
426
|
}
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
427
|
+
var _proto = AddressValueChecker.prototype;
|
|
428
|
+
_proto.validate = function validate(value) {
|
|
429
|
+
return _instanceof(value, AddressValue);
|
|
430
|
+
};
|
|
431
|
+
_proto.transform = function transform(value, oldValue) {
|
|
432
|
+
if (value === undefined || value === null || value === "") {
|
|
433
|
+
return new AddressValue();
|
|
434
|
+
}
|
|
435
|
+
var result;
|
|
436
|
+
if (isPlainObject(value)) {
|
|
437
|
+
result = new AddressValue(_objectSpread({}, oldValue, camelizeKeys(value)));
|
|
438
|
+
}
|
|
439
|
+
if (isString(value) && isJSONObject(value)) {
|
|
440
|
+
try {
|
|
441
|
+
var newValue = JSON.parse(value);
|
|
442
|
+
result = new AddressValue(_objectSpread({}, oldValue, camelizeKeys(newValue)));
|
|
443
|
+
} catch (e) {}
|
|
444
|
+
}
|
|
445
|
+
if (result) {
|
|
446
|
+
var stringChecker = new StringValueChecker();
|
|
447
|
+
if (!stringChecker.validate(result.city)) {
|
|
448
|
+
result.city = stringChecker.transform(result.city);
|
|
495
449
|
}
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
return new AddressValue();
|
|
502
|
-
}
|
|
503
|
-
var result;
|
|
504
|
-
if (isPlainObject(value)) {
|
|
505
|
-
result = new AddressValue(_objectSpread({}, oldValue, camelizeKeys(value)));
|
|
506
|
-
}
|
|
507
|
-
if (isString(value) && isJSONObject(value)) {
|
|
508
|
-
try {
|
|
509
|
-
var newValue = JSON.parse(value);
|
|
510
|
-
result = new AddressValue(_objectSpread({}, oldValue, camelizeKeys(newValue)));
|
|
511
|
-
} catch (e) {}
|
|
512
|
-
}
|
|
513
|
-
if (result) {
|
|
514
|
-
var stringChecker = new StringValueChecker();
|
|
515
|
-
if (!stringChecker.validate(result.city)) {
|
|
516
|
-
result.city = stringChecker.transform(result.city);
|
|
517
|
-
}
|
|
518
|
-
if (!stringChecker.validate(result.district)) {
|
|
519
|
-
result.district = stringChecker.transform(result.district);
|
|
520
|
-
}
|
|
521
|
-
if (!stringChecker.validate(result.province)) {
|
|
522
|
-
result.province = stringChecker.transform(result.province);
|
|
523
|
-
}
|
|
524
|
-
return result;
|
|
525
|
-
}
|
|
526
|
-
throw "".concat(value, " is not a { city: string, district: string, province: string } object");
|
|
450
|
+
if (!stringChecker.validate(result.district)) {
|
|
451
|
+
result.district = stringChecker.transform(result.district);
|
|
452
|
+
}
|
|
453
|
+
if (!stringChecker.validate(result.province)) {
|
|
454
|
+
result.province = stringChecker.transform(result.province);
|
|
527
455
|
}
|
|
456
|
+
return result;
|
|
528
457
|
}
|
|
529
|
-
|
|
458
|
+
throw "".concat(value, " is not a { city: string, district: string, province: string } object");
|
|
459
|
+
};
|
|
530
460
|
return AddressValueChecker;
|
|
531
461
|
}(ValueChecker);
|
|
532
462
|
var ValueCheckerFactory = /*#__PURE__*/ function() {
|
|
@@ -534,69 +464,64 @@ var ValueCheckerFactory = /*#__PURE__*/ function() {
|
|
|
534
464
|
function ValueCheckerFactory() {
|
|
535
465
|
_classCallCheck(this, ValueCheckerFactory);
|
|
536
466
|
}
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
case FieldTypes.ADDRESS:
|
|
573
|
-
checker = new AddressValueChecker();
|
|
574
|
-
break;
|
|
575
|
-
}
|
|
576
|
-
return checker;
|
|
577
|
-
}
|
|
467
|
+
ValueCheckerFactory.getValueChecker = function getValueChecker(fieldType) {
|
|
468
|
+
var checker;
|
|
469
|
+
switch(fieldType){
|
|
470
|
+
case FieldTypes.VARCHAR:
|
|
471
|
+
case FieldTypes.TIMESTAMP:
|
|
472
|
+
case FieldTypes.TEXT:
|
|
473
|
+
case FieldTypes.RELATION:
|
|
474
|
+
case FieldTypes.AUTO_NUMBER:
|
|
475
|
+
checker = new StringValueChecker();
|
|
476
|
+
break;
|
|
477
|
+
case FieldTypes.DECIMAL:
|
|
478
|
+
checker = new NumberValueChecker();
|
|
479
|
+
break;
|
|
480
|
+
case FieldTypes.EMPLOYEES:
|
|
481
|
+
case FieldTypes.DEPARTMENTS:
|
|
482
|
+
case FieldTypes.IMAGE:
|
|
483
|
+
case FieldTypes.FILE:
|
|
484
|
+
case FieldTypes.ARRAY:
|
|
485
|
+
checker = new StringArrayValueChecker();
|
|
486
|
+
break;
|
|
487
|
+
case FieldTypes.MONEY:
|
|
488
|
+
checker = new MoneyValueChecker();
|
|
489
|
+
break;
|
|
490
|
+
case FieldTypes.TIMESCOPE:
|
|
491
|
+
checker = new TimeScopeValueChecker();
|
|
492
|
+
break;
|
|
493
|
+
case FieldTypes.CALC:
|
|
494
|
+
checker = new CalcValueChecker();
|
|
495
|
+
break;
|
|
496
|
+
case FieldTypes.DECIMAL_RANGE:
|
|
497
|
+
checker = new NumberArrayValueChecker();
|
|
498
|
+
break;
|
|
499
|
+
case FieldTypes.ADDRESS:
|
|
500
|
+
checker = new AddressValueChecker();
|
|
501
|
+
break;
|
|
578
502
|
}
|
|
579
|
-
|
|
503
|
+
return checker;
|
|
504
|
+
};
|
|
580
505
|
return ValueCheckerFactory;
|
|
581
506
|
}();
|
|
582
507
|
function getFieldTypeFromKey(key) {
|
|
583
508
|
if ([
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
509
|
+
"min",
|
|
510
|
+
"max",
|
|
511
|
+
"currency",
|
|
512
|
+
"unit"
|
|
588
513
|
].includes(key)) {
|
|
589
514
|
return FieldTypes.VARCHAR;
|
|
590
515
|
} else if ([
|
|
591
|
-
|
|
592
|
-
|
|
516
|
+
"result",
|
|
517
|
+
"amount"
|
|
593
518
|
].includes(key)) {
|
|
594
519
|
return FieldTypes.DECIMAL;
|
|
595
520
|
}
|
|
596
521
|
}
|
|
597
522
|
export function checkerValue(fieldType, key, value, oldValue) {
|
|
598
|
-
var
|
|
599
|
-
var getCheckerFieldType = (
|
|
523
|
+
var _getFieldTypeFromKey;
|
|
524
|
+
var getCheckerFieldType = (_getFieldTypeFromKey = getFieldTypeFromKey(key)) !== null && _getFieldTypeFromKey !== void 0 ? _getFieldTypeFromKey : fieldType;
|
|
600
525
|
var checker = ValueCheckerFactory.getValueChecker(getCheckerFieldType);
|
|
601
526
|
if (!checker || checker.validate(value)) {
|
|
602
527
|
return value;
|