@tsed/core 8.11.0 → 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,164 +0,0 @@
1
- import {Metadata} from "./Metadata.js";
2
- import {CLASS_STORE, METHOD_STORE, PARAM_STORE, PROPERTY_STORE, Store} from "./Store.js";
3
-
4
- class FakeMetadata {
5
- attr1: any;
6
- attr2: any;
7
-
8
- constructor(public target: any) {}
9
-
10
- test() {
11
- return this.target;
12
- }
13
- }
14
-
15
- class SuperFake extends FakeMetadata {}
16
-
17
- describe("Store", () => {
18
- describe("constructor", () => {
19
- describe("when metadata should be store on class", () => {
20
- let spyGet: any, store: any, store2: any, store3: any;
21
- beforeEach(() => {
22
- spyGet = vi.spyOn(Metadata, "getOwn");
23
- store = Store.from(FakeMetadata);
24
- store2 = Store.from(FakeMetadata);
25
- store3 = Store.from(class {});
26
-
27
- store.set("keyTest", {test: "2"});
28
- });
29
-
30
- it("should have been called the Metadata.get()", () => {
31
- expect(spyGet).toHaveBeenCalledWith(CLASS_STORE, FakeMetadata);
32
- });
33
-
34
- it("should share the same StoreMap when the signature is equals", () => {
35
- expect(store.get("keyTest")).toBe(store2.get("keyTest"));
36
- });
37
-
38
- it("should not share the same StoreMap when the signature is not equals", () => {
39
- expect(store.get("keyTest")).not.toBe(store3.get("keyTest"));
40
- });
41
- });
42
-
43
- describe("when metadata should be store on method", () => {
44
- it("should have been called the Metadata.get()", () => {
45
- const spyGet = vi.spyOn(Metadata, "getOwn");
46
- Store.from(FakeMetadata, "get", {
47
- value: () => {}
48
- });
49
-
50
- expect(spyGet).toHaveBeenCalledWith(METHOD_STORE, FakeMetadata, "get");
51
- });
52
- });
53
-
54
- describe("when metadata should be store on property (1)", () => {
55
- it("should have been called the Metadata.get()", () => {
56
- const spyGet = vi.spyOn(Metadata, "getOwn");
57
- const store = Store.from(FakeMetadata, "get");
58
- expect(spyGet).toHaveBeenCalledWith(PROPERTY_STORE, FakeMetadata, "get");
59
- });
60
- });
61
-
62
- describe("when metadata should be store on property (2)", () => {
63
- it("should have been called the Metadata.get()", () => {
64
- const spyGet = vi.spyOn(Metadata, "getOwn");
65
- Store.from(FakeMetadata, "get", {
66
- set: () => {}
67
- });
68
-
69
- expect(spyGet).toHaveBeenCalledWith(PROPERTY_STORE, FakeMetadata, "get");
70
- });
71
- });
72
-
73
- describe("when metadata should be store on property (3)", () => {
74
- it("should have been called the Metadata.get()", () => {
75
- const spyGet = vi.spyOn(Metadata, "getOwn");
76
- Store.from(FakeMetadata, "get", {
77
- get: () => {}
78
- });
79
-
80
- expect(spyGet).toHaveBeenCalledWith(PROPERTY_STORE, FakeMetadata, "get");
81
- });
82
- });
83
-
84
- describe("when metadata should be store on parameters", () => {
85
- it("should have been called the Metadata.get()", () => {
86
- const spyGet = vi.spyOn(Metadata, "getOwn");
87
- Store.from(FakeMetadata, "get", 0);
88
-
89
- expect(spyGet).toHaveBeenCalledWith(PARAM_STORE, FakeMetadata, "get");
90
- });
91
- });
92
- });
93
-
94
- describe("set()", () => {
95
- it("should add a metadata", () => {
96
- const store = Store.from(FakeMetadata);
97
- store.set("key", {});
98
-
99
- expect(store.get("key")).toEqual({});
100
- });
101
- });
102
-
103
- describe("has()", () => {
104
- it("should return true if class is known", () => {
105
- const store = Store.from(FakeMetadata);
106
- expect(store.has("key")).toBe(true);
107
- });
108
- it("should return false if class is unknown", () => {
109
- const store = Store.from(FakeMetadata);
110
- expect(store.has("key2")).toBe(false);
111
- });
112
- });
113
-
114
- describe("delete()", () => {
115
- it("should remove key", () => {
116
- const store = Store.from(FakeMetadata);
117
- store.set("key", {test: true});
118
-
119
- expect(store.get("key")).toEqual({test: true});
120
-
121
- store.delete("key");
122
- expect(store.get("key")).toBeUndefined();
123
- });
124
- });
125
-
126
- describe("merge()", () => {
127
- it("should merge metadata", () => {
128
- const store = Store.from(FakeMetadata);
129
- store.merge("key3", {attr1: 1});
130
- store.merge("key3", {attr2: 2});
131
-
132
- expect(store.get("key3")).toEqual({attr1: 1, attr2: 2});
133
- });
134
- });
135
-
136
- describe("inheritance", () => {
137
- it("should haven't the same sc", () => {
138
- Store.from(FakeMetadata).set("sc", {test: "test"});
139
- Store.from(SuperFake).set("sc", {test: "test2"});
140
- const r1 = Store.from(SuperFake).get("sc");
141
- const r2 = Store.from(FakeMetadata).get("sc");
142
-
143
- expect(r1).not.toEqual(r2);
144
- });
145
- });
146
-
147
- describe("from()", () => {
148
- it("should create a store from Symbol", () => {
149
- // GIVEN
150
- const TOKEN = Symbol.for("token");
151
- const TOKEN2 = Symbol.for("token2");
152
-
153
- const store1 = Store.from(TOKEN);
154
- const store2 = Store.from(TOKEN);
155
- const store3 = Store.from(TOKEN2);
156
-
157
- // WHEN
158
- store1.set("test", "value");
159
-
160
- expect(store2.get("test")).toBe("value");
161
- expect(store3.get("test")).toBeUndefined();
162
- });
163
- });
164
- });
@@ -1,175 +0,0 @@
1
- import {decoratorTypeOf} from "../utils/decoratorTypeOf.js";
2
- import {deepClone} from "../utils/deepClone.js";
3
- import {deepMerge} from "../utils/deepMerge.js";
4
- import {descriptorOf} from "../utils/descriptorOf.js";
5
- import {isSymbol} from "../utils/isSymbol.js";
6
- import {nameOf} from "../utils/nameOf.js";
7
- import {DecoratorTypes} from "./DecoratorTypes.js";
8
- import {Metadata} from "./Metadata.js";
9
- import type {Type} from "./Type.js";
10
-
11
- /**
12
- * @ignore
13
- */
14
- export const CLASS_STORE = "tsed:class:store";
15
- /**
16
- * @ignore
17
- */
18
- export const METHOD_STORE = "tsed:method:store";
19
- /**
20
- * @ignore
21
- */
22
- export const PROPERTY_STORE = "tsed:property:store";
23
- /**
24
- * @ignore
25
- */
26
- export const PARAM_STORE = "tsed:param:store";
27
-
28
- const stores = new Map<symbol, Store>();
29
-
30
- function storeGet(key: string, ...args: any[]): Store {
31
- if (isSymbol(args[0])) {
32
- if (!stores.has(args[0])) {
33
- stores.set(args[0], new Store());
34
- }
35
-
36
- return stores.get(args[0])!;
37
- } else {
38
- const registry = Metadata as any;
39
-
40
- if (!registry.hasOwn(key, ...args)) {
41
- registry.set(key, new Store(), ...args);
42
- }
43
-
44
- return registry.getOwn(key, ...args);
45
- }
46
- }
47
-
48
- function defineStore(args: any[]): Store {
49
- const [target, propertyKey, descriptor] = args;
50
-
51
- switch (decoratorTypeOf(args)) {
52
- case DecoratorTypes.PARAM_CTOR:
53
- case DecoratorTypes.PARAM_STC:
54
- case DecoratorTypes.PARAM:
55
- const store = storeGet(PARAM_STORE, target, propertyKey);
56
- if (!store.has("" + descriptor)) {
57
- store.set("" + descriptor, new Store());
58
- }
59
-
60
- return store.get("" + descriptor);
61
- case DecoratorTypes.PROP:
62
- case DecoratorTypes.PROP_STC:
63
- return storeGet(PROPERTY_STORE, target, propertyKey);
64
- case DecoratorTypes.METHOD:
65
- case DecoratorTypes.METHOD_STC:
66
- return storeGet(METHOD_STORE, target, propertyKey);
67
- case DecoratorTypes.CLASS:
68
- return storeGet(CLASS_STORE, target);
69
- }
70
- }
71
-
72
- export class Store {
73
- private _entries = new Map<string, any>();
74
- /**
75
- * Create or get a Store from given args (target, property, descriptor).
76
- * @param args
77
- * @returns {Store}
78
- */
79
- static from(...args: any[]): Store {
80
- return defineStore(args);
81
- }
82
-
83
- /**
84
- * Create store on the method.
85
- * @param target
86
- * @param {string} propertyKey
87
- * @returns {Store}
88
- */
89
- static fromMethod(target: any, propertyKey: string | symbol): Store {
90
- return Store.from(target, propertyKey, descriptorOf(target, propertyKey));
91
- }
92
-
93
- static mergeStoreFrom(target: Type<any>, source: Type<any>, ...args: any[]) {
94
- const store = Store.from(target, ...args);
95
-
96
- Store.from(source, ...args)._entries.forEach((value, key) => {
97
- store.merge(key, value);
98
- });
99
-
100
- return store;
101
- }
102
-
103
- static mergeStoreMethodFrom(target: Type<any>, source: Type<any>, propertyKey: string | symbol) {
104
- return this.mergeStoreFrom(target, source, propertyKey, descriptorOf(target, propertyKey));
105
- }
106
-
107
- /**
108
- * The get() method returns a specified element from a Map object.
109
- * @param key Required. The key of the element to return from the Map object.
110
- * @param defaultValue
111
- * @returns {T} Returns the element associated with the specified key or undefined if the key can't be found in the Map object.
112
- */
113
- get<T = any>(key: any, defaultValue?: any): T {
114
- return this._entries.get(nameOf(key)) || defaultValue;
115
- }
116
-
117
- /**
118
- * The has() method returns a boolean indicating whether an element with the specified key exists or not.
119
- * @param key
120
- * @returns {boolean}
121
- */
122
- has(key: any): boolean {
123
- return this._entries.has(nameOf(key));
124
- }
125
-
126
- /**
127
- * The set() method adds or updates an element with a specified key and value to a Map object.
128
- * @param key Required. The key of the element to add to the Map object.
129
- * @param metadata Required. The value of the element to add to the Map object.
130
- */
131
- set(key: any, metadata: any): Store {
132
- this._entries.set(nameOf(key), metadata);
133
-
134
- return this;
135
- }
136
-
137
- /**
138
- * The delete() method removes the specified element from a Map object.
139
- * @param key Required. The key of the element to remove from the Map object.
140
- * @returns {boolean} Returns true if an element in the Map object existed and has been removed, or false if the element does not exist.
141
- */
142
- delete(key: string): boolean {
143
- return this._entries.delete(nameOf(key));
144
- }
145
-
146
- /**
147
- * Merge given value with existing value.
148
- * @param key
149
- * @param value
150
- * @param inverse Change the merge order. Get the existing value and apply over given value
151
- * @returns {Store}
152
- */
153
- merge(key: any, value: any, inverse: boolean = false): Store {
154
- let _value_ = this.get(key);
155
-
156
- if (_value_) {
157
- value = deepClone(value);
158
- _value_ = deepClone(_value_);
159
- value = inverse ? deepMerge(value, _value_) : deepMerge(_value_, value);
160
- }
161
-
162
- this.set(key, value);
163
-
164
- return this;
165
- }
166
-
167
- toJson() {
168
- return [...this._entries.entries()].reduce((obj, [key, value]) => {
169
- return {
170
- ...obj,
171
- [key]: value
172
- };
173
- }, {});
174
- }
175
- }
package/src/types/Type.ts DELETED
@@ -1,20 +0,0 @@
1
- /**
2
- * An example of a `Type` is `MyCustomComponent` filters, which in JavaScript is represented by
3
- * the `MyCustomComponent` constructor function.
4
- */
5
- // tslint:disable-next-line: variable-name
6
- /**
7
- *
8
- */
9
- export interface Type<T = any> extends Function {
10
- new (...args: any[]): T;
11
- }
12
-
13
- export const Type = Function;
14
-
15
- // @ts-ignore
16
- global.Type = Type;
17
-
18
- export interface AbstractType<T> extends Function {
19
- prototype: T;
20
- }
@@ -1 +0,0 @@
1
- export type ValueOf<T> = T[keyof T];
@@ -1,159 +0,0 @@
1
- import {createReadStream} from "node:fs";
2
-
3
- import {of} from "rxjs";
4
-
5
- import {AnyToPromise, AnyToPromiseStatus} from "./AnyToPromise.js";
6
- import {catchAsyncError} from "./catchError.js";
7
- import {isStream} from "./isStream.js";
8
-
9
- const rootDir = import.meta.dirname; // automatically replaced by import.meta.dirname on build
10
-
11
- describe("AnyToPromise", () => {
12
- it("should handle sync value", async () => {
13
- const resolver = new AnyToPromise();
14
-
15
- const result = await resolver.call(() => {
16
- return "test";
17
- });
18
-
19
- resolver.cancel();
20
- resolver.resolve();
21
- resolver.next();
22
- resolver.reject(new Error(""));
23
-
24
- await resolver.call(() => {
25
- return "test";
26
- });
27
-
28
- expect(result).toEqual({state: "RESOLVED", data: "test", type: "DATA"});
29
- });
30
-
31
- it("should handle async value", async () => {
32
- const resolver = new AnyToPromise();
33
-
34
- const result = await resolver.call(() => {
35
- return Promise.resolve("test");
36
- });
37
-
38
- expect(result).toEqual({state: "RESOLVED", data: "test", type: "DATA"});
39
- });
40
- it("should handle canceled async value", async () => {
41
- const resolver = new AnyToPromise();
42
-
43
- const result = await resolver.call(() => {
44
- return Promise.resolve(AnyToPromiseStatus.CANCELED);
45
- });
46
-
47
- expect(result).toEqual({state: "CANCELED"});
48
- });
49
- it("should handle response with data", async () => {
50
- const resolver = new AnyToPromise();
51
-
52
- const result = await resolver.call(() => {
53
- return Promise.resolve({
54
- data: "data",
55
- headers: {
56
- "Content-Type": "type"
57
- },
58
- status: 200,
59
- statusText: "OK"
60
- });
61
- });
62
-
63
- expect(result).toEqual({
64
- state: "RESOLVED",
65
- data: "data",
66
- headers: {
67
- "Content-Type": "type"
68
- },
69
- status: 200,
70
- type: "DATA"
71
- });
72
- });
73
- it("should handle async undefined value", async () => {
74
- const resolver = new AnyToPromise();
75
-
76
- const result = await resolver.call(() => {
77
- return Promise.resolve(undefined);
78
- });
79
-
80
- expect(result).toEqual({state: "RESOLVED", data: undefined, type: "DATA"});
81
- });
82
- it("should handle observable", async () => {
83
- const resolver = new AnyToPromise();
84
-
85
- const result = await resolver.call(() => {
86
- return of("test");
87
- });
88
-
89
- expect(result).toEqual({state: "RESOLVED", data: "test", type: "DATA"});
90
- });
91
- it("should handle buffer", async () => {
92
- const resolver = new AnyToPromise();
93
-
94
- const result = await resolver.call(() => {
95
- return Buffer.from("test");
96
- });
97
-
98
- expect(Buffer.isBuffer(result.data)).toBe(true);
99
- expect(result.type).toBe("BUFFER");
100
- });
101
- it("should handle stream", async () => {
102
- const resolver = new AnyToPromise();
103
-
104
- const result = await resolver.call(() => {
105
- return createReadStream(rootDir + "/__mock__/response.txt");
106
- });
107
-
108
- expect(result.type).toBe("STREAM");
109
- expect(isStream(result.data)).toBe(true);
110
- });
111
-
112
- it("should catch error", async () => {
113
- const resolver = new AnyToPromise();
114
-
115
- const result = await resolver.call(() => {
116
- return Promise.resolve("test");
117
- });
118
-
119
- expect(result).toEqual({state: "RESOLVED", data: "test", type: "DATA"});
120
- });
121
-
122
- it("should handle async error", async () => {
123
- const resolver = new AnyToPromise();
124
-
125
- const error = await catchAsyncError(() => {
126
- return resolver.call(() => {
127
- return Promise.reject(new Error("test"));
128
- });
129
- });
130
-
131
- expect(error?.message).toEqual("test");
132
- });
133
-
134
- it("should handle sync error", async () => {
135
- const resolver = new AnyToPromise();
136
-
137
- const error = await catchAsyncError(() => {
138
- return resolver.call(() => {
139
- throw new Error("test");
140
- });
141
- });
142
-
143
- expect(error?.message).toEqual("test");
144
- });
145
-
146
- it("should handle next callback with error", async () => {
147
- const resolver = new AnyToPromise();
148
- const {next} = resolver;
149
-
150
- const error = await catchAsyncError(() => {
151
- return resolver.call(() => {
152
- next(new Error("test"));
153
- return Promise.resolve();
154
- });
155
- });
156
-
157
- expect(error?.message).toEqual("test");
158
- });
159
- });
@@ -1,181 +0,0 @@
1
- import {isObject} from "./isObject.js";
2
- import {isObservable} from "./isObservable.js";
3
- import {isPromise} from "./isPromise.js";
4
- import {isStream} from "./isStream.js";
5
-
6
- /**
7
- * @ignore
8
- */
9
- function isResponse(obj: any) {
10
- return isObject(obj) && "data" in obj && "headers" in obj && "status" in obj && "statusText" in obj;
11
- }
12
-
13
- /**
14
- * @ignore
15
- */
16
- export enum AnyToPromiseStatus {
17
- PENDING = "PENDING",
18
- CANCELED = "CANCELED",
19
- RESOLVED = "RESOLVED",
20
- REJECTED = "REJECTED"
21
- }
22
-
23
- export enum AnyToPromiseResponseTypes {
24
- STREAM = "STREAM",
25
- BUFFER = "BUFFER",
26
- DATA = "DATA"
27
- }
28
-
29
- export interface AnyPromiseResult<T = any> {
30
- state: AnyToPromiseStatus;
31
- type: AnyToPromiseResponseTypes;
32
- status?: number;
33
- headers?: Record<string, any>;
34
- data: T;
35
- }
36
-
37
- export class AnyToPromise<T = any> {
38
- public status = AnyToPromiseStatus.PENDING;
39
- public args: any[];
40
-
41
- #resolves: any;
42
- #rejects: any;
43
- #hasNextFunction = false;
44
-
45
- readonly #promise: Promise<AnyPromiseResult<T>>;
46
-
47
- constructor({hasNextFunction = false}: {hasNextFunction?: boolean} = {}) {
48
- this.#hasNextFunction = hasNextFunction;
49
-
50
- this.#promise = new Promise((resolve: any, reject: any) => {
51
- this.#resolves = resolve;
52
- this.#rejects = reject;
53
- });
54
- }
55
-
56
- isDone(): boolean {
57
- return this.status !== AnyToPromiseStatus.PENDING;
58
- }
59
-
60
- get next() {
61
- this.#hasNextFunction = true;
62
-
63
- return (error?: any) => {
64
- if (this.isDone()) {
65
- return;
66
- }
67
-
68
- return error ? this.reject(error) : this.resolve({type: AnyToPromiseResponseTypes.DATA});
69
- };
70
- }
71
-
72
- /**
73
- *
74
- */
75
- call(cb: Function): Promise<AnyPromiseResult<T>> {
76
- if (this.isDone()) {
77
- return Promise.resolve(this as any);
78
- }
79
-
80
- try {
81
- this.handle(cb());
82
- } catch (er) {
83
- this.reject(er);
84
- }
85
-
86
- return this.#promise;
87
- }
88
-
89
- reject(er: any) {
90
- if (this.isDone()) {
91
- return;
92
- }
93
-
94
- this.done(AnyToPromiseStatus.REJECTED);
95
-
96
- this.#rejects(er);
97
- }
98
-
99
- resolve(response: any = {}) {
100
- if (this.isDone()) {
101
- return;
102
- }
103
-
104
- this.done(AnyToPromiseStatus.RESOLVED);
105
-
106
- this.#resolves({...response, state: AnyToPromiseStatus.RESOLVED});
107
- }
108
-
109
- destroy() {}
110
-
111
- cancel() {
112
- if (this.isDone()) {
113
- return;
114
- }
115
-
116
- this.done(AnyToPromiseStatus.CANCELED);
117
-
118
- return this.#resolves({state: AnyToPromiseStatus.CANCELED});
119
- }
120
-
121
- done(status: AnyToPromiseStatus) {
122
- this.destroy();
123
- this.status = status;
124
- }
125
-
126
- handle(process: any, additionalProps = {}): any {
127
- if (this.isDone()) {
128
- return;
129
- }
130
-
131
- if (process) {
132
- if (this.isCanceledResponse(process)) {
133
- // ABANDON
134
- return this.cancel();
135
- }
136
-
137
- if (isObservable(process)) {
138
- process = process.toPromise();
139
- }
140
-
141
- if (isResponse(process)) {
142
- return this.handle(process.data, {
143
- ...additionalProps,
144
- status: process.status,
145
- headers: process.headers
146
- });
147
- }
148
-
149
- if (isStream(process)) {
150
- return this.resolve({...additionalProps, type: AnyToPromiseResponseTypes.STREAM, data: process});
151
- }
152
- if (isStream(process) || Buffer.isBuffer(process)) {
153
- return this.resolve({...additionalProps, type: AnyToPromiseResponseTypes.BUFFER, data: process});
154
- }
155
-
156
- if (isPromise(process)) {
157
- return process
158
- .then((result: any) => this.handle(result, additionalProps))
159
- .catch((error: any) => {
160
- if (error.response && isResponse(error.response)) {
161
- return this.handle(error.response);
162
- }
163
- return this.reject(error);
164
- });
165
- }
166
- }
167
-
168
- if (!this.#hasNextFunction) {
169
- // no next function and empty response
170
- return this.resolve({
171
- ...additionalProps,
172
- data: process,
173
- type: AnyToPromiseResponseTypes.DATA
174
- });
175
- }
176
- }
177
-
178
- protected isCanceledResponse(process: any) {
179
- return process === AnyToPromiseStatus.CANCELED;
180
- }
181
- }