Skip to content

@bight-ts/core — Storage

import {
createStorage,
type StorageAdapter,
type StorageContext,
} from "@bight-ts/core";

Wraps a StorageAdapter in a StorageContext with global and guilds stores.

The interface that all storage backends implement.

MethodSignatureDescription
getGlobal<T>(key: string) => Promise<T | undefined>Read a global value
setGlobal<T>(key: string, value: T) => Promise<void>Write a global value
getGuild<T>(guildId: string, key: string) => Promise<T | undefined>Read a guild-scoped value
setGuild<T>(guildId: string, key: string, value: T) => Promise<void>Write a guild-scoped value
patchGuild<T>(guildId: string, patch: Partial<T>) => Promise<T>Shallow-merge into guild state
ensureGuild<T>(guildId: string, defaults: T) => Promise<T>Overlay defaults under existing values

Returned by createStorage(). The high-level API your code uses.

PropertyTypeDescription
adapterStorageAdapterThe raw adapter (for advanced use)
globalGlobalConfigStoreGlobal key-value store
guildsGuildConfigStoreGuild-scoped key-value store
MethodSignature
get<T>(key: string) => Promise<T | undefined>
set<T>(key: string, value: T) => Promise<void>
MethodSignatureNotes
get<T>(guildId, key) => Promise<T | undefined>
set<T>(guildId, key, value) => Promise<void>
patch<T>(guildId, patch) => Promise<T>Shallow merge — existing keys are overwritten, missing keys are preserved
ensure<T>(guildId, defaults) => Promise<T>Defaults fill in missing keys without overwriting existing values

The types the storage layer can persist: string | number | boolean | null | StorageValue[] | { [key: string]: StorageValue }.