@equinor/fusion-framework-module
Advanced tools
Comparing version 4.3.0 to 4.3.1
309
CHANGELOG.md
# Change Log | ||
## 4.3.1 | ||
### Patch Changes | ||
- [#2177](https://github.com/equinor/fusion-framework/pull/2177) [`fb424be`](https://github.com/equinor/fusion-framework/commit/fb424be24ad9349d01daef91a01c464d7b1413d2) Thanks [@odinr](https://github.com/odinr)! - ## @equinor/fusion-framework-module | ||
### Changes to `BaseConfigBuilder` | ||
The `_createConfig` method in `BaseConfigBuilder` has been updated to return an `ObservableInput<TConfig>` instead of an `Observable<TConfig>`. | ||
This allows for more flexibility in how the config is created, as the method can now return a Promise or other observable-like type. | ||
Additionally, the `_createConfig` method now uses `from()` to convert the result of `_buildConfig` to an observable stream. | ||
Here's an example of how the updated `_createConfig` method can be used: | ||
```typescript | ||
protected _createConfig( | ||
init: ConfigBuilderCallbackArgs, | ||
initial?: Partial<TConfig> | ||
): ObservableInput<TConfig> { | ||
return from(this._buildConfig(init, initial)).pipe( | ||
mergeMap((config) => this._processConfig(config, init)) | ||
); | ||
} | ||
``` | ||
This change allows for asynchronous operations to be performed within the `_buildConfig` method, which can then be processed in the `_processConfig` method. | ||
Consumers of the `BaseConfigBuilder` class should not need to update their code, as the public API remains the same. | ||
- [#2177](https://github.com/equinor/fusion-framework/pull/2177) [`fb424be`](https://github.com/equinor/fusion-framework/commit/fb424be24ad9349d01daef91a01c464d7b1413d2) Thanks [@odinr](https://github.com/odinr)! - ## @equinor/fusion-framework-module | ||
### Improved documentation for `BaseConfigBuilder` | ||
The `BaseConfigBuilder` class has been updated with improved documentation to better explain its usage and capabilities. | ||
#### What changed? | ||
The `BaseConfigBuilder` class is an abstract class that provides a flexible and extensible way to build and configure modules. It allows you to define configuration callbacks for different parts of your module's configuration, and then combine and process these callbacks to generate the final configuration object. | ||
The documentation has been expanded to include: | ||
1. A detailed explanation of how the `BaseConfigBuilder` class is designed to be used, including an example of creating a configuration builder for a hypothetical `MyModule` module. | ||
2. Descriptions of the key methods and properties provided by the `BaseConfigBuilder` class, such as `createConfig`, `createConfigAsync`, `_set`, `_buildConfig`, and `_processConfig`. | ||
3. Guidance on how to override the `_processConfig` method to add additional logic or validation to the configuration object before it is returned. | ||
4. Examples of how to use the `BaseConfigBuilder` class to handle common configuration scenarios, such as setting default values or validating configuration properties. | ||
- [#2177](https://github.com/equinor/fusion-framework/pull/2177) [`fb424be`](https://github.com/equinor/fusion-framework/commit/fb424be24ad9349d01daef91a01c464d7b1413d2) Thanks [@odinr](https://github.com/odinr)! - ## @equinor/fusion-framework-module | ||
### Changes to `BaseConfigBuilder` | ||
The `BaseConfigBuilder` class has been updated to improve its extendability and provide better access to the internal configuration callbacks. | ||
#### Added `_get` and `_has` methods | ||
Two new protected methods have been added to the `BaseConfigBuilder` class: | ||
1. `_get<TTarget extends DotPath<TConfig>>(target: TTarget)`: This method retrieves the configuration callback for the specified target path in the configuration. It returns the callback or `undefined` if no callback is registered for the given target. | ||
2. `_has<TTarget extends DotPath<TConfig>>(target: TTarget)`: This method checks if the given target path exists in the configuration callbacks. It returns `true` if the target path exists, `false` otherwise. | ||
These methods allow subclasses of `BaseConfigBuilder` to easily access and check the existence of configuration callbacks for specific targets. | ||
#### Example usage | ||
Suppose you have a subclass of `BaseConfigBuilder` called `MyConfigBuilder`. You can use the new `_get` and `_has` methods like this: | ||
```typescript | ||
class MyConfigBuilder extends BaseConfigBuilder<MyConfig> { | ||
// override the _buildConfig method | ||
async _createConfig( | ||
init: ConfigBuilderCallbackArgs, | ||
initial?: Partial<TConfig>, | ||
): ObservableInput<TConfig> { | ||
// Check if a callback is registered for the'my.custom.config' target | ||
if (this._has('my.custom.config')) { | ||
// register a fallback value for the'my.custom.config' target if no callback is registered | ||
this._set('my.custom.config', async () => { | ||
return 42; | ||
}); | ||
} else { | ||
// if a callback is registered, call it and log the result | ||
configCallback = this._get('my.custom.config'); | ||
configValue$ = from(configCallback(init, initial)); | ||
console.log(await lastValueFrom(configValue$)); | ||
} | ||
return lastValueFrom(from(super._createConfig(init, initial))); | ||
} | ||
} | ||
``` | ||
> [!WARNING] | ||
> the example code is not intended to be a working implementation of the `MyConfigBuilder` class. It is only intended to demonstrate how the new `_get` and `_has` methods can be used. | ||
This change allows for more flexibility and easier extensibility of the `BaseConfigBuilder` class. | ||
## 4.3.0 | ||
@@ -7,7 +102,7 @@ | ||
- [#1953](https://github.com/equinor/fusion-framework/pull/1953) [`f3ae28d`](https://github.com/equinor/fusion-framework/commit/f3ae28dc6d1d5043605e07e2cd2e83ae799cd904) Thanks [@odinr](https://github.com/odinr)! - updated typescript to 5.4.2 | ||
- [#1953](https://github.com/equinor/fusion-framework/pull/1953) [`f3ae28d`](https://github.com/equinor/fusion-framework/commit/f3ae28dc6d1d5043605e07e2cd2e83ae799cd904) Thanks [@odinr](https://github.com/odinr)! - updated typescript to 5.4.2 | ||
### Patch Changes | ||
- [#1953](https://github.com/equinor/fusion-framework/pull/1953) [`f3ae28d`](https://github.com/equinor/fusion-framework/commit/f3ae28dc6d1d5043605e07e2cd2e83ae799cd904) Thanks [@odinr](https://github.com/odinr)! - Reworked `DotPath` since previous method used recursive typing | ||
- [#1953](https://github.com/equinor/fusion-framework/pull/1953) [`f3ae28d`](https://github.com/equinor/fusion-framework/commit/f3ae28dc6d1d5043605e07e2cd2e83ae799cd904) Thanks [@odinr](https://github.com/odinr)! - Reworked `DotPath` since previous method used recursive typing | ||
@@ -18,3 +113,3 @@ ## 4.2.7 | ||
- [#1792](https://github.com/equinor/fusion-framework/pull/1792) [`152cf73`](https://github.com/equinor/fusion-framework/commit/152cf73d39eb32ccbaddaa6941e315c437c4972d) Thanks [@odinr](https://github.com/odinr)! - improve resolve of dot path for BaseConfigBuilder | ||
- [#1792](https://github.com/equinor/fusion-framework/pull/1792) [`152cf73`](https://github.com/equinor/fusion-framework/commit/152cf73d39eb32ccbaddaa6941e315c437c4972d) Thanks [@odinr](https://github.com/odinr)! - improve resolve of dot path for BaseConfigBuilder | ||
@@ -25,3 +120,3 @@ ## 4.2.6 | ||
- [#1595](https://github.com/equinor/fusion-framework/pull/1595) [`9c24e84`](https://github.com/equinor/fusion-framework/commit/9c24e847d041dea8384c77439e6b237f5bdb3125) Thanks [@Gustav-Eikaas](https://github.com/Gustav-Eikaas)! - support for module resolution NodeNext & Bundler | ||
- [#1595](https://github.com/equinor/fusion-framework/pull/1595) [`9c24e84`](https://github.com/equinor/fusion-framework/commit/9c24e847d041dea8384c77439e6b237f5bdb3125) Thanks [@Gustav-Eikaas](https://github.com/Gustav-Eikaas)! - support for module resolution NodeNext & Bundler | ||
@@ -32,3 +127,3 @@ ## 4.2.5 | ||
- [`b5dfe5d2`](https://github.com/equinor/fusion-framework/commit/b5dfe5d29a249e0cca6c9589322931dfedd06acc) Thanks [@odinr](https://github.com/odinr)! - force patch bump, realign missing snapshot | ||
- [`b5dfe5d2`](https://github.com/equinor/fusion-framework/commit/b5dfe5d29a249e0cca6c9589322931dfedd06acc) Thanks [@odinr](https://github.com/odinr)! - force patch bump, realign missing snapshot | ||
@@ -39,3 +134,3 @@ ## 4.2.4 | ||
- [`9076a498`](https://github.com/equinor/fusion-framework/commit/9076a49876e7a414a27557b7fb9095a67fe3a57f) Thanks [@odinr](https://github.com/odinr)! - replace `scan` + `last` whith `reduce` in `BaseConfigBuilder._buildConfig` | ||
- [`9076a498`](https://github.com/equinor/fusion-framework/commit/9076a49876e7a414a27557b7fb9095a67fe3a57f) Thanks [@odinr](https://github.com/odinr)! - replace `scan` + `last` whith `reduce` in `BaseConfigBuilder._buildConfig` | ||
@@ -46,9 +141,9 @@ ## 4.2.3 | ||
- [#1109](https://github.com/equinor/fusion-framework/pull/1109) [`7ec195d4`](https://github.com/equinor/fusion-framework/commit/7ec195d42098fec8794db13e83b71ef7753ff862) Thanks [@odinr](https://github.com/odinr)! - Change packaged manager from yarn to pnpm | ||
- [#1109](https://github.com/equinor/fusion-framework/pull/1109) [`7ec195d4`](https://github.com/equinor/fusion-framework/commit/7ec195d42098fec8794db13e83b71ef7753ff862) Thanks [@odinr](https://github.com/odinr)! - Change packaged manager from yarn to pnpm | ||
conflicts of `@types/react` made random outcomes when using `yarn` | ||
conflicts of `@types/react` made random outcomes when using `yarn` | ||
this change should not affect consumer of the packages, but might conflict dependent on local package manager. | ||
this change should not affect consumer of the packages, but might conflict dependent on local package manager. | ||
- [#1145](https://github.com/equinor/fusion-framework/pull/1145) [`d276fc5d`](https://github.com/equinor/fusion-framework/commit/d276fc5d514566d05c64705076a1cb91c6a44272) Thanks [@dependabot](https://github.com/apps/dependabot)! - build(deps): bump rxjs from 7.5.7 to [7.8.1](https://github.com/ReactiveX/rxjs/blob/7.8.1/CHANGELOG.md) | ||
- [#1145](https://github.com/equinor/fusion-framework/pull/1145) [`d276fc5d`](https://github.com/equinor/fusion-framework/commit/d276fc5d514566d05c64705076a1cb91c6a44272) Thanks [@dependabot](https://github.com/apps/dependabot)! - build(deps): bump rxjs from 7.5.7 to [7.8.1](https://github.com/ReactiveX/rxjs/blob/7.8.1/CHANGELOG.md) | ||
@@ -59,5 +154,5 @@ ## 4.2.2 | ||
- [#1047](https://github.com/equinor/fusion-framework/pull/1047) [`1a2880d2`](https://github.com/equinor/fusion-framework/commit/1a2880d2e4c80ac5ce08f63ca3699fe77e4b565c) Thanks [@dependabot](https://github.com/apps/dependabot)! - build(deps): bump @typescript-eslint/eslint-plugin from 5.59.11 to 6.1.0 | ||
- [#1047](https://github.com/equinor/fusion-framework/pull/1047) [`1a2880d2`](https://github.com/equinor/fusion-framework/commit/1a2880d2e4c80ac5ce08f63ca3699fe77e4b565c) Thanks [@dependabot](https://github.com/apps/dependabot)! - build(deps): bump @typescript-eslint/eslint-plugin from 5.59.11 to 6.1.0 | ||
only style semantics updated | ||
only style semantics updated | ||
@@ -68,3 +163,3 @@ ## 4.2.1 | ||
- [#946](https://github.com/equinor/fusion-framework/pull/946) [`5a160d88`](https://github.com/equinor/fusion-framework/commit/5a160d88981ddfe861d391cfefe10f54dda3d352) Thanks [@odinr](https://github.com/odinr)! - Build/update typescript to 5 | ||
- [#946](https://github.com/equinor/fusion-framework/pull/946) [`5a160d88`](https://github.com/equinor/fusion-framework/commit/5a160d88981ddfe861d391cfefe10f54dda3d352) Thanks [@odinr](https://github.com/odinr)! - Build/update typescript to 5 | ||
@@ -75,82 +170,82 @@ ## 4.2.0 | ||
- [#902](https://github.com/equinor/fusion-framework/pull/902) [`3efbf0bb`](https://github.com/equinor/fusion-framework/commit/3efbf0bb93fc11aa158872cd6ab98a22bcfb59e5) Thanks [@odinr](https://github.com/odinr)! - **Feat(module)** add base module class | ||
- [#902](https://github.com/equinor/fusion-framework/pull/902) [`3efbf0bb`](https://github.com/equinor/fusion-framework/commit/3efbf0bb93fc11aa158872cd6ab98a22bcfb59e5) Thanks [@odinr](https://github.com/odinr)! - **Feat(module)** add base module class | ||
As a module developer there should be a base provider class to extend, which handles basic wireing. | ||
As a module developer there should be a base provider class to extend, which handles basic wireing. | ||
Some aspects of providers should be the same for all, like `version` handling. | ||
Some aspects of providers should be the same for all, like `version` handling. | ||
These new features does not change any existing code, only tooling for future development | ||
These new features does not change any existing code, only tooling for future development | ||
- [#882](https://github.com/equinor/fusion-framework/pull/882) [`76b30c1e`](https://github.com/equinor/fusion-framework/commit/76b30c1e86db3db18adbe759bb1e39885de1c898) Thanks [@odinr](https://github.com/odinr)! - Add possibility to add multilevel config for module | ||
- [#882](https://github.com/equinor/fusion-framework/pull/882) [`76b30c1e`](https://github.com/equinor/fusion-framework/commit/76b30c1e86db3db18adbe759bb1e39885de1c898) Thanks [@odinr](https://github.com/odinr)! - Add possibility to add multilevel config for module | ||
```ts | ||
type MyModuleConfig = { | ||
foo: string; | ||
bar?: number; | ||
nested?: { up: boolean }; | ||
}; | ||
```ts | ||
type MyModuleConfig = { | ||
foo: string; | ||
bar?: number; | ||
nested?: { up: boolean }; | ||
}; | ||
class MyModuleConfigurator extends BaseConfigBuilder<MyModuleConfig> { | ||
public setFoo(cb: ModuleConfigCallback<string>) { | ||
this._set("foo", cb); | ||
} | ||
class MyModuleConfigurator extends BaseConfigBuilder<MyModuleConfig> { | ||
public setFoo(cb: ModuleConfigCallback<string>) { | ||
this._set('foo', cb); | ||
} | ||
public setBar(cb: ModuleConfigCallback<number>) { | ||
this._set("bar", cb); | ||
} | ||
public setBar(cb: ModuleConfigCallback<number>) { | ||
this._set('bar', cb); | ||
} | ||
public setUp(cb: ModuleConfigCallback<boolean>) { | ||
this._set("nested.up", cb); | ||
public setUp(cb: ModuleConfigCallback<boolean>) { | ||
this._set('nested.up', cb); | ||
} | ||
} | ||
} | ||
``` | ||
``` | ||
- [#902](https://github.com/equinor/fusion-framework/pull/902) [`3efbf0bb`](https://github.com/equinor/fusion-framework/commit/3efbf0bb93fc11aa158872cd6ab98a22bcfb59e5) Thanks [@odinr](https://github.com/odinr)! - **Feat(module): add semver** | ||
- [#902](https://github.com/equinor/fusion-framework/pull/902) [`3efbf0bb`](https://github.com/equinor/fusion-framework/commit/3efbf0bb93fc11aa158872cd6ab98a22bcfb59e5) Thanks [@odinr](https://github.com/odinr)! - **Feat(module): add semver** | ||
In some cases other modules might require features in sibling modules | ||
In some cases other modules might require features in sibling modules | ||
```ts | ||
if (modules.context.version.satisfies(">=7.2")) { | ||
// do some code | ||
} else { | ||
throw Error( | ||
"this feature requires ContextModule of 7.2 or higher, please update depencies", | ||
); | ||
} | ||
``` | ||
```ts | ||
if (modules.context.version.satisfies('>=7.2')) { | ||
// do some code | ||
} else { | ||
throw Error( | ||
'this feature requires ContextModule of 7.2 or higher, please update depencies', | ||
); | ||
} | ||
``` | ||
Usage: | ||
Usage: | ||
- log telemetry about module usage and outdated application | ||
- debug code runtime by knowing version of implementation | ||
- write inter-opt when breaking changes accour | ||
- log telemetry about module usage and outdated application | ||
- debug code runtime by knowing version of implementation | ||
- write inter-opt when breaking changes accour | ||
### Patch Changes | ||
- [#907](https://github.com/equinor/fusion-framework/pull/907) [`7500ec2c`](https://github.com/equinor/fusion-framework/commit/7500ec2c9ca9b926a19539fc97c61c67f76fc8d9) Thanks [@odinr](https://github.com/odinr)! - export `lib` assets: | ||
- [#907](https://github.com/equinor/fusion-framework/pull/907) [`7500ec2c`](https://github.com/equinor/fusion-framework/commit/7500ec2c9ca9b926a19539fc97c61c67f76fc8d9) Thanks [@odinr](https://github.com/odinr)! - export `lib` assets: | ||
- SemanticVersion | ||
- ModuleProvider | ||
- SemanticVersion | ||
- ModuleProvider | ||
- [#913](https://github.com/equinor/fusion-framework/pull/913) [`83ee5abf`](https://github.com/equinor/fusion-framework/commit/83ee5abf7bcab193c85980e5ae44895cd7f6f08d) Thanks [@odinr](https://github.com/odinr)! - **Change base behavior of BaseModuleProvider** | ||
- [#913](https://github.com/equinor/fusion-framework/pull/913) [`83ee5abf`](https://github.com/equinor/fusion-framework/commit/83ee5abf7bcab193c85980e5ae44895cd7f6f08d) Thanks [@odinr](https://github.com/odinr)! - **Change base behavior of BaseModuleProvider** | ||
because of weird limitations of JavaScript, private fields are not accessible until all constructors are initialized (from ancestor to current child). | ||
This causes the `abstract` init function could not access private members when overridden. | ||
because of weird limitations of JavaScript, private fields are not accessible until all constructors are initialized (from ancestor to current child). | ||
This causes the `abstract` init function could not access private members when overridden. | ||
- **removed** `init` from `BaseModuleProvider` | ||
- _this is a breaking change, but not yet published, yet the `patch` version_ | ||
- https://github.com/equinor/fusion-framework/blob/43854d9538ade189483c43e04b52eff7e1aa3b0c/packages/modules/module/src/lib/provider/BaseModuleProvider.ts#L31 | ||
- **added** `provider` sub-scope for package | ||
- **removed** `init` from `BaseModuleProvider` | ||
- _this is a breaking change, but not yet published, yet the `patch` version_ | ||
- https://github.com/equinor/fusion-framework/blob/43854d9538ade189483c43e04b52eff7e1aa3b0c/packages/modules/module/src/lib/provider/BaseModuleProvider.ts#L31 | ||
- **added** `provider` sub-scope for package | ||
> The usage when extending `BaseModuleProvider` is not as 😘, but now works | ||
> The usage when extending `BaseModuleProvider` is not as 😘, but now works | ||
- [#907](https://github.com/equinor/fusion-framework/pull/907) [`7500ec2c`](https://github.com/equinor/fusion-framework/commit/7500ec2c9ca9b926a19539fc97c61c67f76fc8d9) Thanks [@odinr](https://github.com/odinr)! - allow `SemanticVersion` as `version` in ctor args for `BaseModuleProvider` | ||
- [#907](https://github.com/equinor/fusion-framework/pull/907) [`7500ec2c`](https://github.com/equinor/fusion-framework/commit/7500ec2c9ca9b926a19539fc97c61c67f76fc8d9) Thanks [@odinr](https://github.com/odinr)! - allow `SemanticVersion` as `version` in ctor args for `BaseModuleProvider` | ||
- [#924](https://github.com/equinor/fusion-framework/pull/924) [`060818eb`](https://github.com/equinor/fusion-framework/commit/060818eb04ebb9ed6deaed1f0b4530201b1181cf) Thanks [@asbjornhaland](https://github.com/asbjornhaland)! - fix(module): add config builder callback args to process config method so that | ||
- [#924](https://github.com/equinor/fusion-framework/pull/924) [`060818eb`](https://github.com/equinor/fusion-framework/commit/060818eb04ebb9ed6deaed1f0b4530201b1181cf) Thanks [@asbjornhaland](https://github.com/asbjornhaland)! - fix(module): add config builder callback args to process config method so that | ||
- [#905](https://github.com/equinor/fusion-framework/pull/905) [`a7858a1c`](https://github.com/equinor/fusion-framework/commit/a7858a1c01542e2dc94370709f122b4b99c3219c) Thanks [@odinr](https://github.com/odinr)! - **🚧 Chore: dedupe packages** | ||
- [#905](https://github.com/equinor/fusion-framework/pull/905) [`a7858a1c`](https://github.com/equinor/fusion-framework/commit/a7858a1c01542e2dc94370709f122b4b99c3219c) Thanks [@odinr](https://github.com/odinr)! - **🚧 Chore: dedupe packages** | ||
- align all versions of typescript | ||
- update types to build | ||
- a couple of typecasts did not [satisfies](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-0.html#satisfies-support-in-jsdoc) and was recasted as `unknwon`, marked with `TODO`, should be fixed in future | ||
- align all versions of typescript | ||
- update types to build | ||
- a couple of typecasts did not [satisfies](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-0.html#satisfies-support-in-jsdoc) and was recasted as `unknwon`, marked with `TODO`, should be fixed in future | ||
@@ -164,3 +259,3 @@ All notable changes to this project will be documented in this file. | ||
- **module:** create base configurator ([f94b51e](https://github.com/equinor/fusion-framework/commit/f94b51e53d6ae235456e2ea2b5a82db5aa1a18f0)) | ||
- **module:** create base configurator ([f94b51e](https://github.com/equinor/fusion-framework/commit/f94b51e53d6ae235456e2ea2b5a82db5aa1a18f0)) | ||
@@ -171,7 +266,7 @@ ## 4.0.0 (2023-05-05) | ||
- **modules:** postInitialize no longer support void function, should not affect any application, only used internally | ||
- **modules:** postInitialize no longer support void function, should not affect any application, only used internally | ||
### Features | ||
- **modules:** change postInitialize to return ObservableInput ([f1c2f56](https://github.com/equinor/fusion-framework/commit/f1c2f5644c6db2405bf5747a1094548e1723cce1)) | ||
- **modules:** change postInitialize to return ObservableInput ([f1c2f56](https://github.com/equinor/fusion-framework/commit/f1c2f5644c6db2405bf5747a1094548e1723cce1)) | ||
@@ -198,3 +293,3 @@ ## 3.0.0 (2023-04-16) | ||
- **module:** add base module config builder ([5a897b7](https://github.com/equinor/fusion-framework/commit/5a897b762a3a9139a1de025d1b1f4ae162079028)) | ||
- **module:** add base module config builder ([5a897b7](https://github.com/equinor/fusion-framework/commit/5a897b762a3a9139a1de025d1b1f4ae162079028)) | ||
@@ -209,3 +304,3 @@ ## 1.2.10 (2022-12-01) | ||
- **module-msal:** await redirect handling ([92686d2](https://github.com/equinor/fusion-framework/commit/92686d2ae054d7f507093b839edb2fe5775c7449)) | ||
- **module-msal:** await redirect handling ([92686d2](https://github.com/equinor/fusion-framework/commit/92686d2ae054d7f507093b839edb2fe5775c7449)) | ||
@@ -216,3 +311,3 @@ ## 1.2.8 (2022-11-03) | ||
- **module:** allow debug logging ([315f845](https://github.com/equinor/fusion-framework/commit/315f845e78469a05f27793a56dd281832e7b5dd7)) | ||
- **module:** allow debug logging ([315f845](https://github.com/equinor/fusion-framework/commit/315f845e78469a05f27793a56dd281832e7b5dd7)) | ||
@@ -231,3 +326,3 @@ ## 1.2.7 (2022-11-02) | ||
- **module:** update typing ([9428770](https://github.com/equinor/fusion-framework/commit/9428770eca39d5e5afe00b94d0d09a688fc821b0)) | ||
- **module:** update typing ([9428770](https://github.com/equinor/fusion-framework/commit/9428770eca39d5e5afe00b94d0d09a688fc821b0)) | ||
@@ -238,3 +333,3 @@ ## [1.2.4](https://github.com/equinor/fusion-framework/compare/@equinor/fusion-framework-module@1.2.3...@equinor/fusion-framework-module@1.2.4) (2022-10-17) | ||
- expose init interface for modules ([208cf79](https://github.com/equinor/fusion-framework/commit/208cf792b83d093a0c9ba1cdf919b4196e442989)) | ||
- expose init interface for modules ([208cf79](https://github.com/equinor/fusion-framework/commit/208cf792b83d093a0c9ba1cdf919b4196e442989)) | ||
@@ -249,3 +344,3 @@ ## 1.2.3 (2022-10-03) | ||
- **module:** update interface for logging ([fc23ea3](https://github.com/equinor/fusion-framework/commit/fc23ea3602c0b18b3f54de584773f76ffe63617c)) | ||
- **module:** update interface for logging ([fc23ea3](https://github.com/equinor/fusion-framework/commit/fc23ea3602c0b18b3f54de584773f76ffe63617c)) | ||
@@ -256,3 +351,3 @@ ## 1.2.1 (2022-09-27) | ||
- update registering of configuration ([20942ce](https://github.com/equinor/fusion-framework/commit/20942ce1c7a853ea3b55c031a242646e378db8c9)) | ||
- update registering of configuration ([20942ce](https://github.com/equinor/fusion-framework/commit/20942ce1c7a853ea3b55c031a242646e378db8c9)) | ||
@@ -263,3 +358,3 @@ ## 1.2.0 (2022-09-20) | ||
- **module:** add has module check ([e32cf7b](https://github.com/equinor/fusion-framework/commit/e32cf7b751854ae8e306bb1d6a84260099752714)) | ||
- **module:** add has module check ([e32cf7b](https://github.com/equinor/fusion-framework/commit/e32cf7b751854ae8e306bb1d6a84260099752714)) | ||
@@ -278,3 +373,3 @@ ## [1.1.3](https://github.com/equinor/fusion-framework/compare/@equinor/fusion-framework-module@1.1.2...@equinor/fusion-framework-module@1.1.3) (2022-09-14) | ||
- update typings and linting ([7d2056b](https://github.com/equinor/fusion-framework/commit/7d2056b7866850b7efdfd4567385b5dbbcdf8761)) | ||
- update typings and linting ([7d2056b](https://github.com/equinor/fusion-framework/commit/7d2056b7866850b7efdfd4567385b5dbbcdf8761)) | ||
@@ -285,3 +380,3 @@ ## [1.1.0](https://github.com/equinor/fusion-framework/compare/@equinor/fusion-framework-module@1.0.1...@equinor/fusion-framework-module@1.1.0) (2022-09-13) | ||
- **module:** allow setting log levels ([017b5b3](https://github.com/equinor/fusion-framework/commit/017b5b34645aa001297f37e7aef5557e9027beee)) | ||
- **module:** allow setting log levels ([017b5b3](https://github.com/equinor/fusion-framework/commit/017b5b34645aa001297f37e7aef5557e9027beee)) | ||
@@ -304,12 +399,12 @@ ## [1.0.1](https://github.com/equinor/fusion-framework/compare/@equinor/fusion-framework-module@1.0.1-next.1...@equinor/fusion-framework-module@1.0.1) (2022-09-12) | ||
- **module:** initialize modules now takes configurator object as argument. | ||
- **module:** initialize modules now takes configurator object as argument. | ||
### Features | ||
- **module:** rewrite config to object ([74566f3](https://github.com/equinor/fusion-framework/commit/74566f36eb73c63e1e25df05d89f6f6490dc8272)) | ||
- **module:** rewrite config to object ([74566f3](https://github.com/equinor/fusion-framework/commit/74566f36eb73c63e1e25df05d89f6f6490dc8272)) | ||
### Bug Fixes | ||
- **module:** await all creation of configs ([25649a4](https://github.com/equinor/fusion-framework/commit/25649a4a6bc4249f2fe996c0bdf735a7ebd42186)) | ||
- **module:** expose logger ([c88574a](https://github.com/equinor/fusion-framework/commit/c88574a61d368841dd648c511d80cad2e5efd7c6)) | ||
- **module:** await all creation of configs ([25649a4](https://github.com/equinor/fusion-framework/commit/25649a4a6bc4249f2fe996c0bdf735a7ebd42186)) | ||
- **module:** expose logger ([c88574a](https://github.com/equinor/fusion-framework/commit/c88574a61d368841dd648c511d80cad2e5efd7c6)) | ||
@@ -320,12 +415,12 @@ ## [1.0.0-alpha.0](https://github.com/equinor/fusion-framework/compare/@equinor/fusion-framework-module@0.4.4...@equinor/fusion-framework-module@1.0.0-alpha.0) (2022-09-12) | ||
- **module:** initialize modules now takes configurator object as argument. | ||
- **module:** initialize modules now takes configurator object as argument. | ||
### Features | ||
- **module:** rewrite config to object ([74566f3](https://github.com/equinor/fusion-framework/commit/74566f36eb73c63e1e25df05d89f6f6490dc8272)) | ||
- **module:** rewrite config to object ([74566f3](https://github.com/equinor/fusion-framework/commit/74566f36eb73c63e1e25df05d89f6f6490dc8272)) | ||
### Bug Fixes | ||
- **module:** await all creation of configs ([25649a4](https://github.com/equinor/fusion-framework/commit/25649a4a6bc4249f2fe996c0bdf735a7ebd42186)) | ||
- **module:** expose logger ([c88574a](https://github.com/equinor/fusion-framework/commit/c88574a61d368841dd648c511d80cad2e5efd7c6)) | ||
- **module:** await all creation of configs ([25649a4](https://github.com/equinor/fusion-framework/commit/25649a4a6bc4249f2fe996c0bdf735a7ebd42186)) | ||
- **module:** expose logger ([c88574a](https://github.com/equinor/fusion-framework/commit/c88574a61d368841dd648c511d80cad2e5efd7c6)) | ||
@@ -344,3 +439,3 @@ ## 0.4.4 (2022-09-05) | ||
- improve logging of initializing modules ([f313bca](https://github.com/equinor/fusion-framework/commit/f313bca19103356f9d1a2bc09b57d4ff975e46a0)) | ||
- improve logging of initializing modules ([f313bca](https://github.com/equinor/fusion-framework/commit/f313bca19103356f9d1a2bc09b57d4ff975e46a0)) | ||
@@ -351,34 +446,34 @@ ## [0.4.1](https://github.com/equinor/fusion-framework/compare/@equinor/fusion-framework-module@0.4.0...@equinor/fusion-framework-module@0.4.1) (2022-08-15) | ||
- enhance post initialize ([4d10184](https://github.com/equinor/fusion-framework/commit/4d10184bf89d8968360be726ec3885444999ef8f)) | ||
- enhance post initialize ([4d10184](https://github.com/equinor/fusion-framework/commit/4d10184bf89d8968360be726ec3885444999ef8f)) | ||
# 0.4.0 (2022-08-11) | ||
- feat!: allow modules to displose ([32b69fb](https://github.com/equinor/fusion-framework/commit/32b69fb7cc61e78e503e67d0e77f21fb44b600b9)) | ||
- feat!: allow modules to displose ([32b69fb](https://github.com/equinor/fusion-framework/commit/32b69fb7cc61e78e503e67d0e77f21fb44b600b9)) | ||
### BREAKING CHANGES | ||
- module.initialize now has object as arg | ||
- module.initialize now has object as arg | ||
# [0.3.0](https://github.com/equinor/fusion-framework/compare/@equinor/fusion-framework-module@0.2.8...@equinor/fusion-framework-module@0.3.0) (2022-08-04) | ||
- feat(module)!: allow requireing module instnce (#190) ([3a7e67e](https://github.com/equinor/fusion-framework/commit/3a7e67e9accb5185100325c92d5850a44626e498)), closes [#190](https://github.com/equinor/fusion-framework/issues/190) | ||
- feat(module)!: allow requireing module instnce (#190) ([3a7e67e](https://github.com/equinor/fusion-framework/commit/3a7e67e9accb5185100325c92d5850a44626e498)), closes [#190](https://github.com/equinor/fusion-framework/issues/190) | ||
### BREAKING CHANGES | ||
- `deps` prop is remove from module object, use `await require('MODULE')`; | ||
- `deps` prop is remove from module object, use `await require('MODULE')`; | ||
- feat(module)!: allow requireing module instnce | ||
- feat(module)!: allow requireing module instnce | ||
when module initiates it should be allowed to await an required module. | ||
- add method for awaiting required module | ||
- add typing for config in initialize fase | ||
- add method for awaiting required module | ||
- add typing for config in initialize fase | ||
- update service discovery to await http module | ||
- add service discovery client | ||
- allow configuration of service discovery client | ||
- update service discovery to await http module | ||
- add service discovery client | ||
- allow configuration of service discovery client | ||
* `deps` prop is remove from module object, use `await require('MODULE')`; | ||
* `deps` prop is remove from module object, use `await require('MODULE')`; | ||
* fix(module-http): add default interface for HttpClientOptions | ||
* fix(module-http): add default interface for HttpClientOptions | ||
@@ -421,3 +516,3 @@ ## 0.2.8 (2022-08-01) | ||
- **module:** allow modules to have deps ([#128](https://github.com/equinor/fusion-framework/issues/128)) ([2466b1a](https://github.com/equinor/fusion-framework/commit/2466b1ad9d43aa472da9daf8c59b350844c0dae9)) | ||
- **module:** allow modules to have deps ([#128](https://github.com/equinor/fusion-framework/issues/128)) ([2466b1a](https://github.com/equinor/fusion-framework/commit/2466b1ad9d43aa472da9daf8c59b350844c0dae9)) | ||
@@ -432,8 +527,8 @@ ## 0.1.1 (2022-02-09) | ||
- **react-app:** fix AppConfigurator interface ([e5a8a21](https://github.com/equinor/fusion-framework/commit/e5a8a21ff6a558876e3db9a2596e891d9abea0cd)) | ||
- **react-app:** fix AppConfigurator interface ([e5a8a21](https://github.com/equinor/fusion-framework/commit/e5a8a21ff6a558876e3db9a2596e891d9abea0cd)) | ||
### Features | ||
- add package for creating framework modules ([4020a1e](https://github.com/equinor/fusion-framework/commit/4020a1e444d990e62f5fd4371302fff01b73616c)) | ||
- **framework:** allow registering config, init hooks from config ([5f12718](https://github.com/equinor/fusion-framework/commit/5f1271817b73dccbb5c0b69389877c4278e6920e)) | ||
- **reat-app:** add default modules ([74bf60e](https://github.com/equinor/fusion-framework/commit/74bf60ec07ea9573901d4160de5d4252e6e9c167)) | ||
- add package for creating framework modules ([4020a1e](https://github.com/equinor/fusion-framework/commit/4020a1e444d990e62f5fd4371302fff01b73616c)) | ||
- **framework:** allow registering config, init hooks from config ([5f12718](https://github.com/equinor/fusion-framework/commit/5f1271817b73dccbb5c0b69389877c4278e6920e)) | ||
- **reat-app:** add default modules ([74bf60e](https://github.com/equinor/fusion-framework/commit/74bf60ec07ea9573901d4160de5d4252e6e9c167)) |
@@ -17,3 +17,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import { from, lastValueFrom, of } from 'rxjs'; | ||
import { mergeMap, reduce } from 'rxjs/operators'; | ||
import { mergeMap, reduce, switchMap } from 'rxjs/operators'; | ||
const assignConfigValue = (obj, prop, value) => { | ||
@@ -36,3 +36,3 @@ var _a; | ||
createConfig(init, initial) { | ||
return this._createConfig(init, initial); | ||
return from(this._createConfig(init, initial)); | ||
} | ||
@@ -47,4 +47,10 @@ createConfigAsync(init, initial) { | ||
} | ||
_get(target) { | ||
return __classPrivateFieldGet(this, _BaseConfigBuilder_configCallbacks, "f")[target]; | ||
} | ||
_has(target) { | ||
return target in __classPrivateFieldGet(this, _BaseConfigBuilder_configCallbacks, "f"); | ||
} | ||
_createConfig(init, initial) { | ||
return this._buildConfig(init, initial).pipe(mergeMap((config) => this._processConfig(config, init))); | ||
return from(this._buildConfig(init, initial)).pipe(switchMap((config) => this._processConfig(config, init))); | ||
} | ||
@@ -51,0 +57,0 @@ _buildConfig(init, initial) { |
@@ -1,2 +0,2 @@ | ||
export const version = '4.3.0'; | ||
export const version = '4.3.1'; | ||
//# sourceMappingURL=version.js.map |
@@ -18,5 +18,7 @@ import { type Observable, type ObservableInput } from 'rxjs'; | ||
protected _set<TTarget extends DotPath<TConfig>>(target: TTarget, cb: ConfigBuilderCallback<DotPathType<TConfig, TTarget>>): void; | ||
protected _createConfig(init: ConfigBuilderCallbackArgs, initial?: Partial<TConfig>): Observable<TConfig>; | ||
protected _buildConfig(init: ConfigBuilderCallbackArgs, initial?: Partial<TConfig>): Observable<Partial<TConfig>>; | ||
protected _get<TTarget extends DotPath<TConfig>>(target: TTarget): ConfigBuilderCallback<DotPathType<TConfig, TTarget>> | undefined; | ||
protected _has<TTarget extends DotPath<TConfig>>(target: TTarget): boolean; | ||
protected _createConfig(init: ConfigBuilderCallbackArgs, initial?: Partial<TConfig>): ObservableInput<TConfig>; | ||
protected _buildConfig(init: ConfigBuilderCallbackArgs, initial?: Partial<TConfig>): ObservableInput<Partial<TConfig>>; | ||
protected _processConfig(config: Partial<TConfig>, _init: ConfigBuilderCallbackArgs): ObservableInput<TConfig>; | ||
} |
@@ -1,1 +0,1 @@ | ||
export declare const version = "4.3.0"; | ||
export declare const version = "4.3.1"; |
{ | ||
"name": "@equinor/fusion-framework-module", | ||
"version": "4.3.0", | ||
"version": "4.3.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/esm/index.js", |
import { from, lastValueFrom, of, type Observable, type ObservableInput } from 'rxjs'; | ||
import { mergeMap, reduce } from 'rxjs/operators'; | ||
import { mergeMap, reduce, switchMap } from 'rxjs/operators'; | ||
import { Modules, ModuleType } from './types'; | ||
import { type DotPath, type DotPathType } from './utils/dot-path'; | ||
/** helper function for extracting multilevel attribute keys */ | ||
/** | ||
* Recursively assigns a configuration value to a nested object property. | ||
* | ||
* This helper function is used to set a value in a nested object structure, creating | ||
* intermediate objects as needed. It supports dot-separated property paths to access | ||
* deeply nested properties. | ||
* | ||
* @param obj - The object to assign the value to. | ||
* @param prop - The property path, either as a string with dot-separated parts or an array of property names. | ||
* @param value - The value to assign. | ||
* @returns The modified object. | ||
*/ | ||
const assignConfigValue = <T>( | ||
@@ -12,6 +23,14 @@ obj: Record<string, unknown>, | ||
): T => { | ||
// Split the property path into individual parts | ||
const props = typeof prop === 'string' ? prop.split('.') : prop; | ||
// Get the first property in the path | ||
const attr = props.shift(); | ||
// If there is a property to process | ||
if (attr) { | ||
// Create the nested object if it doesn't exist | ||
obj[attr] ??= {}; | ||
// If there are more properties in the path, recurse | ||
props.length | ||
@@ -21,2 +40,4 @@ ? assignConfigValue(obj[attr] as Record<string, unknown>, props, value) | ||
} | ||
// Return the modified object | ||
return obj as T; | ||
@@ -26,4 +47,6 @@ }; | ||
/** | ||
* callback arguments for config builder callback function | ||
* @template TRef parent instance | ||
* Defines the arguments passed to a configuration builder callback function. | ||
* | ||
* @template TConfig - The type of the configuration object. | ||
* @template TRef - The type of the reference or parent module. | ||
*/ | ||
@@ -64,3 +87,4 @@ export type ConfigBuilderCallbackArgs<TConfig = unknown, TRef = unknown> = { | ||
* @template TReturn expected return type of callback | ||
* @returns either a sync value or an observable input (async) | ||
* @param args - An object containing arguments that can be used to configure the `ConfigBuilder`. | ||
* @returns The configured value, or an observable that emits the configured value. | ||
*/ | ||
@@ -72,22 +96,36 @@ export type ConfigBuilderCallback<TReturn = unknown> = ( | ||
/** | ||
* template class for building module config | ||
* The `BaseConfigBuilder` class is an abstract class that provides a flexible and extensible way to build and configure modules. | ||
* It allows you to define configuration callbacks for different parts of your module's configuration, | ||
* and then combine and process these callbacks to generate the final configuration object. | ||
* | ||
* The config builder will be the interface consumers of the module will use to configure the module. | ||
* | ||
* The config builder is designed to be used in the following way: | ||
* | ||
* @example | ||
* ```ts | ||
* Imagine you have a module called `MyModule` that requires a configuration object with the following structure: | ||
* | ||
* ```typescript | ||
* type MyModuleConfig = { | ||
* foo: string; | ||
* bar?: number, | ||
* nested?: { up: boolean } | ||
* foo: string; | ||
* bar?: number; | ||
* nested?: { up: boolean }; | ||
* }; | ||
* ``` | ||
* | ||
* You can create a configuration builder for this module by extending the `BaseConfigBuilder` class: | ||
* | ||
* ```typescript | ||
* import { BaseConfigBuilder, ConfigBuilderCallback } from '@equinor/fusion-framework'; | ||
* | ||
* class MyModuleConfigurator extends BaseConfigBuilder<MyModuleConfig> { | ||
* public setFoo(cb: ModuleConfigCallback<string>) { | ||
* this._set('foo', cb); | ||
* public setFoo(cb: ConfigBuilderCallback<string>) { | ||
* this._set('foo', cb); | ||
* } | ||
* | ||
* public setBar(cb: ModuleConfigCallback<number>) { | ||
* public setBar(cb: ConfigBuilderCallback<number>) { | ||
* this._set('bar', cb); | ||
* } | ||
* | ||
* public setUp(cb: ModuleConfigCallback<boolean>) { | ||
* public setUp(cb: ConfigBuilderCallback<boolean>) { | ||
* this._set('nested.up', cb); | ||
@@ -97,3 +135,39 @@ * } | ||
* ``` | ||
* @template TConfig expected config the builder will create | ||
* | ||
* In this example, we define three methods (`setFoo`, `setBar`, and `setUp`) that allow us to set configuration callbacks for different parts of the `MyModuleConfig` object. | ||
* These methods use the `_set` method provided by the `BaseConfigBuilder` class to register the callbacks. | ||
* | ||
* To create the final configuration object, you can use the `createConfig` or `createConfigAsync` methods provided by the `BaseConfigBuilder` class: | ||
* | ||
* ```typescript | ||
* import { configure } from './configure'; | ||
* | ||
* const configurator = new MyModuleConfigurator(); | ||
* const config = await configurator.createConfigAsync(configure); | ||
* ``` | ||
* | ||
* The `configure` function is where you define the actual configuration callbacks. For example: | ||
* | ||
* ```typescript | ||
* import type { ModuleInitializerArgs } from '@equinor/fusion-framework'; | ||
* | ||
* export const configure: ModuleInitializerArgs<MyModuleConfig> = (configurator) => { | ||
* configurator.setFoo(async () => 'https://foo.bar'); | ||
* configurator.setBar(() => 69); | ||
* configurator.setUp(() => true); | ||
* }; | ||
* ``` | ||
* | ||
* In this example, we define the configuration callbacks for the `foo`, `bar`, and `nested.up` properties of the `MyModuleConfig` object. | ||
* | ||
* The `BaseConfigBuilder` class provides several methods and properties to help you build and process the configuration object: | ||
* | ||
* - `createConfig`: Returns an observable that emits the final configuration object. | ||
* - `createConfigAsync`: Returns a promise that resolves with the final configuration object. | ||
* - `_set`: Registers a configuration callback for a specific target path in the configuration object. | ||
* - `_buildConfig`: Builds the configuration object by executing all registered configuration callbacks and merging the results. | ||
* - `_processConfig`: Allows you to perform post-processing on the built configuration object before returning it. | ||
* | ||
* You can override the `_processConfig` method to add additional logic or validation to the configuration object before it is returned. | ||
* | ||
*/ | ||
@@ -108,3 +182,4 @@ export abstract class BaseConfigBuilder<TConfig extends object = Record<string, unknown>> { | ||
* @param initial optional initial config | ||
* @returns configuration object | ||
* @returns observable configuration object | ||
* @sealed | ||
*/ | ||
@@ -115,7 +190,14 @@ public createConfig( | ||
): Observable<TConfig> { | ||
return this._createConfig(init, initial); | ||
return from(this._createConfig(init, initial)); | ||
} | ||
/** | ||
* Asynchronously creates a configuration object of type `TConfig` based on the provided `init` callback and optional `initial` partial configuration. | ||
* | ||
* @see async version of {@link BaseConfigBuilder.createConfig} | ||
* @param init - A callback function that is responsible for initializing the configuration object. | ||
* @param initial - An optional partial configuration object that will be merged with the result of the `init` callback. | ||
* @returns A Promise that resolves to the created configuration object of type `TConfig`. | ||
* @protected | ||
* @sealed | ||
*/ | ||
@@ -130,6 +212,9 @@ public async createConfigAsync( | ||
/** | ||
* internally set configuration of a config attribute | ||
* @param target attribute name of config dot notaded | ||
* @param cb callback function for setting the attribute | ||
* @template TKey keyof config | ||
* Sets a configuration callback for the specified target path in the configuration. | ||
* | ||
* @param target - The target path in the configuration to set the callback for. | ||
* @param cb - The callback function to be executed when the configuration for the specified target path is updated. | ||
* @template TKey - a key of the config object | ||
* @protected | ||
* @sealed | ||
*/ | ||
@@ -144,10 +229,61 @@ protected _set<TTarget extends DotPath<TConfig>>( | ||
/** | ||
* @private internal creation of config | ||
* Retrieves the configuration callback for the specified target path in the configuration. | ||
* | ||
* @param target - The target path in the configuration to retrieve the callback for. | ||
* @returns The configuration builder callback for the specified target, or `undefined` if no callback is registered. | ||
* @protected | ||
* @sealed | ||
*/ | ||
protected _get<TTarget extends DotPath<TConfig>>( | ||
target: TTarget, | ||
): ConfigBuilderCallback<DotPathType<TConfig, TTarget>> | undefined { | ||
return this.#configCallbacks[target] as ConfigBuilderCallback< | ||
DotPathType<TConfig, TTarget> | ||
>; | ||
} | ||
/** | ||
* Checks if the given target path exists in the configuration callbacks. | ||
* @param target - The target path to check. | ||
* @returns `true` if the target path exists in the configuration callbacks, `false` otherwise. | ||
* @protected | ||
* @sealed | ||
*/ | ||
protected _has<TTarget extends DotPath<TConfig>>(target: TTarget): boolean { | ||
return target in this.#configCallbacks; | ||
} | ||
/** | ||
* Builds and processes the configuration object by executing all registered configuration callbacks, merging the results and post-processing the result. | ||
* | ||
* @example | ||
* ```ts | ||
* _createConfig(init, initial) { | ||
* if(!(this._has('foo.bar') || initial?.foo?.bar)){ | ||
* console.warn(`'foo.bar' is not configured, adding default value`); | ||
* this._set('foo.bar', async(args) => { | ||
* if(!args.hasModule('some_module')){ | ||
* throw Error(`'some_module' is not configured`); | ||
* } | ||
* const someModule = await arg.requireInstance('some_module'); | ||
* return someModule.doSomething(); | ||
* }); | ||
* } | ||
* super._createConfig(init, initial); | ||
* } | ||
* ``` | ||
* | ||
* @param init - The configuration builder callback arguments, which include the module context and other relevant data. | ||
* @param initial - An optional partial configuration object to use as the initial base for the configuration. | ||
* @returns An observable that emits the processed configuration. | ||
* @protected | ||
*/ | ||
protected _createConfig( | ||
init: ConfigBuilderCallbackArgs, | ||
initial?: Partial<TConfig>, | ||
): Observable<TConfig> { | ||
return this._buildConfig(init, initial).pipe( | ||
mergeMap((config) => this._processConfig(config, init)), | ||
): ObservableInput<TConfig> { | ||
// Build the initial configuration and then process it | ||
return from(this._buildConfig(init, initial)).pipe( | ||
// Process the built configuration with the provided initialization arguments | ||
switchMap((config) => this._processConfig(config, init)), | ||
); | ||
@@ -157,3 +293,15 @@ } | ||
/** | ||
* @private internal builder | ||
* Builds the configuration object by executing all registered configuration callbacks and merging the results. | ||
* | ||
* @note overriding this method is not recommended, use {@link BaseConfigBuilder._createConfig} instead. | ||
* - use {@link BaseConfigBuilder._createConfig} to add custom initialization logic before building the configuration. | ||
* - use {@link BaseConfigBuilder._processConfig} to validate and post-process the configuration. | ||
* | ||
* | ||
* @param init - The initialization arguments passed to the configuration callbacks. | ||
* @param initial - An optional partial configuration object to use as the initial state. | ||
* @returns An observable that emits the final configuration object. | ||
* @protected | ||
* @sealed | ||
* @readonly | ||
*/ | ||
@@ -163,10 +311,16 @@ protected _buildConfig( | ||
initial?: Partial<TConfig>, | ||
): Observable<Partial<TConfig>> { | ||
): ObservableInput<Partial<TConfig>> { | ||
return from(Object.entries<ConfigBuilderCallback>(this.#configCallbacks)).pipe( | ||
// Transform each config callback into a target-value pair | ||
mergeMap(async ([target, cb]) => { | ||
// Execute callback with init and await result | ||
const value = await cb(init); | ||
// Return target-value pair | ||
return { target, value }; | ||
}), | ||
// Reduce the target-value pairs into a single configuration object | ||
reduce( | ||
// Assign each value to the corresponding target in the accumulator | ||
(acc, { target, value }) => assignConfigValue(acc, target, value), | ||
// Initialize accumulator with initial config or empty object | ||
initial ?? ({} as TConfig), | ||
@@ -183,2 +337,23 @@ ), | ||
* added config callbacks for | ||
* | ||
* @example | ||
* ```ts | ||
* protected _processConfig(config, init) { | ||
* if(!config.foo){ | ||
* config.foo = 1; | ||
* } elseif(!isNaN(config.foo)) { | ||
* throw Error(`'foo' is not a number`); | ||
* } elseif(config.foo < 0) { | ||
* throw Error(`'foo' is negative`); | ||
* } elseif(config.foo > 100) { | ||
* throw Error(`'foo' is too large`); | ||
* } | ||
* return config; | ||
* } | ||
* ``` | ||
* | ||
* @param config - The partial configuration object to process. | ||
* @param _init - Additional configuration arguments (not used in this implementation). | ||
* @returns An observable input that emits the processed configuration object. | ||
* @protected | ||
*/ | ||
@@ -185,0 +360,0 @@ protected _processConfig( |
// Generated by genversion. | ||
export const version = '4.3.0'; | ||
export const version = '4.3.1'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
202891
1773