42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
import { createApplication } from "../application/create-application.js";
|
|
|
|
/**
|
|
* This is the only module allowed to join concrete adapters to application
|
|
* ports. Boot phases are explicit so failures can stop before product mount.
|
|
*
|
|
* @template Config
|
|
* @template Release
|
|
* @template {Parameters<typeof createApplication>[0]} OutputPorts
|
|
* @template Infrastructure
|
|
* @param {{
|
|
* loadConfig(): Promise<Config>,
|
|
* loadRelease(config: Config): Promise<Release>,
|
|
* createAdapters(context: {
|
|
* config: Config,
|
|
* release: Release
|
|
* }): Promise<{
|
|
* outputPorts: OutputPorts,
|
|
* infrastructure: Infrastructure
|
|
* }>
|
|
* }} factories
|
|
* @returns {Promise<Readonly<{
|
|
* config: Config,
|
|
* release: Release,
|
|
* infrastructure: Infrastructure,
|
|
* application: ReturnType<typeof createApplication>
|
|
* }>>}
|
|
*/
|
|
export async function createCompositionRoot(factories) {
|
|
const config = await factories.loadConfig();
|
|
const release = await factories.loadRelease(config);
|
|
const adapters = await factories.createAdapters({ config, release });
|
|
const application = createApplication(adapters.outputPorts);
|
|
|
|
return Object.freeze({
|
|
config,
|
|
release,
|
|
infrastructure: adapters.infrastructure,
|
|
application,
|
|
});
|
|
}
|