UNPKG

convex

Version:

Client for the Convex Cloud

87 lines (86 loc) 3.17 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var remote_query_set_exports = {}; __export(remote_query_set_exports, { RemoteQuerySet: () => RemoteQuerySet }); module.exports = __toCommonJS(remote_query_set_exports); var import_values = require("../../values/index.js"); var import_long = require("../long.js"); var import_logging = require("../logging.js"); class RemoteQuerySet { constructor(queryPath) { this.version = { querySet: 0, ts: import_long.Long.fromNumber(0), identity: 0 }; this.remoteQuerySet = /* @__PURE__ */ new Map(); this.queryPath = queryPath; } transition(transition) { const start = transition.startVersion; if (this.version.querySet !== start.querySet || this.version.ts.notEquals(start.ts) || this.version.identity !== start.identity) { throw new Error(`Invalid start version: ${start.ts}:${start.querySet}`); } for (const modification of transition.modifications) { switch (modification.type) { case "QueryUpdated": { const queryPath = this.queryPath(modification.queryId); if (queryPath) { for (const line of modification.logLines) { (0, import_logging.logToConsole)("info", "query", queryPath, line); } } const value = (0, import_values.jsonToConvex)(modification.value ?? null); this.remoteQuerySet.set(modification.queryId, { success: true, value }); break; } case "QueryFailed": { const queryPath = this.queryPath(modification.queryId); if (queryPath) { for (const line of modification.logLines) { (0, import_logging.logToConsole)("info", "query", queryPath, line); } } this.remoteQuerySet.set(modification.queryId, { success: false, errorMessage: modification.errorMessage }); break; } case "QueryRemoved": { this.remoteQuerySet.delete(modification.queryId); break; } default: { const _ = modification; throw new Error(`Invalid modification ${modification}`); } } } this.version = transition.endVersion; } remoteQueryResults() { return this.remoteQuerySet; } timestamp() { return this.version.ts; } } //# sourceMappingURL=remote_query_set.js.map