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 }),
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { PRODUCT_APP } from "../.generated/product-app.ts";
|
||||
import { PRODUCT_CONTEXT_MODULES } from "../.generated/product-context-index.ts";
|
||||
import { defineDeployableAppModule } from "./deployable-app-module.ts";
|
||||
|
||||
/**
|
||||
* The deployable app this build produces. Its identity, budget and direct
|
||||
* contexts all come from the generator's selected app (`--app=`/`PRODUCT_APP_ID`,
|
||||
* or the single declared app), so the bundle only ever contains that app.
|
||||
*/
|
||||
export const TEMPLATE_APP_MODULE = defineDeployableAppModule({
|
||||
id: PRODUCT_APP.id,
|
||||
contexts: PRODUCT_CONTEXT_MODULES,
|
||||
budget: Object.freeze({ maxContexts: PRODUCT_APP.maxContexts }),
|
||||
} as const);
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* Spec §5.3. Ownership declaration of the template deployable app. The
|
||||
* generator reads these literals; contexts name this id as their owner.
|
||||
*/
|
||||
export const APP_MODULE_ID = "template-app";
|
||||
export const APP_MAX_CONTEXTS = 20;
|
||||
Reference in New Issue
Block a user