local Y=require((game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")):WaitForChild("\078\101\118\101\114\109\111\114\101"))local w=Y("\080\114\111\109\105\115\101")local T={}function T.GetAsync(Y,T)assert(typeof(Y)=="\073\110\115\116\097\110\099\101")assert(type(T)=="\115\116\114\105\110\103")return w.spawn(function(w,t)local M=nil local p,f=pcall(function()M=Y:GetAsync(T)end)if not p then return t(f)end return w(M)end)end function T.UpdateAsync(Y,T,t)assert(typeof(Y)=="\073\110\115\116\097\110\099\101")assert(type(T)=="\115\116\114\105\110\103")assert(type(t)=="\102\117\110\099\116\105\111\110")return w.spawn(function(w,M)local p=nil local f,y=pcall(function()p={Y:UpdateAsync(T,t)}end)if not f then return M(y)end if not p then return M("\078\111 \114\101\115\117\108\116 \108\111\097\100\101\100")end return w(unpack(p))end)end function T.SetAsync(Y,T,t)assert(typeof(Y)=="\073\110\115\116\097\110\099\101")assert(type(T)=="\115\116\114\105\110\103")return w.spawn(function(w,M)local p,f=pcall(function()Y:SetAsync(T,t)end)if not p then return M(f)end return w(true)end)end return T
--- Utility methods to interactive with DataStores
-- @module DataStorePromises

local require = require(game:GetService("ReplicatedStorage"):WaitForChild("Nevermore"))

local Promise = require("Promise")

local DataStorePromises = {}

function DataStorePromises.GetAsync(robloxDataStore, key)
	assert(typeof(robloxDataStore) == "Instance")
	assert(type(key) == "string")

	return Promise.spawn(function(resolve, reject)
		local result = nil
		local ok, err = pcall(function()
			result = robloxDataStore:GetAsync(key)
		end)
		if not ok then
			return reject(err)
		end
		return resolve(result)
	end)
end

function DataStorePromises.UpdateAsync(robloxDataStore, key, updateFunc)
	assert(typeof(robloxDataStore) == "Instance")
	assert(type(key) == "string")
	assert(type(updateFunc) == "function")

	return Promise.spawn(function(resolve, reject)
		local result = nil
		local ok, err = pcall(function()
			result = { robloxDataStore:UpdateAsync(key, updateFunc) }
		end)
		if not ok then
			return reject(err)
		end
		if not result then
			return reject("No result loaded")
		end
		return resolve(unpack(result))
	end)
end

function DataStorePromises.SetAsync(robloxDataStore, key, value)
	assert(typeof(robloxDataStore) == "Instance")
	assert(type(key) == "string")

	return Promise.spawn(function(resolve, reject)
		local ok, err = pcall(function()
			robloxDataStore:SetAsync(key, value)
		end)
		if not ok then
			return reject(err)
		end
		return resolve(true)
	end)
end

return DataStorePromises