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

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 (77) hide show
  1. package/dist/cjs/index.cjs +1574 -833
  2. package/dist/esm/index.mjs +1571 -834
  3. package/dist/types/errors/baseError.d.ts +8 -1
  4. package/dist/types/factories/factory.d.ts +20 -1
  5. package/dist/types/helpers/arrayHelper.d.ts +13 -0
  6. package/dist/types/helpers/envHelper.d.ts +16 -0
  7. package/dist/types/helpers/errorHelper.d.ts +2 -1
  8. package/dist/types/helpers/jsonHelper.d.ts +30 -0
  9. package/dist/types/helpers/objectHelper.d.ts +25 -0
  10. package/dist/types/helpers/uint8ArrayHelper.d.ts +11 -0
  11. package/dist/types/index.d.ts +6 -0
  12. package/dist/types/models/IComponent.d.ts +12 -3
  13. package/dist/types/models/II18nShared.d.ts +29 -0
  14. package/dist/types/models/coerceType.d.ts +49 -0
  15. package/dist/types/models/compressionType.d.ts +1 -1
  16. package/dist/types/models/objectOrArray.d.ts +4 -0
  17. package/dist/types/utils/asyncCache.d.ts +10 -1
  18. package/dist/types/utils/coerce.d.ts +22 -0
  19. package/dist/types/utils/guards.d.ts +35 -0
  20. package/dist/types/utils/is.d.ts +12 -0
  21. package/dist/types/utils/sharedStore.d.ts +23 -0
  22. package/dist/types/utils/validation.d.ts +2 -0
  23. package/docs/changelog.md +323 -1
  24. package/docs/reference/classes/AlreadyExistsError.md +103 -27
  25. package/docs/reference/classes/ArrayHelper.md +71 -5
  26. package/docs/reference/classes/AsyncCache.md +75 -13
  27. package/docs/reference/classes/Base32.md +9 -5
  28. package/docs/reference/classes/Base58.md +9 -5
  29. package/docs/reference/classes/Base64.md +12 -6
  30. package/docs/reference/classes/Base64Url.md +9 -5
  31. package/docs/reference/classes/BaseError.md +101 -29
  32. package/docs/reference/classes/BitString.md +23 -11
  33. package/docs/reference/classes/Coerce.md +110 -12
  34. package/docs/reference/classes/Compression.md +19 -11
  35. package/docs/reference/classes/ConflictError.md +106 -28
  36. package/docs/reference/classes/Converter.md +72 -28
  37. package/docs/reference/classes/EnvHelper.md +45 -0
  38. package/docs/reference/classes/ErrorHelper.md +19 -7
  39. package/docs/reference/classes/Factory.md +95 -17
  40. package/docs/reference/classes/FilenameHelper.md +6 -4
  41. package/docs/reference/classes/GeneralError.md +101 -27
  42. package/docs/reference/classes/GuardError.md +106 -28
  43. package/docs/reference/classes/Guards.md +398 -80
  44. package/docs/reference/classes/HexHelper.md +18 -8
  45. package/docs/reference/classes/I18n.md +46 -20
  46. package/docs/reference/classes/Is.md +179 -51
  47. package/docs/reference/classes/JsonHelper.md +146 -10
  48. package/docs/reference/classes/NotFoundError.md +103 -27
  49. package/docs/reference/classes/NotImplementedError.md +97 -25
  50. package/docs/reference/classes/NotSupportedError.md +100 -26
  51. package/docs/reference/classes/ObjectHelper.md +197 -39
  52. package/docs/reference/classes/RandomHelper.md +6 -4
  53. package/docs/reference/classes/SharedStore.md +94 -0
  54. package/docs/reference/classes/StringHelper.md +54 -20
  55. package/docs/reference/classes/Uint8ArrayHelper.md +35 -0
  56. package/docs/reference/classes/UnauthorizedError.md +100 -26
  57. package/docs/reference/classes/UnprocessableError.md +101 -27
  58. package/docs/reference/classes/Url.md +37 -17
  59. package/docs/reference/classes/Urn.md +63 -27
  60. package/docs/reference/classes/Validation.md +349 -135
  61. package/docs/reference/classes/ValidationError.md +100 -26
  62. package/docs/reference/index.md +7 -0
  63. package/docs/reference/interfaces/IComponent.md +30 -8
  64. package/docs/reference/interfaces/IError.md +2 -2
  65. package/docs/reference/interfaces/II18nShared.md +47 -0
  66. package/docs/reference/interfaces/IKeyValue.md +3 -1
  67. package/docs/reference/interfaces/ILabelledValue.md +3 -1
  68. package/docs/reference/interfaces/ILocaleDictionary.md +1 -1
  69. package/docs/reference/interfaces/IPatchOperation.md +1 -1
  70. package/docs/reference/interfaces/IValidationFailure.md +1 -1
  71. package/docs/reference/type-aliases/CoerceType.md +5 -0
  72. package/docs/reference/type-aliases/CompressionType.md +1 -1
  73. package/docs/reference/type-aliases/ObjectOrArray.md +11 -0
  74. package/docs/reference/variables/CoerceType.md +67 -0
  75. package/docs/reference/variables/CompressionType.md +1 -1
  76. package/locales/en.json +14 -1
  77. package/package.json +7 -7
@@ -4,13 +4,13 @@ Class to help with arrays.
4
4
 
5
5
  ## Constructors
6
6
 
7
- ### new ArrayHelper()
7
+ ### Constructor
8
8
 
9
- > **new ArrayHelper**(): [`ArrayHelper`](ArrayHelper.md)
9
+ > **new ArrayHelper**(): `ArrayHelper`
10
10
 
11
11
  #### Returns
12
12
 
13
- [`ArrayHelper`](ArrayHelper.md)
13
+ `ArrayHelper`
14
14
 
15
15
  ## Methods
16
16
 
@@ -22,11 +22,15 @@ Do the two arrays match.
22
22
 
23
23
  #### Parameters
24
24
 
25
- **arr1**: `unknown`
25
+ ##### arr1
26
+
27
+ `unknown`
26
28
 
27
29
  The first array.
28
30
 
29
- **arr2**: `unknown`
31
+ ##### arr2
32
+
33
+ `unknown`
30
34
 
31
35
  The second array.
32
36
 
@@ -35,3 +39,65 @@ The second array.
35
39
  `boolean`
36
40
 
37
41
  True if both arrays are empty of have the same values.
42
+
43
+ ***
44
+
45
+ ### fromObjectOrArray()
46
+
47
+ Convert an object or array to an array.
48
+
49
+ #### Param
50
+
51
+ The object or array to convert.
52
+
53
+ #### Call Signature
54
+
55
+ > `static` **fromObjectOrArray**\<`T`\>(`value`): `undefined`
56
+
57
+ Convert an object or array to an array.
58
+
59
+ ##### Type Parameters
60
+
61
+ ###### T
62
+
63
+ `T` = `unknown`
64
+
65
+ ##### Parameters
66
+
67
+ ###### value
68
+
69
+ `undefined`
70
+
71
+ The object or array to convert.
72
+
73
+ ##### Returns
74
+
75
+ `undefined`
76
+
77
+ The array.
78
+
79
+ #### Call Signature
80
+
81
+ > `static` **fromObjectOrArray**\<`T`\>(`value`): `T`[]
82
+
83
+ Convert an object or array to an array.
84
+
85
+ ##### Type Parameters
86
+
87
+ ###### T
88
+
89
+ `T` = `unknown`
90
+
91
+ ##### Parameters
92
+
93
+ ###### value
94
+
95
+ [`ObjectOrArray`](../type-aliases/ObjectOrArray.md)\<`T`\>
96
+
97
+ The object or array to convert.
98
+
99
+ ##### Returns
100
+
101
+ `T`[]
102
+
103
+ The array.
@@ -4,40 +4,54 @@ Cache the results from asynchronous requests.
4
4
 
5
5
  ## Constructors
6
6
 
7
- ### new AsyncCache()
7
+ ### Constructor
8
8
 
9
- > **new AsyncCache**(): [`AsyncCache`](AsyncCache.md)
9
+ > **new AsyncCache**(): `AsyncCache`
10
10
 
11
11
  #### Returns
12
12
 
13
- [`AsyncCache`](AsyncCache.md)
13
+ `AsyncCache`
14
14
 
15
15
  ## Methods
16
16
 
17
17
  ### exec()
18
18
 
19
- > `static` **exec**\<`T`\>(`key`, `ttlMs`, `requestMethod`): `undefined` \| `Promise`\<`T`\>
19
+ > `static` **exec**\<`T`\>(`key`, `ttlMs`, `requestMethod`, `cacheFailures?`): `undefined` \| `Promise`\<`T`\>
20
20
 
21
21
  Execute an async request and cache the result.
22
22
 
23
23
  #### Type Parameters
24
24
 
25
- **T** = `unknown`
25
+ ##### T
26
+
27
+ `T` = `unknown`
26
28
 
27
29
  #### Parameters
28
30
 
29
- **key**: `string`
31
+ ##### key
32
+
33
+ `string`
30
34
 
31
35
  The key for the entry in the cache.
32
36
 
33
- **ttlMs**: `undefined` \| `number`
37
+ ##### ttlMs
34
38
 
35
39
  The TTL of the entry in the cache.
36
40
 
37
- **requestMethod**
41
+ `undefined` | `number`
42
+
43
+ ##### requestMethod
44
+
45
+ () => `Promise`\<`T`\>
38
46
 
39
47
  The method to call if not cached.
40
48
 
49
+ ##### cacheFailures?
50
+
51
+ `boolean`
52
+
53
+ Cache failure results, defaults to false.
54
+
41
55
  #### Returns
42
56
 
43
57
  `undefined` \| `Promise`\<`T`\>
@@ -54,11 +68,15 @@ Get an entry from the cache.
54
68
 
55
69
  #### Type Parameters
56
70
 
57
- **T** = `unknown`
71
+ ##### T
72
+
73
+ `T` = `unknown`
58
74
 
59
75
  #### Parameters
60
76
 
61
- **key**: `string`
77
+ ##### key
78
+
79
+ `string`
62
80
 
63
81
  The key to get from the cache.
64
82
 
@@ -70,6 +88,46 @@ The item from the cache if it exists.
70
88
 
71
89
  ***
72
90
 
91
+ ### set()
92
+
93
+ > `static` **set**\<`T`\>(`key`, `value`, `ttlMs?`): `Promise`\<`void`\>
94
+
95
+ Set an entry into the cache.
96
+
97
+ #### Type Parameters
98
+
99
+ ##### T
100
+
101
+ `T` = `unknown`
102
+
103
+ #### Parameters
104
+
105
+ ##### key
106
+
107
+ `string`
108
+
109
+ The key to set in the cache.
110
+
111
+ ##### value
112
+
113
+ `T`
114
+
115
+ The value to set in the cache.
116
+
117
+ ##### ttlMs?
118
+
119
+ `number`
120
+
121
+ The TTL of the entry in the cache in ms, defaults to 1s.
122
+
123
+ #### Returns
124
+
125
+ `Promise`\<`void`\>
126
+
127
+ Nothing.
128
+
129
+ ***
130
+
73
131
  ### remove()
74
132
 
75
133
  > `static` **remove**(`key`): `void`
@@ -78,7 +136,9 @@ Remove an entry from the cache.
78
136
 
79
137
  #### Parameters
80
138
 
81
- **key**: `string`
139
+ ##### key
140
+
141
+ `string`
82
142
 
83
143
  The key to remove from the cache.
84
144
 
@@ -90,13 +150,15 @@ The key to remove from the cache.
90
150
 
91
151
  ### clearCache()
92
152
 
93
- > `static` **clearCache**(`prefix`?): `void`
153
+ > `static` **clearCache**(`prefix?`): `void`
94
154
 
95
155
  Clear the cache.
96
156
 
97
157
  #### Parameters
98
158
 
99
- **prefix?**: `string`
159
+ ##### prefix?
160
+
161
+ `string`
100
162
 
101
163
  Optional prefix to clear only entries with that prefix.
102
164
 
@@ -4,13 +4,13 @@ Class to help with base63 Encoding/Decoding.
4
4
 
5
5
  ## Constructors
6
6
 
7
- ### new Base32()
7
+ ### Constructor
8
8
 
9
- > **new Base32**(): [`Base32`](Base32.md)
9
+ > **new Base32**(): `Base32`
10
10
 
11
11
  #### Returns
12
12
 
13
- [`Base32`](Base32.md)
13
+ `Base32`
14
14
 
15
15
  ## Methods
16
16
 
@@ -22,7 +22,9 @@ Convert the base 32 string to a byte array.
22
22
 
23
23
  #### Parameters
24
24
 
25
- **base32**: `string`
25
+ ##### base32
26
+
27
+ `string`
26
28
 
27
29
  The base32 string to convert.
28
30
 
@@ -46,7 +48,9 @@ Convert a byte array to base 32.
46
48
 
47
49
  #### Parameters
48
50
 
49
- **bytes**: `Uint8Array`
51
+ ##### bytes
52
+
53
+ `Uint8Array`
50
54
 
51
55
  The byte array to convert.
52
56
 
@@ -4,13 +4,13 @@ Class to help with base58 Encoding/Decoding.
4
4
 
5
5
  ## Constructors
6
6
 
7
- ### new Base58()
7
+ ### Constructor
8
8
 
9
- > **new Base58**(): [`Base58`](Base58.md)
9
+ > **new Base58**(): `Base58`
10
10
 
11
11
  #### Returns
12
12
 
13
- [`Base58`](Base58.md)
13
+ `Base58`
14
14
 
15
15
  ## Methods
16
16
 
@@ -22,7 +22,9 @@ Convert the base 58 string to a byte array.
22
22
 
23
23
  #### Parameters
24
24
 
25
- **base58**: `string`
25
+ ##### base58
26
+
27
+ `string`
26
28
 
27
29
  The base58 string to convert.
28
30
 
@@ -46,7 +48,9 @@ Convert a byte array to base 58.
46
48
 
47
49
  #### Parameters
48
50
 
49
- **bytes**: `Uint8Array`
51
+ ##### bytes
52
+
53
+ `Uint8Array`
50
54
 
51
55
  The byte array to encode.
52
56
 
@@ -5,13 +5,13 @@ Sourced from https://github.com/beatgammit/base64-js.
5
5
 
6
6
  ## Constructors
7
7
 
8
- ### new Base64()
8
+ ### Constructor
9
9
 
10
- > **new Base64**(): [`Base64`](Base64.md)
10
+ > **new Base64**(): `Base64`
11
11
 
12
12
  #### Returns
13
13
 
14
- [`Base64`](Base64.md)
14
+ `Base64`
15
15
 
16
16
  ## Methods
17
17
 
@@ -23,7 +23,9 @@ Get the byte length of the data.
23
23
 
24
24
  #### Parameters
25
25
 
26
- **base64**: `string`
26
+ ##### base64
27
+
28
+ `string`
27
29
 
28
30
  The base64 string.
29
31
 
@@ -43,7 +45,9 @@ Convert the base 64 string to a byte array.
43
45
 
44
46
  #### Parameters
45
47
 
46
- **base64**: `string`
48
+ ##### base64
49
+
50
+ `string`
47
51
 
48
52
  The base64 string to convert.
49
53
 
@@ -63,7 +67,9 @@ Convert a byte array to base 64.
63
67
 
64
68
  #### Parameters
65
69
 
66
- **bytes**: `Uint8Array`
70
+ ##### bytes
71
+
72
+ `Uint8Array`
67
73
 
68
74
  The byte array to convert.
69
75
 
@@ -5,13 +5,13 @@ https://www.rfc-editor.org/rfc/rfc4648#section-5.
5
5
 
6
6
  ## Constructors
7
7
 
8
- ### new Base64Url()
8
+ ### Constructor
9
9
 
10
- > **new Base64Url**(): [`Base64Url`](Base64Url.md)
10
+ > **new Base64Url**(): `Base64Url`
11
11
 
12
12
  #### Returns
13
13
 
14
- [`Base64Url`](Base64Url.md)
14
+ `Base64Url`
15
15
 
16
16
  ## Methods
17
17
 
@@ -23,7 +23,9 @@ Convert the base 64 string to a byte array.
23
23
 
24
24
  #### Parameters
25
25
 
26
- **base64Url**: `string`
26
+ ##### base64Url
27
+
28
+ `string`
27
29
 
28
30
  The base64 url string to convert.
29
31
 
@@ -43,7 +45,9 @@ Convert a byte array to base 64 url.
43
45
 
44
46
  #### Parameters
45
47
 
46
- **bytes**: `Uint8Array`
48
+ ##### bytes
49
+
50
+ `Uint8Array`
47
51
 
48
52
  The byte array to convert.
49
53
 
@@ -25,37 +25,45 @@ Class to handle errors.
25
25
 
26
26
  ## Constructors
27
27
 
28
- ### new BaseError()
28
+ ### Constructor
29
29
 
30
- > **new BaseError**(`name`, `source`, `message`, `properties`?, `inner`?): [`BaseError`](BaseError.md)
30
+ > **new BaseError**(`name`, `source`, `message`, `properties?`, `inner?`): `BaseError`
31
31
 
32
32
  Create a new instance of BaseError.
33
33
 
34
34
  #### Parameters
35
35
 
36
- **name**: `string`
36
+ ##### name
37
+
38
+ `string`
37
39
 
38
40
  The name of the error.
39
41
 
40
- **source**: `string`
42
+ ##### source
43
+
44
+ `string`
41
45
 
42
46
  The source of the error.
43
47
 
44
- **message**: `string`
48
+ ##### message
49
+
50
+ `string`
45
51
 
46
52
  The message as a code.
47
53
 
48
- **properties?**
54
+ ##### properties?
49
55
 
50
56
  Any additional information for the error.
51
57
 
52
- **inner?**: `unknown`
58
+ ##### inner?
59
+
60
+ `unknown`
53
61
 
54
62
  The inner error if we have wrapped another error.
55
63
 
56
64
  #### Returns
57
65
 
58
- [`BaseError`](BaseError.md)
66
+ `BaseError`
59
67
 
60
68
  #### Overrides
61
69
 
@@ -83,7 +91,7 @@ Any additional information for the error.
83
91
 
84
92
  #### Index Signature
85
93
 
86
- \[`id`: `string`\]: `unknown`
94
+ \[`id`: `string`\]: `unknown`
87
95
 
88
96
  #### Implementation of
89
97
 
@@ -105,19 +113,21 @@ The inner error if there was one.
105
113
 
106
114
  ### fromError()
107
115
 
108
- > `static` **fromError**(`err`): [`BaseError`](BaseError.md)
116
+ > `static` **fromError**(`err`): `BaseError`
109
117
 
110
118
  Construct an error from an existing one.
111
119
 
112
120
  #### Parameters
113
121
 
114
- **err**: `unknown`
122
+ ##### err
123
+
124
+ `unknown`
115
125
 
116
126
  The existing error.
117
127
 
118
128
  #### Returns
119
129
 
120
- [`BaseError`](BaseError.md)
130
+ `BaseError`
121
131
 
122
132
  The new instance.
123
133
 
@@ -131,7 +141,9 @@ Flatten an error tree.
131
141
 
132
142
  #### Parameters
133
143
 
134
- **err**: `unknown`
144
+ ##### err
145
+
146
+ `unknown`
135
147
 
136
148
  The starting error.
137
149
 
@@ -151,10 +163,12 @@ Expand an error tree.
151
163
 
152
164
  #### Parameters
153
165
 
154
- **errors**: `undefined` \| [`IError`](../interfaces/IError.md)[]
166
+ ##### errors
155
167
 
156
168
  The list of errors to expand.
157
169
 
170
+ `undefined` | [`IError`](../interfaces/IError.md)[]
171
+
158
172
  #### Returns
159
173
 
160
174
  `undefined` \| [`IError`](../interfaces/IError.md)
@@ -171,14 +185,18 @@ Test to see if the error has the specified error name.
171
185
 
172
186
  #### Parameters
173
187
 
174
- **error**: `unknown`
188
+ ##### error
189
+
190
+ `unknown`
175
191
 
176
192
  The error to test.
177
193
 
178
- **name**: `string` \| `RegExp`
194
+ ##### name
179
195
 
180
196
  The name to check for.
181
197
 
198
+ `string` | `RegExp`
199
+
182
200
  #### Returns
183
201
 
184
202
  `error is BaseError`
@@ -195,14 +213,18 @@ Test to see if the error has the specified error message.
195
213
 
196
214
  #### Parameters
197
215
 
198
- **error**: `unknown`
216
+ ##### error
217
+
218
+ `unknown`
199
219
 
200
220
  The error to test.
201
221
 
202
- **message**: `string` \| `RegExp`
222
+ ##### message
203
223
 
204
224
  The message to check for.
205
225
 
226
+ `string` | `RegExp`
227
+
206
228
  #### Returns
207
229
 
208
230
  `error is BaseError`
@@ -219,14 +241,18 @@ Test to see if the error has the specified error code.
219
241
 
220
242
  #### Parameters
221
243
 
222
- **error**: `unknown`
244
+ ##### error
245
+
246
+ `unknown`
223
247
 
224
248
  The error to test.
225
249
 
226
- **code**: `string` \| `RegExp`
250
+ ##### code
227
251
 
228
252
  The code to check for.
229
253
 
254
+ `string` | `RegExp`
255
+
230
256
  #### Returns
231
257
 
232
258
  `boolean`
@@ -243,14 +269,18 @@ Test to see if any of the errors or children have the given error name.
243
269
 
244
270
  #### Parameters
245
271
 
246
- **error**: `unknown`
272
+ ##### error
273
+
274
+ `unknown`
247
275
 
248
276
  The error to test.
249
277
 
250
- **name**: `string` \| `RegExp`
278
+ ##### name
251
279
 
252
280
  The name to check for.
253
281
 
282
+ `string` | `RegExp`
283
+
254
284
  #### Returns
255
285
 
256
286
  `error is BaseError`
@@ -267,14 +297,18 @@ Test to see if any of the errors or children have the given error message.
267
297
 
268
298
  #### Parameters
269
299
 
270
- **error**: `unknown`
300
+ ##### error
301
+
302
+ `unknown`
271
303
 
272
304
  The error to test.
273
305
 
274
- **message**: `string` \| `RegExp`
306
+ ##### message
275
307
 
276
308
  The message to check for.
277
309
 
310
+ `string` | `RegExp`
311
+
278
312
  #### Returns
279
313
 
280
314
  `error is BaseError`
@@ -291,11 +325,15 @@ Test to see if any of the errors or children are from a specific class.
291
325
 
292
326
  #### Parameters
293
327
 
294
- **error**: `unknown`
328
+ ##### error
329
+
330
+ `unknown`
295
331
 
296
332
  The error to test.
297
333
 
298
- **cls**: `string`
334
+ ##### cls
335
+
336
+ `string`
299
337
 
300
338
  The class to check for.
301
339
 
@@ -315,14 +353,18 @@ Test to see if any of the errors or children have the given error code.
315
353
 
316
354
  #### Parameters
317
355
 
318
- **error**: `unknown`
356
+ ##### error
357
+
358
+ `unknown`
319
359
 
320
360
  The error to test.
321
361
 
322
- **code**: `string` \| `RegExp`
362
+ ##### code
323
363
 
324
364
  The code to check for.
325
365
 
366
+ `string` | `RegExp`
367
+
326
368
  #### Returns
327
369
 
328
370
  `error is BaseError`
@@ -331,12 +373,42 @@ True if the error has the name.
331
373
 
332
374
  ***
333
375
 
376
+ ### isEmpty()
377
+
378
+ > `static` **isEmpty**(`err`): `boolean`
379
+
380
+ Is the error empty.
381
+
382
+ #### Parameters
383
+
384
+ ##### err
385
+
386
+ [`IError`](../interfaces/IError.md)
387
+
388
+ The error to check for being empty.
389
+
390
+ #### Returns
391
+
392
+ `boolean`
393
+
394
+ True if the error is empty.
395
+
396
+ ***
397
+
334
398
  ### toJsonObject()
335
399
 
336
- > **toJsonObject**(): [`IError`](../interfaces/IError.md)
400
+ > **toJsonObject**(`includeStackTrace?`): [`IError`](../interfaces/IError.md)
337
401
 
338
402
  Serialize the error to the error model.
339
403
 
404
+ #### Parameters
405
+
406
+ ##### includeStackTrace?
407
+
408
+ `boolean`
409
+
410
+ Whether to include the error stack in the model, defaults to false.
411
+
340
412
  #### Returns
341
413
 
342
414
  [`IError`](../interfaces/IError.md)