@qubit-ltd/common-decorator 3.10.0 → 3.10.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.
@@ -1608,7 +1608,6 @@ function ofValueImpl(Class, value) {
1608
1608
  * The default instance of the specified class, or a new instance will be
1609
1609
  * created if it does not exist.
1610
1610
  * @author Haixing Hu
1611
- * @private
1612
1611
  */
1613
1612
  function getDefaultInstance(Class) {
1614
1613
  if (Class.prototype === Object.prototype) {
@@ -1810,7 +1809,6 @@ function getFieldMetadata(metadata, field, key) {
1810
1809
  * @return {function|null}
1811
1810
  * the element type of the specified field of the object, or `null` if the
1812
1811
  * field element type cannot be inferred.
1813
- * @private
1814
1812
  * @author Haixing Hu
1815
1813
  */
1816
1814
  function getFieldElementType(Class, field) {
@@ -1878,7 +1876,6 @@ function getFieldElementType(Class, field) {
1878
1876
  * @return {function|undefined}
1879
1877
  * the type of the specified field of the object, or `undefined` if the field
1880
1878
  * type cannot be inferred.
1881
- * @private
1882
1879
  * @author Haixing Hu
1883
1880
  */
1884
1881
  function getFieldType(Class, field) {
@@ -1933,7 +1930,6 @@ function getFieldType(Class, field) {
1933
1930
  * @return {string}
1934
1931
  * The corresponding key of the source object.
1935
1932
  * @author Haixing Hu
1936
- * @private
1937
1933
  */
1938
1934
  function getSourceField(targetField, options) {
1939
1935
  if ((options === null || options === void 0 ? void 0 : options.convertNaming) === true) {
@@ -1953,22 +1949,26 @@ function getSourceField(targetField, options) {
1953
1949
  // All rights reserved.
1954
1950
  //
1955
1951
  ////////////////////////////////////////////////////////////////////////////////
1952
+
1956
1953
  /**
1957
- * Determine whether the prototype of a specified class has the specified
1958
- * prototype function.
1954
+ * Determines whether the specified prototype function exists anywhere in the
1955
+ * prototype chain of a specified class.
1959
1956
  *
1960
- * Note that the function may be inherited from its parent class.
1957
+ * This function checks the entire prototype chain, including methods inherited
1958
+ * from parent classes. It uses `Reflect.has()` which searches through the complete
1959
+ * prototype chain, unlike `Object.prototype.hasOwnProperty` which only checks
1960
+ * direct properties.
1961
1961
  *
1962
1962
  * @param {function} Class
1963
1963
  * Constructor for the specified class.
1964
1964
  * @param {string} name
1965
1965
  * The name of the specified prototype function.
1966
1966
  * @returns {Boolean}
1967
- * Whether the prototype of the specified class has the specified prototype
1968
- * function. Note that the function may be inherited from its parent class.
1967
+ * Returns true if the specified function exists anywhere in the prototype chain
1968
+ * of the class, whether defined by the class itself or inherited from a parent class.
1969
1969
  * @see hasOwnPrototypeFunction
1970
+ * Checks only methods defined directly on the class.
1970
1971
  * @author Haixing Hu
1971
- * @private
1972
1972
  */
1973
1973
  function hasPrototypeFunction(Class, name) {
1974
1974
  return Class !== null && Class.prototype && Reflect.has(Class.prototype, name) && typeof Class.prototype[name] === 'function';
@@ -3862,6 +3862,127 @@ clone.registerCloneHook(function (info, obj) {
3862
3862
  //
3863
3863
  ////////////////////////////////////////////////////////////////////////////////
3864
3864
 
3865
+ /**
3866
+ * Determines whether a class directly owns a specific property (not inherited from parent classes).
3867
+ *
3868
+ * This function checks if the specified property is directly defined on either:
3869
+ * 1. The prototype of the class itself, or
3870
+ * 2. The default instance of the class
3871
+ *
3872
+ * Unlike JavaScript's built-in `Object.prototype.hasOwnProperty`, this function:
3873
+ * - Accepts a class constructor rather than an object instance
3874
+ * - Checks both the prototype and default instance
3875
+ * - Only reports properties owned directly by the class (not inherited properties)
3876
+ *
3877
+ * @param {function} Class
3878
+ * The constructor of the class to check.
3879
+ * @param {string} field
3880
+ * The name of the property to check for.
3881
+ * @returns {boolean}
3882
+ * Returns true if and only if the property is directly defined by the class
3883
+ * (either on its prototype or default instance), not inherited from parent classes.
3884
+ * @see hasPrototypeFunction
3885
+ * For checking inherited properties in the prototype chain.
3886
+ * @author Haixing Hu
3887
+ */
3888
+ function hasOwnProperty(Class, field) {
3889
+ if (!Class || !Class.prototype) {
3890
+ return false;
3891
+ }
3892
+ if (Object.prototype.hasOwnProperty.call(Class.prototype, field)) {
3893
+ return true;
3894
+ } else {
3895
+ var defaultInstance = getDefaultInstance(Class);
3896
+ return defaultInstance && Object.prototype.hasOwnProperty.call(defaultInstance, field);
3897
+ }
3898
+ }
3899
+
3900
+ ////////////////////////////////////////////////////////////////////////////////
3901
+ //
3902
+ // Copyright (c) 2022 - 2025.
3903
+ // Haixing Hu, Qubit Co. Ltd.
3904
+ //
3905
+ // All rights reserved.
3906
+ //
3907
+ ////////////////////////////////////////////////////////////////////////////////
3908
+
3909
+ /**
3910
+ * Determines whether the specified prototype function is directly defined in the
3911
+ * prototype of a specified class (not inherited from parent classes).
3912
+ *
3913
+ * This function checks ONLY the methods defined directly on the class's prototype,
3914
+ * and ignores methods inherited from parent classes. It uses `Object.prototype.hasOwnProperty`
3915
+ * to ensure only "own properties" of the prototype are considered.
3916
+ *
3917
+ * @param {function} Class
3918
+ * Constructor for the specified class.
3919
+ * @param {string} name
3920
+ * The name of the specified prototype function.
3921
+ * @returns {Boolean}
3922
+ * Returns true if and only if the specified function is directly defined on
3923
+ * the prototype of the class itself (not inherited from parent classes).
3924
+ * @see hasPrototypeFunction
3925
+ * Checks for methods anywhere in the prototype chain.
3926
+ * @author Haixing Hu
3927
+ * @private
3928
+ */
3929
+ function hasOwnPrototypeFunction(Class, name) {
3930
+ return Class !== null && Class.prototype && Object.prototype.hasOwnProperty.call(Class.prototype, name) && typeof Class.prototype[name] === 'function';
3931
+ }
3932
+
3933
+ ////////////////////////////////////////////////////////////////////////////////
3934
+ //
3935
+ // Copyright (c) 2022 - 2025.
3936
+ // Haixing Hu, Qubit Co. Ltd.
3937
+ //
3938
+ // All rights reserved.
3939
+ //
3940
+ ////////////////////////////////////////////////////////////////////////////////
3941
+
3942
+ /**
3943
+ * Determines whether a class has a specific property (including inherited properties).
3944
+ *
3945
+ * This function checks if the specified property is defined on either:
3946
+ * 1. The prototype chain of the class, or
3947
+ * 2. The default instance of the class
3948
+ *
3949
+ * Unlike `hasOwnProperty()` which only checks direct properties, this function:
3950
+ * - Accepts a class constructor rather than an object instance
3951
+ * - Checks both the prototype chain and default instance
3952
+ * - Reports properties defined anywhere in the inheritance chain
3953
+ *
3954
+ * @param {function} Class
3955
+ * The constructor of the class to check.
3956
+ * @param {string} field
3957
+ * The name of the property to check for.
3958
+ * @returns {boolean}
3959
+ * Returns true if the property is defined by the class or any of its parent
3960
+ * classes (either on its prototype chain or default instance).
3961
+ * @see hasOwnProperty
3962
+ * For checking only direct properties not inherited from parent classes.
3963
+ * @author Haixing Hu
3964
+ */
3965
+ function hasProperty(Class, field) {
3966
+ if (!Class || !Class.prototype) {
3967
+ return false;
3968
+ }
3969
+ if (Reflect.has(Class.prototype, field)) {
3970
+ return true;
3971
+ } else {
3972
+ var defaultInstance = getDefaultInstance(Class);
3973
+ return defaultInstance && Reflect.has(defaultInstance, field);
3974
+ }
3975
+ }
3976
+
3977
+ ////////////////////////////////////////////////////////////////////////////////
3978
+ //
3979
+ // Copyright (c) 2022 - 2025.
3980
+ // Haixing Hu, Qubit Co. Ltd.
3981
+ //
3982
+ // All rights reserved.
3983
+ //
3984
+ ////////////////////////////////////////////////////////////////////////////////
3985
+
3865
3986
  /**
3866
3987
  * Decorates a class field to specify its label, i.e., the display name of the
3867
3988
  * field in the UI.
@@ -10180,33 +10301,6 @@ function isNullishOrEmptyImpl(Class, obj) {
10180
10301
  return obj.isEmpty();
10181
10302
  }
10182
10303
 
10183
- ////////////////////////////////////////////////////////////////////////////////
10184
- //
10185
- // Copyright (c) 2022 - 2025.
10186
- // Haixing Hu, Qubit Co. Ltd.
10187
- //
10188
- // All rights reserved.
10189
- //
10190
- ////////////////////////////////////////////////////////////////////////////////
10191
- /**
10192
- * Determines whether the specified prototype function is defined in the
10193
- * prototype of a specified class.
10194
- *
10195
- * @param {function} Class
10196
- * Constructor for the specified class.
10197
- * @param {string} name
10198
- * The name of the specified prototype function.
10199
- * @returns {Boolean}
10200
- * Whether the specified prototype function is defined in the prototype of
10201
- * the specified class.
10202
- * @see hasPrototypeFunction
10203
- * @author Haixing Hu
10204
- * @private
10205
- */
10206
- function hasOwnPrototypeFunction(Class, name) {
10207
- return Class !== null && Class.prototype && Object.prototype.hasOwnProperty.call(Class.prototype, name) && typeof Class.prototype[name] === 'function';
10208
- }
10209
-
10210
10304
  ////////////////////////////////////////////////////////////////////////////////
10211
10305
  //
10212
10306
  // Copyright (c) 2022 - 2025.
@@ -11432,40 +11526,6 @@ function validateImpl(Class, obj, fields, context) {
11432
11526
  }
11433
11527
  }
11434
11528
 
11435
- ////////////////////////////////////////////////////////////////////////////////
11436
- //
11437
- // Copyright (c) 2022 - 2025.
11438
- // Haixing Hu, Qubit Co. Ltd.
11439
- //
11440
- // All rights reserved.
11441
- //
11442
- ////////////////////////////////////////////////////////////////////////////////
11443
-
11444
- /**
11445
- * Tests whether the specified class has the specified field.
11446
- *
11447
- * @param {function} Class
11448
- * The constructor of the specified class.
11449
- * @param {string} field
11450
- * The name of the specified field.
11451
- * @returns {boolean}
11452
- * Whether the specified class has the specified field defined in its
11453
- * prototype or its default instance.
11454
- * @author Haixing Hu
11455
- * @private
11456
- */
11457
- function hasOwnClassField(Class, field) {
11458
- if (!Class || !Class.prototype) {
11459
- return false;
11460
- }
11461
- if (Object.prototype.hasOwnProperty.call(Class.prototype, field)) {
11462
- return true;
11463
- } else {
11464
- var defaultInstance = getDefaultInstance(Class);
11465
- return defaultInstance && Object.prototype.hasOwnProperty.call(defaultInstance, field);
11466
- }
11467
- }
11468
-
11469
11529
  function ownKeys$1(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
11470
11530
  function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
11471
11531
 
@@ -11973,7 +12033,7 @@ function Model(Class, context) {
11973
12033
  };
11974
12034
  }
11975
12035
  // Add the instance method `generateId()` to the class containing the `id` field
11976
- if (hasOwnClassField(Class, 'id') && !hasPrototypeFunction(Class, 'generateId')) {
12036
+ if (hasOwnProperty(Class, 'id') && !hasPrototypeFunction(Class, 'generateId')) {
11977
12037
  // If its own instance has an `id` field, and there is no `generateId()`
11978
12038
  // method on itself or its parent class prototype
11979
12039
  setClassMetadata(Class, KEY_CLASS_NEXT_ID, 0);
@@ -12063,8 +12123,15 @@ function Model(Class, context) {
12063
12123
  * @name Model#toJSON
12064
12124
  * @memberof Model
12065
12125
  */
12066
- Class.prototype.toJSON = function toJSON(key) {
12067
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
12126
+ Class.prototype.toJSON = function toJSON() {
12127
+ var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
12128
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
12129
+ if (_typeof(key) === 'object') {
12130
+ // if the key is an object, it means that the `toJSON()` method is called
12131
+ // directly with the only argument `options`, so the `key` is the `options`
12132
+ options = key;
12133
+ key = '';
12134
+ }
12068
12135
  return toJsonImpl(this, key, _objectSpread$1(_objectSpread$1({}, options), {}, {
12069
12136
  skipRootToJSON: true
12070
12137
  }));
@@ -12122,7 +12189,7 @@ function Model(Class, context) {
12122
12189
  * @memberof Model
12123
12190
  */
12124
12191
  Class.prototype.toJsonString = function toJsonString() {
12125
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;
12192
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
12126
12193
  return toJsonStringImpl(Class, this, options);
12127
12194
  };
12128
12195
  }
@@ -13319,6 +13386,14 @@ exports.createArray = createArray;
13319
13386
  exports.createPage = createPage;
13320
13387
  exports.defaultNormalizer = defaultNormalizer;
13321
13388
  exports.enumNormalizer = enumNormalizer;
13389
+ exports.getDefaultInstance = getDefaultInstance;
13390
+ exports.getFieldElementType = getFieldElementType;
13391
+ exports.getFieldType = getFieldType;
13392
+ exports.getSourceField = getSourceField;
13393
+ exports.hasOwnProperty = hasOwnProperty;
13394
+ exports.hasOwnPrototypeFunction = hasOwnPrototypeFunction;
13395
+ exports.hasProperty = hasProperty;
13396
+ exports.hasPrototypeFunction = hasPrototypeFunction;
13322
13397
  exports.isEnumClass = isEnumClass;
13323
13398
  exports.isEnumerator = isEnumerator;
13324
13399
  exports.normalize = normalize;