@schorts/shared-kernel 4.2.0 → 4.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/dist/cjs/value-objects/array-value.js +2 -0
  2. package/dist/cjs/value-objects/array-value.js.map +1 -1
  3. package/dist/cjs/value-objects/index.js +3 -1
  4. package/dist/cjs/value-objects/index.js.map +1 -1
  5. package/dist/cjs/value-objects/object-value.js +2 -0
  6. package/dist/cjs/value-objects/object-value.js.map +1 -1
  7. package/dist/cjs/value-objects/url-value.js +23 -0
  8. package/dist/cjs/value-objects/url-value.js.map +1 -0
  9. package/dist/esm/value-objects/array-value.js +2 -0
  10. package/dist/esm/value-objects/array-value.js.map +1 -1
  11. package/dist/esm/value-objects/index.js +3 -1
  12. package/dist/esm/value-objects/index.js.map +1 -1
  13. package/dist/esm/value-objects/object-value.js +2 -0
  14. package/dist/esm/value-objects/object-value.js.map +1 -1
  15. package/dist/esm/value-objects/url-value.js +23 -0
  16. package/dist/esm/value-objects/url-value.js.map +1 -0
  17. package/dist/types/pub-sub/subscription.d.ts +0 -1
  18. package/dist/types/pub-sub/subscription.d.ts.map +1 -1
  19. package/dist/types/telemetry/telemetry.d.ts +0 -1
  20. package/dist/types/telemetry/telemetry.d.ts.map +1 -1
  21. package/dist/types/value-objects/array-value.d.ts +2 -0
  22. package/dist/types/value-objects/array-value.d.ts.map +1 -1
  23. package/dist/types/value-objects/index.d.ts +1 -0
  24. package/dist/types/value-objects/index.d.ts.map +1 -1
  25. package/dist/types/value-objects/object-value.d.ts +2 -0
  26. package/dist/types/value-objects/object-value.d.ts.map +1 -1
  27. package/dist/types/value-objects/url-value.d.ts +11 -0
  28. package/dist/types/value-objects/url-value.d.ts.map +1 -0
  29. package/package.json +11 -3
  30. package/.idx/airules.md +0 -186
  31. package/.idx/dev.nix +0 -54
  32. package/.vscode/settings.json +0 -7
  33. package/CHANGELOG +0 -357
  34. package/__tests__/auth/auth-provider.test.ts +0 -50
  35. package/__tests__/auth/require-auth.decorator.test.ts +0 -88
  36. package/__tests__/criteria/criteria.test.ts +0 -159
  37. package/__tests__/criteria/direction.test.ts +0 -11
  38. package/__tests__/criteria/filter-criterion.test.ts +0 -15
  39. package/__tests__/criteria/operator.test.ts +0 -22
  40. package/__tests__/criteria/order.test.ts +0 -14
  41. package/__tests__/dao/dao.test.ts +0 -126
  42. package/__tests__/domain-events/domain-event-primitives.test.ts +0 -34
  43. package/__tests__/domain-events/domain-event.test.ts +0 -50
  44. package/__tests__/entities/entity-registry.test.ts +0 -71
  45. package/__tests__/entities/entity.test.ts +0 -114
  46. package/__tests__/entities/register-entity.decorator.test.ts +0 -54
  47. package/__tests__/formatters/pascal-camel-to-snake.test.ts +0 -19
  48. package/__tests__/http/fetch-http-provider.test.ts +0 -155
  49. package/__tests__/http/http-provider.test.ts +0 -55
  50. package/__tests__/json-api/json-api-connector.test.ts +0 -78
  51. package/__tests__/json-api/json-api-list.test.ts +0 -24
  52. package/__tests__/json-api/json-api-single.test.ts +0 -24
  53. package/__tests__/json-api/url-criteria-builder.test.ts +0 -74
  54. package/__tests__/messages/message.test.ts +0 -16
  55. package/__tests__/models/base-model.test.ts +0 -10
  56. package/__tests__/state-manager/state-manager.test.ts +0 -101
  57. package/__tests__/unit-of-work/unit-of-work.test.ts +0 -47
  58. package/__tests__/utils/url/url-with-params-builder.test.ts +0 -39
  59. package/__tests__/value-objects/coordinates-value.test.ts +0 -68
  60. package/__tests__/value-objects/email-value.test.ts +0 -43
  61. package/__tests__/value-objects/enum-value.test.ts +0 -51
  62. package/__tests__/value-objects/integer-value.test.ts +0 -115
  63. package/__tests__/value-objects/phone-value.test.ts +0 -82
  64. package/__tests__/value-objects/slug-value.test.ts +0 -43
  65. package/__tests__/value-objects/string-value.test.ts +0 -121
  66. package/__tests__/value-objects/uuid-value.test.ts +0 -67
  67. package/__tests__/value-objects/value-object.test.ts +0 -25
  68. package/jest.config.js +0 -25
  69. package/src/abac/index.ts +0 -1
  70. package/src/abac/predicate.ts +0 -3
  71. package/src/auth/auth-provider.ts +0 -11
  72. package/src/auth/exceptions/index.ts +0 -2
  73. package/src/auth/exceptions/not-authenticated.ts +0 -11
  74. package/src/auth/exceptions/require-auth-not-implemented-correctly.ts +0 -11
  75. package/src/auth/index.ts +0 -3
  76. package/src/auth/require-auth.decorator.ts +0 -42
  77. package/src/converters/index.ts +0 -1
  78. package/src/converters/remote-file-to-base64.ts +0 -19
  79. package/src/criteria/criteria.ts +0 -46
  80. package/src/criteria/direction.ts +0 -1
  81. package/src/criteria/exceptions/index.ts +0 -2
  82. package/src/criteria/exceptions/limit-not-valid.ts +0 -11
  83. package/src/criteria/exceptions/offset-not-valid.ts +0 -11
  84. package/src/criteria/index.ts +0 -5
  85. package/src/criteria/operator.ts +0 -12
  86. package/src/criteria/order.ts +0 -4
  87. package/src/dao/dao.ts +0 -16
  88. package/src/dao/index.ts +0 -1
  89. package/src/domain-events/domain-event-primitives.ts +0 -10
  90. package/src/domain-events/domain-event-registry.ts +0 -40
  91. package/src/domain-events/domain-event.ts +0 -29
  92. package/src/domain-events/exceptions/domain-event-not-registered.ts +0 -11
  93. package/src/domain-events/exceptions/index.ts +0 -1
  94. package/src/domain-events/index.ts +0 -4
  95. package/src/entities/entity-registry.ts +0 -30
  96. package/src/entities/entity.ts +0 -25
  97. package/src/entities/exceptions/entity-not-registered.ts +0 -11
  98. package/src/entities/exceptions/index.ts +0 -1
  99. package/src/entities/index.ts +0 -4
  100. package/src/entities/register-entity.decorator.ts +0 -16
  101. package/src/event-bus/event-store.ts +0 -9
  102. package/src/event-bus/event-subscriber.ts +0 -5
  103. package/src/event-bus/in-memory/async-in-memory-event-bus.ts +0 -67
  104. package/src/event-bus/in-memory/in-memory-event-store.ts +0 -28
  105. package/src/event-bus/in-memory/index.ts +0 -2
  106. package/src/event-bus/index.ts +0 -3
  107. package/src/formatters/index.ts +0 -1
  108. package/src/formatters/pascal-camel-to-snake.ts +0 -8
  109. package/src/http/exceptions/http-exception.ts +0 -8
  110. package/src/http/exceptions/index.ts +0 -1
  111. package/src/http/fetch-http-provider.ts +0 -151
  112. package/src/http/http-interceptor.ts +0 -3
  113. package/src/http/http-provider.ts +0 -7
  114. package/src/http/index.ts +0 -5
  115. package/src/i18n/index.ts +0 -2
  116. package/src/i18n/shared-kernel-translation-keys.ts +0 -19
  117. package/src/i18n/translation-resolver.ts +0 -3
  118. package/src/index.ts +0 -21
  119. package/src/json-api/exceptions/index.ts +0 -1
  120. package/src/json-api/exceptions/json-api-errors.ts +0 -17
  121. package/src/json-api/index.ts +0 -5
  122. package/src/json-api/json-api-connector.ts +0 -97
  123. package/src/json-api/json-api-list.ts +0 -13
  124. package/src/json-api/json-api-single.ts +0 -13
  125. package/src/json-api/url-criteria-builder.ts +0 -49
  126. package/src/messages/index.ts +0 -1
  127. package/src/messages/message.ts +0 -3
  128. package/src/models/base-model.ts +0 -3
  129. package/src/models/index.ts +0 -1
  130. package/src/pub-sub/index.ts +0 -2
  131. package/src/pub-sub/publisher.ts +0 -3
  132. package/src/pub-sub/subscription.ts +0 -7
  133. package/src/rbac/base-resource.ts +0 -3
  134. package/src/rbac/exceptions/index.ts +0 -1
  135. package/src/rbac/exceptions/not-authorized.ts +0 -1
  136. package/src/rbac/index.ts +0 -5
  137. package/src/rbac/permission.ts +0 -4
  138. package/src/rbac/rbac-policy.ts +0 -41
  139. package/src/result/index.ts +0 -1
  140. package/src/result/result.ts +0 -35
  141. package/src/state-manager/in-memory-state-manager.ts +0 -22
  142. package/src/state-manager/index.ts +0 -3
  143. package/src/state-manager/session-storage-state-manager.ts +0 -47
  144. package/src/state-manager/state-manager.ts +0 -28
  145. package/src/telemetry/console-telemetry.ts +0 -27
  146. package/src/telemetry/index.ts +0 -2
  147. package/src/telemetry/telemetry.ts +0 -6
  148. package/src/unit-of-work/index.ts +0 -1
  149. package/src/unit-of-work/unit-of-work.ts +0 -5
  150. package/src/utils/index.ts +0 -2
  151. package/src/utils/url/index.ts +0 -1
  152. package/src/utils/url/url-with-params-builder.ts +0 -19
  153. package/src/utils/value-objects/index.ts +0 -1
  154. package/src/utils/value-objects/rule.ts +0 -3
  155. package/src/value-objects/array-value.ts +0 -92
  156. package/src/value-objects/boolean-value.ts +0 -23
  157. package/src/value-objects/coordinates-value.ts +0 -50
  158. package/src/value-objects/date-value.ts +0 -36
  159. package/src/value-objects/email-value.ts +0 -25
  160. package/src/value-objects/enum-value.ts +0 -27
  161. package/src/value-objects/exceptions/index.ts +0 -2
  162. package/src/value-objects/exceptions/value-not-valid.ts +0 -3
  163. package/src/value-objects/exceptions/values-not-valid.ts +0 -11
  164. package/src/value-objects/float-valuet.ts +0 -39
  165. package/src/value-objects/index.ts +0 -17
  166. package/src/value-objects/integer-value.ts +0 -29
  167. package/src/value-objects/object-value.ts +0 -84
  168. package/src/value-objects/phone-value.ts +0 -53
  169. package/src/value-objects/slug-value.ts +0 -25
  170. package/src/value-objects/string-value.ts +0 -27
  171. package/src/value-objects/uuid-value.ts +0 -34
  172. package/src/value-objects/value-object.ts +0 -7
  173. package/tsconfig.cjs.json +0 -13
  174. package/tsconfig.esm.json +0 -12
  175. package/tsconfig.json +0 -47
package/CHANGELOG DELETED
@@ -1,357 +0,0 @@
1
- # Changelog
2
-
3
- All notable changes to this project will be documented in this file.
4
-
5
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
-
8
- ## [4.2.0] - 2025-10-21
9
-
10
- ### Added
11
-
12
- - Added `ConsoleTelemetry` for dev or test environments.
13
-
14
- ## [4.1.2] - 2025-10-21
15
-
16
- ### Changed
17
-
18
- - Allow any params in the `init` method of the `Telemetry` and `Subscription`.
19
-
20
- ## [4.1.1] - 2025-10-21
21
-
22
- ### Added
23
-
24
- - Added telemetry module to the main entry point.
25
-
26
- ## [4.1.0] - 2025-10-21
27
-
28
- ### Added
29
-
30
- - Added `Telemetry`.
31
-
32
- ## [4.0.0] - 2025-10-21
33
-
34
- ### Added
35
-
36
- - Added `ABAC` support to `RBACPolicy`.
37
-
38
- ## [3.1.5] - 2025-10-18
39
-
40
- ### Fixed
41
-
42
- - Fixed `greater_than_or_equal` validation in the `FloatValue`.
43
-
44
- ## [3.1.4] - 2025-10-18
45
-
46
- ### Added
47
-
48
- - Added `converters` module.
49
-
50
- ## [3.1.3] - 2025-10-18
51
-
52
- ### Added
53
-
54
- - Added support for `meta` field on the body for the `create` method of the `JSONAPIConnector`.
55
-
56
- ## [3.1.2] - 2025-10-18
57
-
58
- ### Added
59
-
60
- - Added support for arrays in the `create` method of the `JSONAPIConnector`.
61
-
62
- ## [3.1.1] - 2025-10-16
63
-
64
- ### Added
65
-
66
- - Added `in-memory` implementation to the `state-manager` module.
67
-
68
- ## [3.1.0] - 2025-10-16
69
-
70
- ### Added
71
-
72
- - Added `pub-sub` module.
73
-
74
- ## [3.0.0] - 2025-10-15
75
-
76
- ### Changed
77
-
78
- - Update how filters are stored in the `Criteria` to allow multiple filters over one field.
79
-
80
- ## [2.6.0] - 2025-10-14
81
-
82
- ### Added
83
-
84
- - Added `countBy` to `DAO`.
85
-
86
- ## [2.5.9] - 2025-10-14
87
-
88
- ### Fixed
89
-
90
- - `JSONAPIErrors` was never thrown in the `JSONAPIConnector` due to a missing `await`.
91
-
92
- ## [2.5.8] - 2025-10-14
93
-
94
- ### Fixed
95
-
96
- - Remove `Object.freeze` from `IntegerValue` and `FloatValue` to prevent errors when assigning the `attributeName` on subclasses.
97
-
98
- ## [2.5.7] - 2025-10-13
99
-
100
- ### Added
101
-
102
- - Added `ObjectValue`.
103
-
104
- ## [2.5.6] - 2025-10-13
105
-
106
- ### Added
107
-
108
- - Added `min` and `max` to `FloatValue`.
109
-
110
- ## [2.5.5] - 2025-10-13
111
-
112
- ### Added
113
-
114
- - Added `greater_than_or_equal` and `less_than_or_equal` to `rule`.
115
-
116
- ## [2.5.4] - 2025-10-13
117
-
118
- ### Added
119
-
120
- - Added `rule` function to avoid the use of `const` when defining the schema on the `ArrayValue`.
121
-
122
- ## [2.5.3] - 2025-10-13
123
-
124
- ### Added
125
-
126
- - Added `ArrayValue` to value-objects.
127
-
128
- ## [2.5.2] - 2025-10-13
129
-
130
- ### Changed
131
-
132
- - Allow `DateValue` to be optional.
133
-
134
- ## [2.5.1] - 2025-10-13
135
-
136
- ### Changed
137
-
138
- - `toPrimitives` method from `DomainEvent` now is defined in the abstract class. In future versions the `DomainEventRegistry` will be updated to handle the transformation of values like date/string and preserve it between conversions.
139
-
140
- ## [2.5.0] - 2025-10-12
141
-
142
- ### Added
143
-
144
- _ Added `event-bus` with `in-memory` implementations.
145
-
146
- ## [2.4.2] - 2025-10-12
147
-
148
- ### Fixed
149
-
150
- - Add `id` param to `create` method in the `JSONAPIConnector`.
151
-
152
- ## [2.4.1] - 2025-10-12
153
-
154
- ### Fixed
155
-
156
- - Added missed export for `JSONAPIErrors`.
157
-
158
- ## [2.4.0] - 2025-10-11
159
-
160
- ### Changed
161
-
162
- - Now the `JSONAPIConnector` throws a `JSONAPIErrors` exception instead of a generic `HTTPException`.
163
-
164
- ## [2.3.4] - 2025-10-11
165
-
166
- ### Changed
167
-
168
- - Allow partial attributes in the `create` and `update` methods of the `JSONAPIConnector`.
169
-
170
- ## [2.3.3] - 2025-10-11
171
-
172
- ### Added
173
-
174
- - Added `ValueNotValid` exception.
175
-
176
- ## [2.3.2] - 2025-10-11
177
-
178
- ### Added
179
-
180
- - Added `NotAuthorized` exception.
181
-
182
- ## [2.3.1] - 2025-10-11
183
-
184
- ### Changed
185
-
186
- - `userID` now is protected in the `RBACPolicy`.
187
-
188
- ## [2.3.0] - 2025-10-10
189
-
190
- ### Added
191
-
192
- - Added `RBAC` module.
193
-
194
- ## [2.2.4] - 2025-10-10
195
-
196
- ### Changed
197
-
198
- - Remove `Optional` param in the `EnumValue`. Instead allow null values in the `allowedTypes` array.
199
-
200
- ## [2.2.3] - 2025-10-10
201
-
202
- ### Changed
203
-
204
- - Allow `optional` param in the `EnumValue`.
205
-
206
- ## [2.2.2] - 2025-10-10
207
-
208
- ### Added
209
-
210
- - Added `FloatValue` to value-objects.
211
-
212
- ## [2.2.1] - 2025-10-10
213
-
214
- ### Added
215
-
216
- - Added `DateValue` to value-objects.
217
-
218
- ## [2.2.0] - 2025-10-09
219
-
220
- ### Changed
221
-
222
- - Now the `FetchHTTPProvider` returns the body of the request even on errors to handle JSON/API errors better.
223
-
224
- ## [2.0.1]
225
-
226
- ### Added
227
-
228
- - Added `BooleanValue`.
229
-
230
- ## [2.0.0]
231
-
232
- ### Changed
233
-
234
- - Rename method `currentUser` to `getCurrentUser` on the `AuthProvider` interface.
235
-
236
- ## [1.3.2]
237
-
238
- ### Changed
239
-
240
- - Now the `.authenticate` method from `AuthProvider` should return the token to remove responsabilities from it. A `AuthManager` should be implemented instead in case of future needs.
241
-
242
- ## [1.3.1] - 2025-10-04
243
-
244
- ### Added
245
-
246
- - Added `ValuesNotValid` exception to have a central error for value objects.
247
-
248
- ## [1.3.0] - 2025-10-04
249
-
250
- ### Added
251
-
252
- - Added `Result` to have more controlled results in application services.
253
-
254
- ### Fixed
255
-
256
- - Added missed exports for `i18n` module.
257
-
258
- ## [1.2.3] - 2025-10-03
259
-
260
- ### Changed
261
-
262
- - Added to constructor of the `FetchHTTPProvider` the possibility to receive a function to fetch the `Authorization`.
263
-
264
- ## [1.2.2] - 2025-10-03
265
-
266
- ### Added
267
-
268
- - Added implementation of the state manager from the session storage.
269
-
270
- ### Changed
271
-
272
- - `FetchHTTPProvider` now supports the `headers` options.
273
-
274
- ## [1.2.1] - 2025-10-03
275
-
276
- ### Changed
277
-
278
- - `FetchHTTPProvider` now supports the `credentials` options.
279
-
280
- ## [1.2.0] - 2025-10-02
281
-
282
- ### Added
283
-
284
- - Added `i18n` support via `TranslationResolver`.
285
-
286
- ## [1.1.5] - 2025-10-01
287
-
288
- ### Changed
289
-
290
- - Now the `BaseModel` is more flexible to avoid typing issues in the `fromPrimitives` method.
291
-
292
- ## [1.1.4] - 2025-10-01
293
-
294
- ### Added
295
-
296
- - Added support for `CommonJS`.
297
-
298
- ## [1.1.3] - 2025-10-01
299
-
300
- ### Added
301
-
302
- - Added root entry point. Now you can import everything from `@schorts/shared-kernel` instead of having to choose an specific module. Example: `@schorts/shared-kernel/auth`.
303
-
304
- ## [1.1.2] - 2025-09-30
305
-
306
- ### Changed
307
-
308
- - Now the `DAO` actions like `create`, `update` and `delete` can receive a `UnitOfWork`.
309
-
310
- ## [1.1.1] - 2025-09-30
311
-
312
- ### Added
313
-
314
- - Added `RegisterEntity` decorator to only decorate the entity to add it to the `EntityRegistry`.
315
-
316
- ## [1.1.0] - 2025-09-30
317
-
318
- ### Changed
319
-
320
- - Now the `ValueObject` for ID property on `Entity` is required.
321
-
322
- ### Added
323
-
324
- - Added `EntityRegistry` to dynamically instantiate entities in the DAO implementation.
325
-
326
- ## [1.0.5] - 2025-09-30
327
-
328
- ### Added
329
-
330
- - Introduce `DAO` concept for a related package with a `Firestore` implementation.
331
- - Introduce `UnitOfWOrk` concept for a related package with a `Firestore` implementation.
332
-
333
- ## [1.0.4] - 2025-09-30
334
-
335
- ### Fixed
336
-
337
- - Add `dist` folder to the repo and NPM package.
338
-
339
- ## [1.0.3] - 2025-09-30
340
-
341
- ### Added
342
-
343
- - This CHANGELOG file to keep track of the relevant changes.
344
-
345
- ### Changed
346
-
347
- - Removed indirect dependencies from the `package.json`.
348
-
349
- [1.2.0]: https://github.com/schorts99/shared-kernel/compare/v1.2.4...v1.2.0
350
- [1.1.4]: https://github.com/schorts99/shared-kernel/compare/v1.1.3...v1.1.4
351
- [1.1.3]: https://github.com/schorts99/shared-kernel/compare/v1.1.2...v1.1.3
352
- [1.1.2]: https://github.com/schorts99/shared-kernel/compare/v1.1.1...v1.1.2
353
- [1.1.1]: https://github.com/schorts99/shared-kernel/compare/v1.1.0...v1.1.1
354
- [1.1.0]: https://github.com/schorts99/shared-kernel/compare/v1.0.5...v1.1.0
355
- [1.0.5]: https://github.com/schorts99/shared-kernel/compare/v1.0.4...v0.0.5
356
- [1.0.4]: https://github.com/schorts99/shared-kernel/compare/v1.0.3...v0.0.4
357
- [1.0.3]: https://github.com/schorts99/shared-kernel/releases/tag/v1.0.3
@@ -1,50 +0,0 @@
1
- import { expectTypeOf } from "expect-type";
2
-
3
- import { AuthProvider } from "../../src/auth";
4
- import { Entity } from "../../src/entities";
5
- import { UUIDValue } from "../../src/value-objects";
6
-
7
- type Model = {
8
- id: string;
9
- name: string;
10
- };
11
-
12
- class IDValue extends UUIDValue {
13
- attributeName = "ID";
14
- }
15
-
16
- class TestUser extends Entity<IDValue, Model> {
17
- toPrimitives(): Model {
18
- return {
19
- id: this.id.toString(),
20
- name: "test",
21
- };
22
- }
23
- }
24
-
25
- describe('AuthProvider', () => {
26
- it('should declare an "authenticate" method', () => {
27
- expectTypeOf<AuthProvider<TestUser>['authenticate']>().toBeFunction();
28
- expectTypeOf<AuthProvider<TestUser>['authenticate']>().returns.toEqualTypeOf<Promise<void>>();
29
- });
30
-
31
- it('should declare a "logout" method', () => {
32
- expectTypeOf<AuthProvider<TestUser>['logout']>().toBeFunction();
33
- expectTypeOf<AuthProvider<TestUser >['logout']>().returns.toEqualTypeOf<Promise<void>>();
34
- });
35
-
36
- it('should declare a "isAuthenticated" method', () => {
37
- expectTypeOf<AuthProvider<TestUser>['isAuthenticated']>().toBeFunction();
38
- expectTypeOf<AuthProvider<TestUser>['isAuthenticated']>().returns.toEqualTypeOf<Promise<boolean>>();
39
- });
40
-
41
- it('should declare a "currentUser" method', () => {
42
- expectTypeOf<AuthProvider<TestUser>['currentUser']>().toBeFunction();
43
- expectTypeOf<AuthProvider<TestUser>['currentUser']>().returns.toEqualTypeOf<Promise<TestUser | null>>();
44
- });
45
-
46
- it('should declare a "onAuthChange" method', () => {
47
- expectTypeOf<AuthProvider<TestUser>['onAuthChange']>().toBeFunction();
48
- expectTypeOf<AuthProvider<TestUser>['onAuthChange']>().returns.toEqualTypeOf<() => void>();
49
- });
50
- });
@@ -1,88 +0,0 @@
1
- import { RequireAuth, NotAuthenticated } from '../../src/auth';
2
-
3
- class FakeAuthProvider {
4
- constructor(private authenticated: boolean) {}
5
- async isAuthenticated() {
6
- return this.authenticated;
7
- }
8
- }
9
-
10
- class TestService {
11
- authProvider: FakeAuthProvider;
12
-
13
- constructor(authenticated: boolean) {
14
- this.authProvider = new FakeAuthProvider(authenticated);
15
- }
16
-
17
- async securedMethod(): Promise<string> {
18
- return 'should not reach';
19
- }
20
- }
21
-
22
- describe('RequireAuth decorator (manual application)', () => {
23
- it('should throw NotAuthenticated when not authenticated and no onFail', async () => {
24
- const service = new TestService(false);
25
- const originalMethod = service.securedMethod;
26
- const decorated = RequireAuth()(originalMethod, {
27
- kind: 'method',
28
- name: 'securedMethod',
29
- access: { has: () => true, get: () => originalMethod },
30
- static: false,
31
- private: false,
32
- addInitializer: () => {},
33
- metadata: {
34
- get: () => undefined,
35
- set: () => {},
36
- },
37
- });
38
- const wrappedMethod = typeof decorated === 'function' ? decorated : decorated?.value;
39
- service.securedMethod = wrappedMethod.bind(service);
40
-
41
- await expect(service.securedMethod()).rejects.toThrow(NotAuthenticated);
42
- });
43
-
44
- it('should return fallback value when not authenticated and onFail is provided', async () => {
45
- const service = new TestService(false);
46
- const fallback = () => 'fallback';
47
- const originalMethod = service.securedMethod;
48
- const decorated = RequireAuth(fallback)(originalMethod, {
49
- kind: 'method',
50
- name: 'securedMethod',
51
- access: { has: () => true, get: () => originalMethod },
52
- static: false,
53
- private: false,
54
- addInitializer: () => {},
55
- metadata: {
56
- get: () => undefined,
57
- set: () => {},
58
- },
59
- });
60
- const wrappedMethod = typeof decorated === 'function' ? decorated : decorated?.value;
61
- service.securedMethod = wrappedMethod.bind(service);
62
- const result = await service.securedMethod();
63
-
64
- expect(result).toBe('fallback');
65
- });
66
-
67
- it('should call original method when authenticated', async () => {
68
- const service = new TestService(true);
69
- const originalMethod = service.securedMethod;
70
- const decorated = RequireAuth()(originalMethod, {
71
- kind: 'method',
72
- name: 'securedMethod',
73
- access: { has: () => true, get: () => originalMethod },
74
- static: false,
75
- private: false,
76
- addInitializer: () => {},
77
- metadata: {
78
- get: () => undefined,
79
- set: () => {},
80
- },
81
- });
82
- const wrappedMethod = typeof decorated === 'function' ? decorated : decorated?.value;
83
- service.securedMethod = wrappedMethod.bind(service);
84
- const result = await service.securedMethod();
85
-
86
- expect(result).toBe('should not reach');
87
- });
88
- });
@@ -1,159 +0,0 @@
1
- import { expectTypeOf } from "expect-type";
2
-
3
- import {
4
- Criteria,
5
- FilterCriterion,
6
- Order,
7
- Operator,
8
- Direction,
9
- PaginationNotValid,
10
- OffsetNotValid,
11
- LimitNotValid,
12
- } from "../../src/criteria";
13
-
14
- describe('Criteria', () => {
15
- describe('filters', () => {
16
- it('should be defined', () => {
17
- expectTypeOf<Criteria>().toHaveProperty("filters");
18
- });
19
-
20
- it('should be of type Record<string, FilterCriterion>', () => {
21
- expectTypeOf<Criteria["filters"]>().toEqualTypeOf<Record<string, FilterCriterion>>();
22
- });
23
-
24
- it('should be empty', () => {
25
- const criteria = new Criteria();
26
- const filters = criteria.filters;
27
- const filterKeys = Object.keys(filters);
28
-
29
- expect(filterKeys).toHaveLength(0);
30
- });
31
- });
32
-
33
- describe('orders', () => {
34
- it('should be defined', () => {
35
- expectTypeOf<Criteria>().toHaveProperty("orders");
36
- });
37
-
38
- it('should be of type Array<Order>', () => {
39
- expectTypeOf<Criteria["orders"]>().toEqualTypeOf<Array<Order>>();
40
- });
41
-
42
- it('should be empty', () => {
43
- const criteria = new Criteria();
44
- const orders = criteria.orders;
45
-
46
- expect(orders).toHaveLength(0);
47
- });
48
- });
49
-
50
- it('should have a "limit" property of type number or undefined', () => {
51
- expectTypeOf<Criteria>().toHaveProperty("limit");
52
- expectTypeOf<Criteria["limit"]>().toEqualTypeOf<number | undefined>();
53
- });
54
-
55
- it('should have a "offset" property of type number or undefined', () => {
56
- expectTypeOf<Criteria>().toHaveProperty("offset");
57
- expectTypeOf<Criteria["offset"]>().toEqualTypeOf<number | undefined>();
58
- });
59
-
60
- describe('#where', () => {
61
- it('should receive field, operator and value', () => {
62
- expectTypeOf<Criteria["where"]>().parameters.toEqualTypeOf<[string, Operator, any]>();
63
- });
64
-
65
- it('should return the same instance', () => {
66
- const criteria = new Criteria();
67
- const result = criteria.where('field', 'EQUAL', 'value');
68
-
69
- expect(result).toEqual(criteria);
70
- });
71
-
72
- it('should add the filter to the "filters" property', () => {
73
- const criteria = new Criteria();
74
- const result = criteria.where('field', 'EQUAL', 'value');
75
- const filters = result.filters;
76
- const expectedFilters = { field: { value: "value", operator: "EQUAL" } };
77
-
78
- expect(filters["field"]).toBeDefined();
79
- expect(filters).toEqual(expectedFilters);
80
- });
81
- });
82
-
83
- describe('#orderBy', () => {
84
- it('should receive field and direction', () => {
85
- expectTypeOf<Criteria["orderBy"]>().parameters.toEqualTypeOf<[string, Direction?]>();
86
- });
87
-
88
- it('should return the same instance', () => {
89
- const criteria = new Criteria();
90
- const result = criteria.orderBy('field', 'DESC');
91
-
92
- expect(result).toEqual(criteria);
93
- });
94
-
95
- it('should add the order to the "orders" property', () => {
96
- const criteria = new Criteria();
97
- const result = criteria.orderBy("field", "DESC");
98
- const orders = result.orders;
99
- const expectedOrders = [{ field: "field", direction: "DESC" }];
100
-
101
- expect(orders).toHaveLength(1);
102
- expect(orders).toEqual(expectedOrders);
103
- });
104
- });
105
-
106
- describe('#limitResults', () => {
107
- it('should receive a number', () => {
108
- expectTypeOf<Criteria["limitResults"]>().parameters.toEqualTypeOf<[number]>();
109
- });
110
-
111
- it('should return the same instance', () => {
112
- const criteria = new Criteria();
113
- const result = criteria.limitResults(1);
114
-
115
- expect(result).toEqual(criteria);
116
- });
117
-
118
- it('should assign the value to the "limit" property', () => {
119
- const criteria = new Criteria();
120
- const limit = 1;
121
- const result = criteria.limitResults(limit);
122
-
123
- expect(result.limit).toEqual(limit);
124
- });
125
-
126
- it('should throw an LimitNotValid exception if value is less than 1', () => {
127
- const criteria = new Criteria();
128
-
129
- expect(() => criteria.limitResults(0)).toThrow(LimitNotValid);
130
- });
131
- });
132
-
133
- describe('#offsetResults', () => {
134
- it('should receive a number', () => {
135
- expectTypeOf<Criteria["offsetResults"]>().parameters.toEqualTypeOf<[number]>();
136
- });
137
-
138
- it('should return the same instance', () => {
139
- const criteria = new Criteria();
140
- const result = criteria.offsetResults(1);
141
-
142
- expect(result).toEqual(criteria);
143
- });
144
-
145
- it('should assign the value to the "offset" property', () => {
146
- const criteria = new Criteria();
147
- const offset = 1;
148
- const result = criteria.offsetResults(offset);
149
-
150
- expect(result.offset).toEqual(offset);
151
- });
152
-
153
- it('should throw an OffsetNotValid exception if value is less than 1', () => {
154
- const criteria = new Criteria();
155
-
156
- expect(() => criteria.offsetResults(0)).toThrow(OffsetNotValid);
157
- });
158
- });
159
- });
@@ -1,11 +0,0 @@
1
- import { expectTypeOf } from "expect-type";
2
-
3
- import { Direction } from "../../src/criteria";
4
-
5
- type ExpectedDirection = "ASC" | "DESC";
6
-
7
- describe('Direction', () => {
8
- it('should match the expected type', () => {
9
- expectTypeOf<Direction>().toEqualTypeOf<ExpectedDirection>();
10
- });
11
- });
@@ -1,15 +0,0 @@
1
- import { expectTypeOf } from "expect-type";
2
-
3
- import { FilterCriterion, Operator } from "../../src/criteria";
4
-
5
- type ExpectedFilterCriterion = {
6
- value: any;
7
- operator: Operator;
8
- }
9
-
10
- describe('FilterCriterion', () => {
11
- it('should match the expected type', () => {
12
- expectTypeOf<FilterCriterion>().toEqualTypeOf<ExpectedFilterCriterion>();
13
- });
14
- });
15
-
@@ -1,22 +0,0 @@
1
- import { expectTypeOf } from "expect-type";
2
-
3
- import { Operator } from "../../src/criteria";
4
-
5
- type ExpectedOperator =
6
- | "EQUAL"
7
- | "GREATER_THAN"
8
- | "LESS_THAN"
9
- | "GREATER_THAN_OR_EQUAL"
10
- | "LESS_THAN_OR_EQUAL"
11
- | "NOT_EQUAL"
12
- | "IN"
13
- | "NOT_IN"
14
- | "LIKE"
15
- | "BETWEEN"
16
- | "GEO_RADIUS";
17
-
18
- describe('Operator', () => {
19
- it('should match the expected type', () => {
20
- expectTypeOf<Operator>().toEqualTypeOf<ExpectedOperator>();
21
- });
22
- });