'use strict'; const pg = require('pg'); function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; } const pg__default = /*#__PURE__*/_interopDefaultCompat(pg); var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => { __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); return value; }; const { Pool } = pg__default; class SlayQPostgresDriver { constructor(options) { __publicField(this, "_pg"); const connectionUrl = options.connectionUrl ?? process.env.DATABASE_URL; if (!connectionUrl) { throw new Error("Missing required database connection url."); } this._pg = new Pool({ connectionString: connectionUrl }); } async addJob(jobDef) { try { await this._pg.query("select add_worker_job($1, $2, $3, $4, $5, $6, $7, $8, $9)", [ jobDef.identifier, jobDef.payload, jobDef.queue_name ?? null, jobDef.run_at ?? null, jobDef.max_attempts ?? null, jobDef.job_key ?? null, jobDef.priority ?? null, jobDef.flags ?? null, jobDef.job_key_mode ?? null ]); return null; } catch (e) { return { message: e.message ?? "Error adding job." }; } } async cancelPendingTasks(event, matchKey, matchVal) { try { await this._pg.query("select cancel_pending_tasks($1, $2, $3)", [ event, matchKey, `${matchVal}` ]); return null; } catch (e) { return { message: e.message ?? "Error cancelling tasks." }; } } async triggerWaiting(event, match, matchVal) { try { await this._pg.query("select trigger_waiting_workers($1, $2, $3)", [ event, match, `${matchVal}` ]); return null; } catch (e) { return { message: e.message ?? "Error triggering waiting." }; } } async triggerWaitingInvokers(jobKey, result) { try { console.log(result); await this._pg.query("select trigger_waiting_invoker($1, $2)", [ jobKey, JSON.stringify(result) ]); return null; } catch (e) { return { message: e.message ?? "Error triggering waiting invokers." }; } } async waitForEvent(jobKey, event, matchKey, matchValue, stepName, expiresAt) { try { await this._pg.query("select wait_for_worker_event($1, $2, $3, $4, $5, $6)", [ jobKey, event, matchKey, `${matchValue}`, stepName, expiresAt.toISOString() ]); return null; } catch (e) { return { message: e.message ?? "Error waiting for worker event." }; } } async waitForInvocation(invokerJobKey, targetJobKey, stepName) { try { await this._pg.query("select wait_for_invocation($1, $2, $3)", [ invokerJobKey, targetJobKey, stepName ]); return null; } catch (e) { return { message: e.message ?? "Error waiting for invocation." }; } } async updateStepCache(jobKey, stepCache) { try { await this._pg.query("select update_step_cache($1, $2)", [ jobKey, stepCache ]); return null; } catch (e) { return { message: e.message ?? "Error waiting for invocation." }; } } } exports.SlayQPostgresDriver = SlayQPostgresDriver;