@twin.org/core 0.0.1-next.6 → 0.0.1-next.60

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 (79) hide show
  1. package/dist/cjs/index.cjs +1672 -787
  2. package/dist/esm/index.mjs +1668 -788
  3. package/dist/types/encoding/base58.d.ts +18 -0
  4. package/dist/types/errors/baseError.d.ts +2 -1
  5. package/dist/types/factories/factory.d.ts +20 -1
  6. package/dist/types/helpers/arrayHelper.d.ts +13 -0
  7. package/dist/types/helpers/envHelper.d.ts +16 -0
  8. package/dist/types/helpers/errorHelper.d.ts +2 -1
  9. package/dist/types/helpers/jsonHelper.d.ts +30 -0
  10. package/dist/types/helpers/objectHelper.d.ts +33 -0
  11. package/dist/types/helpers/uint8ArrayHelper.d.ts +11 -0
  12. package/dist/types/index.d.ts +7 -0
  13. package/dist/types/models/IComponent.d.ts +12 -3
  14. package/dist/types/models/II18nShared.d.ts +29 -0
  15. package/dist/types/models/coerceType.d.ts +49 -0
  16. package/dist/types/models/compressionType.d.ts +1 -1
  17. package/dist/types/models/objectOrArray.d.ts +4 -0
  18. package/dist/types/utils/asyncCache.d.ts +10 -1
  19. package/dist/types/utils/coerce.d.ts +22 -0
  20. package/dist/types/utils/converter.d.ts +12 -0
  21. package/dist/types/utils/guards.d.ts +35 -0
  22. package/dist/types/utils/is.d.ts +12 -0
  23. package/dist/types/utils/sharedStore.d.ts +23 -0
  24. package/dist/types/utils/validation.d.ts +2 -0
  25. package/docs/changelog.md +79 -1
  26. package/docs/reference/classes/AlreadyExistsError.md +77 -27
  27. package/docs/reference/classes/ArrayHelper.md +79 -5
  28. package/docs/reference/classes/AsyncCache.md +75 -13
  29. package/docs/reference/classes/Base32.md +9 -5
  30. package/docs/reference/classes/Base58.md +61 -0
  31. package/docs/reference/classes/Base64.md +12 -6
  32. package/docs/reference/classes/Base64Url.md +9 -5
  33. package/docs/reference/classes/BaseError.md +79 -29
  34. package/docs/reference/classes/BitString.md +23 -11
  35. package/docs/reference/classes/Coerce.md +110 -12
  36. package/docs/reference/classes/Compression.md +19 -11
  37. package/docs/reference/classes/ConflictError.md +80 -28
  38. package/docs/reference/classes/Converter.md +110 -26
  39. package/docs/reference/classes/EnvHelper.md +45 -0
  40. package/docs/reference/classes/ErrorHelper.md +19 -7
  41. package/docs/reference/classes/Factory.md +95 -17
  42. package/docs/reference/classes/FilenameHelper.md +6 -4
  43. package/docs/reference/classes/GeneralError.md +75 -27
  44. package/docs/reference/classes/GuardError.md +80 -28
  45. package/docs/reference/classes/Guards.md +398 -80
  46. package/docs/reference/classes/HexHelper.md +18 -8
  47. package/docs/reference/classes/I18n.md +46 -20
  48. package/docs/reference/classes/Is.md +179 -51
  49. package/docs/reference/classes/JsonHelper.md +146 -10
  50. package/docs/reference/classes/NotFoundError.md +77 -27
  51. package/docs/reference/classes/NotImplementedError.md +71 -25
  52. package/docs/reference/classes/NotSupportedError.md +74 -26
  53. package/docs/reference/classes/ObjectHelper.md +225 -35
  54. package/docs/reference/classes/RandomHelper.md +6 -4
  55. package/docs/reference/classes/SharedStore.md +94 -0
  56. package/docs/reference/classes/StringHelper.md +54 -20
  57. package/docs/reference/classes/Uint8ArrayHelper.md +35 -0
  58. package/docs/reference/classes/UnauthorizedError.md +74 -26
  59. package/docs/reference/classes/UnprocessableError.md +75 -27
  60. package/docs/reference/classes/Url.md +37 -17
  61. package/docs/reference/classes/Urn.md +63 -27
  62. package/docs/reference/classes/Validation.md +349 -135
  63. package/docs/reference/classes/ValidationError.md +74 -26
  64. package/docs/reference/index.md +8 -0
  65. package/docs/reference/interfaces/IComponent.md +30 -8
  66. package/docs/reference/interfaces/IError.md +2 -2
  67. package/docs/reference/interfaces/II18nShared.md +47 -0
  68. package/docs/reference/interfaces/IKeyValue.md +3 -1
  69. package/docs/reference/interfaces/ILabelledValue.md +3 -1
  70. package/docs/reference/interfaces/ILocaleDictionary.md +1 -1
  71. package/docs/reference/interfaces/IPatchOperation.md +1 -1
  72. package/docs/reference/interfaces/IValidationFailure.md +1 -1
  73. package/docs/reference/type-aliases/CoerceType.md +5 -0
  74. package/docs/reference/type-aliases/CompressionType.md +1 -1
  75. package/docs/reference/type-aliases/ObjectOrArray.md +11 -0
  76. package/docs/reference/variables/CoerceType.md +67 -0
  77. package/docs/reference/variables/CompressionType.md +1 -1
  78. package/locales/en.json +23 -1
  79. package/package.json +6 -6
@@ -8,41 +8,51 @@ Class to handle errors which are triggered by conflicting data.
8
8
 
9
9
  ## Constructors
10
10
 
11
- ### new ConflictError()
11
+ ### Constructor
12
12
 
13
- > **new ConflictError**(`source`, `message`, `conflictId`?, `conflicts`?, `inner`?): [`ConflictError`](ConflictError.md)
13
+ > **new ConflictError**(`source`, `message`, `conflictId?`, `conflicts?`, `inner?`): `ConflictError`
14
14
 
15
15
  Create a new instance of ConflictError.
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
- **conflictId?**: `string`
31
+ ##### conflictId?
32
+
33
+ `string`
28
34
 
29
35
  The id that has conflicts.
30
36
 
31
- **conflicts?**: `string`[]
37
+ ##### conflicts?
38
+
39
+ `string`[]
32
40
 
33
41
  The conflicts that occurred.
34
42
 
35
- **inner?**: `unknown`
43
+ ##### inner?
44
+
45
+ `unknown`
36
46
 
37
47
  The inner error if we have wrapped another error.
38
48
 
39
49
  #### Returns
40
50
 
41
- [`ConflictError`](ConflictError.md)
51
+ `ConflictError`
42
52
 
43
53
  #### Overrides
44
54
 
45
- [`BaseError`](BaseError.md).[`constructor`](BaseError.md#constructors)
55
+ [`BaseError`](BaseError.md).[`constructor`](BaseError.md#constructor)
46
56
 
47
57
  ## Properties
48
58
 
@@ -66,7 +76,7 @@ Any additional information for the error.
66
76
 
67
77
  #### Index Signature
68
78
 
69
- \[`id`: `string`\]: `unknown`
79
+ \[`id`: `string`\]: `unknown`
70
80
 
71
81
  #### Inherited from
72
82
 
@@ -102,7 +112,9 @@ Construct an error from an existing one.
102
112
 
103
113
  #### Parameters
104
114
 
105
- **err**: `unknown`
115
+ ##### err
116
+
117
+ `unknown`
106
118
 
107
119
  The existing error.
108
120
 
@@ -126,7 +138,9 @@ Flatten an error tree.
126
138
 
127
139
  #### Parameters
128
140
 
129
- **err**: `unknown`
141
+ ##### err
142
+
143
+ `unknown`
130
144
 
131
145
  The starting error.
132
146
 
@@ -150,10 +164,12 @@ Expand an error tree.
150
164
 
151
165
  #### Parameters
152
166
 
153
- **errors**: `undefined` \| [`IError`](../interfaces/IError.md)[]
167
+ ##### errors
154
168
 
155
169
  The list of errors to expand.
156
170
 
171
+ `undefined` | [`IError`](../interfaces/IError.md)[]
172
+
157
173
  #### Returns
158
174
 
159
175
  `undefined` \| [`IError`](../interfaces/IError.md)
@@ -174,14 +190,18 @@ Test to see if the error has the specified error name.
174
190
 
175
191
  #### Parameters
176
192
 
177
- **error**: `unknown`
193
+ ##### error
194
+
195
+ `unknown`
178
196
 
179
197
  The error to test.
180
198
 
181
- **name**: `string` \| `RegExp`
199
+ ##### name
182
200
 
183
201
  The name to check for.
184
202
 
203
+ `string` | `RegExp`
204
+
185
205
  #### Returns
186
206
 
187
207
  `error is BaseError`
@@ -202,14 +222,18 @@ Test to see if the error has the specified error message.
202
222
 
203
223
  #### Parameters
204
224
 
205
- **error**: `unknown`
225
+ ##### error
226
+
227
+ `unknown`
206
228
 
207
229
  The error to test.
208
230
 
209
- **message**: `string` \| `RegExp`
231
+ ##### message
210
232
 
211
233
  The message to check for.
212
234
 
235
+ `string` | `RegExp`
236
+
213
237
  #### Returns
214
238
 
215
239
  `error is BaseError`
@@ -230,14 +254,18 @@ Test to see if the error has the specified error code.
230
254
 
231
255
  #### Parameters
232
256
 
233
- **error**: `unknown`
257
+ ##### error
258
+
259
+ `unknown`
234
260
 
235
261
  The error to test.
236
262
 
237
- **code**: `string` \| `RegExp`
263
+ ##### code
238
264
 
239
265
  The code to check for.
240
266
 
267
+ `string` | `RegExp`
268
+
241
269
  #### Returns
242
270
 
243
271
  `boolean`
@@ -258,14 +286,18 @@ Test to see if any of the errors or children have the given error name.
258
286
 
259
287
  #### Parameters
260
288
 
261
- **error**: `unknown`
289
+ ##### error
290
+
291
+ `unknown`
262
292
 
263
293
  The error to test.
264
294
 
265
- **name**: `string` \| `RegExp`
295
+ ##### name
266
296
 
267
297
  The name to check for.
268
298
 
299
+ `string` | `RegExp`
300
+
269
301
  #### Returns
270
302
 
271
303
  `error is BaseError`
@@ -286,14 +318,18 @@ Test to see if any of the errors or children have the given error message.
286
318
 
287
319
  #### Parameters
288
320
 
289
- **error**: `unknown`
321
+ ##### error
322
+
323
+ `unknown`
290
324
 
291
325
  The error to test.
292
326
 
293
- **message**: `string` \| `RegExp`
327
+ ##### message
294
328
 
295
329
  The message to check for.
296
330
 
331
+ `string` | `RegExp`
332
+
297
333
  #### Returns
298
334
 
299
335
  `error is BaseError`
@@ -314,11 +350,15 @@ Test to see if any of the errors or children are from a specific class.
314
350
 
315
351
  #### Parameters
316
352
 
317
- **error**: `unknown`
353
+ ##### error
354
+
355
+ `unknown`
318
356
 
319
357
  The error to test.
320
358
 
321
- **cls**: `string`
359
+ ##### cls
360
+
361
+ `string`
322
362
 
323
363
  The class to check for.
324
364
 
@@ -342,14 +382,18 @@ Test to see if any of the errors or children have the given error code.
342
382
 
343
383
  #### Parameters
344
384
 
345
- **error**: `unknown`
385
+ ##### error
386
+
387
+ `unknown`
346
388
 
347
389
  The error to test.
348
390
 
349
- **code**: `string` \| `RegExp`
391
+ ##### code
350
392
 
351
393
  The code to check for.
352
394
 
395
+ `string` | `RegExp`
396
+
353
397
  #### Returns
354
398
 
355
399
  `error is BaseError`
@@ -364,10 +408,18 @@ True if the error has the name.
364
408
 
365
409
  ### toJsonObject()
366
410
 
367
- > **toJsonObject**(): [`IError`](../interfaces/IError.md)
411
+ > **toJsonObject**(`includeStackTrace?`): [`IError`](../interfaces/IError.md)
368
412
 
369
413
  Serialize the error to the error model.
370
414
 
415
+ #### Parameters
416
+
417
+ ##### includeStackTrace?
418
+
419
+ `boolean`
420
+
421
+ Whether to include the error stack in the model, defaults to false.
422
+
371
423
  #### Returns
372
424
 
373
425
  [`IError`](../interfaces/IError.md)
@@ -4,33 +4,39 @@ Convert arrays to and from different formats.
4
4
 
5
5
  ## Constructors
6
6
 
7
- ### new Converter()
7
+ ### Constructor
8
8
 
9
- > **new Converter**(): [`Converter`](Converter.md)
9
+ > **new Converter**(): `Converter`
10
10
 
11
11
  #### Returns
12
12
 
13
- [`Converter`](Converter.md)
13
+ `Converter`
14
14
 
15
15
  ## Methods
16
16
 
17
17
  ### bytesToUtf8()
18
18
 
19
- > `static` **bytesToUtf8**(`array`, `startIndex`?, `length`?): `string`
19
+ > `static` **bytesToUtf8**(`array`, `startIndex?`, `length?`): `string`
20
20
 
21
21
  Encode a raw array to UTF8 string.
22
22
 
23
23
  #### Parameters
24
24
 
25
- **array**: `ArrayLike`\<`number`\>
25
+ ##### array
26
+
27
+ `ArrayLike`\<`number`\>
26
28
 
27
29
  The bytes to encode.
28
30
 
29
- **startIndex?**: `number`
31
+ ##### startIndex?
32
+
33
+ `number`
30
34
 
31
35
  The index to start in the bytes.
32
36
 
33
- **length?**: `number`
37
+ ##### length?
38
+
39
+ `number`
34
40
 
35
41
  The length of bytes to read.
36
42
 
@@ -50,7 +56,9 @@ Convert a UTF8 string to raw array.
50
56
 
51
57
  #### Parameters
52
58
 
53
- **utf8**: `string`
59
+ ##### utf8
60
+
61
+ `string`
54
62
 
55
63
  The text to decode.
56
64
 
@@ -64,29 +72,39 @@ The array.
64
72
 
65
73
  ### bytesToHex()
66
74
 
67
- > `static` **bytesToHex**(`array`, `includePrefix`, `startIndex`?, `length`?, `reverse`?): `string`
75
+ > `static` **bytesToHex**(`array`, `includePrefix`, `startIndex?`, `length?`, `reverse?`): `string`
68
76
 
69
77
  Encode a raw array to hex string.
70
78
 
71
79
  #### Parameters
72
80
 
73
- **array**: `ArrayLike`\<`number`\>
81
+ ##### array
82
+
83
+ `ArrayLike`\<`number`\>
74
84
 
75
85
  The bytes to encode.
76
86
 
77
- **includePrefix**: `boolean` = `false`
87
+ ##### includePrefix
88
+
89
+ `boolean` = `false`
78
90
 
79
91
  Include the 0x prefix on the returned hex.
80
92
 
81
- **startIndex?**: `number`
93
+ ##### startIndex?
94
+
95
+ `number`
82
96
 
83
97
  The index to start in the bytes.
84
98
 
85
- **length?**: `number`
99
+ ##### length?
100
+
101
+ `number`
86
102
 
87
103
  The length of bytes to read.
88
104
 
89
- **reverse?**: `boolean`
105
+ ##### reverse?
106
+
107
+ `boolean`
90
108
 
91
109
  Reverse the combine direction.
92
110
 
@@ -100,17 +118,21 @@ The array formatted as hex.
100
118
 
101
119
  ### hexToBytes()
102
120
 
103
- > `static` **hexToBytes**(`hex`, `reverse`?): `Uint8Array`
121
+ > `static` **hexToBytes**(`hex`, `reverse?`): `Uint8Array`
104
122
 
105
123
  Decode a hex string to raw array.
106
124
 
107
125
  #### Parameters
108
126
 
109
- **hex**: `string`
127
+ ##### hex
128
+
129
+ `string`
110
130
 
111
131
  The hex to decode.
112
132
 
113
- **reverse?**: `boolean`
133
+ ##### reverse?
134
+
135
+ `boolean`
114
136
 
115
137
  Store the characters in reverse.
116
138
 
@@ -130,11 +152,15 @@ Convert the UTF8 to hex.
130
152
 
131
153
  #### Parameters
132
154
 
133
- **utf8**: `string`
155
+ ##### utf8
156
+
157
+ `string`
134
158
 
135
159
  The text to convert.
136
160
 
137
- **includePrefix**: `boolean` = `false`
161
+ ##### includePrefix
162
+
163
+ `boolean` = `false`
138
164
 
139
165
  Include the 0x prefix on the returned hex.
140
166
 
@@ -154,7 +180,9 @@ Convert the hex text to text.
154
180
 
155
181
  #### Parameters
156
182
 
157
- **hex**: `string`
183
+ ##### hex
184
+
185
+ `string`
158
186
 
159
187
  The hex to convert.
160
188
 
@@ -174,7 +202,9 @@ Convert bytes to binary string.
174
202
 
175
203
  #### Parameters
176
204
 
177
- **bytes**: `Uint8Array`
205
+ ##### bytes
206
+
207
+ `Uint8Array`
178
208
 
179
209
  The bytes to convert.
180
210
 
@@ -194,7 +224,9 @@ Convert a binary string to bytes.
194
224
 
195
225
  #### Parameters
196
226
 
197
- **binary**: `string`
227
+ ##### binary
228
+
229
+ `string`
198
230
 
199
231
  The binary string.
200
232
 
@@ -214,7 +246,9 @@ Convert bytes to base64 string.
214
246
 
215
247
  #### Parameters
216
248
 
217
- **bytes**: `Uint8Array`
249
+ ##### bytes
250
+
251
+ `Uint8Array`
218
252
 
219
253
  The bytes to convert.
220
254
 
@@ -234,7 +268,9 @@ Convert a base64 string to bytes.
234
268
 
235
269
  #### Parameters
236
270
 
237
- **base64**: `string`
271
+ ##### base64
272
+
273
+ `string`
238
274
 
239
275
  The base64 string.
240
276
 
@@ -254,7 +290,9 @@ Convert bytes to base64 url string.
254
290
 
255
291
  #### Parameters
256
292
 
257
- **bytes**: `Uint8Array`
293
+ ##### bytes
294
+
295
+ `Uint8Array`
258
296
 
259
297
  The bytes to convert.
260
298
 
@@ -274,7 +312,9 @@ Convert a base64 url string to bytes.
274
312
 
275
313
  #### Parameters
276
314
 
277
- **base64Url**: `string`
315
+ ##### base64Url
316
+
317
+ `string`
278
318
 
279
319
  The base64 url string.
280
320
 
@@ -283,3 +323,47 @@ The base64 url string.
283
323
  `Uint8Array`
284
324
 
285
325
  The bytes.
326
+
327
+ ***
328
+
329
+ ### bytesToBase58()
330
+
331
+ > `static` **bytesToBase58**(`bytes`): `string`
332
+
333
+ Convert bytes to base58 string.
334
+
335
+ #### Parameters
336
+
337
+ ##### bytes
338
+
339
+ `Uint8Array`
340
+
341
+ The bytes to convert.
342
+
343
+ #### Returns
344
+
345
+ `string`
346
+
347
+ A base58 string of the bytes.
348
+
349
+ ***
350
+
351
+ ### base58ToBytes()
352
+
353
+ > `static` **base58ToBytes**(`base58`): `Uint8Array`
354
+
355
+ Convert a base58 string to bytes.
356
+
357
+ #### Parameters
358
+
359
+ ##### base58
360
+
361
+ `string`
362
+
363
+ The base58 string.
364
+
365
+ #### Returns
366
+
367
+ `Uint8Array`
368
+
369
+ The bytes.
@@ -0,0 +1,45 @@
1
+ # Class: EnvHelper
2
+
3
+ Environment variable helper.
4
+
5
+ ## Constructors
6
+
7
+ ### Constructor
8
+
9
+ > **new EnvHelper**(): `EnvHelper`
10
+
11
+ #### Returns
12
+
13
+ `EnvHelper`
14
+
15
+ ## Methods
16
+
17
+ ### envToJson()
18
+
19
+ > `static` **envToJson**\<`T`\>(`envVars`, `prefix?`): `T`
20
+
21
+ Get the environment variable as an object with camel cased names.
22
+
23
+ #### Type Parameters
24
+
25
+ ##### T
26
+
27
+ `T` = \{[`id`: `string`]: `string`; \}
28
+
29
+ #### Parameters
30
+
31
+ ##### envVars
32
+
33
+ The environment variables.
34
+
35
+ ##### prefix?
36
+
37
+ `string`
38
+
39
+ The prefix of the environment variables, if not provided gets all.
40
+
41
+ #### Returns
42
+
43
+ `T`
44
+
45
+ The object with camel cased names.
@@ -4,28 +4,36 @@ Error helper functions.
4
4
 
5
5
  ## Constructors
6
6
 
7
- ### new ErrorHelper()
7
+ ### Constructor
8
8
 
9
- > **new ErrorHelper**(): [`ErrorHelper`](ErrorHelper.md)
9
+ > **new ErrorHelper**(): `ErrorHelper`
10
10
 
11
11
  #### Returns
12
12
 
13
- [`ErrorHelper`](ErrorHelper.md)
13
+ `ErrorHelper`
14
14
 
15
15
  ## Methods
16
16
 
17
17
  ### formatErrors()
18
18
 
19
- > `static` **formatErrors**(`error`): `string`[]
19
+ > `static` **formatErrors**(`error`, `includeDetails?`): `string`[]
20
20
 
21
21
  Format Errors and returns just their messages.
22
22
 
23
23
  #### Parameters
24
24
 
25
- **error**: `unknown`
25
+ ##### error
26
+
27
+ `unknown`
26
28
 
27
29
  The error to format.
28
30
 
31
+ ##### includeDetails?
32
+
33
+ `boolean`
34
+
35
+ Whether to include error details, defaults to false.
36
+
29
37
  #### Returns
30
38
 
31
39
  `string`[]
@@ -42,7 +50,9 @@ Localize the content of an error and any inner errors.
42
50
 
43
51
  #### Parameters
44
52
 
45
- **error**: `unknown`
53
+ ##### error
54
+
55
+ `unknown`
46
56
 
47
57
  The error to format.
48
58
 
@@ -62,7 +72,9 @@ Localize the content of an error and any inner errors.
62
72
 
63
73
  #### Parameters
64
74
 
65
- **error**: [`IError`](../interfaces/IError.md)
75
+ ##### error
76
+
77
+ [`IError`](../interfaces/IError.md)
66
78
 
67
79
  The error to format.
68
80