"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DebugComplete = exports.__ShardFunctions = exports.VectorBufferStream = exports.VersionValidationResult = exports.isWithinMaximumVersion = exports.meetsMinimumVersion = exports.DevSecurityLevel = exports.nestedCountersInstance = exports.ShardusTypes = exports.Shardus = void 0;
exports.shardusFactory = shardusFactory;
const deepmerge_1 = __importDefault(require("deepmerge"));
const shardus_1 = __importDefault(require("./shardus"));
const ShardusTypes = __importStar(require("./shardus/shardus-types"));
exports.ShardusTypes = ShardusTypes;
const utils_1 = require("./utils");
var shardus_2 = require("./shardus");
Object.defineProperty(exports, "Shardus", { enumerable: true, get: function () { return __importDefault(shardus_2).default; } });
var nestedCounters_1 = require("./utils/nestedCounters");
Object.defineProperty(exports, "nestedCountersInstance", { enumerable: true, get: function () { return nestedCounters_1.nestedCountersInstance; } });
var shardus_types_1 = require("./shardus/shardus-types");
Object.defineProperty(exports, "DevSecurityLevel", { enumerable: true, get: function () { return shardus_types_1.DevSecurityLevel; } });
// Export version-related functionality
var version_1 = require("./utils/functions/version");
Object.defineProperty(exports, "meetsMinimumVersion", { enumerable: true, get: function () { return version_1.meetsMinimumVersion; } });
Object.defineProperty(exports, "isWithinMaximumVersion", { enumerable: true, get: function () { return version_1.isWithinMaximumVersion; } });
Object.defineProperty(exports, "VersionValidationResult", { enumerable: true, get: function () { return version_1.VersionValidationResult; } });
var VectorBufferStream_1 = require("./utils/serialization/VectorBufferStream");
Object.defineProperty(exports, "VectorBufferStream", { enumerable: true, get: function () { return VectorBufferStream_1.VectorBufferStream; } });
//export { JoinRequest } from './shardus/shardus-types'
// Temporary private export to avoid digging into shardus source code for
// functions it otherwise wasn't exporting. ATTOW we have not decided on whether
// a more permanent solution is proper.
const shardFunctions_1 = require("./state-manager/shardFunctions");
const config_1 = __importDefault(require("./config"));
exports.__ShardFunctions = {
    addressToPartition: shardFunctions_1.addressToPartition,
    partitionInWrappingRange: shardFunctions_1.partitionInWrappingRange,
    findHomeNode: shardFunctions_1.findHomeNode,
};
var TransactionQueue_1 = require("./state-manager/TransactionQueue");
Object.defineProperty(exports, "DebugComplete", { enumerable: true, get: function () { return TransactionQueue_1.DebugComplete; } });
const defaultConfigs = config_1.default;
const overwriteMerge = (target, source, options) => source;
function shardusFactory(configs = {}) {
    const mergedConfigs = (0, deepmerge_1.default)(defaultConfigs, configs, {
        arrayMerge: overwriteMerge,
    });
    const { isValid, error } = (0, utils_1.compareObjectShape)(defaultConfigs, mergedConfigs);
    if (error) {
        const fRed = '\x1b[31m'; //fg red
        const bYellow = '\x1b[43m'; //bg yellow
        const defectiveObjectPath = error.defectiveChain.join('.');
        const defectiveObjectPathColored = `${fRed}${bYellow}${defectiveObjectPath}\x1b[0m`;
        const msg = `Unacceptable config object shape, defective settings detected: ${defectiveObjectPath}`;
        console.log('\x1b[1m', //bold, bright
        '\x1b[31m', //fg red
        'INVALID CONFIG OBJECT PROPERTY OR TYPE MISMATCH OCCURS:', `${defectiveObjectPathColored}`);
        console.log('\x1b[36m', //cyan
        'For more information on configuration object, check the documentation', '\x1b[0m' //color reset
        );
        throw new Error(msg);
    }
    return new shardus_1.default(mergedConfigs);
}
//# sourceMappingURL=index.js.map