100 lines
3.3 KiB
TypeScript
100 lines
3.3 KiB
TypeScript
import { PLATFORM_ROUTE_RUNTIME_CONTRACT } from "../contracts/route-runtime-contract.ts";
|
|
import { PLATFORM_ROUTE_REGISTRY } from "../contracts/routes.ts";
|
|
import {
|
|
composeSchemaRegistry,
|
|
PLATFORM_SCHEMA_REGISTRY,
|
|
} from "../contracts/schema-registry.ts";
|
|
import { REFERENCE_FEATURE_CONTRACT } from "./reference-feature/contracts/reference-feature-contract.ts";
|
|
import {
|
|
composeApiOperations,
|
|
validateApiRuntimeBindings,
|
|
} from "../contracts/api-operations.ts";
|
|
import { validateRestProfileBindings } from "../contracts/rest-profiles.ts";
|
|
import { composeRuntimeSchemaCodecs } from "../contracts/schema-registry.ts";
|
|
import { composeBoundaryMapperRegistry } from "../contracts/boundary-mapper.ts";
|
|
|
|
export const INSTALLED_FEATURE_CONTRACTS = Object.freeze([
|
|
REFERENCE_FEATURE_CONTRACT,
|
|
]);
|
|
|
|
export const ROUTE_REGISTRY = Object.freeze({
|
|
...PLATFORM_ROUTE_REGISTRY,
|
|
...REFERENCE_FEATURE_CONTRACT.routes,
|
|
});
|
|
export const ROUTE_RUNTIME_CONTRACT = Object.freeze({
|
|
...PLATFORM_ROUTE_RUNTIME_CONTRACT,
|
|
...REFERENCE_FEATURE_CONTRACT.routeRuntimeContracts,
|
|
});
|
|
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) }),
|
|
);
|
|
export const INVALIDATION_REGISTRY = Object.freeze({
|
|
topics: Object.freeze(
|
|
INSTALLED_FEATURE_CONTRACTS.flatMap(
|
|
(contract) => contract.invalidation.topics,
|
|
),
|
|
),
|
|
namespaces: Object.freeze(
|
|
INSTALLED_FEATURE_CONTRACTS.flatMap(
|
|
(contract) => contract.invalidation.namespaces,
|
|
),
|
|
),
|
|
edges: Object.freeze(
|
|
INSTALLED_FEATURE_CONTRACTS.flatMap(
|
|
(contract) => contract.invalidation.edges,
|
|
),
|
|
),
|
|
});
|
|
export const INVALIDATION_TOPIC_VERSIONS = Object.freeze(
|
|
INSTALLED_FEATURE_CONTRACTS.flatMap((contract) => 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 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;
|
|
}
|