From e994d8cef03f1492411c82385bfe3a2f46468210 Mon Sep 17 00:00:00 2001 From: Jeroen Claassens Date: Sun, 17 Oct 2021 13:58:48 +0200 Subject: [PATCH] feat(piece): add `options` field to read raw options (#127) --- src/lib/structures/AliasPiece.ts | 3 ++- src/lib/structures/Piece.ts | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/lib/structures/AliasPiece.ts b/src/lib/structures/AliasPiece.ts index 94ddf2c2..d2c916fa 100644 --- a/src/lib/structures/AliasPiece.ts +++ b/src/lib/structures/AliasPiece.ts @@ -11,7 +11,7 @@ export interface AliasPieceOptions extends PieceOptions { /** * The piece to be stored in {@link AliasStore} instances. */ -export class AliasPiece extends Piece { +export class AliasPiece extends Piece { /** * The aliases for the piece. */ @@ -38,4 +38,5 @@ export class AliasPiece extends Piece { */ export interface AliasPieceJSON extends PieceJSON { aliases: string[]; + options: AliasPieceOptions; } diff --git a/src/lib/structures/Piece.ts b/src/lib/structures/Piece.ts index 460b8aca..feb74e87 100644 --- a/src/lib/structures/Piece.ts +++ b/src/lib/structures/Piece.ts @@ -49,7 +49,7 @@ export interface PieceOptions { /** * The piece to be stored in {@link Store} instances. */ -export class Piece { +export class Piece { /** * The store that contains the piece. */ @@ -70,11 +70,17 @@ export class Piece { */ public enabled: boolean; + /** + * The raw options passed to this {@link Piece} + */ + public readonly options: O; + public constructor(context: PieceContext, options: PieceOptions = {}) { this.store = context.store; this.location = new PieceLocation(context.path, context.root); this.name = options.name ?? context.name; this.enabled = options.enabled ?? true; + this.options = options as O; } /** @@ -123,7 +129,8 @@ export class Piece { return { location: this.location.toJSON(), name: this.name, - enabled: this.enabled + enabled: this.enabled, + options: this.options }; } } @@ -135,4 +142,5 @@ export interface PieceJSON { location: PieceLocationJSON; name: string; enabled: boolean; + options: PieceOptions; }