@evolu/relay 1.1.2-preview.5 → 4.0.0

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 CHANGED
@@ -1,91 +1,64 @@
1
1
  # Evolu Relay
2
2
 
3
- A WebSocket relay server for the Evolu database system that enables real-time synchronization between clients.
3
+ Evolu Relay provides sync and backup for Evolu apps. This package is the
4
+ reference relay built on Node.js. It is published to npm as `@evolu/relay` and
5
+ to Docker Hub as [`evoluhq/relay`](https://hub.docker.com/r/evoluhq/relay).
4
6
 
5
- ## 🚀 Quick Start
7
+ The relay listens on port 4000 by default and stores its SQLite database in
8
+ the `data` directory of the current working directory. Point your app to
9
+ `ws://localhost:4000` by setting the WebSocket transport in your Evolu config.
6
10
 
7
- ### Docker Development (Recommended)
11
+ ## Run with npm
8
12
 
9
13
  ```bash
10
- cd apps/relay
11
- pnpm docker:up
14
+ npx @evolu/relay
12
15
  ```
13
16
 
14
- ### Production Deployment
17
+ ## Run with Docker
15
18
 
16
19
  ```bash
17
- # Complete server setup + deployment
18
- pnpm deploy:full
20
+ docker run --rm -p 4000:4000 -v evolu-relay-data:/app/data docker.io/evoluhq/relay:4
19
21
  ```
20
22
 
21
- The relay will be available at `http://localhost:4000` (Docker) or your server's IP:4000 (production)
23
+ For Docker Compose, download the repository's
24
+ [`docker-compose.yml`](https://github.com/evoluhq/evolu/blob/main/apps/relay/docker-compose.yml)
25
+ and run `docker compose up` from the directory containing that file.
22
26
 
23
- ## 📖 Documentation
27
+ Tags follow the npm package version: `4.0.0`, `4.0`, `4`, and `latest` for the
28
+ newest stable release. Prerelease versions only get their full version tag.
24
29
 
25
- - **[Docker Setup](./README.docker.md)** - Complete Docker containerization guide
30
+ ## Configure
26
31
 
27
- ## 🔧 Development
32
+ The relay reads `PORT` and Relay-specific `EVOLU_RELAY_*` environment variables:
28
33
 
29
- ### Local Development (Node.js)
34
+ | Variable | Default | Description |
35
+ | ----------------------------- | -------- | --------------------------------------------------------------- |
36
+ | `PORT` | `4000` | The TCP port to listen on, also supplied by hosting platforms. |
37
+ | `EVOLU_RELAY_MAX_OWNER_BYTES` | No limit | The storage quota per owner, as a size literal such as `10MiB`. |
30
38
 
31
- ```bash
32
- pnpm dev # Start with file watching
33
- pnpm build # Build TypeScript
34
- pnpm start # Start built application
35
- ```
39
+ Quota values use `ByteSizeLiteral`, such as `0B`, `512KiB`, or `1.5GiB`.
40
+ Bare byte counts such as `1048576` are not accepted; use `1MiB` instead.
41
+ Leave the variable unset for no per-owner storage limit, or set a quota
42
+ appropriate for your deployment. `0B` allows no stored bytes; it does not disable
43
+ the quota. A per-owner quota is not a limit on total disk usage.
36
44
 
37
- ### Docker Development
45
+ An invalid `PORT`, or an empty, malformed, or unknown `EVOLU_RELAY_*` variable,
46
+ stops the relay with a formatted validation error. Invalid supplied values
47
+ never fall back to defaults. `EVOLU_RELAY_PORT` is not supported; use `PORT`.
38
48
 
39
49
  ```bash
40
- pnpm docker:up # Start with logs
41
- pnpm docker:up:detached # Start in background
42
- pnpm docker:down # Stop containers
43
- pnpm docker:logs # View logs
44
- pnpm docker:shell # Access container shell
45
- pnpm docker:clean # Clean up everything
50
+ PORT=4001 EVOLU_RELAY_MAX_OWNER_BYTES=10MiB npx @evolu/relay
46
51
  ```
47
52
 
48
- ## 🛠️ Available Commands
49
-
50
- ### Development
51
-
52
- | Command | Description |
53
- | ------------ | ------------------------------------------- |
54
- | `pnpm dev` | Start development server with file watching |
55
- | `pnpm build` | Build TypeScript to JavaScript |
56
- | `pnpm start` | Start the built application |
57
- | `pnpm clean` | Clean build artifacts |
58
-
59
- ### Docker
60
-
61
- | Command | Description |
62
- | ------------------------- | ------------------------------------ |
63
- | `pnpm docker:up` | Build and start containers with logs |
64
- | `pnpm docker:up:detached` | Start containers in background |
65
- | `pnpm docker:down` | Stop all containers |
66
- | `pnpm docker:restart` | Restart containers with rebuild |
67
- | `pnpm docker:logs` | View container logs |
68
- | `pnpm docker:shell` | Access running container shell |
69
- | `pnpm docker:stats` | View container resource usage |
70
- | `pnpm docker:clean` | Remove containers and cleanup |
71
-
72
- ## 📋 Requirements
73
-
74
- - **Node.js** ≥22.0.0
75
- - **Docker** (for containerized development/deployment)
76
- - **pnpm** (workspace package manager)
53
+ The Docker health check follows `PORT`. Use a fixed, nonzero port in Docker;
54
+ `PORT=0` selects an unpredictable port that the health check cannot discover.
55
+ The image exposes port 4000, so map a custom port explicitly:
77
56
 
78
- ## 🔗 Integration
79
-
80
- After deployment, your Evolu applications can connect to the relay:
81
-
82
- **Development**: `ws://localhost:4000`
83
- **Production**: `ws://your-server-ip:4000`
84
-
85
- The relay handles WebSocket connections and data synchronization across all connected Evolu applications.
86
-
87
- ---
88
-
89
- 📚 **Quick Links**:
57
+ ```bash
58
+ docker run --rm -e PORT=4001 -p 4001:4001 -v evolu-relay-data:/app/data docker.io/evoluhq/relay:4
59
+ ```
90
60
 
91
- - [Docker Setup Guide](./README.docker.md) - Local development and testing
61
+ To add authorization or integrate the relay into your own server, use the
62
+ `createRelay` API from `@evolu/nodejs` instead. This package's
63
+ [`src/index.ts`](https://github.com/evoluhq/evolu/blob/main/apps/relay/src/index.ts)
64
+ is the complete example.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env node
2
+ import { ByteSizeLiteral, byteSizeToByteLength, createConsole, createConsoleFormatter, env, optional, Port, PortFromString, withDefault, } from "@evolu/common";
3
+ import { installPolyfills } from "@evolu/common/polyfills";
4
+ import { createRelay, createRelayDeps, runMain } from "@evolu/nodejs";
5
+ import { mkdirSync } from "node:fs";
6
+ installPolyfills();
7
+ /** Validated hosting and Evolu Relay environment settings. */
8
+ const RelayEnv = env({
9
+ port: withDefault(optional(PortFromString), Port.orThrow(4000)),
10
+ EVOLU_RELAY: {
11
+ maxOwnerBytes: optional(ByteSizeLiteral),
12
+ },
13
+ });
14
+ const deps = {
15
+ ...createRelayDeps(),
16
+ console: createConsole({
17
+ // level: "debug",
18
+ formatter: createConsoleFormatter()({
19
+ timestampFormat: "relative",
20
+ }),
21
+ }),
22
+ };
23
+ await runMain(deps)((run) => {
24
+ const config = RelayEnv.orThrow(process.env, { errors: "all" });
25
+ const maxOwnerBytes = config.maxOwnerBytes === undefined
26
+ ? undefined
27
+ : byteSizeToByteLength(config.maxOwnerBytes);
28
+ // Ensure the database is created in a predictable location for Docker.
29
+ mkdirSync("data", { recursive: true });
30
+ process.chdir("data");
31
+ return run(createRelay({
32
+ port: config.port,
33
+ // Note: Relay requires URL in format ws://host:port/<ownerId>
34
+ // isOwnerAllowed: (_ownerId) => true,
35
+ isOwnerWithinQuota: (_ownerId, requiredBytes) => maxOwnerBytes === undefined || requiredBytes <= maxOwnerBytes,
36
+ }));
37
+ });
package/package.json CHANGED
@@ -1,41 +1,49 @@
1
1
  {
2
2
  "name": "@evolu/relay",
3
- "version": "1.1.2-preview.5",
3
+ "version": "4.0.0",
4
+ "description": "Evolu Relay server",
5
+ "keywords": [
6
+ "evolu",
7
+ "local-first",
8
+ "relay",
9
+ "sync"
10
+ ],
11
+ "author": "Daniel Steigerwald <daniel@steigerwald.cz>",
12
+ "license": "MIT",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/evoluhq/evolu.git"
16
+ },
17
+ "bugs": {
18
+ "url": "https://github.com/evoluhq/evolu/issues"
19
+ },
20
+ "homepage": "https://evolu.dev",
4
21
  "type": "module",
5
22
  "bin": {
6
- "@evolu/relay": "dist/src/cli.js"
23
+ "evolu-relay": "./dist/src/index.js"
7
24
  },
25
+ "files": [
26
+ "dist/src/**",
27
+ "README.md"
28
+ ],
8
29
  "dependencies": {
9
- "commander": "^14.0.1",
10
- "@evolu/common": "6.0.1-preview.19",
11
- "@evolu/nodejs": "1.0.1-preview.7"
30
+ "@evolu/common": "8.10.0",
31
+ "@evolu/nodejs": "4.0.0"
12
32
  },
13
33
  "devDependencies": {
14
- "@types/node": "^22.17.1",
15
- "typescript": "^5.9.2",
16
- "@evolu/tsconfig": "0.0.2"
34
+ "@evolu/typescript-config": "0.1.1",
35
+ "@types/node": "^24.10.9",
36
+ "@typescript/native": "npm:typescript@^7.0.2"
17
37
  },
18
38
  "engines": {
19
- "node": ">=22.0.0"
39
+ "node": ">=24.20.0"
20
40
  },
21
41
  "publishConfig": {
22
42
  "access": "public"
23
43
  },
24
44
  "scripts": {
25
- "dev": "tsx --watch src/cli.ts -- start",
26
- "build": "shx rm -rf dist && tsc",
27
- "start": "node dist/src/cli.js",
28
- "clean": "shx rm -rf .turbo node_modules dist db.sqlite",
29
- "docker:build": "docker-compose build --no-cache",
30
- "docker:up": "docker-compose up --build",
31
- "docker:up:detached": "docker-compose up -d --build",
32
- "docker:down": "docker-compose down -v",
33
- "docker:restart": "docker-compose down && docker-compose up --build",
34
- "docker:logs": "docker-compose logs -f evolu-relay",
35
- "docker:shell": "docker exec -it evolu-relay-server sh",
36
- "docker:inspect": "docker inspect evolu-relay-server",
37
- "docker:stats": "docker stats evolu-relay-server",
38
- "docker:clean": "docker-compose down -v && docker system prune -f",
39
- "docker:clean:all": "docker-compose down -v && docker system prune -af && docker volume prune -f"
45
+ "dev": "node --watch --watch-preserve-output src/index.ts",
46
+ "build": "tsc --build tsconfig.json",
47
+ "start": "node dist/src/index.js"
40
48
  }
41
49
  }
package/.dockerignore DELETED
@@ -1,16 +0,0 @@
1
- node_modules
2
- .turbo
3
- dist
4
- *.log
5
- .env
6
- .env.local
7
- .DS_Store
8
- coverage
9
- .nyc_output
10
- *.db
11
- *.sqlite
12
- .git
13
- .gitignore
14
- README.md
15
- CHANGELOG.md
16
- examples
@@ -1,4 +0,0 @@
1
-
2
- > @evolu/relay@1.1.2-preview.5 build /home/runner/work/evolu/evolu/apps/relay
3
- > shx rm -rf dist && tsc
4
-