"use strict";
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getByRemoteById = exports.getByRemoteOnce = exports.hasInLocal = exports.getInLocal = exports.register = exports.removeRemoteGlobalThis = exports.addRemoteGlobalThis = exports.getId = exports.setId = void 0;
const data = new Map();
let pipeId;
let remoteGlobalThisSet = new Set();
const SYMBOL_NAME = `__MOMETA_PIPE__`;
function setId(id) {
    pipeId = id;
}
exports.setId = setId;
function getId() {
    return pipeId;
}
exports.getId = getId;
function addRemoteGlobalThis(g) {
    remoteGlobalThisSet.add(g);
}
exports.addRemoteGlobalThis = addRemoteGlobalThis;
function removeRemoteGlobalThis(g) {
    remoteGlobalThisSet.delete(g);
}
exports.removeRemoteGlobalThis = removeRemoteGlobalThis;
function register(name, value) {
    data.set(name, value);
    return () => {
        data.delete(name);
    };
}
exports.register = register;
function getInLocal(name) {
    return data.get(name);
}
exports.getInLocal = getInLocal;
function hasInLocal(name) {
    return data.has(name);
}
exports.hasInLocal = hasInLocal;
function getByRemoteOnce(name) {
    for (const g of remoteGlobalThisSet.values()) {
        if (g[SYMBOL_NAME] && g[SYMBOL_NAME].hasInLocal(name)) {
            return g[SYMBOL_NAME].getInLocal(name);
        }
    }
}
exports.getByRemoteOnce = getByRemoteOnce;
function getByRemoteById(name, id) {
    for (const g of remoteGlobalThisSet.values()) {
        if (g[SYMBOL_NAME] && g[SYMBOL_NAME].getId() === id) {
            return g[SYMBOL_NAME].getInLocal(name);
        }
    }
}
exports.getByRemoteById = getByRemoteById;
const exps = {
    getId,
    getByRemoteById,
    getInLocal,
    getByRemoteOnce,
    setId,
    addRemoteGlobalThis,
    register,
    hasInLocal,
    remoteGlobalThisSet,
    removeRemoteGlobalThis,
    data
};
// 防止重入，如 empty-placeholder 再次加载
globalThis[SYMBOL_NAME] = (_a = globalThis[SYMBOL_NAME]) !== null && _a !== void 0 ? _a : exps;
//# sourceMappingURL=pipe.js.map