iii-browser-sdk 0.10.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.spdx +22 -0
- package/README.md +118 -0
- package/dist/index.cjs +805 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +839 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +839 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +800 -0
- package/dist/index.mjs.map +1 -0
- package/dist/state.cjs +14 -0
- package/dist/state.cjs.map +1 -0
- package/dist/state.d.cts +86 -0
- package/dist/state.d.cts.map +1 -0
- package/dist/state.d.mts +86 -0
- package/dist/state.d.mts.map +1 -0
- package/dist/state.mjs +12 -0
- package/dist/state.mjs.map +1 -0
- package/dist/stream-B4Etd7Hp.d.cts +145 -0
- package/dist/stream-B4Etd7Hp.d.cts.map +1 -0
- package/dist/stream-CCorhlLO.d.mts +145 -0
- package/dist/stream-CCorhlLO.d.mts.map +1 -0
- package/dist/stream.cjs +0 -0
- package/dist/stream.d.cts +2 -0
- package/dist/stream.d.mts +2 -0
- package/dist/stream.mjs +1 -0
- package/package.json +52 -0
package/LICENSE.spdx
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
SPDXVersion: SPDX-2.1
|
|
2
|
+
DataLicense: CC0-1.0
|
|
3
|
+
PackageName: iii
|
|
4
|
+
DataFormat: SPDXRef-1
|
|
5
|
+
PackageSupplier: Organization: Motia LLC
|
|
6
|
+
PackageHomePage: https://iii.dev
|
|
7
|
+
PackageLicenseDeclared: Elastic-2.0
|
|
8
|
+
PackageLicenseDeclared: Apache-2.0
|
|
9
|
+
PackageCopyrightText: 2024-present, Motia LLC
|
|
10
|
+
PackageSummary: <text>iii is a single engine with three primitives (Function, Trigger, Discovery)
|
|
11
|
+
that replaces API frameworks, task queues, cron schedulers, pub/sub, state stores,
|
|
12
|
+
and observability pipelines.
|
|
13
|
+
</text>
|
|
14
|
+
PackageComment: <text>The engine runtime (engine/) is licensed under Elastic License 2.0.
|
|
15
|
+
All other components (sdk/, cli/, console/, frameworks/, docs/, website/)
|
|
16
|
+
are licensed under Apache License 2.0.
|
|
17
|
+
</text>
|
|
18
|
+
Created: 2024-01-01T00:00:00Z
|
|
19
|
+
PackageDownloadLocation: git://github.com/iii-hq/iii
|
|
20
|
+
PackageDownloadLocation: git+https://github.com/iii-hq/iii.git
|
|
21
|
+
PackageDownloadLocation: git+ssh://github.com/iii-hq/iii.git
|
|
22
|
+
Creator: Organization: Motia LLC
|
package/README.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
[](https://iii.dev)
|
|
2
|
+
|
|
3
|
+
This is an SDK for [iii](https://iii.dev) — unreasonably simple backend development.
|
|
4
|
+
|
|
5
|
+
# iii-browser-sdk
|
|
6
|
+
|
|
7
|
+
Browser SDK for the [iii engine](https://github.com/iii-hq/iii) — WebSocket-based, no Node.js dependencies, no OpenTelemetry.
|
|
8
|
+
|
|
9
|
+
[](https://www.npmjs.com/package/iii-browser-sdk)
|
|
10
|
+
[](../../../LICENSE)
|
|
11
|
+
|
|
12
|
+
## Why the browser SDK
|
|
13
|
+
|
|
14
|
+
The browser SDK turns your frontend into a **first-class iii worker**:
|
|
15
|
+
|
|
16
|
+
- **Persistent connection** — one WebSocket replaces many HTTP round-trips.
|
|
17
|
+
- **Bi-directional** — the engine can invoke functions registered in the browser. Backend workers push data to the frontend with `trigger()`, enabling real-time patterns without polling.
|
|
18
|
+
- **Same API** — `registerFunction`, `trigger`, `registerTrigger`, `onFunctionsAvailable` — all the primitives you use server-side work identically in the browser.
|
|
19
|
+
- **Zero Node.js dependencies** — runs in any browser environment with native `WebSocket`.
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install iii-browser-sdk
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Hello World
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import { registerWorker } from 'iii-browser-sdk'
|
|
31
|
+
|
|
32
|
+
const iii = registerWorker('ws://localhost:49135', {
|
|
33
|
+
workerName: 'browser-client',
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
iii.registerFunction(
|
|
37
|
+
{ id: 'ui::show-notification' },
|
|
38
|
+
async (data: { title: string; body: string }) => {
|
|
39
|
+
showToast(data.title, data.body)
|
|
40
|
+
return { displayed: true }
|
|
41
|
+
},
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
const users = await iii.trigger({
|
|
45
|
+
function_id: 'api::get::users',
|
|
46
|
+
payload: {},
|
|
47
|
+
})
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## API
|
|
51
|
+
|
|
52
|
+
| Operation | Signature | Description |
|
|
53
|
+
| ------------------------ | --------------------------------------------------------------------- | ------------------------------------------------------------ |
|
|
54
|
+
| Initialize | `registerWorker(url, options?)` | Connect to the engine via browser WebSocket. Returns `ISdk` |
|
|
55
|
+
| Register function | `iii.registerFunction({ id }, handler)` | Register a function the engine (or backend) can invoke |
|
|
56
|
+
| Register trigger | `iii.registerTrigger({ type, function_id, config })` | Bind a trigger to a function |
|
|
57
|
+
| Invoke (await) | `await iii.trigger({ function_id, payload })` | Invoke a function and wait for the result |
|
|
58
|
+
| Invoke (fire-and-forget) | `iii.trigger({ function_id, payload, action: TriggerAction.Void() })` | Invoke without waiting |
|
|
59
|
+
| Create channel | `iii.createChannel()` | Create a streaming channel pair (writer + reader) |
|
|
60
|
+
| Functions available | `iii.onFunctionsAvailable(fn)` | Subscribe to function availability changes |
|
|
61
|
+
| Shutdown | `iii.shutdown()` | Gracefully disconnect from the engine |
|
|
62
|
+
|
|
63
|
+
### Registering Functions
|
|
64
|
+
|
|
65
|
+
Register a function in the browser that backend workers can call:
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
iii.registerFunction(
|
|
69
|
+
{ id: 'ui::show-notification' },
|
|
70
|
+
async (data: { title: string; body: string }) => {
|
|
71
|
+
showToast(data.title, data.body)
|
|
72
|
+
return { displayed: true }
|
|
73
|
+
},
|
|
74
|
+
)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Calling Backend Functions
|
|
78
|
+
|
|
79
|
+
Invoke any function registered in the engine directly from the browser:
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
const users = await iii.trigger({
|
|
83
|
+
function_id: 'api::get::users',
|
|
84
|
+
payload: {},
|
|
85
|
+
})
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Receiving Live Invocations
|
|
89
|
+
|
|
90
|
+
Backend workers can push data to the browser in real time. No polling required:
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
iii.registerFunction(
|
|
94
|
+
{ id: 'ui::update-dashboard' },
|
|
95
|
+
async (metrics: { cpu: number; memory: number; requests: number }) => {
|
|
96
|
+
document.getElementById('cpu')!.textContent = `${metrics.cpu}%`
|
|
97
|
+
document.getElementById('memory')!.textContent = `${metrics.memory}MB`
|
|
98
|
+
document.getElementById('requests')!.textContent = `${metrics.requests}/s`
|
|
99
|
+
return null
|
|
100
|
+
},
|
|
101
|
+
)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Exports
|
|
105
|
+
|
|
106
|
+
| Import | What it provides |
|
|
107
|
+
| ------------------------ | ------------------------------------- |
|
|
108
|
+
| `iii-browser-sdk` | Core SDK (`registerWorker`, types) |
|
|
109
|
+
| `iii-browser-sdk/stream` | Stream types for real-time state |
|
|
110
|
+
| `iii-browser-sdk/state` | State types for key-value operations |
|
|
111
|
+
|
|
112
|
+
## Resources
|
|
113
|
+
|
|
114
|
+
- [Documentation](https://iii.dev/docs)
|
|
115
|
+
- [Use iii in the Browser](https://iii.dev/docs/how-to/use-iii-in-the-browser)
|
|
116
|
+
- [Browser SDK API Reference](https://iii.dev/docs/api-reference/sdk-browser)
|
|
117
|
+
- [iii Engine](https://github.com/iii-hq/iii)
|
|
118
|
+
- [Examples](https://github.com/iii-hq/iii-examples)
|