@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
@@ -8,37 +8,43 @@ Class to handle errors when some data can not be processed.
8
8
 
9
9
  ## Constructors
10
10
 
11
- ### new UnprocessableError()
11
+ ### Constructor
12
12
 
13
- > **new UnprocessableError**(`source`, `message`, `properties`?, `inner`?): [`UnprocessableError`](UnprocessableError.md)
13
+ > **new UnprocessableError**(`source`, `message`, `properties?`, `inner?`): `UnprocessableError`
14
14
 
15
15
  Create a new instance of UnprocessableError.
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
- **properties?**
31
+ ##### properties?
28
32
 
29
33
  Any additional information for the error.
30
34
 
31
- **inner?**: `unknown`
35
+ ##### inner?
36
+
37
+ `unknown`
32
38
 
33
39
  The inner error if we have wrapped another error.
34
40
 
35
41
  #### Returns
36
42
 
37
- [`UnprocessableError`](UnprocessableError.md)
43
+ `UnprocessableError`
38
44
 
39
45
  #### Overrides
40
46
 
41
- [`BaseError`](BaseError.md).[`constructor`](BaseError.md#constructors)
47
+ [`BaseError`](BaseError.md).[`constructor`](BaseError.md#constructor)
42
48
 
43
49
  ## Properties
44
50
 
@@ -62,7 +68,7 @@ Any additional information for the error.
62
68
 
63
69
  #### Index Signature
64
70
 
65
- \[`id`: `string`\]: `unknown`
71
+ \[`id`: `string`\]: `unknown`
66
72
 
67
73
  #### Inherited from
68
74
 
@@ -98,7 +104,9 @@ Construct an error from an existing one.
98
104
 
99
105
  #### Parameters
100
106
 
101
- **err**: `unknown`
107
+ ##### err
108
+
109
+ `unknown`
102
110
 
103
111
  The existing error.
104
112
 
@@ -122,7 +130,9 @@ Flatten an error tree.
122
130
 
123
131
  #### Parameters
124
132
 
125
- **err**: `unknown`
133
+ ##### err
134
+
135
+ `unknown`
126
136
 
127
137
  The starting error.
128
138
 
@@ -146,10 +156,12 @@ Expand an error tree.
146
156
 
147
157
  #### Parameters
148
158
 
149
- **errors**: `undefined` \| [`IError`](../interfaces/IError.md)[]
159
+ ##### errors
150
160
 
151
161
  The list of errors to expand.
152
162
 
163
+ `undefined` | [`IError`](../interfaces/IError.md)[]
164
+
153
165
  #### Returns
154
166
 
155
167
  `undefined` \| [`IError`](../interfaces/IError.md)
@@ -170,14 +182,18 @@ Test to see if the error has the specified error name.
170
182
 
171
183
  #### Parameters
172
184
 
173
- **error**: `unknown`
185
+ ##### error
186
+
187
+ `unknown`
174
188
 
175
189
  The error to test.
176
190
 
177
- **name**: `string` \| `RegExp`
191
+ ##### name
178
192
 
179
193
  The name to check for.
180
194
 
195
+ `string` | `RegExp`
196
+
181
197
  #### Returns
182
198
 
183
199
  `error is BaseError`
@@ -198,14 +214,18 @@ Test to see if the error has the specified error message.
198
214
 
199
215
  #### Parameters
200
216
 
201
- **error**: `unknown`
217
+ ##### error
218
+
219
+ `unknown`
202
220
 
203
221
  The error to test.
204
222
 
205
- **message**: `string` \| `RegExp`
223
+ ##### message
206
224
 
207
225
  The message to check for.
208
226
 
227
+ `string` | `RegExp`
228
+
209
229
  #### Returns
210
230
 
211
231
  `error is BaseError`
@@ -226,14 +246,18 @@ Test to see if the error has the specified error code.
226
246
 
227
247
  #### Parameters
228
248
 
229
- **error**: `unknown`
249
+ ##### error
250
+
251
+ `unknown`
230
252
 
231
253
  The error to test.
232
254
 
233
- **code**: `string` \| `RegExp`
255
+ ##### code
234
256
 
235
257
  The code to check for.
236
258
 
259
+ `string` | `RegExp`
260
+
237
261
  #### Returns
238
262
 
239
263
  `boolean`
@@ -254,14 +278,18 @@ Test to see if any of the errors or children have the given error name.
254
278
 
255
279
  #### Parameters
256
280
 
257
- **error**: `unknown`
281
+ ##### error
282
+
283
+ `unknown`
258
284
 
259
285
  The error to test.
260
286
 
261
- **name**: `string` \| `RegExp`
287
+ ##### name
262
288
 
263
289
  The name to check for.
264
290
 
291
+ `string` | `RegExp`
292
+
265
293
  #### Returns
266
294
 
267
295
  `error is BaseError`
@@ -282,14 +310,18 @@ Test to see if any of the errors or children have the given error message.
282
310
 
283
311
  #### Parameters
284
312
 
285
- **error**: `unknown`
313
+ ##### error
314
+
315
+ `unknown`
286
316
 
287
317
  The error to test.
288
318
 
289
- **message**: `string` \| `RegExp`
319
+ ##### message
290
320
 
291
321
  The message to check for.
292
322
 
323
+ `string` | `RegExp`
324
+
293
325
  #### Returns
294
326
 
295
327
  `error is BaseError`
@@ -310,11 +342,15 @@ Test to see if any of the errors or children are from a specific class.
310
342
 
311
343
  #### Parameters
312
344
 
313
- **error**: `unknown`
345
+ ##### error
346
+
347
+ `unknown`
314
348
 
315
349
  The error to test.
316
350
 
317
- **cls**: `string`
351
+ ##### cls
352
+
353
+ `string`
318
354
 
319
355
  The class to check for.
320
356
 
@@ -338,14 +374,18 @@ Test to see if any of the errors or children have the given error code.
338
374
 
339
375
  #### Parameters
340
376
 
341
- **error**: `unknown`
377
+ ##### error
378
+
379
+ `unknown`
342
380
 
343
381
  The error to test.
344
382
 
345
- **code**: `string` \| `RegExp`
383
+ ##### code
346
384
 
347
385
  The code to check for.
348
386
 
387
+ `string` | `RegExp`
388
+
349
389
  #### Returns
350
390
 
351
391
  `error is BaseError`
@@ -358,12 +398,46 @@ True if the error has the name.
358
398
 
359
399
  ***
360
400
 
401
+ ### isEmpty()
402
+
403
+ > `static` **isEmpty**(`err`): `boolean`
404
+
405
+ Is the error empty.
406
+
407
+ #### Parameters
408
+
409
+ ##### err
410
+
411
+ [`IError`](../interfaces/IError.md)
412
+
413
+ The error to check for being empty.
414
+
415
+ #### Returns
416
+
417
+ `boolean`
418
+
419
+ True if the error is empty.
420
+
421
+ #### Inherited from
422
+
423
+ [`BaseError`](BaseError.md).[`isEmpty`](BaseError.md#isempty)
424
+
425
+ ***
426
+
361
427
  ### toJsonObject()
362
428
 
363
- > **toJsonObject**(): [`IError`](../interfaces/IError.md)
429
+ > **toJsonObject**(`includeStackTrace?`): [`IError`](../interfaces/IError.md)
364
430
 
365
431
  Serialize the error to the error model.
366
432
 
433
+ #### Parameters
434
+
435
+ ##### includeStackTrace?
436
+
437
+ `boolean`
438
+
439
+ Whether to include the error stack in the model, defaults to false.
440
+
367
441
  #### Returns
368
442
 
369
443
  [`IError`](../interfaces/IError.md)
@@ -4,39 +4,43 @@ Class to help with urls.
4
4
 
5
5
  ## Constructors
6
6
 
7
- ### new Url()
7
+ ### Constructor
8
8
 
9
- > **new Url**(`url`): [`Url`](Url.md)
9
+ > **new Url**(`url`): `Url`
10
10
 
11
11
  Create a new instance of Url.
12
12
 
13
13
  #### Parameters
14
14
 
15
- **url**: `string`
15
+ ##### url
16
+
17
+ `string`
16
18
 
17
19
  The url string.
18
20
 
19
21
  #### Returns
20
22
 
21
- [`Url`](Url.md)
23
+ `Url`
22
24
 
23
25
  ## Methods
24
26
 
25
27
  ### tryParseExact()
26
28
 
27
- > `static` **tryParseExact**(`url`): `undefined` \| [`Url`](Url.md)
29
+ > `static` **tryParseExact**(`url`): `undefined` \| `Url`
28
30
 
29
31
  Try and parse a string into the url parts.
30
32
 
31
33
  #### Parameters
32
34
 
33
- **url**: `unknown`
35
+ ##### url
36
+
37
+ `unknown`
34
38
 
35
39
  The url to parse.
36
40
 
37
41
  #### Returns
38
42
 
39
- `undefined` \| [`Url`](Url.md)
43
+ `undefined` \| `Url`
40
44
 
41
45
  The formatted url or undefined if the value is not a url.
42
46
 
@@ -50,15 +54,21 @@ Parse a string into the url parts.
50
54
 
51
55
  #### Parameters
52
56
 
53
- **source**: `string`
57
+ ##### source
58
+
59
+ `string`
54
60
 
55
61
  The source of the error.
56
62
 
57
- **property**: `string`
63
+ ##### property
64
+
65
+ `string`
58
66
 
59
67
  The name of the property.
60
68
 
61
- **value**: `unknown`
69
+ ##### value
70
+
71
+ `unknown`
62
72
 
63
73
  The url to parse.
64
74
 
@@ -80,15 +90,21 @@ Validate a string as a Url.
80
90
 
81
91
  #### Parameters
82
92
 
83
- **property**: `string`
93
+ ##### property
94
+
95
+ `string`
84
96
 
85
97
  Throw an exception if the url property is invalid.
86
98
 
87
- **value**: `unknown`
99
+ ##### value
100
+
101
+ `unknown`
88
102
 
89
103
  The url to parse.
90
104
 
91
- **failures**: [`IValidationFailure`](../interfaces/IValidationFailure.md)[]
105
+ ##### failures
106
+
107
+ [`IValidationFailure`](../interfaces/IValidationFailure.md)[]
92
108
 
93
109
  The list of failures to add to.
94
110
 
@@ -108,7 +124,9 @@ Construct a url from a URL.
108
124
 
109
125
  #### Parameters
110
126
 
111
- **url**: `URL`
127
+ ##### url
128
+
129
+ `URL`
112
130
 
113
131
  The url to construct from.
114
132
 
@@ -122,19 +140,21 @@ The formatted url.
122
140
 
123
141
  ### fromParts()
124
142
 
125
- > `static` **fromParts**(`urlParts`): [`Url`](Url.md)
143
+ > `static` **fromParts**(`urlParts`): `Url`
126
144
 
127
145
  Construct a url from valid parts.
128
146
 
129
147
  #### Parameters
130
148
 
131
- **urlParts**: [`IUrlParts`](../interfaces/IUrlParts.md)
149
+ ##### urlParts
150
+
151
+ [`IUrlParts`](../interfaces/IUrlParts.md)
132
152
 
133
153
  The url to create the parts from.
134
154
 
135
155
  #### Returns
136
156
 
137
- [`Url`](Url.md)
157
+ `Url`
138
158
 
139
159
  The formatted url.
140
160
 
@@ -4,43 +4,49 @@ Class to help with urns.
4
4
 
5
5
  ## Constructors
6
6
 
7
- ### new Urn()
7
+ ### Constructor
8
8
 
9
- > **new Urn**(`namespaceIdentifier`, `namespaceSpecific`): [`Urn`](Urn.md)
9
+ > **new Urn**(`namespaceIdentifier`, `namespaceSpecific`): `Urn`
10
10
 
11
11
  Create a new instance of Urn.
12
12
 
13
13
  #### Parameters
14
14
 
15
- **namespaceIdentifier**: `string`
15
+ ##### namespaceIdentifier
16
+
17
+ `string`
16
18
 
17
19
  The identifier for the namespace.
18
20
 
19
- **namespaceSpecific**: `string` \| `string`[]
21
+ ##### namespaceSpecific
20
22
 
21
23
  The specific part of the namespace.
22
24
 
25
+ `string` | `string`[]
26
+
23
27
  #### Returns
24
28
 
25
- [`Urn`](Urn.md)
29
+ `Urn`
26
30
 
27
31
  ## Methods
28
32
 
29
33
  ### generateRandom()
30
34
 
31
- > `static` **generateRandom**(`namespace`): [`Urn`](Urn.md)
35
+ > `static` **generateRandom**(`namespace`): `Urn`
32
36
 
33
37
  Generate a random identifier with 32 byte id.
34
38
 
35
39
  #### Parameters
36
40
 
37
- **namespace**: `string`
41
+ ##### namespace
42
+
43
+ `string`
38
44
 
39
45
  The prefix for the urn.
40
46
 
41
47
  #### Returns
42
48
 
43
- [`Urn`](Urn.md)
49
+ `Urn`
44
50
 
45
51
  A new Id in URN format.
46
52
 
@@ -54,11 +60,15 @@ Does the provided urn match the namespace.
54
60
 
55
61
  #### Parameters
56
62
 
57
- **urn**: `string`
63
+ ##### urn
64
+
65
+ `string`
58
66
 
59
67
  The urn to check.
60
68
 
61
- **namespace**: `string`
69
+ ##### namespace
70
+
71
+ `string`
62
72
 
63
73
  The namespace to match.
64
74
 
@@ -72,19 +82,21 @@ True if the namespace matches.
72
82
 
73
83
  ### tryParseExact()
74
84
 
75
- > `static` **tryParseExact**(`urn`): `undefined` \| [`Urn`](Urn.md)
85
+ > `static` **tryParseExact**(`urn`): `undefined` \| `Urn`
76
86
 
77
87
  Try and parse a string into the urn parts.
78
88
 
79
89
  #### Parameters
80
90
 
81
- **urn**: `unknown`
91
+ ##### urn
92
+
93
+ `unknown`
82
94
 
83
95
  The urn to parse.
84
96
 
85
97
  #### Returns
86
98
 
87
- `undefined` \| [`Urn`](Urn.md)
99
+ `undefined` \| `Urn`
88
100
 
89
101
  The formatted urn or undefined if the value is not a urn.
90
102
 
@@ -92,19 +104,21 @@ The formatted urn or undefined if the value is not a urn.
92
104
 
93
105
  ### fromValidString()
94
106
 
95
- > `static` **fromValidString**(`urn`): [`Urn`](Urn.md)
107
+ > `static` **fromValidString**(`urn`): `Urn`
96
108
 
97
109
  Construct a urn from a string that has already been validated.
98
110
 
99
111
  #### Parameters
100
112
 
101
- **urn**: `string`
113
+ ##### urn
114
+
115
+ `string`
102
116
 
103
117
  The urn to parse.
104
118
 
105
119
  #### Returns
106
120
 
107
- [`Urn`](Urn.md)
121
+ `Urn`
108
122
 
109
123
  The formatted urn.
110
124
 
@@ -118,7 +132,9 @@ Add a urn: prefix if there isn't one already.
118
132
 
119
133
  #### Parameters
120
134
 
121
- **urn**: `unknown`
135
+ ##### urn
136
+
137
+ `unknown`
122
138
 
123
139
  The urn string to add a prefix to.
124
140
 
@@ -138,15 +154,21 @@ Parse a string into the urn parts.
138
154
 
139
155
  #### Parameters
140
156
 
141
- **source**: `string`
157
+ ##### source
158
+
159
+ `string`
142
160
 
143
161
  The source of the error.
144
162
 
145
- **property**: `string`
163
+ ##### property
164
+
165
+ `string`
146
166
 
147
167
  The name of the property.
148
168
 
149
- **value**: `unknown`
169
+ ##### value
170
+
171
+ `unknown`
150
172
 
151
173
  The urn to parse.
152
174
 
@@ -168,15 +190,21 @@ Validate a string as a Urn.
168
190
 
169
191
  #### Parameters
170
192
 
171
- **property**: `string`
193
+ ##### property
194
+
195
+ `string`
172
196
 
173
197
  Throw an exception if the urn property is invalid.
174
198
 
175
- **value**: `unknown`
199
+ ##### value
200
+
201
+ `unknown`
176
202
 
177
203
  The urn to parse.
178
204
 
179
- **failures**: [`IValidationFailure`](../interfaces/IValidationFailure.md)[]
205
+ ##### failures
206
+
207
+ [`IValidationFailure`](../interfaces/IValidationFailure.md)[]
180
208
 
181
209
  The list of failures to add to.
182
210
 
@@ -196,7 +224,9 @@ Get the parts.
196
224
 
197
225
  #### Parameters
198
226
 
199
- **startIndex**: `number` = `0`
227
+ ##### startIndex
228
+
229
+ `number` = `0`
200
230
 
201
231
  The index to start from, defaults to 0.
202
232
 
@@ -244,7 +274,9 @@ Get the namespace specific parts.
244
274
 
245
275
  #### Parameters
246
276
 
247
- **startIndex**: `number` = `0`
277
+ ##### startIndex
278
+
279
+ `number` = `0`
248
280
 
249
281
  The index to start from, defaults to 0.
250
282
 
@@ -264,7 +296,9 @@ Get the namespace specific.
264
296
 
265
297
  #### Parameters
266
298
 
267
- **startIndex**: `number` = `0`
299
+ ##### startIndex
300
+
301
+ `number` = `0`
268
302
 
269
303
  The index to start from, defaults to 0.
270
304
 
@@ -284,7 +318,9 @@ Convert the parts in to a full string.
284
318
 
285
319
  #### Parameters
286
320
 
287
- **omitPrefix**: `boolean` = `true`
321
+ ##### omitPrefix
322
+
323
+ `boolean` = `true`
288
324
 
289
325
  Omit the urn: prefix from the string.
290
326