@twin.org/core 0.0.1-next.9 → 0.0.2-next.10

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 (85) hide show
  1. package/dist/cjs/index.cjs +2266 -1470
  2. package/dist/esm/index.mjs +2263 -1471
  3. package/dist/types/errors/alreadyExistsError.d.ts +2 -2
  4. package/dist/types/errors/baseError.d.ts +25 -5
  5. package/dist/types/errors/conflictError.d.ts +2 -2
  6. package/dist/types/errors/generalError.d.ts +2 -2
  7. package/dist/types/errors/notFoundError.d.ts +2 -2
  8. package/dist/types/errors/notSupportedError.d.ts +2 -2
  9. package/dist/types/errors/unauthorizedError.d.ts +2 -2
  10. package/dist/types/errors/unprocessableError.d.ts +2 -2
  11. package/dist/types/factories/factory.d.ts +21 -2
  12. package/dist/types/helpers/arrayHelper.d.ts +13 -0
  13. package/dist/types/helpers/envHelper.d.ts +16 -0
  14. package/dist/types/helpers/errorHelper.d.ts +5 -4
  15. package/dist/types/helpers/jsonHelper.d.ts +30 -0
  16. package/dist/types/helpers/objectHelper.d.ts +25 -0
  17. package/dist/types/helpers/uint8ArrayHelper.d.ts +11 -0
  18. package/dist/types/index.d.ts +6 -0
  19. package/dist/types/models/IComponent.d.ts +6 -6
  20. package/dist/types/models/IError.d.ts +2 -2
  21. package/dist/types/models/II18nShared.d.ts +29 -0
  22. package/dist/types/models/coerceType.d.ts +49 -0
  23. package/dist/types/models/compressionType.d.ts +1 -1
  24. package/dist/types/models/objectOrArray.d.ts +4 -0
  25. package/dist/types/utils/asyncCache.d.ts +10 -1
  26. package/dist/types/utils/coerce.d.ts +22 -0
  27. package/dist/types/utils/guards.d.ts +35 -0
  28. package/dist/types/utils/is.d.ts +18 -0
  29. package/dist/types/utils/sharedStore.d.ts +23 -0
  30. package/dist/types/utils/validation.d.ts +2 -0
  31. package/docs/changelog.md +442 -1
  32. package/docs/reference/classes/AlreadyExistsError.md +166 -32
  33. package/docs/reference/classes/ArrayHelper.md +71 -5
  34. package/docs/reference/classes/AsyncCache.md +75 -13
  35. package/docs/reference/classes/Base32.md +9 -5
  36. package/docs/reference/classes/Base58.md +9 -5
  37. package/docs/reference/classes/Base64.md +12 -6
  38. package/docs/reference/classes/Base64Url.md +9 -5
  39. package/docs/reference/classes/BaseError.md +160 -34
  40. package/docs/reference/classes/BitString.md +23 -11
  41. package/docs/reference/classes/Coerce.md +110 -12
  42. package/docs/reference/classes/Compression.md +19 -11
  43. package/docs/reference/classes/ConflictError.md +169 -33
  44. package/docs/reference/classes/Converter.md +72 -28
  45. package/docs/reference/classes/EnvHelper.md +45 -0
  46. package/docs/reference/classes/ErrorHelper.md +22 -10
  47. package/docs/reference/classes/Factory.md +96 -18
  48. package/docs/reference/classes/FilenameHelper.md +6 -4
  49. package/docs/reference/classes/GeneralError.md +164 -32
  50. package/docs/reference/classes/GuardError.md +168 -32
  51. package/docs/reference/classes/Guards.md +398 -80
  52. package/docs/reference/classes/HexHelper.md +18 -8
  53. package/docs/reference/classes/I18n.md +46 -20
  54. package/docs/reference/classes/Is.md +207 -51
  55. package/docs/reference/classes/JsonHelper.md +146 -10
  56. package/docs/reference/classes/NotFoundError.md +166 -32
  57. package/docs/reference/classes/NotImplementedError.md +159 -29
  58. package/docs/reference/classes/NotSupportedError.md +163 -31
  59. package/docs/reference/classes/ObjectHelper.md +197 -39
  60. package/docs/reference/classes/RandomHelper.md +6 -4
  61. package/docs/reference/classes/SharedStore.md +94 -0
  62. package/docs/reference/classes/StringHelper.md +54 -20
  63. package/docs/reference/classes/Uint8ArrayHelper.md +35 -0
  64. package/docs/reference/classes/UnauthorizedError.md +163 -31
  65. package/docs/reference/classes/UnprocessableError.md +164 -32
  66. package/docs/reference/classes/Url.md +37 -17
  67. package/docs/reference/classes/Urn.md +63 -27
  68. package/docs/reference/classes/Validation.md +349 -135
  69. package/docs/reference/classes/ValidationError.md +162 -30
  70. package/docs/reference/index.md +7 -0
  71. package/docs/reference/interfaces/IComponent.md +21 -11
  72. package/docs/reference/interfaces/IError.md +4 -4
  73. package/docs/reference/interfaces/II18nShared.md +47 -0
  74. package/docs/reference/interfaces/IKeyValue.md +3 -1
  75. package/docs/reference/interfaces/ILabelledValue.md +3 -1
  76. package/docs/reference/interfaces/ILocaleDictionary.md +1 -1
  77. package/docs/reference/interfaces/IPatchOperation.md +1 -1
  78. package/docs/reference/interfaces/IValidationFailure.md +1 -1
  79. package/docs/reference/type-aliases/CoerceType.md +5 -0
  80. package/docs/reference/type-aliases/CompressionType.md +1 -1
  81. package/docs/reference/type-aliases/ObjectOrArray.md +11 -0
  82. package/docs/reference/variables/CoerceType.md +67 -0
  83. package/docs/reference/variables/CompressionType.md +2 -2
  84. package/locales/en.json +14 -1
  85. package/package.json +7 -7
@@ -4,13 +4,13 @@ Helpers methods for JSON objects.
4
4
 
5
5
  ## Constructors
6
6
 
7
- ### new JsonHelper()
7
+ ### Constructor
8
8
 
9
- > **new JsonHelper**(): [`JsonHelper`](JsonHelper.md)
9
+ > **new JsonHelper**(): `JsonHelper`
10
10
 
11
11
  #### Returns
12
12
 
13
- [`JsonHelper`](JsonHelper.md)
13
+ `JsonHelper`
14
14
 
15
15
  ## Methods
16
16
 
@@ -23,7 +23,9 @@ Based on https://www.rfc-editor.org/rfc/rfc8785.
23
23
 
24
24
  #### Parameters
25
25
 
26
- **object**: `unknown`
26
+ ##### object
27
+
28
+ `unknown`
27
29
 
28
30
  The object to be serialized.
29
31
 
@@ -44,15 +46,21 @@ Based on https://www.rfc-editor.org/rfc/rfc6902.
44
46
 
45
47
  #### Type Parameters
46
48
 
47
- **T** = `unknown`
49
+ ##### T
50
+
51
+ `T` = `unknown`
48
52
 
49
53
  #### Parameters
50
54
 
51
- **object1**: `T`
55
+ ##### object1
56
+
57
+ `T`
52
58
 
53
59
  The first object.
54
60
 
55
- **object2**: `T`
61
+ ##### object2
62
+
63
+ `T`
56
64
 
57
65
  The second object.
58
66
 
@@ -73,15 +81,21 @@ Based on https://www.rfc-editor.org/rfc/rfc6902.
73
81
 
74
82
  #### Type Parameters
75
83
 
76
- **T** = `unknown`
84
+ ##### T
85
+
86
+ `T` = `unknown`
77
87
 
78
88
  #### Parameters
79
89
 
80
- **object**: `T`
90
+ ##### object
91
+
92
+ `T`
81
93
 
82
94
  The object to patch.
83
95
 
84
- **patches**: [`IPatchOperation`](../interfaces/IPatchOperation.md)[]
96
+ ##### patches
97
+
98
+ [`IPatchOperation`](../interfaces/IPatchOperation.md)[]
85
99
 
86
100
  The second object.
87
101
 
@@ -90,3 +104,125 @@ The second object.
90
104
  `T`
91
105
 
92
106
  The updated object.
107
+
108
+ #### Throws
109
+
110
+ GeneralError if the patch fails.
111
+
112
+ ***
113
+
114
+ ### stringifyEx()
115
+
116
+ > `static` **stringifyEx**(`object`, `space?`): `string`
117
+
118
+ Stringify the JSON with support for extended data types date/bigint/uint8array.
119
+
120
+ #### Parameters
121
+
122
+ ##### object
123
+
124
+ `any`
125
+
126
+ The object to stringify.
127
+
128
+ ##### space?
129
+
130
+ Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.
131
+
132
+ `string` | `number`
133
+
134
+ #### Returns
135
+
136
+ `string`
137
+
138
+ The stringified object.
139
+
140
+ ***
141
+
142
+ ### parseEx()
143
+
144
+ > `static` **parseEx**(`json`): `any`
145
+
146
+ Parse the JSON string with support for extended data types date/bigint/uint8array.
147
+
148
+ #### Parameters
149
+
150
+ ##### json
151
+
152
+ `string`
153
+
154
+ The object to pause.
155
+
156
+ #### Returns
157
+
158
+ `any`
159
+
160
+ The object.
161
+
162
+ ***
163
+
164
+ ### stringifyExReplacer()
165
+
166
+ > `static` **stringifyExReplacer**(`this`, `key`, `value`): `unknown`
167
+
168
+ Replacer function to handle extended data types.
169
+
170
+ #### Parameters
171
+
172
+ ##### this
173
+
174
+ `any`
175
+
176
+ The object.
177
+
178
+ ##### key
179
+
180
+ `string`
181
+
182
+ The key.
183
+
184
+ ##### value
185
+
186
+ `unknown`
187
+
188
+ The value.
189
+
190
+ #### Returns
191
+
192
+ `unknown`
193
+
194
+ The value.
195
+
196
+ ***
197
+
198
+ ### parseExReviver()
199
+
200
+ > `static` **parseExReviver**(`this`, `key`, `value`): `unknown`
201
+
202
+ Reviver function to handle extended data types.
203
+
204
+ #### Parameters
205
+
206
+ ##### this
207
+
208
+ `any`
209
+
210
+ The object.
211
+
212
+ ##### key
213
+
214
+ `string`
215
+
216
+ The key.
217
+
218
+ ##### value
219
+
220
+ `unknown`
221
+
222
+ The value.
223
+
224
+ #### Returns
225
+
226
+ `unknown`
227
+
228
+ The value.
@@ -8,37 +8,45 @@ Class to handle errors which are triggered by data not being found.
8
8
 
9
9
  ## Constructors
10
10
 
11
- ### new NotFoundError()
11
+ ### Constructor
12
12
 
13
- > **new NotFoundError**(`source`, `message`, `notFoundId`?, `inner`?): [`NotFoundError`](NotFoundError.md)
13
+ > **new NotFoundError**(`source`, `message`, `notFoundId?`, `cause?`): `NotFoundError`
14
14
 
15
15
  Create a new instance of NotFoundError.
16
16
 
17
17
  #### Parameters
18
18
 
19
- **source**: `string`
19
+ ##### source
20
+
21
+ `string`
20
22
 
21
23
  The source of the error.
22
24
 
23
- **message**: `string`
25
+ ##### message
26
+
27
+ `string`
24
28
 
25
29
  The message as a code.
26
30
 
27
- **notFoundId?**: `string`
31
+ ##### notFoundId?
32
+
33
+ `string`
28
34
 
29
35
  The id for the item.
30
36
 
31
- **inner?**: `unknown`
37
+ ##### cause?
32
38
 
33
- The inner error if we have wrapped another error.
39
+ `unknown`
40
+
41
+ The cause of the error if we have wrapped another error.
34
42
 
35
43
  #### Returns
36
44
 
37
- [`NotFoundError`](NotFoundError.md)
45
+ `NotFoundError`
38
46
 
39
47
  #### Overrides
40
48
 
41
- [`BaseError`](BaseError.md).[`constructor`](BaseError.md#constructors)
49
+ [`BaseError`](BaseError.md).[`constructor`](BaseError.md#constructor)
42
50
 
43
51
  ## Properties
44
52
 
@@ -62,7 +70,7 @@ Any additional information for the error.
62
70
 
63
71
  #### Index Signature
64
72
 
65
- \[`id`: `string`\]: `unknown`
73
+ \[`id`: `string`\]: `unknown`
66
74
 
67
75
  #### Inherited from
68
76
 
@@ -70,15 +78,15 @@ Any additional information for the error.
70
78
 
71
79
  ***
72
80
 
73
- ### inner?
81
+ ### cause?
74
82
 
75
- > `optional` **inner**: [`IError`](../interfaces/IError.md)
83
+ > `optional` **cause**: [`IError`](../interfaces/IError.md)
76
84
 
77
- The inner error if there was one.
85
+ The cause of the error.
78
86
 
79
87
  #### Inherited from
80
88
 
81
- [`BaseError`](BaseError.md).[`inner`](BaseError.md#inner)
89
+ [`BaseError`](BaseError.md).[`cause`](BaseError.md#cause)
82
90
 
83
91
  ***
84
92
 
@@ -98,7 +106,9 @@ Construct an error from an existing one.
98
106
 
99
107
  #### Parameters
100
108
 
101
- **err**: `unknown`
109
+ ##### err
110
+
111
+ `unknown`
102
112
 
103
113
  The existing error.
104
114
 
@@ -122,7 +132,9 @@ Flatten an error tree.
122
132
 
123
133
  #### Parameters
124
134
 
125
- **err**: `unknown`
135
+ ##### err
136
+
137
+ `unknown`
126
138
 
127
139
  The starting error.
128
140
 
@@ -146,10 +158,12 @@ Expand an error tree.
146
158
 
147
159
  #### Parameters
148
160
 
149
- **errors**: `undefined` \| [`IError`](../interfaces/IError.md)[]
161
+ ##### errors
150
162
 
151
163
  The list of errors to expand.
152
164
 
165
+ `undefined` | [`IError`](../interfaces/IError.md)[]
166
+
153
167
  #### Returns
154
168
 
155
169
  `undefined` \| [`IError`](../interfaces/IError.md)
@@ -170,14 +184,18 @@ Test to see if the error has the specified error name.
170
184
 
171
185
  #### Parameters
172
186
 
173
- **error**: `unknown`
187
+ ##### error
188
+
189
+ `unknown`
174
190
 
175
191
  The error to test.
176
192
 
177
- **name**: `string` \| `RegExp`
193
+ ##### name
178
194
 
179
195
  The name to check for.
180
196
 
197
+ `string` | `RegExp`
198
+
181
199
  #### Returns
182
200
 
183
201
  `error is BaseError`
@@ -198,14 +216,18 @@ Test to see if the error has the specified error message.
198
216
 
199
217
  #### Parameters
200
218
 
201
- **error**: `unknown`
219
+ ##### error
220
+
221
+ `unknown`
202
222
 
203
223
  The error to test.
204
224
 
205
- **message**: `string` \| `RegExp`
225
+ ##### message
206
226
 
207
227
  The message to check for.
208
228
 
229
+ `string` | `RegExp`
230
+
209
231
  #### Returns
210
232
 
211
233
  `error is BaseError`
@@ -226,14 +248,18 @@ Test to see if the error has the specified error code.
226
248
 
227
249
  #### Parameters
228
250
 
229
- **error**: `unknown`
251
+ ##### error
252
+
253
+ `unknown`
230
254
 
231
255
  The error to test.
232
256
 
233
- **code**: `string` \| `RegExp`
257
+ ##### code
234
258
 
235
259
  The code to check for.
236
260
 
261
+ `string` | `RegExp`
262
+
237
263
  #### Returns
238
264
 
239
265
  `boolean`
@@ -254,14 +280,18 @@ Test to see if any of the errors or children have the given error name.
254
280
 
255
281
  #### Parameters
256
282
 
257
- **error**: `unknown`
283
+ ##### error
284
+
285
+ `unknown`
258
286
 
259
287
  The error to test.
260
288
 
261
- **name**: `string` \| `RegExp`
289
+ ##### name
262
290
 
263
291
  The name to check for.
264
292
 
293
+ `string` | `RegExp`
294
+
265
295
  #### Returns
266
296
 
267
297
  `error is BaseError`
@@ -282,14 +312,18 @@ Test to see if any of the errors or children have the given error message.
282
312
 
283
313
  #### Parameters
284
314
 
285
- **error**: `unknown`
315
+ ##### error
316
+
317
+ `unknown`
286
318
 
287
319
  The error to test.
288
320
 
289
- **message**: `string` \| `RegExp`
321
+ ##### message
290
322
 
291
323
  The message to check for.
292
324
 
325
+ `string` | `RegExp`
326
+
293
327
  #### Returns
294
328
 
295
329
  `error is BaseError`
@@ -310,11 +344,15 @@ Test to see if any of the errors or children are from a specific class.
310
344
 
311
345
  #### Parameters
312
346
 
313
- **error**: `unknown`
347
+ ##### error
348
+
349
+ `unknown`
314
350
 
315
351
  The error to test.
316
352
 
317
- **cls**: `string`
353
+ ##### cls
354
+
355
+ `string`
318
356
 
319
357
  The class to check for.
320
358
 
@@ -338,14 +376,18 @@ Test to see if any of the errors or children have the given error code.
338
376
 
339
377
  #### Parameters
340
378
 
341
- **error**: `unknown`
379
+ ##### error
380
+
381
+ `unknown`
342
382
 
343
383
  The error to test.
344
384
 
345
- **code**: `string` \| `RegExp`
385
+ ##### code
346
386
 
347
387
  The code to check for.
348
388
 
389
+ `string` | `RegExp`
390
+
349
391
  #### Returns
350
392
 
351
393
  `error is BaseError`
@@ -358,12 +400,104 @@ True if the error has the name.
358
400
 
359
401
  ***
360
402
 
403
+ ### isEmpty()
404
+
405
+ > `static` **isEmpty**(`err`): `boolean`
406
+
407
+ Is the error empty, i.e. does it have no message, source, properties, or cause?
408
+
409
+ #### Parameters
410
+
411
+ ##### err
412
+
413
+ [`IError`](../interfaces/IError.md)
414
+
415
+ The error to check for being empty.
416
+
417
+ #### Returns
418
+
419
+ `boolean`
420
+
421
+ True if the error is empty.
422
+
423
+ #### Inherited from
424
+
425
+ [`BaseError`](BaseError.md).[`isEmpty`](BaseError.md#isempty)
426
+
427
+ ***
428
+
429
+ ### isAggregateError()
430
+
431
+ > `static` **isAggregateError**(`err`): `err is AggregateError`
432
+
433
+ Is the error an aggregate error.
434
+
435
+ #### Parameters
436
+
437
+ ##### err
438
+
439
+ `unknown`
440
+
441
+ The error to check for being an aggregate error.
442
+
443
+ #### Returns
444
+
445
+ `err is AggregateError`
446
+
447
+ True if the error is an aggregate error.
448
+
449
+ #### Inherited from
450
+
451
+ [`BaseError`](BaseError.md).[`isAggregateError`](BaseError.md#isaggregateerror)
452
+
453
+ ***
454
+
455
+ ### fromAggregate()
456
+
457
+ > `static` **fromAggregate**(`err`, `includeStackTrace?`): [`IError`](../interfaces/IError.md)[]
458
+
459
+ Convert the aggregate error to an array of errors.
460
+
461
+ #### Parameters
462
+
463
+ ##### err
464
+
465
+ `unknown`
466
+
467
+ The error to convert.
468
+
469
+ ##### includeStackTrace?
470
+
471
+ `boolean`
472
+
473
+ Whether to include the error stack in the model, defaults to false.
474
+
475
+ #### Returns
476
+
477
+ [`IError`](../interfaces/IError.md)[]
478
+
479
+ The array of errors.
480
+
481
+ #### Inherited from
482
+
483
+ [`BaseError`](BaseError.md).[`fromAggregate`](BaseError.md#fromaggregate)
484
+
485
+ ***
486
+
361
487
  ### toJsonObject()
362
488
 
363
- > **toJsonObject**(): [`IError`](../interfaces/IError.md)
489
+ > **toJsonObject**(`includeStackTrace?`): [`IError`](../interfaces/IError.md)
364
490
 
365
491
  Serialize the error to the error model.
366
492
 
493
+ #### Parameters
494
+
495
+ ##### includeStackTrace?
496
+
497
+ `boolean`
498
+
499
+ Whether to include the error stack in the model, defaults to false.
500
+
367
501
  #### Returns
368
502
 
369
503
  [`IError`](../interfaces/IError.md)