@twin.org/core 0.0.1-next.15 → 0.0.1-next.17

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.
@@ -1871,6 +1871,29 @@ class Factory {
1871
1871
  }
1872
1872
  return Factory._factories[typeName];
1873
1873
  }
1874
+ /**
1875
+ * Get all the factories.
1876
+ * @returns All the factories.
1877
+ */
1878
+ static getFactories() {
1879
+ return Factory._factories;
1880
+ }
1881
+ /**
1882
+ * Reset all the factories, which removes any created instances, but not the registrations.
1883
+ */
1884
+ static resetFactories() {
1885
+ for (const typeName in Factory._factories) {
1886
+ Factory._factories[typeName].reset();
1887
+ }
1888
+ }
1889
+ /**
1890
+ * Clear all the factories, which removes anything registered with the factories.
1891
+ */
1892
+ static clearFactories() {
1893
+ for (const typeName in Factory._factories) {
1894
+ Factory._factories[typeName].clear();
1895
+ }
1896
+ }
1874
1897
  /**
1875
1898
  * Register a new generator.
1876
1899
  * @param name The name of the generator.
@@ -3084,42 +3107,6 @@ class FilenameHelper {
3084
3107
  }
3085
3108
  }
3086
3109
 
3087
- /**
3088
- * Helper functions for modules.
3089
- */
3090
- class ModuleHelper {
3091
- /**
3092
- * Runtime name for the class.
3093
- */
3094
- static CLASS_NAME = "ModuleHelper";
3095
- /**
3096
- * Get the module entry.
3097
- * @param module The module.
3098
- * @param entry The entry to get from the module.
3099
- * @returns The entry from the module.
3100
- * @throws GeneralError if getting the module entry failed.
3101
- */
3102
- static async getModuleEntry(module, entry) {
3103
- try {
3104
- const moduleInstance = await import(module);
3105
- const moduleEntry = moduleInstance[entry];
3106
- if (Is.empty(moduleEntry)) {
3107
- throw new GeneralError(ModuleHelper.CLASS_NAME, "getModuleEntry", {
3108
- module,
3109
- entry
3110
- });
3111
- }
3112
- return moduleEntry;
3113
- }
3114
- catch (err) {
3115
- throw new GeneralError(ModuleHelper.CLASS_NAME, "getModuleEntry", {
3116
- module,
3117
- entry
3118
- }, BaseError.fromError(err));
3119
- }
3120
- }
3121
- }
3122
-
3123
3110
  // Copyright 2024 IOTA Stiftung.
3124
3111
  // SPDX-License-Identifier: Apache-2.0.
3125
3112
  /**
@@ -4518,7 +4505,6 @@ exports.HexHelper = HexHelper;
4518
4505
  exports.I18n = I18n;
4519
4506
  exports.Is = Is;
4520
4507
  exports.JsonHelper = JsonHelper;
4521
- exports.ModuleHelper = ModuleHelper;
4522
4508
  exports.NotFoundError = NotFoundError;
4523
4509
  exports.NotImplementedError = NotImplementedError;
4524
4510
  exports.NotSupportedError = NotSupportedError;
@@ -1869,6 +1869,29 @@ class Factory {
1869
1869
  }
1870
1870
  return Factory._factories[typeName];
1871
1871
  }
1872
+ /**
1873
+ * Get all the factories.
1874
+ * @returns All the factories.
1875
+ */
1876
+ static getFactories() {
1877
+ return Factory._factories;
1878
+ }
1879
+ /**
1880
+ * Reset all the factories, which removes any created instances, but not the registrations.
1881
+ */
1882
+ static resetFactories() {
1883
+ for (const typeName in Factory._factories) {
1884
+ Factory._factories[typeName].reset();
1885
+ }
1886
+ }
1887
+ /**
1888
+ * Clear all the factories, which removes anything registered with the factories.
1889
+ */
1890
+ static clearFactories() {
1891
+ for (const typeName in Factory._factories) {
1892
+ Factory._factories[typeName].clear();
1893
+ }
1894
+ }
1872
1895
  /**
1873
1896
  * Register a new generator.
1874
1897
  * @param name The name of the generator.
@@ -3082,42 +3105,6 @@ class FilenameHelper {
3082
3105
  }
3083
3106
  }
3084
3107
 
3085
- /**
3086
- * Helper functions for modules.
3087
- */
3088
- class ModuleHelper {
3089
- /**
3090
- * Runtime name for the class.
3091
- */
3092
- static CLASS_NAME = "ModuleHelper";
3093
- /**
3094
- * Get the module entry.
3095
- * @param module The module.
3096
- * @param entry The entry to get from the module.
3097
- * @returns The entry from the module.
3098
- * @throws GeneralError if getting the module entry failed.
3099
- */
3100
- static async getModuleEntry(module, entry) {
3101
- try {
3102
- const moduleInstance = await import(module);
3103
- const moduleEntry = moduleInstance[entry];
3104
- if (Is.empty(moduleEntry)) {
3105
- throw new GeneralError(ModuleHelper.CLASS_NAME, "getModuleEntry", {
3106
- module,
3107
- entry
3108
- });
3109
- }
3110
- return moduleEntry;
3111
- }
3112
- catch (err) {
3113
- throw new GeneralError(ModuleHelper.CLASS_NAME, "getModuleEntry", {
3114
- module,
3115
- entry
3116
- }, BaseError.fromError(err));
3117
- }
3118
- }
3119
- }
3120
-
3121
3108
  // Copyright 2024 IOTA Stiftung.
3122
3109
  // SPDX-License-Identifier: Apache-2.0.
3123
3110
  /**
@@ -4490,4 +4477,4 @@ class Validation {
4490
4477
  }
4491
4478
  }
4492
4479
 
4493
- export { AlreadyExistsError, ArrayHelper, AsyncCache, Base32, Base58, Base64, Base64Url, BaseError, BitString, Coerce, ComponentFactory, Compression, CompressionType, ConflictError, Converter, EnvHelper, ErrorHelper, Factory, FilenameHelper, GeneralError, GuardError, Guards, HexHelper, I18n, Is, JsonHelper, ModuleHelper, NotFoundError, NotImplementedError, NotSupportedError, ObjectHelper, RandomHelper, StringHelper, UnauthorizedError, UnprocessableError, Url, Urn, Validation, ValidationError };
4480
+ export { AlreadyExistsError, ArrayHelper, AsyncCache, Base32, Base58, Base64, Base64Url, BaseError, BitString, Coerce, ComponentFactory, Compression, CompressionType, ConflictError, Converter, EnvHelper, ErrorHelper, Factory, FilenameHelper, GeneralError, GuardError, Guards, HexHelper, I18n, Is, JsonHelper, NotFoundError, NotImplementedError, NotSupportedError, ObjectHelper, RandomHelper, StringHelper, UnauthorizedError, UnprocessableError, Url, Urn, Validation, ValidationError };
@@ -10,6 +10,21 @@ export declare class Factory<T> {
10
10
  * @returns The factory instance.
11
11
  */
12
12
  static createFactory<U>(typeName: string, autoInstance?: boolean, matcher?: (names: string[], name: string) => string | undefined): Factory<U>;
13
+ /**
14
+ * Get all the factories.
15
+ * @returns All the factories.
16
+ */
17
+ static getFactories(): {
18
+ [typeName: string]: Factory<unknown>;
19
+ };
20
+ /**
21
+ * Reset all the factories, which removes any created instances, but not the registrations.
22
+ */
23
+ static resetFactories(): void;
24
+ /**
25
+ * Clear all the factories, which removes anything registered with the factories.
26
+ */
27
+ static clearFactories(): void;
13
28
  /**
14
29
  * Register a new generator.
15
30
  * @param name The name of the generator.
@@ -21,7 +21,6 @@ export * from "./helpers/errorHelper";
21
21
  export * from "./helpers/filenameHelper";
22
22
  export * from "./helpers/hexHelper";
23
23
  export * from "./helpers/jsonHelper";
24
- export * from "./helpers/moduleHelper";
25
24
  export * from "./helpers/objectHelper";
26
25
  export * from "./helpers/randomHelper";
27
26
  export * from "./helpers/stringHelper";
package/docs/changelog.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # @twin.org/core - Changelog
2
2
 
3
- ## 0.0.1-next.15
3
+ ## 0.0.1-next.17
4
4
 
5
5
  - Initial Release
@@ -40,6 +40,44 @@ The factory instance.
40
40
 
41
41
  ***
42
42
 
43
+ ### getFactories()
44
+
45
+ > `static` **getFactories**(): `object`
46
+
47
+ Get all the factories.
48
+
49
+ #### Returns
50
+
51
+ `object`
52
+
53
+ All the factories.
54
+
55
+ ***
56
+
57
+ ### resetFactories()
58
+
59
+ > `static` **resetFactories**(): `void`
60
+
61
+ Reset all the factories, which removes any created instances, but not the registrations.
62
+
63
+ #### Returns
64
+
65
+ `void`
66
+
67
+ ***
68
+
69
+ ### clearFactories()
70
+
71
+ > `static` **clearFactories**(): `void`
72
+
73
+ Clear all the factories, which removes anything registered with the factories.
74
+
75
+ #### Returns
76
+
77
+ `void`
78
+
79
+ ***
80
+
43
81
  ### register()
44
82
 
45
83
  > **register**\<`U`\>(`name`, `generator`): `void`
@@ -24,7 +24,6 @@
24
24
  - [FilenameHelper](classes/FilenameHelper.md)
25
25
  - [HexHelper](classes/HexHelper.md)
26
26
  - [JsonHelper](classes/JsonHelper.md)
27
- - [ModuleHelper](classes/ModuleHelper.md)
28
27
  - [ObjectHelper](classes/ObjectHelper.md)
29
28
  - [RandomHelper](classes/RandomHelper.md)
30
29
  - [StringHelper](classes/StringHelper.md)
package/locales/en.json CHANGED
@@ -92,9 +92,6 @@
92
92
  },
93
93
  "base58": {
94
94
  "invalidCharacter": "Data contains a character \"{invalidCharacter}\" which is not in the charset"
95
- },
96
- "moduleHelper": {
97
- "getModuleEntry": "Failed to load entry \"{entry}\" from module \"{module}\""
98
95
  }
99
96
  },
100
97
  "errorNames": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/core",
3
- "version": "0.0.1-next.15",
3
+ "version": "0.0.1-next.17",
4
4
  "description": "Helper methods/classes for data type checking/validation/guarding/error handling",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,17 +0,0 @@
1
- /**
2
- * Helper functions for modules.
3
- */
4
- export declare class ModuleHelper {
5
- /**
6
- * Runtime name for the class.
7
- */
8
- static readonly CLASS_NAME: string;
9
- /**
10
- * Get the module entry.
11
- * @param module The module.
12
- * @param entry The entry to get from the module.
13
- * @returns The entry from the module.
14
- * @throws GeneralError if getting the module entry failed.
15
- */
16
- static getModuleEntry<T>(module: string, entry: string): Promise<T>;
17
- }
@@ -1,53 +0,0 @@
1
- # Class: ModuleHelper
2
-
3
- Helper functions for modules.
4
-
5
- ## Constructors
6
-
7
- ### new ModuleHelper()
8
-
9
- > **new ModuleHelper**(): [`ModuleHelper`](ModuleHelper.md)
10
-
11
- #### Returns
12
-
13
- [`ModuleHelper`](ModuleHelper.md)
14
-
15
- ## Properties
16
-
17
- ### CLASS\_NAME
18
-
19
- > `readonly` `static` **CLASS\_NAME**: `string`
20
-
21
- Runtime name for the class.
22
-
23
- ## Methods
24
-
25
- ### getModuleEntry()
26
-
27
- > `static` **getModuleEntry**\<`T`\>(`module`, `entry`): `Promise`\<`T`\>
28
-
29
- Get the module entry.
30
-
31
- #### Type Parameters
32
-
33
- • **T**
34
-
35
- #### Parameters
36
-
37
- • **module**: `string`
38
-
39
- The module.
40
-
41
- • **entry**: `string`
42
-
43
- The entry to get from the module.
44
-
45
- #### Returns
46
-
47
- `Promise`\<`T`\>
48
-
49
- The entry from the module.
50
-
51
- #### Throws
52
-
53
- GeneralError if getting the module entry failed.