The fixture relied on reference-feature and its context, so sample removal failed on it. It now installs two synthetic features in its own context, and the invalidation flatMaps get the same explicit element types as the other composers (frozen empty arrays exposed the same union inference failure). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
137 lines
4.7 KiB
TypeScript
137 lines
4.7 KiB
TypeScript
import {
|
|
composeApiOperations,
|
|
validateApiRuntimeBindings,
|
|
} from "../contracts/api-operations.ts";
|
|
import { composeBoundaryMapperRegistry } from "../contracts/boundary-mapper.ts";
|
|
import { PLATFORM_ROUTE_RUNTIME_CONTRACT } from "../contracts/route-runtime-contract.ts";
|
|
import { validateRestProfileBindings } from "../contracts/rest-profiles.ts";
|
|
import { PLATFORM_ROUTE_REGISTRY } from "../contracts/routes.ts";
|
|
import {
|
|
composeRuntimeSchemaCodecs,
|
|
composeSchemaRegistry,
|
|
PLATFORM_SCHEMA_REGISTRY,
|
|
} from "../contracts/schema-registry.ts";
|
|
import { composeUniqueRecord } from "../platform/cardinality/compose-unique-record.ts";
|
|
import { INSTALLED_PRODUCT_FEATURES } from "./installed-product-manifest.ts";
|
|
|
|
export const INSTALLED_FEATURE_CONTRACTS = INSTALLED_PRODUCT_FEATURES;
|
|
|
|
// 09-01. The registries keep composeUniqueRecord's own type, the intersection
|
|
// of every record. The former cast to `PLATFORM & InstalledFeatureContract[...]`
|
|
// was an intersection with a union once two features were installed, which
|
|
// kept only the route keys common to both.
|
|
export const ROUTE_REGISTRY = composeUniqueRecord(
|
|
[
|
|
PLATFORM_ROUTE_REGISTRY,
|
|
...INSTALLED_FEATURE_CONTRACTS.map((contract) => contract.routes),
|
|
],
|
|
() => "route registry",
|
|
);
|
|
|
|
export const ROUTE_RUNTIME_CONTRACT = composeUniqueRecord(
|
|
[
|
|
PLATFORM_ROUTE_RUNTIME_CONTRACT,
|
|
...INSTALLED_FEATURE_CONTRACTS.map(
|
|
(contract) => contract.routeRuntimeContracts,
|
|
),
|
|
],
|
|
() => "route runtime contract",
|
|
);
|
|
|
|
export const API_OPERATIONS = composeApiOperations(
|
|
INSTALLED_FEATURE_CONTRACTS.map((contract) => contract.apiOperations),
|
|
);
|
|
export const REST_PROFILE_BINDINGS_VALID = validateRestProfileBindings(
|
|
API_OPERATIONS,
|
|
Object.freeze({ PRIMARY_API: Object.freeze(["omit"] as const) }),
|
|
);
|
|
// 09-01. Element types are spelled out for the same reason as in
|
|
// installed-feature-adapters.ts: flatMap over the installed-contract union
|
|
// otherwise returns the member arrays unflattened.
|
|
type InstalledInvalidation =
|
|
(typeof INSTALLED_FEATURE_CONTRACTS)[number]["invalidation"];
|
|
type InstalledTopicVersion =
|
|
(typeof INSTALLED_FEATURE_CONTRACTS)[number]["topicVersions"][number];
|
|
|
|
export const INVALIDATION_REGISTRY = Object.freeze({
|
|
topics: Object.freeze(
|
|
INSTALLED_FEATURE_CONTRACTS.flatMap(
|
|
(contract): readonly InstalledInvalidation["topics"][number][] =>
|
|
contract.invalidation.topics,
|
|
),
|
|
),
|
|
namespaces: Object.freeze(
|
|
INSTALLED_FEATURE_CONTRACTS.flatMap(
|
|
(contract): readonly InstalledInvalidation["namespaces"][number][] =>
|
|
contract.invalidation.namespaces,
|
|
),
|
|
),
|
|
edges: Object.freeze(
|
|
INSTALLED_FEATURE_CONTRACTS.flatMap(
|
|
(contract): readonly InstalledInvalidation["edges"][number][] =>
|
|
contract.invalidation.edges,
|
|
),
|
|
),
|
|
});
|
|
export const INVALIDATION_TOPIC_VERSIONS = Object.freeze(
|
|
INSTALLED_FEATURE_CONTRACTS.flatMap(
|
|
(contract): readonly InstalledTopicVersion[] => contract.topicVersions,
|
|
),
|
|
);
|
|
export const SCHEMA_REGISTRY = composeSchemaRegistry([
|
|
PLATFORM_SCHEMA_REGISTRY,
|
|
...INSTALLED_FEATURE_CONTRACTS.map((contract) => contract.schemas),
|
|
]);
|
|
export const RUNTIME_SCHEMA_CODECS = composeRuntimeSchemaCodecs(
|
|
INSTALLED_FEATURE_CONTRACTS.map((contract) => contract.runtimeSchemas),
|
|
);
|
|
export const MAPPER_REGISTRY = composeBoundaryMapperRegistry(
|
|
INSTALLED_FEATURE_CONTRACTS.map((contract) => contract.mappers),
|
|
);
|
|
export const API_RUNTIME_BINDINGS_VALID = validateApiRuntimeBindings(
|
|
API_OPERATIONS,
|
|
SCHEMA_REGISTRY,
|
|
RUNTIME_SCHEMA_CODECS,
|
|
MAPPER_REGISTRY,
|
|
);
|
|
|
|
export const ROUTE_FEATURE_OWNER: Readonly<Record<string, string>> =
|
|
Object.freeze(
|
|
Object.fromEntries(
|
|
INSTALLED_FEATURE_CONTRACTS.flatMap((contract) =>
|
|
Object.keys(contract.routes).map(
|
|
(routeId) => [routeId, contract.featureId] as const,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
export const NAVIGATION_ROUTES = Object.freeze(
|
|
Object.values(ROUTE_REGISTRY)
|
|
.filter(isNavigableRoute)
|
|
.sort((left, right) => left.navigationOrder - right.navigationOrder),
|
|
);
|
|
|
|
type InstalledRouteDefinition =
|
|
(typeof ROUTE_REGISTRY)[keyof typeof ROUTE_REGISTRY];
|
|
type NavigableRoute = InstalledRouteDefinition &
|
|
Readonly<{ navigationOrder: number }>;
|
|
|
|
function isNavigableRoute(
|
|
definition: InstalledRouteDefinition,
|
|
): definition is NavigableRoute {
|
|
return definition.navigationOrder !== null;
|
|
}
|
|
|
|
export function getRoute(routeId: string): InstalledRouteDefinition {
|
|
const registry: Readonly<Record<string, InstalledRouteDefinition>> =
|
|
ROUTE_REGISTRY;
|
|
const selected = registry[routeId];
|
|
if (!selected) throw new Error(`Unregistered route: ${routeId}`);
|
|
return selected;
|
|
}
|
|
|
|
export function routePath(routeId: string): string {
|
|
return getRoute(routeId).path;
|
|
}
|