DMF Core Package

The @dream.mf/core package provides the core functionality for the Dream Packages ecosystem. It handles runtime management, plugin registration, and remote module loading.

Installation

npm install @dream.mf/core
# or
yarn add @dream.mf/core

Core Functions

Runtime Management

init()

Initializes the dream-mf runtime environment by setting up the global DreamMF object.

import { init } from '@dream.mf/core';

init();

Runtime Type Definition

interface Runtime {
  version: string;
  environment: string;
  profile?: any;
  logger?: Logger;
  bundler?: Bundler;
  authentication?: Authentication;
  remotes?: Array<Remotes>;
  plugins?: Array<Plugin>;
}

validateRuntime()

Checks if the dream-mf runtime has been installed and initialized by verifying the presence of the global DreamMF object.

import { validateRuntime } from '@dream.mf/core';

if (validateRuntime()) {
  // Runtime is ready
  console.log('Dream.MF runtime is initialized');
}

Plugin Management

registerRuntimePlugin(pluginName: string, config: object)

Registers a plugin with the runtime. Plugins can extend the functionality of the Dream.MF framework.

Plugin Type Definition
interface Plugin {
  name: string;
  config?: object;
}
Example
import { registerRuntimePlugin } from '@dream.mf/core';

registerRuntimePlugin('analytics', {
  trackingId: 'UA-XXXXX-Y',
  debug: true
});

Remote Module Management

registerRuntimeRemote(scope: string, module: string, url: string, loadType?: RemoteLoadType)

Registers a remote module with the runtime for module federation.

Remote Type Definition
interface Remotes {
  url: string;
  scope: string;
  modules: string[];
  loadType?: RemoteLoadType;
}
Example
import { registerRuntimeRemote } from '@dream.mf/core';

registerRuntimeRemote(
  'shop',
  'product-catalog',
  'https://shop.example.com/remoteEntry.js'
);

User Profile Management

registerUserProfile(userProfile?: any)

Registers the current user's profile information in the runtime for easy access across the application.

Example
import { registerUserProfile } from '@dream.mf/core';

registerUserProfile({
  id: '123',
  name: 'John Doe',
  roles: ['admin']
});

Runtime Property Management

validateRuntimeProperty(propertyName: string)

Checks if a specific property exists in the runtime.

registerRuntimeProperty(propertyName: string, object: object)

Registers a new property with the runtime.

Example
import { validateRuntimeProperty, registerRuntimeProperty } from '@dream.mf/core';

if (!validateRuntimeProperty('customFeature')) {
  registerRuntimeProperty('customFeature', {
    enabled: true,
    config: { /* ... */ }
  });
}

Types

Runtime

interface Runtime {
  version: string;
  environment: string;
  profile?: any;
  logger?: Logger;
  bundler?: Bundler;
  authentication?: Authentication;
  remotes?: Array<Remotes>;
  plugins?: Array<Plugin>;
}

Plugin

interface Plugin {
  name: string;
  config?: object;
}

Remotes

interface Remotes {
  url: string;
  scope: string;
  modules: string[];
  loadType?: RemoteLoadType;
}

Example Usage

import { init, registerRuntimePlugin, registerRuntimeRemote } from '@dream.mf/core';

// Initialize the runtime
init();

// Register a plugin
registerRuntimePlugin('logger', {
  level: 'debug'
});

// Register a remote module
registerRuntimeRemote(
  'ui-components',
  'button',
  'https://my-cdn.com/components'
);