refactor: 도메인이 100개 1000개씩 늘어나도 유지보수 쉬운 구조로 변경
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
import { composeUniqueRecord } from "../../src/platform/cardinality/compose-unique-record.ts";
|
||||
import {
|
||||
resolveProductFeatures,
|
||||
selectCompiledProductFeatures,
|
||||
} from "../../src/contracts/product-features.ts";
|
||||
import { defineBoundedContextModule } from "../../src/contexts/bounded-context-module.ts";
|
||||
import { defineDeployableAppModule } from "../../src/apps/deployable-app-module.ts";
|
||||
|
||||
/**
|
||||
* Spec §39. Scale-sensitive production composition paths, each parameterized
|
||||
* by one cardinality `n`. Inputs are built outside the timed region.
|
||||
*/
|
||||
export type CompositionWorkload = Readonly<{
|
||||
name: string;
|
||||
implementation: string;
|
||||
prepare(n: number): () => unknown;
|
||||
}>;
|
||||
|
||||
export function createUniqueRegistryParts(
|
||||
count: number,
|
||||
): readonly Readonly<Record<string, number>>[] {
|
||||
return Array.from({ length: count }, (_, index) =>
|
||||
Object.freeze({ [`route-${index}`]: index }),
|
||||
);
|
||||
}
|
||||
|
||||
function featureIds(count: number): string[] {
|
||||
return Array.from(
|
||||
{ length: count },
|
||||
(_, index) => `feature-${index.toString().padStart(7, "0")}`,
|
||||
);
|
||||
}
|
||||
|
||||
const CONTEXT_FEATURES = 200;
|
||||
|
||||
export const COMPOSITION_WORKLOADS: readonly CompositionWorkload[] = Object.freeze([
|
||||
{
|
||||
name: "registry-composition",
|
||||
implementation: "composeUniqueRecord",
|
||||
prepare(n: number) {
|
||||
const parts = createUniqueRegistryParts(n);
|
||||
return () => composeUniqueRecord(parts, () => "route");
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "product-feature-selection",
|
||||
implementation: "selectCompiledProductFeatures",
|
||||
prepare(n: number) {
|
||||
const compiled = featureIds(n).map((featureId) => Object.freeze({ featureId }));
|
||||
const declared = compiled
|
||||
.filter((_, index) => index % 2 === 0)
|
||||
.map((feature) => feature.featureId)
|
||||
.join(",");
|
||||
return () => selectCompiledProductFeatures(compiled, declared);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "product-feature-resolution",
|
||||
implementation: "resolveProductFeatures",
|
||||
prepare(n: number) {
|
||||
const compiled = featureIds(n);
|
||||
const installed = compiled.filter((_, index) => index % 3 !== 0);
|
||||
return () => resolveProductFeatures(compiled, installed);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "context-hierarchy-composition",
|
||||
implementation: "defineBoundedContextModule+defineDeployableAppModule",
|
||||
prepare(n: number) {
|
||||
const features = featureIds(n).map((id) =>
|
||||
Object.freeze({
|
||||
id,
|
||||
contracts: Object.freeze({ featureId: id }),
|
||||
routes: Object.freeze({}),
|
||||
adapters: Object.freeze([]),
|
||||
runtimes: Object.freeze([]),
|
||||
messages: Object.freeze({}),
|
||||
contractContributions: Object.freeze([]),
|
||||
}),
|
||||
);
|
||||
const contextCount = Math.ceil(n / CONTEXT_FEATURES);
|
||||
return () => {
|
||||
const contexts = Array.from({ length: contextCount }, (_, contextIndex) =>
|
||||
defineBoundedContextModule({
|
||||
id: `context-${contextIndex}`,
|
||||
features: features.slice(
|
||||
contextIndex * CONTEXT_FEATURES,
|
||||
(contextIndex + 1) * CONTEXT_FEATURES,
|
||||
),
|
||||
budget: Object.freeze({ maxFeatures: CONTEXT_FEATURES }),
|
||||
}),
|
||||
);
|
||||
// Apps are sharded by the same direct-child budget.
|
||||
const apps: unknown[] = [];
|
||||
for (let index = 0; index < contexts.length; index += 20) {
|
||||
apps.push(
|
||||
defineDeployableAppModule({
|
||||
id: `app-${index / 20}`,
|
||||
contexts: contexts.slice(index, index + 20),
|
||||
budget: Object.freeze({ maxContexts: 20 }),
|
||||
}),
|
||||
);
|
||||
}
|
||||
return apps;
|
||||
};
|
||||
},
|
||||
},
|
||||
]);
|
||||
Reference in New Issue
Block a user