import { openDbReadonly, ReadonlyDbError } from '../../server/db/readonly.js';
import { RawEntityReader } from '../../server/domain/raw-entity-reader.js';
import { serializationEngine } from '../../server/core/plugin-host/serialization-engine.js';
import '../../server/serialization/registerAll.js';
import { CliError } from './errors.js';
import { resolveProject } from './project.js';
export function createContext(args) {
    const projectDir = resolveProject(args.project);
    try {
        const { handle, close } = openDbReadonly(projectDir);
        const reader = new RawEntityReader(handle);
        return {
            projectDir,
            reader,
            registry: serializationEngine,
            db: handle,
            close,
        };
    }
    catch (err) {
        if (err instanceof ReadonlyDbError) {
            throw new CliError(err.code, err.message, err.hint);
        }
        throw err;
    }
}
//# sourceMappingURL=context.js.map