You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: integrate guards in typescript and rust guides (#676)
* docs: integrate guards in typescript and rust guides
Signed-off-by: David Dal Busco <david.dalbusco@outlook.com>
* 📄 Update LLMs.txt snapshot for PR review
---------
Signed-off-by: David Dal Busco <david.dalbusco@outlook.com>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Copy file name to clipboardExpand all lines: .llms-snapshots/llms-full.txt
+50Lines changed: 50 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -7101,6 +7101,40 @@ Hooks execute asynchronously, separate from the request-response cycle. Changes
7101
7101
7102
7102
---
7103
7103
7104
+
## Custom Functions
7105
+
7106
+
Custom Functions let you define callable endpoints directly inside your Satellite. Unlike hooks, which react to events, custom functions are explicitly invoked - from your frontend or from other modules.
7107
+
7108
+
### Query vs. Update
7109
+
7110
+
A **query** is a read-only function. It returns data without modifying any state. Queries are fast and suitable for fetching or computing information.
7111
+
7112
+
An **update** is a function that can read and write state. Use it when your logic needs to persist data or trigger side effects. Updates can also be used for read operations when the response needs to be certified - making them suitable for security-sensitive use cases where data integrity must be guaranteed.
7113
+
7114
+
### Defining a Function
7115
+
7116
+
You define them using standard `ic_cdk` macros:
7117
+
7118
+
```
7119
+
use ic_cdk::query;#[ic_cdk::query]fn hello_world() -> String { "Hello, World!".to_string()}include_satellite!();
7120
+
```
7121
+
7122
+
When you build your project, Juno automatically generates a client API based on your function definitions, so you can call them directly from your frontend.
7123
+
7124
+
### Guards
7125
+
7126
+
Guards let you protect custom functions by running a check before the handler executes. If the guard returns an error, the function is not invoked.
Juno provides built-in guards you can use directly.
7133
+
7134
+
📦 See all available built-in guards in the ([SDK reference](#guards)).
7135
+
7136
+
---
7137
+
7104
7138
## Assertions
7105
7139
7106
7140
Assertions allow you to validate or reject operations before they are executed. They're useful for enforcing data integrity, security policies, or business rules inside your Satellite, and they run synchronously during the request lifecycle.
@@ -7305,6 +7339,22 @@ When you build your project, a type-safe client API is automatically generated b
A **query** is a read-only function. It returns data without modifying any state. Queries are fast and suitable for fetching or computing information.
4
+
5
+
An **update** is a function that can read and write state. Use it when your logic needs to persist data or trigger side effects. Updates can also be used for read operations when the response needs to be certified - making them suitable for security-sensitive use cases where data integrity must be guaranteed.
Copy file name to clipboardExpand all lines: docs/guides/rust.mdx
+50Lines changed: 50 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -105,6 +105,56 @@ Hooks execute asynchronously, separate from the request-response cycle. Changes
105
105
106
106
---
107
107
108
+
## Custom Functions
109
+
110
+
Custom Functions let you define callable endpoints directly inside your Satellite. Unlike hooks, which react to events, custom functions are explicitly invoked - from your frontend or from other modules.
When you build your project, Juno automatically generates a client API based on your function definitions, so you can call them directly from your frontend.
132
+
133
+
### Guards
134
+
135
+
Guards let you protect custom functions by running a check before the handler executes. If the guard returns an error, the function is not invoked.
136
+
137
+
```rust
138
+
usejunobuild_satellite::caller_is_admin;
139
+
140
+
fnmy_function_guard() ->Result<(), String> {
141
+
caller_is_admin()
142
+
}
143
+
144
+
#[ic_cdk::query(guard ="my_function_guard")]
145
+
fnhello_world() ->String {
146
+
"Hello, admin!".to_string()
147
+
}
148
+
149
+
include_satellite!();
150
+
```
151
+
152
+
Juno provides built-in guards you can use directly.
153
+
154
+
📦 See all available built-in guards in the [SDK reference](#guards).
155
+
156
+
---
157
+
108
158
## Assertions
109
159
110
160
Assertions allow you to validate or reject operations before they are executed. They're useful for enforcing data integrity, security policies, or business rules inside your Satellite, and they run synchronously during the request lifecycle.
Copy file name to clipboardExpand all lines: docs/guides/typescript.mdx
+35-4Lines changed: 35 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -141,11 +141,9 @@ Custom Functions let you define callable endpoints directly inside your Satellit
141
141
142
142
You define them using `defineQuery` or `defineUpdate`, describe their input and output shapes with the `j` type system, and Juno takes care of generating all the necessary bindings under the hood.
A **query** is a read-only function. It returns data without modifying any state. Queries are fast and suitable for fetching or computing information.
147
-
148
-
An **update** is a function that can read and write state. Use it when your logic needs to persist data or trigger side effects. Updates can also be used for read operations when the response needs to be certified - making them suitable for security-sensitive use cases where data integrity must be guaranteed.
146
+
<QueryVsUpdate />
149
147
150
148
### Defining a Function
151
149
@@ -182,6 +180,39 @@ import { functions } from "../declarations/satellite/satellite.api.ts";
0 commit comments