local function q(q)local K={}for q,k in pairs(q)do local B={}for q,K in pairs(k)do local k={}for q,K in pairs(K)do k[q]=K end if next(k)~=nil then B[q]=k end end if next(B)~=nil then K[q]=B end end if next(K)~=nil then return K end end local function K(q)if type(q)=="\110\117\109\098\101\114"then if q~=q then return"\078\065\078"elseif q>=math.huge then return"\073\078\070"elseif q<=-math.huge then return"-\073\078\070"end return tostring(q)end return q end local function k()if Constants.YIELD_TIME_MAX>0 then wait(rand:NextNumber(Constants.YIELD_TIME_MIN,Constants.YIELD_TIME_MAX))end end local function B(q)if Constants.SIMULATE_ERROR_RATE>0 and rand:NextNumber()<=Constants.SIMULATE_ERROR_RATE then k()error(q.." \114\101\106\101\099\116\101\100 \119\105\116\104 \101\114\114\111\114 \040\115\105\109\117\108\097\116\101\100 \101\114\114\111\114\041",3)end end

local function prepareDataStoresForExport(origin)
	local dataPrepared = {}

	for name, scopes in pairs(origin) do
		local exportScopes = {}
		for scope, data in pairs(scopes) do
			local exportData = {}
			for key, value in pairs(data) do
				exportData[key] = value
			end
			if next(exportData) ~= nil then -- Only export datastore when non-empty
				exportScopes[scope] = exportData
			end
		end
		if next(exportScopes) ~= nil then -- Only export scope list when non-empty
			dataPrepared[name] = exportScopes
		end
	end

	if next(dataPrepared) ~= nil then -- Only return datastore type when non-empty
		return dataPrepared
	end
end

local function preprocessKey(key)
	if type(key) == "number" then
		if key ~= key then
			return "NAN"
		elseif key >= math.huge then
			return "INF"
		elseif key <= -math.huge then
			return "-INF"
		end
		return tostring(key)
	end
	return key
end

local function simulateYield()
	if Constants.YIELD_TIME_MAX > 0 then
		wait(rand:NextNumber(Constants.YIELD_TIME_MIN, Constants.YIELD_TIME_MAX))
	end
end

local function simulateErrorCheck(method)
	if Constants.SIMULATE_ERROR_RATE > 0 and rand:NextNumber() <= Constants.SIMULATE_ERROR_RATE then
		simulateYield()
		error(method .. " rejected with error (simulated error)", 3)
	end
end
