@twin.org/core 0.0.1-next.5 → 0.0.1-next.51

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 (66) hide show
  1. package/dist/cjs/index.cjs +1401 -736
  2. package/dist/esm/index.mjs +1398 -737
  3. package/dist/types/encoding/base58.d.ts +18 -0
  4. package/dist/types/factories/factory.d.ts +20 -1
  5. package/dist/types/helpers/envHelper.d.ts +16 -0
  6. package/dist/types/helpers/jsonHelper.d.ts +30 -0
  7. package/dist/types/helpers/objectHelper.d.ts +33 -0
  8. package/dist/types/helpers/uint8ArrayHelper.d.ts +11 -0
  9. package/dist/types/index.d.ts +4 -0
  10. package/dist/types/models/IComponent.d.ts +12 -3
  11. package/dist/types/models/coerceType.d.ts +49 -0
  12. package/dist/types/models/compressionType.d.ts +1 -1
  13. package/dist/types/utils/asyncCache.d.ts +8 -0
  14. package/dist/types/utils/coerce.d.ts +22 -0
  15. package/dist/types/utils/converter.d.ts +12 -0
  16. package/dist/types/utils/guards.d.ts +16 -0
  17. package/dist/types/utils/is.d.ts +12 -0
  18. package/dist/types/utils/validation.d.ts +2 -0
  19. package/docs/changelog.md +15 -1
  20. package/docs/reference/classes/AlreadyExistsError.md +67 -25
  21. package/docs/reference/classes/ArrayHelper.md +6 -2
  22. package/docs/reference/classes/AsyncCache.md +56 -6
  23. package/docs/reference/classes/Base32.md +6 -2
  24. package/docs/reference/classes/Base58.md +61 -0
  25. package/docs/reference/classes/Base64.md +9 -3
  26. package/docs/reference/classes/Base64Url.md +6 -2
  27. package/docs/reference/classes/BaseError.md +65 -23
  28. package/docs/reference/classes/BitString.md +18 -6
  29. package/docs/reference/classes/Coerce.md +104 -8
  30. package/docs/reference/classes/Compression.md +16 -8
  31. package/docs/reference/classes/ConflictError.md +70 -26
  32. package/docs/reference/classes/Converter.md +104 -20
  33. package/docs/reference/classes/EnvHelper.md +43 -0
  34. package/docs/reference/classes/ErrorHelper.md +9 -3
  35. package/docs/reference/classes/Factory.md +78 -10
  36. package/docs/reference/classes/FilenameHelper.md +3 -1
  37. package/docs/reference/classes/GeneralError.md +65 -25
  38. package/docs/reference/classes/GuardError.md +70 -26
  39. package/docs/reference/classes/Guards.md +286 -74
  40. package/docs/reference/classes/HexHelper.md +15 -5
  41. package/docs/reference/classes/I18n.md +42 -16
  42. package/docs/reference/classes/Is.md +160 -44
  43. package/docs/reference/classes/JsonHelper.md +137 -5
  44. package/docs/reference/classes/NotFoundError.md +67 -25
  45. package/docs/reference/classes/NotImplementedError.md +61 -23
  46. package/docs/reference/classes/NotSupportedError.md +64 -24
  47. package/docs/reference/classes/ObjectHelper.md +188 -20
  48. package/docs/reference/classes/RandomHelper.md +3 -1
  49. package/docs/reference/classes/StringHelper.md +51 -17
  50. package/docs/reference/classes/Uint8ArrayHelper.md +35 -0
  51. package/docs/reference/classes/UnauthorizedError.md +64 -24
  52. package/docs/reference/classes/UnprocessableError.md +65 -25
  53. package/docs/reference/classes/Url.md +30 -10
  54. package/docs/reference/classes/Urn.md +54 -18
  55. package/docs/reference/classes/Validation.md +315 -109
  56. package/docs/reference/classes/ValidationError.md +64 -24
  57. package/docs/reference/index.md +5 -0
  58. package/docs/reference/interfaces/IComponent.md +30 -8
  59. package/docs/reference/interfaces/IError.md +1 -1
  60. package/docs/reference/interfaces/ILocaleDictionary.md +1 -1
  61. package/docs/reference/interfaces/IValidationFailure.md +1 -1
  62. package/docs/reference/type-aliases/CoerceType.md +5 -0
  63. package/docs/reference/variables/CoerceType.md +67 -0
  64. package/docs/reference/variables/CompressionType.md +1 -1
  65. package/locales/en.json +21 -1
  66. package/package.json +6 -6
@@ -16,19 +16,27 @@ Create a new instance of AlreadyExistsError.
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
- **existingId?**: `string`
31
+ ##### existingId?
32
+
33
+ `string`
28
34
 
29
35
  The id for the item.
30
36
 
31
- **inner?**: `unknown`
37
+ ##### inner?
38
+
39
+ `unknown`
32
40
 
33
41
  The inner error if we have wrapped another error.
34
42
 
@@ -58,7 +66,7 @@ The source of the error.
58
66
 
59
67
  #### Inherited from
60
68
 
61
- [`BaseError`](BaseError.md).[`source`](BaseError.md#source)
69
+ [`BaseError`](BaseError.md).[`source`](BaseError.md#source-1)
62
70
 
63
71
  ***
64
72
 
@@ -70,11 +78,11 @@ Any additional information for the error.
70
78
 
71
79
  #### Index Signature
72
80
 
73
- \[`id`: `string`\]: `unknown`
81
+ \[`id`: `string`\]: `unknown`
74
82
 
75
83
  #### Inherited from
76
84
 
77
- [`BaseError`](BaseError.md).[`properties`](BaseError.md#properties)
85
+ [`BaseError`](BaseError.md).[`properties`](BaseError.md#properties-1)
78
86
 
79
87
  ***
80
88
 
@@ -86,7 +94,7 @@ The inner error if there was one.
86
94
 
87
95
  #### Inherited from
88
96
 
89
- [`BaseError`](BaseError.md).[`inner`](BaseError.md#inner)
97
+ [`BaseError`](BaseError.md).[`inner`](BaseError.md#inner-1)
90
98
 
91
99
  ## Methods
92
100
 
@@ -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`
@@ -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
 
@@ -26,15 +26,21 @@ Execute an async request and cache the result.
26
26
 
27
27
  #### Parameters
28
28
 
29
- **key**: `string`
29
+ ##### key
30
+
31
+ `string`
30
32
 
31
33
  The key for the entry in the cache.
32
34
 
33
- **ttlMs**: `undefined` \| `number`
35
+ ##### ttlMs
34
36
 
35
37
  The TTL of the entry in the cache.
36
38
 
37
- **requestMethod**
39
+ `undefined` | `number`
40
+
41
+ ##### requestMethod
42
+
43
+ () => `Promise`\<`T`\>
38
44
 
39
45
  The method to call if not cached.
40
46
 
@@ -58,7 +64,9 @@ Get an entry from the cache.
58
64
 
59
65
  #### Parameters
60
66
 
61
- **key**: `string`
67
+ ##### key
68
+
69
+ `string`
62
70
 
63
71
  The key to get from the cache.
64
72
 
@@ -70,6 +78,44 @@ The item from the cache if it exists.
70
78
 
71
79
  ***
72
80
 
81
+ ### set()
82
+
83
+ > `static` **set**\<`T`\>(`key`, `value`, `ttlMs`?): `Promise`\<`void`\>
84
+
85
+ Set an entry into the cache.
86
+
87
+ #### Type Parameters
88
+
89
+ • **T** = `unknown`
90
+
91
+ #### Parameters
92
+
93
+ ##### key
94
+
95
+ `string`
96
+
97
+ The key to set in the cache.
98
+
99
+ ##### value
100
+
101
+ `T`
102
+
103
+ The value to set in the cache.
104
+
105
+ ##### ttlMs?
106
+
107
+ `number`
108
+
109
+ The TTL of the entry in the cache in ms, defaults to 1s.
110
+
111
+ #### Returns
112
+
113
+ `Promise`\<`void`\>
114
+
115
+ Nothing.
116
+
117
+ ***
118
+
73
119
  ### remove()
74
120
 
75
121
  > `static` **remove**(`key`): `void`
@@ -78,7 +124,9 @@ Remove an entry from the cache.
78
124
 
79
125
  #### Parameters
80
126
 
81
- **key**: `string`
127
+ ##### key
128
+
129
+ `string`
82
130
 
83
131
  The key to remove from the cache.
84
132
 
@@ -96,7 +144,9 @@ Clear the cache.
96
144
 
97
145
  #### Parameters
98
146
 
99
- **prefix?**: `string`
147
+ ##### prefix?
148
+
149
+ `string`
100
150
 
101
151
  Optional prefix to clear only entries with that prefix.
102
152
 
@@ -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
 
@@ -0,0 +1,61 @@
1
+ # Class: Base58
2
+
3
+ Class to help with base58 Encoding/Decoding.
4
+
5
+ ## Constructors
6
+
7
+ ### new Base58()
8
+
9
+ > **new Base58**(): [`Base58`](Base58.md)
10
+
11
+ #### Returns
12
+
13
+ [`Base58`](Base58.md)
14
+
15
+ ## Methods
16
+
17
+ ### decode()
18
+
19
+ > `static` **decode**(`base58`): `Uint8Array`
20
+
21
+ Convert the base 58 string to a byte array.
22
+
23
+ #### Parameters
24
+
25
+ ##### base58
26
+
27
+ `string`
28
+
29
+ The base58 string to convert.
30
+
31
+ #### Returns
32
+
33
+ `Uint8Array`
34
+
35
+ The byte array.
36
+
37
+ #### Throws
38
+
39
+ If the input string contains a character not in the Base58 alphabet.
40
+
41
+ ***
42
+
43
+ ### encode()
44
+
45
+ > `static` **encode**(`bytes`): `string`
46
+
47
+ Convert a byte array to base 58.
48
+
49
+ #### Parameters
50
+
51
+ ##### bytes
52
+
53
+ `Uint8Array`
54
+
55
+ The byte array to encode.
56
+
57
+ #### Returns
58
+
59
+ `string`
60
+
61
+ The data as base58 string.
@@ -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
 
@@ -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
 
@@ -33,23 +33,31 @@ 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
 
@@ -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
 
@@ -111,7 +119,9 @@ 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
 
@@ -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`