35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import type { BoundedContextModule } from "../contexts/bounded-context-module.ts";
|
|
import { assertWithinCardinalityBudget } from "../platform/cardinality/cardinality-budget.ts";
|
|
|
|
export type DeployableAppModule<Context extends BoundedContextModule = BoundedContextModule> = Readonly<{
|
|
id: string;
|
|
contexts: readonly Context[];
|
|
budget: Readonly<{ maxContexts: number }>;
|
|
}>;
|
|
|
|
export function defineDeployableAppModule<const Context extends BoundedContextModule>(
|
|
definition: Readonly<{
|
|
id: string;
|
|
contexts: readonly Context[];
|
|
budget: Readonly<{ maxContexts: number }>;
|
|
}>,
|
|
): DeployableAppModule<Context> {
|
|
assertWithinCardinalityBudget(
|
|
`${definition.id}.contexts`,
|
|
definition.contexts.length,
|
|
definition.budget.maxContexts,
|
|
);
|
|
const seen = new Set<string>();
|
|
for (const context of definition.contexts) {
|
|
if (seen.has(context.id)) {
|
|
throw new TypeError(`Duplicate ${definition.id}.contexts child id: ${context.id}`);
|
|
}
|
|
seen.add(context.id);
|
|
}
|
|
return Object.freeze({
|
|
...definition,
|
|
contexts: Object.freeze([...definition.contexts]),
|
|
budget: Object.freeze({ ...definition.budget }),
|
|
});
|
|
}
|