Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
minaxolone committed Jul 14, 2024
1 parent 850c325 commit 5c6037b
Show file tree
Hide file tree
Showing 108 changed files with 1,490 additions and 1,877 deletions.
5 changes: 1 addition & 4 deletions api/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ module.exports = {
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
extends: ['plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'],
root: true,
env: {
node: true,
Expand Down
1 change: 1 addition & 0 deletions api/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
transformer/
3 changes: 0 additions & 3 deletions api/.prettierrc

This file was deleted.

6 changes: 3 additions & 3 deletions api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ Before you begin, ensure you have met the following requirements:
- npm or yarn
- Redis


## Installation

First, install the project dependencies:

```bash
$ npm install
```
Then, install [Redis](https://redis.io/docs/install/install-redis/) on your machine.

Then, install [Redis](https://redis.io/docs/install/install-redis/) on your machine.

After installing Redis, start the Redis server:

```bash
```bash
$ brew services start redis
```

Expand Down
2 changes: 1 addition & 1 deletion api/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import BN from 'bn.js';

const v = '0x86ea91e266287d11011f5c0b3963d2ea'
const v = '0x86ea91e266287d11011f5c0b3963d2ea';
const b = new BN(v.substring(2), 'hex');
console.log(b.toString(10));
12 changes: 6 additions & 6 deletions api/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { JestConfigWithTsJest } from 'ts-jest';

const jestConfig: JestConfigWithTsJest = {
moduleFileExtensions: ["js", "json", "ts"],
rootDir: "src",
testRegex: ".*\\.spec\\.ts$",
collectCoverageFrom: ["**/*.(t|j)s"],
coverageDirectory: "../coverage",
testEnvironment: "node",
moduleFileExtensions: ['js', 'json', 'ts'],
rootDir: 'src',
testRegex: '.*\\.spec\\.ts$',
collectCoverageFrom: ['**/*.(t|j)s'],
coverageDirectory: '../coverage',
testEnvironment: 'node',
preset: 'ts-jest/presets/default-esm', // or other ESM presets
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
Expand Down
36 changes: 18 additions & 18 deletions api/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { join } from "node:path";
import { Module } from "@nestjs/common";
import { GraphQLModule as NestGraphQLModule } from "@nestjs/graphql";
import { ConfigModule } from "@nestjs/config";
import { ApolloDriver, ApolloDriverConfig } from "@nestjs/apollo";
import { join } from 'node:path';
import { Module } from '@nestjs/common';
import { GraphQLModule as NestGraphQLModule } from '@nestjs/graphql';
import { ConfigModule } from '@nestjs/config';
import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo';

import config from "../config/config.js";
import { AppService } from "./app.service.js";
import { ClickhouseModule } from "../clickhouse/clickhouse.module.js";
import { OlModule } from "../ol/ol.module.js";
import { S3Module } from "../s3/s3.module.js";
import { NodeWatcherModule } from "../node-watcher/node-watcher.module.js";
import { GraphQLModule } from "../graphql/graphql.module.js";
import { StatsModule } from "../stats/stats.module.js";
import { WalletSubscriptionModule } from "../wallet-subscription/wallet-subscription.module.js";
import { NatsModule } from "../nats/nats.module.js";
import { OlSwapModule } from "../ol-swap/OlSwapModule.js";
import { MultiSigModule } from "../multi-sig/multi-sig.module.js";
import config from '../config/config.js';
import { AppService } from './app.service.js';
import { ClickhouseModule } from '../clickhouse/clickhouse.module.js';
import { OlModule } from '../ol/ol.module.js';
import { S3Module } from '../s3/s3.module.js';
import { NodeWatcherModule } from '../node-watcher/node-watcher.module.js';
import { GraphQLModule } from '../graphql/graphql.module.js';
import { StatsModule } from '../stats/stats.module.js';
import { WalletSubscriptionModule } from '../wallet-subscription/wallet-subscription.module.js';
import { NatsModule } from '../nats/nats.module.js';
import { OlSwapModule } from '../ol-swap/OlSwapModule.js';
import { MultiSigModule } from '../multi-sig/multi-sig.module.js';

@Module({
imports: [
Expand All @@ -29,7 +29,7 @@ import { MultiSigModule } from "../multi-sig/multi-sig.module.js";

NestGraphQLModule.forRoot<ApolloDriverConfig>({
driver: ApolloDriver,
autoSchemaFile: join(process.cwd(), "src/schema.gql"),
autoSchemaFile: join(process.cwd(), 'src/schema.gql'),
playground: true,
subscriptions: {
'graphql-ws': {
Expand Down
16 changes: 8 additions & 8 deletions api/src/app/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ export class AppService implements OnModuleInit {
const addr = server.address();

if (addr && typeof addr !== 'string') {
let host: string;
if (addr.family === 'IPv6') {
host = `[${addr.address}]:${addr.port}`;
} else {
host = `${addr.address}:${addr.port}`;
}
let host: string;
if (addr.family === 'IPv6') {
host = `[${addr.address}]:${addr.port}`;
} else {
host = `${addr.address}:${addr.port}`;
}

const uri = `http://${host}`;
this.logger.log(`Serving at ${uri}"`);
const uri = `http://${host}`;
this.logger.log(`Serving at ${uri}"`);
}
}
}
2 changes: 1 addition & 1 deletion api/src/clickhouse/clickhouse.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { ClickhouseService } from './clickhouse.service.js';

@Module({
providers: [ClickhouseService],
exports: [ClickhouseService]
exports: [ClickhouseService],
})
export class ClickhouseModule {}
50 changes: 22 additions & 28 deletions api/src/clickhouse/clickhouse.service.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import pathUtil from "node:path";
import fs from "node:fs";
import pathUtil from 'node:path';
import fs from 'node:fs';

import axios from "axios";
import qs from "qs";
import {
Injectable,
OnApplicationShutdown,
OnModuleInit,
} from "@nestjs/common";
import { createClient, ClickHouseClient } from "@clickhouse/client";
import { ConfigService } from "@nestjs/config";
import axios from 'axios';
import qs from 'qs';
import { Injectable, OnApplicationShutdown, OnModuleInit } from '@nestjs/common';
import { createClient, ClickHouseClient } from '@clickhouse/client';
import { ConfigService } from '@nestjs/config';

import { ClickhouseConfig } from "../config/config.interface.js";
import { ClickhouseConfig } from '../config/config.interface.js';

export interface ClickhouseQueryResponse<T> {
meta: { name: string; type: string }[];
Expand All @@ -29,13 +25,13 @@ export class ClickhouseService implements OnModuleInit, OnApplicationShutdown {
private readonly config: ClickhouseConfig;

public constructor(config: ConfigService) {
const clickhouseConfig = config.get<ClickhouseConfig>("clickhouse")!;
const clickhouseConfig = config.get<ClickhouseConfig>('clickhouse')!;

this.config = clickhouseConfig;

let protocol = "http";
let protocol = 'http';
if (clickhouseConfig.port === 443) {
protocol = "https";
protocol = 'https';
}

const url = `${protocol}://${clickhouseConfig.host}:${clickhouseConfig.port}`;
Expand All @@ -50,13 +46,13 @@ export class ClickhouseService implements OnModuleInit, OnApplicationShutdown {

public async onModuleInit() {
const dirname = pathUtil.dirname(new URL(import.meta.url).pathname);
const queriesDir = pathUtil.join(dirname, "queries");
const queriesDir = pathUtil.join(dirname, 'queries');
const files = await fs.promises.readdir(queriesDir);
for (const file of files) {
const queryName = file.split(".")[0];
const queryName = file.split('.')[0];
this.insertQueries.set(
queryName,
await fs.promises.readFile(pathUtil.join(queriesDir, file), "utf-8"),
await fs.promises.readFile(pathUtil.join(queriesDir, file), 'utf-8'),
);
}
}
Expand All @@ -66,28 +62,26 @@ export class ClickhouseService implements OnModuleInit, OnApplicationShutdown {
}

public async insertParquetFile(path: string): Promise<void> {
const queryName = pathUtil.basename(path).split(".")[0];
const queryName = pathUtil.basename(path).split('.')[0];
const query = this.insertQueries.get(queryName);
if (!query) {
throw new Error(`insert query missing for ${queryName}`);
}

const clickhouseConfig = this.config;

let protocol = "http";
let protocol = 'http';
if (clickhouseConfig.port === 443) {
protocol = "https";
protocol = 'https';
}

const url = `${protocol}://${clickhouseConfig.host}:${clickhouseConfig.port}/?${qs.stringify(
{
database: clickhouseConfig.database,
query,
},
)}`;
const url = `${protocol}://${clickhouseConfig.host}:${clickhouseConfig.port}/?${qs.stringify({
database: clickhouseConfig.database,
query,
})}`;

await axios({
method: "POST",
method: 'POST',
url,
auth: {
username: clickhouseConfig.username,
Expand Down
2 changes: 1 addition & 1 deletion api/src/config/config.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ export interface FirebaseConfig {

export interface NatsConfig {
servers: string;
}
}
15 changes: 8 additions & 7 deletions api/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ export default (): Config => {

const config: Config = {
port: ENV.PORT !== undefined ? parseInt(ENV.PORT, 10) : 3000,
cacheEnabled: ENV.CACHE_ENABLED === "true",
cacheEnabled: ENV.CACHE_ENABLED === 'true',
dataApiHost: ENV.DATA_API_HOST!,

info: {
build: ENV.CI_COMMIT_SHA,
},

ol: {
provider: "https://rpc.0l.fyi",
provider: 'https://rpc.0l.fyi',
dataApiHost: ENV.DATA_API_HOST!,
},

Expand All @@ -24,7 +24,7 @@ export default (): Config => {
accessKey: ENV.S3_ACCESS_KEY_ID!,
secretKey: ENV.S3_SECRET_ACCESS_KEY!,
port: ENV.S3_PORT ? parseInt(ENV.S3_PORT, 10) : 443,
useSSL: ENV.S3_USE_SSL ? ENV.S3_USE_SSL === "true" : true,
useSSL: ENV.S3_USE_SSL ? ENV.S3_USE_SSL === 'true' : true,
bucket: ENV.S3_BUCKET!,
storageClass: ENV.S3_STORAGE_CLASS!,
},
Expand All @@ -39,20 +39,21 @@ export default (): Config => {

apn: ENV.APN_PRIVATE_KEY
? {
privateKey: Buffer.from(ENV.APN_PRIVATE_KEY, "base64"),
privateKey: Buffer.from(ENV.APN_PRIVATE_KEY, 'base64'),
keyId: ENV.APN_KEY_ID!,
teamId: ENV.APN_TEAM_ID!,
}
: undefined,

firebase: ENV.FIREBASE_SERVICE_ACCOUNT
? {
serviceAccount: ENV.FIREBASE_SERVICE_ACCOUNT,
} : undefined,
serviceAccount: ENV.FIREBASE_SERVICE_ACCOUNT,
}
: undefined,

nats: {
servers: ENV.NATS_SERVERS!,
}
},
};

return config;
Expand Down
4 changes: 2 additions & 2 deletions api/src/firebase/firebase.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Module } from "@nestjs/common";
import { FirebaseService } from "./firebase.service.js";
import { Module } from '@nestjs/common';
import { FirebaseService } from './firebase.service.js';

@Module({
imports: [],
Expand Down
22 changes: 11 additions & 11 deletions api/src/firebase/firebase.service.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { Injectable } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import admin from "firebase-admin";
import { FirebaseConfig } from "../config/config.interface.js";
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import admin from 'firebase-admin';
import { FirebaseConfig } from '../config/config.interface.js';

@Injectable()
export class FirebaseService {
public readonly app?: admin.app.App;

public constructor(
config: ConfigService,
) {
const firebaseConfig = config.get<FirebaseConfig>("firebase");
public constructor(config: ConfigService) {
const firebaseConfig = config.get<FirebaseConfig>('firebase');
if (firebaseConfig) {
const serviceAccount = JSON.parse(Buffer.from(firebaseConfig.serviceAccount, "base64").toString("utf-8"));
const serviceAccount = JSON.parse(
Buffer.from(firebaseConfig.serviceAccount, 'base64').toString('utf-8'),
);

this.app = admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
credential: admin.credential.cert(serviceAccount),
});
}
}
}
}
12 changes: 6 additions & 6 deletions api/src/graphql/bigint.scalar.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Scalar, CustomScalar } from "@nestjs/graphql";
import { Kind, ValueNode } from "graphql";
import BN from "bn.js";
import { Scalar, CustomScalar } from '@nestjs/graphql';
import { Kind, ValueNode } from 'graphql';
import BN from 'bn.js';

@Scalar("BigInt", (type) => BN)
@Scalar('BigInt', (type) => BN)
export class BigIntScalar implements CustomScalar<string, BN> {
public readonly description = "BigInt";
public readonly description = 'BigInt';

private static INVALID_BIGINT_REPRESENTATION =
"Invalid bigint literal representation. Must be base 10 number";
'Invalid bigint literal representation. Must be base 10 number';

private static checkLiteral(value: string) {
if (/^[0-9]*$/i.test(value) === false) {
Expand Down
Loading

0 comments on commit 5c6037b

Please sign in to comment.