From 3c3917092bbf7241ad8d08c7d733553ea38356c8 Mon Sep 17 00:00:00 2001 From: nigiri <168690269+0xnigir1@users.noreply.github.com> Date: Fri, 23 Aug 2024 18:50:32 -0300 Subject: [PATCH] docs: add tsdocs --- .../src/interfaces/metadata.interface.ts | 24 +++++++++++++++++++ .../src/providers/githubMetadata.provider.ts | 2 ++ .../providers/localFileMetadata.provider.ts | 4 +++- .../src/providers/staticMetadata.provider.ts | 6 +++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/packages/metadata/src/interfaces/metadata.interface.ts b/packages/metadata/src/interfaces/metadata.interface.ts index 1313b14..929aaed 100644 --- a/packages/metadata/src/interfaces/metadata.interface.ts +++ b/packages/metadata/src/interfaces/metadata.interface.ts @@ -1,6 +1,30 @@ import { Token, TokenType, ZKChainMetadata } from "@zkchainhub/shared"; +/** + * Represents a metadata provider that retrieves chains and tokens metadata. + */ export interface IMetadataProvider { + /** + * Retrieves the metadata for ZK chains of the ecosystem + * + * @returns A promise that resolves to the metadata of ZK chains. + * + * @throws {FetchError} + * If there is an issue with the network request. + * + * + * @throws {InvalidSchema} + * If the response data is invalid or cannot be parsed. + */ getChainsMetadata(): Promise; + + /** + * Retrieves metadata for tokens of the ecosystem + * + * @returns A promise that resolves to an array of token metadata. + * + * @throws {FetchError} If there is an issue with the network request. + * @throws {InvalidSchema} If the response data is invalid or cannot be parsed. + */ getTokensMetadata(): Promise[]>; } diff --git a/packages/metadata/src/providers/githubMetadata.provider.ts b/packages/metadata/src/providers/githubMetadata.provider.ts index a64dba8..b38fa1b 100644 --- a/packages/metadata/src/providers/githubMetadata.provider.ts +++ b/packages/metadata/src/providers/githubMetadata.provider.ts @@ -34,6 +34,7 @@ export class GithubMetadataProvider implements IMetadataProvider { }); } + /** @inheritdoc */ async getChainsMetadata(): Promise { let cachedData = await this.cache.get( `${GITHUB_METADATA_PREFIX}-chains`, @@ -66,6 +67,7 @@ export class GithubMetadataProvider implements IMetadataProvider { return cachedData; } + /** @inheritdoc */ async getTokensMetadata(): Promise[]> { let cachedData = await this.cache.get[] | undefined>( `${GITHUB_METADATA_PREFIX}-tokens`, diff --git a/packages/metadata/src/providers/localFileMetadata.provider.ts b/packages/metadata/src/providers/localFileMetadata.provider.ts index 6f0a09d..771d1cf 100644 --- a/packages/metadata/src/providers/localFileMetadata.provider.ts +++ b/packages/metadata/src/providers/localFileMetadata.provider.ts @@ -16,7 +16,7 @@ import { ChainSchema, TokenSchema } from "../schemas/index.js"; export const LOCALFILE_METADATA_PREFIX = "local-metadata"; /** - * Represents a local file metadata provider. + * Represents a provider that retrieves metadata from local files. */ export class LocalFileMetadataProvider implements IMetadataProvider { /** @@ -42,6 +42,7 @@ export class LocalFileMetadataProvider implements IMetadataProvider { } } + /** @inheritdoc */ async getChainsMetadata(): Promise { let cachedData = await this.cache.get( `${LOCALFILE_METADATA_PREFIX}-chains`, @@ -70,6 +71,7 @@ export class LocalFileMetadataProvider implements IMetadataProvider { return cachedData; } + /** @inheritdoc */ async getTokensMetadata(): Promise[]> { let cachedData = await this.cache.get[]>( `${LOCALFILE_METADATA_PREFIX}-tokens`, diff --git a/packages/metadata/src/providers/staticMetadata.provider.ts b/packages/metadata/src/providers/staticMetadata.provider.ts index 39b08c4..fda0440 100644 --- a/packages/metadata/src/providers/staticMetadata.provider.ts +++ b/packages/metadata/src/providers/staticMetadata.provider.ts @@ -2,10 +2,16 @@ import { Token, tokens, TokenType, ZKChainMetadata, zkChainsMetadata } from "@zk import { IMetadataProvider } from "../interfaces/index.js"; +/** + * Represents a provider that retrieves metadata from static data of mainnet. + */ export class StaticMetadataProvider implements IMetadataProvider { + /** @inheritdoc */ async getChainsMetadata(): Promise { return structuredClone(zkChainsMetadata); } + + /** @inheritdoc */ async getTokensMetadata(): Promise[]> { return Array.from(tokens); }