@sola-air-ui/relay 1.0.2 → 1.0.4

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.
Files changed (4) hide show
  1. package/README.md +25 -8
  2. package/package.json +5 -2
  3. package/src/cli.js +27 -23
  4. package/src/index.js +596 -532
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @sola-air-ui/relay
2
2
 
3
- A local data proxy for [Sola AIR](https://sola-air.dev)'s `createData`/`$data` primitive — keeps database credentials on your own machine (or server) instead of shipping them to the browser, and streams live query results to Sola components over a local connection.
3
+ A local data proxy for [Sola AIR](https://sola-air.dev)'s `createData`/`$data` primitive. It keeps database credentials on your own machine (or server) instead of shipping them to the browser, and answers Sola components' queries over a local HTTP endpoint.
4
4
 
5
5
  ## Install
6
6
 
@@ -8,35 +8,52 @@ A local data proxy for [Sola AIR](https://sola-air.dev)'s `createData`/`$data` p
8
8
  npm install @sola-air-ui/relay
9
9
  ```
10
10
 
11
+ ## Configure
12
+
13
+ The relay reads `sola-relay.json` from the directory you start it in. Each entry under `connections` is a name you choose plus its settings:
14
+
15
+ ```json
16
+ {
17
+ "connections": {
18
+ "postgres-primary": { "type": "postgres", "connectionString": "postgres://user:pass@localhost:5432/mydb" },
19
+ "orders-db": { "type": "mysql", "host": "localhost", "user": "reader", "password": "…", "database": "shop" }
20
+ }
21
+ }
22
+ ```
23
+
24
+ `postgres` settings go to `pg`'s `Pool`, and `mysql` settings to `mysql2`'s `createPool`. Give the relay a read-only database user.
25
+
11
26
  ## Run
12
27
 
13
28
  ```bash
14
- npx sola-relay --db postgres://user:pass@localhost:5432/mydb
29
+ npx sola-relay --port 4040
15
30
  ```
16
31
 
17
- By default this starts a local relay process that Sola's `createData()` calls connect to for real-time data sync — your Postgres/MySQL credentials never leave the process running the relay.
32
+ `--port` is the only option (default `4040`). The relay serves `POST /api/query`, `GET /api/schema?source=…` and `GET /api/status`, which lists each connection and whether it connected.
18
33
 
19
34
  ## Supported data sources
20
35
 
21
36
  - **PostgreSQL** (via `pg`)
22
37
  - **MySQL** (via `mysql2`)
23
- - Live updates pushed to connected clients over WebSocket (`ws`)
38
+ - **Google Sheets** (`type: "sheet"` with a `sheetId`): reads a sheet that is shared publicly, as CSV.
24
39
 
25
40
  ## Usage from a component
26
41
 
27
42
  ```html
28
43
  <script>
29
- let customers = $data('postgres-primary:customers', { sync: 'realtime' });
44
+ let customers = $data('postgres-primary:customers', { refresh: '30s' });
30
45
  </script>
31
46
 
32
- <Table rows={customers} />
47
+ <Table rows={() => customers().data} />
33
48
  ```
34
49
 
35
- `postgres-primary` refers to the connection alias configured when you start the relay — see `sola-relay --help` for connection/alias options.
50
+ The source is `connection:table`. `postgres-primary` is a name from `sola-relay.json`, and `customers` is a table in that database (`schema.table` works too). Connection names may use letters, digits, `_` and `-`. Table names must be plain identifiers, because they go into the query. With no `:table`, the connection name is used as the table name. `refresh` re-runs the query on that interval.
36
51
 
37
52
  ## Security note
38
53
 
39
- The relay is designed to run somewhere trusted (your dev machine, or a backend service you control) — never expose its port directly to the public internet without your own auth layer in front of it.
54
+ - SQL connections run a single read-only `SELECT`; anything else gets a 400.
55
+ - Every query is appended to `sola-relay-audit.log` in the working directory.
56
+ - The relay has no authentication of its own. Run it somewhere trusted (your dev machine, or a backend service you control), and never expose its port to the public internet without your own auth layer in front of it.
40
57
 
41
58
  ## License
42
59
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sola-air-ui/relay",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Sola Relay — local data proxy that keeps credentials on-device and streams live data to Sola components",
5
5
  "type": "module",
6
6
  "bin": {
@@ -10,6 +10,9 @@
10
10
  "exports": {
11
11
  ".": "./src/index.js"
12
12
  },
13
+ "scripts": {
14
+ "test": "node --test test/*.test.js"
15
+ },
13
16
  "keywords": [
14
17
  "sola",
15
18
  "relay",
@@ -22,7 +25,7 @@
22
25
  "homepage": "https://sola-air.dev",
23
26
  "repository": {
24
27
  "type": "git",
25
- "url": "git+https://github.com/rbm3267/sola-air.git"
28
+ "url": "git+https://github.com/Rbm3267/sola-air.git"
26
29
  },
27
30
  "dependencies": {
28
31
  "pg": "^8.11.0",
package/src/cli.js CHANGED
@@ -1,24 +1,28 @@
1
1
  #!/usr/bin/env node
2
-
3
- // ─── Sola Relay CLI ───
4
- // Usage: npx sola-relay [--port 4040]
5
-
6
- import { createServer } from 'http';
7
- import { RelayServer } from './index.js';
8
-
9
- const args = process.argv.slice(2);
10
- const portIndex = args.indexOf('--port');
11
- const port = portIndex !== -1 ? parseInt(args[portIndex + 1]) : 4040;
12
-
13
- console.log(`
14
- ☀️ Sola Relay v0.0.1
15
- ─────────────────────
16
- Dashboard: http://localhost:${port}
17
- API: http://localhost:${port}/api/query
18
- Status: http://localhost:${port}/api/status
19
- ─────────────────────
20
- Data never leaves your machine.
21
- `);
22
-
23
- const relay = new RelayServer({ port });
24
- relay.start();
2
+
3
+ // ─── Sola Relay CLI ───
4
+ // Usage: npx sola-relay [--port 4040]
5
+
6
+ import { readFileSync } from 'fs';
7
+ import { RelayServer } from './index.js';
8
+
9
+ const { version: RELAY_VERSION } = JSON.parse(
10
+ readFileSync(new URL('../package.json', import.meta.url), 'utf8')
11
+ );
12
+
13
+ const args = process.argv.slice(2);
14
+ const portIndex = args.indexOf('--port');
15
+ const port = portIndex !== -1 ? parseInt(args[portIndex + 1]) : 4040;
16
+
17
+ console.log(`
18
+ ☀️ Sola Relay v${RELAY_VERSION}
19
+ ─────────────────────
20
+ Dashboard: http://localhost:${port}
21
+ API: http://localhost:${port}/api/query
22
+ Status: http://localhost:${port}/api/status
23
+ ─────────────────────
24
+ Data never leaves your machine.
25
+ `);
26
+
27
+ const relay = new RelayServer({ port });
28
+ relay.start();