Skip to content

Commit 53d90c6

Browse files
committed
feat: docs for hercules ts sdk
1 parent 6519c1d commit 53d90c6

39 files changed

Lines changed: 2314 additions & 6 deletions

docs/core/action.mdx

Lines changed: 271 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
1+
---
2+
title: Action
3+
description: The root class for every Hercules action
4+
---
5+
6+
import { TypeTable } from 'fumadocs-ui/components/type-table';
7+
8+
`Action` is the entry point of every Hercules action. It manages the gRPC connection to Aquila, holds all registered
9+
functions, events, and data types, and emits lifecycle events you can subscribe to.
10+
11+
```ts
12+
import { Action } from '@code0-tech/hercules';
13+
```
14+
15+
## Constructor
16+
17+
```ts
18+
new Action(
19+
identifier: string,
20+
version: string,
21+
aquilaUrl: string | undefined,
22+
author: string,
23+
icon: string,
24+
documentation: string,
25+
name: Translation[],
26+
configurationDefinitions?: ConfigurationDefinition[]
27+
)
28+
```
29+
30+
<TypeTable
31+
type={{
32+
identifier: {
33+
description: 'Unique identifier for this action.',
34+
type: 'string',
35+
required: true,
36+
},
37+
version: {
38+
description: 'Semver version string.',
39+
type: 'string',
40+
required: true,
41+
},
42+
aquilaUrl: {
43+
description: 'Default gRPC endpoint for Aquila. Can be overridden in connect().',
44+
type: 'string | undefined',
45+
required: true,
46+
},
47+
author: {
48+
description: 'Author or organisation name.',
49+
type: 'string',
50+
required: true,
51+
},
52+
icon: {
53+
description: 'Icon identifier (e.g. "tabler:bolt").',
54+
type: 'string',
55+
required: true,
56+
},
57+
documentation: {
58+
description: 'Short documentation string for this action.',
59+
type: 'string',
60+
required: true,
61+
},
62+
name: {
63+
description: 'Localised display names.',
64+
type: 'Translation[]',
65+
required: true,
66+
},
67+
configurationDefinitions: {
68+
description: 'Per-project configuration fields shown in the platform UI.',
69+
type: 'ConfigurationDefinition[]',
70+
default: '[]',
71+
},
72+
}}
73+
/>
74+
75+
### Example
76+
77+
```ts
78+
const action = new Action(
79+
'my-action',
80+
'1.0.0',
81+
'aquila.example.com:8081',
82+
'my-org',
83+
'tabler:bolt',
84+
'Does something useful',
85+
[{ code: 'en-US', content: 'My Action' }],
86+
[
87+
{
88+
identifier: 'API_KEY',
89+
type: 'string',
90+
name: [{ code: 'en-US', content: 'API Key' }],
91+
},
92+
],
93+
);
94+
```
95+
96+
## Properties
97+
98+
### Managers
99+
100+
Each manager is a key-value store backed by a `Map`. See [BaseManager](./base-manager.mdx) for available methods.
101+
102+
<TypeTable
103+
type={{
104+
configs: {
105+
description: 'Stores per-project configurations keyed by project ID. Updated automatically when Aquila sends module configurations.',
106+
type: 'ConfigManager',
107+
},
108+
functions: {
109+
description: 'Stores registered public-facing function definitions keyed by runtimeName.',
110+
type: 'FunctionManager',
111+
},
112+
runtimeFunctions: {
113+
description: 'Stores registered runtime function definitions keyed by runtimeName.',
114+
type: 'RuntimeFunctionManager',
115+
},
116+
dataTypes: {
117+
description: 'Stores registered data type definitions keyed by identifier.',
118+
type: 'DataTypeManager',
119+
},
120+
events: {
121+
description: 'Stores registered public-facing event definitions keyed by identifier.',
122+
type: 'EventManager',
123+
},
124+
runtimeEvents: {
125+
description: 'Stores registered runtime event definitions keyed by identifier.',
126+
type: 'RuntimeEventManager',
127+
},
128+
}}
129+
/>
130+
131+
### Getters
132+
133+
<TypeTable
134+
type={{
135+
identifier: {
136+
description: 'The action identifier passed to the constructor.',
137+
type: 'string',
138+
},
139+
version: {
140+
description: 'The version string passed to the constructor.',
141+
type: 'string',
142+
},
143+
stream: {
144+
description: 'The active gRPC duplex stream. undefined until connect() resolves.',
145+
type: 'DuplexStreamingCall | undefined',
146+
},
147+
}}
148+
/>
149+
150+
## Methods
151+
152+
### `registerFunction`
153+
154+
```ts
155+
action.registerFunction<T extends RuntimeFunctionClass>(klass: FunctionClass<T>): void
156+
```
157+
158+
Registers a public-facing function definition. The class must extend a `RuntimeFunctionClass`.
159+
160+
```ts
161+
action.registerFunction(FibonacciFunction);
162+
```
163+
164+
### `registerRuntimeFunction`
165+
166+
```ts
167+
action.registerRuntimeFunction(klass: RuntimeFunctionClass): void
168+
```
169+
170+
Registers a runtime function implementation. Unless `@OmitRuntimeFunction()` is applied, a matching `FunctionProps`
171+
entry is also created automatically.
172+
173+
```ts
174+
action.registerRuntimeFunction(FibonacciRuntimeFunction);
175+
```
176+
177+
### `registerDataTypeClass`
178+
179+
```ts
180+
action.registerDataTypeClass(klass: DataTypeClass): void
181+
```
182+
183+
Registers a custom data type.
184+
185+
### `registerEventClass`
186+
187+
```ts
188+
action.registerEventClass(klass: EventClass): void
189+
```
190+
191+
Registers a user-facing event (flow type).
192+
193+
### `registerRuntimeEventClass`
194+
195+
```ts
196+
action.registerRuntimeEventClass(klass: RuntimeEventClass): void
197+
```
198+
199+
Registers a runtime event definition. Unless `@OmitEvent()` is applied, a matching `EventModel` entry is also created
200+
automatically.
201+
202+
### `connect`
203+
204+
```ts
205+
action.connect(authToken: string, aquilaUrl?: string, grpcOptions?: GrpcOptions): Promise<void>
206+
```
207+
208+
Opens the gRPC connection to Aquila, sends the module descriptor, and starts processing the incoming stream.
209+
210+
<TypeTable
211+
type={{
212+
authToken: {
213+
description: 'Authentication token for Aquila.',
214+
type: 'string',
215+
required: true,
216+
},
217+
aquilaUrl: {
218+
description: 'Override the URL set in the constructor.',
219+
type: 'string',
220+
},
221+
grpcOptions: {
222+
description: 'Additional gRPC transport options.',
223+
type: 'GrpcOptions',
224+
},
225+
}}
226+
/>
227+
228+
```ts
229+
await action.connect(process.env.AUTH_TOKEN!);
230+
```
231+
232+
### `fire`
233+
234+
```ts
235+
action.fire(
236+
eventClass: EventClass | RuntimeEventClass,
237+
projectId: number | bigint,
238+
payload: PlainValue
239+
): Promise<void>
240+
```
241+
242+
Dispatches an event to Aquila for a specific project. Throws if `connect()` has not been called or if the class is
243+
missing an `@Identifier` decorator.
244+
245+
<TypeTable
246+
type={{
247+
eventClass: {
248+
description: 'The EventClass or RuntimeEventClass to fire. Must have an @Identifier decorator.',
249+
type: 'EventClass | RuntimeEventClass',
250+
required: true,
251+
},
252+
projectId: {
253+
description: 'ID of the project this event belongs to.',
254+
type: 'number | bigint',
255+
required: true,
256+
},
257+
payload: {
258+
description: 'Event payload matching the event signature.',
259+
type: 'PlainValue',
260+
required: true,
261+
},
262+
}}
263+
/>
264+
265+
```ts
266+
await action.fire(UserCreatedRuntimeEvent, projectId, { userId: 42 });
267+
```
268+
269+
All manager properties on `Action` extend [`BaseManager`](./base-manager.mdx).
270+
271+
`Action` extends Node.js `EventEmitter` — see [`CodeZeroEvent`](./code-zero-event.mdx) for all available events.

docs/core/base-manager.mdx

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
title: BaseManager
3+
description: Shared base class for all managers in Hercules
4+
---
5+
6+
import { TypeTable } from 'fumadocs-ui/components/type-table';
7+
8+
`BaseManager<K, V>` is the abstract base class extended by all managers on the `Action` instance. It wraps a `Map<K,
9+
V>` and exposes a consistent set of read and write methods.
10+
11+
All specific managers — `FunctionManager`, `RuntimeFunctionManager`, `EventManager`, `RuntimeEventManager`,
12+
`DataTypeManager`, and `ConfigManager` — inherit these methods exactly.
13+
14+
## Methods
15+
16+
<TypeTable
17+
type={{
18+
size: {
19+
description: 'Number of entries currently in the manager.',
20+
type: 'number',
21+
},
22+
get: {
23+
description: 'Retrieve a value by key. Returns undefined if not found.',
24+
type: '(key: K) => V | undefined',
25+
},
26+
set: {
27+
description: 'Store a value. Returns the manager instance for chaining.',
28+
type: '(key: K, value: V) => this',
29+
},
30+
has: {
31+
description: 'Check whether a key exists.',
32+
type: '(key: K) => boolean',
33+
},
34+
delete: {
35+
description: 'Remove an entry by key. Returns true if the entry existed.',
36+
type: '(key: K) => boolean',
37+
},
38+
clear: {
39+
description: 'Remove all entries.',
40+
type: '() => void',
41+
},
42+
values: {
43+
description: 'All values as an array.',
44+
type: '() => V[]',
45+
},
46+
keys: {
47+
description: 'All keys as an array.',
48+
type: '() => K[]',
49+
},
50+
entries: {
51+
description: 'All key-value pairs as an array of tuples.',
52+
type: '() => [K, V][]',
53+
},
54+
find: {
55+
description: 'Returns the first value for which the predicate returns true, or undefined.',
56+
type: '(predicate: (value: V, key: K) => boolean) => V | undefined',
57+
},
58+
filter: {
59+
description: 'Returns all values for which the predicate returns true.',
60+
type: '(predicate: (value: V, key: K) => boolean) => V[]',
61+
},
62+
map: {
63+
description: 'Transforms all values into a new array.',
64+
type: '<T>(fn: (value: V, key: K) => T) => T[]',
65+
},
66+
some: {
67+
description: 'Returns true if at least one value satisfies the predicate.',
68+
type: '(predicate: (value: V, key: K) => boolean) => boolean',
69+
},
70+
every: {
71+
description: 'Returns true if all values satisfy the predicate.',
72+
type: '(predicate: (value: V, key: K) => boolean) => boolean',
73+
},
74+
forEach: {
75+
description: 'Calls the function once for each entry.',
76+
type: '(fn: (value: V, key: K) => void) => void',
77+
},
78+
}}
79+
/>
80+
81+
## Implementations
82+
83+
| Manager | Key | Value |
84+
|---|---|---|
85+
| [`FunctionManager`](./function-manager.mdx) | `string` (runtimeName) | `FunctionProps` |
86+
| [`RuntimeFunctionManager`](./runtime-function-manager.mdx) | `string` (runtimeName) | `RuntimeFunctionProps` |
87+
| [`EventManager`](./event-manager.mdx) | `string` (identifier) | `EventModel` |
88+
| [`RuntimeEventManager`](./runtime-event-manager.mdx) | `string` (identifier) | `RuntimeEventProps` |
89+
| [`DataTypeManager`](./data-type-manager.mdx) | `string` (identifier) | `DataTypeProps` |
90+
| [`ConfigManager`](./config-manager.mdx) | `bigint` (projectId) | `ProjectConfiguration` |

0 commit comments

Comments
 (0)