'use strict'; const supabaseJs = require('@supabase/supabase-js'); 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; }; class SlayQSupabaseDriver { constructor(options = {}) { __publicField(this, "_client"); const url = options.supabaseUrl ?? process.env.SUPABASE_URL; if (!url) { throw new Error("Missing required supabase url."); } const key = options.supabaseServiceKey ?? process.env.SUPABASE_SERVICE_KEY; if (!key) { throw new Error("Missing required supabase service key."); } this._client = supabaseJs.createClient(url, key); } async addJob(jobDef) { const { error } = await this._client.rpc("add_worker_job", jobDef); return error; } async triggerWaiting(event, match, matchVal) { const { error } = await this._client.rpc("trigger_waiting_workers", { _event: event, _match_key: match, _match_value: `${matchVal}` }); return error; } async triggerWaitingInvokers(jobKey, result) { const { error } = await this._client.rpc("trigger_waiting_invoker", { _job_key: jobKey, _result: result ?? null }); return error; } async waitForEvent(jobKey, event, matchKey, matchValue, stepName, expiresAt) { const { error } = await this._client.rpc("wait_for_worker_event", { _job_key: jobKey, _event: event, _match_key: matchKey, _match_value: `${matchValue}`, _step_name: stepName, _expires_at: expiresAt.toISOString() }); return error; } async waitForInvocation(invokerJobKey, targetJobKey, stepName) { const { error } = await this._client.rpc("wait_for_invocation", { _invoker_job_key: invokerJobKey, _target_job_key: targetJobKey, _step_name: stepName }); return error; } async cancelPendingTasks(event, matchKey, matchVal) { const { error } = await this._client.rpc("cancel_pending_tasks", { event, matchkey: matchKey, matchval: `${matchVal}` }); return error; } async updateStepCache(jobKey, stepCache) { const { error } = await this._client.rpc("update_step_cache", { _job_key: jobKey, _step_cache: stepCache ?? null }); return error; } } exports.SlayQSupabaseDriver = SlayQSupabaseDriver;