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 4 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
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@
"format": "prettier --write \"**/*.{ts,tsx,md}\""
},
"workspaces": [
"packages/*",
"tooling/*"
"packages/**",
"tooling/**"
],
"devDependencies": {
"@commitlint/config-conventional": "19.2.2",
"@hyperhub/test-config": "workspace:*",
"@hyperhub/typescript-config": "workspace:*",
"@types/node": "18.13.0",
"commitlint": "19.3.0",
"husky": "9.0.11",
"lint-staged": "15.2.4",
"prettier": "3.2.5",
"turbo": "1.13.3"
"ts-node-dev": "2.0.0",
"turbo": "1.13.3",
"typescript": "4.9.4"
},
"lint-staged": {
"**/*.{js,jsx,ts,tsx}": "eslint --cache --fix",
Expand Down
3 changes: 3 additions & 0 deletions packages/__example__/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Example Package

Easily kickoff a package replicating this structure.
5 changes: 5 additions & 0 deletions packages/__example__/__test__/example.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { describe, it } from 'vitest'

describe('examplePackage test', () => {
it.skip("Implement tests")
});
19 changes: 19 additions & 0 deletions packages/__example__/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@hyperhub/example",
"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/errors": "workspace:*",
"@hyperhub/test-config": "workspace:*",
"@hyperhub/typescript-config": "workspace:*",
"typescript": "4.9.4",
"vitest": "1.6.0"
}
}
3 changes: 3 additions & 0 deletions packages/__example__/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const example = () => {
// Implement
};
8 changes: 8 additions & 0 deletions packages/__example__/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/__example__/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/*"],
},
}),
);
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;
}
}
17 changes: 17 additions & 0 deletions packages/errors/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "@hyperhub/typescript-config/base.json",
"compilerOptions": {
<<<<<<< HEAD
"outDir": "./dist",
"rootDir": "./src",
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "**/*.test.ts"]
=======
"rootDir": "./src",
"outDir": "./dist",
"declaration": true,
"declarationMap": true
}
>>>>>>> feeaa35 (chore: add EOF)
}
3 changes: 3 additions & 0 deletions packages/lib/coingecko/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Coingecko Package

Adds coingecko API utilities.
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);
})
});
19 changes: 19 additions & 0 deletions packages/lib/coingecko/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"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/errors": "workspace:*",
"@hyperhub/test-config": "workspace:*",
"@hyperhub/typescript-config": "workspace:*",
"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/*"],
},
}),
);
2 changes: 2 additions & 0 deletions packages/serverless/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
COINGECKO_API_URL=""
COINGECKO_API_KEY=""
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.
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);
})
});
8 changes: 2 additions & 6 deletions packages/serverless/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,14 @@
"tsc": "tsc --noEmit"
},
"devDependencies": {
"@hyperhub/errors": "workspace:*",
"@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"
"serverless-offline": "12.0.4"
}
}
7 changes: 7 additions & 0 deletions packages/serverless/src/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { BaseError } from "@hyperhub/errors";

export default class LambdaError extends BaseError {
constructor(description: string) {
super({ name: "LambdaError", description });
}
};
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');
};
10 changes: 8 additions & 2 deletions packages/serverless/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
{
"extends": "@hyperhub/typescript-config/base.json",
"include": ["."],
<<<<<<< HEAD
"exclude": ["dist", "node_modules", "__test__"],
"compilerOptions": {
"outDir": "./dist",
=======
"include": ["./src/**/*.ts"],
"exclude": ["dist", "node_modules"],
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist",
"outDir": "./dist"
>>>>>>> 5d538ab (fix: deps (#10))
}
}
1 change: 0 additions & 1 deletion tooling/test-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"devDependencies": {
"@hyperhub/typescript-config": "workspace:*",
"@vitest/coverage-v8": "1.6.0",
"typescript": "5.4.5",
"vitest": "1.6.0"
}
}
1 change: 0 additions & 1 deletion tooling/typescript-config/base.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Default",

"compilerOptions": {
"lib": ["ESNext"],
"module": "commonjs",
Expand Down
2 changes: 1 addition & 1 deletion turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"globalDependencies": ["**/.env.*local"],
"pipeline": {
"build": {
"dependsOn": ["^build"],
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 stay

"dependsOn": [],
"outputs": ["dist/**"]
},
"test": {
Expand Down
Loading