All Projects β†’ buildthomas β†’ MockDataStoreService

buildthomas / MockDataStoreService

Licence: Apache-2.0 License
Emulation of Roblox's DataStoreService for seamless offline development & testing

Programming Languages

lua
6591 projects

Projects that are alternatives of or similar to MockDataStoreService

jsrobowar
πŸ‘Ύ A port of RoboWar to the web browser using JavaScript and HTML5. (2010)
Stars: ✭ 31 (-20.51%)
Mutual labels:  emulation
Chrome
This is the source of the Roblox+ Google Chrome extension!
Stars: ✭ 27 (-30.77%)
Mutual labels:  roblox
retro-home
Retro Home; your home for retro-gaming πŸ•Ή
Stars: ✭ 76 (+94.87%)
Mutual labels:  emulation
CrystalBoy
C# GameBoy Emulator
Stars: ✭ 93 (+138.46%)
Mutual labels:  emulation
arcade-manager
Arcade management tool to handle your MAME/FBA romsets
Stars: ✭ 104 (+166.67%)
Mutual labels:  emulation
mupen64plus-rsp-cxd4
Exemplary MSP communications simulator using a normalized VU.
Stars: ✭ 26 (-33.33%)
Mutual labels:  emulation
Pyblox
An API wrapper for Roblox written in Python. (Receives Updates)
Stars: ✭ 30 (-23.08%)
Mutual labels:  roblox
FEX
A fast usermode x86 and x86-64 emulator for Arm64
Stars: ✭ 650 (+1566.67%)
Mutual labels:  emulation
dndb
A Deno πŸ¦• persistent, embeddable and optimized NoSQL database for JS & TS
Stars: ✭ 64 (+64.1%)
Mutual labels:  datastore
Aurora
(Deprecated) Aurora is a library that can manage status effects (known as "Auras") in your Roblox game.
Stars: ✭ 23 (-41.03%)
Mutual labels:  roblox
ria-jit
Lightweight and performant dynamic binary translation for RISC–V code on x86–64
Stars: ✭ 38 (-2.56%)
Mutual labels:  emulation
vscode-rojo
Visual Studio Code plugin for Rojo
Stars: ✭ 21 (-46.15%)
Mutual labels:  roblox
server
The ViUR application development framework - legacy version 2.x for Python 2.7
Stars: ✭ 12 (-69.23%)
Mutual labels:  datastore
Healthify
Healthify - An app to track your daily water intake and sleep and boost your work efficiency. Healthify is built using Kotlin and follows all modern android Development practices and hence is a good learning resource for beginners
Stars: ✭ 37 (-5.13%)
Mutual labels:  datastore
mupen64plus-input-sdl
Input plugin for Mupen64Plus v2.0 project using SDL. This is derived from the original Mupen64 blight_input plugin.
Stars: ✭ 36 (-7.69%)
Mutual labels:  emulation
ghidra-emu-fun
Ghidra Emulates Functions
Stars: ✭ 36 (-7.69%)
Mutual labels:  emulation
megado
A SEGA Genesis/Mega Drive emulator in C
Stars: ✭ 16 (-58.97%)
Mutual labels:  emulation
matter
A modern ECS library for Roblox.
Stars: ✭ 39 (+0%)
Mutual labels:  roblox
Adonis
Roblox Server Administration System
Stars: ✭ 134 (+243.59%)
Mutual labels:  roblox
blessed-xterm
XTerm Widget for Blessed Curses Environment
Stars: ✭ 37 (-5.13%)
Mutual labels:  emulation

MockDataStoreService

Emulation of Roblox's DataStoreService for seamless offline development & testing
 

This is a set of modules that emulates datastores in Lua rather than using the actual service. This is useful for testing in offline projects / local place files with code/frameworks that need to have access to datastores.

The MockDataStoreService behaves exactly like DataStoreService: it has the same API, and will also work even if the place is not currently published to a game with Studio API access enabled (it will act as a DataStoreService with no data stored on the back-end, unless you import some data from a json string manually using the module).

A small top-level helper module is provided (DataStoreService) that automatically detects and selects which datastores should be used (real datastores for published games with API access, mock datastores for offline games / published games without API access).

It is recommended to use this code in the structure that it is provided in, and to simply call require(path.to.DataStoreService) instead of game:GetService("DataStoreService") anywhere in your code to use it properly.


Usage:

local DataStoreService = require(the.path.to.DataStoreService)

-- Use as actual DataStoreService, i.e.:

local gds = DataStoreService:GetGlobalDataStore()
local ds = DataStoreService:GetDataStore("TestName", "TestScope")
local ods = DataStoreService:GetOrderedDataStore("TestName")

local value = ds:GetAsync("TestKey")
ds:SetAsync("TestKey", "TestValue")
local value = ds:IncrementAsync("IntegerKey", 3)
local value = ds:UpdateAsync("UpdateKey", function(oldValue) return newValue end)
local value = ds:RemoveAsync("TestKey")
local connection = ds:OnUpdate("UpdateKey", function(value) print(value) end)

local pages = ods:GetSortedAsync(true, 50, 1, 100)
repeat
    for _, pair in ipairs(pages:GetCurrentPage()) do
        local key, value = pair.key, pair.value
        -- (...)
    end
until pages.IsFinished or pages:AdvanceToNextPageAsync()

local budget = DataStoreService:GetRequestBudgetForRequestType(
    Enum.DataStoreRequestType.UpdateAsync
)

-- Import/export data to a specific datastore:

ds:ImportFromJSON({ -- feed table or json string representing contents of datastore
    TestKey = "Hello world!"; -- a key value pair
    AnotherKey = {a = 1, b = 2}; -- another key value pair
    -- (...)
})

print(ds:ExportToJSON())

-- Import/export entirety of DataStoreService:

DataStoreService:ImportFromJSON({ -- feed table or json string
    DataStore = { -- regular datastores
        TestName = { -- name of datastore
            TestScope = { -- scope of datastore
                TestKey = "Hello world!"; -- a key value pair
                AnotherKey = {1,2,3}; -- another key value pair
                -- (...)
            }
        }
    };
    GlobalDataStore = { -- the (one) globaldatastore
        TestKey = "Hello world!"; -- a key value pair
        AnotherKey = {1,2,3}; -- another key value pair
        -- (...)
    };
    OrderedDataStore = { -- ordered datastores
        TestName = { -- name of ordered datastore
            TestScope = { -- scope of ordered datastore
                TestKey = 15; -- a key value pair
                AnotherKey = 3; -- another key value pair
                -- (...)
            }
        }
    };
}

print(DataStoreService:ExportToJSON())

Review the API of datastores here:


Features:

  • Identical API and near-identical behavior compared to real DataStoreService.
  • Error messages are more verbose/accurate than the ones generated by actual datastores, which makes development/bug-fixing easier.
  • Throws descriptive errors for attempts at storing invalid data, telling you exactly which part of the data is invalid. (credit to @Corecii's helper function)
  • Emulates the yielding of datastore requests (waits a random amount of time before returning from the call).
  • Extra API for json-exporting/importing contents of one/all datastores for easy testing.
  • All operations safely deep-copy values where necessary (not possible to alter values in the datastore by externally altering tables, etc).
  • Enforces the "6 seconds between writes on the same key" rule.
  • Enforces datastore budgets correctly: budget are set and increased at the rates of the actual service, requests will be throttled if the budget is exceeded, and if there are too many throttled requests in the queue then new requests will error instead of throttling.
  • Functionality for simulating errors at a certain rate (similar to deprecated/removed Diabolical Mode that Studio used to have).

TODOs:

  • Add more test cases for budgeting
  • Refine existing tests
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].