"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MeshClientRegistry = void 0;
const tslib_1 = require("tslib");
const _a = tslib_1.__importStar(require("@zyno-io/ts-server-foundation/type-metadata-runtime"));
const __tsf_metadata_type = _a.createCompactMetadataRegistryV1("[1,[{\"kind\":7},{\"kind\":3},{\"kind\":6},{\"kind\":8},{\"kind\":22,\"type\":{\"kind\":12,\"types\":[{\"kind\":18,\"types\":[{\"kind\":20,\"name\":\"status\",\"type\":{\"kind\":10,\"literal\":\"ok\"},\"optional\":false},{\"kind\":20,\"name\":\"supersededNodeId\",\"type\":{\"kind\":12,\"types\":[{\"kind\":7},{\"kind\":5}]},\"optional\":false},{\"kind\":20,\"name\":\"supersededConnectionId\",\"type\":{\"kind\":12,\"types\":[{\"kind\":6},{\"kind\":4}]},\"optional\":true}]},{\"kind\":18,\"types\":[{\"kind\":20,\"name\":\"status\",\"type\":{\"kind\":10,\"literal\":\"conflict\"},\"optional\":false},{\"kind\":20,\"name\":\"ownerNodeId\",\"type\":{\"kind\":12,\"types\":[{\"kind\":7},{\"kind\":5}]},\"optional\":false}]}],\"typeName\":\"RegisterResult\"}},{\"kind\":22,\"type\":{\"kind\":8}},{\"kind\":2},{\"kind\":22,\"type\":{\"kind\":3}},{\"kind\":12,\"types\":[{\"kind\":10,\"literal\":\"active\"},{\"kind\":10,\"literal\":\"pending\"}],\"typeName\":\"MeshClientRegistrationState\"},{\"kind\":22,\"type\":{\"kind\":12,\"types\":[{\"kind\":12,\"types\":[{\"kind\":8},{\"kind\":10,\"literal\":\"previous-changed\"}],\"typeName\":\"MeshClientClaimCommitResult\"},{\"kind\":4}]}},{\"kind\":22,\"type\":{\"kind\":12,\"types\":[{\"kind\":8},{\"kind\":4}]}},{\"kind\":18,\"typeName\":\"MeshClientRegistryBackend\",\"types\":[]}]]", []);
let _MeshClientRegistryMetadata_1;
class MeshClientRegistry {
    nodeId;
    backend;
    processId;
    constructor(nodeId, backend, processId) {
        this.nodeId = nodeId;
        this.backend = backend;
        this.processId = processId;
    }
    /** @internal Keeps the public registry facade stable across service start. */
    setNodeId(nodeId) {
        this.nodeId = nodeId;
    }
    async register(clientId, metadata, allowSupersede, connectionId) {
        return this.backend.register(clientId, this.nodeId, metadata, allowSupersede, connectionId, this.processId);
    }
    async reserve(clientId, metadata, allowSupersede, connectionId) {
        return this.backend.reserve(clientId, this.nodeId, metadata, allowSupersede, connectionId, this.processId);
    }
    async activate(clientId, metadata, connectionId) {
        return this.backend.activate(clientId, this.nodeId, metadata, connectionId);
    }
    async unregister(clientId, connectionId) {
        return this.backend.unregister(clientId, this.nodeId, connectionId);
    }
    async updateMetadata(clientId, metadata, connectionId) {
        return this.backend.updateMetadata(clientId, this.nodeId, metadata, connectionId);
    }
    async getClient(clientId) {
        return this.backend.getClient(clientId);
    }
    /** @internal Exact/raw lookup for claim commit response-loss reconciliation. */
    async getClientIncludingPending(clientId) {
        return this.backend.getClientIncludingPending?.(clientId);
    }
    async listClients() {
        return this.backend.listClients();
    }
    async listClientsForNode(nodeId) {
        return this.backend.listClientsForNode(nodeId ?? this.nodeId);
    }
    async listClientsPage(cursor = '0') {
        if (this.backend.listClientsPage)
            return this.backend.listClientsPage(cursor);
        return cursor === '0' ? { clients: await this.backend.listClients() } : { clients: [] };
    }
    async listClientsForNodePage(nodeId = this.nodeId, cursor = '0') {
        if (this.backend.listClientsForNodePage)
            return this.backend.listClientsForNodePage(nodeId, cursor);
        return cursor === '0' ? { clients: await this.backend.listClientsForNode(nodeId) } : { clients: [] };
    }
    async cleanupNode(nodeId) {
        return this.backend.cleanupNode(nodeId ?? this.nodeId);
    }
    async refreshNode() {
        await this.backend.refreshNode?.(this.nodeId);
    }
    async claim(clientId, metadata, state, allowSupersede, connectionId, operationId) {
        if (!this.backend.claim ||
            !this.backend.commitClaim ||
            !this.backend.abortClaim ||
            !this.backend.getClientIncludingPending ||
            !this.backend.removeClaimResult ||
            !this.backend.removeClaimPrevious) {
            return undefined;
        }
        return this.backend.claim(clientId, this.nodeId, metadata, state, allowSupersede, connectionId, this.processId, operationId);
    }
    async commitClaim(clientId, claimId) {
        return this.backend.commitClaim?.(clientId, this.nodeId, claimId);
    }
    async removeClaimPrevious(clientId, claimId) {
        return this.backend.removeClaimPrevious?.(clientId, this.nodeId, claimId);
    }
    async abortClaim(clientId, claimId) {
        return this.backend.abortClaim?.(clientId, this.nodeId, claimId);
    }
    async removeClaimResult(clientId, claimId) {
        return this.backend.removeClaimResult?.(clientId, this.nodeId, claimId);
    }
    static __tsfType = _MeshClientRegistryMetadata_1 = _a.decodeCompactMetadataV1("[1,{\"kind\":16,\"name\":\"MeshClientRegistry\",\"typeName\":\"MeshClientRegistry\",\"classType\":{\"$tsf\":0},\"properties\":[],\"methods\":[{\"name\":\"setNodeId\",\"parameters\":[{\"name\":\"nodeId\",\"type\":{\"$tsfType\":0},\"optional\":false,\"default\":false}],\"returnType\":{\"$tsfType\":1}},{\"name\":\"register\",\"parameters\":[{\"name\":\"clientId\",\"type\":{\"$tsfType\":2},\"optional\":false,\"default\":false},{\"name\":\"metadata\",\"type\":{\"kind\":16,\"typeName\":\"TMeta\",\"classType\":{\"$tsf\":1}},\"optional\":false,\"default\":false},{\"name\":\"allowSupersede\",\"type\":{\"$tsfType\":3},\"optional\":false,\"default\":false},{\"name\":\"connectionId\",\"type\":{\"$tsfType\":2},\"optional\":false,\"default\":false}],\"returnType\":{\"$tsfType\":4}},{\"name\":\"reserve\",\"parameters\":[{\"name\":\"clientId\",\"type\":{\"$tsfType\":2},\"optional\":false,\"default\":false},{\"name\":\"metadata\",\"type\":{\"kind\":16,\"typeName\":\"TMeta\",\"classType\":{\"$tsf\":1}},\"optional\":false,\"default\":false},{\"name\":\"allowSupersede\",\"type\":{\"$tsfType\":3},\"optional\":false,\"default\":false},{\"name\":\"connectionId\",\"type\":{\"$tsfType\":2},\"optional\":false,\"default\":false}],\"returnType\":{\"$tsfType\":4}},{\"name\":\"activate\",\"parameters\":[{\"name\":\"clientId\",\"type\":{\"$tsfType\":2},\"optional\":false,\"default\":false},{\"name\":\"metadata\",\"type\":{\"kind\":16,\"typeName\":\"TMeta\",\"classType\":{\"$tsf\":1}},\"optional\":false,\"default\":false},{\"name\":\"connectionId\",\"type\":{\"$tsfType\":2},\"optional\":false,\"default\":false}],\"returnType\":{\"$tsfType\":5}},{\"name\":\"unregister\",\"parameters\":[{\"name\":\"clientId\",\"type\":{\"$tsfType\":2},\"optional\":false,\"default\":false},{\"name\":\"connectionId\",\"type\":{\"$tsfType\":2},\"optional\":false,\"default\":false}],\"returnType\":{\"$tsfType\":5}},{\"name\":\"updateMetadata\",\"parameters\":[{\"name\":\"clientId\",\"type\":{\"$tsfType\":2},\"optional\":false,\"default\":false},{\"name\":\"metadata\",\"type\":{\"kind\":16,\"typeName\":\"TMeta\",\"classType\":{\"$tsf\":1}},\"optional\":false,\"default\":false},{\"name\":\"connectionId\",\"type\":{\"$tsfType\":2},\"optional\":false,\"default\":false}],\"returnType\":{\"$tsfType\":5}},{\"name\":\"getClient\",\"parameters\":[{\"name\":\"clientId\",\"type\":{\"$tsfType\":2},\"optional\":false,\"default\":false}],\"returnType\":{\"kind\":22,\"type\":{\"kind\":12,\"types\":[{\"kind\":18,\"typeName\":\"RegisteredClient\",\"types\":[{\"kind\":20,\"name\":\"clientId\",\"type\":{\"kind\":6},\"optional\":false},{\"kind\":20,\"name\":\"nodeId\",\"type\":{\"kind\":7},\"optional\":false},{\"kind\":20,\"name\":\"connectionId\",\"type\":{\"kind\":6},\"optional\":false},{\"kind\":20,\"name\":\"processId\",\"type\":{\"kind\":12,\"types\":[{\"kind\":6},{\"kind\":4}]},\"optional\":true},{\"kind\":20,\"name\":\"connectedAt\",\"type\":{\"kind\":7},\"optional\":false},{\"kind\":20,\"name\":\"metadata\",\"type\":{\"kind\":16,\"typeName\":\"TMeta\",\"classType\":{\"$tsf\":1}},\"optional\":false}]},{\"kind\":4}]}}},{\"name\":\"getClientIncludingPending\",\"parameters\":[{\"name\":\"clientId\",\"type\":{\"$tsfType\":2},\"optional\":false,\"default\":false}],\"returnType\":{\"kind\":22,\"type\":{\"kind\":12,\"types\":[{\"kind\":18,\"typeName\":\"MeshClientRecord\",\"types\":[{\"kind\":20,\"name\":\"clientId\",\"type\":{\"kind\":6},\"optional\":false},{\"kind\":20,\"name\":\"nodeId\",\"type\":{\"kind\":7},\"optional\":false},{\"kind\":20,\"name\":\"connectionId\",\"type\":{\"kind\":6},\"optional\":false},{\"kind\":20,\"name\":\"processId\",\"type\":{\"kind\":12,\"types\":[{\"kind\":6},{\"kind\":4}]},\"optional\":true},{\"kind\":20,\"name\":\"connectedAt\",\"type\":{\"kind\":7},\"optional\":false},{\"kind\":20,\"name\":\"metadata\",\"type\":{\"kind\":16,\"typeName\":\"TMeta\",\"classType\":{\"$tsf\":1}},\"optional\":false},{\"kind\":20,\"name\":\"state\",\"type\":{\"kind\":12,\"types\":[{\"kind\":10,\"literal\":\"active\"},{\"kind\":10,\"literal\":\"pending\"}],\"typeName\":\"MeshClientRegistrationState\"},\"optional\":false},{\"kind\":20,\"name\":\"claimId\",\"type\":{\"kind\":12,\"types\":[{\"kind\":6},{\"kind\":4}]},\"optional\":true}]},{\"kind\":4}]}}},{\"name\":\"listClients\",\"parameters\":[],\"returnType\":{\"kind\":22,\"type\":{\"kind\":14,\"type\":{\"kind\":18,\"typeName\":\"RegisteredClient\",\"types\":[{\"kind\":20,\"name\":\"clientId\",\"type\":{\"kind\":6},\"optional\":false},{\"kind\":20,\"name\":\"nodeId\",\"type\":{\"kind\":7},\"optional\":false},{\"kind\":20,\"name\":\"connectionId\",\"type\":{\"kind\":6},\"optional\":false},{\"kind\":20,\"name\":\"processId\",\"type\":{\"kind\":12,\"types\":[{\"kind\":6},{\"kind\":4}]},\"optional\":true},{\"kind\":20,\"name\":\"connectedAt\",\"type\":{\"kind\":7},\"optional\":false},{\"kind\":20,\"name\":\"metadata\",\"type\":{\"kind\":16,\"typeName\":\"TMeta\",\"classType\":{\"$tsf\":1}},\"optional\":false}]}}}},{\"name\":\"listClientsForNode\",\"parameters\":[{\"name\":\"nodeId\",\"type\":{\"$tsfType\":0},\"optional\":true,\"default\":false}],\"returnType\":{\"kind\":22,\"type\":{\"kind\":14,\"type\":{\"kind\":18,\"typeName\":\"RegisteredClient\",\"types\":[{\"kind\":20,\"name\":\"clientId\",\"type\":{\"kind\":6},\"optional\":false},{\"kind\":20,\"name\":\"nodeId\",\"type\":{\"kind\":7},\"optional\":false},{\"kind\":20,\"name\":\"connectionId\",\"type\":{\"kind\":6},\"optional\":false},{\"kind\":20,\"name\":\"processId\",\"type\":{\"kind\":12,\"types\":[{\"kind\":6},{\"kind\":4}]},\"optional\":true},{\"kind\":20,\"name\":\"connectedAt\",\"type\":{\"kind\":7},\"optional\":false},{\"kind\":20,\"name\":\"metadata\",\"type\":{\"kind\":16,\"typeName\":\"TMeta\",\"classType\":{\"$tsf\":1}},\"optional\":false}]}}}},{\"name\":\"listClientsPage\",\"parameters\":[{\"name\":\"cursor\",\"type\":{\"$tsfType\":6},\"optional\":true,\"default\":true}],\"returnType\":{\"kind\":22,\"type\":{\"kind\":18,\"typeName\":\"MeshClientListPage\",\"types\":[{\"kind\":20,\"name\":\"clients\",\"type\":{\"kind\":14,\"type\":{\"kind\":18,\"typeName\":\"RegisteredClient\",\"types\":[{\"kind\":20,\"name\":\"clientId\",\"type\":{\"kind\":6},\"optional\":false},{\"kind\":20,\"name\":\"nodeId\",\"type\":{\"kind\":7},\"optional\":false},{\"kind\":20,\"name\":\"connectionId\",\"type\":{\"kind\":6},\"optional\":false},{\"kind\":20,\"name\":\"processId\",\"type\":{\"kind\":12,\"types\":[{\"kind\":6},{\"kind\":4}]},\"optional\":true},{\"kind\":20,\"name\":\"connectedAt\",\"type\":{\"kind\":7},\"optional\":false},{\"kind\":20,\"name\":\"metadata\",\"type\":{\"kind\":16,\"typeName\":\"TMeta\",\"classType\":{\"$tsf\":1}},\"optional\":false}]}},\"optional\":false},{\"kind\":20,\"name\":\"cursor\",\"type\":{\"kind\":12,\"types\":[{\"kind\":6},{\"kind\":4}]},\"optional\":true}]}}},{\"name\":\"listClientsForNodePage\",\"parameters\":[{\"name\":\"nodeId\",\"type\":{\"$tsfType\":6},\"optional\":true,\"default\":true},{\"name\":\"cursor\",\"type\":{\"$tsfType\":6},\"optional\":true,\"default\":true}],\"returnType\":{\"kind\":22,\"type\":{\"kind\":18,\"typeName\":\"MeshClientListPage\",\"types\":[{\"kind\":20,\"name\":\"clients\",\"type\":{\"kind\":14,\"type\":{\"kind\":18,\"typeName\":\"RegisteredClient\",\"types\":[{\"kind\":20,\"name\":\"clientId\",\"type\":{\"kind\":6},\"optional\":false},{\"kind\":20,\"name\":\"nodeId\",\"type\":{\"kind\":7},\"optional\":false},{\"kind\":20,\"name\":\"connectionId\",\"type\":{\"kind\":6},\"optional\":false},{\"kind\":20,\"name\":\"processId\",\"type\":{\"kind\":12,\"types\":[{\"kind\":6},{\"kind\":4}]},\"optional\":true},{\"kind\":20,\"name\":\"connectedAt\",\"type\":{\"kind\":7},\"optional\":false},{\"kind\":20,\"name\":\"metadata\",\"type\":{\"kind\":16,\"typeName\":\"TMeta\",\"classType\":{\"$tsf\":1}},\"optional\":false}]}},\"optional\":false},{\"kind\":20,\"name\":\"cursor\",\"type\":{\"kind\":12,\"types\":[{\"kind\":6},{\"kind\":4}]},\"optional\":true}]}}},{\"name\":\"cleanupNode\",\"parameters\":[{\"name\":\"nodeId\",\"type\":{\"$tsfType\":0},\"optional\":true,\"default\":false}],\"returnType\":{\"kind\":22,\"type\":{\"kind\":14,\"type\":{\"kind\":18,\"typeName\":\"RegisteredClient\",\"types\":[{\"kind\":20,\"name\":\"clientId\",\"type\":{\"kind\":6},\"optional\":false},{\"kind\":20,\"name\":\"nodeId\",\"type\":{\"kind\":7},\"optional\":false},{\"kind\":20,\"name\":\"connectionId\",\"type\":{\"kind\":6},\"optional\":false},{\"kind\":20,\"name\":\"processId\",\"type\":{\"kind\":12,\"types\":[{\"kind\":6},{\"kind\":4}]},\"optional\":true},{\"kind\":20,\"name\":\"connectedAt\",\"type\":{\"kind\":7},\"optional\":false},{\"kind\":20,\"name\":\"metadata\",\"type\":{\"kind\":16,\"typeName\":\"TMeta\",\"classType\":{\"$tsf\":1}},\"optional\":false}]}}}},{\"name\":\"refreshNode\",\"parameters\":[],\"returnType\":{\"$tsfType\":7}},{\"name\":\"claim\",\"parameters\":[{\"name\":\"clientId\",\"type\":{\"$tsfType\":2},\"optional\":false,\"default\":false},{\"name\":\"metadata\",\"type\":{\"kind\":16,\"typeName\":\"TMeta\",\"classType\":{\"$tsf\":1}},\"optional\":false,\"default\":false},{\"name\":\"state\",\"type\":{\"$tsfType\":8},\"optional\":false,\"default\":false},{\"name\":\"allowSupersede\",\"type\":{\"$tsfType\":3},\"optional\":false,\"default\":false},{\"name\":\"connectionId\",\"type\":{\"$tsfType\":2},\"optional\":false,\"default\":false},{\"name\":\"operationId\",\"type\":{\"$tsfType\":2},\"optional\":true,\"default\":false}],\"returnType\":{\"kind\":22,\"type\":{\"kind\":12,\"types\":[{\"kind\":2,\"typeName\":\"MeshClientClaim\",\"typeArguments\":[{\"kind\":16,\"typeName\":\"TMeta\",\"classType\":{\"$tsf\":1}}]},{\"kind\":4}]}}},{\"name\":\"commitClaim\",\"parameters\":[{\"name\":\"clientId\",\"type\":{\"$tsfType\":2},\"optional\":false,\"default\":false},{\"name\":\"claimId\",\"type\":{\"$tsfType\":2},\"optional\":false,\"default\":false}],\"returnType\":{\"$tsfType\":9}},{\"name\":\"removeClaimPrevious\",\"parameters\":[{\"name\":\"clientId\",\"type\":{\"$tsfType\":2},\"optional\":false,\"default\":false},{\"name\":\"claimId\",\"type\":{\"$tsfType\":2},\"optional\":false,\"default\":false}],\"returnType\":{\"$tsfType\":10}},{\"name\":\"abortClaim\",\"parameters\":[{\"name\":\"clientId\",\"type\":{\"$tsfType\":2},\"optional\":false,\"default\":false},{\"name\":\"claimId\",\"type\":{\"$tsfType\":2},\"optional\":false,\"default\":false}],\"returnType\":{\"$tsfType\":10}},{\"name\":\"removeClaimResult\",\"parameters\":[{\"name\":\"clientId\",\"type\":{\"$tsfType\":2},\"optional\":false,\"default\":false},{\"name\":\"claimId\",\"type\":{\"$tsfType\":2},\"optional\":false,\"default\":false}],\"returnType\":{\"$tsfType\":10}}],\"hasConstructor\":true,\"constructorParameters\":[{\"name\":\"nodeId\",\"type\":{\"$tsfType\":0},\"optional\":false,\"default\":false},{\"name\":\"backend\",\"type\":{\"$tsfType\":11},\"optional\":false,\"default\":false},{\"name\":\"processId\",\"type\":{\"$tsfType\":2},\"optional\":true,\"default\":false}]}]", [() => MeshClientRegistry, () => (typeof TMeta !== "undefined" ? TMeta : (typeof exports !== "undefined" ? exports.TMeta : undefined))], __tsf_metadata_type);
}
exports.MeshClientRegistry = MeshClientRegistry;
_MeshClientRegistryMetadata_1.classType = MeshClientRegistry;
MeshClientRegistry.__tsfType = _MeshClientRegistryMetadata_1;
//# sourceMappingURL=mesh-client-registry.js.map