Class: AliasStore<T, StoreName>
The store class which contains AliasPieces.
Extends
Store<T,StoreName>
Type parameters
| Type parameter | Value |
|---|---|
T extends AliasPiece | - |
StoreName extends StoreRegistryKey | StoreRegistryKey |
Constructors
new AliasStore()
new AliasStore<
T,StoreName>(constructor:AbstractConstructor<T>,options:StoreOptions<T,StoreName>):AliasStore<T,StoreName>
Parameters
| Parameter | Type | Description |
|---|---|---|
constructor | AbstractConstructor<T> | The piece constructor this store loads. |
options | StoreOptions<T, StoreName> | The options for the store. |
Returns
AliasStore<T, StoreName>
Inherited from
Source
projects/pieces/src/lib/structures/Store.ts:80
Properties
#calledLoadAll
private#calledLoadAll:boolean=false
Whether or not the store has called loadAll at least once.
Inherited from
Source
projects/pieces/src/lib/structures/Store.ts:69
#walk()
private#walk: (store:Store<T,never>,path:string,logger?:null|StoreLogger) =>AsyncIterableIterator<string>
The walk function for the store.
Parameters
| Parameter | Type |
|---|---|
store | Store<T, never> |
path | string |
logger? | null | StoreLogger |
Returns
AsyncIterableIterator<string>
Inherited from
Source
projects/pieces/src/lib/structures/Store.ts:74
Constructor
readonlyConstructor:AbstractConstructor<T>
Inherited from
Source
projects/pieces/src/lib/structures/Store.ts:56
aliases
readonlyaliases:Collection<string,T>
The aliases referencing to pieces.
Source
projects/pieces/src/lib/structures/AliasStore.ts:13
name
readonlyname:StoreName
Inherited from
Source
projects/pieces/src/lib/structures/Store.ts:57
paths
readonlypaths:Set<string>
Inherited from
Source
projects/pieces/src/lib/structures/Store.ts:58
strategy
readonlystrategy:ILoaderStrategy<T>
Inherited from
Source
projects/pieces/src/lib/structures/Store.ts:59
defaultStrategy
staticdefaultStrategy:ILoaderStrategy<any>
The default strategy, defaults to LoaderStrategy, which is constructed on demand when a store is constructed, when none was set beforehand.
Inherited from
Source
projects/pieces/src/lib/structures/Store.ts:377
logger
staticlogger:null|StoreLogger=null
The default logger, defaults to null.
Inherited from
Source
projects/pieces/src/lib/structures/Store.ts:382
Accessors
container
getcontainer():Container
A reference to the Container object for ease of use.
See
container
Returns
Source
projects/pieces/src/lib/structures/Store.ts:97
Methods
construct()
construct(
Ctor:ILoaderResultEntry<T>,data:HydratedModuleData):T
Constructs a Piece instance.
Parameters
| Parameter | Type | Description |
|---|---|---|
Ctor | ILoaderResultEntry<T> | The Piece's constructor used to build the instance. |
data | HydratedModuleData | The module's information |
Returns
T
An instance of the constructed piece.
Inherited from
Source
projects/pieces/src/lib/structures/Store.ts:335
get()
get(
key:string):undefined|T
Looks up the name by the store, falling back to an alias lookup.
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | The key to look for. |
Returns
undefined | T
Overrides
Store.get
Source
projects/pieces/src/lib/structures/AliasStore.ts:19
has()
has(
key:string):boolean
Checks whether a key is in the store, or is an alias
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | The key to check |
Returns
boolean
Overrides
Store.has
Source
projects/pieces/src/lib/structures/AliasStore.ts:27
insert()
insert(
piece:T):Promise<T>
Inserts a piece into the store, and adds all the aliases.
Parameters
| Parameter | Type | Description |
|---|---|---|
piece | T | The piece to be inserted into the store. |
Returns
Promise<T>
The inserted piece.
Overrides
Source
projects/pieces/src/lib/structures/AliasStore.ts:54
load()
load(
root:string,path:string):Promise<T[]>
Loads one or more pieces from a path.
Parameters
| Parameter | Type | Description |
|---|---|---|
root | string | The root directory the file is from. |
path | string | The path of the file to load, relative to the root. |
Returns
Promise<T[]>
All the loaded pieces.
Inherited from
Source
projects/pieces/src/lib/structures/Store.ts:182
loadAll()
loadAll():
Promise<void>
Loads all pieces from all directories specified by paths.
Returns
Promise<void>
Inherited from
Source
projects/pieces/src/lib/structures/Store.ts:241
loadPiece()
loadPiece(
entry:StoreManuallyRegisteredPiece<StoreName>):Promise<void>
Adds a piece into the store's list of manually registered pieces. If () was called, the
piece will be loaded immediately, otherwise it will be queued until () is called.
All manually registered pieces will be kept even after they are loaded to ensure they can be loaded again if
() is called again.
Parameters
| Parameter | Type | Description |
|---|---|---|
entry | StoreManuallyRegisteredPiece<StoreName> | The entry to load. |
Returns
Promise<void>
Inherited from
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 always throw a TypeError if
entry.pieceis not a class. - This method will always throw a
LoaderErrorif the piece does not extend thestore'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.get('commands').loadPiece({
name: 'ping',
piece: PingCommand
});
Source
projects/pieces/src/lib/structures/Store.ts:154
registerPath()
registerPath(
path:Path):this
Registers a directory into the store.
Parameters
| Parameter | Type | Description |
|---|---|---|
path | Path | The path to be added. |
Returns
this
Inherited from
Example
store
.registerPath(resolve('commands'))
.registerPath(resolve('third-party', 'commands'));
Source
projects/pieces/src/lib/structures/Store.ts:111
resolve()
resolve(
name:string|T):T
Resolves a piece by its name or its instance.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | T | The name of the piece or the instance itself. |
Returns
T
The resolved piece.
Inherited from
Source
projects/pieces/src/lib/structures/Store.ts:282
unload()
unload(
name:string|T):Promise<T>
Unloads a piece given its instance or its name, and removes all the aliases.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | T | The name of the file to load. |
Returns
Promise<T>
Returns the piece that was unloaded.
Overrides
Source
projects/pieces/src/lib/structures/AliasStore.ts:36
unloadAll()
unloadAll():
Promise<T[]>
Unloads all pieces from the store.
Returns
Promise<T[]>