Skip to content

Commit e994d8c

Browse files
authored
feat(piece): add options field to read raw options (#127)
1 parent a3f81e1 commit e994d8c

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/lib/structures/AliasPiece.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export interface AliasPieceOptions extends PieceOptions {
1111
/**
1212
* The piece to be stored in {@link AliasStore} instances.
1313
*/
14-
export class AliasPiece extends Piece {
14+
export class AliasPiece<O extends AliasPieceOptions = AliasPieceOptions> extends Piece<O> {
1515
/**
1616
* The aliases for the piece.
1717
*/
@@ -38,4 +38,5 @@ export class AliasPiece extends Piece {
3838
*/
3939
export interface AliasPieceJSON extends PieceJSON {
4040
aliases: string[];
41+
options: AliasPieceOptions;
4142
}

src/lib/structures/Piece.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export interface PieceOptions {
4949
/**
5050
* The piece to be stored in {@link Store} instances.
5151
*/
52-
export class Piece {
52+
export class Piece<O extends PieceOptions = PieceOptions> {
5353
/**
5454
* The store that contains the piece.
5555
*/
@@ -70,11 +70,17 @@ export class Piece {
7070
*/
7171
public enabled: boolean;
7272

73+
/**
74+
* The raw options passed to this {@link Piece}
75+
*/
76+
public readonly options: O;
77+
7378
public constructor(context: PieceContext, options: PieceOptions = {}) {
7479
this.store = context.store;
7580
this.location = new PieceLocation(context.path, context.root);
7681
this.name = options.name ?? context.name;
7782
this.enabled = options.enabled ?? true;
83+
this.options = options as O;
7884
}
7985

8086
/**
@@ -123,7 +129,8 @@ export class Piece {
123129
return {
124130
location: this.location.toJSON(),
125131
name: this.name,
126-
enabled: this.enabled
132+
enabled: this.enabled,
133+
options: this.options
127134
};
128135
}
129136
}
@@ -135,4 +142,5 @@ export interface PieceJSON {
135142
location: PieceLocationJSON;
136143
name: string;
137144
enabled: boolean;
145+
options: PieceOptions;
138146
}

0 commit comments

Comments
 (0)