Skip to content

Commit 407169a

Browse files
committed
Refactor spec docs: restructure schema and add actions/hooks
Reorganized the spec documentation by splitting metadata-format.md into object.md, and updating sidebar and index to reflect new structure. Added new documentation for Actions (action.md) and Hooks (hook.md). Removed http-protocol.md and updated references to match the new organization.
1 parent 91de44f commit 407169a

6 files changed

Lines changed: 112 additions & 297 deletions

File tree

docs/.vitepress/config.mts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,18 @@ export default defineConfig({
4343
// Sidebar for Spec section
4444
'/spec/': [
4545
{
46-
text: 'Protocol Specifications',
46+
text: 'Core Schema',
4747
items: [
4848
{ text: 'Overview', link: '/spec/' },
49-
{ text: 'Metadata Format', link: '/spec/metadata-format' },
49+
{ text: 'Objects & Fields', link: '/spec/object' },
50+
{ text: 'Actions (RPC)', link: '/spec/action' },
51+
{ text: 'Hooks', link: '/spec/hook' },
52+
]
53+
},
54+
{
55+
text: 'Data & Transport',
56+
items: [
5057
{ text: 'Query Language', link: '/spec/query-language' },
51-
{ text: 'HTTP Protocol', link: '/spec/http-protocol' }
5258
]
5359
}
5460
]

docs/spec/action.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Action Definitions (RPC)
2+
3+
Custom business logic can be defined in the `actions` section. Actions act as Remote Procedure Calls (RPC) scoped to the object.
4+
5+
```yaml
6+
actions:
7+
approve:
8+
label: Approve Request
9+
description: Approves the current record.
10+
params:
11+
comment:
12+
type: textarea
13+
label: Approval Comments
14+
result:
15+
type: boolean
16+
```
17+
18+
## 1. Properties
19+
20+
| Property | Type | Description |
21+
| :--- | :--- | :--- |
22+
| `label` | `string` | Display label (e.g., for buttons). |
23+
| `icon` | `string` | Icon name. |
24+
| `description` | `string` | Help text. |
25+
| `confirmText` | `string` | Confirmation message before execution. |
26+
| `params` | `Map<string, FieldConfig>` | Input parameters schema. Same structure as Object fields. |
27+
| `result` | `FieldConfig` | The shape of the return value. |

docs/spec/hook.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Hooks (Triggers)
2+
3+
Hooks allow you to execute server-side logic before or after database operations. They are defined in a separate `*.hook.ts` file or registered dynamically.
4+
5+
## 1. Supported Hooks
6+
7+
| Hook | Description | Context Properties |
8+
| :--- | :--- | :--- |
9+
| `beforeFind` | Before a query is executed. | `query` |
10+
| `afterFind` | After a query is executed (results available). | `query`, `result` |
11+
| `beforeCreate` | Before a record is inserted. | `doc` |
12+
| `afterCreate` | After a record is inserted. | `doc`, `result`, `id` |
13+
| `beforeUpdate` | Before a record is updated. | `id`, `doc`, `query` |
14+
| `afterUpdate` | After a record is updated. | `id`, `doc`, `result` |
15+
| `beforeDelete` | Before a record is deleted. | `id`, `query` |
16+
| `afterDelete` | After a record is deleted. | `id`, `result` |
17+
18+
## 2. Hook Implementation
19+
20+
```typescript
21+
import { ObjectQL } from '@objectql/core';
22+
23+
// Inside your server-side loader
24+
const objectql = new ObjectQL();
25+
26+
objectql.registerHook('projects', 'beforeCreate', async (ctx) => {
27+
if (ctx.doc.budget < 0) {
28+
throw new Error("Budget cannot be negative");
29+
}
30+
});
31+
```

docs/spec/http-protocol.md

Lines changed: 0 additions & 234 deletions
This file was deleted.

docs/spec/index.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
This section contains the technical specifications for the ObjectQL platform. It is intended for driver developers, system integrators, and anyone who needs to understand the low-level protocols.
44

5-
* [**Metadata Format**](./metadata-format.md)
6-
* Complete definition of the YAML/JSON schema for Objects and Fields.
7-
* [**Query Language (JSON)**](./query-language.md)
8-
* Specification of the Unified Query JSON format used by drivers and APIs.
9-
* [**HTTP Protocol**](./http-protocol.md)
10-
* Standard REST API endpoints and payload formats.
5+
## Core Schema
6+
* [**Objects & Fields**](./object.md) - Defining data models, field types, and validation rules.
7+
* [**Actions (RPC)**](./action.md) - Defining custom server-side functions and APIs.
8+
* [**Hooks (Triggers)**](./hook.md) - Attaching logic to database events.
9+
* [**App Definition**](./app.md) - Configuring menus and UI layout.
10+
11+
## Data & Transport
12+
* [**Query Language (JSON)**](./query-language.md) - Specification of the Unified Query JSON format used by drivers and APIs.
13+
* [**HTTP Protocol**](./http-protocol.md) - Standard REST API endpoints and payload formats.

0 commit comments

Comments
 (0)