"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.__tsfTypeAliases = exports.SrpcError = void 0;
exports.isSrpcMessageHandlerClass = isSrpcMessageHandlerClass;
exports.encodeSrpcMessage = encodeSrpcMessage;
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\":6},{\"kind\":8}]]", []);
let _SrpcErrorMetadata_1;
class SrpcError extends Error {
    isUserError;
    constructor(message, isUserError) {
        super(message);
        this.isUserError = isUserError;
        this.name = 'SrpcError';
    }
    static __tsfType = _SrpcErrorMetadata_1 = _a.decodeCompactMetadataV1("[1,{\"kind\":16,\"name\":\"SrpcError\",\"typeName\":\"SrpcError\",\"classType\":{\"$tsf\":0},\"properties\":[],\"methods\":[],\"hasConstructor\":true,\"constructorParameters\":[{\"name\":\"message\",\"type\":{\"$tsfType\":0},\"optional\":false,\"default\":false},{\"name\":\"isUserError\",\"type\":{\"$tsfType\":1},\"optional\":true,\"default\":false}]}]", [() => SrpcError], __tsf_metadata_type);
}
exports.SrpcError = SrpcError;
_SrpcErrorMetadata_1.classType = SrpcError;
SrpcError.__tsfType = _SrpcErrorMetadata_1;
function isSrpcMessageHandlerClass(handler) {
    return typeof handler === 'function' && typeof handler.prototype?.handle === 'function';
}
function encodeSrpcMessage(codec, message) {
    const encoded = codec.encode(message);
    const bytes = 'finish' in encoded ? encoded.finish() : encoded;
    return Buffer.isBuffer(bytes) ? bytes : Buffer.from(bytes);
}
exports.__tsfTypeAliases = _a.decodeCompactMetadataV1("[1,{\"BaseMessage\":{\"kind\":18,\"typeName\":\"BaseMessage\",\"types\":[{\"kind\":20,\"name\":\"requestId\",\"type\":{\"kind\":12,\"types\":[{\"kind\":6},{\"kind\":4}]},\"optional\":true},{\"kind\":20,\"name\":\"reply\",\"type\":{\"kind\":12,\"types\":[{\"kind\":8},{\"kind\":4}]},\"optional\":true},{\"kind\":20,\"name\":\"error\",\"type\":{\"kind\":12,\"types\":[{\"kind\":6},{\"kind\":4}]},\"optional\":true},{\"kind\":20,\"name\":\"userError\",\"type\":{\"kind\":12,\"types\":[{\"kind\":8},{\"kind\":4}]},\"optional\":true},{\"kind\":20,\"name\":\"trace\",\"type\":{\"kind\":12,\"types\":[{\"kind\":18,\"types\":[{\"kind\":20,\"name\":\"traceId\",\"type\":{\"kind\":6},\"optional\":false},{\"kind\":20,\"name\":\"spanId\",\"type\":{\"kind\":6},\"optional\":false},{\"kind\":20,\"name\":\"traceFlags\",\"type\":{\"kind\":7},\"optional\":false}]},{\"kind\":4}]},\"optional\":true},{\"kind\":20,\"name\":\"pingPong\",\"type\":{\"kind\":12,\"types\":[{\"kind\":18,\"types\":[]},{\"kind\":4}]},\"optional\":true},{\"kind\":20,\"name\":\"byteStreamOperation\",\"type\":{\"kind\":12,\"types\":[{\"kind\":18,\"types\":[{\"kind\":20,\"name\":\"streamId\",\"type\":{\"kind\":7},\"optional\":false},{\"kind\":20,\"name\":\"write\",\"type\":{\"kind\":12,\"types\":[{\"kind\":18,\"types\":[{\"kind\":20,\"name\":\"chunk\",\"type\":{\"kind\":16,\"typeName\":\"Uint8Array\",\"classType\":{\"$tsf\":0}},\"optional\":false}]},{\"kind\":4}]},\"optional\":true},{\"kind\":20,\"name\":\"finish\",\"type\":{\"kind\":12,\"types\":[{\"kind\":18,\"types\":[]},{\"kind\":4}]},\"optional\":true},{\"kind\":20,\"name\":\"destroy\",\"type\":{\"kind\":12,\"types\":[{\"kind\":18,\"types\":[{\"kind\":20,\"name\":\"error\",\"type\":{\"kind\":12,\"types\":[{\"kind\":6},{\"kind\":4}]},\"optional\":true}]},{\"kind\":4}]},\"optional\":true}]},{\"kind\":4}]},\"optional\":true}]},\"IQueuedRequest\":{\"kind\":18,\"typeName\":\"IQueuedRequest\",\"types\":[{\"kind\":20,\"name\":\"exp\",\"type\":{\"kind\":7},\"optional\":false},{\"kind\":20,\"name\":\"resolve\",\"type\":{\"kind\":2,\"typeName\":\"(value: unknown) =\\u003e void\"},\"optional\":false},{\"kind\":20,\"name\":\"reject\",\"type\":{\"kind\":2,\"typeName\":\"(err: unknown) =\\u003e void\"},\"optional\":false}]},\"ISrpcLogger\":{\"kind\":18,\"typeName\":\"ISrpcLogger\",\"types\":[]},\"ISrpcMessageHandler\":{\"kind\":18,\"typeName\":\"ISrpcMessageHandler\",\"types\":[{\"kind\":20,\"name\":\"handle\",\"type\":{\"kind\":2,\"typeName\":\"SrpcMessageHandlerFn\",\"typeArguments\":[{\"kind\":2,\"typeName\":\"C\"},{\"kind\":2,\"typeName\":\"I\"},{\"kind\":2,\"typeName\":\"O\"}]},\"optional\":false}]},\"ISrpcServerOptions\":{\"kind\":18,\"typeName\":\"ISrpcServerOptions\",\"types\":[{\"kind\":20,\"name\":\"logger\",\"type\":{\"kind\":18,\"typeName\":\"ISrpcLogger\",\"types\":[]},\"optional\":false},{\"kind\":20,\"name\":\"clientMessage\",\"type\":{\"kind\":16,\"typeName\":\"SrpcMessageFns\",\"classType\":{\"$tsf\":1},\"typeArguments\":[{\"kind\":16,\"typeName\":\"TClientOutput\",\"classType\":{\"$tsf\":2}}]},\"optional\":false},{\"kind\":20,\"name\":\"serverMessage\",\"type\":{\"kind\":16,\"typeName\":\"SrpcMessageFns\",\"classType\":{\"$tsf\":1},\"typeArguments\":[{\"kind\":16,\"typeName\":\"TServerOutput\",\"classType\":{\"$tsf\":3}}]},\"optional\":false},{\"kind\":20,\"name\":\"wsPath\",\"type\":{\"kind\":6},\"optional\":false},{\"kind\":20,\"name\":\"debug\",\"type\":{\"kind\":12,\"types\":[{\"kind\":8},{\"kind\":4}]},\"optional\":true},{\"kind\":20,\"name\":\"logLevel\",\"type\":{\"kind\":12,\"types\":[{\"kind\":12,\"types\":[{\"kind\":10,\"literal\":\"info\"},{\"kind\":10,\"literal\":\"debug\"},{\"kind\":10,\"literal\":false}]},{\"kind\":4}]},\"optional\":true},{\"kind\":20,\"name\":\"httpServer\",\"type\":{\"kind\":12,\"types\":[{\"kind\":16,\"typeName\":\"Server\",\"classType\":{\"$tsfImport\":[4,\"node:http\",\"Server\"]}},{\"kind\":4}]},\"optional\":true}]},\"SrpcDisconnectCause\":{\"kind\":12,\"types\":[{\"kind\":10,\"literal\":\"disconnect\"},{\"kind\":10,\"literal\":\"conflict\"},{\"kind\":10,\"literal\":\"supersede\"},{\"kind\":10,\"literal\":\"timeout\"},{\"kind\":10,\"literal\":\"badArg\"}],\"typeName\":\"SrpcDisconnectCause\"},\"SrpcMessageFns\":{\"kind\":18,\"typeName\":\"SrpcMessageFns\",\"types\":[]},\"SrpcMeta\":{\"kind\":17,\"typeName\":\"SrpcMeta\"},\"SrpcStream\":{\"kind\":18,\"typeName\":\"SrpcStream\",\"types\":[{\"kind\":20,\"name\":\"byteStream\",\"type\":{\"kind\":18,\"typeName\":\"IByteStream\",\"types\":[{\"kind\":20,\"name\":\"parentStreamId\",\"type\":{\"kind\":6},\"optional\":false}]},\"optional\":false},{\"kind\":20,\"name\":\"$ws\",\"type\":{\"kind\":16,\"typeName\":\"WebSocket\",\"classType\":{\"$tsf\":5}},\"optional\":false},{\"kind\":20,\"name\":\"$queue\",\"type\":{\"kind\":16,\"typeName\":\"Map\",\"classType\":{\"$tsf\":6},\"typeArguments\":[{\"kind\":6},{\"kind\":18,\"typeName\":\"IQueuedRequest\",\"types\":[{\"kind\":20,\"name\":\"exp\",\"type\":{\"kind\":7},\"optional\":false},{\"kind\":20,\"name\":\"resolve\",\"type\":{\"kind\":2,\"typeName\":\"(value: unknown) =\\u003e void\"},\"optional\":false},{\"kind\":20,\"name\":\"reject\",\"type\":{\"kind\":2,\"typeName\":\"(err: unknown) =\\u003e void\"},\"optional\":false}]}]},\"optional\":false},{\"kind\":20,\"name\":\"id\",\"type\":{\"kind\":6},\"optional\":false},{\"kind\":20,\"name\":\"clientStreamId\",\"type\":{\"kind\":6},\"optional\":false},{\"kind\":20,\"name\":\"address\",\"type\":{\"kind\":6},\"optional\":false},{\"kind\":20,\"name\":\"clientId\",\"type\":{\"kind\":6},\"optional\":false},{\"kind\":20,\"name\":\"appVersion\",\"type\":{\"kind\":6},\"optional\":false},{\"kind\":20,\"name\":\"configureTs\",\"type\":{\"kind\":7},\"optional\":false},{\"kind\":20,\"name\":\"protocolVersion\",\"type\":{\"kind\":7},\"optional\":false},{\"kind\":20,\"name\":\"supersede\",\"type\":{\"kind\":8},\"optional\":false},{\"kind\":20,\"name\":\"meta\",\"type\":{\"kind\":2,\"typeName\":\"T\"},\"optional\":false},{\"kind\":20,\"name\":\"connectedAt\",\"type\":{\"kind\":7},\"optional\":false},{\"kind\":20,\"name\":\"isActivated\",\"type\":{\"kind\":8},\"optional\":false},{\"kind\":20,\"name\":\"lastPingAt\",\"type\":{\"kind\":7},\"optional\":false}]}}]", [() => (typeof Uint8Array !== "undefined" ? Uint8Array : (typeof exports !== "undefined" ? exports.Uint8Array : undefined)), () => (typeof SrpcMessageFns !== "undefined" ? SrpcMessageFns : (typeof exports !== "undefined" ? exports.SrpcMessageFns : undefined)), () => (typeof TClientOutput !== "undefined" ? TClientOutput : (typeof exports !== "undefined" ? exports.TClientOutput : undefined)), () => (typeof TServerOutput !== "undefined" ? TServerOutput : (typeof exports !== "undefined" ? exports.TServerOutput : undefined)), require, () => (typeof WebSocket !== "undefined" ? WebSocket : (typeof exports !== "undefined" ? exports.WebSocket : undefined)), () => (typeof Map !== "undefined" ? Map : (typeof exports !== "undefined" ? exports.Map : undefined))], __tsf_metadata_type);
//# sourceMappingURL=types.js.map