Skip to content

Commit

Permalink
feat: metadata package scaffold (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xnigir1 authored Aug 22, 2024
1 parent e0dfb47 commit b7d67af
Show file tree
Hide file tree
Showing 15 changed files with 155 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/metadata/package.json
Original file line number Diff line number Diff line change
@@ -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:*"
}
}
3 changes: 3 additions & 0 deletions packages/metadata/src/external.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type { IMetadataService } from "./internal.js";

export { StaticMetadataService, GithubMetadataService } from "./internal.js";
1 change: 1 addition & 0 deletions packages/metadata/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./external.js";
1 change: 1 addition & 0 deletions packages/metadata/src/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./metadata.interface.js";
6 changes: 6 additions & 0 deletions packages/metadata/src/interfaces/metadata.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Token, TokenType, ZKChainMetadata } from "@zkchainhub/shared";

export interface IMetadataService {
getChainsMetadata(): Promise<ZKChainMetadata>;
getTokensMetadata(): Promise<Token<TokenType>[]>;
}
2 changes: 2 additions & 0 deletions packages/metadata/src/internal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./interfaces/index.js";
export * from "./services/index.js";
15 changes: 15 additions & 0 deletions packages/metadata/src/services/githubMetadata.service.ts
Original file line number Diff line number Diff line change
@@ -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<ZKChainMetadata> {
//TODO: Implement this method
throw new Error("Method not implemented.");
}

async getTokensMetadata(): Promise<Token<TokenType>[]> {
//TODO: Implement this method
throw new Error("Method not implemented.");
}
}
2 changes: 2 additions & 0 deletions packages/metadata/src/services/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./githubMetadata.service.js";
export * from "./staticMetadata.service.js";
12 changes: 12 additions & 0 deletions packages/metadata/src/services/staticMetadata.service.ts
Original file line number Diff line number Diff line change
@@ -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<ZKChainMetadata> {
return structuredClone(zkChainsMetadata);
}
async getTokensMetadata(): Promise<Token<TokenType>[]> {
return Array.from(tokens);
}
}
Original file line number Diff line number Diff line change
@@ -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");
});
});
Original file line number Diff line number Diff line change
@@ -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<ZKChainMetadata>();
});
});

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<Token<TokenType>[]>();
});
});
});
11 changes: 11 additions & 0 deletions packages/metadata/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.build.json",
"compilerOptions": {
"composite": true,
"declarationMap": true,
"declaration": true,
"outDir": "dist"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "test"]
}
4 changes: 4 additions & 0 deletions packages/metadata/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["src/**/*"]
}
22 changes: 22 additions & 0 deletions packages/metadata/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -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"),
},
},
});
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b7d67af

Please sign in to comment.