Types
Common types shared among different modules.
Types
PatchOperation
interface PatchOperation {op: "add" | "replace" | "remove"--
The operation type.
path: string--
A JSON Pointer string indicating the target location.
value: any?--
The value to add or replace (used for "add" and "replace"). Optional for "remove".
}Represents a single operation within a JSON Patch array. Used for describing changes between data states.
TxPatch
An array of PatchOperation objects representing the changes made during a transaction.
TxInfo
interface TxInfo {committedData: any--
The last known data state that was successfully saved to the primary DataStore record before the transaction identified by txId began.
txId: string?--
The unique identifier of the transaction currently attempting to modify this data. If nil, no transaction is active or the last one completed and was cleaned up.
txPatch: TxPatch?--
The set of changes (JSON Patch) applied by the transaction identified by txId. This is used to reconstruct the final state if the transaction is confirmed as committed.
}
Holds information about the state of data potentially involved in a transaction.
Used by the Transactions module to determine the correct data to return during reads.
File
interface File {data: any?--
The actual data, if it was stored directly (not sharded). Mutually exclusive with shard and count.
shard: string?--
The unique identifier for the set of shards, if the data was sharded. Mutually exclusive with data.
count: number?--
The total number of shards, if the data was sharded. Mutually exclusive with data.
}Represents the stored data, abstracting away the sharding mechanism.
If the data was small enough, it's stored directly in the data field.
If the data was large and sharded, shard and count are present instead,
pointing to the location and number of data shards stored separately.
DataStoreRecord
interface DataStoreRecord {appliedMigrations: {string}--
A list of names of migration steps that have already been successfully applied to the data associated with this record. Initialized as empty.
file: File--
A File object representing the actual user data. This might contain the data directly or point to shards.
orphanedFiles: {File}--
A list of sharded File objects that are no longer referenced by any active record. This is used for cleanup and garbage collection of unused data. Initialized as empty.
}
The structure of the primary record stored in the main DataStore for each key.
This record contains metadata and a reference (File) to the actual user data.
MigrationStep
interface MigrationStep {name: string--
The unique name of the migration step.
apply: (data: {[string]: any}) → {[string]: any}--
The function that transforms the data for this step.
}
Represents a migration step that can be applied to data when loading it.
Each step has a name and an apply function that takes the data as input
and returns a modified version of the data.
StoreContext<T>
interface StoreContext<T> {name: string--
The name of the store, used for logging and potentially identifying DataStore keys.
template: T--
A default template object representing the initial state for new data entries.
schema: (value: any) → (boolean,string?)--
A validation function (like one created by t) used to check if loaded or modified data conforms to the expected structure. Returns true if valid, or false and an error message string if invalid.
migrationSteps: {MigrationStep}--
A list of migration steps to apply to data when it's loaded, based on the appliedMigrations field in the DataStoreRecord. Initialized as empty.
importLegacyData: ((key: string) → any?)?--
An optional function to load data from a legacy storage system when a key is accessed for the first time in this store.
changedCallbacks: {(key: string,newData: T,oldData: T?) → ()}--
A list of functions to call whenever data for a key is successfully changed. Provides the key, the new data state, and the previous data state (if available). Initialized as empty.
logger: Logger--
A Logger instance used for internal logging within the store and its components.
onLockLost: ((key: string) → ())?--
An optional callback function triggered if the distributed lock for a key is lost unexpectedly (e.g., due to expiration or external interference).
}
Contains all the contextual information and dependencies required for a Store
or PlayerStore instance to operate. This includes configuration, service instances,
callbacks, and underlying storage objects.
RetryHandle<T>
interface RetryHandle<T> {promise: T--
The Promise representing the asynchronous operation being retried. This promise resolves or rejects based on the outcome of the operation after retries.
cancel: () → ()--
A function that can be called to signal cancellation. If called, the retry mechanism will stop further attempts and reject the promise.
}
A handle returned by retry utility functions like hashMapRetry.
It bundles the core Promise with a way to cancel the retry operation.
When the cancel function is called, instead of cancelling the Promise itself,
the retry mechanism is stopped, and the Promise is rejected with a cancellation error
when the next retry attempt is made.