@geolonia/geonicdb-cli 0.1.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 +459 -0
- package/dist/index.js +3413 -0
- package/dist/index.js.map +1 -0
- package/package.json +73 -0
package/README.md
ADDED
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
# @geolonia/geonicdb-cli
|
|
2
|
+
|
|
3
|
+
CLI tool for [GeonicDB](https://geonicdb.geolonia.com/) — a FIWARE Orion compatible Context Broker.
|
|
4
|
+
|
|
5
|
+
Supports the **NGSI-LD** API.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install -g @geolonia/geonicdb-cli
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or run directly with npx:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npx @geolonia/geonicdb-cli <command>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The CLI is available as `geonic`.
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# Set the server URL
|
|
25
|
+
geonic config set url http://localhost:3000
|
|
26
|
+
|
|
27
|
+
# Create an entity
|
|
28
|
+
geonic entities create '{"id":"Room1","type":"Room","temperature":{"value":23,"type":"Number"}}'
|
|
29
|
+
|
|
30
|
+
# List entities
|
|
31
|
+
geonic entities list
|
|
32
|
+
|
|
33
|
+
# Get an entity by ID
|
|
34
|
+
geonic entities get Room1
|
|
35
|
+
|
|
36
|
+
# Update attributes
|
|
37
|
+
geonic entities update Room1 '{"temperature":{"value":25,"type":"Number"}}'
|
|
38
|
+
|
|
39
|
+
# Delete an entity
|
|
40
|
+
geonic entities delete Room1
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Getting Help
|
|
44
|
+
|
|
45
|
+
The CLI provides built-in help in wp-cli style. Use `geonic help` to explore available commands:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# Show all available commands
|
|
49
|
+
geonic help
|
|
50
|
+
|
|
51
|
+
# Get help on a specific command
|
|
52
|
+
geonic help entities
|
|
53
|
+
|
|
54
|
+
# Get help on a subcommand
|
|
55
|
+
geonic help entities list
|
|
56
|
+
|
|
57
|
+
# Works with nested commands too
|
|
58
|
+
geonic help admin tenants
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
You can also use `--help` on any command:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
geonic entities --help
|
|
65
|
+
geonic entities list --help
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Global Options
|
|
69
|
+
|
|
70
|
+
| Option | Description |
|
|
71
|
+
|---|---|
|
|
72
|
+
| `-u, --url <url>` | Base URL of the GeonicDB server |
|
|
73
|
+
| `-s, --service <name>` | `NGSILD-Tenant` header |
|
|
74
|
+
| `--token <token>` | Authentication token |
|
|
75
|
+
| `-p, --profile <name>` | Use a named profile |
|
|
76
|
+
| `--api-key <key>` | API key for authentication |
|
|
77
|
+
| `-f, --format <fmt>` | Output format: `json`, `table`, `geojson` |
|
|
78
|
+
| `--no-color` | Disable color output |
|
|
79
|
+
| `-v, --verbose` | Verbose output |
|
|
80
|
+
|
|
81
|
+
Options are resolved in this order (first wins):
|
|
82
|
+
|
|
83
|
+
1. Command-line flags
|
|
84
|
+
2. Config file (`~/.config/geonic/config.json`)
|
|
85
|
+
3. Defaults (`format=json`)
|
|
86
|
+
|
|
87
|
+
## Commands
|
|
88
|
+
|
|
89
|
+
### help — Get help on commands
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
geonic help [<command>] [<subcommand>]
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### config — Manage CLI configuration
|
|
96
|
+
|
|
97
|
+
| Subcommand | Description |
|
|
98
|
+
|---|---|
|
|
99
|
+
| `config set <key> <value>` | Save a config value |
|
|
100
|
+
| `config get <key>` | Get a config value |
|
|
101
|
+
| `config list` | List all config values |
|
|
102
|
+
| `config delete <key>` | Delete a config value |
|
|
103
|
+
|
|
104
|
+
### profile — Manage connection profiles
|
|
105
|
+
|
|
106
|
+
| Subcommand | Description |
|
|
107
|
+
|---|---|
|
|
108
|
+
| `profile list` | List all profiles |
|
|
109
|
+
| `profile use <name>` | Switch active profile |
|
|
110
|
+
| `profile create <name>` | Create a new profile |
|
|
111
|
+
| `profile delete <name>` | Delete a profile |
|
|
112
|
+
| `profile show [name]` | Show profile settings |
|
|
113
|
+
|
|
114
|
+
### auth — Authentication
|
|
115
|
+
|
|
116
|
+
| Subcommand | Description |
|
|
117
|
+
|---|---|
|
|
118
|
+
| `auth login` | Authenticate and save token |
|
|
119
|
+
| `auth logout` | Clear saved authentication token |
|
|
120
|
+
|
|
121
|
+
The `auth login` command reads `GDB_EMAIL` and `GDB_PASSWORD` environment variables. It also supports OAuth Client Credentials flow with `--client-id` and `--client-secret`.
|
|
122
|
+
|
|
123
|
+
### me — Display current user
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
geonic me
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Displays the current authenticated user, token expiry, and active profile.
|
|
130
|
+
|
|
131
|
+
### entities — Manage context entities
|
|
132
|
+
|
|
133
|
+
| Subcommand | Description |
|
|
134
|
+
|---|---|
|
|
135
|
+
| `entities list` | List entities |
|
|
136
|
+
| `entities get <id>` | Get an entity by ID |
|
|
137
|
+
| `entities create [json]` | Create a new entity |
|
|
138
|
+
| `entities update <id> [json]` | Update attributes (PATCH) |
|
|
139
|
+
| `entities replace <id> [json]` | Replace all attributes (PUT) |
|
|
140
|
+
| `entities upsert [json]` | Create or update entities |
|
|
141
|
+
| `entities delete <id>` | Delete an entity by ID |
|
|
142
|
+
|
|
143
|
+
`entities list` supports filtering options: `--type`, `--id-pattern`, `--query`, `--attrs`, `--georel`, `--geometry`, `--coords`, `--spatial-id`, `--limit`, `--offset`, `--order-by`, `--count`.
|
|
144
|
+
|
|
145
|
+
#### entities attrs — Manage entity attributes
|
|
146
|
+
|
|
147
|
+
| Subcommand | Description |
|
|
148
|
+
|---|---|
|
|
149
|
+
| `entities attrs list <entityId>` | List all attributes |
|
|
150
|
+
| `entities attrs get <entityId> <attrName>` | Get a specific attribute |
|
|
151
|
+
| `entities attrs add <entityId> [json]` | Add attributes |
|
|
152
|
+
| `entities attrs update <entityId> <attrName> [json]` | Update an attribute |
|
|
153
|
+
| `entities attrs delete <entityId> <attrName>` | Delete an attribute |
|
|
154
|
+
|
|
155
|
+
### entityOperations (batch) — Batch operations
|
|
156
|
+
|
|
157
|
+
| Subcommand | Description |
|
|
158
|
+
|---|---|
|
|
159
|
+
| `entityOperations create [json]` | Batch create entities |
|
|
160
|
+
| `entityOperations upsert [json]` | Batch upsert entities |
|
|
161
|
+
| `entityOperations update [json]` | Batch update entities |
|
|
162
|
+
| `entityOperations delete [json]` | Batch delete entities |
|
|
163
|
+
| `entityOperations query [json]` | Batch query entities |
|
|
164
|
+
| `entityOperations merge [json]` | Batch merge entities |
|
|
165
|
+
|
|
166
|
+
`batch` is available as an alias for `entityOperations`.
|
|
167
|
+
|
|
168
|
+
### subscriptions (sub) — Manage context subscriptions
|
|
169
|
+
|
|
170
|
+
| Subcommand | Description |
|
|
171
|
+
|---|---|
|
|
172
|
+
| `sub list` | List subscriptions |
|
|
173
|
+
| `sub get <id>` | Get a subscription by ID |
|
|
174
|
+
| `sub create [json]` | Create a subscription |
|
|
175
|
+
| `sub update <id> [json]` | Update a subscription |
|
|
176
|
+
| `sub delete <id>` | Delete a subscription |
|
|
177
|
+
|
|
178
|
+
### registrations (reg) — Manage context registrations
|
|
179
|
+
|
|
180
|
+
| Subcommand | Description |
|
|
181
|
+
|---|---|
|
|
182
|
+
| `reg list` | List registrations |
|
|
183
|
+
| `reg get <id>` | Get a registration by ID |
|
|
184
|
+
| `reg create [json]` | Create a registration |
|
|
185
|
+
| `reg update <id> [json]` | Update a registration |
|
|
186
|
+
| `reg delete <id>` | Delete a registration |
|
|
187
|
+
|
|
188
|
+
### types — Browse entity types
|
|
189
|
+
|
|
190
|
+
| Subcommand | Description |
|
|
191
|
+
|---|---|
|
|
192
|
+
| `types list` | List available entity types |
|
|
193
|
+
| `types get <typeName>` | Get details for a type |
|
|
194
|
+
|
|
195
|
+
### temporal — Temporal entity operations
|
|
196
|
+
|
|
197
|
+
#### temporal entities
|
|
198
|
+
|
|
199
|
+
| Subcommand | Description |
|
|
200
|
+
|---|---|
|
|
201
|
+
| `temporal entities list` | List temporal entities |
|
|
202
|
+
| `temporal entities get <id>` | Get a temporal entity by ID |
|
|
203
|
+
| `temporal entities create [json]` | Create a temporal entity |
|
|
204
|
+
| `temporal entities delete <id>` | Delete a temporal entity |
|
|
205
|
+
|
|
206
|
+
Temporal entities list/get support: `--time-rel`, `--time-at`, `--end-time-at`, `--last-n`.
|
|
207
|
+
|
|
208
|
+
#### temporal entityOperations
|
|
209
|
+
|
|
210
|
+
| Subcommand | Description |
|
|
211
|
+
|---|---|
|
|
212
|
+
| `temporal entityOperations query [json]` | Query temporal entities (POST) |
|
|
213
|
+
|
|
214
|
+
Temporal entityOperations query supports: `--aggr-methods`, `--aggr-period`.
|
|
215
|
+
|
|
216
|
+
### snapshots — Snapshot operations
|
|
217
|
+
|
|
218
|
+
| Subcommand | Description |
|
|
219
|
+
|---|---|
|
|
220
|
+
| `snapshots list` | List snapshots |
|
|
221
|
+
| `snapshots get <id>` | Get a snapshot by ID |
|
|
222
|
+
| `snapshots create` | Create a new snapshot |
|
|
223
|
+
| `snapshots delete <id>` | Delete a snapshot |
|
|
224
|
+
| `snapshots clone <id>` | Clone a snapshot |
|
|
225
|
+
|
|
226
|
+
### rules — Rule engine management
|
|
227
|
+
|
|
228
|
+
| Subcommand | Description |
|
|
229
|
+
|---|---|
|
|
230
|
+
| `rules list` | List all rules |
|
|
231
|
+
| `rules get <id>` | Get a rule by ID |
|
|
232
|
+
| `rules create [json]` | Create a new rule |
|
|
233
|
+
| `rules update <id> [json]` | Update a rule |
|
|
234
|
+
| `rules delete <id>` | Delete a rule |
|
|
235
|
+
| `rules activate <id>` | Activate a rule |
|
|
236
|
+
| `rules deactivate <id>` | Deactivate a rule |
|
|
237
|
+
|
|
238
|
+
### custom-data-models (models) — Custom data model management
|
|
239
|
+
|
|
240
|
+
| Subcommand | Description |
|
|
241
|
+
|---|---|
|
|
242
|
+
| `custom-data-models list` | List all models |
|
|
243
|
+
| `custom-data-models get <id>` | Get a model by ID |
|
|
244
|
+
| `custom-data-models create [json]` | Create a new model |
|
|
245
|
+
| `custom-data-models update <id> [json]` | Update a model |
|
|
246
|
+
| `custom-data-models delete <id>` | Delete a model |
|
|
247
|
+
|
|
248
|
+
`models` is available as an alias for `custom-data-models`.
|
|
249
|
+
|
|
250
|
+
### catalog — DCAT-AP catalog
|
|
251
|
+
|
|
252
|
+
| Subcommand | Description |
|
|
253
|
+
|---|---|
|
|
254
|
+
| `catalog get` | Get the catalog |
|
|
255
|
+
| `catalog datasets list` | List all datasets |
|
|
256
|
+
| `catalog datasets get <id>` | Get a dataset by ID |
|
|
257
|
+
| `catalog datasets sample <id>` | Get sample data for a dataset |
|
|
258
|
+
|
|
259
|
+
### admin — Administration
|
|
260
|
+
|
|
261
|
+
#### admin tenants
|
|
262
|
+
|
|
263
|
+
| Subcommand | Description |
|
|
264
|
+
|---|---|
|
|
265
|
+
| `admin tenants list` | List all tenants |
|
|
266
|
+
| `admin tenants get <id>` | Get a tenant by ID |
|
|
267
|
+
| `admin tenants create [json]` | Create a new tenant |
|
|
268
|
+
| `admin tenants update <id> [json]` | Update a tenant |
|
|
269
|
+
| `admin tenants delete <id>` | Delete a tenant |
|
|
270
|
+
| `admin tenants activate <id>` | Activate a tenant |
|
|
271
|
+
| `admin tenants deactivate <id>` | Deactivate a tenant |
|
|
272
|
+
|
|
273
|
+
#### admin users
|
|
274
|
+
|
|
275
|
+
| Subcommand | Description |
|
|
276
|
+
|---|---|
|
|
277
|
+
| `admin users list` | List all users |
|
|
278
|
+
| `admin users get <id>` | Get a user by ID |
|
|
279
|
+
| `admin users create [json]` | Create a new user |
|
|
280
|
+
| `admin users update <id> [json]` | Update a user |
|
|
281
|
+
| `admin users delete <id>` | Delete a user |
|
|
282
|
+
| `admin users activate <id>` | Activate a user |
|
|
283
|
+
| `admin users deactivate <id>` | Deactivate a user |
|
|
284
|
+
| `admin users unlock <id>` | Unlock a user |
|
|
285
|
+
|
|
286
|
+
#### admin policies
|
|
287
|
+
|
|
288
|
+
| Subcommand | Description |
|
|
289
|
+
|---|---|
|
|
290
|
+
| `admin policies list` | List all policies |
|
|
291
|
+
| `admin policies get <id>` | Get a policy by ID |
|
|
292
|
+
| `admin policies create [json]` | Create a new policy |
|
|
293
|
+
| `admin policies update <id> [json]` | Update a policy |
|
|
294
|
+
| `admin policies delete <id>` | Delete a policy |
|
|
295
|
+
| `admin policies activate <id>` | Activate a policy |
|
|
296
|
+
| `admin policies deactivate <id>` | Deactivate a policy |
|
|
297
|
+
|
|
298
|
+
#### admin oauth-clients
|
|
299
|
+
|
|
300
|
+
| Subcommand | Description |
|
|
301
|
+
|---|---|
|
|
302
|
+
| `admin oauth-clients list` | List all OAuth clients |
|
|
303
|
+
| `admin oauth-clients get <id>` | Get an OAuth client by ID |
|
|
304
|
+
| `admin oauth-clients create [json]` | Create a new OAuth client |
|
|
305
|
+
| `admin oauth-clients update <id> [json]` | Update an OAuth client |
|
|
306
|
+
| `admin oauth-clients delete <id>` | Delete an OAuth client |
|
|
307
|
+
|
|
308
|
+
#### admin cadde
|
|
309
|
+
|
|
310
|
+
| Subcommand | Description |
|
|
311
|
+
|---|---|
|
|
312
|
+
| `admin cadde get` | Get CADDE configuration |
|
|
313
|
+
| `admin cadde set [json]` | Set CADDE configuration |
|
|
314
|
+
| `admin cadde delete` | Delete CADDE configuration |
|
|
315
|
+
|
|
316
|
+
### health — Check server health
|
|
317
|
+
|
|
318
|
+
```bash
|
|
319
|
+
geonic health
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
### version — Display version info
|
|
323
|
+
|
|
324
|
+
```bash
|
|
325
|
+
geonic version
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
## Input Formats
|
|
329
|
+
|
|
330
|
+
Commands that accept JSON data support multiple input methods. The `[json]` argument is optional — when omitted, the CLI auto-detects piped stdin or launches interactive mode.
|
|
331
|
+
|
|
332
|
+
**Inline JSON / JSON5**
|
|
333
|
+
|
|
334
|
+
```bash
|
|
335
|
+
# Standard JSON
|
|
336
|
+
geonic entities create '{"id":"Room1","type":"Room"}'
|
|
337
|
+
|
|
338
|
+
# JSON5 — unquoted keys, single quotes, trailing commas, comments
|
|
339
|
+
geonic entities create "{id: 'Room1', type: 'Room',}"
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
[JSON5](https://json5.org/) syntax is supported everywhere JSON is accepted (inline, files, stdin, interactive).
|
|
343
|
+
|
|
344
|
+
**File input** (prefix with `@`)
|
|
345
|
+
|
|
346
|
+
```bash
|
|
347
|
+
geonic entities create @payload.json
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
**Stdin (auto-detect)**
|
|
351
|
+
|
|
352
|
+
When no argument is given and stdin is piped, the CLI reads from stdin automatically — no `-` required:
|
|
353
|
+
|
|
354
|
+
```bash
|
|
355
|
+
cat payload.json | geonic entities create
|
|
356
|
+
echo '{"id":"Room1","type":"Room"}' | geonic entities create
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
The explicit `-` marker is still supported for backward compatibility:
|
|
360
|
+
|
|
361
|
+
```bash
|
|
362
|
+
cat payload.json | geonic entities create -
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
**Interactive mode**
|
|
366
|
+
|
|
367
|
+
When no argument is given and the terminal is a TTY (no pipe), the CLI enters interactive mode with a `json>` prompt. Type or paste JSON and the input auto-submits when braces/brackets are balanced:
|
|
368
|
+
|
|
369
|
+
```text
|
|
370
|
+
$ geonic entities create
|
|
371
|
+
Enter JSON (auto-submits when braces close, Ctrl+C to cancel):
|
|
372
|
+
json> {
|
|
373
|
+
... "id": "Room1",
|
|
374
|
+
... "type": "Room"
|
|
375
|
+
... }
|
|
376
|
+
Entity created.
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
## Output Formats
|
|
380
|
+
|
|
381
|
+
Specify the output format with `--format` or `geonic config set format <fmt>`.
|
|
382
|
+
|
|
383
|
+
| Format | Description |
|
|
384
|
+
|---|---|
|
|
385
|
+
| `json` | Pretty-printed JSON (default) |
|
|
386
|
+
| `table` | ASCII table |
|
|
387
|
+
| `geojson` | GeoJSON FeatureCollection |
|
|
388
|
+
|
|
389
|
+
Use `--key-values` on `entities list` and `entities get` to request simplified key-value format from the API.
|
|
390
|
+
|
|
391
|
+
## Configuration
|
|
392
|
+
|
|
393
|
+
The CLI stores configuration in `~/.config/geonic/config.json`.
|
|
394
|
+
|
|
395
|
+
```bash
|
|
396
|
+
# Set the default server
|
|
397
|
+
geonic config set url http://localhost:3000
|
|
398
|
+
|
|
399
|
+
# Set default output format
|
|
400
|
+
geonic config set format table
|
|
401
|
+
|
|
402
|
+
# View all settings
|
|
403
|
+
geonic config list
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
Override the config directory with the `GEONIC_CONFIG_DIR` environment variable:
|
|
407
|
+
|
|
408
|
+
```bash
|
|
409
|
+
GEONIC_CONFIG_DIR=/path/to/config geonic entities list
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
## Development
|
|
413
|
+
|
|
414
|
+
Requires Node.js >= 20.
|
|
415
|
+
|
|
416
|
+
```bash
|
|
417
|
+
# Install dependencies
|
|
418
|
+
npm install
|
|
419
|
+
|
|
420
|
+
# Build
|
|
421
|
+
npm run build
|
|
422
|
+
|
|
423
|
+
# Run tests
|
|
424
|
+
npm test
|
|
425
|
+
|
|
426
|
+
# Lint
|
|
427
|
+
npm run lint
|
|
428
|
+
|
|
429
|
+
# Type check
|
|
430
|
+
npm run typecheck
|
|
431
|
+
|
|
432
|
+
# Watch mode (rebuild on change)
|
|
433
|
+
npm run dev
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
### Local testing
|
|
437
|
+
|
|
438
|
+
Use `npm link` to register the `geonic` command globally as a symlink:
|
|
439
|
+
|
|
440
|
+
```bash
|
|
441
|
+
npm link
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
After linking, rebuild to reflect code changes:
|
|
445
|
+
|
|
446
|
+
```bash
|
|
447
|
+
npm run build
|
|
448
|
+
geonic help
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
To unlink:
|
|
452
|
+
|
|
453
|
+
```bash
|
|
454
|
+
npm unlink -g @geolonia/geonicdb-cli
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
## License
|
|
458
|
+
|
|
459
|
+
MIT
|