Skip to content

Commit

Permalink
docs: serverless functions assertions (#111)
Browse files Browse the repository at this point in the history
Signed-off-by: David Dal Busco <[email protected]>
  • Loading branch information
peterpeterparker authored Mar 29, 2024
1 parent 6dc9af9 commit 938cb38
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions docs/build/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ In the stock Satellite, custom hooks are not active by default. Developers shoul

---

## Assertions

In addition to hooks, developers have the option to expand the native rule set of their Satellites by creating custom assertions. These assertions can be implemented similarly to hooks, with the key difference being that they are synchronous and must return a result indicating the outcome of the assertion.

| Assertion | Provider | Description |
| --------------------- | --------- | --------------------------------------------- |
| `assert_set_doc` | Datastore | Ensures a document can be created or updated. |
| `assert_delete_doc` | Datastore | Verifies that a document can be deleted. |
| `assert_upload_asset` | Storage | Confirms an asset upload can be committed. |
| `assert_delete_asset` | Storage | Checks that an asset can be deleted. |

---

## Getting Started

Incorporating custom Functions into a Juno Satellite requires developers to prepare their project with the necessary Rust environment. This foundational step ensures the capability to develop tailored logic within the Satellite.
Expand Down Expand Up @@ -206,6 +219,54 @@ async fn on_delete_many_assets(context: OnDeleteManyAssetsContext) -> Result<(),

Similarly to [on_set_doc](#on_set_doc), the hook can scope the events to a particular list of collections or be left empty if it should never fire.

### assert_set_doc

Ensures a document can be created or updated.

```rust
#[assert_set_doc]
fn assert_set_doc(_context: AssertSetDocContext) -> Result<(), String> {
// Custom logic for asserting a document's creation or update is possible
Ok(())
}
```

### assert_delete_doc

Verifies that a document can be deleted.

```rust
#[assert_delete_doc]
fn assert_delete_doc(context: AssertDeleteDocContext) -> Result<(), String> {
// Custom logic for asserting a document can be deleted
Ok(())
}
```

### assert_upload_asset

Confirms an asset upload can be committed.

```rust
#[assert_upload_asset]
fn assert_upload_asset(_context: AssertUploadAssetContext) -> Result<(), String> {
// Custom logic for asserting an asset upload is possible
Ok(())
}
```

### assert_delete_asset

Checks that an asset can be deleted.

```rust
#[assert_delete_asset]
fn assert_delete_asset(_context: AssertDeleteAssetContext) -> Result<(), String> {
// Custom logic for asserting an asset can be deleted
Ok(())
}
```

### Including the Satellite

After defining your Functions, at the very end of your `lib.rs` module, include the Satellite to ensure that your custom logic and the default features or Juno are properly registered and executable within the Juno ecosystem.
Expand All @@ -214,6 +275,8 @@ After defining your Functions, at the very end of your `lib.rs` module, include
include_satellite!();
```

---

## Additional Notes

WebAssembly (Wasm) binaries serve as the compilation target for the Satellites. While Juno's CLI automatically specifies this target for you, manual execution of certain `cargo` commands necessitates explicitly providing this target.
Expand Down

0 comments on commit 938cb38

Please sign in to comment.