-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
AliasPiece.ts
56 lines (50 loc) · 1.54 KB
/
AliasPiece.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { Piece } from './Piece';
import type { StoreRegistryKey } from './StoreRegistry';
export interface AliasPieceOptions extends Piece.Options {
/**
* The aliases for the piece.
* @default []
*/
readonly aliases?: readonly string[];
}
/**
* The piece to be stored in {@link AliasStore} instances.
*/
export class AliasPiece<Options extends AliasPieceOptions = AliasPieceOptions, StoreName extends StoreRegistryKey = StoreRegistryKey> extends Piece<
Options,
StoreName
> {
/**
* The aliases for the piece.
*/
public aliases: readonly string[];
public constructor(context: AliasPiece.LoaderContext<StoreName>, options: AliasPieceOptions = {}) {
super(context, options);
this.aliases = options.aliases ?? [];
}
/**
* Defines the `JSON.stringify` behavior of this alias piece.
*/
public override toJSON(): AliasPiece.JSON {
return {
...super.toJSON(),
aliases: this.aliases.slice()
};
}
}
/**
* The return type of {@link AliasPiece.toJSON}.
*/
export interface AliasPieceJSON extends Piece.JSON {
aliases: string[];
options: AliasPieceOptions;
}
export namespace AliasPiece {
export const { Location } = Piece;
export type Options = AliasPieceOptions;
/** @deprecated Use {@linkcode LoaderContext} instead. */
export type Context<StoreName extends StoreRegistryKey = StoreRegistryKey> = Piece.LoaderContext<StoreName>;
export type LoaderContext<StoreName extends StoreRegistryKey = StoreRegistryKey> = Piece.LoaderContext<StoreName>;
export type JSON = AliasPieceJSON;
export type LocationJSON = Piece.LocationJSON;
}