{"id":"xoifaii/ledger","name":"ledger","scope":"xoifaii","platform":"roblox","description":"Lock-free event-sourced player data for Roblox. State is a fold over validated ops, no session locks.","version":"7.3.1","latest":"7.3.1","versions":["1.1.0","1.1.1","2.0.0","2.0.1","2.0.2","2.0.3","2.1.0","2.2.0","3.0.0","3.0.1","3.1.1","3.1.2","3.2.0","3.4.0","4.0.0","4.0.1","4.0.2","4.0.3","4.0.4","4.0.5","4.0.6","4.1.0","4.1.1","4.3.0","4.3.1","4.4.0","4.4.1","4.5.0","5.0.0","5.0.1","5.1.1","5.2.0","5.2.1","5.2.2","5.3.0","5.4.0","5.4.1","6.0.0","6.0.1","6.1.0","6.2.0","7.0.0","7.0.1","7.0.2","7.0.3","7.0.4","7.0.5","7.1.0","7.2.0","7.3.0","7.3.1"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{},"integrity":"e38c7c7009547a2f0fe8516a40d12cfe542df40ed44ec96eca3a19855a518628","likes":0,"downloads":1,"install":"forest install xoifaii/ledger","url":"https://forest.dev/p/roblox/xoifaii/ledger","files":"https://api.forest.dev/ai/package/roblox/xoifaii/ledger/files","readme":"<div align=\"center\">\r\n\r\n# Ledger\r\n[![GitHub](https://img.shields.io/badge/GitHub-Ledger-181717?style=for-the-badge&logo=github&logoColor=white)](https://github.com/XoifaiI/Ledger) [![Docs](https://img.shields.io/badge/Docs-Read-8B5CF6?style=for-the-badge)](https://xoifaii.github.io/LedgerDocs/)\r\n\r\n</div>\r\n\r\n## What is this?\r\n\r\nA datastore library for Roblox with no session locks. You never write state. You write down\r\nthe change you want, a function you own decides whether it is valid, and Ledger saves each\r\nchange exactly once.\r\n\r\n```luau\r\ntype PlayerData = {\r\n\tGold: number,\r\n\tItems: { [string]: number },\r\n}\r\n\r\ntype PlayerOps = {\r\n\tSpendGold: { Amount: number },\r\n}\r\n\r\nlocal PlayerStore = Ledger.New<<PlayerData, PlayerOps>>({\r\n\tName = \"PlayerData\",\r\n\tKeys = \"Player\",\r\n\tDefault = { Gold = 100, Items = {} },\r\n\tMustExist = false,\r\n\tErasable = true,\r\n\tReducer = function(Data, Op)\r\n\t\tif Op.Kind == \"SpendGold\" then\r\n\t\t\tif Op.Amount > Data.Gold then\r\n\t\t\t\treturn nil -- refused, on every server\r\n\t\t\tend\r\n\t\t\tlocal New = table.clone(Data)\r\n\t\t\tNew.Gold -= Op.Amount\r\n\t\t\treturn New\r\n\t\tend\r\n\t\treturn nil\r\n\tend,\r\n})\r\n\r\nlocal Session = PlayerStore:Load(Player)\r\nif Session then\r\n\tlocal Ok, Why = Session:Commit({ Kind = \"SpendGold\", Amount = 25 })\r\n\tif not Ok then\r\n\t\twarn(\"Couldn't spend gold:\", Why)\r\n\tend\r\nend\r\n```\r\n\r\nTwo servers spend the same 100 gold at once: the reducer accepts one and refuses the other.\r\nEvery server agrees, every time, and every call says what happened.\r\n\r\nA session lock serializes writers. A validating fold makes the invalid state unreachable,\r\nwhich is a stronger guarantee that also costs nothing when a server crashes: no lease to wait\r\nout, no locked player join stall, no side channel to touch someone offline or on another\r\nserver. Changes are ops with names, and a reducer validates them.\r\n\r\n## Features\r\n\r\n- **Lock free** | every server, same result, no locks\r\n- **Cross server** | write to any player, even offline\r\n- **Entity stores** |  clans, listings, world records\r\n- **Transactions** | up to 29 players or keys, all move or none do\r\n- **Balances** | gold keeps moving while a trade is in progress\r\n- **Limited items** | sold from every server, never oversold\r\n- **Global counters** | every server adds, reading is free\r\n- **Migrations** | old servers can't corrupt new data\r\n- **Idempotent** | a write retried applies one time\r\n- **Typed ops** | name them once, every write is checked\r\n- **Loud misuse** | bad code throws, immediately\r\n\r\n## Installing\r\n\r\n**Wally**\r\n\r\n```toml\r\n[dependencies]\r\nLedger = \"xoifaii/ledger@7.3.1\"\r\n```\r\n\r\n**Model file**: insert the [Ledger](https://github.com/XoifaiI/Ledger/releases) module anywhere server side.\r\n\r\n**roblox-ts**\r\n\r\n```\r\nnpm install @xoifail/ledger\r\n```\r\nThe same types work for TypeScript: see [Types](https://xoifaii.github.io/LedgerDocs/docs/reference/types).\r\n\r\n## License\r\n\r\nThis project has the [MIT License](https://github.com/XoifaiI/Ledger/blob/main/LICENSE).\r\n","readmeTruncated":false}