diff --git a/packages/metadata/package.json b/packages/metadata/package.json new file mode 100644 index 0000000..f68c0dc --- /dev/null +++ b/packages/metadata/package.json @@ -0,0 +1,29 @@ +{ + "name": "@zkchainhub/metadata", + "version": "1.0.0", + "main": "./dist/src/index.js", + "typings": "./dist/src/index.d.ts", + "type": "module", + "directories": { + "src": "src" + }, + "files": [ + "dist/*", + "package.json", + "!**/*.tsbuildinfo" + ], + "scripts": { + "build": "tsc -p tsconfig.build.json", + "check-types": "tsc --noEmit -p ./tsconfig.json", + "clean": "rm -rf dist", + "lint": "eslint \"{src,test}/**/*.{js,ts,json}\"", + "lint:fix": "pnpm lint --fix", + "format": "prettier --check \"{src,test}/**/*.{js,ts,json}\"", + "format:fix": "prettier --write \"{src,test}/**/*.{js,ts,json}\"", + "test": "vitest run --config vitest.config.ts --passWithNoTests", + "test:cov": "vitest run --config vitest.config.ts --coverage" + }, + "dependencies": { + "@zkchainhub/shared": "workspace:*" + } +} diff --git a/packages/metadata/src/external.ts b/packages/metadata/src/external.ts new file mode 100644 index 0000000..d309d41 --- /dev/null +++ b/packages/metadata/src/external.ts @@ -0,0 +1,3 @@ +export type { IMetadataService } from "./internal.js"; + +export { StaticMetadataService, GithubMetadataService } from "./internal.js"; diff --git a/packages/metadata/src/index.ts b/packages/metadata/src/index.ts new file mode 100644 index 0000000..a5a2748 --- /dev/null +++ b/packages/metadata/src/index.ts @@ -0,0 +1 @@ +export * from "./external.js"; diff --git a/packages/metadata/src/interfaces/index.ts b/packages/metadata/src/interfaces/index.ts new file mode 100644 index 0000000..c9f5d31 --- /dev/null +++ b/packages/metadata/src/interfaces/index.ts @@ -0,0 +1 @@ +export * from "./metadata.interface.js"; diff --git a/packages/metadata/src/interfaces/metadata.interface.ts b/packages/metadata/src/interfaces/metadata.interface.ts new file mode 100644 index 0000000..c1eccea --- /dev/null +++ b/packages/metadata/src/interfaces/metadata.interface.ts @@ -0,0 +1,6 @@ +import { Token, TokenType, ZKChainMetadata } from "@zkchainhub/shared"; + +export interface IMetadataService { + getChainsMetadata(): Promise; + getTokensMetadata(): Promise[]>; +} diff --git a/packages/metadata/src/internal.ts b/packages/metadata/src/internal.ts new file mode 100644 index 0000000..08c7612 --- /dev/null +++ b/packages/metadata/src/internal.ts @@ -0,0 +1,2 @@ +export * from "./interfaces/index.js"; +export * from "./services/index.js"; diff --git a/packages/metadata/src/services/githubMetadata.service.ts b/packages/metadata/src/services/githubMetadata.service.ts new file mode 100644 index 0000000..1c11e26 --- /dev/null +++ b/packages/metadata/src/services/githubMetadata.service.ts @@ -0,0 +1,15 @@ +import { Token, TokenType, ZKChainMetadata } from "@zkchainhub/shared"; + +import { IMetadataService } from "../interfaces/index.js"; + +export class GithubMetadataService implements IMetadataService { + async getChainsMetadata(): Promise { + //TODO: Implement this method + throw new Error("Method not implemented."); + } + + async getTokensMetadata(): Promise[]> { + //TODO: Implement this method + throw new Error("Method not implemented."); + } +} diff --git a/packages/metadata/src/services/index.ts b/packages/metadata/src/services/index.ts new file mode 100644 index 0000000..b5d1470 --- /dev/null +++ b/packages/metadata/src/services/index.ts @@ -0,0 +1,2 @@ +export * from "./githubMetadata.service.js"; +export * from "./staticMetadata.service.js"; diff --git a/packages/metadata/src/services/staticMetadata.service.ts b/packages/metadata/src/services/staticMetadata.service.ts new file mode 100644 index 0000000..7414c03 --- /dev/null +++ b/packages/metadata/src/services/staticMetadata.service.ts @@ -0,0 +1,12 @@ +import { Token, tokens, TokenType, ZKChainMetadata, zkChainsMetadata } from "@zkchainhub/shared"; + +import { IMetadataService } from "../interfaces/index.js"; + +export class StaticMetadataService implements IMetadataService { + async getChainsMetadata(): Promise { + return structuredClone(zkChainsMetadata); + } + async getTokensMetadata(): Promise[]> { + return Array.from(tokens); + } +} diff --git a/packages/metadata/test/unit/services/githubMetadata.service.spec.ts b/packages/metadata/test/unit/services/githubMetadata.service.spec.ts new file mode 100644 index 0000000..9a117c3 --- /dev/null +++ b/packages/metadata/test/unit/services/githubMetadata.service.spec.ts @@ -0,0 +1,11 @@ +import { describe, it } from "vitest"; + +describe("GithubMetadataService", () => { + describe("getChainsMetadata", () => { + it.skip("returns the ZKChainMetadata"); + }); + + describe("getTokensMetadata", () => { + it.skip("return an array of Token objects"); + }); +}); diff --git a/packages/metadata/test/unit/services/staticMetadata.service.spec.ts b/packages/metadata/test/unit/services/staticMetadata.service.spec.ts new file mode 100644 index 0000000..0a5c632 --- /dev/null +++ b/packages/metadata/test/unit/services/staticMetadata.service.spec.ts @@ -0,0 +1,30 @@ +import { beforeEach, describe, expect, expectTypeOf, it } from "vitest"; + +import { Token, TokenType, ZKChainMetadata } from "@zkchainhub/shared"; + +import { StaticMetadataService } from "../../../src/internal.js"; + +describe("StaticMetadataService", () => { + let metadataService: StaticMetadataService; + + beforeEach(() => { + metadataService = new StaticMetadataService(); + }); + + describe("getChainsMetadata", () => { + it("should return the ZKChainMetadata", async () => { + const result = await metadataService.getChainsMetadata(); + expect(result).toBeDefined(); + expectTypeOf(result).toEqualTypeOf(); + }); + }); + + describe("getTokensMetadata", () => { + it("should return an array of Token objects", async () => { + const result = await metadataService.getTokensMetadata(); + expect(result).toBeDefined(); + expect(Array.isArray(result)).toBe(true); + expectTypeOf(result).toEqualTypeOf[]>(); + }); + }); +}); diff --git a/packages/metadata/tsconfig.build.json b/packages/metadata/tsconfig.build.json new file mode 100644 index 0000000..32768e3 --- /dev/null +++ b/packages/metadata/tsconfig.build.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.build.json", + "compilerOptions": { + "composite": true, + "declarationMap": true, + "declaration": true, + "outDir": "dist" + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "dist", "test"] +} diff --git a/packages/metadata/tsconfig.json b/packages/metadata/tsconfig.json new file mode 100644 index 0000000..66bb87a --- /dev/null +++ b/packages/metadata/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.json", + "include": ["src/**/*"] +} diff --git a/packages/metadata/vitest.config.ts b/packages/metadata/vitest.config.ts new file mode 100644 index 0000000..3aa3262 --- /dev/null +++ b/packages/metadata/vitest.config.ts @@ -0,0 +1,22 @@ +import path from "path"; +import { defineConfig } from "vitest/config"; + +export default defineConfig({ + test: { + globals: true, // Use Vitest's global API without importing it in each file + environment: "node", // Use the Node.js environment + include: ["test/**/*.spec.ts"], // Include test files + exclude: ["node_modules", "dist"], // Exclude certain directories + coverage: { + provider: "v8", + reporter: ["text", "json", "html"], // Coverage reporters + exclude: ["node_modules", "dist"], // Files to exclude from coverage + }, + }, + resolve: { + alias: { + // Setup path alias based on tsconfig paths + "@": path.resolve(__dirname, "src"), + }, + }, +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c2ca1bf..e995b08 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -129,6 +129,12 @@ importers: specifier: 4.17.0 version: 4.17.0 + packages/metadata: + dependencies: + "@zkchainhub/shared": + specifier: workspace:* + version: link:../shared + packages/metrics: dependencies: "@zkchainhub/pricing":