"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPartitionCount = exports.parseMetadata = void 0;
const utils_1 = require("@streamr/utils");
const StreamrClientError_1 = require("./StreamrClientError");
const parseMetadata = (metadata) => {
    try {
        return JSON.parse(metadata);
    }
    catch (_ignored) {
        return {};
    }
};
exports.parseMetadata = parseMetadata;
const getPartitionCount = (metadata) => {
    const metadataValue = metadata.partitions;
    if (metadataValue !== undefined) {
        try {
            (0, utils_1.ensureValidStreamPartitionCount)(metadataValue);
        }
        catch {
            throw new StreamrClientError_1.StreamrClientError(`Invalid partition count: ${metadataValue}`, 'INVALID_STREAM_METADATA');
        }
    }
    return metadataValue ?? utils_1.DEFAULT_PARTITION_COUNT;
};
exports.getPartitionCount = getPartitionCount;
//# sourceMappingURL=StreamMetadata.js.map