{"id":"vyon/session-service","name":"session-service","scope":"vyon","platform":"roblox","description":"SessionService is a simple data management service inspired by real world uses of databases.","version":"0.1.4","latest":"0.1.4","versions":["0.1.1","0.1.2","0.1.3","0.1.4"],"license":"MIT","licenseRating":"safe","licenseCaveats":["The package archive does not include its license text; the license is declared in its manifest metadata."],"licenseVerified":false,"dependencies":{"howmanysmall/janitor":{"version":"^1.15.1","alias":"Janitor"},"evaera/promise":{"version":"^4.0.0","alias":"Promise"},"sleitnick/signal":{"version":"^1.5.0","alias":"Signal"}},"integrity":"335c64bfa2dc21f43dbd3b2be83a5506ef50f4363ec3bb916268e431fb54cda4","likes":0,"downloads":0,"install":"forest install vyon/session-service","url":"https://forest.dev/p/roblox/vyon/session-service","files":"https://api.forest.dev/ai/package/roblox/vyon/session-service/files","readme":"# SessionService\r\nSessionService is a simple data management service inspired by real world uses of databases.\r\n\r\nThe service is designed to utilize sharding and load and unload data as needed. Similar to how DataStore2 works in Roblox. Also taking the great stuff from ProfileService and essentially fusing the 2 together.\r\n\r\nThe great thing about this service is that there is a lot of flexibility when it comes to changing data. You can change the data from the instance data (PlayerData folder). This allows you to have a lot of control over how you want to manage your data.\r\n\r\n## Usage\r\n#### Basic Usage\r\n```lua\r\n-- Services:\r\nlocal Players = game:GetService(\"Players\")\r\n\r\n-- Modules:\r\nlocal SessionService = require(script.SessionService)\r\n\r\n-- Variables:\r\nlocal Store = SessionService:GetStore(\"MyDataStore\", {\r\n\tCoins = 0,\r\n})\r\n\r\n-- Functions:\r\nlocal function PlayerAdded(Player: Player)\r\n\tprint(Player.Name, \"has joined!\")\r\n\r\n\t-- Load data:\r\n\tlocal _, Data = Store:LoadAsync(Player)\r\n\t\t:catch(function(Error: string)\r\n\t\t\twarn(Error)\r\n\t\tend)\r\n\t\t:await()\r\n\r\n\t-- Do stuff with data:\r\n\tprint(Data.Coins)\r\n\r\n\t-- We can manually save data:\r\n\tStore:SaveAsync(Player) --> This will queue the data to be saved.\r\n\r\n\tlocal Session: SessionService.Session = SessionService:GetSession(Store.Name, Player)\r\n\r\n\tSession.Updated:Connect(function(Data: table)\r\n\t\twarn(\"Data updated!\")\r\n\tend)\r\n\r\n\ttask.defer(function()\r\n\t\twhile Player:IsDescendantOf(Players) do\r\n\t\t\tSession:QueueUpdate(function()\r\n\t\t\t\tData.Coins += 1\r\n\t\t\t\tprint(Data.Coins)\r\n\t\t\tend)\r\n\r\n\t\t\ttask.wait(1)\r\n\t\tend\r\n\tend)\r\nend\r\n\r\nlocal function PlayerRemoving(Player: Player)\r\n\tprint(Player.Name, \"is leaving!\")\r\n\r\n\t-- Unload data:\r\n\tStore:UnloadAsync(Player)\r\n\t\t:catch(function(Error: string)\r\n\t\t\twarn(Error)\r\n\t\tend)\r\n\t\t:await() --> This will remove the data from the current session, and remove the session lock from the player.\r\nend\r\n\r\n-- Connections:\r\nStore.AutoSaveStart:Connect(function()\r\n\tprint(\"Auto save is starting!\")\r\nend)\r\n\r\nfor _, Player in Players:GetPlayers() do\r\n\ttask.defer(PlayerAdded, Player)\r\nend\r\n\r\nPlayers.PlayerAdded:Connect(PlayerAdded)\r\nPlayers.PlayerRemoving:Connect(PlayerRemoving)\r\n```\r\n\r\n## Documentation\r\n### SessionService\r\n","readmeTruncated":false}