Skip to content

Commit 21f552c

Browse files
committed
fix(klesia): decouple server from exports
1 parent 8b296dd commit 21f552c

File tree

7 files changed

+64
-55
lines changed

7 files changed

+64
-55
lines changed

apps/klesia/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
},
1313
"scripts": {
1414
"build": "tsup-node",
15-
"dev": "tsup-node --watch --onSuccess \"node dist/index.js\"",
16-
"start": "node dist/index.js",
15+
"dev": "tsup-node --watch --onSuccess \"node dist/server.js\"",
16+
"start": "node dist/server.js",
1717
"test": "bun test"
1818
},
1919
"dependencies": {

apps/klesia/src/index.spec.ts

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,58 @@
1-
import { expect, it } from "bun:test";
1+
import { describe, expect, it } from "bun:test";
22
import { testClient } from "hono/testing";
33
import { klesiaRpcRoute } from "./";
44

5-
const client = testClient(klesiaRpcRoute);
5+
const request = testClient(klesiaRpcRoute).api.$post;
66

7-
it("returns result for mina_getTransactionCount", async () => {
8-
const response = await client.api.$post({
9-
json: {
10-
method: "mina_getTransactionCount",
11-
params: ["B62qkYa1o6Mj6uTTjDQCob7FYZspuhkm4RRQhgJg9j4koEBWiSrTQrS"],
12-
},
7+
describe("Mina Devnet RPC", () => {
8+
it("returns result for mina_getTransactionCount", async () => {
9+
const response = await request({
10+
json: {
11+
method: "mina_getTransactionCount",
12+
params: ["B62qkYa1o6Mj6uTTjDQCob7FYZspuhkm4RRQhgJg9j4koEBWiSrTQrS"],
13+
},
14+
});
15+
const { result } = (await response.json()) as { result: string };
16+
expect(BigInt(result)).toBeGreaterThan(0);
1317
});
14-
const { result } = (await response.json()) as { result: string };
15-
expect(BigInt(result)).toBeGreaterThan(0);
16-
});
1718

18-
it("returns result for mina_getBalance", async () => {
19-
const response = await client.api.$post({
20-
json: {
21-
method: "mina_getBalance",
22-
params: ["B62qkYa1o6Mj6uTTjDQCob7FYZspuhkm4RRQhgJg9j4koEBWiSrTQrS"],
23-
},
19+
it("returns result for mina_getBalance", async () => {
20+
const response = await request({
21+
json: {
22+
method: "mina_getBalance",
23+
params: ["B62qkYa1o6Mj6uTTjDQCob7FYZspuhkm4RRQhgJg9j4koEBWiSrTQrS"],
24+
},
25+
});
26+
const { result } = (await response.json()) as { result: string };
27+
expect(BigInt(String(result))).toBeGreaterThan(0);
2428
});
25-
const { result } = (await response.json()) as { result: string };
26-
expect(BigInt(String(result))).toBeGreaterThan(0);
27-
});
2829

29-
it("returns result for mina_blockHash", async () => {
30-
const response = await client.api.$post({
31-
json: { method: "mina_blockHash" },
30+
it("returns result for mina_blockHash", async () => {
31+
const response = await request({
32+
json: { method: "mina_blockHash" },
33+
});
34+
const { result } = (await response.json()) as { result: string };
35+
expect(result.length).toBeGreaterThan(0);
3236
});
33-
const { result } = (await response.json()) as { result: string };
34-
expect(result.length).toBeGreaterThan(0);
35-
});
3637

37-
it("returns result for mina_chainId", async () => {
38-
const response = await client.api.$post({
39-
json: { method: "mina_chainId" },
38+
it("returns result for mina_chainId", async () => {
39+
const response = await request({
40+
json: { method: "mina_chainId" },
41+
});
42+
const { result } = (await response.json()) as { result: string };
43+
expect(result.length).toBeGreaterThan(0);
4044
});
41-
const { result } = (await response.json()) as { result: string };
42-
expect(result.length).toBeGreaterThan(0);
43-
});
4445

45-
it("returns result for mina_getAccount", async () => {
46-
const response = await client.api.$post({
47-
json: {
48-
method: "mina_getAccount",
49-
params: ["B62qkYa1o6Mj6uTTjDQCob7FYZspuhkm4RRQhgJg9j4koEBWiSrTQrS"],
50-
},
46+
it("returns result for mina_getAccount", async () => {
47+
const response = await request({
48+
json: {
49+
method: "mina_getAccount",
50+
params: ["B62qkYa1o6Mj6uTTjDQCob7FYZspuhkm4RRQhgJg9j4koEBWiSrTQrS"],
51+
},
52+
});
53+
// biome-ignore lint/suspicious/noExplicitAny: TODO
54+
const { result } = (await response.json()) as any;
55+
expect(BigInt(result.nonce)).toBeGreaterThanOrEqual(0);
56+
expect(BigInt(result.balance)).toBeGreaterThanOrEqual(0);
5157
});
52-
// biome-ignore lint/suspicious/noExplicitAny: TODO
53-
const { result } = (await response.json()) as any;
54-
expect(BigInt(result.nonce)).toBeGreaterThanOrEqual(0);
55-
expect(BigInt(result.balance)).toBeGreaterThanOrEqual(0);
5658
});

apps/klesia/src/index.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import "dotenv/config";
2-
import { serve } from "@hono/node-server";
32
import { getConnInfo } from "@hono/node-server/conninfo";
4-
import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
3+
import { OpenAPIHono, createRoute } from "@hono/zod-openapi";
54
import { PublicKeySchema } from "@mina-js/shared";
65
import { rateLimiter } from "hono-rate-limiter";
76
import { cors } from "hono/cors";
@@ -142,13 +141,6 @@ export const klesiaRpcRoute = api.openapi(rpcRoute, async ({ req, json }) => {
142141
.exhaustive();
143142
});
144143

145-
serve(
146-
{ fetch: api.fetch, port: z.coerce.number().parse(process.env.PORT ?? 3000) },
147-
(info) => {
148-
console.log(`Listening on http://localhost:${info.port}`);
149-
},
150-
);
151-
152144
export type KlesiaRpc = typeof klesiaRpcRoute;
153145
export {
154146
KlesiaNetwork,

apps/klesia/src/server.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { serve } from "@hono/node-server";
2+
import { z } from "@hono/zod-openapi";
3+
import { api } from "./";
4+
5+
serve(
6+
{ fetch: api.fetch, port: z.coerce.number().parse(process.env.PORT ?? 3000) },
7+
(info) => {
8+
console.log(`Listening on http://localhost:${info.port}`);
9+
},
10+
);

apps/klesia/tsup.config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import { defineConfig } from "tsup";
12
import sharedConfig from "../../packages/shared/tsup.config";
23

3-
export default sharedConfig;
4+
export default defineConfig({
5+
...sharedConfig,
6+
entry: ["src/index.ts", "src/server.ts"],
7+
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"private": true,
44
"scripts": {
55
"build": "turbo build",
6-
"test": "bun run --filter '*' test",
6+
"test": "turbo test",
77
"cleanup": "bun run --filter '*' cleanup",
88
"lint": "bunx biome check .",
99
"format": "bunx biome check . --write --unsafe"

turbo.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"dependsOn": ["^build"],
66
"outputs": ["dist/**"]
77
},
8+
"test": {},
89
"cleanup": {},
910
"dev": {
1011
"persistent": true,

0 commit comments

Comments
 (0)