@qubit-ltd/common-decorator 3.9.1 → 3.10.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/README.md +8 -3
- package/README.zh_CN.md +5 -1
- package/dist/common-decorator.cjs +41 -19
- package/dist/common-decorator.cjs.map +1 -1
- package/dist/common-decorator.min.cjs +1 -1
- package/dist/common-decorator.min.cjs.map +1 -1
- package/dist/common-decorator.min.mjs +1 -1
- package/dist/common-decorator.min.mjs.map +1 -1
- package/dist/common-decorator.mjs +41 -19
- package/dist/common-decorator.mjs.map +1 -1
- package/doc/api/DefaultAssignmentOptions.html +1 -1
- package/doc/api/DefaultOptions.html +1 -1
- package/doc/api/DefaultToJsonOptions.html +1 -1
- package/doc/api/Enum.html +1 -1
- package/doc/api/Model.html +27 -11
- package/doc/api/Page.html +1 -1
- package/doc/api/global.html +3 -2
- package/doc/api/index.html +8 -4
- package/doc/common-decorator.min.visualization.html +1 -1
- package/doc/common-decorator.visualization.html +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -127,9 +127,11 @@ class.
|
|
|
127
127
|
- `object`: the calling object itself.
|
|
128
128
|
|
|
129
129
|
This function copies the fields of the object `obj` to this object, only copying
|
|
130
|
-
fields defined in this object's class. If a field in the `obj` object
|
|
131
|
-
|
|
132
|
-
`
|
|
130
|
+
fields defined in this object's class. If a field doesn't exist in the `obj` object,
|
|
131
|
+
it sets the field's value to the default value. If a field exists in the `obj` object
|
|
132
|
+
but its value is `null` or `undefined`, the function preserves the `null` or `undefined`
|
|
133
|
+
value rather than setting it to the default value. Note that `obj` can have a different
|
|
134
|
+
prototype to this object.
|
|
133
135
|
|
|
134
136
|
#### <span id="model-clone">Instance method: Class.prototype.clone()</span>
|
|
135
137
|
|
|
@@ -227,6 +229,9 @@ fields of this object. If `fields` is an array of strings, it normalizes all the
|
|
|
227
229
|
normalizable fields whose names are specified in the array. Note that a field is
|
|
228
230
|
normalizable if and only if it is decorated by the `@Normalizable` decorator.
|
|
229
231
|
|
|
232
|
+
**IMPORTANT**: If a field value is `null` or `undefined`, the normalization process will
|
|
233
|
+
preserve the `null` or `undefined` value rather than replacing it with a default value.
|
|
234
|
+
|
|
230
235
|
#### <span id="model-validateField">Instance method: Class.prototype.validateField(field)</span>
|
|
231
236
|
|
|
232
237
|
- Parameters:
|
package/README.zh_CN.md
CHANGED
|
@@ -112,7 +112,8 @@ pnpm add @qubit-ltd/common-decorator
|
|
|
112
112
|
- `object`:调用该方法的对象自身。
|
|
113
113
|
|
|
114
114
|
此函数将 `obj` 对象的字段复制到当前对象中,仅复制当前对象类中定义的字段。
|
|
115
|
-
如果 `obj`
|
|
115
|
+
如果 `obj` 中不存在某个字段,则将当前对象对应字段设为默认值。但如果 `obj` 中某个字段存在
|
|
116
|
+
且值为 `null` 或 `undefined`,函数会保留这些 `null` 或 `undefined` 值,而不是设为默认值。
|
|
116
117
|
注意,`obj` 可以与当前对象有不同的原型。
|
|
117
118
|
|
|
118
119
|
#### <span id="model-clone">实例方法:Class.prototype.clone()</span>
|
|
@@ -189,6 +190,9 @@ pnpm add @qubit-ltd/common-decorator
|
|
|
189
190
|
如果 `fields` 是一个字符串数组,则规范化数组中指定名称的所有可规范化字段。
|
|
190
191
|
请注意,字段只有在被 `@Normalizable` 装饰器装饰时才是可规范化的。
|
|
191
192
|
|
|
193
|
+
**重要提示**:如果字段值为 `null` 或 `undefined`,规范化过程将会保留这些 `null` 或 `undefined` 值,
|
|
194
|
+
而不会将其替换为默认值。
|
|
195
|
+
|
|
192
196
|
#### <span id="model-validateField">实例方法:Class.prototype.validateField(field)</span>
|
|
193
197
|
|
|
194
198
|
- 参数:
|
|
@@ -1042,7 +1042,8 @@ function enumNormalizer(EnumClass) {
|
|
|
1042
1042
|
* A default normalizer for a non-static class field.
|
|
1043
1043
|
*
|
|
1044
1044
|
* This normalizer does the following things:
|
|
1045
|
-
* - If the value is `undefined` or `null`, it returns the value itself
|
|
1045
|
+
* - If the value is `undefined` or `null`, it returns the value itself without
|
|
1046
|
+
* changing it;
|
|
1046
1047
|
* - If the value is a string, it returns the trimmed string;
|
|
1047
1048
|
* - If the value is a collection, it returns the same type of collection whose
|
|
1048
1049
|
* elements are normalized by the default normalizer;
|
|
@@ -10266,7 +10267,12 @@ function normalizeArrayField(Class, obj, field, value, options, normalizer) {
|
|
|
10266
10267
|
elementTypes: options.elementTypes
|
|
10267
10268
|
};
|
|
10268
10269
|
obj[field] = value.map(function (v) {
|
|
10269
|
-
|
|
10270
|
+
// for null or undefined values, keep the original value without normalization
|
|
10271
|
+
if (v === null || v === undefined) {
|
|
10272
|
+
return v;
|
|
10273
|
+
} else {
|
|
10274
|
+
return normalizer(v, context);
|
|
10275
|
+
}
|
|
10270
10276
|
});
|
|
10271
10277
|
return true;
|
|
10272
10278
|
}
|
|
@@ -10416,19 +10422,16 @@ function normalizeNormalField(Class, obj, field, value, options, normalizer) {
|
|
|
10416
10422
|
* @param {any} value
|
|
10417
10423
|
* The value of the specified field of the specified object.
|
|
10418
10424
|
* @returns {boolean}
|
|
10419
|
-
* If the field value is nullish, this function
|
|
10420
|
-
*
|
|
10421
|
-
* value of the default instance of the specified class, and returns `true`;
|
|
10425
|
+
* If the field value is nullish, this function returns `true` and preserves
|
|
10426
|
+
* the nullish value (null or undefined) in the object's field;
|
|
10422
10427
|
* otherwise, this function does nothing and returns `false`.
|
|
10423
10428
|
* @author Haixing Hu
|
|
10424
10429
|
* @private
|
|
10425
10430
|
*/
|
|
10426
10431
|
function normalizeNullishField(Class, obj, field, value) {
|
|
10427
10432
|
if (value === undefined || value === null) {
|
|
10428
|
-
// For field values that are `undefined` or `null`, the
|
|
10429
|
-
//
|
|
10430
|
-
var defaultInstance = getDefaultInstance(Class);
|
|
10431
|
-
obj[field] = defaultInstance[field];
|
|
10433
|
+
// For field values that are `undefined` or `null`, preserve the original value
|
|
10434
|
+
// instead of replacing it with the default value
|
|
10432
10435
|
return true;
|
|
10433
10436
|
}
|
|
10434
10437
|
return false;
|
|
@@ -11475,12 +11478,13 @@ function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t
|
|
|
11475
11478
|
*
|
|
11476
11479
|
* - Instance method `assign(obj, options)`: Copies the properties of the object
|
|
11477
11480
|
* `obj` to this object, only copying properties defined in the class of this
|
|
11478
|
-
* object. If a property in
|
|
11479
|
-
*
|
|
11480
|
-
*
|
|
11481
|
-
* The
|
|
11482
|
-
*
|
|
11483
|
-
*
|
|
11481
|
+
* object. If a property in `obj` does not exist, it sets the property of this
|
|
11482
|
+
* object to the default value. If a property exists in `obj` but its value is
|
|
11483
|
+
* `null` or `undefined`, the function preserves the `null` or `undefined` value.
|
|
11484
|
+
* The function returns this object itself. Note that `obj` can have a different
|
|
11485
|
+
* prototype than this object. The `options` parameter is the additional options
|
|
11486
|
+
* for the assignment. Available options will be explained below. If the `options`
|
|
11487
|
+
* parameter is `undefined` or `null`, the default options will be used. The default
|
|
11484
11488
|
* options can be retrieved by calling `DefaultOptions.get('assign')`.
|
|
11485
11489
|
* - Instance method `clear()`: Sets all the properties of this object to their
|
|
11486
11490
|
* default values.
|
|
@@ -11707,8 +11711,10 @@ function Model(Class, context) {
|
|
|
11707
11711
|
* Copies the properties from a specified data object to this object, only
|
|
11708
11712
|
* copying properties defined in the class of this object.
|
|
11709
11713
|
*
|
|
11710
|
-
* If a property in the data object
|
|
11711
|
-
* sets the property of this object to the default value.
|
|
11714
|
+
* If a property in the data object doesn't exist, the function
|
|
11715
|
+
* sets the property of this object to the default value. However, if a property
|
|
11716
|
+
* exists in the data object but its value is `null` or `undefined`, the function
|
|
11717
|
+
* will preserve that `null` or `undefined` value in this object.
|
|
11712
11718
|
*
|
|
11713
11719
|
* Note that the data object may have a different prototype than this object.
|
|
11714
11720
|
*
|
|
@@ -11824,6 +11830,10 @@ function Model(Class, context) {
|
|
|
11824
11830
|
* A field is normalizable if and only if it is decorated with the
|
|
11825
11831
|
* `@{@link Normalizable}` decorator.
|
|
11826
11832
|
*
|
|
11833
|
+
* If a field value is `null` or `undefined`, the normalization process will
|
|
11834
|
+
* preserve the `null` or `undefined` value rather than replacing it with a
|
|
11835
|
+
* default value.
|
|
11836
|
+
*
|
|
11827
11837
|
* @param {undefined|string|array} fields
|
|
11828
11838
|
* the names of fields to be normalized. If this argument is not specified,
|
|
11829
11839
|
* or `undefined`, or `null`, or a string `'*'`, this function normalizes
|
|
@@ -12124,8 +12134,10 @@ function Model(Class, context) {
|
|
|
12124
12134
|
* It copies the property values from the corresponding properties of the
|
|
12125
12135
|
* specified data object maintaining the same prototype and class definition.
|
|
12126
12136
|
*
|
|
12127
|
-
* If a property in the data object
|
|
12128
|
-
*
|
|
12137
|
+
* If a property doesn't exist in the data object, the function sets the property
|
|
12138
|
+
* of the created instance to the default value. If a property exists in the data
|
|
12139
|
+
* object but its value is `null` or `undefined`, the function preserves the `null`
|
|
12140
|
+
* or `undefined` value.
|
|
12129
12141
|
*
|
|
12130
12142
|
* This method is usually used to transform a plain JSON object into the
|
|
12131
12143
|
* specified domain object.
|
|
@@ -12179,6 +12191,11 @@ function Model(Class, context) {
|
|
|
12179
12191
|
* copied from the corresponding elements in the data object array,
|
|
12180
12192
|
* maintaining the same prototype and class definition.
|
|
12181
12193
|
*
|
|
12194
|
+
* For each element in the array, if a property doesn't exist in the data object,
|
|
12195
|
+
* the function sets the property of the created instance to the default value.
|
|
12196
|
+
* If a property exists in the data object but its value is `null` or `undefined`,
|
|
12197
|
+
* the function preserves the `null` or `undefined` value.
|
|
12198
|
+
*
|
|
12182
12199
|
* This method is usually used to transform an array of plain JSON objects
|
|
12183
12200
|
* into an array of specified domain objects.
|
|
12184
12201
|
*
|
|
@@ -12231,6 +12248,11 @@ function Model(Class, context) {
|
|
|
12231
12248
|
* list of domain objects obtained from a server using the GET method, and
|
|
12232
12249
|
* the object should conform to the `Page` class definition.
|
|
12233
12250
|
*
|
|
12251
|
+
* For each element in the page content array, if a property doesn't exist in
|
|
12252
|
+
* the data object, the function sets the property of the created instance to
|
|
12253
|
+
* the default value. If a property exists in the data object but its value is
|
|
12254
|
+
* `null` or `undefined`, the function preserves the `null` or `undefined` value.
|
|
12255
|
+
*
|
|
12234
12256
|
* @param {object} page
|
|
12235
12257
|
* the specified pagination data object, which must conform to the
|
|
12236
12258
|
* `Page` class definition.
|