refactor: 도메인이 100개 1000개씩 늘어나도 유지보수 쉬운 구조로 변경

This commit is contained in:
donghyeon-ka
2026-09-24 00:42:21 +09:00
parent 91ae42a2a7
commit 6f6c48ebb7
1274 changed files with 290812 additions and 0 deletions
+34
View File
@@ -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 }),
});
}