Skip to content

Commit a7aafcb

Browse files
committed
update sdk
1 parent 8e4616c commit a7aafcb

File tree

7 files changed

+284
-13
lines changed

7 files changed

+284
-13
lines changed

.github/workflows/publish.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Publish to npm
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: '18'
20+
registry-url: 'https://registry.npmjs.org'
21+
22+
- name: Setup Bun
23+
uses: oven-sh/setup-bun@v1
24+
with:
25+
bun-version: latest
26+
27+
- name: Install pnpm
28+
uses: pnpm/action-setup@v2
29+
with:
30+
version: latest
31+
32+
- name: Get pnpm store directory
33+
shell: bash
34+
run: |
35+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
36+
37+
- name: Setup pnpm cache
38+
uses: actions/cache@v3
39+
with:
40+
path: ${{ env.STORE_PATH }}
41+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
42+
restore-keys: |
43+
${{ runner.os }}-pnpm-store-
44+
45+
- name: Install dependencies
46+
run: pnpm install --frozen-lockfile
47+
48+
- name: Build SDK
49+
run: |
50+
cd sdk
51+
pnpm build
52+
53+
- name: Run tests
54+
run: |
55+
cd sdk
56+
pnpm test
57+
58+
- name: Publish to npm
59+
run: |
60+
cd sdk
61+
npm publish --access public
62+
env:
63+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

README.md

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,53 @@ A TypeScript SDK for interacting with PolkaVM Query (PVQ)
55
## Installation
66

77
```bash
8+
# Install the published package
9+
npm install @open-web3/pvq
10+
# or
11+
yarn add @open-web3/pvq
12+
# or
13+
pnpm add @open-web3/pvq
14+
15+
# Or install from source
816
pnpm add pvq-sdk
917
```
1018

19+
## Quick Start
20+
21+
```typescript
22+
import { ApiPromise } from '@polkadot/api';
23+
import { PvqProgram } from '@open-web3/pvq';
24+
25+
// Connect to a Polkadot node
26+
const api = await ApiPromise.create({
27+
provider: 'ws://localhost:9944'
28+
});
29+
30+
// Create PVQ program instance
31+
const program = new PvqProgram(
32+
api,
33+
guestProgramBytes, // Uint8Array or hex string
34+
programMetadata // Program metadata object
35+
);
36+
37+
// Execute a query
38+
const result = await program.entrypoint.sumBalance([
39+
21,
40+
['15oF4uVJwmo4TdGW7VfQxNLavjCXviqxT9S1MgbjMNHr6Sp5']
41+
], {
42+
gasLimit: 1000000000000000000n
43+
});
44+
45+
console.log('Query result:', result);
46+
```
47+
1148
## Usage Examples
1249

1350
### Basic Program Execution
1451

1552
```typescript
1653
import { ApiPromise, WsProvider } from '@polkadot/api';
17-
import { PvqProgram } from 'pvq-sdk';
54+
import { PvqProgram } from '@open-web3/pvq';
1855

1956
async function executeProgram() {
2057
const provider = new WsProvider('ws://127.0.0.1:8000');
@@ -60,7 +97,7 @@ const result = await program.executeQuery('sum_balance', { gasLimit: 1000000n },
6097

6198
```typescript
6299
// Fetch metadata from the chain
63-
const metadata = await program.metadata();
100+
const metadata = await program.getMetadata();
64101
console.log('Chain metadata:', metadata);
65102
```
66103

@@ -75,6 +112,33 @@ console.log('Extensions matched:', matched); // true or throws error if not matc
75112
console.log('Cached result:', program.extensionsMatched); // true/false/undefined
76113
```
77114

115+
## API Reference
116+
117+
### PvqProgram
118+
119+
Main class for interacting with PVQ programs.
120+
121+
#### Constructor
122+
123+
```typescript
124+
new PvqProgram(
125+
api: ApiBase<ApiTypes>,
126+
guestProgram: Uint8Array | `0x${string}`,
127+
programMetadata: Record<string, unknown>
128+
)
129+
```
130+
131+
#### Methods
132+
133+
- `executeQuery(entrypoint, options, params)` - Execute a query on the program
134+
- `checkExtensions()` - Check if required extensions are available
135+
- `getMetadata()` - Get runtime metadata
136+
137+
#### Properties
138+
139+
- `entrypoint` - Object containing all available entrypoints as camelCase methods
140+
- `extensionsMatched` - Boolean indicating if extensions check passed
141+
78142
## Program Metadata Format
79143

80144
Your program metadata should follow this structure:

sdk/.npmignore

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Source files
2+
src/
3+
*.ts
4+
*.tsx
5+
6+
# Build artifacts
7+
*.map
8+
dist/**/*.map
9+
10+
# Test files
11+
*.test.js
12+
*.test.d.ts
13+
**/*.test.*
14+
15+
# Development files
16+
.git/
17+
.gitignore
18+
.eslintrc*
19+
.prettierrc*
20+
tsconfig*.json
21+
build.cjs
22+
bun.lockb
23+
24+
# IDE files
25+
.vscode/
26+
.idea/
27+
*.swp
28+
*.swo
29+
30+
# OS files
31+
.DS_Store
32+
Thumbs.db

sdk/README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# @open-web3/pvq
2+
3+
PVQ (Programmable Virtual Query) SDK for Polkadot ecosystem
4+
5+
## Installation
6+
7+
```bash
8+
npm install @open-web3/pvq
9+
# or
10+
yarn add @open-web3/pvq
11+
# or
12+
pnpm add @open-web3/pvq
13+
```
14+
15+
## Usage
16+
17+
```typescript
18+
import { ApiPromise } from '@polkadot/api';
19+
import { PvqProgram } from '@open-web3/pvq';
20+
21+
// Connect to a Polkadot node
22+
const api = await ApiPromise.create({
23+
provider: 'ws://localhost:9944'
24+
});
25+
26+
// Create PVQ program instance
27+
const program = new PvqProgram(
28+
api,
29+
guestProgramBytes, // Uint8Array or hex string
30+
programMetadata // Program metadata object
31+
);
32+
33+
// Execute a query
34+
const result = await program.entrypoint.sumBalance([
35+
21,
36+
['15oF4uVJwmo4TdGW7VfQxNLavjCXviqxT9S1MgbjMNHr6Sp5']
37+
], {
38+
gasLimit: 1000000000000000000n
39+
});
40+
41+
console.log('Query result:', result);
42+
```
43+
44+
## API Reference
45+
46+
### PvqProgram
47+
48+
Main class for interacting with PVQ programs.
49+
50+
#### Constructor
51+
52+
```typescript
53+
new PvqProgram(
54+
api: ApiBase<ApiTypes>,
55+
guestProgram: Uint8Array | `0x${string}`,
56+
programMetadata: Record<string, unknown>
57+
)
58+
```
59+
60+
#### Methods
61+
62+
- `executeQuery(entrypoint, options, params)` - Execute a query on the program
63+
- `checkExtensions()` - Check if required extensions are available
64+
- `getMetadata()` - Get runtime metadata
65+
66+
#### Properties
67+
68+
- `entrypoint` - Object containing all available entrypoints as camelCase methods
69+
- `extensionsMatched` - Boolean indicating if extensions check passed
70+
71+
## Development
72+
73+
```bash
74+
# Install dependencies
75+
pnpm install
76+
77+
# Build the SDK
78+
cd sdk && pnpm build
79+
80+
# Run tests
81+
pnpm test
82+
83+
# Run linting
84+
pnpm lint
85+
```

sdk/build.cjs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { build } from "esbuild";
22

33
await build({
4-
entryPoints: ["src/index.ts"],
4+
entryPoints: [
5+
"src/pvq.ts",
6+
"src/program-registry.ts",
7+
"src/types.ts",
8+
"src/typesdef.ts"
9+
],
510
outdir: "dist/esm",
611
bundle: false,
712
format: "esm",
@@ -11,7 +16,12 @@ await build({
1116
});
1217

1318
await build({
14-
entryPoints: ["src/index.ts"],
19+
entryPoints: [
20+
"src/pvq.ts",
21+
"src/program-registry.ts",
22+
"src/types.ts",
23+
"src/typesdef.ts"
24+
],
1525
outdir: "dist/cjs",
1626
bundle: false,
1727
format: "cjs",

sdk/package.json

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
11
{
2-
"name": "pvq-sdk",
2+
"name": "@open-web3/pvq",
3+
"version": "0.0.1",
34
"type": "module",
45
"devDependencies": {
56
"@types/bun": "latest",
67
"esbuild": "^0.25.2",
78
"prettier": "^3.5.3",
89
"eslint": "^9.0.0"
910
},
10-
"main": "dist/cjs/index.js",
11-
"module": "dist/esm/index.js",
12-
"types": "dist/types/index.d.ts",
11+
"main": "dist/cjs/pvq.js",
12+
"module": "dist/esm/pvq.js",
13+
"types": "dist/types/pvq.d.ts",
1314
"exports": {
14-
"require": "./dist/cjs/index.js",
15-
"import": "./dist/esm/index.js"
15+
"require": "./dist/cjs/pvq.js",
16+
"import": "./dist/esm/pvq.js"
1617
},
18+
"files": [
19+
"dist",
20+
"README.md"
21+
],
1722
"scripts": {
1823
"test": "bun test",
1924
"build": "bun run build:js && bun run build:types",
2025
"build:js": "bun run build.cjs",
2126
"build:types": "tsc -p tsconfig.types.json",
2227
"lint": "eslint src/**/*.ts",
23-
"lint:fix": "eslint src/**/*.ts --fix"
28+
"lint:fix": "eslint src/**/*.ts --fix",
29+
"prepublishOnly": "pnpm build",
30+
"clean": "rm -rf dist"
2431
},
2532
"peerDependencies": {
2633
"typescript": "^5.0.0"

sdk/tsconfig.types.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,17 @@
33
"emitDeclarationOnly": true,
44
"declaration": true,
55
"outDir": "dist/types",
6-
"strict": true
6+
"strict": true,
7+
"target": "ES2020",
8+
"module": "ESNext",
9+
"moduleResolution": "bundler",
10+
"esModuleInterop": true,
11+
"allowSyntheticDefaultImports": true,
12+
"resolveJsonModule": true,
13+
"skipLibCheck": true,
14+
"downlevelIteration": true,
15+
"lib": ["ES2020", "DOM"]
716
},
8-
"include": ["src"]
17+
"include": ["src"],
18+
"exclude": ["src/**/*.test.ts"]
919
}

0 commit comments

Comments
 (0)