"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.DetachedFieldIndexSummarizer = void 0;
const client_utils_1 = require("@fluid-internal/client-utils");
const internal_1 = require("@fluidframework/shared-object-base/internal");
/**
 * The storage key for the blob in the summary containing schema data
 */
const detachedFieldIndexBlobKey = "DetachedFieldIndexBlob";
/**
 * Provides methods for summarizing and loading a tree index.
 */
class DetachedFieldIndexSummarizer {
    constructor(detachedFieldIndex) {
        this.detachedFieldIndex = detachedFieldIndex;
        this.key = "DetachedFieldIndex";
    }
    summarize(props) {
        const data = this.detachedFieldIndex.encode();
        return (0, internal_1.createSingleBlobSummary)(detachedFieldIndexBlobKey, props.stringify(data));
    }
    async load(services, parse) {
        if (await services.contains(detachedFieldIndexBlobKey)) {
            const detachedFieldIndexBuffer = await services.readBlob(detachedFieldIndexBlobKey);
            const treeBufferString = (0, client_utils_1.bufferToString)(detachedFieldIndexBuffer, "utf8");
            const parsed = parse(treeBufferString);
            this.detachedFieldIndex.loadData(parsed);
        }
    }
}
exports.DetachedFieldIndexSummarizer = DetachedFieldIndexSummarizer;
//# sourceMappingURL=detachedFieldIndexSummarizer.js.map