diff --git a/packages/__example__/README.md b/packages/__example__/README.md new file mode 100644 index 0000000..08ddd1b --- /dev/null +++ b/packages/__example__/README.md @@ -0,0 +1,3 @@ +### Example Package + +Easily kickoff a package replicating this structure. \ No newline at end of file diff --git a/packages/__example__/package.json b/packages/__example__/package.json new file mode 100644 index 0000000..6c942ae --- /dev/null +++ b/packages/__example__/package.json @@ -0,0 +1,17 @@ +{ + "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:*" + } +} diff --git a/packages/__example__/src/index.ts b/packages/__example__/src/index.ts new file mode 100644 index 0000000..48fbc47 --- /dev/null +++ b/packages/__example__/src/index.ts @@ -0,0 +1,3 @@ +export const example = () => { + // Implement +}; diff --git a/packages/__example__/tsconfig.json b/packages/__example__/tsconfig.json new file mode 100644 index 0000000..864b4c6 --- /dev/null +++ b/packages/__example__/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "@hyperhub/typescript-config/base.json", + "include": ["./src/**/*.ts"], + "exclude": ["dist", "node_modules"], + "compilerOptions": { + "rootDir": "./src", + "outDir": "./dist" + } +} diff --git a/packages/__example__/vitest.config.ts b/packages/__example__/vitest.config.ts new file mode 100644 index 0000000..89e76a7 --- /dev/null +++ b/packages/__example__/vitest.config.ts @@ -0,0 +1,11 @@ +import { baseConfig } from "@hyperhub/test-config"; +import { mergeConfig, defineConfig } from "vitest/config"; + +export default mergeConfig( + baseConfig, + defineConfig({ + test: { + exclude: ["coverage/*"], + }, + }), +); diff --git a/packages/errors/README.md b/packages/errors/README.md new file mode 100644 index 0000000..191e3f2 --- /dev/null +++ b/packages/errors/README.md @@ -0,0 +1 @@ +## Errors package \ No newline at end of file diff --git a/packages/errors/__test__/example.test.ts b/packages/errors/__test__/example.test.ts new file mode 100644 index 0000000..819a81c --- /dev/null +++ b/packages/errors/__test__/example.test.ts @@ -0,0 +1,7 @@ +import { describe, test, expect } from 'vitest' + +describe('exampleHandler', () => { + test('Sample exampleHandler test', () => { + expect(true).toBe(true); + }) +}); diff --git a/packages/errors/package.json b/packages/errors/package.json new file mode 100644 index 0000000..8628c69 --- /dev/null +++ b/packages/errors/package.json @@ -0,0 +1,17 @@ +{ + "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:*" + } +} diff --git a/packages/errors/src/index.ts b/packages/errors/src/index.ts new file mode 100644 index 0000000..8a5b06e --- /dev/null +++ b/packages/errors/src/index.ts @@ -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; + } +} diff --git a/packages/errors/tsconfig.json b/packages/errors/tsconfig.json new file mode 100644 index 0000000..fe937b0 --- /dev/null +++ b/packages/errors/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "@hyperhub/typescript-config/base.json", + "include": ["./src/**/*.ts"], + "exclude": ["dist", "node_modules"], + "compilerOptions": { + "outDir": "./dist", + "rootDir": "./src", + "declaration": true, + "declarationMap": true + } +} diff --git a/packages/lib/coingecko/README.md b/packages/lib/coingecko/README.md new file mode 100644 index 0000000..7412d0b --- /dev/null +++ b/packages/lib/coingecko/README.md @@ -0,0 +1,3 @@ +## Coingecko Package + +Adds coingecko API utilities. \ No newline at end of file diff --git a/packages/lib/coingecko/package.json b/packages/lib/coingecko/package.json new file mode 100644 index 0000000..4097ad2 --- /dev/null +++ b/packages/lib/coingecko/package.json @@ -0,0 +1,17 @@ +{ + "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:*" + } +} diff --git a/packages/lib/coingecko/src/errors.ts b/packages/lib/coingecko/src/errors.ts new file mode 100644 index 0000000..eea43b3 --- /dev/null +++ b/packages/lib/coingecko/src/errors.ts @@ -0,0 +1,7 @@ +import { BaseError } from "@hyperhub/errors"; + +export class CoingeckoError extends BaseError { + constructor(description: string) { + super({ name: "CoingeckoError", description }); + } +} diff --git a/packages/lib/coingecko/src/index.ts b/packages/lib/coingecko/src/index.ts new file mode 100644 index 0000000..5000ee9 --- /dev/null +++ b/packages/lib/coingecko/src/index.ts @@ -0,0 +1,24 @@ +import type { AxiosInstance, CreateAxiosDefaults } from "axios"; +import axios from "axios"; + +export default class CoingeckoService { + private instance: AxiosInstance; + + constructor(private url: string, private apiKey:string){ + const config: CreateAxiosDefaults = { + baseURL: url, + 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; + } +} diff --git a/packages/lib/coingecko/tsconfig.json b/packages/lib/coingecko/tsconfig.json new file mode 100644 index 0000000..864b4c6 --- /dev/null +++ b/packages/lib/coingecko/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "@hyperhub/typescript-config/base.json", + "include": ["./src/**/*.ts"], + "exclude": ["dist", "node_modules"], + "compilerOptions": { + "rootDir": "./src", + "outDir": "./dist" + } +} diff --git a/packages/lib/coingecko/vitest.config.ts b/packages/lib/coingecko/vitest.config.ts new file mode 100644 index 0000000..89e76a7 --- /dev/null +++ b/packages/lib/coingecko/vitest.config.ts @@ -0,0 +1,11 @@ +import { baseConfig } from "@hyperhub/test-config"; +import { mergeConfig, defineConfig } from "vitest/config"; + +export default mergeConfig( + baseConfig, + defineConfig({ + test: { + exclude: ["coverage/*"], + }, + }), +); diff --git a/packages/serverless/.env.example b/packages/serverless/.env.example new file mode 100644 index 0000000..c8e2d40 --- /dev/null +++ b/packages/serverless/.env.example @@ -0,0 +1 @@ +EXAMPLE_VAR="" diff --git a/packages/serverless/README.MD b/packages/serverless/README.MD new file mode 100644 index 0000000..a623da4 --- /dev/null +++ b/packages/serverless/README.MD @@ -0,0 +1,4 @@ +## Serverless Package + + +Adds serverless utils to build lambda functions. \ No newline at end of file diff --git a/packages/serverless/package.json b/packages/serverless/package.json index 58ac097..99b42d1 100644 --- a/packages/serverless/package.json +++ b/packages/serverless/package.json @@ -10,6 +10,7 @@ "tsc": "tsc --noEmit" }, "devDependencies": { + "@hyperhub/errors": "workspace:*", "@hyperhub/typescript-config": "workspace:*", "@serverless/typescript": "3.27.0", "@types/aws-lambda": "8.10.71", diff --git a/packages/serverless/src/errors.ts b/packages/serverless/src/errors.ts new file mode 100644 index 0000000..8990fb2 --- /dev/null +++ b/packages/serverless/src/errors.ts @@ -0,0 +1,7 @@ +import { BaseError } from "@hyperhub/errors"; + +export default class LambdaError extends BaseError { + constructor(description: string) { + super({ name: "LambdaError", description }); + } +}; diff --git a/packages/serverless/src/handlers/exampleHandler.ts b/packages/serverless/src/handlers/exampleHandler.ts deleted file mode 100644 index 23fc2ee..0000000 --- a/packages/serverless/src/handlers/exampleHandler.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Handler, Context } from "aws-lambda"; - -export const example: Handler = async (event, _context: Context) => { - try { - return { - statusCode: 200, - body: JSON.stringify({ - message: {}, - input: event, - }), - }; - } catch (error) { - throw Error(JSON.stringify(error)); - } -}; diff --git a/packages/serverless/src/index.ts b/packages/serverless/src/index.ts index c0b6086..1db8170 100644 --- a/packages/serverless/src/index.ts +++ b/packages/serverless/src/index.ts @@ -1 +1,3 @@ -export { example } from './handlers/exampleHandler'; \ No newline at end of file +export const buildHandler = () => { + console.log('@@//TODO'); +}; diff --git a/yarn.lock b/yarn.lock index 55c29e3..69d82e3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1459,10 +1459,40 @@ __metadata: languageName: node linkType: hard +"@hyperhub/coingecko@workspace:packages/lib/coingecko": + version: 0.0.0-use.local + resolution: "@hyperhub/coingecko@workspace:packages/lib/coingecko" + dependencies: + "@hyperhub/errors": "workspace:*" + "@hyperhub/test-config": "workspace:*" + "@hyperhub/typescript-config": "workspace:*" + languageName: unknown + linkType: soft + +"@hyperhub/errors@workspace:*, @hyperhub/errors@workspace:packages/errors": + version: 0.0.0-use.local + resolution: "@hyperhub/errors@workspace:packages/errors" + dependencies: + "@hyperhub/test-config": "workspace:*" + "@hyperhub/typescript-config": "workspace:*" + languageName: unknown + linkType: soft + +"@hyperhub/example@workspace:packages/__example__": + version: 0.0.0-use.local + resolution: "@hyperhub/example@workspace:packages/__example__" + dependencies: + "@hyperhub/errors": "workspace:*" + "@hyperhub/test-config": "workspace:*" + "@hyperhub/typescript-config": "workspace:*" + languageName: unknown + linkType: soft + "@hyperhub/serverless@workspace:packages/serverless": version: 0.0.0-use.local resolution: "@hyperhub/serverless@workspace:packages/serverless" dependencies: + "@hyperhub/errors": "workspace:*" "@hyperhub/typescript-config": "workspace:*" "@serverless/typescript": "npm:3.27.0" "@types/aws-lambda": "npm:8.10.71" @@ -2700,14 +2730,14 @@ __metadata: linkType: hard "ajv@npm:^8.0.0, ajv@npm:^8.11.0, ajv@npm:^8.12.0": - version: 8.13.0 - resolution: "ajv@npm:8.13.0" + version: 8.14.0 + resolution: "ajv@npm:8.14.0" dependencies: fast-deep-equal: "npm:^3.1.3" json-schema-traverse: "npm:^1.0.0" require-from-string: "npm:^2.0.2" uri-js: "npm:^4.4.1" - checksum: 10/4ada268c9a6e44be87fd295df0f0a91267a7bae8dbc8a67a2d5799c3cb459232839c99d18b035597bb6e3ffe88af6979f7daece854f590a81ebbbc2dfa80002c + checksum: 10/b6430527c2e1bf3d20dce4cca2979b5cc69db15751ac00105e269e04d7b09c2e20364070257cafacfa676171a8bf9c84c1cd9def97267a20cd15c64daa486151 languageName: node linkType: hard @@ -2967,8 +2997,8 @@ __metadata: linkType: hard "aws-sdk@npm:^2.1303.0": - version: 2.1627.0 - resolution: "aws-sdk@npm:2.1627.0" + version: 2.1628.0 + resolution: "aws-sdk@npm:2.1628.0" dependencies: buffer: "npm:4.9.2" events: "npm:1.1.1" @@ -2980,7 +3010,7 @@ __metadata: util: "npm:^0.12.4" uuid: "npm:8.0.0" xml2js: "npm:0.6.2" - checksum: 10/85973c824b3216e8c648bf2e77308dd36e24aa7d5a45e747d1ca2ecadbcae196e172d82a368dd145fb9c6e8c2571f7ce7db0b112928c451757eed8d6d1126302 + checksum: 10/783ae6374bca38971682d1ecfdba52c51d003b173f2f2dca92d433d6ee42c69f907afd26d15a2f70eff82d023c606d9dfe0514f50bdc26a939368f31f3d92d54 languageName: node linkType: hard @@ -7907,9 +7937,9 @@ __metadata: linkType: hard "sax@npm:>=0.6.0": - version: 1.3.0 - resolution: "sax@npm:1.3.0" - checksum: 10/bb571b31d30ecb0353c2ff5f87b117a03e5fb9eb4c1519141854c1a8fbee0a77ddbe8045f413259e711833aa03da210887df8527d19cdc55f299822dbf4b34de + version: 1.4.0 + resolution: "sax@npm:1.4.0" + checksum: 10/b69ca09c4131d86b61f8c0f3732b8f2e73f43a60ebe082911d4b960366d9a858458e4ab947a6c586fac8beccd45cc0feba5904309b132a37ee1bd23f76670052 languageName: node linkType: hard