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
Copy file name to clipboardExpand all lines: docs/build/functions/development/index.mdx
+42-18Lines changed: 42 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,116 +4,140 @@ When you're ready to implement Functions within your Juno Satellite, you'll have
4
4
5
5
---
6
6
7
-
## Hooks
7
+
## Event-driven Functions
8
+
9
+
Event-driven functions respond to actions occurring in your Satellite. They are triggered automatically and never invoked directly.
10
+
11
+
---
12
+
13
+
### Hooks
8
14
9
15
Hooks allow you to define event-driven logic that responds to specific actions within your Satellite. The following is a list of available hooks and their respective use cases.
Assertions enable validation checks before specific actions are executed within your Satellite. The following is a list of available assertions and their functionalities.
Copy file name to clipboardExpand all lines: docs/build/functions/index.md
+31-21Lines changed: 31 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,33 +16,28 @@ keywords:
16
16
17
17
Functions are a set of features enabling developers to extend the native capabilities of [Satellites](../../terminology.mdx#satellite) using Rust or TypeScript. They let you define serverless behaviors directly within your containerized environment.
18
18
19
-
Triggered by events like document and asset operations, they allow you to automatically run backend code or assertions. These functions are shipped with your container and don’t require you to manage or scale your own servers.
19
+
There are two types of functions:
20
20
21
-
---
22
-
23
-
## How does it work?
24
-
25
-
Functions are defined using hooks that automatically respond to document and asset events such as create, update, or delete. This allows you to embed dynamic behavior directly into your container.
21
+
-[Event-driven functions](#event-driven-functions): triggered automatically in response to actions such as a document being created or an asset being uploaded.
22
+
-[Callable functions](#callable-functions): explicitly invoked from your frontend or from other services.
26
23
27
-
A naive schema representation of a hook that is triggered when a document is set:
28
-
29
-

24
+
---
30
25
31
-
### Asynchronous Hook Spawning
26
+
##Event-driven Functions
32
27
33
-
When a Function is triggered, it spawns hooks asynchronously, operating independently of the caller's action. This means that the execution of the hooks is initiated without waiting for a synchronous response, ensuring that the flow of update calls to the Satellite remains unhindered. Consequently, callers may receive feedback on their actions before the corresponding hooks have commenced their execution.
28
+
Event-driven functions respond to actions occurring in your Satellite. They are triggered automatically and never invoked directly.
34
29
35
-
### Error-Resilient Execution
30
+
### Hooks
36
31
37
-
Hooks are initiated only when there are no errors in the preceding operations. This ensures a robust and dependable execution flow, promoting reliability and consistency in the functioning of Functions.
32
+
Hooks respond to specific actions within your Satellite. They run asynchronously, independently of the caller's request - meaning the caller may receive a response before the hook has finished executing.
38
33
39
-
### Optional
34
+

40
35
41
-
Custom hooks are not active by default. You need to opt in to enable event-driven execution of your own logic.
36
+
:::note
42
37
43
-
---
38
+
Hooks are only initiated when the preceding operation completes without errors.
@@ -58,11 +53,9 @@ Custom hooks are not active by default. You need to opt in to enable event-drive
58
53
|`on_init`| Satellite | Called during the initialization of the Satellite. |
59
54
|`on_post_upgrade`| Satellite | Invoked after the Satellite has been upgraded to a new version. |
60
55
61
-
---
62
-
63
-
## Assertions
56
+
### Assertions
64
57
65
-
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.
58
+
Assertions run synchronously before an operation is executed. They allow you to validate or reject actions before any data is written.
@@ -73,6 +66,23 @@ In addition to hooks, developers have the option to expand the native rule set o
73
66
74
67
---
75
68
69
+
## Callable Functions
70
+
71
+
Callable functions are explicitly invoked — from your frontend or from other services. They expose query and update endpoints directly from your Satellite.
72
+
73
+
:::tip
74
+
75
+
This is conceptually similar to exposing your own endpoints on an API.
|`query`| A read-only function that returns data without modifying state. |
82
+
|`update`| A function that can read and write state. |
83
+
84
+
---
85
+
76
86
## Rust vs. TypeScript
77
87
78
88
You can write serverless functions in either [Rust](./development/rust.mdx) or [TypeScript](./development/typescript.mdx), depending on your needs and project goals.
0 commit comments