fix: revert dev

This commit is contained in:
Barrett Ruth 2026-03-13 17:58:49 -04:00
parent e8ebe154a1
commit c69f297dd5
4 changed files with 160 additions and 12 deletions

View file

@ -1141,18 +1141,60 @@ end
---@class pending.SyncBackend
---@field name string
---@field auth fun(): nil
---@field auth? fun(sub_action?: string): nil
---@field push? fun(): nil
---@field pull? fun(): nil
---@field sync? fun(): nil
---@field health? fun(): nil
---@type table<string, pending.SyncBackend>
local _registered_backends = {}
---@type string[]?
local _sync_backends = nil
---@type table<string, true>?
local _sync_backend_set = nil
---@param name string
---@return pending.SyncBackend?
function M.resolve_backend(name)
if _registered_backends[name] then
return _registered_backends[name]
end
local ok, mod = pcall(require, 'pending.sync.' .. name)
if ok and type(mod) == 'table' and mod.name then
return mod
end
return nil
end
---@param backend pending.SyncBackend
---@return nil
function M.register_backend(backend)
if type(backend) ~= 'table' or type(backend.name) ~= 'string' or backend.name == '' then
log.error('register_backend: backend must have a non-empty `name` field')
return
end
local builtin_ok, builtin = pcall(require, 'pending.sync.' .. backend.name)
if builtin_ok and type(builtin) == 'table' and builtin.name then
log.error('register_backend: backend `' .. backend.name .. '` already exists as a built-in')
return
end
if _registered_backends[backend.name] then
log.error('register_backend: backend `' .. backend.name .. '` is already registered')
return
end
_registered_backends[backend.name] = backend
_sync_backends = nil
_sync_backend_set = nil
end
---@return table<string, pending.SyncBackend>
function M.registered_backends()
return _registered_backends
end
---@return string[], table<string, true>
local function discover_backends()
if _sync_backends then
@ -1169,6 +1211,12 @@ local function discover_backends()
_sync_backend_set[mod.name] = true
end
end
for name, _ in pairs(_registered_backends) do
if not _sync_backend_set[name] then
table.insert(_sync_backends, name)
_sync_backend_set[name] = true
end
end
table.sort(_sync_backends)
return _sync_backends, _sync_backend_set
end
@ -1177,8 +1225,8 @@ end
---@param action? string
---@return nil
local function run_sync(backend_name, action)
local ok, backend = pcall(require, 'pending.sync.' .. backend_name)
if not ok then
local backend = M.resolve_backend(backend_name)
if not backend then
log.error('Unknown sync backend: ' .. backend_name)
return
end
@ -1543,8 +1591,8 @@ function M.auth(args)
local backends_list = discover_backends()
local auth_backends = {}
for _, name in ipairs(backends_list) do
local ok, mod = pcall(require, 'pending.sync.' .. name)
if ok and type(mod.auth) == 'function' then
local mod = M.resolve_backend(name)
if mod and type(mod.auth) == 'function' then
table.insert(auth_backends, { name = name, mod = mod })
end
end