Skip to main content

Lapis

Types

Migration

type Migration = (any) → any | {
backwardsCompatibleboolean?,
migrate(any) → any
}

CollectionOptions<T>

interface CollectionOptions<T> {
validate((any) → true | (
false,
string
))?--

Takes a document's data and returns true on success or false and an error on fail.

defaultDataT | (keystring) → T--

If set to a function, it's called when a new document is created and is passed the key of the document.

freezeDataboolean?--

If true, data will be deep frozen and can only be updated immutably by calling Document:write. Default: true

migrations{Migration}?--

Migrations take old data and return new data. Order is first to last. For more information, see: Migrations.

}

Functions

setConfig

Lapis.setConfig(partialConfigPartialLapisConfig) → ()

Types

interface PartialLapisConfig {
saveAttemptsnumber?--

Max save/close retry attempts

loadAttemptsnumber?--

Max load retry attempts

loadRetryDelaynumber?--

Seconds between load attempts

showRetryWarningsboolean?--

Show warning on retry

dataStoreService(DataStoreService | table)?--

Useful for mocking DataStoreService, especially in a local place

}
Lapis.setConfig({
	saveAttempts = 10,
	showRetryWarnings = false,
})
-- The default config values:
{
	saveAttempts = 5,
	loadAttempts = 20,
	loadRetryDelay = 1,
	showRetryWarnings = true,
	dataStoreService = DataStoreService,
}

createCollection

Lapis.createCollection(
namestring,
optionsCollectionOptions
) → Collection

Creates a Collection.

Show raw api
{
    "functions": [
        {
            "name": "setConfig",
            "desc": "```lua\nLapis.setConfig({\n\tsaveAttempts = 10,\n\tshowRetryWarnings = false,\n})\n```\n\n```lua\n-- The default config values:\n{\n\tsaveAttempts = 5,\n\tloadAttempts = 20,\n\tloadRetryDelay = 1,\n\tshowRetryWarnings = true,\n\tdataStoreService = DataStoreService,\n}\n```",
            "params": [
                {
                    "name": "partialConfig",
                    "desc": "",
                    "lua_type": "PartialLapisConfig"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 91,
                "path": "src/init.luau"
            }
        },
        {
            "name": "createCollection",
            "desc": "Creates a [Collection].",
            "params": [
                {
                    "name": "name",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "options",
                    "desc": "",
                    "lua_type": "CollectionOptions"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Collection"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 111,
                "path": "src/init.luau"
            }
        }
    ],
    "properties": [],
    "types": [
        {
            "name": "PartialLapisConfig",
            "desc": "",
            "fields": [
                {
                    "name": "saveAttempts",
                    "lua_type": "number?",
                    "desc": "Max save/close retry attempts"
                },
                {
                    "name": "loadAttempts",
                    "lua_type": "number?",
                    "desc": "Max load retry attempts"
                },
                {
                    "name": "loadRetryDelay",
                    "lua_type": "number?",
                    "desc": "Seconds between load attempts"
                },
                {
                    "name": "showRetryWarnings",
                    "lua_type": "boolean?",
                    "desc": "Show warning on retry"
                },
                {
                    "name": "dataStoreService",
                    "lua_type": "(DataStoreService | table)?",
                    "desc": "Useful for mocking DataStoreService, especially in a local place"
                }
            ],
            "source": {
                "line": 64,
                "path": "src/init.luau"
            }
        },
        {
            "name": "Migration",
            "desc": "",
            "lua_type": "(any) -> any | { backwardsCompatible: boolean?, migrate: (any) -> any }",
            "source": {
                "line": 69,
                "path": "src/init.luau"
            }
        },
        {
            "name": "CollectionOptions<T>",
            "desc": "",
            "fields": [
                {
                    "name": "validate",
                    "lua_type": "((any) -> true | (false, string))?",
                    "desc": "Takes a document's data and returns true on success or false and an error on fail."
                },
                {
                    "name": "defaultData",
                    "lua_type": "T | (key: string) -> T",
                    "desc": "If set to a function, it's called when a new document is created and is passed the key of the document."
                },
                {
                    "name": "freezeData",
                    "lua_type": "boolean?",
                    "desc": "If `true`, data will be deep frozen and can only be updated immutably by calling [`Document:write`](Document#write). Default: `true`"
                },
                {
                    "name": "migrations",
                    "lua_type": "{ Migration }?",
                    "desc": "Migrations take old data and return new data. Order is first to last. For more information, see: [Migrations](../docs/Migrations)."
                }
            ],
            "source": {
                "line": 103,
                "path": "src/init.luau"
            }
        }
    ],
    "name": "Lapis",
    "desc": "",
    "source": {
        "line": 53,
        "path": "src/init.luau"
    }
}