-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from 2 commits
60d759b
5664ddb
d41540d
194a387
3837b07
049187d
74cb3f2
6409c41
2076128
da3c9f2
ab960ca
feeaa35
f001408
c6d6cd0
3e1462b
8308e08
cdc21b4
d46267e
14a6981
e91cdba
b9e4f20
2b50c45
78ed5c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
COINGECKO_API_URL="" | ||
COINGECKO_API_KEY="" |
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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should only be a dep from test-config or iam wrong ? |
||
} | ||
} |
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; | ||
} | ||
} |
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", | ||
} | ||
} |
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); | ||
}) | ||
}); |
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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
} | ||
} |
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 }); | ||
} | ||
} |
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; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
} |
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", | ||
} | ||
} |
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/*"], | ||
}, | ||
}), | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
## Serverless Package | ||
|
||
|
||
Adds serverless utils to build lambda functions. |
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); | ||
}); | ||
}); |
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); | ||
}) | ||
}); |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export { example } from './handlers/exampleHandler'; | ||
export const buildHandler = () => { | ||
console.log('@@//TODO'); | ||
}; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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