@sapphire/pieces
Namespaces
Enumerations
Classes
- AliasPiece
- AliasStore
- LoaderError
- LoaderStrategy
- MissingExportsError
- Piece
- PieceLocation
- Store
- StoreRegistry
Interfaces
- AliasPieceJSON
- AliasPieceOptions
- Container
- HydratedModuleData
- ILoaderStrategy
- ModuleData
- PieceContext
- PieceJSON
- PieceLocationJSON
- PieceOptions
- RootData
- StoreLogger
- StoreOptions
- StoreRegistryEntries
Type Aliases
AsyncPreloadResult
Ƭ AsyncPreloadResult<T
>: Promise
<Constructor
<T
> & Record
<PropertyKey
, unknown
>>
Represents the return data from preload
Type parameters
Name | Type |
---|---|
T | extends Piece |
Defined in
projects/pieces/src/lib/strategies/ILoaderStrategy.ts:48
FilterResult
Ƭ FilterResult: ModuleData
| null
The result from the filter.
Defined in
projects/pieces/src/lib/strategies/ILoaderStrategy.ts:38
ILoaderResult
Ƭ ILoaderResult<T
>: AsyncIterableIterator
<ILoaderResultEntry
<T
>>
Represents the return data from load.
Type parameters
Name | Type |
---|---|
T | extends Piece |
Defined in
projects/pieces/src/lib/strategies/ILoaderStrategy.ts:58
ILoaderResultEntry
Ƭ ILoaderResultEntry<T
>: Ctor
<ConstructorParameters
<typeof Piece
>, T
>
Represents an entry from ILoaderResult.
Type parameters
Name | Type |
---|---|
T | extends Piece |
Defined in
projects/pieces/src/lib/strategies/ILoaderStrategy.ts:53
PreloadResult
Ƭ PreloadResult<T
>: Awaitable
<Constructor
<T
> & Record
<PropertyKey
, unknown
>>
Represents the return data from preload
Type parameters
Name | Type |
---|---|
T | extends Piece |
Defined in
projects/pieces/src/lib/strategies/ILoaderStrategy.ts:43
Variables
container
• Const
container: Container
The injected variables that will be accessible to any place. To add an extra property, simply add a property with a regular assignment, and it will be available in all places simultaneously.
Example
// Add a reference for the version:
import { container } from '@sapphire/pieces';
container.version = '1.0.0';
// Can be placed anywhere in a TypeScript file, for JavaScript projects,
// you can create an `augments.d.ts` and place the code there.
declare module '@sapphire/pieces' {
interface Container {
version: string;
}
}
// In any piece, core, plugin, or custom:
export class UserCommand extends Command {
public run(message, args) {
// The injected version is available here:
const { version } = this.container;
// ...
}
}
Example
// In a plugin's context, e.g. API:
class Api extends Plugin {
static [postInitialization]() {
const server = new Server(this);
container.server = server;
// ...
}
}
declare module '@sapphire/pieces' {
interface Container {
server: Server;
}
}
// In any piece, even those that aren't routes nor middlewares:
export class UserRoute extends Route {
public [methods.POST](message, args) {
// The injected server is available here:
const { server } = this.container;
// ...
}
}
Defined in
projects/pieces/src/lib/shared/Container.ts:78
Functions
getRootData
▸ getRootData(): RootData