Skip to content

Commit fe222d9

Browse files
committed
Add server integration and CLI documentation
Introduces a new server integration guide for ObjectQL, detailing usage with Node.js, Express, and Next.js, and describing the HTTP protocol. Adds a README for the CLI package with installation and command usage. Updates main README and guide index to reference new server features and documentation.
1 parent 0ea579f commit fe222d9

4 files changed

Lines changed: 144 additions & 1 deletion

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ It is **not** an ORM, but a high-level data protocol designed for AI agents, low
4444
* The core logic is completely decoupled from storage drivers.
4545
* Easily extensible to support other data sources (e.g., REST APIs, GraphQL, SQLite).
4646

47-
47+
* **🌐 Universal Server:**
48+
* Built-in HTTP adapter (`@objectql/server`) to run anywhere (Node, Express, Next.js).
49+
* Standardized JSON API for CRUD and Actions.
4850

4951
## 📦 Installation
5052

docs/guide/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ ObjectQL connects to your database via drivers.
1414
* [**MongoDB**](./drivers/mongo.md): MongoDB support.
1515

1616
## 3. Building Apps
17+
* [**Server Integration**](./server-integration.md): Running ObjectQL on Node, Express, or Next.js.
1718
* [**Hooks**](./logic-hooks.md): Writing triggers (before/after create, update, delete).
1819
* [**Custom Actions**](./logic-actions.md): Defining custom RPC endpoints.
1920
* [**AI Applications**](./ai.md): Building AI-powered apps.

docs/guide/server-integration.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Server Integration
2+
3+
ObjectQL is designed to be framework-agnostic. While it can be used directly as a library, we provide a standard `@objectql/server` package to expose your application via HTTP.
4+
5+
## The `@objectql/server` Package
6+
7+
This package provides a standardized way to handle HTTP requests, similar to libraries like `better-auth`. It receives a standard JSON request body and routes it to the correct internal ObjectQL operation (`find`, `create`, `action`, etc.).
8+
9+
### Installation
10+
11+
```bash
12+
pnpm add @objectql/server
13+
```
14+
15+
## Supported Frameworks
16+
17+
### 1. Node.js (Raw HTTP)
18+
19+
You can mount the handler directly on a native Node.js `http.Server`.
20+
21+
```typescript
22+
import { createNodeHandler } from '@objectql/server';
23+
import { app } from './my-objectql-app'; // Your ObjectQL instance
24+
import { createServer } from 'http';
25+
26+
const server = createServer(createNodeHandler(app));
27+
server.listen(3000);
28+
```
29+
30+
### 2. Express
31+
32+
Mount ObjectQL on any route path.
33+
34+
```typescript
35+
import express from 'express';
36+
import { createNodeHandler } from '@objectql/server';
37+
import { app } from './my-objectql-app';
38+
39+
const server = express();
40+
// ObjectQL server adapter handles body parsing automatically,
41+
// but works fine if you already used express.json()
42+
server.all('/api/objectql', createNodeHandler(app));
43+
44+
server.listen(3000);
45+
```
46+
47+
### 3. Next.js (Pages Router)
48+
49+
```typescript
50+
// pages/api/objectql.ts
51+
import { createNodeHandler } from '@objectql/server';
52+
import { app } from '../../lib/store';
53+
54+
export const config = {
55+
api: {
56+
bodyParser: false, // Let ObjectQL handle it, or true if you prefer
57+
},
58+
};
59+
60+
export default createNodeHandler(app);
61+
```
62+
63+
## The Protocol
64+
65+
The server exposes a single endpoint that accepts POST requests with a JSON body defined by `ObjectQLRequest`:
66+
67+
```typescript
68+
interface ObjectQLRequest {
69+
op: 'find' | 'findOne' | 'create' | 'update' | 'delete' | 'count' | 'action';
70+
object: string;
71+
args: any;
72+
user?: any; // For passing authentication context
73+
}
74+
```
75+
76+
**Example (cURL):**
77+
78+
```bash
79+
curl -X POST http://localhost:3000/api/objectql \
80+
-H "Content-Type: application/json" \
81+
-d '{
82+
"op": "create",
83+
"object": "User",
84+
"args": {
85+
"data": { "name": "Alice", "email": "alice@example.com" }
86+
}
87+
}'
88+
```
89+
90+
## Dev Server
91+
92+
For rapid prototyping, `@objectql/cli` provides a built-in dev server.
93+
94+
```bash
95+
# Serves the current directory schema on port 3000
96+
objectql serve
97+
```
98+
99+
See [CLI Documentation](../package/cli) for more details.

packages/cli/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# @objectql/cli
2+
3+
Command Line Interface for ObjectQL.
4+
5+
## Installation
6+
7+
```bash
8+
npm install -g @objectql/cli
9+
# OR
10+
pnpm add -D @objectql/cli
11+
```
12+
13+
## Commands
14+
15+
### `generate` (alias: `g`)
16+
17+
Generate TypeScript interfaces from your `object.yml` definitions.
18+
19+
```bash
20+
objectql generate -s src -o src/generated
21+
```
22+
23+
### `serve` (alias: `s`)
24+
25+
Start a lightweight development server with an in-memory database. Perfect for rapid prototyping without setting up a backend project.
26+
27+
```bash
28+
# Start server in current directory (port 3000)
29+
objectql serve
30+
31+
# Specify options
32+
objectql serve --dir ./src/schema --port 8080
33+
```
34+
35+
### `repl` (alias: `r`)
36+
37+
Start an interactive shell to query your data.
38+
39+
```bash
40+
objectql repl
41+
```

0 commit comments

Comments
 (0)