Skip to content

Commit

Permalink
docs: add tsdocs
Browse files Browse the repository at this point in the history
  • Loading branch information
0xnigir1 committed Aug 23, 2024
1 parent f9ae12b commit 3c39170
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
24 changes: 24 additions & 0 deletions packages/metadata/src/interfaces/metadata.interface.ts
Original file line number Diff line number Diff line change
@@ -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<ZKChainMetadata>;

/**
* 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<Token<TokenType>[]>;
}
2 changes: 2 additions & 0 deletions packages/metadata/src/providers/githubMetadata.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class GithubMetadataProvider implements IMetadataProvider {
});
}

/** @inheritdoc */
async getChainsMetadata(): Promise<ZKChainMetadata> {
let cachedData = await this.cache.get<ZKChainMetadata | undefined>(
`${GITHUB_METADATA_PREFIX}-chains`,
Expand Down Expand Up @@ -66,6 +67,7 @@ export class GithubMetadataProvider implements IMetadataProvider {
return cachedData;
}

/** @inheritdoc */
async getTokensMetadata(): Promise<Token<TokenType>[]> {
let cachedData = await this.cache.get<Token<TokenType>[] | undefined>(
`${GITHUB_METADATA_PREFIX}-tokens`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand All @@ -42,6 +42,7 @@ export class LocalFileMetadataProvider implements IMetadataProvider {
}
}

/** @inheritdoc */
async getChainsMetadata(): Promise<ZKChainMetadata> {
let cachedData = await this.cache.get<ZKChainMetadata>(
`${LOCALFILE_METADATA_PREFIX}-chains`,
Expand Down Expand Up @@ -70,6 +71,7 @@ export class LocalFileMetadataProvider implements IMetadataProvider {
return cachedData;
}

/** @inheritdoc */
async getTokensMetadata(): Promise<Token<TokenType>[]> {
let cachedData = await this.cache.get<Token<TokenType>[]>(
`${LOCALFILE_METADATA_PREFIX}-tokens`,
Expand Down
6 changes: 6 additions & 0 deletions packages/metadata/src/providers/staticMetadata.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ZKChainMetadata> {
return structuredClone(zkChainsMetadata);
}

/** @inheritdoc */
async getTokensMetadata(): Promise<Token<TokenType>[]> {
return Array.from(tokens);
}
Expand Down

0 comments on commit 3c39170

Please sign in to comment.