@tsed/core 8.18.2 → 8.19.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.
Files changed (139) hide show
  1. package/lib/esm/decorators/storeFn.js +8 -4
  2. package/lib/esm/decorators/storeMerge.js +10 -0
  3. package/lib/esm/decorators/storeSet.js +10 -0
  4. package/lib/esm/errors/UnsupportedDecoratorType.js +8 -0
  5. package/lib/esm/types/DecoratorTypes.js +16 -0
  6. package/lib/esm/types/Env.js +8 -2
  7. package/lib/esm/types/Metadata.js +9 -0
  8. package/lib/esm/types/Store.js +14 -0
  9. package/lib/esm/types/Type.js +4 -2
  10. package/lib/esm/utils/AnyToPromise.js +20 -0
  11. package/lib/esm/utils/ancestorOf.js +17 -0
  12. package/lib/esm/utils/ancestorsOf.js +8 -2
  13. package/lib/esm/utils/catchError.js +12 -0
  14. package/lib/esm/utils/classOf.js +14 -7
  15. package/lib/esm/utils/cleanObject.js +7 -3
  16. package/lib/esm/utils/constructorOf.js +15 -4
  17. package/lib/esm/utils/createInstance.js +11 -0
  18. package/lib/esm/utils/decorateMethodsOf.js +11 -0
  19. package/lib/esm/utils/decoratorArgs.js +10 -0
  20. package/lib/esm/utils/decoratorTypeOf.js +11 -1
  21. package/lib/esm/utils/deepClone.js +7 -3
  22. package/lib/esm/utils/deepMerge.js +15 -0
  23. package/lib/esm/utils/descriptorOf.js +15 -4
  24. package/lib/esm/utils/getClassOrSymbol.js +8 -0
  25. package/lib/esm/utils/getConstructorArgNames.js +10 -0
  26. package/lib/esm/utils/getRandomId.js +8 -0
  27. package/lib/esm/utils/hasJsonMethod.js +6 -0
  28. package/lib/esm/utils/http/getHostInfoFromPort.js +9 -0
  29. package/lib/esm/utils/inheritedDescriptorOf.js +6 -0
  30. package/lib/esm/utils/isArray.js +8 -7
  31. package/lib/esm/utils/isArrowFn.js +6 -0
  32. package/lib/esm/utils/isBoolean.js +9 -2
  33. package/lib/esm/utils/isBuffer.js +10 -3
  34. package/lib/esm/utils/isClass.js +9 -0
  35. package/lib/esm/utils/isCollection.js +6 -3
  36. package/lib/esm/utils/isDate.js +3 -2
  37. package/lib/esm/utils/isEmpty.js +4 -3
  38. package/lib/esm/utils/isEnumerable.js +3 -2
  39. package/lib/esm/utils/isFunction.js +6 -0
  40. package/lib/esm/utils/isInheritedFrom.js +6 -0
  41. package/lib/esm/utils/isMomentObject.js +6 -0
  42. package/lib/esm/utils/isMongooseObject.js +13 -1
  43. package/lib/esm/utils/isNil.js +6 -0
  44. package/lib/esm/utils/isNumber.js +9 -2
  45. package/lib/esm/utils/isObject.js +6 -0
  46. package/lib/esm/utils/isObservable.js +6 -0
  47. package/lib/esm/utils/isPlainObject.js +9 -2
  48. package/lib/esm/utils/isPrimitive.js +14 -7
  49. package/lib/esm/utils/isPromise.js +4 -3
  50. package/lib/esm/utils/isProtectedKey.js +4 -2
  51. package/lib/esm/utils/isRegExp.js +6 -0
  52. package/lib/esm/utils/isSerializable.js +6 -0
  53. package/lib/esm/utils/isStream.js +6 -0
  54. package/lib/esm/utils/isString.js +10 -2
  55. package/lib/esm/utils/isSymbol.js +9 -1
  56. package/lib/esm/utils/methodsOf.js +4 -2
  57. package/lib/esm/utils/nameOf.js +12 -5
  58. package/lib/esm/utils/objectKeys.js +6 -0
  59. package/lib/esm/utils/primitiveOf.js +6 -0
  60. package/lib/esm/utils/prototypeOf.js +4 -3
  61. package/lib/esm/utils/setValue.js +20 -0
  62. package/lib/esm/utils/toMap.js +6 -0
  63. package/lib/esm/utils/toStringConstructor.js +10 -0
  64. package/lib/esm/utils/uniq.js +10 -1
  65. package/lib/esm/utils/useDecorators.js +6 -0
  66. package/lib/esm/utils/useMethodDecorators.js +12 -0
  67. package/lib/types/decorators/storeFn.d.ts +8 -4
  68. package/lib/types/decorators/storeMerge.d.ts +10 -0
  69. package/lib/types/decorators/storeSet.d.ts +10 -0
  70. package/lib/types/errors/UnsupportedDecoratorType.d.ts +8 -0
  71. package/lib/types/types/AnyDecorator.d.ts +10 -0
  72. package/lib/types/types/DecoratorParameters.d.ts +21 -0
  73. package/lib/types/types/DecoratorTypes.d.ts +16 -0
  74. package/lib/types/types/Env.d.ts +8 -2
  75. package/lib/types/types/Metadata.d.ts +9 -0
  76. package/lib/types/types/MetadataTypes.d.ts +12 -0
  77. package/lib/types/types/Relation.d.ts +8 -0
  78. package/lib/types/types/Store.d.ts +14 -0
  79. package/lib/types/types/Type.d.ts +14 -4
  80. package/lib/types/types/ValueOf.d.ts +10 -0
  81. package/lib/types/utils/AnyToPromise.d.ts +28 -0
  82. package/lib/types/utils/ancestorOf.d.ts +17 -0
  83. package/lib/types/utils/ancestorsOf.d.ts +8 -2
  84. package/lib/types/utils/catchError.d.ts +12 -0
  85. package/lib/types/utils/classOf.d.ts +14 -7
  86. package/lib/types/utils/cleanObject.d.ts +7 -3
  87. package/lib/types/utils/constructorOf.d.ts +15 -4
  88. package/lib/types/utils/createInstance.d.ts +11 -0
  89. package/lib/types/utils/decorateMethodsOf.d.ts +11 -0
  90. package/lib/types/utils/decoratorArgs.d.ts +10 -0
  91. package/lib/types/utils/decoratorTypeOf.d.ts +10 -0
  92. package/lib/types/utils/deepClone.d.ts +7 -3
  93. package/lib/types/utils/deepMerge.d.ts +30 -0
  94. package/lib/types/utils/descriptorOf.d.ts +15 -4
  95. package/lib/types/utils/getClassOrSymbol.d.ts +8 -0
  96. package/lib/types/utils/getConstructorArgNames.d.ts +10 -0
  97. package/lib/types/utils/getRandomId.d.ts +8 -0
  98. package/lib/types/utils/getValue.d.ts +7 -26
  99. package/lib/types/utils/hasJsonMethod.d.ts +6 -0
  100. package/lib/types/utils/http/getHostInfoFromPort.d.ts +15 -0
  101. package/lib/types/utils/inheritedDescriptorOf.d.ts +6 -0
  102. package/lib/types/utils/isArray.d.ts +8 -7
  103. package/lib/types/utils/isArrowFn.d.ts +6 -0
  104. package/lib/types/utils/isBoolean.d.ts +9 -2
  105. package/lib/types/utils/isBuffer.d.ts +10 -5
  106. package/lib/types/utils/isClass.d.ts +9 -0
  107. package/lib/types/utils/isCollection.d.ts +6 -3
  108. package/lib/types/utils/isDate.d.ts +3 -2
  109. package/lib/types/utils/isEmpty.d.ts +4 -3
  110. package/lib/types/utils/isEnumerable.d.ts +3 -2
  111. package/lib/types/utils/isFunction.d.ts +6 -0
  112. package/lib/types/utils/isInheritedFrom.d.ts +6 -0
  113. package/lib/types/utils/isMomentObject.d.ts +6 -0
  114. package/lib/types/utils/isMongooseObject.d.ts +13 -1
  115. package/lib/types/utils/isNil.d.ts +6 -0
  116. package/lib/types/utils/isNumber.d.ts +9 -2
  117. package/lib/types/utils/isObject.d.ts +6 -0
  118. package/lib/types/utils/isObservable.d.ts +8 -1
  119. package/lib/types/utils/isPlainObject.d.ts +9 -2
  120. package/lib/types/utils/isPrimitive.d.ts +14 -7
  121. package/lib/types/utils/isPromise.d.ts +4 -3
  122. package/lib/types/utils/isProtectedKey.d.ts +4 -2
  123. package/lib/types/utils/isRegExp.d.ts +6 -0
  124. package/lib/types/utils/isSerializable.d.ts +6 -0
  125. package/lib/types/utils/isStream.d.ts +6 -0
  126. package/lib/types/utils/isString.d.ts +10 -2
  127. package/lib/types/utils/isSymbol.d.ts +9 -1
  128. package/lib/types/utils/methodsOf.d.ts +4 -2
  129. package/lib/types/utils/nameOf.d.ts +12 -5
  130. package/lib/types/utils/objectKeys.d.ts +6 -0
  131. package/lib/types/utils/primitiveOf.d.ts +6 -0
  132. package/lib/types/utils/prototypeOf.d.ts +4 -3
  133. package/lib/types/utils/setValue.d.ts +20 -0
  134. package/lib/types/utils/toMap.d.ts +18 -0
  135. package/lib/types/utils/toStringConstructor.d.ts +10 -0
  136. package/lib/types/utils/uniq.d.ts +10 -1
  137. package/lib/types/utils/useDecorators.d.ts +6 -0
  138. package/lib/types/utils/useMethodDecorators.d.ts +12 -0
  139. package/package.json +5 -5
@@ -1,9 +1,13 @@
1
1
  import { Store } from "../types/Store.js";
2
2
  /**
3
- * Create a store correctly configured from the parameters given by the decorator.
4
- * The `fn` can return a decorator that will be initialized with the parameters (target, propertyKey, descriptor).
5
- * @param {(store: Store, parameters: DecoratorParameters) => void} fn
6
- * @returns {Function}
3
+ * Creates a decorator factory that initializes a Store from decorator parameters and invokes a callback.
4
+ *
5
+ * The callback receives both the Store instance and the original decorator parameters.
6
+ * If the callback returns a function, that function is invoked with the same decorator parameters.
7
+ *
8
+ * @public
9
+ * @since v7.0.0
10
+ * @see Store
7
11
  */
8
12
  export function StoreFn(fn) {
9
13
  return (...parameters) => {
@@ -1,4 +1,14 @@
1
1
  import { StoreFn } from "./storeFn.js";
2
+ /**
3
+ * Creates a decorator that merges a key-value pair into the target's Store metadata.
4
+ *
5
+ * Uses {@link Store.merge} internally to deep-merge the provided value with existing metadata.
6
+ *
7
+ * @public
8
+ * @since v7.0.0
9
+ * @see StoreFn
10
+ * @see Store
11
+ */
2
12
  export function StoreMerge(key, value) {
3
13
  return StoreFn((store) => {
4
14
  store.merge(key, value);
@@ -1,4 +1,14 @@
1
1
  import { StoreFn } from "./storeFn.js";
2
+ /**
3
+ * Creates a decorator that sets a key-value pair in the target's Store metadata.
4
+ *
5
+ * Uses {@link Store.set} internally to directly set the provided value (no merging).
6
+ *
7
+ * @public
8
+ * @since v7.0.0
9
+ * @see StoreFn
10
+ * @see Store
11
+ */
2
12
  export function StoreSet(key, value) {
3
13
  return StoreFn((store) => {
4
14
  store.set(key, value);
@@ -1,6 +1,14 @@
1
1
  import { classOf } from "../utils/classOf.js";
2
2
  import { decoratorTypeOf } from "../utils/decoratorTypeOf.js";
3
3
  import { nameOf } from "../utils/nameOf.js";
4
+ /**
5
+ * Error thrown when a decorator is used in an unsupported location or context.
6
+ *
7
+ * Provides a descriptive message indicating where the decorator was applied and why it's invalid.
8
+ *
9
+ * @public
10
+ * @since v7.0.0
11
+ */
4
12
  export class UnsupportedDecoratorType extends Error {
5
13
  constructor(decorator, args) {
6
14
  super(UnsupportedDecoratorType.buildMessage(decorator, args));
@@ -1,11 +1,27 @@
1
+ /**
2
+ * Normalized decorator kinds recognized by Ts.ED.
3
+ *
4
+ * This enum helps identify, at runtime, the element a decorator applies to
5
+ * (parameter, property, method, class, and static/constructor variants).
6
+ *
7
+ * @public
8
+ */
1
9
  export var DecoratorTypes;
2
10
  (function (DecoratorTypes) {
11
+ /** Decorator applied to an instance parameter */
3
12
  DecoratorTypes["PARAM"] = "parameter";
13
+ /** Decorator applied to a constructor parameter */
4
14
  DecoratorTypes["PARAM_CTOR"] = "parameter.constructor";
15
+ /** Decorator applied to a static method parameter */
5
16
  DecoratorTypes["PARAM_STC"] = "parameter.static";
17
+ /** Decorator applied to an instance property */
6
18
  DecoratorTypes["PROP"] = "property";
19
+ /** Decorator applied to a static property */
7
20
  DecoratorTypes["PROP_STC"] = "property.static";
21
+ /** Decorator applied to an instance method */
8
22
  DecoratorTypes["METHOD"] = "method";
23
+ /** Decorator applied to a static method */
9
24
  DecoratorTypes["METHOD_STC"] = "method.static";
25
+ /** Decorator applied to a class */
10
26
  DecoratorTypes["CLASS"] = "class";
11
27
  })(DecoratorTypes || (DecoratorTypes = {}));
@@ -1,5 +1,10 @@
1
1
  /**
2
+ * Represents the current application runtime environment.
2
3
  *
4
+ * Used by Ts.ED to adapt behaviors (logging, error verbosity, defaults, etc.)
5
+ * depending on the environment.
6
+ *
7
+ * @public
3
8
  */
4
9
  export var Env;
5
10
  (function (Env) {
@@ -8,8 +13,9 @@ export var Env;
8
13
  Env["TEST"] = "test";
9
14
  })(Env || (Env = {}));
10
15
  /**
11
- * Fallback
12
- * @type {Env}
16
+ * Compatibility alias. Prefer using `Env` directly.
17
+ *
18
+ * @deprecated Use `Env` directly.
13
19
  */
14
20
  // tslint:disable-next-line: variable-name
15
21
  export const EnvTypes = Env;
@@ -25,6 +25,15 @@ const DESIGN_RETURN_TYPE = "design:returntype";
25
25
  */
26
26
  const PROPERTIES = new Map();
27
27
  /**
28
+ * Static helper around `reflect-metadata` to read and write metadata on classes,
29
+ * methods, properties and parameters.
30
+ *
31
+ * This is the single entry point used across Ts.ED core to interact with
32
+ * design-time type information (e.g. param types, return types) and custom
33
+ * metadata keys. Only the exported class symbol is documented here per the
34
+ * symbols-only rule; individual members are intentionally not described.
35
+ *
36
+ * @public
28
37
  * @stable
29
38
  */
30
39
  export class Metadata {
@@ -7,18 +7,22 @@ import { nameOf } from "../utils/nameOf.js";
7
7
  import { DecoratorTypes } from "./DecoratorTypes.js";
8
8
  import { Metadata } from "./Metadata.js";
9
9
  /**
10
+ * Metadata key used to reference the class-level store.
10
11
  * @ignore
11
12
  */
12
13
  export const CLASS_STORE = "tsed:class:store";
13
14
  /**
15
+ * Metadata key used to reference the method-level store.
14
16
  * @ignore
15
17
  */
16
18
  export const METHOD_STORE = "tsed:method:store";
17
19
  /**
20
+ * Metadata key used to reference the property-level store.
18
21
  * @ignore
19
22
  */
20
23
  export const PROPERTY_STORE = "tsed:property:store";
21
24
  /**
25
+ * Metadata key used to reference the parameter-level store.
22
26
  * @ignore
23
27
  */
24
28
  export const PARAM_STORE = "tsed:param:store";
@@ -59,6 +63,16 @@ function defineStore(args) {
59
63
  return storeGet(CLASS_STORE, target);
60
64
  }
61
65
  }
66
+ /**
67
+ * Lightweight key/value registry used to attach and retrieve metadata at
68
+ * class, method, property, and parameter levels.
69
+ *
70
+ * The `Store` is used internally by decorators and utilities to group
71
+ * metadata by symbol. Only the exported class is documented per the
72
+ * symbols-only rule; members are intentionally not described here.
73
+ *
74
+ * @public
75
+ */
62
76
  export class Store {
63
77
  constructor() {
64
78
  this._entries = new Map();
@@ -1,5 +1,7 @@
1
1
  /**
2
- * An example of a `Type` is `MyCustomComponent` filters, which in JavaScript is represented by
3
- * the `MyCustomComponent` constructor function.
2
+ * Alias of the JavaScript base constructor, used to preserve
3
+ * compatibility with certain inference contexts.
4
+ *
5
+ * @deprecated Avoid using this constant directly; prefer the `Type<T>` type.
4
6
  */
5
7
  export const Type = Function;
@@ -11,6 +11,11 @@ function isResponse(obj) {
11
11
  /**
12
12
  * @ignore
13
13
  */
14
+ /**
15
+ * Represents the lifecycle state of an `AnyToPromise` operation.
16
+ *
17
+ * @public
18
+ */
14
19
  export var AnyToPromiseStatus;
15
20
  (function (AnyToPromiseStatus) {
16
21
  AnyToPromiseStatus["PENDING"] = "PENDING";
@@ -18,12 +23,27 @@ export var AnyToPromiseStatus;
18
23
  AnyToPromiseStatus["RESOLVED"] = "RESOLVED";
19
24
  AnyToPromiseStatus["REJECTED"] = "REJECTED";
20
25
  })(AnyToPromiseStatus || (AnyToPromiseStatus = {}));
26
+ /**
27
+ * Describes the high-level response kind produced by `AnyToPromise`.
28
+ *
29
+ * @public
30
+ */
21
31
  export var AnyToPromiseResponseTypes;
22
32
  (function (AnyToPromiseResponseTypes) {
23
33
  AnyToPromiseResponseTypes["STREAM"] = "STREAM";
24
34
  AnyToPromiseResponseTypes["BUFFER"] = "BUFFER";
25
35
  AnyToPromiseResponseTypes["DATA"] = "DATA";
26
36
  })(AnyToPromiseResponseTypes || (AnyToPromiseResponseTypes = {}));
37
+ /**
38
+ * Utility that normalizes various async-like values (Promise, Observable, Stream, plain value)
39
+ * into a single Promise-based flow with a consistent result shape.
40
+ *
41
+ * This class is used internally to handle controller/middleware outputs, but can be
42
+ * reused anywhere a unified async handling is desired.
43
+ *
44
+ * @typeParam T Type of the resulting payload.
45
+ * @public
46
+ */
27
47
  export class AnyToPromise {
28
48
  #resolves;
29
49
  #rejects;
@@ -1,6 +1,23 @@
1
+ /**
2
+ * Returns the immediate prototype (ancestor) of the given target.
3
+ *
4
+ * Internally uses `Object.getPrototypeOf` to retrieve the prototype chain ancestor.
5
+ *
6
+ * @public
7
+ * @since v7.0.0
8
+ */
1
9
  export function ancestorOf(target) {
2
10
  return target && Object.getPrototypeOf(target);
3
11
  }
12
+ /**
13
+ * Returns the inherited class (ancestor) of the given target.
14
+ *
15
+ * An alias for {@link ancestorOf}.
16
+ *
17
+ * @public
18
+ * @since v7.0.0
19
+ * @see ancestorOf
20
+ */
4
21
  export function getInheritedClass(target) {
5
22
  return ancestorOf(target);
6
23
  }
@@ -2,9 +2,15 @@ import { getInheritedClass } from "./ancestorOf.js";
2
2
  import { classOf } from "./classOf.js";
3
3
  import { nameOf } from "./nameOf.js";
4
4
  /**
5
+ * Returns all ancestor classes in the prototype chain of the target.
5
6
  *
6
- * @param target
7
- * @returns {Array}
7
+ * Traverses the prototype chain from the target's class up to the root,
8
+ * returning an array of all named constructor functions encountered.
9
+ *
10
+ * @public
11
+ * @since v7.0.0
12
+ * @see classOf
13
+ * @see getInheritedClass
8
14
  */
9
15
  export function ancestorsOf(target) {
10
16
  const classes = [];
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Executes a callback and returns any thrown error, or undefined if no error occurred.
3
+ *
4
+ * @public
5
+ * @since v7.0.0
6
+ */
1
7
  export function catchError(cb) {
2
8
  try {
3
9
  cb();
@@ -6,6 +12,12 @@ export function catchError(cb) {
6
12
  return er;
7
13
  }
8
14
  }
15
+ /**
16
+ * Executes an async callback and returns any thrown error, or undefined if no error occurred.
17
+ *
18
+ * @public
19
+ * @since v7.0.0
20
+ */
9
21
  export async function catchAsyncError(cb) {
10
22
  try {
11
23
  await cb();
@@ -1,16 +1,23 @@
1
1
  /**
2
- * Get the provide constructor if target is an instance.
3
- * @param target
4
- * @returns {*}
2
+ * Returns the constructor of a target. If `target` is already a class
3
+ * (constructor function), it is returned as is; if it is an instance,
4
+ * its constructor is returned.
5
+ *
6
+ * @param target Instance or constructor.
7
+ * @returns The constructor associated with the target.
8
+ * @example
9
+ * ```ts
10
+ * class A {}
11
+ * getClass(A) === A; // true
12
+ * getClass(new A()) === A; // true
13
+ * ```
5
14
  */
6
15
  export function getClass(target) {
7
16
  return target.prototype ? target : target.constructor;
8
17
  }
9
18
  /**
10
- * Get the provide constructor if target is an instance.
11
- * @param target
12
- * @returns {*}
13
- * @alias getClass
19
+ * Alias of `getClass`.
20
+ * @see getClass
14
21
  */
15
22
  export function classOf(target) {
16
23
  return getClass(target);
@@ -1,8 +1,12 @@
1
1
  import { isProtectedKey } from "./isProtectedKey.js";
2
2
  /**
3
- * Remove undefined value
4
- * @param obj
5
- * @param ignore
3
+ * Returns a copy of an object with undefined values, protected keys, and ignored keys removed.
4
+ *
5
+ * Filters out entries that are undefined, match protected key patterns, or are in the ignore list.
6
+ *
7
+ * @public
8
+ * @since v7.0.0
9
+ * @see isProtectedKey
6
10
  */
7
11
  export function cleanObject(obj, ignore = []) {
8
12
  return Object.entries(obj).reduce((obj, [key, value]) => {
@@ -1,13 +1,24 @@
1
1
  /**
2
- * Get the class constructor
3
- * @param target
2
+ * Get the class constructor from a class or an instance.
3
+ *
4
+ * If `target` is already a constructor, it is returned as-is; otherwise the
5
+ * constructor of the instance is returned.
6
+ *
7
+ * @param target A class constructor or an instance.
8
+ * @returns The class constructor function.
9
+ * @example
10
+ * ```ts
11
+ * class A {}
12
+ * getConstructor(A) === A; // true
13
+ * getConstructor(new A()) === A; // true
14
+ * ```
4
15
  */
5
16
  export function getConstructor(target) {
6
17
  return typeof target === "function" ? target : target.constructor;
7
18
  }
8
19
  /**
9
- * Get the class constructor
10
- * @param target
20
+ * Alias of `getConstructor`.
21
+ * @see getConstructor
11
22
  */
12
23
  export function constructorOf(target) {
13
24
  return getConstructor(target);
@@ -1,4 +1,15 @@
1
1
  import { classOf } from "./classOf.js";
2
+ /**
3
+ * Creates a lightweight object instance that inherits from the provided value's prototype.
4
+ *
5
+ * If the input is a class or instance whose constructor is not Object, this function
6
+ * returns `Object.create(obj)` to preserve the prototype chain without invoking the constructor.
7
+ * Otherwise, it returns a plain empty object.
8
+ *
9
+ * @public
10
+ * @since v7.0.0
11
+ * @see classOf
12
+ */
2
13
  export function createInstance(obj) {
3
14
  return obj ? (classOf(obj) !== Object ? Object.create(obj) : {}) : {};
4
15
  }
@@ -3,6 +3,17 @@ import { classOf } from "./classOf.js";
3
3
  import { descriptorOf } from "./descriptorOf.js";
4
4
  import { methodsOf } from "./methodsOf.js";
5
5
  import { prototypeOf } from "./prototypeOf.js";
6
+ /**
7
+ * Applies a decorator to all methods of a class, copying inherited methods if necessary.
8
+ *
9
+ * For each method, if inherited from a parent class, it first copies the method to the target class
10
+ * and merges its Store metadata, then applies the decorator.
11
+ *
12
+ * @public
13
+ * @since v7.0.0
14
+ * @see methodsOf
15
+ * @see Store
16
+ */
6
17
  export function decorateMethodsOf(klass, decorator) {
7
18
  methodsOf(klass).forEach(({ target, propertyKey }) => {
8
19
  const proto = prototypeOf(klass);
@@ -1,4 +1,14 @@
1
1
  import { descriptorOf } from "./descriptorOf.js";
2
+ /**
3
+ * Constructs decorator parameters (target, propertyKey, descriptor) for a given class member.
4
+ *
5
+ * Retrieves the property descriptor and returns a tuple compatible with decorator signatures.
6
+ *
7
+ * @public
8
+ * @since v7.0.0
9
+ * @see DecoratorParameters
10
+ * @see descriptorOf
11
+ */
2
12
  export function decoratorArgs(target, propertyKey) {
3
13
  return [target, propertyKey, descriptorOf(target, propertyKey)];
4
14
  }
@@ -1,12 +1,22 @@
1
1
  import { DecoratorTypes } from "../types/DecoratorTypes.js";
2
2
  import { classOf } from "./classOf.js";
3
+ /**
4
+ * Determines the decorator type from decorator parameters.
5
+ *
6
+ * Analyzes the target, propertyKey, and descriptor to classify the decorator as
7
+ * class, method, property, parameter, or their static variants.
8
+ *
9
+ * @public
10
+ * @since v7.0.0
11
+ * @see DecoratorTypes
12
+ */
3
13
  export function decoratorTypeOf(args) {
4
14
  const [target, propertyKey, descriptor] = args;
5
15
  const staticType = (type) => {
6
16
  return target !== classOf(target) ? type : `${type}.static`;
7
17
  };
8
18
  if (typeof descriptor === "number") {
9
- return propertyKey ? staticType("parameter") : "parameter.constructor";
19
+ return propertyKey ? staticType("parameter") : DecoratorTypes.PARAM_CTOR;
10
20
  }
11
21
  if (descriptor && descriptor.value) {
12
22
  return staticType("method");
@@ -7,9 +7,13 @@ import { isRegExp } from "./isRegExp.js";
7
7
  import { isSymbol } from "./isSymbol.js";
8
8
  const isBasicType = (source) => isNil(source) || isPrimitive(source) || isSymbol(source) || isFunction(source);
9
9
  /**
10
- * Return a cloned value
11
- * @param source
12
- * @param stack
10
+ * Creates a deep clone of the provided value, preserving prototype chains and handling circular references.
11
+ *
12
+ * Supports primitives, dates, regular expressions, typed arrays, buffers, maps, sets, and plain objects.
13
+ * Uses a WeakMap to track and handle circular references correctly.
14
+ *
15
+ * @public
16
+ * @since v7.0.0
13
17
  */
14
18
  export const deepClone = (source, stack = new WeakMap()) => {
15
19
  // provides an early exit for simple cases
@@ -3,6 +3,12 @@ import { isFunction } from "./isFunction.js";
3
3
  import { isPrimitive } from "./isPrimitive.js";
4
4
  import { isSymbol } from "./isSymbol.js";
5
5
  import { objectKeys } from "./objectKeys.js";
6
+ /**
7
+ * Creates a merge reducer using a custom comparator function.
8
+ *
9
+ * @public
10
+ * @since v7.0.0
11
+ */
6
12
  export function mergeReducerBuilder(cb) {
7
13
  return (collection, value, options) => {
8
14
  const index = collection.findIndex((item) => cb(item, value));
@@ -29,6 +35,15 @@ function shouldReturnObj(obj, source) {
29
35
  function shouldReturnSource(obj, source) {
30
36
  return obj === undefined || obj === null || (obj === "" && source !== "");
31
37
  }
38
+ /**
39
+ * Deeply merges two values, combining objects recursively and handling arrays with custom reducers.
40
+ *
41
+ * Supports primitives, arrays, and objects. Can clean undefined properties and apply custom transformations.
42
+ *
43
+ * @public
44
+ * @since v7.0.0
45
+ * @see DeepMergeOptions
46
+ */
32
47
  export function deepMerge(source, obj, options = {}) {
33
48
  if (shouldReturnSource(obj, source)) {
34
49
  return source;
@@ -1,12 +1,23 @@
1
1
  /**
2
- * Return the descriptor for a given class and propertyKey
3
- * @param target
4
- * @param {string} propertyKey
5
- * @returns {PropertyDescriptor}
2
+ * Retrieves the property descriptor for a given class and property key.
3
+ *
4
+ * Checks both the target and its prototype for the property descriptor.
5
+ *
6
+ * @public
7
+ * @since v7.0.0
6
8
  */
7
9
  export function descriptorOf(target, propertyKey) {
8
10
  return Reflect.getOwnPropertyDescriptor((target && target.prototype) || target, propertyKey);
9
11
  }
12
+ /**
13
+ * Checks whether a property descriptor represents a method.
14
+ *
15
+ * Returns true if the descriptor has a value property (indicating a method).
16
+ *
17
+ * @public
18
+ * @since v7.0.0
19
+ * @see descriptorOf
20
+ */
10
21
  export function isMethodDescriptor(target, propertyKey) {
11
22
  return descriptorOf(target, propertyKey)?.value;
12
23
  }
@@ -1,5 +1,13 @@
1
1
  import { classOf } from "./classOf.js";
2
2
  import { isClass } from "./isClass.js";
3
+ /**
4
+ * Retourne le constructeur de classe lorsque `target` est une classe/instance,
5
+ * sinon retourne la valeur telle quelle (utile pour les `symbol`).
6
+ *
7
+ * @param target Valeur potentiellement typée classe, instance, ou symbole.
8
+ * @returns Le constructeur de la classe ou la valeur originale si ce n'est pas une classe.
9
+ * @public
10
+ */
3
11
  export function getClassOrSymbol(target) {
4
12
  return isClass(target) ? classOf(target) : target;
5
13
  }
@@ -1,4 +1,14 @@
1
1
  import { toStringConstructor } from "./toStringConstructor.js";
2
+ /**
3
+ * Extracts constructor parameter names from a class constructor.
4
+ *
5
+ * Parses the constructor's string representation to retrieve parameter names.
6
+ * Returns an array of trimmed, non-empty parameter names.
7
+ *
8
+ * @public
9
+ * @since v7.0.0
10
+ * @see toStringConstructor
11
+ */
2
12
  export function getConstructorArgNames(target) {
3
13
  return toStringConstructor(target)
4
14
  .split("constructor(")[1]
@@ -1,3 +1,11 @@
1
+ /**
2
+ * Generates a random identifier string starting with 'e'.
3
+ *
4
+ * Uses base-36 encoding of a random number to create a unique identifier.
5
+ *
6
+ * @public
7
+ * @since v7.0.0
8
+ */
1
9
  export function getRandomId() {
2
10
  return `e${Math.random().toString(36).substring(7)}`;
3
11
  }
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Checks whether an object has a toJSON method.
3
+ *
4
+ * @public
5
+ * @since v7.0.0
6
+ */
1
7
  export function hasJsonMethod(obj) {
2
8
  return obj && typeof obj.toJSON === "function";
3
9
  }
@@ -1,3 +1,12 @@
1
+ /**
2
+ * Parses an address-port combination and returns host information with protocol.
3
+ *
4
+ * Accepts either a numeric port or a string in the format "address:port".
5
+ * Returns an object with protocol, address, port, and a toString method for URL formatting.
6
+ *
7
+ * @public
8
+ * @since v7.0.0
9
+ */
1
10
  export function getHostInfoFromPort(protocol, addressPort) {
2
11
  let address = "0.0.0.0";
3
12
  let port = addressPort;
@@ -1,4 +1,10 @@
1
1
  import { ancestorsOf } from "./ancestorsOf.js";
2
+ /**
3
+ * Retrieves the property descriptor for a given property key from the target's inheritance chain.
4
+ *
5
+ * @public
6
+ * @since v7.0.0
7
+ */
2
8
  export function inheritedDescriptorOf(target, propertyKey) {
3
9
  for (const klass of ancestorsOf(target)) {
4
10
  const descriptor = Object.getOwnPropertyDescriptor((klass && klass.prototype) || klass, propertyKey);
@@ -1,16 +1,17 @@
1
1
  /**
2
- * Return true if value is an array
3
- * @param target
4
- * @returns {boolean}
2
+ * Checks if a value is an array.
3
+ *
4
+ * @public
5
+ * @since v7.0.0
5
6
  */
6
7
  export function isArray(target) {
7
8
  return Array.isArray(target);
8
9
  }
9
10
  /**
10
- * Return true if the clazz is an array.
11
- * @param target
12
- * @returns {boolean}
13
- * @ignore
11
+ * Checks if a value is the Array constructor or an array instance.
12
+ *
13
+ * @public
14
+ * @since v7.0.0
14
15
  */
15
16
  export function isArrayOrArrayClass(target) {
16
17
  return target === Array || isArray(target);
@@ -1,4 +1,10 @@
1
1
  import { isFunction } from "./isFunction.js";
2
+ /**
3
+ * Checks if a value is an arrow function by verifying it has no prototype property.
4
+ *
5
+ * @public
6
+ * @since v7.0.0
7
+ */
2
8
  export function isArrowFn(target) {
3
9
  return target && isFunction(target) && !target.prototype;
4
10
  }
@@ -1,11 +1,18 @@
1
1
  /**
2
+ * Checks if a value is a boolean primitive.
2
3
  *
3
- * @param target
4
- * @returns {boolean}
4
+ * @public
5
+ * @since v7.0.0
5
6
  */
6
7
  export function isBoolean(target) {
7
8
  return typeof target === "boolean" || target instanceof Boolean || target === Boolean;
8
9
  }
10
+ /**
11
+ * Checks if a value is a boolean primitive, Boolean object, or the Boolean constructor.
12
+ *
13
+ * @public
14
+ * @since v7.0.0
15
+ */
9
16
  export function isBooleanOrBooleanClass(target) {
10
17
  return typeof target === "boolean" || target instanceof Boolean || target === Boolean;
11
18
  }