refactor: 도메인이 100개 1000개씩 늘어나도 유지보수 쉬운 구조로 변경
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import type { RouteObject } from "react-router-dom";
|
||||
import type { AnyFeatureModule } from "../features/feature-module.ts";
|
||||
import { assertWithinCardinalityBudget } from "../platform/cardinality/cardinality-budget.ts";
|
||||
|
||||
export type BoundedContextRouteModule = Readonly<{
|
||||
path: string;
|
||||
loadRoutes(): Promise<readonly RouteObject[]>;
|
||||
}>;
|
||||
|
||||
export type BoundedContextModule<
|
||||
Feature extends AnyFeatureModule = AnyFeatureModule,
|
||||
> = Readonly<{
|
||||
id: string;
|
||||
features: readonly Feature[];
|
||||
budget: Readonly<{ maxFeatures: number }>;
|
||||
route?: BoundedContextRouteModule;
|
||||
}>;
|
||||
|
||||
export function defineBoundedContextModule<const Feature extends AnyFeatureModule>(
|
||||
definition: Readonly<{
|
||||
id: string;
|
||||
features: readonly Feature[];
|
||||
budget: Readonly<{ maxFeatures: number }>;
|
||||
route?: BoundedContextRouteModule;
|
||||
}>,
|
||||
): BoundedContextModule<Feature> {
|
||||
assertWithinCardinalityBudget(
|
||||
`${definition.id}.features`,
|
||||
definition.features.length,
|
||||
definition.budget.maxFeatures,
|
||||
);
|
||||
const seen = new Set<string>();
|
||||
for (const feature of definition.features) {
|
||||
if (seen.has(feature.id)) {
|
||||
throw new TypeError(`Duplicate ${definition.id}.features child id: ${feature.id}`);
|
||||
}
|
||||
seen.add(feature.id);
|
||||
}
|
||||
return Object.freeze({
|
||||
...definition,
|
||||
features: Object.freeze([...definition.features]),
|
||||
budget: Object.freeze({ ...definition.budget }),
|
||||
...(definition.route ? { route: Object.freeze({ ...definition.route }) } : {}),
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Spec §5.2. Ownership declaration of the reference bounded context: the app
|
||||
* that owns it, its route root, and its direct-feature budget. Features name
|
||||
* this id as their owner.
|
||||
*/
|
||||
export const CONTEXT_MODULE_ID = "reference-context";
|
||||
export const CONTEXT_APP_ID = "template-app";
|
||||
export const CONTEXT_ROUTE_PATH = "examples/reference-resources/*";
|
||||
export const CONTEXT_MAX_FEATURES = 200;
|
||||
Reference in New Issue
Block a user