@twin.org/core 0.0.2-next.20 → 0.0.2-next.22

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 (34) hide show
  1. package/dist/cjs/index.cjs +107 -76
  2. package/dist/esm/index.mjs +107 -76
  3. package/dist/types/encoding/base32.d.ts +4 -0
  4. package/dist/types/encoding/base58.d.ts +4 -0
  5. package/dist/types/encoding/base64.d.ts +4 -0
  6. package/dist/types/encoding/base64Url.d.ts +4 -0
  7. package/dist/types/factories/factory.d.ts +4 -0
  8. package/dist/types/helpers/jsonHelper.d.ts +4 -0
  9. package/dist/types/helpers/objectHelper.d.ts +4 -0
  10. package/dist/types/models/IComponent.d.ts +4 -2
  11. package/dist/types/models/IValidationFailure.d.ts +0 -4
  12. package/dist/types/types/bitString.d.ts +4 -0
  13. package/dist/types/types/url.d.ts +6 -1
  14. package/dist/types/types/urn.d.ts +6 -1
  15. package/dist/types/utils/compression.d.ts +4 -0
  16. package/dist/types/utils/i18n.d.ts +15 -0
  17. package/docs/changelog.md +34 -0
  18. package/docs/reference/classes/Base32.md +8 -0
  19. package/docs/reference/classes/Base58.md +8 -0
  20. package/docs/reference/classes/Base64.md +8 -0
  21. package/docs/reference/classes/Base64Url.md +8 -0
  22. package/docs/reference/classes/BitString.md +8 -0
  23. package/docs/reference/classes/Compression.md +8 -0
  24. package/docs/reference/classes/Factory.md +8 -0
  25. package/docs/reference/classes/I18n.md +52 -0
  26. package/docs/reference/classes/JsonHelper.md +8 -0
  27. package/docs/reference/classes/ObjectHelper.md +8 -0
  28. package/docs/reference/classes/Url.md +15 -1
  29. package/docs/reference/classes/Urn.md +15 -1
  30. package/docs/reference/interfaces/IComponent.md +5 -5
  31. package/docs/reference/interfaces/IValidationFailure.md +0 -8
  32. package/locales/.validate-ignore +1 -0
  33. package/locales/en.json +4 -5
  34. package/package.json +8 -4
@@ -2,6 +2,10 @@
2
2
  * Class to help with objects.
3
3
  */
4
4
  export declare class ObjectHelper {
5
+ /**
6
+ * Runtime name for the class.
7
+ */
8
+ static readonly CLASS_NAME: string;
5
9
  /**
6
10
  * Convert an object to bytes.
7
11
  * @param obj The object to convert.
@@ -3,9 +3,11 @@
3
3
  */
4
4
  export interface IComponent {
5
5
  /**
6
- * The name of the component.
6
+ * All methods are optional, so we introduce an index signature to allow
7
+ * any additional properties or methods, which removes the TypeScript error where
8
+ * the class has no properties in common with the type.
7
9
  */
8
- readonly CLASS_NAME: string;
10
+ [key: string]: any;
9
11
  /**
10
12
  * Bootstrap the component by creating and initializing any resources it needs.
11
13
  * @param nodeLoggingComponentType The node logging component type.
@@ -10,10 +10,6 @@ export interface IValidationFailure {
10
10
  * The reason the validation failed as an i18 resource error.
11
11
  */
12
12
  reason: string;
13
- /**
14
- * The optional human readable name for the field as an i18 resource.
15
- */
16
- fieldName?: string;
17
13
  /**
18
14
  * Additional properties for the validation failure.
19
15
  */
@@ -2,6 +2,10 @@
2
2
  * A class to represent a bit string.
3
3
  */
4
4
  export declare class BitString {
5
+ /**
6
+ * Runtime name for the class.
7
+ */
8
+ static readonly CLASS_NAME: string;
5
9
  /**
6
10
  * Create a new instance of BitString.
7
11
  * @param numberBits The length of the bit string.
@@ -4,6 +4,10 @@ import type { IValidationFailure } from "../models/IValidationFailure";
4
4
  * Class to help with urls.
5
5
  */
6
6
  export declare class Url {
7
+ /**
8
+ * Runtime name for the class.
9
+ */
10
+ static readonly CLASS_NAME: string;
7
11
  /**
8
12
  * Create a new instance of Url.
9
13
  * @param url The url string.
@@ -28,9 +32,10 @@ export declare class Url {
28
32
  * @param property Throw an exception if the url property is invalid.
29
33
  * @param value The url to parse.
30
34
  * @param failures The list of failures to add to.
35
+ * @param fieldNameResource The optional human readable name for the field as an i18 resource.
31
36
  * @returns The formatted url.
32
37
  */
33
- static validate(property: string, value: unknown, failures: IValidationFailure[]): value is Url;
38
+ static validate(property: string, value: unknown, failures: IValidationFailure[], fieldNameResource?: string): value is Url;
34
39
  /**
35
40
  * Construct a url from a URL.
36
41
  * @param url The url to construct from.
@@ -3,6 +3,10 @@ import type { IValidationFailure } from "../models/IValidationFailure";
3
3
  * Class to help with urns.
4
4
  */
5
5
  export declare class Urn {
6
+ /**
7
+ * Runtime name for the class.
8
+ */
9
+ static readonly CLASS_NAME: string;
6
10
  /**
7
11
  * Create a new instance of Urn.
8
12
  * @param namespaceIdentifier The identifier for the namespace.
@@ -53,9 +57,10 @@ export declare class Urn {
53
57
  * @param property Throw an exception if the urn property is invalid.
54
58
  * @param value The urn to parse.
55
59
  * @param failures The list of failures to add to.
60
+ * @param fieldNameResource The optional human readable name for the field as an i18 resource.
56
61
  * @returns The formatted urn.
57
62
  */
58
- static validate(property: string, value: unknown, failures: IValidationFailure[]): value is string;
63
+ static validate(property: string, value: unknown, failures: IValidationFailure[], fieldNameResource?: string): value is string;
59
64
  /**
60
65
  * Get the parts.
61
66
  * @param startIndex The index to start from, defaults to 0.
@@ -3,6 +3,10 @@ import { CompressionType } from "../models/compressionType";
3
3
  * A class to handle compression.
4
4
  */
5
5
  export declare class Compression {
6
+ /**
7
+ * Runtime name for the class.
8
+ */
9
+ static readonly CLASS_NAME: string;
6
10
  /**
7
11
  * Compress bytes using GZIP.
8
12
  * @param bytes The bytes to compress.
@@ -78,4 +78,19 @@ export declare class I18n {
78
78
  * @returns True if the key exists.
79
79
  */
80
80
  static hasMessage(key: string): boolean;
81
+ /**
82
+ * Flatten the translation property paths for faster lookup.
83
+ * @param translation The translation to merge.
84
+ * @param propertyPath The current root path.
85
+ * @param mergedKeys The merged keys dictionary to populate.
86
+ */
87
+ static flattenTranslationKeys(translation: ILocaleDictionary, propertyPath: string, mergedKeys: {
88
+ [key: string]: string;
89
+ }): void;
90
+ /**
91
+ * Get a list of the property names from the message.
92
+ * @param message The message to extract the property names from.
93
+ * @returns The list of property names.
94
+ */
95
+ static getPropertyNames(message: string): string[];
81
96
  }
package/docs/changelog.md CHANGED
@@ -1,5 +1,39 @@
1
1
  # @twin.org/core - Changelog
2
2
 
3
+ ## [0.0.2-next.22](https://github.com/twinfoundation/framework/compare/core-v0.0.2-next.21...core-v0.0.2-next.22) (2025-10-10)
4
+
5
+
6
+ ### Miscellaneous Chores
7
+
8
+ * **core:** Synchronize repo versions
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/nameof bumped from 0.0.2-next.21 to 0.0.2-next.22
16
+ * devDependencies
17
+ * @twin.org/nameof-transformer bumped from 0.0.2-next.21 to 0.0.2-next.22
18
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.21 to 0.0.2-next.22
19
+
20
+ ## [0.0.2-next.21](https://github.com/twinfoundation/framework/compare/core-v0.0.2-next.20...core-v0.0.2-next.21) (2025-10-09)
21
+
22
+
23
+ ### Features
24
+
25
+ * locales validation ([#197](https://github.com/twinfoundation/framework/issues/197)) ([55fdadb](https://github.com/twinfoundation/framework/commit/55fdadb13595ce0047f787bd1d4135d429a99f12))
26
+
27
+
28
+ ### Dependencies
29
+
30
+ * The following workspace dependencies were updated
31
+ * dependencies
32
+ * @twin.org/nameof bumped from 0.0.2-next.20 to 0.0.2-next.21
33
+ * devDependencies
34
+ * @twin.org/nameof-transformer bumped from 0.0.2-next.20 to 0.0.2-next.21
35
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.20 to 0.0.2-next.21
36
+
3
37
  ## [0.0.2-next.20](https://github.com/twinfoundation/framework/compare/core-v0.0.2-next.19...core-v0.0.2-next.20) (2025-10-02)
4
38
 
5
39
 
@@ -12,6 +12,14 @@ Class to help with base63 Encoding/Decoding.
12
12
 
13
13
  `Base32`
14
14
 
15
+ ## Properties
16
+
17
+ ### CLASS\_NAME
18
+
19
+ > `readonly` `static` **CLASS\_NAME**: `string`
20
+
21
+ Runtime name for the class.
22
+
15
23
  ## Methods
16
24
 
17
25
  ### decode()
@@ -12,6 +12,14 @@ Class to help with base58 Encoding/Decoding.
12
12
 
13
13
  `Base58`
14
14
 
15
+ ## Properties
16
+
17
+ ### CLASS\_NAME
18
+
19
+ > `readonly` `static` **CLASS\_NAME**: `string`
20
+
21
+ Runtime name for the class.
22
+
15
23
  ## Methods
16
24
 
17
25
  ### decode()
@@ -13,6 +13,14 @@ Sourced from https://github.com/beatgammit/base64-js.
13
13
 
14
14
  `Base64`
15
15
 
16
+ ## Properties
17
+
18
+ ### CLASS\_NAME
19
+
20
+ > `readonly` `static` **CLASS\_NAME**: `string`
21
+
22
+ Runtime name for the class.
23
+
16
24
  ## Methods
17
25
 
18
26
  ### byteLength()
@@ -13,6 +13,14 @@ https://www.rfc-editor.org/rfc/rfc4648#section-5.
13
13
 
14
14
  `Base64Url`
15
15
 
16
+ ## Properties
17
+
18
+ ### CLASS\_NAME
19
+
20
+ > `readonly` `static` **CLASS\_NAME**: `string`
21
+
22
+ Runtime name for the class.
23
+
16
24
  ## Methods
17
25
 
18
26
  ### decode()
@@ -22,6 +22,14 @@ The length of the bit string.
22
22
 
23
23
  `BitString`
24
24
 
25
+ ## Properties
26
+
27
+ ### CLASS\_NAME
28
+
29
+ > `readonly` `static` **CLASS\_NAME**: `string`
30
+
31
+ Runtime name for the class.
32
+
25
33
  ## Methods
26
34
 
27
35
  ### fromBits()
@@ -12,6 +12,14 @@ A class to handle compression.
12
12
 
13
13
  `Compression`
14
14
 
15
+ ## Properties
16
+
17
+ ### CLASS\_NAME
18
+
19
+ > `readonly` `static` **CLASS\_NAME**: `string`
20
+
21
+ Runtime name for the class.
22
+
15
23
  ## Methods
16
24
 
17
25
  ### compress()
@@ -8,6 +8,14 @@ Factory for creating implementation of generic types.
8
8
 
9
9
  `T`
10
10
 
11
+ ## Properties
12
+
13
+ ### CLASS\_NAME
14
+
15
+ > `readonly` `static` **CLASS\_NAME**: `string`
16
+
17
+ Runtime name for the class.
18
+
11
19
  ## Methods
12
20
 
13
21
  ### createFactory()
@@ -261,3 +261,55 @@ The key to check for existence.
261
261
  `boolean`
262
262
 
263
263
  True if the key exists.
264
+
265
+ ***
266
+
267
+ ### flattenTranslationKeys()
268
+
269
+ > `static` **flattenTranslationKeys**(`translation`, `propertyPath`, `mergedKeys`): `void`
270
+
271
+ Flatten the translation property paths for faster lookup.
272
+
273
+ #### Parameters
274
+
275
+ ##### translation
276
+
277
+ [`ILocaleDictionary`](../interfaces/ILocaleDictionary.md)
278
+
279
+ The translation to merge.
280
+
281
+ ##### propertyPath
282
+
283
+ `string`
284
+
285
+ The current root path.
286
+
287
+ ##### mergedKeys
288
+
289
+ The merged keys dictionary to populate.
290
+
291
+ #### Returns
292
+
293
+ `void`
294
+
295
+ ***
296
+
297
+ ### getPropertyNames()
298
+
299
+ > `static` **getPropertyNames**(`message`): `string`[]
300
+
301
+ Get a list of the property names from the message.
302
+
303
+ #### Parameters
304
+
305
+ ##### message
306
+
307
+ `string`
308
+
309
+ The message to extract the property names from.
310
+
311
+ #### Returns
312
+
313
+ `string`[]
314
+
315
+ The list of property names.
@@ -12,6 +12,14 @@ Helpers methods for JSON objects.
12
12
 
13
13
  `JsonHelper`
14
14
 
15
+ ## Properties
16
+
17
+ ### CLASS\_NAME
18
+
19
+ > `readonly` `static` **CLASS\_NAME**: `string`
20
+
21
+ Runtime name for the class.
22
+
15
23
  ## Methods
16
24
 
17
25
  ### canonicalize()
@@ -12,6 +12,14 @@ Class to help with objects.
12
12
 
13
13
  `ObjectHelper`
14
14
 
15
+ ## Properties
16
+
17
+ ### CLASS\_NAME
18
+
19
+ > `readonly` `static` **CLASS\_NAME**: `string`
20
+
21
+ Runtime name for the class.
22
+
15
23
  ## Methods
16
24
 
17
25
  ### toBytes()
@@ -22,6 +22,14 @@ The url string.
22
22
 
23
23
  `Url`
24
24
 
25
+ ## Properties
26
+
27
+ ### CLASS\_NAME
28
+
29
+ > `readonly` `static` **CLASS\_NAME**: `string`
30
+
31
+ Runtime name for the class.
32
+
25
33
  ## Methods
26
34
 
27
35
  ### tryParseExact()
@@ -84,7 +92,7 @@ GuardError If the value does not match the assertion.
84
92
 
85
93
  ### validate()
86
94
 
87
- > `static` **validate**(`property`, `value`, `failures`): `value is Url`
95
+ > `static` **validate**(`property`, `value`, `failures`, `fieldNameResource?`): `value is Url`
88
96
 
89
97
  Validate a string as a Url.
90
98
 
@@ -108,6 +116,12 @@ The url to parse.
108
116
 
109
117
  The list of failures to add to.
110
118
 
119
+ ##### fieldNameResource?
120
+
121
+ `string`
122
+
123
+ The optional human readable name for the field as an i18 resource.
124
+
111
125
  #### Returns
112
126
 
113
127
  `value is Url`
@@ -28,6 +28,14 @@ The specific part of the namespace.
28
28
 
29
29
  `Urn`
30
30
 
31
+ ## Properties
32
+
33
+ ### CLASS\_NAME
34
+
35
+ > `readonly` `static` **CLASS\_NAME**: `string`
36
+
37
+ Runtime name for the class.
38
+
31
39
  ## Methods
32
40
 
33
41
  ### generateRandom()
@@ -184,7 +192,7 @@ GuardError If the value does not match the assertion.
184
192
 
185
193
  ### validate()
186
194
 
187
- > `static` **validate**(`property`, `value`, `failures`): `value is string`
195
+ > `static` **validate**(`property`, `value`, `failures`, `fieldNameResource?`): `value is string`
188
196
 
189
197
  Validate a string as a Urn.
190
198
 
@@ -208,6 +216,12 @@ The urn to parse.
208
216
 
209
217
  The list of failures to add to.
210
218
 
219
+ ##### fieldNameResource?
220
+
221
+ `string`
222
+
223
+ The optional human readable name for the field as an i18 resource.
224
+
211
225
  #### Returns
212
226
 
213
227
  `value is string`
@@ -2,13 +2,13 @@
2
2
 
3
3
  Interface describing a component which can be bootstrapped, started and stopped.
4
4
 
5
- ## Properties
5
+ ## Indexable
6
6
 
7
- ### CLASS\_NAME
7
+ \[`key`: `string`\]: `any`
8
8
 
9
- > `readonly` **CLASS\_NAME**: `string`
10
-
11
- The name of the component.
9
+ All methods are optional, so we introduce an index signature to allow
10
+ any additional properties or methods, which removes the TypeScript error where
11
+ the class has no properties in common with the type.
12
12
 
13
13
  ## Methods
14
14
 
@@ -20,14 +20,6 @@ The reason the validation failed as an i18 resource error.
20
20
 
21
21
  ***
22
22
 
23
- ### fieldName?
24
-
25
- > `optional` **fieldName**: `string`
26
-
27
- The optional human readable name for the field as an i18 resource.
28
-
29
- ***
30
-
31
23
  ### properties?
32
24
 
33
25
  > `optional` **properties**: `object`
@@ -0,0 +1 @@
1
+ ^errorNames.*$
package/locales/en.json CHANGED
@@ -38,9 +38,7 @@
38
38
  "beUrn": "{fieldName} must be a correctly formatted urn",
39
39
  "beUrl": "{fieldName} must be a correctly formatted url",
40
40
  "beJSON": "{fieldName} must be correctly formatted JSON",
41
- "beEmail": "{fieldName} must be a correctly formatted e-mail address",
42
- "failed": "Validation failed",
43
- "failedObject": "Validation of \"{objectName}\" failed"
41
+ "beEmail": "{fieldName} must be a correctly formatted e-mail address"
44
42
  },
45
43
  "guard": {
46
44
  "undefined": "Property \"{property}\" must be defined, it is \"{value}\"",
@@ -87,7 +85,7 @@
87
85
  "noGet": "The requested {typeName} \"{name}\" does not exist in the factory"
88
86
  },
89
87
  "bitString": {
90
- "outOfRange": "The index should be >= 0 and less than the length of the bit string"
88
+ "outOfRange": "The index should be >= 0 and less than the length of the bit string, the index is \"{index}\" and the number of bit is \"{numberBits}\""
91
89
  },
92
90
  "base32": {
93
91
  "invalidCharacter": "Data contains a character \"{invalidCharacter}\" which is not in the charset"
@@ -112,7 +110,8 @@
112
110
  "alreadyExistsError": "Already Exists",
113
111
  "notImplementedError": "Not Implemented",
114
112
  "validationError": "Validation",
115
- "unprocessableError": "Unprocessable"
113
+ "unprocessableError": "Unprocessable",
114
+ "unauthorizedError": "Unauthorized"
116
115
  },
117
116
  "validation": {
118
117
  "defaultFieldName": "The field"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/core",
3
- "version": "0.0.2-next.20",
3
+ "version": "0.0.2-next.22",
4
4
  "description": "Helper methods/classes for data type checking/validation/guarding/error handling",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,8 +14,8 @@
14
14
  "node": ">=20.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@twin.org/nameof": "0.0.2-next.20",
18
- "intl-messageformat": "10.7.16",
17
+ "@twin.org/nameof": "0.0.2-next.22",
18
+ "intl-messageformat": "10.7.17",
19
19
  "rfc6902": "5.1.2"
20
20
  },
21
21
  "main": "./dist/cjs/index.cjs",
@@ -45,5 +45,9 @@
45
45
  "core",
46
46
  "foundation",
47
47
  "utilities"
48
- ]
48
+ ],
49
+ "bugs": {
50
+ "url": "git+https://github.com/twinfoundation/framework/issues"
51
+ },
52
+ "homepage": "https://twindev.org"
49
53
  }