Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Piece and Store namespaces for easier importing types #138

Merged
merged 5 commits into from
Nov 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/lib/structures/AliasPiece.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Piece, PieceContext, PieceJSON, PieceOptions } from './Piece';
import { Piece } from './Piece';

export interface AliasPieceOptions extends PieceOptions {
export interface AliasPieceOptions extends Piece.Options {
/**
* The aliases for the piece.
* @default []
Expand All @@ -17,7 +17,7 @@ export class AliasPiece<O extends AliasPieceOptions = AliasPieceOptions> extends
*/
public aliases: readonly string[];

public constructor(context: PieceContext, options: AliasPieceOptions = {}) {
public constructor(context: Piece.Context, options: AliasPieceOptions = {}) {
super(context, options);
this.aliases = options.aliases ?? [];
}
Expand All @@ -36,13 +36,15 @@ export class AliasPiece<O extends AliasPieceOptions = AliasPieceOptions> extends
/**
* The return type of {@link AliasPiece.toJSON}.
*/
export interface AliasPieceJSON extends PieceJSON {
export interface AliasPieceJSON extends Piece.JSON {
aliases: string[];
options: AliasPieceOptions;
}

export namespace AliasPiece {
export const { Location } = Piece;
export type Options = AliasPieceOptions;
export type Context = PieceContext;
export type Context = Piece.Context;
export type JSON = AliasPieceJSON;
export type LocationJSON = Piece.LocationJSON;
}
2 changes: 2 additions & 0 deletions src/lib/structures/Piece.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ export interface PieceJSON {
}

export namespace Piece {
export const Location = PieceLocation;
export type Options = PieceOptions;
export type Context = PieceContext;
export type JSON = PieceJSON;
export type LocationJSON = PieceLocationJSON;
}
8 changes: 8 additions & 0 deletions src/lib/structures/Store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { LoaderError, LoaderErrorType } from '../errors/LoaderError';
import { container, Container } from '../shared/Container';
import type { HydratedModuleData, ILoaderResultEntry, ILoaderStrategy, ModuleData } from '../strategies/ILoaderStrategy';
import { LoaderStrategy } from '../strategies/LoaderStrategy';
import { StoreRegistry, StoreRegistryEntries } from './StoreRegistry';
import type { Piece } from './Piece';

/**
Expand Down Expand Up @@ -306,3 +307,10 @@ export class Store<T extends Piece> extends Collection<string, T> {
}

type ErrorWithCode = Error & { code: string };

export namespace Store {
export const Registry = StoreRegistry;
export type Options<T extends Piece> = StoreOptions<T>;
export type Logger = StoreLogger;
export type RegistryEntries = StoreRegistryEntries;
}