built lib
This commit is contained in:
parent
1e0f3a74a3
commit
cdb7637c6c
|
|
@ -0,0 +1,2 @@
|
|||
export declare function undef<A>(): A | undefined;
|
||||
export declare function memoize<A>(fn: () => A): () => A;
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.memoize = exports.undef = void 0;
|
||||
function undef() {
|
||||
return undefined;
|
||||
}
|
||||
exports.undef = undef;
|
||||
function memoize(fn) {
|
||||
let memo;
|
||||
return () => {
|
||||
if (memo === undefined) {
|
||||
memo = fn();
|
||||
}
|
||||
return memo;
|
||||
};
|
||||
}
|
||||
exports.memoize = memoize;
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
import { ContentType, Message, MessageFromClient, CreateMailboxResponse, KeyValPair, MessageEnvelope, SendReceipt } from "./proto/wsmessages";
|
||||
export interface ContentTypeHandler {
|
||||
readonly webSocketUrlPath: string;
|
||||
sendMessageFromClient(mfc: MessageFromClient, ws: WebSocket): void;
|
||||
}
|
||||
export declare const ContentTypeHandler: {
|
||||
Json: ContentTypeHandler;
|
||||
Protobuf: ContentTypeHandler;
|
||||
};
|
||||
export declare function newHermesClient(rootUrl: string, contentTypeHandler: ContentTypeHandler): HermesClient;
|
||||
export interface ChangeDataCaptureEvent {
|
||||
id: string;
|
||||
schema: string;
|
||||
table: string;
|
||||
action: string;
|
||||
data: any;
|
||||
commitTime: string;
|
||||
}
|
||||
interface RawRpcRequest {
|
||||
to: string;
|
||||
endPoint: string;
|
||||
body?: Uint8Array;
|
||||
contentType?: ContentType;
|
||||
headers?: KeyValPair[];
|
||||
state?: Uint8Array;
|
||||
}
|
||||
export declare class RpcRequestResponse {
|
||||
correlationId: string;
|
||||
sendReceiptEnvelope: MessageEnvelope | undefined;
|
||||
sendReceipt: SendReceipt | undefined;
|
||||
sentMessage: Message | undefined;
|
||||
inboxEnvelope: MessageEnvelope | undefined;
|
||||
inboxMessage: Message | undefined;
|
||||
constructor(correlationId: string);
|
||||
role(): string | undefined;
|
||||
contentType(): ContentType;
|
||||
isProtobuf(): boolean;
|
||||
isJson(): boolean;
|
||||
isClient(): boolean | undefined;
|
||||
hasRequestAndResponse(): boolean;
|
||||
timeStarted(): Date | undefined;
|
||||
timeStartedL(): number | undefined;
|
||||
timeCompleted(): Date | undefined;
|
||||
durationInMillis(): number | undefined;
|
||||
endPoint(): string | undefined;
|
||||
requestMessage(): Message | undefined;
|
||||
requestEnvelope(): MessageEnvelope | undefined;
|
||||
responseMessage(): Message | undefined;
|
||||
responseEnvelope(): MessageEnvelope | undefined;
|
||||
status(): string;
|
||||
processSchema(reqOrResp: "request" | "response", data?: Uint8Array): Promise<any>;
|
||||
responseObj(): Promise<any>;
|
||||
requestObj(): Promise<any>;
|
||||
}
|
||||
declare const GlobalClient: {
|
||||
get: () => HermesClient;
|
||||
};
|
||||
export default GlobalClient;
|
||||
export declare function runHermesClientTest(): void;
|
||||
export declare function runHermesClientTest2(): void;
|
||||
export interface CdcSubscription {
|
||||
tables: CdcTable[];
|
||||
startSeq?: string;
|
||||
}
|
||||
export interface CdcTable {
|
||||
database: string;
|
||||
table: string;
|
||||
}
|
||||
export interface HermesClient {
|
||||
readonly rootUrl: string;
|
||||
mailbox(): Promise<CreateMailboxResponse>;
|
||||
rawRpcCall(request: RawRpcRequest): Promise<Message>;
|
||||
cdcSubscribe<A>(cdcs: CdcSubscription, listener: (cdcEvent: ChangeDataCaptureEvent, a: A) => void): void;
|
||||
rpcObserverSubscribe(readerKey: string, listener: (correlation: RpcRequestResponse) => void): void;
|
||||
}
|
||||
|
|
@ -0,0 +1,689 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.runHermesClientTest2 = exports.runHermesClientTest = exports.RpcRequestResponse = exports.newHermesClient = exports.ContentTypeHandler = void 0;
|
||||
const wsmessages_1 = require("./proto/wsmessages");
|
||||
const Utils_1 = require("../Utils");
|
||||
const JsonContentTypeHandler = {
|
||||
webSocketUrlPath: "/api/ws/send_receive_json",
|
||||
sendMessageFromClient(mfc, ws) {
|
||||
const obj = wsmessages_1.MessageFromClient.toJSON(mfc);
|
||||
const jsonStr = JSON.stringify(obj);
|
||||
ws.send(jsonStr);
|
||||
}
|
||||
};
|
||||
const ProtobufContentTypeHandler = {
|
||||
webSocketUrlPath: "/api/ws/send_receive_proto",
|
||||
sendMessageFromClient(mfc, ws) {
|
||||
const bytes = wsmessages_1.MessageFromClient.encode(mfc).finish();
|
||||
ws.send(bytes);
|
||||
}
|
||||
};
|
||||
exports.ContentTypeHandler = {
|
||||
Json: JsonContentTypeHandler,
|
||||
Protobuf: ProtobufContentTypeHandler,
|
||||
};
|
||||
function newHermesClient(rootUrl, contentTypeHandler) {
|
||||
const hci = new HermesClientImpl(rootUrl, contentTypeHandler);
|
||||
hci.mailbox().then((mbox) => {
|
||||
const correlations = hci.correlations;
|
||||
hci.channelMessageSubscribe({
|
||||
id: "rpc-inbox",
|
||||
state: "rpc-inbox",
|
||||
readerKey: mbox.readerKey,
|
||||
channel: "rpc-inbox",
|
||||
startSeq: "all"
|
||||
}, (me, msg) => {
|
||||
var _a, _b, _c, _d, _e, _f;
|
||||
if (me.messageBytes) {
|
||||
try {
|
||||
const msg = wsmessages_1.Message.decode(me.messageBytes);
|
||||
const endPoint = (_b = (_a = msg.header) === null || _a === void 0 ? void 0 : _a.rpcHeader) === null || _b === void 0 ? void 0 : _b.endPoint;
|
||||
if (((_d = (_c = msg.header) === null || _c === void 0 ? void 0 : _c.rpcHeader) === null || _d === void 0 ? void 0 : _d.frameType) === wsmessages_1.RpcFrameType.Request && endPoint == "ping") {
|
||||
hci.sendPongResponse(mbox, msg, endPoint);
|
||||
}
|
||||
else {
|
||||
const correlationId = (_f = (_e = msg.header) === null || _e === void 0 ? void 0 : _e.rpcHeader) === null || _f === void 0 ? void 0 : _f.correlationId;
|
||||
if (correlationId) {
|
||||
const resolve = correlations.get(correlationId);
|
||||
if (resolve !== undefined) {
|
||||
resolve(msg);
|
||||
}
|
||||
correlations.delete(correlationId);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
console.error("error decoding message", e);
|
||||
}
|
||||
}
|
||||
// noop since we are only interested in the correlationId for rpc and that happens in onMessage
|
||||
});
|
||||
});
|
||||
// send ping every 30 seconds
|
||||
setInterval(() => hci.sendPing(), 30 * 1000);
|
||||
return hci;
|
||||
}
|
||||
exports.newHermesClient = newHermesClient;
|
||||
/**
|
||||
* Create the mailbox
|
||||
* @param channels
|
||||
* @param rootUrl
|
||||
* @returns
|
||||
*/
|
||||
async function createMailbox(channels, rootUrl) {
|
||||
const mbox = {
|
||||
channels: channels,
|
||||
privateMetadata: {},
|
||||
publicMetadata: {},
|
||||
purgeTimeoutInMillis: 0,
|
||||
closeTimeoutInMillis: 0,
|
||||
extraData: {},
|
||||
};
|
||||
const mboxObj = wsmessages_1.CreateMailboxRequest.toJSON(mbox);
|
||||
const mboxJson = JSON.stringify(mboxObj);
|
||||
let mailboxResponse = undefined;
|
||||
const response = await fetch(`${rootUrl}/api/create_mailbox`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: mboxJson,
|
||||
});
|
||||
if (response.ok) {
|
||||
const responseJsonStr = await response.text();
|
||||
mailboxResponse = wsmessages_1.CreateMailboxResponse.fromJSON(JSON.parse(responseJsonStr));
|
||||
}
|
||||
else {
|
||||
throw new Error(`createMailbox failed with status ${response.status}`);
|
||||
}
|
||||
return mailboxResponse;
|
||||
}
|
||||
class Constants {
|
||||
}
|
||||
Constants.rpcInboxChannelName = "rpc-inbox";
|
||||
Constants.rpcSentChannelName = "rpc-sent";
|
||||
class HermesConnection {
|
||||
constructor(clientImpl, mailbox, webSocket) {
|
||||
this.clientImpl = clientImpl;
|
||||
this.mailbox = mailbox;
|
||||
this.webSocket = webSocket;
|
||||
const self = this;
|
||||
webSocket.onmessage = function (event) {
|
||||
if (event.data instanceof ArrayBuffer) {
|
||||
self.onWebSocketBinaryMessage(event.data);
|
||||
}
|
||||
else {
|
||||
self.onWebSocketTextMessage(event.data);
|
||||
}
|
||||
};
|
||||
webSocket.onclose = function (event) {
|
||||
console.log("HermesConnection websocket closed", event);
|
||||
clientImpl.reconnect();
|
||||
};
|
||||
// resend un ack'ed messages
|
||||
clientImpl.sentMessagesWaitingForAck.forEach((smr, idempotentId) => {
|
||||
self.sendSendMessageRequest(smr, false);
|
||||
});
|
||||
}
|
||||
onWebSocketTextMessage(message) {
|
||||
const jsonObj = JSON.parse(message);
|
||||
const m2c = wsmessages_1.MessageToClient.fromJSON(jsonObj);
|
||||
this.onMessageToClient(m2c);
|
||||
}
|
||||
onWebSocketBinaryMessage(message) {
|
||||
const m2c = wsmessages_1.MessageToClient.decode(new Uint8Array(message));
|
||||
this.onMessageToClient(m2c);
|
||||
}
|
||||
onMessageToClient(m2c) {
|
||||
var _a, _b, _c;
|
||||
if (m2c.notification !== undefined) {
|
||||
console.log("hermes client received notification " + m2c.notification, m2c.notification);
|
||||
}
|
||||
else if (m2c.messageEnvelope !== undefined) {
|
||||
const me = m2c.messageEnvelope;
|
||||
if (me.messageBytes === undefined) {
|
||||
console.log("hermes client received empty messageEnvelope", m2c.messageEnvelope);
|
||||
}
|
||||
else {
|
||||
const subscriptionId = (_a = me.serverEnvelope) === null || _a === void 0 ? void 0 : _a.subscriptionId;
|
||||
if (subscriptionId) {
|
||||
const activeSub = this.clientImpl.activeSubscriptions.get(subscriptionId);
|
||||
if (activeSub) {
|
||||
const startSeq = (_b = me.serverEnvelope) === null || _b === void 0 ? void 0 : _b.sequence;
|
||||
if (startSeq) {
|
||||
activeSub.protoRawSubscription.startSeq = String(startSeq);
|
||||
}
|
||||
activeSub.onMessageEvent(me);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (m2c.sendMessageResponse !== undefined) {
|
||||
const id = (_c = m2c.sendMessageResponse) === null || _c === void 0 ? void 0 : _c.idempotentId;
|
||||
if (id) {
|
||||
this.clientImpl.sentMessagesWaitingForAck.delete(id);
|
||||
}
|
||||
console.log("hermes client received SendMessageResponse", m2c.sendMessageResponse);
|
||||
}
|
||||
else if (m2c.subscribeResponse !== undefined) {
|
||||
console.log("hermes client received subscribeResponse", m2c.subscribeResponse);
|
||||
}
|
||||
else if (m2c.ping !== undefined) {
|
||||
this.webSocket.send(JSON.stringify({ pong: {} }));
|
||||
}
|
||||
else if (m2c.pong !== undefined) {
|
||||
console.log("hermes client received pong");
|
||||
}
|
||||
}
|
||||
sendMessageFromClient(mfc) {
|
||||
console.log("sending websocket message", mfc);
|
||||
this.clientImpl.contentTypeHandler.sendMessageFromClient(mfc, this.webSocket);
|
||||
}
|
||||
addActiveSubscription(activeSub) {
|
||||
const listeners = this.clientImpl.activeSubscriptions.get(activeSub.subscriptionId);
|
||||
if (listeners) {
|
||||
throw Error(`subscriptionId ${activeSub.subscriptionId} is already subscribed`);
|
||||
}
|
||||
else {
|
||||
this.clientImpl.activeSubscriptions.set(activeSub.subscriptionId, activeSub);
|
||||
}
|
||||
}
|
||||
cdcSubscribe(cdcs, listener) {
|
||||
const subscriptionId = "cdc-" + cdcs.tables.map((t) => t.database + "." + t.table).join("-");
|
||||
const protoCdcs = {
|
||||
id: subscriptionId,
|
||||
matchers: cdcs.tables,
|
||||
startSeq: cdcs.startSeq,
|
||||
};
|
||||
this.sendMessageFromClient({ subscribeRequest: { subscriptions: [{ changeDataCapture: protoCdcs }] } });
|
||||
function onMessage(msg) {
|
||||
const json = new TextDecoder().decode(msg.messageBytes);
|
||||
const cdcEvent = JSON.parse(json);
|
||||
listener(cdcEvent, cdcEvent.data);
|
||||
}
|
||||
this.addActiveSubscription({
|
||||
subscriptionId: subscriptionId,
|
||||
protoRawSubscription: protoCdcs,
|
||||
onMessageEvent: onMessage,
|
||||
protoSubscription: { changeDataCapture: protoCdcs }
|
||||
});
|
||||
}
|
||||
channelMessageSubscribe(ms, listener) {
|
||||
this.rawChannelSubscribe(ms, wsmessages_1.Message.decode, listener);
|
||||
}
|
||||
channelSendReceiptSubscribe(ms, listener) {
|
||||
this.rawChannelSubscribe(ms, wsmessages_1.SendReceipt.decode, listener);
|
||||
}
|
||||
rawChannelSubscribe(ms, decoder, listener) {
|
||||
const subscriptionId = ms.id;
|
||||
if (!subscriptionId) {
|
||||
throw new Error("MailboxSubscription id is undefined");
|
||||
}
|
||||
function onMessage(msg) {
|
||||
if (msg.messageBytes === undefined) {
|
||||
console.error("MessageEnvelope.messageBytes is undefined");
|
||||
return;
|
||||
}
|
||||
const a = decoder(msg.messageBytes);
|
||||
listener(msg, a);
|
||||
}
|
||||
this.sendMessageFromClient({ subscribeRequest: { subscriptions: [{ mailbox: ms }] } });
|
||||
this.addActiveSubscription({
|
||||
subscriptionId: subscriptionId,
|
||||
onMessageEvent: onMessage,
|
||||
protoRawSubscription: ms,
|
||||
protoSubscription: { mailbox: ms }
|
||||
});
|
||||
}
|
||||
sendPing() {
|
||||
this.sendMessageFromClient({ ping: {} });
|
||||
}
|
||||
sendSendMessageRequest(smr, registerForAck) {
|
||||
if (registerForAck && smr.idempotentId) {
|
||||
this.clientImpl.sentMessagesWaitingForAck.set(smr.idempotentId, smr);
|
||||
}
|
||||
this.sendMessageFromClient({ sendMessageRequest: smr });
|
||||
}
|
||||
rawRpcCall(request) {
|
||||
var _a;
|
||||
const emptyBytes = new Uint8Array(0);
|
||||
const correlationId = ((_a = this.mailbox.address) !== null && _a !== void 0 ? _a : "") + "-" + this.clientImpl.correlationIdCounter++;
|
||||
const idempotentId = this.mailbox.address + correlationId;
|
||||
const smr = {
|
||||
channel: Constants.rpcInboxChannelName,
|
||||
to: [request.to],
|
||||
idempotentId: idempotentId,
|
||||
message: {
|
||||
header: {
|
||||
rpcHeader: {
|
||||
correlationId: correlationId,
|
||||
endPoint: request.endPoint,
|
||||
frameType: wsmessages_1.RpcFrameType.Request,
|
||||
errorInfo: undefined,
|
||||
},
|
||||
sender: this.mailbox.address,
|
||||
contentType: request.contentType,
|
||||
extraHeaders: request.headers,
|
||||
senderSequence: 0,
|
||||
},
|
||||
serverEnvelope: undefined,
|
||||
senderEnvelope: {
|
||||
created: Date.now(),
|
||||
},
|
||||
data: request.body !== undefined ? request.body : emptyBytes,
|
||||
},
|
||||
};
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
this.clientImpl.correlations.set(correlationId, resolve);
|
||||
});
|
||||
this.sendSendMessageRequest(smr, true);
|
||||
return promise;
|
||||
}
|
||||
rpcObserverSubscribe(readerKey, listener) {
|
||||
console.log("rpcObserverSubscribe", readerKey);
|
||||
const correlations = new Map();
|
||||
const msInbox = {
|
||||
id: "rpc-inbox-" + readerKey,
|
||||
readerKey: readerKey,
|
||||
channel: "rpc-inbox",
|
||||
startSeq: "first",
|
||||
};
|
||||
this.channelMessageSubscribe(msInbox, (me, msg) => {
|
||||
var _a, _b;
|
||||
const correlationId = (_b = (_a = msg.header) === null || _a === void 0 ? void 0 : _a.rpcHeader) === null || _b === void 0 ? void 0 : _b.correlationId;
|
||||
if (correlationId) {
|
||||
var correlation = correlations.get(correlationId);
|
||||
if (!correlation) {
|
||||
correlation = new RpcRequestResponse(correlationId);
|
||||
correlations.set(correlationId, correlation);
|
||||
}
|
||||
correlation.inboxEnvelope = me;
|
||||
correlation.inboxMessage = msg;
|
||||
listener(correlation);
|
||||
}
|
||||
});
|
||||
const msSent = {
|
||||
id: "rpc-sent-" + readerKey,
|
||||
readerKey: readerKey,
|
||||
channel: "rpc-sent",
|
||||
startSeq: "first",
|
||||
};
|
||||
this.channelSendReceiptSubscribe(msSent, (me, sr) => {
|
||||
var _a, _b, _c, _d, _e;
|
||||
const msg = (_a = sr.request) === null || _a === void 0 ? void 0 : _a.message;
|
||||
const correlationId = (_e = (_d = (_c = (_b = sr.request) === null || _b === void 0 ? void 0 : _b.message) === null || _c === void 0 ? void 0 : _c.header) === null || _d === void 0 ? void 0 : _d.rpcHeader) === null || _e === void 0 ? void 0 : _e.correlationId;
|
||||
if (correlationId !== undefined) {
|
||||
var correlation = correlations.get(correlationId);
|
||||
if (correlation === undefined) {
|
||||
correlation = new RpcRequestResponse(correlationId);
|
||||
correlations.set(correlationId, correlation);
|
||||
}
|
||||
correlation.sentMessage = msg;
|
||||
correlation.sendReceiptEnvelope = me;
|
||||
correlation.sendReceipt = sr;
|
||||
listener(correlation);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
class HermesClientImpl {
|
||||
constructor(rootUrl, contentTypeHandler) {
|
||||
this.correlationIdCounter = 0;
|
||||
this.correlations = new Map();
|
||||
this.activeSubscriptions = new Map();
|
||||
this.sentMessagesWaitingForAck = new Map();
|
||||
const thisHermesClientImpl = this;
|
||||
this.rootUrl = rootUrl;
|
||||
this.contentTypeHandler = contentTypeHandler;
|
||||
this.mailboxResponseP = createMailbox([Constants.rpcInboxChannelName, Constants.rpcSentChannelName], rootUrl);
|
||||
var tempMailboxResponseP = this.mailboxResponseP;
|
||||
var tempWsUrl = new URL(rootUrl);
|
||||
tempWsUrl.protocol = tempWsUrl.protocol.replace("http", "ws");
|
||||
tempWsUrl.pathname = contentTypeHandler.webSocketUrlPath;
|
||||
this.wsUrl = tempWsUrl.toString();
|
||||
this.currentConn = this.newHermesConnection();
|
||||
}
|
||||
sendPongResponse(mbox, pingMsg, endPoint) {
|
||||
var _a, _b, _c, _d, _e, _f;
|
||||
const correlationId = (_b = (_a = pingMsg.header) === null || _a === void 0 ? void 0 : _a.rpcHeader) === null || _b === void 0 ? void 0 : _b.correlationId;
|
||||
const sender = (_c = pingMsg === null || pingMsg === void 0 ? void 0 : pingMsg.header) === null || _c === void 0 ? void 0 : _c.sender;
|
||||
const contentType = (_e = (_d = pingMsg === null || pingMsg === void 0 ? void 0 : pingMsg.header) === null || _d === void 0 ? void 0 : _d.contentType) !== null && _e !== void 0 ? _e : wsmessages_1.ContentType.UnspecifiedCT;
|
||||
if (correlationId !== undefined && sender !== undefined) {
|
||||
var ping = {};
|
||||
if (pingMsg.data !== undefined) {
|
||||
if (contentType == wsmessages_1.ContentType.Json) {
|
||||
ping = wsmessages_1.Ping.fromJSON(pingMsg.data);
|
||||
}
|
||||
else {
|
||||
ping = wsmessages_1.Ping.decode(pingMsg.data);
|
||||
}
|
||||
}
|
||||
const pong = { payload: ping.payload };
|
||||
var data;
|
||||
if (contentType == wsmessages_1.ContentType.Json) {
|
||||
data = new TextEncoder().encode(JSON.stringify(wsmessages_1.Pong.toJSON(pong)));
|
||||
}
|
||||
else {
|
||||
data = wsmessages_1.Pong.encode(pong).finish();
|
||||
}
|
||||
const idempotentId = mbox.address + correlationId;
|
||||
const smr = {
|
||||
channel: Constants.rpcInboxChannelName,
|
||||
to: [sender],
|
||||
idempotentId: idempotentId,
|
||||
message: {
|
||||
header: {
|
||||
rpcHeader: {
|
||||
correlationId: correlationId,
|
||||
endPoint: endPoint,
|
||||
frameType: wsmessages_1.RpcFrameType.SuccessResponse,
|
||||
errorInfo: undefined,
|
||||
},
|
||||
sender: mbox.address,
|
||||
contentType: (_f = pingMsg === null || pingMsg === void 0 ? void 0 : pingMsg.header) === null || _f === void 0 ? void 0 : _f.contentType,
|
||||
},
|
||||
serverEnvelope: undefined,
|
||||
senderEnvelope: {
|
||||
created: Date.now(),
|
||||
},
|
||||
data: data,
|
||||
},
|
||||
};
|
||||
this.withConn((conn) => {
|
||||
conn.sendSendMessageRequest(smr, true);
|
||||
});
|
||||
}
|
||||
else {
|
||||
console.log("ignoring ping no correlation id", pingMsg);
|
||||
}
|
||||
}
|
||||
reconnect() {
|
||||
this.currentConn = this.newHermesConnection();
|
||||
}
|
||||
newHermesConnection() {
|
||||
const outerThis = this;
|
||||
return new Promise((resolve, reject) => {
|
||||
this.mailboxResponseP.then((mbox) => {
|
||||
var webSocket = new WebSocket(this.wsUrl);
|
||||
webSocket.binaryType = "arraybuffer";
|
||||
webSocket.onopen = function (event) {
|
||||
console.log("hermes client websocket opened, sending first message");
|
||||
const resubscriptions = Object.values(outerThis.activeSubscriptions).map((as) => { return as.protoSubscription; });
|
||||
// send first message
|
||||
const firstMessage = {
|
||||
senderInfo: {
|
||||
readerKey: mbox.readerKey,
|
||||
address: mbox.address,
|
||||
},
|
||||
subscriptions: resubscriptions,
|
||||
mailboxTimeoutInMs: 2 * 60 * 1000, // 2 minutes
|
||||
};
|
||||
const mfc = {
|
||||
firstMessage: firstMessage,
|
||||
};
|
||||
console.log("sending first message");
|
||||
outerThis.contentTypeHandler.sendMessageFromClient(mfc, webSocket);
|
||||
console.log("resolving promise");
|
||||
resolve(new HermesConnection(outerThis, mbox, webSocket));
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
mailbox() {
|
||||
return this.mailboxResponseP;
|
||||
}
|
||||
async withConn(fn) {
|
||||
return this.currentConn.then((conn) => fn(conn));
|
||||
}
|
||||
async withConnP(fn) {
|
||||
return this.currentConn.then((conn) => fn(conn));
|
||||
}
|
||||
rawRpcCall(request) {
|
||||
return this.withConnP((conn) => {
|
||||
return conn.rawRpcCall(request);
|
||||
});
|
||||
}
|
||||
cdcSubscribe(cdcs, listener) {
|
||||
this.withConn((conn) => {
|
||||
conn.cdcSubscribe(cdcs, listener);
|
||||
});
|
||||
}
|
||||
rpcObserverSubscribe(readerKey, listener) {
|
||||
console.log("outer rpcObserverSubscribe", readerKey);
|
||||
this.withConn((conn) => {
|
||||
console.log("inner rpcObserverSubscribe", readerKey);
|
||||
conn.rpcObserverSubscribe(readerKey, listener);
|
||||
});
|
||||
}
|
||||
channelMessageSubscribe(ms, listener) {
|
||||
this.withConn((conn) => {
|
||||
conn.channelMessageSubscribe(ms, listener);
|
||||
});
|
||||
}
|
||||
channelSendReceiptSubscribe(ms, listener) {
|
||||
this.withConn((conn) => {
|
||||
conn.channelSendReceiptSubscribe(ms, listener);
|
||||
});
|
||||
}
|
||||
sendPing() {
|
||||
this.withConn((conn) => {
|
||||
conn.sendPing();
|
||||
});
|
||||
}
|
||||
}
|
||||
class RpcRequestResponse {
|
||||
constructor(correlationId) {
|
||||
this.correlationId = correlationId;
|
||||
}
|
||||
role() {
|
||||
const ic = this.isClient();
|
||||
if (ic) {
|
||||
return "client";
|
||||
}
|
||||
else if (ic === false) {
|
||||
return "server";
|
||||
}
|
||||
}
|
||||
contentType() {
|
||||
var _a, _b, _c, _d, _e, _f;
|
||||
const contentType = (_f = (_c = (_b = (_a = this.requestMessage()) === null || _a === void 0 ? void 0 : _a.header) === null || _b === void 0 ? void 0 : _b.contentType) !== null && _c !== void 0 ? _c : (_e = (_d = this.responseMessage()) === null || _d === void 0 ? void 0 : _d.header) === null || _e === void 0 ? void 0 : _e.contentType) !== null && _f !== void 0 ? _f : wsmessages_1.ContentType.UnspecifiedCT;
|
||||
return contentType;
|
||||
}
|
||||
isProtobuf() {
|
||||
return this.contentType() === wsmessages_1.ContentType.Protobuf;
|
||||
}
|
||||
isJson() {
|
||||
return this.contentType() === wsmessages_1.ContentType.Json;
|
||||
}
|
||||
isClient() {
|
||||
var _a, _b, _c, _d, _e, _f;
|
||||
const inboxFrameType = (_c = (_b = (_a = this.inboxMessage) === null || _a === void 0 ? void 0 : _a.header) === null || _b === void 0 ? void 0 : _b.rpcHeader) === null || _c === void 0 ? void 0 : _c.frameType;
|
||||
const sentFrameType = (_f = (_e = (_d = this.sentMessage) === null || _d === void 0 ? void 0 : _d.header) === null || _e === void 0 ? void 0 : _e.rpcHeader) === null || _f === void 0 ? void 0 : _f.frameType;
|
||||
if (sentFrameType === wsmessages_1.RpcFrameType.Request) {
|
||||
return true;
|
||||
}
|
||||
else if (inboxFrameType === wsmessages_1.RpcFrameType.Request) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
hasRequestAndResponse() {
|
||||
return this.sendReceiptEnvelope && this.inboxEnvelope ? true : false;
|
||||
}
|
||||
timeStarted() {
|
||||
var _a, _b, _c, _d;
|
||||
const ic = this.isClient();
|
||||
var time = (0, Utils_1.undef)();
|
||||
if (ic === true) {
|
||||
time = (_b = (_a = this.sendReceiptEnvelope) === null || _a === void 0 ? void 0 : _a.serverEnvelope) === null || _b === void 0 ? void 0 : _b.created;
|
||||
}
|
||||
else if (ic === false) {
|
||||
time = (_d = (_c = this.inboxEnvelope) === null || _c === void 0 ? void 0 : _c.serverEnvelope) === null || _d === void 0 ? void 0 : _d.created;
|
||||
}
|
||||
if (time) {
|
||||
return new Date(time);
|
||||
}
|
||||
}
|
||||
timeStartedL() {
|
||||
var _a, _b, _c, _d;
|
||||
const ic = this.isClient();
|
||||
var time = (0, Utils_1.undef)();
|
||||
if (ic === true) {
|
||||
time = (_b = (_a = this.sendReceiptEnvelope) === null || _a === void 0 ? void 0 : _a.serverEnvelope) === null || _b === void 0 ? void 0 : _b.created;
|
||||
}
|
||||
else if (ic === false) {
|
||||
time = (_d = (_c = this.inboxEnvelope) === null || _c === void 0 ? void 0 : _c.serverEnvelope) === null || _d === void 0 ? void 0 : _d.created;
|
||||
}
|
||||
return time;
|
||||
}
|
||||
timeCompleted() {
|
||||
var _a, _b, _c, _d;
|
||||
const ic = this.isClient();
|
||||
var time = undefined;
|
||||
if (ic === false) {
|
||||
time = (_b = (_a = this.sendReceiptEnvelope) === null || _a === void 0 ? void 0 : _a.serverEnvelope) === null || _b === void 0 ? void 0 : _b.created;
|
||||
}
|
||||
else if (ic === true) {
|
||||
time = (_d = (_c = this.inboxEnvelope) === null || _c === void 0 ? void 0 : _c.serverEnvelope) === null || _d === void 0 ? void 0 : _d.created;
|
||||
}
|
||||
if (time) {
|
||||
return new Date(time);
|
||||
}
|
||||
}
|
||||
durationInMillis() {
|
||||
var _a, _b;
|
||||
const ts = (_a = this.timeStarted()) === null || _a === void 0 ? void 0 : _a.getTime();
|
||||
const tc = (_b = this.timeCompleted()) === null || _b === void 0 ? void 0 : _b.getTime();
|
||||
if (ts && tc) {
|
||||
return tc - ts;
|
||||
}
|
||||
}
|
||||
endPoint() {
|
||||
var _a, _b, _c;
|
||||
return (_c = (_b = (_a = this.requestMessage()) === null || _a === void 0 ? void 0 : _a.header) === null || _b === void 0 ? void 0 : _b.rpcHeader) === null || _c === void 0 ? void 0 : _c.endPoint;
|
||||
}
|
||||
requestMessage() {
|
||||
const ic = this.isClient();
|
||||
if (ic === true) {
|
||||
return this.sentMessage;
|
||||
}
|
||||
else if (ic === false) {
|
||||
return this.inboxMessage;
|
||||
}
|
||||
}
|
||||
requestEnvelope() {
|
||||
const ic = this.isClient();
|
||||
if (ic === true) {
|
||||
return this.sendReceiptEnvelope;
|
||||
}
|
||||
else if (ic === false) {
|
||||
return this.inboxEnvelope;
|
||||
}
|
||||
}
|
||||
responseMessage() {
|
||||
const ic = this.isClient();
|
||||
if (ic === true) {
|
||||
return this.inboxMessage;
|
||||
}
|
||||
else if (ic === false) {
|
||||
return this.sentMessage;
|
||||
}
|
||||
}
|
||||
responseEnvelope() {
|
||||
const ic = this.isClient();
|
||||
if (ic === true) {
|
||||
return this.inboxEnvelope;
|
||||
}
|
||||
else if (ic === false) {
|
||||
return this.sendReceiptEnvelope;
|
||||
}
|
||||
}
|
||||
status() {
|
||||
var _a, _b, _c;
|
||||
const frameType = (_c = (_b = (_a = this.responseMessage()) === null || _a === void 0 ? void 0 : _a.header) === null || _b === void 0 ? void 0 : _b.rpcHeader) === null || _c === void 0 ? void 0 : _c.frameType;
|
||||
if (!frameType) {
|
||||
return "";
|
||||
}
|
||||
else if (frameType === wsmessages_1.RpcFrameType.ErrorResponse) {
|
||||
return "error";
|
||||
}
|
||||
else if (frameType === wsmessages_1.RpcFrameType.SuccessResponse) {
|
||||
return "success";
|
||||
}
|
||||
else {
|
||||
return `Unexpected frame types ${frameType}`;
|
||||
}
|
||||
}
|
||||
async processSchema(reqOrResp, data) {
|
||||
if (this.isJson()) {
|
||||
const jsonStr = new TextDecoder().decode(data);
|
||||
return JSON.parse(jsonStr);
|
||||
}
|
||||
else {
|
||||
const endPoint = this.endPoint();
|
||||
if (endPoint === undefined) {
|
||||
return {
|
||||
"error": "no endpoint"
|
||||
};
|
||||
}
|
||||
if (data === undefined) {
|
||||
return {};
|
||||
}
|
||||
return protobufToJson(endPoint, reqOrResp, data);
|
||||
}
|
||||
}
|
||||
async responseObj() {
|
||||
var _a;
|
||||
return this.processSchema("response", (_a = this.responseMessage()) === null || _a === void 0 ? void 0 : _a.data);
|
||||
}
|
||||
async requestObj() {
|
||||
var _a;
|
||||
return this.processSchema("request", (_a = this.requestMessage()) === null || _a === void 0 ? void 0 : _a.data);
|
||||
}
|
||||
}
|
||||
exports.RpcRequestResponse = RpcRequestResponse;
|
||||
const GlobalClient = {
|
||||
get: (0, Utils_1.memoize)(() => newHermesClient("https://hermes-go.ahsrcm.com", JsonContentTypeHandler))
|
||||
};
|
||||
exports.default = GlobalClient;
|
||||
function runHermesClientTest() {
|
||||
}
|
||||
exports.runHermesClientTest = runHermesClientTest;
|
||||
function runHermesClientTest2() {
|
||||
// const hc = newHermesClient("https://hermes-go.ahsrcm.com", ContentType.Protobuf);
|
||||
const hc = newHermesClient("https://hermes-go.ahsrcm.com", JsonContentTypeHandler);
|
||||
hc.mailbox().then((mbox) => {
|
||||
const cdcs = {
|
||||
tables: [
|
||||
{
|
||||
database: "nefario",
|
||||
table: "service",
|
||||
},
|
||||
],
|
||||
startSeq: "new",
|
||||
};
|
||||
hc.cdcSubscribe(cdcs, (cdcEvent, a) => {
|
||||
console.log("cdcEvent", cdcEvent);
|
||||
});
|
||||
});
|
||||
// hc.correlatedRpcReader("rrb07167144dc644a0be22a85301afea7e" , (correlation) => {
|
||||
// console.log("correlation", correlation);
|
||||
// });
|
||||
}
|
||||
exports.runHermesClientTest2 = runHermesClientTest2;
|
||||
async function protobufToJson(schemaName, frametype, bytes) {
|
||||
// const mboxObj = CreateMailboxRequest.toJSON(mbox);
|
||||
// const mboxJson = JSON.stringify(mboxObj);
|
||||
// let mailboxResponse: CreateMailboxResponse | undefined = undefined;
|
||||
const rootUrl = GlobalClient.get().rootUrl;
|
||||
const response = await fetch(`${rootUrl}/api/proto_to_json?schema=${schemaName}&frametype=${frametype}`, {
|
||||
method: "POST",
|
||||
body: bytes,
|
||||
});
|
||||
if (response.ok) {
|
||||
const jsonStr = await response.text();
|
||||
return JSON.parse(jsonStr);
|
||||
}
|
||||
else {
|
||||
throw new Error(`proto_to_json failed with status ${response.status}`);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,201 @@
|
|||
import * as _m0 from "../../../../node_modules/protobufjs/minimal";
|
||||
export declare const protobufPackage = "google.protobuf";
|
||||
/**
|
||||
* `NullValue` is a singleton enumeration to represent the null value for the
|
||||
* `Value` type union.
|
||||
*
|
||||
* The JSON representation for `NullValue` is JSON `null`.
|
||||
*/
|
||||
export declare enum NullValue {
|
||||
/** NULL_VALUE - Null value. */
|
||||
NULL_VALUE = 0,
|
||||
UNRECOGNIZED = -1
|
||||
}
|
||||
export declare function nullValueFromJSON(object: any): NullValue;
|
||||
export declare function nullValueToJSON(object: NullValue): string;
|
||||
/**
|
||||
* `Struct` represents a structured data value, consisting of fields
|
||||
* which map to dynamically typed values. In some languages, `Struct`
|
||||
* might be supported by a native representation. For example, in
|
||||
* scripting languages like JS a struct is represented as an
|
||||
* object. The details of that representation are described together
|
||||
* with the proto support for the language.
|
||||
*
|
||||
* The JSON representation for `Struct` is JSON object.
|
||||
*/
|
||||
export interface Struct {
|
||||
/** Unordered map of dynamically typed values. */
|
||||
fields: {
|
||||
[key: string]: any | undefined;
|
||||
};
|
||||
}
|
||||
export interface Struct_FieldsEntry {
|
||||
key: string;
|
||||
value: any | undefined;
|
||||
}
|
||||
/**
|
||||
* `Value` represents a dynamically typed value which can be either
|
||||
* null, a number, a string, a boolean, a recursive struct value, or a
|
||||
* list of values. A producer of value is expected to set one of these
|
||||
* variants. Absence of any variant indicates an error.
|
||||
*
|
||||
* The JSON representation for `Value` is JSON value.
|
||||
*/
|
||||
export interface Value {
|
||||
/** Represents a null value. */
|
||||
nullValue?: NullValue | undefined;
|
||||
/** Represents a double value. */
|
||||
numberValue?: number | undefined;
|
||||
/** Represents a string value. */
|
||||
stringValue?: string | undefined;
|
||||
/** Represents a boolean value. */
|
||||
boolValue?: boolean | undefined;
|
||||
/** Represents a structured value. */
|
||||
structValue?: {
|
||||
[key: string]: any;
|
||||
} | undefined;
|
||||
/** Represents a repeated `Value`. */
|
||||
listValue?: Array<any> | undefined;
|
||||
}
|
||||
/**
|
||||
* `ListValue` is a wrapper around a repeated field of values.
|
||||
*
|
||||
* The JSON representation for `ListValue` is JSON array.
|
||||
*/
|
||||
export interface ListValue {
|
||||
/** Repeated field of dynamically typed values. */
|
||||
values: any[];
|
||||
}
|
||||
export declare const Struct: {
|
||||
encode(message: Struct, writer?: _m0.Writer): _m0.Writer;
|
||||
decode(input: _m0.Reader | Uint8Array, length?: number): Struct;
|
||||
fromJSON(object: any): Struct;
|
||||
toJSON(message: Struct): unknown;
|
||||
create<I extends {
|
||||
fields?: {
|
||||
[x: string]: any;
|
||||
} | undefined;
|
||||
} & {
|
||||
fields?: ({
|
||||
[x: string]: any;
|
||||
} & {
|
||||
[x: string]: any;
|
||||
} & { [K in Exclude<keyof I["fields"], string | number>]: never; }) | undefined;
|
||||
} & { [K_1 in Exclude<keyof I, "fields">]: never; }>(base?: I): Struct;
|
||||
fromPartial<I_1 extends {
|
||||
fields?: {
|
||||
[x: string]: any;
|
||||
} | undefined;
|
||||
} & {
|
||||
fields?: ({
|
||||
[x: string]: any;
|
||||
} & {
|
||||
[x: string]: any;
|
||||
} & { [K_2 in Exclude<keyof I_1["fields"], string | number>]: never; }) | undefined;
|
||||
} & { [K_3 in Exclude<keyof I_1, "fields">]: never; }>(object: I_1): Struct;
|
||||
wrap(object: {
|
||||
[key: string]: any;
|
||||
} | undefined): Struct;
|
||||
unwrap(message: Struct): {
|
||||
[key: string]: any;
|
||||
};
|
||||
};
|
||||
export declare const Struct_FieldsEntry: {
|
||||
encode(message: Struct_FieldsEntry, writer?: _m0.Writer): _m0.Writer;
|
||||
decode(input: _m0.Reader | Uint8Array, length?: number): Struct_FieldsEntry;
|
||||
fromJSON(object: any): Struct_FieldsEntry;
|
||||
toJSON(message: Struct_FieldsEntry): unknown;
|
||||
create<I extends {
|
||||
key?: string | undefined;
|
||||
value?: any | undefined;
|
||||
} & {
|
||||
key?: string | undefined;
|
||||
value?: any | undefined;
|
||||
} & { [K in Exclude<keyof I, keyof Struct_FieldsEntry>]: never; }>(base?: I): Struct_FieldsEntry;
|
||||
fromPartial<I_1 extends {
|
||||
key?: string | undefined;
|
||||
value?: any | undefined;
|
||||
} & {
|
||||
key?: string | undefined;
|
||||
value?: any | undefined;
|
||||
} & { [K_1 in Exclude<keyof I_1, keyof Struct_FieldsEntry>]: never; }>(object: I_1): Struct_FieldsEntry;
|
||||
};
|
||||
export declare const Value: {
|
||||
encode(message: Value, writer?: _m0.Writer): _m0.Writer;
|
||||
decode(input: _m0.Reader | Uint8Array, length?: number): Value;
|
||||
fromJSON(object: any): Value;
|
||||
toJSON(message: Value): unknown;
|
||||
create<I extends {
|
||||
nullValue?: NullValue | undefined;
|
||||
numberValue?: number | undefined;
|
||||
stringValue?: string | undefined;
|
||||
boolValue?: boolean | undefined;
|
||||
structValue?: {
|
||||
[x: string]: any;
|
||||
} | undefined;
|
||||
listValue?: any[] | undefined;
|
||||
} & {
|
||||
nullValue?: NullValue | undefined;
|
||||
numberValue?: number | undefined;
|
||||
stringValue?: string | undefined;
|
||||
boolValue?: boolean | undefined;
|
||||
structValue?: ({
|
||||
[x: string]: any;
|
||||
} & {
|
||||
[x: string]: any;
|
||||
} & { [K in Exclude<keyof I["structValue"], string | number>]: never; }) | undefined;
|
||||
listValue?: (any[] & any[] & { [K_1 in Exclude<keyof I["listValue"], keyof any[]>]: never; }) | undefined;
|
||||
} & { [K_2 in Exclude<keyof I, keyof Value>]: never; }>(base?: I): Value;
|
||||
fromPartial<I_1 extends {
|
||||
nullValue?: NullValue | undefined;
|
||||
numberValue?: number | undefined;
|
||||
stringValue?: string | undefined;
|
||||
boolValue?: boolean | undefined;
|
||||
structValue?: {
|
||||
[x: string]: any;
|
||||
} | undefined;
|
||||
listValue?: any[] | undefined;
|
||||
} & {
|
||||
nullValue?: NullValue | undefined;
|
||||
numberValue?: number | undefined;
|
||||
stringValue?: string | undefined;
|
||||
boolValue?: boolean | undefined;
|
||||
structValue?: ({
|
||||
[x: string]: any;
|
||||
} & {
|
||||
[x: string]: any;
|
||||
} & { [K_3 in Exclude<keyof I_1["structValue"], string | number>]: never; }) | undefined;
|
||||
listValue?: (any[] & any[] & { [K_4 in Exclude<keyof I_1["listValue"], keyof any[]>]: never; }) | undefined;
|
||||
} & { [K_5 in Exclude<keyof I_1, keyof Value>]: never; }>(object: I_1): Value;
|
||||
wrap(value: any): Value;
|
||||
unwrap(message: any): string | number | boolean | Object | null | Array<any> | undefined;
|
||||
};
|
||||
export declare const ListValue: {
|
||||
encode(message: ListValue, writer?: _m0.Writer): _m0.Writer;
|
||||
decode(input: _m0.Reader | Uint8Array, length?: number): ListValue;
|
||||
fromJSON(object: any): ListValue;
|
||||
toJSON(message: ListValue): unknown;
|
||||
create<I extends {
|
||||
values?: any[] | undefined;
|
||||
} & {
|
||||
values?: (any[] & any[] & { [K in Exclude<keyof I["values"], keyof any[]>]: never; }) | undefined;
|
||||
} & { [K_1 in Exclude<keyof I, "values">]: never; }>(base?: I): ListValue;
|
||||
fromPartial<I_1 extends {
|
||||
values?: any[] | undefined;
|
||||
} & {
|
||||
values?: (any[] & any[] & { [K_2 in Exclude<keyof I_1["values"], keyof any[]>]: never; }) | undefined;
|
||||
} & { [K_3 in Exclude<keyof I_1, "values">]: never; }>(object: I_1): ListValue;
|
||||
wrap(array: Array<any> | undefined): ListValue;
|
||||
unwrap(message: ListValue): Array<any>;
|
||||
};
|
||||
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
||||
export type DeepPartial<T> = T extends Builtin ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
|
||||
[K in keyof T]?: DeepPartial<T[K]>;
|
||||
} : Partial<T>;
|
||||
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
||||
export type Exact<P, I extends P> = P extends Builtin ? P : P & {
|
||||
[K in keyof P]: Exact<P[K], I[K]>;
|
||||
} & {
|
||||
[K in Exclude<keyof I, KeysOfUnion<P>>]: never;
|
||||
};
|
||||
export {};
|
||||
|
|
@ -0,0 +1,469 @@
|
|||
"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 (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ListValue = exports.Value = exports.Struct_FieldsEntry = exports.Struct = exports.nullValueToJSON = exports.nullValueFromJSON = exports.NullValue = exports.protobufPackage = void 0;
|
||||
/* eslint-disable */
|
||||
const _m0 = __importStar(require("../../../../node_modules/protobufjs/minimal"));
|
||||
exports.protobufPackage = "google.protobuf";
|
||||
/**
|
||||
* `NullValue` is a singleton enumeration to represent the null value for the
|
||||
* `Value` type union.
|
||||
*
|
||||
* The JSON representation for `NullValue` is JSON `null`.
|
||||
*/
|
||||
var NullValue;
|
||||
(function (NullValue) {
|
||||
/** NULL_VALUE - Null value. */
|
||||
NullValue[NullValue["NULL_VALUE"] = 0] = "NULL_VALUE";
|
||||
NullValue[NullValue["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
|
||||
})(NullValue || (exports.NullValue = NullValue = {}));
|
||||
function nullValueFromJSON(object) {
|
||||
switch (object) {
|
||||
case 0:
|
||||
case "NULL_VALUE":
|
||||
return NullValue.NULL_VALUE;
|
||||
case -1:
|
||||
case "UNRECOGNIZED":
|
||||
default:
|
||||
return NullValue.UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
exports.nullValueFromJSON = nullValueFromJSON;
|
||||
function nullValueToJSON(object) {
|
||||
switch (object) {
|
||||
case NullValue.NULL_VALUE:
|
||||
return "NULL_VALUE";
|
||||
case NullValue.UNRECOGNIZED:
|
||||
default:
|
||||
return "UNRECOGNIZED";
|
||||
}
|
||||
}
|
||||
exports.nullValueToJSON = nullValueToJSON;
|
||||
function createBaseStruct() {
|
||||
return { fields: {} };
|
||||
}
|
||||
exports.Struct = {
|
||||
encode(message, writer = _m0.Writer.create()) {
|
||||
Object.entries(message.fields).forEach(([key, value]) => {
|
||||
if (value !== undefined) {
|
||||
exports.Struct_FieldsEntry.encode({ key: key, value }, writer.uint32(10).fork()).ldelim();
|
||||
}
|
||||
});
|
||||
return writer;
|
||||
},
|
||||
decode(input, length) {
|
||||
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
||||
let end = length === undefined ? reader.len : reader.pos + length;
|
||||
const message = createBaseStruct();
|
||||
while (reader.pos < end) {
|
||||
const tag = reader.uint32();
|
||||
switch (tag >>> 3) {
|
||||
case 1:
|
||||
if (tag !== 10) {
|
||||
break;
|
||||
}
|
||||
const entry1 = exports.Struct_FieldsEntry.decode(reader, reader.uint32());
|
||||
if (entry1.value !== undefined) {
|
||||
message.fields[entry1.key] = entry1.value;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if ((tag & 7) === 4 || tag === 0) {
|
||||
break;
|
||||
}
|
||||
reader.skipType(tag & 7);
|
||||
}
|
||||
return message;
|
||||
},
|
||||
fromJSON(object) {
|
||||
return {
|
||||
fields: isObject(object.fields)
|
||||
? Object.entries(object.fields).reduce((acc, [key, value]) => {
|
||||
acc[key] = value;
|
||||
return acc;
|
||||
}, {})
|
||||
: {},
|
||||
};
|
||||
},
|
||||
toJSON(message) {
|
||||
const obj = {};
|
||||
if (message.fields) {
|
||||
const entries = Object.entries(message.fields);
|
||||
if (entries.length > 0) {
|
||||
obj.fields = {};
|
||||
entries.forEach(([k, v]) => {
|
||||
obj.fields[k] = v;
|
||||
});
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
},
|
||||
create(base) {
|
||||
return exports.Struct.fromPartial(base !== null && base !== void 0 ? base : {});
|
||||
},
|
||||
fromPartial(object) {
|
||||
var _a;
|
||||
const message = createBaseStruct();
|
||||
message.fields = Object.entries((_a = object.fields) !== null && _a !== void 0 ? _a : {}).reduce((acc, [key, value]) => {
|
||||
if (value !== undefined) {
|
||||
acc[key] = value;
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
return message;
|
||||
},
|
||||
wrap(object) {
|
||||
const struct = createBaseStruct();
|
||||
if (object !== undefined) {
|
||||
Object.keys(object).forEach((key) => {
|
||||
struct.fields[key] = object[key];
|
||||
});
|
||||
}
|
||||
return struct;
|
||||
},
|
||||
unwrap(message) {
|
||||
const object = {};
|
||||
if (message.fields) {
|
||||
Object.keys(message.fields).forEach((key) => {
|
||||
object[key] = message.fields[key];
|
||||
});
|
||||
}
|
||||
return object;
|
||||
},
|
||||
};
|
||||
function createBaseStruct_FieldsEntry() {
|
||||
return { key: "", value: undefined };
|
||||
}
|
||||
exports.Struct_FieldsEntry = {
|
||||
encode(message, writer = _m0.Writer.create()) {
|
||||
if (message.key !== "") {
|
||||
writer.uint32(10).string(message.key);
|
||||
}
|
||||
if (message.value !== undefined) {
|
||||
exports.Value.encode(exports.Value.wrap(message.value), writer.uint32(18).fork()).ldelim();
|
||||
}
|
||||
return writer;
|
||||
},
|
||||
decode(input, length) {
|
||||
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
||||
let end = length === undefined ? reader.len : reader.pos + length;
|
||||
const message = createBaseStruct_FieldsEntry();
|
||||
while (reader.pos < end) {
|
||||
const tag = reader.uint32();
|
||||
switch (tag >>> 3) {
|
||||
case 1:
|
||||
if (tag !== 10) {
|
||||
break;
|
||||
}
|
||||
message.key = reader.string();
|
||||
continue;
|
||||
case 2:
|
||||
if (tag !== 18) {
|
||||
break;
|
||||
}
|
||||
message.value = exports.Value.unwrap(exports.Value.decode(reader, reader.uint32()));
|
||||
continue;
|
||||
}
|
||||
if ((tag & 7) === 4 || tag === 0) {
|
||||
break;
|
||||
}
|
||||
reader.skipType(tag & 7);
|
||||
}
|
||||
return message;
|
||||
},
|
||||
fromJSON(object) {
|
||||
return {
|
||||
key: isSet(object.key) ? globalThis.String(object.key) : "",
|
||||
value: isSet(object === null || object === void 0 ? void 0 : object.value) ? object.value : undefined,
|
||||
};
|
||||
},
|
||||
toJSON(message) {
|
||||
const obj = {};
|
||||
if (message.key !== "") {
|
||||
obj.key = message.key;
|
||||
}
|
||||
if (message.value !== undefined) {
|
||||
obj.value = message.value;
|
||||
}
|
||||
return obj;
|
||||
},
|
||||
create(base) {
|
||||
return exports.Struct_FieldsEntry.fromPartial(base !== null && base !== void 0 ? base : {});
|
||||
},
|
||||
fromPartial(object) {
|
||||
var _a, _b;
|
||||
const message = createBaseStruct_FieldsEntry();
|
||||
message.key = (_a = object.key) !== null && _a !== void 0 ? _a : "";
|
||||
message.value = (_b = object.value) !== null && _b !== void 0 ? _b : undefined;
|
||||
return message;
|
||||
},
|
||||
};
|
||||
function createBaseValue() {
|
||||
return {
|
||||
nullValue: undefined,
|
||||
numberValue: undefined,
|
||||
stringValue: undefined,
|
||||
boolValue: undefined,
|
||||
structValue: undefined,
|
||||
listValue: undefined,
|
||||
};
|
||||
}
|
||||
exports.Value = {
|
||||
encode(message, writer = _m0.Writer.create()) {
|
||||
if (message.nullValue !== undefined) {
|
||||
writer.uint32(8).int32(message.nullValue);
|
||||
}
|
||||
if (message.numberValue !== undefined) {
|
||||
writer.uint32(17).double(message.numberValue);
|
||||
}
|
||||
if (message.stringValue !== undefined) {
|
||||
writer.uint32(26).string(message.stringValue);
|
||||
}
|
||||
if (message.boolValue !== undefined) {
|
||||
writer.uint32(32).bool(message.boolValue);
|
||||
}
|
||||
if (message.structValue !== undefined) {
|
||||
exports.Struct.encode(exports.Struct.wrap(message.structValue), writer.uint32(42).fork()).ldelim();
|
||||
}
|
||||
if (message.listValue !== undefined) {
|
||||
exports.ListValue.encode(exports.ListValue.wrap(message.listValue), writer.uint32(50).fork()).ldelim();
|
||||
}
|
||||
return writer;
|
||||
},
|
||||
decode(input, length) {
|
||||
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
||||
let end = length === undefined ? reader.len : reader.pos + length;
|
||||
const message = createBaseValue();
|
||||
while (reader.pos < end) {
|
||||
const tag = reader.uint32();
|
||||
switch (tag >>> 3) {
|
||||
case 1:
|
||||
if (tag !== 8) {
|
||||
break;
|
||||
}
|
||||
message.nullValue = reader.int32();
|
||||
continue;
|
||||
case 2:
|
||||
if (tag !== 17) {
|
||||
break;
|
||||
}
|
||||
message.numberValue = reader.double();
|
||||
continue;
|
||||
case 3:
|
||||
if (tag !== 26) {
|
||||
break;
|
||||
}
|
||||
message.stringValue = reader.string();
|
||||
continue;
|
||||
case 4:
|
||||
if (tag !== 32) {
|
||||
break;
|
||||
}
|
||||
message.boolValue = reader.bool();
|
||||
continue;
|
||||
case 5:
|
||||
if (tag !== 42) {
|
||||
break;
|
||||
}
|
||||
message.structValue = exports.Struct.unwrap(exports.Struct.decode(reader, reader.uint32()));
|
||||
continue;
|
||||
case 6:
|
||||
if (tag !== 50) {
|
||||
break;
|
||||
}
|
||||
message.listValue = exports.ListValue.unwrap(exports.ListValue.decode(reader, reader.uint32()));
|
||||
continue;
|
||||
}
|
||||
if ((tag & 7) === 4 || tag === 0) {
|
||||
break;
|
||||
}
|
||||
reader.skipType(tag & 7);
|
||||
}
|
||||
return message;
|
||||
},
|
||||
fromJSON(object) {
|
||||
return {
|
||||
nullValue: isSet(object.nullValue) ? nullValueFromJSON(object.nullValue) : undefined,
|
||||
numberValue: isSet(object.numberValue) ? globalThis.Number(object.numberValue) : undefined,
|
||||
stringValue: isSet(object.stringValue) ? globalThis.String(object.stringValue) : undefined,
|
||||
boolValue: isSet(object.boolValue) ? globalThis.Boolean(object.boolValue) : undefined,
|
||||
structValue: isObject(object.structValue) ? object.structValue : undefined,
|
||||
listValue: globalThis.Array.isArray(object.listValue) ? [...object.listValue] : undefined,
|
||||
};
|
||||
},
|
||||
toJSON(message) {
|
||||
const obj = {};
|
||||
if (message.nullValue !== undefined) {
|
||||
obj.nullValue = nullValueToJSON(message.nullValue);
|
||||
}
|
||||
if (message.numberValue !== undefined) {
|
||||
obj.numberValue = message.numberValue;
|
||||
}
|
||||
if (message.stringValue !== undefined) {
|
||||
obj.stringValue = message.stringValue;
|
||||
}
|
||||
if (message.boolValue !== undefined) {
|
||||
obj.boolValue = message.boolValue;
|
||||
}
|
||||
if (message.structValue !== undefined) {
|
||||
obj.structValue = message.structValue;
|
||||
}
|
||||
if (message.listValue !== undefined) {
|
||||
obj.listValue = message.listValue;
|
||||
}
|
||||
return obj;
|
||||
},
|
||||
create(base) {
|
||||
return exports.Value.fromPartial(base !== null && base !== void 0 ? base : {});
|
||||
},
|
||||
fromPartial(object) {
|
||||
var _a, _b, _c, _d, _e, _f;
|
||||
const message = createBaseValue();
|
||||
message.nullValue = (_a = object.nullValue) !== null && _a !== void 0 ? _a : undefined;
|
||||
message.numberValue = (_b = object.numberValue) !== null && _b !== void 0 ? _b : undefined;
|
||||
message.stringValue = (_c = object.stringValue) !== null && _c !== void 0 ? _c : undefined;
|
||||
message.boolValue = (_d = object.boolValue) !== null && _d !== void 0 ? _d : undefined;
|
||||
message.structValue = (_e = object.structValue) !== null && _e !== void 0 ? _e : undefined;
|
||||
message.listValue = (_f = object.listValue) !== null && _f !== void 0 ? _f : undefined;
|
||||
return message;
|
||||
},
|
||||
wrap(value) {
|
||||
const result = createBaseValue();
|
||||
if (value === null) {
|
||||
result.nullValue = NullValue.NULL_VALUE;
|
||||
}
|
||||
else if (typeof value === "boolean") {
|
||||
result.boolValue = value;
|
||||
}
|
||||
else if (typeof value === "number") {
|
||||
result.numberValue = value;
|
||||
}
|
||||
else if (typeof value === "string") {
|
||||
result.stringValue = value;
|
||||
}
|
||||
else if (globalThis.Array.isArray(value)) {
|
||||
result.listValue = value;
|
||||
}
|
||||
else if (typeof value === "object") {
|
||||
result.structValue = value;
|
||||
}
|
||||
else if (typeof value !== "undefined") {
|
||||
throw new globalThis.Error("Unsupported any value type: " + typeof value);
|
||||
}
|
||||
return result;
|
||||
},
|
||||
unwrap(message) {
|
||||
if (message.stringValue !== undefined) {
|
||||
return message.stringValue;
|
||||
}
|
||||
else if ((message === null || message === void 0 ? void 0 : message.numberValue) !== undefined) {
|
||||
return message.numberValue;
|
||||
}
|
||||
else if ((message === null || message === void 0 ? void 0 : message.boolValue) !== undefined) {
|
||||
return message.boolValue;
|
||||
}
|
||||
else if ((message === null || message === void 0 ? void 0 : message.structValue) !== undefined) {
|
||||
return message.structValue;
|
||||
}
|
||||
else if ((message === null || message === void 0 ? void 0 : message.listValue) !== undefined) {
|
||||
return message.listValue;
|
||||
}
|
||||
else if ((message === null || message === void 0 ? void 0 : message.nullValue) !== undefined) {
|
||||
return null;
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
};
|
||||
function createBaseListValue() {
|
||||
return { values: [] };
|
||||
}
|
||||
exports.ListValue = {
|
||||
encode(message, writer = _m0.Writer.create()) {
|
||||
for (const v of message.values) {
|
||||
exports.Value.encode(exports.Value.wrap(v), writer.uint32(10).fork()).ldelim();
|
||||
}
|
||||
return writer;
|
||||
},
|
||||
decode(input, length) {
|
||||
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
||||
let end = length === undefined ? reader.len : reader.pos + length;
|
||||
const message = createBaseListValue();
|
||||
while (reader.pos < end) {
|
||||
const tag = reader.uint32();
|
||||
switch (tag >>> 3) {
|
||||
case 1:
|
||||
if (tag !== 10) {
|
||||
break;
|
||||
}
|
||||
message.values.push(exports.Value.unwrap(exports.Value.decode(reader, reader.uint32())));
|
||||
continue;
|
||||
}
|
||||
if ((tag & 7) === 4 || tag === 0) {
|
||||
break;
|
||||
}
|
||||
reader.skipType(tag & 7);
|
||||
}
|
||||
return message;
|
||||
},
|
||||
fromJSON(object) {
|
||||
return { values: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.values) ? [...object.values] : [] };
|
||||
},
|
||||
toJSON(message) {
|
||||
var _a;
|
||||
const obj = {};
|
||||
if ((_a = message.values) === null || _a === void 0 ? void 0 : _a.length) {
|
||||
obj.values = message.values;
|
||||
}
|
||||
return obj;
|
||||
},
|
||||
create(base) {
|
||||
return exports.ListValue.fromPartial(base !== null && base !== void 0 ? base : {});
|
||||
},
|
||||
fromPartial(object) {
|
||||
var _a;
|
||||
const message = createBaseListValue();
|
||||
message.values = ((_a = object.values) === null || _a === void 0 ? void 0 : _a.map((e) => e)) || [];
|
||||
return message;
|
||||
},
|
||||
wrap(array) {
|
||||
const result = createBaseListValue();
|
||||
result.values = array !== null && array !== void 0 ? array : [];
|
||||
return result;
|
||||
},
|
||||
unwrap(message) {
|
||||
if ((message === null || message === void 0 ? void 0 : message.hasOwnProperty("values")) && globalThis.Array.isArray(message.values)) {
|
||||
return message.values;
|
||||
}
|
||||
else {
|
||||
return message;
|
||||
}
|
||||
},
|
||||
};
|
||||
function isObject(value) {
|
||||
return typeof value === "object" && value !== null;
|
||||
}
|
||||
function isSet(value) {
|
||||
return value !== null && value !== undefined;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,2 @@
|
|||
export declare function undef<A>(): A | undefined;
|
||||
export declare function memoize<A>(fn: () => A): () => A;
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
export function undef() {
|
||||
return undefined;
|
||||
}
|
||||
export function memoize(fn) {
|
||||
let memo;
|
||||
return () => {
|
||||
if (memo === undefined) {
|
||||
memo = fn();
|
||||
}
|
||||
return memo;
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
import { ContentType, Message, MessageFromClient, CreateMailboxResponse, KeyValPair, MessageEnvelope, SendReceipt } from "./proto/wsmessages";
|
||||
export interface ContentTypeHandler {
|
||||
readonly webSocketUrlPath: string;
|
||||
sendMessageFromClient(mfc: MessageFromClient, ws: WebSocket): void;
|
||||
}
|
||||
export declare const ContentTypeHandler: {
|
||||
Json: ContentTypeHandler;
|
||||
Protobuf: ContentTypeHandler;
|
||||
};
|
||||
export declare function newHermesClient(rootUrl: string, contentTypeHandler: ContentTypeHandler): HermesClient;
|
||||
export interface ChangeDataCaptureEvent {
|
||||
id: string;
|
||||
schema: string;
|
||||
table: string;
|
||||
action: string;
|
||||
data: any;
|
||||
commitTime: string;
|
||||
}
|
||||
interface RawRpcRequest {
|
||||
to: string;
|
||||
endPoint: string;
|
||||
body?: Uint8Array;
|
||||
contentType?: ContentType;
|
||||
headers?: KeyValPair[];
|
||||
state?: Uint8Array;
|
||||
}
|
||||
export declare class RpcRequestResponse {
|
||||
correlationId: string;
|
||||
sendReceiptEnvelope: MessageEnvelope | undefined;
|
||||
sendReceipt: SendReceipt | undefined;
|
||||
sentMessage: Message | undefined;
|
||||
inboxEnvelope: MessageEnvelope | undefined;
|
||||
inboxMessage: Message | undefined;
|
||||
constructor(correlationId: string);
|
||||
role(): string | undefined;
|
||||
contentType(): ContentType;
|
||||
isProtobuf(): boolean;
|
||||
isJson(): boolean;
|
||||
isClient(): boolean | undefined;
|
||||
hasRequestAndResponse(): boolean;
|
||||
timeStarted(): Date | undefined;
|
||||
timeStartedL(): number | undefined;
|
||||
timeCompleted(): Date | undefined;
|
||||
durationInMillis(): number | undefined;
|
||||
endPoint(): string | undefined;
|
||||
requestMessage(): Message | undefined;
|
||||
requestEnvelope(): MessageEnvelope | undefined;
|
||||
responseMessage(): Message | undefined;
|
||||
responseEnvelope(): MessageEnvelope | undefined;
|
||||
status(): string;
|
||||
processSchema(reqOrResp: "request" | "response", data?: Uint8Array): Promise<any>;
|
||||
responseObj(): Promise<any>;
|
||||
requestObj(): Promise<any>;
|
||||
}
|
||||
declare const GlobalClient: {
|
||||
get: () => HermesClient;
|
||||
};
|
||||
export default GlobalClient;
|
||||
export declare function runHermesClientTest(): void;
|
||||
export declare function runHermesClientTest2(): void;
|
||||
export interface CdcSubscription {
|
||||
tables: CdcTable[];
|
||||
startSeq?: string;
|
||||
}
|
||||
export interface CdcTable {
|
||||
database: string;
|
||||
table: string;
|
||||
}
|
||||
export interface HermesClient {
|
||||
readonly rootUrl: string;
|
||||
mailbox(): Promise<CreateMailboxResponse>;
|
||||
rawRpcCall(request: RawRpcRequest): Promise<Message>;
|
||||
cdcSubscribe<A>(cdcs: CdcSubscription, listener: (cdcEvent: ChangeDataCaptureEvent, a: A) => void): void;
|
||||
rpcObserverSubscribe(readerKey: string, listener: (correlation: RpcRequestResponse) => void): void;
|
||||
}
|
||||
|
|
@ -0,0 +1,682 @@
|
|||
import { ContentType, Message, MessageFromClient, MessageToClient, CreateMailboxResponse, CreateMailboxRequest, RpcFrameType, SendReceipt, Ping, Pong, } from "./proto/wsmessages";
|
||||
import { memoize, undef } from "../Utils";
|
||||
const JsonContentTypeHandler = {
|
||||
webSocketUrlPath: "/api/ws/send_receive_json",
|
||||
sendMessageFromClient(mfc, ws) {
|
||||
const obj = MessageFromClient.toJSON(mfc);
|
||||
const jsonStr = JSON.stringify(obj);
|
||||
ws.send(jsonStr);
|
||||
}
|
||||
};
|
||||
const ProtobufContentTypeHandler = {
|
||||
webSocketUrlPath: "/api/ws/send_receive_proto",
|
||||
sendMessageFromClient(mfc, ws) {
|
||||
const bytes = MessageFromClient.encode(mfc).finish();
|
||||
ws.send(bytes);
|
||||
}
|
||||
};
|
||||
export const ContentTypeHandler = {
|
||||
Json: JsonContentTypeHandler,
|
||||
Protobuf: ProtobufContentTypeHandler,
|
||||
};
|
||||
export function newHermesClient(rootUrl, contentTypeHandler) {
|
||||
const hci = new HermesClientImpl(rootUrl, contentTypeHandler);
|
||||
hci.mailbox().then((mbox) => {
|
||||
const correlations = hci.correlations;
|
||||
hci.channelMessageSubscribe({
|
||||
id: "rpc-inbox",
|
||||
state: "rpc-inbox",
|
||||
readerKey: mbox.readerKey,
|
||||
channel: "rpc-inbox",
|
||||
startSeq: "all"
|
||||
}, (me, msg) => {
|
||||
var _a, _b, _c, _d, _e, _f;
|
||||
if (me.messageBytes) {
|
||||
try {
|
||||
const msg = Message.decode(me.messageBytes);
|
||||
const endPoint = (_b = (_a = msg.header) === null || _a === void 0 ? void 0 : _a.rpcHeader) === null || _b === void 0 ? void 0 : _b.endPoint;
|
||||
if (((_d = (_c = msg.header) === null || _c === void 0 ? void 0 : _c.rpcHeader) === null || _d === void 0 ? void 0 : _d.frameType) === RpcFrameType.Request && endPoint == "ping") {
|
||||
hci.sendPongResponse(mbox, msg, endPoint);
|
||||
}
|
||||
else {
|
||||
const correlationId = (_f = (_e = msg.header) === null || _e === void 0 ? void 0 : _e.rpcHeader) === null || _f === void 0 ? void 0 : _f.correlationId;
|
||||
if (correlationId) {
|
||||
const resolve = correlations.get(correlationId);
|
||||
if (resolve !== undefined) {
|
||||
resolve(msg);
|
||||
}
|
||||
correlations.delete(correlationId);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
console.error("error decoding message", e);
|
||||
}
|
||||
}
|
||||
// noop since we are only interested in the correlationId for rpc and that happens in onMessage
|
||||
});
|
||||
});
|
||||
// send ping every 30 seconds
|
||||
setInterval(() => hci.sendPing(), 30 * 1000);
|
||||
return hci;
|
||||
}
|
||||
/**
|
||||
* Create the mailbox
|
||||
* @param channels
|
||||
* @param rootUrl
|
||||
* @returns
|
||||
*/
|
||||
async function createMailbox(channels, rootUrl) {
|
||||
const mbox = {
|
||||
channels: channels,
|
||||
privateMetadata: {},
|
||||
publicMetadata: {},
|
||||
purgeTimeoutInMillis: 0,
|
||||
closeTimeoutInMillis: 0,
|
||||
extraData: {},
|
||||
};
|
||||
const mboxObj = CreateMailboxRequest.toJSON(mbox);
|
||||
const mboxJson = JSON.stringify(mboxObj);
|
||||
let mailboxResponse = undefined;
|
||||
const response = await fetch(`${rootUrl}/api/create_mailbox`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: mboxJson,
|
||||
});
|
||||
if (response.ok) {
|
||||
const responseJsonStr = await response.text();
|
||||
mailboxResponse = CreateMailboxResponse.fromJSON(JSON.parse(responseJsonStr));
|
||||
}
|
||||
else {
|
||||
throw new Error(`createMailbox failed with status ${response.status}`);
|
||||
}
|
||||
return mailboxResponse;
|
||||
}
|
||||
class Constants {
|
||||
}
|
||||
Constants.rpcInboxChannelName = "rpc-inbox";
|
||||
Constants.rpcSentChannelName = "rpc-sent";
|
||||
class HermesConnection {
|
||||
constructor(clientImpl, mailbox, webSocket) {
|
||||
this.clientImpl = clientImpl;
|
||||
this.mailbox = mailbox;
|
||||
this.webSocket = webSocket;
|
||||
const self = this;
|
||||
webSocket.onmessage = function (event) {
|
||||
if (event.data instanceof ArrayBuffer) {
|
||||
self.onWebSocketBinaryMessage(event.data);
|
||||
}
|
||||
else {
|
||||
self.onWebSocketTextMessage(event.data);
|
||||
}
|
||||
};
|
||||
webSocket.onclose = function (event) {
|
||||
console.log("HermesConnection websocket closed", event);
|
||||
clientImpl.reconnect();
|
||||
};
|
||||
// resend un ack'ed messages
|
||||
clientImpl.sentMessagesWaitingForAck.forEach((smr, idempotentId) => {
|
||||
self.sendSendMessageRequest(smr, false);
|
||||
});
|
||||
}
|
||||
onWebSocketTextMessage(message) {
|
||||
const jsonObj = JSON.parse(message);
|
||||
const m2c = MessageToClient.fromJSON(jsonObj);
|
||||
this.onMessageToClient(m2c);
|
||||
}
|
||||
onWebSocketBinaryMessage(message) {
|
||||
const m2c = MessageToClient.decode(new Uint8Array(message));
|
||||
this.onMessageToClient(m2c);
|
||||
}
|
||||
onMessageToClient(m2c) {
|
||||
var _a, _b, _c;
|
||||
if (m2c.notification !== undefined) {
|
||||
console.log("hermes client received notification " + m2c.notification, m2c.notification);
|
||||
}
|
||||
else if (m2c.messageEnvelope !== undefined) {
|
||||
const me = m2c.messageEnvelope;
|
||||
if (me.messageBytes === undefined) {
|
||||
console.log("hermes client received empty messageEnvelope", m2c.messageEnvelope);
|
||||
}
|
||||
else {
|
||||
const subscriptionId = (_a = me.serverEnvelope) === null || _a === void 0 ? void 0 : _a.subscriptionId;
|
||||
if (subscriptionId) {
|
||||
const activeSub = this.clientImpl.activeSubscriptions.get(subscriptionId);
|
||||
if (activeSub) {
|
||||
const startSeq = (_b = me.serverEnvelope) === null || _b === void 0 ? void 0 : _b.sequence;
|
||||
if (startSeq) {
|
||||
activeSub.protoRawSubscription.startSeq = String(startSeq);
|
||||
}
|
||||
activeSub.onMessageEvent(me);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (m2c.sendMessageResponse !== undefined) {
|
||||
const id = (_c = m2c.sendMessageResponse) === null || _c === void 0 ? void 0 : _c.idempotentId;
|
||||
if (id) {
|
||||
this.clientImpl.sentMessagesWaitingForAck.delete(id);
|
||||
}
|
||||
console.log("hermes client received SendMessageResponse", m2c.sendMessageResponse);
|
||||
}
|
||||
else if (m2c.subscribeResponse !== undefined) {
|
||||
console.log("hermes client received subscribeResponse", m2c.subscribeResponse);
|
||||
}
|
||||
else if (m2c.ping !== undefined) {
|
||||
this.webSocket.send(JSON.stringify({ pong: {} }));
|
||||
}
|
||||
else if (m2c.pong !== undefined) {
|
||||
console.log("hermes client received pong");
|
||||
}
|
||||
}
|
||||
sendMessageFromClient(mfc) {
|
||||
console.log("sending websocket message", mfc);
|
||||
this.clientImpl.contentTypeHandler.sendMessageFromClient(mfc, this.webSocket);
|
||||
}
|
||||
addActiveSubscription(activeSub) {
|
||||
const listeners = this.clientImpl.activeSubscriptions.get(activeSub.subscriptionId);
|
||||
if (listeners) {
|
||||
throw Error(`subscriptionId ${activeSub.subscriptionId} is already subscribed`);
|
||||
}
|
||||
else {
|
||||
this.clientImpl.activeSubscriptions.set(activeSub.subscriptionId, activeSub);
|
||||
}
|
||||
}
|
||||
cdcSubscribe(cdcs, listener) {
|
||||
const subscriptionId = "cdc-" + cdcs.tables.map((t) => t.database + "." + t.table).join("-");
|
||||
const protoCdcs = {
|
||||
id: subscriptionId,
|
||||
matchers: cdcs.tables,
|
||||
startSeq: cdcs.startSeq,
|
||||
};
|
||||
this.sendMessageFromClient({ subscribeRequest: { subscriptions: [{ changeDataCapture: protoCdcs }] } });
|
||||
function onMessage(msg) {
|
||||
const json = new TextDecoder().decode(msg.messageBytes);
|
||||
const cdcEvent = JSON.parse(json);
|
||||
listener(cdcEvent, cdcEvent.data);
|
||||
}
|
||||
this.addActiveSubscription({
|
||||
subscriptionId: subscriptionId,
|
||||
protoRawSubscription: protoCdcs,
|
||||
onMessageEvent: onMessage,
|
||||
protoSubscription: { changeDataCapture: protoCdcs }
|
||||
});
|
||||
}
|
||||
channelMessageSubscribe(ms, listener) {
|
||||
this.rawChannelSubscribe(ms, Message.decode, listener);
|
||||
}
|
||||
channelSendReceiptSubscribe(ms, listener) {
|
||||
this.rawChannelSubscribe(ms, SendReceipt.decode, listener);
|
||||
}
|
||||
rawChannelSubscribe(ms, decoder, listener) {
|
||||
const subscriptionId = ms.id;
|
||||
if (!subscriptionId) {
|
||||
throw new Error("MailboxSubscription id is undefined");
|
||||
}
|
||||
function onMessage(msg) {
|
||||
if (msg.messageBytes === undefined) {
|
||||
console.error("MessageEnvelope.messageBytes is undefined");
|
||||
return;
|
||||
}
|
||||
const a = decoder(msg.messageBytes);
|
||||
listener(msg, a);
|
||||
}
|
||||
this.sendMessageFromClient({ subscribeRequest: { subscriptions: [{ mailbox: ms }] } });
|
||||
this.addActiveSubscription({
|
||||
subscriptionId: subscriptionId,
|
||||
onMessageEvent: onMessage,
|
||||
protoRawSubscription: ms,
|
||||
protoSubscription: { mailbox: ms }
|
||||
});
|
||||
}
|
||||
sendPing() {
|
||||
this.sendMessageFromClient({ ping: {} });
|
||||
}
|
||||
sendSendMessageRequest(smr, registerForAck) {
|
||||
if (registerForAck && smr.idempotentId) {
|
||||
this.clientImpl.sentMessagesWaitingForAck.set(smr.idempotentId, smr);
|
||||
}
|
||||
this.sendMessageFromClient({ sendMessageRequest: smr });
|
||||
}
|
||||
rawRpcCall(request) {
|
||||
var _a;
|
||||
const emptyBytes = new Uint8Array(0);
|
||||
const correlationId = ((_a = this.mailbox.address) !== null && _a !== void 0 ? _a : "") + "-" + this.clientImpl.correlationIdCounter++;
|
||||
const idempotentId = this.mailbox.address + correlationId;
|
||||
const smr = {
|
||||
channel: Constants.rpcInboxChannelName,
|
||||
to: [request.to],
|
||||
idempotentId: idempotentId,
|
||||
message: {
|
||||
header: {
|
||||
rpcHeader: {
|
||||
correlationId: correlationId,
|
||||
endPoint: request.endPoint,
|
||||
frameType: RpcFrameType.Request,
|
||||
errorInfo: undefined,
|
||||
},
|
||||
sender: this.mailbox.address,
|
||||
contentType: request.contentType,
|
||||
extraHeaders: request.headers,
|
||||
senderSequence: 0,
|
||||
},
|
||||
serverEnvelope: undefined,
|
||||
senderEnvelope: {
|
||||
created: Date.now(),
|
||||
},
|
||||
data: request.body !== undefined ? request.body : emptyBytes,
|
||||
},
|
||||
};
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
this.clientImpl.correlations.set(correlationId, resolve);
|
||||
});
|
||||
this.sendSendMessageRequest(smr, true);
|
||||
return promise;
|
||||
}
|
||||
rpcObserverSubscribe(readerKey, listener) {
|
||||
console.log("rpcObserverSubscribe", readerKey);
|
||||
const correlations = new Map();
|
||||
const msInbox = {
|
||||
id: "rpc-inbox-" + readerKey,
|
||||
readerKey: readerKey,
|
||||
channel: "rpc-inbox",
|
||||
startSeq: "first",
|
||||
};
|
||||
this.channelMessageSubscribe(msInbox, (me, msg) => {
|
||||
var _a, _b;
|
||||
const correlationId = (_b = (_a = msg.header) === null || _a === void 0 ? void 0 : _a.rpcHeader) === null || _b === void 0 ? void 0 : _b.correlationId;
|
||||
if (correlationId) {
|
||||
var correlation = correlations.get(correlationId);
|
||||
if (!correlation) {
|
||||
correlation = new RpcRequestResponse(correlationId);
|
||||
correlations.set(correlationId, correlation);
|
||||
}
|
||||
correlation.inboxEnvelope = me;
|
||||
correlation.inboxMessage = msg;
|
||||
listener(correlation);
|
||||
}
|
||||
});
|
||||
const msSent = {
|
||||
id: "rpc-sent-" + readerKey,
|
||||
readerKey: readerKey,
|
||||
channel: "rpc-sent",
|
||||
startSeq: "first",
|
||||
};
|
||||
this.channelSendReceiptSubscribe(msSent, (me, sr) => {
|
||||
var _a, _b, _c, _d, _e;
|
||||
const msg = (_a = sr.request) === null || _a === void 0 ? void 0 : _a.message;
|
||||
const correlationId = (_e = (_d = (_c = (_b = sr.request) === null || _b === void 0 ? void 0 : _b.message) === null || _c === void 0 ? void 0 : _c.header) === null || _d === void 0 ? void 0 : _d.rpcHeader) === null || _e === void 0 ? void 0 : _e.correlationId;
|
||||
if (correlationId !== undefined) {
|
||||
var correlation = correlations.get(correlationId);
|
||||
if (correlation === undefined) {
|
||||
correlation = new RpcRequestResponse(correlationId);
|
||||
correlations.set(correlationId, correlation);
|
||||
}
|
||||
correlation.sentMessage = msg;
|
||||
correlation.sendReceiptEnvelope = me;
|
||||
correlation.sendReceipt = sr;
|
||||
listener(correlation);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
class HermesClientImpl {
|
||||
constructor(rootUrl, contentTypeHandler) {
|
||||
this.correlationIdCounter = 0;
|
||||
this.correlations = new Map();
|
||||
this.activeSubscriptions = new Map();
|
||||
this.sentMessagesWaitingForAck = new Map();
|
||||
const thisHermesClientImpl = this;
|
||||
this.rootUrl = rootUrl;
|
||||
this.contentTypeHandler = contentTypeHandler;
|
||||
this.mailboxResponseP = createMailbox([Constants.rpcInboxChannelName, Constants.rpcSentChannelName], rootUrl);
|
||||
var tempMailboxResponseP = this.mailboxResponseP;
|
||||
var tempWsUrl = new URL(rootUrl);
|
||||
tempWsUrl.protocol = tempWsUrl.protocol.replace("http", "ws");
|
||||
tempWsUrl.pathname = contentTypeHandler.webSocketUrlPath;
|
||||
this.wsUrl = tempWsUrl.toString();
|
||||
this.currentConn = this.newHermesConnection();
|
||||
}
|
||||
sendPongResponse(mbox, pingMsg, endPoint) {
|
||||
var _a, _b, _c, _d, _e, _f;
|
||||
const correlationId = (_b = (_a = pingMsg.header) === null || _a === void 0 ? void 0 : _a.rpcHeader) === null || _b === void 0 ? void 0 : _b.correlationId;
|
||||
const sender = (_c = pingMsg === null || pingMsg === void 0 ? void 0 : pingMsg.header) === null || _c === void 0 ? void 0 : _c.sender;
|
||||
const contentType = (_e = (_d = pingMsg === null || pingMsg === void 0 ? void 0 : pingMsg.header) === null || _d === void 0 ? void 0 : _d.contentType) !== null && _e !== void 0 ? _e : ContentType.UnspecifiedCT;
|
||||
if (correlationId !== undefined && sender !== undefined) {
|
||||
var ping = {};
|
||||
if (pingMsg.data !== undefined) {
|
||||
if (contentType == ContentType.Json) {
|
||||
ping = Ping.fromJSON(pingMsg.data);
|
||||
}
|
||||
else {
|
||||
ping = Ping.decode(pingMsg.data);
|
||||
}
|
||||
}
|
||||
const pong = { payload: ping.payload };
|
||||
var data;
|
||||
if (contentType == ContentType.Json) {
|
||||
data = new TextEncoder().encode(JSON.stringify(Pong.toJSON(pong)));
|
||||
}
|
||||
else {
|
||||
data = Pong.encode(pong).finish();
|
||||
}
|
||||
const idempotentId = mbox.address + correlationId;
|
||||
const smr = {
|
||||
channel: Constants.rpcInboxChannelName,
|
||||
to: [sender],
|
||||
idempotentId: idempotentId,
|
||||
message: {
|
||||
header: {
|
||||
rpcHeader: {
|
||||
correlationId: correlationId,
|
||||
endPoint: endPoint,
|
||||
frameType: RpcFrameType.SuccessResponse,
|
||||
errorInfo: undefined,
|
||||
},
|
||||
sender: mbox.address,
|
||||
contentType: (_f = pingMsg === null || pingMsg === void 0 ? void 0 : pingMsg.header) === null || _f === void 0 ? void 0 : _f.contentType,
|
||||
},
|
||||
serverEnvelope: undefined,
|
||||
senderEnvelope: {
|
||||
created: Date.now(),
|
||||
},
|
||||
data: data,
|
||||
},
|
||||
};
|
||||
this.withConn((conn) => {
|
||||
conn.sendSendMessageRequest(smr, true);
|
||||
});
|
||||
}
|
||||
else {
|
||||
console.log("ignoring ping no correlation id", pingMsg);
|
||||
}
|
||||
}
|
||||
reconnect() {
|
||||
this.currentConn = this.newHermesConnection();
|
||||
}
|
||||
newHermesConnection() {
|
||||
const outerThis = this;
|
||||
return new Promise((resolve, reject) => {
|
||||
this.mailboxResponseP.then((mbox) => {
|
||||
var webSocket = new WebSocket(this.wsUrl);
|
||||
webSocket.binaryType = "arraybuffer";
|
||||
webSocket.onopen = function (event) {
|
||||
console.log("hermes client websocket opened, sending first message");
|
||||
const resubscriptions = Object.values(outerThis.activeSubscriptions).map((as) => { return as.protoSubscription; });
|
||||
// send first message
|
||||
const firstMessage = {
|
||||
senderInfo: {
|
||||
readerKey: mbox.readerKey,
|
||||
address: mbox.address,
|
||||
},
|
||||
subscriptions: resubscriptions,
|
||||
mailboxTimeoutInMs: 2 * 60 * 1000, // 2 minutes
|
||||
};
|
||||
const mfc = {
|
||||
firstMessage: firstMessage,
|
||||
};
|
||||
console.log("sending first message");
|
||||
outerThis.contentTypeHandler.sendMessageFromClient(mfc, webSocket);
|
||||
console.log("resolving promise");
|
||||
resolve(new HermesConnection(outerThis, mbox, webSocket));
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
mailbox() {
|
||||
return this.mailboxResponseP;
|
||||
}
|
||||
async withConn(fn) {
|
||||
return this.currentConn.then((conn) => fn(conn));
|
||||
}
|
||||
async withConnP(fn) {
|
||||
return this.currentConn.then((conn) => fn(conn));
|
||||
}
|
||||
rawRpcCall(request) {
|
||||
return this.withConnP((conn) => {
|
||||
return conn.rawRpcCall(request);
|
||||
});
|
||||
}
|
||||
cdcSubscribe(cdcs, listener) {
|
||||
this.withConn((conn) => {
|
||||
conn.cdcSubscribe(cdcs, listener);
|
||||
});
|
||||
}
|
||||
rpcObserverSubscribe(readerKey, listener) {
|
||||
console.log("outer rpcObserverSubscribe", readerKey);
|
||||
this.withConn((conn) => {
|
||||
console.log("inner rpcObserverSubscribe", readerKey);
|
||||
conn.rpcObserverSubscribe(readerKey, listener);
|
||||
});
|
||||
}
|
||||
channelMessageSubscribe(ms, listener) {
|
||||
this.withConn((conn) => {
|
||||
conn.channelMessageSubscribe(ms, listener);
|
||||
});
|
||||
}
|
||||
channelSendReceiptSubscribe(ms, listener) {
|
||||
this.withConn((conn) => {
|
||||
conn.channelSendReceiptSubscribe(ms, listener);
|
||||
});
|
||||
}
|
||||
sendPing() {
|
||||
this.withConn((conn) => {
|
||||
conn.sendPing();
|
||||
});
|
||||
}
|
||||
}
|
||||
export class RpcRequestResponse {
|
||||
constructor(correlationId) {
|
||||
this.correlationId = correlationId;
|
||||
}
|
||||
role() {
|
||||
const ic = this.isClient();
|
||||
if (ic) {
|
||||
return "client";
|
||||
}
|
||||
else if (ic === false) {
|
||||
return "server";
|
||||
}
|
||||
}
|
||||
contentType() {
|
||||
var _a, _b, _c, _d, _e, _f;
|
||||
const contentType = (_f = (_c = (_b = (_a = this.requestMessage()) === null || _a === void 0 ? void 0 : _a.header) === null || _b === void 0 ? void 0 : _b.contentType) !== null && _c !== void 0 ? _c : (_e = (_d = this.responseMessage()) === null || _d === void 0 ? void 0 : _d.header) === null || _e === void 0 ? void 0 : _e.contentType) !== null && _f !== void 0 ? _f : ContentType.UnspecifiedCT;
|
||||
return contentType;
|
||||
}
|
||||
isProtobuf() {
|
||||
return this.contentType() === ContentType.Protobuf;
|
||||
}
|
||||
isJson() {
|
||||
return this.contentType() === ContentType.Json;
|
||||
}
|
||||
isClient() {
|
||||
var _a, _b, _c, _d, _e, _f;
|
||||
const inboxFrameType = (_c = (_b = (_a = this.inboxMessage) === null || _a === void 0 ? void 0 : _a.header) === null || _b === void 0 ? void 0 : _b.rpcHeader) === null || _c === void 0 ? void 0 : _c.frameType;
|
||||
const sentFrameType = (_f = (_e = (_d = this.sentMessage) === null || _d === void 0 ? void 0 : _d.header) === null || _e === void 0 ? void 0 : _e.rpcHeader) === null || _f === void 0 ? void 0 : _f.frameType;
|
||||
if (sentFrameType === RpcFrameType.Request) {
|
||||
return true;
|
||||
}
|
||||
else if (inboxFrameType === RpcFrameType.Request) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
hasRequestAndResponse() {
|
||||
return this.sendReceiptEnvelope && this.inboxEnvelope ? true : false;
|
||||
}
|
||||
timeStarted() {
|
||||
var _a, _b, _c, _d;
|
||||
const ic = this.isClient();
|
||||
var time = undef();
|
||||
if (ic === true) {
|
||||
time = (_b = (_a = this.sendReceiptEnvelope) === null || _a === void 0 ? void 0 : _a.serverEnvelope) === null || _b === void 0 ? void 0 : _b.created;
|
||||
}
|
||||
else if (ic === false) {
|
||||
time = (_d = (_c = this.inboxEnvelope) === null || _c === void 0 ? void 0 : _c.serverEnvelope) === null || _d === void 0 ? void 0 : _d.created;
|
||||
}
|
||||
if (time) {
|
||||
return new Date(time);
|
||||
}
|
||||
}
|
||||
timeStartedL() {
|
||||
var _a, _b, _c, _d;
|
||||
const ic = this.isClient();
|
||||
var time = undef();
|
||||
if (ic === true) {
|
||||
time = (_b = (_a = this.sendReceiptEnvelope) === null || _a === void 0 ? void 0 : _a.serverEnvelope) === null || _b === void 0 ? void 0 : _b.created;
|
||||
}
|
||||
else if (ic === false) {
|
||||
time = (_d = (_c = this.inboxEnvelope) === null || _c === void 0 ? void 0 : _c.serverEnvelope) === null || _d === void 0 ? void 0 : _d.created;
|
||||
}
|
||||
return time;
|
||||
}
|
||||
timeCompleted() {
|
||||
var _a, _b, _c, _d;
|
||||
const ic = this.isClient();
|
||||
var time = undefined;
|
||||
if (ic === false) {
|
||||
time = (_b = (_a = this.sendReceiptEnvelope) === null || _a === void 0 ? void 0 : _a.serverEnvelope) === null || _b === void 0 ? void 0 : _b.created;
|
||||
}
|
||||
else if (ic === true) {
|
||||
time = (_d = (_c = this.inboxEnvelope) === null || _c === void 0 ? void 0 : _c.serverEnvelope) === null || _d === void 0 ? void 0 : _d.created;
|
||||
}
|
||||
if (time) {
|
||||
return new Date(time);
|
||||
}
|
||||
}
|
||||
durationInMillis() {
|
||||
var _a, _b;
|
||||
const ts = (_a = this.timeStarted()) === null || _a === void 0 ? void 0 : _a.getTime();
|
||||
const tc = (_b = this.timeCompleted()) === null || _b === void 0 ? void 0 : _b.getTime();
|
||||
if (ts && tc) {
|
||||
return tc - ts;
|
||||
}
|
||||
}
|
||||
endPoint() {
|
||||
var _a, _b, _c;
|
||||
return (_c = (_b = (_a = this.requestMessage()) === null || _a === void 0 ? void 0 : _a.header) === null || _b === void 0 ? void 0 : _b.rpcHeader) === null || _c === void 0 ? void 0 : _c.endPoint;
|
||||
}
|
||||
requestMessage() {
|
||||
const ic = this.isClient();
|
||||
if (ic === true) {
|
||||
return this.sentMessage;
|
||||
}
|
||||
else if (ic === false) {
|
||||
return this.inboxMessage;
|
||||
}
|
||||
}
|
||||
requestEnvelope() {
|
||||
const ic = this.isClient();
|
||||
if (ic === true) {
|
||||
return this.sendReceiptEnvelope;
|
||||
}
|
||||
else if (ic === false) {
|
||||
return this.inboxEnvelope;
|
||||
}
|
||||
}
|
||||
responseMessage() {
|
||||
const ic = this.isClient();
|
||||
if (ic === true) {
|
||||
return this.inboxMessage;
|
||||
}
|
||||
else if (ic === false) {
|
||||
return this.sentMessage;
|
||||
}
|
||||
}
|
||||
responseEnvelope() {
|
||||
const ic = this.isClient();
|
||||
if (ic === true) {
|
||||
return this.inboxEnvelope;
|
||||
}
|
||||
else if (ic === false) {
|
||||
return this.sendReceiptEnvelope;
|
||||
}
|
||||
}
|
||||
status() {
|
||||
var _a, _b, _c;
|
||||
const frameType = (_c = (_b = (_a = this.responseMessage()) === null || _a === void 0 ? void 0 : _a.header) === null || _b === void 0 ? void 0 : _b.rpcHeader) === null || _c === void 0 ? void 0 : _c.frameType;
|
||||
if (!frameType) {
|
||||
return "";
|
||||
}
|
||||
else if (frameType === RpcFrameType.ErrorResponse) {
|
||||
return "error";
|
||||
}
|
||||
else if (frameType === RpcFrameType.SuccessResponse) {
|
||||
return "success";
|
||||
}
|
||||
else {
|
||||
return `Unexpected frame types ${frameType}`;
|
||||
}
|
||||
}
|
||||
async processSchema(reqOrResp, data) {
|
||||
if (this.isJson()) {
|
||||
const jsonStr = new TextDecoder().decode(data);
|
||||
return JSON.parse(jsonStr);
|
||||
}
|
||||
else {
|
||||
const endPoint = this.endPoint();
|
||||
if (endPoint === undefined) {
|
||||
return {
|
||||
"error": "no endpoint"
|
||||
};
|
||||
}
|
||||
if (data === undefined) {
|
||||
return {};
|
||||
}
|
||||
return protobufToJson(endPoint, reqOrResp, data);
|
||||
}
|
||||
}
|
||||
async responseObj() {
|
||||
var _a;
|
||||
return this.processSchema("response", (_a = this.responseMessage()) === null || _a === void 0 ? void 0 : _a.data);
|
||||
}
|
||||
async requestObj() {
|
||||
var _a;
|
||||
return this.processSchema("request", (_a = this.requestMessage()) === null || _a === void 0 ? void 0 : _a.data);
|
||||
}
|
||||
}
|
||||
const GlobalClient = {
|
||||
get: memoize(() => newHermesClient("https://hermes-go.ahsrcm.com", JsonContentTypeHandler))
|
||||
};
|
||||
export default GlobalClient;
|
||||
export function runHermesClientTest() {
|
||||
}
|
||||
export function runHermesClientTest2() {
|
||||
// const hc = newHermesClient("https://hermes-go.ahsrcm.com", ContentType.Protobuf);
|
||||
const hc = newHermesClient("https://hermes-go.ahsrcm.com", JsonContentTypeHandler);
|
||||
hc.mailbox().then((mbox) => {
|
||||
const cdcs = {
|
||||
tables: [
|
||||
{
|
||||
database: "nefario",
|
||||
table: "service",
|
||||
},
|
||||
],
|
||||
startSeq: "new",
|
||||
};
|
||||
hc.cdcSubscribe(cdcs, (cdcEvent, a) => {
|
||||
console.log("cdcEvent", cdcEvent);
|
||||
});
|
||||
});
|
||||
// hc.correlatedRpcReader("rrb07167144dc644a0be22a85301afea7e" , (correlation) => {
|
||||
// console.log("correlation", correlation);
|
||||
// });
|
||||
}
|
||||
async function protobufToJson(schemaName, frametype, bytes) {
|
||||
// const mboxObj = CreateMailboxRequest.toJSON(mbox);
|
||||
// const mboxJson = JSON.stringify(mboxObj);
|
||||
// let mailboxResponse: CreateMailboxResponse | undefined = undefined;
|
||||
const rootUrl = GlobalClient.get().rootUrl;
|
||||
const response = await fetch(`${rootUrl}/api/proto_to_json?schema=${schemaName}&frametype=${frametype}`, {
|
||||
method: "POST",
|
||||
body: bytes,
|
||||
});
|
||||
if (response.ok) {
|
||||
const jsonStr = await response.text();
|
||||
return JSON.parse(jsonStr);
|
||||
}
|
||||
else {
|
||||
throw new Error(`proto_to_json failed with status ${response.status}`);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,201 @@
|
|||
import * as _m0 from "../../../../node_modules/protobufjs/minimal";
|
||||
export declare const protobufPackage = "google.protobuf";
|
||||
/**
|
||||
* `NullValue` is a singleton enumeration to represent the null value for the
|
||||
* `Value` type union.
|
||||
*
|
||||
* The JSON representation for `NullValue` is JSON `null`.
|
||||
*/
|
||||
export declare enum NullValue {
|
||||
/** NULL_VALUE - Null value. */
|
||||
NULL_VALUE = 0,
|
||||
UNRECOGNIZED = -1
|
||||
}
|
||||
export declare function nullValueFromJSON(object: any): NullValue;
|
||||
export declare function nullValueToJSON(object: NullValue): string;
|
||||
/**
|
||||
* `Struct` represents a structured data value, consisting of fields
|
||||
* which map to dynamically typed values. In some languages, `Struct`
|
||||
* might be supported by a native representation. For example, in
|
||||
* scripting languages like JS a struct is represented as an
|
||||
* object. The details of that representation are described together
|
||||
* with the proto support for the language.
|
||||
*
|
||||
* The JSON representation for `Struct` is JSON object.
|
||||
*/
|
||||
export interface Struct {
|
||||
/** Unordered map of dynamically typed values. */
|
||||
fields: {
|
||||
[key: string]: any | undefined;
|
||||
};
|
||||
}
|
||||
export interface Struct_FieldsEntry {
|
||||
key: string;
|
||||
value: any | undefined;
|
||||
}
|
||||
/**
|
||||
* `Value` represents a dynamically typed value which can be either
|
||||
* null, a number, a string, a boolean, a recursive struct value, or a
|
||||
* list of values. A producer of value is expected to set one of these
|
||||
* variants. Absence of any variant indicates an error.
|
||||
*
|
||||
* The JSON representation for `Value` is JSON value.
|
||||
*/
|
||||
export interface Value {
|
||||
/** Represents a null value. */
|
||||
nullValue?: NullValue | undefined;
|
||||
/** Represents a double value. */
|
||||
numberValue?: number | undefined;
|
||||
/** Represents a string value. */
|
||||
stringValue?: string | undefined;
|
||||
/** Represents a boolean value. */
|
||||
boolValue?: boolean | undefined;
|
||||
/** Represents a structured value. */
|
||||
structValue?: {
|
||||
[key: string]: any;
|
||||
} | undefined;
|
||||
/** Represents a repeated `Value`. */
|
||||
listValue?: Array<any> | undefined;
|
||||
}
|
||||
/**
|
||||
* `ListValue` is a wrapper around a repeated field of values.
|
||||
*
|
||||
* The JSON representation for `ListValue` is JSON array.
|
||||
*/
|
||||
export interface ListValue {
|
||||
/** Repeated field of dynamically typed values. */
|
||||
values: any[];
|
||||
}
|
||||
export declare const Struct: {
|
||||
encode(message: Struct, writer?: _m0.Writer): _m0.Writer;
|
||||
decode(input: _m0.Reader | Uint8Array, length?: number): Struct;
|
||||
fromJSON(object: any): Struct;
|
||||
toJSON(message: Struct): unknown;
|
||||
create<I extends {
|
||||
fields?: {
|
||||
[x: string]: any;
|
||||
} | undefined;
|
||||
} & {
|
||||
fields?: ({
|
||||
[x: string]: any;
|
||||
} & {
|
||||
[x: string]: any;
|
||||
} & { [K in Exclude<keyof I["fields"], string | number>]: never; }) | undefined;
|
||||
} & { [K_1 in Exclude<keyof I, "fields">]: never; }>(base?: I): Struct;
|
||||
fromPartial<I_1 extends {
|
||||
fields?: {
|
||||
[x: string]: any;
|
||||
} | undefined;
|
||||
} & {
|
||||
fields?: ({
|
||||
[x: string]: any;
|
||||
} & {
|
||||
[x: string]: any;
|
||||
} & { [K_2 in Exclude<keyof I_1["fields"], string | number>]: never; }) | undefined;
|
||||
} & { [K_3 in Exclude<keyof I_1, "fields">]: never; }>(object: I_1): Struct;
|
||||
wrap(object: {
|
||||
[key: string]: any;
|
||||
} | undefined): Struct;
|
||||
unwrap(message: Struct): {
|
||||
[key: string]: any;
|
||||
};
|
||||
};
|
||||
export declare const Struct_FieldsEntry: {
|
||||
encode(message: Struct_FieldsEntry, writer?: _m0.Writer): _m0.Writer;
|
||||
decode(input: _m0.Reader | Uint8Array, length?: number): Struct_FieldsEntry;
|
||||
fromJSON(object: any): Struct_FieldsEntry;
|
||||
toJSON(message: Struct_FieldsEntry): unknown;
|
||||
create<I extends {
|
||||
key?: string | undefined;
|
||||
value?: any | undefined;
|
||||
} & {
|
||||
key?: string | undefined;
|
||||
value?: any | undefined;
|
||||
} & { [K in Exclude<keyof I, keyof Struct_FieldsEntry>]: never; }>(base?: I): Struct_FieldsEntry;
|
||||
fromPartial<I_1 extends {
|
||||
key?: string | undefined;
|
||||
value?: any | undefined;
|
||||
} & {
|
||||
key?: string | undefined;
|
||||
value?: any | undefined;
|
||||
} & { [K_1 in Exclude<keyof I_1, keyof Struct_FieldsEntry>]: never; }>(object: I_1): Struct_FieldsEntry;
|
||||
};
|
||||
export declare const Value: {
|
||||
encode(message: Value, writer?: _m0.Writer): _m0.Writer;
|
||||
decode(input: _m0.Reader | Uint8Array, length?: number): Value;
|
||||
fromJSON(object: any): Value;
|
||||
toJSON(message: Value): unknown;
|
||||
create<I extends {
|
||||
nullValue?: NullValue | undefined;
|
||||
numberValue?: number | undefined;
|
||||
stringValue?: string | undefined;
|
||||
boolValue?: boolean | undefined;
|
||||
structValue?: {
|
||||
[x: string]: any;
|
||||
} | undefined;
|
||||
listValue?: any[] | undefined;
|
||||
} & {
|
||||
nullValue?: NullValue | undefined;
|
||||
numberValue?: number | undefined;
|
||||
stringValue?: string | undefined;
|
||||
boolValue?: boolean | undefined;
|
||||
structValue?: ({
|
||||
[x: string]: any;
|
||||
} & {
|
||||
[x: string]: any;
|
||||
} & { [K in Exclude<keyof I["structValue"], string | number>]: never; }) | undefined;
|
||||
listValue?: (any[] & any[] & { [K_1 in Exclude<keyof I["listValue"], keyof any[]>]: never; }) | undefined;
|
||||
} & { [K_2 in Exclude<keyof I, keyof Value>]: never; }>(base?: I): Value;
|
||||
fromPartial<I_1 extends {
|
||||
nullValue?: NullValue | undefined;
|
||||
numberValue?: number | undefined;
|
||||
stringValue?: string | undefined;
|
||||
boolValue?: boolean | undefined;
|
||||
structValue?: {
|
||||
[x: string]: any;
|
||||
} | undefined;
|
||||
listValue?: any[] | undefined;
|
||||
} & {
|
||||
nullValue?: NullValue | undefined;
|
||||
numberValue?: number | undefined;
|
||||
stringValue?: string | undefined;
|
||||
boolValue?: boolean | undefined;
|
||||
structValue?: ({
|
||||
[x: string]: any;
|
||||
} & {
|
||||
[x: string]: any;
|
||||
} & { [K_3 in Exclude<keyof I_1["structValue"], string | number>]: never; }) | undefined;
|
||||
listValue?: (any[] & any[] & { [K_4 in Exclude<keyof I_1["listValue"], keyof any[]>]: never; }) | undefined;
|
||||
} & { [K_5 in Exclude<keyof I_1, keyof Value>]: never; }>(object: I_1): Value;
|
||||
wrap(value: any): Value;
|
||||
unwrap(message: any): string | number | boolean | Object | null | Array<any> | undefined;
|
||||
};
|
||||
export declare const ListValue: {
|
||||
encode(message: ListValue, writer?: _m0.Writer): _m0.Writer;
|
||||
decode(input: _m0.Reader | Uint8Array, length?: number): ListValue;
|
||||
fromJSON(object: any): ListValue;
|
||||
toJSON(message: ListValue): unknown;
|
||||
create<I extends {
|
||||
values?: any[] | undefined;
|
||||
} & {
|
||||
values?: (any[] & any[] & { [K in Exclude<keyof I["values"], keyof any[]>]: never; }) | undefined;
|
||||
} & { [K_1 in Exclude<keyof I, "values">]: never; }>(base?: I): ListValue;
|
||||
fromPartial<I_1 extends {
|
||||
values?: any[] | undefined;
|
||||
} & {
|
||||
values?: (any[] & any[] & { [K_2 in Exclude<keyof I_1["values"], keyof any[]>]: never; }) | undefined;
|
||||
} & { [K_3 in Exclude<keyof I_1, "values">]: never; }>(object: I_1): ListValue;
|
||||
wrap(array: Array<any> | undefined): ListValue;
|
||||
unwrap(message: ListValue): Array<any>;
|
||||
};
|
||||
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
||||
export type DeepPartial<T> = T extends Builtin ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
|
||||
[K in keyof T]?: DeepPartial<T[K]>;
|
||||
} : Partial<T>;
|
||||
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
||||
export type Exact<P, I extends P> = P extends Builtin ? P : P & {
|
||||
[K in keyof P]: Exact<P[K], I[K]>;
|
||||
} & {
|
||||
[K in Exclude<keyof I, KeysOfUnion<P>>]: never;
|
||||
};
|
||||
export {};
|
||||
|
|
@ -0,0 +1,441 @@
|
|||
/* eslint-disable */
|
||||
import * as _m0 from "../../../../node_modules/protobufjs/minimal";
|
||||
export const protobufPackage = "google.protobuf";
|
||||
/**
|
||||
* `NullValue` is a singleton enumeration to represent the null value for the
|
||||
* `Value` type union.
|
||||
*
|
||||
* The JSON representation for `NullValue` is JSON `null`.
|
||||
*/
|
||||
export var NullValue;
|
||||
(function (NullValue) {
|
||||
/** NULL_VALUE - Null value. */
|
||||
NullValue[NullValue["NULL_VALUE"] = 0] = "NULL_VALUE";
|
||||
NullValue[NullValue["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
|
||||
})(NullValue || (NullValue = {}));
|
||||
export function nullValueFromJSON(object) {
|
||||
switch (object) {
|
||||
case 0:
|
||||
case "NULL_VALUE":
|
||||
return NullValue.NULL_VALUE;
|
||||
case -1:
|
||||
case "UNRECOGNIZED":
|
||||
default:
|
||||
return NullValue.UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
export function nullValueToJSON(object) {
|
||||
switch (object) {
|
||||
case NullValue.NULL_VALUE:
|
||||
return "NULL_VALUE";
|
||||
case NullValue.UNRECOGNIZED:
|
||||
default:
|
||||
return "UNRECOGNIZED";
|
||||
}
|
||||
}
|
||||
function createBaseStruct() {
|
||||
return { fields: {} };
|
||||
}
|
||||
export const Struct = {
|
||||
encode(message, writer = _m0.Writer.create()) {
|
||||
Object.entries(message.fields).forEach(([key, value]) => {
|
||||
if (value !== undefined) {
|
||||
Struct_FieldsEntry.encode({ key: key, value }, writer.uint32(10).fork()).ldelim();
|
||||
}
|
||||
});
|
||||
return writer;
|
||||
},
|
||||
decode(input, length) {
|
||||
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
||||
let end = length === undefined ? reader.len : reader.pos + length;
|
||||
const message = createBaseStruct();
|
||||
while (reader.pos < end) {
|
||||
const tag = reader.uint32();
|
||||
switch (tag >>> 3) {
|
||||
case 1:
|
||||
if (tag !== 10) {
|
||||
break;
|
||||
}
|
||||
const entry1 = Struct_FieldsEntry.decode(reader, reader.uint32());
|
||||
if (entry1.value !== undefined) {
|
||||
message.fields[entry1.key] = entry1.value;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if ((tag & 7) === 4 || tag === 0) {
|
||||
break;
|
||||
}
|
||||
reader.skipType(tag & 7);
|
||||
}
|
||||
return message;
|
||||
},
|
||||
fromJSON(object) {
|
||||
return {
|
||||
fields: isObject(object.fields)
|
||||
? Object.entries(object.fields).reduce((acc, [key, value]) => {
|
||||
acc[key] = value;
|
||||
return acc;
|
||||
}, {})
|
||||
: {},
|
||||
};
|
||||
},
|
||||
toJSON(message) {
|
||||
const obj = {};
|
||||
if (message.fields) {
|
||||
const entries = Object.entries(message.fields);
|
||||
if (entries.length > 0) {
|
||||
obj.fields = {};
|
||||
entries.forEach(([k, v]) => {
|
||||
obj.fields[k] = v;
|
||||
});
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
},
|
||||
create(base) {
|
||||
return Struct.fromPartial(base !== null && base !== void 0 ? base : {});
|
||||
},
|
||||
fromPartial(object) {
|
||||
var _a;
|
||||
const message = createBaseStruct();
|
||||
message.fields = Object.entries((_a = object.fields) !== null && _a !== void 0 ? _a : {}).reduce((acc, [key, value]) => {
|
||||
if (value !== undefined) {
|
||||
acc[key] = value;
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
return message;
|
||||
},
|
||||
wrap(object) {
|
||||
const struct = createBaseStruct();
|
||||
if (object !== undefined) {
|
||||
Object.keys(object).forEach((key) => {
|
||||
struct.fields[key] = object[key];
|
||||
});
|
||||
}
|
||||
return struct;
|
||||
},
|
||||
unwrap(message) {
|
||||
const object = {};
|
||||
if (message.fields) {
|
||||
Object.keys(message.fields).forEach((key) => {
|
||||
object[key] = message.fields[key];
|
||||
});
|
||||
}
|
||||
return object;
|
||||
},
|
||||
};
|
||||
function createBaseStruct_FieldsEntry() {
|
||||
return { key: "", value: undefined };
|
||||
}
|
||||
export const Struct_FieldsEntry = {
|
||||
encode(message, writer = _m0.Writer.create()) {
|
||||
if (message.key !== "") {
|
||||
writer.uint32(10).string(message.key);
|
||||
}
|
||||
if (message.value !== undefined) {
|
||||
Value.encode(Value.wrap(message.value), writer.uint32(18).fork()).ldelim();
|
||||
}
|
||||
return writer;
|
||||
},
|
||||
decode(input, length) {
|
||||
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
||||
let end = length === undefined ? reader.len : reader.pos + length;
|
||||
const message = createBaseStruct_FieldsEntry();
|
||||
while (reader.pos < end) {
|
||||
const tag = reader.uint32();
|
||||
switch (tag >>> 3) {
|
||||
case 1:
|
||||
if (tag !== 10) {
|
||||
break;
|
||||
}
|
||||
message.key = reader.string();
|
||||
continue;
|
||||
case 2:
|
||||
if (tag !== 18) {
|
||||
break;
|
||||
}
|
||||
message.value = Value.unwrap(Value.decode(reader, reader.uint32()));
|
||||
continue;
|
||||
}
|
||||
if ((tag & 7) === 4 || tag === 0) {
|
||||
break;
|
||||
}
|
||||
reader.skipType(tag & 7);
|
||||
}
|
||||
return message;
|
||||
},
|
||||
fromJSON(object) {
|
||||
return {
|
||||
key: isSet(object.key) ? globalThis.String(object.key) : "",
|
||||
value: isSet(object === null || object === void 0 ? void 0 : object.value) ? object.value : undefined,
|
||||
};
|
||||
},
|
||||
toJSON(message) {
|
||||
const obj = {};
|
||||
if (message.key !== "") {
|
||||
obj.key = message.key;
|
||||
}
|
||||
if (message.value !== undefined) {
|
||||
obj.value = message.value;
|
||||
}
|
||||
return obj;
|
||||
},
|
||||
create(base) {
|
||||
return Struct_FieldsEntry.fromPartial(base !== null && base !== void 0 ? base : {});
|
||||
},
|
||||
fromPartial(object) {
|
||||
var _a, _b;
|
||||
const message = createBaseStruct_FieldsEntry();
|
||||
message.key = (_a = object.key) !== null && _a !== void 0 ? _a : "";
|
||||
message.value = (_b = object.value) !== null && _b !== void 0 ? _b : undefined;
|
||||
return message;
|
||||
},
|
||||
};
|
||||
function createBaseValue() {
|
||||
return {
|
||||
nullValue: undefined,
|
||||
numberValue: undefined,
|
||||
stringValue: undefined,
|
||||
boolValue: undefined,
|
||||
structValue: undefined,
|
||||
listValue: undefined,
|
||||
};
|
||||
}
|
||||
export const Value = {
|
||||
encode(message, writer = _m0.Writer.create()) {
|
||||
if (message.nullValue !== undefined) {
|
||||
writer.uint32(8).int32(message.nullValue);
|
||||
}
|
||||
if (message.numberValue !== undefined) {
|
||||
writer.uint32(17).double(message.numberValue);
|
||||
}
|
||||
if (message.stringValue !== undefined) {
|
||||
writer.uint32(26).string(message.stringValue);
|
||||
}
|
||||
if (message.boolValue !== undefined) {
|
||||
writer.uint32(32).bool(message.boolValue);
|
||||
}
|
||||
if (message.structValue !== undefined) {
|
||||
Struct.encode(Struct.wrap(message.structValue), writer.uint32(42).fork()).ldelim();
|
||||
}
|
||||
if (message.listValue !== undefined) {
|
||||
ListValue.encode(ListValue.wrap(message.listValue), writer.uint32(50).fork()).ldelim();
|
||||
}
|
||||
return writer;
|
||||
},
|
||||
decode(input, length) {
|
||||
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
||||
let end = length === undefined ? reader.len : reader.pos + length;
|
||||
const message = createBaseValue();
|
||||
while (reader.pos < end) {
|
||||
const tag = reader.uint32();
|
||||
switch (tag >>> 3) {
|
||||
case 1:
|
||||
if (tag !== 8) {
|
||||
break;
|
||||
}
|
||||
message.nullValue = reader.int32();
|
||||
continue;
|
||||
case 2:
|
||||
if (tag !== 17) {
|
||||
break;
|
||||
}
|
||||
message.numberValue = reader.double();
|
||||
continue;
|
||||
case 3:
|
||||
if (tag !== 26) {
|
||||
break;
|
||||
}
|
||||
message.stringValue = reader.string();
|
||||
continue;
|
||||
case 4:
|
||||
if (tag !== 32) {
|
||||
break;
|
||||
}
|
||||
message.boolValue = reader.bool();
|
||||
continue;
|
||||
case 5:
|
||||
if (tag !== 42) {
|
||||
break;
|
||||
}
|
||||
message.structValue = Struct.unwrap(Struct.decode(reader, reader.uint32()));
|
||||
continue;
|
||||
case 6:
|
||||
if (tag !== 50) {
|
||||
break;
|
||||
}
|
||||
message.listValue = ListValue.unwrap(ListValue.decode(reader, reader.uint32()));
|
||||
continue;
|
||||
}
|
||||
if ((tag & 7) === 4 || tag === 0) {
|
||||
break;
|
||||
}
|
||||
reader.skipType(tag & 7);
|
||||
}
|
||||
return message;
|
||||
},
|
||||
fromJSON(object) {
|
||||
return {
|
||||
nullValue: isSet(object.nullValue) ? nullValueFromJSON(object.nullValue) : undefined,
|
||||
numberValue: isSet(object.numberValue) ? globalThis.Number(object.numberValue) : undefined,
|
||||
stringValue: isSet(object.stringValue) ? globalThis.String(object.stringValue) : undefined,
|
||||
boolValue: isSet(object.boolValue) ? globalThis.Boolean(object.boolValue) : undefined,
|
||||
structValue: isObject(object.structValue) ? object.structValue : undefined,
|
||||
listValue: globalThis.Array.isArray(object.listValue) ? [...object.listValue] : undefined,
|
||||
};
|
||||
},
|
||||
toJSON(message) {
|
||||
const obj = {};
|
||||
if (message.nullValue !== undefined) {
|
||||
obj.nullValue = nullValueToJSON(message.nullValue);
|
||||
}
|
||||
if (message.numberValue !== undefined) {
|
||||
obj.numberValue = message.numberValue;
|
||||
}
|
||||
if (message.stringValue !== undefined) {
|
||||
obj.stringValue = message.stringValue;
|
||||
}
|
||||
if (message.boolValue !== undefined) {
|
||||
obj.boolValue = message.boolValue;
|
||||
}
|
||||
if (message.structValue !== undefined) {
|
||||
obj.structValue = message.structValue;
|
||||
}
|
||||
if (message.listValue !== undefined) {
|
||||
obj.listValue = message.listValue;
|
||||
}
|
||||
return obj;
|
||||
},
|
||||
create(base) {
|
||||
return Value.fromPartial(base !== null && base !== void 0 ? base : {});
|
||||
},
|
||||
fromPartial(object) {
|
||||
var _a, _b, _c, _d, _e, _f;
|
||||
const message = createBaseValue();
|
||||
message.nullValue = (_a = object.nullValue) !== null && _a !== void 0 ? _a : undefined;
|
||||
message.numberValue = (_b = object.numberValue) !== null && _b !== void 0 ? _b : undefined;
|
||||
message.stringValue = (_c = object.stringValue) !== null && _c !== void 0 ? _c : undefined;
|
||||
message.boolValue = (_d = object.boolValue) !== null && _d !== void 0 ? _d : undefined;
|
||||
message.structValue = (_e = object.structValue) !== null && _e !== void 0 ? _e : undefined;
|
||||
message.listValue = (_f = object.listValue) !== null && _f !== void 0 ? _f : undefined;
|
||||
return message;
|
||||
},
|
||||
wrap(value) {
|
||||
const result = createBaseValue();
|
||||
if (value === null) {
|
||||
result.nullValue = NullValue.NULL_VALUE;
|
||||
}
|
||||
else if (typeof value === "boolean") {
|
||||
result.boolValue = value;
|
||||
}
|
||||
else if (typeof value === "number") {
|
||||
result.numberValue = value;
|
||||
}
|
||||
else if (typeof value === "string") {
|
||||
result.stringValue = value;
|
||||
}
|
||||
else if (globalThis.Array.isArray(value)) {
|
||||
result.listValue = value;
|
||||
}
|
||||
else if (typeof value === "object") {
|
||||
result.structValue = value;
|
||||
}
|
||||
else if (typeof value !== "undefined") {
|
||||
throw new globalThis.Error("Unsupported any value type: " + typeof value);
|
||||
}
|
||||
return result;
|
||||
},
|
||||
unwrap(message) {
|
||||
if (message.stringValue !== undefined) {
|
||||
return message.stringValue;
|
||||
}
|
||||
else if ((message === null || message === void 0 ? void 0 : message.numberValue) !== undefined) {
|
||||
return message.numberValue;
|
||||
}
|
||||
else if ((message === null || message === void 0 ? void 0 : message.boolValue) !== undefined) {
|
||||
return message.boolValue;
|
||||
}
|
||||
else if ((message === null || message === void 0 ? void 0 : message.structValue) !== undefined) {
|
||||
return message.structValue;
|
||||
}
|
||||
else if ((message === null || message === void 0 ? void 0 : message.listValue) !== undefined) {
|
||||
return message.listValue;
|
||||
}
|
||||
else if ((message === null || message === void 0 ? void 0 : message.nullValue) !== undefined) {
|
||||
return null;
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
};
|
||||
function createBaseListValue() {
|
||||
return { values: [] };
|
||||
}
|
||||
export const ListValue = {
|
||||
encode(message, writer = _m0.Writer.create()) {
|
||||
for (const v of message.values) {
|
||||
Value.encode(Value.wrap(v), writer.uint32(10).fork()).ldelim();
|
||||
}
|
||||
return writer;
|
||||
},
|
||||
decode(input, length) {
|
||||
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
||||
let end = length === undefined ? reader.len : reader.pos + length;
|
||||
const message = createBaseListValue();
|
||||
while (reader.pos < end) {
|
||||
const tag = reader.uint32();
|
||||
switch (tag >>> 3) {
|
||||
case 1:
|
||||
if (tag !== 10) {
|
||||
break;
|
||||
}
|
||||
message.values.push(Value.unwrap(Value.decode(reader, reader.uint32())));
|
||||
continue;
|
||||
}
|
||||
if ((tag & 7) === 4 || tag === 0) {
|
||||
break;
|
||||
}
|
||||
reader.skipType(tag & 7);
|
||||
}
|
||||
return message;
|
||||
},
|
||||
fromJSON(object) {
|
||||
return { values: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.values) ? [...object.values] : [] };
|
||||
},
|
||||
toJSON(message) {
|
||||
var _a;
|
||||
const obj = {};
|
||||
if ((_a = message.values) === null || _a === void 0 ? void 0 : _a.length) {
|
||||
obj.values = message.values;
|
||||
}
|
||||
return obj;
|
||||
},
|
||||
create(base) {
|
||||
return ListValue.fromPartial(base !== null && base !== void 0 ? base : {});
|
||||
},
|
||||
fromPartial(object) {
|
||||
var _a;
|
||||
const message = createBaseListValue();
|
||||
message.values = ((_a = object.values) === null || _a === void 0 ? void 0 : _a.map((e) => e)) || [];
|
||||
return message;
|
||||
},
|
||||
wrap(array) {
|
||||
const result = createBaseListValue();
|
||||
result.values = array !== null && array !== void 0 ? array : [];
|
||||
return result;
|
||||
},
|
||||
unwrap(message) {
|
||||
if ((message === null || message === void 0 ? void 0 : message.hasOwnProperty("values")) && globalThis.Array.isArray(message.values)) {
|
||||
return message.values;
|
||||
}
|
||||
else {
|
||||
return message;
|
||||
}
|
||||
},
|
||||
};
|
||||
function isObject(value) {
|
||||
return typeof value === "object" && value !== null;
|
||||
}
|
||||
function isSet(value) {
|
||||
return value !== null && value !== undefined;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -10,7 +10,7 @@ case `uname` in
|
|||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
exec "$basedir/node" "$basedir/../tsc/bin/tsc" "$@"
|
||||
exec "$basedir/node" "$basedir/../typescript/bin/tsc" "$@"
|
||||
else
|
||||
exec node "$basedir/../tsc/bin/tsc" "$@"
|
||||
exec node "$basedir/../typescript/bin/tsc" "$@"
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -14,4 +14,4 @@ IF EXIST "%dp0%\node.exe" (
|
|||
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
)
|
||||
|
||||
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\tsc\bin\tsc" %*
|
||||
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\typescript\bin\tsc" %*
|
||||
|
|
|
|||
|
|
@ -11,17 +11,17 @@ $ret=0
|
|||
if (Test-Path "$basedir/node$exe") {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "$basedir/node$exe" "$basedir/../tsc/bin/tsc" $args
|
||||
$input | & "$basedir/node$exe" "$basedir/../typescript/bin/tsc" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../tsc/bin/tsc" $args
|
||||
& "$basedir/node$exe" "$basedir/../typescript/bin/tsc" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../tsc/bin/tsc" $args
|
||||
$input | & "node$exe" "$basedir/../typescript/bin/tsc" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../tsc/bin/tsc" $args
|
||||
& "node$exe" "$basedir/../typescript/bin/tsc" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,15 +102,6 @@
|
|||
"tslib": "^2.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/tsc": {
|
||||
"version": "2.0.4",
|
||||
"resolved": "https://registry.npmjs.org/tsc/-/tsc-2.0.4.tgz",
|
||||
"integrity": "sha512-fzoSieZI5KKJVBYGvwbVZs/J5za84f2lSTLPYf6AGiIf43tZ3GNrI1QzTLcjtyDDP4aLxd46RTZq1nQxe7+k5Q==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"tsc": "bin/tsc"
|
||||
}
|
||||
},
|
||||
"node_modules/tslib": {
|
||||
"version": "2.6.2",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz",
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
# Release
|
||||
|
||||
`npm publish`
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
## DEPRECATED.
|
||||
|
||||
Use [`typescript`](https://www.npmjs.com/package/typescript) to get access to the `tsc` CLI command.
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
#!/usr/bin/env node
|
||||
require('./tsc.js')
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
// @ts-check
|
||||
|
||||
// https://stackoverflow.com/questions/9781218/how-to-change-node-jss-console-font-color
|
||||
const colours = {
|
||||
reset: "\x1b[0m",
|
||||
bright: "\x1b[1m",
|
||||
dim: "\x1b[2m",
|
||||
underscore: "\x1b[4m",
|
||||
blink: "\x1b[5m",
|
||||
reverse: "\x1b[7m",
|
||||
hidden: "\x1b[8m",
|
||||
|
||||
fg: {
|
||||
black: "\x1b[30m",
|
||||
red: "\x1b[31m",
|
||||
green: "\x1b[32m",
|
||||
yellow: "\x1b[33m",
|
||||
blue: "\x1b[34m",
|
||||
magenta: "\x1b[35m",
|
||||
cyan: "\x1b[36m",
|
||||
white: "\x1b[37m",
|
||||
crimson: "\x1b[38m" // Scarlet
|
||||
},
|
||||
bg: {
|
||||
black: "\x1b[40m",
|
||||
red: "\x1b[41m",
|
||||
green: "\x1b[42m",
|
||||
yellow: "\x1b[43m",
|
||||
blue: "\x1b[44m",
|
||||
magenta: "\x1b[45m",
|
||||
cyan: "\x1b[46m",
|
||||
white: "\x1b[47m",
|
||||
crimson: "\x1b[48m"
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
console.log()
|
||||
const msg = " This is not the tsc command you are looking for "
|
||||
console.log(colours.bg.red + " ".repeat(msg.length) + colours.reset)
|
||||
console.log(colours.bg.red + colours.fg.white + msg + colours.reset);
|
||||
console.log(colours.bg.red + " ".repeat(msg.length) + colours.reset)
|
||||
|
||||
console.log()
|
||||
console.log(`To get access to the TypeScript compiler, ${colours.fg.blue}tsc${colours.reset}, from the command line either:\n`)
|
||||
console.log(`- Use ${colours.bright}npm install typescript${colours.reset} to first add TypeScript to your project ${colours.bright}before${colours.reset} using npx`)
|
||||
console.log(`- Use ${colours.bright}yarn${colours.reset} to avoid accidentally running code from un-installed packages`)
|
||||
|
||||
process.exitCode = 1;
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
{
|
||||
"name": "tsc",
|
||||
"version": "2.0.4",
|
||||
"description": "A deprecated release of the TypeScript compiler",
|
||||
"main": "./bin/tsc.js",
|
||||
"bin": {
|
||||
"tsc": "./bin/tsc"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/basarat/tsc.git"
|
||||
},
|
||||
"keywords": [
|
||||
"typescript"
|
||||
],
|
||||
"author": "basaratali@gmail.com",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/basarat/tsc/issues"
|
||||
},
|
||||
"homepage": "https://github.com/basarat/tsc#readme"
|
||||
}
|
||||
|
|
@ -14,7 +14,6 @@
|
|||
"rxjs": "^7.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tsc": "^2.0.4",
|
||||
"typescript": "^5.4.5"
|
||||
}
|
||||
},
|
||||
|
|
@ -116,15 +115,6 @@
|
|||
"tslib": "^2.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/tsc": {
|
||||
"version": "2.0.4",
|
||||
"resolved": "https://registry.npmjs.org/tsc/-/tsc-2.0.4.tgz",
|
||||
"integrity": "sha512-fzoSieZI5KKJVBYGvwbVZs/J5za84f2lSTLPYf6AGiIf43tZ3GNrI1QzTLcjtyDDP4aLxd46RTZq1nQxe7+k5Q==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"tsc": "bin/tsc"
|
||||
}
|
||||
},
|
||||
"node_modules/tslib": {
|
||||
"version": "2.6.2",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz",
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
"license": "ISC",
|
||||
"description": "",
|
||||
"devDependencies": {
|
||||
"tsc": "^2.0.4",
|
||||
"typescript": "^5.4.5"
|
||||
},
|
||||
"dependencies": {
|
||||
|
|
|
|||
|
|
@ -92,11 +92,6 @@ rxjs@^7.8.1:
|
|||
dependencies:
|
||||
tslib "^2.1.0"
|
||||
|
||||
tsc@^2.0.4:
|
||||
version "2.0.4"
|
||||
resolved "https://registry.npmjs.org/tsc/-/tsc-2.0.4.tgz"
|
||||
integrity sha512-fzoSieZI5KKJVBYGvwbVZs/J5za84f2lSTLPYf6AGiIf43tZ3GNrI1QzTLcjtyDDP4aLxd46RTZq1nQxe7+k5Q==
|
||||
|
||||
tslib@^2.1.0:
|
||||
version "2.6.2"
|
||||
resolved "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz"
|
||||
|
|
|
|||
Loading…
Reference in New Issue