Skip to content

Commit

Permalink
feat!: refactor from express to fastify (#2045)
Browse files Browse the repository at this point in the history
* feat: route splitting between express and fastify

* feat: refactor `/extended/v1/tx/*` endpoints to fastify

* feat: refactor `/extended/v1/stx_supply/*` endpoints to fastify

* feat: refactor `/extended/v1/info/*` endpoints to fastify

* feat: refactor `/extended/v1/tokens/*` endpoints to fastify

* feat: refactor `/extended/v1/tokens/*` endpoints to fastify

* feat: refactor `/extended/v1/contract/*` endpoints to fastify

* feat: refactor `/extended/v1/fee_rate/*` endpoints to fastify

* feat: refactor `/extended/v1/microblock/*` endpoints to fastify

* feat: refactor `/extended/v1/block/*` endpoints to fastify

* feat: refactor `/extended/v1/burnchain/*` endpoints to fastify

* feat: refactor `/extended/v1/address/*` endpoints to fastify

* feat: refactor `/extended/v1/search/*` endpoints to fastify

* feat: refactor `/extended/v1/pox*` endpoints to fastify

* feat: refactor `/extended/v1/faucets/*` endpoints to fastify

* feat: refactor `/extended/v1/debug/*` endpoints to fastify

* feat: refactor `/extended/v2/blocks/*` and `/extended/v2/burn-blocks/*` endpoints to fastify

* feat: refactor `/extended/v2/smart-contracts/*` endpoints to fastify

* feat: refactor `/extended/v2/mempool/*` endpoints to fastify

* feat: refactor `/extended/v2/pox/*` endpoints to fastify

* feat: refactor `/extended/v2/addresses/*` endpoints to fastify

* feat: refactor `/v1/names/*` endpoints to fastify

* feat: refactor `/v1/namespaces/*` endpoints to fastify

* feat: refactor `/v1/addresses/*` endpoints to fastify

* feat: refactor `/v2/prices/*` endpoints to fastify

* feat: refactor core-node RPC proxy (/v2/*) to fastify

* chore: remove dead code

* feat: openAPI spec generation from fastify routes

* chore: remove references to legacy generated types

* docs: missing openapi tag on burn-blocks route

* docs: update docs and client generation scripts

* fix: several query params should be optional

* fix: only use a GET route for extended status

* chore: simpify typing for TransactionSchema and MempoolTransactionSchema

* feat: refactor client library

* chore: remove dependencies on old generated types

* chore: isolate rosetta json schemas and delete the rest

* chore: cleanup prometheus metrics

* fix: misc tests

* test: misc rosetta fixes

* fix: batch insert length assertion (#2042)

* fix: batch insert length assertion

* build: upgrade docker-compose

* build: use docker compose

* test: misc bns test fixes

* test: misc pox fixes

* ci: misc fixes

* chore: fix unused exports lint

* chore: simplify docs and client package.json scripts

* feat: refactor event-server from express to fastify

* chore: expose more helper types in the client lib

* ci: fix client npm lib building

* fix: openapi and client support for comma-separated query params

* chore: expose more helper types to client lib

* ci: fix lint and tests

* fix: ensure height-or-hash params are parsed correctly and have correct openapi and client types

* docs: client library migration guide

* fix: tx event pagination limit

* docs: note RPC client library change

* fix: tx event-limit default should be 100

* fix: missing event limit max overrides on a few endpoints

* chore: use PrincipalSchema in multiple areas

* chore: use UntilBlockSchema in multiple areas

* fix: perform status endpoint sql inside transactions

* chore: do not commit openapi schema files

* chore: fix tests

---------

Co-authored-by: Rafael Cárdenas <[email protected]>
  • Loading branch information
zone117x and rafaelcr authored Aug 19, 2024
1 parent f401a0f commit bd65fcf
Show file tree
Hide file tree
Showing 706 changed files with 49,876 additions and 72,060 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ src/tests-bns/
client/src/
config/
utils/src/
client*
116 changes: 0 additions & 116 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,56 +52,6 @@ jobs:
- name: Lint Unused Exports
run: npm run lint:unused-exports

lint-docs:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./docs
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"

- name: Cache node modules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: |
~/.npm
**/node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install deps
run: npm ci --audit=false

- name: Build schema & docs
run: npm run build

- name: Validate generated types
run: tsc index.d.ts

- name: Lint JSON
run: npm run lint:json

- name: Lint YAML
run: npm run lint:yaml

- name: Lint OpenAPI
run: npm run lint:openapi

- name: Validate schemas
run: npm run validate:schemas

test:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -133,10 +83,6 @@ jobs:
working-directory: client
run: npm ci --audit=false

- name: Install docs deps
working-directory: docs
run: npm ci --audit=false

- name: Setup env vars
run: echo "STACKS_CORE_EVENT_HOST=http://0.0.0.0" >> $GITHUB_ENV

Expand Down Expand Up @@ -415,68 +361,6 @@ jobs:
flag-name: run-${{ github.job }}
parallel: true

test-subnets:
if: false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'

- name: Cache node modules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: |
~/.npm
**/node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install deps
run: npm ci --audit=false

- name: Setup env vars
run: echo "STACKS_CORE_EVENT_HOST=http://0.0.0.0" >> $GITHUB_ENV

- name: Setup integration environment
run: |
sudo ufw disable
npm run devenv:deploy:subnets -- -d
npm run devenv:logs:subnets -- --no-color &> docker-compose-logs.txt &
- name: Run tests
run: npm run test:subnets

- name: Print integration environment logs
run: cat docker-compose-logs.txt
if: failure()

- name: Teardown integration environment
run: npm run devenv:stop:subnets
if: always()

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
if: always()

- name: Upload coverage to Coveralls
uses: coverallsapp/github-action@master
if: always()
with:
github-token: ${{ secrets.github_token }}
flag-name: run-${{ github.job }}
parallel: true

test-bns-e2e:
runs-on: ubuntu-latest
steps:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,7 @@ yarn.lock
#rosetta-cli results
rosetta-output-construction/rosetta-cli-output-const.json
rosetta-output/rosetta-cli-output.json

# doc schema
docs/openapi.json
docs/openapi.yaml
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ src/tests-rosetta/
src/tests-rosetta-cli/
src/tests-bns/
src/tests/synthetic-tx-payloads/
src/rosetta/json-schemas/
11 changes: 0 additions & 11 deletions .proxy-cache-control.json

This file was deleted.

6 changes: 3 additions & 3 deletions .releaserc
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
[
"@semantic-release/exec",
{
"execCwd": "client",
"prepareCmd": "npm ci"
}
],
[
"@semantic-release/npm",
"@semantic-release/exec",
{
"pkgRoot": "./docs"
"execCwd": "client",
"prepareCmd": "npm ci"
}
],
[
Expand Down
1 change: 0 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"args": ["${workspaceFolder}/src/index.ts"],
"outputCapture": "std",
"internalConsoleOptions": "openOnSessionStart",
"preLaunchTask": "generate:schemas",
"env": {
"NODE_ENV": "development",
"TS_NODE_SKIP_IGNORE": "true"
Expand Down
8 changes: 0 additions & 8 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "generate:schemas",
"type": "npm",
"script": "generate:schemas",
"presentation": {
"reveal": "silent"
}
},
{
"label": "stacks-node:deploy-dev",
"type": "shell",
Expand Down
19 changes: 0 additions & 19 deletions client/.eslintrc.js

This file was deleted.

73 changes: 73 additions & 0 deletions client/MIGRATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
## @stacks/blockchain-api-client (&lt;=7.x.x) → (8.x.x)

## Breaking Changes

This library is now generated with [openapi-typescript](https://openapi-ts.dev/openapi-fetch/) rather than [swagger-codegen](https://github.com/swagger-api/swagger-codegen). Several types which previously presented as the `any` type are now fixed, and the `@stacks/stacks-blockchain-api-types` package is no longer needed.


This repo no longer includes a schema for the Stacks Blockchain RPC interface. An alternative client library for the RPC interface can be found at https://github.com/hirosystems/stacks.js/pull/1737.

#### Configuration & Middleware

```ts
// old:
import { TransactionsApi, Configuration } from '@stacks/blockchain-api-client';
const client = new TransactionsApi(new Configuration({
basePath: 'https://api.mainnet.hiro.so',
middleware: [{
pre({url, init}) {
init.headers = new Headers(init.headers);
init.headers.set('x-custom-header', 'custom-value');
return Promise.resolve({ url, init });
}
}]
}));


// new:
import { createClient } from '@stacks/blockchain-api-client';
const client = createClient({
baseUrl: 'https://api.mainnet.hiro.so'
});
client.use({
onRequest({request}) {
request.headers.set('x-custom-header', 'custom-value');
return request;
}
});
```

#### Performing Requests

```ts
// old:
const blockTxs = await client.getTransactionsByBlock({
heightOrHash: 2000,
limit: 20,
offset: 100
});
console.log('Block transactions:', blockTxs);

// new:
const { data: blockTxs } = await client.GET('/extended/v2/blocks/{height_or_hash}/transactions', {
params: {
path: { height_or_hash: 2000 },
query: { limit: 20, offset: 100 },
}
});
console.log('Block transactions:', blockTxs);
```

#### Referencing Types

```ts
// old:
import { MempoolTransactionStatsResponse } from '@stacks/blockchain-api-client';
let response: MempoolTransactionStatsResponse;
response = await client.getMempoolTransactionStats();

// new:
import { OperationResponse } from '@stacks/blockchain-api-client';
let response: OperationResponse['/extended/v1/tx/mempool/stats'];
response = (await client.GET('/extended/v1/tx/mempool/stats')).data;
```
4 changes: 4 additions & 0 deletions client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

A JS Client for the Stacks Blockchain API

## Breaking changes from (&lt;=7.x.x) → (8.x.x)

See [MIGRATION.md](./MIGRATION.md) for details.

## Features

This package provides the ability to:
Expand Down
7 changes: 0 additions & 7 deletions client/openapitools.json

This file was deleted.

Loading

0 comments on commit bd65fcf

Please sign in to comment.