@vaultgradient/pipequery-cli 0.3.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 +384 -0
- package/dist/index.js +4630 -0
- package/package.json +43 -0
- package/src/commands/completion.ts +167 -0
- package/src/commands/dashboard.ts +44 -0
- package/src/commands/endpoint.ts +99 -0
- package/src/commands/init.ts +20 -0
- package/src/commands/monitor.ts +52 -0
- package/src/commands/query.ts +81 -0
- package/src/commands/remote.ts +89 -0
- package/src/commands/repl.ts +222 -0
- package/src/commands/serve.ts +122 -0
- package/src/commands/source.ts +150 -0
- package/src/commands/stop.ts +50 -0
- package/src/config/defaults.ts +48 -0
- package/src/config/loader.ts +37 -0
- package/src/config/schema.ts +73 -0
- package/src/docker/templates.ts +43 -0
- package/src/engine.ts +5 -0
- package/src/index.ts +164 -0
- package/src/server/activity-log.ts +28 -0
- package/src/server/app.ts +101 -0
- package/src/server/cache.ts +30 -0
- package/src/server/routes/control.ts +100 -0
- package/src/server/routes/dynamic.ts +51 -0
- package/src/server/routes/health.ts +16 -0
- package/src/server/routes/sse.ts +96 -0
- package/src/server/sources/file.ts +79 -0
- package/src/server/sources/manager.ts +120 -0
- package/src/server/sources/rest.ts +85 -0
- package/src/server/sources/static.ts +31 -0
- package/src/server/sources/types.ts +15 -0
- package/src/server/sources/websocket.ts +86 -0
- package/src/tui/App.tsx +141 -0
- package/src/tui/MonitorApp.tsx +271 -0
- package/src/tui/components/BarChart.tsx +48 -0
- package/src/tui/components/CandleChart.tsx +133 -0
- package/src/tui/components/Heatmap.tsx +92 -0
- package/src/tui/components/Layout.tsx +42 -0
- package/src/tui/components/OrderBook.tsx +94 -0
- package/src/tui/components/Panel.tsx +35 -0
- package/src/tui/components/Sparkline.tsx +55 -0
- package/src/tui/components/StatBox.tsx +37 -0
- package/src/tui/components/StatusBar.tsx +51 -0
- package/src/tui/components/Table.tsx +133 -0
- package/src/tui/hooks/useBatchedData.ts +77 -0
- package/src/tui/hooks/useKeyboard.ts +23 -0
- package/src/tui/hooks/useLiveData.ts +161 -0
- package/src/tui/hooks/useMouse.ts +86 -0
- package/src/tui/hooks/useSSE.ts +95 -0
- package/src/tui/hooks/useServerData.ts +37 -0
- package/src/utils/banner.ts +70 -0
- package/src/utils/logger.ts +10 -0
- package/src/utils/parseDuration.ts +12 -0
- package/src/utils/server-discovery.ts +43 -0
- package/src/utils/sync-output.ts +62 -0
- package/src/utils/yaml.ts +12 -0
- package/tsconfig.json +17 -0
- package/tsup.config.ts +13 -0
package/README.md
ADDED
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
# pq — PipeQuery CLI
|
|
2
|
+
|
|
3
|
+
A command-line tool for building data pipelines, REST APIs, and terminal dashboards using PipeQuery expressions.
|
|
4
|
+
|
|
5
|
+
Connect to any data source (REST APIs, WebSockets, files), run pipe-based queries to transform and aggregate data, then expose results as API endpoints or visualize them as rich terminal charts.
|
|
6
|
+
|
|
7
|
+
**Create API endpoints on the fly** — run `pq endpoint add /api/prices -q "crypto | sort(price desc)"` and instantly get a live JSON endpoint, no config file needed.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install -g @andreadito/pq
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Or install from source:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
git clone https://github.com/andreadito/pipequery.git
|
|
19
|
+
cd pipequery/cli
|
|
20
|
+
npm install && npm run build
|
|
21
|
+
npm link
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# 1. Initialize a project
|
|
28
|
+
pq init
|
|
29
|
+
|
|
30
|
+
# 2. Start the server
|
|
31
|
+
pq serve
|
|
32
|
+
|
|
33
|
+
# 3. Run a query
|
|
34
|
+
pq query "crypto | sort(market_cap desc) | first(5)"
|
|
35
|
+
|
|
36
|
+
# 4. Launch the terminal dashboard
|
|
37
|
+
pq dashboard
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Commands
|
|
41
|
+
|
|
42
|
+
### `pq init`
|
|
43
|
+
|
|
44
|
+
Creates a `pipequery.yaml` config file in the current directory with example sources, endpoints, and a dashboard layout.
|
|
45
|
+
|
|
46
|
+
### `pq serve`
|
|
47
|
+
|
|
48
|
+
Starts the PipeQuery server.
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pq serve # Foreground mode
|
|
52
|
+
pq serve -p 4000 # Custom port
|
|
53
|
+
pq serve -d # Run as background daemon
|
|
54
|
+
pq serve --stop # Stop a running daemon
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### `pq query <expression>`
|
|
58
|
+
|
|
59
|
+
Runs a PipeQuery expression against the running server and prints results.
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pq query "crypto | sort(price desc) | first(10)"
|
|
63
|
+
pq query "orders | groupBy(status) | count()" -f json
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Options:
|
|
67
|
+
- `-f, --format <format>` — Output format: `table` (default) or `json`
|
|
68
|
+
|
|
69
|
+
### `pq source`
|
|
70
|
+
|
|
71
|
+
Manage data sources at runtime. Changes are applied live and persisted to config.
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
# List all sources
|
|
75
|
+
pq source list
|
|
76
|
+
|
|
77
|
+
# Add a REST source
|
|
78
|
+
pq source add coins -t rest -u "https://api.example.com/coins" -i 30s
|
|
79
|
+
|
|
80
|
+
# Add a file source with live watching
|
|
81
|
+
pq source add orders -t file -p ./data/orders.csv -w
|
|
82
|
+
|
|
83
|
+
# Test a source (fetch sample data)
|
|
84
|
+
pq source test coins
|
|
85
|
+
|
|
86
|
+
# Remove a source
|
|
87
|
+
pq source remove coins
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Source types:
|
|
91
|
+
- **rest** — Polls a REST API at a configurable interval
|
|
92
|
+
- **websocket** — Streams data from a WebSocket connection
|
|
93
|
+
- **file** — Reads JSON or CSV files, optionally watches for changes
|
|
94
|
+
- **static** — Inline JSON data defined in config
|
|
95
|
+
|
|
96
|
+
### `pq endpoint`
|
|
97
|
+
|
|
98
|
+
Create API endpoints on the fly — no config file edits needed. Each endpoint runs a PipeQuery expression against live data and serves the result as JSON over HTTP. Changes take effect immediately and are persisted to `pipequery.yaml`.
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
# List endpoints
|
|
102
|
+
pq endpoint list
|
|
103
|
+
|
|
104
|
+
# Create a live API endpoint instantly
|
|
105
|
+
pq endpoint add /api/top-coins -q "crypto | sort(market_cap desc) | first(10)"
|
|
106
|
+
|
|
107
|
+
# Add with response caching
|
|
108
|
+
pq endpoint add /api/summary -q "orders | groupBy(status) | count()" -c 30s
|
|
109
|
+
|
|
110
|
+
# Remove an endpoint
|
|
111
|
+
pq endpoint remove /api/top-coins
|
|
112
|
+
|
|
113
|
+
# Your endpoint is immediately available:
|
|
114
|
+
# curl http://localhost:3000/api/top-coins
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### `pq dashboard`
|
|
118
|
+
|
|
119
|
+
Launches an interactive terminal dashboard with live-updating panels.
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
pq dashboard # Launch the "main" dashboard
|
|
123
|
+
pq dashboard -n monitor # Launch a named dashboard
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Keyboard shortcuts:
|
|
127
|
+
- `Tab` / `Shift+Tab` — Cycle panel focus
|
|
128
|
+
- `↑` / `↓` — Scroll table rows
|
|
129
|
+
- `]` / `[` — Grow / shrink focused panel width
|
|
130
|
+
- `r` — Force refresh
|
|
131
|
+
- `q` — Quit
|
|
132
|
+
|
|
133
|
+
Panels are arranged in an equal-width 2-column grid that fills the terminal. Use `[` and `]` to resize the focused panel (25%–75% range), with the neighboring panel adjusting automatically.
|
|
134
|
+
|
|
135
|
+
Dashboard panels support multiple visualization types:
|
|
136
|
+
- **table** — Scrollable, sortable data table
|
|
137
|
+
- **bar** — Horizontal bar chart
|
|
138
|
+
- **sparkline** — Mini line chart with braille characters
|
|
139
|
+
- **stat** — Single value display
|
|
140
|
+
- **orderbook** — Live bid/ask depth chart with cumulative bars and spread
|
|
141
|
+
- **heatmap** — Color-coded numeric grid (red → yellow → green)
|
|
142
|
+
- **candle** — ASCII candlestick chart for OHLC data
|
|
143
|
+
|
|
144
|
+
### `pq stop`
|
|
145
|
+
|
|
146
|
+
Stops the running PipeQuery server (daemon or foreground).
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
pq stop # Graceful shutdown (SIGTERM)
|
|
150
|
+
pq stop --force # Force kill (SIGKILL)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### `pq monitor`
|
|
154
|
+
|
|
155
|
+
Launches a real-time activity monitor showing server requests, queries, and events.
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
pq monitor
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### `pq repl`
|
|
162
|
+
|
|
163
|
+
Opens an interactive REPL for running PipeQuery expressions against the server.
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
pq repl
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### `pq remote`
|
|
170
|
+
|
|
171
|
+
Deploy the server with Docker and control it from anywhere.
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
# Generate Dockerfile and docker-compose.yaml
|
|
175
|
+
pq remote deploy
|
|
176
|
+
|
|
177
|
+
# Connect your local CLI to a remote server
|
|
178
|
+
pq remote connect https://my-server.example.com
|
|
179
|
+
|
|
180
|
+
# Check remote server health
|
|
181
|
+
pq remote status
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Docker & Remote Deployment
|
|
185
|
+
|
|
186
|
+
The `pq` server and CLI are fully decoupled. You can run the server in Docker (locally or on a remote machine) and control it from your local terminal.
|
|
187
|
+
|
|
188
|
+
### Run locally with Docker Desktop
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
# Build and run the server
|
|
192
|
+
docker build -t pipequery .
|
|
193
|
+
docker run -p 3000:3000 pipequery
|
|
194
|
+
|
|
195
|
+
# From any terminal, connect and start working
|
|
196
|
+
pq remote connect http://localhost:3000
|
|
197
|
+
pq source add crypto -t rest -u "https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&per_page=20" -i 30s
|
|
198
|
+
pq endpoint add /api/top -q "crypto | sort(market_cap desc) | first(5)"
|
|
199
|
+
curl http://localhost:3000/api/top
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Deploy to a remote server
|
|
203
|
+
|
|
204
|
+
```bash
|
|
205
|
+
# Generate deployment files from your project
|
|
206
|
+
pq remote deploy
|
|
207
|
+
# → Creates Dockerfile, docker-compose.yaml, .dockerignore
|
|
208
|
+
|
|
209
|
+
# Deploy to your server
|
|
210
|
+
scp -r . user@server:~/pipequery
|
|
211
|
+
ssh user@server "cd pipequery && docker compose up -d"
|
|
212
|
+
|
|
213
|
+
# Connect your local CLI to the remote server
|
|
214
|
+
pq remote connect https://my-server.example.com:3000
|
|
215
|
+
|
|
216
|
+
# Now all commands work against the remote server
|
|
217
|
+
pq source add store -t rest -u "https://fakestoreapi.com/products" -i 5m
|
|
218
|
+
pq endpoint add /api/products -q "store | sort(price desc)"
|
|
219
|
+
pq query "store | where(price > 50) | select(title, price, category)"
|
|
220
|
+
pq dashboard -n main
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### How it works
|
|
224
|
+
|
|
225
|
+
Running `pq remote connect <url>` saves the remote URL in your local `pipequery.yaml`. After that, all CLI commands (`query`, `source`, `endpoint`, `dashboard`, `monitor`) talk to the remote server instead of looking for a local one. No local server needed — just the `pq` CLI.
|
|
226
|
+
|
|
227
|
+
### `pq completion`
|
|
228
|
+
|
|
229
|
+
Generate shell tab-completion scripts.
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
# Auto-detect shell
|
|
233
|
+
pq completion
|
|
234
|
+
|
|
235
|
+
# Specific shell
|
|
236
|
+
pq completion -s bash
|
|
237
|
+
pq completion -s zsh
|
|
238
|
+
pq completion -s fish
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Configuration
|
|
242
|
+
|
|
243
|
+
All configuration lives in `pipequery.yaml`:
|
|
244
|
+
|
|
245
|
+
```yaml
|
|
246
|
+
server:
|
|
247
|
+
port: 3000
|
|
248
|
+
host: 0.0.0.0
|
|
249
|
+
|
|
250
|
+
sources:
|
|
251
|
+
crypto:
|
|
252
|
+
type: rest
|
|
253
|
+
url: https://api.coingecko.com/api/v3/coins/markets
|
|
254
|
+
params:
|
|
255
|
+
vs_currency: usd
|
|
256
|
+
interval: 30s
|
|
257
|
+
orders:
|
|
258
|
+
type: file
|
|
259
|
+
path: ./data/orders.csv
|
|
260
|
+
watch: true
|
|
261
|
+
|
|
262
|
+
endpoints:
|
|
263
|
+
/api/top-coins:
|
|
264
|
+
query: "crypto | sort(market_cap desc) | first(10)"
|
|
265
|
+
cache: 30s
|
|
266
|
+
|
|
267
|
+
dashboards:
|
|
268
|
+
main:
|
|
269
|
+
refresh: 10s
|
|
270
|
+
panels:
|
|
271
|
+
- title: Top Coins
|
|
272
|
+
query: "crypto | sort(market_cap desc) | first(10)"
|
|
273
|
+
viz: table
|
|
274
|
+
- title: Volume Leaders
|
|
275
|
+
query: "crypto | sort(total_volume desc) | first(8)"
|
|
276
|
+
viz: bar
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### Source Configuration
|
|
280
|
+
|
|
281
|
+
#### REST Source
|
|
282
|
+
```yaml
|
|
283
|
+
sources:
|
|
284
|
+
my_api:
|
|
285
|
+
type: rest
|
|
286
|
+
url: https://api.example.com/data
|
|
287
|
+
interval: 30s # Poll interval
|
|
288
|
+
headers: # Optional HTTP headers
|
|
289
|
+
Authorization: "Bearer TOKEN"
|
|
290
|
+
params: # Optional query parameters
|
|
291
|
+
limit: 100
|
|
292
|
+
dataPath: data.items # Optional: extract nested data
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
#### WebSocket Source
|
|
296
|
+
```yaml
|
|
297
|
+
sources:
|
|
298
|
+
live_feed:
|
|
299
|
+
type: websocket
|
|
300
|
+
url: wss://stream.example.com/feed
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
#### File Source
|
|
304
|
+
```yaml
|
|
305
|
+
sources:
|
|
306
|
+
orders:
|
|
307
|
+
type: file
|
|
308
|
+
path: ./data/orders.csv # JSON or CSV
|
|
309
|
+
watch: true # Re-read on change
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
#### Static Source
|
|
313
|
+
```yaml
|
|
314
|
+
sources:
|
|
315
|
+
regions:
|
|
316
|
+
type: static
|
|
317
|
+
data:
|
|
318
|
+
- { code: US, name: United States }
|
|
319
|
+
- { code: EU, name: European Union }
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
## Example Data Sources
|
|
323
|
+
|
|
324
|
+
These free public APIs work great with `pq` — no API keys needed:
|
|
325
|
+
|
|
326
|
+
```bash
|
|
327
|
+
# Crypto prices (CoinGecko)
|
|
328
|
+
pq source add crypto -t rest -u "https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&per_page=20" -i 30s
|
|
329
|
+
pq query "crypto | sort(market_cap desc) | first(5) | select(name, current_price, market_cap)"
|
|
330
|
+
|
|
331
|
+
# World countries (REST Countries)
|
|
332
|
+
pq source add countries -t rest -u "https://restcountries.com/v3.1/all?fields=name,population,region,area" -i 1h
|
|
333
|
+
pq query "countries | sort(population desc) | first(10) | select(name, population, region)"
|
|
334
|
+
|
|
335
|
+
# E-commerce products (Fake Store)
|
|
336
|
+
pq source add store -t rest -u "https://fakestoreapi.com/products" -i 5m
|
|
337
|
+
pq query "store | where(price > 50) | sort(price desc) | select(title, price, category)"
|
|
338
|
+
|
|
339
|
+
# Live earthquakes (USGS)
|
|
340
|
+
pq source add quakes -t rest -u "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson" -i 5m
|
|
341
|
+
|
|
342
|
+
# Mock users & posts (JSONPlaceholder)
|
|
343
|
+
pq source add users -t rest -u "https://jsonplaceholder.typicode.com/users" -i 1h
|
|
344
|
+
pq source add posts -t rest -u "https://jsonplaceholder.typicode.com/posts" -i 1h
|
|
345
|
+
|
|
346
|
+
# Exchange rates (NBP)
|
|
347
|
+
pq source add forex -t rest -u "https://api.nbp.pl/api/exchangerates/tables/A/?format=json" -i 1h
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
## PipeQuery Expressions
|
|
351
|
+
|
|
352
|
+
PipeQuery uses a pipe-based syntax to transform data:
|
|
353
|
+
|
|
354
|
+
```
|
|
355
|
+
source | operation1(args) | operation2(args) | ...
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
Common operations:
|
|
359
|
+
- `sort(field desc)` — Sort by field
|
|
360
|
+
- `first(n)` / `last(n)` — Take first/last N items
|
|
361
|
+
- `filter(field > value)` — Filter rows
|
|
362
|
+
- `groupBy(field)` — Group by field
|
|
363
|
+
- `count()` / `sum(field)` / `avg(field)` — Aggregations
|
|
364
|
+
- `select(field1, field2)` — Pick specific fields
|
|
365
|
+
- `where(condition)` — Filter with condition
|
|
366
|
+
- `map(expr)` — Transform each row
|
|
367
|
+
|
|
368
|
+
## Architecture
|
|
369
|
+
|
|
370
|
+
```
|
|
371
|
+
pq CLI ──── REST Control API ──── Fastify Server
|
|
372
|
+
├── SourceManager (REST/WS/File/Static adapters)
|
|
373
|
+
├── PipeQuery Engine
|
|
374
|
+
├── Dynamic API Endpoints (/api/*)
|
|
375
|
+
└── SSE for real-time dashboard updates
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
The CLI communicates with the server via a control API at `/api/_control/*`. When the server isn't running, config-only commands (like `source list`) read directly from `pipequery.yaml`.
|
|
379
|
+
|
|
380
|
+
The dashboard uses Server-Sent Events (SSE) for real-time push updates when connected, falling back to polling when SSE is unavailable.
|
|
381
|
+
|
|
382
|
+
## License
|
|
383
|
+
|
|
384
|
+
MIT
|