@catargo/lyra
v0.6.2-velover.5
Published
Lyra (paradoxum-games/lyra) for roblox-ts: session-locked player data with transactions, validation, migrations and sharding. Install it under its roblox-ts name: bun add @rbxts/lyra@npm:@catargo/lyra
Readme
@catargo/lyra
Lyra for roblox-ts: safe player data with session locking, validation, migrations, automatic sharding and multi-key transactions.
This is a fork of 6ixfalls/rbxts-lyra, the roblox-ts build
of paradoxum-games' Luau library. The library stays Luau (src/*.luau) with hand-written typings
(src/*.d.ts), so upstream fixes merge cleanly. Everything around it is a roblox-ts project: bun,
TypeScript 7, and tests in TypeScript that run in Roblox Studio.
Early development. Upstream: "While Lyra has been tested and is used in production, it's still in early development. Some features, like transactions, have not yet been battle-tested in production at scale. Avoid using Lyra in production games where data loss would be catastrophic until it has been tested more thoroughly."
Install
On npm as @catargo/lyra. Install it under its roblox-ts name, so that it lands in
node_modules/@rbxts/lyra:
bun add @rbxts/lyra@npm:@catargo/lyraIt expects the standard roblox-ts Rojo layout (node_modules/@rbxts mapped under
ReplicatedStorage.rbxts_include.node_modules): the Luau requires @rbxts/t beside it and the
roblox-ts runtime Promise in rbxts_include by string path.
Quick start
import { createPlayerStore } from "@rbxts/lyra"; // named exports only
import { Players } from "@rbxts/services";
import { t } from "@rbxts/t";
const store = createPlayerStore({
name: "PlayerData",
template: { coins: 0, inventory: [] as string[] },
schema: t.strictInterface({ coins: t.number, inventory: t.array(t.string) }),
freezeData: false, // keep your tables writable (see below)
studioIgnoresLocks: false, // a Studio playtest must not steal live players' locks
});
Players.PlayerAdded.Connect((player) => {
store.load(player).catch(warn); // Lyra kicks the player itself if the load fails
});
Players.PlayerRemoving.Connect((player) => {
store.unload(player).catch(warn);
});
game.BindToClose(() => store.closeAsync()); // Lyra doesn't bind it for you
// Copy-on-write update: return new data, or false to abort.
store.updateImmutable(player, (data) => ({ ...data, coins: data.coins + 100 }));
// Atomic across players: both change, or neither does.
store.txImmutable([giver, receiver], (state) => {
const from = state.get(giver)!;
const to = state.get(receiver)!;
if (from.coins < 50) return false;
return new Map([
[giver, { ...from, coins: from.coins - 50 }],
[receiver, { ...to, coins: to.coins + 50 }],
]);
});The full guide, with the gotchas (locks and kicks, freezing, JSON-safe data, transaction costs), is
the skill in skills/lyra/SKILL.md, which ships in the package as a Claude Code plugin (below). Upstream's
guides are in docs/ (written for Luau; the TypeScript names are the same).
What this fork changes
All in CHANGELOG.md. In short:
freezeData(defaulttrue):falsestops Lyra deep freezing your data and the tables you hand it.- Configurable timings:
lockDuration(90 s),lockRefreshInterval(two thirds of it, at most 60 s) andautosaveInterval(300 s). studioIgnoresLocks(defaulttrue, as upstream):falsestops a Studio server from taking locks that live servers hold.- A cheaper "did anything change" check after each update (shared subtables are skipped).
- String requires throughout;
@rbxts/tas a range, so it dedupes with yours. - Typing fixes:
PlayerStore.createPlayerStore,unload/unloadAsyncreturn nothing.
The skill for Claude Code
The package carries a Claude Code plugin with the lyra skill. To use it in a project, add to the
project's .claude/settings.json, with the absolute path of the project's installed package:
{
"extraKnownMarketplaces": {
"catargo-lyra": {
"source": { "source": "directory", "path": "C:/path/to/project/node_modules/@rbxts/lyra" }
}
},
"enabledPlugins": { "lyra@catargo-lyra": true }
}- Use an absolute path: Claude Code records a directory marketplace by name, user-wide, at the path it first resolved, so a relative path would stay pinned to the first folder that registered it.
- It loads from
node_modulesin place: a package update reaches it at the next session, or after/reload-plugins. The skill is/lyra:lyra; only its description is in context until it is used.
Development
src/ the package: Lyra's Luau + its .d.ts typings (all that ships)
docs/ upstream's guides, as plain Markdown
test-place/ a Flamework v2 place (rbxts-rs flamework-template) with the tests, in TypeScript
scripts/ typecheck.mjs
skills/ the lyra skill (how to use the package), shipped as a Claude Code plugin
.claude-plugin/ its plugin.json and marketplace.jsonbun install
bun run typecheck # src/*.d.ts with TypeScript 7
bun run test # the tests, in Roblox Studio (see test-place/README.md)
bun run test --cloud --run-timeout 300s # in a real server, on real DataStores (needs the key)
bun run format # StyLua on src/ (rokit install for StyLua)- Keep
.luauchanges small and list each inCHANGELOG.md, so upstream merges stay easy. Keep the.d.tsfiles in step with the Luau. - A change to Lyra comes with a test in
test-place/src/server/tests/. - Release: bump
versioninpackage.json, add aCHANGELOG.mdentry, commit, tagv<version>, checknpm pack --dry-runships nothing private, thennpm publish --tag latest --otp <code>(npm wants a tag for prerelease versions).
Credits
Lyra by paradoxum-games (nomer888, outofbears and contributors). roblox-ts packaging by 6ixfalls. MIT.
