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

feat: base pkg structure #8

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
60d759b
chore: add intermediate packages structure
0xjjojo May 23, 2024
5664ddb
chore: add intermediate structure for base packages and modularize pa…
0xjjojo May 23, 2024
d41540d
fix: update coingecko package.json
0xjjojo May 23, 2024
194a387
Add: coingecko readme
0xjjojo May 23, 2024
3837b07
add: example package to follow guidelines
0xjjojo May 23, 2024
049187d
add: base config files for example pkg
0xjjojo May 23, 2024
74cb3f2
wip: single package errors working from building individually
0xjjojo May 24, 2024
6409c41
chore: set correct dependencies, fix tsconfig.json for individual pkg…
0xjjojo May 24, 2024
2076128
chore: set .env.example over individual pkg
0xjjojo May 24, 2024
da3c9f2
remove: deprecated js output
0xjjojo May 24, 2024
ab960ca
misc: remove unnecesary path key from base tsconfig, and within test-…
0xjjojo May 24, 2024
feeaa35
chore: add EOF
0xjjojo May 24, 2024
f001408
add: declaration and declarationMap for error packages .d.ts output
0xjjojo May 24, 2024
c6d6cd0
Add: errors package to serverless
0xjjojo May 24, 2024
3e1462b
chore: fix lockfile
0xjjojo May 24, 2024
8308e08
Add: ^ to build pipeline
0xjjojo May 24, 2024
cdc21b4
refactor: cg constructor w dep inyection
0xjjojo May 24, 2024
d46267e
add: rebase last commits, add coingecko readme and packages, fix depr…
0xjjojo May 24, 2024
14a6981
fix: conflicts
0xjjojo May 24, 2024
e91cdba
fix: merge upstream conflcits
0xjjojo May 26, 2024
b9e4f20
add: declaration and declaration map to errors pkg
0xjjojo May 27, 2024
2b50c45
fix: yarn.lock
0xjjojo May 27, 2024
78ed5c2
chore: add EOF
0xjjojo May 27, 2024
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
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
COINGECKO_API_URL=""
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be done at package level ?? I think 🤔 cc @0xkenj1

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, each of the packages that has runtime should have its own env vars

COINGECKO_API_KEY=""
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
],
"devDependencies": {
"@commitlint/config-conventional": "19.2.2",
"@hyperhub/errors": "workspace:*",
"@hyperhub/serverless": "workspace:*",
"@hyperhub/test-config": "workspace:*",
"@hyperhub/typescript-config": "workspace:*",
"commitlint": "19.3.0",
Expand Down
19 changes: 19 additions & 0 deletions packages/errors/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@hyperhub/errors",
"version": "0.0.0",
"private": true,
"license": "MIT",
"main": "dist/index.js",
"scripts": {
"build": "tsc -p tsconfig.json"
},
"publishConfig": {
"access": "public"
},
"devDependencies": {
"@hyperhub/test-config": "workspace:*",
"@hyperhub/typescript-config": "workspace:*",
"typescript": "5.4.5",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this shoould be a global dependency of the monorepo

"vitest": "1.6.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should only be a dep from test-config or iam wrong ?

}
}
15 changes: 15 additions & 0 deletions packages/errors/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export abstract class BaseError extends Error {
readonly name: string;
readonly description: string;

constructor({ name, description }: { name: string; description: string }) {
super(description);
this.name = name;
this.description = description;
Object.setPrototypeOf(this, BaseError.prototype);
}

public getDescription(): string {
return this.description;
}
}
8 changes: 8 additions & 0 deletions packages/errors/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "@hyperhub/typescript-config/base.json",
"exclude": ["dist", "node_modules", "__test__"],
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist",
}
}
7 changes: 7 additions & 0 deletions packages/lib/coingecko/__test__/example.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { describe, test, expect } from 'vitest'

describe('exampleHandler', () => {
test('Sample coingecko test', () => {
expect(true).toBe(true);
})
});
27 changes: 27 additions & 0 deletions packages/lib/coingecko/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "@hyperhub/coingecko",
"private": true,
"version": "0.0.0",
"scripts": {
"build": "tsc -p tsconfig.json",
"lint": "eslint --fix --ext .js,.jsx,.ts,.tsx src",
"test": "vitest",
"coverage": "vitest run --coverage",
"tsc": "tsc --noEmit"
},
"devDependencies": {
"@hyperhub/typescript-config": "workspace:*",
"@serverless/typescript": "3.27.0",
"@types/aws-lambda": "8.10.71",
"@types/node": "18.13.0",
"@vitest/coverage-v8": "1.6.0",
"esbuild": "0.16.0",
"serverless": "3.27.0",
"serverless-esbuild": "1.37.3",
"serverless-iam-roles-per-function": "3.2.0",
"serverless-offline": "12.0.4",
"ts-node-dev": "2.0.0",
"typescript": "4.9.4",
"vitest": "1.6.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

}
}
7 changes: 7 additions & 0 deletions packages/lib/coingecko/src/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { BaseError } from "@hyperhub/errors";

export class CoingeckoError extends BaseError {
constructor(description: string) {
super({ name: "CoingeckoError", description });
}
}
40 changes: 40 additions & 0 deletions packages/lib/coingecko/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import type { AxiosInstance, CreateAxiosDefaults } from "axios";
import axios from "axios";

export default class CoingeckoService {
private instance: AxiosInstance;
private baseURL: string;
private apiKey: string;

constructor() {
const baseURL = process.env.COINGECKO_API_URL;
const apiKey = process.env.COINGECKO_API_KEY;

if (!baseURL) {
throw new Error("Missing Coingecko baseUrl");
}

if (!apiKey) {
throw new Error("Missing coingecko api key");
}

this.apiKey = apiKey;
this.baseURL = baseURL;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets use the approach we have talked offline

const config: CreateAxiosDefaults = {
baseURL: this.baseURL,
headers: {
"x-cg-demo-api-key": this.apiKey,
},
};

this.instance = axios.create(config);
}

get(): AxiosInstance {
if (!this.instance) {
throw new Error("Client not initialized");
}
return this.instance;
}
}
8 changes: 8 additions & 0 deletions packages/lib/coingecko/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "@hyperhub/typescript-config/base.json",
"exclude": ["dist", "node_modules", "__test__"],
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist",
}
}
11 changes: 11 additions & 0 deletions packages/lib/coingecko/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { baseConfig } from "@hyperhub/test-config";
import { mergeConfig, defineConfig } from "vitest/config";

export default mergeConfig(
baseConfig,
defineConfig({
test: {
exclude: ["coverage/*"],
},
}),
);
4 changes: 4 additions & 0 deletions packages/serverless/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Serverless Package


Adds serverless utils to build lambda functions.
8 changes: 8 additions & 0 deletions packages/serverless/__test__/handlers/example.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
(0, vitest_1.describe)('exampleHandler', () => {
(0, vitest_1.test)('Sample exampleHandler test', () => {
(0, vitest_1.expect)(true).toBe(true);
});
});
7 changes: 7 additions & 0 deletions packages/serverless/__test__/handlers/example.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { describe, test, expect } from 'vitest'

describe('exampleHandler', () => {
test('Sample exampleHandler test', () => {
expect(true).toBe(true);
})
});
15 changes: 0 additions & 15 deletions packages/serverless/src/handlers/exampleHandler.ts

This file was deleted.

4 changes: 3 additions & 1 deletion packages/serverless/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export { example } from './handlers/exampleHandler';
export const buildHandler = () => {
console.log('@@//TODO');
};
3 changes: 1 addition & 2 deletions packages/serverless/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "@hyperhub/typescript-config/base.json",
"include": ["."],
"exclude": ["dist", "node_modules"],
"exclude": ["dist", "node_modules", "__test__"],
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist",
Expand Down
Loading
Loading