@equinor/fusion-framework-module
Advanced tools
Comparing version 4.3.3 to 4.3.4
# Change Log | ||
## 4.3.4 | ||
### Patch Changes | ||
- [#2434](https://github.com/equinor/fusion-framework/pull/2434) [`75d676d`](https://github.com/equinor/fusion-framework/commit/75d676d2c7919f30e036b5ae97c4d814c569aa87) Thanks [@odinr](https://github.com/odinr)! - **@equinor/fusion-framework-module:** | ||
Updated the `_buildConfig` method in `BaseConfigBuilder` to improve error handling and configuration merging. | ||
- Enhanced `_buildConfig` to log errors when a configuration callback fails, providing more detailed error messages. | ||
- Improved the merging process of configuration callbacks by filtering out undefined values and mapping them to target-value pairs. | ||
- Updated the `_buildConfig` method to initialize the accumulator with the initial configuration or an empty object. | ||
```ts | ||
type MyConfig = { | ||
foo?: number; | ||
bar?: string; | ||
} | ||
const initial = {foo: 1, bar: 'baz'}; | ||
export class MyConfigurator extends BaseConfigBuilder<MyConfig> { | ||
setFoo(cb: ConfigBuilderCallback<MyConfig['foo']>){ | ||
this._set('foo', cb); | ||
} | ||
setBar(cb: ConfigBuilderCallback<MyConfig['bar']>){ | ||
this._set('bar', cb); | ||
} | ||
} | ||
const configurator = MyConfigurator(); | ||
configurator.setFoo(async () => { | ||
if(someCondition) // do some async work | ||
}); | ||
configurator.setBar(() => { | ||
return 'override'; | ||
}); | ||
configurator.createConfig(initial).subscribe(console.log); | ||
``` | ||
_Output:_ | ||
```diff | ||
- {foo: undefined, bar: 'override'} | ||
+ {foo: 1, bar: 'override'} | ||
``` | ||
Example of a failed configuration callback: | ||
```ts | ||
configurator.setFoo(async () => { | ||
throw new Error('Failed to set foo'); | ||
}); | ||
``` | ||
_Output:_ | ||
```diff | ||
- Configuration failed | ||
+ {foo: 1, bar: 'override'} | ||
``` | ||
- [#2407](https://github.com/equinor/fusion-framework/pull/2407) [`00d5e9c`](https://github.com/equinor/fusion-framework/commit/00d5e9c632876742c3d2a74efea2f126a0a169d9) Thanks [@odinr](https://github.com/odinr)! - Improved Configuration Callback Handling | ||
BaseConfigBuilder.\_buildConfig will now correctly handle asynchronous configuration callbacks. This change simplifies the handling of asynchronous configuration callbacks by removing the `async` keyword and directly using RxJS operators. | ||
## 4.3.3 | ||
@@ -4,0 +72,0 @@ |
@@ -16,4 +16,4 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
var _BaseConfigBuilder_configCallbacks; | ||
import { from, lastValueFrom, of } from 'rxjs'; | ||
import { mergeMap, reduce, switchMap } from 'rxjs/operators'; | ||
import { EMPTY, from, lastValueFrom, of } from 'rxjs'; | ||
import { catchError, filter, map, mergeMap, reduce, switchMap } from 'rxjs/operators'; | ||
/** | ||
@@ -238,8 +238,10 @@ * Recursively assigns a configuration value to a nested object property. | ||
// Transform each config callback into a target-value pair | ||
mergeMap((_a) => __awaiter(this, [_a], void 0, function* ([target, cb]) { | ||
// Execute callback with init and await result | ||
const value = yield cb(init); | ||
// Return target-value pair | ||
return { target, value }; | ||
})), | ||
mergeMap(([target, cb]) => from(cb(init)).pipe( | ||
// Filter out undefined values, mostly for void return types | ||
filter((value) => value !== undefined), | ||
// Map the value to a target-value pair | ||
map((value) => ({ target, value })), catchError((error) => { | ||
console.error(`Failed to execute config callback: ${cb.name} for attribute: '${target}'`, error); | ||
return EMPTY; | ||
}))), | ||
// Reduce the target-value pairs into a single configuration object | ||
@@ -246,0 +248,0 @@ reduce( |
// Generated by genversion. | ||
export const version = '4.3.3'; | ||
export const version = '4.3.4'; | ||
//# sourceMappingURL=version.js.map |
@@ -35,8 +35,23 @@ import { type Observable, type ObservableInput } from 'rxjs'; | ||
/** | ||
* config builder callback function blueprint | ||
* @template TReturn expected return type of callback | ||
* @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. | ||
* Represents a callback function used in the ConfigBuilder. | ||
* | ||
* The callback function receives the `ConfigBuilderCallbackArgs` as an argument and returns an `Observable` that emits the return value of the callback function or void. | ||
* Return void or undefined to skip providing a value for the configuration attribute. | ||
* | ||
* @example | ||
* ```typescript | ||
* const callback: ConfigBuilderCallback<string> = async(args) => { | ||
* if(args.hasModule('some_module')){ | ||
* const someModule = await args.requireInstance('some_module'); | ||
* return someModule.doSomething(); | ||
* } | ||
* // will not provide a value for the configuration attribute | ||
* }; | ||
* ``` | ||
* | ||
* @template TReturn The return type of the callback function. | ||
* @param args The arguments passed to the callback function. | ||
* @returns An Observable that emits the return value of the callback function or void. | ||
*/ | ||
export type ConfigBuilderCallback<TReturn = unknown> = (args: ConfigBuilderCallbackArgs) => ObservableInput<TReturn>; | ||
export type ConfigBuilderCallback<TReturn = unknown> = (args: ConfigBuilderCallbackArgs) => ObservableInput<TReturn | void>; | ||
/** | ||
@@ -43,0 +58,0 @@ * The `BaseConfigBuilder` class is an abstract class that provides a flexible and extensible way to build and configure modules. |
@@ -1,1 +0,1 @@ | ||
export declare const version = "4.3.3"; | ||
export declare const version = "4.3.4"; |
{ | ||
"name": "@equinor/fusion-framework-module", | ||
"version": "4.3.3", | ||
"version": "4.3.4", | ||
"description": "", | ||
@@ -45,3 +45,3 @@ "main": "dist/esm/index.js", | ||
"@types/semver": "^7.5.0", | ||
"typescript": "^5.5.3" | ||
"typescript": "^5.5.4" | ||
}, | ||
@@ -48,0 +48,0 @@ "peerDependencies": { |
@@ -1,3 +0,3 @@ | ||
import { from, lastValueFrom, of, type Observable, type ObservableInput } from 'rxjs'; | ||
import { mergeMap, reduce, switchMap } from 'rxjs/operators'; | ||
import { EMPTY, from, lastValueFrom, of, type Observable, type ObservableInput } from 'rxjs'; | ||
import { catchError, filter, map, mergeMap, reduce, switchMap } from 'rxjs/operators'; | ||
import { Modules, ModuleType } from './types'; | ||
@@ -82,10 +82,25 @@ import { type DotPath, type DotPathType } from './utils/dot-path'; | ||
/** | ||
* config builder callback function blueprint | ||
* @template TReturn expected return type of callback | ||
* @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. | ||
* Represents a callback function used in the ConfigBuilder. | ||
* | ||
* The callback function receives the `ConfigBuilderCallbackArgs` as an argument and returns an `Observable` that emits the return value of the callback function or void. | ||
* Return void or undefined to skip providing a value for the configuration attribute. | ||
* | ||
* @example | ||
* ```typescript | ||
* const callback: ConfigBuilderCallback<string> = async(args) => { | ||
* if(args.hasModule('some_module')){ | ||
* const someModule = await args.requireInstance('some_module'); | ||
* return someModule.doSomething(); | ||
* } | ||
* // will not provide a value for the configuration attribute | ||
* }; | ||
* ``` | ||
* | ||
* @template TReturn The return type of the callback function. | ||
* @param args The arguments passed to the callback function. | ||
* @returns An Observable that emits the return value of the callback function or void. | ||
*/ | ||
export type ConfigBuilderCallback<TReturn = unknown> = ( | ||
args: ConfigBuilderCallbackArgs, | ||
) => ObservableInput<TReturn>; | ||
) => ObservableInput<TReturn | void>; | ||
@@ -304,8 +319,17 @@ /** | ||
// 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 }; | ||
}), | ||
mergeMap(([target, cb]) => | ||
from(cb(init)).pipe( | ||
// Filter out undefined values, mostly for void return types | ||
filter((value) => value !== undefined), | ||
// Map the value to a target-value pair | ||
map((value) => ({ target, value })), | ||
catchError((error) => { | ||
console.error( | ||
`Failed to execute config callback: ${cb.name} for attribute: '${target}'`, | ||
error, | ||
); | ||
return EMPTY; | ||
}), | ||
), | ||
), | ||
// Reduce the target-value pairs into a single configuration object | ||
@@ -312,0 +336,0 @@ reduce( |
// Generated by genversion. | ||
export const version = '4.3.3'; | ||
export const version = '4.3.4'; |
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
237199
2601