Exact source used by this build. SHA-256: 45dc8030771477b6313407d034f13ce7359bd91a520ae3ab395ceb6555dc2731.
1 /** A content domain owns its data, schemas and any additional invariants. */
2 export interface ContentDomain {
3 readonly id: string;
4 /** Parsed content passed to systems under this domain's ID. */
5 readonly data?: unknown;
6 validate(): void;
7 }
8
9 /** Compose new domain payloads without editing the simulation or its host. */
10 export function assembleDomainData(domains: readonly ContentDomain[]): Record<string, unknown> {
11 const seen = new Set<string>();
12 const entries: [string, unknown][] = [];
13 for (const domain of domains) {
14 if (seen.has(domain.id)) throw new Error(`Duplicate content domain: ${domain.id}`);
15 seen.add(domain.id);
16 if (domain.data !== undefined) entries.push([domain.id, domain.data]);
17 }
18 return Object.fromEntries(entries);
19 }
20
21 export function validateDomains(domains: readonly ContentDomain[]): void {
22 const seen = new Set<string>();
23 for (const domain of domains) {
24 if (seen.has(domain.id)) throw new Error(`Duplicate content domain: ${domain.id}`);
25 seen.add(domain.id);
26 domain.validate();
27 }
28 }
29