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

Improve docs #211

Merged
merged 16 commits into from
Jun 20, 2024
Merged
Changes from 1 commit
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
Next Next commit
Remove abstract provider plugin logic
  • Loading branch information
rileystephens28 committed Jun 19, 2024
commit 54d69d4cc569bdaedf29a75d79e5e43aab51b0be
57 changes: 0 additions & 57 deletions src/providers/abstract-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,27 +329,6 @@ function getTime(): number {
return new Date().getTime();
}

/**
* An **AbstractPlugin** is used to provide additional internal services to an
* {@link AbstractProvider | **AbstractProvider**} without adding backwards-incompatible changes to method signatures or
* other internal and complex logic.
*
* @category Providers
*/
export interface AbstractProviderPlugin {
/**
* The reverse domain notation of the plugin.
*/
readonly name: string;

/**
* Creates a new instance of the plugin, connected to `provider`.
*
* @param {AbstractProvider} provider - The provider to connect to.
*/
connect(provider: AbstractProvider<any>): AbstractProviderPlugin;
}

/**
* A normalized filter used for {@link PerformActionRequest | **PerformActionRequest**} objects.
*
Expand Down Expand Up @@ -582,7 +561,6 @@ export class AbstractProvider<C = FetchRequest> implements Provider {
_urlMap: Map<Shard, C>;
#connect: FetchRequest[];
#subs: Map<string, Sub>;
#plugins: Map<string, AbstractProviderPlugin>;

// null=unpaused, true=paused+dropWhilePaused, false=paused
#pausedState: null | boolean;
Expand Down Expand Up @@ -632,7 +610,6 @@ export class AbstractProvider<C = FetchRequest> implements Provider {
this.#performCache = new Map();

this.#subs = new Map();
this.#plugins = new Map();
this.#pausedState = null;

this.#destroyed = false;
Expand Down Expand Up @@ -746,39 +723,6 @@ export class AbstractProvider<C = FetchRequest> implements Provider {
return this;
}

/**
* Returns all the registered plug-ins.
*
* @returns {AbstractProviderPlugin[]} An array of all the registered plug-ins.
*/
get plugins(): Array<AbstractProviderPlugin> {
return Array.from(this.#plugins.values());
}

/**
* Attach a new plug-in.
*
* @param {AbstractProviderPlugin} plugin - The plug-in to attach.
*/
attachPlugin(plugin: AbstractProviderPlugin): this {
if (this.#plugins.get(plugin.name)) {
throw new Error(`cannot replace existing plugin: ${plugin.name} `);
}
this.#plugins.set(plugin.name, plugin.connect(this));
return this;
}

/**
* Get a plugin by name.
*
* @param {string} name - The name of the plugin to get.
*
* @returns {AbstractProviderPlugin | null} The plugin, or `null` if not found.
*/
getPlugin<T extends AbstractProviderPlugin = AbstractProviderPlugin>(name: string): null | T {
return <T>this.#plugins.get(name) || null;
}

// Shares multiple identical requests made during the same 250ms
async #perform<T = any>(req: PerformActionRequest): Promise<T> {
const timeout = this.#options.cacheTimeout;
Expand Down Expand Up @@ -1374,7 +1318,6 @@ export class AbstractProvider<C = FetchRequest> implements Provider {
}

async #getBlock(shard: Shard, block: BlockTag | string, includeTransactions: boolean): Promise<any> {
// @TODO: Add CustomBlockPlugin check
if (isHexString(block, 32)) {
return await this.#perform({
method: 'getBlock',
Expand Down