Skip to content

Commit 99216e1

Browse files
authored
Publish preparations (#206)
1 parent 80ca6d5 commit 99216e1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+777
-620
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ v8-compile-cache-0
1414
/packages/crypto-target-*/wasm-target
1515
/packages/core/crypto/wasm-target
1616
**/*_generated_.ts
17+
/packages/core/data-model/schema/schema.json
1718

CONTRIBUTING.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Contributing to Iroha JavaScript
2+
3+
This document explains how this repo works, and how to work with it.
4+
5+
Steps, in short:
6+
7+
1. Install Rust and `wasm-pack`.
8+
2. Install Deno v2 and Node.js v22
9+
3. Link Iroha repository
10+
4. Explore `tasks` in the root `deno.json`
11+
5. Work with the code
12+
13+
TODO: setting up commit hooks
14+
15+
## Installing Rust and `wasm-pack`
16+
17+
```sh
18+
# install rustup
19+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
20+
21+
# add necessary components
22+
rustup component add rust-src --target wasm32-unknown-unknown
23+
24+
# install wasm-pack
25+
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
26+
```
27+
28+
## Installing Deno & Node.js
29+
30+
This must be pretty straightforward. A few notes though:
31+
32+
- While this project is mostly driven by Deno, there are some Node.js parts, unfortunately. Specifically,
33+
`tests/browser` is a `pnpm` project, because otherwise it's hard to make Cypress work.
34+
- Thus, run `corepack enable` (or install `npm i -g pnpm`) so that `pnpm` is also available.
35+
36+
## Linking & building Iroha
37+
38+
For this project to function, you must link Iroha repository. There are two ways to do so:
39+
40+
```sh
41+
# symlink to the local path
42+
deno task prep:iroha --path /path/to/local/iroha/clone
43+
```
44+
45+
```sh
46+
# clone the repo
47+
deno task prep:iroha --git https://github.com/hyperledger-iroha/iroha.git --rev v2.0.0-rc.1.0
48+
```
49+
50+
After Iroha is linked, you need to prepare some artifacts from it (binaries such as `irohad`, `kagami`, `iroha_codec`;
51+
`executor.wasm`; `schema.json`):
52+
53+
```sh
54+
deno task prep:iroha:build
55+
```
56+
57+
## Running tests
58+
59+
Please explore `tasks` in the root `deno.jsonc`.
60+
61+
```sh
62+
# run them all
63+
deno task test
64+
65+
# unit, non-integration tests
66+
deno run npm:vitest
67+
# or
68+
pnpm dlx vitest
69+
```
70+
71+
Tests are mostly written in Vitest (except the doctests), and it doesn't work very well with Deno (considering
72+
migration). To improve development experience, consider running Vitest via `pnpm dlx` or similar.

README.md

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,54 @@
11
# Iroha JavaScript
22

3-
This is a JavaScript (TypeScript) SDK for Iroha 2.
3+
The JavaScript (TypeScript) SDK of [Iroha 2](https://github.com/hyperledger-iroha/iroha).
44

5-
TODO
5+
Works in Deno, Node.js, and the Browser. (TODO: check in Bun and Cloudflare Workers).
6+
7+
Packages and documentation are available on JSR: https://jsr.io/@iroha
8+
9+
## Usage
10+
11+
### Installation
12+
13+
```shell
14+
# deno
15+
deno add jsr:@iroha/core
16+
17+
# npm (one of the below, depending on your package manager)
18+
npx jsr add @iroha/core
19+
yarn dlx jsr add @iroha/core
20+
pnpm dlx jsr add @iroha/core
21+
bunx jsr add @iroha/core
22+
```
23+
24+
### Quick Example
25+
26+
```ts
27+
import '@iroha/crypto-target-node/install'
28+
import { Client } from '@iroha/client'
29+
import * as types from '@iroha/core/data-model'
30+
31+
const kp = types.KeyPair.random()
32+
33+
const client = new Client({
34+
toriiBaseURL: new URL('http://localhost:8080'),
35+
chain: '000-000',
36+
accountDomain: new types.Name('wonderland'),
37+
accountKeyPair: kp,
38+
})
39+
40+
async function test() {
41+
const { blocks } = await client.api.telemetry.status()
42+
console.log(blocks) // => 3
43+
}
44+
```
45+
46+
This example assumes running in Deno/Node.js.
47+
48+
## Iroha Compatibility
49+
50+
See the ["Compatibility" secion in `@iroha/core` package documentation](https://jsr.io/@iroha/core#iroha-compatibility).
51+
52+
## Contributing
53+
54+
See [CONTRIBUTING.md](./CONTRIBUTING.md)

deno.jsonc

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
{
2+
"license": "Apache 2.0",
23
"nodeModulesDir": "auto",
4+
"exclude": ["**/docs"],
35
"workspace": [
46
"./packages/core",
57
"./packages/crypto-target-node",
68
"./packages/crypto-target-web",
79
"./packages/client",
10+
"./packages/client-web-socket-node",
811

912
"./tests/support/test-configuration",
1013
"./tests/support/test-peer",
@@ -24,15 +27,19 @@
2427
},
2528
"prep:crypto-wasm": "deno run --allow-read --allow-env --allow-run --allow-write ./etc/task-prep-crypto-wasm.ts",
2629
"prep:crypto-wasm:copy": "deno task prep:crypto-wasm --onlyCopy",
27-
"prep:codegen": "deno run --allow-write --allow-read ./etc/task-codegen.ts",
30+
"prep:codegen": {
31+
"command": "deno run --allow-write --allow-read ./etc/task-codegen.ts",
32+
"dependencies": ["prep:iroha:check"]
33+
},
2834
"prep:codegen:watch": "watchexec -e ts deno task prep:codegen",
2935
"prep:ensure-ready": {
3036
"dependencies": ["prep:codegen", "prep:crypto-wasm:copy", "prep:iroha:check"]
3137
},
3238
"check:all": {
33-
"command": "deno check .",
39+
"command": "deno check --doc .",
3440
"dependencies": ["prep:ensure-ready"]
3541
},
42+
"test:deno": "deno test --doc --allow-read",
3643
"test:vitest": {
3744
"dependencies": ["prep:ensure-ready"],
3845
"description": "Run Vitest",
@@ -48,7 +55,7 @@
4855
},
4956
"test": {
5057
"description": "Run all tests, from unit to integration",
51-
"command": "deno task test:vitest && deno task test:integration:node && deno task test:integration:browser"
58+
"command": "deno task test:deno && deno task test:vitest && deno task test:integration:node && deno task test:integration:browser"
5259
},
5360
"dev:run-test-peer": {
5461
"dependencies": ["prep:ensure-ready"],
@@ -98,7 +105,10 @@
98105
"publish": {
99106
"exclude": [
100107
"!**/*_generated_.ts",
101-
"!packages/crypto-target-*/wasm-target"
108+
"!packages/crypto-target-*/wasm-target",
109+
"!packages/core/crypto/wasm-target",
110+
"!packages/core/data-model/schema/schema.json"
102111
]
103-
}
112+
},
113+
"test": { "exclude": ["prep", "crypto-wasm"] }
104114
}

deno.lock

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

etc/task-codegen.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,20 @@ const tsFormatter = dprint.createFromBuffer(await Deno.readFile(dprintTS.getPath
1111
const formatTS = (code: string) => tsFormatter.formatText({ filePath: 'file.ts', fileText: code })
1212

1313
async function write({ file, code }: { file: string; code: string }) {
14+
let status: string
1415
try {
1516
const prevCode = await Deno.readTextFile(file)
1617
if (prevCode === code) {
17-
$.logStep(`Skipping ${colors.cyan(file)}, no change`)
18-
return
18+
status = 'unchanged'
1919
} else {
2020
await Deno.writeTextFile(file, code)
21-
$.logStep(`Re-written ${colors.cyan(file)}`)
21+
status = 'updated'
2222
}
2323
} catch {
2424
await Deno.writeTextFile(file, code)
25-
$.logStep(`Written ${colors.cyan(file)}`)
25+
status = 'created'
2626
}
27+
$.logStep(`Generated ${colors.cyan(file)} (${status})`)
2728
}
2829

2930
/**

etc/task-prep-iroha.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,21 @@ async function copyArtifacts() {
8282
$.logStep(`Finished copying artifacts to ${colors.bold(colors.cyan(PREP_OUTPUT_DIR))}`)
8383
}
8484

85+
async function copySchemaJson() {
86+
const dest = resolveFromRoot('packages/core/data-model/schema/schema.json')
87+
88+
try {
89+
await Deno.remove(dest)
90+
} catch (err) {
91+
if (!(err instanceof Deno.errors.NotFound)) {
92+
throw err
93+
}
94+
}
95+
96+
await copy(path.join(PREP_OUTPUT_DIR, 'schema.json'), dest)
97+
$.logStep('Copied', dest)
98+
}
99+
85100
const args = parseArgs(Deno.args, {
86101
string: ['git', 'git-rev', 'path'],
87102
boolean: ['check', 'build'],
@@ -100,6 +115,7 @@ await match(args)
100115
.with({ check: true }, async () => {
101116
if (await dirExists(PREP_OUTPUT_DIR)) {
102117
$.logStep(`Checked that ${colors.cyan(PREP_OUTPUT_DIR)} exists`)
118+
await copySchemaJson()
103119
} else {
104120
$.logError(
105121
`Error: ${PREP_OUTPUT_DIR} doesn't exist. Make sure to run ${

etc/task-publish.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const PATHS = [
66
'packages/crypto-target-node',
77
'packages/crypto-target-web',
88
'packages/client',
9+
'packages/client-web-socket-node',
910
].map(
1011
(x) => resolveFromRoot(x),
1112
)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "@iroha/client-web-socket-node",
3+
"version": "0.1.0",
4+
"exports": "./mod.ts",
5+
"imports": {
6+
"ws": "npm:ws@^8.18.0"
7+
}
8+
}

packages/client/web-socket/node.ts renamed to packages/client-web-socket-node/mod.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1-
import type { IncomingData, IsomorphicWebSocketAdapter } from './types.ts'
1+
/**
2+
* WebSocket adapter for Node.js environment. Build on top of `npm:ws`.
3+
*
4+
* @example
5+
* ```ts
6+
* import ws from '@iroha/client-web-socket-node'
7+
* import { WebSocketAPI } from '@iroha/client'
8+
*
9+
* new WebSocketAPI(new URL('http://localhost:8080'), ws)
10+
* ```
11+
*
12+
* @module
13+
*/
14+
15+
import type { IncomingData, IsomorphicWebSocketAdapter } from '@iroha/client/web-socket'
216
import WebSocket from 'ws'
317
import { Buffer } from 'node:buffer'
418

@@ -13,7 +27,10 @@ function handleIncomingData(
1327
throw new Error('Unable to parse incoming data')
1428
}
1529

16-
export const adapter: IsomorphicWebSocketAdapter = {
30+
/**
31+
* The WebSocket adapter.
32+
*/
33+
const adapter: IsomorphicWebSocketAdapter = {
1734
initWebSocket: (params) => {
1835
const socket = new WebSocket(params.url)
1936

@@ -33,3 +50,5 @@ export const adapter: IsomorphicWebSocketAdapter = {
3350
}
3451
},
3552
}
53+
54+
export default adapter

0 commit comments

Comments
 (0)