refactor: 도메인이 100개 1000개씩 늘어나도 유지보수 쉬운 구조로 변경
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
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 }),
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user