function coreOptions(graph) {
    return {
        persistence: graph._persistence,
        graphName: graph._graphName,
        writerId: graph._writerId,
        gcPolicy: graph._gcPolicy,
        autoMaterialize: false,
        onDeleteWithData: graph._onDeleteWithData,
        crypto: graph._crypto,
        codec: graph._codec,
        audit: false,
    };
}
function addCachePorts(opts, g) {
    if (g._checkpointPolicy) {
        opts.checkpointPolicy = g._checkpointPolicy;
    }
    if (g._logger) {
        opts.logger = g._logger;
    }
    if (g._seekCache) {
        opts.seekCache = g._seekCache;
    }
}
function addStoragePorts(opts, g) {
    if (g._blobStorage) {
        opts.blobStorage = g._blobStorage;
    }
    if (g._patchBlobStorage) {
        opts.patchBlobStorage = g._patchBlobStorage;
    }
}
function addConfigPorts(opts, g) {
    if (g._trustConfig !== undefined && g._trustConfig !== null) {
        opts.trust = g._trustConfig;
    }
    if (g._patchJournal !== undefined && g._patchJournal !== null) {
        opts.patchJournal = g._patchJournal;
    }
}
function addStoresPorts(opts, g) {
    if (g._checkpointStore !== undefined && g._checkpointStore !== null) {
        opts.checkpointStore = g._checkpointStore;
    }
    if (g._indexStore !== undefined && g._indexStore !== null) {
        opts.indexStore = g._indexStore;
    }
}
/** Opens a detached read-only clone for snapshot queries. */
export async function openDetachedGraph(graph, open) {
    const opts = coreOptions(graph);
    addCachePorts(opts, graph);
    addStoragePorts(opts, graph);
    addConfigPorts(opts, graph);
    addStoresPorts(opts, graph);
    return await open(opts);
}
