Skip to content

Commit 3c2b1bd

Browse files
Merge pull request #1 from viamrobotics/v0.0.1
v0.1.0
2 parents a60ca27 + bf513ad commit 3c2b1bd

33 files changed

+1404
-232
lines changed

.changeset/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changesets
2+
3+
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
4+
with multi-package repos, or single-package repos to help you version and publish your code. You can
5+
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
6+
7+
We have a quick list of common questions to get you started engaging with this project in
8+
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)

.changeset/config.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
3+
"changelog": "@changesets/cli/changelog",
4+
"commit": false,
5+
"fixed": [],
6+
"linked": [],
7+
"access": "restricted",
8+
"baseBranch": "main",
9+
"updateInternalDependencies": "patch",
10+
"ignore": []
11+
}

.changeset/silver-bags-dress.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@viamrobotics/svelte-sdk': minor
3+
---
4+
5+
Initial release

.github/workflows/main.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Main
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
permissions: write-all
8+
9+
jobs:
10+
deploy-and-publish:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout 🛎️
15+
uses: actions/checkout@v4
16+
17+
- name: Setup pnpm
18+
uses: pnpm/action-setup@v4
19+
with:
20+
node-version: 22
21+
22+
- name: Install and Build 🔧
23+
run: |
24+
pnpm i
25+
pnpm run build
26+
27+
- name: Create Release Pull Request or Publish to npm
28+
id: changesets
29+
uses: changesets/action@v1
30+
with:
31+
# This expects you to have a script called release which does a build for your packages and calls changeset publish
32+
publish: npm run release
33+
env:
34+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/pullrequest.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Pull Request Checks
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
jobs:
9+
check:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout 🛎️
14+
uses: actions/checkout@v4
15+
16+
- name: Setup Node
17+
uses: pnpm/action-setup@v4
18+
with:
19+
node-version: 22
20+
21+
- name: Install 🔧
22+
run: pnpm i
23+
24+
- name: Check 💅
25+
run: npm run check
26+
27+
lint:
28+
runs-on: ubuntu-latest
29+
30+
steps:
31+
- name: Checkout 🛎️
32+
uses: actions/checkout@v4
33+
34+
- name: Setup Node
35+
uses: pnpm/action-setup@v4
36+
with:
37+
node-version: 22
38+
39+
- name: Install 🔧
40+
run: pnpm i
41+
42+
- name: Lint 💅
43+
run: npm run lint
44+
45+
test:
46+
runs-on: ubuntu-latest
47+
48+
steps:
49+
- name: Checkout 🛎️
50+
uses: actions/checkout@v4
51+
52+
- name: Setup pnpm
53+
uses: pnpm/action-setup@v4
54+
with:
55+
node-version: 22
56+
57+
- name: Install 🔧
58+
run: pnpm i
59+
60+
- name: Install playwright 🔧
61+
run: npx playwright install chromium --with-deps
62+
63+
- name: Test 🔬
64+
run: pnpm test

.prettierrc.cjs

Lines changed: 0 additions & 12 deletions
This file was deleted.

README.md

Lines changed: 158 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,154 @@
11
# viam-svelte-sdk
22

3+
`pnpm i --save @viamrobotics/svelte-sdk @viamrobotics/sdk @tanstack/svelte-query`
4+
5+
## Getting started
6+
7+
The Viam Svelte SDK provides a reactive layer over `@viamrobotics/sdk`.
8+
9+
To get started, Include the `ViamProvider` component. Any child component will have access to the SDK hooks.
10+
11+
A map of `PartID`s to `DialConf`s must also be provided to connect to your machine(s).
12+
13+
```svelte
14+
<script lang="ts">
15+
import { ViamProvider } from '@viamrobotics/svelte-sdk';
16+
import type { DialConf } from '@viamrobotics/sdk';
17+
18+
let { children } = $props();
19+
20+
const dialConfigs: Record<string, DialConf> = {
21+
'my-part-id': {
22+
host: 'my-host',
23+
credentials: {
24+
type: 'api-key',
25+
authEntity: 'my-api-key-id',
26+
payload: 'my-api-key-value',
27+
},
28+
signalingAddress: 'https://app.viam.dev:443',
29+
disableSessions: false,
30+
},
31+
};
32+
</script>
33+
34+
<ViamProvider {dialConfigs}>
35+
{@render children()}
36+
</ViamProvider>
37+
```
38+
39+
### useRobotClient / useConnectionStatus
40+
41+
In any child component, you can access the `RobotClient` and `MachineConnectionStatus` of any connected machine with the `useRobotClient` and `useConnectionStatus` hooks.
42+
43+
```svelte
44+
<script lang="ts">
45+
import { useConnectionStatus, useRobotClient } from '@viamrobotics/svelte-sdk';
46+
47+
interface Props {
48+
partID: string;
49+
}
50+
51+
let { partID }: Props = $props();
52+
53+
const status = useConnectionStatus(() => partID);
54+
const client = useRobotClient(() => partID);
55+
56+
$inspect(status.current);
57+
$inspect(client.current);
58+
</script>
59+
```
60+
61+
### createRobotQuery / createRobotMutation
62+
63+
To execute queries / mutations directly on the robot client, use the following convenience hooks.
64+
65+
```svelte
66+
<script lang="ts">
67+
import {
68+
createRobotMutation,
69+
createRobotQuery,
70+
useRobotClient,
71+
} from '@viamrobotics/svelte-sdk';
72+
73+
let { partID } = $props();
74+
75+
const client = useRobotClient(() => partID);
76+
const version = createRobotQuery(client, 'getVersion');
77+
const stopAll = createRobotMutation(client, 'stopAll');
78+
</script>
79+
80+
{#if version.current.error}
81+
Error fetching version: {version.current.error.message}
82+
{:else if version.current.data}
83+
<p>Platform: {version.current.data.platform}</p>
84+
<p>API version: {version.current.data.apiVersion}</p>
85+
<p>Version: {version.current.data.version}</p>
86+
{/if}
87+
88+
<button onclick={() => stopAll.current.mutate([])}> Stop All </button>
89+
```
90+
91+
### createResourceClient / createResourceQuery / createResourceMutation
92+
93+
To create and execute queries / mutations on resource (component / service) clients, use the following convenience hooks.
94+
95+
```svelte
96+
<script lang="ts">
97+
import { BaseClient } from '@viamrobotics/sdk';
98+
import {
99+
createResourceClient,
100+
createResourceQuery,
101+
createResourceMutation,
102+
} from '@viamrobotics/svelte-sdk';
103+
104+
interface Props {
105+
partID: string;
106+
name: string;
107+
}
108+
109+
let { partID, name }: Props = $props();
110+
111+
const client = createResourceClient(
112+
BaseClient,
113+
() => partID,
114+
() => name
115+
);
116+
117+
const isMoving = createResourceQuery(client, 'isMoving');
118+
const moveStraight = createResourceMutation(client, 'moveStraight');
119+
</script>
120+
121+
Is moving: {isMoving.current.data ?? false}
122+
123+
<button onclick={() => moveStraight.current.mutate([100, 10])}> Move </button>
124+
```
125+
126+
### useResourceNames
127+
128+
Wraps `client.resourceNames()` in a reactive query. Supports optional filtering by resource subtype.
129+
130+
```svelte
131+
<script lang="ts">
132+
import { useResourceNames } from '@viamrobotics/svelte-sdk';
133+
134+
interface Props {
135+
partID: string;
136+
}
137+
138+
let { partID }: Props = $props();
139+
140+
const resources = useResourceNames(() => partID);
141+
const arms = useResourceNames(
142+
() => partID,
143+
() => 'arm'
144+
);
145+
146+
$inspect(resources.current);
147+
$inspect(resources.error);
148+
$inspect(resources.fetching);
149+
</script>
150+
```
151+
3152
## Developing
4153

5154
First install dependencies with `pnpm install`, then start a development server:
@@ -11,10 +160,18 @@ pnpm dev
11160
pnpm dev -- --open
12161
```
13162

14-
## Building
163+
## Building and Publishing
15164

16165
To build the library:
17166

18167
```bash
19168
pnpm package
20169
```
170+
171+
To publish a new version of the library, run the changeset CLI:
172+
173+
```bash
174+
npx @changesets/cli
175+
```
176+
177+
This will trigger the github changeset bot to prepare a new version in CI.

0 commit comments

Comments
 (0)