@korajs/server 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -0
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# @korajs/server
|
|
2
|
+
|
|
3
|
+
Self-hosted sync server for Kora.js applications. Accepts WebSocket and HTTP connections from Kora clients, stores operations, and relays changes between devices. Supports multiple storage backends via Drizzle ORM.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @korajs/server
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { createKoraServer, MemoryServerStore } from '@korajs/server'
|
|
15
|
+
|
|
16
|
+
const server = createKoraServer({
|
|
17
|
+
store: new MemoryServerStore(),
|
|
18
|
+
port: 4567,
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
await server.start()
|
|
22
|
+
// Kora sync server listening on ws://localhost:4567
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Production Setup with PostgreSQL
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { createKoraServer, PostgresServerStore } from '@korajs/server'
|
|
29
|
+
|
|
30
|
+
const server = createKoraServer({
|
|
31
|
+
store: new PostgresServerStore({
|
|
32
|
+
connectionString: process.env.DATABASE_URL,
|
|
33
|
+
}),
|
|
34
|
+
port: 4567,
|
|
35
|
+
auth: async (token) => {
|
|
36
|
+
// Validate JWT or session token
|
|
37
|
+
const user = await verifyToken(token)
|
|
38
|
+
return { userId: user.id }
|
|
39
|
+
},
|
|
40
|
+
scopes: {
|
|
41
|
+
todos: (ctx) => ({ where: { userId: ctx.userId } }),
|
|
42
|
+
},
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
await server.start()
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Storage Backends
|
|
49
|
+
|
|
50
|
+
| Backend | Package | Use Case |
|
|
51
|
+
|---------|---------|----------|
|
|
52
|
+
| `MemoryServerStore` | Built-in | Development and testing |
|
|
53
|
+
| `SqliteServerStore` | Built-in | Small deployments, prototyping |
|
|
54
|
+
| `PostgresServerStore` | Built-in | Production |
|
|
55
|
+
|
|
56
|
+
## Configuration
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
createKoraServer({
|
|
60
|
+
store: serverStore, // Required: storage backend
|
|
61
|
+
port: 4567, // Default: 4567
|
|
62
|
+
auth: async (token) => {}, // Optional: authentication handler
|
|
63
|
+
scopes: {}, // Optional: per-collection data scoping
|
|
64
|
+
maxBatchSize: 1000, // Optional: max operations per sync batch
|
|
65
|
+
})
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## License
|
|
69
|
+
|
|
70
|
+
MIT
|
|
71
|
+
|
|
72
|
+
See the [full documentation](https://github.com/ehoneahobed/kora) for guides, API reference, and examples.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@korajs/server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Kora.js self-hosted sync server",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"better-sqlite3": "^12.8.0",
|
|
36
36
|
"drizzle-orm": "^0.45.2",
|
|
37
37
|
"ws": "^8.18.0",
|
|
38
|
-
"@korajs/core": "0.1.
|
|
39
|
-
"@korajs/sync": "0.1.
|
|
38
|
+
"@korajs/core": "0.1.2",
|
|
39
|
+
"@korajs/sync": "0.1.2"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"postgres": "^3.4.0"
|