convex
Version:
Client for the Convex Cloud
75 lines (74 loc) • 2.63 kB
JavaScript
;
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 action_manager_exports = {};
__export(action_manager_exports, {
ActionManager: () => ActionManager
});
module.exports = __toCommonJS(action_manager_exports);
var import_values = require("../../values/index.js");
var import_logging = require("../logging.js");
class ActionManager {
constructor() {
this.inflightActions = /* @__PURE__ */ new Map();
}
request(udfPath, args, actionId) {
const message = {
type: "Action",
actionId,
udfPath,
args: (0, import_values.convexToJson)(args)
};
const result = new Promise((resolve, reject) => {
this.inflightActions.set(actionId, {
message,
onResult: resolve,
onFailure: reject
});
});
return { message, result };
}
onResponse(response) {
const actionInfo = this.inflightActions.get(response.actionId);
if (actionInfo === void 0) {
return;
}
this.inflightActions.delete(response.actionId);
const udfPath = actionInfo.message.udfPath;
for (const line of response.logLines) {
(0, import_logging.logToConsole)("info", "action", udfPath, line);
}
if (response.success) {
actionInfo.onResult((0, import_values.jsonToConvex)(response.result));
} else {
(0, import_logging.logToConsole)("error", "action", udfPath, response.result);
actionInfo.onFailure((0, import_logging.createError)("action", udfPath, response.result));
}
}
hasInflightActions() {
return this.inflightActions.size > 0;
}
restart() {
for (const [actionId, actionInfo] of this.inflightActions) {
this.inflightActions.delete(actionId);
const udfPath = actionInfo.message.udfPath;
actionInfo.onFailure((0, import_logging.createError)("action", udfPath, "Transient error"));
}
}
}
//# sourceMappingURL=action_manager.js.map