Skip to content

Commit

Permalink
fix: more file reorg (#300)
Browse files Browse the repository at this point in the history
* fix: more file reorg

* fix: fix build

* fix: fix

* fix: last changes
  • Loading branch information
cgilbe27 authored Jan 24, 2024
1 parent 4f3e92d commit d6a053a
Show file tree
Hide file tree
Showing 82 changed files with 410 additions and 290 deletions.
7 changes: 1 addition & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@ module.exports = {
node: true,
"jest/globals": true,
},
rules: {
"no-unused-vars": [
"off",
{ args: "none", argsIgnorePattern: "^_", vars: "local" },
],
},
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint", "jest", "prettier"],
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
],
}
21 changes: 12 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
reports
junit.xml
dist
temp
.build-cache
.DS_STORE
# Created by https://www.gitignore.io/api/node,intellij+all,visualstudiocode
# Edit at https://www.gitignore.io/?templates=node,intellij+all,visualstudiocode

docs/
src/protojs/
proto/
src/indexer-nibi/gql/
src/gql/utils/generated.ts
src/gql/utils/schema.graphql
dist
**/node_modules/*
nibiru/


reports
junit.xml
temp
.build-cache
.DS_STORE

### Intellij+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
Expand Down Expand Up @@ -203,5 +208,3 @@ typings/
# End of https://www.gitignore.io/api/node,intellij+all,visualstudiocode
.yarn
.DS_Store

nibiru/
2 changes: 1 addition & 1 deletion barrelsby.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"directory": ["./src/sdk", "./src/indexer-nibi"]
"directory": ["./src/sdk", "./src/gql"]
}
10 changes: 5 additions & 5 deletions codegen.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import type { CodegenConfig } from "@graphql-codegen/cli"
const { pascalCase } = require("change-case-all")
import { pascalCase } from "change-case-all"

const changeQueryName = (str: string) => `GQL${pascalCase(str)}`

export default {
schema: {
"indexer-nibi": {
loader: "./src/indexer-nibi/graphql-codegen/codegen-loader.js",
codegen: {
loader: "./src/gql/graphql-codegen/codegen-loader.js",
},
},
hooks: {
afterOneFileWrite: ["prettier --write"],
},
config: { namingConvention: changeQueryName },
generates: {
"./src/indexer-nibi/gql/schema.graphql": {
"./src/gql/utils/schema.graphql": {
plugins: ["schema-ast"],
},
"./src/indexer-nibi/gql/generated.ts": {
"./src/gql/utils/generated.ts": {
plugins: ["typescript", "typescript-operations"],
config: {
immutableTypes: true,
Expand Down
30 changes: 20 additions & 10 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Config } from "jest"
const { pathsToModuleNameMapper } = require("ts-jest")

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { compilerOptions } = require("./tsconfig")

// For a detailed explanation regarding each configuration property, visit:
Expand All @@ -14,9 +15,25 @@ const config: Config = {
"!**/dist/**",
"!**/index.*.ts",
"!**/index.ts",
"!**/sdk/test/helpers.ts",
],
coveragePathIgnorePatterns: ["/node_modules/", "/dist/", "/src/protojs/"],
coveragePathIgnorePatterns: [
"/docs/",
"/node_modules/",
"/build/",
"/coverage/",
"/dist/",
"/src/protojs/",
"/nibiru",
],
testPathIgnorePatterns: [
"/docs/",
"/node_modules/",
"/build/",
"/coverage/",
"/dist/",
"/src/protojs/",
"/nibiru",
],
coverageReporters: ["json-summary", "text", "html", "lcov"],
coverageThreshold: {
global: {
Expand All @@ -26,7 +43,6 @@ const config: Config = {
statements: 75,
},
},
coverageProvider: "v8",
globals: {
window: {
location: {},
Expand All @@ -35,16 +51,10 @@ const config: Config = {
moduleDirectories: ["<rootDir>", "node_modules", "src"],
moduleFileExtensions: ["js", "jsx", "ts", "tsx"],
modulePaths: [compilerOptions.baseUrl], // <-- This will be set to 'baseUrl' value
moduleNameMapper: {
"~/(.*)": "<rootDir>/src/$1",
...pathsToModuleNameMapper(compilerOptions.paths),
},
roots: ["<rootDir>"],
modulePathIgnorePatterns: ["examples"],
preset: "ts-jest",
testEnvironment: "node",
reporters: ["default"],
testPathIgnorePatterns: ["/node_modules/", "/build/", "/coverage/", "/dist/"],
testTimeout: 120000,
}

Expand Down
1 change: 0 additions & 1 deletion nibiru
Submodule nibiru deleted from 3aba36
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"docgen:changes": "git diff-index --name-only origin/HEAD -- | grep -q \"src\" && yarn docgen || true",
"clean": "tsc --clean",
"commit": "cz",
"gql-generate": "rm -rf src/indexer-nibi/gql && graphql-code-generator --config codegen.ts",
"gql-generate": "graphql-code-generator --config codegen.ts",
"test": "jest",
"test:verbose": "jest --verbose --detectOpenHandles",
"test:watch": "jest --watch",
Expand All @@ -34,6 +34,7 @@
"format:md": "yarn lint:md --fix",
"proto-gen": "bash ./scripts/protocgen.sh",
"prettier": "prettier --write . --ignore-path .gitignore",
"eslint": "eslint --fix . --ignore-path .gitignore",
"prepare": "husky install",
"semantic-release": "semantic-release"
},
Expand Down
28 changes: 15 additions & 13 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#!/bin/bash
set -e

# TODO: This assumes nibiru is a relative path in the current working directory, but this doesn't work locally
cd nibiru
git checkout releases/v0.21.x
cd ..
yarn gql-generate
yarn proto-gen
yarn build:tsc

echo "Fix path resolution"
dist_folder="./dist"
# Go through all ts and js files in the dist folder
find "$dist_folder" -type f \( -name "*.ts" -o -name "*.js" \) -exec sed -i 's|require("@/|require("src/|g' {} +
# Test for ./nibiru/ directory
if [ -d "./nibiru/" ]; then
echo "The ./nibiru/ directory exists."
cd nibiru
git checkout releases/v0.21.x
cd ..
else
cd ../nibiru
git checkout releases/v0.21.x
git pull
cd ../ts-sdk
fi

# yarn docgen
yarn gql-generate & yarn proto-gen
yarn build:tsc
yarn docgen
5 changes: 5 additions & 0 deletions scripts/protocgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ set -eo pipefail
# PKG_OUT_DIR: Output path where the generated code will go upon
# successful execution.
NIBIRU_REPO="./nibiru"

if [ -d "../nibiru/" ]; then
NIBIRU_REPO="../nibiru"
fi

PKG_OUT_DIR="./src/protojs"

# -----------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { fetch } = require("cross-fetch")
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { getIntrospectionQuery, buildClientSchema } = require("graphql")

module.exports = async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { GraphQLSchema } from "graphql"

// eslint-disable-next-line @typescript-eslint/no-var-requires
const loader = require("./codegen-loader")

describe("codegen-loader tests", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { WebSocket } from "ws"
import { HeartMonitor } from "./heart-monitor"
import { cleanResponse, gqlEndptFromTmRpc } from "./gql"
import {
GovernanceFields,
IbcFields,
Expand All @@ -16,8 +15,13 @@ import {
delegationsQueryString,
QueryWasmArgs,
GqlWasmFields,
} from "./query"
GqlOutCommunityPool,
GqlOutDelegations,
} from "../query"
import {
checkFields,
cleanResponse,
gqlEndptFromTmRpc,
defaultDelegations,
defaultDistributionCommission,
defaultGovDeposit,
Expand Down Expand Up @@ -49,8 +53,6 @@ import {
defaultUsers,
defaultValidator,
defaultVolume,
} from "./defaultObjects"
import {
GQLDelegation,
GQLDistributionCommission,
GQLGovDepositsOrder,
Expand Down Expand Up @@ -87,15 +89,7 @@ import {
GQLUnbonding,
GQLUser,
GQLValidator,
} from "./gql/generated"

const checkFields = (objects: any[], fields: any[]) => {
objects.forEach((obj: any) => {
fields.forEach((field: string | any[]) => {
expect(obj).toHaveProperty(field)
})
})
}
} from "../utils"

const nibiruUrl = "devnet-2"

Expand Down Expand Up @@ -231,14 +225,14 @@ const testIbc = async (args: QueryIbcArgs, fields?: IbcFields) => {

test("ibc", async () => {
await testIbc({
ibcChannels: {},
ibcChannels: undefined,
ibcTransfers: {
limit: 1,
},
})
await testIbc(
{
ibcChannels: {},
ibcChannels: undefined,
ibcTransfers: {
limit: 1,
},
Expand Down Expand Up @@ -707,7 +701,11 @@ test("perpPositionsSubscription", async () => {
})

test("queryBatchHandler", async () => {
const resp = await heartMonitor.GQLQueryGqlBatchHandler([
// TODO: Make a partial type that includes all of these
const resp = await heartMonitor.GQLQueryGqlBatchHandler<{
communityPool: GqlOutCommunityPool[]
delegations: GqlOutDelegations[]
}>([
communityPoolQueryString({}, true),
delegationsQueryString(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ import {
GQLUnbonding,
GQLUser,
GQLValidator,
GQLWasm,
} from "./gql/generated"
} from "../utils"
import {
GqlOutCommunityPool,
GqlOutDelegations,
Expand Down Expand Up @@ -87,7 +86,7 @@ import {
GqlOutIbc,
ibc,
QueryPerpArgs,
} from "./query"
} from "../query"
import {
markPriceCandlesSubscription,
GqlOutPerpMarket,
Expand All @@ -96,9 +95,9 @@ import {
oraclePricesSubscription,
GqlOutOraclePrices,
GqlOutPerpPositions,
} from "./subscription"
import { queryBatchHandler } from "./batchHandlers/queryBatchHandler"
import { GqlOutWasm, GqlWasmFields, QueryWasmArgs, wasm } from "./query/wasm"
} from "../subscription"
import { queryBatchHandler } from "../utils"
import { GqlOutWasm, GqlWasmFields, QueryWasmArgs, wasm } from "../query/wasm"

/** IHeartMonitor is an interface for a Heart Monitor GraphQL API.
* Each of its methods corresponds to a GQLQueryGql function. */
Expand Down Expand Up @@ -170,9 +169,9 @@ export interface IHeartMonitor {
AsyncIterableIterator<ExecutionResult<GqlOutPerpPositions>> | undefined
>

readonly GQLQueryGqlBatchHandler: (
readonly GQLQueryGqlBatchHandler: <T>(
queryQueryStrings: string[]
) => Promise<any>
) => Promise<T>

readonly redelegations: (
args: GQLQueryGqlRedelegationsArgs,
Expand Down Expand Up @@ -316,8 +315,8 @@ export class HeartMonitor implements IHeartMonitor {
fields?: Partial<GQLPerpPosition>
) => perpPositionsSubscription(args, this.subscriptionClient, fields)

GQLQueryGqlBatchHandler = async (queryQueryStrings: string[]) =>
queryBatchHandler(queryQueryStrings, this.gqlEndpt)
GQLQueryGqlBatchHandler = async <T>(queryQueryStrings: string[]) =>
<T>queryBatchHandler(queryQueryStrings, this.gqlEndpt)

redelegations = async (
args: GQLQueryGqlRedelegationsArgs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
* @file Automatically generated by barrelsby.
*/

export * from "./queryBatchHandler"
export * from "./heart-monitor"
8 changes: 8 additions & 0 deletions src/gql/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* @file Automatically generated by barrelsby.
*/

export * from "./heart-monitor/index"
export * from "./query/index"
export * from "./subscription/index"
export * from "./utils/index"
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { defaultToken } from "../defaultObjects"
import { convertObjectToPropertiesString, doGqlQuery, gqlQuery } from "../gql"
import { defaultToken } from "../utils/defaultObjects"
import {
convertObjectToPropertiesString,
doGqlQuery,
gqlQuery,
} from "../utils/consts"
import {
GQLQueryGqlCommunityPoolArgs,
GQLQuery,
GQLToken,
} from "../gql/generated"
} from "../utils/generated"

export interface GqlOutCommunityPool {
communityPool?: GQLQuery["communityPool"]
Expand Down
Loading

0 comments on commit d6a053a

Please sign in to comment.