-
Notifications
You must be signed in to change notification settings - Fork 0
Reference System Objects
System objects are special objects in ARO that represent external sources and sinks of data. They provide a unified interface for interacting with I/O streams, HTTP requests, files, and plugin-provided resources.
ARO uses a consistent pattern for interacting with system objects:
| Pattern | Direction | Example |
|---|---|---|
| Source | Read FROM object | <Extract> the <data> from the <request: body>. |
| Sink | Write TO object | <Log> "Hello" to the <console>. |
| Bidirectional | Both | <Read>/<Write> the <data> from/to the <file: "./data.json">. |
Sink actions use a clean syntax where the value comes directly after the verb:
<Log> "Hello, World!" to the <console>.
(* Variables work too *)
<Compute> the <greeting> from "Welcome to ARO!".
<Log> <greeting> to the <console>.
(* Objects and arrays *)
<Log> { status: "ok", count: 42 } to the <console>.
Sink verbs that support this syntax:
-
log,print,output,debug(LogAction) -
write(WriteAction) -
send,dispatch(SendAction)
| Identifier | Type | Description |
|---|---|---|
console |
Sink | Standard output stream |
stderr |
Sink | Standard error stream |
stdin |
Source | Standard input stream |
(* Write to console *)
<Log> "Starting server..." to the <console>.
(* Write to stderr *)
<Log> "Warning: config missing" to the <stderr>.
(* Read from stdin *)
<Read> the <input> from the <stdin>.
| Identifier | Type | Description |
|---|---|---|
env |
Source | Environment variables |
(* Read an environment variable *)
<Extract> the <api-key> from the <env: API_KEY>.
(* Read all environment variables *)
<Extract> the <all-vars> from the <env>.
| Identifier | Type | Description |
|---|---|---|
Contract |
Source | OpenAPI contract metadata |
The Contract magic object provides access to the OpenAPI specification at runtime. It's automatically available in any ARO application with an openapi.yaml file.
Properties:
-
Contract.http-server- HTTP server configuration object-
port- Server port (from OpenAPI servers[0].url) -
hostname- Server hostname (default: "0.0.0.0") -
routes- Array of route paths (e.g.,["/users", "/orders"]) -
routeCount- Number of routes defined
-
(* Start HTTP server from Contract *)
<Start> the <http-server> with <Contract>.
(* Access Contract properties *)
<Log> <Contract.http-server.port> to the <console>.
<Log> <Contract.http-server.routes> to the <console>.
(* Shorthand: <http-server> resolves to Contract.http-server *)
<Log> <http-server.port> to the <console>.
Note: Contract is a magic system object (always capitalized), meaning it's automatically generated by the runtime from the OpenAPI specification, not explicitly bound by user code.
| Identifier | Type | Description |
|---|---|---|
file |
Bidirectional | File I/O with format detection |
The file object automatically detects the format based on file extension and serializes/deserializes accordingly.
(* Read JSON file *)
<Read> the <config> from the <file: "./config.json">.
(* Read YAML file *)
<Read> the <settings> from the <file: "./settings.yaml">.
(* Write data to JSON file *)
<Write> <data> to the <file: "./output.json">.
(* Write to CSV *)
<Write> <records> to the <file: "./export.csv">.
Supported formats: .json, .yaml, .yml, .csv, .xml, .toml, .ini, .plist, .sql, .env, .log, .txt
These objects are only available within HTTP request handler feature sets.
| Identifier | Type | Description |
|---|---|---|
request |
Source | Full HTTP request |
pathParameters |
Source | URL path parameters |
queryParameters |
Source | URL query parameters |
headers |
Source | HTTP headers |
body |
Source | Request body |
(getUser: User API) {
(* Access path parameters *)
<Extract> the <id> from the <pathParameters: id>.
(* Access query parameters *)
<Extract> the <limit> from the <queryParameters: limit>.
(* Access headers *)
<Extract> the <auth> from the <headers: Authorization>.
(* Access request body *)
<Extract> the <data> from the <body>.
(* Access full request *)
<Extract> the <method> from the <request: method>.
<Return> an <OK: status> with <user>.
}
| Identifier | Type | Description |
|---|---|---|
event |
Source | Event payload |
shutdown |
Source | Shutdown context |
(Send Email: UserCreated Handler) {
<Extract> the <user> from the <event: user>.
<Send> the <welcome-email> to the <user: email>.
<Return> an <OK: status> for the <notification>.
}
(Application-End: Success) {
<Extract> the <reason> from the <shutdown: reason>.
<Log> <reason> to the <console>.
}
| Identifier | Type | Description |
|---|---|---|
connection |
Bidirectional | Socket connection |
packet |
Source | Socket data packet |
(Echo Server: Socket Event Handler) {
<Extract> the <data> from the <packet>.
<Send> <data> to the <connection>.
}
Plugins can provide custom system objects that integrate with ARO's source/sink pattern.
{
"services": [...],
"systemObjects": [
{
"identifier": "redis",
"description": "Redis key-value store",
"capabilities": ["readable", "writable"],
"readSymbol": "redis_read",
"writeSymbol": "redis_write"
}
]
}import Foundation
@_cdecl("redis_read")
public func redisRead(
_ propertyPtr: UnsafePointer<CChar>?,
_ resultPtr: UnsafeMutablePointer<UnsafeMutablePointer<CChar>?>
) -> Int32 {
let key = propertyPtr.map { String(cString: $0) } ?? ""
// Your Redis read logic here
guard let value = RedisClient.shared.get(key) else {
return 1 // Not found
}
resultPtr.pointee = strdup(value)
return 0
}
@_cdecl("redis_write")
public func redisWrite(
_ valuePtr: UnsafePointer<CChar>,
_ resultPtr: UnsafeMutablePointer<UnsafeMutablePointer<CChar>?>
) -> Int32 {
let value = String(cString: valuePtr)
// Your Redis write logic here
RedisClient.shared.set(value)
return 0
}(* Read from Redis *)
<Get> the <session> from the <redis: "session:123">.
(* Write to Redis *)
<Set> <userData> to the <redis: "user:456">.
| Capability | Description |
|---|---|
source |
Can read data (readable) |
sink |
Can write data (writable) |
bidirectional |
Both readable and writable |
System object errors are handled by the ARO runtime with descriptive messages:
System object 'redis' is not readable (sink only)
Property 'nonexistent' not found in system object 'request'
System object 'database' is not available in non-HTTP context
Failed to read from system object 'redis': Connection refused
Fundamentals
- The Basics
- Feature Sets
- Actions
- Variables
- Type System
- Control Flow
- Error Handling
- Computations
- Dates
- Concurrency
Runtime & Events
I/O & Communication
Advanced