import { freezeNode } from '@prisma-next/framework-components/ir'; import type { MongoSchemaCollection } from './schema-collection'; import { MongoSchemaIRNode } from './schema-node'; import type { MongoSchemaVisitor } from './visitor'; export class MongoSchemaIR extends MongoSchemaIRNode { readonly nodeKind = 'schema' as const; /** Fixed sentinel: the schema is always the diff tree's single root. */ readonly id = 'schema'; readonly collections: ReadonlyArray; readonly collectionNames: ReadonlyArray; private readonly _byName: Map; constructor(collections: ReadonlyArray) { super(); const sorted = [...collections].sort((a, b) => a.name.localeCompare(b.name)); this.collections = sorted; this._byName = new Map(sorted.map((c) => [c.name, c])); this.collectionNames = sorted.map((c) => c.name); freezeNode(this); } accept(visitor: MongoSchemaVisitor): R { return visitor.schema(this); } collection(name: string): MongoSchemaCollection | undefined { return this._byName.get(name); } }