Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,28 @@ aliases:
branches:
only: /^(pull|dependabot|fix|feat)\/.*$/

# -------------------------
# ALIASES: Bun Install
# -------------------------
- &install-bun
name: Install Bun
command: |
curl -fsSL https://bun.sh/install | bash -s "bun-v1.3.1"
echo 'export PATH="$HOME/.bun/bin:$PATH"' >> $BASH_ENV

defaults: &defaults
working_directory: ~/client-js
docker:
- image: cimg/node:20.11.0
- image: cimg/node:24.10.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a bun one?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there is an official one, regardless I think it's maybe better to stay on node runtime maybe for a cpl iterations, as bun runtime is so new and most users are probably going to be using node.


jobs:
test:
<<: *defaults
steps:
- checkout
- run: *install-bun
- restore_cache: *restore-deps-cache
- run: npm install
- run: bun install
- run: npm install codecov
- run: npm test
- run: ./node_modules/.bin/codecov
Expand All @@ -43,18 +53,20 @@ jobs:
<<: *defaults
steps:
- checkout
- run: *install-bun
- restore_cache: *restore-deps-cache
- run: npm install
- run: npm run build
- run: bun install
- run: bun run build
- save_cache: *save-deps-cache

release:
<<: *defaults
steps:
- checkout
- run: *install-bun
- restore_cache: *restore-deps-cache
- run: npm install
- run: npm run build
- run: bun install
- run: bun run build
- run: npm install semantic-release @semantic-release/changelog @semantic-release/git @semantic-release/github @semantic-release/npm @semantic-release/commit-analyzer @semantic-release/release-notes-generator @qiwi/semantic-release-gh-pages-plugin
- run: git checkout .
- run: ./node_modules/.bin/semantic-release
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ build
.DS_Store
node_modules
coverage
dist
12 changes: 12 additions & 0 deletions .prettierc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"endOfLine": "lf",
"bracketSameLine": false,
"arrowParens": "always",
"bracketSpacing": true,
"useTabs": false,
"tabWidth": 2,
"printWidth": 100,
"trailingComma": "es5",
"singleQuote": true,
"semi": true
}
34 changes: 24 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ A browser-compatible JSON-RPC client with multiple transports:
- PostMessageWindow
- PostMessageIframe


```javascript
import { RequestManager, HTTPTransport, Client } from "@open-rpc/client-js";
const transport = new HTTPTransport("http://localhost:8545");
const client = new Client(new RequestManager([transport]));
const result = await client.request({method: "addition", params: [2, 2]});
const result = await client.request({ method: "addition", params: [2, 2] });
// => { jsonrpc: '2.0', id: 1, result: 4 }
```

Expand All @@ -36,7 +35,11 @@ const result = await client.request({method: "addition", params: [2, 2]});

```javascript
import { EventEmitter } from "events";
import { RequestManager, EventEmitterTransport, Client } from "@open-rpc/client-js";
import {
RequestManager,
EventEmitterTransport,
Client,
} from "@open-rpc/client-js";

const chan1 = "chan1";
const chan2 = "chan2";
Expand All @@ -57,7 +60,7 @@ emitter.on(chan1, (jsonrpcRequest) => {
});

const main = async () => {
const result = await client.request({method: "addition", params: [2, 2]});
const result = await client.request({ method: "addition", params: [2, 2] });
console.log(result);
};

Expand All @@ -68,7 +71,6 @@ main().then(() => {

</details>


<details>
<summary>HTTP</summary>

Expand All @@ -80,7 +82,7 @@ const requestManager = new RequestManager([transport]);
const client = new Client(requestManager);

const main = async () => {
const result = await client.request({method: "addition", params: [2, 2]});
const result = await client.request({ method: "addition", params: [2, 2] });
console.log(result);
};

Expand All @@ -91,31 +93,43 @@ main().then(() => {

</details>


<details>
<summary>WebSocket</summary>

```javascript
import { RequestManager, Client, WebSocketTransport } from "@open-rpc/client-js";
import {
RequestManager,
Client,
WebSocketTransport,
} from "@open-rpc/client-js";

const transport = new WebSocketTransport("ws://localhost:3333");
const requestManager = new RequestManager([transport]);
const client = new Client(requestManager);

const main = async () => {
const result = await client.request({method: "addition", params: [2, 2]});
const result = await client.request({ method: "addition", params: [2, 2] });
console.log(result);
};

main().then(() => {
console.log("DONE");
client.close();
});

```

</details>

### Building

```sh
# Install bun
curl -fsSL https://bun.sh/install | bash

# Build the repo
bun install
bun run build
```

### Contributing

Expand Down
25 changes: 25 additions & 0 deletions build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bun
import { $ } from "bun";

const baseConfig = {
entrypoints: ["./src/index.ts"],
sourcemap: "external",
minify: false,
splitting: false,
};


await Bun.build({
...baseConfig,
outdir: "./dist",
target: "node",
format: "esm",
external: ["ws", "isomorphic-ws"],
});

await Bun.build({
...baseConfig,
outdir: "./dist/browser",
target: "browser",
format: "esm",
});
Loading