Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🤖 Bip Bop - Fusion Framework Release #2168

Merged
merged 1 commit into from
May 23, 2024
Merged

🤖 Bip Bop - Fusion Framework Release #2168

merged 1 commit into from
May 23, 2024

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented May 21, 2024

This PR was opened by the Changesets release GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.

Releases

@equinor/[email protected]

Major Changes

  • #2155 97a79fb Thanks @odinr! - The Logger module is a new package for handling logging in the Fusion frontend ecosystem.

    • The Logger class extends the ILogger interface, ensuring that all logger implementations adhere to a consistent contract.
    • The ConsoleLogger class is a concrete implementation of the Logger class that logs messages to the console.
    • The _createMessage method in the Logger class has been made abstract, allowing concrete implementations to define their own message formatting logic.
    • Added a version property to the Logger class, which exposes the current version of the logger module.
    • Introduced a resolveLogLevel utility function that can resolve log levels from both string and numeric representations.
    • Added support for resolving the default log level from the FUSION_LOG_LEVEL environment variable. If the environment variable is not set, it defaults to LogLevel.Error.

    To use the new Logger module, import the necessary components and create a new logger instance:

    import { ConsoleLogger, LogLevel } from '@equinor/fusion-log';
    
    // Create a new console logger
    const logger = new ConsoleLogger('MyApplication');
    
    // Set the log level
    logger.level = LogLevel.Debug;
    
    // Log messages at different levels
    logger.debug('This is a debug message');
    logger.info('This is an info message');
    logger.warn('This is a warning message');
    logger.error('This is an error message');
    
    // Create a sub-logger
    const subLogger = logger.createSubLogger('SubComponent');
    subLogger.debug('This is a debug message from the sub-logger');

    To resolve a log level from a string or numeric value, use the resolveLogLevel function:

    import { resolveLogLevel, LogLevel } from '@equinor/fusion-log';
    
    // Resolve log level from a string
    const logLevelFromString = resolveLogLevel('debug'); // LogLevel.Debug
    
    // Resolve log level from a number
    const logLevelFromNumber = resolveLogLevel(3); // LogLevel.Info

    The default log level can be controlled using the FUSION_LOG_LEVEL environment variable. If the variable is set to an invalid value, it will default to LogLevel.Debug in development environments and LogLevel.Error in production environments.

    # Set the default log level to Debug
    FUSION_LOG_LEVEL=debug
    
    # Set the default log level to Warning
    FUSION_LOG_LEVEL=warning

Minor Changes

  • #2155 97a79fb Thanks @odinr! - Added a new script test:coverage to the package.json file. This script runs the test suite with code coverage reporting enabled, allowing developers to analyze the test coverage of the codebase.

    Example usage:

    pnpm test
    pnpm test:coverage

    This will run the test suite using Vitest and generate a code coverage report.

    Added a new test suite for the ConsoleLogger class. The test suite covers various scenarios, including:

    • Logging messages at different log levels (debug, info, warning, error)
    • Logging multiple messages in a single call
    • Logging messages with a custom title
    • Ensuring that messages with a lower log level than the configured level are not logged
    • Testing sub-loggers and their behavior, including custom sub-titles

    Added a new configuration file vitest.config.ts for Vitest, the test runner used in this package. This file sets up the project-specific configuration for Vitest, such as the test file pattern and environment variables.

@equinor/[email protected]

Minor Changes

  • #2180 060a1aa Thanks @odinr! - ## @equinor/fusion-react

    What changed?

    The useAppEnvironmentVariables hook has been added to the @equinor/fusion-react package.
    This hook provides access to the application's environment variables, which are retrieved from the app module provided by the framework.

    Why the change?

    Previously, there was no built-in way to access the application's environment variables from the React components.
    This new hook fills that gap, making it easier for developers to retrieve and use the environment configuration in their applications.

    How to use the new feature

    To use the useAppEnvironmentVariables hook, simply import it and call it in your React component:

    import { useAppEnvironmentVariables } from '@equinor/fusion-react';
    
    const MyComponent = () => {
      const env = useAppEnvironmentVariables<{ API_URL: string }>();
    
      if (!env.complete) {
        return <div>Loading environment variables...</div>;
      }
    
      if (env.error) {
        return <div>Error loading environment variables</div>;
      }
    
      return (
        <div>
          My environment variables: {JSON.stringify(env.value, null, 2)}
        </div>
      );
    };

    The hook returns an observable state object that represents the current environment configuration.
    The value property of this object contains the environment variables, which can be typed using a generic type parameter.

    If the environment configuration is not yet available (e.g., during the initial load), the complete property will be false.
    If there was an error retrieving the configuration, the error property will be set.

    Migration guide

    There are no breaking changes introduced with this feature. Developers can start using the useAppEnvironmentVariables hook immediately to access their application's environment variables.

Patch Changes

@equinor/[email protected]

Patch Changes

@equinor/[email protected]

Patch Changes

@equinor/[email protected]

Patch Changes

@equinor/[email protected]

Patch Changes

@equinor/[email protected]

Patch Changes

@equinor/[email protected]

Patch Changes

@equinor/[email protected]

Patch Changes

  • #2171 9a91bb7 Thanks @odinr! - ## @equinor/fusion-event

    Improved Type Resolution for FrameworkEventInitType

    The FrameworkEventInitType type has been enhanced to better resolve types for both IFrameworkEvent and FrameworkEvent.

    When defining events FrameworkEventMap, the dispatch type can now be inferred from the event type.

    Changes

    The type definition for FrameworkEventInitType has been updated as follows:

    export type FrameworkEventInitType<T> =
        T extends IFrameworkEvent<infer U> ? U : T extends FrameworkEvent<infer U> ? U : never;

    This change ensures that FrameworkEventInitType can now correctly infer the type for both IFrameworkEvent and FrameworkEvent.

  • Updated dependencies [fb424be, fb424be, fb424be]:

@equinor/[email protected]

Patch Changes

@equinor/[email protected]

Patch Changes

@equinor/[email protected]

Patch Changes

  • #2177 fb424be Thanks @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:

    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 fb424be Thanks @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 fb424be Thanks @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:

    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.

@equinor/[email protected]

Patch Changes

@equinor/[email protected]

Patch Changes

@equinor/[email protected]

Patch Changes

@equinor/[email protected]

Patch Changes

@equinor/[email protected]

Patch Changes

@equinor/[email protected]

Patch Changes

@equinor/[email protected]

Patch Changes

@equinor/[email protected]

Patch Changes

@equinor/[email protected]

Patch Changes

@equinor/[email protected]

Patch Changes

@equinor/[email protected]

Patch Changes

@equinor/[email protected]

Patch Changes

@equinor/[email protected]

Patch Changes

@equinor/[email protected]

Patch Changes

@equinor/[email protected]

Patch Changes

@equinor/[email protected]

Patch Changes

@equinor/[email protected]

Patch Changes

@equinor/[email protected]

Patch Changes

@equinor/[email protected]

Patch Changes

  • #2170 6a81125 Thanks @odinr! - ## @equinor/fusion-query

    Improved Action Suffix Resolution

    We have improved the way action suffixes are resolved in the observable package. This change includes the following updates:

    • Enhanced actionBaseType function: Now supports extracting the base action type from both action objects and action type strings.
    • New isActionWithSuffix function: A utility function to check if an action has a specific suffix.
    • Updated isRequestAction, isSuccessAction, isFailureAction, and isCompleteAction functions: These functions now utilize isActionWithSuffix for better type safety and readability.

    Example Usage

    Extracting Base Action Type

    const actionBaseTypeName = actionBaseType('update_my_stuff::request'); // 'update_my_stuff'

    Checking Action Suffix

    if (isRequestAction(action)) {
        // Handle request action
    }
    
    if (isSuccessAction(action)) {
        // Handle success action
    }
    
    if (isFailureAction(action)) {
        // Handle failure action
    }
    
    if (isCompleteAction(action)) {
        // Handle complete action (either success or failure)
    }
    
    // Example
    import { createReducer, isSuccessAction } from '@equinor/fusion-observable';
    
    type Actions =
        | { type: 'foo::request'; type: 'foo::success' }
        | { type: 'fooBar::request'; type: 'fooBar::success' };
    
    const reducer = createReducer<any, Actions>(null, (builder) => {
        builder.addMatcher(isSuccessAction, (state, action) => {
            // IntelliSense will type hint only `::success` actions
            console.log(action.type); // 'foo::success' || 'fooBar::success'
        });
    });
  • #2169 cd737c2 Thanks @odinr! - ## @equinor/fusion-query

    Updated Logger Dependency

    Replaced the internal logger implementation with the @equinor/fusion-log package. This change affects the following files:

    • package.json: Removed chalk dependency and added @equinor/fusion-log.
    • src/Query.ts: Updated import statements to use @equinor/fusion-log.
    • src/QueryTask.ts: Updated import statements to use @equinor/fusion-log.
    • src/client/QueryClient.ts: Updated import statements to use @equinor/fusion-log.
    • Deleted src/logger.ts as it is no longer needed.
    typescript;
    // Before
    import { ConsoleLogger, ILogger } from './logger';
    
    // After
    import { ConsoleLogger, ILogger } from '@equinor/fusion-log';
  • Updated dependencies [97a79fb, 97a79fb]:

@equinor/[email protected]

Patch Changes

@equinor/[email protected]

Major Changes

  • #2180 060a1aa Thanks @odinr! - ## @equinor/fusion-framework-cookbook-app-react-environment-variables

    This new cookbook demonstrates how to use the useAppEnvironmentVariables hook to access environment variables in a Fusion Framework React application.

    The cookbook uses the newly created hook useAppEnvironmentVariables from @equinor/fusion-framework-react-app which retrieve environment variables from the application's configuration.

@equinor/[email protected]

Patch Changes

@equinor/[email protected]

Patch Changes

  • #2182 13d1ae4 Thanks @odinr! - updated all cookbooks to use workspace:^ as a dependency version.

@equinor/[email protected]

Patch Changes

  • #2182 13d1ae4 Thanks @odinr! - updated all cookbooks to use workspace:^ as a dependency version.

@equinor/[email protected]

Patch Changes

@equinor/[email protected]

Patch Changes

@equinor/[email protected]

Patch Changes

@equinor/[email protected]

Patch Changes

  • #2182 13d1ae4 Thanks @odinr! - updated all cookbooks to use workspace:^ as a dependency version.

@equinor/[email protected]

Patch Changes

  • #2182 13d1ae4 Thanks @odinr! - updated all cookbooks to use workspace:^ as a dependency version.

@equinor/[email protected]

Patch Changes

@equinor/[email protected]

Patch Changes

  • #2182 13d1ae4 Thanks @odinr! - updated all cookbooks to use workspace:^ as a dependency version.

@equinor/[email protected]

Patch Changes

  • #2180 060a1aa Thanks @odinr! - ## @equinor/fusion-framework-docs

    Updated the "Getting started" guide with a new section about using environment variables.

@github-actions github-actions bot requested review from odinr and a team as code owners May 21, 2024 08:12
@github-actions github-actions bot marked this pull request as draft May 21, 2024 08:12
@github-actions github-actions bot force-pushed the changeset-release/main branch 7 times, most recently from 9eb7924 to 4779193 Compare May 23, 2024 07:43
@github-actions github-actions bot added 👨🏻‍🍳 cookbooks 👾 React 💾 CLI fusion framework CLI 📚 documentation Improvements or additions to documentation 🛠️ utils packages related to utils 🧬 Modules labels May 23, 2024
@odinr odinr marked this pull request as ready for review May 23, 2024 14:58
@odinr odinr enabled auto-merge (squash) May 23, 2024 14:58
Copy link
Contributor Author

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 12.86% 3678 / 28592
🔵 Statements 12.86% 3678 / 28592
🔵 Functions 12.68% 92 / 725
🔵 Branches 27.3% 225 / 824
File CoverageNo changed files found.
Generated in workflow #6283

@odinr odinr merged commit aac8550 into main May 23, 2024
10 checks passed
@odinr odinr deleted the changeset-release/main branch May 23, 2024 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💾 CLI fusion framework CLI 👨🏻‍🍳 cookbooks 📚 documentation Improvements or additions to documentation 🧬 Modules 👾 React 🛠️ utils packages related to utils
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant