Class: StoreRegistry
Defined in: projects/pieces/src/lib/structures/StoreRegistry.ts:31
A strict-typed store registry. This is available in container.
Since
2.1.0
Example
// Adding new stores
// Register the store:
container.stores.register(new RouteStore());
// Augment Sapphire to add the new store, in case of a JavaScript
// project, this can be moved to an `Augments.d.ts` (or any other name)
// file somewhere:
declare module '@sapphire/pieces' {
  export interface StoreRegistryEntries {
    routes: RouteStore;
  }
}
Extends
- Collection<- StoreRegistryKey,- StoreRegistryValue>
Constructors
Constructor
new StoreRegistry(
entries?:null| readonly readonly [never,never][]):StoreRegistry
Defined in: node_modules/typescript/lib/lib.es2015.collection.d.ts:50
Parameters
| Parameter | Type | 
|---|---|
| entries? | null| readonly readonly [never,never][] | 
Returns
StoreRegistry
Inherited from
Collection<StoreRegistryKey, StoreRegistryValue>.constructor
Constructor
new StoreRegistry(
iterable?:null|Iterable<readonly [never,never]>):StoreRegistry
Defined in: node_modules/typescript/lib/lib.es2015.collection.d.ts:49
Parameters
| Parameter | Type | 
|---|---|
| iterable? | null|Iterable<readonly [never,never]> | 
Returns
StoreRegistry
Inherited from
Collection<StoreRegistryKey, StoreRegistryValue>.constructor
Methods
deregister()
deregister<
T>(store:Store<T>):this
Defined in: projects/pieces/src/lib/structures/StoreRegistry.ts:126
Deregisters a store.
Type Parameters
| Type Parameter | 
|---|
| TextendsPiece<PieceOptions,never> | 
Parameters
| Parameter | Type | Description | 
|---|---|---|
| store | Store<T> | The store to deregister. | 
Returns
this
Since
2.1.0
get()
Call Signature
get<
K>(key:K):StoreRegistryEntries[K]
Defined in: projects/pieces/src/lib/structures/StoreRegistry.ts:184
Type Parameters
| Type Parameter | 
|---|
| Kextendsnever | 
Parameters
| Parameter | Type | 
|---|---|
| key | K | 
Returns
Inherited from
Collection.get
Call Signature
get(
key:string):undefined
Defined in: projects/pieces/src/lib/structures/StoreRegistry.ts:185
Parameters
| Parameter | Type | 
|---|---|
| key | string | 
Returns
undefined
Inherited from
Collection.get
has()
Call Signature
has(
key:never):true
Defined in: projects/pieces/src/lib/structures/StoreRegistry.ts:186
Parameters
| Parameter | Type | 
|---|---|
| key | never | 
Returns
true
Inherited from
Collection.has
Call Signature
has(
key:string):false
Defined in: projects/pieces/src/lib/structures/StoreRegistry.ts:187
Parameters
| Parameter | Type | 
|---|---|
| key | string | 
Returns
false
Inherited from
Collection.has
load()
load():
Promise<void>
Defined in: projects/pieces/src/lib/structures/StoreRegistry.ts:41
Loads all the registered stores.
Returns
Promise<void>
Since
2.1.0
loadPiece()
loadPiece<
StoreName>(entry:StoreManagerManuallyRegisteredPiece<StoreName>):Promise<void>
Defined in: projects/pieces/src/lib/structures/StoreRegistry.ts:168
If the store was registered, this method will call the store's
() loadPiece() method.
If it was called, the entry will be loaded immediately without queueing.
Type Parameters
| Type Parameter | 
|---|
| StoreNameextendsnever | 
Parameters
| Parameter | Type | Description | 
|---|---|---|
| entry | StoreManagerManuallyRegisteredPiece<StoreName> | The entry to load. | 
Returns
Promise<void>
Remarks
- Pieces loaded this way will have their rootandpathset toVirtualPath, and as such, cannot be reloaded.
- This method is useful in environments where file system access is limited or unavailable, such as when using Serverless Computing.
- This method will not throw an error if a store with the given name does not exist, it will simply be queued until it's registered.
- This method will always throw a TypeError if entry.pieceis not a class.
- If the store is registered, this method will always throw a LoaderErrorif the piece does not extend the registeredstore's piece constructor.
- This operation is atomic, if any of the above errors are thrown, the piece will not be loaded.
Seealso
Since
3.8.0
Example
import { container } from '@sapphire/pieces';
class PingCommand extends Command {
  // ...
}
container.stores.loadPiece({
  store: 'commands',
  name: 'ping',
  piece: PingCommand
});
register()
register<
T>(store:Store<T>):this
Defined in: projects/pieces/src/lib/structures/StoreRegistry.ts:105
Registers a store.
Type Parameters
| Type Parameter | 
|---|
| TextendsPiece<PieceOptions,never> | 
Parameters
| Parameter | Type | Description | 
|---|---|---|
| store | Store<T> | The store to register. | 
Returns
this
Remarks
- This method will allow StoreRegistryto manage the store, meaning:- ()will call the store's- () registerPath()method on call.
- ()will call the store's- () load()method on call.
- ()will call the store's- () loadPiece()method on call.
 
- This will also add all the manually registered pieces by ()in the store.
It is generally recommended to register a store as early as possible, before any of the aforementioned methods are called, otherwise you will have to manually call the aforementioned methods for the store to work properly.
If there were manually registered pieces for this store with (), this method
will add them to the store and delete the queue. Note, however, that this method will not call the store's
() loadPiece() method, and as such, the pieces will not be loaded until
() is called.
Since
2.1.0
registerPath()
registerPath(
rootDirectory:Path):void
Defined in: projects/pieces/src/lib/structures/StoreRegistry.ts:74
Registers all user directories from the process working directory, the default value is obtained by assuming
CommonJS (high accuracy) but with fallback for ECMAScript Modules (reads package.json's main entry, fallbacks
to process.cwd()).
By default, if you have this folder structure:
/home/me/my-bot
├─ src
│  ├─ commands
│  ├─ events
│  └─ main.js
└─ package.json
And you run node src/main.js, the directories /home/me/my-bot/src/commands and /home/me/my-bot/src/events will
be registered for the commands and events stores respectively, since both directories are located in the same
directory as your main file.
Note: this also registers directories for all other stores, even if they don't have a folder, this allows you to create new pieces and hot-load them later anytime.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| rootDirectory | Path | The root directory to register pieces at. | 
Returns
void
Since
2.1.0