Martin Karkowski
4791914998
- Modified: - cli.runNopeBackend: added the flag "noBaseServices" to prevent providing the base-services - communication.getLayer.nodejs/browser: adding default value for logger - dispatcher.getDispatcher: changed option "constructorClass" to "dispatcherConstructorClass" - helpers.limit.spec: Adapted Timings - loader.getPackageLoader.nodejs/browser: Changed the options.
77 lines
2.0 KiB
TypeScript
77 lines
2.0 KiB
TypeScript
/**
|
|
* @author Martin Karkowski
|
|
* @email m.karkowski@zema.de
|
|
*/
|
|
|
|
import { getSingleton } from "../helpers/singletonMethod";
|
|
import {
|
|
IDispatcherConstructor,
|
|
INopeDispatcherOptions,
|
|
INopePackageLoader,
|
|
INopePackageLoaderConstructor,
|
|
} from "../types/nope";
|
|
import { generateNopeBasicPackage } from "./generateNopeBasicPackage";
|
|
import { NopePackageLoader } from "./nopePackageLoader";
|
|
|
|
/**
|
|
* Function to extract the Package-Loader.
|
|
* @param {INopeDispatcherOptions} dispatcherOptions The provided options for the Dispatcher
|
|
* @param options Settings for the creation of the Dispatcher etc.
|
|
* @returns {INopePackageLoader} The Package loader.
|
|
*/
|
|
export function getPackageLoader(
|
|
dispatcherOptions: INopeDispatcherOptions,
|
|
options: {
|
|
packageLoaderConstructorClass?: INopePackageLoaderConstructor;
|
|
dispatcherConstructorClass?: IDispatcherConstructor;
|
|
singleton?: boolean;
|
|
useBaseServices?: boolean;
|
|
} = {}
|
|
): INopePackageLoader {
|
|
if (
|
|
options.packageLoaderConstructorClass === null ||
|
|
options.packageLoaderConstructorClass === undefined
|
|
) {
|
|
options.packageLoaderConstructorClass = NopePackageLoader;
|
|
}
|
|
|
|
options = Object.assign(
|
|
{
|
|
packageLoaderConstructorClass: null,
|
|
dispatcherConstructorClass: null,
|
|
singleton: true,
|
|
useBaseServices: true,
|
|
},
|
|
options
|
|
);
|
|
|
|
const create = () => {
|
|
// Create a loader
|
|
const loader = new options.packageLoaderConstructorClass();
|
|
|
|
// load the default Package:
|
|
loader
|
|
.addPackage(
|
|
generateNopeBasicPackage(dispatcherOptions, options.singleton)
|
|
)
|
|
.catch((e) => {
|
|
throw e;
|
|
});
|
|
|
|
return loader;
|
|
};
|
|
|
|
if (options.singleton) {
|
|
// Create a singaleton if required.
|
|
// use the container to receive the
|
|
// singleton object
|
|
const container = getSingleton("nopeBackendPackageLoader.instance", create);
|
|
|
|
return container.instance;
|
|
}
|
|
|
|
// No singleton is required =>
|
|
// create a new instance.
|
|
return create();
|
|
}
|