Ledger

Types

The types Ledger exports, and when to use them.

Type your config, ops and variables so Luau catches mistakes.

local Config: Ledger.TypedConfig<Data, Ops> = {
	Name = "PlayerData",
	Keys = "Player",
	MustExist = false,
	Erasable = false,
	Default = { Gold = 0, Items = {} },
	Balances = {
		Gold = { Credit = "AddGold" },
	},
}

local function GoldOp(Amount: number): Ledger.OpOf<Ops, "AddGold">
	return { Kind = "AddGold", Amount = Amount }
end

All types are Ledger.<Name>, for example Ledger.Info<Data>. Luau checks them in strict mode with the new type solver. For roblox-ts, the npm package @xoifail/ledger has the same types.

The ones you will use

TypeIs
ReasonOne of the 15 answers, as text.
Info<D>The third value of a no: State, Identity, Key, ShortReason, Name, Outcome. See Answers.
Frozen<D>What Peek and Get give: your data, read only.
TypedConfig<D, O>The table for Ledger.New.
BalanceField<T>One entry of Balances: { Credit?, Debit?, Min?, Max?, Arithmetic? }.
Op<O>An op of any kind in O.
OpOf<O, "Kind">One kind of op. A wrong field is named in the error.
Reducer<D, O>A reducer function.
TypedStore<D, O>, TypedSession<D, O>The store and session objects.
Quantity, KeyPages<K>, VersionPagesThe quantity, key-pager and version-pager objects.
Observer<T>, Connection, Future<T...>See Observers.
CutThe answer of Reset and Erase: { Name, Losses? }.
ClosedThe answer of Quantity:Close: { Removed, Left, Missing }.

Options

EditOptions, CommitOptions, BumpOptions, PeekOptions, DidApplyOptions, ResetOptions<D>, EraseOptions, TxOptions, TakeOptions, ConfirmOptions, GatherOptions, DepositOptions, WithdrawOptions, LegOptions.

Everything else

KeyLike, KeysMode, OpMap, Name, OpId, Applied, Terms<O>, Overloads<O, Shape>, Fate<O>, DidApplyInfo, InfoKey, Identity, Record<D>, LossRecords, PendingItems, KeyVersion, ShortReason, LoadFailedHandler, ResultSchema<D>, Migration, BalanceField<T>, BalanceKindLimits<T>, Amount, Arithmetic<T>, Windows, TotalDeclaration, QuantityDeclaration, KeyOfStore, TxLeg, Leg<S>, TakeLeg, SessionCommon<D, O>, Session<D>, StoreCommon<D>, Store<D>, Config<D>.

Ledger.Took, Ledger.QuantityTotal and Ledger.HoldHandle name the results of Take, Quantity:Total and Hold, so you can type a variable that keeps one (a checkout that holds a hold between two clicks, for example).

An OpId is what Ledger.Id() gives. It is opaque: you cannot turn it into text or build one.

Next: Limits

On this page