-
Notifications
You must be signed in to change notification settings - Fork 1
docs: overhaul all SDK READMEs #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rohitg00
wants to merge
10
commits into
main
Choose a base branch
from
docs/readme-overhaul
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
af20100
docs: overhaul all SDK READMEs with correct API patterns
rohitg00 c95a805
fix: correct Streams example in Rust README
rohitg00 274e36e
fix: address review findings across READMEs
rohitg00 c9f2480
docs: replace "callable" with "invoked by name" in Python and Rust AP…
rohitg00 032bd16
docs: align all SDK READMEs to identical structure
rohitg00 c071e8f
docs: add connect() prerequisite notes to trigger and invoke examples
rohitg00 b7cb265
docs: add crates.io badge to root README
rohitg00 dae7a26
docs: add TriggerHandler comment to Rust custom trigger type example
rohitg00 50743bb
nit: small README text changes during review
anthonyiscoding 74f5010
docs: overhaul READMEs for consistency across all SDKs
rohitg00 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,100 +1,100 @@ | ||
| # III SDK for Node.js | ||
| # iii-sdk | ||
|
|
||
| ## Installation | ||
| Node.js / TypeScript SDK for the [iii engine](https://github.com/iii-hq/iii). | ||
|
|
||
| [](https://www.npmjs.com/package/iii-sdk) | ||
| [](../../../LICENSE) | ||
|
|
||
| ## Install | ||
|
|
||
| ```bash | ||
| npm install iii-sdk | ||
| ``` | ||
|
|
||
| ## Usage | ||
| ## Quick Start | ||
|
|
||
| ```javascript | ||
| import { III } from 'iii-sdk' | ||
| import { init } from 'iii-sdk' | ||
|
|
||
| /** | ||
| * Make sure the III Core Instance is up and Running on the given URL. | ||
| */ | ||
| const iii = new III(process.env.III_BRIDGE_URL ?? 'ws://localhost:49134') | ||
| const iii = init('ws://localhost:49134') | ||
|
|
||
| iii.registerFunction({ id: 'myFunction' }, (req) => { | ||
| return { status_code: 200, body: { message: 'Hello, world!' } } | ||
| iii.registerFunction({ id: 'greet' }, async (input) => { | ||
| return { message: `Hello, ${input.name}!` } | ||
| }) | ||
|
|
||
| iii.registerTrigger({ | ||
| type: 'http', | ||
| function_id: 'myFunction', | ||
| config: { api_path: 'myApiPath', http_method: 'POST' }, | ||
| function_id: 'greet', | ||
| config: { api_path: 'greet', http_method: 'POST' }, | ||
| }) | ||
|
|
||
| const result = await iii.trigger('greet', { name: 'world' }) | ||
| ``` | ||
|
|
||
| ### Registering Functions | ||
| ## API | ||
|
|
||
| III Allows you to register functions that can be invoked by other services. | ||
| | Method | Description | | ||
| |--------|-------------| | ||
| | `init(url, options?)` | Create and connect to the engine. Returns an `ISdk` instance | | ||
| | `iii.registerFunction({ id }, handler)` | Register a function that can be invoked by name | | ||
| | `iii.registerTrigger({ type, function_id, config })` | Bind a trigger (HTTP, cron, queue, etc.) to a function | | ||
| | `iii.registerTriggerType({ id, description }, handlers)` | Register a custom trigger type | | ||
| | `await iii.trigger(id, data, timeoutMs?)` | Invoke a function and wait for the result | | ||
| | `iii.triggerVoid(id, data)` | Invoke a function without waiting (fire-and-forget) | | ||
|
|
||
| ### Registering Functions | ||
|
|
||
| ```javascript | ||
| iii.registerFunction({ id: 'myFunction' }, (req) => { | ||
| // ... do something | ||
| return { status_code: 200, body: { message: 'Hello, world!' } } | ||
| iii.registerFunction({ id: 'orders.create' }, async (input) => { | ||
| return { status_code: 201, body: { id: '123', item: input.body.item } } | ||
| }) | ||
| ``` | ||
|
|
||
| ### Registering Triggers | ||
|
|
||
| III Allows you to register triggers that can be invoked by other services. | ||
|
|
||
| ```javascript | ||
| iii.registerTrigger({ | ||
| type: 'http', | ||
| function_id: 'myFunction', | ||
| config: { api_path: 'myApiPath', http_method: 'POST' }, | ||
| function_id: 'orders.create', | ||
| config: { api_path: 'orders', http_method: 'POST' }, | ||
| }) | ||
| ``` | ||
|
|
||
| ### Registering Trigger Types | ||
|
|
||
| Triggers are mostly created by III Core Modules, but you can also create your own triggers | ||
| ### Custom Trigger Types | ||
|
|
||
| ```javascript | ||
| iii.registerTrigger_type( | ||
| iii.registerTriggerType( | ||
| { id: 'webhook', description: 'External webhook trigger' }, | ||
| { | ||
| /** | ||
| * This is the id of the trigger type, it's unique. | ||
| * Then, you can register a trigger by calling the registerTrigger method. | ||
| */ | ||
| id: 'myTrigger_type', | ||
| description: 'My trigger type', | ||
| }, | ||
| { | ||
| /** | ||
| * Trigger config has: id, function_id, and config. | ||
| * Your logic should know what to do with the config. | ||
| */ | ||
| registerTrigger: async (config) => { | ||
| // ... do something | ||
| }, | ||
| unregisterTrigger: async (config) => { | ||
| // ... do something | ||
| }, | ||
| registerTrigger: async (config) => { /* setup */ }, | ||
| unregisterTrigger: async (config) => { /* teardown */ }, | ||
| }, | ||
| ) | ||
| ``` | ||
|
|
||
| ### Invoking Functions | ||
|
|
||
| III Allows you to invoke functions, they can be functions from the Core Modules or | ||
| functions registered by workers. | ||
|
|
||
| ```javascript | ||
| const result = await iii.call('myFunction', { param1: 'value1' }) | ||
| console.log(result) | ||
| const result = await iii.trigger('orders.create', { item: 'widget' }) | ||
|
|
||
| iii.triggerVoid('analytics.track', { event: 'page_view' }) | ||
| ``` | ||
|
|
||
| ### Invoking Functions Async | ||
| ## Subpath Exports | ||
|
|
||
| III Allows you to invoke functions asynchronously, they can be functions from the Core Modules or functions registered by workers. | ||
| | Import | What it provides | | ||
| |--------|-----------------| | ||
| | `iii-sdk` | Core SDK (`init`, types) | | ||
| | `iii-sdk/stream` | Stream client for real-time state | | ||
| | `iii-sdk/state` | State client for key-value operations | | ||
| | `iii-sdk/telemetry` | OpenTelemetry integration | | ||
|
|
||
| ```javascript | ||
| iii.callVoid('myFunction', { param1: 'value1' }) | ||
| ``` | ||
| ## Deprecated | ||
|
|
||
| `call()` and `callVoid()` are deprecated aliases for `trigger()` and `triggerVoid()`. They still work but will be removed in a future release. | ||
|
|
||
| ## Resources | ||
|
|
||
| This means the Engine won't hold the execution of the function, it will return immediately. Which means the function will be executed in the background. | ||
| - [Documentation](https://iii.dev/docs) | ||
| - [iii Engine](https://github.com/iii-hq/iii) | ||
| - [Examples](https://github.com/iii-hq/iii-examples) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.