@tsed/core 8.11.1 → 8.11.2-rc.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 (259) hide show
  1. package/lib/esm/decorators/storeFn.js +0 -1
  2. package/lib/esm/decorators/storeMerge.js +0 -1
  3. package/lib/esm/decorators/storeSet.js +0 -1
  4. package/lib/esm/errors/UnsupportedDecoratorType.js +0 -1
  5. package/lib/esm/index.js +0 -1
  6. package/lib/esm/types/AnyDecorator.js +0 -1
  7. package/lib/esm/types/DecoratorParameters.js +0 -1
  8. package/lib/esm/types/DecoratorTypes.js +0 -1
  9. package/lib/esm/types/Env.js +0 -1
  10. package/lib/esm/types/Metadata.js +0 -1
  11. package/lib/esm/types/MetadataTypes.js +0 -1
  12. package/lib/esm/types/Relation.js +0 -1
  13. package/lib/esm/types/Store.js +0 -1
  14. package/lib/esm/types/Type.js +0 -1
  15. package/lib/esm/types/ValueOf.js +0 -1
  16. package/lib/esm/utils/AnyToPromise.js +0 -1
  17. package/lib/esm/utils/ancestorOf.js +0 -1
  18. package/lib/esm/utils/ancestorsOf.js +0 -1
  19. package/lib/esm/utils/catchError.js +0 -1
  20. package/lib/esm/utils/classOf.js +0 -1
  21. package/lib/esm/utils/cleanObject.js +0 -1
  22. package/lib/esm/utils/constructorOf.js +0 -1
  23. package/lib/esm/utils/createInstance.js +0 -1
  24. package/lib/esm/utils/decorateMethodsOf.js +0 -1
  25. package/lib/esm/utils/decoratorArgs.js +0 -1
  26. package/lib/esm/utils/decoratorTypeOf.js +0 -1
  27. package/lib/esm/utils/deepClone.js +0 -1
  28. package/lib/esm/utils/deepMerge.js +0 -1
  29. package/lib/esm/utils/descriptorOf.js +0 -1
  30. package/lib/esm/utils/getClassOrSymbol.js +0 -1
  31. package/lib/esm/utils/getConstructorArgNames.js +0 -1
  32. package/lib/esm/utils/getRandomId.js +0 -1
  33. package/lib/esm/utils/getValue.js +0 -1
  34. package/lib/esm/utils/hasJsonMethod.js +0 -1
  35. package/lib/esm/utils/http/getHostInfoFromPort.js +0 -1
  36. package/lib/esm/utils/inheritedDescriptorOf.js +0 -1
  37. package/lib/esm/utils/isArray.js +0 -1
  38. package/lib/esm/utils/isArrowFn.js +0 -1
  39. package/lib/esm/utils/isBoolean.js +0 -1
  40. package/lib/esm/utils/isBuffer.js +0 -1
  41. package/lib/esm/utils/isClass.js +0 -1
  42. package/lib/esm/utils/isCollection.js +0 -1
  43. package/lib/esm/utils/isDate.js +0 -1
  44. package/lib/esm/utils/isEmpty.js +0 -1
  45. package/lib/esm/utils/isEnumerable.js +0 -1
  46. package/lib/esm/utils/isFunction.js +0 -1
  47. package/lib/esm/utils/isInheritedFrom.js +0 -1
  48. package/lib/esm/utils/isMomentObject.js +0 -1
  49. package/lib/esm/utils/isMongooseObject.js +0 -1
  50. package/lib/esm/utils/isNil.js +0 -1
  51. package/lib/esm/utils/isNumber.js +0 -1
  52. package/lib/esm/utils/isObject.js +0 -1
  53. package/lib/esm/utils/isObservable.js +0 -1
  54. package/lib/esm/utils/isPlainObject.js +0 -1
  55. package/lib/esm/utils/isPrimitive.js +0 -1
  56. package/lib/esm/utils/isPromise.js +0 -1
  57. package/lib/esm/utils/isProtectedKey.js +0 -1
  58. package/lib/esm/utils/isRegExp.js +0 -1
  59. package/lib/esm/utils/isSerializable.js +0 -1
  60. package/lib/esm/utils/isStream.js +0 -1
  61. package/lib/esm/utils/isString.js +0 -1
  62. package/lib/esm/utils/isSymbol.js +0 -1
  63. package/lib/esm/utils/methodsOf.js +0 -1
  64. package/lib/esm/utils/nameOf.js +0 -1
  65. package/lib/esm/utils/objectKeys.js +0 -1
  66. package/lib/esm/utils/primitiveOf.js +0 -1
  67. package/lib/esm/utils/prototypeOf.js +0 -1
  68. package/lib/esm/utils/setValue.js +0 -1
  69. package/lib/esm/utils/toMap.js +0 -1
  70. package/lib/esm/utils/toStringConstructor.js +0 -1
  71. package/lib/esm/utils/uniq.js +0 -1
  72. package/lib/esm/utils/useDecorators.js +0 -1
  73. package/lib/esm/utils/useMethodDecorators.js +0 -1
  74. package/package.json +8 -5
  75. package/.barrelsby.json +0 -5
  76. package/lib/esm/decorators/storeFn.js.map +0 -1
  77. package/lib/esm/decorators/storeMerge.js.map +0 -1
  78. package/lib/esm/decorators/storeSet.js.map +0 -1
  79. package/lib/esm/errors/UnsupportedDecoratorType.js.map +0 -1
  80. package/lib/esm/index.js.map +0 -1
  81. package/lib/esm/types/AnyDecorator.js.map +0 -1
  82. package/lib/esm/types/DecoratorParameters.js.map +0 -1
  83. package/lib/esm/types/DecoratorTypes.js.map +0 -1
  84. package/lib/esm/types/Env.js.map +0 -1
  85. package/lib/esm/types/Metadata.js.map +0 -1
  86. package/lib/esm/types/MetadataTypes.js.map +0 -1
  87. package/lib/esm/types/Relation.js.map +0 -1
  88. package/lib/esm/types/Store.js.map +0 -1
  89. package/lib/esm/types/Type.js.map +0 -1
  90. package/lib/esm/types/ValueOf.js.map +0 -1
  91. package/lib/esm/utils/AnyToPromise.js.map +0 -1
  92. package/lib/esm/utils/ancestorOf.js.map +0 -1
  93. package/lib/esm/utils/ancestorsOf.js.map +0 -1
  94. package/lib/esm/utils/catchError.js.map +0 -1
  95. package/lib/esm/utils/classOf.js.map +0 -1
  96. package/lib/esm/utils/cleanObject.js.map +0 -1
  97. package/lib/esm/utils/constructorOf.js.map +0 -1
  98. package/lib/esm/utils/createInstance.js.map +0 -1
  99. package/lib/esm/utils/decorateMethodsOf.js.map +0 -1
  100. package/lib/esm/utils/decoratorArgs.js.map +0 -1
  101. package/lib/esm/utils/decoratorTypeOf.js.map +0 -1
  102. package/lib/esm/utils/deepClone.js.map +0 -1
  103. package/lib/esm/utils/deepMerge.js.map +0 -1
  104. package/lib/esm/utils/descriptorOf.js.map +0 -1
  105. package/lib/esm/utils/getClassOrSymbol.js.map +0 -1
  106. package/lib/esm/utils/getConstructorArgNames.js.map +0 -1
  107. package/lib/esm/utils/getRandomId.js.map +0 -1
  108. package/lib/esm/utils/getValue.js.map +0 -1
  109. package/lib/esm/utils/hasJsonMethod.js.map +0 -1
  110. package/lib/esm/utils/http/getHostInfoFromPort.js.map +0 -1
  111. package/lib/esm/utils/inheritedDescriptorOf.js.map +0 -1
  112. package/lib/esm/utils/isArray.js.map +0 -1
  113. package/lib/esm/utils/isArrowFn.js.map +0 -1
  114. package/lib/esm/utils/isBoolean.js.map +0 -1
  115. package/lib/esm/utils/isBuffer.js.map +0 -1
  116. package/lib/esm/utils/isClass.js.map +0 -1
  117. package/lib/esm/utils/isCollection.js.map +0 -1
  118. package/lib/esm/utils/isDate.js.map +0 -1
  119. package/lib/esm/utils/isEmpty.js.map +0 -1
  120. package/lib/esm/utils/isEnumerable.js.map +0 -1
  121. package/lib/esm/utils/isFunction.js.map +0 -1
  122. package/lib/esm/utils/isInheritedFrom.js.map +0 -1
  123. package/lib/esm/utils/isMomentObject.js.map +0 -1
  124. package/lib/esm/utils/isMongooseObject.js.map +0 -1
  125. package/lib/esm/utils/isNil.js.map +0 -1
  126. package/lib/esm/utils/isNumber.js.map +0 -1
  127. package/lib/esm/utils/isObject.js.map +0 -1
  128. package/lib/esm/utils/isObservable.js.map +0 -1
  129. package/lib/esm/utils/isPlainObject.js.map +0 -1
  130. package/lib/esm/utils/isPrimitive.js.map +0 -1
  131. package/lib/esm/utils/isPromise.js.map +0 -1
  132. package/lib/esm/utils/isProtectedKey.js.map +0 -1
  133. package/lib/esm/utils/isRegExp.js.map +0 -1
  134. package/lib/esm/utils/isSerializable.js.map +0 -1
  135. package/lib/esm/utils/isStream.js.map +0 -1
  136. package/lib/esm/utils/isString.js.map +0 -1
  137. package/lib/esm/utils/isSymbol.js.map +0 -1
  138. package/lib/esm/utils/methodsOf.js.map +0 -1
  139. package/lib/esm/utils/nameOf.js.map +0 -1
  140. package/lib/esm/utils/objectKeys.js.map +0 -1
  141. package/lib/esm/utils/primitiveOf.js.map +0 -1
  142. package/lib/esm/utils/prototypeOf.js.map +0 -1
  143. package/lib/esm/utils/setValue.js.map +0 -1
  144. package/lib/esm/utils/toMap.js.map +0 -1
  145. package/lib/esm/utils/toStringConstructor.js.map +0 -1
  146. package/lib/esm/utils/uniq.js.map +0 -1
  147. package/lib/esm/utils/useDecorators.js.map +0 -1
  148. package/lib/esm/utils/useMethodDecorators.js.map +0 -1
  149. package/src/decorators/storeFn.ts +0 -20
  150. package/src/decorators/storeMerge.ts +0 -8
  151. package/src/decorators/storeSet.ts +0 -8
  152. package/src/errors/UnsupportedDecoratorType.spec.ts +0 -81
  153. package/src/errors/UnsupportedDecoratorType.ts +0 -25
  154. package/src/index.ts +0 -75
  155. package/src/types/AnyDecorator.ts +0 -1
  156. package/src/types/DecoratorParameters.ts +0 -8
  157. package/src/types/DecoratorTypes.ts +0 -10
  158. package/src/types/Env.ts +0 -15
  159. package/src/types/Metadata.spec.ts +0 -142
  160. package/src/types/Metadata.ts +0 -523
  161. package/src/types/MetadataTypes.ts +0 -6
  162. package/src/types/Relation.ts +0 -1
  163. package/src/types/Store.spec.ts +0 -164
  164. package/src/types/Store.ts +0 -175
  165. package/src/types/Type.ts +0 -20
  166. package/src/types/ValueOf.ts +0 -1
  167. package/src/utils/AnyToPromise.spec.ts +0 -159
  168. package/src/utils/AnyToPromise.ts +0 -181
  169. package/src/utils/ObjectUtils.spec.ts +0 -322
  170. package/src/utils/ancestorOf.ts +0 -7
  171. package/src/utils/ancestorsOf.ts +0 -21
  172. package/src/utils/catchError.spec.ts +0 -17
  173. package/src/utils/catchError.ts +0 -15
  174. package/src/utils/classOf.ts +0 -18
  175. package/src/utils/cleanObject.spec.ts +0 -22
  176. package/src/utils/cleanObject.ts +0 -20
  177. package/src/utils/constructorOf.ts +0 -17
  178. package/src/utils/createInstance.ts +0 -5
  179. package/src/utils/decorateMethodsOf.spec.ts +0 -83
  180. package/src/utils/decorateMethodsOf.ts +0 -31
  181. package/src/utils/decoratorArgs.spec.ts +0 -15
  182. package/src/utils/decoratorArgs.ts +0 -6
  183. package/src/utils/decoratorTypeOf.spec.ts +0 -92
  184. package/src/utils/decoratorTypeOf.ts +0 -24
  185. package/src/utils/deepClone.spec.ts +0 -130
  186. package/src/utils/deepClone.ts +0 -85
  187. package/src/utils/deepMerge.spec.ts +0 -223
  188. package/src/utils/deepMerge.ts +0 -85
  189. package/src/utils/descriptorOf.spec.ts +0 -16
  190. package/src/utils/descriptorOf.ts +0 -13
  191. package/src/utils/getClassOrSymbol.ts +0 -6
  192. package/src/utils/getConstructorArgNames.spec.ts +0 -11
  193. package/src/utils/getConstructorArgNames.ts +0 -10
  194. package/src/utils/getRandomId.spec.ts +0 -7
  195. package/src/utils/getRandomId.ts +0 -3
  196. package/src/utils/getValue.spec.ts +0 -62
  197. package/src/utils/getValue.ts +0 -87
  198. package/src/utils/hasJsonMethod.spec.ts +0 -11
  199. package/src/utils/hasJsonMethod.ts +0 -3
  200. package/src/utils/http/getHostInfoFromPort.spec.ts +0 -25
  201. package/src/utils/http/getHostInfoFromPort.ts +0 -20
  202. package/src/utils/inheritedDescriptorOf.ts +0 -13
  203. package/src/utils/isArray.ts +0 -18
  204. package/src/utils/isArrowFn.ts +0 -5
  205. package/src/utils/isBoolean.ts +0 -12
  206. package/src/utils/isBuffer.spec.ts +0 -14
  207. package/src/utils/isBuffer.ts +0 -19
  208. package/src/utils/isClass.spec.ts +0 -15
  209. package/src/utils/isClass.ts +0 -28
  210. package/src/utils/isCollection.ts +0 -20
  211. package/src/utils/isDate.ts +0 -8
  212. package/src/utils/isEmpty.spec.ts +0 -10
  213. package/src/utils/isEmpty.ts +0 -10
  214. package/src/utils/isEnumerable.ts +0 -21
  215. package/src/utils/isFunction.ts +0 -3
  216. package/src/utils/isInheritedFrom.ts +0 -26
  217. package/src/utils/isMomentObject.spec.ts +0 -16
  218. package/src/utils/isMomentObject.ts +0 -3
  219. package/src/utils/isMongooseObject.spec.ts +0 -22
  220. package/src/utils/isMongooseObject.ts +0 -9
  221. package/src/utils/isNil.spec.ts +0 -10
  222. package/src/utils/isNil.ts +0 -3
  223. package/src/utils/isNumber.ts +0 -12
  224. package/src/utils/isObject.ts +0 -3
  225. package/src/utils/isObservable.ts +0 -3
  226. package/src/utils/isPlainObject.spec.ts +0 -10
  227. package/src/utils/isPlainObject.ts +0 -14
  228. package/src/utils/isPrimitive.spec.ts +0 -17
  229. package/src/utils/isPrimitive.ts +0 -26
  230. package/src/utils/isPromise.ts +0 -13
  231. package/src/utils/isProtectedKey.spec.ts +0 -14
  232. package/src/utils/isProtectedKey.ts +0 -7
  233. package/src/utils/isRegExp.ts +0 -3
  234. package/src/utils/isSerializable.spec.ts +0 -14
  235. package/src/utils/isSerializable.ts +0 -9
  236. package/src/utils/isStream.ts +0 -3
  237. package/src/utils/isString.ts +0 -11
  238. package/src/utils/isSymbol.spec.ts +0 -11
  239. package/src/utils/isSymbol.ts +0 -11
  240. package/src/utils/methodsOf.spec.ts +0 -33
  241. package/src/utils/methodsOf.ts +0 -26
  242. package/src/utils/nameOf.ts +0 -27
  243. package/src/utils/objectKeys.spec.ts +0 -10
  244. package/src/utils/objectKeys.ts +0 -5
  245. package/src/utils/primitiveOf.ts +0 -19
  246. package/src/utils/prototypeOf.ts +0 -10
  247. package/src/utils/setValue.spec.ts +0 -60
  248. package/src/utils/setValue.ts +0 -35
  249. package/src/utils/toMap.spec.ts +0 -211
  250. package/src/utils/toMap.ts +0 -44
  251. package/src/utils/toStringConstructor.ts +0 -9
  252. package/src/utils/toStringConstrutor.spec.ts +0 -18
  253. package/src/utils/uniq.spec.ts +0 -8
  254. package/src/utils/uniq.ts +0 -16
  255. package/src/utils/useDecorators.spec.ts +0 -61
  256. package/src/utils/useDecorators.ts +0 -21
  257. package/src/utils/useMethodDecorator.spec.ts +0 -45
  258. package/src/utils/useMethodDecorators.ts +0 -12
  259. package/vitest.config.mts +0 -21
@@ -1,142 +0,0 @@
1
- import {Metadata} from "./Metadata.js";
2
-
3
- function logger(target: any, method?: any, descriptor?: any) {
4
- return descriptor;
5
- }
6
-
7
- @logger
8
- class Test {
9
- @logger
10
- attribut: string = "";
11
-
12
- // tslint:disable-next-line: no-unused-variable
13
- constructor(private type?: string) {}
14
-
15
- static methodStatic() {}
16
-
17
- @logger
18
- method(type: string): boolean {
19
- return true;
20
- }
21
- }
22
-
23
- class Test2 {
24
- attribut: any;
25
-
26
- constructor() {}
27
-
28
- static methodStatic() {}
29
-
30
- method() {}
31
- }
32
-
33
- describe("Metadata", () => {
34
- describe("has", () => {
35
- it("should return false (String)", () => {
36
- expect(Metadata.has("testunknow", String)).toBe(false);
37
- });
38
-
39
- it("should return false (bad target)", () => {
40
- expect(Metadata.has("testunknow", undefined)).toBe(false);
41
- });
42
- });
43
-
44
- describe("set", () => {
45
- it("should set meta on a class", () => {
46
- expect(Metadata.set("metadatakey1", "test1", Test)).toBeUndefined();
47
- expect(Metadata.has("metadatakey1", Test)).toBe(true);
48
- });
49
-
50
- it("should set meta on instance", () => {
51
- expect(Metadata.set("metadatakey2", "test2", new Test())).toBeUndefined();
52
- expect(Metadata.has("metadatakey2", Test)).toBe(true);
53
- });
54
-
55
- it("should set meta on a method", () => {
56
- expect(Metadata.set("metadatakey3", "test1", Test, "method")).toBeUndefined();
57
- expect(Metadata.has("metadatakey3", Test, "method")).toBe(true);
58
- });
59
- });
60
-
61
- describe("get", () => {
62
- it("should get meta on a class", () => {
63
- expect(Metadata.get("metadatakey1", Test)).toBe("test1");
64
- });
65
-
66
- it("should get meta on a method", () => {
67
- expect(Metadata.get("metadatakey3", Test, "method")).toBe("test1");
68
- });
69
- });
70
-
71
- describe("getOwn", () => {
72
- it("should get meta on a class", () => {
73
- expect(Metadata.getOwn("metadatakey1", Test)).toBe("test1");
74
- });
75
-
76
- it("should get meta on a method", () => {
77
- expect(Metadata.getOwn("metadatakey3", Test, "method")).toBe("test1");
78
- });
79
- });
80
-
81
- describe("delete", () => {
82
- it("should remove meta on a class", () => {
83
- expect(Metadata.delete("metadatakey1", Test)).toBe(true);
84
- });
85
- });
86
-
87
- describe("getType", () => {
88
- it("should return attribut type", () => {
89
- expect(Metadata.getType(Test.prototype, "attribut")).toBe(String);
90
- });
91
- });
92
-
93
- describe("getOwnType", () => {
94
- it("should return attribut type", () => {
95
- expect(Metadata.getOwnType(Test.prototype, "attribut")).toBe(String);
96
- });
97
- });
98
-
99
- describe("getParamTypes", () => {
100
- it("should return types on constructor", () => {
101
- expect(Metadata.getParamTypes(Test)).toBeInstanceOf(Array);
102
- expect(Metadata.getParamTypes(Test)[0]).toBe(String);
103
- });
104
-
105
- it("should return types on method", () => {
106
- expect(Metadata.getParamTypes(Test.prototype, "method")).toBeInstanceOf(Array);
107
- expect(Metadata.getParamTypes(Test.prototype, "method")[0]).toBe(String);
108
- });
109
- });
110
-
111
- describe("getOwnParamTypes", () => {
112
- it("should return types on constructor", () => {
113
- expect(Metadata.getOwnParamTypes(Test)).toBeInstanceOf(Array);
114
- expect(Metadata.getOwnParamTypes(Test)[0]).toBe(String);
115
- });
116
-
117
- it("should return types on method", () => {
118
- expect(Metadata.getOwnParamTypes(Test.prototype, "method")).toBeInstanceOf(Array);
119
- expect(Metadata.getOwnParamTypes(Test.prototype, "method")[0]).toBe(String);
120
- });
121
- });
122
-
123
- describe("list", () => {
124
- it("should return unique provide from property key", () => {
125
- Metadata.set("controller", "test", Test);
126
- Metadata.set("controller", "test2", Test2);
127
- Metadata.set("controller", "test", Test);
128
-
129
- const result = Metadata.getTargetsFromPropertyKey("controller");
130
-
131
- expect(result).toBeInstanceOf(Array);
132
- // expect(result.length).to.equal(2);
133
- expect(result.indexOf(Test) > -1).toBe(true);
134
- expect(result.indexOf(Test2) > -1).toBe(true);
135
-
136
- const result2 = Metadata.getTargetsFromPropertyKey("controller2");
137
-
138
- expect(result2).toBeInstanceOf(Array);
139
- expect(result2.length).toBe(0);
140
- });
141
- });
142
- });
@@ -1,523 +0,0 @@
1
- import "reflect-metadata";
2
-
3
- import {classOf} from "../utils/classOf.js";
4
-
5
- /**
6
- * Metadata key
7
- * @private
8
- * @type {string}
9
- */
10
- const DESIGN_PARAM_TYPES = "design:paramtypes";
11
- /**
12
- * Metadata key
13
- * @private
14
- * @type {string}
15
- */
16
- const DESIGN_TYPE = "design:type";
17
- /**
18
- * Metadata key
19
- * @private
20
- * @type {string}
21
- */
22
- const DESIGN_RETURN_TYPE = "design:returntype";
23
-
24
- /**
25
- * Properties collections
26
- * @private
27
- * @type {string}
28
- */
29
- const PROPERTIES: Map<string | symbol, any[]> = new Map<string | symbol, any[]>();
30
-
31
- /**
32
- * @stable
33
- */
34
- export class Metadata {
35
- /**
36
- * Gets the metadata value for the provided metadata key on the target object or its prototype chain.
37
- * @param key A key used to store and retrieve metadata.
38
- * @param target The target object on which the metadata is defined.
39
- * @param propertyKey The property key for the target.
40
- * @returns The metadata value for the metadata key if found; otherwise, `undefined`.
41
- * @example
42
- *
43
- * ```typescript
44
- * class Example {
45
- * // property declarations are not part of ES6, though they are valid in TypeScript:
46
- * // static staticProperty;
47
- * // property;
48
- *
49
- * static staticMethod(p) { }
50
- * method(p) { }
51
- * }
52
- *
53
- * // constructor
54
- * result = Metadata.get("custom:annotation", Example);
55
- *
56
- * // property (on constructor)
57
- * result = Metadata.get("custom:annotation", Example, "staticProperty");
58
- *
59
- * // property (on prototype)
60
- * result = Metadata.get("custom:annotation", Example.prototype, "property");
61
- *
62
- * // method (on constructor)
63
- * result = Metadata.get("custom:annotation", Example, "staticMethod");
64
- *
65
- * // method (on prototype)
66
- * result = Metadata.get("custom:annotation", Example.prototype, "method");
67
- * ```
68
- *
69
- */
70
- static get(key: string, target: any, propertyKey?: string | symbol): any {
71
- return Reflect.getMetadata(key, classOf(target), propertyKey!);
72
- }
73
-
74
- /**
75
- * Gets the metadata value for the provided metadata key on the target object or its prototype chain.
76
- * @param key A key used to store and retrieve metadata.
77
- * @param target The target object on which the metadata is defined.
78
- * @param propertyKey The property key for the target.
79
- * @returns The metadata value for the metadata key if found; otherwise, `undefined`.
80
- * @example
81
- *
82
- * ```typescript
83
- * class Example {
84
- * // property declarations are not part of ES6, though they are valid in TypeScript:
85
- * // static staticProperty;
86
- * // property;
87
- *
88
- * static staticMethod(p) { }
89
- * method(p) { }
90
- * }
91
- *
92
- * // constructor
93
- * result = Metadata.getOwn("custom:annotation", Example);
94
- *
95
- * // property (on constructor)
96
- * result = Metadata.getOwn("custom:annotation", Example, "staticProperty");
97
- *
98
- * // property (on prototype)
99
- * result = Metadata.getOwn("custom:annotation", Example.prototype, "property");
100
- *
101
- * // method (on constructor)
102
- * result = Metadata.getOwn("custom:annotation", Example, "staticMethod");
103
- *
104
- * // method (on prototype)
105
- * result = Metadata.getOwn("custom:annotation", Example.prototype, "method");
106
- * ```
107
- *
108
- */
109
- static getOwn(key: string, target: any, propertyKey?: string | symbol): any {
110
- return Reflect.getOwnMetadata(key, classOf(target), propertyKey!);
111
- }
112
-
113
- /**
114
- * Gets the metadata value for the provided metadata DESIGN_TYPE on the target object or its prototype chain.
115
- * @param target The target object on which the metadata is defined.
116
- * @param propertyKey The property key for the target.
117
- * @returns The metadata value for the metadata key if found; otherwise, `undefined`.
118
- * @example
119
- *
120
- * ```typescript
121
- * class Example {
122
- * // property declarations are not part of ES6, though they are valid in TypeScript:
123
- * // static staticProperty;
124
- * // property;
125
- *
126
- * static staticMethod(p) { }
127
- * method(p) { }
128
- * }
129
- *
130
- * // on contructor
131
- * result = Metadata.getType(Example);
132
- *
133
- * // property (on constructor)
134
- * result = Metadata.getType(Example, "staticProperty");
135
- *
136
- * // method (on constructor)
137
- * result = Metadata.getType(Example, "staticMethod");
138
- * ```
139
- *
140
- */
141
- static getType(target: any, propertyKey?: string | symbol): any {
142
- return Reflect.getMetadata(DESIGN_TYPE, target, propertyKey!);
143
- }
144
-
145
- /**
146
- * Gets the metadata value for the provided metadata DESIGN_TYPE on the target object or its prototype chain.
147
- * @param target The target object on which the metadata is defined.
148
- * @param propertyKey The property key for the target.
149
- * @returns The metadata value for the metadata key if found; otherwise, `undefined`.
150
- * @example
151
- *
152
- * ```typescript
153
- * class Example {
154
- * // property declarations are not part of ES6, though they are valid in TypeScript:
155
- * // static staticProperty;
156
- * // property;
157
- *
158
- * static staticMethod(p) { }
159
- * method(p) { }
160
- * }
161
- *
162
- * // on contructor
163
- * result = Metadata.getOwnType(Example);
164
- *
165
- * // property (on constructor)
166
- * result = Metadata.getOwnType(Example, "staticProperty");
167
- *
168
- * // method (on constructor)
169
- * result = Metadata.getOwnType(Example, "staticMethod");
170
- * ```
171
- *
172
- */
173
- static getOwnType(target: any, propertyKey?: string | symbol): any {
174
- return Reflect.getMetadata(DESIGN_TYPE, target, propertyKey!);
175
- }
176
-
177
- /**
178
- * Gets the metadata value for the provided metadata DESIGN_RETURN_TYPE on the target object or its prototype chain.
179
- * @param target The target object on which the metadata is defined.
180
- * @param propertyKey The property key for the target.
181
- * @returns The metadata value for the metadata key if found; otherwise, `undefined`.
182
- * @example
183
- *
184
- * ```typescript
185
- * class Example {
186
- * // property declarations are not part of ES6, though they are valid in TypeScript:
187
- * // static staticProperty;
188
- * // property;
189
- *
190
- * static staticMethod(p) { }
191
- * method(p) { }
192
- * }
193
- *
194
- * // on contructor
195
- * result = Metadata.getReturnType(Example);
196
- *
197
- * // property (on constructor)
198
- * result = Metadata.getReturnType(Example, "staticProperty");
199
- *
200
- * // method (on constructor)
201
- * result = Metadata.getReturnType(Example, "staticMethod");
202
- * ```
203
- *
204
- */
205
- static getReturnType(target: any, propertyKey?: string | symbol): any {
206
- return Reflect.getMetadata(DESIGN_RETURN_TYPE, target, propertyKey!);
207
- }
208
-
209
- /**
210
- * Gets the metadata value for the provided metadata DESIGN_RETURN_TYPE on the target object or its prototype chain.
211
- * @param target The target object on which the metadata is defined.
212
- * @param propertyKey The property key for the target.
213
- * @returns The metadata value for the metadata key if found; otherwise, `undefined`.
214
- * @example
215
- *
216
- * ```typescript
217
- * class Example {
218
- * // property declarations are not part of ES6, though they are valid in TypeScript:
219
- * // static staticProperty;
220
- * // property;
221
- *
222
- * static staticMethod(p) { }
223
- * method(p) { }
224
- * }
225
- *
226
- * // on contructor
227
- * result = Metadata.getOwnReturnType(Example);
228
- *
229
- * // property (on constructor)
230
- * result = Metadata.getOwnReturnType(Example, "staticProperty");
231
- *
232
- * // method (on constructor)
233
- * result = Metadata.getOwnReturnType(Example, "staticMethod");
234
- * ```
235
- *
236
- */
237
- static getOwnReturnType(target: any, propertyKey?: string | symbol): any {
238
- return Reflect.getOwnMetadata(DESIGN_RETURN_TYPE, target, propertyKey!);
239
- }
240
-
241
- /**
242
- * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined.
243
- * @param key A key used to store and retrieve metadata.
244
- * @param target The target object on which the metadata is defined.
245
- * @param propertyKey The property key for the target.
246
- * @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`.
247
- * @example
248
- *
249
- * ```typescript
250
- * class Example {
251
- * // property declarations are not part of ES6, though they are valid in TypeScript:
252
- * // static staticProperty;
253
- * // property;
254
- *
255
- * static staticMethod(p) { }
256
- * method(p) { }
257
- * }
258
- *
259
- * // constructor
260
- * result = Metadata.has("custom:annotation", Example);
261
- *
262
- * // property (on constructor)
263
- * result = Metadata.has("custom:annotation", Example, "staticProperty");
264
- *
265
- * // property (on prototype)
266
- * result = Metadata.has("custom:annotation", Example.prototype, "property");
267
- *
268
- * // method (on constructor)
269
- * result = Metadata.has("custom:annotation", Example, "staticMethod");
270
- *
271
- * // method (on prototype)
272
- * result = Metadata.has("custom:annotation", Example.prototype, "method");
273
- * ```
274
- *
275
- */
276
- static has(key: string, target: any, propertyKey?: string | symbol): boolean {
277
- try {
278
- return Reflect.hasMetadata(key, classOf(target), propertyKey!);
279
- } catch (er) {}
280
-
281
- return false;
282
- }
283
-
284
- /**
285
- * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined.
286
- * @param key A key used to store and retrieve metadata.
287
- * @param target The target object on which the metadata is defined.
288
- * @param propertyKey The property key for the target.
289
- * @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`.
290
- * @example
291
- *
292
- * ```typescript
293
- * class Example {
294
- * // property declarations are not part of ES6, though they are valid in TypeScript:
295
- * // static staticProperty;
296
- * // property;
297
- *
298
- * static staticMethod(p) { }
299
- * method(p) { }
300
- * }
301
- *
302
- * // constructor
303
- * result = Metadata.has("custom:annotation", Example);
304
- *
305
- * // property (on constructor)
306
- * result = Metadata.hasOwn("custom:annotation", Example, "staticProperty");
307
- *
308
- * // property (on prototype)
309
- * result = Metadata.hasOwn("custom:annotation", Example.prototype, "property");
310
- *
311
- * // method (on constructor)
312
- * result = Metadata.hasOwn("custom:annotation", Example, "staticMethod");
313
- *
314
- * // method (on prototype)
315
- * result = Metadata.hasOwn("custom:annotation", Example.prototype, "method");
316
- * ```
317
- *
318
- */
319
- static hasOwn(key: string, target: any, propertyKey?: string | symbol): boolean {
320
- return Reflect.hasOwnMetadata(key, classOf(target), propertyKey!);
321
- }
322
-
323
- /**
324
- * Deletes the metadata entry from the target object with the provided key.
325
- * @param key A key used to store and retrieve metadata.
326
- * @param target The target object on which the metadata is defined.
327
- * @param propertyKey The property key for the target.
328
- * @returns `true` if the metadata entry was found and deleted; otherwise, false.
329
- * @example
330
- *
331
- * ```typescript
332
- * class Example {
333
- * // property declarations are not part of ES6, though they are valid in TypeScript:
334
- * // static staticProperty;
335
- * // property;
336
- *
337
- * static staticMethod(p) { }
338
- * method(p) { }
339
- * }
340
- *
341
- * // constructor
342
- * result = Metadata.delete("custom:annotation", Example);
343
- *
344
- * // property (on constructor)
345
- * result = Metadata.delete("custom:annotation", Example, "staticProperty");
346
- *
347
- * // property (on prototype)
348
- * result = Metadata.delete("custom:annotation", Example.prototype, "property");
349
- *
350
- * // method (on constructor)
351
- * result = Metadata.delete("custom:annotation", Example, "staticMethod");
352
- *
353
- * // method (on prototype)
354
- * result = Metadata.delete("custom:annotation", Example.prototype, "method");
355
- * ```
356
- *
357
- */
358
- static delete(key: string, target: any, propertyKey?: string | symbol): boolean {
359
- return Reflect.deleteMetadata(key, classOf(target), propertyKey!);
360
- }
361
-
362
- /**
363
- * Set the metadata value for the provided metadata DESIGN_PARAM_TYPES on the target object or its prototype chain.
364
- * @param target The target object on which the metadata is defined.
365
- * @param propertyKey The property key for the target.
366
- * @param value A value that contains attached metadata.
367
- * @returns The metadata value for the metadata key if found; otherwise, `undefined`.
368
- * @example
369
- *
370
- * ```typescript
371
- * class Example {
372
- * // property declarations are not part of ES6, though they are valid in TypeScript:
373
- * // static staticProperty;
374
- * // property;
375
- *
376
- * static staticMethod(p) { }
377
- * method(p) { }
378
- * }
379
- *
380
- * // on contructor
381
- * result = Metadata.setParamTypes(Example, undefined, [Object]);
382
- *
383
- * // property (on constructor)
384
- * result = Metadata.setParamTypes(Example, "staticProperty", [Object]);
385
- *
386
- * // property (on prototype)
387
- * result = Metadata.setParamTypes(Example.prototype, "property", [Object]);
388
- *
389
- * // method (on constructor)
390
- * result = Metadata.setParamTypes(Example, "staticMethod", [Object]);
391
- *
392
- * // method (on prototype)
393
- * result = Metadata.setParamTypes(Example.prototype, "method", [Object]);
394
- * ```
395
- *
396
- */
397
- static setParamTypes(target: any, propertyKey: string | symbol, value: any): void {
398
- return this.set(DESIGN_PARAM_TYPES, value, target.prototype, propertyKey);
399
- }
400
-
401
- /**
402
- * Get all metadata for a metadataKey.
403
- * @param metadataKey
404
- */
405
- static getTargetsFromPropertyKey = (metadataKey: string | symbol): any[] =>
406
- PROPERTIES.has(metadataKey) ? PROPERTIES.get(metadataKey) || [] : [];
407
-
408
- /**
409
- * Define a unique metadata entry on the target.
410
- * @param key A key used to store and retrieve metadata.
411
- * @param value A value that contains attached metadata.
412
- * @param target The target object on which to define metadata.
413
- * @param propertyKey The property key for the target.
414
- * @example
415
- *
416
- * ```typescript
417
- * class Example {
418
- * // property declarations are not part of ES6, though they are valid in TypeScript:
419
- * // static staticProperty;
420
- * // property;
421
- *
422
- * static staticMethod(p) { }
423
- * method(p) { }
424
- * }
425
- *
426
- * // constructor
427
- * Reflect.defineMetadata("custom:annotation", options, Example);
428
- *
429
- * // property (on constructor)
430
- * Reflect.defineMetadata("custom:annotation", Number, Example, "staticProperty");
431
- *
432
- * // property (on prototype)
433
- * Reflect.defineMetadata("custom:annotation", Number, Example.prototype, "property");
434
- *
435
- * // method (on constructor)
436
- * Reflect.defineMetadata("custom:annotation", Number, Example, "staticMethod");
437
- *
438
- * // method (on prototype)
439
- * Reflect.defineMetadata("custom:annotation", Number, Example.prototype, "method");
440
- *
441
- * // decorator factory as metadata-producing annotation.
442
- * function MyAnnotation(options): PropertyDecorator {
443
- * return (target, key) => Reflect.defineMetadata("custom:annotation", options, target, key);
444
- * }
445
- * ```
446
- *
447
- */
448
- static set(key: string, value: any, target: any, propertyKey?: string | symbol): void {
449
- const targets: any[] = PROPERTIES.has(key) ? PROPERTIES.get(key) || [] : [];
450
- const classConstructor = classOf(target);
451
-
452
- if (targets.indexOf(classConstructor) === -1) {
453
- targets.push(classConstructor);
454
- PROPERTIES.set(key, targets);
455
- }
456
-
457
- Reflect.defineMetadata(key, value, classOf(target), propertyKey!);
458
- }
459
-
460
- /**
461
- * Gets the metadata value for the provided metadata DESIGN_PARAM_TYPES on the target object or its prototype chain.
462
- * @param targetPrototype
463
- * @param propertyKey The property key for the target.
464
- * @returns The metadata value for the metadata key if found; otherwise, `undefined`.
465
- * @example
466
- *
467
- * ```typescript
468
- * class Example {
469
- * // property declarations are not part of ES6, though they are valid in TypeScript:
470
- * // static staticProperty;
471
- * // property;
472
- *
473
- * static staticMethod(p) { }
474
- * method(p) { }
475
- * }
476
- *
477
- * // on contructor
478
- * result = Metadata.getParamTypes(Example.prototype);
479
- *
480
- * // property (on constructor)
481
- * result = Metadata.getParamTypes(Example.prototype, "staticProperty");
482
- *
483
- * // method (on constructor)
484
- * result = Metadata.getParamTypes(Example.prototype, "staticMethod");
485
- * ```
486
- *
487
- */
488
- static getParamTypes(targetPrototype: any, propertyKey?: string | symbol): any[] {
489
- return Reflect.getMetadata(DESIGN_PARAM_TYPES, targetPrototype, propertyKey!) || [];
490
- }
491
-
492
- /**
493
- * Gets the metadata value for the provided metadata DESIGN_PARAM_TYPES on the target object or its prototype chain.
494
- * @param target The target object on which the metadata is defined.
495
- * @param propertyKey The property key for the target.
496
- * @returns The metadata value for the metadata key if found; otherwise, `undefined`.
497
- * @example
498
- *
499
- * ```typescript
500
- * class Example {
501
- * // property declarations are not part of ES6, though they are valid in TypeScript:
502
- * // static staticProperty;
503
- * // property;
504
- *
505
- * static staticMethod(p) { }
506
- * method(p) { }
507
- * }
508
- *
509
- * // on contructor
510
- * result = Metadata.getParamTypes(Example);
511
- *
512
- * // property (on constructor)
513
- * result = Metadata.getParamTypes(Example, "staticProperty");
514
- *
515
- * // method (on constructor)
516
- * result = Metadata.getParamTypes(Example, "staticMethod");
517
- * ```
518
- *
519
- */
520
- static getOwnParamTypes(target: any, propertyKey?: string | symbol): any[] {
521
- return Reflect.getOwnMetadata(DESIGN_PARAM_TYPES, target, propertyKey!) || [];
522
- }
523
- }
@@ -1,6 +0,0 @@
1
- import type {Type} from "./Type.js";
2
-
3
- export interface MetadataTypes<T = any, C = any> {
4
- type?: Type<T> | T;
5
- collectionType?: Type<C> | C;
6
- }
@@ -1 +0,0 @@
1
- export type Relation<T> = T;