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>[] { 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({}), messages: Object.freeze({}), loadRuntime: async () => Object.freeze({ featureId: id, apiContract: Object.freeze({}), adapters: 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; }; }, }, ]);